diff -r 4ba74b706853 -r ac7e49c234d8 gst-plugins-mythtv/src/gstmythtvsrc.c --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Mon Nov 06 23:12:21 2006 +0000 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Fri Nov 10 19:35:39 2006 +0000 @@ -38,7 +38,7 @@ #define GMYTHTV_TRANSFER_MAX_WAITS 100 -#define GMYTHTV_TRANSFER_MAX_BUFFER 64*1024 +#define GMYTHTV_TRANSFER_MAX_BUFFER 4*1024 //( 32*1024 ) /* 4*1024 ??? */ @@ -61,10 +61,12 @@ GST_PAD_ALWAYS, GST_STATIC_CAPS ("video/x-nuv") ); +/* static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, - GST_PAD_ALWAYS, + GST_PAD_SOMETIMES, GST_STATIC_CAPS ("video/x-nuv") ); +*/ enum { @@ -104,7 +106,7 @@ static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data); -static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event); +//static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event); //static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query ); static gint do_read_request_response (GstMythtvSrc *src, guint64 offset, @@ -207,7 +209,7 @@ (gobject_class, PROP_GMYTHTV_CHANNEL_NUM, g_param_spec_int ("mythtv-channel", "mythtv-channel", "Change MythTV channel number", - 0, 200, GST_GMYTHTV_CHANNEL_NUM, G_PARAM_READWRITE)); + 0, 99999, GST_GMYTHTV_CHANNEL_NUM, G_PARAM_READWRITE)); #ifndef GST_DISABLE_GST_DEBUG g_object_class_install_property @@ -263,8 +265,8 @@ this->adapter = NULL; - this->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink"); - gst_element_add_pad (GST_ELEMENT (this), this->sinkpad); + //this->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink"); + //gst_element_add_pad (GST_ELEMENT (this), this->sinkpad); /* this->srcpad = gst_pad_new_from_static_template (&srctemplate, "src"); @@ -275,8 +277,8 @@ gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE ); - gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)), - gst_mythtv_src_handle_event ); + // gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)), + // gst_mythtv_src_handle_event ); /* gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)), gst_mythtv_src_query ); @@ -327,9 +329,6 @@ * Retry whilst authentication fails and we supply it. */ gint len = 0; - /* max number of buffer resend interactions */ - //guint max_tries = 3; - GST_OBJECT_LOCK(src); while ( sizetoread > 0 ) { @@ -353,7 +352,7 @@ { if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */ src->update_prog_chain = TRUE; - goto done; + goto done; } else if ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) { src->update_prog_chain = TRUE; @@ -435,7 +434,7 @@ GST_OBJECT_LOCK(src); if (G_UNLIKELY (src->read_offset != offset)) { - gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset - src->content_size_last, SEEK_SET); + gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset, SEEK_SET); g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n", __FUNCTION__, src->read_offset, new_offset ); if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) { @@ -521,11 +520,10 @@ { gint64 size_tmp = 0; - guint max_tries = 3; - if (src->live_tv == TRUE && ( abs( src->content_size - src->prev_content_size ) < - GMYTHTV_TRANSFER_MAX_BUFFER ) ) { - /* sets the last content size amount before it can be updated */ - src->prev_content_size = src->content_size; + guint max_tries = 2; + if (src->live_tv == TRUE && ( abs( src->content_size - src->bytes_read ) < + GMYTHTV_TRANSFER_MAX_BUFFER ) ) { + get_file_pos: g_usleep( 10 ); size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer ); @@ -535,6 +533,8 @@ goto get_file_pos; g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n", __FUNCTION__, size_tmp ); + /* sets the last content size amount before it can be updated */ + src->prev_content_size = src->content_size; } return src->content_size; @@ -551,8 +551,8 @@ gboolean ret = TRUE; - if ( !src->do_start ) - goto done; + if ( G_UNLIKELY (src->update_prog_chain) ) + goto change_progchain; if (src->unique_setup == FALSE) { src->unique_setup = TRUE; @@ -617,10 +617,10 @@ src->content_size = src->file_transfer->filesize; + src->do_start = FALSE; + GST_OBJECT_UNLOCK(src); - src->do_start = FALSE; - done: return TRUE; @@ -640,6 +640,21 @@ (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name)); return FALSE; } +change_progchain: + { + GST_ELEMENT_ERROR (src, RESOURCE, READ, + (NULL), ("Seek failed, go to the next program info... (%s)", + src->uri_name)); + // go to the next program chain + src->unique_setup = FALSE; + src->update_prog_chain = TRUE; + + //GST_OBJECT_LOCK(src); + gst_mythtv_src_next_program_chain( src ); + //GST_OBJECT_UNLOCK(src); + + return TRUE; + } } /* create a new socket for connecting to the next program chain */ @@ -730,16 +745,13 @@ #endif src->content_size = src->file_transfer->filesize; - while ( src->content_size < GMYTHTV_TRANSFER_MAX_BUFFER*4 ) + while ( src->content_size < GMYTHTV_TRANSFER_MAX_BUFFER*4 ) src->content_size = gst_mythtv_src_get_position( src ); src->read_offset = 0; src->update_prog_chain = FALSE; - gst_pad_push_event ( src->sinkpad, - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, src->content_size, 0 ) ); - done: return TRUE; @@ -904,6 +916,7 @@ return TRUE; } +#if 0 static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event) { @@ -992,6 +1005,7 @@ return gst_pad_event_default (pad, event); } +#endif static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src ) @@ -1034,7 +1048,7 @@ goto read_error; } - if ( GST_FLOW_OK != ( ret = gst_pad_push ( src->sinkpad, buf ) ) ) { + if ( GST_FLOW_OK != ( ret = gst_pad_push ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), buf ) ) ) { goto done; } @@ -1120,7 +1134,7 @@ GST_ELEMENT_ERROR (src, STREAM, FAILED, ("Internal data stream error."), ("streaming stopped, reason %s", gst_flow_get_name (res))); - gst_pad_send_event( src->sinkpad, gst_event_new_eos() ); + gst_pad_send_event( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), gst_event_new_eos() ); } return res; } @@ -1129,7 +1143,7 @@ static GstStateChangeReturn gst_mythtv_src_change_state (GstElement * element, GstStateChange transition) { - GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; //GST_STATE_CHANGE_NO_PREROLL; + GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;//GST_STATE_CHANGE_NO_PREROLL; GstMythtvSrc *src = GST_MYTHTV_SRC (element); switch (transition) { @@ -1152,23 +1166,21 @@ switch (transition) { case GST_STATE_CHANGE_READY_TO_NULL: g_print( "[%s] READY to NULL called!\n", __FUNCTION__ ); - if ( src->live_tv && src->update_prog_chain ) { - gst_pad_push_event ( src->sinkpad, - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, src->content_size, 0 ) ); - gst_element_set_state ( GST_ELEMENT (src), GST_STATE_READY ); - } break; case GST_STATE_CHANGE_PLAYING_TO_PAUSED: g_print( "[%s] PLAYING to PAUSED called!\n", __FUNCTION__ ); case GST_STATE_CHANGE_PAUSED_TO_READY: g_print( "[%s] PAUSED to READY called!\n", __FUNCTION__ ); if ( src->live_tv && src->update_prog_chain ) { + GstPad *pad_peer; + gst_pad_push_event ( pad_peer = gst_pad_get_peer( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) ), + gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0 ) ); src->read_offset = 0; src->bytes_read = 0; src->unique_setup = FALSE; - //GST_OBJECT_LOCK( src ); + GST_OBJECT_LOCK( src ); gst_mythtv_src_next_program_chain( src ); - //GST_OBJECT_UNLOCK( src ); + GST_OBJECT_UNLOCK( src ); } break; default: