# HG changeset patch # User rosfran # Date 1171405988 0 # Node ID 5486e606498bcdda8ef12c04c963031e6f4c964b # Parent f7b40eb795c2895bdb8137acf38062f6260dddc7 [svn r358] Fixes on the GMythProgramInfo attributes, changes all references from GStaticMutex to GMutex. diff -r f7b40eb795c2 -r 5486e606498b gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Mon Feb 12 17:56:41 2007 +0000 +++ b/gmyth/src/gmyth_file_transfer.c Tue Feb 13 22:33:08 2007 +0000 @@ -253,12 +253,14 @@ g_return_val_if_fail (transfer != NULL, FALSE); g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE); + /* if (transfer->filename != NULL) { g_free (transfer->filename); transfer->filename = NULL; } + */ transfer->filename = g_strdup( filename ); @@ -268,6 +270,7 @@ gmyth_debug ("Connection to backend failed (Control Socket).\n"); ret = FALSE; } + } else { g_warning("Remote transfer control socket already created.\n"); } @@ -291,70 +294,85 @@ base_str = g_string_new (""); /* Creates the control socket */ + if (transfer->control_sock != NULL) { g_object_unref (transfer->control_sock); transfer->control_sock = NULL; } + + //if ( NULL == transfer->control_sock ) + //{ + transfer->control_sock = gmyth_socket_new(); - transfer->control_sock = gmyth_socket_new(); - - // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version - if (!gmyth_socket_connect_to_backend (transfer->control_sock, - transfer->backend_info->hostname, transfer->backend_info->port, TRUE)) { - - g_object_unref (transfer->control_sock); - transfer->control_sock = NULL; - return FALSE; - } + // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version + if (!gmyth_socket_connect_to_backend (transfer->control_sock, + transfer->backend_info->hostname, transfer->backend_info->port, TRUE)) { + + g_object_unref (transfer->control_sock); + transfer->control_sock = NULL; + return FALSE; + } + + //} /* Creates the data socket */ if (transfer->sock != NULL) { g_object_unref (transfer->sock); transfer->sock = NULL; - } - - transfer->sock = gmyth_socket_new (); - gmyth_socket_connect (transfer->sock, transfer->backend_info->hostname, transfer->backend_info->port); - gmyth_debug("Connecting file transfer... (%s, %d)", transfer->backend_info->hostname, transfer->backend_info->port); - - strlist = gmyth_string_list_new(); - hostname = gmyth_socket_get_local_hostname(); - gmyth_debug( "[%s] MythTV version (from backend) = %d.\n", __FUNCTION__, transfer->control_sock->mythtv_version ); - if ( transfer->control_sock->mythtv_version > 26 ) - g_string_printf( base_str, "ANN FileTransfer %s 1 -1", hostname->str); - else - g_string_printf( base_str, "ANN FileTransfer %s", hostname->str); - - gmyth_string_list_append_string (strlist, base_str ); - gmyth_string_list_append_char_array (strlist, transfer->filename); - - gmyth_socket_write_stringlist (transfer->sock, strlist ); - gmyth_socket_read_stringlist (transfer->sock, strlist ); - - /* file identification used in future file transfer requests to backend */ - transfer->file_id = 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 = gmyth_util_decode_long_long( strlist, 2 ); - - gmyth_debug ( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__, - transfer->file_id, transfer->filesize ); - - if (transfer->filesize < 0 ) { - gmyth_debug ( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, transfer->filesize ); - g_object_unref (transfer->sock); - transfer->sock = NULL; - ret = FALSE; - goto cleanup; - } + } + + //if ( NULL == transfer->sock ) { + transfer->sock = gmyth_socket_new (); + gmyth_socket_connect (transfer->sock, transfer->backend_info->hostname, transfer->backend_info->port); + gmyth_debug("Connecting file transfer... (%s, %d)", transfer->backend_info->hostname, transfer->backend_info->port); + //} + + if ( transfer->control_sock != NULL ) + { + + strlist = gmyth_string_list_new(); + hostname = gmyth_socket_get_local_hostname(); + gmyth_debug( "[%s] MythTV version (from backend) = %d.\n", __FUNCTION__, transfer->control_sock->mythtv_version ); + if ( transfer->control_sock->mythtv_version > 26 ) + g_string_printf( base_str, "ANN FileTransfer %s 1 -1", hostname->str); + else + g_string_printf( base_str, "ANN FileTransfer %s", hostname->str); + + gmyth_string_list_append_string (strlist, base_str ); + gmyth_string_list_append_char_array (strlist, transfer->filename); + + gmyth_socket_write_stringlist (transfer->sock, strlist ); + gmyth_socket_read_stringlist (transfer->sock, strlist ); + + /* file identification used in future file transfer requests to backend */ + transfer->file_id = 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 = gmyth_util_decode_long_long( strlist, 2 ); + + gmyth_debug ( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__, + transfer->file_id, transfer->filesize ); + + if (transfer->filesize < 0 ) { + gmyth_debug ( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, transfer->filesize ); + g_object_unref (transfer->sock); + transfer->sock = NULL; + ret = FALSE; + goto cleanup; + } + + } /* if - Control Socket is not equals to NULL? */ cleanup: if ( strlist != NULL ) g_object_unref( strlist ); - - g_string_free (base_str, TRUE); - g_string_free (hostname, TRUE); + + if ( base_str != NULL ) + g_string_free (base_str, TRUE); + + if ( hostname != NULL ) + g_string_free (hostname, TRUE); return ret; } @@ -633,24 +651,27 @@ transfer->priv->do_next_program_chain ) { - total_read = GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN; + total_read = GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN; - g_mutex_lock( transfer->mutex ); + //g_mutex_lock( transfer->mutex ); - ret = gmyth_livetv_next_program_chain( transfer->priv->livetv ); + //ret = gmyth_livetv_next_program_chain( transfer->priv->livetv ); + GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info( transfer->priv->livetv->recorder ); - if ( transfer->priv->livetv->proginfo != NULL && - transfer->priv->livetv->proginfo->pathname != NULL && - g_ascii_strcasecmp( transfer->priv->livetv->proginfo->pathname->str, transfer->filename ) != 0 ) - ret = gmyth_file_transfer_open ( transfer, transfer->priv->livetv->proginfo->pathname->str ); + if ( prog_info != NULL && prog_info->pathname != NULL && strlen( prog_info->pathname->str ) > 0 && + g_ascii_strcasecmp( prog_info->pathname->str, transfer->filename ) != 0 ) + ret = gmyth_file_transfer_open ( transfer, g_strrstr( prog_info->pathname->str, "/" ) ); - g_mutex_unlock( transfer->mutex ); + if ( prog_info != NULL ) + g_object_unref( prog_info ); + + //g_mutex_unlock( transfer->mutex ); if ( !ret ) - gmyth_debug( "Cannot change to the next program chain!" ); + gmyth_debug( "Cannot change to the next program info!" ); else - gmyth_debug( "OK!!! MOVED to the next program chain [%s]!", - (gmyth_tvchain_get_id( transfer->priv->livetv->tvchain ))->str ); + gmyth_debug( "OK!!! MOVED to the next program info [%s]!", + transfer->filename ); } } /* if */ diff -r f7b40eb795c2 -r 5486e606498b gmyth/src/gmyth_livetv.c --- a/gmyth/src/gmyth_livetv.c Mon Feb 12 17:56:41 2007 +0000 +++ b/gmyth/src/gmyth_livetv.c Tue Feb 13 22:33:08 2007 +0000 @@ -175,9 +175,11 @@ if ( live_tv->file_transfer != NULL ) { gmyth_debug( "Emitting signal to the FileTransfer... [ \"program-info-changed \" ]" ); + /* GMythProgramInfo* prog_info = gmyth_recorder_get_current_program_info( live_tv->recorder ); if ( prog_info != NULL ) live_tv->proginfo = prog_info; + */ gmyth_file_transfer_emit_program_info_changed_signal( live_tv->file_transfer, msg_code, (gpointer)live_tv ); @@ -198,9 +200,11 @@ if ( live_tv->file_transfer != NULL ) { gmyth_debug( "Emitting signal to the FileTransfer... [ \"backend-done-recording\" ]" ); + /* GMythProgramInfo* prog_info = gmyth_recorder_get_current_program_info( live_tv->recorder ); if ( prog_info != NULL ) live_tv->proginfo = prog_info; + */ gmyth_file_transfer_emit_program_info_changed_signal( live_tv->file_transfer, msg_code, (gpointer)live_tv ); @@ -292,7 +296,7 @@ livetv->backend_info = backend_info; - //if ( NULL == livetv->socket ) { + if ( NULL == livetv->socket ) { livetv->socket = gmyth_socket_new (); /* FIME: Implement this at gmyth_socket */ @@ -303,7 +307,7 @@ res = FALSE; goto error; } - //} + } g_static_mutex_lock( &lock ); @@ -316,12 +320,23 @@ goto error; } + if ( livetv->recorder != NULL ) + { + g_object_unref( livetv->recorder ); + livetv->recorder= NULL; + } + if ( gmyth_remote_util_get_free_recorder_count (livetv->socket) <= 0 ) { - gmyth_debug ("No free remote encoder available."); - res = FALSE; - goto error; + gmyth_debug ("No free remote encoder available. Trying to close the actual recording..."); + + //res = FALSE; + //goto error; + if ( livetv->recorder != NULL ) { + g_object_unref( livetv->recorder ); + livetv->recorder = NULL; + } } - + /* Gets the recorder num */ livetv->recorder = remote_request_next_free_recorder (livetv->socket, -1); gmyth_socket_close_connection (livetv->socket); @@ -490,7 +505,8 @@ g_print( "[%s] ERROR running LiveTV setup.\n", __FUNCTION__ ); if ( livetv->local_hostname != NULL ) { - g_string_free( livetv->local_hostname, FALSE ); + g_string_free( livetv->local_hostname, TRUE ); + livetv->local_hostname = NULL; res = FALSE; } @@ -695,6 +711,10 @@ if ( !gmyth_recorder_stop_livetv (livetv->recorder) ) { g_warning ("[%s] Error while stoping remote encoder", __FUNCTION__); } + + if ( !gmyth_recorder_finish_recording(livetv->recorder) ) { + g_warning ("[%s] Error while finishing recording on remote encoder", __FUNCTION__); + } } } diff -r f7b40eb795c2 -r 5486e606498b gmyth/src/gmyth_programinfo.c --- a/gmyth/src/gmyth_programinfo.c Mon Feb 12 17:56:41 2007 +0000 +++ b/gmyth/src/gmyth_programinfo.c Tue Feb 13 22:33:08 2007 +0000 @@ -47,6 +47,8 @@ G_DEFINE_TYPE(GMythProgramInfo, gmyth_program_info, G_TYPE_OBJECT) +static const gchar* gmyth_program_info_non_null_value( const GString *str ); + static void gmyth_program_info_class_init (GMythProgramInfoClass *klass) { @@ -309,25 +311,25 @@ gmyth_string_list_append_string (slist, prog->chansign); /* 6 */ gmyth_string_list_append_string (slist, prog->channame); /* 7 */ gmyth_string_list_append_string (slist, prog->pathname); /* 8 */ - gmyth_string_list_append_int (slist, 0); /* 9 */ + gmyth_string_list_append_int64 (slist, 0); /* 9 */ // fixme //gmyth_string_list_append_int64 (slist, 100/*prog->filesize*/); /* 9 */ //gmyth_string_list_append_int (slist, 0); /* 10 */ if (prog->startts) - gmyth_string_list_append_int64 (slist, prog->startts->tv_sec); /* 10 */ //DATETIME_TO_LIST(startts) + gmyth_string_list_append_int (slist, prog->startts->tv_sec); /* 11 */ //DATETIME_TO_LIST(startts) else - gmyth_string_list_append_int64 (slist, 0); + gmyth_string_list_append_int (slist, 0); if (prog->endts) - gmyth_string_list_append_int64 (slist, prog->endts->tv_sec); /* 12 */ //DATETIME_TO_LIST(endts) + gmyth_string_list_append_int (slist, prog->endts->tv_sec); /* 12 */ //DATETIME_TO_LIST(endts) else - gmyth_string_list_append_int64 (slist, 0); + gmyth_string_list_append_int (slist, 0); - gmyth_string_list_append_int (slist, prog->duplicate); /* 14 */ - gmyth_string_list_append_int (slist, prog->shareable); /* 15 */ - gmyth_string_list_append_int (slist, prog->findid); /* 16 */ + gmyth_string_list_append_int (slist, prog->duplicate); /* 13 */ + gmyth_string_list_append_int (slist, prog->shareable); /* 14 */ + gmyth_string_list_append_int (slist, prog->findid); /* 15 */ gmyth_string_list_append_string (slist, prog->hostname); /* 16 */ gmyth_string_list_append_int (slist, prog->sourceid); /* 17 */ gmyth_string_list_append_int (slist, prog->cardid); /* 18 */ @@ -338,8 +340,8 @@ gmyth_string_list_append_int (slist, 0 /*prog->rectype*/); /* 23 */ gmyth_string_list_append_int (slist, 0 /*prog->dupin*/); /* 24 */ gmyth_string_list_append_int (slist, 0 /*prog->dupmethod*/); /* 25 */ - gmyth_string_list_append_int64 (slist, prog->recstartts != NULL ? prog->recstartts->tv_sec : 0); /* 26 */ //DATETIME_TO_LIST(recstartts) - gmyth_string_list_append_int64 (slist, prog->recendts != NULL ? prog->recendts->tv_sec : 0); /* 27 */ //DATETIME_TO_LIST(recendts) + gmyth_string_list_append_int (slist, prog->recstartts != NULL ? prog->recstartts->tv_sec : 0); /* 26 */ //DATETIME_TO_LIST(recstartts) + gmyth_string_list_append_int (slist, prog->recendts != NULL ? prog->recendts->tv_sec : 0); /* 27 */ //DATETIME_TO_LIST(recendts) gmyth_string_list_append_int (slist, prog->repeat); /* 28 */ gmyth_string_list_append_int (slist, prog->programflags); /* 29 */ gmyth_string_list_append_char_array (slist, "Default"); /* 30 */ //prog->(recgroup != "") ? recgroup : "Default") @@ -348,9 +350,9 @@ gmyth_string_list_append_string (slist, prog->seriesid); /* 33 */ gmyth_string_list_append_string (slist, prog->programid); /* 34 */ gmyth_string_list_append_char_array (slist, ""); /* 35 */ - gmyth_string_list_append_int64 (slist, prog->lastmodified != NULL ? prog->lastmodified->tv_sec : 0); /* 36 */ //DATETIME_TO_LIST(lastmodified) + gmyth_string_list_append_int (slist, prog->lastmodified != NULL ? prog->lastmodified->tv_sec : 0); /* 36 */ //DATETIME_TO_LIST(lastmodified) gmyth_string_list_append_int (slist, 0); /* 37 */ //FLOAT_TO_LIST(stars) - gmyth_string_list_append_int64 (slist, prog->originalAirDate != NULL ? prog->originalAirDate->tv_sec : 0); /* 38 */ //DATETIME_TO_LIST(QDateTime(originalAirDate)) + gmyth_string_list_append_int (slist, prog->originalAirDate != NULL ? prog->originalAirDate->tv_sec : 0); /* 38 */ //DATETIME_TO_LIST(QDateTime(originalAirDate)) gmyth_string_list_append_int (slist, prog->hasAirDate); /* 39 */ gmyth_string_list_append_char_array (slist, "Default"); /* 40 */ //prog->(playgroup != "") ? playgroup : "Default") gmyth_string_list_append_int (slist, prog->recpriority2); /* 41 */ @@ -416,11 +418,23 @@ prog->channame = gmyth_string_list_get_string (slist, 5); prog->chanstr = gmyth_string_list_get_string (slist, 6); prog->chansign = gmyth_string_list_get_string (slist, 7); - prog->pathname = gmyth_string_list_get_string (slist, 8); + prog->pathname = gmyth_string_list_get_string (slist, 8); + + prog->filesize = gmyth_string_list_get_int64 (slist, 9); + + gmyth_debug( "Prog info: [ %s, %s, %s, %s, %s, %s, %s, %s, %s, %d ]\n", + gmyth_program_info_non_null_value( prog->title ), + gmyth_program_info_non_null_value( prog->subtitle ), + gmyth_program_info_non_null_value( prog->description ), + gmyth_program_info_non_null_value( prog->category ), + gmyth_program_info_non_null_value( prog->chanid ), + gmyth_program_info_non_null_value( prog->channame ), + gmyth_program_info_non_null_value( prog->chanstr ), + gmyth_program_info_non_null_value( prog->chansign ), + gmyth_program_info_non_null_value( prog->pathname ), + gmyth_string_list_get_int (slist, 11) ); //gmyth_string_list_get_int (slist, 9); - prog->filesize = gmyth_string_list_get_int64 (slist, 9); - prog->startts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( (time_t)gmyth_string_list_get_int (slist, 11) ))->str ); //DATETIME_TO_LIST(startts) prog->endts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( @@ -457,7 +471,61 @@ (time_t)gmyth_string_list_get_int (slist, 38) ))->str ); //DATETIME_TO_LIST(QDateTime(originalAirDate)) prog->hasAirDate = gmyth_string_list_get_int (slist, 39); prog->playgroup = gmyth_string_list_get_string (slist, 40); //prog->(playgroup != "") ? playgroup : "Default") - //prog->recpriority2 = gmyth_string_list_get_int (slist, 41); + prog->recpriority2 = gmyth_string_list_get_int (slist, 41); return prog; } + +static const gchar* +gmyth_program_info_non_null_value( const GString *str ) +{ + return ( str != NULL && str->str != NULL && strlen( str->str ) > 0 ? str->str : " " ); +} + +const gchar* +gmyth_program_info_to_string( const GMythProgramInfo* prog ) +{ + return g_strdup_printf( "Title: %s, Subtitle: %s, Description: %s, Category: %s, Channel ID: %s, "\ + "Channel Name: %s, Chan str: %s, Channel Sign: %s, Path Name: %s, File Size: %lld, \n"\ + "Start TS: %s, End TS: %s, Duplicate: %d, Shareable: %d, Find ID: %d, Hostname: %s, "\ + "Source ID: %d, Vard ID: %d, Input ID: %d, Rec Priority: %d, Reactivate: %d, \n"\ + "Record ID: %d, Rec Start TS: %s, Rec End TS: %s, Repeat: %d, Program Flags: %d, "\ + "Rec Group: %s, Channel Comm Free: %d, Channel Output Filters: %s, Series ID: %s, \n"\ + "Program ID: %s, Last Modified Date: %s, Original Air Date: %s, Has Air Date: %d, " + "Play Group: %s.\n", + gmyth_program_info_non_null_value( prog->title ), + gmyth_program_info_non_null_value( prog->subtitle ), + gmyth_program_info_non_null_value( prog->description ), + gmyth_program_info_non_null_value( prog->category ), + gmyth_program_info_non_null_value( prog->chanid ), + gmyth_program_info_non_null_value( prog->channame ), + gmyth_program_info_non_null_value( prog->chanstr ), + gmyth_program_info_non_null_value( prog->chansign ), + gmyth_program_info_non_null_value( prog->pathname ), + prog->filesize, + gmyth_util_time_to_string_from_time_val( prog->startts), + gmyth_util_time_to_string_from_time_val( prog->endts), + prog->duplicate, + prog->shareable, + prog->findid, + gmyth_program_info_non_null_value( prog->hostname ), + prog->sourceid, + prog->cardid, + prog->inputid, + prog->recpriority, + prog->reactivate, + prog->recordid, + gmyth_util_time_to_string_from_time_val(prog->recstartts), + gmyth_util_time_to_string_from_time_val(prog->recendts), + prog->repeat, + prog->programflags, + gmyth_program_info_non_null_value( prog->recgroup ), + prog->chancommfree, + gmyth_program_info_non_null_value( prog->chanOutputFilters ), + gmyth_program_info_non_null_value( prog->seriesid ), + gmyth_program_info_non_null_value( prog->programid ), + gmyth_util_time_to_string_from_time_val(prog->lastmodified), + gmyth_util_time_to_string_from_time_val(prog->originalAirDate), + prog->hasAirDate, + gmyth_program_info_non_null_value(prog->playgroup) ); +} diff -r f7b40eb795c2 -r 5486e606498b gmyth/src/gmyth_programinfo.h --- a/gmyth/src/gmyth_programinfo.h Mon Feb 12 17:56:41 2007 +0000 +++ b/gmyth/src/gmyth_programinfo.h Tue Feb 13 22:33:08 2007 +0000 @@ -156,6 +156,8 @@ GMythStringList* gmyth_program_info_to_string_list (GMythProgramInfo *prog, GMythStringList *slist); GMythProgramInfo* gmyth_program_info_from_string_list (GMythStringList *slist); +const gchar* gmyth_program_info_to_string( const GMythProgramInfo* prog ); + G_END_DECLS #endif /*_GMYTH_PROGRAMINFO_H*/ diff -r f7b40eb795c2 -r 5486e606498b gmyth/src/gmyth_recorder.c --- a/gmyth/src/gmyth_recorder.c Mon Feb 12 17:56:41 2007 +0000 +++ b/gmyth/src/gmyth_recorder.c Tue Feb 13 22:33:08 2007 +0000 @@ -70,7 +70,7 @@ { GMythRecorder *recorder = GMYTH_RECORDER(object); - //gmyth_recorder_close(recorder); + gmyth_recorder_close(recorder); if ( recorder->myth_socket != NULL ) { g_object_unref (recorder->myth_socket); @@ -92,8 +92,7 @@ void gmyth_recorder_close (GMythRecorder *recorder) { - if (recorder->myth_socket != NULL) - gmyth_socket_close_connection(recorder->myth_socket); + gmyth_recorder_finish_recording( recorder ); } /** Creates a new instance of GMythRecorder. @@ -731,9 +730,8 @@ program_info->programid = gmyth_string_list_get_string (str_list, 13); } - if ( ( program_info->chanid != NULL && strlen( program_info->chanid->str ) > 0 ) && - ( program_info->channame != NULL && strlen( program_info->channame->str ) > 0 ) && - ( program_info->title != NULL && strlen( program_info->title->str ) > 0 ) ) + if ( /*( program_info->chanid != NULL && strlen( program_info->chanid->str ) > 0 ) &&*/ + ( program_info->pathname != NULL && strlen( program_info->pathname->str ) > 0 ) ) { gmyth_debug( "OK!!! Got the next program info..." ); } else { @@ -825,3 +823,41 @@ return ret; } + +gboolean +gmyth_recorder_finish_recording ( GMythRecorder *recorder ) +{ + gboolean ret = TRUE; + + g_return_val_if_fail( recorder != NULL, FALSE ); + + GMythStringList *str_list = gmyth_string_list_new (); + GString *message = g_string_new (""); + + g_string_printf( message, "%s %d", GMYTHTV_RECORDER_HEADER, recorder->recorder_num); + gmyth_string_list_append_string (str_list, message); + gmyth_string_list_append_string (str_list, g_string_new ("FINISH_RECORDING")); + + gmyth_socket_sendreceive_stringlist ( recorder->myth_socket, str_list ); + + if ( str_list != NULL && gmyth_string_list_length(str_list) > 0 ) + { + GString *str = NULL; + if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && strcmp( str->str, "ok" )!= 0 ) + { + gint is_rec = gmyth_string_list_get_int( str_list, 0 ); + if ( is_rec != 0 ) + ret = TRUE; + else + ret = FALSE; + } + } + gmyth_debug( "%s, stream is %s being recorded!\n", ret ? "YES" : "NO", ret ? "" : "NOT" ); + //g_static_mutex_unlock (&mutex); + + if ( str_list != NULL ) + g_object_unref (str_list); + + return ret; + +} diff -r f7b40eb795c2 -r 5486e606498b gmyth/src/gmyth_recorder.h --- a/gmyth/src/gmyth_recorder.h Mon Feb 12 17:56:41 2007 +0000 +++ b/gmyth/src/gmyth_recorder.h Tue Feb 13 22:33:08 2007 +0000 @@ -133,6 +133,8 @@ gboolean gmyth_recorder_is_recording ( GMythRecorder *recorder ); +gboolean gmyth_recorder_finish_recording ( GMythRecorder *recorder ); + G_END_DECLS #endif /* __GMYTH_REMOTE_ENCODER_H__ */ diff -r f7b40eb795c2 -r 5486e606498b gmyth/src/gmyth_socket.c --- a/gmyth/src/gmyth_socket.c Mon Feb 12 17:56:41 2007 +0000 +++ b/gmyth/src/gmyth_socket.c Tue Feb 13 22:33:08 2007 +0000 @@ -69,7 +69,7 @@ // FIXME: put this in the right place #define MYTHTV_VERSION_DEFAULT 31 -static GStaticMutex mutex = G_STATIC_MUTEX_INIT; +/* static GStaticMutex mutex = G_STATIC_MUTEX_INIT; */ /*static GStaticRWLock rwlock = G_STATIC_RW_LOCK_INIT;*/ @@ -282,7 +282,7 @@ return str; } - g_static_mutex_lock( &mutex ); + g_mutex_lock( gmyth_socket->mutex ); addr_info0 = addr_info_data; @@ -323,7 +323,7 @@ } } - g_static_mutex_unlock (&mutex); + g_mutex_unlock (gmyth_socket->mutex); if ( str != NULL && str->str != NULL ) local_hostname = g_strdup( str->str ); @@ -340,14 +340,18 @@ /* disconnect socket */ gmyth_socket_close_connection (gmyth_socket); - /* g_free (gmyth_socket->hostname); gmyth_socket->hostname = NULL; - */ g_free (local_hostname); local_hostname = NULL; + + if ( gmyth_socket->mutex != NULL ) + { + g_mutex_free( gmyth_socket->mutex ); + gmyth_socket->mutex = NULL; + } G_OBJECT_CLASS (gmyth_socket_parent_class)->dispose (object); } @@ -370,6 +374,8 @@ GMythSocket *gmyth_socket = GMYTH_SOCKET (g_object_new(GMYTH_SOCKET_TYPE, NULL)); gmyth_socket->mythtv_version = MYTHTV_VERSION_DEFAULT; + + gmyth_socket->mutex = g_mutex_new(); return gmyth_socket; } @@ -663,7 +669,7 @@ goto done; } - g_static_mutex_lock( &mutex ); + g_mutex_lock( gmyth_socket->mutex ); gmyth_debug ("Sending command to backend: %s\n", command->str); buffer = g_strnfill( BUFLEN, ' ' ); @@ -693,7 +699,7 @@ ret = TRUE; } - g_static_mutex_unlock( &mutex ); + g_mutex_unlock( gmyth_socket->mutex ); done: if ( error != NULL ) { g_printerr( "[%s] Error found reading data from IO channel: (%d, %s)\n", __FUNCTION__, error->code, error->message ); @@ -949,11 +955,11 @@ /* verify if the input (read) buffer is ready to receive data */ - //g_static_mutex_lock( &mutex ); + g_mutex_lock( gmyth_socket->mutex ); //g_static_rw_lock_reader_lock (&rwlock); - buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE); - //buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' '); + //buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE); + buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' '); if ( NULL == gmyth_socket->sd_io_ch ) { gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port ); @@ -981,7 +987,7 @@ g_debug ("[%s] Error in mythprotocol response from backend\n", __FUNCTION__); str = NULL; //return NULL; - } else { + } else if ( buffer != NULL && strlen(buffer) > 0 ) { //io_status = g_io_channel_flush( gmyth_socket->sd_io_ch, &error ); /* verify if the input (read) buffer is ready to receive data */ @@ -1020,7 +1026,7 @@ //} } - //g_static_mutex_unlock( &mutex ); + g_mutex_unlock( gmyth_socket->mutex ); //g_static_rw_lock_reader_unlock (&rwlock); gmyth_debug ("Response received from backend: {%s}\n", buffer); @@ -1054,7 +1060,7 @@ GPtrArray *ptr_array = NULL; gchar *str_array = NULL; - g_static_mutex_lock( &mutex ); + g_mutex_lock( gmyth_socket->mutex ); //g_static_rw_lock_writer_lock (&rwlock); ptr_array = g_ptr_array_sized_new (g_list_length(str_list->glist)); @@ -1072,7 +1078,7 @@ str_array = g_strjoinv (MYTH_SEPARATOR, (gchar **) (ptr_array->pdata)); - g_static_mutex_unlock( &mutex ); + g_mutex_unlock( gmyth_socket->mutex ); //g_static_rw_lock_writer_unlock (&rwlock); gmyth_debug ( "[%s] Sending socket request: %s\n", __FUNCTION__, str_array ); @@ -1106,15 +1112,17 @@ if ( response != NULL && response->str != NULL && response->len > 0 ) { - g_static_mutex_lock( &mutex ); + g_mutex_lock( gmyth_socket->mutex ); gmyth_string_list_clear_all (str_list); str_array = g_strsplit (response->str, MYTH_SEPARATOR, -1); - for (i=0; i< g_strv_length (str_array); i++) { - gmyth_string_list_append_char_array (str_list, str_array[i] ); + for ( i=0; i< g_strv_length (str_array); i++ ) { + //if ( str_array[i] != NULL && strlen( str_array[i] ) > 0 ) + gmyth_string_list_append_char_array ( str_list, str_array[i] ); } - g_static_mutex_unlock( &mutex ); + + g_mutex_unlock( gmyth_socket->mutex ); } diff -r f7b40eb795c2 -r 5486e606498b gmyth/src/gmyth_socket.h --- a/gmyth/src/gmyth_socket.h Mon Feb 12 17:56:41 2007 +0000 +++ b/gmyth/src/gmyth_socket.h Tue Feb 13 22:33:08 2007 +0000 @@ -66,15 +66,17 @@ struct _GMythSocket { - GObject parent; + GObject parent; + + GMutex *mutex; /* socket descriptor */ - gint sd; - GIOChannel *sd_io_ch; + gint sd; + GIOChannel *sd_io_ch; - gchar *hostname; - gint port; - gint mythtv_version; + gchar *hostname; + gint port; + gint mythtv_version; }; /* used when no protocol version number was negotiated */ diff -r f7b40eb795c2 -r 5486e606498b gmyth/src/gmyth_stringlist.c --- a/gmyth/src/gmyth_stringlist.c Mon Feb 12 17:56:41 2007 +0000 +++ b/gmyth/src/gmyth_stringlist.c Tue Feb 13 22:33:08 2007 +0000 @@ -91,7 +91,7 @@ gmyth_string_list_new () { GMythStringList *gmyth_string_list = GMYTH_STRING_LIST (g_object_new (GMYTH_STRING_LIST_TYPE, NULL)); - + return gmyth_string_list; } @@ -202,7 +202,8 @@ tmp_str = g_string_new (value); - g_return_val_if_fail( tmp_str != NULL, NULL ); + if ( NULL == tmp_str ) + return NULL; gmyth_string_list_append_string (strlist, tmp_str); @@ -242,7 +243,8 @@ tmp_str = (GString *) g_list_nth_data (strlist->glist, index); - g_return_val_if_fail( tmp_str != NULL && tmp_str->str != NULL, 0 ); + if ( NULL == tmp_str || NULL == tmp_str->str || strlen( tmp_str->str ) <= 0 ) + return 0; return (gint) ( /* 0x00000000ffffffffL & (gint64)*/g_ascii_strtoull ( tmp_str->str, NULL, 10 ) ); } diff -r f7b40eb795c2 -r 5486e606498b gmyth/src/gmyth_uri.c --- a/gmyth/src/gmyth_uri.c Mon Feb 12 17:56:41 2007 +0000 +++ b/gmyth/src/gmyth_uri.c Tue Feb 13 22:33:08 2007 +0000 @@ -374,7 +374,7 @@ /* gmyth_debug( "Channel tuple is [ %s, %s ]", chan_key_value[0], chan_key_value[1] ); */ - if ( chan_key_value[1] != NULL ) + if ( chan_key_value[1] != NULL && strlen( chan_key_value[1] ) > 0 ) { channel = g_strdup( chan_key_value[1] ); }