gmyth/src/gmyth_livetv.c
author rosfran
Wed May 16 15:42:38 2007 +0100 (2007-05-16)
branchtrunk
changeset 665 ef870f327d30
parent 662 9d602fc9a799
child 681 1d488185037f
permissions -rwxr-xr-x
[svn r671] Fixes t the DVB backend messages.
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@655
    11
          *//*
rosfran@655
    12
       * 
rosfran@655
    13
       * This program is free software; you can redistribute it and/or modify
rosfran@655
    14
       * it under the terms of the GNU Lesser General Public License as published by
rosfran@655
    15
       * the Free Software Foundation; either version 2 of the License, or
rosfran@655
    16
       * (at your option) any later version.
rosfran@655
    17
       *
rosfran@655
    18
       * This program is distributed in the hope that it will be useful,
rosfran@655
    19
       * but WITHOUT ANY WARRANTY; without even the implied warranty of
rosfran@655
    20
       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
rosfran@655
    21
       * GNU General Public License for more details.
rosfran@655
    22
       *
rosfran@655
    23
       * You should have received a copy of the GNU Lesser General Public License
rosfran@655
    24
       * along with this program; if not, write to the Free Software
rosfran@655
    25
       * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
rosfran@655
    26
       */
rosfran@655
    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
rosfran@655
    32
#include "gmyth_livetv.h"
rosfran@42
    33
#include "gmyth_remote_util.h"
rosfran@42
    34
#include "gmyth_tvchain.h"
melunko@117
    35
#include "gmyth_socket.h"
rosfran@307
    36
#include "gmyth_backendinfo.h"
renatofilho@131
    37
#include "gmyth_debug.h"
rosfran@41
    38
rosfran@550
    39
#include "gmyth_file.h"
rosfran@42
    40
#include "gmyth_file_transfer.h"
rosfran@550
    41
#include "gmyth_file_local.h"
rosfran@216
    42
#include "gmyth_monitor_handler.h"
rosfran@41
    43
rosfran@428
    44
#include "gmyth_common.h"
rosfran@568
    45
#include "gmyth_util.h"
rosfran@428
    46
rosfran@655
    47
static void gmyth_livetv_class_init (GMythLiveTVClass * klass);
rosfran@655
    48
static void gmyth_livetv_init (GMythLiveTV * object);
rosfran@41
    49
rosfran@655
    50
static void gmyth_livetv_dispose (GObject * object);
rosfran@655
    51
static void gmyth_livetv_finalize (GObject * object);
rosfran@41
    52
rosfran@655
    53
static gint tvchain_curr_index = -1;
rosfran@41
    54
rosfran@358
    55
/*static GStaticMutex lock = G_STATIC_MUTEX_INIT;*/
melunko@107
    56
rosfran@288
    57
#define GMYTHTV_TRANSFER_MAX_WAITS	    100
melunko@107
    58
rosfran@655
    59
G_DEFINE_TYPE (GMythLiveTV, gmyth_livetv, G_TYPE_OBJECT)
rosfran@655
    60
     static void gmyth_livetv_class_init (GMythLiveTVClass * klass)
rosfran@655
    61
{
rosfran@655
    62
    GObjectClass *gobject_class;
rosfran@41
    63
rosfran@655
    64
    gobject_class = (GObjectClass *) klass;
rosfran@41
    65
rosfran@655
    66
    gobject_class->dispose = gmyth_livetv_dispose;
rosfran@655
    67
    gobject_class->finalize = gmyth_livetv_finalize;
rosfran@41
    68
}
rosfran@41
    69
rosfran@41
    70
static void
rosfran@655
    71
gmyth_livetv_init (GMythLiveTV * livetv)
rosfran@41
    72
{
leo_sobral@437
    73
    livetv->monitor = NULL;
rosfran@655
    74
    livetv->backend_info = NULL;
rosfran@655
    75
    livetv->local_hostname = NULL;
rosfran@655
    76
    livetv->file = NULL;
rosfran@655
    77
    livetv->setup_done = FALSE;
rosfran@655
    78
rosfran@655
    79
    livetv->socket = NULL;
rosfran@655
    80
    livetv->recorder = NULL;
rosfran@655
    81
    livetv->tvchain = NULL;
rosfran@655
    82
    livetv->proginfo = NULL;
rosfran@655
    83
    livetv->uri = NULL;
rosfran@655
    84
rosfran@655
    85
    livetv->mutex = g_mutex_new ();
rosfran@41
    86
}
rosfran@41
    87
rosfran@41
    88
static void
rosfran@655
    89
gmyth_livetv_dispose (GObject * object)
rosfran@655
    90
{
rosfran@655
    91
    GMythLiveTV *livetv = GMYTH_LIVETV (object);
rosfran@41
    92
rosfran@655
    93
    if (livetv->disposed)
rosfran@655
    94
    {
leo_sobral@437
    95
        /* If dispose did already run, return. */
leo_sobral@437
    96
        return;
leo_sobral@437
    97
    }
rosfran@655
    98
leo_sobral@437
    99
    /* Make sure dispose does not run twice. */
leo_sobral@437
   100
    livetv->disposed = TRUE;
leo_sobral@437
   101
rosfran@655
   102
    if (livetv->monitor != NULL)
rosfran@655
   103
    {
rosfran@655
   104
        g_object_unref (livetv->monitor);
rosfran@655
   105
        livetv->monitor = NULL;
rosfran@655
   106
    }
rosfran@655
   107
rosfran@655
   108
    if (livetv->file != NULL)
rosfran@655
   109
    {
rosfran@550
   110
        g_object_unref (livetv->file);
rosfran@550
   111
        livetv->file = NULL;
rosfran@550
   112
    }
rosfran@655
   113
rosfran@655
   114
    if (livetv->recorder != NULL)
rosfran@655
   115
    {
rosfran@490
   116
        //gmyth_recorder_close(livetv->recorder);
rosfran@655
   117
        g_object_unref (livetv->recorder);
rosfran@655
   118
        livetv->recorder = NULL;
rosfran@655
   119
    }
rosfran@41
   120
rosfran@655
   121
    if (livetv->socket != NULL)
rosfran@655
   122
    {
rosfran@655
   123
        g_object_unref (livetv->socket);
rosfran@655
   124
        livetv->socket = NULL;
rosfran@655
   125
    }
rosfran@41
   126
rosfran@655
   127
    if (livetv->tvchain != NULL)
rosfran@655
   128
    {
rosfran@655
   129
        g_object_unref (livetv->tvchain);
rosfran@655
   130
        livetv->tvchain = NULL;
rosfran@655
   131
    }
rosfran@655
   132
rosfran@655
   133
    if (livetv->proginfo != NULL)
rosfran@655
   134
    {
rosfran@655
   135
        g_object_unref (livetv->proginfo);
rosfran@655
   136
        livetv->proginfo = NULL;
rosfran@655
   137
    }
rosfran@655
   138
rosfran@655
   139
    if (livetv->backend_info != NULL)
rosfran@655
   140
    {
rosfran@655
   141
        g_object_unref (livetv->backend_info);
rosfran@655
   142
        livetv->backend_info = NULL;
rosfran@655
   143
    }
rosfran@655
   144
rosfran@655
   145
    if (livetv->uri != NULL)
rosfran@655
   146
    {
rosfran@655
   147
        g_object_unref (livetv->uri);
rosfran@655
   148
        livetv->uri = NULL;
rosfran@655
   149
    }
rosfran@655
   150
rosfran@655
   151
    if (livetv->mutex != NULL)
rosfran@655
   152
    {
rosfran@655
   153
        g_mutex_free (livetv->mutex);
rosfran@655
   154
        livetv->mutex = NULL;
rosfran@655
   155
    }
rosfran@655
   156
rosfran@655
   157
    if (livetv->local_hostname != NULL)
rosfran@655
   158
    {
leo_sobral@452
   159
        g_string_free (livetv->local_hostname, TRUE);
leo_sobral@452
   160
        livetv->local_hostname = NULL;
leo_sobral@452
   161
    }
leo_sobral@437
   162
rosfran@655
   163
    G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object);
