# HG changeset patch # User rosfran # Date 1170968279 0 # Node ID 6d9f4e8468b3bfe373ab63a5fbe08fe2d4656e3e # Parent 60bfeabc0af66e00fdc131433820cf5a6cc78ec6 [svn r340] LiveTV is running now. diff -r 60bfeabc0af6 -r 6d9f4e8468b3 libgnomevfs2-mythtv/modules/mythtv-method.c --- a/libgnomevfs2-mythtv/modules/mythtv-method.c Thu Feb 08 20:57:31 2007 +0000 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c Thu Feb 08 20:57:59 2007 +0000 @@ -60,6 +60,8 @@ GByteArray *buffer; gsize buffer_remain; + gboolean is_livetv; + } MythtvHandle; static GnomeVFSResult @@ -73,12 +75,13 @@ GMythBackendInfo *backend_info; GMythURI *gmyth_uri = NULL; gboolean ret = TRUE; - gboolean is_livetv = FALSE; _GNOME_VFS_METHOD_PARAM_CHECK (method_handle != NULL); _GNOME_VFS_METHOD_PARAM_CHECK (uri != NULL); myth_handle = g_new0 (MythtvHandle, 1); + + myth_handle->is_livetv = FALSE; if (mode & GNOME_VFS_OPEN_WRITE) { return GNOME_VFS_ERROR_NOT_PERMITTED; @@ -103,75 +106,86 @@ gmyth_uri = gmyth_uri_new_with_value( gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) ); - is_livetv = gmyth_uri_is_livetv( gmyth_uri ); + myth_handle->is_livetv = gmyth_uri_is_livetv( gmyth_uri ); /* Connect to the backend */ - if ( gmyth_uri != NULL && is_livetv == TRUE ) { - myth_handle->livetv = gmyth_livetv_new (); + if ( gmyth_uri != NULL && myth_handle->is_livetv == TRUE ) { + + if ( NULL == myth_handle->livetv ) + { + myth_handle->livetv = gmyth_livetv_new (); - myth_handle->channel_name = gmyth_uri_get_channel_name( gmyth_uri ); - - g_print( "[%s] Channel name = %s", __FUNCTION__, myth_handle->channel_name ); + myth_handle->channel_name = gmyth_uri_get_channel_name( gmyth_uri ); + + g_debug( "[%s] Channel name = %s\n", __FUNCTION__, myth_handle->channel_name ); + + if ( myth_handle->channel_name != NULL ) { + if (gmyth_livetv_channel_name_setup (myth_handle->livetv, myth_handle->channel_name, + 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; + } + } + } + + if ( NULL == myth_handle->file_transfer ) { + myth_handle->file_transfer = gmyth_livetv_create_file_transfer (myth_handle->livetv); - if ( myth_handle->channel_name != NULL ) { - if (gmyth_livetv_channel_name_setup (myth_handle->livetv, myth_handle->channel_name, - 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; - g_warning ("MythTV FileTransfer is NULL!\n"); - return GNOME_VFS_ERROR_NOT_OPEN; - } - - if ( !gmyth_file_transfer_open( myth_handle->file_transfer, myth_handle->livetv->uri != NULL ? - gmyth_uri_get_path(myth_handle->livetv->uri) : - myth_handle->livetv->proginfo->pathname->str ) ) - { - g_object_unref( myth_handle->file_transfer ); - myth_handle->file_transfer = NULL; - ret = FALSE; - } + if (NULL == myth_handle->file_transfer) { + ret = FALSE; + g_debug ("MythTV FileTransfer is NULL!\n"); + return GNOME_VFS_ERROR_NOT_OPEN; + } + + if ( !gmyth_file_transfer_open( myth_handle->file_transfer, myth_handle->livetv->uri != NULL ? + gmyth_uri_get_path(myth_handle->livetv->uri) : + myth_handle->livetv->proginfo->pathname->str ) ) + { + g_debug ("Couldn't open MythTV FileTransfer is NULL!\n"); + g_object_unref( myth_handle->file_transfer ); + myth_handle->file_transfer = NULL; + ret = FALSE; + } + } /* if - FileTransfer is NULL, or not */ } else { + + if (NULL == myth_handle->file_transfer ) { - myth_handle->file_transfer = gmyth_file_transfer_new (backend_info); - - /* Verifies if the file exists */ - if (!gmyth_util_file_exists (backend_info, gmyth_uri_get_path (gmyth_uri))) { - g_object_unref (backend_info); - ret = FALSE; - } - - /* sets the Playback monitor connection */ - ret = gmyth_file_transfer_open ( myth_handle->file_transfer, - gmyth_uri_get_path (gmyth_uri) ); + myth_handle->file_transfer = gmyth_file_transfer_new (backend_info); + + /* Verifies if the file exists */ + if (!gmyth_util_file_exists (backend_info, gmyth_uri_get_path (gmyth_uri))) { + g_object_unref (backend_info); + ret = FALSE; + } + + /* sets the Playback monitor connection */ + ret = gmyth_file_transfer_open ( myth_handle->file_transfer, + gmyth_uri_get_path (gmyth_uri) ); + + } } /* if - LiveTV or not? */ if (ret == FALSE) { - g_warning ("MythTV FileTransfer open error.\n"); + g_debug ("MythTV FileTransfer open error.\n"); return GNOME_VFS_ERROR_NOT_OPEN; } - g_object_unref (backend_info); + //g_object_unref (backend_info); //if ( gmyth_uri != NULL ) // g_object_unref( gmyth_uri ); g_return_val_if_fail (myth_handle->file_transfer != NULL, GNOME_VFS_ERROR_NOT_OPEN); - if ( myth_handle->file_transfer->filesize < 0 && is_livetv ) { + if ( myth_handle->file_transfer->filesize < 0 && myth_handle->is_livetv ) { myth_handle->content_size = (GnomeVFSFileSize) 0; myth_handle->content_size = gmyth_recorder_get_file_position( myth_handle->livetv->recorder ); } else @@ -261,12 +275,12 @@ MythtvHandle *myth_handle = (MythtvHandle *) method_handle; if (myth_handle->file_transfer) { - gmyth_file_transfer_close (myth_handle->file_transfer); - g_object_unref (myth_handle->file_transfer); + //gmyth_file_transfer_close (myth_handle->file_transfer); + g_object_unref (myth_handle->file_transfer); myth_handle->file_transfer = NULL; } - if (myth_handle->livetv) { + if (myth_handle->is_livetv && myth_handle->livetv != NULL) { g_object_unref (myth_handle->livetv); myth_handle->livetv = NULL; } @@ -289,11 +303,10 @@ GnomeVFSContext *context) { GMythFileTransfer *file_transfer = NULL; - GMythRecorder *recorder = NULL; - GMythTVChain *tvchain = NULL; + //GMythRecorder *recorder = NULL; GMythBackendInfo *backend_info = NULL; GMythURI *gmyth_uri = NULL; - GMythSocket *socket = NULL; + //GMythSocket *socket = NULL; gboolean is_livetv = FALSE; gboolean ret = TRUE; @@ -325,11 +338,10 @@ /* Connect to the backend */ if ( gmyth_uri != NULL && is_livetv == TRUE ) { - + #if 0 gboolean res = TRUE; - /* start to get file info from LiveTV remote encoder */ - + /* start to get file info from LiveTV remote encoder */ socket = gmyth_socket_new (); /* FIME: Implement this at gmyth_socket */ @@ -365,71 +377,17 @@ g_print ("[%s] Fail while setting remote encoder\n", __FUNCTION__); res = FALSE; goto error; - } + } - /* Creates livetv chain handler */ - tvchain = gmyth_tvchain_new(); - gmyth_tvchain_initialize ( tvchain, backend_info ); - - if ( tvchain == NULL || tvchain->tvchain_id == NULL ) { - g_print ("[%s] TVChain couldn't be initialized.\n", __FUNCTION__); - res = FALSE; - goto error; - } - - // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly) - res = gmyth_recorder_spawntv ( recorder, - gmyth_tvchain_get_id(tvchain) ); - if (!res) { - g_print ("[%s] Fail while spawn tv\n", __FUNCTION__); - res = FALSE; - goto error; - } - - gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri ); - - if ( res == TRUE ) { - /* loop finished, set the max tries variable to zero again... */ - gint wait_to_transfer = 0; - - while ( wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS && - (gmyth_recorder_is_recording (recorder) == FALSE) ) - g_usleep (500); - - /* IS_RECORDING again, just like the MythTV backend does... */ - gmyth_recorder_is_recording (recorder); - - if ( channel_name != NULL ) - { - /* Pauses remote encoder. */ - res = gmyth_recorder_pause_recording(recorder); - if ( !res ) { - g_print ("[%s] Fail while pausing remote encoder\n", __FUNCTION__); - res = FALSE; - goto error; - } - - if ( gmyth_recorder_check_channel_name( recorder, channel_name ) ) - { - if ( !gmyth_recorder_set_channel_name( recorder, channel_name ) ) - { - g_warning( "Channel will not changes to: [%s].\n", channel_name ); - } - } - - } /* if - changes the channel number */ - - sleep( 1 ); - - } - - /* DEBUG message */ + //gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri ); + + /* DEBUG message */ GMythProgramInfo* prog_info = gmyth_recorder_get_current_program_info( recorder ); - //gmyth_debug( "New ProgramInfo...\n" ); - gmyth_program_info_print( prog_info ); if ( prog_info != NULL ) { + //gmyth_debug( "New ProgramInfo...\n" ); + gmyth_program_info_print( prog_info ); g_print( "path = %s", prog_info->pathname->str ); @@ -449,14 +407,15 @@ file_info->size = gmyth_recorder_get_file_position( recorder ); } - if ( tvchain != NULL) - g_object_unref (tvchain); - if ( recorder != NULL ) - gmyth_recorder_close (recorder); + g_object_unref (recorder); if ( prog_info != NULL ) g_object_unref( prog_info ); + + #endif + file_info->size = 0; + file_info->name = g_strdup ( "LiveTV.nuv" ); } else { @@ -472,8 +431,7 @@ /* sets the Playback monitor connection */ ret = gmyth_file_transfer_open ( file_transfer, gmyth_uri_get_path (gmyth_uri) ); - file_info->name = g_strdup ( gnome_vfs_uri_get_path (uri) ); - + file_info->name = g_strdup ( gnome_vfs_uri_get_path (uri) ); } /* if - LiveTV or not? */ @@ -485,13 +443,13 @@ if ( ret == TRUE && file_transfer != NULL ) { file_info->size = gmyth_file_transfer_get_filesize (file_transfer); if ( file_transfer ) - gmyth_file_transfer_close (file_transfer); + g_object_unref (file_transfer); } - + file_info->block_count = GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT; file_info->io_block_size = GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE; -error: +//error: if (backend_info) g_object_unref (backend_info);