gst-plugins-mythtv/myth_livetv.c
author leo_sobral
Thu Sep 21 00:05:27 2006 +0100 (2006-09-21)
branchtrunk
changeset 3 265cdb1c59e3
parent 2 mythtv_plugin/myth_livetv.c@bd3829c2e9c9
permissions -rwxr-xr-x
[svn r4] Renamed the mythtv GStreamer module name.
leo_sobral@2
     1
leo_sobral@2
     2
#include <gmyth/gmyth_context.h>
leo_sobral@2
     3
#include <gmyth/gmyth_remote_util.h>
leo_sobral@2
     4
#include <gmyth/gmyth_tvchain.h>
leo_sobral@2
     5
leo_sobral@2
     6
#include "myth_livetv.h"
leo_sobral@2
     7
#include "myth_file_transfer.h"
leo_sobral@2
     8
leo_sobral@2
     9
static void myth_livetv_class_init          (MythLiveTVClass *klass);
leo_sobral@2
    10
static void myth_livetv_init                (MythLiveTV *object);
leo_sobral@2
    11
leo_sobral@2
    12
static void myth_livetv_dispose  (GObject *object);
leo_sobral@2
    13
static void myth_livetv_finalize (GObject *object);
leo_sobral@2
    14
leo_sobral@2
    15
G_DEFINE_TYPE(MythLiveTV, myth_livetv, G_TYPE_OBJECT)
leo_sobral@2
    16
leo_sobral@2
    17
static void
leo_sobral@2
    18
myth_livetv_class_init (MythLiveTVClass *klass)
leo_sobral@2
    19
{
leo_sobral@2
    20
	GObjectClass *gobject_class;
leo_sobral@2
    21
leo_sobral@2
    22
	gobject_class = (GObjectClass *) klass;
leo_sobral@2
    23
leo_sobral@2
    24
	gobject_class->dispose  = myth_livetv_dispose;
leo_sobral@2
    25
	gobject_class->finalize = myth_livetv_finalize;	
leo_sobral@2
    26
}
leo_sobral@2
    27
leo_sobral@2
    28
static void
leo_sobral@2
    29
myth_livetv_init (MythLiveTV *livetv)
leo_sobral@2
    30
{
leo_sobral@2
    31
	livetv->backend_hostname = NULL;
leo_sobral@2
    32
	livetv->backend_port = 0;
leo_sobral@2
    33
	livetv->local_hostname = NULL;
leo_sobral@2
    34
leo_sobral@2
    35
	livetv->remote_encoder = NULL;
leo_sobral@2
    36
	livetv->tvchain = NULL;
leo_sobral@2
    37
	livetv->proginfo = NULL;
leo_sobral@2
    38
}
leo_sobral@2
    39
leo_sobral@2
    40
static void
leo_sobral@2
    41
myth_livetv_dispose  (GObject *object)
leo_sobral@2
    42
{
leo_sobral@2
    43
leo_sobral@2
    44
	G_OBJECT_CLASS (myth_livetv_parent_class)->dispose (object);
leo_sobral@2
    45
}
leo_sobral@2
    46
leo_sobral@2
    47
static void
leo_sobral@2
    48
myth_livetv_finalize (GObject *object)
leo_sobral@2
    49
{
leo_sobral@2
    50
	g_signal_handlers_destroy (object);
leo_sobral@2
    51
leo_sobral@2
    52
	MythLiveTV *livetv = MYTH_LIVETV (object);
leo_sobral@2
    53
leo_sobral@2
    54
	g_debug ("[%s] Finalizing livetv", __FUNCTION__);
leo_sobral@2
    55
leo_sobral@2
    56
	if ( livetv->remote_encoder != NULL ) {
leo_sobral@2
    57
		g_object_unref (livetv->remote_encoder);
leo_sobral@2
    58
		livetv->remote_encoder = NULL;
leo_sobral@2
    59
	}
leo_sobral@2
    60
leo_sobral@2
    61
	if ( livetv->tvchain != NULL ) {
leo_sobral@2
    62
		g_object_unref (livetv->tvchain);
leo_sobral@2
    63
		livetv->tvchain = NULL;
leo_sobral@2
    64
	}
leo_sobral@2
    65
leo_sobral@2
    66
	if ( livetv->proginfo != NULL ) {
leo_sobral@2
    67
		g_object_unref (livetv->proginfo);
leo_sobral@2
    68
		livetv->proginfo = NULL;
leo_sobral@2
    69
	}
leo_sobral@2
    70
leo_sobral@2
    71
	G_OBJECT_CLASS ( myth_livetv_parent_class )->finalize ( object );
leo_sobral@2
    72
}
leo_sobral@2
    73
