# HG changeset patch # User rosfran # Date 1174587146 0 # Node ID 44db5239d628bd3c0b02c5f59eda966c0b0a09ae # Parent be6bb250b01a4feac3f350c2908c91b672cc322e [svn r433] GMutex fixes on TVChain, added missing g_object_refs. diff -r be6bb250b01a -r 44db5239d628 gmyth/src/gmyth_file_transfer.h --- a/gmyth/src/gmyth_file_transfer.h Thu Mar 22 15:19:38 2007 +0000 +++ b/gmyth/src/gmyth_file_transfer.h Thu Mar 22 18:12:26 2007 +0000 @@ -54,7 +54,7 @@ #define GMYTH_FILE_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferClass)) #define GMYTHTV_FILE_TRANSFER_READ_ERROR -314 -#define GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN -315 +#define GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN -315 typedef struct _GMythFileTransfer GMythFileTransfer; typedef struct _GMythFileTransferClass GMythFileTransferClass; diff -r be6bb250b01a -r 44db5239d628 gmyth/src/gmyth_livetv.c --- a/gmyth/src/gmyth_livetv.c Thu Mar 22 15:19:38 2007 +0000 +++ b/gmyth/src/gmyth_livetv.c Thu Mar 22 18:12:26 2007 +0000 @@ -39,6 +39,8 @@ #include "gmyth_file_transfer.h" #include "gmyth_monitor_handler.h" +#include "gmyth_common.h" + static void gmyth_livetv_class_init (GMythLiveTVClass *klass); static void gmyth_livetv_init (GMythLiveTV *object); @@ -146,6 +148,11 @@ G_OBJECT_CLASS ( gmyth_livetv_parent_class )->finalize ( object ); } +/** + * Creates a new GMythLiveTV instance + * + * @return a newly allocated GMythLiveTV instance + */ GMythLiveTV* gmyth_livetv_new () { @@ -156,6 +163,16 @@ return livetv; } +/** + * The GObject signal handler function, from which all status messages + * from the Monitor Handler will be advertized, all time it receives + * LiveTV status messages from the MythTV backend + * + * @param monitor a GMythMonitorHandler instance + * @param msg_code the MythTV's server numeric status code + * @param message the message's string description + * @param user_data pointer to the GMythLiveTV instance + */ static void gmyth_livetv_monitor_signal_handler( GMythMonitorHandler *monitor, gint msg_code, gchar* message, gpointer user_data ) @@ -248,6 +265,15 @@ } +/** + * Starts the Monitor Handler to this GMythLiveTV session, in order + * to receive the status messages from the MythTV's backend server + * + * @param live_tv the GMythLiveTV instance + * + * @return true if the Monitor Handler start-up process + * had been concluded succcesfully + */ gboolean gmyth_livetv_monitor_handler_start( GMythLiveTV *livetv ) { @@ -289,6 +315,15 @@ } +/** + * Stops the Monitor Handler to this GMythLiveTV session, in order + * to stop receiving the status messages from the MythTV's backend server + * + * @param live_tv the GMythLiveTV instance + * + * @return true if the Monitor Handler shutdown process + * had been concluded succcesfully + */ void gmyth_livetv_monitor_handler_stop( GMythLiveTV *livetv ) { @@ -301,7 +336,7 @@ } -/* +#if 0 static gchar* gmyth_livetv_create_remote_url( GMythLiveTV *livetv ) { @@ -312,8 +347,20 @@ return uri; } -*/ +#endif +/** + * Configures the GMythLiveTV session, sends SPAWN_LIVETV message, + * sets the channel name, and gets the first program info about the + * actual recording + * + * @param live_tv the GMythLiveTV instance + * @param channel the channel name (the chan_name field, from the tvchain table) + * @param backend_info the GMythBackendInfo describing the remote server + * + * @return true if the LiveTV's recorder instance configuration + * had been concluded succcesfully + */ static gboolean gmyth_livetv_setup_recorder_channel_name ( GMythLiveTV *livetv, gchar* channel, GMythBackendInfo *backend_info ) @@ -353,12 +400,14 @@ } if ( gmyth_remote_util_get_free_recorder_count (livetv->socket) <= 0 ) { + +#ifdef GMYTH_USE_DEBUG gmyth_debug ("No free remote encoder available."); - +#endif res = FALSE; goto error; } - + /* Gets the recorder num */ livetv->recorder = remote_request_next_free_recorder (livetv->socket, -1); gmyth_socket_close_connection (livetv->socket); @@ -466,7 +515,9 @@ /* check if the program chain could be obtained from the MythTV protocol message */ if ( prog_info != NULL ) { +#ifdef GMYTH_USE_DEBUG gmyth_debug( "Program Info: %s\n", gmyth_program_info_to_string( prog_info ) ); +#endif livetv->proginfo = prog_info; /* testing change channel */ //gmyth_recorder_spawntv_no_tvchain( livetv->recorder ); @@ -544,6 +595,18 @@ } +/** + * Setup the GMythLiveTV session, sends SPAWN_LIVETV message, + * sets the channel name, and gets the first program info about the + * actual recording + * + * @param live_tv the GMythLiveTV instance + * @param channel the channel name, in numerical format + * @param backend_info the GMythBackendInfo describing the remote server + * + * @return true if the LiveTV's recorder instance configuration + * had been concluded succcesfully + */ static gboolean gmyth_livetv_setup_recorder ( GMythLiveTV *livetv, gint channel, GMythBackendInfo *backend_info ) { @@ -551,24 +614,66 @@ g_strdup_printf( "%d", channel ) : NULL, backend_info ); } +/** + * Setup the GMythLiveTV session, sends SPAWN_LIVETV message, + * sets the channel name (numerical format), and gets the first program info about the + * actual recording + * + * @param live_tv the GMythLiveTV instance + * @param channel the channel name, in numerical format + * @param backend_info the GMythBackendInfo describing the remote server + * + * @return true if the LiveTV's recorder instance configuration + * had been concluded succcesfully + */ gboolean gmyth_livetv_channel_setup ( GMythLiveTV *livetv, gint channel, GMythBackendInfo *backend_info ) { return gmyth_livetv_setup_recorder ( livetv, channel, backend_info ); } +/** + * Setup the GMythLiveTV session, sends SPAWN_LIVETV message, + * sets the channel name (string format), and gets the first program info about the + * actual recording + * + * @param live_tv the GMythLiveTV instance + * @param channel the channel name, in numerical format + * @param backend_info the GMythBackendInfo describing the remote server + * + * @return true if the LiveTV's recorder instance configuration + * had been concluded succcesfully + */ gboolean gmyth_livetv_channel_name_setup ( GMythLiveTV *livetv, gchar* channel, GMythBackendInfo *backend_info ) { return gmyth_livetv_setup_recorder_channel_name ( livetv, channel, backend_info ); } +/** + * Setup the GMythLiveTV session, sends SPAWN_LIVETV message, + * and gets the first program info about the actual recording + * (doesn't changes the channel). + * + * @param live_tv the GMythLiveTV instance + * @param backend_info the GMythBackendInfo describing the remote server + * + * @return true if the LiveTV's recorder instance configuration + * had been concluded succcesfully + */ gboolean gmyth_livetv_setup ( GMythLiveTV *livetv, GMythBackendInfo *backend_info ) { return gmyth_livetv_setup_recorder ( livetv, -1, backend_info ); } +/** + * Gets the next program info from this GMythLiveTV session. + * + * @param live_tv the GMythLiveTV instance + * + * @return true if the next program info could be got + */ gboolean gmyth_livetv_next_program_chain ( GMythLiveTV *livetv ) { @@ -639,6 +744,15 @@ } +/** + * Creates a File Transfer session, using all configuration information + * got from the actual program info. + * + * @param live_tv the GMythLiveTV instance + * + * @return the actual GMythFileTransfer instance, generated using the + * data got from the actual program info. + */ GMythFileTransfer * gmyth_livetv_create_file_transfer( GMythLiveTV *livetv ) { @@ -653,10 +767,12 @@ goto done; } +#ifdef GMYTH_USE_DEBUG if ( livetv->proginfo != NULL ) gmyth_debug( "URI path (from program info) = %s.\n", livetv->proginfo->pathname->str ); else - gmyth_debug( "URI path (from URI) = %s.\n", livetv->uri->uri->str ); + gmyth_debug( "URI path (from URI) = %s.\n", livetv->uri->uri->str ); +#endif g_mutex_lock( livetv->mutex ); @@ -676,11 +792,15 @@ livetv->uri->path = NULL; } */ - gmyth_debug( "URI is NULL, creating from the ProgramInfo pathname... (%s)", livetv->proginfo->pathname->str ); +#ifdef GMYTH_USE_DEBUG + gmyth_debug( "URI is not NULL, creating from the ProgramInfo pathname... (%s)", livetv->proginfo->pathname->str ); +#endif livetv->uri->path = g_string_erase(livetv->uri->path, 0, -1); livetv->uri->path = g_string_new( g_strrstr( livetv->proginfo->pathname->str, "/" ) ); } else { +#ifdef GMYTH_USE_DEBUG gmyth_debug( "URI is NULL, creating from the ProgramInfo pathname... (%s)", livetv->proginfo->pathname->str ); +#endif livetv->uri = gmyth_uri_new_with_value( livetv->proginfo->pathname->str ); } @@ -698,9 +818,9 @@ goto done; } - //gmyth_file_transfer_settimeout( livetv->file_transfer, TRUE ); + /* gmyth_file_transfer_settimeout( livetv->file_transfer, TRUE ); */ - g_mutex_unlock( livetv->mutex ); + g_mutex_unlock( livetv->mutex ); done: /* @@ -715,7 +835,11 @@ } -/* FIXME: How to proceed differently between livetv and recorded content */ +/** + * Stops this LiveTV session. + * + * @param live_tv the GMythLiveTV instance + */ void gmyth_livetv_stop_playing (GMythLiveTV *livetv) { @@ -723,11 +847,11 @@ if (livetv->is_livetv) { if ( !gmyth_recorder_stop_livetv (livetv->recorder) ) { - g_debug ("[%s] Error while stoping remote encoder", __FUNCTION__); + gmyth_debug ("[%s] Error while stoping remote encoder", __FUNCTION__); } if ( !gmyth_recorder_finish_recording(livetv->recorder) ) { - g_debug ("[%s] Error while finishing recording on remote encoder", __FUNCTION__); + gmyth_debug ("[%s] Error while finishing recording on remote encoder", __FUNCTION__); } } } diff -r be6bb250b01a -r 44db5239d628 gmyth/src/gmyth_tvchain.c --- a/gmyth/src/gmyth_tvchain.c Thu Mar 22 15:19:38 2007 +0000 +++ b/gmyth/src/gmyth_tvchain.c Thu Mar 22 18:12:26 2007 +0000 @@ -52,8 +52,6 @@ G_DEFINE_TYPE(GMythTVChain, gmyth_tvchain, G_TYPE_OBJECT) -static GStaticMutex mutex = G_STATIC_MUTEX_INIT; - static void gmyth_tvchain_class_init (GMythTVChainClass *klass) { @@ -67,11 +65,13 @@ static void gmyth_tvchain_init (GMythTVChain *tvchain) -{ +{ tvchain->tvchain_id = NULL; tvchain->cur_chanid = g_string_new (""); tvchain->cur_startts = NULL; + + tvchain->mutex = g_mutex_new(); } GMythTVChain* @@ -88,13 +88,18 @@ GMythTVChain *tvchain = GMYTH_TVCHAIN(object); if ( tvchain->tvchain_id != NULL ) { - g_string_free( tvchain->tvchain_id, TRUE ); - tvchain->tvchain_id = NULL; + g_string_free( tvchain->tvchain_id, TRUE ); + tvchain->tvchain_id = NULL; + } + + if ( tvchain->mutex != NULL ) { + g_mutex_free( tvchain->mutex ); + tvchain->mutex = NULL; } if ( tvchain->tvchain_list != NULL ) { - g_list_free( tvchain->tvchain_list ); - tvchain->tvchain_list = NULL; + g_list_free( tvchain->tvchain_list ); + tvchain->tvchain_list = NULL; } if ( tvchain->cur_chanid != NULL ) { @@ -190,7 +195,7 @@ gboolean ret = TRUE; GString *stmt_str = NULL; - g_static_mutex_lock( &mutex ); + g_mutex_lock( tvchain->mutex ); /* gets the initial size of the TVChain entries list */ guint prev_size = g_list_length (tvchain->tvchain_list); @@ -206,7 +211,7 @@ gmyth_query = gmyth_query_new (); if (!gmyth_query_connect (gmyth_query, tvchain->backend_info)) { g_warning ("[%s] Could not connect to db", __FUNCTION__); - g_static_mutex_unlock( &mutex ); + g_mutex_unlock( tvchain->mutex ); ret = FALSE; goto done; } @@ -245,13 +250,13 @@ } } else { g_warning ("gmyth_tvchain_reload_all query error!\n"); - g_static_mutex_unlock( &mutex ); + g_mutex_unlock( tvchain->mutex ); ret = FALSE; goto done; } - g_static_mutex_unlock( &mutex ); + g_mutex_unlock( tvchain->mutex ); tvchain->cur_pos = gmyth_tvchain_program_is_at (tvchain, tvchain->cur_chanid, tvchain->cur_startts); g_print( "[%s] TVChain current position = %d.\n", __FUNCTION__, tvchain->cur_pos ); @@ -294,7 +299,7 @@ GList *tmp_list = tvchain->tvchain_list; guint list_size = g_list_length (tvchain->tvchain_list); - g_static_mutex_lock( &mutex ); + g_mutex_lock( tvchain->mutex ); for (; tmp_list && ( count < list_size ); tmp_list = tvchain->tvchain_list->next, count++) { @@ -302,11 +307,11 @@ if ( !g_strncasecmp (entry->chanid->str, chanid->str, chanid->len) && entry->starttime == startts ) { - g_static_mutex_unlock( &mutex ); + g_mutex_unlock( tvchain->mutex ); return count; } } - g_static_mutex_unlock( &mutex ); + g_mutex_unlock( tvchain->mutex ); return -1; } @@ -343,7 +348,7 @@ g_return_val_if_fail( tvchain != NULL && tvchain->tvchain_list != NULL, NULL ); - g_static_mutex_lock( &mutex ); + g_mutex_lock( tvchain->mutex ); gint size = g_list_length (tvchain->tvchain_list); gint new_index = (index < 0 || index >= size) ? size - 1 : index; @@ -351,7 +356,7 @@ if (new_index >= 0) chain_entry = (struct LiveTVChainEntry*) g_list_nth_data (tvchain->tvchain_list, new_index); - g_static_mutex_unlock( &mutex ); + g_mutex_unlock( tvchain->mutex ); if ( chain_entry != NULL ) { gmyth_debug ("[%s] Got TV Chain entry at %d.\n", __FUNCTION__, new_index ); diff -r be6bb250b01a -r 44db5239d628 gmyth/src/gmyth_tvchain.h --- a/gmyth/src/gmyth_tvchain.h Thu Mar 22 15:19:38 2007 +0000 +++ b/gmyth/src/gmyth_tvchain.h Thu Mar 22 18:12:26 2007 +0000 @@ -84,6 +84,8 @@ gint cur_pos; GMythBackendInfo *backend_info; + + GMutex *mutex; }; GType gmyth_tvchain_get_type (void);