[svn r35] Performance optimization.
2 #include <gmyth/gmyth_context.h>
3 #include <gmyth/gmyth_remote_util.h>
4 #include <gmyth/gmyth_tvchain.h>
6 #include "myth_livetv.h"
7 #include "myth_file_transfer.h"
9 static void myth_livetv_class_init (MythLiveTVClass *klass);
10 static void myth_livetv_init (MythLiveTV *object);
12 static void myth_livetv_dispose (GObject *object);
13 static void myth_livetv_finalize (GObject *object);
15 G_DEFINE_TYPE(MythLiveTV, myth_livetv, G_TYPE_OBJECT)
18 myth_livetv_class_init (MythLiveTVClass *klass)
20 GObjectClass *gobject_class;
22 gobject_class = (GObjectClass *) klass;
24 gobject_class->dispose = myth_livetv_dispose;
25 gobject_class->finalize = myth_livetv_finalize;
29 myth_livetv_init (MythLiveTV *livetv)
31 livetv->backend_hostname = NULL;
32 livetv->backend_port = 0;
33 livetv->local_hostname = NULL;
35 livetv->remote_encoder = NULL;
36 livetv->tvchain = NULL;
37 livetv->proginfo = NULL;
41 myth_livetv_dispose (GObject *object)
44 G_OBJECT_CLASS (myth_livetv_parent_class)->dispose (object);
48 myth_livetv_finalize (GObject *object)
50 g_signal_handlers_destroy (object);
52 MythLiveTV *livetv = MYTH_LIVETV (object);
54 g_debug ("[%s] Finalizing livetv", __FUNCTION__);
56 if ( livetv->remote_encoder != NULL ) {
57 g_object_unref (livetv->remote_encoder);
58 livetv->remote_encoder = NULL;
61 if ( livetv->tvchain != NULL ) {
62 g_object_unref (livetv->tvchain);
63 livetv->tvchain = NULL;
66 if ( livetv->proginfo != NULL ) {
67 g_object_unref (livetv->proginfo);
68 livetv->proginfo = NULL;
71 G_OBJECT_CLASS ( myth_livetv_parent_class )->finalize ( object );
77 MythLiveTV *livetv = MYTH_LIVETV ( g_object_new( MYTH_LIVETV_TYPE, NULL ) );
83 myth_livetv_setup ( MythLiveTV *livetv )
86 // FIXME: Get from the settings
87 GMythSettings *msettings = gmyth_context_get_settings ();
90 livetv->is_livetv = TRUE;
92 res = gmyth_context_check_connection();
94 g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);
99 livetv->backend_hostname = gmyth_settings_get_backend_hostname(msettings);
100 livetv->backend_port = gmyth_settings_get_backend_port (msettings);
102 livetv->local_hostname = g_string_new("");
103 gmyth_context_get_local_hostname (livetv->local_hostname);
105 if ( livetv->local_hostname == NULL ) {
110 // Gets the remote encoder num
111 livetv->remote_encoder = remote_request_next_free_recorder (-1);
113 if ( livetv->remote_encoder == NULL ) {
114 g_warning ("[%s] None remote encoder available", __FUNCTION__);
119 // Creates livetv chain handler
120 livetv->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) );
121 gmyth_tvchain_initialize ( livetv->tvchain, livetv->local_hostname );
123 if ( livetv->tvchain == NULL || livetv->tvchain->tvchain_id == NULL ) {
128 // Init remote encoder. Opens its control socket.
129 res = gmyth_remote_encoder_setup(livetv->remote_encoder);
131 g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
135 // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
136 res = gmyth_remote_encoder_spawntv ( livetv->remote_encoder,
137 gmyth_tvchain_get_id(livetv->tvchain) );
139 g_warning ("[%s] Fail while spawn tv\n", __FUNCTION__);
144 // Reload all TV chain from Mysql database.
145 gmyth_tvchain_reload_all (livetv->tvchain);
147 if ( livetv->tvchain == NULL ) {
152 // Get program info from database using chanid and starttime
153 livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, -1);
154 if ( livetv->proginfo == NULL ) {
155 g_warning ("[%s] LiveTV not successfully started.\n", __FUNCTION__ );
159 g_debug ("[%s] MythLiveTV: All requests to backend to start TV were OK.\n", __FUNCTION__ );
165 if ( livetv->backend_hostname != NULL ) {
166 g_string_free( livetv->backend_hostname, TRUE );
170 if ( livetv->local_hostname != NULL ) {
171 g_string_free( livetv->local_hostname, TRUE );
175 if ( livetv->remote_encoder != NULL ) {
176 g_object_unref (livetv->remote_encoder);
177 livetv->remote_encoder = NULL;
180 if ( livetv->tvchain != NULL ) {
181 g_object_unref (livetv->tvchain);
182 livetv->tvchain = NULL;
185 if ( livetv->proginfo != NULL ) {
186 g_object_unref (livetv->proginfo);
187 livetv->proginfo = NULL;
194 // FIXME: How to proceed differently between livetv and recorded content
196 myth_livetv_stop_playing (MythLiveTV *livetv)
198 g_debug ("[%s] Stopping the LiveTV...\n", __FUNCTION__);
200 if (livetv->is_livetv) {
201 if (!gmyth_remote_encoder_stop_livetv (livetv->remote_encoder)) {
202 g_warning ("[%s] Error while stoping remote encoder", __FUNCTION__);
208 myth_livetv_is_playing (MythLiveTV *livetv)
214 myth_livetv_start_playing (MythLiveTV *livetv)