leo_sobral@2
    74
MythLiveTV*
leo_sobral@2
    75
myth_livetv_new ()
leo_sobral@2
    76
{
leo_sobral@2
    77
	MythLiveTV *livetv = MYTH_LIVETV ( g_object_new( MYTH_LIVETV_TYPE, NULL ) );
leo_sobral@2
    78
leo_sobral@2
    79
	return livetv;
leo_sobral@2
    80
}
leo_sobral@2
    81
leo_sobral@2
    82
gboolean
leo_sobral@2
    83
myth_livetv_setup ( MythLiveTV *livetv )
leo_sobral@2
    84
{
leo_sobral@2
    85
leo_sobral@2
    86
	// FIXME: Get from the settings
leo_sobral@2
    87
	GMythSettings *msettings = gmyth_context_get_settings ();
leo_sobral@2
    88
	gboolean res = TRUE;
leo_sobral@2
    89
leo_sobral@2
    90
	livetv->is_livetv = TRUE;
leo_sobral@2
    91
leo_sobral@2
    92
	res = gmyth_context_check_connection();
leo_sobral@2
    93
	if (!res) {
leo_sobral@2
    94
		g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);	
leo_sobral@2
    95
		res = FALSE;
leo_sobral@2
    96
		goto error;
leo_sobral@2
    97
	}
leo_sobral@2
    98
leo_sobral@2
    99
	livetv->backend_hostname = gmyth_settings_get_backend_hostname(msettings);
leo_sobral@2
   100
	livetv->backend_port = gmyth_settings_get_backend_port (msettings);
leo_sobral@2
   101
leo_sobral@2
   102
	livetv->local_hostname  = g_string_new("");    
leo_sobral@2
   103
	gmyth_context_get_local_hostname (livetv->local_hostname);
leo_sobral@2
   104
leo_sobral@2
   105
	if ( livetv->local_hostname == NULL ) {
leo_sobral@2
   106
		res = FALSE;
leo_sobral@2
   107
		goto error;
leo_sobral@2
   108
	}
leo_sobral@2
   109
leo_sobral@2
   110
	// Gets the remote encoder num
leo_sobral@2
   111
	livetv->remote_encoder = remote_request_next_free_recorder (-1);
leo_sobral@2
   112
leo_sobral@2
   113
	if ( livetv->remote_encoder == NULL ) {
leo_sobral@2
   114
		g_warning ("[%s] None remote encoder available", __FUNCTION__);
leo_sobral@2
   115
		res = FALSE;
leo_sobral@2
   116
		goto error;
leo_sobral@2
   117
	}
leo_sobral@2
   118
leo_sobral@2
   119
	// Creates livetv chain handler
leo_sobral@2
   120
	livetv->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) );
leo_sobral@2
   121
	gmyth_tvchain_initialize ( livetv->tvchain, livetv->local_hostname );
leo_sobral@2
   122
leo_sobral@2
   123
	if ( livetv->tvchain == NULL || livetv->tvchain->tvchain_id == NULL ) {
leo_sobral@2
   124
		res = FALSE;
leo_sobral@2
   125
		goto error;
leo_sobral@2
   126
	}
leo_sobral@2
   127
leo_sobral@2
   128
	// Init remote encoder. Opens its control socket.
leo_sobral@2
   129
	res = gmyth_remote_encoder_setup(livetv->remote_encoder);
leo_sobral@2
   130
	if ( !res ) {
leo_sobral@2
   131
		g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
leo_sobral@2
   132
		res = FALSE;
leo_sobral@2
   133
		goto error;
leo_sobral@2
   134
	}
leo_sobral@2
   135
	// Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
leo_sobral@2
   136
	res = gmyth_remote_encoder_spawntv ( livetv->remote_encoder,
leo_sobral@2
   137
			gmyth_tvchain_get_id(livetv->tvchain) );
leo_sobral@2
   138
	if (!res) {
leo_sobral@2
   139
		g_warning ("[%s] Fail while spawn tv\n", __FUNCTION__);
leo_sobral@2
   140
		res = FALSE;
leo_sobral@2
   141
		goto error;
leo_sobral@2
   142
	}
