diff -r 324e04989738 -r ba5dc9bff3a1 gst-plugins-mythtv/src/gmyth_livetv.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gst-plugins-mythtv/src/gmyth_livetv.c Mon Oct 23 15:42:46 2006 +0100 @@ -0,0 +1,220 @@ + +#include +#include +#include + +#include "gmyth_livetv.h" +#include "gmyth_file_transfer.h" + +static void gmyth_livetv_class_init (GMythLiveTVClass *klass); +static void gmyth_livetv_init (GMythLiveTV *object); + +static void gmyth_livetv_dispose (GObject *object); +static void gmyth_livetv_finalize (GObject *object); + +static gint tvchain_curr_index = -1; + +G_DEFINE_TYPE(GMythLiveTV, gmyth_livetv, G_TYPE_OBJECT) + +static void +gmyth_livetv_class_init (GMythLiveTVClass *klass) +{ + GObjectClass *gobject_class; + + gobject_class = (GObjectClass *) klass; + + gobject_class->dispose = gmyth_livetv_dispose; + gobject_class->finalize = gmyth_livetv_finalize; +} + +static void +gmyth_livetv_init (GMythLiveTV *livetv) +{ + livetv->backend_hostname = NULL; + livetv->backend_port = 0; + livetv->local_hostname = NULL; + + livetv->remote_encoder = NULL; + livetv->tvchain = NULL; + livetv->proginfo = NULL; +} + +static void +gmyth_livetv_dispose (GObject *object) +{ + + G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object); +} + +static void +gmyth_livetv_finalize (GObject *object) +{ + g_signal_handlers_destroy (object); + + GMythLiveTV *livetv = GMYTH_LIVETV (object); + + g_debug ("[%s] Finalizing livetv", __FUNCTION__); + + if ( livetv->remote_encoder != NULL ) { + g_object_unref (livetv->remote_encoder); + livetv->remote_encoder = NULL; + } + + if ( livetv->tvchain != NULL ) { + g_object_unref (livetv->tvchain); + livetv->tvchain = NULL; + } + + if ( livetv->proginfo != NULL ) { + g_object_unref (livetv->proginfo); + livetv->proginfo = NULL; + } + + G_OBJECT_CLASS ( gmyth_livetv_parent_class )->finalize ( object ); +} + +GMythLiveTV* +gmyth_livetv_new () +{ + GMythLiveTV *livetv = GMYTH_LIVETV ( g_object_new( GMYTH_LIVETV_TYPE, NULL ) ); + + return livetv; +} + +gboolean +gmyth_livetv_setup ( GMythLiveTV *livetv ) +{ + GMythSettings *msettings = gmyth_context_get_settings (); + gboolean res = TRUE; + + livetv->is_livetv = TRUE; + + res = gmyth_context_check_connection(); + if (!res) { + g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__); + res = FALSE; + goto error; + } + + livetv->backend_hostname = gmyth_settings_get_backend_hostname(msettings); + livetv->backend_port = gmyth_settings_get_backend_port (msettings); + + livetv->local_hostname = g_string_new(""); + gmyth_context_get_local_hostname (livetv->local_hostname); + + if ( livetv->local_hostname == NULL ) { + res = FALSE; + goto error; + } + + // Gets the remote encoder num + livetv->remote_encoder = remote_request_next_free_recorder (-1); + + if ( livetv->remote_encoder == NULL ) { + g_warning ("[%s] None remote encoder available", __FUNCTION__); + res = FALSE; + goto error; + } + + // Creates livetv chain handler + livetv->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) ); + gmyth_tvchain_initialize ( livetv->tvchain, livetv->local_hostname ); + + if ( livetv->tvchain == NULL || livetv->tvchain->tvchain_id == NULL ) { + res = FALSE; + goto error; + } + + // Init remote encoder. Opens its control socket. + res = gmyth_remote_encoder_setup(livetv->remote_encoder); + if ( !res ) { + g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__); + res = FALSE; + goto error; + } + // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly) + res = gmyth_remote_encoder_spawntv ( livetv->remote_encoder, + gmyth_tvchain_get_id(livetv->tvchain) ); + if (!res) { + g_warning ("[%s] Fail while spawn tv\n", __FUNCTION__); + res = FALSE; + goto error; + } + + // Reload all TV chain from Mysql database. + gmyth_tvchain_reload_all (livetv->tvchain); + + if ( livetv->tvchain == NULL ) { + res = FALSE; + goto error; + } + + // Get program info from database using chanid and starttime + livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, tvchain_curr_index++ ); + if ( livetv->proginfo == NULL ) { + g_warning ("[%s] LiveTV not successfully started.\n", __FUNCTION__ ); + res = FALSE; + goto error; + } else { + g_debug ("[%s] GMythLiveTV: All requests to backend to start TV were OK.\n", __FUNCTION__ ); + } + + return res; + +error: + if ( livetv->backend_hostname != NULL ) { + g_string_free( livetv->backend_hostname, TRUE ); + res = FALSE; + } + + if ( livetv->local_hostname != NULL ) { + g_string_free( livetv->local_hostname, TRUE ); + res = FALSE; + } + + if ( livetv->remote_encoder != NULL ) { + g_object_unref (livetv->remote_encoder); + livetv->remote_encoder = NULL; + } + + if ( livetv->tvchain != NULL ) { + g_object_unref (livetv->tvchain); + livetv->tvchain = NULL; + } + + if ( livetv->proginfo != NULL ) { + g_object_unref (livetv->proginfo); + livetv->proginfo = NULL; + } + + return res; + +} + +// FIXME: How to proceed differently between livetv and recorded content +void +gmyth_livetv_stop_playing (GMythLiveTV *livetv) +{ + g_debug ("[%s] Stopping the LiveTV...\n", __FUNCTION__); + + if (livetv->is_livetv) { + if (!gmyth_remote_encoder_stop_livetv (livetv->remote_encoder)) { + g_warning ("[%s] Error while stoping remote encoder", __FUNCTION__); + } + } +} + +gboolean +gmyth_livetv_is_playing (GMythLiveTV *livetv) +{ + return TRUE; +} + +void +gmyth_livetv_start_playing (GMythLiveTV *livetv) +{ + + // TODO + +} +