gmyth/src/gmyth_livetv.c
author rosfran
Tue Dec 12 18:19:35 2006 +0000 (2006-12-12)
branchtrunk
changeset 216 001205bb0f40
parent 213 631f2cf13501
child 220 462a3c81abd6
permissions -rwxr-xr-x
[svn r217] Added signals to program changed messages coming from backend (MythTV).
rosfran@68
     1
/**
rosfran@68
     2
 * GMyth Library
rosfran@68
     3
 *
rosfran@68
     4
 * @file gmyth/gmyth_livetv.c
rosfran@68
     5
 * 
rosfran@68
     6
 * @brief <p> GMythLiveTV starts a remote TV session with the MythTV backend.
rosfran@68
     7
 *
rosfran@68
     8
 * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
rosfran@68
     9
 * @author Rosfran Lins Borges <rosfran.borges@indt.org.br>
rosfran@68
    10
 *
rosfran@68
    11
 *//*
rosfran@68
    12
 * 
rosfran@68
    13
 * This program is free software; you can redistribute it and/or modify
rosfran@68
    14
 * it under the terms of the GNU Lesser General Public License as published by
rosfran@68
    15
 * the Free Software Foundation; either version 2 of the License, or
rosfran@68
    16
 * (at your option) any later version.
rosfran@68
    17
 *
rosfran@68
    18
 * This program is distributed in the hope that it will be useful,
rosfran@68
    19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rosfran@68
    20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
rosfran@68
    21
 * GNU General Public License for more details.
rosfran@68
    22
 *
rosfran@68
    23
 * You should have received a copy of the GNU Lesser General Public License
rosfran@68
    24
 * along with this program; if not, write to the Free Software
rosfran@68
    25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
rosfran@68
    26
 */
leo_sobral@213
    27
  
leo_sobral@213
    28
#ifdef HAVE_CONFIG_H
leo_sobral@213
    29
#include "config.h"
leo_sobral@213
    30
#endif
leo_sobral@213
    31
leo_sobral@213
    32
#include "gmyth_livetv.h"
rosfran@68
    33
 
rosfran@216
    34
#ifdef HAVE_CONFIG_H
rosfran@216
    35
#include "config.h"
rosfran@216
    36
#endif
rosfran@216
    37
rosfran@42
    38
#include "gmyth_remote_util.h"
rosfran@42
    39
#include "gmyth_tvchain.h"
melunko@117
    40
#include "gmyth_socket.h"
renatofilho@131
    41
#include "gmyth_debug.h"
rosfran@41
    42
rosfran@42
    43
#include "gmyth_file_transfer.h"
rosfran@216
    44
#include "gmyth_monitor_handler.h"
rosfran@41
    45
rosfran@41
    46
static void gmyth_livetv_class_init          (GMythLiveTVClass *klass);
rosfran@41
    47
static void gmyth_livetv_init                (GMythLiveTV *object);
rosfran@41
    48
rosfran@41
    49
static void gmyth_livetv_dispose  (GObject *object);
rosfran@41
    50
static void gmyth_livetv_finalize (GObject *object);
rosfran@41
    51
rosfran@41
    52
static gint tvchain_curr_index = -1; 
rosfran@41
    53
melunko@107
    54
#define GMYTHTV_RECORDER_HEADER         "QUERY_RECORDER"
melunko@107
    55
melunko@107
    56
rosfran@41
    57
G_DEFINE_TYPE(GMythLiveTV, gmyth_livetv, G_TYPE_OBJECT)
rosfran@41
    58
rosfran@41
    59
static void
rosfran@41
    60
gmyth_livetv_class_init (GMythLiveTVClass *klass)
rosfran@41
    61
{
rosfran@41
    62
	GObjectClass *gobject_class;
rosfran@41
    63
rosfran@41
    64
	gobject_class = (GObjectClass *) klass;
rosfran@41
    65
rosfran@41
    66
	gobject_class->dispose  = gmyth_livetv_dispose;
rosfran@41
    67
	gobject_class->finalize = gmyth_livetv_finalize;	
rosfran@41
    68
}
rosfran@41
    69
