[svn r103] Changed the way buffers are received from the MythTV backend; size can increase.
1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Wed Nov 22 19:53:52 2006 +0000
1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Wed Nov 22 20:21:46 2006 +0000
1.3 @@ -40,6 +40,8 @@
1.4
1.5 #define GMYTHTV_TRANSFER_MAX_WAITS 100
1.6
1.7 +#define GMYTHTV_TRANSFER_MAX_RESENDS 5
1.8 +
1.9 #define GMYTHTV_TRANSFER_MAX_BUFFER 128*1024
1.10 //( 32*1024 )
1.11
1.12 @@ -114,8 +116,7 @@
1.13
1.14 static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
1.15
1.16 -static gint do_read_request_response (GstMythtvSrc * src, guint64 offset,
1.17 - guint size, guint8 **data_ptr);
1.18 +static gint do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr);
1.19
1.20 GStaticRecMutex th_mutex = G_STATIC_REC_MUTEX_INIT;
1.21
1.22 @@ -334,10 +335,13 @@
1.23 }
1.24
1.25 static gint
1.26 -do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, guint8 **data_ptr)
1.27 +do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr)
1.28 {
1.29 gint read = 0;
1.30 guint sizetoread = size;
1.31 + guint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
1.32 +
1.33 + //*data_ptr = g_malloc0( size );
1.34
1.35 g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread );
1.36
1.37 @@ -345,10 +349,10 @@
1.38 * Retry whilst authentication fails and we supply it. */
1.39 gint len = 0;
1.40
1.41 - while ( sizetoread > 0 ) {
1.42 + while ( sizetoread == size && --max_iters > 0) {
1.43
1.44 len = gmyth_file_transfer_read( src->file_transfer,
1.45 - *data_ptr + offset + read, sizetoread, TRUE );
1.46 + data_ptr, sizetoread, TRUE );
1.47
1.48 if ( len > 0 ) {
1.49 read += len;
1.50 @@ -377,7 +381,7 @@
1.51 goto done;
1.52 }
1.53
1.54 - if ( read < 0 && !src->live_tv )
1.55 + if ( ( read < 0 && !src->live_tv ) || max_iters == 0 )
1.56 goto eos;
1.57
1.58 goto done;
1.59 @@ -386,7 +390,6 @@
1.60 src->eos = TRUE;
1.61
1.62 done:
1.63 -
1.64 return read;
1.65 }
1.66
1.67 @@ -414,9 +417,10 @@
1.68
1.69 /* just get from the byte array, no network effort... */
1.70 if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE ) {
1.71 - guint8 *buffer = g_malloc0( INTERNAL_BUFFER_SIZE - src->buffer_remain );
1.72 + guint buffer_size_inter = INTERNAL_BUFFER_SIZE - src->buffer_remain;
1.73 + GByteArray *buffer = g_byte_array_new();
1.74
1.75 - read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(buffer) );
1.76 + read = do_read_request_response( src, buffer_size_inter, buffer );
1.77
1.78 if (G_UNLIKELY (read < 0)) {
1.79 if ( src->live_tv )
1.80 @@ -428,9 +432,14 @@
1.81 if ( G_UNLIKELY (src->update_prog_chain) )
1.82 goto change_progchain;
1.83
1.84 - src->bytes_queue = g_byte_array_append( src->bytes_queue, buffer, read );
1.85 + src->bytes_queue = g_byte_array_append( src->bytes_queue, g_memdup( buffer->data, read ), read );
1.86
1.87 src->buffer_remain = src->buffer_remain + read;
1.88 +
1.89 + if ( buffer != NULL ) {
1.90 + g_byte_array_free( buffer, TRUE );
1.91 + buffer = NULL;
1.92 + }
1.93
1.94 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
1.95 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,