[svn r38] Added program chain backend events. trunk
authorrosfran
Mon Oct 23 14:36:26 2006 +0100 (2006-10-23)
branchtrunk
changeset 37324e04989738
parent 36 a6559a231dd2
child 38 d5f5855e7800
[svn r38] Added program chain backend events.
gst-plugins-mythtv/src/gstmythtvsrc.c
gst-plugins-mythtv/src/myth_file_transfer.c
gst-plugins-mythtv/src/myth_livetv.c
     1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c	Sat Oct 21 03:54:07 2006 +0100
     1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c	Mon Oct 23 14:36:26 2006 +0100
     1.3 @@ -101,7 +101,7 @@
     1.4  static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
     1.5  //static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query );
     1.6  
     1.7 -static guint do_read_request_response (GstMythtvSrc *src, guint64 offset, 
     1.8 +static gint do_read_request_response (GstMythtvSrc *src, guint64 offset, 
     1.9  		guint size, GstBuffer **outbuf);
    1.10  //static gboolean gst_mythtv_src_sink_activate_pull (GstPad * srcpad, gboolean active);
    1.11  
    1.12 @@ -276,10 +276,10 @@
    1.13    G_OBJECT_CLASS (parent_class)->finalize (gobject);
    1.14  }
    1.15  
    1.16 -static guint
    1.17 +static gint
    1.18  do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, GstBuffer **outbuf)
    1.19  {
    1.20 -  guint read = 0;
    1.21 +  gint read = 0;
    1.22    guint sizetoread = size; //GST_BUFFER_SIZE (outbuf);
    1.23    //GstBuffer *buffer = gst_buffer_new_and_alloc( size ); 
    1.24  
    1.25 @@ -287,9 +287,9 @@
    1.26  
    1.27    /* Loop sending the Myth File Transfer request:
    1.28     * Retry whilst authentication fails and we supply it. */
    1.29 -  guint len = 0;
    1.30 +  gint len = 0;
    1.31  
    1.32 -  //GST_OBJECT_LOCK(src);
    1.33 +  GST_OBJECT_LOCK(src);
    1.34  
    1.35    while ( sizetoread > 0 ) {
    1.36    	
    1.37 @@ -346,7 +346,6 @@
    1.38    GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
    1.39    GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
    1.40    GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
    1.41 -  //*outbuf = buffer;  
    1.42    //memcpy( GST_BUFFER_DATA( *outbuf ), GST_BUFFER_DATA( buffer ), read );
    1.43       
    1.44    g_print( "Stopping: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
    1.45 @@ -359,11 +358,10 @@
    1.46    goto done;
    1.47  
    1.48  eos:
    1.49 -  //GST_OBJECT_UNLOCK(src);  
    1.50    src->eos = TRUE;
    1.51    
    1.52  done:
    1.53 -  //GST_OBJECT_UNLOCK(src);
    1.54 +  GST_OBJECT_UNLOCK(src);
    1.55  
    1.56    return read;
    1.57  }
    1.58 @@ -373,7 +371,7 @@
    1.59  {
    1.60    GstMythtvSrc *src;
    1.61    GstFlowReturn ret = GST_FLOW_OK;
    1.62 -  guint read = 0;
    1.63 +  gint read = -1;
    1.64    
    1.65    src = GST_MYTHTV_SRC (psrc);
    1.66    /* The caller should know the number of bytes and not read beyond EOS. */
    1.67 @@ -389,7 +387,7 @@
    1.68      if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) {
    1.69      {
    1.70        //GST_OBJECT_UNLOCK(src);
    1.71 -      goto read_error;
    1.72 +      goto seek_failed;
    1.73      }
    1.74  
    1.75      src->read_offset = offset;
    1.76 @@ -445,6 +443,17 @@
    1.77  	  src->uri_name));
    1.78      return GST_FLOW_ERROR;
    1.79    }
    1.80 +seek_failed:
    1.81 +  {
    1.82 +    GST_ELEMENT_ERROR (src, RESOURCE, READ,
    1.83 +	(NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
    1.84 +	  src->uri_name));
    1.85 +	// go to the next program chain
    1.86 +	src->unique_setup = FALSE;
    1.87 +	gst_mythtv_src_start( psrc );
    1.88 +  
    1.89 +    return GST_FLOW_OK;
    1.90 +  }
    1.91  
    1.92  }
    1.93  
    1.94 @@ -683,6 +692,7 @@
    1.95      ret= FALSE;
    1.96    } else if ( abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) {
    1.97      //g_static_mutex_lock( &update_size_mutex );
    1.98 +    GST_OBJECT_LOCK(src);
    1.99  
   1.100    	guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
   1.101    	if ( src->content_size < new_offset ) {
   1.102 @@ -703,6 +713,7 @@
   1.103  	  __FUNCTION__, size_tmp );
   1.104      }
   1.105  #endif
   1.106 +	GST_OBJECT_UNLOCK(src);
   1.107      //g_static_mutex_unlock( &update_size_mutex );
   1.108  
   1.109    }
     2.1 --- a/gst-plugins-mythtv/src/myth_file_transfer.c	Sat Oct 21 03:54:07 2006 +0100
     2.2 +++ b/gst-plugins-mythtv/src/myth_file_transfer.c	Mon Oct 23 14:36:26 2006 +0100
     2.3 @@ -32,7 +32,7 @@
     2.4  #define MYTHTV_RETRIES			1
     2.5  #define MYTHTV_FILE_SIZE		-1
     2.6  
     2.7 -#define MYTHTV_BUFFER_SIZE		256*1024
     2.8 +#define MYTHTV_BUFFER_SIZE		8*1024
     2.9  
    2.10  #define MYTHTV_VERSION			30
    2.11  
    2.12 @@ -60,6 +60,8 @@
    2.13  
    2.14  static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
    2.15  
    2.16 +static GMainContext *io_watcher_context = NULL;
    2.17 +
    2.18  static void myth_file_transfer_class_init          (MythFileTransferClass *klass);
    2.19  static void myth_file_transfer_init                (MythFileTransfer *object);
    2.20  
    2.21 @@ -73,6 +75,7 @@
    2.22  
    2.23  G_DEFINE_TYPE(MythFileTransfer, myth_file_transfer, G_TYPE_OBJECT)
    2.24  
    2.25 +#if 0
    2.26  static guint64
    2.27  mmyth_util_decode_long_long( GMythStringList *strlist, guint offset  )
    2.28  {
    2.29 @@ -93,6 +96,7 @@
    2.30    return ret_value;
    2.31  
    2.32  }
    2.33 +#endif
    2.34  
    2.35  static void
    2.36  myth_file_transfer_class_init (MythFileTransferClass *klass)
    2.37 @@ -224,9 +228,9 @@
    2.38  
    2.39  #if 0
    2.40    /* configure the control socket */
    2.41 -  if ((*transfer)->control_sock == NULL) { 
    2.42 +  if ((*transfer)->event_sock == NULL) { 
    2.43  
    2.44 -    if ( myth_connect_to_transfer_backend ( transfer, MYTH_PLAYBACK_TYPE ) == NULL ) {
    2.45 +    if ( myth_connect_to_transfer_backend ( transfer, MYTH_MONITOR_TYPE ) == NULL ) {
    2.46        g_printerr( "Connection to backend failed (Event Socket).\n" );
    2.47        ret = FALSE;
    2.48      }
    2.49 @@ -326,7 +330,7 @@
    2.50      if ( sock_type == MYTH_PLAYBACK_TYPE )
    2.51      {
    2.52        (*transfer)->control_sock = sock;
    2.53 -      g_string_printf( base_str, "ANN Playback %s %d", hostname->str, FALSE );
    2.54 +      g_string_printf( base_str, "ANN Playback %s %d", hostname->str, TRUE );
    2.55  
    2.56        gmyth_socket_send_command( (*transfer)->control_sock, base_str );
    2.57        GString *resp = gmyth_socket_receive_response( (*transfer)->control_sock );
    2.58 @@ -340,7 +344,8 @@
    2.59        gmyth_socket_send_command( (*transfer)->event_sock, base_str );
    2.60        GString *resp = gmyth_socket_receive_response( (*transfer)->event_sock );
    2.61        g_print( "[%s] Got Monitor response from %s: %s\n", __FUNCTION__, base_str->str, resp->str );
    2.62 -      g_thread_create( myth_init_io_watchers, (void*)(*transfer), FALSE, NULL );
    2.63 +      //g_thread_create( myth_init_io_watchers, (void*)(*transfer), FALSE, NULL );
    2.64 +      myth_init_io_watchers ( (void*)(*transfer) );
    2.65  
    2.66        g_printerr( "[%s] Watch listener function to the IO control channel on thread %p.\n", __FUNCTION__, g_thread_self() );
    2.67  
    2.68 @@ -363,7 +368,7 @@
    2.69        (*transfer)->recordernum = gmyth_string_list_get_int( strlist, 1 );
    2.70  
    2.71        /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */
    2.72 -      (*transfer)->filesize = mmyth_util_decode_long_long( strlist, 2 );
    2.73 +      (*transfer)->filesize = gmyth_util_decode_long_long( strlist, 2 );
    2.74  
    2.75        printf( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__,
    2.76  	  (*transfer)->recordernum, (*transfer)->filesize );
    2.77 @@ -472,7 +477,7 @@
    2.78  guint64
    2.79  myth_file_transfer_get_file_position ( MythFileTransfer *file_transfer )
    2.80  {
    2.81 -  guint64 pos = 0;
    2.82 +  gint64 pos = 0;
    2.83  
    2.84    GMythStringList *str_list = gmyth_string_list_new ();
    2.85  
    2.86 @@ -641,6 +646,8 @@
    2.87    GIOStatus ret;
    2.88    GError *err = NULL;
    2.89    gchar *msg = g_strdup("");
    2.90 +  
    2.91 +  g_static_mutex_lock( &mutex );  
    2.92  
    2.93    gsize len;
    2.94    if (condition & G_IO_HUP)
    2.95 @@ -651,6 +658,8 @@
    2.96    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 : "" );
    2.97    if ( msg != NULL )
    2.98      g_free (msg);
    2.99 +    
   2.100 +  g_static_mutex_unlock( &mutex );
   2.101  
   2.102    return TRUE;
   2.103  
   2.104 @@ -660,32 +669,41 @@
   2.105  myth_init_io_watchers( void *data )
   2.106  {
   2.107    MythFileTransfer *transfer = (MythFileTransfer*)data;
   2.108 -  GMainContext *context = g_main_context_new();
   2.109 +  io_watcher_context = g_main_context_new();
   2.110    GMainLoop *loop = g_main_loop_new( NULL, FALSE );
   2.111  
   2.112    GSource *source = NULL;
   2.113  
   2.114    if ( transfer->event_sock->sd_io_ch != NULL )
   2.115      source = g_io_create_watch( transfer->event_sock->sd_io_ch, G_IO_IN | G_IO_HUP );
   2.116 +  else
   2.117 +  	goto cleanup;
   2.118  
   2.119    g_source_set_callback ( source, (GSourceFunc)myth_control_sock_listener, NULL, NULL );
   2.120  
   2.121 -  g_source_attach( source, context );
   2.122 +  g_source_attach( source, io_watcher_context );
   2.123  
   2.124 -  if (source==NULL)
   2.125 +  if (source==NULL) {
   2.126      g_printerr( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ );
   2.127 +    goto cleanup;
   2.128 +  }
   2.129 +  
   2.130 +  g_print( "[%s]\tOK! Starting listener on the MONITOR event socket...\n", __FUNCTION__ );
   2.131  
   2.132    g_main_loop_run( loop );
   2.133  
   2.134 -  g_source_unref( source );
   2.135 +cleanup:
   2.136 +  if ( source != NULL )
   2.137 +    g_source_unref( source );
   2.138  
   2.139    g_main_loop_unref( loop );
   2.140  
   2.141 -  g_main_context_unref( context );
   2.142 +  g_main_context_unref( io_watcher_context );
   2.143  
   2.144    return NULL;
   2.145  }
   2.146  
   2.147 +
   2.148  gint 
   2.149  myth_file_transfer_read(MythFileTransfer *transfer, void *data, gint size, gboolean read_unlimited)
   2.150  {
     3.1 --- a/gst-plugins-mythtv/src/myth_livetv.c	Sat Oct 21 03:54:07 2006 +0100
     3.2 +++ b/gst-plugins-mythtv/src/myth_livetv.c	Mon Oct 23 14:36:26 2006 +0100
     3.3 @@ -12,6 +12,8 @@
     3.4  static void myth_livetv_dispose  (GObject *object);
     3.5  static void myth_livetv_finalize (GObject *object);
     3.6  
     3.7 +static gint tvchain_curr_index = -1; 
     3.8 +
     3.9  G_DEFINE_TYPE(MythLiveTV, myth_livetv, G_TYPE_OBJECT)
    3.10  
    3.11  static void
    3.12 @@ -82,8 +84,6 @@
    3.13  gboolean
    3.14  myth_livetv_setup ( MythLiveTV *livetv )
    3.15  {
    3.16 -
    3.17 -	// FIXME: Get from the settings
    3.18  	GMythSettings *msettings = gmyth_context_get_settings ();
    3.19  	gboolean res = TRUE;
    3.20  
    3.21 @@ -150,7 +150,7 @@
    3.22  	}
    3.23  
    3.24  	// Get program info from database using chanid and starttime
    3.25 -	livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, -1);
    3.26 +	livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, tvchain_curr_index++ );
    3.27  	if ( livetv->proginfo == NULL ) {
    3.28  		g_warning ("[%s] LiveTV not successfully started.\n", __FUNCTION__ );
    3.29  		res = FALSE;