rosfran@41
    70
static void
rosfran@41
    71
gmyth_livetv_init (GMythLiveTV *livetv)
rosfran@41
    72
{
rosfran@216
    73
	livetv->backend_info = NULL;
rosfran@41
    74
	livetv->local_hostname = NULL;
rosfran@216
    75
	livetv->file_transfer = NULL;
rosfran@216
    76
	livetv->setup_done = FALSE;
rosfran@41
    77
rosfran@65
    78
	livetv->recorder = NULL;
rosfran@41
    79
	livetv->tvchain = NULL;
rosfran@41
    80
	livetv->proginfo = NULL;
rosfran@41
    81
}
rosfran@41
    82
rosfran@41
    83
static void
rosfran@41
    84
gmyth_livetv_dispose  (GObject *object)
rosfran@41
    85
{
rosfran@41
    86
rosfran@41
    87
	G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object);
rosfran@41
    88
}
rosfran@41
    89
rosfran@41
    90
static void
rosfran@41
    91
gmyth_livetv_finalize (GObject *object)
rosfran@41
    92
{
rosfran@41
    93
	g_signal_handlers_destroy (object);
rosfran@41
    94
rosfran@41
    95
	GMythLiveTV *livetv = GMYTH_LIVETV (object);
rosfran@41
    96
renatofilho@131
    97
	gmyth_debug ("[%s] Finalizing livetv", __FUNCTION__);
rosfran@41
    98
rosfran@216
    99
	if ( livetv->monitor != NULL ) {
rosfran@216
   100
		g_object_unref (livetv->monitor);
rosfran@216
   101
		livetv->monitor = NULL;
rosfran@216
   102
	}
rosfran@216
   103
rosfran@65
   104
	if ( livetv->recorder != NULL ) {
rosfran@65
   105
		g_object_unref (livetv->recorder);
rosfran@65
   106
		livetv->recorder = NULL;
rosfran@41
   107
	}
rosfran@41
   108
rosfran@41
   109
	if ( livetv->tvchain != NULL ) {
rosfran@41
   110
		g_object_unref (livetv->tvchain);
rosfran@41
   111
		livetv->tvchain = NULL;
rosfran@41
   112
	}
rosfran@41
   113
rosfran@41
   114
	if ( livetv->proginfo != NULL ) {
rosfran@41
   115
		g_object_unref (livetv->proginfo);
rosfran@41
   116
		livetv->proginfo = NULL;
rosfran@41
   117
	}
rosfran@216
   118
	
rosfran@216
   119
	if ( livetv->file_transfer != NULL ) {
rosfran@216
   120
		g_object_unref (livetv->file_transfer);
rosfran@216
   121
		livetv->file_transfer = NULL;
rosfran@216
   122
	}
rosfran@216
   123
	
rosfran@216
   124
	if ( livetv->backend_info != NULL ) {
rosfran@216
   125
		g_object_unref (livetv->backend_info);
rosfran@216
   126
		livetv->backend_info = NULL;
rosfran@216
   127
	}
rosfran@41
   128
rosfran@41
   129
	G_OBJECT_CLASS ( gmyth_livetv_parent_class )->finalize ( object );
rosfran@41
   130
}
rosfran@41
   131
rosfran@41
   132
GMythLiveTV*
rosfran@41
   133
gmyth_livetv_new ()
rosfran@41
   134
{
rosfran@41
   135
	GMythLiveTV *livetv = GMYTH_LIVETV ( g_object_new( GMYTH_LIVETV_TYPE, NULL ) );
rosfran@41
   136
rosfran@41
   137
	return livetv;
rosfran@41
   138
}
rosfran@41
   139
rosfran@212
   140
static void
rosfran@212
   141
gmyth_livetv_monitor_signal_handler( GMythMonitorHandler *monitor, gint msg_code, 
rosfran@216
   142
							gchar* message, gpointer livetv )