rosfran@336
   164
}
rosfran@336
   165
rosfran@336
   166
static void
rosfran@655
   167
gmyth_livetv_finalize (GObject * object)
rosfran@336
   168
{
rosfran@655
   169
    g_signal_handlers_destroy (object);
rosfran@336
   170
rosfran@655
   171
    G_OBJECT_CLASS (gmyth_livetv_parent_class)->finalize (object);
rosfran@41
   172
}
rosfran@41
   173
rosfran@428
   174
/**
rosfran@428
   175
 * Creates a new GMythLiveTV instance
rosfran@428
   176
 * 
rosfran@428
   177
 * @return a newly allocated GMythLiveTV instance
rosfran@428
   178
 */
rosfran@655
   179
GMythLiveTV *
rosfran@655
   180
gmyth_livetv_new (GMythBackendInfo * backend_info)
rosfran@41
   181
{
rosfran@655
   182
    GMythLiveTV *livetv = GMYTH_LIVETV (g_object_new (GMYTH_LIVETV_TYPE, NULL));
rosfran@655
   183
rosfran@655
   184
    livetv->backend_info = backend_info;
leo_sobral@437
   185
    g_object_ref (livetv->backend_info);
leo_sobral@437
   186
rosfran@655
   187
    return livetv;
rosfran@41
   188
}
rosfran@41
   189
rosfran@428
   190
/**
rosfran@428
   191
 * The GObject signal handler function, from which all status messages 
rosfran@428
   192
 * from the Monitor Handler will be advertized, all time it receives
rosfran@428
   193
 * LiveTV status messages from the MythTV backend
rosfran@428
   194
 * 
rosfran@428
   195
 * @param monitor a GMythMonitorHandler instance
rosfran@428
   196
 * @param msg_code the MythTV's server numeric status code
rosfran@428
   197
 * @param message the message's string description
rosfran@428
   198
 * @param user_data pointer to the GMythLiveTV instance
rosfran@428
   199
 */
rosfran@212
   200
static void
rosfran@655
   201
gmyth_livetv_monitor_signal_handler (GMythMonitorHandler * monitor,
rosfran@655
   202
                                     gint msg_code, gchar * message,
rosfran@655
   203
                                     gpointer user_data)
