diff -r f4be69980934 -r ba9bf90e7c4b gst-plugins-mythtv/src/gstmythtvsrc.c --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Wed Nov 22 14:37:47 2006 +0000 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Fri Nov 24 01:51:47 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,