rosfran@212
   143
{
rosfran@216
   144
	GMythLiveTV *live_tv = (GMythLiveTV*) livetv;
rosfran@216
   145
	
rosfran@212
   146
	gmyth_debug( "LIVETV Signal handler ( msg = %s, code = %d )\n", message, msg_code );
rosfran@216
   147
	
rosfran@216
   148
	if ( NULL == live_tv )
rosfran@216
   149
		return;		
rosfran@216
   150
	
rosfran@216
   151
	switch ( msg_code ) 
rosfran@216
   152
	{
rosfran@216
   153
		
rosfran@216
   154
		case GMYTH_BACKEND_PROGRAM_INFO_CHANGED:
rosfran@216
   155
		{
rosfran@216
   156
			gmyth_debug( "LIVETV Program Changed event received [ msg = %s ]\n", message );
rosfran@216
   157
			/*
rosfran@216
   158
			if ( !gmyth_livetv_next_program_chain( live_tv ) )
rosfran@216
   159
			{
rosfran@216
   160
				gmyth_debug( "Cannot change to the next program chain!" );
rosfran@216
   161
			}
rosfran@216
   162
			else
rosfran@216
   163
			{
rosfran@216
   164
			*/
rosfran@216
   165
			gmyth_debug( "OK!!! MOVED to the next program chain [%s]!", 
rosfran@216
   166
									(gmyth_tvchain_get_id( live_tv->tvchain ))->str );
rosfran@216
   167
			/* advertises the FileTransfer about the program info changed */
rosfran@216
   168
			g_signal_emit ( live_tv->file_transfer,
rosfran@216
   169
             GMYTH_FILE_TRANSFER_GET_CLASS (live_tv->file_transfer)->program_info_changed_handler_signal_id,
rosfran@216
   170
             0, /* details */
rosfran@216
   171
             msg_code, live_tv );
rosfran@216
   172
			/*}*/
rosfran@216
   173
			break;
rosfran@216
   174
		}
rosfran@216
   175
		default:
rosfran@216
   176
			break;
rosfran@216
   177
		
rosfran@216
   178
	}
rosfran@216
   179
	
rosfran@212
   180
}
rosfran@212
   181
rosfran@41
   182
gboolean
melunko@117
   183
gmyth_livetv_setup ( GMythLiveTV *livetv, GMythBackendInfo *backend_info )
rosfran@41
   184
{
rosfran@41
   185
	gboolean res = TRUE;
rosfran@41
   186
melunko@117
   187
	GMythSocket *socket = gmyth_socket_new ();
rosfran@216
   188
	
rosfran@216
   189
	livetv->backend_info = backend_info;
rosfran@41
   190
melunko@117
   191
	// FIME: Implement this at gmyth_socket
rosfran@216
   192
	res = gmyth_socket_connect_to_backend (socket, livetv->backend_info->hostname,
rosfran@216
   193
			livetv->backend_info->port, TRUE);
rosfran@41
   194
	if (!res) {
rosfran@41
   195
		g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);	
rosfran@41
   196
		res = FALSE;
rosfran@41
   197
		goto error;
rosfran@41
   198
	}
rosfran@41
   199
melunko@117
   200
	livetv->is_livetv = TRUE;
rosfran@203
   201
	
rosfran@203
   202
  livetv->monitor = gmyth_monitor_handler_new ( );
rosfran@203
   203
  
rosfran@216
   204
  res = gmyth_monitor_handler_open (livetv->monitor, livetv->backend_info->hostname, 
rosfran@216
   205
  				livetv->backend_info->port );
rosfran@203
   206
  
rosfran@203
   207
  if ( res == TRUE )
