[svn r357] Improvements on the do_read GnomeVFS callbacks.
1.1 --- a/libgnomevfs2-mythtv/modules/mythtv-method.c Mon Feb 12 15:22:28 2007 +0000
1.2 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c Mon Feb 12 17:56:41 2007 +0000
1.3 @@ -40,7 +40,7 @@
1.4 #define MYTHTV_VERSION_DEFAULT 30
1.5 #define MYTHTV_TRANSFER_MAX_WAITS 100
1.6
1.7 -#define MYTHTV_BUFFER_SIZE 1024*80
1.8 +#define MYTHTV_BUFFER_SIZE 1024*64
1.9 #define MYTHTV_MAX_VFS_BUFFER_SIZE 4096
1.10 #define MYTHTV_MAX_REQUEST_SIZE 1024*64
1.11
1.12 @@ -214,7 +214,8 @@
1.13
1.14 *bytes_read = 0;
1.15
1.16 - g_debug ("XXXXXXXXXX Requested %llu bytes...\n", (guint64)num_bytes);
1.17 + g_debug ("XXXXXXXXXX Requested %llu bytes (remains %d bytes on buffer...)\n",
1.18 + (guint64)num_bytes, myth_handle->buffer->len );
1.19
1.20 if ( !myth_handle->is_livetv && ( myth_handle->bytes_read >= myth_handle->content_size ) )
1.21 return GNOME_VFS_ERROR_EOF;
1.22 @@ -227,31 +228,37 @@
1.23 bytes_to_read = num_bytes;
1.24
1.25 /* Loop sending the Myth File Transfer request:
1.26 - * Retry whilst authentication fails and we supply it. */
1.27 - //if (myth_handle->buffer_remain < MYTHTV_BUFFER_SIZE) {
1.28 - if ( ( myth_handle->buffer_remain = myth_handle->buffer->len ) < MYTHTV_MAX_VFS_BUFFER_SIZE ) {
1.29 - gint buffer_size = MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain;
1.30 + * Retry whilst authentication fails and we supply it. */
1.31 + /* if (myth_handle->buffer_remain < MYTHTV_BUFFER_SIZE) { */
1.32 + if ( ( myth_handle->buffer_remain = myth_handle->buffer->len ) < MYTHTV_MAX_VFS_BUFFER_SIZE )
1.33 + {
1.34 + gint buffer_size;
1.35
1.36 - /* resize buffer length request to no more than MYTHTV_MAX_REQUEST_SIZE */
1.37 - if ( buffer_size > MYTHTV_MAX_REQUEST_SIZE )
1.38 - buffer_size = MYTHTV_MAX_REQUEST_SIZE;
1.39 -
1.40 - GByteArray *tmp_buffer = g_byte_array_new();
1.41 -
1.42 - g_debug ("XXXXXXXXXX Pedindo %d (restam apenas %d no buffer)\n", buffer_size, myth_handle->buffer_remain);
1.43 -
1.44 - gint len = gmyth_file_transfer_read (myth_handle->file_transfer,
1.45 - tmp_buffer, buffer_size, TRUE);
1.46 -
1.47 - if (!myth_handle->is_livetv && len < 0) {
1.48 - g_byte_array_free (tmp_buffer, TRUE);
1.49 - g_debug ("Fail to read bytes");
1.50 - return GNOME_VFS_ERROR_IO;
1.51 - } /*else if (len == 0) {
1.52 + while ( MYTHTV_BUFFER_SIZE != myth_handle->buffer_remain ) {
1.53 +
1.54 + /* resize buffer length request to no more than MYTHTV_MAX_REQUEST_SIZE */
1.55 + if ( ( MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain ) <= MYTHTV_MAX_REQUEST_SIZE )
1.56 + buffer_size = MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain;
1.57 + else
1.58 + buffer_size = MYTHTV_MAX_REQUEST_SIZE;
1.59 +
1.60 + GByteArray *tmp_buffer = g_byte_array_new();
1.61 +
1.62 + g_debug ("XXXXXXXXXX Asking %d bytes (there is %d bytes in the buffer)\n",
1.63 + buffer_size, myth_handle->buffer_remain);
1.64 +
1.65 + gint len = gmyth_file_transfer_read (myth_handle->file_transfer,
1.66 + tmp_buffer, buffer_size, TRUE);
1.67 +
1.68 + if (!myth_handle->is_livetv && len < 0) {
1.69 g_byte_array_free (tmp_buffer, TRUE);
1.70 - g_warning ("End of file probably achieved");
1.71 - return GNOME_VFS_ERROR_EOF;
1.72 - }*/
1.73 + g_debug ("Fail to read bytes");
1.74 + return GNOME_VFS_ERROR_IO;
1.75 + } /*else if (len == 0) {
1.76 + g_byte_array_free (tmp_buffer, TRUE);
1.77 + g_warning ("End of file probably achieved");
1.78 + return GNOME_VFS_ERROR_EOF;
1.79 + }*/
1.80
1.81 myth_handle->buffer = g_byte_array_append (myth_handle->buffer,
1.82 tmp_buffer->data, len);
1.83 @@ -263,21 +270,25 @@
1.84 g_byte_array_free (tmp_buffer, TRUE);
1.85 tmp_buffer = NULL;
1.86 }
1.87 - } /* if - got from the network, or not */
1.88 -
1.89 - bytes_to_read = (bytes_to_read > myth_handle->buffer_remain) ? myth_handle->buffer_remain : bytes_to_read;
1.90 - /* gets the first buffer_size bytes from the byte array buffer variable */
1.91 + } /* while - iterates until fills the internal buffer */
1.92 +
1.93 + } /* if - got from the network, or not */
1.94 +
1.95 + bytes_to_read = (bytes_to_read > myth_handle->buffer_remain) ? myth_handle->buffer_remain : bytes_to_read;
1.96 + /* gets the first buffer_size bytes from the byte array buffer variable */
1.97
1.98 - g_memmove (buffer, myth_handle->buffer->data, bytes_to_read);
1.99 + g_memmove (buffer, myth_handle->buffer->data, bytes_to_read);
1.100
1.101 - myth_handle->bytes_read += bytes_to_read;
1.102 - myth_handle->buffer_remain -= bytes_to_read;
1.103 + myth_handle->bytes_read += bytes_to_read;
1.104 + myth_handle->buffer_remain -= bytes_to_read;
1.105
1.106 - /* flushs the newly buffer got from byte array */
1.107 - myth_handle->buffer = g_byte_array_remove_range (myth_handle->buffer, 0, bytes_to_read);
1.108 - *bytes_read = bytes_to_read;
1.109 -
1.110 - return GNOME_VFS_OK;
1.111 + /* flushs the newly buffer got from byte array */
1.112 + myth_handle->buffer = g_byte_array_remove_range (myth_handle->buffer, 0, bytes_to_read);
1.113 + g_debug ("Got from %llu bytes from internal buffer. (there are %d bytes in the buffer, from a total of %llu dispatched.)\n",
1.114 + bytes_to_read, myth_handle->buffer_remain, myth_handle->bytes_read );
1.115 + *bytes_read = bytes_to_read;
1.116 +
1.117 + return GNOME_VFS_OK;
1.118 }
1.119
1.120 static GnomeVFSResult
1.121 @@ -402,13 +413,15 @@
1.122 }
1.123
1.124 // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
1.125 + /*
1.126 res = gmyth_recorder_spawntv ( recorder,
1.127 gmyth_tvchain_get_id(tvchain) );
1.128 if (!res) {
1.129 g_warning ("[%s] Fail while spawn tv\n", __FUNCTION__);
1.130 res = FALSE;
1.131 goto error;
1.132 - }
1.133 + }
1.134 + */
1.135
1.136 //gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri );
1.137