1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/gst-plugins-mythtv/src/gmyth_livetv.c Mon Oct 23 18:12:18 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 "gmyth_livetv.h"
1.10 +#include "gmyth_file_transfer.h"
1.11 +
1.12 +static void gmyth_livetv_class_init (GMythLiveTVClass *klass);
1.13 +static void gmyth_livetv_init (GMythLiveTV *object);
1.14 +
1.15 +static void gmyth_livetv_dispose (GObject *object);
1.16 +static void gmyth_livetv_finalize (GObject *object);
1.17 +
1.18 +static gint tvchain_curr_index = -1;
1.19 +
1.20 +G_DEFINE_TYPE(GMythLiveTV, gmyth_livetv, G_TYPE_OBJECT)
1.21 +
1.22 +static void
1.23 +gmyth_livetv_class_init (GMythLiveTVClass *klass)
1.24 +{
1.25 + GObjectClass *gobject_class;
1.26 +
1.27 + gobject_class = (GObjectClass *) klass;
1.28 +
1.29 + gobject_class->dispose = gmyth_livetv_dispose;
1.30 + gobject_class->finalize = gmyth_livetv_finalize;
1.31 +}
1.32 +
1.33 +static void
1.34 +gmyth_livetv_init (GMythLiveTV *livetv)
1.35 +{
1.36 + livetv->backend_hostname = NULL;
1.37 + livetv->backend_port = 0;
1.38 + livetv->local_hostname = NULL;
1.39 +
1.40 + livetv->remote_encoder = NULL;
1.41 + livetv->tvchain = NULL;
1.42 + livetv->proginfo = NULL;
1.43 +}
1.44 +
1.45 +static void
1.46 +gmyth_livetv_dispose (GObject *object)
1.47 +{
1.48 +
1.49 + G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object);
1.50 +}
1.51 +
1.52 +static void
1.53 +gmyth_livetv_finalize (GObject *object)
1.54 +{
1.55 + g_signal_handlers_destroy (object);
1.56 +
1.57 + GMythLiveTV *livetv = GMYTH_LIVETV (object);
1.58 +
1.59 + g_debug ("[%s] Finalizing livetv", __FUNCTION__);
1.60 +
1.61 + if ( livetv->remote_encoder != NULL ) {
1.62 + g_object_unref (livetv->remote_encoder);
1.63 + livetv->remote_encoder = NULL;
1.64 + }
1.65 +
1.66 + if ( livetv->tvchain != NULL ) {
1.67 + g_object_unref (livetv->tvchain);
1.68 + livetv->tvchain = NULL;
1.69 + }
1.70 +
1.71 + if ( livetv->proginfo != NULL ) {
1.72 + g_object_unref (livetv->proginfo);
1.73 + livetv->proginfo = NULL;
1.74 + }
1.75 +
1.76 + G_OBJECT_CLASS ( gmyth_livetv_parent_class )->finalize ( object );
1.77 +}
1.78 +
1.79 +GMythLiveTV*
1.80 +gmyth_livetv_new ()
1.81 +{
1.82 + GMythLiveTV *livetv = GMYTH_LIVETV ( g_object_new( GMYTH_LIVETV_TYPE, NULL ) );
1.83 +
1.84 + return livetv;
1.85 +}
1.86 +
1.87 +gboolean
1.88 +gmyth_livetv_setup ( GMythLiveTV *livetv )
1.89 +{
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, tvchain_curr_index++ );
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] GMythLiveTV: 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 +gmyth_livetv_stop_playing (GMythLiveTV *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 +gmyth_livetv_is_playing (GMythLiveTV *livetv)
1.212 +{
1.213 + return TRUE;
1.214 +}
1.215 +
1.216 +void
1.217 +gmyth_livetv_start_playing (GMythLiveTV *livetv)
1.218 +{
1.219 +
1.220 + // TODO
1.221 +
1.222 +}
1.223 +