melunko@38
|
1 |
/*
|
melunko@38
|
2 |
* @author Hallyson Melo <hallyson.melo@indt.org.br>
|
melunko@38
|
3 |
*
|
melunko@38
|
4 |
* This program is free software; you can redistribute it and/or modify
|
melunko@38
|
5 |
* it under the terms of the GNU Lesser General Public License as published by
|
melunko@38
|
6 |
* the Free Software Foundation; either version 2 of the License, or
|
melunko@38
|
7 |
* (at your option) any later version.
|
melunko@38
|
8 |
*
|
melunko@38
|
9 |
* This program is distributed in the hope that it will be useful,
|
melunko@38
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
melunko@38
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
melunko@38
|
12 |
* GNU General Public License for more details.
|
melunko@38
|
13 |
*
|
melunko@38
|
14 |
* You should have received a copy of the GNU Lesser General Public License
|
melunko@38
|
15 |
* along with this program; if not, write to the Free Software
|
melunko@38
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
melunko@38
|
17 |
*/
|
melunko@38
|
18 |
|
melunko@38
|
19 |
#ifdef HAVE_CONFIG_H
|
melunko@38
|
20 |
#include <config.h>
|
melunko@38
|
21 |
#endif
|
melunko@38
|
22 |
|
melunko@38
|
23 |
#include <string.h>
|
melunko@38
|
24 |
#include <glib.h>
|
melunko@38
|
25 |
#include <math.h>
|
melunko@38
|
26 |
|
melunko@38
|
27 |
#include <libgnomevfs/gnome-vfs-module.h>
|
melunko@38
|
28 |
#include <libgnomevfs/gnome-vfs-utils.h>
|
melunko@38
|
29 |
|
rosfran@277
|
30 |
#include <gmyth/gmyth_file_transfer.h>
|
rosfran@277
|
31 |
#include <gmyth/gmyth_livetv.h>
|
rosfran@277
|
32 |
#include <gmyth/gmyth_uri.h>
|
rosfran@277
|
33 |
#include <gmyth/gmyth_recorder.h>
|
rosfran@277
|
34 |
#include <gmyth/gmyth_backendinfo.h>
|
rosfran@277
|
35 |
#include <gmyth/gmyth_util.h>
|
rosfran@332
|
36 |
#include <gmyth/gmyth_remote_util.h>
|
rosfran@332
|
37 |
#include <gmyth/gmyth_tvchain.h>
|
melunko@38
|
38 |
|
melunko@38
|
39 |
#define GST_MYTHTV_ID_NUM 1
|
melunko@38
|
40 |
#define MYTHTV_VERSION_DEFAULT 30
|
rosfran@277
|
41 |
#define MYTHTV_TRANSFER_MAX_WAITS 100
|
melunko@38
|
42 |
|
rosfran@327
|
43 |
#define MYTHTV_BUFFER_SIZE 1024*64
|
melunko@111
|
44 |
|
melunko@38
|
45 |
static GnomeVFSResult do_read (GnomeVFSMethod *method,
|
melunko@38
|
46 |
GnomeVFSMethodHandle *method_handle,
|
melunko@38
|
47 |
gpointer buffer,
|
melunko@38
|
48 |
GnomeVFSFileSize num_bytes,
|
melunko@38
|
49 |
GnomeVFSFileSize *bytes_read,
|
melunko@38
|
50 |
GnomeVFSContext *context);
|
melunko@38
|
51 |
|
melunko@38
|
52 |
typedef struct {
|
melunko@48
|
53 |
GMythFileTransfer *file_transfer;
|
rosfran@277
|
54 |
GMythLiveTV *livetv;
|
rosfran@327
|
55 |
gchar *channel_name;
|
melunko@38
|
56 |
|
melunko@38
|
57 |
gint mythtv_version;
|
rosfran@297
|
58 |
gint64 content_size;
|
melunko@38
|
59 |
guint64 bytes_read;
|
melunko@111
|
60 |
|
rosfran@116
|
61 |
GByteArray *buffer;
|
melunko@111
|
62 |
gsize buffer_remain;
|
rosfran@338
|
63 |
gboolean is_livetv;
|
rosfran@338
|
64 |
|
melunko@38
|
65 |
} MythtvHandle;
|
melunko@38
|
66 |
|
melunko@38
|
67 |
static GnomeVFSResult
|
melunko@38
|
68 |
do_open (GnomeVFSMethod *method,
|
melunko@38
|
69 |
GnomeVFSMethodHandle **method_handle,
|
melunko@38
|
70 |
GnomeVFSURI *uri,
|
melunko@38
|
71 |
GnomeVFSOpenMode mode,
|
melunko@38
|
72 |
GnomeVFSContext *context)
|
melunko@38
|
73 |
{
|
melunko@111
|
74 |
MythtvHandle *myth_handle;
|
melunko@160
|
75 |
GMythBackendInfo *backend_info;
|
rosfran@277
|
76 |
GMythURI *gmyth_uri = NULL;
|
rosfran@277
|
77 |
gboolean ret = TRUE;
|
melunko@38
|
78 |
|
melunko@38
|
79 |
_GNOME_VFS_METHOD_PARAM_CHECK (method_handle != NULL);
|
melunko@38
|
80 |
_GNOME_VFS_METHOD_PARAM_CHECK (uri != NULL);
|
melunko@38
|
81 |
|
melunko@111
|
82 |
myth_handle = g_new0 (MythtvHandle, 1);
|
rosfran@338
|
83 |
|
rosfran@338
|
84 |
myth_handle->is_livetv = FALSE;
|
melunko@111
|
85 |
|
melunko@38
|
86 |
if (mode & GNOME_VFS_OPEN_WRITE) {
|
melunko@38
|
87 |
return GNOME_VFS_ERROR_NOT_PERMITTED;
|
melunko@38
|
88 |
}
|
melunko@38
|
89 |
|
renatofilho@149
|
90 |
if (gnome_vfs_uri_get_host_name (uri) == NULL) {
|
renatofilho@149
|
91 |
return GNOME_VFS_ERROR_INVALID_HOST_NAME;
|
melunko@38
|
92 |
}
|
melunko@38
|
93 |
|
melunko@38
|
94 |
/* Initialize mythtv handler*/
|
melunko@38
|
95 |
myth_handle->file_transfer = NULL;
|
rosfran@277
|
96 |
myth_handle->livetv = NULL;
|
melunko@38
|
97 |
myth_handle->mythtv_version = MYTHTV_VERSION_DEFAULT;
|
melunko@38
|
98 |
myth_handle->bytes_read = 0;
|
rosfran@328
|
99 |
myth_handle->content_size = (GnomeVFSFileSize) - 1;
|
melunko@38
|
100 |
|
rosfran@277
|
101 |
/* Creates and fills out the backend info structure */
|
rosfran@281
|
102 |
backend_info = gmyth_backend_info_new_with_uri (
|
rosfran@281
|
103 |
gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) );
|
rosfran@277
|
104 |
|
rosfran@277
|
105 |
/* creates an instance of */
|
rosfran@281
|
106 |
gmyth_uri = gmyth_uri_new_with_value(
|
rosfran@281
|
107 |
gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) );
|
rosfran@297
|
108 |
|
rosfran@338
|
109 |
myth_handle->is_livetv = gmyth_uri_is_livetv( gmyth_uri );
|
rosfran@297
|
110 |
|
rosfran@277
|
111 |
/* Connect to the backend */
|
rosfran@338
|
112 |
if ( gmyth_uri != NULL && myth_handle->is_livetv == TRUE ) {
|
rosfran@338
|
113 |
|
rosfran@344
|
114 |
if ( NULL == myth_handle->livetv )
|
rosfran@338
|
115 |
{
|
rosfran@338
|
116 |
myth_handle->livetv = gmyth_livetv_new ();
|
rosfran@180
|
117 |
|
rosfran@338
|
118 |
myth_handle->channel_name = gmyth_uri_get_channel_name( gmyth_uri );
|
rosfran@338
|
119 |
|
rosfran@338
|
120 |
g_debug( "[%s] Channel name = %s\n", __FUNCTION__, myth_handle->channel_name );
|
rosfran@338
|
121 |
|
rosfran@338
|
122 |
if ( myth_handle->channel_name != NULL ) {
|
rosfran@338
|
123 |
if (gmyth_livetv_channel_name_setup (myth_handle->livetv, myth_handle->channel_name,
|
rosfran@338
|
124 |
backend_info) == FALSE) {
|
rosfran@338
|
125 |
g_object_unref( gmyth_uri );
|
rosfran@338
|
126 |
ret = FALSE;
|
rosfran@338
|
127 |
}
|
rosfran@338
|
128 |
} else {
|
rosfran@338
|
129 |
if ( gmyth_livetv_setup (myth_handle->livetv, backend_info) == FALSE ) {
|
rosfran@338
|
130 |
g_object_unref( gmyth_uri );
|
rosfran@338
|
131 |
ret = FALSE;
|
rosfran@338
|
132 |
}
|
rosfran@338
|
133 |
}
|
rosfran@338
|
134 |
}
|
rosfran@338
|
135 |
|
rosfran@338
|
136 |
if ( NULL == myth_handle->file_transfer ) {
|
rosfran@338
|
137 |
myth_handle->file_transfer = gmyth_livetv_create_file_transfer (myth_handle->livetv);
|
rosfran@277
|
138 |
|
rosfran@338
|
139 |
if (NULL == myth_handle->file_transfer) {
|
rosfran@338
|
140 |
ret = FALSE;
|
rosfran@338
|
141 |
g_debug ("MythTV FileTransfer is NULL!\n");
|
rosfran@338
|
142 |
return GNOME_VFS_ERROR_NOT_OPEN;
|
rosfran@338
|
143 |
}
|
rosfran@338
|
144 |
|
rosfran@338
|
145 |
if ( !gmyth_file_transfer_open( myth_handle->file_transfer, myth_handle->livetv->uri != NULL ?
|
rosfran@338
|
146 |
gmyth_uri_get_path(myth_handle->livetv->uri) :
|
rosfran@338
|
147 |
myth_handle->livetv->proginfo->pathname->str ) )
|
rosfran@338
|
148 |
{
|
rosfran@338
|
149 |
g_debug ("Couldn't open MythTV FileTransfer is NULL!\n");
|
rosfran@338
|
150 |
g_object_unref( myth_handle->file_transfer );
|
rosfran@338
|
151 |
myth_handle->file_transfer = NULL;
|
rosfran@338
|
152 |
ret = FALSE;
|
rosfran@338
|
153 |
}
|
rosfran@338
|
154 |
} /* if - FileTransfer is NULL, or not */
|
rosfran@323
|
155 |
|
rosfran@277
|
156 |
} else {
|
rosfran@338
|
157 |
|
rosfran@338
|
158 |
if (NULL == myth_handle->file_transfer ) {
|
rosfran@277
|
159 |
|
rosfran@338
|
160 |
myth_handle->file_transfer = gmyth_file_transfer_new (backend_info);
|
rosfran@338
|
161 |
|
rosfran@338
|
162 |
/* Verifies if the file exists */
|
rosfran@338
|
163 |
if (!gmyth_util_file_exists (backend_info, gmyth_uri_get_path (gmyth_uri))) {
|
rosfran@338
|
164 |
g_object_unref (backend_info);
|
rosfran@338
|
165 |
ret = FALSE;
|
rosfran@338
|
166 |
}
|
rosfran@338
|
167 |
|
rosfran@338
|
168 |
/* sets the Playback monitor connection */
|
rosfran@338
|
169 |
ret = gmyth_file_transfer_open ( myth_handle->file_transfer,
|
rosfran@338
|
170 |
gmyth_uri_get_path (gmyth_uri) );
|
rosfran@338
|
171 |
|
rosfran@338
|
172 |
}
|
rosfran@277
|
173 |
|
rosfran@277
|
174 |
} /* if - LiveTV or not? */
|
rosfran@277
|
175 |
|
rosfran@277
|
176 |
if (ret == FALSE) {
|
rosfran@338
|
177 |
g_debug ("MythTV FileTransfer open error.\n");
|
rosfran@277
|
178 |
return GNOME_VFS_ERROR_NOT_OPEN;
|
rosfran@323
|
179 |
}
|
melunko@251
|
180 |
|
rosfran@338
|
181 |
//g_object_unref (backend_info);
|
rosfran@297
|
182 |
|
rosfran@297
|
183 |
//if ( gmyth_uri != NULL )
|
rosfran@297
|
184 |
// g_object_unref( gmyth_uri );
|
rosfran@297
|
185 |
|
rosfran@297
|
186 |
g_return_val_if_fail (myth_handle->file_transfer != NULL, GNOME_VFS_ERROR_NOT_OPEN);
|
rosfran@323
|
187 |
|
rosfran@340
|
188 |
if ( /*myth_handle->file_transfer->filesize <= 0 && */myth_handle->is_livetv ) {
|
rosfran@340
|
189 |
myth_handle->content_size = (GnomeVFSFileSize) - 1;
|
rosfran@340
|
190 |
//myth_handle->content_size = gmyth_recorder_get_file_position( myth_handle->livetv->recorder );
|
rosfran@327
|
191 |
} else
|
rosfran@323
|
192 |
myth_handle->content_size = myth_handle->file_transfer->filesize;
|
melunko@111
|
193 |
|
rosfran@116
|
194 |
myth_handle->buffer = g_byte_array_sized_new (MYTHTV_BUFFER_SIZE);
|
melunko@111
|
195 |
myth_handle->buffer_remain = 0;
|
melunko@38
|
196 |
|
melunko@38
|
197 |
*method_handle = (GnomeVFSMethodHandle *) myth_handle;
|
melunko@38
|
198 |
|
melunko@38
|
199 |
return GNOME_VFS_OK;
|
melunko@38
|
200 |
}
|
melunko@38
|
201 |
|
melunko@38
|
202 |
static GnomeVFSResult
|
melunko@38
|
203 |
do_read (GnomeVFSMethod *method,
|
melunko@38
|
204 |
GnomeVFSMethodHandle *method_handle,
|
melunko@38
|
205 |
gpointer buffer,
|
melunko@38
|
206 |
GnomeVFSFileSize num_bytes,
|
melunko@38
|
207 |
GnomeVFSFileSize *bytes_read,
|
melunko@38
|
208 |
GnomeVFSContext *context)
|
melunko@38
|
209 |
{
|
rosfran@327
|
210 |
MythtvHandle *myth_handle = (MythtvHandle *) method_handle;
|
rosfran@327
|
211 |
GnomeVFSFileSize bytes_to_read;
|
melunko@38
|
212 |
|
rosfran@327
|
213 |
*bytes_read = 0;
|
melunko@38
|
214 |
|
rosfran@340
|
215 |
if ( !myth_handle->is_livetv && ( myth_handle->bytes_read >= myth_handle->content_size ) )
|
rosfran@327
|
216 |
return GNOME_VFS_ERROR_EOF;
|
melunko@38
|
217 |
|
rosfran@327
|
218 |
// fixme: change this to min math function
|
rosfran@341
|
219 |
if (!myth_handle->is_livetv && ( myth_handle->content_size > 0 ) &&
|
rosfran@341
|
220 |
( num_bytes > ( myth_handle->content_size - myth_handle->bytes_read ) ) )
|
rosfran@327
|
221 |
bytes_to_read = myth_handle->content_size - myth_handle->bytes_read;
|
rosfran@327
|
222 |
else
|
rosfran@327
|
223 |
bytes_to_read = num_bytes;
|
melunko@38
|
224 |
|
rosfran@327
|
225 |
/* Loop sending the Myth File Transfer request:
|
rosfran@327
|
226 |
* Retry whilst authentication fails and we supply it. */
|
rosfran@327
|
227 |
//if (myth_handle->buffer_remain < MYTHTV_BUFFER_SIZE) {
|
rosfran@327
|
228 |
if ( ( myth_handle->buffer_remain = myth_handle->buffer->len ) < MYTHTV_BUFFER_SIZE ) {
|
rosfran@327
|
229 |
GByteArray *tmp_buffer = g_byte_array_new();
|
melunko@38
|
230 |
|
rosfran@327
|
231 |
printf ("XXXXXXXXXXXXXX Pedindo %d %d\n", MYTHTV_BUFFER_SIZE, myth_handle->buffer_remain);
|
melunko@317
|
232 |
|
rosfran@327
|
233 |
gint len = gmyth_file_transfer_read (myth_handle->file_transfer,
|
rosfran@327
|
234 |
tmp_buffer, MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain, TRUE);
|
melunko@38
|
235 |
|
rosfran@341
|
236 |
if (!myth_handle->is_livetv && len < 0) {
|
rosfran@327
|
237 |
g_byte_array_free (tmp_buffer, TRUE);
|
rosfran@333
|
238 |
g_print ("Fail to read bytes");
|
melunko@251
|
239 |
return GNOME_VFS_ERROR_IO;
|
rosfran@327
|
240 |
} /*else if (len == 0) {
|
rosfran@327
|
241 |
g_byte_array_free (tmp_buffer, TRUE);
|
rosfran@327
|
242 |
g_warning ("End of file probably achieved");
|
rosfran@327
|
243 |
return GNOME_VFS_ERROR_EOF;
|
rosfran@327
|
244 |
}*/
|
rosfran@327
|
245 |
|
rosfran@327
|
246 |
myth_handle->buffer = g_byte_array_append (myth_handle->buffer,
|
rosfran@327
|
247 |
tmp_buffer->data, len);
|
rosfran@327
|
248 |
|
rosfran@327
|
249 |
myth_handle->buffer_remain += len;
|
melunko@111
|
250 |
|
rosfran@327
|
251 |
g_byte_array_free (tmp_buffer, TRUE);
|
rosfran@327
|
252 |
tmp_buffer = NULL;
|
rosfran@116
|
253 |
}
|
melunko@38
|
254 |
|
melunko@111
|
255 |
bytes_to_read = (bytes_to_read > myth_handle->buffer_remain) ? myth_handle->buffer_remain : bytes_to_read;
|
renatofilho@164
|
256 |
/* gets the first buffer_size bytes from the byte array buffer variable */
|
rosfran@116
|
257 |
|
renatofilho@149
|
258 |
g_memmove (buffer, myth_handle->buffer->data, bytes_to_read);
|
rosfran@116
|
259 |
|
melunko@111
|
260 |
myth_handle->bytes_read += bytes_to_read;
|
rosfran@116
|
261 |
myth_handle->buffer_remain -= bytes_to_read;
|
rosfran@116
|
262 |
|
rosfran@116
|
263 |
/* flushs the newly buffer got from byte array */
|
renatofilho@149
|
264 |
myth_handle->buffer = g_byte_array_remove_range (myth_handle->buffer, 0, bytes_to_read);
|
melunko@111
|
265 |
*bytes_read = bytes_to_read;
|
melunko@38
|
266 |
|
melunko@38
|
267 |
return GNOME_VFS_OK;
|
melunko@38
|
268 |
}
|
melunko@38
|
269 |
|
melunko@38
|
270 |
static GnomeVFSResult
|
melunko@38
|
271 |
do_close (GnomeVFSMethod *method,
|
melunko@38
|
272 |
GnomeVFSMethodHandle *method_handle,
|
melunko@38
|
273 |
GnomeVFSContext *context)
|
melunko@38
|
274 |
{
|
melunko@111
|
275 |
|
melunko@38
|
276 |
MythtvHandle *myth_handle = (MythtvHandle *) method_handle;
|
melunko@38
|
277 |
|
rosfran@344
|
278 |
if (myth_handle->file_transfer != NULL) {
|
rosfran@338
|
279 |
//gmyth_file_transfer_close (myth_handle->file_transfer);
|
rosfran@338
|
280 |
g_object_unref (myth_handle->file_transfer);
|
renatofilho@164
|
281 |
myth_handle->file_transfer = NULL;
|
melunko@111
|
282 |
}
|
rosfran@127
|
283 |
|
rosfran@338
|
284 |
if (myth_handle->is_livetv && myth_handle->livetv != NULL) {
|
rosfran@277
|
285 |
g_object_unref (myth_handle->livetv);
|
rosfran@277
|
286 |
myth_handle->livetv = NULL;
|
rosfran@277
|
287 |
}
|
rosfran@277
|
288 |
|
rosfran@127
|
289 |
if (myth_handle->buffer) {
|
renatofilho@164
|
290 |
g_byte_array_free (myth_handle->buffer, TRUE);
|
renatofilho@164
|
291 |
myth_handle->buffer = NULL;
|
rosfran@127
|
292 |
}
|
melunko@38
|
293 |
|
melunko@38
|
294 |
g_free (myth_handle);
|
melunko@38
|
295 |
|
melunko@38
|
296 |
return GNOME_VFS_OK;
|
melunko@38
|
297 |
}
|
melunko@38
|
298 |
|
melunko@38
|
299 |
static GnomeVFSResult
|
melunko@38
|
300 |
do_get_file_info (GnomeVFSMethod *method,
|
melunko@38
|
301 |
GnomeVFSURI *uri,
|
melunko@38
|
302 |
GnomeVFSFileInfo *file_info,
|
melunko@38
|
303 |
GnomeVFSFileInfoOptions options,
|
melunko@38
|
304 |
GnomeVFSContext *context)
|
melunko@38
|
305 |
{
|
renatofilho@188
|
306 |
GMythFileTransfer *file_transfer = NULL;
|
rosfran@340
|
307 |
GMythRecorder *recorder = NULL;
|
rosfran@297
|
308 |
GMythBackendInfo *backend_info = NULL;
|
rosfran@297
|
309 |
GMythURI *gmyth_uri = NULL;
|
rosfran@340
|
310 |
GMythSocket *socket = NULL;
|
rosfran@297
|
311 |
gboolean is_livetv = FALSE;
|
rosfran@301
|
312 |
gboolean ret = TRUE;
|
rosfran@297
|
313 |
|
rosfran@297
|
314 |
/* Creates and fills out the backend info structure */
|
rosfran@297
|
315 |
backend_info = gmyth_backend_info_new_with_uri (
|
rosfran@297
|
316 |
gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) );
|
rosfran@297
|
317 |
|
rosfran@297
|
318 |
/* creates an instance of */
|
rosfran@297
|
319 |
gmyth_uri = gmyth_uri_new_with_value(
|
rosfran@297
|
320 |
gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) );
|
renatofilho@188
|
321 |
|
rosfran@297
|
322 |
is_livetv = gmyth_uri_is_livetv( gmyth_uri );
|
rosfran@297
|
323 |
|
melunko@38
|
324 |
file_info->valid_fields = file_info->valid_fields
|
melunko@38
|
325 |
| GNOME_VFS_FILE_INFO_FIELDS_TYPE
|
melunko@38
|
326 |
| GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE
|
melunko@38
|
327 |
| GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS;
|
melunko@38
|
328 |
file_info->type = GNOME_VFS_FILE_TYPE_REGULAR;
|
rosfran@297
|
329 |
/* fixme: get from file extension? */
|
melunko@111
|
330 |
file_info->mime_type = g_strdup ("video/x-nuv");
|
melunko@38
|
331 |
file_info->permissions =
|
melunko@38
|
332 |
GNOME_VFS_PERM_USER_READ |
|
melunko@38
|
333 |
GNOME_VFS_PERM_OTHER_READ |
|
melunko@38
|
334 |
GNOME_VFS_PERM_GROUP_READ;
|
rosfran@331
|
335 |
|
rosfran@332
|
336 |
g_print( "gnome_vfs_uri == %s | gmyth_uri == %s.\n",
|
rosfran@331
|
337 |
gnome_vfs_uri_get_path (uri),
|
rosfran@331
|
338 |
gmyth_uri_get_path (gmyth_uri) );
|
melunko@38
|
339 |
|
rosfran@301
|
340 |
/* Connect to the backend */
|
rosfran@297
|
341 |
if ( gmyth_uri != NULL && is_livetv == TRUE ) {
|
rosfran@332
|
342 |
gboolean res = TRUE;
|
rosfran@332
|
343 |
|
rosfran@338
|
344 |
/* start to get file info from LiveTV remote encoder */
|
rosfran@332
|
345 |
socket = gmyth_socket_new ();
|
rosfran@332
|
346 |
|
rosfran@332
|
347 |
/* FIME: Implement this at gmyth_socket */
|
rosfran@332
|
348 |
res = gmyth_socket_connect_to_backend (socket, backend_info->hostname,
|
rosfran@332
|
349 |
backend_info->port, TRUE);
|
rosfran@332
|
350 |
if (!res) {
|
rosfran@333
|
351 |
g_print ("[%s] LiveTV can not connect to backend", __FUNCTION__);
|
rosfran@332
|
352 |
res = FALSE;
|
rosfran@332
|
353 |
goto error;
|
rosfran@332
|
354 |
}
|
rosfran@332
|
355 |
|
rosfran@332
|
356 |
if ( gmyth_remote_util_get_free_recorder_count (socket) <= 0 ) {
|
rosfran@333
|
357 |
g_print ("No free remote encoder available.");
|
rosfran@332
|
358 |
res = FALSE;
|
rosfran@332
|
359 |
goto error;
|
rosfran@332
|
360 |
}
|
rosfran@332
|
361 |
|
rosfran@332
|
362 |
/* Gets the recorder num */
|
rosfran@332
|
363 |
recorder = remote_request_next_free_recorder (socket, -1);
|
rosfran@335
|
364 |
|
rosfran@335
|
365 |
if ( socket != NULL )
|
rosfran@335
|
366 |
g_object_unref (socket);
|
rosfran@332
|
367 |
|
rosfran@332
|
368 |
if ( recorder == NULL ) {
|
rosfran@333
|
369 |
g_print ("[%s] None remote encoder available", __FUNCTION__);
|
rosfran@332
|
370 |
res = FALSE;
|
rosfran@332
|
371 |
goto error;
|
rosfran@332
|
372 |
}
|
rosfran@332
|
373 |
|
rosfran@332
|
374 |
/* Init remote encoder. Opens its control socket. */
|
rosfran@332
|
375 |
res = gmyth_recorder_setup(recorder);
|
rosfran@332
|
376 |
if ( !res ) {
|
rosfran@333
|
377 |
g_print ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
|
rosfran@332
|
378 |
res = FALSE;
|
rosfran@332
|
379 |
goto error;
|
rosfran@338
|
380 |
}
|
rosfran@332
|
381 |
|
rosfran@338
|
382 |
//gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri );
|
rosfran@338
|
383 |
|
rosfran@338
|
384 |
/* DEBUG message */
|
rosfran@332
|
385 |
GMythProgramInfo* prog_info = gmyth_recorder_get_current_program_info( recorder );
|
rosfran@332
|
386 |
|
rosfran@332
|
387 |
if ( prog_info != NULL )
|
rosfran@332
|
388 |
{
|
rosfran@338
|
389 |
gmyth_program_info_print( prog_info );
|
rosfran@332
|
390 |
|
rosfran@332
|
391 |
g_print( "path = %s", prog_info->pathname->str );
|
rosfran@332
|
392 |
|
rosfran@332
|
393 |
file_info->name = g_strdup ( g_strrstr( prog_info->pathname->str, "/" ) );
|
rosfran@332
|
394 |
|
rosfran@332
|
395 |
} else {
|
rosfran@341
|
396 |
file_info->name = g_strdup ( "LiveTV.nuv" );
|
rosfran@332
|
397 |
file_info->size = gmyth_recorder_get_file_position( recorder );
|
rosfran@332
|
398 |
}
|
rosfran@333
|
399 |
|
rosfran@332
|
400 |
if ( recorder != NULL )
|
rosfran@338
|
401 |
g_object_unref (recorder);
|
rosfran@333
|
402 |
|
rosfran@333
|
403 |
if ( prog_info != NULL )
|
rosfran@333
|
404 |
g_object_unref( prog_info );
|
rosfran@338
|
405 |
|
rosfran@340
|
406 |
file_info->size = (GnomeVFSFileSize) - 1;
|
rosfran@331
|
407 |
|
rosfran@297
|
408 |
} else {
|
rosfran@332
|
409 |
|
rosfran@332
|
410 |
/* start to get file info from remote file encoder */
|
rosfran@297
|
411 |
file_transfer = gmyth_file_transfer_new (backend_info);
|
rosfran@297
|
412 |
|
rosfran@297
|
413 |
/* Verifies if the file exists */
|
rosfran@297
|
414 |
if (!gmyth_util_file_exists (backend_info, gmyth_uri_get_path (gmyth_uri))) {
|
rosfran@297
|
415 |
g_object_unref (backend_info);
|
rosfran@297
|
416 |
return GNOME_VFS_ERROR_NOT_FOUND;
|
rosfran@297
|
417 |
}
|
rosfran@297
|
418 |
|
rosfran@297
|
419 |
/* sets the Playback monitor connection */
|
rosfran@297
|
420 |
ret = gmyth_file_transfer_open ( file_transfer, gmyth_uri_get_path (gmyth_uri) );
|
rosfran@331
|
421 |
|
rosfran@338
|
422 |
file_info->name = g_strdup ( gnome_vfs_uri_get_path (uri) );
|
rosfran@297
|
423 |
|
rosfran@335
|
424 |
} /* if - LiveTV or not? */
|
rosfran@297
|
425 |
|
rosfran@297
|
426 |
if (ret == FALSE) {
|
rosfran@335
|
427 |
g_debug ("MythTV FileTransfer open error\n");
|
rosfran@297
|
428 |
return GNOME_VFS_ERROR_NOT_OPEN;
|
rosfran@297
|
429 |
}
|
rosfran@335
|
430 |
|
rosfran@332
|
431 |
if ( ret == TRUE && file_transfer != NULL ) {
|
rosfran@323
|
432 |
file_info->size = gmyth_file_transfer_get_filesize (file_transfer);
|
rosfran@331
|
433 |
if ( file_transfer )
|
rosfran@338
|
434 |
g_object_unref (file_transfer);
|
rosfran@331
|
435 |
}
|
rosfran@338
|
436 |
|
rosfran@331
|
437 |
file_info->block_count = GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT;
|
rosfran@331
|
438 |
file_info->io_block_size = GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE;
|
rosfran@332
|
439 |
|
rosfran@340
|
440 |
error:
|
rosfran@331
|
441 |
if (backend_info)
|
rosfran@331
|
442 |
g_object_unref (backend_info);
|
rosfran@301
|
443 |
|
melunko@38
|
444 |
return GNOME_VFS_OK;
|
melunko@38
|
445 |
}
|
melunko@38
|
446 |
|
melunko@38
|
447 |
static gboolean
|
melunko@38
|
448 |
do_is_local (GnomeVFSMethod *method,
|
melunko@38
|
449 |
const GnomeVFSURI *uri)
|
melunko@38
|
450 |
{
|
melunko@38
|
451 |
return FALSE;
|
melunko@38
|
452 |
}
|
melunko@38
|
453 |
|
melunko@38
|
454 |
static GnomeVFSMethod method = {
|
melunko@38
|
455 |
sizeof (GnomeVFSMethod),
|
melunko@38
|
456 |
do_open,
|
melunko@38
|
457 |
NULL,
|
melunko@38
|
458 |
do_close,
|
melunko@38
|
459 |
do_read,
|
melunko@38
|
460 |
NULL,
|
melunko@38
|
461 |
NULL,
|
melunko@38
|
462 |
NULL,
|
melunko@38
|
463 |
NULL,
|
melunko@38
|
464 |
NULL,
|
melunko@38
|
465 |
NULL,
|
melunko@38
|
466 |
NULL,
|
melunko@38
|
467 |
do_get_file_info,
|
melunko@38
|
468 |
NULL,
|
melunko@38
|
469 |
do_is_local,
|
melunko@38
|
470 |
NULL,
|
melunko@38
|
471 |
NULL,
|
melunko@38
|
472 |
NULL,
|
melunko@38
|
473 |
NULL,
|
melunko@38
|
474 |
NULL,
|
melunko@38
|
475 |
NULL,
|
melunko@38
|
476 |
NULL,
|
melunko@38
|
477 |
NULL,
|
melunko@38
|
478 |
NULL,
|
melunko@38
|
479 |
NULL,
|
melunko@38
|
480 |
NULL,
|
melunko@38
|
481 |
NULL,
|
melunko@38
|
482 |
};
|
melunko@38
|
483 |
|
melunko@38
|
484 |
|
melunko@38
|
485 |
GnomeVFSMethod *
|
melunko@38
|
486 |
vfs_module_init (const char *method_name, const char *args)
|
melunko@38
|
487 |
{
|
melunko@38
|
488 |
return &method;
|
melunko@38
|
489 |
}
|
melunko@38
|
490 |
|
melunko@38
|
491 |
void
|
melunko@38
|
492 |
vfs_module_shutdown (GnomeVFSMethod *method)
|
melunko@38
|
493 |
{
|
melunko@38
|
494 |
}
|