rosfran@203
   208
  {
rosfran@203
   209
  	gmyth_debug("Connect MythTV Monitor event socket! Trying to start the message handler...");
rosfran@203
   210
  	
rosfran@203
   211
  	res = gmyth_monitor_handler_start ( livetv->monitor );
rosfran@203
   212
  	
rosfran@203
   213
  	if (res)
rosfran@203
   214
  	{
rosfran@203
   215
  		gmyth_debug("MythTV Monitor event socket connected and listening!");
rosfran@212
   216
  		g_signal_connect (G_OBJECT (livetv->monitor), "backend-events-handler",
rosfran@212
   217
                  (GCallback)gmyth_livetv_monitor_signal_handler,
rosfran@216
   218
                  livetv);
rosfran@203
   219
  	}
rosfran@203
   220
  	else
rosfran@203
   221
  	{
rosfran@203
   222
  		gmyth_debug("Problems when trying to start MythTV Monitor event socket!");
rosfran@203
   223
  		goto error;  		
rosfran@203
   224
  	}
rosfran@203
   225
  }
rosfran@41
   226
melunko@117
   227
	livetv->local_hostname  = gmyth_socket_get_local_hostname ( );
rosfran@41
   228
rosfran@41
   229
	if ( livetv->local_hostname == NULL ) {
rosfran@41
   230
		res = FALSE;
rosfran@41
   231
		goto error;
rosfran@41
   232
	}
rosfran@41
   233
rosfran@65
   234
	// Gets the recorder num
melunko@117
   235
	livetv->recorder = remote_request_next_free_recorder (socket, -1);
melunko@117
   236
	gmyth_socket_close_connection (socket);
rosfran@41
   237
rosfran@65
   238
	if ( livetv->recorder == NULL ) {
rosfran@41
   239
		g_warning ("[%s] None remote encoder available", __FUNCTION__);
rosfran@41
   240
		res = FALSE;
rosfran@41
   241
		goto error;
rosfran@41
   242
	}
rosfran@41
   243
rosfran@41
   244
	// Creates livetv chain handler
rosfran@41
   245
	livetv->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) );
rosfran@216
   246
	gmyth_tvchain_initialize ( livetv->tvchain, livetv->backend_info );
rosfran@41
   247
rosfran@41
   248
	if ( livetv->tvchain == NULL || livetv->tvchain->tvchain_id == NULL ) {
rosfran@41
   249
		res = FALSE;
rosfran@41
   250
		goto error;
rosfran@41
   251
	}
rosfran@41
   252
rosfran@41
   253
	// Init remote encoder. Opens its control socket.
rosfran@65
   254
	res = gmyth_recorder_setup(livetv->recorder);
rosfran@41
   255
	if ( !res ) {
rosfran@41
   256
		g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
rosfran@41
   257
		res = FALSE;
rosfran@41
   258
		goto error;
rosfran@41
   259
	}
rosfran@67
   260
rosfran@67
   261
#if 0
rosfran@67
   262
  gint ch = 1011;
rosfran@67
   263
  gint idx = 0;  
rosfran@67
   264
  for ( ; idx < 5; idx++ ) {
rosfran@67
   265
  	if ( gmyth_recorder_check_channel( livetv->recorder, ch ) ) {
rosfran@67
   266
	  	if ( gmyth_recorder_set_channel( livetv->recorder, ch ) ) {
rosfran@67
   267
	  		g_print( "[%s] Channel changed!!! [%d].\n", __FUNCTION__, ch );
rosfran@67
   268
	  		break;
rosfran@67
   269
	  	}
rosfran@67
   270
  	}
rosfran@67
   271
  	++ch;
rosfran@67
   272
  }
rosfran@67
   273
#endif
rosfran@67
   274
rosfran@41
   275
	// Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
rosfran@65
   276
	res = gmyth_recorder_spawntv ( livetv->recorder,
rosfran@41
   277
			gmyth_tvchain_get_id(livetv->tvchain) );
rosfran@41
   278
	if (!res) {
rosfran@41
   279
		g_warning ("[%s] Fail while spawn tv\n", __FUNCTION__);
rosfran@41
   280
		res = FALSE;
rosfran@41
   281
		goto error;
rosfran@41
   282
	}
rosfran@41
   283
rosfran@41
   284
	// Reload all TV chain from Mysql database.
rosfran@41
   285
	gmyth_tvchain_reload_all (livetv->tvchain);
rosfran@41
   286
rosfran@41
   287
	if ( livetv->tvchain == NULL ) {
rosfran@41
   288
		res = FALSE;
rosfran@41
   289
		goto error;
rosfran@41
   290
	}
