# HG changeset patch # User rosfran # Date 1163788787 0 # Node ID 51d01302867466c1209c9d1a77a10242abf43cb1 # Parent da398435732b3b973c983446fa537e4dc25b9c99 [svn r96] Removed guint8 * buffer, changed to a GstAdapter. diff -r da398435732b -r 51d013028674 gst-plugins-mythtv/src/gstmythtvsrc.c --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Fri Nov 17 18:18:24 2006 +0000 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Fri Nov 17 18:39:47 2006 +0000 @@ -30,7 +30,7 @@ GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug); #define GST_CAT_DEFAULT mythtvsrc_debug -#define GST_GMYTHTV_ID_NUM 1 +#define GST_GMYTHTV_ID_NUM 1 #define GST_GMYTHTV_CHANNEL_NUM 1000 @@ -42,12 +42,12 @@ //( 32*1024 ) /* 4*1024 ??? */ -#define MAX_READ_SIZE 4*1024 +#define MAX_READ_SIZE 6*1024 //( 32*1024 ) #define GST_FLOW_ERROR_NO_DATA -101 -#define INTERNAL_BUFFER_SIZE 28*1024 +#define INTERNAL_BUFFER_SIZE 30*1024 /* stablish a maximum iteration value to the IS_RECORDING message */ static guint wait_to_transfer = 0; @@ -570,121 +570,86 @@ goto eos; if ( G_UNLIKELY (src->update_prog_chain) ) 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 - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size ); - //GST_TASK_WAIT( src->th_read_ahead ); + /* just get from the adapter, no network effort... */ + GstBuffer *buffer; + guint size = (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; + + g_print ( "[%s]\t\tCreate: buffer_remain: %d\n", __FUNCTION__, + (gint) src->buffer_remain); + + /* Create the buffer. */ + ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), + src->read_offset /*GST_BUFFER_OFFSET_NONE*/, size, + GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf ); + + if (G_UNLIKELY (ret != GST_FLOW_OK)) { + if ( src->live_tv ) + goto change_progchain; + else + goto done; } - g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size ); + if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) { - //gst_task_pause( src->th_read_ahead ); + buffer = gst_buffer_new_and_alloc( INTERNAL_BUFFER_SIZE - src->buffer_remain ); - //g_static_rec_mutex_unlock( &th_mutex ); + read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) ); - /* just get from the adapter, no network effort... */ - if ( FALSE ) - { - //g_static_rec_mutex_lock( &th_mutex ); - - *outbuf = gst_adapter_take_buffer( src->adapter, adapter_size ); - // src->read_offset += size; - read = adapter_size; - - gst_adapter_flush( src->adapter, adapter_size ); - //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__, - (gint) src->buffer_offset, - (gint) src->buffer_remain); - - /* Create the buffer. */ - ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), - src->read_offset /*GST_BUFFER_OFFSET_NONE*/, size, - GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf ); - - if (G_UNLIKELY (ret != GST_FLOW_OK)) { + if (G_UNLIKELY (read < 0)) { if ( src->live_tv ) goto change_progchain; else - goto done; + goto read_error; } - if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) { - - buffer = gst_buffer_new_and_alloc( INTERNAL_BUFFER_SIZE - src->buffer_remain ); + if ( G_UNLIKELY (src->update_prog_chain) ) + goto change_progchain; - read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) ); + gst_adapter_push( src->adapter, buffer ); - if (G_UNLIKELY (read < 0)) { - if ( src->live_tv ) - goto change_progchain; - else - goto read_error; - } + src->buffer_remain = src->buffer_remain + read; - if ( G_UNLIKELY (src->update_prog_chain) ) - goto change_progchain; - - gst_adapter_push( src->adapter, buffer ); - - src->buffer_offset = 0; - src->buffer_remain = src->buffer_remain + read; - - 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 ); - - } - - 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) = 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) ), 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); - - src->buffer_offset += GST_BUFFER_SIZE (*outbuf); - src->buffer_remain -= GST_BUFFER_SIZE (*outbuf); - - src->read_offset += GST_BUFFER_SIZE (*outbuf); - 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( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\ - "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), - GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) ); - - /* just get from the adapter, no network effort... */ + 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 ); } + 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) = 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) ), 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); + + src->buffer_remain -= GST_BUFFER_SIZE (*outbuf); + + src->read_offset += GST_BUFFER_SIZE (*outbuf); + 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( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\ + "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), + GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) ); + + /* just get from the adapter, no network effort... */ + + return ret; - //g_static_rec_mutex_lock( &th_mutex ); - - //GST_TASK_SIGNAL( src->th_read_ahead ); - - //g_static_rec_mutex_unlock( &th_mutex ); - done: { const gchar *reason = gst_flow_get_name (ret); @@ -761,11 +726,6 @@ gboolean ret = TRUE; g_print( "[%s]DO Seek called! (start = %lld, stop = %lld)\n", __FUNCTION__, segment->start, segment->stop ); - //g_static_rec_mutex_lock( &th_mutex ); - - //GST_TASK_WAIT( src->th_read_ahead ); - - //g_static_rec_mutex_unlock( &th_mutex ); if ( segment->format == GST_FORMAT_TIME ) { @@ -792,19 +752,18 @@ src->read_offset = new_offset; - //gst_segment_set_seek( segment, segment->rate, GST_FORMAT_BYTES, GST_SEEK_FLAG_NONE, - //GST_SEEK_TYPE_CUR, src->read_offset, GST_SEEK_TYPE_CUR, segment->stop, &ret ); - if ( ret == FALSE ) { g_print( "[%s] Failed to set the SEEK on segment!\n", __FUNCTION__ ); } } - //g_static_rec_mutex_lock( &th_mutex ); + /* + g_static_rec_mutex_lock( &th_mutex ); - //GST_TASK_SIGNAL( src->th_read_ahead ); + GST_TASK_SIGNAL( src->th_read_ahead ); - //g_static_rec_mutex_unlock( &th_mutex ); + g_static_rec_mutex_unlock( &th_mutex ); + */ done: return ret; @@ -970,11 +929,6 @@ //gst_task_set_lock( src->th_read_ahead, &th_mutex ); //gst_task_start( src->th_read_ahead ); // } - //gst_pad_push_event ( GST_BASE_SRC_PAD (bsrc), - // gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, src->content_size, 0 ) ); - - src->buffer = g_malloc0 (INTERNAL_BUFFER_SIZE); - src->buffer_offset = 0; src->buffer_remain = 0; diff -r da398435732b -r 51d013028674 gst-plugins-mythtv/src/gstmythtvsrc.h --- a/gst-plugins-mythtv/src/gstmythtvsrc.h Fri Nov 17 18:18:24 2006 +0000 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.h Fri Nov 17 18:39:47 2006 +0000 @@ -75,11 +75,7 @@ gint64 read_offset; gint64 adapter_offset; - //guint64 file_size; - /* added by melunko */ - guint8* buffer; - - gint buffer_offset; + /* added by melunko (buffer cache) */ gint buffer_remain; gboolean eos;