leo_sobral@2
   143
leo_sobral@2
   144
	// Reload all TV chain from Mysql database.
leo_sobral@2
   145
	gmyth_tvchain_reload_all (livetv->tvchain);
leo_sobral@2
   146
leo_sobral@2
   147
	if ( livetv->tvchain == NULL ) {
leo_sobral@2
   148
		res = FALSE;
leo_sobral@2
   149
		goto error;
leo_sobral@2
   150
	}
leo_sobral@2
   151
leo_sobral@2
   152
	// Get program info from database using chanid and starttime
leo_sobral@2
   153
	livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, -1);
leo_sobral@2
   154
	if ( livetv->proginfo == NULL ) {
leo_sobral@2
   155
		g_warning ("[%s] LiveTV not successfully started.\n", __FUNCTION__ );
leo_sobral@2
   156
		res = FALSE;
leo_sobral@2
   157
		goto error;
leo_sobral@2
   158
	} else {
leo_sobral@2
   159
		g_debug ("[%s] MythLiveTV: All requests to backend to start TV were OK.\n", __FUNCTION__ );
leo_sobral@2
   160
	}
leo_sobral@2
   161
leo_sobral@2
   162
	return res;
leo_sobral@2
   163
leo_sobral@2
   164
error:
leo_sobral@2
   165
	if ( livetv->backend_hostname != NULL ) {
leo_sobral@2
   166
		g_string_free( livetv->backend_hostname, TRUE );
leo_sobral@2
   167
		res = FALSE;
leo_sobral@2
   168
	}
leo_sobral@2
   169
leo_sobral@2
   170
	if ( livetv->local_hostname != NULL ) {
leo_sobral@2
   171
		g_string_free( livetv->local_hostname, TRUE );
leo_sobral@2
   172
		res = FALSE;
leo_sobral@2
   173
	}
leo_sobral@2
   174
leo_sobral@2
   175
	if ( livetv->remote_encoder != NULL ) {
leo_sobral@2
   176
		g_object_unref (livetv->remote_encoder);
leo_sobral@2
   177
		livetv->remote_encoder = NULL;
leo_sobral@2
   178
	}
leo_sobral@2
   179
leo_sobral@2
   180
	if ( livetv->tvchain != NULL ) {
leo_sobral@2
   181
		g_object_unref (livetv->tvchain);
leo_sobral@2
   182
		livetv->tvchain = NULL;
leo_sobral@2
   183
	}
leo_sobral@2
   184
leo_sobral@2
   185
	if ( livetv->proginfo != NULL ) {
leo_sobral@2
   186
		g_object_unref (livetv->proginfo);
leo_sobral@2
   187
		livetv->proginfo = NULL;
leo_sobral@2
   188
	}
leo_sobral@2
   189
leo_sobral@2
   190
	return res;
leo_sobral@2
   191
leo_sobral@2
   192
}
leo_sobral@2
   193
leo_sobral@2
   194
// FIXME: How to proceed differently between livetv and recorded content
leo_sobral@2
   195
void
leo_sobral@2
   196
myth_livetv_stop_playing (MythLiveTV *livetv) 
leo_sobral@2
   197
{
leo_sobral@2
   198
	g_debug ("[%s] Stopping the LiveTV...\n", __FUNCTION__);
leo_sobral@2
   199
leo_sobral@2
   200
	if (livetv->is_livetv) {
leo_sobral@2
   201
		if (!gmyth_remote_encoder_stop_livetv (livetv->remote_encoder)) {
leo_sobral@2
   202
			g_warning ("[%s] Error while stoping remote encoder", __FUNCTION__);	
leo_sobral@2
   203
		}
leo_sobral@2
   204
	}
leo_sobral@2
   205
}
leo_sobral@2
   206
leo_sobral@2
   207
gboolean
leo_sobral@2
   208
myth_livetv_is_playing (MythLiveTV *livetv)
leo_sobral@2
   209
{
leo_sobral@2
   210
	return TRUE;
leo_sobral@2
   211
}
leo_sobral@2
   212
leo_sobral@2
   213
void
leo_sobral@2
   214
myth_livetv_start_playing (MythLiveTV *livetv)
leo_sobral@2
   215
{
leo_sobral@2
   216
leo_sobral@2
   217
	// TODO
leo_sobral@2
   218
leo_sobral@2
   219
}
leo_sobral@2
   220