rosfran@212
   204
{
rosfran@655
   205
    GMythLiveTV *live_tv = GMYTH_LIVETV (user_data);
rosfran@655
   206
rosfran@655
   207
    gmyth_debug
rosfran@655
   208
        ("LIVETV Signal handler ( msg = %s, code = %d, live_tv param = %s, user_data = %s )\n",
rosfran@655
   209
         message, msg_code, live_tv != NULL ? "" : "NULL",
rosfran@655
   210
         user_data != NULL ? "" : "NULL");
rosfran@655
   211
rosfran@655
   212
    if (NULL == live_tv || !IS_GMYTH_FILE_TRANSFER (live_tv->file))
rosfran@655
   213
    {
rosfran@655
   214
        gmyth_debug ("LiveTV_obj is equals to NULL!!!");
rosfran@655
   215
        return;
rosfran@655
   216
    }
rosfran@655
   217
rosfran@655
   218
    switch (msg_code)
rosfran@655
   219
    {
rosfran@655
   220
rosfran@655
   221
        case GMYTH_BACKEND_PROGRAM_INFO_CHANGED:
rosfran@655
   222
            {
rosfran@655
   223
                gmyth_debug
rosfran@655
   224
                    ("LIVETV Program Changed request received [ msg = %s ]. Watching if the new "
rosfran@655
   225
                     "TV Chain ID is the same as the old one...\n", message);
rosfran@655
   226
                if (g_ascii_strcasecmp
rosfran@655
   227
                    (message,
rosfran@655
   228
                     (gmyth_tvchain_get_id (live_tv->tvchain))->str) != 0)
rosfran@655
   229
                {
rosfran@655
   230
                    gmyth_debug
rosfran@655
   231
                        ("OK!!! MOVED to the next program chain [actual == %s]!",
rosfran@655
   232
                         (gmyth_tvchain_get_id (live_tv->tvchain))->str);
rosfran@655
   233
                    /* advertises the FileTransfer about the program info changed */
rosfran@655
   234
                    if (live_tv->file != NULL)
rosfran@655
   235
                    {
rosfran@655
   236
                        gmyth_debug
rosfran@655
   237
                            ("Emitting signal to the FileTransfer... [ \"program-info-changed \" ]");
rosfran@655
   238
rosfran@655
   239
                        gmyth_file_transfer_emit_program_info_changed_signal
rosfran@655
   240
                            (GMYTH_FILE_TRANSFER (live_tv->file), msg_code,
rosfran@655
   241
                             (gpointer) (live_tv->recorder));
rosfran@655
   242
rosfran@655
   243
                        /* gmyth_livetv_monitor_handler_stop( live_tv ); */
rosfran@655
   244
                    }
rosfran@655
   245
                    else
rosfran@655
   246
                        gmyth_debug
rosfran@655
   247
                            ("LIVETV file_transfer is NULL!!! Cannot move to the next program chain event received.\n");
rosfran@655
   248
                }
rosfran@655
   249
                break;
rosfran@655
   250
            }
rosfran@655
   251
        case GMYTH_BACKEND_DONE_RECORDING:
rosfran@655
   252
            {
rosfran@655
   253
                gmyth_debug
rosfran@655
   254
                    ("LIVETV Program Changed request received [ msg = %s ]. Watching if the new "
rosfran@655
   255
                     "TV Chain ID is the same as the old one...\n", message);
rosfran@655
   256
                if (g_ascii_strcasecmp
rosfran@655
   257
                    (message,
rosfran@655
   258
                     (gmyth_tvchain_get_id (live_tv->tvchain))->str) != 0)
rosfran@655
   259
                {
rosfran@655
   260
                    gmyth_debug
rosfran@655
   261
                        ("OK!!! MOVED to the next program chain [actual == %s]!",
rosfran@655
   262
                         (gmyth_tvchain_get_id (live_tv->tvchain))->str);
rosfran@655
   263
                    /* advertises the FileTransfer about the program info changed */
rosfran@655
   264
                    if (live_tv->file != NULL)
rosfran@655
   265
                    {
rosfran@655
   266
                        gmyth_debug
rosfran@655
   267
                            ("Emitting signal to the FileTransfer... [ \"backend-done-recording\" ]");
rosfran@655
   268
rosfran@655
   269
                        gmyth_file_transfer_emit_program_info_changed_signal
rosfran@655
   270
                            (GMYTH_FILE_TRANSFER (live_tv->file), msg_code,
rosfran@655
   271
                             (gpointer) (live_tv->recorder));
rosfran@655
   272
rosfran@655
   273
                    }
rosfran@655
   274
                    else
rosfran@655
   275
                        gmyth_debug
rosfran@655
   276
                            ("LIVETV file_transfer is NULL!!! Cannot move to the next program chain event received.\n");
rosfran@655
   277
                }
rosfran@655
   278
                break;
rosfran@655
   279
            }
rosfran@655
   280
        case GMYTH_BACKEND_STOP_LIVETV:
rosfran@655
   281
            {
rosfran@655
   282
                gmyth_debug
rosfran@655
   283
                    ("LIVETV Stop LiveTV request received [ msg = %s ]. Going out the "
rosfran@655
   284
                     "LiveTV...\n", message);
rosfran@655
   285
                /* stops the LiveTV */
rosfran@655
   286
                if (live_tv != NULL)
rosfran@655
   287
                {
rosfran@655
   288
                    gmyth_debug ("Going out the LiveTV... [ \"quit-livetv\" ]");
rosfran@655
   289
rosfran@655
   290
                    g_object_unref (live_tv);
rosfran@655
   291
                }
rosfran@655
   292
                else
rosfran@655
   293
                    gmyth_debug
rosfran@655
   294
                        ("LIVETV file_transfer is NULL!!! Cannot move to the next program chain event received.\n");
rosfran@655
   295
rosfran@655
   296
                break;
rosfran@655
   297
            }
rosfran@655
   298
        default:
rosfran@655
   299
            break;
rosfran@665
   300
    } /* switch (Monitor Handler messages) */
rosfran@655
   301
rosfran@220
   302
}
rosfran@220
   303
rosfran@428
   304
/**
rosfran@428
   305
 * Starts the Monitor Handler to this GMythLiveTV session, in order
rosfran@428
   306
 * to receive the status messages from the MythTV's backend server 
rosfran@428
   307
 * 
rosfran@428
   308
 * @param live_tv the GMythLiveTV instance
rosfran@428
   309
 * 
rosfran@428
   310
 * @return <code>true</code> if the Monitor Handler start-up process
rosfran@428
   311
 * 	   had been concluded succcesfully 
rosfran@428
   312
 */
rosfran@220
   313
gboolean
rosfran@655
   314
gmyth_livetv_monitor_handler_start (GMythLiveTV * livetv)
rosfran@220
   315
{
rosfran@655
   316
    gboolean res = TRUE;
rosfran@655
   317
rosfran@655
   318
    if (livetv->monitor != NULL)
rosfran@655
   319
    {
rosfran@655
   320
        g_object_unref (livetv->monitor);
rosfran@655
   321
        livetv->monitor = NULL;
rosfran@655
   322
    }
rosfran@655
   323
rosfran@655
   324
    livetv->monitor = gmyth_monitor_handler_new ();
rosfran@655
   325
rosfran@655
   326
    res =
rosfran@655
   327
        gmyth_monitor_handler_open (livetv->monitor,
rosfran@655
   328
                                    livetv->backend_info->hostname,
rosfran@655
   329
                                    livetv->backend_info->port);
rosfran@655
   330
rosfran@655
   331
    if (res == TRUE)
rosfran@655
   332
    {
rosfran@655
   333
        gmyth_debug
rosfran@655
   334
            ("Connect MythTV Monitor event socket! Trying to start the message handler...");
rosfran@655
   335
rosfran@655
   336
        res = gmyth_monitor_handler_start (livetv->monitor);
rosfran@655
   337
rosfran@655
   338
        if (res)
rosfran@655
   339
        {
rosfran@655
   340
            gmyth_debug
rosfran@655
   341
                ("MythTV Monitor event socket connected and listening!");
rosfran@655
   342
            g_signal_connect (G_OBJECT (livetv->monitor),
rosfran@655
   343
                              "backend-events-handler",
rosfran@655
   344
                              (GCallback) gmyth_livetv_monitor_signal_handler,
rosfran@655
   345
                              livetv);
rosfran@655
   346
        }
rosfran@655
   347
        else
rosfran@655
   348
        {
rosfran@655
   349
            gmyth_debug
rosfran@655
   350
                ("Problems when trying to start MythTV Monitor event socket!");
rosfran@655
   351
            goto error;
rosfran@655
   352
        }
rosfran@655
   353
    }
rosfran@655
   354
rosfran@655
   355
  error:
rosfran@655
   356
    return res;
rosfran@655
   357
rosfran@212
   358
}
rosfran@212
   359
rosfran@428
   360
/**
rosfran@428
   361
 * Stops the Monitor Handler to this GMythLiveTV session, in order
rosfran@428
   362
 * to stop receiving the status messages from the MythTV's backend server 
rosfran@428
   363
 * 
rosfran@428
   364
 * @param live_tv the GMythLiveTV instance
rosfran@428
   365
 * 
rosfran@428
   366
 * @return <code>true</code> if the Monitor Handler shutdown process
rosfran@428
   367
 * 	   had been concluded succcesfully 
rosfran@428
   368
 */
