# HG changeset patch # User rosfran # Date 1172779432 0 # Node ID 8ce4806990850ad637684fc3ca7cab82f48461ec # Parent e0dfe4bd83a20c38d2b5158ee58f2feae6eccf3f [svn r386] Put a mutex on the GMythFileTransfer send/receive transfer methods. Added timeout message to the LiveTV. diff -r e0dfe4bd83a2 -r 8ce480699085 gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Thu Mar 01 17:57:42 2007 +0000 +++ b/gmyth/src/gmyth_file_transfer.c Thu Mar 01 20:03:52 2007 +0000 @@ -109,9 +109,9 @@ void gmyth_file_transfer_close( GMythFileTransfer *transfer ); -static gboolean myth_control_acquire_context( gboolean do_wait ); +static gboolean myth_control_acquire_context( GMythFileTransfer *transfer, gboolean do_wait ); -static gboolean myth_control_release_context( ); +static gboolean myth_control_release_context( GMythFileTransfer *transfer ); G_DEFINE_TYPE(GMythFileTransfer, gmyth_file_transfer, G_TYPE_OBJECT) @@ -290,6 +290,8 @@ gboolean ret = TRUE; g_return_val_if_fail (transfer != NULL, FALSE ); + + myth_control_acquire_context( transfer, TRUE ); base_str = g_string_new (""); @@ -365,6 +367,8 @@ cleanup: + myth_control_release_context( transfer ); + if ( strlist != NULL ) g_object_unref( strlist ); @@ -404,6 +408,8 @@ g_return_val_if_fail (transfer->control_sock != NULL, FALSE); g_return_val_if_fail (transfer->sock != NULL, FALSE); + + myth_control_acquire_context( transfer, TRUE ); strlist = gmyth_string_list_new(); query = g_string_new (GMYTHTV_QUERY_HEADER); @@ -414,6 +420,8 @@ gmyth_socket_write_stringlist( transfer->control_sock, strlist ); gmyth_socket_read_stringlist( transfer->control_sock, strlist ); + + myth_control_release_context( transfer ); g_string_free (query, TRUE); g_object_unref (strlist); @@ -428,6 +436,8 @@ GString *query; g_return_if_fail (transfer->control_sock != NULL); + + myth_control_acquire_context( transfer, TRUE ); strlist = gmyth_string_list_new( ); query = g_string_new (GMYTHTV_QUERY_HEADER); @@ -438,7 +448,7 @@ if ( gmyth_socket_sendreceive_stringlist(transfer->control_sock, strlist) <= 0 ) { // fixme: time out??? - g_printerr( "Remote file timeout.\n" ); + gmyth_debug ( "Remote file timeout.\n" ); } g_string_free (query, TRUE); @@ -453,7 +463,9 @@ g_object_unref( transfer->control_sock ); transfer->control_sock = NULL; } - + + myth_control_release_context( transfer ); + } gint64 @@ -469,7 +481,7 @@ query = g_string_new (GMYTHTV_QUERY_HEADER); g_string_append_printf (query, "%d", transfer->file_id); - myth_control_acquire_context( TRUE ); + myth_control_acquire_context( transfer, TRUE ); gmyth_string_list_append_string( strlist, query ); gmyth_string_list_append_char_array( strlist, "SEEK" ); @@ -489,18 +501,18 @@ gmyth_debug ( "[%s] got reading position pointer from the streaming = %lld\n", __FUNCTION__, retval ); - myth_control_release_context( ); + myth_control_release_context( transfer ); return retval; } static gboolean -myth_control_acquire_context( gboolean do_wait ) +myth_control_acquire_context( GMythFileTransfer *transfer, gboolean do_wait ) { gboolean ret = TRUE; //guint max_iter = 50; - //g_mutex_lock( mutex ); + g_mutex_lock( transfer->mutex ); //while ( !has_io_access ) // g_cond_wait( io_watcher_cond, mutex ); @@ -523,7 +535,7 @@ } static gboolean -myth_control_release_context( ) +myth_control_release_context( GMythFileTransfer *transfer ) { gboolean ret = TRUE; @@ -537,7 +549,7 @@ //g_cond_broadcast( io_watcher_cond ); - //g_mutex_unlock( mutex ); + g_mutex_unlock( transfer->mutex ); return ret; } @@ -591,7 +603,7 @@ /* send requests to the maximum number of REQUEST_BLOCK messages */ guint max_tries = 5; - myth_control_acquire_context( TRUE ); + myth_control_acquire_context( transfer, TRUE ); while (total_read == 0 && --max_tries > 0) { GMythStringList *strlist = gmyth_string_list_new(); @@ -676,7 +688,7 @@ } /* if */ - myth_control_release_context( ); + myth_control_release_context( transfer ); g_string_free (query, TRUE); if ( error != NULL ) { @@ -710,7 +722,6 @@ transfer->priv->livetv = livetv; transfer->priv->do_next_program_chain = TRUE; - //g_object_unref( transfer ); } gboolean @@ -721,19 +732,26 @@ g_return_val_if_fail (transfer->sock != NULL, FALSE); g_return_val_if_fail (transfer->control_sock != NULL, FALSE); - -// if ( transfer->timeoutisfast == fast ) -// return; + + myth_control_acquire_context( transfer, TRUE ); strlist = gmyth_string_list_new(); gmyth_string_list_append_char_array( strlist, GMYTHTV_QUERY_HEADER ); gmyth_string_list_append_char_array( strlist, "SET_TIMEOUT" ); gmyth_string_list_append_int( strlist, fast ); - gmyth_socket_write_stringlist( transfer->control_sock, strlist ); - gmyth_socket_read_stringlist( transfer->control_sock, strlist ); + gint strlist_len = gmyth_socket_sendreceive_stringlist( transfer->control_sock, + strlist ); + + if ( strlist_len > 0 ) + gmyth_debug( "Yes, timeout was changed: %s.", gmyth_string_list_get_char_array( strlist, 0 ) ); + else + gmyth_debug( "Timeout cannot be changed!" ); + + myth_control_release_context( transfer ); -// transfer->timeoutisfast = fast; + gmyth_debug ( "%s setting timeout flag of this file transfer = %s\n", + strlist_len > 0 ? "Yes," : "NOT", fast ? "FAST" : "NOT FAST" ); return TRUE; } diff -r e0dfe4bd83a2 -r 8ce480699085 gmyth/src/gmyth_livetv.c --- a/gmyth/src/gmyth_livetv.c Thu Mar 01 17:57:42 2007 +0000 +++ b/gmyth/src/gmyth_livetv.c Thu Mar 01 20:03:52 2007 +0000 @@ -399,7 +399,7 @@ while (wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && (gmyth_recorder_is_recording (livetv->recorder) == FALSE)) - g_usleep (50); + g_usleep (800); if ( channel != NULL ) { @@ -421,7 +421,7 @@ } /* if - changes the channel number */ - sleep (8); /* FIXME: this is evil (tpm) */ + sleep (2); /* FIXME: this is evil (tpm) */ } /* DEBUG message */