# HG changeset patch # User rosfran # Date 1161610586 -3600 # Node ID 324e049897382bfb179599a38a6f5788a3616248 # Parent a6559a231dd2ce09f6151a09c26d4823b2cd2233 [svn r38] Added program chain backend events. diff -r a6559a231dd2 -r 324e04989738 gst-plugins-mythtv/src/gstmythtvsrc.c --- a/gst-plugins-mythtv/src/gstmythtvsrc.c Sat Oct 21 03:54:07 2006 +0100 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c Mon Oct 23 14:36:26 2006 +0100 @@ -101,7 +101,7 @@ static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event); //static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query ); -static guint do_read_request_response (GstMythtvSrc *src, guint64 offset, +static gint do_read_request_response (GstMythtvSrc *src, guint64 offset, guint size, GstBuffer **outbuf); //static gboolean gst_mythtv_src_sink_activate_pull (GstPad * srcpad, gboolean active); @@ -276,10 +276,10 @@ G_OBJECT_CLASS (parent_class)->finalize (gobject); } -static guint +static gint do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, GstBuffer **outbuf) { - guint read = 0; + gint read = 0; guint sizetoread = size; //GST_BUFFER_SIZE (outbuf); //GstBuffer *buffer = gst_buffer_new_and_alloc( size ); @@ -287,9 +287,9 @@ /* Loop sending the Myth File Transfer request: * Retry whilst authentication fails and we supply it. */ - guint len = 0; + gint len = 0; - //GST_OBJECT_LOCK(src); + GST_OBJECT_LOCK(src); while ( sizetoread > 0 ) { @@ -346,7 +346,6 @@ 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; - //*outbuf = buffer; //memcpy( GST_BUFFER_DATA( *outbuf ), GST_BUFFER_DATA( buffer ), read ); g_print( "Stopping: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\ @@ -359,11 +358,10 @@ goto done; eos: - //GST_OBJECT_UNLOCK(src); src->eos = TRUE; done: - //GST_OBJECT_UNLOCK(src); + GST_OBJECT_UNLOCK(src); return read; } @@ -373,7 +371,7 @@ { GstMythtvSrc *src; GstFlowReturn ret = GST_FLOW_OK; - guint read = 0; + gint read = -1; src = GST_MYTHTV_SRC (psrc); /* The caller should know the number of bytes and not read beyond EOS. */ @@ -389,7 +387,7 @@ if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) { { //GST_OBJECT_UNLOCK(src); - goto read_error; + goto seek_failed; } src->read_offset = offset; @@ -445,6 +443,17 @@ src->uri_name)); return GST_FLOW_ERROR; } +seek_failed: + { + GST_ELEMENT_ERROR (src, RESOURCE, READ, + (NULL), ("Seek failed, go to the next program info... (%i, %s)", read, + src->uri_name)); + // go to the next program chain + src->unique_setup = FALSE; + gst_mythtv_src_start( psrc ); + + return GST_FLOW_OK; + } } @@ -683,6 +692,7 @@ ret= FALSE; } else if ( abs ( src->content_size - src->read_offset ) <= MYTHTV_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 ) { @@ -703,6 +713,7 @@ __FUNCTION__, size_tmp ); } #endif + GST_OBJECT_UNLOCK(src); //g_static_mutex_unlock( &update_size_mutex ); } diff -r a6559a231dd2 -r 324e04989738 gst-plugins-mythtv/src/myth_file_transfer.c --- a/gst-plugins-mythtv/src/myth_file_transfer.c Sat Oct 21 03:54:07 2006 +0100 +++ b/gst-plugins-mythtv/src/myth_file_transfer.c Mon Oct 23 14:36:26 2006 +0100 @@ -32,7 +32,7 @@ #define MYTHTV_RETRIES 1 #define MYTHTV_FILE_SIZE -1 -#define MYTHTV_BUFFER_SIZE 256*1024 +#define MYTHTV_BUFFER_SIZE 8*1024 #define MYTHTV_VERSION 30 @@ -60,6 +60,8 @@ static GStaticMutex mutex = G_STATIC_MUTEX_INIT; +static GMainContext *io_watcher_context = NULL; + static void myth_file_transfer_class_init (MythFileTransferClass *klass); static void myth_file_transfer_init (MythFileTransfer *object); @@ -73,6 +75,7 @@ G_DEFINE_TYPE(MythFileTransfer, myth_file_transfer, G_TYPE_OBJECT) +#if 0 static guint64 mmyth_util_decode_long_long( GMythStringList *strlist, guint offset ) { @@ -93,6 +96,7 @@ return ret_value; } +#endif static void myth_file_transfer_class_init (MythFileTransferClass *klass) @@ -224,9 +228,9 @@ #if 0 /* configure the control socket */ - if ((*transfer)->control_sock == NULL) { + if ((*transfer)->event_sock == NULL) { - if ( myth_connect_to_transfer_backend ( transfer, MYTH_PLAYBACK_TYPE ) == NULL ) { + if ( myth_connect_to_transfer_backend ( transfer, MYTH_MONITOR_TYPE ) == NULL ) { g_printerr( "Connection to backend failed (Event Socket).\n" ); ret = FALSE; } @@ -326,7 +330,7 @@ if ( sock_type == MYTH_PLAYBACK_TYPE ) { (*transfer)->control_sock = sock; - g_string_printf( base_str, "ANN Playback %s %d", hostname->str, FALSE ); + g_string_printf( base_str, "ANN Playback %s %d", hostname->str, TRUE ); gmyth_socket_send_command( (*transfer)->control_sock, base_str ); GString *resp = gmyth_socket_receive_response( (*transfer)->control_sock ); @@ -340,7 +344,8 @@ gmyth_socket_send_command( (*transfer)->event_sock, base_str ); GString *resp = gmyth_socket_receive_response( (*transfer)->event_sock ); g_print( "[%s] Got Monitor response from %s: %s\n", __FUNCTION__, base_str->str, resp->str ); - g_thread_create( myth_init_io_watchers, (void*)(*transfer), FALSE, NULL ); + //g_thread_create( myth_init_io_watchers, (void*)(*transfer), FALSE, NULL ); + myth_init_io_watchers ( (void*)(*transfer) ); g_printerr( "[%s] Watch listener function to the IO control channel on thread %p.\n", __FUNCTION__, g_thread_self() ); @@ -363,7 +368,7 @@ (*transfer)->recordernum = gmyth_string_list_get_int( strlist, 1 ); /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */ - (*transfer)->filesize = mmyth_util_decode_long_long( strlist, 2 ); + (*transfer)->filesize = gmyth_util_decode_long_long( strlist, 2 ); printf( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__, (*transfer)->recordernum, (*transfer)->filesize ); @@ -472,7 +477,7 @@ guint64 myth_file_transfer_get_file_position ( MythFileTransfer *file_transfer ) { - guint64 pos = 0; + gint64 pos = 0; GMythStringList *str_list = gmyth_string_list_new (); @@ -641,6 +646,8 @@ GIOStatus ret; GError *err = NULL; gchar *msg = g_strdup(""); + + g_static_mutex_lock( &mutex ); gsize len; if (condition & G_IO_HUP) @@ -651,6 +658,8 @@ g_print ("\n\n\n\n\n\n[%s]\t\tEVENT: Read %u bytes: %s\n\n\n\n\n", __FUNCTION__, len, msg != NULL ? msg : "" ); if ( msg != NULL ) g_free (msg); + + g_static_mutex_unlock( &mutex ); return TRUE; @@ -660,32 +669,41 @@ myth_init_io_watchers( void *data ) { MythFileTransfer *transfer = (MythFileTransfer*)data; - GMainContext *context = g_main_context_new(); + io_watcher_context = g_main_context_new(); GMainLoop *loop = g_main_loop_new( NULL, FALSE ); GSource *source = NULL; if ( transfer->event_sock->sd_io_ch != NULL ) source = g_io_create_watch( transfer->event_sock->sd_io_ch, G_IO_IN | G_IO_HUP ); + else + goto cleanup; g_source_set_callback ( source, (GSourceFunc)myth_control_sock_listener, NULL, NULL ); - g_source_attach( source, context ); + g_source_attach( source, io_watcher_context ); - if (source==NULL) + if (source==NULL) { g_printerr( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ ); + goto cleanup; + } + + g_print( "[%s]\tOK! Starting listener on the MONITOR event socket...\n", __FUNCTION__ ); g_main_loop_run( loop ); - g_source_unref( source ); +cleanup: + if ( source != NULL ) + g_source_unref( source ); g_main_loop_unref( loop ); - g_main_context_unref( context ); + g_main_context_unref( io_watcher_context ); return NULL; } + gint myth_file_transfer_read(MythFileTransfer *transfer, void *data, gint size, gboolean read_unlimited) { diff -r a6559a231dd2 -r 324e04989738 gst-plugins-mythtv/src/myth_livetv.c --- a/gst-plugins-mythtv/src/myth_livetv.c Sat Oct 21 03:54:07 2006 +0100 +++ b/gst-plugins-mythtv/src/myth_livetv.c Mon Oct 23 14:36:26 2006 +0100 @@ -12,6 +12,8 @@ static void myth_livetv_dispose (GObject *object); static void myth_livetv_finalize (GObject *object); +static gint tvchain_curr_index = -1; + G_DEFINE_TYPE(MythLiveTV, myth_livetv, G_TYPE_OBJECT) static void @@ -82,8 +84,6 @@ gboolean myth_livetv_setup ( MythLiveTV *livetv ) { - - // FIXME: Get from the settings GMythSettings *msettings = gmyth_context_get_settings (); gboolean res = TRUE; @@ -150,7 +150,7 @@ } // Get program info from database using chanid and starttime - livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, -1); + livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, tvchain_curr_index++ ); if ( livetv->proginfo == NULL ) { g_warning ("[%s] LiveTV not successfully started.\n", __FUNCTION__ ); res = FALSE;