# HG changeset patch # User rosfran # Date 1171303001 0 # Node ID f7b40eb795c2895bdb8137acf38062f6260dddc7 # Parent ce009d76ffb5f80c60764129f77fd731eece9ad9 [svn r357] Improvements on the do_read GnomeVFS callbacks. diff -r ce009d76ffb5 -r f7b40eb795c2 libgnomevfs2-mythtv/modules/mythtv-method.c --- a/libgnomevfs2-mythtv/modules/mythtv-method.c Mon Feb 12 15:22:28 2007 +0000 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c Mon Feb 12 17:56:41 2007 +0000 @@ -40,7 +40,7 @@ #define MYTHTV_VERSION_DEFAULT 30 #define MYTHTV_TRANSFER_MAX_WAITS 100 -#define MYTHTV_BUFFER_SIZE 1024*80 +#define MYTHTV_BUFFER_SIZE 1024*64 #define MYTHTV_MAX_VFS_BUFFER_SIZE 4096 #define MYTHTV_MAX_REQUEST_SIZE 1024*64 @@ -214,7 +214,8 @@ *bytes_read = 0; - g_debug ("XXXXXXXXXX Requested %llu bytes...\n", (guint64)num_bytes); + g_debug ("XXXXXXXXXX Requested %llu bytes (remains %d bytes on buffer...)\n", + (guint64)num_bytes, myth_handle->buffer->len ); if ( !myth_handle->is_livetv && ( myth_handle->bytes_read >= myth_handle->content_size ) ) return GNOME_VFS_ERROR_EOF; @@ -227,31 +228,37 @@ 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 ( ( myth_handle->buffer_remain = myth_handle->buffer->len ) < MYTHTV_MAX_VFS_BUFFER_SIZE ) { - gint buffer_size = MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain; + * 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_MAX_VFS_BUFFER_SIZE ) + { + gint buffer_size; - /* resize buffer length request to no more than MYTHTV_MAX_REQUEST_SIZE */ - if ( buffer_size > MYTHTV_MAX_REQUEST_SIZE ) - buffer_size = MYTHTV_MAX_REQUEST_SIZE; - - GByteArray *tmp_buffer = g_byte_array_new(); - - g_debug ("XXXXXXXXXX Pedindo %d (restam apenas %d no buffer)\n", buffer_size, myth_handle->buffer_remain); - - gint len = gmyth_file_transfer_read (myth_handle->file_transfer, - tmp_buffer, buffer_size, TRUE); - - if (!myth_handle->is_livetv && len < 0) { - g_byte_array_free (tmp_buffer, TRUE); - g_debug ("Fail to read bytes"); - return GNOME_VFS_ERROR_IO; - } /*else if (len == 0) { + while ( MYTHTV_BUFFER_SIZE != myth_handle->buffer_remain ) { + + /* resize buffer length request to no more than MYTHTV_MAX_REQUEST_SIZE */ + if ( ( MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain ) <= MYTHTV_MAX_REQUEST_SIZE ) + buffer_size = MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain; + else + buffer_size = MYTHTV_MAX_REQUEST_SIZE; + + GByteArray *tmp_buffer = g_byte_array_new(); + + g_debug ("XXXXXXXXXX Asking %d bytes (there is %d bytes in the buffer)\n", + buffer_size, myth_handle->buffer_remain); + + gint len = gmyth_file_transfer_read (myth_handle->file_transfer, + tmp_buffer, buffer_size, TRUE); + + if (!myth_handle->is_livetv && len < 0) { g_byte_array_free (tmp_buffer, TRUE); - g_warning ("End of file probably achieved"); - return GNOME_VFS_ERROR_EOF; - }*/ + g_debug ("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; + }*/ myth_handle->buffer = g_byte_array_append (myth_handle->buffer, tmp_buffer->data, len); @@ -263,21 +270,25 @@ g_byte_array_free (tmp_buffer, TRUE); tmp_buffer = NULL; } - } /* if - got from the network, or not */ - - bytes_to_read = (bytes_to_read > myth_handle->buffer_remain) ? myth_handle->buffer_remain : bytes_to_read; - /* gets the first buffer_size bytes from the byte array buffer variable */ + } /* while - iterates until fills the internal buffer */ + + } /* if - got from the network, or not */ + + bytes_to_read = (bytes_to_read > myth_handle->buffer_remain) ? myth_handle->buffer_remain : bytes_to_read; + /* gets the first buffer_size bytes from the byte array buffer variable */ - g_memmove (buffer, myth_handle->buffer->data, bytes_to_read); + g_memmove (buffer, myth_handle->buffer->data, bytes_to_read); - myth_handle->bytes_read += bytes_to_read; - myth_handle->buffer_remain -= bytes_to_read; + myth_handle->bytes_read += bytes_to_read; + myth_handle->buffer_remain -= bytes_to_read; - /* flushs the newly buffer got from byte array */ - myth_handle->buffer = g_byte_array_remove_range (myth_handle->buffer, 0, bytes_to_read); - *bytes_read = bytes_to_read; - - return GNOME_VFS_OK; + /* flushs the newly buffer got from byte array */ + myth_handle->buffer = g_byte_array_remove_range (myth_handle->buffer, 0, bytes_to_read); + g_debug ("Got from %llu bytes from internal buffer. (there are %d bytes in the buffer, from a total of %llu dispatched.)\n", + bytes_to_read, myth_handle->buffer_remain, myth_handle->bytes_read ); + *bytes_read = bytes_to_read; + + return GNOME_VFS_OK; } static GnomeVFSResult @@ -402,13 +413,15 @@ } // 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_warning ("[%s] Fail while spawn tv\n", __FUNCTION__); res = FALSE; goto error; - } + } + */ //gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri );