diff -r 9f0346db9a46 -r 890b023c759f libgnomevfs2-mythtv/modules/mythtv-method.c --- a/libgnomevfs2-mythtv/modules/mythtv-method.c Wed Jan 10 17:19:50 2007 +0000 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c Fri Jan 19 00:51:49 2007 +0000 @@ -27,12 +27,16 @@ #include #include -#include -#include -#include +#include +#include +#include +#include +#include +#include #define GST_MYTHTV_ID_NUM 1 #define MYTHTV_VERSION_DEFAULT 30 +#define MYTHTV_TRANSFER_MAX_WAITS 100 #define MYTHTV_BUFFER_SIZE 1024*64 @@ -45,6 +49,8 @@ typedef struct { GMythFileTransfer *file_transfer; + GMythLiveTV *livetv; + gint channel_num; gint mythtv_version; guint64 content_size; @@ -65,7 +71,10 @@ { MythtvHandle *myth_handle; GMythBackendInfo *backend_info; - gboolean ret; + GMythURI *gmyth_uri = NULL; + gboolean ret = TRUE; + gboolean is_livetv = FALSE; + gint wait_to_transfer = 0; _GNOME_VFS_METHOD_PARAM_CHECK (method_handle != NULL); _GNOME_VFS_METHOD_PARAM_CHECK (uri != NULL); @@ -82,36 +91,83 @@ /* Initialize mythtv handler*/ myth_handle->file_transfer = NULL; + myth_handle->livetv = NULL; myth_handle->mythtv_version = MYTHTV_VERSION_DEFAULT; myth_handle->bytes_read = 0; myth_handle->content_size = -1; - /* Creates and fills out the backend info structure */ - backend_info = gmyth_backend_info_new_full ( - gnome_vfs_uri_get_host_name (uri), - NULL, NULL, NULL, - gnome_vfs_uri_get_host_port (uri)); + /* Creates and fills out the backend info structure */ + backend_info = gmyth_backend_info_new_with_uri ( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ) ); + + /* creates an instance of */ + gmyth_uri = gmyth_uri_new_with_value( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ) ); + + /* Connect to the backend */ + if ( gmyth_uri != NULL && ( is_livetv = gmyth_uri_is_livetv( gmyth_uri ) ) == TRUE ) { + myth_handle->livetv = gmyth_livetv_new (); + myth_handle->channel_num = gmyth_uri_get_channel_num( gmyth_uri ); + + if ( myth_handle->channel_num != -1 ) { + if (gmyth_livetv_channel_setup (myth_handle->livetv, myth_handle->channel_num, + backend_info) == FALSE) { + g_object_unref( gmyth_uri ); + ret = FALSE; + } + } else { + if ( gmyth_livetv_setup (myth_handle->livetv, backend_info) == FALSE ) { + g_object_unref( gmyth_uri ); + ret = FALSE; + } + } + + myth_handle->file_transfer = gmyth_livetv_create_file_transfer (myth_handle->livetv); + + if (NULL == myth_handle->file_transfer) { + ret = FALSE; + } + + if ( gmyth_uri != NULL ) + g_object_unref( gmyth_uri ); + + } else { + + myth_handle->file_transfer = gmyth_file_transfer_new (backend_info); + + /* Verifies if the file exists */ + if (!gmyth_util_file_exists (backend_info, gnome_vfs_uri_get_path (uri))) { + g_object_unref (backend_info); + return GNOME_VFS_ERROR_NOT_FOUND; + } + + /* sets the Playback monitor connection */ + ret = gmyth_file_transfer_open ( myth_handle->file_transfer, gnome_vfs_uri_get_path (uri) ); + + } /* if - LiveTV or not? */ + + if (ret == FALSE) { + g_warning ("MythTV FileTransfer open error\n"); + return GNOME_VFS_ERROR_NOT_OPEN; + } + + if ( is_livetv == TRUE && ret == TRUE ) { + /* loop finished, set the max tries variable to zero again... */ + wait_to_transfer = 0; + + while ( wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS && + (gmyth_livetv_is_recording (myth_handle->livetv) == FALSE)) + g_usleep (500); + + /* IS_RECORDING again, just like the MythTV backend does... */ + gmyth_livetv_is_recording (myth_handle->livetv); + + sleep (4); /* FIXME: this is evil (tpm) */ + } - /* Verifies if the file exists */ - if (!gmyth_util_file_exists (backend_info, gnome_vfs_uri_get_path (uri))) { - g_object_unref (backend_info); - return GNOME_VFS_ERROR_NOT_FOUND; - } - - /* Connect to the backend */ - myth_handle->file_transfer = gmyth_file_transfer_new (backend_info); g_object_unref (backend_info); g_return_val_if_fail (myth_handle->file_transfer != NULL, GNOME_VFS_ERROR_NOT_OPEN); - /* sets the Playback monitor connection */ - ret = gmyth_file_transfer_open (myth_handle->file_transfer, gnome_vfs_uri_get_path (uri)); - if (ret == FALSE) { - g_warning ("Mythtv FileTransfer open error\n"); - return GNOME_VFS_ERROR_NOT_OPEN; - } - myth_handle->content_size = myth_handle->file_transfer->filesize; myth_handle->buffer = g_byte_array_sized_new (MYTHTV_BUFFER_SIZE); @@ -201,6 +257,11 @@ myth_handle->file_transfer = NULL; } + if (myth_handle->livetv) { + g_object_unref (myth_handle->livetv); + myth_handle->livetv = NULL; + } + if (myth_handle->buffer) { g_byte_array_free (myth_handle->buffer, TRUE); myth_handle->buffer = NULL;