rosfran@41
   291
rosfran@41
   292
	// Get program info from database using chanid and starttime
rosfran@41
   293
	livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, tvchain_curr_index++ );
rosfran@41
   294
	if ( livetv->proginfo == NULL ) {
rosfran@41
   295
		g_warning ("[%s] LiveTV not successfully started.\n", __FUNCTION__ );
rosfran@41
   296
		res = FALSE;
rosfran@41
   297
		goto error;
rosfran@41
   298
	} else {
renatofilho@131
   299
		gmyth_debug ("[%s] GMythLiveTV: All requests to backend to start TV were OK.\n", __FUNCTION__ );
rosfran@41
   300
	}
rosfran@216
   301
	
rosfran@216
   302
	livetv->setup_done = TRUE;
rosfran@216
   303
	
rosfran@41
   304
	return res;
rosfran@41
   305
rosfran@41
   306
error:
rosfran@54
   307
	g_print( "[%s] ERROR running LiveTV setup.\n", __FUNCTION__ );
rosfran@54
   308
rosfran@54
   309
	if ( livetv->local_hostname != NULL ) {
rosfran@54
   310
		g_string_free( livetv->local_hostname, TRUE );
rosfran@54
   311
		res = FALSE;
rosfran@54
   312
	}
rosfran@54
   313
rosfran@65
   314
	if ( livetv->recorder != NULL ) {
rosfran@65
   315
		g_object_unref (livetv->recorder);
rosfran@65
   316
		livetv->recorder = NULL;
rosfran@54
   317
	}
rosfran@54
   318
rosfran@54
   319
	if ( livetv->tvchain != NULL ) {
rosfran@54
   320
		g_object_unref (livetv->tvchain);
rosfran@54
   321
		livetv->tvchain = NULL;
rosfran@54
   322
	}
rosfran@54
   323
rosfran@54
   324
	if ( livetv->proginfo != NULL ) {
rosfran@54
   325
		g_object_unref (livetv->proginfo);
rosfran@54
   326
		livetv->proginfo = NULL;
rosfran@54
   327
	}
rosfran@54
   328
rosfran@54
   329
	return res;
rosfran@54
   330
rosfran@54
   331
}
rosfran@54
   332
rosfran@54
   333
gboolean
rosfran@54
   334
gmyth_livetv_next_program_chain ( GMythLiveTV *livetv )
rosfran@54
   335
{
rosfran@54
   336
	gboolean res = TRUE;
rosfran@54
   337
	
rosfran@216
   338
	if ( !livetv->setup_done )
rosfran@216
   339
	{
rosfran@216
   340
		gmyth_debug ( "Call the setup function first!" );
rosfran@216
   341
		res= FALSE;
rosfran@216
   342
		goto error;		
rosfran@216
   343
	}
rosfran@216
   344
	
rosfran@216
   345
	/* Reload all TV chain from Mysql database. */
rosfran@54
   346
	gmyth_tvchain_reload_all (livetv->tvchain);
rosfran@54
   347
rosfran@54
   348
	if ( livetv->tvchain == NULL ) {
rosfran@54
   349
		res = FALSE;
rosfran@54
   350
		goto error;
rosfran@54
   351
	}
rosfran@54
   352
rosfran@54
   353
	// Get program info from database using chanid and starttime
rosfran@54
   354
	livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, -1 );
rosfran@54
   355
	if ( livetv->proginfo == NULL ) {
rosfran@54
   356
		g_warning ("[%s] LiveTV not successfully started on the next program chain.\n", __FUNCTION__ );
rosfran@54
   357
		res = FALSE;
rosfran@54
   358
		goto error;
rosfran@54
   359
	} else {
renatofilho@131
   360
		gmyth_debug ("[%s] GMythLiveTV: All requests to backend to start TV were OK, TV chain changed.\n", __FUNCTION__ );
rosfran@54
   361
	}
rosfran@54
   362
rosfran@54
   363
	return res;
rosfran@54
   364
rosfran@54
   365
