diff -r 324e04989738 -r 686549eb5657 gst-plugins-mythtv/src/gstmythtvsrc.c --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Mon Oct 23 14:36:26 2006 +0100 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Mon Oct 23 16:02:15 2006 +0100 @@ -18,8 +18,8 @@ #endif #include "gstmythtvsrc.h" -#include "myth_file_transfer.h" -#include "myth_livetv.h" +#include "gmyth_file_transfer.h" +#include "gmyth_livetv.h" #include #include @@ -30,13 +30,13 @@ GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug); #define GST_CAT_DEFAULT mythtvsrc_debug -#define GST_MYTHTV_ID_NUM 1 +#define GST_GMYTHTV_ID_NUM 1 -#define MYTHTV_VERSION_DEFAULT 30 +#define GMYTHTV_VERSION_DEFAULT 30 -#define MYTHTV_TRANSFER_MAX_WAITS 100 +#define GMYTHTV_TRANSFER_MAX_WAITS 100 -#define MYTHTV_TRANSFER_MAX_BUFFER 1024*1024 +#define GMYTHTV_TRANSFER_MAX_BUFFER 1024*1024 //( 32*1024 ) /* 4*1024 ??? */ @@ -70,12 +70,12 @@ PROP_LOCATION, PROP_URI, #ifndef GST_DISABLE_GST_DEBUG - PROP_MYTHTV_DBG, + PROP_GMYTHTV_DBG, #endif - PROP_MYTHTV_VERSION, - PROP_MYTHTV_LIVE, - PROP_MYTHTV_LIVEID, - PROP_MYTHTV_LIVE_CHAINID + PROP_GMYTHTV_VERSION, + PROP_GMYTHTV_LIVE, + PROP_GMYTHTV_LIVEID, + PROP_GMYTHTV_LIVE_CHAINID }; static void gst_mythtv_src_finalize (GObject * gobject); @@ -168,32 +168,32 @@ "", G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_MYTHTV_VERSION, + (gobject_class, PROP_GMYTHTV_VERSION, g_param_spec_int ("mythtv-version", "mythtv-version", "Change Myth TV version", 26, 30, 26, G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_MYTHTV_LIVEID, + (gobject_class, PROP_GMYTHTV_LIVEID, g_param_spec_int ("mythtv-live-id", "mythtv-live-id", "Change Myth TV version", - 0, 200, GST_MYTHTV_ID_NUM, G_PARAM_READWRITE)); + 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_MYTHTV_LIVE_CHAINID, + (gobject_class, PROP_GMYTHTV_LIVE_CHAINID, g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid", "Sets the Myth TV chain ID (from TV Chain)", "", G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_MYTHTV_LIVE, + (gobject_class, PROP_GMYTHTV_LIVE, g_param_spec_boolean ("mythtv-live", "mythtv-live", "Enable MythTV Live TV content streaming", FALSE, G_PARAM_READWRITE)); #ifndef GST_DISABLE_GST_DEBUG g_object_class_install_property - (gobject_class, PROP_MYTHTV_DBG, + (gobject_class, PROP_GMYTHTV_DBG, g_param_spec_boolean ("mythtv-debug", "mythtv-debug", "Enable MythTV debug messages", FALSE, G_PARAM_READWRITE)); @@ -218,7 +218,7 @@ this->unique_setup = FALSE; - this->mythtv_version = MYTHTV_VERSION_DEFAULT; + this->mythtv_version = GMYTHTV_VERSION_DEFAULT; this->bytes_read = 0; @@ -293,7 +293,7 @@ while ( sizetoread > 0 ) { - len = myth_file_transfer_read( src->file_transfer, + len = gmyth_file_transfer_read( src->file_transfer, GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE ); if ( len > 0 ) { @@ -305,25 +305,29 @@ goto done; } else if ( /*src->content_size >= src->read_offset && abs ( src->content_size - src->read_offset ) <= 1024 ) ||*/ - ( src->content_size <= ( src->read_offset + size + MYTHTV_TRANSFER_MAX_BUFFER ) ) ) + ( src->content_size <= ( src->read_offset + size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) ) { #if ENABLE_TIMING_POSITION == 1 - guint64 size_tmp = 0; + gint64 size_tmp = 0; if (src->live_tv == TRUE) { get_file_pos: - size_tmp = myth_file_transfer_get_file_position( src->file_transfer ); - if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) ) + 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 + else if ( size_tmp > 0 ) goto get_file_pos; - g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n", + g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n", __FUNCTION__, size_tmp ); } #else - guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer ); - if ( src->content_size < new_offset ) { - src->content_size = new_offset; - } + 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; + } #endif goto done; } @@ -377,17 +381,19 @@ /* The caller should know the number of bytes and not read beyond EOS. */ if (G_UNLIKELY (src->eos)) goto eos; + if ( G_UNLIKELY (src->update_prog_chain) ) + goto change_progchain; //GST_OBJECT_LOCK(src); if (G_UNLIKELY (src->read_offset != offset)) { - guint64 new_offset = myth_file_transfer_seek(src->file_transfer, offset, SEEK_SET); - g_print( "[%s] SRC Offset = %llu, NEW actual backend SEEK Offset = %llu.\n", + 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)) { { //GST_OBJECT_UNLOCK(src); - goto seek_failed; + goto change_progchain; } src->read_offset = offset; @@ -407,6 +413,9 @@ 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; + if (G_UNLIKELY (read < 0) || *outbuf == NULL) { //if ( src->live_tv ) // goto done; @@ -443,7 +452,7 @@ src->uri_name)); return GST_FLOW_ERROR; } -seek_failed: +change_progchain: { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("Seek failed, go to the next program info... (%i, %s)", read, @@ -470,16 +479,16 @@ if ( src->do_start ) { #if ENABLE_TIMING_POSITION == 1 - guint64 size_tmp = 0; + gint64 size_tmp = 0; if (src->live_tv == TRUE) { get_file_pos: g_usleep( 50 ); - size_tmp = myth_file_transfer_get_file_position( src->file_transfer ); - if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) ) + 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 + else if ( size_tmp > 0 ) goto get_file_pos; - g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n", + g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n", __FUNCTION__, size_tmp ); } #endif @@ -494,16 +503,16 @@ if ( src->do_start ) { #if ENABLE_TIMING_POSITION == 1 - guint64 size_tmp = 0; + gint64 size_tmp = 0; if (src->live_tv == TRUE) { get_file_pos: g_usleep( 50 ); - size_tmp = myth_file_transfer_get_file_position( src->file_transfer ); - if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) ) + 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 + else if ( size_tmp > 0 ) goto get_file_pos; - g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n", + g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n", __FUNCTION__, size_tmp ); } #endif @@ -532,8 +541,8 @@ GST_OBJECT_LOCK(src); if ( src->live_tv ) { - src->spawn_livetv = myth_livetv_new( ); - if ( myth_livetv_setup( src->spawn_livetv ) == FALSE ) { + src->spawn_livetv = gmyth_livetv_new( ); + if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) { ret = FALSE; goto init_failed; } @@ -548,7 +557,7 @@ g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name ); } - src->file_transfer = myth_file_transfer_new( src->live_tv_id, + src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, g_string_new( src->uri_name ), -1, src->mythtv_version ); if ( src->file_transfer == NULL ) { @@ -558,19 +567,19 @@ } /* sets the Playback monitor connection */ - ret = myth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv ); + ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv ); if ( src->live_tv == TRUE && ret == TRUE ) { /* loop finished, set the max tries variable to zero again... */ wait_to_transfer = 0; - while ( wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS && ( myth_file_transfer_is_recording( src->file_transfer ) == FALSE - /*|| ( myth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) ) + while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE + /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) ) g_usleep( 100 ); } /* sets the FileTransfer instance connection (video/audio download) */ - ret = myth_file_transfer_setup( &(src->file_transfer), src->live_tv ); + ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv ); if ( ret == FALSE ) { GST_OBJECT_UNLOCK(src); @@ -624,7 +633,7 @@ guint64 size = 0; - mythtv = GST_MYTHTV_SRC( GST_PAD_PARENT (pad) ); + mythtv = GST_GMYTHTV_SRC( GST_PAD_PARENT (pad) ); size = gst_mythtv_src_get_position (mythtv); @@ -690,26 +699,31 @@ if (src->content_size <= 0) { ret= FALSE; - } else if ( abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) { + } else if ( abs ( src->content_size - src->read_offset ) <= GMYTHTV_TRANSFER_MAX_BUFFER ) { //g_static_mutex_lock( &update_size_mutex ); GST_OBJECT_LOCK(src); - guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer ); - if ( src->content_size < new_offset ) { - src->content_size = new_offset; - } + 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; + src->content_size = 0; + } #if ENABLE_TIMING_POSITION == 1 - guint64 size_tmp = 0; + gint64 size_tmp = 0; if (src->live_tv == TRUE) { get_file_pos: g_usleep( 5 ); - size_tmp = myth_file_transfer_get_file_position( src->file_transfer ); - if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) ) + 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 + else if ( size_tmp > 0 ) goto get_file_pos; - g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n", + g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n", __FUNCTION__, size_tmp ); } #endif @@ -849,28 +863,28 @@ break; } #ifndef GST_DISABLE_GST_DEBUG - case PROP_MYTHTV_DBG: + case PROP_GMYTHTV_DBG: { mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value); break; } #endif - case PROP_MYTHTV_VERSION: + case PROP_GMYTHTV_VERSION: { mythtvsrc->mythtv_version = g_value_get_int (value); break; } - case PROP_MYTHTV_LIVEID: + case PROP_GMYTHTV_LIVEID: { mythtvsrc->live_tv_id = g_value_get_int (value); break; } - case PROP_MYTHTV_LIVE: + case PROP_GMYTHTV_LIVE: { mythtvsrc->live_tv = g_value_get_boolean (value); break; } - case PROP_MYTHTV_LIVE_CHAINID: + case PROP_GMYTHTV_LIVE_CHAINID: { if (!g_value_get_string (value)) { GST_WARNING ("MythTV Live chainid property cannot be NULL"); @@ -918,24 +932,24 @@ break; } #ifndef GST_DISABLE_GST_DEBUG - case PROP_MYTHTV_DBG: + case PROP_GMYTHTV_DBG: g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg ); break; #endif - case PROP_MYTHTV_VERSION: + case PROP_GMYTHTV_VERSION: { g_value_set_int ( value, mythtvsrc->mythtv_version ); break; } - case PROP_MYTHTV_LIVEID: + case PROP_GMYTHTV_LIVEID: { g_value_set_int ( value, mythtvsrc->live_tv_id ); break; } - case PROP_MYTHTV_LIVE: + case PROP_GMYTHTV_LIVE: g_value_set_boolean ( value, mythtvsrc->live_tv ); break; - case PROP_MYTHTV_LIVE_CHAINID: + case PROP_GMYTHTV_LIVE_CHAINID: { gchar *str = g_strdup( "" ); @@ -960,7 +974,7 @@ * register the element factories and pad templates * register the features */ - static gboolean +static gboolean plugin_init (GstPlugin * plugin) { return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,