diff -r b2b0169716dc -r 2a552f003c4e gst-plugins-mythtv/src/gstmythtvsrc.c --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Fri Oct 27 00:22:59 2006 +0100 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Fri Oct 27 23:42:34 2006 +0100 @@ -33,7 +33,7 @@ #define GST_GMYTHTV_ID_NUM 1 #define GMYTHTV_VERSION_DEFAULT 30 - + #define GMYTHTV_TRANSFER_MAX_WAITS 100 #define GMYTHTV_TRANSFER_MAX_BUFFER 512*1024 @@ -229,6 +229,8 @@ this->content_size = 0; this->read_offset = 0; + this->content_size_last = 0; + this->live_tv = FALSE; this->enable_timing_position = FALSE; @@ -299,9 +301,9 @@ GST_OBJECT_LOCK(src); while ( sizetoread > 0 ) { - - len = gmyth_file_transfer_read( src->file_transfer, - GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE ); + + len = gmyth_file_transfer_read( src->file_transfer, + GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE ); if ( len > 0 ) { read += len; @@ -309,79 +311,79 @@ } else if ( len <= 0 ) { - + if ( src->live_tv == FALSE ) { - goto done; + goto done; } else { - if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */ - src->update_prog_chain = TRUE; - if ( gst_mythtv_src_next_program_chain ( src ) ) - continue; - else - goto done; - } else - if ( src->content_size <= - ( src->read_offset + size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) { - src->update_prog_chain = TRUE; - if ( src->enable_timing_position ) { - gint64 size_tmp = 0; - if (src->live_tv == TRUE) { - 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 ); - } - } else { - gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer ); - if ( new_offset > 0 ) { - if ( src->content_size < new_offset ) { - src->content_size = new_offset; - } - } else { - src->update_prog_chain = TRUE; - } - } - goto done; - } + if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */ + src->update_prog_chain = TRUE; + if ( gst_mythtv_src_next_program_chain ( src ) ) + continue; + else + goto done; + } else + if ( src->content_size <= + ( src->read_offset + size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) { + src->update_prog_chain = TRUE; + if ( src->enable_timing_position ) { + gint64 size_tmp = 0; + if (src->live_tv == TRUE) { +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 ); } + } else { + gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer ); + if ( new_offset > 0 ) { + if ( src->content_size < new_offset ) { + src->content_size = new_offset; + } + } else { + src->update_prog_chain = TRUE; + } + } + goto done; + } + } - } - + } + if ( read == sizetoread ) break; } - + if ( read > 0 ) { - src->read_offset += read; + src->read_offset += read; src->bytes_read += 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 ); - - GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read; - GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset; - GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read; - - g_print( "Stopping: [%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) ); - + + 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 ); + + GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read; + GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset; + GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read; + + 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) ); + } else if ( !src->live_tv ) - goto eos; - + goto eos; + goto done; eos: src->eos = TRUE; - + done: GST_OBJECT_UNLOCK(src); @@ -405,7 +407,7 @@ GST_OBJECT_LOCK(src); if (G_UNLIKELY (src->read_offset != offset)) { - gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset, SEEK_SET); + gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset - src->content_size_last, 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)) { @@ -430,9 +432,7 @@ if (G_UNLIKELY (ret != GST_FLOW_OK)) goto done; - //g_static_mutex_lock( &update_size_mutex ); read = do_read_request_response ( src, src->read_offset, size, outbuf ); - //g_static_mutex_unlock( &update_size_mutex ); if (G_UNLIKELY (src->update_prog_chain) ) goto change_progchain; @@ -492,20 +492,20 @@ g_static_mutex_lock( &update_size_mutex ); if ( src->do_start ) { - if ( src->enable_timing_position ) { - gint64 size_tmp = 0; - if (src->live_tv == TRUE) { - get_file_pos: - g_usleep( 50 ); - 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 ); - } - } + if ( src->enable_timing_position ) { + gint64 size_tmp = 0; + if (src->live_tv == TRUE) { +get_file_pos: + g_usleep( 50 ); + 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 ); + } + } } g_static_mutex_unlock( &update_size_mutex ); @@ -516,16 +516,17 @@ { gint64 size_tmp = 0; + guint max_tries = 3; if (src->live_tv == TRUE) { get_file_pos: - g_usleep( 50 ); + g_usleep( 10 ); 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; + src->content_size = size_tmp; + else if ( size_tmp > 0 && --max_tries > 0 ) + goto get_file_pos; g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n", - __FUNCTION__, size_tmp ); + __FUNCTION__, size_tmp ); } return src->content_size; @@ -639,27 +640,25 @@ GString *chain_id_local = NULL; gboolean ret = TRUE; - + if ( !src->live_tv ) - goto init_failed; - + goto init_failed; + + src->update_prog_chain = FALSE; + if (src->file_transfer) { g_object_unref (src->file_transfer); src->file_transfer = NULL; } - + if (src->uri_name) { g_free (src->uri_name); } - + if ( src->live_tv ) { - if ( src->update_prog_chain ) - { - if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) { - ret = FALSE; - goto init_failed; - } - src->update_prog_chain = FALSE; + if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) { + ret = FALSE; + goto init_failed; } /* set up the uri variable */ src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str ); @@ -685,12 +684,12 @@ if ( src->live_tv == TRUE && ret == TRUE ) { /* loop finished, set the max tries variable to zero again... */ wait_to_transfer = 0; - - g_usleep( 500 ); + + g_usleep( 200 ); while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && - ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) ) - g_usleep( 100 ); + ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) ) + g_usleep( 1000 ); } /* sets the FileTransfer instance connection (video/audio download) */ @@ -703,18 +702,23 @@ #endif goto begin_req_failed; } - + src->content_size_last = src->content_size; + +#if 0 if ( src->content_size < src->file_transfer->filesize ) { - src->content_size = src->file_transfer->filesize; + src->content_size = src->file_transfer->filesize; } else { - gint64 pos = gst_mythtv_src_get_position(src); - if ( pos > src->file_transfer->filesize ) - src->content_size = pos; + //gint64 pos = gst_mythtv_src_get_position(src); + //if ( pos > src->file_transfer->filesize ) + // src->content_size = pos; + } - - src->read_offset = 0; - - src->update_prog_chain = FALSE; +#endif + + src->content_size = src->file_transfer->filesize; + //src->read_offset = 0; + + //src->update_prog_chain = FALSE; return TRUE; @@ -734,7 +738,7 @@ (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name)); return FALSE; } - + } #if 0 @@ -813,36 +817,36 @@ if (src->content_size <= 0) { ret= FALSE; - } else { - //g_static_mutex_lock( &update_size_mutex ); - //GST_OBJECT_LOCK(src); + } else if ( src->live_tv ) { + //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 ) { - if ( src->content_size < new_offset ) { - src->content_size = new_offset; - } - } else { - if ( src->live_tv ) - 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 ); - } - } - //GST_OBJECT_UNLOCK(src); - //g_static_mutex_unlock( &update_size_mutex ); + gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer ); + if ( new_offset > 0 ) { + if ( src->content_size < new_offset ) { + src->content_size = new_offset; + } + } else { + if ( src->live_tv ) + 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 ); + } + } + //GST_OBJECT_UNLOCK(src); + //g_static_mutex_unlock( &update_size_mutex ); } *size = src->content_size; @@ -887,25 +891,25 @@ case GST_EVENT_FLUSH_START: //src->eos = FALSE; g_print( "\n\n\n[%s]\t\tGot FLUSH_START event!!!\n\n\n", __FUNCTION__ ); - cont_size = gst_mythtv_src_get_position (src); - if ( !src->live_tv ) { - if ( cont_size > src->content_size ) { - src->content_size = cont_size; - src->eos = FALSE; - } else { - src->eos = TRUE; - gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL ); - gst_element_set_locked_state ( GST_ELEMENT (src), FALSE ); - } - } else { - if ( cont_size <= 0 ) { - src->update_prog_chain = TRUE; - src->eos = TRUE; - src->unique_setup = FALSE; - src->do_start = TRUE; - } - } - break; + cont_size = gst_mythtv_src_get_position (src); + if ( !src->live_tv ) { + if ( cont_size > src->content_size ) { + src->content_size = cont_size; + src->eos = FALSE; + } else { + src->eos = TRUE; + gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL ); + gst_element_set_locked_state ( GST_ELEMENT (src), FALSE ); + } + } else { + if ( cont_size <= 0 ) { + src->update_prog_chain = TRUE; + src->eos = TRUE; + src->unique_setup = FALSE; + src->do_start = TRUE; + } + } + break; case GST_EVENT_FLUSH_STOP: src->do_start = TRUE; src->eos = FALSE; @@ -915,18 +919,19 @@ #endif case GST_EVENT_EOS: g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ ); - cont_size = gst_mythtv_src_get_position (src); - if ( !src->live_tv ) { - if ( cont_size > src->content_size ) { - src->content_size = cont_size; - src->eos = FALSE; - } else { - src->eos = TRUE; - gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL ); - gst_element_set_locked_state ( GST_ELEMENT (src), FALSE ); - } - } else - src->eos = TRUE; + + if ( src->live_tv ) { + cont_size = gst_mythtv_src_get_position (src); + if ( cont_size > src->content_size ) { + src->content_size = cont_size; + src->eos = FALSE; + } else { + src->eos = TRUE; + gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL ); + gst_element_set_locked_state ( GST_ELEMENT (src), FALSE ); + } + } else + src->eos = TRUE; break; #if 0 case GST_EVENT_NEWSEGMENT: @@ -970,6 +975,59 @@ return TRUE; } +#if 0 +static gboolean +gst_nuv_demux_sink_activate (GstPad * sinkpad) +{ + gboolean res = TRUE; + GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad)); + + if (gst_pad_check_pull_range (sinkpad)) { + nuv->mode = 0; + nuv->adapter = NULL; + res = gst_pad_activate_pull (sinkpad, TRUE); + } else { + nuv->mode = 1; + nuv->adapter = gst_adapter_new (); + res = gst_pad_activate_push (sinkpad, TRUE); + } + + g_object_unref (nuv); + return res; +} + +static gboolean +gst_nuv_demux_sink_activate_pull (GstPad * sinkpad, gboolean active) +{ + GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad)); + + if (active) { + gst_pad_start_task (sinkpad, (GstTaskFunction) gst_nuv_demux_loop, sinkpad); + } else { + gst_pad_stop_task (sinkpad); + } + gst_object_unref (nuv); + + return TRUE; +} + +static GstFlowReturn +gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf) +{ + GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad)); + + gst_adapter_push (nuv->adapter, buf); + + return gst_nuv_demux_play (pad); +} + +static void +gst_nuv_demux_loop (GstPad * pad) +{ + gst_nuv_demux_play (pad); +} +#endif + static GstStateChangeReturn gst_mythtv_src_change_state (GstElement * element, GstStateChange transition) { @@ -978,12 +1036,8 @@ switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: - src->content_size = 0; - src->read_offset = 0; - src->bytes_read = 0; src->do_start = TRUE; src->unique_setup = FALSE; - src->eos = TRUE; break; case GST_STATE_CHANGE_READY_TO_PAUSED: case GST_STATE_CHANGE_PAUSED_TO_PLAYING: @@ -992,18 +1046,22 @@ default: break; } - - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + + ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); if (ret == GST_STATE_CHANGE_FAILURE) return ret; switch (transition) { case GST_STATE_CHANGE_READY_TO_NULL: break; + case GST_STATE_CHANGE_PLAYING_TO_PAUSED: case GST_STATE_CHANGE_PAUSED_TO_READY: - if ( src->live_tv && src->update_prog_chain ) - gst_mythtv_src_next_program_chain( src ); - break; + if ( src->live_tv && src->update_prog_chain ) { + src->read_offset = 0; + src->bytes_read = 0; + gst_mythtv_src_next_program_chain( src ); + } + break; default: break; }