[svn r433] GMutex fixes on TVChain, added missing g_object_refs.
1.1 --- a/gmyth/src/gmyth_file_transfer.h Thu Mar 22 15:19:38 2007 +0000
1.2 +++ b/gmyth/src/gmyth_file_transfer.h Thu Mar 22 18:12:26 2007 +0000
1.3 @@ -54,7 +54,7 @@
1.4 #define GMYTH_FILE_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferClass))
1.5
1.6 #define GMYTHTV_FILE_TRANSFER_READ_ERROR -314
1.7 -#define GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN -315
1.8 +#define GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN -315
1.9
1.10 typedef struct _GMythFileTransfer GMythFileTransfer;
1.11 typedef struct _GMythFileTransferClass GMythFileTransferClass;
2.1 --- a/gmyth/src/gmyth_livetv.c Thu Mar 22 15:19:38 2007 +0000
2.2 +++ b/gmyth/src/gmyth_livetv.c Thu Mar 22 18:12:26 2007 +0000
2.3 @@ -39,6 +39,8 @@
2.4 #include "gmyth_file_transfer.h"
2.5 #include "gmyth_monitor_handler.h"
2.6
2.7 +#include "gmyth_common.h"
2.8 +
2.9 static void gmyth_livetv_class_init (GMythLiveTVClass *klass);
2.10 static void gmyth_livetv_init (GMythLiveTV *object);
2.11
2.12 @@ -146,6 +148,11 @@
2.13 G_OBJECT_CLASS ( gmyth_livetv_parent_class )->finalize ( object );
2.14 }
2.15
2.16 +/**
2.17 + * Creates a new GMythLiveTV instance
2.18 + *
2.19 + * @return a newly allocated GMythLiveTV instance
2.20 + */
2.21 GMythLiveTV*
2.22 gmyth_livetv_new ()
2.23 {
2.24 @@ -156,6 +163,16 @@
2.25 return livetv;
2.26 }
2.27
2.28 +/**
2.29 + * The GObject signal handler function, from which all status messages
2.30 + * from the Monitor Handler will be advertized, all time it receives
2.31 + * LiveTV status messages from the MythTV backend
2.32 + *
2.33 + * @param monitor a GMythMonitorHandler instance
2.34 + * @param msg_code the MythTV's server numeric status code
2.35 + * @param message the message's string description
2.36 + * @param user_data pointer to the GMythLiveTV instance
2.37 + */
2.38 static void
2.39 gmyth_livetv_monitor_signal_handler( GMythMonitorHandler *monitor, gint msg_code,
2.40 gchar* message, gpointer user_data )
2.41 @@ -248,6 +265,15 @@
2.42
2.43 }
2.44
2.45 +/**
2.46 + * Starts the Monitor Handler to this GMythLiveTV session, in order
2.47 + * to receive the status messages from the MythTV's backend server
2.48 + *
2.49 + * @param live_tv the GMythLiveTV instance
2.50 + *
2.51 + * @return <code>true</code> if the Monitor Handler start-up process
2.52 + * had been concluded succcesfully
2.53 + */
2.54 gboolean
2.55 gmyth_livetv_monitor_handler_start( GMythLiveTV *livetv )
2.56 {
2.57 @@ -289,6 +315,15 @@
2.58
2.59 }
2.60
2.61 +/**
2.62 + * Stops the Monitor Handler to this GMythLiveTV session, in order
2.63 + * to stop receiving the status messages from the MythTV's backend server
2.64 + *
2.65 + * @param live_tv the GMythLiveTV instance
2.66 + *
2.67 + * @return <code>true</code> if the Monitor Handler shutdown process
2.68 + * had been concluded succcesfully
2.69 + */
2.70 void
2.71 gmyth_livetv_monitor_handler_stop( GMythLiveTV *livetv )
2.72 {
2.73 @@ -301,7 +336,7 @@
2.74
2.75 }
2.76
2.77 -/*
2.78 +#if 0
2.79 static gchar*
2.80 gmyth_livetv_create_remote_url( GMythLiveTV *livetv )
2.81 {
2.82 @@ -312,8 +347,20 @@
2.83
2.84 return uri;
2.85 }
2.86 -*/
2.87 +#endif
2.88
2.89 +/**
2.90 + * Configures the GMythLiveTV session, sends SPAWN_LIVETV message,
2.91 + * sets the channel name, and gets the first program info about the
2.92 + * actual recording
2.93 + *
2.94 + * @param live_tv the GMythLiveTV instance
2.95 + * @param channel the channel name (the chan_name field, from the tvchain table)
2.96 + * @param backend_info the GMythBackendInfo describing the remote server
2.97 + *
2.98 + * @return <code>true</code> if the LiveTV's recorder instance configuration
2.99 + * had been concluded succcesfully
2.100 + */
2.101 static gboolean
2.102 gmyth_livetv_setup_recorder_channel_name ( GMythLiveTV *livetv, gchar* channel,
2.103 GMythBackendInfo *backend_info )
2.104 @@ -353,12 +400,14 @@
2.105 }
2.106
2.107 if ( gmyth_remote_util_get_free_recorder_count (livetv->socket) <= 0 ) {
2.108 +
2.109 +#ifdef GMYTH_USE_DEBUG
2.110 gmyth_debug ("No free remote encoder available.");
2.111 -
2.112 +#endif
2.113 res = FALSE;
2.114 goto error;
2.115 }
2.116 -
2.117 +
2.118 /* Gets the recorder num */
2.119 livetv->recorder = remote_request_next_free_recorder (livetv->socket, -1);
2.120 gmyth_socket_close_connection (livetv->socket);
2.121 @@ -466,7 +515,9 @@
2.122 /* check if the program chain could be obtained from the MythTV protocol message */
2.123 if ( prog_info != NULL )
2.124 {
2.125 +#ifdef GMYTH_USE_DEBUG
2.126 gmyth_debug( "Program Info: %s\n", gmyth_program_info_to_string( prog_info ) );
2.127 +#endif
2.128 livetv->proginfo = prog_info;
2.129 /* testing change channel */
2.130 //gmyth_recorder_spawntv_no_tvchain( livetv->recorder );
2.131 @@ -544,6 +595,18 @@
2.132
2.133 }
2.134
2.135 +/**
2.136 + * Setup the GMythLiveTV session, sends SPAWN_LIVETV message,
2.137 + * sets the channel name, and gets the first program info about the
2.138 + * actual recording
2.139 + *
2.140 + * @param live_tv the GMythLiveTV instance
2.141 + * @param channel the channel name, in numerical format
2.142 + * @param backend_info the GMythBackendInfo describing the remote server
2.143 + *
2.144 + * @return <code>true</code> if the LiveTV's recorder instance configuration
2.145 + * had been concluded succcesfully
2.146 + */
2.147 static gboolean
2.148 gmyth_livetv_setup_recorder ( GMythLiveTV *livetv, gint channel, GMythBackendInfo *backend_info )
2.149 {
2.150 @@ -551,24 +614,66 @@
2.151 g_strdup_printf( "%d", channel ) : NULL, backend_info );
2.152 }
2.153
2.154 +/**
2.155 + * Setup the GMythLiveTV session, sends SPAWN_LIVETV message,
2.156 + * sets the channel name (numerical format), and gets the first program info about the
2.157 + * actual recording
2.158 + *
2.159 + * @param live_tv the GMythLiveTV instance
2.160 + * @param channel the channel name, in numerical format
2.161 + * @param backend_info the GMythBackendInfo describing the remote server
2.162 + *
2.163 + * @return <code>true</code> if the LiveTV's recorder instance configuration
2.164 + * had been concluded succcesfully
2.165 + */
2.166 gboolean
2.167 gmyth_livetv_channel_setup ( GMythLiveTV *livetv, gint channel, GMythBackendInfo *backend_info )
2.168 {
2.169 return gmyth_livetv_setup_recorder ( livetv, channel, backend_info );
2.170 }
2.171
2.172 +/**
2.173 + * Setup the GMythLiveTV session, sends SPAWN_LIVETV message,
2.174 + * sets the channel name (string format), and gets the first program info about the
2.175 + * actual recording
2.176 + *
2.177 + * @param live_tv the GMythLiveTV instance
2.178 + * @param channel the channel name, in numerical format
2.179 + * @param backend_info the GMythBackendInfo describing the remote server
2.180 + *
2.181 + * @return <code>true</code> if the LiveTV's recorder instance configuration
2.182 + * had been concluded succcesfully
2.183 + */
2.184 gboolean
2.185 gmyth_livetv_channel_name_setup ( GMythLiveTV *livetv, gchar* channel, GMythBackendInfo *backend_info )
2.186 {
2.187 return gmyth_livetv_setup_recorder_channel_name ( livetv, channel, backend_info );
2.188 }
2.189
2.190 +/**
2.191 + * Setup the GMythLiveTV session, sends SPAWN_LIVETV message,
2.192 + * and gets the first program info about the actual recording
2.193 + * (doesn't changes the channel).
2.194 + *
2.195 + * @param live_tv the GMythLiveTV instance
2.196 + * @param backend_info the GMythBackendInfo describing the remote server
2.197 + *
2.198 + * @return <code>true</code> if the LiveTV's recorder instance configuration
2.199 + * had been concluded succcesfully
2.200 + */
2.201 gboolean
2.202 gmyth_livetv_setup ( GMythLiveTV *livetv, GMythBackendInfo *backend_info )
2.203 {
2.204 return gmyth_livetv_setup_recorder ( livetv, -1, backend_info );
2.205 }
2.206
2.207 +/**
2.208 + * Gets the next program info from this GMythLiveTV session.
2.209 + *
2.210 + * @param live_tv the GMythLiveTV instance
2.211 + *
2.212 + * @return <code>true</code> if the next program info could be got
2.213 + */
2.214 gboolean
2.215 gmyth_livetv_next_program_chain ( GMythLiveTV *livetv )
2.216 {
2.217 @@ -639,6 +744,15 @@
2.218
2.219 }
2.220
2.221 +/**
2.222 + * Creates a File Transfer session, using all configuration information
2.223 + * got from the actual program info.
2.224 + *
2.225 + * @param live_tv the GMythLiveTV instance
2.226 + *
2.227 + * @return the actual GMythFileTransfer instance, generated using the
2.228 + * data got from the actual program info.
2.229 + */
2.230 GMythFileTransfer *
2.231 gmyth_livetv_create_file_transfer( GMythLiveTV *livetv )
2.232 {
2.233 @@ -653,10 +767,12 @@
2.234 goto done;
2.235 }
2.236
2.237 +#ifdef GMYTH_USE_DEBUG
2.238 if ( livetv->proginfo != NULL )
2.239 gmyth_debug( "URI path (from program info) = %s.\n", livetv->proginfo->pathname->str );
2.240 else
2.241 - gmyth_debug( "URI path (from URI) = %s.\n", livetv->uri->uri->str );
2.242 + gmyth_debug( "URI path (from URI) = %s.\n", livetv->uri->uri->str );
2.243 +#endif
2.244
2.245 g_mutex_lock( livetv->mutex );
2.246
2.247 @@ -676,11 +792,15 @@
2.248 livetv->uri->path = NULL;
2.249 }
2.250 */
2.251 - gmyth_debug( "URI is NULL, creating from the ProgramInfo pathname... (%s)", livetv->proginfo->pathname->str );
2.252 +#ifdef GMYTH_USE_DEBUG
2.253 + gmyth_debug( "URI is not NULL, creating from the ProgramInfo pathname... (%s)", livetv->proginfo->pathname->str );
2.254 +#endif
2.255 livetv->uri->path = g_string_erase(livetv->uri->path, 0, -1);
2.256 livetv->uri->path = g_string_new( g_strrstr( livetv->proginfo->pathname->str, "/" ) );
2.257 } else {
2.258 +#ifdef GMYTH_USE_DEBUG
2.259 gmyth_debug( "URI is NULL, creating from the ProgramInfo pathname... (%s)", livetv->proginfo->pathname->str );
2.260 +#endif
2.261 livetv->uri = gmyth_uri_new_with_value( livetv->proginfo->pathname->str );
2.262 }
2.263
2.264 @@ -698,9 +818,9 @@
2.265 goto done;
2.266 }
2.267
2.268 - //gmyth_file_transfer_settimeout( livetv->file_transfer, TRUE );
2.269 + /* gmyth_file_transfer_settimeout( livetv->file_transfer, TRUE ); */
2.270
2.271 - g_mutex_unlock( livetv->mutex );
2.272 + g_mutex_unlock( livetv->mutex );
2.273
2.274 done:
2.275 /*
2.276 @@ -715,7 +835,11 @@
2.277
2.278 }
2.279
2.280 -/* FIXME: How to proceed differently between livetv and recorded content */
2.281 +/**
2.282 + * Stops this LiveTV session.
2.283 + *
2.284 + * @param live_tv the GMythLiveTV instance
2.285 + */
2.286 void
2.287 gmyth_livetv_stop_playing (GMythLiveTV *livetv)
2.288 {
2.289 @@ -723,11 +847,11 @@
2.290
2.291 if (livetv->is_livetv) {
2.292 if ( !gmyth_recorder_stop_livetv (livetv->recorder) ) {
2.293 - g_debug ("[%s] Error while stoping remote encoder", __FUNCTION__);
2.294 + gmyth_debug ("[%s] Error while stoping remote encoder", __FUNCTION__);
2.295 }
2.296
2.297 if ( !gmyth_recorder_finish_recording(livetv->recorder) ) {
2.298 - g_debug ("[%s] Error while finishing recording on remote encoder", __FUNCTION__);
2.299 + gmyth_debug ("[%s] Error while finishing recording on remote encoder", __FUNCTION__);
2.300 }
2.301 }
2.302 }
3.1 --- a/gmyth/src/gmyth_tvchain.c Thu Mar 22 15:19:38 2007 +0000
3.2 +++ b/gmyth/src/gmyth_tvchain.c Thu Mar 22 18:12:26 2007 +0000
3.3 @@ -52,8 +52,6 @@
3.4
3.5 G_DEFINE_TYPE(GMythTVChain, gmyth_tvchain, G_TYPE_OBJECT)
3.6
3.7 -static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
3.8 -
3.9 static void
3.10 gmyth_tvchain_class_init (GMythTVChainClass *klass)
3.11 {
3.12 @@ -67,11 +65,13 @@
3.13
3.14 static void
3.15 gmyth_tvchain_init (GMythTVChain *tvchain)
3.16 -{
3.17 +{
3.18 tvchain->tvchain_id = NULL;
3.19
3.20 tvchain->cur_chanid = g_string_new ("");
3.21 tvchain->cur_startts = NULL;
3.22 +
3.23 + tvchain->mutex = g_mutex_new();
3.24 }
3.25
3.26 GMythTVChain*
3.27 @@ -88,13 +88,18 @@
3.28 GMythTVChain *tvchain = GMYTH_TVCHAIN(object);
3.29
3.30 if ( tvchain->tvchain_id != NULL ) {
3.31 - g_string_free( tvchain->tvchain_id, TRUE );
3.32 - tvchain->tvchain_id = NULL;
3.33 + g_string_free( tvchain->tvchain_id, TRUE );
3.34 + tvchain->tvchain_id = NULL;
3.35 + }
3.36 +
3.37 + if ( tvchain->mutex != NULL ) {
3.38 + g_mutex_free( tvchain->mutex );
3.39 + tvchain->mutex = NULL;
3.40 }
3.41
3.42 if ( tvchain->tvchain_list != NULL ) {
3.43 - g_list_free( tvchain->tvchain_list );
3.44 - tvchain->tvchain_list = NULL;
3.45 + g_list_free( tvchain->tvchain_list );
3.46 + tvchain->tvchain_list = NULL;
3.47 }
3.48
3.49 if ( tvchain->cur_chanid != NULL ) {
3.50 @@ -190,7 +195,7 @@
3.51 gboolean ret = TRUE;
3.52 GString *stmt_str = NULL;
3.53
3.54 - g_static_mutex_lock( &mutex );
3.55 + g_mutex_lock( tvchain->mutex );
3.56
3.57 /* gets the initial size of the TVChain entries list */
3.58 guint prev_size = g_list_length (tvchain->tvchain_list);
3.59 @@ -206,7 +211,7 @@
3.60 gmyth_query = gmyth_query_new ();
3.61 if (!gmyth_query_connect (gmyth_query, tvchain->backend_info)) {
3.62 g_warning ("[%s] Could not connect to db", __FUNCTION__);
3.63 - g_static_mutex_unlock( &mutex );
3.64 + g_mutex_unlock( tvchain->mutex );
3.65 ret = FALSE;
3.66 goto done;
3.67 }
3.68 @@ -245,13 +250,13 @@
3.69 }
3.70 } else {
3.71 g_warning ("gmyth_tvchain_reload_all query error!\n");
3.72 - g_static_mutex_unlock( &mutex );
3.73 + g_mutex_unlock( tvchain->mutex );
3.74
3.75 ret = FALSE;
3.76 goto done;
3.77 }
3.78
3.79 - g_static_mutex_unlock( &mutex );
3.80 + g_mutex_unlock( tvchain->mutex );
3.81
3.82 tvchain->cur_pos = gmyth_tvchain_program_is_at (tvchain, tvchain->cur_chanid, tvchain->cur_startts);
3.83 g_print( "[%s] TVChain current position = %d.\n", __FUNCTION__, tvchain->cur_pos );
3.84 @@ -294,7 +299,7 @@
3.85 GList *tmp_list = tvchain->tvchain_list;
3.86 guint list_size = g_list_length (tvchain->tvchain_list);
3.87
3.88 - g_static_mutex_lock( &mutex );
3.89 + g_mutex_lock( tvchain->mutex );
3.90
3.91 for (; tmp_list && ( count < list_size ); tmp_list = tvchain->tvchain_list->next, count++)
3.92 {
3.93 @@ -302,11 +307,11 @@
3.94 if ( !g_strncasecmp (entry->chanid->str, chanid->str, chanid->len)
3.95 && entry->starttime == startts )
3.96 {
3.97 - g_static_mutex_unlock( &mutex );
3.98 + g_mutex_unlock( tvchain->mutex );
3.99 return count;
3.100 }
3.101 }
3.102 - g_static_mutex_unlock( &mutex );
3.103 + g_mutex_unlock( tvchain->mutex );
3.104
3.105 return -1;
3.106 }
3.107 @@ -343,7 +348,7 @@
3.108
3.109 g_return_val_if_fail( tvchain != NULL && tvchain->tvchain_list != NULL, NULL );
3.110
3.111 - g_static_mutex_lock( &mutex );
3.112 + g_mutex_lock( tvchain->mutex );
3.113
3.114 gint size = g_list_length (tvchain->tvchain_list);
3.115 gint new_index = (index < 0 || index >= size) ? size - 1 : index;
3.116 @@ -351,7 +356,7 @@
3.117 if (new_index >= 0)
3.118 chain_entry = (struct LiveTVChainEntry*) g_list_nth_data (tvchain->tvchain_list, new_index);
3.119
3.120 - g_static_mutex_unlock( &mutex );
3.121 + g_mutex_unlock( tvchain->mutex );
3.122
3.123 if ( chain_entry != NULL ) {
3.124 gmyth_debug ("[%s] Got TV Chain entry at %d.\n", __FUNCTION__, new_index );
4.1 --- a/gmyth/src/gmyth_tvchain.h Thu Mar 22 15:19:38 2007 +0000
4.2 +++ b/gmyth/src/gmyth_tvchain.h Thu Mar 22 18:12:26 2007 +0000
4.3 @@ -84,6 +84,8 @@
4.4 gint cur_pos;
4.5
4.6 GMythBackendInfo *backend_info;
4.7 +
4.8 + GMutex *mutex;
4.9 };
4.10
4.11 GType gmyth_tvchain_get_type (void);