rosfran@220
   369
void
rosfran@655
   370
gmyth_livetv_monitor_handler_stop (GMythLiveTV * livetv)
rosfran@220
   371
{
rosfran@655
   372
rosfran@655
   373
    if (livetv->monitor != NULL)
rosfran@655
   374
    {
rosfran@655
   375
        g_object_unref (livetv->monitor);
rosfran@655
   376
        livetv->monitor = NULL;
rosfran@655
   377
    }
rosfran@655
   378
rosfran@326
   379
}
rosfran@307
   380
rosfran@428
   381
#if 0
rosfran@655
   382
static gchar *
rosfran@655
   383
gmyth_livetv_create_remote_url (GMythLiveTV * livetv)
rosfran@307
   384
{
rosfran@655
   385
    gchar *uri = g_strdup ("");
rosfran@655
   386
    gmyth_backend_info_get_remote_h
rosfran@655
   387
        //gmyth_backend(livetv->backend_info)
rosfran@655
   388
        return uri;
rosfran@307
   389
}
rosfran@428
   390
#endif
rosfran@307
   391
rosfran@428
   392
/**
rosfran@428
   393
 * Configures the GMythLiveTV session, sends SPAWN_LIVETV message, 
rosfran@428
   394
 * sets the channel name, and gets the first program info about the
rosfran@428
   395
 * actual recording 
rosfran@428
   396
 * 
rosfran@428
   397
 * @param live_tv the GMythLiveTV instance
rosfran@428
   398
 * @param channel the channel name (the chan_name field, from the tvchain table)
rosfran@428
   399
 * @param backend_info the GMythBackendInfo describing the remote server
rosfran@428
   400
 * 
rosfran@428
   401
 * @return <code>true</code> if the LiveTV's recorder instance configuration 
rosfran@428
   402
 * 				had been concluded succcesfully 
rosfran@428
   403
 */
rosfran@237
   404
static gboolean
rosfran@655
   405
