# HG changeset patch # User rosfran # Date 1163776828 0 # Node ID ae73b4837eedb662ae5db38206cf20c04b85f67a # Parent e594fc21deef37b8da9394f66b6ff5fa5e022ecd [svn r94] Changed to use GstAdapter, instead of using the guint pointer. diff -r e594fc21deef -r ae73b4837eed gst-plugins-mythtv/src/gstmythtvsrc.c --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Fri Nov 17 14:46:38 2006 +0000 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Fri Nov 17 15:20:28 2006 +0000 @@ -42,12 +42,12 @@ //( 32*1024 ) /* 4*1024 ??? */ -#define MAX_READ_SIZE 12*1024 +#define MAX_READ_SIZE 6*1024 //( 32*1024 ) #define GST_FLOW_ERROR_NO_DATA -101 -#define INTERNAL_BUFFER_SIZE 18*1024 +#define INTERNAL_BUFFER_SIZE 28*1024 /* stablish a maximum iteration value to the IS_RECORDING message */ static guint wait_to_transfer = 0; @@ -113,7 +113,7 @@ static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event); static gint do_read_request_response (GstMythtvSrc * src, guint64 offset, - guint size, gint8 **data_ptr); + guint size, guint8 **data_ptr); GStaticRecMutex th_mutex = G_STATIC_REC_MUTEX_INIT; @@ -328,7 +328,7 @@ } static gint -do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, gint8 **data_ptr) +do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, guint8 **data_ptr) { gint read = 0; guint sizetoread = size; @@ -572,20 +572,23 @@ goto change_progchain; //g_static_rec_mutex_lock( &th_mutex ); + g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size ); while ( src->adapter != NULL && ( ( adapter_size = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) && --max_adapter_rep > 0 ) { - g_print ( "[%s] %d - Waiting for read_ahead task...\n", __FUNCTION__, max_adapter_rep ); + g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size ); //GST_TASK_WAIT( src->th_read_ahead ); } + g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size ); + //gst_task_pause( src->th_read_ahead ); //g_static_rec_mutex_unlock( &th_mutex ); /* just get from the adapter, no network effort... */ - if ( adapter_size > 0 ) + if ( FALSE ) { //g_static_rec_mutex_lock( &th_mutex ); @@ -597,6 +600,7 @@ //g_static_rec_mutex_unlock( &th_mutex ); } else { + GstBuffer *buffer; guint size = (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; g_print ( "[%s]\t\tCreate: buffer_offset: %d, buffer_remain: %d\n", __FUNCTION__, @@ -615,12 +619,14 @@ goto done; } - if (src->buffer_remain < MAX_READ_SIZE) { - gint8 *tmp_buffer = g_malloc0( INTERNAL_BUFFER_SIZE ); // FIXME: DON'T ALLOC EVERY TIME + if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) { + //gint8 *tmp_buffer = g_malloc0( INTERNAL_BUFFER_SIZE ); // FIXME: DON'T ALLOC EVERY TIME + buffer = gst_buffer_new_and_alloc( INTERNAL_BUFFER_SIZE - src->buffer_remain ); - memcpy (tmp_buffer, src->buffer + src->buffer_offset, src->buffer_remain); + //g_memmove (tmp_buffer, src->buffer + src->buffer_offset, src->buffer_remain); + //g_memmove( tmp_buffer, src->buffer, src->buffer_remain ); - read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &tmp_buffer ); + read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) ); if (G_UNLIKELY (read < 0)) { if ( src->live_tv ) @@ -632,24 +638,30 @@ if ( G_UNLIKELY (src->update_prog_chain) ) goto change_progchain; + gst_adapter_push( src->adapter, buffer ); + //len = gmyth_file_transfer_read( src->file_transfer, // tmp_buffer + src->buffer_remain, INTERNAL_BUFFER_SIZE - src->buffer_remain, TRUE ); // fixme: handle eos // fixme: can I deallocate the previous buffer here? - g_memmove( src->buffer + src->buffer_remain, tmp_buffer, read); + //g_memmove( src->buffer, tmp_buffer, INTERNAL_BUFFER_SIZE ); src->buffer_offset = 0; src->buffer_remain = src->buffer_remain + read; - // g_free( tmp_buffer ); + //g_free( tmp_buffer ); } + size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; + + buffer = gst_adapter_take_buffer( src->adapter, size ); + g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain ); - GST_BUFFER_SIZE (*outbuf) = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; + GST_BUFFER_SIZE (*outbuf) = size; GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) ); GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf ); - g_memmove( GST_BUFFER_DATA( (*outbuf) ), src->buffer + src->buffer_offset, GST_BUFFER_SIZE(*outbuf) ); + g_memmove( GST_BUFFER_DATA( (*outbuf) ), GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(*outbuf) ); GST_BUFFER_OFFSET (*outbuf) = src->read_offset; GST_BUFFER_OFFSET_END (*outbuf) = src->read_offset + GST_BUFFER_SIZE (*outbuf); @@ -660,6 +672,9 @@ src->bytes_read += GST_BUFFER_SIZE (*outbuf); g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) ); + //gst_adapter_flush( src->adapter, size ); + gst_buffer_unref( buffer ); + g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\ "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, src->read_offset, src->content_size );