# HG changeset patch # User rosfran # Date 1164226906 0 # Node ID 4f7789e3bfd4c14b9431a6edba5917ca77ebf603 # Parent cf4a26332b8cb24f24278324f496c107153d7584 [svn r103] Changed the way buffers are received from the MythTV backend; size can increase. diff -r cf4a26332b8c -r 4f7789e3bfd4 gst-plugins-mythtv/src/gstmythtvsrc.c --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Wed Nov 22 19:53:52 2006 +0000 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Wed Nov 22 20:21:46 2006 +0000 @@ -40,6 +40,8 @@ #define GMYTHTV_TRANSFER_MAX_WAITS 100 +#define GMYTHTV_TRANSFER_MAX_RESENDS 5 + #define GMYTHTV_TRANSFER_MAX_BUFFER 128*1024 //( 32*1024 ) @@ -114,8 +116,7 @@ static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event); -static gint do_read_request_response (GstMythtvSrc * src, guint64 offset, - guint size, guint8 **data_ptr); +static gint do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr); GStaticRecMutex th_mutex = G_STATIC_REC_MUTEX_INIT; @@ -334,10 +335,13 @@ } static gint -do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, guint8 **data_ptr) +do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr) { gint read = 0; guint sizetoread = size; + guint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS; + + //*data_ptr = g_malloc0( size ); g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread ); @@ -345,10 +349,10 @@ * Retry whilst authentication fails and we supply it. */ gint len = 0; - while ( sizetoread > 0 ) { + while ( sizetoread == size && --max_iters > 0) { len = gmyth_file_transfer_read( src->file_transfer, - *data_ptr + offset + read, sizetoread, TRUE ); + data_ptr, sizetoread, TRUE ); if ( len > 0 ) { read += len; @@ -377,7 +381,7 @@ goto done; } - if ( read < 0 && !src->live_tv ) + if ( ( read < 0 && !src->live_tv ) || max_iters == 0 ) goto eos; goto done; @@ -386,7 +390,6 @@ src->eos = TRUE; done: - return read; } @@ -414,9 +417,10 @@ /* just get from the byte array, no network effort... */ if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE ) { - guint8 *buffer = g_malloc0( INTERNAL_BUFFER_SIZE - src->buffer_remain ); + guint buffer_size_inter = INTERNAL_BUFFER_SIZE - src->buffer_remain; + GByteArray *buffer = g_byte_array_new(); - read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(buffer) ); + read = do_read_request_response( src, buffer_size_inter, buffer ); if (G_UNLIKELY (read < 0)) { if ( src->live_tv ) @@ -428,9 +432,14 @@ if ( G_UNLIKELY (src->update_prog_chain) ) goto change_progchain; - src->bytes_queue = g_byte_array_append( src->bytes_queue, buffer, read ); + src->bytes_queue = g_byte_array_append( src->bytes_queue, g_memdup( buffer->data, read ), read ); src->buffer_remain = src->buffer_remain + read; + + if ( buffer != NULL ) { + g_byte_array_free( buffer, TRUE ); + buffer = NULL; + } g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\ "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,