gmyth_livetv_setup_recorder_channel_name (GMythLiveTV * livetv, gchar * channel)
rosfran@41
   406
{
rosfran@655
   407
    gboolean res = TRUE;
rosfran@655
   408
leo_sobral@437
   409
    g_return_val_if_fail (livetv != NULL, FALSE);
rosfran@41
   410
rosfran@655
   411
    if (NULL == livetv->socket)
rosfran@655
   412
    {
rosfran@655
   413
        livetv->socket = gmyth_socket_new ();
rosfran@428
   414
rosfran@655
   415
        /* FIME: Implement this at gmyth_socket */
rosfran@655
   416
        res =
rosfran@655
   417
            gmyth_socket_connect_to_backend (livetv->socket,
rosfran@655
   418
                                             livetv->backend_info->hostname,
rosfran@655
   419
                                             livetv->backend_info->port, TRUE);
rosfran@655
   420
        if (!res)
rosfran@655
   421
        {
rosfran@655
   422
            gmyth_debug ("[%s] LiveTV can not connect to backend",
rosfran@655
   423
                         __FUNCTION__);
rosfran@655
   424
            res = FALSE;
rosfran@655
   425
            goto error;
rosfran@655
   426
        }
rosfran@655
   427
    }
rosfran@41
   428
rosfran@655
   429
    g_mutex_lock (livetv->mutex);
rosfran@282
   430
rosfran@655
   431
    livetv->is_livetv = TRUE;
rosfran@288
   432
rosfran@655
   433
    livetv->local_hostname = gmyth_socket_get_local_hostname ();
rosfran@288
   434
rosfran@655
   435
    if (livetv->local_hostname == NULL)
rosfran@655
   436
    {
melunko@662
   437
        g_warning ("livetv could not retrieve the local hostname");
rosfran@655
   438
        res = FALSE;
rosfran@655
   439
        goto error;
melunko@662
   440
    } else {
melunko@662
   441
        gmyth_debug ("Local hostname: %s", livetv->local_hostname->str);
rosfran@655
   442
    }
rosfran@655
   443
rosfran@655
   444
    if (livetv->recorder != NULL)
rosfran@655
   445
    {
rosfran@655
   446
        g_object_unref (livetv->recorder);
rosfran@655
   447
        livetv->recorder = NULL;
rosfran@655
   448
    }
rosfran@655
   449
rosfran@655
   450
    if (gmyth_remote_util_get_free_recorder_count (livetv->socket) <= 0)
rosfran@655
   451
    {
rosfran@655
   452
        gmyth_debug ("No free remote encoder available.");
rosfran@655
   453
        res = FALSE;
rosfran@655
   454
        goto error;
rosfran@655
   455
    }
rosfran@655
   456
rosfran@655
   457
    /* Gets the recorder num */
rosfran@655
   458
    livetv->recorder = remote_request_next_free_recorder (livetv->socket, -1);
rosfran@655
   459
    gmyth_socket_close_connection (livetv->socket);
rosfran@655
   460
rosfran@655
   461
    if (NULL == livetv->recorder)
rosfran@655
   462
    {
rosfran@655
   463
        gmyth_debug ("[%s] None remote encoder available", __FUNCTION__);
rosfran@655
   464
        res = FALSE;
rosfran@655
   465
        goto error;
rosfran@655
   466
    }
rosfran@655
   467
rosfran@655
   468
    /* Init remote encoder. Opens its control socket. */
rosfran@655
   469
    res = gmyth_recorder_setup (livetv->recorder);
rosfran@655
   470
    if (!res)
rosfran@655
   471
    {
rosfran@655
   472
        gmyth_debug ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
rosfran@655
   473
        res = FALSE;
rosfran@655
   474
        goto error;
rosfran@655
   475
    }
rosfran@655
   476
rosfran@655
   477
    /* Creates livetv chain handler */
rosfran@655
   478
    livetv->tvchain = gmyth_tvchain_new ();
rosfran@655
   479
    gmyth_tvchain_initialize (livetv->tvchain, livetv->backend_info);
rosfran@655
   480
rosfran@655
   481
    if (livetv->tvchain == NULL || livetv->tvchain->tvchain_id == NULL)
rosfran@655
   482
    {
rosfran@655
   483
        res = FALSE;
rosfran@655
   484
        goto error;
rosfran@655
   485
    }
rosfran@655
   486
rosfran@655
   487
    // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
rosfran@655
   488
    res = gmyth_recorder_spawntv (livetv->recorder,
rosfran@655
   489
                                  gmyth_tvchain_get_id (livetv->tvchain));
rosfran@655
   490
    if (!res)
rosfran@655
   491
    {
rosfran@655
   492
        gmyth_debug ("[%s] Fail while spawn tv\n", __FUNCTION__);
rosfran@655
   493
        res = FALSE;
rosfran@655
   494
        goto error;
rosfran@655
   495
    }
rosfran@655
   496
rosfran@655
   497
    if (res == TRUE)
rosfran@655
   498
    {
rosfran@655
   499
        /* loop finished, set the max tries variable to zero again... */
rosfran@655
   500
        gint wait_to_transfer = 0;
rosfran@655
   501
rosfran@655
   502
        while (wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
rosfran@655
   503
               (gmyth_recorder_is_recording (livetv->recorder) == FALSE))
rosfran@655
   504
            g_usleep (300);
rosfran@655
   505
rosfran@655
   506
        if (channel != NULL)
rosfran@655
   507
        {
rosfran@655
   508
            /* Pauses remote encoder. */
rosfran@655
   509
            res = gmyth_recorder_pause_recording (livetv->recorder);
rosfran@655
   510
            if (!res)
rosfran@655
   511
            {
rosfran@655
   512
                gmyth_debug ("[%s] Fail while pausing remote encoder\n",
rosfran@655
   513
                             __FUNCTION__);
rosfran@655
   514
                res = FALSE;
rosfran@655
   515
                goto error;
rosfran@655
   516
            }
rosfran@655
   517
rosfran@655
   518
            if (gmyth_recorder_check_channel_name (livetv->recorder, channel))
rosfran@655
   519
            {
rosfran@655
   520
                if (gmyth_recorder_set_channel_name (livetv->recorder, channel))
rosfran@655
   521
                {
rosfran@655
   522
                    gmyth_debug ("Channel changed!!! [%s].\n", channel);
rosfran@655
   523
                }
rosfran@655
   524
            }
rosfran@655
   525
rosfran@655
   526
        }                       /* if - changes the channel number */
rosfran@655
   527
        /* sleep (5); *//* FIXME: this is evil (tpm) */
rosfran@655
   528
    }
rosfran@655
   529
rosfran@655
   530
    /* DEBUG message */
rosfran@655
   531
    GMythProgramInfo *prog_info =
rosfran@655
   532
        gmyth_recorder_get_current_program_info (livetv->recorder);
rosfran@655
   533
rosfran@655
   534
    if (NULL == prog_info)
rosfran@655
   535
    {
rosfran@655
   536
        gmyth_debug ("ProgramInfo is equals to NULL!!!");
rosfran@655
   537
rosfran@493
   538
        gint i;
rosfran@493
   539
        gchar *channame = NULL;
rosfran@655
   540
rosfran@655
   541
        gmyth_debug ("Problem getting current proginfo!\n");
rosfran@655
   542
rosfran@493
   543
        /*
rosfran@493
   544
         * mythbackend must not be tuned in to a channel, so keep
rosfran@493
   545
         * changing channels until we find a valid one, or until
rosfran@493
   546
         * we decide to give up.
rosfran@493
   547
         */
rosfran@655
   548
        for (i = 1; i < 1000; i++)
rosfran@655
   549
        {
rosfran@655
   550
            if (channame != NULL)
rosfran@655
   551
                g_free (channame);
rosfran@655
   552
            channame = g_strdup_printf ("%d", i);
rosfran@655
   553
            if (gmyth_recorder_set_channel_name (livetv->recorder, channame) <
rosfran@655
   554
                0)
rosfran@655
   555
            {
rosfran@493
   556
                continue;
rosfran@493
   557
            }
rosfran@655
   558
            prog_info =
rosfran@655
   559
                gmyth_recorder_get_next_program_info (livetv->recorder,
rosfran@655
   560
                                                      BROWSE_DIRECTION_UP);
rosfran@655
   561
            gmyth_program_info_print (prog_info);
rosfran@493
   562
            if (prog_info != NULL)
rosfran@493
   563
                break;
rosfran@493
   564
        }
rosfran@326
   565
rosfran@655
   566
    }                           /* if - Program Info */
melunko@412
   567
rosfran@655
   568
    /* prints program info data text */
rosfran@655
   569
    gmyth_debug ("New ProgramInfo...\n");
rosfran@655
   570
    gmyth_program_info_print (prog_info);
rosfran@655
   571
rosfran@655
   572
    /* check if the program chain could be obtained from the MythTV protocol message */
rosfran@655
   573
    if (prog_info != NULL)
rosfran@655
   574
    {
rosfran@655
   575
        gmyth_backend_info_set_username (livetv->tvchain->backend_info,
rosfran@655
   576
                                         "mythtv");
rosfran@655
   577
        gmyth_backend_info_set_password (livetv->tvchain->backend_info,
rosfran@655
   578
                                         "mythtv");
rosfran@655
   579
        gmyth_backend_info_set_db_name (livetv->tvchain->backend_info,
rosfran@655
   580
                                        "mythconverg");
rosfran@655
   581
        GList *prog_list =
rosfran@655
   582
            gmyth_tvchain_get_program_info_from_channel (livetv->tvchain,
rosfran@655
   583
                                                         channel);
rosfran@578
   584
        GMythProgramInfo *ch_prog = NULL;
rosfran@655
   585
        if (prog_list != NULL && g_list_length (prog_list) > 0)
rosfran@655
   586
        {
rosfran@655
   587
            ch_prog = (GMythProgramInfo *) g_list_nth_data (prog_list, 0);
rosfran@655
   588
            gmyth_debug ("Channel program info (from a list with size = %d)!",
rosfran@655
   589
                         g_list_length (prog_list));
rosfran@655
   590
            gmyth_program_info_print (ch_prog);
rosfran@655
   591
        }
rosfran@288
   592
rosfran@655
   593
        gmyth_debug ("Program Info: %s\n",
rosfran@655
   594
                     gmyth_program_info_to_string (prog_info));
rosfran@655
   595
        livetv->proginfo = prog_info;
rosfran@655
   596
        /* testing change channel */
rosfran@655
   597
        //gmyth_recorder_spawntv_no_tvchain( livetv->recorder );
rosfran@655
   598
    }
rosfran@655
   599
    else
rosfran@655
   600
    {
rosfran@282
   601
rosfran@655
   602
        /* check for the program info in the TV program chain could be obtained 
rosfran@655
   603
           from the MythTV MySQL database */
rosfran@41
   604
rosfran@655
   605
        /* Reload all TV chain from Mysql database. */
rosfran@655
   606
        gmyth_tvchain_reload_all (livetv->tvchain);
rosfran@655
   607
rosfran@655
   608
        if (livetv->tvchain == NULL)
rosfran@655
   609
        {
rosfran@655
   610
            res = FALSE;
rosfran@655
   611
            goto error;
rosfran@655
   612
        }
rosfran@655
   613
rosfran@655
   614
        /* Get program info from database using chanid and starttime */
rosfran@655
   615
        livetv->proginfo =
rosfran@655
   616
            gmyth_tvchain_get_program_at (livetv->tvchain,
rosfran@655
   617
                                          tvchain_curr_index++);
rosfran@655
   618
        if (livetv->proginfo == NULL)
rosfran@655
   619
        {
rosfran@655
   620
            gmyth_debug ("LiveTV not successfully started.\n");
rosfran@655
   621
            res = FALSE;
rosfran@655
   622
            goto error;
rosfran@655
   623
        }
rosfran@655
   624
        else
rosfran@655
   625
        {
rosfran@655
   626
            res = TRUE;
rosfran@655
   627
            gmyth_debug
rosfran@655
   628
                ("GMythLiveTV: All requests to backend to start TV were OK. [%s]\n",
rosfran@655
   629
                 livetv->proginfo->pathname->str);
rosfran@655
   630
        }
rosfran@655
   631
rosfran@655
   632
    }
rosfran@655
   633
rosfran@655
   634
    livetv->uri =
rosfran@655
   635
        (GMythURI *) gmyth_backend_info_get_uri (livetv->backend_info);
rosfran@655
   636
rosfran@655
   637
    g_mutex_unlock (livetv->mutex);
rosfran@655
   638
rosfran@655
   639
    if (!gmyth_livetv_monitor_handler_start (livetv))
rosfran@655
   640
    {
rosfran@655
   641
        res = FALSE;
rosfran@655
   642
        gmyth_debug ("LiveTV MONITOR handler error on setup!");
rosfran@655
   643
        goto error;
rosfran@655
   644
    }
rosfran@655
   645
rosfran@655
   646
    livetv->setup_done = TRUE;
rosfran@655
   647
rosfran@655
   648
    return res;
rosfran@655
   649
rosfran@655
   650
  error:
rosfran@655
   651
    gmyth_debug ("[%s] ERROR running LiveTV setup.\n", __FUNCTION__);
rosfran@54
   652
leo_sobral@437
   653
    res = FALSE;
leo_sobral@437
   654
melunko@662
   655
    if (livetv->local_hostname != NULL)
melunko@662
   656
        g_string_free (livetv->local_hostname, TRUE);
rosfran@54
   657
rosfran@655
   658
    if (livetv->recorder != NULL)
rosfran@655
   659
    {
rosfran@655
   660
        g_object_unref (livetv->recorder);
rosfran@655
   661
        livetv->recorder = NULL;
rosfran@655
   662
    }
rosfran@54
   663
rosfran@655
   664
    if (livetv->tvchain != NULL)
rosfran@655
   665
    {
rosfran@655
   666
        g_object_unref (livetv->tvchain);
rosfran@655
   667
        livetv->tvchain = NULL;
rosfran@655
   668
    }
rosfran@54
   669
rosfran@655
   670
    if (livetv->proginfo != NULL)
rosfran@655
   671
    {
rosfran@655
   672
        g_object_unref (livetv->proginfo);
rosfran@655
   673
        livetv->proginfo = NULL;
rosfran@655
   674
    }
rosfran@54
   675
rosfran@655
   676
    if (livetv->monitor != NULL)
rosfran@655
   677
    {
rosfran@655
   678
        g_object_unref (livetv->monitor);
rosfran@655
   679
        livetv->monitor = NULL;
rosfran@655
   680
    }
rosfran@220
   681
rosfran@655
   682
    return res;
rosfran@54
   683
rosfran@54
   684
}
rosfran@54
   685
