diff -r c71d37b93734 -r 9e534ac483e6 gst-plugins-mythtv/src/myth_file_transfer.c --- a/gst-plugins-mythtv/src/myth_file_transfer.c Wed Oct 18 23:45:17 2006 +0100 +++ b/gst-plugins-mythtv/src/myth_file_transfer.c Mon Oct 23 14:43:18 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) {