maemo-ui/src/mmyth_tvplayer.c
author renatofilho
Fri Oct 27 19:10:56 2006 +0100 (2006-10-27)
branchtrunk
changeset 60 98fa2109e716
parent 20 7174e23f7617
child 64 f926338c6952
permissions -rw-r--r--
[svn r61] - bug fixes;
     1 /**
     2  * GMyth Library
     3  *
     4  * @file gmyth/mmyth_tvplayer.c
     5  * 
     6  * @brief <p> This component provides playback of the remote A/V using
     7  * GStreamer.
     8  * 
     9  * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    10  * @author Hallyson Luiz de Morais Melo <hallyson.melo@indt.org.br>
    11  *
    12  *//*
    13  * 
    14  * This program is free software; you can redistribute it and/or modify
    15  * it under the terms of the GNU Lesser General Public License as published by
    16  * the Free Software Foundation; either version 2 of the License, or
    17  * (at your option) any later version.
    18  *
    19  * This program is distributed in the hope that it will be useful,
    20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    22  * GNU General Public License for more details.
    23  *
    24  * You should have received a copy of the GNU Lesser General Public License
    25  * along with this program; if not, write to the Free Software
    26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    27  */
    28 
    29 #include "mmyth_tvplayer.h"
    30  
    31 #include <gdk/gdkx.h>
    32 
    33 #include "gmyth_context.h"
    34 #include "gmyth_remote_util.h"
    35 
    36 typedef struct _GstPlayerWindowStateChange
    37 {
    38     GstElement *play;
    39     GstState old_state, new_state;
    40     MMythTVPlayer *tvplayer;
    41 } GstPlayerWindowStateChange;
    42 
    43 typedef struct _GstPlayerWindowTagFound
    44 {
    45     GstElement *play;
    46     GstTagList *taglist;
    47     MMythTVPlayer *tvplayer;
    48 } GstPlayerWindowTagFound;
    49 
    50 /*
    51 static gboolean idle_state (gpointer data);
    52 */
    53 static gboolean bus_call (GstBus * bus, GstMessage * msg, gpointer data);
    54 
    55 static void mmyth_tvplayer_class_init          (MMythTVPlayerClass *klass);
    56 static void mmyth_tvplayer_init                (MMythTVPlayer *object);
    57 
    58 static void mmyth_tvplayer_dispose  (GObject *object);
    59 static void mmyth_tvplayer_finalize (GObject *object);
    60 
    61 G_DEFINE_TYPE(MMythTVPlayer, mmyth_tvplayer, G_TYPE_OBJECT)
    62 
    63 static gboolean mmyth_tvplayer_create_pipeline (MMythTVPlayer* tvplayer);
    64 static void     new_pad_cb (GstElement *element, 
    65                             GstPad *pad, gpointer data);
    66 
    67 static gboolean expose_cb (GtkWidget * widget, 
    68                            GdkEventExpose * event, 
    69                            gpointer user_data);
    70 
    71 static void
    72 mmyth_tvplayer_class_init (MMythTVPlayerClass *klass)
    73 {
    74 	GObjectClass *gobject_class;
    75 
    76     gobject_class = (GObjectClass *) klass;
    77 	
    78     gobject_class->dispose  = mmyth_tvplayer_dispose;
    79     gobject_class->finalize = mmyth_tvplayer_finalize;	
    80 }
    81 
    82 static void
    83 new_pad_cb (GstElement *element, GstPad *pad, gpointer data)
    84 {
    85 	MMythTVPlayer *tvplayer = MMYTH_TVPLAYER (data);
    86 	GstPadLinkReturn ret;
    87 	char *s;
    88 	
    89 	s = gst_caps_to_string (pad->caps);
    90 
    91 	if ( s[0] == 'a') {
    92 		ret = gst_pad_link (pad, gst_element_get_pad (tvplayer->audioqueue, "sink"));
    93 	} else {
    94 		ret = gst_pad_link (pad, gst_element_get_pad (tvplayer->videoqueue, "sink")); 
    95 	}
    96 	
    97 	g_free(s);
    98 }
    99 
   100 static gboolean
   101 expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer user_data)
   102 {
   103     MMythTVPlayer *tvplayer = MMYTH_TVPLAYER (user_data);
   104 
   105 	if (tvplayer && tvplayer->videow) {
   106 	    gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (tvplayer->gst_videosink),
   107                                   GDK_WINDOW_XWINDOW (widget->window));
   108 		return TRUE;
   109 	}
   110 	
   111 	g_warning ("MMythTVPlayer expose called before setting video window\n");
   112 	
   113     return FALSE;
   114 }
   115 
   116 static void
   117 mmyth_tvplayer_init (MMythTVPlayer *tvplayer)
   118 {
   119     tvplayer->gst_pipeline = NULL;
   120     tvplayer->gst_source = NULL;
   121     tvplayer->gst_videodec = NULL;
   122     tvplayer->gst_videosink = NULL;
   123     tvplayer->videoqueue = NULL;
   124     tvplayer->audioqueue = NULL;
   125     
   126     /* GTKWidget for rendering the video */
   127     tvplayer->videow = NULL;
   128 	tvplayer->expose_handler = 0;
   129 	    
   130 	tvplayer->backend_hostname = NULL;
   131 	tvplayer->backend_port = 0;
   132 	tvplayer->local_hostname = NULL;
   133 
   134 	tvplayer->remote_encoder = NULL;
   135 	tvplayer->tvchain = NULL;
   136 	tvplayer->proginfo = NULL;
   137 }
   138 
   139 static void
   140 mmyth_tvplayer_dispose (GObject *object)
   141 {
   142 
   143 	G_OBJECT_CLASS (mmyth_tvplayer_parent_class)->dispose (object);
   144 }
   145 
   146 static void
   147 mmyth_tvplayer_finalize (GObject *object)
   148 {
   149 	g_signal_handlers_destroy (object);
   150 
   151 	MMythTVPlayer *tvplayer = MMYTH_TVPLAYER (object);
   152 
   153 	g_debug ("[%s] Finalizing tvplayer", __FUNCTION__);
   154 	
   155 	if (tvplayer->videow != NULL) {
   156 		if (g_signal_handler_is_connected (tvplayer->videow, 
   157 						tvplayer->expose_handler)) {
   158 			g_signal_handler_disconnect (tvplayer->videow,
   159 				tvplayer->expose_handler);
   160 		}
   161 		g_object_unref (tvplayer->videow);
   162 	}
   163 	
   164 	if ( tvplayer->remote_encoder != NULL )
   165 		g_object_unref (tvplayer->remote_encoder);
   166 	if ( tvplayer->tvchain != NULL )
   167 		g_object_unref (tvplayer->tvchain);
   168 	if ( tvplayer->proginfo != NULL )
   169 		g_object_unref (tvplayer->proginfo);	
   170 
   171 	// Release Gstreamer elements
   172 	if ( tvplayer->gst_pipeline != NULL )
   173 		g_object_unref (tvplayer->gst_pipeline);	
   174 	if ( tvplayer->gst_source != NULL )
   175 		g_object_unref (tvplayer->gst_source);	
   176 	if ( tvplayer->gst_videodec != NULL )
   177 		g_object_unref (tvplayer->gst_videodec);	
   178 	if ( tvplayer->gst_videosink != NULL )
   179 		g_object_unref (tvplayer->gst_videosink);	
   180 	if ( tvplayer->videoqueue != NULL )
   181 		g_object_unref (tvplayer->videoqueue);	
   182 	if ( tvplayer->audioqueue != NULL )
   183 		g_object_unref (tvplayer->audioqueue);	
   184 
   185 	G_OBJECT_CLASS (mmyth_tvplayer_parent_class)->finalize (object);
   186 }
   187 
   188 /** Creates a new instance of MMythTVPlayer. 
   189  * 
   190  * @return a new instance of MMythTVPlayer.
   191  */
   192 MMythTVPlayer *
   193 mmyth_tvplayer_new ()
   194 {
   195     MMythTVPlayer *tvplayer = 
   196         MMYTH_TVPLAYER (g_object_new(MMYTH_TVPLAYER_TYPE, NULL));
   197     
   198     return tvplayer;
   199 }
   200 
   201 /** Initializes the tv player.
   202  *
   203  * @param tvplayer the object instance.
   204  * @return gboolean TRUE if the pipeline was created 
   205  * successfully, FALSE otherwise.
   206  */
   207 gboolean
   208 mmyth_tvplayer_initialize (MMythTVPlayer *tvplayer)
   209 {
   210 	
   211     if (!mmyth_tvplayer_create_pipeline (tvplayer)) {
   212     	g_warning ("[%s] Error while creating pipeline. TV Player not initialized", __FUNCTION__);
   213 		return FALSE;
   214 	} else {
   215 		g_debug ("[%s] GStreamer pipeline created", __FUNCTION__);	
   216     }
   217 
   218 	return TRUE;
   219 }
   220 
   221 /** Creates the GStreamer pipeline used by the player.
   222  *
   223  * @param tvplayer the object instance.
   224  * @return gboolean TRUE if the pipeline was created 
   225  * successfully, FALSE otherwise.
   226  */
   227 static gboolean
   228 mmyth_tvplayer_create_pipeline (MMythTVPlayer* tvplayer)
   229 {
   230     GstElement *pipeline;
   231     GstElement *source, *parser;
   232     GstElement *videodec, *videosink;
   233 #ifndef MAEMO_PLATFORM    
   234     GstElement *audiodec, *audioconv;
   235 #endif
   236     GstElement *audiosink;
   237     GstElement *videoqueue, *audioqueue;
   238 
   239     g_debug ("MMythTVPlayer: Setting the Gstreamer pipeline\n");
   240 	
   241     pipeline = gst_pipeline_new ("video-player");
   242     source = gst_element_factory_make ("mythtvsrc", "myth-source");
   243     parser = gst_element_factory_make ("ffdemux_nuv", "nuv-demux");
   244 
   245     /* Gstreamer Video elements */
   246     videoqueue = gst_element_factory_make ("queue", "video-queue");
   247     videodec = gst_element_factory_make ("ffdec_mpeg4", "video-decoder");
   248 #ifdef MAEMO_PLATFORM
   249     videosink = gst_element_factory_make ("sdlvideosink", "image-output");
   250 #else
   251     videosink = gst_element_factory_make ("xvimagesink", "image-output");
   252 #endif
   253     
   254     /* Gstreamer Audio elements */
   255     audioqueue = gst_element_factory_make ("queue", "audio-queue");    
   256 #ifdef MAEMO_PLATFORM    
   257     audiosink = gst_element_factory_make ("dspmp3sink", "audio-output");
   258 #else    
   259     audiodec = gst_element_factory_make ("ffdec_mp3", "audio-decoder");
   260     audioconv = gst_element_factory_make ("audioconvert", "audio-converter");
   261     audiosink = gst_element_factory_make ("alsasink", "audio-output");
   262 #endif    
   263     
   264     if (!(pipeline && source && parser && videodec && videosink) ||
   265     	!(videoqueue && audioqueue && audiosink)) {
   266         /* FIXME: hanlde the error correctly */
   267         /* video_alignment is not being created (below) 
   268            and is causing problems to the ui */
   269 
   270 	    tvplayer->gst_pipeline = NULL;
   271 	    tvplayer->gst_videodec = NULL;
   272 	    tvplayer->gst_videosink = NULL;
   273            
   274         g_warning ("GstElement creation error!\n");
   275         return FALSE;
   276     }
   277 
   278 #ifndef MAEMO_PLATFORM    
   279     if (!(audiodec && audioconv)) {
   280         g_warning ("GstElement for audio stream creation error!");
   281         return FALSE;
   282     }
   283 #endif    
   284     
   285     
   286     tvplayer->gst_pipeline = pipeline;
   287     tvplayer->gst_source = source;
   288     tvplayer->gst_videodec = videodec;
   289     tvplayer->gst_videosink = videosink;
   290     g_object_ref (tvplayer->gst_pipeline);
   291     g_object_ref (tvplayer->gst_source);
   292     g_object_ref (tvplayer->gst_videodec);
   293     g_object_ref (tvplayer->gst_videosink);
   294 
   295     tvplayer->videoqueue = videoqueue;
   296     tvplayer->audioqueue = audioqueue;
   297     g_object_ref (tvplayer->videoqueue);
   298     g_object_ref (tvplayer->audioqueue);
   299    	
   300     g_object_set (G_OBJECT (videosink), "sync", TRUE, NULL);
   301     g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL);
   302 
   303     gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (tvplayer->gst_pipeline)),
   304                        bus_call, tvplayer);
   305 
   306     gst_bin_add_many (GST_BIN (pipeline), source, parser, videoqueue,
   307     			videodec, videosink, audioqueue, audiodec, audioconv, audiosink, NULL);
   308 
   309     {
   310 //        GstCaps *rtpcaps = gst_caps_new_simple ("application/x-rtp", NULL);
   311 //        gst_element_link_filtered(source, parser, rtpcaps);
   312     }
   313     
   314     gst_element_link (source, parser);
   315     gst_element_link_many (videoqueue, videodec, videosink, NULL);
   316     gst_element_link_many (audioqueue, audiodec, audioconv, audiosink, NULL);
   317     
   318     g_signal_connect (parser, "pad-added", G_CALLBACK (new_pad_cb), tvplayer);
   319     
   320     return TRUE;
   321 }
   322 
   323 /** Configures the backend and the tv player 
   324  * for playing the recorded content A/V.
   325  *
   326  * FIXME: Change filename to program info or other structure about the recorded
   327  *
   328  * @param tvplayer the object instance.
   329  * @param filename the file uri of the recorded content to be played.
   330  * @return TRUE if successfull, FALSE if any error happens.
   331  */
   332 gboolean
   333 mmyth_tvplayer_record_setup (MMythTVPlayer *tvplayer, gchar *filename)
   334 {
   335 	GMythSettings *msettings = gmyth_context_get_settings();
   336 	
   337 	// FIXME: we should receive the uri instead of filename
   338 	GString *hostname = gmyth_settings_get_backend_hostname (msettings);
   339 	int port = gmyth_settings_get_backend_port(msettings);
   340 	
   341 	GString *fullpath = g_string_new ("myth://");
   342 	g_string_append_printf (fullpath, "%s:%d/%s", hostname->str, port, filename);
   343 	
   344 	tvplayer->is_livetv = FALSE;
   345 
   346 	g_debug ("[%s] Setting record uri to gstreamer pipeline to %s", __FUNCTION__, fullpath->str);
   347 		
   348     g_object_set (G_OBJECT (tvplayer->gst_source), "location",
   349           fullpath->str, NULL);
   350           
   351     return TRUE;
   352 }
   353 
   354 /** Configures the backend and the tv player 
   355  * for playing the live tv.
   356  *
   357  * @param tvplayer the object instance.
   358  * @return TRUE if successfull, FALSE if any error happens.
   359  */
   360 gboolean
   361 mmyth_tvplayer_livetv_setup (MMythTVPlayer *tvplayer)
   362 {
   363 	GMythSettings *msettings = gmyth_context_get_settings ();
   364 	gboolean res = TRUE;
   365 
   366 	res = gmyth_context_check_connection();
   367 	if (!res) {
   368 		g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);	
   369 		res = FALSE;
   370 		goto error;
   371 	}
   372 
   373 	tvplayer->backend_hostname = gmyth_settings_get_backend_hostname(msettings);
   374 	tvplayer->backend_port = gmyth_settings_get_backend_port (msettings);
   375 
   376 	tvplayer->local_hostname  = g_string_new("");    
   377 	gmyth_context_get_local_hostname (tvplayer->local_hostname);
   378 
   379 	if ( tvplayer->local_hostname == NULL ) {
   380 		res = FALSE;
   381 		goto error;
   382 	}
   383 
   384 	// Gets the remote encoder num
   385 	tvplayer->remote_encoder = remote_request_next_free_recorder (-1);
   386 
   387 	if ( tvplayer->remote_encoder == NULL ) {
   388 		g_warning ("[%s] None remote encoder available", __FUNCTION__);
   389 		res = FALSE;
   390 		goto error;
   391 	}
   392 
   393 	// Creates livetv chain handler
   394 	tvplayer->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) );
   395 	gmyth_tvchain_initialize ( tvplayer->tvchain, tvplayer->local_hostname );
   396 
   397 	if ( tvplayer->tvchain == NULL || tvplayer->tvchain->tvchain_id == NULL ) {
   398 		res = FALSE;
   399 		goto error;
   400 	}
   401 
   402 	// Init remote encoder. Opens its control socket.
   403 	res = gmyth_remote_encoder_setup(tvplayer->remote_encoder);
   404 	if ( !res ) {
   405 		g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
   406 		res = FALSE;
   407 		goto error;
   408 	}
   409 	// Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
   410 	res = gmyth_remote_encoder_spawntv ( tvplayer->remote_encoder,
   411 			gmyth_tvchain_get_id(tvplayer->tvchain) );
   412 	if (!res) {
   413 		g_warning ("[%s] Fail while spawn tv\n", __FUNCTION__);
   414 		res = FALSE;
   415 		goto error;
   416 	}
   417 
   418 	// Reload all TV chain from Mysql database.
   419 	gmyth_tvchain_reload_all (tvplayer->tvchain);
   420 
   421 	if ( tvplayer->tvchain == NULL ) {
   422 		res = FALSE;
   423 		goto error;
   424 	}
   425 
   426 	// Get program info from database using chanid and starttime
   427 	tvplayer->proginfo = gmyth_tvchain_get_program_at (tvplayer->tvchain, -1);
   428 	if ( tvplayer->proginfo == NULL ) {
   429 		g_warning ("[%s] LiveTV not successfully started.\n", __FUNCTION__ );
   430 		res = FALSE;
   431 		goto error;
   432 	} else {
   433 		g_debug ("[%s] MythLiveTV: All requests to backend to start TV were OK.\n", __FUNCTION__ );
   434 	}
   435 
   436 	return res;
   437 
   438 error:
   439 	if ( tvplayer->backend_hostname != NULL ) {
   440 		g_string_free( tvplayer->backend_hostname, TRUE );
   441 		res = FALSE;
   442 	}
   443 
   444 	if ( tvplayer->local_hostname != NULL ) {
   445 		g_string_free( tvplayer->local_hostname, TRUE );
   446 		res = FALSE;
   447 	}
   448 
   449 	if ( tvplayer->remote_encoder != NULL ) {
   450 		g_object_unref (tvplayer->remote_encoder);
   451 		tvplayer->remote_encoder = NULL;
   452 	}
   453 
   454 	if ( tvplayer->tvchain != NULL ) {
   455 		g_object_unref (tvplayer->tvchain);
   456 		tvplayer->tvchain = NULL;
   457 	}
   458 
   459 	if ( tvplayer->proginfo != NULL ) {
   460 		g_object_unref (tvplayer->proginfo);
   461 		tvplayer->proginfo = NULL;
   462 	}
   463 
   464 	return res;
   465 
   466 }
   467 
   468 /** Sets the GTK video widget for the tv player. 
   469  *
   470  * @param tvplayer the object instance.
   471  * @param videow the GTK video window.
   472  * @return TRUE if successfull, FALSE if any error happens.
   473  */
   474 gboolean
   475 mmyth_tvplayer_set_widget (MMythTVPlayer *tvplayer, GtkWidget *videow)
   476 {
   477 	tvplayer->videow = videow;
   478 	g_object_ref (videow);
   479 	
   480 	g_debug ("[%s] Setting widget for tv player render", __FUNCTION__);
   481 	
   482     tvplayer->expose_handler = g_signal_connect (tvplayer->videow, "expose-event", 
   483                                                  G_CALLBACK (expose_cb), tvplayer);
   484 
   485     //g_signal_connect(miptv_ui->videow, "size_request", G_CALLBACK(cb_preferred_video_size), miptv_ui);
   486 
   487     return TRUE;
   488 }
   489 
   490 static gboolean
   491 bus_call (GstBus * bus, GstMessage * msg, gpointer data)
   492 {
   493     //MMythTVPlayer *tvplayer = MMYTH_TVPLAYER ( data );
   494     //GMainLoop *loop = tvplayer->loop;
   495 
   496     switch (GST_MESSAGE_TYPE (msg)) {
   497         case GST_MESSAGE_EOS:
   498 			printf ("End of stream\n");
   499             //g_idle_add ((GSourceFunc) idle_eos, data);
   500             gst_element_set_state ( GST_ELEMENT (GST_MESSAGE_SRC (msg)), GST_STATE_NULL );
   501 	    gst_element_set_locked_state ( GST_ELEMENT (GST_MESSAGE_SRC (msg)), TRUE );
   502             break;
   503         case GST_MESSAGE_ERROR:
   504         {
   505                 gchar *debug;
   506                 GError *err;
   507 
   508                 gst_message_parse_error (msg, &err, &debug);
   509                 g_free (debug);
   510 
   511                 printf ("Error: %s\n", err->message);
   512                 g_error_free (err);
   513 
   514                 //g_main_loop_quit (loop);
   515         }
   516             break;
   517         default:
   518             printf (gst_message_type_get_name (GST_MESSAGE_TYPE (msg)));
   519             printf ("\n");
   520             break;
   521     }
   522 
   523     return TRUE;
   524 }
   525 
   526 
   527 #if 0
   528 static gboolean
   529 idle_state (gpointer data)
   530 {
   531     GstPlayerWindowStateChange *st = data;
   532 
   533     if (st->old_state == GST_STATE_PLAYING) {
   534         if (st->miptv_ui->idle_id != 0) {
   535             g_source_remove (st->miptv_ui->idle_id);
   536             st->miptv_ui->idle_id = 0;
   537         }
   538     }
   539     else if (st->new_state == GST_STATE_PLAYING) {
   540         if (st->miptv_ui->idle_id != 0)
   541             g_source_remove (st->miptv_ui->idle_id);
   542 
   543         st->miptv_ui->idle_id = g_idle_add (cb_iterate, st->miptv_ui);
   544     }
   545 
   546     /* new movie loaded? */
   547     if (st->old_state == GST_STATE_READY && st->new_state > GST_STATE_READY) {
   548 
   549         /* gboolean have_video = FALSE; */
   550 
   551         gtk_widget_show (st->miptv_ui->videow);
   552 
   553         gtk_window_resize (GTK_WINDOW (st->miptv_ui->main_window), 1, 1);
   554 
   555     }
   556 
   557     /* discarded movie? */
   558     if (st->old_state > GST_STATE_READY && st->new_state == GST_STATE_READY) {
   559 
   560         if (st->miptv_ui->tagcache) {
   561             gst_tag_list_free (st->miptv_ui->tagcache);
   562             st->miptv_ui->tagcache = NULL;
   563         }
   564     }
   565 
   566     gst_object_unref (GST_OBJECT (st->play));
   567     //g_object_unref (G_OBJECT (st->win));
   568     g_free (st);
   569 
   570     /* once */
   571     return FALSE;
   572 }
   573 
   574 #endif
   575 
   576 /** Stops playing the current A/V.
   577  *
   578  * FIXME: How to proceed differently between livetv 
   579  * and recorded content?
   580  *
   581  * @param tvplayer the object instance.
   582  * @return void 
   583  */
   584 void
   585 mmyth_tvplayer_stop_playing (MMythTVPlayer *tvplayer) 
   586 {
   587     g_debug ("[%s] Setting gstreamer pipeline state to NULL", __FUNCTION__);
   588 
   589     gst_element_set_state (tvplayer->gst_pipeline, GST_STATE_NULL);
   590     
   591     if (tvplayer->is_livetv) {
   592 	    if (!gmyth_remote_encoder_stop_livetv (tvplayer->remote_encoder)) {
   593 	    	g_warning ("[%s] Error while stoping remote encoder", __FUNCTION__);	
   594 	    }
   595     }
   596 }
   597 
   598 /** Queries if the tvplayer is active playing A/V content.
   599  *
   600  * @param tvplayer the object instance.
   601  * @return TRUE if the tvplayer is active, FALSE otherwise.
   602  */
   603 gboolean
   604 mmyth_tvplayer_is_playing (MMythTVPlayer *tvplayer)
   605 {
   606 	return (GST_STATE (tvplayer->gst_pipeline) == GST_STATE_PLAYING);
   607 }
   608 
   609 /** Static function that sets the tvplayer state to PLAYING.
   610  *
   611  * @param tvplayer the object instance.
   612  * @return TRUE if the tvplayer is active, FALSE otherwise.
   613  */
   614 static gboolean
   615 idle_play (gpointer data)
   616 {
   617     MMythTVPlayer *tvplayer = MMYTH_TVPLAYER (data);
   618 
   619 	g_debug ("MMythTVPlayer: Setting pipeline state to PLAYING\n");
   620 
   621     gst_element_set_state (tvplayer->gst_pipeline, GST_STATE_PLAYING);
   622 
   623     return FALSE;
   624 }
   625 
   626 /** Start playing A/V with the tvplayer attributes.
   627  *
   628  * @param tvplayer the object instance.
   629  */
   630 void
   631 mmyth_tvplayer_start_playing (MMythTVPlayer *tvplayer)
   632 {
   633 
   634 	// FIXME: Move this to livetv_setup??
   635 	if (tvplayer->is_livetv) {
   636 
   637 	#if 0
   638 		if (!tvplayer || !(tvplayer->proginfo) || !(tvplayer->local_hostname)
   639 				|| !(tvplayer->gst_source)) {
   640 			g_warning ("GMythtvPlayer not ready to start playing\n");		
   641 		}
   642 
   643 		if (!(tvplayer->proginfo->pathname)) {
   644 			g_warning ("[%s] Playback url is null, could not play the myth content", __FUNCTION__);
   645 			return;
   646 		}
   647 
   648 		g_debug ("MMythTVPlayer: Start playing %s", tvplayer->proginfo->pathname->str);
   649 #endif
   650 		g_object_set (G_OBJECT (tvplayer->gst_source), "mythtv-live",
   651 				TRUE, NULL);
   652 #if 0
   653 		if ( tvplayer->tvchain != NULL ) {
   654 			GString *str_chainid = gmyth_tvchain_get_id(tvplayer->tvchain);
   655 			g_print( "[%s]\tCHAIN ID: %s\n", __FUNCTION__, str_chainid->str );
   656 
   657 			g_object_set (G_OBJECT (tvplayer->gst_source), "mythtv-live-chainid", 
   658 					g_strdup( str_chainid->str ), NULL);      
   659 			if ( str_chainid!=NULL)
   660 				g_string_free( str_chainid, FALSE );
   661 		}
   662 
   663 		if ( tvplayer->remote_encoder != NULL )	
   664 			g_object_set (G_OBJECT (tvplayer->gst_source), "mythtv-live-id",
   665 					tvplayer->remote_encoder->recorder_num, NULL );
   666 		g_debug ("[%s] Setting location to %s", __FUNCTION__, 
   667 				tvplayer->proginfo->pathname->str);
   668 
   669 		/* Sets the gstreamer properties acording to the service access address */
   670 		g_object_set (G_OBJECT (tvplayer->gst_source), "location",
   671 				tvplayer->proginfo->pathname->str, NULL);              
   672 #endif
   673 	}
   674 
   675 	g_object_set (G_OBJECT (tvplayer->gst_source), "mythtv-version",
   676               MYTHTV_VERSION_DEFAULT, NULL);
   677 
   678     g_object_set (G_OBJECT (tvplayer->gst_source), "mythtv-debug",
   679               TRUE, NULL);
   680 
   681     g_idle_add (idle_play, tvplayer);
   682 
   683 }
   684