1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/gst-plugins-mythtv/myth_livetv.c Thu Sep 21 00:05:27 2006 +0100
1.3 @@ -0,0 +1,220 @@
1.4 +
1.5 +#include <gmyth/gmyth_context.h>
1.6 +#include <gmyth/gmyth_remote_util.h>
1.7 +#include <gmyth/gmyth_tvchain.h>
1.8 +
1.9 +#include "myth_livetv.h"
1.10 +#include "myth_file_transfer.h"
1.11 +
1.12 +static void myth_livetv_class_init (MythLiveTVClass *klass);
1.13 +static void myth_livetv_init (MythLiveTV *object);
1.14 +
1.15 +static void myth_livetv_dispose (GObject *object);
1.16 +static void myth_livetv_finalize (GObject *object);
1.17 +
1.18 +G_DEFINE_TYPE(MythLiveTV, myth_livetv, G_TYPE_OBJECT)
1.19 +
1.20 +static void
1.21 +myth_livetv_class_init (MythLiveTVClass *klass)
1.22 +{
1.23 + GObjectClass *gobject_class;
1.24 +
1.25 + gobject_class = (GObjectClass *) klass;
1.26 +
1.27 + gobject_class->dispose = myth_livetv_dispose;
1.28 + gobject_class->finalize = myth_livetv_finalize;
1.29 +}
1.30 +
1.31 +static void
1.32 +myth_livetv_init (MythLiveTV *livetv)
1.33 +{
1.34 + livetv->backend_hostname = NULL;
1.35 + livetv->backend_port = 0;
1.36 + livetv->local_hostname = NULL;
1.37 +
1.38 + livetv->remote_encoder = NULL;
1.39 + livetv->tvchain = NULL;
1.40 + livetv->proginfo = NULL;
1.41 +}
1.42 +
1.43 +static void
1.44 +myth_livetv_dispose (GObject *object)
1.45 +{
1.46 +
1.47 + G_OBJECT_CLASS (myth_livetv_parent_class)->dispose (object);
1.48 +}
1.49 +
1.50 +static void
1.51 +myth_livetv_finalize (GObject *object)
1.52 +{
1.53 + g_signal_handlers_destroy (object);
1.54 +
1.55 + MythLiveTV *livetv = MYTH_LIVETV (object);
1.56 +
1.57 + g_debug ("[%s] Finalizing livetv", __FUNCTION__);
1.58 +
1.59 + if ( livetv->remote_encoder != NULL ) {
1.60 + g_object_unref (livetv->remote_encoder);
1.61 + livetv->remote_encoder = NULL;
1.62 + }
1.63 +
1.64 + if ( livetv->tvchain != NULL ) {
1.65 + g_object_unref (livetv->tvchain);
1.66 + livetv->tvchain = NULL;
1.67 + }
1.68 +
1.69 + if ( livetv->proginfo != NULL ) {
1.70 + g_object_unref (livetv->proginfo);
1.71 + livetv->proginfo = NULL;
1.72 + }
1.73 +
1.74 + G_OBJECT_CLASS ( myth_livetv_parent_class )->finalize ( object );
1.75 +}
1.76 +
1.77 +MythLiveTV*
1.78 +myth_livetv_new ()
1.79 +{
1.80 + MythLiveTV *livetv = MYTH_LIVETV ( g_object_new( MYTH_LIVETV_TYPE, NULL ) );
1.81 +
1.82 + return livetv;
1.83 +}
1.84 +
1.85 +gboolean
1.86 +myth_livetv_setup ( MythLiveTV *livetv )
1.87 +{
1.88 +
1.89 + // FIXME: Get from the settings
1.90 + GMythSettings *msettings = gmyth_context_get_settings ();
1.91 + gboolean res = TRUE;
1.92 +
1.93 + livetv->is_livetv = TRUE;
1.94 +
1.95 + res = gmyth_context_check_connection();
1.96 + if (!res) {
1.97 + g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);
1.98 + res = FALSE;
1.99 + goto error;
1.100 + }
1.101 +
1.102 + livetv->backend_hostname = gmyth_settings_get_backend_hostname(msettings);
1.103 + livetv->backend_port = gmyth_settings_get_backend_port (msettings);
1.104 +
1.105 + livetv->local_hostname = g_string_new("");
1.106 + gmyth_context_get_local_hostname (livetv->local_hostname);
1.107 +
1.108 + if ( livetv->local_hostname == NULL ) {
1.109 + res = FALSE;
1.110 + goto error;
1.111 + }
1.112 +
1.113 + // Gets the remote encoder num
1.114 + livetv->remote_encoder = remote_request_next_free_recorder (-1);
1.115 +
1.116 + if ( livetv->remote_encoder == NULL ) {
1.117 + g_warning ("[%s] None remote encoder available", __FUNCTION__);
1.118 + res = FALSE;
1.119 + goto error;
1.120 + }
1.121 +
1.122 + // Creates livetv chain handler
1.123 + livetv->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) );
1.124 + gmyth_tvchain_initialize ( livetv->tvchain, livetv->local_hostname );
1.125 +
1.126 + if ( livetv->tvchain == NULL || livetv->tvchain->tvchain_id == NULL ) {
1.127 + res = FALSE;
1.128 + goto error;
1.129 + }
1.130 +
1.131 + // Init remote encoder. Opens its control socket.
1.132 + res = gmyth_remote_encoder_setup(livetv->remote_encoder);
1.133 + if ( !res ) {
1.134 + g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
1.135 + res = FALSE;
1.136 + goto error;
1.137 + }
1.138 + // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
1.139 + res = gmyth_remote_encoder_spawntv ( livetv->remote_encoder,
1.140 + gmyth_tvchain_get_id(livetv->tvchain) );
1.141 + if (!res) {
1.142 + g_warning ("[%s] Fail while spawn tv\n", __FUNCTION__);
1.143 + res = FALSE;
1.144 + goto error;
1.145 + }
1.146 +
1.147 + // Reload all TV chain from Mysql database.
1.148 + gmyth_tvchain_reload_all (livetv->tvchain);
1.149 +
1.150 + if ( livetv->tvchain == NULL ) {
1.151 + res = FALSE;
1.152 + goto error;
1.153 + }
1.154 +
1.155 + // Get program info from database using chanid and starttime
1.156 + livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, -1);
1.157 + if ( livetv->proginfo == NULL ) {
1.158 + g_warning ("[%s] LiveTV not successfully started.\n", __FUNCTION__ );
1.159 + res = FALSE;
1.160 + goto error;
1.161 + } else {
1.162 + g_debug ("[%s] MythLiveTV: All requests to backend to start TV were OK.\n", __FUNCTION__ );
1.163 + }
1.164 +
1.165 + return res;
1.166 +
1.167 +error:
1.168 + if ( livetv->backend_hostname != NULL ) {
1.169 + g_string_free( livetv->backend_hostname, TRUE );
1.170 + res = FALSE;
1.171 + }
1.172 +
1.173 + if ( livetv->local_hostname != NULL ) {
1.174 + g_string_free( livetv->local_hostname, TRUE );
1.175 + res = FALSE;
1.176 + }
1.177 +
1.178 + if ( livetv->remote_encoder != NULL ) {
1.179 + g_object_unref (livetv->remote_encoder);
1.180 + livetv->remote_encoder = NULL;
1.181 + }
1.182 +
1.183 + if ( livetv->tvchain != NULL ) {
1.184 + g_object_unref (livetv->tvchain);
1.185 + livetv->tvchain = NULL;
1.186 + }
1.187 +
1.188 + if ( livetv->proginfo != NULL ) {
1.189 + g_object_unref (livetv->proginfo);
1.190 + livetv->proginfo = NULL;
1.191 + }
1.192 +
1.193 + return res;
1.194 +
1.195 +}
1.196 +
1.197 +// FIXME: How to proceed differently between livetv and recorded content
1.198 +void
1.199 +myth_livetv_stop_playing (MythLiveTV *livetv)
1.200 +{
1.201 + g_debug ("[%s] Stopping the LiveTV...\n", __FUNCTION__);
1.202 +
1.203 + if (livetv->is_livetv) {
1.204 + if (!gmyth_remote_encoder_stop_livetv (livetv->remote_encoder)) {
1.205 + g_warning ("[%s] Error while stoping remote encoder", __FUNCTION__);
1.206 + }
1.207 + }
1.208 +}
1.209 +
1.210 +gboolean
1.211 +myth_livetv_is_playing (MythLiveTV *livetv)
1.212 +{
1.213 + return TRUE;
1.214 +}
1.215 +
1.216 +void
1.217 +myth_livetv_start_playing (MythLiveTV *livetv)
1.218 +{
1.219 +
1.220 + // TODO
1.221 +
1.222 +}
1.223 +