rosfran@428
   686
/**
rosfran@428
   687
 * Setup the GMythLiveTV session, sends SPAWN_LIVETV message, 
rosfran@428
   688
 * sets the channel name, and gets the first program info about the
rosfran@428
   689
 * actual recording 
rosfran@428
   690
 * 
rosfran@428
   691
 * @param live_tv the GMythLiveTV instance
rosfran@428
   692
 * @param channel the channel name, in numerical format
rosfran@428
   693
 * @param backend_info the GMythBackendInfo describing the remote server
rosfran@428
   694
 * 
rosfran@428
   695
 * @return <code>true</code> if the LiveTV's recorder instance configuration 
rosfran@428
   696
 * 				had been concluded succcesfully 
rosfran@428
   697
 */
rosfran@307
   698
static gboolean
rosfran@655
   699
gmyth_livetv_setup_recorder (GMythLiveTV * livetv, gint channel)
rosfran@307
   700
{
rosfran@655
   701
    return gmyth_livetv_setup_recorder_channel_name (livetv, (channel != -1) ?
rosfran@655
   702
                                                     g_strdup_printf ("%d",
rosfran@655
   703
                                                                      channel) :
rosfran@655
   704
                                                     NULL);
rosfran@307
   705
}
rosfran@307
   706
rosfran@428
   707
/**
rosfran@428
   708
 * Setup the GMythLiveTV session, sends SPAWN_LIVETV message, 
rosfran@428
   709
 * sets the channel name (numerical format), and gets the first program info about the
rosfran@428
   710
 * actual recording 
rosfran@428
   711
 * 
rosfran@428
   712
 * @param live_tv the GMythLiveTV instance
rosfran@428
   713
 * @param channel the channel name, in numerical format
rosfran@428
   714
 * @param backend_info the GMythBackendInfo describing the remote server
rosfran@428
   715
 * 
rosfran@428
   716
 * @return <code>true</code> if the LiveTV's recorder instance configuration 
rosfran@428
   717
 * 				had been concluded succcesfully 
rosfran@428
   718
 */
rosfran@54
   719
gboolean
rosfran@655
   720
gmyth_livetv_channel_setup (GMythLiveTV * livetv, gint channel)
rosfran@237
   721
{
rosfran@655
   722
    return gmyth_livetv_setup_recorder (livetv, channel);
rosfran@237
   723
}
rosfran@237
   724
rosfran@428
   725
/**
rosfran@428
   726
 * Setup the GMythLiveTV session, sends SPAWN_LIVETV message, 
rosfran@428
   727
 * sets the channel name (string format), and gets the first program info about the
rosfran@428
   728
 * actual recording 
rosfran@428
   729
 * 
rosfran@428
   730
 * @param live_tv the GMythLiveTV instance
rosfran@428
   731
 * @param channel the channel name, in numerical format
rosfran@428
   732
 * @param backend_info the GMythBackendInfo describing the remote server
rosfran@428
   733
 * 
rosfran@428
   734
 * @return <code>true</code> if the LiveTV's recorder instance configuration 
rosfran@428
   735
 * 				had been concluded succcesfully 
rosfran@428
   736
 */