error:
rosfran@54
   366
	g_print( "[%s] ERROR running LiveTV setup.\n", __FUNCTION__ );
rosfran@41
   367
rosfran@41
   368
	if ( livetv->local_hostname != NULL ) {
rosfran@41
   369
		g_string_free( livetv->local_hostname, TRUE );
rosfran@41
   370
		res = FALSE;
rosfran@41
   371
	}
rosfran@41
   372
rosfran@65
   373
	if ( livetv->recorder != NULL ) {
rosfran@65
   374
		g_object_unref (livetv->recorder);
rosfran@65
   375
		livetv->recorder = NULL;
rosfran@41
   376
	}
rosfran@41
   377
rosfran@41
   378
	if ( livetv->tvchain != NULL ) {
rosfran@41
   379
		g_object_unref (livetv->tvchain);
rosfran@41
   380
		livetv->tvchain = NULL;
rosfran@41
   381
	}
rosfran@41
   382
rosfran@41
   383
	if ( livetv->proginfo != NULL ) {
rosfran@41
   384
		g_object_unref (livetv->proginfo);
rosfran@41
   385
		livetv->proginfo = NULL;
rosfran@41
   386
	}
rosfran@41
   387
rosfran@41
   388
	return res;
rosfran@41
   389
rosfran@41
   390
}
rosfran@41
   391
rosfran@216
   392
GMythFileTransfer *
rosfran@216
   393
gmyth_livetv_create_file_transfer( GMythLiveTV *livetv )
rosfran@216
   394
{
rosfran@216
   395
	GMythURI* uri = NULL;
rosfran@216
   396
	
rosfran@216
   397
	if ( NULL == livetv || NULL == livetv->proginfo )
rosfran@216
   398
		goto done;
rosfran@216
   399
	
rosfran@216
   400
	if ( !livetv->setup_done )
rosfran@216
   401
	{
rosfran@216
   402
		gmyth_debug( "Error: You must do the LiveTV setup, just before generating the FileTransfer from LiveTV source!" );
rosfran@216
   403
		goto done;
rosfran@216
   404
	}	
rosfran@216
   405
rosfran@216
   406
  gmyth_debug( "URI path = %s.\n", livetv->proginfo->pathname->str ); 
rosfran@216
   407
rosfran@216
   408
	livetv->file_transfer = gmyth_file_transfer_new( livetv->backend_info );
rosfran@216
   409
rosfran@216
   410
  if ( NULL == livetv->file_transfer ) 
rosfran@216
   411
  {
rosfran@216
   412
  	gmyth_debug( "Error: couldn't create the FileTransfer from LiveTV source!" );
rosfran@216
   413
    goto done;
rosfran@216
   414
  }
rosfran@216
   415
  
rosfran@216
   416
  uri = gmyth_uri_new_with_value( livetv->proginfo->pathname->str );
rosfran@216
   417
  if ( NULL == uri )
rosfran@216
   418
  {
rosfran@216
   419
  	gmyth_debug( "Couldn't parse the URI to start LiveTV! [uri = %s]", livetv->proginfo->pathname->str );  	
rosfran@216
   420
  }
rosfran@216
   421
rosfran@216
   422
	if ( !gmyth_file_transfer_open( livetv->file_transfer, uri != NULL ? gmyth_uri_get_path(uri) : 
rosfran@216
   423
				livetv->proginfo->pathname->str ) )
rosfran@216
   424
	{
rosfran@216
   425
		gmyth_debug( "Error: couldn't open the FileTransfer from LiveTV source!" );
rosfran@216
   426
		g_object_unref( livetv->file_transfer );
rosfran@216
   427
		livetv->file_transfer = NULL;
rosfran@216
   428
		goto done;
rosfran@216
   429
	}
rosfran@216
   430
rosfran@216
   431
done:
rosfran@216
   432
	if ( uri != NULL )
rosfran@216
   433
	{
rosfran@216
   434
		g_object_unref( uri );
rosfran@216
   435
		uri = NULL;
rosfran@216
   436
	}	
rosfran@216
   437
	
rosfran@216
   438
	return livetv->file_transfer;
rosfran@216
   439
	
rosfran@216
   440
}
rosfran@216
   441
