# HG changeset patch # User rosfran # Date 1170722077 0 # Node ID 41995e0df2baa48240504c1a26fc4c7ced94c83c # Parent 81b1f3006eb22da8c551680647a85273eba5e262 [svn r329] Cleaning some non-mandatory code snippets from the GnomeVFS handler to the do_get_file_info. diff -r 81b1f3006eb2 -r 41995e0df2ba libgnomevfs2-mythtv/modules/mythtv-method.c --- a/libgnomevfs2-mythtv/modules/mythtv-method.c Tue Feb 06 00:33:35 2007 +0000 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c Tue Feb 06 00:34:37 2007 +0000 @@ -38,7 +38,7 @@ #define MYTHTV_VERSION_DEFAULT 30 #define MYTHTV_TRANSFER_MAX_WAITS 100 -#define MYTHTV_BUFFER_SIZE 1024*64 +#define MYTHTV_BUFFER_SIZE 1024*64 static GnomeVFSResult do_read (GnomeVFSMethod *method, GnomeVFSMethodHandle *method_handle, @@ -50,7 +50,7 @@ typedef struct { GMythFileTransfer *file_transfer; GMythLiveTV *livetv; - gint channel_num; + gchar *channel_name; gint mythtv_version; gint64 content_size; @@ -91,7 +91,7 @@ myth_handle->livetv = NULL; myth_handle->mythtv_version = MYTHTV_VERSION_DEFAULT; myth_handle->bytes_read = 0; - myth_handle->content_size = 0; + myth_handle->content_size = -1; /* Creates and fills out the backend info structure */ backend_info = gmyth_backend_info_new_with_uri ( @@ -107,10 +107,12 @@ if ( gmyth_uri != NULL && is_livetv == TRUE ) { myth_handle->livetv = gmyth_livetv_new (); - myth_handle->channel_num = gmyth_uri_get_channel_num( gmyth_uri ); + myth_handle->channel_name = gmyth_uri_get_channel_name( gmyth_uri ); + + g_print( "[%s] Channel name = %s", __FUNCTION__, myth_handle->channel_name ); - if ( myth_handle->channel_num != -1 ) { - if (gmyth_livetv_channel_setup (myth_handle->livetv, myth_handle->channel_num, + 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; @@ -148,7 +150,8 @@ } /* sets the Playback monitor connection */ - ret = gmyth_file_transfer_open ( myth_handle->file_transfer, gmyth_uri_get_path (gmyth_uri) ); + ret = gmyth_file_transfer_open ( myth_handle->file_transfer, + gmyth_uri_get_path (gmyth_uri) ); } /* if - LiveTV or not? */ @@ -164,9 +167,10 @@ 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 && is_livetv ) { + myth_handle->content_size = (GnomeVFSFileSize) - 1; myth_handle->content_size = gmyth_recorder_get_file_position( myth_handle->livetv->recorder ); - else + } else myth_handle->content_size = myth_handle->file_transfer->filesize; myth_handle->buffer = g_byte_array_sized_new (MYTHTV_BUFFER_SIZE); @@ -185,48 +189,48 @@ GnomeVFSFileSize *bytes_read, GnomeVFSContext *context) { - MythtvHandle *myth_handle = (MythtvHandle *) method_handle; - GnomeVFSFileSize bytes_to_read; + MythtvHandle *myth_handle = (MythtvHandle *) method_handle; + GnomeVFSFileSize bytes_to_read; - *bytes_read = 0; + *bytes_read = 0; - if (myth_handle->bytes_read >= myth_handle->content_size) - return GNOME_VFS_ERROR_EOF; + if (myth_handle->bytes_read >= myth_handle->content_size) + return GNOME_VFS_ERROR_EOF; - // fixme: change this to min math function - if (num_bytes > myth_handle->content_size - myth_handle->bytes_read) - bytes_to_read = myth_handle->content_size - myth_handle->bytes_read; - else - bytes_to_read = num_bytes; + // fixme: change this to min math function + if (myth_handle->content_size > 0 && num_bytes > ( myth_handle->content_size - myth_handle->bytes_read )) + bytes_to_read = myth_handle->content_size - myth_handle->bytes_read; + else + bytes_to_read = num_bytes; - /* Loop sending the Myth File Transfer request: - * Retry whilst authentication fails and we supply it. */ - //if (myth_handle->buffer_remain < MYTHTV_BUFFER_SIZE) { - if ( bytes_to_read > myth_handle->buffer_remain ) { - GByteArray *tmp_buffer = g_byte_array_new(); + /* Loop sending the Myth File Transfer request: + * Retry whilst authentication fails and we supply it. */ + //if (myth_handle->buffer_remain < MYTHTV_BUFFER_SIZE) { + if ( ( myth_handle->buffer_remain = myth_handle->buffer->len ) < MYTHTV_BUFFER_SIZE ) { + GByteArray *tmp_buffer = g_byte_array_new(); - printf ("XXXXXXXXXXXXXX Pedindo %d %d\n", MYTHTV_BUFFER_SIZE, myth_handle->buffer_remain); + printf ("XXXXXXXXXXXXXX Pedindo %d %d\n", MYTHTV_BUFFER_SIZE, myth_handle->buffer_remain); - gint len = gmyth_file_transfer_read (myth_handle->file_transfer, - tmp_buffer, MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain, TRUE); + gint len = gmyth_file_transfer_read (myth_handle->file_transfer, + tmp_buffer, MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain, TRUE); - if (len < 0) { - g_byte_array_free (tmp_buffer, TRUE); - g_warning ("Fail to read bytes"); + if (len < 0) { + g_byte_array_free (tmp_buffer, TRUE); + g_warning ("Fail to read bytes"); return GNOME_VFS_ERROR_IO; - } /*else if (len == 0) { - g_byte_array_free (tmp_buffer, TRUE); - g_warning ("End of file probably achieved"); - return GNOME_VFS_ERROR_EOF; - }*/ + } /*else if (len == 0) { + g_byte_array_free (tmp_buffer, TRUE); + g_warning ("End of file probably achieved"); + return GNOME_VFS_ERROR_EOF; + }*/ + + myth_handle->buffer = g_byte_array_append (myth_handle->buffer, + tmp_buffer->data, len); + + myth_handle->buffer_remain += len; - myth_handle->buffer = g_byte_array_append (myth_handle->buffer, - tmp_buffer->data, len); - - myth_handle->buffer_remain += len; - - g_byte_array_free (tmp_buffer, TRUE); - tmp_buffer = NULL; + g_byte_array_free (tmp_buffer, TRUE); + tmp_buffer = NULL; } bytes_to_read = (bytes_to_read > myth_handle->buffer_remain) ? myth_handle->buffer_remain : bytes_to_read; @@ -281,12 +285,13 @@ GnomeVFSContext *context) { GMythFileTransfer *file_transfer = NULL; - GMythLiveTV *livetv = NULL; + //GMythLiveTV *livetv = NULL; GMythBackendInfo *backend_info = NULL; GMythURI *gmyth_uri = NULL; gboolean is_livetv = FALSE; gboolean ret = TRUE; + file_info->size = (GnomeVFSFileSize) - 1; /* Creates and fills out the backend info structure */ backend_info = gmyth_backend_info_new_with_uri ( gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) ); @@ -312,8 +317,9 @@ /* Connect to the backend */ if ( gmyth_uri != NULL && is_livetv == TRUE ) { - livetv = gmyth_livetv_new (); - + /* + livetv = gmyth_livetv_new (); + gint channel_num = gmyth_uri_get_channel_num( gmyth_uri ); if ( channel_num != -1 ) { @@ -329,11 +335,12 @@ } } - file_transfer = gmyth_livetv_create_file_transfer (livetv); + file_transfer = gmyth_livetv_create_file_transfer (livetv); if (NULL == file_transfer) { ret = FALSE; } + */ } else { @@ -356,16 +363,24 @@ return GNOME_VFS_ERROR_NOT_OPEN; } */ - if ( file_transfer->filesize < 0 && is_livetv ) - file_info->size = gmyth_recorder_get_file_position( livetv->recorder ); - else + if ( is_livetv ) + { + /* + GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info ( GMythRecorder *recorder ) + if ( file_transfer->filesize < 0 ) + file_info->size = gmyth_recorder_get_file_position( livetv->recorder ); + else + */ + file_info->size =(GnomeVFSFileSize) - 1; + } else { file_info->size = gmyth_file_transfer_get_filesize (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; g_object_unref (file_transfer); - g_object_unref (livetv); + //g_object_unref (livetv); g_object_unref (backend_info); return GNOME_VFS_OK;