rosfran@237
   737
gboolean
rosfran@655
   738
gmyth_livetv_channel_name_setup (GMythLiveTV * livetv, gchar * channel)
rosfran@307
   739
{
rosfran@655
   740
    return gmyth_livetv_setup_recorder_channel_name (livetv, channel);
rosfran@307
   741
}
rosfran@307
   742
rosfran@428
   743
/**
rosfran@428
   744
 * Setup the GMythLiveTV session, sends SPAWN_LIVETV message, 
rosfran@428
   745
 * and gets the first program info about the actual recording
rosfran@428
   746
 * (doesn't changes the channel). 
rosfran@428
   747
 * 
rosfran@428
   748
 * @param live_tv the GMythLiveTV instance
rosfran@428
   749
 * @param backend_info the GMythBackendInfo describing the remote server
rosfran@428
   750
 * 
rosfran@428
   751
 * @return <code>true</code> if the LiveTV's recorder instance configuration 
rosfran@428
   752
 * 				had been concluded succcesfully 
rosfran@428
   753
 */
rosfran@307
   754
gboolean
rosfran@655
   755
gmyth_livetv_setup (GMythLiveTV * livetv)
rosfran@237
   756
{
rosfran@655
   757
    return gmyth_livetv_setup_recorder (livetv, -1);
rosfran@237
   758
}
rosfran@237
   759
rosfran@428
   760
/**
rosfran@428
   761
 * Gets the next program info from this GMythLiveTV session.
rosfran@428
   762
 * 
rosfran@428
   763
 * @param live_tv the GMythLiveTV instance
rosfran@428
   764
 * 
rosfran@428
   765
 * @return <code>true</code> if the next program info could be got 
rosfran@428
   766
 */
rosfran@237
   767
gboolean
rosfran@655
   768
gmyth_livetv_next_program_chain (GMythLiveTV * livetv)
rosfran@54
   769
{
rosfran@655
   770
    gboolean res = TRUE;
rosfran@655
   771
    GMythProgramInfo *prog_info = NULL;
rosfran@54
   772
rosfran@655
   773
    if (!livetv->setup_done)
rosfran@655
   774
    {
rosfran@655
   775
        gmyth_debug ("Call the setup function first!");
rosfran@655
   776
        goto error;
rosfran@655
   777
    }
rosfran@54
   778
rosfran@655
   779
    gmyth_debug ("Current ProgramInfo...\n");
rosfran@655
   780
    prog_info = gmyth_recorder_get_current_program_info (livetv->recorder);
rosfran@54
   781
rosfran@655
   782
    if (prog_info != NULL)
rosfran@655
   783
    {
rosfran@655
   784
        livetv->proginfo = prog_info;
rosfran@655
   785
    }
rosfran@655
   786
    else
rosfran@655
   787
    {
rosfran@655
   788
        gmyth_debug
rosfran@655
   789
            ("ProgramInfo equals to NULL!!! Getting the next program info...");
rosfran@655
   790
        prog_info =
rosfran@655
   791
            gmyth_recorder_get_next_program_info (livetv->recorder,
rosfran@655
   792
                                                  BROWSE_DIRECTION_RIGHT);
rosfran@655
   793
        livetv->proginfo = prog_info;
rosfran@655
   794
    }
rosfran@655
   795
    /* prints program info data text */
rosfran@655
   796
    gmyth_program_info_print (prog_info);
rosfran@655
   797
rosfran@655
   798
    if (prog_info != NULL)
rosfran@655
   799
    {
rosfran@655
   800
        res = TRUE;
rosfran@655
   801
        livetv->proginfo = prog_info;
rosfran@655
   802
        gmyth_debug
rosfran@655
   803
            ("GMythLiveTV: All requests to backend to start TV were OK, program info changed.");
rosfran@655
   804
    }
rosfran@655
   805
    else
rosfran@655
   806
    {
rosfran@655
   807
        gmyth_debug
rosfran@655
   808
            ("[%s] LiveTV not successfully started on the next program chain.\n",
rosfran@655
   809
             __FUNCTION__);
rosfran@655
   810
        goto error;
rosfran@655
   811
    }
rosfran@655
   812
rosfran@655
   813
    livetv->setup_done = TRUE;
rosfran@655
   814
rosfran@655
   815
    return res;
rosfran@655
   816
rosfran@655
   817
  error:
rosfran@655
   818
    gmyth_debug ("ERROR running LiveTV setup.\n");
rosfran@41
   819
leo_sobral@437
   820
    res = FALSE;
rosfran@41
   821
rosfran@655
   822
    g_string_free (livetv->local_hostname, TRUE);
rosfran@41
   823
rosfran@655
   824
    if (livetv->recorder != NULL)
rosfran@655
   825
    {
rosfran@655
   826
        g_object_unref (livetv->recorder);
rosfran@655
   827
        livetv->recorder = NULL;
rosfran@655
   828
    }
rosfran@41
   829
rosfran@655
   830
    if (livetv->tvchain != NULL)
rosfran@655
   831
    {
rosfran@655
   832
        g_object_unref (livetv->tvchain);
rosfran@655
   833
        livetv->tvchain = NULL;
rosfran@655
   834
    }
rosfran@41
   835
rosfran@655
   836
    if (livetv->proginfo != NULL)
rosfran@655
   837
    {
rosfran@655
   838
        g_object_unref (livetv->proginfo);
rosfran@655
   839
        livetv->proginfo = NULL;
rosfran@655
   840
    }
rosfran@655
   841
rosfran@655
   842
    return res;
rosfran@41
   843
}
rosfran@41
   844
rosfran@428
   845
/**
rosfran@428
   846
 * Creates a File Transfer session, using all configuration information
rosfran@428
   847
 * got from the actual program info.
rosfran@428
   848
 * 
rosfran@428
   849
 * @param live_tv the GMythLiveTV instance
rosfran@428
   850
 * 
rosfran@428
   851
 * @return the actual GMythFileTransfer instance, generated using the
rosfran@428
   852
 * 		data got from the actual program info.
rosfran@428
   853
 */
rosfran@550
   854
GMythFile *
rosfran@655
   855