rosfran@216
   442
/* FIXME: How to proceed differently between livetv and recorded content */
rosfran@41
   443
void
rosfran@41
   444
gmyth_livetv_stop_playing (GMythLiveTV *livetv) 
rosfran@41
   445
{
renatofilho@131
   446
	gmyth_debug ("[%s] Stopping the LiveTV...\n", __FUNCTION__);
rosfran@41
   447
rosfran@41
   448
	if (livetv->is_livetv) {
rosfran@65
   449
		if (!gmyth_recorder_stop_livetv (livetv->recorder)) {
rosfran@41
   450
			g_warning ("[%s] Error while stoping remote encoder", __FUNCTION__);	
rosfran@41
   451
		}
rosfran@41
   452
	}
rosfran@41
   453
}
rosfran@41
   454
melunko@117
   455
// FIXME: put here just a wrapper function to call gmyth_recorder_is_recording()...
rosfran@41
   456
gboolean
melunko@107
   457
gmyth_livetv_is_recording ( GMythLiveTV *livetv )
melunko@107
   458
{
melunko@107
   459
  gboolean ret = TRUE;
melunko@107
   460
melunko@107
   461
  GMythStringList *str_list = gmyth_string_list_new ();
melunko@107
   462
  GString *message = g_string_new ("");
melunko@107
   463
renatofilho@131
   464
  gmyth_debug ( "[%s]\n", __FUNCTION__ );
melunko@107
   465
  //g_static_mutex_lock (&mutex);
melunko@107
   466
  //
melunko@107
   467
  g_string_printf( message, "%s %d", GMYTHTV_RECORDER_HEADER,
melunko@107
   468
      /* FIXME file_transfer->rec_id >= 0 ? file_transfer->rec_id : file_transfer->card_id );*/
melunko@107
   469
        livetv->recorder->recorder_num);
melunko@107
   470
  gmyth_string_list_append_string (str_list, message);
melunko@107
   471
  gmyth_string_list_append_string (str_list, g_string_new ("IS_RECORDING"));
melunko@107
   472
melunko@107
   473
  gmyth_socket_sendreceive_stringlist ( livetv->recorder->myth_socket, str_list );
melunko@107
   474
melunko@107
   475
  if ( str_list != NULL && gmyth_string_list_length(str_list) > 0 )
melunko@107
   476
  {
melunko@107
   477
    GString *str = NULL;
melunko@107
   478
    if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && strcmp( str->str, "bad" )!= 0 ) {
melunko@107
   479
      gint is_rec = gmyth_string_list_get_int( str_list, 0 );
melunko@107
   480
      if ( is_rec != 0 )
melunko@107
   481
        ret = TRUE;
melunko@107
   482
      else
melunko@107
   483
        ret = FALSE;
melunko@107
   484
    }
melunko@107
   485
  }
melunko@107
   486
  g_print( "[%s] %s, stream is %s being recorded!\n", __FUNCTION__, ret ? "YES" : "NO", ret ? "" : "NOT" );
melunko@107
   487
  //g_static_mutex_unlock (&mutex);
melunko@107
   488
melunko@107
   489
  if ( str_list != NULL )
melunko@107
   490
    g_object_unref (str_list);
melunko@107
   491
melunko@107
   492
  return ret;
melunko@107
   493
melunko@107
   494
}
melunko@107
   495
melunko@107
   496
melunko@107
   497
gboolean
rosfran@41
   498
gmyth_livetv_is_playing (GMythLiveTV *livetv)
rosfran@41
   499
{
rosfran@41
   500
	return TRUE;
rosfran@41
   501
}
rosfran@41
   502
rosfran@41
   503
void
rosfran@41
   504
gmyth_livetv_start_playing (GMythLiveTV *livetv)
rosfran@41
   505
{
rosfran@41
   506
rosfran@41
   507
	// TODO
rosfran@41
   508
rosfran@41
   509
}
rosfran@41
   510