gst-plugins-mythtv/src/myth_file_transfer.c
branchtrunk
changeset 39 9e534ac483e6
parent 34 c71d37b93734
     1.1 --- a/gst-plugins-mythtv/src/myth_file_transfer.c	Wed Oct 18 23:45:17 2006 +0100
     1.2 +++ b/gst-plugins-mythtv/src/myth_file_transfer.c	Mon Oct 23 14:43:18 2006 +0100
     1.3 @@ -32,7 +32,7 @@
     1.4  #define MYTHTV_RETRIES			1
     1.5  #define MYTHTV_FILE_SIZE		-1
     1.6  
     1.7 -#define MYTHTV_BUFFER_SIZE		256*1024
     1.8 +#define MYTHTV_BUFFER_SIZE		8*1024
     1.9  
    1.10  #define MYTHTV_VERSION			30
    1.11  
    1.12 @@ -60,6 +60,8 @@
    1.13  
    1.14  static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
    1.15  
    1.16 +static GMainContext *io_watcher_context = NULL;
    1.17 +
    1.18  static void myth_file_transfer_class_init          (MythFileTransferClass *klass);
    1.19  static void myth_file_transfer_init                (MythFileTransfer *object);
    1.20  
    1.21 @@ -73,6 +75,7 @@
    1.22  
    1.23  G_DEFINE_TYPE(MythFileTransfer, myth_file_transfer, G_TYPE_OBJECT)
    1.24  
    1.25 +#if 0
    1.26  static guint64
    1.27  mmyth_util_decode_long_long( GMythStringList *strlist, guint offset  )
    1.28  {
    1.29 @@ -93,6 +96,7 @@
    1.30    return ret_value;
    1.31  
    1.32  }
    1.33 +#endif
    1.34  
    1.35  static void
    1.36  myth_file_transfer_class_init (MythFileTransferClass *klass)
    1.37 @@ -224,9 +228,9 @@
    1.38  
    1.39  #if 0
    1.40    /* configure the control socket */
    1.41 -  if ((*transfer)->control_sock == NULL) { 
    1.42 +  if ((*transfer)->event_sock == NULL) { 
    1.43  
    1.44 -    if ( myth_connect_to_transfer_backend ( transfer, MYTH_PLAYBACK_TYPE ) == NULL ) {
    1.45 +    if ( myth_connect_to_transfer_backend ( transfer, MYTH_MONITOR_TYPE ) == NULL ) {
    1.46        g_printerr( "Connection to backend failed (Event Socket).\n" );
    1.47        ret = FALSE;
    1.48      }
    1.49 @@ -326,7 +330,7 @@
    1.50      if ( sock_type == MYTH_PLAYBACK_TYPE )
    1.51      {
    1.52        (*transfer)->control_sock = sock;
    1.53 -      g_string_printf( base_str, "ANN Playback %s %d", hostname->str, FALSE );
    1.54 +      g_string_printf( base_str, "ANN Playback %s %d", hostname->str, TRUE );
    1.55  
    1.56        gmyth_socket_send_command( (*transfer)->control_sock, base_str );
    1.57        GString *resp = gmyth_socket_receive_response( (*transfer)->control_sock );
    1.58 @@ -340,7 +344,8 @@
    1.59        gmyth_socket_send_command( (*transfer)->event_sock, base_str );
    1.60        GString *resp = gmyth_socket_receive_response( (*transfer)->event_sock );
    1.61        g_print( "[%s] Got Monitor response from %s: %s\n", __FUNCTION__, base_str->str, resp->str );
    1.62 -      g_thread_create( myth_init_io_watchers, (void*)(*transfer), FALSE, NULL );
    1.63 +      //g_thread_create( myth_init_io_watchers, (void*)(*transfer), FALSE, NULL );
    1.64 +      myth_init_io_watchers ( (void*)(*transfer) );
    1.65  
    1.66        g_printerr( "[%s] Watch listener function to the IO control channel on thread %p.\n", __FUNCTION__, g_thread_self() );
    1.67  
    1.68 @@ -363,7 +368,7 @@
    1.69        (*transfer)->recordernum = gmyth_string_list_get_int( strlist, 1 );
    1.70  
    1.71        /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */
    1.72 -      (*transfer)->filesize = mmyth_util_decode_long_long( strlist, 2 );
    1.73 +      (*transfer)->filesize = gmyth_util_decode_long_long( strlist, 2 );
    1.74  
    1.75        printf( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__,
    1.76  	  (*transfer)->recordernum, (*transfer)->filesize );
    1.77 @@ -472,7 +477,7 @@
    1.78  guint64
    1.79  myth_file_transfer_get_file_position ( MythFileTransfer *file_transfer )
    1.80  {
    1.81 -  guint64 pos = 0;
    1.82 +  gint64 pos = 0;
    1.83  
    1.84    GMythStringList *str_list = gmyth_string_list_new ();
    1.85  
    1.86 @@ -641,6 +646,8 @@
    1.87    GIOStatus ret;
    1.88    GError *err = NULL;
    1.89    gchar *msg = g_strdup("");
    1.90 +  
    1.91 +  g_static_mutex_lock( &mutex );  
    1.92  
    1.93    gsize len;
    1.94    if (condition & G_IO_HUP)
    1.95 @@ -651,6 +658,8 @@
    1.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 : "" );
    1.97    if ( msg != NULL )
    1.98      g_free (msg);
    1.99 +    
   1.100 +  g_static_mutex_unlock( &mutex );
   1.101  
   1.102    return TRUE;
   1.103  
   1.104 @@ -660,32 +669,41 @@
   1.105  myth_init_io_watchers( void *data )
   1.106  {
   1.107    MythFileTransfer *transfer = (MythFileTransfer*)data;
   1.108 -  GMainContext *context = g_main_context_new();
   1.109 +  io_watcher_context = g_main_context_new();
   1.110    GMainLoop *loop = g_main_loop_new( NULL, FALSE );
   1.111  
   1.112    GSource *source = NULL;
   1.113  
   1.114    if ( transfer->event_sock->sd_io_ch != NULL )
   1.115      source = g_io_create_watch( transfer->event_sock->sd_io_ch, G_IO_IN | G_IO_HUP );
   1.116 +  else
   1.117 +  	goto cleanup;
   1.118  
   1.119    g_source_set_callback ( source, (GSourceFunc)myth_control_sock_listener, NULL, NULL );
   1.120  
   1.121 -  g_source_attach( source, context );
   1.122 +  g_source_attach( source, io_watcher_context );
   1.123  
   1.124 -  if (source==NULL)
   1.125 +  if (source==NULL) {
   1.126      g_printerr( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ );
   1.127 +    goto cleanup;
   1.128 +  }
   1.129 +  
   1.130 +  g_print( "[%s]\tOK! Starting listener on the MONITOR event socket...\n", __FUNCTION__ );
   1.131  
   1.132    g_main_loop_run( loop );
   1.133  
   1.134 -  g_source_unref( source );
   1.135 +cleanup:
   1.136 +  if ( source != NULL )
   1.137 +    g_source_unref( source );
   1.138  
   1.139    g_main_loop_unref( loop );
   1.140  
   1.141 -  g_main_context_unref( context );
   1.142 +  g_main_context_unref( io_watcher_context );
   1.143  
   1.144    return NULL;
   1.145  }
   1.146  
   1.147 +
   1.148  gint 
   1.149  myth_file_transfer_read(MythFileTransfer *transfer, void *data, gint size, gboolean read_unlimited)
   1.150  {