gmyth_livetv_create_file_transfer (GMythLiveTV * livetv)
rosfran@216
   856
{
rosfran@655
   857
    //GMythURI* uri = NULL;
rosfran@655
   858
rosfran@655
   859
    if (NULL == livetv)
rosfran@655
   860
        goto done;
rosfran@655
   861
rosfran@655
   862
    if (!livetv->setup_done)
rosfran@550
   863
    {
rosfran@655
   864
        gmyth_debug
rosfran@655
   865
            ("Error: You must do the LiveTV setup, just before generating the FileTransfer from LiveTV source!");
rosfran@655
   866
        goto done;
rosfran@655
   867
    }
rosfran@655
   868
rosfran@655
   869
    if (livetv->proginfo != NULL)
rosfran@655
   870
        gmyth_debug ("URI path (from program info) = %s.\n",
rosfran@655
   871
                     livetv->proginfo->pathname->str);
rosfran@655
   872
    else
rosfran@655
   873
        gmyth_debug ("URI path (from URI) = %s.\n", livetv->uri->uri->str);
rosfran@655
   874
rosfran@655
   875
    g_mutex_lock (livetv->mutex);
rosfran@655
   876
rosfran@655
   877
    if (livetv->file != NULL)
rosfran@655
   878
    {
rosfran@655
   879
        /*gmyth_file_transfer_close( livetv->file ); */
rosfran@655
   880
        g_object_unref (livetv->file);
rosfran@550
   881
        livetv->file = NULL;
rosfran@655
   882
    }
rosfran@216
   883
rosfran@655
   884
    if (livetv->uri != NULL)
rosfran@550
   885
    {
rosfran@655
   886
        gmyth_debug
rosfran@655
   887
            ("URI is not NULL, creating from the ProgramInfo pathname... (%s)",
rosfran@655
   888
             livetv->proginfo->pathname->str);
rosfran@655
   889
        livetv->uri->path = g_string_erase (livetv->uri->path, 0, -1);
rosfran@655
   890
        livetv->uri->path =
rosfran@655
   891
            g_string_new (g_strrstr (livetv->proginfo->pathname->str, "/"));
rosfran@550
   892
    }
rosfran@550
   893
    else
rosfran@554
   894
    {
rosfran@655
   895
        gmyth_debug
rosfran@655
   896
            ("URI is NULL, creating from the ProgramInfo pathname... (%s)",
rosfran@655
   897
             livetv->proginfo->pathname->str);
rosfran@655
   898
        livetv->uri =
rosfran@655
   899
            gmyth_uri_new_with_value (livetv->proginfo->pathname->str);
rosfran@655
   900
    }
rosfran@655
   901
rosfran@655
   902
    if (NULL == livetv->uri)
rosfran@655
   903
    {
rosfran@655
   904
        gmyth_debug ("Couldn't parse the URI to start LiveTV! [ uri = %s ]",
rosfran@655
   905
                     livetv->proginfo->pathname->str);
rosfran@655
   906
        goto done;
rosfran@655
   907
    }
rosfran@655
   908
rosfran@655
   909
    if (gmyth_uri_is_local_file (livetv->uri))
rosfran@655
   910
        livetv->file = GMYTH_FILE (gmyth_file_local_new (livetv->backend_info));
rosfran@655
   911
    else
rosfran@655
   912
    {
rosfran@655
   913
        livetv->file =
rosfran@655
   914
            GMYTH_FILE (gmyth_file_transfer_new (livetv->backend_info));
rosfran@665
   915
        /* gmyth_file_transfer_settimeout( GMYTH_FILE_TRANSFER(livetv->file), TRUE ); */
rosfran@554
   916
    }
rosfran@321
   917
rosfran@655
   918
    if (NULL == livetv->file)
rosfran@550
   919
    {
rosfran@655
   920
        gmyth_debug
rosfran@655
   921
            ("Error: couldn't create the FileTransfer from LiveTV source!");
rosfran@550
   922
        goto done;
rosfran@550
   923
    }
leo_sobral@437
   924
rosfran@655
   925
    g_object_ref (livetv->file);
rosfran@216
   926
rosfran@655
   927
    g_mutex_unlock (livetv->mutex);
rosfran@665
   928
    
rosfran@665
   929
    /* Do some locking procedure with the Monitor Handler messages... */
rosfran@655
   930
rosfran@655
   931
  done:
rosfran@655
   932
    /*
rosfran@655
   933
       if ( uri != NULL )
rosfran@655
   934
       {
rosfran@655
   935
       g_object_unref( uri );
rosfran@655
   936
       uri = NULL;
rosfran@655
   937
       }
rosfran@655
   938
     */
rosfran@655
   939
rosfran@655
   940
    return livetv->file;
rosfran@655
   941
rosfran@216
   942
}
rosfran@216
   943
rosfran@428
   944
/**
rosfran@428
   945
 * Stops this LiveTV session.
rosfran@428
   946
 * 
rosfran@428
   947
 * @param live_tv the GMythLiveTV instance
rosfran@428
   948
 */
rosfran@41
   949
void
rosfran@655
   950
gmyth_livetv_stop_playing (GMythLiveTV * livetv)
rosfran@41
   951
{
rosfran@597
   952
    gmyth_debug ("Stopping the LiveTV...\n");
rosfran@41
   953
rosfran@655
   954
    if (livetv->is_livetv)
rosfran@655
   955
    {
rosfran@655
   956
        if (!gmyth_recorder_stop_livetv (livetv->recorder))
rosfran@655
   957
        {
rosfran@655
   958
            gmyth_debug ("[%s] Error while stoping remote encoder",
rosfran@655
   959
                         __FUNCTION__);
rosfran@655
   960
        }
rosfran@655
   961
rosfran@655
   962
        if (!gmyth_recorder_finish_recording (livetv->recorder))
rosfran@655
   963
        {
rosfran@655
   964
            gmyth_debug
rosfran@655
   965
                ("[%s] Error while finishing recording on remote encoder",
rosfran@655
   966
                 __FUNCTION__);
rosfran@655
   967
        }
rosfran@655
   968
    }
rosfran@41
   969
}
rosfran@41
   970
melunko@107
   971
gboolean
rosfran@655
   972
gmyth_livetv_is_playing (GMythLiveTV * livetv)
rosfran@41
   973
{
rosfran@655
   974
    return TRUE;
rosfran@41
   975
}
rosfran@41
   976
rosfran@41
   977
void
rosfran@655
   978
gmyth_livetv_start_playing (GMythLiveTV * livetv)
rosfran@41
   979
{
rosfran@41
   980
rosfran@655
   981
    // TODO
rosfran@41
   982
rosfran@41
   983
}