leo_sobral@2: /* vim: set sw=2: -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2; c-indent-level: 2-*- */ leo_sobral@2: /** leo_sobral@2: * GStreamer plug-in properties: leo_sobral@2: * - location (backend server hostname/URL) [ex.: myth://192.168.1.73:28722/1000_1092091.nuv] leo_sobral@2: * - path (qurl - remote file to be opened) leo_sobral@2: * - port number leo_sobral@2: * @author Rosfran Lins Borges leo_sobral@2: */ leo_sobral@2: leo_sobral@2: #include "myth_file_transfer.h" leo_sobral@2: #include "myth_uri.h" leo_sobral@2: #include "myth_livetv.h" leo_sobral@2: #include leo_sobral@2: #include leo_sobral@2: #include leo_sobral@2: leo_sobral@2: #include leo_sobral@2: #include leo_sobral@2: leo_sobral@2: #include leo_sobral@2: #include leo_sobral@2: #include leo_sobral@2: #include leo_sobral@2: #include leo_sobral@2: #include leo_sobral@2: leo_sobral@2: #define MYTHTV_QUERY_HEADER "QUERY_FILETRANSFER" leo_sobral@2: #define MYTHTV_RECORDER_HEADER "QUERY_RECORDER" leo_sobral@2: leo_sobral@2: /* default values to the file transfer parameters */ leo_sobral@2: #define MYTHTV_USER_READ_AHEAD FALSE leo_sobral@2: #define MYTHTV_RETRIES 1 leo_sobral@2: #define MYTHTV_FILE_SIZE -1 leo_sobral@2: leo_sobral@2: #define MYTHTV_BUFFER_SIZE 2048 leo_sobral@2: leo_sobral@2: #define MYTHTV_VERSION 30 leo_sobral@2: leo_sobral@2: #define MYTHTV_TRANSFER_MAX_WAITS 700 leo_sobral@2: leo_sobral@2: #ifdef MYTHTV_ENABLE_DEBUG leo_sobral@2: #define MYTHTV_ENABLE_DEBUG 1 leo_sobral@2: #else leo_sobral@2: #undef MYTHTV_ENABLE_DEBUG leo_sobral@2: #endif leo_sobral@2: leo_sobral@2: /* this NDEBUG is to maintain compatibility with GMyth library */ leo_sobral@2: #ifndef NDEBUG leo_sobral@2: #define MYTHTV_ENABLE_DEBUG 1 leo_sobral@2: #endif leo_sobral@2: leo_sobral@2: static guint wait_to_transfer = 0; leo_sobral@2: leo_sobral@2: enum myth_sock_types { leo_sobral@2: MYTH_PLAYBACK_TYPE = 0, leo_sobral@2: MYTH_MONITOR_TYPE, leo_sobral@2: MYTH_FILETRANSFER_TYPE, leo_sobral@2: MYTH_RINGBUFFER_TYPE leo_sobral@2: }; leo_sobral@2: leo_sobral@2: static GStaticMutex mutex = G_STATIC_MUTEX_INIT; leo_sobral@2: leo_sobral@2: static void myth_file_transfer_class_init (MythFileTransferClass *klass); leo_sobral@2: static void myth_file_transfer_init (MythFileTransfer *object); leo_sobral@2: leo_sobral@2: static void myth_file_transfer_dispose (GObject *object); leo_sobral@2: static void myth_file_transfer_finalize (GObject *object); leo_sobral@2: leo_sobral@2: static GMythSocket *myth_connect_to_transfer_backend( MythFileTransfer **transfer, guint sock_type ); leo_sobral@2: static void* myth_init_io_watchers( void *data ); leo_sobral@2: leo_sobral@2: void myth_file_transfer_close( MythFileTransfer *transfer ); leo_sobral@2: leo_sobral@2: G_DEFINE_TYPE(MythFileTransfer, myth_file_transfer, G_TYPE_OBJECT) leo_sobral@2: leo_sobral@2: static guint64 leo_sobral@2: mmyth_util_decode_long_long( GMythStringList *strlist, guint offset ) leo_sobral@2: { leo_sobral@2: leo_sobral@2: guint64 ret_value = 0LL; leo_sobral@2: leo_sobral@2: g_return_val_if_fail( strlist != NULL, ret_value ); leo_sobral@2: leo_sobral@2: if ( offset < gmyth_string_list_length( strlist )) leo_sobral@2: g_printerr( "[%s] Offset is lower than the GMythStringList (offset = %d)!\n", __FUNCTION__, offset ); leo_sobral@2: g_return_val_if_fail( offset < gmyth_string_list_length( strlist ), ret_value ); leo_sobral@2: leo_sobral@2: gint l1 = gmyth_string_list_get_int( strlist, offset ); leo_sobral@2: gint l2 = gmyth_string_list_get_int( strlist, offset + 1 ); leo_sobral@2: leo_sobral@2: ret_value = ((guint64)(l2) & 0xffffffffLL) | ((guint64)(l1) << 32); leo_sobral@2: leo_sobral@2: return ret_value; leo_sobral@2: leo_sobral@2: } leo_sobral@2: leo_sobral@2: static void leo_sobral@2: myth_file_transfer_class_init (MythFileTransferClass *klass) leo_sobral@2: { leo_sobral@2: GObjectClass *gobject_class; leo_sobral@2: leo_sobral@2: gobject_class = (GObjectClass *) klass; leo_sobral@2: leo_sobral@2: gobject_class->dispose = myth_file_transfer_dispose; leo_sobral@2: gobject_class->finalize = myth_file_transfer_finalize; leo_sobral@2: } leo_sobral@2: leo_sobral@2: static void leo_sobral@2: myth_file_transfer_init (MythFileTransfer *myth_file_transfer) leo_sobral@2: { leo_sobral@2: g_return_if_fail( myth_file_transfer != NULL ); leo_sobral@2: myth_file_transfer->mythtv_version = MYTHTV_VERSION; leo_sobral@2: } leo_sobral@2: leo_sobral@2: static void leo_sobral@2: myth_file_transfer_dispose (GObject *object) leo_sobral@2: { leo_sobral@2: MythFileTransfer *myth_file_transfer = MYTH_FILE_TRANSFER(object); leo_sobral@2: leo_sobral@2: myth_file_transfer_close( myth_file_transfer ); leo_sobral@2: leo_sobral@2: G_OBJECT_CLASS (myth_file_transfer_parent_class)->dispose (object); leo_sobral@2: } leo_sobral@2: leo_sobral@2: static void leo_sobral@2: myth_file_transfer_finalize (GObject *object) leo_sobral@2: { leo_sobral@2: g_signal_handlers_destroy (object); leo_sobral@2: leo_sobral@2: G_OBJECT_CLASS (myth_file_transfer_parent_class)->finalize (object); leo_sobral@2: } leo_sobral@2: leo_sobral@2: MythFileTransfer* leo_sobral@2: myth_file_transfer_new (gint num, GString *uri_str, gshort port, gint mythtv_version) leo_sobral@2: { leo_sobral@2: MythFileTransfer *transfer = MYTH_FILE_TRANSFER ( g_object_new ( leo_sobral@2: MYTH_FILE_TRANSFER_TYPE, FALSE )); leo_sobral@2: leo_sobral@2: if ( mythtv_version > 0 ) leo_sobral@2: transfer->mythtv_version = mythtv_version; leo_sobral@2: leo_sobral@2: transfer->card_id = num; leo_sobral@2: leo_sobral@2: transfer->rec_id = -1; leo_sobral@2: rosfran@30: transfer->recordernum = num; leo_sobral@2: transfer->uri = myth_uri_new ( uri_str->str ); leo_sobral@2: leo_sobral@2: transfer->hostname = g_string_new( myth_uri_gethost(transfer->uri) ); leo_sobral@2: g_print( "\t--> transfer->hostname = %s\n", transfer->hostname->str ); leo_sobral@2: leo_sobral@2: if ( port >= 0 ) leo_sobral@2: transfer->port = port; leo_sobral@2: else leo_sobral@2: transfer->port = myth_uri_getport( transfer->uri ); leo_sobral@2: leo_sobral@2: g_print( "\t--> transfer->port = %d\n", transfer->port ); leo_sobral@2: leo_sobral@2: transfer->readposition = 0; leo_sobral@2: transfer->filesize = MYTHTV_FILE_SIZE; leo_sobral@2: transfer->timeoutisfast = FALSE; leo_sobral@2: leo_sobral@2: transfer->userreadahead = MYTHTV_USER_READ_AHEAD; leo_sobral@2: transfer->retries = MYTHTV_RETRIES; leo_sobral@2: leo_sobral@2: transfer->live_tv = FALSE; leo_sobral@2: leo_sobral@2: transfer->query = g_string_new( MYTHTV_QUERY_HEADER ); leo_sobral@2: g_string_append_printf ( transfer->query, " %d", transfer->recordernum ); leo_sobral@2: g_print( "\t--> transfer->query = %s\n", transfer->query->str ); leo_sobral@2: leo_sobral@2: transfer->control_sock = NULL; leo_sobral@2: transfer->event_sock = NULL; leo_sobral@2: transfer->sock = NULL; leo_sobral@2: leo_sobral@2: return transfer; leo_sobral@2: } leo_sobral@2: leo_sobral@2: gboolean leo_sobral@2: myth_file_transfer_livetv_setup( MythFileTransfer **transfer, GMythSocket *live_socket ) leo_sobral@2: { leo_sobral@2: (*transfer)->sock = live_socket; leo_sobral@2: g_object_ref( live_socket ); leo_sobral@2: leo_sobral@2: return TRUE; leo_sobral@2: } leo_sobral@2: leo_sobral@2: gboolean leo_sobral@2: myth_file_transfer_playback_setup( MythFileTransfer **transfer, gboolean live_tv ) leo_sobral@2: { leo_sobral@2: leo_sobral@2: gboolean ret = TRUE; leo_sobral@2: leo_sobral@2: (*transfer)->live_tv = live_tv; leo_sobral@2: leo_sobral@2: printf("[%s] Running config to the %s...\n", __FUNCTION__, live_tv ? "LiveTV" : "FileTransfer" ); leo_sobral@2: leo_sobral@2: /* configure the control socket */ leo_sobral@2: if ((*transfer)->control_sock == NULL) { leo_sobral@2: leo_sobral@2: if ( myth_connect_to_transfer_backend ( transfer, MYTH_PLAYBACK_TYPE ) == NULL ) { leo_sobral@2: g_printerr( "Connection to backend failed (Control Socket).\n" ); leo_sobral@2: ret = FALSE; leo_sobral@2: } leo_sobral@2: leo_sobral@2: } else { leo_sobral@2: g_warning("Remote transfer control socket already created.\n"); leo_sobral@2: } leo_sobral@2: leo_sobral@2: return ret; leo_sobral@2: leo_sobral@2: } leo_sobral@2: leo_sobral@2: gboolean leo_sobral@2: myth_file_transfer_setup( MythFileTransfer **transfer, gboolean live_tv ) leo_sobral@2: { leo_sobral@2: GMythStringList *strlist = NULL; leo_sobral@2: leo_sobral@2: gboolean ret = TRUE; leo_sobral@2: leo_sobral@2: (*transfer)->live_tv = live_tv; leo_sobral@2: leo_sobral@2: printf("[%s] Running config to the %s...\n", __FUNCTION__, live_tv ? "LiveTV" : "FileTransfer" ); leo_sobral@2: leo_sobral@2: #if 0 rosfran@30: /* configure the control socket */ rosfran@30: if ((*transfer)->control_sock == NULL) { leo_sobral@2: rosfran@30: if ( myth_connect_to_transfer_backend ( transfer, MYTH_PLAYBACK_TYPE ) == NULL ) { leo_sobral@2: g_printerr( "Connection to backend failed (Event Socket).\n" ); leo_sobral@2: ret = FALSE; leo_sobral@2: } leo_sobral@2: leo_sobral@2: } else { leo_sobral@2: g_warning("Remote transfer control socket already created.\n"); leo_sobral@2: } leo_sobral@2: #endif leo_sobral@2: leo_sobral@2: /* configure the socket */ leo_sobral@2: if ( (*transfer)->sock == NULL ) { leo_sobral@2: leo_sobral@2: //if ( live_tv == FALSE ) { leo_sobral@2: leo_sobral@2: if ( myth_connect_to_transfer_backend ( transfer, MYTH_FILETRANSFER_TYPE ) == NULL ) { leo_sobral@2: g_printerr ("Connection to backend failed (Raw Transfer Socket).\n"); leo_sobral@2: ret = FALSE; leo_sobral@2: } leo_sobral@2: leo_sobral@2: if ( !(*transfer)->live_tv && (*transfer)->control_sock != NULL) { leo_sobral@2: strlist = gmyth_string_list_new(); leo_sobral@2: g_string_printf ( (*transfer)->query, "%s %d", MYTHTV_QUERY_HEADER, (*transfer)->recordernum ); leo_sobral@2: leo_sobral@2: gmyth_string_list_append_string( strlist, (*transfer)->query ); leo_sobral@2: gmyth_string_list_append_char_array( strlist, "IS_OPEN" ); leo_sobral@2: leo_sobral@2: gmyth_socket_write_stringlist( (*transfer)->control_sock, strlist ); leo_sobral@2: gmyth_socket_read_stringlist( (*transfer)->control_sock, strlist ); leo_sobral@2: leo_sobral@2: if ( strlist!=NULL && gmyth_string_list_get_int( strlist, 0 ) == 1 ) { leo_sobral@2: g_print( "[%s] Remote Myth FileTransfer socket is open!\n", __FUNCTION__ ); leo_sobral@2: } else { leo_sobral@2: g_print( "[%s] Remote Myth FileTransfer socket is CLOSED! See the MythTV Server Backend for configuration details...\n", __FUNCTION__ ); leo_sobral@2: ret = FALSE; leo_sobral@2: } leo_sobral@2: } leo_sobral@2: leo_sobral@2: } else { leo_sobral@2: g_warning("Remote transfer (raw) socket already created.\n"); leo_sobral@2: } leo_sobral@2: leo_sobral@2: return ret; leo_sobral@2: } leo_sobral@2: leo_sobral@2: static GMythSocket * leo_sobral@2: myth_connect_to_transfer_backend( MythFileTransfer **transfer, guint sock_type ) leo_sobral@2: { leo_sobral@2: GMythSocket *sock = NULL; leo_sobral@2: leo_sobral@2: g_return_val_if_fail( transfer != NULL && *transfer != NULL, NULL ); leo_sobral@2: g_return_val_if_fail( (*transfer)->uri != NULL, NULL ); leo_sobral@2: leo_sobral@2: g_static_mutex_lock (&mutex); leo_sobral@2: leo_sobral@2: gchar *path_dir = myth_uri_getpath( (*transfer)->uri ); leo_sobral@2: //g_print( "\t--> %s: path_dir = %s\n", __FUNCTION__, path_dir ); leo_sobral@2: leo_sobral@2: gchar *stype = g_strdup( "" ); leo_sobral@2: leo_sobral@2: // if ( (*transfer)->live_tv == FALSE ) { leo_sobral@2: leo_sobral@2: sock = gmyth_socket_new(); leo_sobral@2: leo_sobral@2: gmyth_socket_connect( &sock, (*transfer)->hostname->str, (*transfer)->port ); leo_sobral@2: leo_sobral@2: /* leo_sobral@2: } else { leo_sobral@2: sock = (*transfer)->sock; leo_sobral@2: } leo_sobral@2: */ leo_sobral@2: #ifdef MYTHTV_ENABLE_DEBUG leo_sobral@2: leo_sobral@2: g_print( "[%s] --> Creating socket... (%s, %d)\n", __FUNCTION__, (*transfer)->hostname->str, (*transfer)->port ); leo_sobral@2: #endif leo_sobral@2: leo_sobral@2: GMythStringList *strlist = NULL; leo_sobral@2: leo_sobral@2: GString *hostname = g_string_new( myth_uri_gethost( (*transfer)->uri ) ); leo_sobral@2: GString *base_str = g_string_new( "" ); leo_sobral@2: leo_sobral@2: if ( gmyth_socket_check_protocol_version_number (sock, (*transfer)->mythtv_version) ) { leo_sobral@2: leo_sobral@2: if (sock == NULL) { leo_sobral@2: stype = (sock_type==MYTH_PLAYBACK_TYPE) ? "control socket" : "file data socket"; leo_sobral@2: g_printerr( "FileTransfer, open_socket(%s): \n" leo_sobral@2: "\t\t\tCould not connect to server \"%s\" @ port %d\n", stype, leo_sobral@2: (*transfer)->hostname->str, (*transfer)->port ); leo_sobral@2: g_object_unref(sock); leo_sobral@2: g_static_mutex_unlock (&mutex); leo_sobral@2: return NULL; leo_sobral@2: } leo_sobral@2: leo_sobral@2: hostname = gmyth_socket_get_local_hostname(); leo_sobral@2: leo_sobral@2: g_print( "[%s] local hostname = %s\n", __FUNCTION__, hostname->str ); leo_sobral@2: leo_sobral@2: if ( sock_type == MYTH_PLAYBACK_TYPE ) leo_sobral@2: { leo_sobral@2: (*transfer)->control_sock = sock; leo_sobral@2: g_string_printf( base_str, "ANN Playback %s %d", hostname->str, FALSE ); leo_sobral@2: leo_sobral@2: gmyth_socket_send_command( (*transfer)->control_sock, base_str ); leo_sobral@2: GString *resp = gmyth_socket_receive_response( (*transfer)->control_sock ); leo_sobral@2: g_print( "[%s] Got Playback response from %s: %s\n", __FUNCTION__, base_str->str, resp->str ); leo_sobral@2: } leo_sobral@2: else if ( sock_type == MYTH_MONITOR_TYPE ) leo_sobral@2: { leo_sobral@2: (*transfer)->event_sock = sock; leo_sobral@2: g_string_printf( base_str, "ANN Monitor %s %d", hostname->str, TRUE ); leo_sobral@2: leo_sobral@2: gmyth_socket_send_command( (*transfer)->event_sock, base_str ); leo_sobral@2: GString *resp = gmyth_socket_receive_response( (*transfer)->event_sock ); leo_sobral@2: g_print( "[%s] Got Monitor response from %s: %s\n", __FUNCTION__, base_str->str, resp->str ); leo_sobral@2: g_thread_create( myth_init_io_watchers, (void*)(*transfer), FALSE, NULL ); leo_sobral@2: leo_sobral@2: g_printerr( "[%s] Watch listener function to the IO control channel on thread %p.\n", __FUNCTION__, g_thread_self() ); leo_sobral@2: leo_sobral@2: } leo_sobral@2: else if ( sock_type == MYTH_FILETRANSFER_TYPE ) leo_sobral@2: { leo_sobral@2: (*transfer)->sock = sock; leo_sobral@2: strlist = gmyth_string_list_new(); leo_sobral@2: //g_string_printf( base_str, "ANN FileTransfer %s %d %d", hostname->str, leo_sobral@2: // transfer->userreadahead, transfer->retries ); leo_sobral@2: g_string_printf( base_str, "ANN FileTransfer %s", hostname->str ); leo_sobral@2: leo_sobral@2: gmyth_string_list_append_string( strlist, base_str ); leo_sobral@2: gmyth_string_list_append_char_array( strlist, path_dir ); leo_sobral@2: leo_sobral@2: gmyth_socket_write_stringlist( (*transfer)->sock, strlist ); leo_sobral@2: gmyth_socket_read_stringlist( (*transfer)->sock, strlist ); leo_sobral@2: leo_sobral@2: /* socket number, where all the stream data comes from - got from the MythTV remote backend */ leo_sobral@2: (*transfer)->recordernum = gmyth_string_list_get_int( strlist, 1 ); leo_sobral@2: leo_sobral@2: /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */ leo_sobral@2: (*transfer)->filesize = mmyth_util_decode_long_long( strlist, 2 ); leo_sobral@2: leo_sobral@2: printf( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__, leo_sobral@2: (*transfer)->recordernum, (*transfer)->filesize ); leo_sobral@2: leo_sobral@2: if ( (*transfer)->filesize <= 0 ) { leo_sobral@2: g_print( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, (*transfer)->filesize ); leo_sobral@2: g_object_unref(sock); leo_sobral@2: sock = NULL; leo_sobral@2: } leo_sobral@2: } leo_sobral@2: else if ( sock_type == MYTH_RINGBUFFER_TYPE ) leo_sobral@2: { leo_sobral@2: (*transfer)->sock = sock; leo_sobral@2: //myth_file_transfer_spawntv( (*transfer), NULL ); leo_sobral@2: leo_sobral@2: strlist = gmyth_string_list_new(); leo_sobral@2: g_string_printf( base_str, "ANN RingBuffer %s %d", hostname->str, (*transfer)->card_id ); leo_sobral@2: leo_sobral@2: gmyth_socket_send_command( (*transfer)->sock, base_str ); leo_sobral@2: GString *resp = gmyth_socket_receive_response( (*transfer)->sock ); leo_sobral@2: g_print( "[%s] Got RingBuffer response from %s: %s\n", __FUNCTION__, base_str->str, resp->str ); leo_sobral@2: leo_sobral@2: } leo_sobral@2: leo_sobral@2: } leo_sobral@2: leo_sobral@2: printf("[%s] ANN %s sent: %s\n", (sock_type==MYTH_PLAYBACK_TYPE) ? "Playback" : (sock_type==MYTH_FILETRANSFER_TYPE) ? "FileTransfer" : "Monitor", __FUNCTION__, base_str->str); leo_sobral@2: leo_sobral@2: if ( strlist != NULL ) leo_sobral@2: g_object_unref( strlist ); leo_sobral@2: leo_sobral@2: g_static_mutex_unlock (&mutex); leo_sobral@2: leo_sobral@2: return sock; leo_sobral@2: } leo_sobral@2: leo_sobral@2: void leo_sobral@2: myth_file_transfer_spawntv ( MythFileTransfer *file_transfer, leo_sobral@2: GString *tvchain_id ) leo_sobral@2: { leo_sobral@2: GMythStringList *str_list; leo_sobral@2: leo_sobral@2: g_debug ("myth_file_transfer_spawntv.\n"); leo_sobral@2: leo_sobral@2: str_list = gmyth_string_list_new (); leo_sobral@2: leo_sobral@2: g_string_printf( file_transfer->query, "%s %d", MYTHTV_RECORDER_HEADER, leo_sobral@2: file_transfer->card_id ); leo_sobral@2: gmyth_string_list_append_string (str_list, file_transfer->query); leo_sobral@2: gmyth_string_list_append_string (str_list, g_string_new ("SPAWN_LIVETV")); leo_sobral@2: if (tvchain_id!=NULL) { leo_sobral@2: gmyth_string_list_append_string (str_list, tvchain_id); leo_sobral@2: gmyth_string_list_append_int (str_list, FALSE); // PIP = FALSE (0) leo_sobral@2: } leo_sobral@2: leo_sobral@2: gmyth_socket_sendreceive_stringlist ( file_transfer->sock, str_list ); leo_sobral@2: leo_sobral@2: //GString *str = NULL; leo_sobral@2: leo_sobral@2: //if (str_list!=NULL && (str = gmyth_string_list_get_string( str_list, 0 )) != NULL && strcasecmp( str->str, "ok" ) != 0 ) { leo_sobral@2: // g_print( "[%s]\t\tSpawnLiveTV is OK!\n", __FUNCTION__ ); leo_sobral@2: //} leo_sobral@2: if (str_list!=NULL) leo_sobral@2: g_object_unref (str_list); leo_sobral@2: leo_sobral@2: } leo_sobral@2: leo_sobral@2: gboolean leo_sobral@2: myth_file_transfer_is_recording ( MythFileTransfer *file_transfer ) leo_sobral@2: { leo_sobral@2: gboolean ret = TRUE; leo_sobral@2: leo_sobral@2: GMythStringList *str_list = gmyth_string_list_new (); leo_sobral@2: leo_sobral@2: g_debug ( "[%s]\n", __FUNCTION__ ); leo_sobral@2: g_static_mutex_lock (&mutex); leo_sobral@2: leo_sobral@2: g_string_printf( file_transfer->query, "%s %d", MYTHTV_RECORDER_HEADER, leo_sobral@2: file_transfer->rec_id >= 0 ? file_transfer->rec_id : file_transfer->card_id ); leo_sobral@2: gmyth_string_list_append_string (str_list, file_transfer->query); leo_sobral@2: gmyth_string_list_append_string (str_list, g_string_new ("IS_RECORDING")); leo_sobral@2: leo_sobral@2: gmyth_socket_sendreceive_stringlist ( file_transfer->control_sock, str_list ); leo_sobral@2: leo_sobral@2: if ( str_list != NULL && gmyth_string_list_length(str_list) > 0 ) leo_sobral@2: { leo_sobral@2: GString *str = NULL; leo_sobral@2: if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && strcmp( str->str, "bad" )!= 0 ) { leo_sobral@2: gint is_rec = gmyth_string_list_get_int( str_list, 0 ); leo_sobral@2: if ( is_rec != 0 ) leo_sobral@2: ret = TRUE; leo_sobral@2: else leo_sobral@2: ret = FALSE; leo_sobral@2: } leo_sobral@2: } leo_sobral@2: g_print( "[%s] %s, stream is %s being recorded!\n", __FUNCTION__, ret ? "YES" : "NO", ret ? "" : "NOT" ); leo_sobral@2: g_static_mutex_unlock (&mutex); leo_sobral@2: leo_sobral@2: if ( str_list != NULL ) leo_sobral@2: g_object_unref (str_list); leo_sobral@2: leo_sobral@2: return ret; leo_sobral@2: leo_sobral@2: } leo_sobral@2: leo_sobral@2: guint64 leo_sobral@2: myth_file_transfer_get_file_position ( MythFileTransfer *file_transfer ) leo_sobral@2: { leo_sobral@2: guint64 pos = 0; leo_sobral@2: leo_sobral@2: GMythStringList *str_list = gmyth_string_list_new (); leo_sobral@2: leo_sobral@2: g_debug ( "[%s]\n", __FUNCTION__ ); leo_sobral@2: g_static_mutex_lock (&mutex); leo_sobral@2: leo_sobral@2: g_string_printf( file_transfer->query, "%s %d", MYTHTV_RECORDER_HEADER, leo_sobral@2: file_transfer->rec_id >= 0 ? file_transfer->rec_id : file_transfer->card_id ); leo_sobral@2: leo_sobral@2: gmyth_string_list_append_string (str_list, file_transfer->query); leo_sobral@2: gmyth_string_list_append_string (str_list, g_string_new ("GET_FILE_POSITION")); leo_sobral@2: leo_sobral@2: gmyth_socket_sendreceive_stringlist ( file_transfer->control_sock, str_list ); leo_sobral@2: leo_sobral@2: if ( str_list != NULL && gmyth_string_list_length(str_list) > 0 ) leo_sobral@2: { leo_sobral@2: GString *str = NULL; leo_sobral@2: if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && strcmp ( str->str, "bad" ) != 0 ) leo_sobral@2: pos = gmyth_util_decode_long_long( str_list, 0 ); leo_sobral@2: } leo_sobral@2: g_static_mutex_unlock (&mutex); leo_sobral@2: leo_sobral@2: #ifndef MYTHTV_ENABLE_DEBUG leo_sobral@2: leo_sobral@2: g_print( "[%s] Got file position = %llu\n", __FUNCTION__, pos ); leo_sobral@2: #endif leo_sobral@2: if (str_list!=NULL) leo_sobral@2: g_object_unref (str_list); leo_sobral@2: leo_sobral@2: return pos; leo_sobral@2: leo_sobral@2: } leo_sobral@2: leo_sobral@2: glong leo_sobral@2: myth_file_transfer_get_recordernum( MythFileTransfer *transfer ) leo_sobral@2: { leo_sobral@2: return transfer->recordernum; leo_sobral@2: } leo_sobral@2: leo_sobral@2: glong leo_sobral@2: myth_file_transfer_get_filesize( MythFileTransfer *transfer ) leo_sobral@2: { leo_sobral@2: return transfer->filesize; leo_sobral@2: } leo_sobral@2: leo_sobral@2: gboolean leo_sobral@2: myth_file_transfer_isopen( MythFileTransfer *transfer ) leo_sobral@2: { leo_sobral@2: return (transfer->sock != NULL && transfer->control_sock != NULL); leo_sobral@2: } leo_sobral@2: leo_sobral@2: void leo_sobral@2: myth_file_transfer_close( MythFileTransfer *transfer ) leo_sobral@2: { leo_sobral@2: GMythStringList *strlist; leo_sobral@2: leo_sobral@2: if (transfer->control_sock == NULL) leo_sobral@2: return; leo_sobral@2: leo_sobral@2: strlist = gmyth_string_list_new( ); leo_sobral@2: leo_sobral@2: g_string_printf( transfer->query, "%s %d", MYTHTV_QUERY_HEADER, leo_sobral@2: transfer->recordernum ); leo_sobral@2: gmyth_string_list_append_string( strlist, transfer->query ); leo_sobral@2: gmyth_string_list_append_char_array( strlist, "DONE" ); leo_sobral@2: leo_sobral@2: leo_sobral@2: if ( gmyth_socket_sendreceive_stringlist(transfer->control_sock, strlist) <= 0 ) leo_sobral@2: { leo_sobral@2: g_printerr( "Remote file timeout.\n" ); leo_sobral@2: } leo_sobral@2: leo_sobral@2: if (transfer->sock) leo_sobral@2: { leo_sobral@2: g_object_unref( transfer->sock ); leo_sobral@2: transfer->sock = NULL; leo_sobral@2: } leo_sobral@2: leo_sobral@2: if (transfer->control_sock) leo_sobral@2: { leo_sobral@2: g_object_unref( transfer->control_sock ); leo_sobral@2: transfer->control_sock = NULL; leo_sobral@2: } leo_sobral@2: leo_sobral@2: } leo_sobral@2: leo_sobral@2: void leo_sobral@2: myth_file_transfer_reset_controlsock( MythFileTransfer *transfer ) leo_sobral@2: { leo_sobral@2: if (transfer->control_sock == NULL) leo_sobral@2: { leo_sobral@2: g_printerr( "myth_file_transfer_reset_controlsock(): Called with no control socket" ); leo_sobral@2: return; leo_sobral@2: } leo_sobral@2: leo_sobral@2: GString *str = gmyth_socket_receive_response( transfer->control_sock ); leo_sobral@2: leo_sobral@2: g_string_free( str, TRUE ); leo_sobral@2: } leo_sobral@2: leo_sobral@2: void leo_sobral@2: myth_file_transfer_reset_sock( MythFileTransfer *transfer ) leo_sobral@2: { leo_sobral@2: if ( transfer->sock == NULL ) leo_sobral@2: { leo_sobral@2: g_printerr( "myth_file_transfer_reset_sock(): Called with no raw socket" ); leo_sobral@2: return; leo_sobral@2: } leo_sobral@2: leo_sobral@2: GString *str = gmyth_socket_receive_response( transfer->sock ); leo_sobral@2: leo_sobral@2: g_string_free( str, TRUE ); leo_sobral@2: } leo_sobral@2: leo_sobral@2: void leo_sobral@2: myth_file_transfer_reset( MythFileTransfer *transfer ) leo_sobral@2: { leo_sobral@2: myth_file_transfer_reset_controlsock( transfer ); leo_sobral@2: myth_file_transfer_reset_sock( transfer ); leo_sobral@2: } leo_sobral@2: leo_sobral@2: guint64 leo_sobral@2: myth_file_transfer_seek(MythFileTransfer *transfer, guint64 pos, gint whence) leo_sobral@2: { leo_sobral@2: if (transfer->sock == NULL) leo_sobral@2: { leo_sobral@2: g_printerr( "[%s] myth_file_transfer_seek(): Called with no socket", __FUNCTION__ ); leo_sobral@2: return 0; leo_sobral@2: } leo_sobral@2: leo_sobral@2: if (transfer->control_sock == NULL) leo_sobral@2: return 0; leo_sobral@2: leo_sobral@2: // if (!controlSock->isOpen() || controlSock->error()) leo_sobral@2: // return 0; leo_sobral@2: leo_sobral@2: GMythStringList *strlist = gmyth_string_list_new(); leo_sobral@2: g_string_printf (transfer->query, "%s %d", MYTHTV_QUERY_HEADER, transfer->recordernum); rosfran@30: gmyth_string_list_append_string( strlist, transfer->query ); leo_sobral@2: gmyth_string_list_append_char_array( strlist, "SEEK" ); leo_sobral@2: gmyth_string_list_append_uint64( strlist, pos ); rosfran@30: rosfran@30: gmyth_string_list_append_int( strlist, whence ); leo_sobral@2: leo_sobral@2: if (pos > 0 ) leo_sobral@2: gmyth_string_list_append_uint64( strlist, pos ); leo_sobral@2: else leo_sobral@2: gmyth_string_list_append_uint64( strlist, transfer->readposition ); rosfran@30: leo_sobral@2: gmyth_socket_sendreceive_stringlist( transfer->control_sock, strlist ); leo_sobral@2: leo_sobral@2: guint64 retval = gmyth_string_list_get_uint64(strlist, 0); leo_sobral@2: transfer->readposition = retval; leo_sobral@2: g_print( "[%s] got reading position pointer from the streaming = %llu\n", leo_sobral@2: __FUNCTION__, retval ); leo_sobral@2: leo_sobral@2: //myth_file_transfer_reset( transfer ); leo_sobral@2: leo_sobral@2: return retval; leo_sobral@2: } leo_sobral@2: leo_sobral@2: static gboolean leo_sobral@2: myth_control_sock_listener( GIOChannel *source, GIOCondition condition, gpointer data ) leo_sobral@2: { leo_sobral@2: leo_sobral@2: GIOStatus ret; leo_sobral@2: GError *err = NULL; leo_sobral@2: gchar *msg = g_strdup(""); leo_sobral@2: leo_sobral@2: gsize len; leo_sobral@2: if (condition & G_IO_HUP) leo_sobral@2: g_error ("Read end of pipe died!\n"); leo_sobral@2: ret = g_io_channel_read_line ( source, &msg, &len, NULL, &err); leo_sobral@2: if ( ret == G_IO_STATUS_ERROR ) leo_sobral@2: g_error ("[%s] Error reading: %s\n", __FUNCTION__, err != NULL ? err->message : "" ); leo_sobral@2: 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 : "" ); leo_sobral@2: if ( msg != NULL ) leo_sobral@2: g_free (msg); leo_sobral@2: leo_sobral@2: return TRUE; leo_sobral@2: leo_sobral@2: } leo_sobral@2: leo_sobral@2: static void* leo_sobral@2: myth_init_io_watchers( void *data ) leo_sobral@2: { leo_sobral@2: MythFileTransfer *transfer = (MythFileTransfer*)data; leo_sobral@2: GMainContext *context = g_main_context_new(); leo_sobral@2: GMainLoop *loop = g_main_loop_new( NULL, FALSE ); leo_sobral@2: leo_sobral@2: GSource *source = NULL; leo_sobral@2: leo_sobral@2: if ( transfer->event_sock->sd_io_ch != NULL ) leo_sobral@2: source = g_io_create_watch( transfer->event_sock->sd_io_ch, G_IO_IN | G_IO_HUP ); leo_sobral@2: leo_sobral@2: g_source_set_callback ( source, (GSourceFunc)myth_control_sock_listener, NULL, NULL ); leo_sobral@2: leo_sobral@2: g_source_attach( source, context ); leo_sobral@2: leo_sobral@2: if (source==NULL) leo_sobral@2: g_printerr( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ ); leo_sobral@2: leo_sobral@2: g_main_loop_run( loop ); leo_sobral@2: leo_sobral@2: g_source_unref( source ); leo_sobral@2: leo_sobral@2: g_main_loop_unref( loop ); leo_sobral@2: leo_sobral@2: g_main_context_unref( context ); leo_sobral@2: leo_sobral@2: return NULL; leo_sobral@2: } leo_sobral@2: leo_sobral@2: gint leo_sobral@2: myth_file_transfer_read(MythFileTransfer *transfer, void *data, gint size, gboolean read_unlimited) leo_sobral@2: { leo_sobral@2: gint recv = 0; leo_sobral@2: gsize bytes_read = 0; leo_sobral@2: leo_sobral@2: gint sent = 0; leo_sobral@2: //guint zerocnt = 0; leo_sobral@2: gboolean response = FALSE; leo_sobral@2: leo_sobral@2: GIOChannel *io_channel; leo_sobral@2: GIOChannel *io_channel_control; leo_sobral@2: leo_sobral@2: GIOCondition io_cond; leo_sobral@2: GIOCondition io_cond_control; leo_sobral@2: GIOStatus io_status = G_IO_STATUS_NORMAL, io_status_control = G_IO_STATUS_NORMAL; leo_sobral@2: leo_sobral@2: gint buf_len = MYTHTV_BUFFER_SIZE; leo_sobral@2: leo_sobral@2: GMythStringList *strlist = NULL; leo_sobral@2: GError *error = NULL; leo_sobral@2: leo_sobral@2: gchar *trash = g_strdup(""); leo_sobral@2: leo_sobral@2: g_return_val_if_fail ( data != NULL, -2 ); leo_sobral@2: leo_sobral@2: /* gets the size of the entire file, if the size requested is lesser than 0 */ leo_sobral@2: if ( size <= 0 ) leo_sobral@2: size = transfer->filesize; leo_sobral@2: leo_sobral@2: io_channel = transfer->sock->sd_io_ch; leo_sobral@2: io_channel_control = transfer->control_sock->sd_io_ch; leo_sobral@2: leo_sobral@2: //g_io_channel_set_flags( io_channel, G_IO_FLAG_APPEND | leo_sobral@2: // G_IO_STATUS_AGAIN | G_IO_FLAG_IS_READABLE | G_IO_FLAG_IS_WRITEABLE | leo_sobral@2: // G_IO_FLAG_IS_SEEKABLE, NULL ); leo_sobral@2: leo_sobral@2: io_status = g_io_channel_set_encoding( io_channel, NULL, &error ); leo_sobral@2: if ( io_status == G_IO_STATUS_NORMAL ) leo_sobral@2: g_print( "[%s] Setting encoding to binary data socket).\n", __FUNCTION__ ); leo_sobral@2: rosfran@30: leo_sobral@2: io_cond = g_io_channel_get_buffer_condition( io_channel ); leo_sobral@2: leo_sobral@2: io_cond_control = g_io_channel_get_buffer_condition( io_channel ); leo_sobral@2: leo_sobral@2: if ( transfer->sock == NULL || ( io_status == G_IO_STATUS_ERROR ) ) leo_sobral@2: { leo_sobral@2: g_printerr( "myth_file_transfer_read(): Called with no raw socket.\n" ); leo_sobral@2: recv = -1; leo_sobral@2: goto cleanup; leo_sobral@2: } leo_sobral@2: leo_sobral@2: if ( transfer->control_sock == NULL || ( io_status_control == G_IO_STATUS_ERROR ) ) leo_sobral@2: { leo_sobral@2: g_printerr( "myth_file_transfer_read(): Called with no control socket.\n" ); leo_sobral@2: recv = -1; leo_sobral@2: goto cleanup; leo_sobral@2: } leo_sobral@2: leo_sobral@2: /* leo_sobral@2: if (!controlSock->isOpen() || controlSock->error()) leo_sobral@2: return -1; leo_sobral@2: */ leo_sobral@2: leo_sobral@2: if ( ( io_cond & G_IO_IN ) != 0 ) { leo_sobral@2: do leo_sobral@2: { leo_sobral@2: leo_sobral@2: io_status = g_io_channel_read_line( io_channel, &trash, &bytes_read, NULL, &error); leo_sobral@2: leo_sobral@2: g_print( "[%s] cleaning buffer on IO binary channel... (%s)\n", __FUNCTION__, trash ); leo_sobral@2: io_cond = g_io_channel_get_buffer_condition( io_channel ); leo_sobral@2: leo_sobral@2: } while ( ( io_cond & G_IO_IN ) != 0 && ( io_status != G_IO_STATUS_ERROR ) ); leo_sobral@2: leo_sobral@2: if ( trash!= NULL ) leo_sobral@2: g_free( trash ); leo_sobral@2: } leo_sobral@2: leo_sobral@2: if ( ( io_cond_control & G_IO_IN ) != 0 ) { leo_sobral@2: GMythStringList *strlist_tmp = gmyth_string_list_new(); leo_sobral@2: gmyth_socket_read_stringlist( transfer->control_sock, strlist_tmp ); leo_sobral@2: g_object_unref( strlist_tmp ); leo_sobral@2: } leo_sobral@2: leo_sobral@2: wait_to_transfer = 0; leo_sobral@2: rosfran@30: //while ( transfer->live_tv && ( myth_file_transfer_get_file_position( transfer ) < 4096 ) && rosfran@30: // wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS ) rosfran@30: // g_usleep( 1000*50 ); /* waits just for 2/10 second */ leo_sobral@2: leo_sobral@2: //g_thread_create( myth_init_io_watchers, (void*)transfer, FALSE, NULL ); leo_sobral@2: //g_printerr( "[%s] Watch listener function to the IO control channel on thread %p.\n", __FUNCTION__, g_thread_self() ); leo_sobral@2: rosfran@30: //g_static_mutex_lock (&mutex); rosfran@30: //strlist = gmyth_string_list_new(); leo_sobral@2: rosfran@31: g_string_printf ( transfer->query, "%s %d", rosfran@31: /*transfer->live_tv ? MYTHTV_RECORDER_HEADER :*/ MYTHTV_QUERY_HEADER, leo_sobral@2: /* transfer->live_tv ? transfer->card_id :*/ transfer->recordernum ); // transfer->recordernum leo_sobral@2: g_print( "\t[%s] Transfer_query = %s\n", __FUNCTION__, transfer->query->str ); rosfran@30: leo_sobral@2: strlist = gmyth_string_list_new(); leo_sobral@2: rosfran@30: gmyth_string_list_append_char_array( strlist, transfer->query->str ); rosfran@31: gmyth_string_list_append_char_array( strlist, rosfran@31: /*transfer->live_tv ? "REQUEST_BLOCK_RINGBUF" :*/ "REQUEST_BLOCK" ); leo_sobral@2: gmyth_string_list_append_int( strlist, size ); leo_sobral@2: leo_sobral@2: gmyth_socket_write_stringlist( transfer->control_sock, strlist ); leo_sobral@2: sent = size; rosfran@30: //g_static_mutex_unlock( &mutex ); leo_sobral@2: //data = (void*)g_new0( gchar, size ); leo_sobral@2: leo_sobral@2: g_io_channel_flush( io_channel_control, NULL ); rosfran@30: //g_io_channel_flush( io_channel, NULL ); rosfran@30: rosfran@30: g_static_mutex_lock( &mutex ); leo_sobral@2: leo_sobral@2: io_cond = g_io_channel_get_buffer_condition( io_channel ); leo_sobral@2: leo_sobral@2: while ( ( recv < sent ) )//&& ( io_cond & G_IO_IN ) != 0 ) leo_sobral@2: { leo_sobral@2: do leo_sobral@2: { leo_sobral@2: //while ( ( io_cond & G_IO_IN ) == 0 ) { leo_sobral@2: //usleep(200); leo_sobral@2: // leo_sobral@2: //io_cond = g_io_channel_get_buffer_condition( io_channel ); rosfran@31: //g_static_mutex_lock( &mutex ); leo_sobral@2: leo_sobral@2: buf_len = ( sent - recv ) > MYTHTV_BUFFER_SIZE ? MYTHTV_BUFFER_SIZE : ( sent - recv ); leo_sobral@2: leo_sobral@2: io_status = g_io_channel_read_chars( io_channel, data + recv, rosfran@30: buf_len, &bytes_read, &error ); rosfran@31: rosfran@31: //g_static_mutex_unlock( &mutex ); leo_sobral@2: /* leo_sobral@2: GString *sss = g_string_new(""); leo_sobral@2: sss = g_string_append_len( sss, (gchar*)data+recv, bytes_read ); leo_sobral@2: leo_sobral@2: g_print( "[%s] Reading buffer (length = %d)\n", __FUNCTION__, bytes_read); leo_sobral@2: */ leo_sobral@2: if ( bytes_read > 0 ) leo_sobral@2: { leo_sobral@2: if ( bytes_read <= buf_len ) leo_sobral@2: recv += bytes_read; leo_sobral@2: } leo_sobral@2: leo_sobral@2: if ( io_status == G_IO_STATUS_EOF ) { leo_sobral@2: g_printerr( "[%s] got EOS!", __FUNCTION__ ); leo_sobral@2: break; leo_sobral@2: } else if ( io_status == G_IO_STATUS_ERROR ) { leo_sobral@2: g_printerr( "[%s] myth_file_transfer_read(): socket error.\n", __FUNCTION__ ); leo_sobral@2: break; leo_sobral@2: } leo_sobral@2: leo_sobral@2: /* increase buffer size, to allow get more data (do not obey to the buffer size) */ leo_sobral@2: if ( read_unlimited == TRUE ) { leo_sobral@2: //if ( recv > buf_len ) leo_sobral@2: // sent += (bytes_read - buf_len) + 1; leo_sobral@2: } leo_sobral@2: if ( bytes_read == buf_len ) leo_sobral@2: break; leo_sobral@2: leo_sobral@2: /* verify if the input (read) buffer is ready to receive data */ leo_sobral@2: io_cond = g_io_channel_get_buffer_condition( io_channel ); leo_sobral@2: leo_sobral@2: g_print( "[%s]\t io_cond %s prepared for reading! (G_IO_IN) !!!\n\n", __FUNCTION__, leo_sobral@2: ( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" ); leo_sobral@2: leo_sobral@2: } while ( recv < sent && ( ( io_cond & G_IO_IN ) != 0 ) && ( io_status == G_IO_STATUS_NORMAL ) ); leo_sobral@2: leo_sobral@2: io_cond_control = g_io_channel_get_buffer_condition( io_channel_control ); leo_sobral@2: if ( ( io_status == G_IO_STATUS_EOF ) || ( ( io_cond_control & G_IO_IN ) != 0 ) ) leo_sobral@2: { leo_sobral@2: gmyth_socket_read_stringlist( transfer->control_sock, strlist ); leo_sobral@2: sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error leo_sobral@2: g_print( "[%s]\t sent = %d, io_cond %s prepared for reading! (G_IO_IN) !!!\n\n", __FUNCTION__, rosfran@31: sent, ( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" ); leo_sobral@2: response = TRUE; rosfran@31: break; leo_sobral@2: } leo_sobral@2: } leo_sobral@2: leo_sobral@2: if ( ( ( error == NULL ) && ( response == FALSE ) ) || leo_sobral@2: ( io_status == G_IO_STATUS_EOF ) || ( ( io_cond & G_IO_IN ) == 0 ) ) leo_sobral@2: { leo_sobral@2: if ( gmyth_socket_read_stringlist( transfer->control_sock, strlist ) > 0 ) leo_sobral@2: { leo_sobral@2: if ( strlist != NULL && gmyth_string_list_length(strlist) > 0 ) { leo_sobral@2: sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error rosfran@31: g_print( "[%s]\t sent = %d, raw buffer I/O socket %s prepared for reading! (G_IO_IN) !!!\n\n", __FUNCTION__, leo_sobral@2: sent, ( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" ); leo_sobral@2: } leo_sobral@2: } leo_sobral@2: else leo_sobral@2: { leo_sobral@2: g_printerr ( "myth_file_transfer_read(): No response from control socket."); rosfran@31: recv = -1; rosfran@31: } rosfran@31: rosfran@31: } else if ( error!=NULL ) { rosfran@31: g_printerr( "[%s] Error occurred: (%d, %s)\n", __FUNCTION__, error->code, error->message ); rosfran@31: //g_error_free( error ); leo_sobral@2: } leo_sobral@2: leo_sobral@2: cleanup: rosfran@31: g_static_mutex_unlock (&mutex); leo_sobral@2: leo_sobral@2: if ( trash != NULL ) leo_sobral@2: g_free( trash ); leo_sobral@2: leo_sobral@2: if ( strlist != NULL ) leo_sobral@2: g_object_unref( strlist ); leo_sobral@2: leo_sobral@2: g_print( "myth_file_transfer_read(): reqd=%d, rcvd=%d, rept=%d, "\ leo_sobral@2: "(rcvd and rept MUST be the same!)\n", size, leo_sobral@2: recv, sent ); leo_sobral@2: leo_sobral@2: //if ( sent != recv ) { leo_sobral@2: // recv = -1; leo_sobral@2: //} leo_sobral@2: rosfran@30: if ( error != NULL ) { rosfran@31: g_printerr( "Cleaning-up ERROR: %s [msg = %s, code = %d]\n", __FUNCTION__, error->message, leo_sobral@2: error->code ); rosfran@30: g_error_free( error ); rosfran@30: } leo_sobral@2: leo_sobral@2: return recv; leo_sobral@2: } leo_sobral@2: rosfran@31: void leo_sobral@2: myth_file_transfer_settimeout( MythFileTransfer *transfer, gboolean fast ) leo_sobral@2: { leo_sobral@2: leo_sobral@2: GMythStringList *strlist = NULL; leo_sobral@2: leo_sobral@2: if ( transfer->timeoutisfast == fast ) leo_sobral@2: return; leo_sobral@2: leo_sobral@2: if ( transfer->sock == NULL ) leo_sobral@2: { leo_sobral@2: g_printerr( "myth_file_transfer_settimeout(): Called with no socket" ); leo_sobral@2: return; leo_sobral@2: } leo_sobral@2: leo_sobral@2: if ( transfer->control_sock == NULL ) leo_sobral@2: return; leo_sobral@2: leo_sobral@2: strlist = gmyth_string_list_new(); leo_sobral@2: gmyth_string_list_append_string( strlist, transfer->query ); leo_sobral@2: gmyth_string_list_append_char_array( strlist, "SET_TIMEOUT" ); leo_sobral@2: gmyth_string_list_append_int( strlist, fast ); leo_sobral@2: leo_sobral@2: gmyth_socket_write_stringlist( transfer->control_sock, strlist ); leo_sobral@2: gmyth_socket_read_stringlist( transfer->control_sock, strlist ); leo_sobral@2: leo_sobral@2: transfer->timeoutisfast = fast; leo_sobral@2: leo_sobral@2: } leo_sobral@2: leo_sobral@2: #ifdef DO_TESTING leo_sobral@2: leo_sobral@2: int leo_sobral@2: main( int argc, char *argv[] ) leo_sobral@2: { leo_sobral@2: g_type_init(); leo_sobral@2: leo_sobral@2: MythFileTransfer *file_transfer = myth_file_transfer_new( 1, leo_sobral@2: g_string_new("myth://192.168.1.109:6543/jshks.nuv"), -1, MYTHTV_VERSION ); leo_sobral@2: myth_file_transfer_setup( &file_transfer ); leo_sobral@2: gchar *data = g_strdup(""); leo_sobral@2: leo_sobral@2: gint num = myth_file_transfer_read( file_transfer, data, -1 ); leo_sobral@2: leo_sobral@2: return 0; leo_sobral@2: leo_sobral@2: } leo_sobral@2: leo_sobral@2: #endif