# HG changeset patch # User rosfran # Date 1164206267 0 # Node ID f4be69980934d11ab6fa7ee236e9452df0aa7756 # Parent 404189e73f8e32849c488c3d3f9127a5ae56034d [svn r101] Changed it back to GstPushSrc. diff -r 404189e73f8e -r f4be69980934 gst-plugins-mythtv/src/gstmythtvsrc.c --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Wed Nov 22 12:55:16 2006 +0000 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Wed Nov 22 14:37:47 2006 +0000 @@ -83,10 +83,10 @@ static void gst_mythtv_src_finalize (GObject * gobject); -static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset, - guint size, GstBuffer ** outbuf); +//static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset, +// guint size, GstBuffer ** outbuf); -//static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf ); +static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf ); static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc); static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc); @@ -96,7 +96,7 @@ //static void gst_mythtv_src_get_times (GstBaseSrc * src, GstBuffer * buffer, // GstClockTime * start, GstClockTime * end); -//static gboolean gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment ); +static gboolean gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment ); static gboolean gst_mythtv_src_next_program_chain ( GstMythtvSrc *src ); @@ -137,8 +137,8 @@ //GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc, // GST_TYPE_BASE_SRC, _urihandler_init) -GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc, - GST_TYPE_BASE_SRC, _urihandler_init) +GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc, + GST_TYPE_PUSH_SRC, _urihandler_init) static void gst_mythtv_src_base_init (gpointer g_class) @@ -158,12 +158,12 @@ gst_mythtv_src_class_init (GstMythtvSrcClass * klass) { GObjectClass *gobject_class; - //GstPushSrcClass *gstpushsrc_class; + GstPushSrcClass *gstpushsrc_class; GstBaseSrcClass *gstbasesrc_class; gobject_class = (GObjectClass *) klass; gstbasesrc_class = (GstBaseSrcClass *) klass; - //gstpushsrc_class = (GstPushSrcClass *) klass; + gstpushsrc_class = (GstPushSrcClass *) klass; gobject_class->set_property = gst_mythtv_src_set_property; gobject_class->get_property = gst_mythtv_src_get_property; @@ -235,8 +235,8 @@ //gstbasesrc_class->get_times = gst_mythtv_src_get_times; - //gstbasesrc_class->do_seek = gst_mythtv_src_do_seek; - gstbasesrc_class->create = gst_mythtv_src_create; + gstbasesrc_class->do_seek = gst_mythtv_src_do_seek; + gstpushsrc_class->create = gst_mythtv_src_create; GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV Client Source"); @@ -281,9 +281,6 @@ this->th_mutex = NULL; - //this->srcpad = gst_pad_new_from_static_template (&srctemplate, "src"); - //gst_element_add_pad (GST_ELEMENT (this), this->srcpad); - gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES ); //gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE ); @@ -327,6 +324,11 @@ if (this->user_agent) { g_free (this->user_agent); } + + if ( this->bytes_queue ) { + g_byte_array_free( this->bytes_queue, TRUE ); + this->bytes_queue = NULL; + } G_OBJECT_CLASS (parent_class)->finalize (gobject); } @@ -343,7 +345,7 @@ * Retry whilst authentication fails and we supply it. */ gint len = 0; - //while ( sizetoread > 0 ) { + while ( sizetoread > 0 ) { len = gmyth_file_transfer_read( src->file_transfer, *data_ptr + offset + read, sizetoread, TRUE ); @@ -365,20 +367,7 @@ if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */ src->update_prog_chain = TRUE; goto done; - } /*if ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) { - src->update_prog_chain = TRUE; - if ( src->enable_timing_position ) { - gint64 size_tmp = 0; -get_file_pos: - size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer ); - if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) - src->content_size = size_tmp; - else if ( size_tmp > 0 ) - goto get_file_pos; - g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n", - __FUNCTION__, size_tmp ); - } - }*/ + } goto done; } @@ -386,7 +375,7 @@ if ( read == sizetoread ) goto done; - //} + } if ( read < 0 && !src->live_tv ) goto eos; @@ -401,15 +390,12 @@ return read; } -#if 0 static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf ) { GstMythtvSrc *src; GstFlowReturn ret = GST_FLOW_OK; gint read = -1; - gint adapter_size = 0; - guint max_adapter_rep = 1; src = GST_MYTHTV_SRC ( psrc ); @@ -420,34 +406,17 @@ goto change_progchain; //g_static_rec_mutex_lock( &th_mutex ); - g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size ); - - /* 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] offset = %llu, size = %d...\n", __FUNCTION__, + src->read_offset, 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 ); + /* 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 ); - if (G_UNLIKELY (ret != GST_FLOW_OK)) { - if ( src->live_tv ) - goto change_progchain; - else - goto done; - } - - if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) { - - ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), - src->read_offset /*GST_BUFFER_OFFSET_NONE*/, INTERNAL_BUFFER_SIZE - src->buffer_remain, - GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), &buffer ); - - read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) ); + read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(buffer) ); if (G_UNLIKELY (read < 0)) { if ( src->live_tv ) @@ -458,33 +427,41 @@ if ( G_UNLIKELY (src->update_prog_chain) ) goto change_progchain; - - gst_adapter_push( src->adapter, buffer ); + + src->bytes_queue = g_byte_array_append( src->bytes_queue, buffer, read ); 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 ); - + } - if ( now == -1 ) - now = gst_element_get_base_time( GST_ELEMENT( src ) ); - //else - // now; + guint buffer_size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; + + /* Create the buffer. */ + ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), + src->read_offset, buffer_size, + GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf ); - size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; + if (G_UNLIKELY (ret != GST_FLOW_OK)) { + if ( src->live_tv ) + goto change_progchain; + else + goto done; + } + + /* gets the first buffer_size bytes from the byte array buffer variable */ + guint8 *buf = g_memdup( src->bytes_queue->data, buffer_size ); - buffer = gst_adapter_take_buffer( src->adapter, size ); + g_print( "[%s] read from network? %s!, buffer_remain = %d\n", __FUNCTION__, + read == -1 ? "NO, got from buffer" : "YES, go see the backend's log file", src->buffer_remain ); - g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain ); - - GST_BUFFER_SIZE (*outbuf) = size; + GST_BUFFER_SIZE (*outbuf) = buffer_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_TIMESTAMP( *outbuf ) = now; + g_memmove( GST_BUFFER_DATA( (*outbuf) ), buf, GST_BUFFER_SIZE(*outbuf) ); GST_BUFFER_OFFSET (*outbuf) = src->read_offset; GST_BUFFER_OFFSET_END (*outbuf) = src->read_offset + GST_BUFFER_SIZE (*outbuf); @@ -493,17 +470,14 @@ 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 ); + + /* flushs the newly buffer got from byte array */ + src->bytes_queue = g_byte_array_remove_range( src->bytes_queue, 0, buffer_size ); 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; done: @@ -546,8 +520,8 @@ } } -#endif +#if 0 static GstFlowReturn gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf ) { @@ -566,15 +540,12 @@ goto change_progchain; //g_static_rec_mutex_lock( &th_mutex ); - g_print ( "[%s] %d - Adapter size = (%d), offset = %llu, size = %d...\n", __FUNCTION__, - max_adapter_rep, adapter_size, offset, size ); - - /* just get from the adapter, no network effort... */ - //GstBuffer *buffer = NULL; + g_print ( "[%s] offset = %llu, size = %d...\n", __FUNCTION__, offset, size ); g_print ( "[%s]\t\tCreate: buffer_remain: %d\n", __FUNCTION__, (gint) src->buffer_remain); + /* 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 ); @@ -631,15 +602,14 @@ 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) ); - + + /* flushs the newly buffer got from byte array */ src->bytes_queue = g_byte_array_remove_range( src->bytes_queue, 0, buffer_size ); 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; done: @@ -682,6 +652,7 @@ } } +#endif gint64 gst_mythtv_src_get_position ( GstMythtvSrc* src ) @@ -709,7 +680,6 @@ } -#if 0 static gboolean gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment ) { @@ -750,13 +720,7 @@ } } - /* - g_static_rec_mutex_lock( &th_mutex ); - GST_TASK_SIGNAL( src->th_read_ahead ); - - g_static_rec_mutex_unlock( &th_mutex ); - */ done: return ret; @@ -785,7 +749,6 @@ } } -#endif #if 0 static void @@ -920,15 +883,12 @@ src->do_start = FALSE; - //if ( src->live_tv ) { - src->bytes_queue = g_byte_array_new(); + src->bytes_queue = g_byte_array_sized_new( INTERNAL_BUFFER_SIZE ); //src->th_read_ahead = gst_task_create( (GstTaskFunction)gst_mythtv_src_read_ahead, src ); //gst_task_set_lock( src->th_read_ahead, &th_mutex ); //gst_task_start( src->th_read_ahead ); - // } src->buffer_remain = 0; - done: return TRUE; @@ -1075,6 +1035,12 @@ src->read_offset = 0; + if ( src->bytes_queue != NULL ) { + g_byte_array_free( src->bytes_queue, TRUE ); + } + + src->bytes_queue = g_byte_array_sized_new( INTERNAL_BUFFER_SIZE ); + done: src->update_prog_chain = FALSE; @@ -1109,15 +1075,11 @@ g_print( "[%s] Differs from previous content size: %d (max.: %d)\n", __FUNCTION__, abs( src->content_size - src->prev_content_size ), GMYTHTV_TRANSFER_MAX_BUFFER ); - if ( src->live_tv ) - //src->content_size = (guint64)-1; + if ( src->live_tv ) { ret = FALSE; - else if (src->content_size == -1) { - //ret= FALSE; - } else if ( src->live_tv && ( abs( src->content_size - src->bytes_read ) < + } else if ( src->live_tv && src->enable_timing_position && ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) ) { //g_static_mutex_lock( &update_size_mutex ); - //GST_OBJECT_LOCK(src); gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer ); if ( new_offset > 0 && new_offset > src->content_size ) { @@ -1126,24 +1088,6 @@ src->update_prog_chain = TRUE; } - if ( src->enable_timing_position ) { - gint64 size_tmp = 0; - if (src->live_tv == TRUE) { -get_file_pos: - g_usleep( 5 ); - size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer ); - if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) - src->content_size = size_tmp; - else if ( size_tmp > 0 ) - goto get_file_pos; - g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n", - __FUNCTION__, size_tmp ); - } - } - - src->prev_content_size = src->content_size; - - //GST_OBJECT_UNLOCK(src); //g_static_mutex_unlock( &update_size_mutex ); } @@ -1272,7 +1216,7 @@ static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src ) { - return FALSE; + return TRUE; } static gboolean @@ -1444,7 +1388,7 @@ return; } - static void +static void gst_mythtv_src_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { diff -r 404189e73f8e -r f4be69980934 gst-plugins-mythtv/src/gstmythtvsrc.h --- a/gst-plugins-mythtv/src/gstmythtvsrc.h Wed Nov 22 12:55:16 2006 +0000 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.h Wed Nov 22 14:37:47 2006 +0000 @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include @@ -48,7 +48,7 @@ } GstMythtvState; struct _GstMythtvSrc { - GstBaseSrc element; + GstPushSrc element; /* MythFileTransfer */ GMythFileTransfer *file_transfer; @@ -73,7 +73,6 @@ guint64 bytes_read; gint64 read_offset; - gint64 adapter_offset; /* added by melunko (buffer cache) */ gint buffer_remain; @@ -98,7 +97,6 @@ GstCaps *mythtv_caps; GstPad *sinkpad; - GstPad *srcpad; GstTask *th_read_ahead; @@ -113,7 +111,7 @@ }; struct _GstMythtvSrcClass { - GstBaseSrcClass parent_class; + GstPushSrcClass parent_class; }; GType gst_mythtv_src_get_type (void);