diff -r d2d5fe1c3997 -r 07951674b0c0 gst-plugins-mythtv/src/gstmythtvsrc.c --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Tue Nov 28 00:54:53 2006 +0000 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Thu Nov 30 15:20:37 2006 +0000 @@ -61,7 +61,7 @@ #define REQUEST_MAX_SIZE 64*1024 -#define INTERNAL_BUFFER_SIZE 200*1024 +#define INTERNAL_BUFFER_SIZE 90*1024 /* stablish a maximum iteration value to the IS_RECORDING message */ static guint wait_to_transfer = 0; @@ -348,7 +348,7 @@ { gint read = 0; guint sizetoread = size; - guint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS; + gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS; GST_LOG_OBJECT( src, "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread ); @@ -382,7 +382,8 @@ goto done; } - } + } else if ( len == 0 ) + goto done; if ( read == sizetoread ) goto done; @@ -423,46 +424,40 @@ (gint) src->buffer_remain, src->bytes_queue->len ); /* just get from the byte array, no network effort... */ - if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE ) { + if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE && + abs( src->content_size - src->bytes_read ) > MAX_READ_SIZE ) { //( ( INTERNAL_BUFFER_SIZE - src->buffer_remain ) >= REQUEST_MAX_SIZE ) ) { GByteArray *buffer = NULL; - guint amount_to_fill = ( INTERNAL_BUFFER_SIZE - src->buffer_remain ); - guint buffer_size_inter = 0; + guint buffer_size_inter = ( INTERNAL_BUFFER_SIZE - src->buffer_remain ); + if ( buffer_size_inter > REQUEST_MAX_SIZE ) + buffer_size_inter = REQUEST_MAX_SIZE; - //do { - if ( amount_to_fill < REQUEST_MAX_SIZE ) - buffer_size_inter = amount_to_fill; - else - buffer_size_inter = REQUEST_MAX_SIZE; + buffer = g_byte_array_new(); - buffer = g_byte_array_new(); - - read = do_read_request_response( src, buffer_size_inter, buffer ); - - if (G_UNLIKELY (read < 0)) { - if ( src->live_tv ) - goto change_progchain; - else - goto read_error; - } - - if ( G_UNLIKELY (src->update_prog_chain) ) - goto change_progchain; - - src->bytes_queue = g_byte_array_append( src->bytes_queue, g_memdup( buffer->data, read ), read ); - if ( read > buffer_size_inter ) - GST_WARNING_OBJECT( src, "[%s] INCREASED buffer size! Backend sent more than we ask him... (%d)\n", - __FUNCTION__, abs( read - buffer_size_inter ) ); - - src->buffer_remain += read; - amount_to_fill -= read; - - //} while ( amount_to_fill > 0 ); - - if ( buffer != NULL ) { - g_byte_array_free( buffer, TRUE ); - buffer = NULL; - } + read = do_read_request_response( src, buffer_size_inter, buffer ); + + if (G_UNLIKELY (read < 0)) { + if ( src->live_tv ) + goto change_progchain; + else + goto read_error; + } else if (G_UNLIKELY (read == 0) && !src->live_tv ) + goto eos; + + if ( G_UNLIKELY (src->update_prog_chain) ) + goto change_progchain; + + src->bytes_queue = g_byte_array_append( src->bytes_queue, g_memdup( buffer->data, read ), read ); + if ( read > buffer_size_inter ) + GST_WARNING_OBJECT( src, "\n\n\n[%s]\t\tINCREASED buffer size! Backend sent more than we ask him... (%d)\n\n\n", + __FUNCTION__, abs( read - buffer_size_inter ) ); + + src->buffer_remain += read; + + if ( buffer != NULL ) { + g_byte_array_free( buffer, TRUE ); + buffer = NULL; + } GST_DEBUG_OBJECT( src, "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\ "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, @@ -510,7 +505,11 @@ "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) ); - return ret; + GST_DEBUG_OBJECT( src, "[%s]\tCONTENT_SIZE = %llu, BYTES_READ = %llu.\n", __FUNCTION__, + src->content_size, src->bytes_read ); + + if ( G_UNLIKELY (src->eos) || ( !src->live_tv && ( src->bytes_read >= src->content_size ) ) ) + goto eos; done: {