#include #include #include #include "myth_livetv.h" #include "myth_file_transfer.h" static void myth_livetv_class_init (MythLiveTVClass *klass); static void myth_livetv_init (MythLiveTV *object); static void myth_livetv_dispose (GObject *object); static void myth_livetv_finalize (GObject *object); G_DEFINE_TYPE(MythLiveTV, myth_livetv, G_TYPE_OBJECT) static void myth_livetv_class_init (MythLiveTVClass *klass) { GObjectClass *gobject_class; gobject_class = (GObjectClass *) klass; gobject_class->dispose = myth_livetv_dispose; gobject_class->finalize = myth_livetv_finalize; } static void myth_livetv_init (MythLiveTV *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 myth_livetv_dispose (GObject *object) { G_OBJECT_CLASS (myth_livetv_parent_class)->dispose (object); } static void myth_livetv_finalize (GObject *object) { g_signal_handlers_destroy (object); MythLiveTV *livetv = MYTH_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 ( myth_livetv_parent_class )->finalize ( object ); } MythLiveTV* myth_livetv_new () { MythLiveTV *livetv = MYTH_LIVETV ( g_object_new( MYTH_LIVETV_TYPE, NULL ) ); return livetv; } gboolean myth_livetv_setup ( MythLiveTV *livetv ) { // FIXME: Get from the settings 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, -1); if ( livetv->proginfo == NULL ) { g_warning ("[%s] LiveTV not successfully started.\n", __FUNCTION__ ); res = FALSE; goto error; } else { g_debug ("[%s] MythLiveTV: 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 myth_livetv_stop_playing (MythLiveTV *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 myth_livetv_is_playing (MythLiveTV *livetv) { return TRUE; } void myth_livetv_start_playing (MythLiveTV *livetv) { // TODO }