branches/gmyth-0.1b/src/gmyth_recorder.c
branchtrunk
changeset 326 81b1f3006eb2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/branches/gmyth-0.1b/src/gmyth_recorder.c	Tue Feb 06 00:33:35 2007 +0000
     1.3 @@ -0,0 +1,654 @@
     1.4 +/**
     1.5 + * GMyth Library
     1.6 + *
     1.7 + * @file gmyth/gmyth_remote_encoder.c
     1.8 + * 
     1.9 + * @brief <p> GMythRecorder class defines functions for playing live tv.
    1.10 + *
    1.11 + * The remote encoder is used by gmyth_tvplayer to setup livetv. 
    1.12 + *
    1.13 + * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    1.14 + * @author Hallyson Luiz de Morais Melo <hallyson.melo@indt.org.br>
    1.15 + *
    1.16 + *//*
    1.17 + * 
    1.18 + * This program is free software; you can redistribute it and/or modify
    1.19 + * it under the terms of the GNU Lesser General Public License as published by
    1.20 + * the Free Software Foundation; either version 2 of the License, or
    1.21 + * (at your option) any later version.
    1.22 + *
    1.23 + * This program is distributed in the hope that it will be useful,
    1.24 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.25 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.26 + * GNU General Public License for more details.
    1.27 + *
    1.28 + * You should have received a copy of the GNU Lesser General Public License
    1.29 + * along with this program; if not, write to the Free Software
    1.30 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.31 + */
    1.32 + 
    1.33 +#ifdef HAVE_CONFIG_H
    1.34 +#include "config.h"
    1.35 +#endif
    1.36 +
    1.37 +#include "gmyth_recorder.h"
    1.38 +
    1.39 +#include <assert.h>
    1.40 +
    1.41 +#include "gmyth_stringlist.h"
    1.42 +#include "gmyth_util.h"
    1.43 +#include "gmyth_debug.h"
    1.44 +
    1.45 +#define	 GMYTHTV_RECORDER_HEADER			"QUERY_RECORDER"
    1.46 +
    1.47 +static void gmyth_recorder_class_init          (GMythRecorderClass *klass);
    1.48 +static void gmyth_recorder_init                (GMythRecorder *object);
    1.49 +
    1.50 +static void gmyth_recorder_dispose  (GObject *object);
    1.51 +static void gmyth_recorder_finalize (GObject *object);
    1.52 +
    1.53 +G_DEFINE_TYPE(GMythRecorder, gmyth_recorder, G_TYPE_OBJECT)
    1.54 +    
    1.55 +static void
    1.56 +gmyth_recorder_class_init (GMythRecorderClass *klass)
    1.57 +{
    1.58 +    GObjectClass *gobject_class;
    1.59 +
    1.60 +    gobject_class = (GObjectClass *) klass;
    1.61 +	
    1.62 +    gobject_class->dispose  = gmyth_recorder_dispose;
    1.63 +    gobject_class->finalize = gmyth_recorder_finalize;	
    1.64 +}
    1.65 +
    1.66 +static void
    1.67 +gmyth_recorder_init (GMythRecorder *gmyth_remote_encoder)
    1.68 +{
    1.69 +}
    1.70 +
    1.71 +static void
    1.72 +gmyth_recorder_dispose  (GObject *object)
    1.73 +{
    1.74 +    // GMythRecorder *gmyth_remote_encoder = GMYTH_RECORDER(object);
    1.75 +    
    1.76 +	G_OBJECT_CLASS (gmyth_recorder_parent_class)->dispose (object);
    1.77 +}
    1.78 +
    1.79 +
    1.80 +static void
    1.81 +gmyth_recorder_finalize (GObject *object)
    1.82 +{
    1.83 +	g_signal_handlers_destroy (object);
    1.84 +
    1.85 +  GMythRecorder *recorder = GMYTH_RECORDER(object);
    1.86 +
    1.87 +	gmyth_debug ("[%s] Closing control socket", __FUNCTION__);
    1.88 +	gmyth_socket_close_connection(recorder->myth_socket);
    1.89 +	g_object_unref (recorder->myth_socket);
    1.90 +    
    1.91 +  G_OBJECT_CLASS (gmyth_recorder_parent_class)->finalize (object);
    1.92 +}
    1.93 +
    1.94 +/** Creates a new instance of GMythRecorder.
    1.95 + * 
    1.96 + * @return a new instance of GMythRecorder.
    1.97 + */
    1.98 +GMythRecorder*
    1.99 +gmyth_recorder_new (int num, GString *hostname, gshort port)
   1.100 +{
   1.101 +	GMythRecorder *encoder = GMYTH_RECORDER ( g_object_new (
   1.102 +			GMYTH_RECORDER_TYPE, FALSE ));
   1.103 +			
   1.104 +	encoder->recorder_num = num;
   1.105 +	encoder->hostname = g_string_new (hostname->str);
   1.106 +	encoder->port = port;
   1.107 +	
   1.108 +	return encoder;
   1.109 +}
   1.110 +
   1.111 +/** Configures the remote encoder instance connecting it to Mythtv backend.
   1.112 + * 
   1.113 + * @param recorder the GMythRecorder instance.
   1.114 + * @return TRUE if successfull, FALSE if any error happens.
   1.115 + */
   1.116 +gboolean
   1.117 +gmyth_recorder_setup (GMythRecorder *recorder)
   1.118 +{
   1.119 +	assert (recorder);
   1.120 +	gmyth_debug ("[%s] Creating socket and connecting to backend", __FUNCTION__);
   1.121 +
   1.122 +	if (recorder->myth_socket == NULL) {
   1.123 +		
   1.124 +		recorder->myth_socket = gmyth_socket_new ();
   1.125 +		
   1.126 +		if (!gmyth_socket_connect_to_backend ( recorder->myth_socket, recorder->hostname->str, 
   1.127 +					recorder->port, TRUE ) ) {
   1.128 +			g_warning ("GMythRemoteEncoder: Connection to backend failed");	
   1.129 +			return FALSE;
   1.130 +		}
   1.131 +		
   1.132 +	} else {
   1.133 +		g_warning("Remote encoder socket already created\n");
   1.134 +	}
   1.135 +
   1.136 +	return TRUE;
   1.137 +}
   1.138 +
   1.139 +/** Sends the SPAWN_LIVETV command through Mythtv protocol. This command
   1.140 + * requests the backend to start capturing TV content.
   1.141 + * 
   1.142 + * @param recorder The GMythRecorder instance.
   1.143 + * @param tvchain_id The tvchain unique id.
   1.144 + * @return true if success, false if any error happens.
   1.145 + */
   1.146 +gboolean
   1.147 +gmyth_recorder_spawntv (GMythRecorder *recorder, GString *tvchain_id)
   1.148 +{
   1.149 +	GMythStringList *str_list;
   1.150 +	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
   1.151 +	
   1.152 +	gmyth_debug ("[%s] Spawntv with tvchain_id = %s", __FUNCTION__, tvchain_id->str);
   1.153 +	
   1.154 +	str_list = gmyth_string_list_new ();
   1.155 +	
   1.156 +	g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); 
   1.157 +	
   1.158 +	gmyth_string_list_append_string (str_list, tmp_str);
   1.159 +	gmyth_string_list_append_string (str_list, g_string_new ("SPAWN_LIVETV"));
   1.160 +	gmyth_string_list_append_string (str_list, tvchain_id);
   1.161 +	gmyth_string_list_append_int (str_list, 0); // PIP = FALSE (0)
   1.162 +
   1.163 +	gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   1.164 +	
   1.165 +    g_string_free (tmp_str, TRUE);
   1.166 +    
   1.167 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   1.168 +    if (tmp_str == NULL) {
   1.169 +    	g_warning ("[%s] Spawntv request returned %s", __FUNCTION__, tmp_str->str);
   1.170 +    	return FALSE;
   1.171 +	}
   1.172 +	
   1.173 +    if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   1.174 +    	g_warning ("[%s] Spawntv request returned %s", __FUNCTION__, tmp_str->str);
   1.175 +	    g_object_unref (str_list);
   1.176 +    	return FALSE;
   1.177 +    }
   1.178 +
   1.179 +    g_object_unref (str_list);
   1.180 +    return TRUE;
   1.181 +
   1.182 +}
   1.183 +
   1.184 +/** 
   1.185 + * Sends the SPAWN_LIVETV command through Mythtv protocol. This command
   1.186 + * requests the backend to start capturing TV content, but it doesn't need
   1.187 + * the TV chain ID.
   1.188 + * 
   1.189 + * @param recorder The GMythRecorder instance.
   1.190 + * @return true if success, false if any error happens.
   1.191 + */
   1.192 +gboolean
   1.193 +gmyth_recorder_spawntv_no_tvchain (GMythRecorder *recorder)
   1.194 +{
   1.195 +	GMythStringList *str_list;
   1.196 +	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
   1.197 +	
   1.198 +	gmyth_debug ("[%s] Spawntv, no TV chain!", __FUNCTION__);
   1.199 +	
   1.200 +	str_list = gmyth_string_list_new ();
   1.201 +	
   1.202 +	g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); 
   1.203 +	
   1.204 +	gmyth_string_list_append_string (str_list, tmp_str);
   1.205 +	gmyth_string_list_append_string (str_list, g_string_new ("SPAWN_LIVETV"));
   1.206 +
   1.207 +	gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   1.208 +	
   1.209 +    g_string_free (tmp_str, TRUE);
   1.210 +    
   1.211 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   1.212 +    if (tmp_str == NULL) {
   1.213 +    	g_warning ("[%s] Spawntv request returned %s", __FUNCTION__, tmp_str->str);
   1.214 +    	return FALSE;
   1.215 +	}
   1.216 +	
   1.217 +    if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   1.218 +    	g_warning ("[%s] Spawntv request returned %s", __FUNCTION__, tmp_str->str);
   1.219 +	    g_object_unref (str_list);
   1.220 +    	return FALSE;
   1.221 +    }
   1.222 +
   1.223 +    g_object_unref (str_list);
   1.224 +    return TRUE;
   1.225 +
   1.226 +}
   1.227 +
   1.228 +/** Sends the command STOP_LIVETV to Mythtv backend.
   1.229 + * 
   1.230 + * @param recorder the GMythRecorder instance.
   1.231 + * @return true if success, false if any error happens.
   1.232 + */
   1.233 +gboolean
   1.234 +gmyth_recorder_stop_livetv (GMythRecorder *recorder)
   1.235 +{
   1.236 +	GMythStringList *str_list;
   1.237 +	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
   1.238 +
   1.239 +	gmyth_debug ("[%s]", __FUNCTION__);
   1.240 +
   1.241 +	str_list = gmyth_string_list_new ();
   1.242 +
   1.243 +	g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); 
   1.244 +	gmyth_string_list_append_char_array( str_list, "STOP_LIVETV" );
   1.245 +
   1.246 +	gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   1.247 +
   1.248 +	g_string_free (tmp_str, TRUE);
   1.249 +
   1.250 +	tmp_str = gmyth_string_list_get_string (str_list, 0);
   1.251 +	if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   1.252 +		g_warning ("[%s] Stop livetv request returned %s", __FUNCTION__, tmp_str->str);
   1.253 +		g_object_unref (str_list);
   1.254 +		return FALSE;
   1.255 +	}
   1.256 +
   1.257 +	g_object_unref (str_list);
   1.258 +	return TRUE;
   1.259 +
   1.260 +}
   1.261 +
   1.262 +/** Sends the FRONTEND_READY command through Mythtv protocol. This command
   1.263 + * advertises the backend to start capturing TV content.
   1.264 + * 
   1.265 + * @param recorder The GMythRecorder instance.
   1.266 + * @return TRUE if success, FALSE if any error happens.
   1.267 + */
   1.268 +gboolean
   1.269 +gmyth_recorder_send_frontend_ready_command (GMythRecorder *recorder)
   1.270 +{
   1.271 +	GMythStringList *str_list;
   1.272 +	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
   1.273 +	
   1.274 +	gmyth_debug ( "[%s] FRONTEND_READY with recorder id = %d", __FUNCTION__, recorder->recorder_num );
   1.275 +	
   1.276 +	str_list = gmyth_string_list_new ();
   1.277 +	
   1.278 +	g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); 
   1.279 +	
   1.280 +	gmyth_string_list_append_string (str_list, tmp_str);
   1.281 +	gmyth_string_list_append_string (str_list, g_string_new ("FRONTEND_READY"));
   1.282 +
   1.283 +	gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   1.284 +	
   1.285 +  g_string_free (tmp_str, TRUE);
   1.286 +    
   1.287 +  tmp_str = gmyth_string_list_get_string (str_list, 0);
   1.288 +  if (tmp_str == NULL) {
   1.289 +  	g_warning ("[%s] FRONTEND_READY command request couldn't returns, reason: %s", __FUNCTION__, tmp_str->str);
   1.290 +  	return FALSE;
   1.291 +	}
   1.292 +	
   1.293 +  if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   1.294 +  	g_warning ("[%s] FRONTEND_READY request returned %s", __FUNCTION__, tmp_str->str);
   1.295 +    g_object_unref (str_list);
   1.296 +  	return FALSE;
   1.297 +  }
   1.298 +
   1.299 +  g_object_unref (str_list);
   1.300 +  return TRUE;
   1.301 +
   1.302 +}
   1.303 +
   1.304 +/** Send a CHECK_CHANNEL command request to the backend, in order to find if a 
   1.305 + * certain channel actually exists.
   1.306 + * 
   1.307 + * @param recorder The GMythRecorder instance.
   1.308 + * @param channel	 The new channel to be checked (string format).
   1.309 + * @return true if success, false if any error happens.
   1.310 + */
   1.311 +gboolean
   1.312 +gmyth_recorder_check_channel_name (GMythRecorder *recorder, gchar* channel)
   1.313 +{
   1.314 +	GMythStringList *str_list;
   1.315 +	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
   1.316 +	
   1.317 +	gmyth_debug ("[%s] CHECK_CHANNEL with channel = %s", __FUNCTION__, channel);
   1.318 +	
   1.319 +	str_list = gmyth_string_list_new ();
   1.320 +	
   1.321 +	g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); 
   1.322 +	
   1.323 +	gmyth_string_list_append_string (str_list, tmp_str);
   1.324 +	gmyth_string_list_append_string (str_list, g_string_new ("CHECK_CHANNEL"));
   1.325 +	gmyth_string_list_append_char_array (str_list, channel);
   1.326 +
   1.327 +	gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   1.328 +	
   1.329 +    g_string_free (tmp_str, TRUE);
   1.330 +    
   1.331 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   1.332 +    if (tmp_str == NULL) {
   1.333 +    	g_warning ("[%s] CHECK_CHANNEL request returned %s", __FUNCTION__, tmp_str->str);
   1.334 +    	return FALSE;
   1.335 +	}
   1.336 +	
   1.337 +    if (g_ascii_strncasecmp (tmp_str->str, "ok", 2) == 0 || g_ascii_strncasecmp (tmp_str->str, "0", 1) == 0 ) {
   1.338 +    	g_warning ("[%s] CHECK_CHANNEL request returned %s", __FUNCTION__, tmp_str->str);
   1.339 +	    g_object_unref (str_list);
   1.340 +    	return FALSE;
   1.341 +    }
   1.342 +
   1.343 +    g_object_unref (str_list);
   1.344 +    return TRUE;
   1.345 +
   1.346 +}
   1.347 +
   1.348 +/** Send a CHECK_CHANNEL command request to the backend, in order to find if a 
   1.349 + * certain channel actually exists.
   1.350 + * 
   1.351 + * @param recorder The GMythRecorder instance.
   1.352 + * @param channel	 The new channel to be checked (decimal integer value).
   1.353 + * @return true if success, false if any error happens.
   1.354 + */
   1.355 +gboolean
   1.356 +gmyth_recorder_check_channel (GMythRecorder *recorder, gint channel)
   1.357 +{
   1.358 +	return gmyth_recorder_check_channel_name( recorder, g_strdup_printf( "%d", channel ) );
   1.359 +}
   1.360 +
   1.361 +/** Send a SET_CHANNEL command request to the backend, to start streaming on another 
   1.362 + * TV content channel.
   1.363 + * 
   1.364 + * @param recorder The GMythRecorder instance.
   1.365 + * @param channel	 The new channel to be loaded.
   1.366 + * @return true if success, false if any error happens.
   1.367 + */
   1.368 +gboolean
   1.369 +gmyth_recorder_set_channel (GMythRecorder *recorder, gint channel)
   1.370 +{
   1.371 +	GMythStringList *str_list;
   1.372 +	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
   1.373 +	
   1.374 +	gmyth_debug ("[%s] SET_CHANNEL with channel = %d", __FUNCTION__, channel);
   1.375 +	
   1.376 +	str_list = gmyth_string_list_new ();
   1.377 +	
   1.378 +	g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); 
   1.379 +	
   1.380 +	gmyth_string_list_append_string (str_list, tmp_str);
   1.381 +	gmyth_string_list_append_string (str_list, g_string_new ("SET_CHANNEL"));
   1.382 +	gmyth_string_list_append_int (str_list, channel);
   1.383 +
   1.384 +	gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   1.385 +	
   1.386 +    g_string_free (tmp_str, TRUE);
   1.387 +    
   1.388 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   1.389 +    if (tmp_str == NULL) {
   1.390 +    	g_warning ("[%s] SET_CHANNEL request returned %s", __FUNCTION__, tmp_str->str);
   1.391 +    	return FALSE;
   1.392 +	}
   1.393 +	
   1.394 +    if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   1.395 +    	g_warning ("[%s] SET_CHANNEL request returned %s", __FUNCTION__, tmp_str->str);
   1.396 +	    g_object_unref (str_list);
   1.397 +    	return FALSE;
   1.398 +    }
   1.399 +
   1.400 +    g_object_unref (str_list);
   1.401 +    return TRUE;
   1.402 +
   1.403 +}
   1.404 +
   1.405 +/** Send a SET_CHANNEL command request to the backend, to start streaming on another 
   1.406 + * TV content channel.
   1.407 + * 
   1.408 + * @param recorder The GMythRecorder instance.
   1.409 + * @param channel	 The new channel to be loaded.
   1.410 + * @return true if success, false if any error happens.
   1.411 + */
   1.412 +gboolean
   1.413 +gmyth_recorder_set_channel_name (GMythRecorder *recorder, const gchar* channel)
   1.414 +{
   1.415 +	GMythStringList *str_list;
   1.416 +	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
   1.417 +	
   1.418 +	gmyth_debug ("[%s] SET_CHANNEL with channel name = %s", __FUNCTION__, channel);
   1.419 +	
   1.420 +	str_list = gmyth_string_list_new ();
   1.421 +	
   1.422 +	g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); 
   1.423 +	
   1.424 +	gmyth_string_list_append_string (str_list, tmp_str);
   1.425 +	gmyth_string_list_append_string (str_list, g_string_new ("SET_CHANNEL"));
   1.426 +	gmyth_string_list_append_char_array (str_list, channel);
   1.427 +
   1.428 +	gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   1.429 +	
   1.430 +    g_string_free (tmp_str, TRUE);
   1.431 +    
   1.432 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   1.433 +    if (tmp_str == NULL) {
   1.434 +    	g_warning ("[%s] SET_CHANNEL name request returned %s", __FUNCTION__, tmp_str->str );
   1.435 +    	return FALSE;
   1.436 +	}
   1.437 +	
   1.438 +    if (g_ascii_strncasecmp (tmp_str->str, "ok", 2) || g_ascii_strtoull( tmp_str->str, NULL, 10 ) == 0 ) {
   1.439 +    	g_warning ("[%s] SET_CHANNEL name request returned %s", __FUNCTION__, tmp_str->str);
   1.440 +	    g_object_unref (str_list);
   1.441 +    	return FALSE;
   1.442 +    }
   1.443 +
   1.444 +    g_object_unref (str_list);
   1.445 +    return TRUE;
   1.446 +
   1.447 +}
   1.448 +
   1.449 +/**
   1.450 + * Changes the channel of the actual Recorder.
   1.451 + * 
   1.452 + * CHANNEL_DIRECTION_UP       - Go up one channel in the listing
   1.453 + *
   1.454 + * CHANNEL_DIRECTION_DOWN     - Go down one channel in the listing
   1.455 + *
   1.456 + * CHANNEL_DIRECTION_FAVORITE - Go to the next favorite channel
   1.457 + *
   1.458 + * CHANNEL_DIRECTION_SAME     - Stay
   1.459 + * 
   1.460 + * @param recorder 	 The GMythRecorder instance.
   1.461 + * @param direction	 The new channel direction where to move to.
   1.462 + * @return true if success, false if any error happens.
   1.463 + */
   1.464 +gboolean
   1.465 +gmyth_recorder_change_channel (GMythRecorder *recorder, const GMythRecorderChannelChangeDirection direction)
   1.466 +{
   1.467 +	GMythStringList *str_list;
   1.468 +	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
   1.469 +	
   1.470 +	gmyth_debug ("[%s] CHANGE_CHANNEL to the channel direction = %u", __FUNCTION__, direction);
   1.471 +	
   1.472 +	str_list = gmyth_string_list_new ();
   1.473 +	
   1.474 +	g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); 
   1.475 +	
   1.476 +	gmyth_string_list_append_string (str_list, tmp_str);
   1.477 +	gmyth_string_list_append_string (str_list, g_string_new ("CHANGE_CHANNEL"));
   1.478 +	gmyth_string_list_append_int (str_list, direction);
   1.479 +
   1.480 +	gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   1.481 +	
   1.482 +    g_string_free (tmp_str, TRUE);
   1.483 +    
   1.484 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   1.485 +    if (tmp_str == NULL) {
   1.486 +    	g_warning ("[%s] CHANGE_CHANNEL name request returned %s", __FUNCTION__, tmp_str->str );
   1.487 +    	return FALSE;
   1.488 +	}
   1.489 +	
   1.490 +    if (g_ascii_strncasecmp (tmp_str->str, "ok", 2) || g_ascii_strtoull( tmp_str->str, NULL, 10 ) == 0 ) {
   1.491 +    	g_warning ("[%s] CHANGE_CHANNEL name request returned %s", __FUNCTION__, tmp_str->str);
   1.492 +	    g_object_unref (str_list);
   1.493 +    	return FALSE;
   1.494 +    }
   1.495 +
   1.496 +    g_object_unref (str_list);
   1.497 +    return TRUE;
   1.498 +
   1.499 +}
   1.500 +
   1.501 +/** Send a PAUSE command request to the backend, to pause streaming on another 
   1.502 + * TV content channel.
   1.503 + * 
   1.504 + * @param recorder The GMythRecorder instance.
   1.505 + * @return true if success, false if any error happens.
   1.506 + */
   1.507 +gboolean
   1.508 +gmyth_recorder_pause_recording ( GMythRecorder *recorder )
   1.509 +{
   1.510 +	GMythStringList *str_list;
   1.511 +	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
   1.512 +	
   1.513 +	gmyth_debug ("[%s] PAUSE", __FUNCTION__);
   1.514 +	
   1.515 +	str_list = gmyth_string_list_new ();
   1.516 +	
   1.517 +	g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); 
   1.518 +	
   1.519 +	gmyth_string_list_append_string (str_list, tmp_str);
   1.520 +	gmyth_string_list_append_string (str_list, g_string_new ("PAUSE"));
   1.521 +
   1.522 +	gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   1.523 +	
   1.524 +    g_string_free (tmp_str, TRUE);
   1.525 +    
   1.526 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   1.527 +    if (tmp_str == NULL) {
   1.528 +    	g_warning ("[%s] PAUSE name request returned %s", __FUNCTION__, tmp_str->str);
   1.529 +    	return FALSE;
   1.530 +	}
   1.531 +	
   1.532 +    if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   1.533 +    	g_warning ("[%s] PAUSE name request returned %s", __FUNCTION__, tmp_str->str);
   1.534 +	    g_object_unref (str_list);
   1.535 +    	return FALSE;
   1.536 +    }
   1.537 +
   1.538 +    g_object_unref (str_list);
   1.539 +    return TRUE;
   1.540 +
   1.541 +}
   1.542 +
   1.543 +/**
   1.544 + * Requests the actual program info from the MythTV backend server.
   1.545 + * 
   1.546 + * @param recorder The GMythRecorder instance.
   1.547 + * @return The actual program info.
   1.548 + */
   1.549 +GMythProgramInfo *
   1.550 +gmyth_recorder_get_current_program_info ( GMythRecorder *recorder )
   1.551 +{
   1.552 +	GMythStringList *str_list;
   1.553 +	GMythProgramInfo *program_info = gmyth_program_info_new();
   1.554 +	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
   1.555 +	
   1.556 +	str_list = gmyth_string_list_new ();
   1.557 +	
   1.558 +	g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); 
   1.559 +	
   1.560 +	gmyth_string_list_append_string (str_list, tmp_str);
   1.561 +	
   1.562 +	if ( recorder->myth_socket->mythtv_version >= 26 )
   1.563 +		gmyth_string_list_append_string (str_list, g_string_new ("GET_CURRENT_RECORDING"));
   1.564 +	else
   1.565 +		gmyth_string_list_append_string (str_list, g_string_new ("GET_PROGRAM_INFO"));
   1.566 +
   1.567 +	gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   1.568 +
   1.569 +  g_string_free (tmp_str, TRUE);
   1.570 +
   1.571 +  if (str_list == NULL) {
   1.572 +  	g_warning ("[%s] GET_PROGRAM_INFO request returned. Error getting program info, string list equals to NULL!", __FUNCTION__);
   1.573 +  	return FALSE;
   1.574 +	}
   1.575 +  
   1.576 +  program_info = gmyth_program_info_from_string_list( str_list );
   1.577 +
   1.578 +  if ( NULL == program_info ) {
   1.579 +  	g_warning ("[%s] GET_PROGRAM_INFO request returned. Error getting program info, it is equals to NULL!!!", __FUNCTION__);
   1.580 +    g_object_unref (program_info);
   1.581 +  	return NULL;
   1.582 +  }
   1.583 +
   1.584 +  g_object_unref (str_list);
   1.585 +  return program_info;
   1.586 +
   1.587 +}
   1.588 +
   1.589 +gint64
   1.590 +gmyth_recorder_get_file_position ( GMythRecorder *recorder )
   1.591 +{
   1.592 +  gint64 pos = 0;
   1.593 +  GString *query = g_string_new( GMYTHTV_RECORDER_HEADER );
   1.594 +
   1.595 +  GMythStringList *str_list = gmyth_string_list_new ();
   1.596 +
   1.597 +  g_string_append_printf( query, " %d", recorder->recorder_num );
   1.598 +
   1.599 +  gmyth_string_list_append_string (str_list, query);
   1.600 +  gmyth_string_list_append_char_array( str_list, "GET_FILE_POSITION" );
   1.601 +
   1.602 +  gmyth_socket_sendreceive_stringlist ( recorder->myth_socket, str_list );
   1.603 +
   1.604 +  if ( str_list != NULL && gmyth_string_list_length(str_list) > 0 ) 
   1.605 +  {
   1.606 +    GString *str = NULL;
   1.607 +    if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && strstr ( str->str, "bad" ) == NULL )
   1.608 +      pos = gmyth_util_decode_long_long( str_list, 0 );
   1.609 +  } 
   1.610 +
   1.611 +#ifndef GMYTHTV_ENABLE_DEBUG
   1.612 +  g_print( "[%s] Got file position = %lld\n", __FUNCTION__, pos );
   1.613 +#endif
   1.614 +  if (str_list!=NULL)
   1.615 +    g_object_unref (str_list);
   1.616 +
   1.617 +  return pos;
   1.618 +
   1.619 +}
   1.620 +
   1.621 +gboolean
   1.622 +gmyth_recorder_is_recording ( GMythRecorder *recorder )
   1.623 +{
   1.624 +  gboolean ret = TRUE;
   1.625 +  
   1.626 +  g_return_val_if_fail( recorder != NULL, FALSE );
   1.627 +
   1.628 +  GMythStringList *str_list = gmyth_string_list_new ();
   1.629 +  GString *message = g_string_new ("");
   1.630 +
   1.631 +  g_string_printf( message, "%s %d", GMYTHTV_RECORDER_HEADER, recorder->recorder_num);
   1.632 +  gmyth_string_list_append_string (str_list, message);
   1.633 +  gmyth_string_list_append_string (str_list, g_string_new ("IS_RECORDING"));
   1.634 +
   1.635 +  gmyth_socket_sendreceive_stringlist ( recorder->myth_socket, str_list );
   1.636 +
   1.637 +  if ( str_list != NULL && gmyth_string_list_length(str_list) > 0 )
   1.638 +  {
   1.639 +    GString *str = NULL;
   1.640 +    if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && strcmp( str->str, "bad" )!= 0 ) 
   1.641 +    {
   1.642 +      gint is_rec = gmyth_string_list_get_int( str_list, 0 );
   1.643 +      if ( is_rec != 0 )
   1.644 +        ret = TRUE;
   1.645 +      else
   1.646 +        ret = FALSE;
   1.647 +    }
   1.648 +  }
   1.649 +  gmyth_debug( "%s, stream is %s being recorded!\n", ret ? "YES" : "NO", ret ? "" : "NOT" );
   1.650 +  //g_static_mutex_unlock (&mutex);
   1.651 +
   1.652 +  if ( str_list != NULL )
   1.653 +    g_object_unref (str_list);
   1.654 +
   1.655 +  return ret;
   1.656 +
   1.657 +}