gst-plugins-mythtv/src/gstmythtvsrc.c
author rosfran
Mon Nov 06 22:50:41 2006 +0000 (2006-11-06)
branchtrunk
changeset 67 0ae13d61ffd3
parent 61 dedcca2fe529
child 70 4ba74b706853
permissions -rwxr-xr-x
[svn r68] Added channel change functions.
     1 /* vim: set sw=2: -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2; c-indent-level: 2 -*- */
     2 /* GStreamer MythTV Plug-in
     3  * Copyright (C) <2006> Rosfran Borges <rosfran.borges@indt.org.br>
     4  *
     5  * This library is free software; you can redistribute it and/or
     6  * modify it under the terms of the GNU Library Lesser General 
     7  * Public License as published by the Free Software Foundation; either
     8  * version 2 of the License, or (at your option) any later version.
     9  *
    10  * This library is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13  * Library General Public License for more 
    14  */
    15 
    16 #ifdef HAVE_CONFIG_H
    17 #include "config.h"
    18 #endif
    19 
    20 #include "gstmythtvsrc.h"
    21 #include <gmyth/gmyth_file_transfer.h>
    22 #include <gmyth/gmyth_livetv.h>
    23 
    24 #include <gmyth/gmyth_socket.h>
    25 #include <gmyth/gmyth_tvchain.h>
    26 
    27 #include <string.h>
    28 #include <unistd.h>
    29 
    30 GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
    31 #define GST_CAT_DEFAULT mythtvsrc_debug
    32 
    33 #define GST_GMYTHTV_ID_NUM		1
    34 
    35 #define GMYTHTV_VERSION_DEFAULT			30
    36  
    37 #define GMYTHTV_TRANSFER_MAX_WAITS	100
    38 
    39 #define GMYTHTV_TRANSFER_MAX_BUFFER	80*1024
    40 //( 32*1024  )
    41 
    42 /* 4*1024 ??? */
    43 #define MAX_READ_SIZE              	12*1024
    44 //( 32*1024 )
    45 
    46 /* stablish a maximum iteration value to the IS_RECORDING message */
    47 static guint wait_to_transfer = 0;
    48 
    49 static const GstElementDetails gst_mythtv_src_details =
    50 GST_ELEMENT_DETAILS ( "MythTV client source",
    51     "Source/Network",
    52     "Control and receive data as a client over the network via raw socket connections using the MythTV protocol",
    53     "Rosfran Borges <rosfran.borges@indt.org.br>" );
    54 
    55 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
    56     GST_PAD_SRC,
    57     GST_PAD_ALWAYS,
    58     GST_STATIC_CAPS ("video/x-nuv") );
    59 
    60 static GStaticMutex update_size_mutex = G_STATIC_MUTEX_INIT;
    61 
    62 enum
    63 {
    64   PROP_0,
    65   PROP_LOCATION,
    66   PROP_URI,
    67 #ifndef GST_DISABLE_GST_DEBUG
    68   PROP_GMYTHTV_DBG,
    69 #endif
    70   PROP_GMYTHTV_VERSION,
    71   PROP_GMYTHTV_LIVE,
    72   PROP_GMYTHTV_LIVEID,
    73   PROP_GMYTHTV_LIVE_CHAINID,
    74   PROP_GMYTHTV_ENABLE_TIMING_POSITION
    75 };
    76 
    77 static void gst_mythtv_src_finalize (GObject * gobject);
    78 
    79 static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset, 
    80 	guint size, GstBuffer ** outbuf);
    81 
    82 static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
    83 static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
    84 static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
    85 static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src );
    86 
    87 static gboolean gst_mythtv_src_next_program_chain ( GstMythtvSrc *src );
    88 
    89 static GstStateChangeReturn
    90 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
    91 
    92 static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
    93     const GValue * value, GParamSpec * pspec);
    94 static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
    95     GValue * value, GParamSpec * pspec);
    96 
    97 static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
    98 
    99 static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
   100 //static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query );
   101 
   102 static gint do_read_request_response (GstMythtvSrc *src, guint64 offset, 
   103 		guint size, GstBuffer **outbuf);
   104 //static gboolean gst_mythtv_src_sink_activate_pull (GstPad * srcpad, gboolean active);
   105 
   106 static void
   107 _urihandler_init (GType type)
   108 {
   109   static const GInterfaceInfo urihandler_info = {
   110     gst_mythtv_src_uri_handler_init,
   111     NULL,
   112     NULL
   113   };
   114 
   115   g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
   116 
   117   GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
   118       "MythTV src");
   119 }
   120 
   121 GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
   122     GST_TYPE_BASE_SRC, _urihandler_init)
   123     
   124 //GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
   125 //    GST_TYPE_PUSH_SRC, _urihandler_init)
   126     
   127   static void
   128 gst_mythtv_src_base_init (gpointer g_class)
   129 {
   130   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
   131 
   132   gst_element_class_add_pad_template (element_class,
   133       gst_static_pad_template_get (&srctemplate));
   134 
   135   gst_element_class_set_details (element_class, &gst_mythtv_src_details);
   136   
   137   element_class->change_state = gst_mythtv_src_change_state;
   138 }
   139 
   140 static void
   141 gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
   142 {
   143   GObjectClass *gobject_class; 
   144   //GstPushSrcClass *gstpushsrc_class;
   145   GstBaseSrcClass *gstbasesrc_class;
   146 
   147   gobject_class = (GObjectClass *) klass;
   148   gstbasesrc_class = (GstBaseSrcClass *) klass;
   149 
   150   gobject_class->set_property = gst_mythtv_src_set_property;
   151   gobject_class->get_property = gst_mythtv_src_get_property;
   152   gobject_class->finalize = gst_mythtv_src_finalize;
   153 
   154   g_object_class_install_property
   155     (gobject_class, PROP_LOCATION,
   156      g_param_spec_string ("location", "Location",
   157        "The location. In the form:"
   158        "\n\t\t\tmyth://a.com/file.nuv"
   159        "\n\t\t\tmyth://a.com:23223/file.nuv "
   160        "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
   161        "", G_PARAM_READWRITE));
   162 
   163   g_object_class_install_property
   164     (gobject_class, PROP_URI,
   165      g_param_spec_string ("uri", "Uri",
   166        "The location in form of a URI (deprecated; use location)",
   167        "", G_PARAM_READWRITE));
   168 
   169   g_object_class_install_property
   170     (gobject_class, PROP_GMYTHTV_VERSION,
   171      g_param_spec_int ("mythtv-version", "mythtv-version",
   172        "Change Myth TV version",
   173        26, 30, 26, G_PARAM_READWRITE));
   174 
   175   g_object_class_install_property
   176     (gobject_class, PROP_GMYTHTV_LIVEID,
   177      g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
   178        "Change Myth TV version",
   179        0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
   180 
   181   g_object_class_install_property
   182     (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
   183      g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
   184        "Sets the Myth TV chain ID (from TV Chain)",
   185        "", G_PARAM_READWRITE));
   186 
   187   g_object_class_install_property
   188     (gobject_class, PROP_GMYTHTV_LIVE,
   189      g_param_spec_boolean ("mythtv-live", "mythtv-live",
   190        "Enable MythTV Live TV content streaming",
   191        FALSE, G_PARAM_READWRITE));
   192 
   193   g_object_class_install_property
   194     (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
   195      g_param_spec_boolean ("mythtv-enable-timing-position", "mythtv-enable-timing-position",
   196        "Enable MythTV Live TV content size continuous updating",
   197        FALSE, G_PARAM_READWRITE));
   198 
   199 #ifndef GST_DISABLE_GST_DEBUG
   200   g_object_class_install_property
   201     (gobject_class, PROP_GMYTHTV_DBG,
   202      g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
   203        "Enable MythTV debug messages",
   204        FALSE, G_PARAM_READWRITE));
   205 #endif
   206 
   207   gstbasesrc_class->start = gst_mythtv_src_start;
   208   gstbasesrc_class->stop = gst_mythtv_src_stop;
   209   gstbasesrc_class->get_size = gst_mythtv_src_get_size;
   210   gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
   211 
   212   gstbasesrc_class->create = gst_mythtv_src_create;
   213     
   214   GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
   215       "MythTV Client Source");
   216 }
   217 
   218 static void
   219 gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
   220 {
   221   this->file_transfer = NULL;
   222 
   223   this->unique_setup = FALSE;
   224 
   225   this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
   226 
   227   this->bytes_read = 0;
   228   
   229   this->prev_content_size = 0;
   230 
   231   this->content_size = 0;
   232   this->read_offset = 0;
   233 
   234   this->content_size_last = 0;
   235 
   236   this->live_tv = FALSE;
   237   
   238   this->enable_timing_position = FALSE;
   239   this->update_prog_chain = FALSE;    
   240 
   241   this->user_agent = g_strdup ("mythtvsrc");
   242   this->mythtv_caps = NULL;
   243   this->update_prog_chain = FALSE;
   244   
   245   this->eos = FALSE;
   246   
   247   gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES );  
   248 
   249   gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE );
   250 
   251   gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
   252       gst_mythtv_src_handle_event );
   253 /*
   254   gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
   255       gst_mythtv_src_query );
   256 */
   257 
   258 }
   259 
   260 static void
   261 gst_mythtv_src_finalize (GObject * gobject)
   262 {
   263   GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
   264 
   265   if (this->mythtv_caps) {
   266     gst_caps_unref (this->mythtv_caps);
   267     this->mythtv_caps = NULL;
   268   }
   269 
   270   if (this->file_transfer) {
   271     g_object_unref (this->file_transfer);
   272     this->file_transfer = NULL;
   273   }
   274 
   275 	if (this->spawn_livetv) {
   276     //g_object_unref (this->spawn_livetv);
   277     this->spawn_livetv = NULL;
   278   }
   279 
   280   if (this->uri_name) {
   281     g_free (this->uri_name);
   282   }
   283 
   284   if (this->user_agent) {
   285     g_free (this->user_agent);
   286   }
   287 
   288   G_OBJECT_CLASS (parent_class)->finalize (gobject);
   289 }
   290 
   291 static gint
   292 do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, GstBuffer **outbuf)
   293 {
   294   gint read = 0;
   295   guint sizetoread = size;
   296 
   297   g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread ); 
   298 
   299   /* Loop sending the Myth File Transfer request:
   300    * Retry whilst authentication fails and we supply it. */
   301   gint len = 0;
   302 
   303   GST_OBJECT_LOCK(src);
   304 
   305   while ( sizetoread > 0 ) {
   306 
   307     len = gmyth_file_transfer_read( src->file_transfer,
   308 	GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE );
   309 
   310     if ( len > 0 ) {
   311       read += len;      
   312       sizetoread -= len;
   313     } 
   314     else if ( len <= 0 ) 
   315     {
   316 
   317       if ( src->live_tv == FALSE ) 
   318       {
   319 	goto eos;
   320       } 
   321       else  
   322       {
   323 	if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
   324 	  src->update_prog_chain = TRUE;
   325 	  if ( gst_mythtv_src_next_program_chain ( src ) )
   326 	    continue;
   327 	  else
   328 	    goto eos;	  	
   329 	} else 
   330 	  if ( abs( src->content_size - src->prev_content_size ) < GMYTHTV_TRANSFER_MAX_BUFFER )  {
   331 	    src->update_prog_chain = TRUE;
   332 	    if ( src->enable_timing_position ) {
   333 	      gint64 size_tmp = 0;
   334 	      if (src->live_tv == TRUE) {
   335 get_file_pos:
   336 		size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   337 		if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   338 		  src->content_size = size_tmp;
   339 		else if ( size_tmp > 0 )
   340 		  goto get_file_pos;
   341 		g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   342 		    __FUNCTION__, size_tmp );
   343 	      }
   344 	    } else if ( abs( src->content_size - src->prev_content_size ) < GMYTHTV_TRANSFER_MAX_BUFFER ) {
   345 	      src->prev_content_size = src->content_size;
   346 	      gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
   347 	      if ( new_offset > 0 ) {
   348 		if ( src->content_size < new_offset ) {
   349 		  src->content_size = new_offset;
   350 		}
   351 	      } else {
   352 		src->update_prog_chain = TRUE;
   353 	      }
   354 	    }
   355 	    goto done;
   356 	  }
   357 	  goto done;
   358       }
   359 
   360     }
   361 
   362     if ( read == sizetoread )
   363       break;
   364   }
   365 
   366   if ( read > 0 ) {
   367     src->read_offset += read;
   368     src->bytes_read += read;
   369 
   370     g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
   371 	"OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, 
   372 	src->read_offset, src->content_size );
   373 
   374     GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
   375     GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
   376     GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
   377 
   378     g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
   379 	"OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), 
   380 	GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
   381 
   382   } else if ( !src->live_tv )
   383     goto eos;
   384 
   385   goto done;
   386 
   387 eos:
   388   src->eos = TRUE;
   389 
   390 done:
   391   GST_OBJECT_UNLOCK(src);
   392 
   393   return read;
   394 }
   395 
   396 static GstFlowReturn
   397 gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf)
   398 {
   399   GstMythtvSrc *src;
   400   GstFlowReturn ret = GST_FLOW_OK;
   401   gint read = -1;
   402   
   403   src = GST_MYTHTV_SRC (psrc);
   404   /* The caller should know the number of bytes and not read beyond EOS. */
   405   if (G_UNLIKELY (src->eos))
   406     goto eos;
   407   if ( G_UNLIKELY (src->update_prog_chain) )
   408     goto change_progchain;
   409   
   410   GST_OBJECT_LOCK(src);
   411 
   412   if (G_UNLIKELY (src->read_offset != offset)) {
   413     gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset - src->content_size_last, SEEK_SET);
   414     g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
   415     	__FUNCTION__, src->read_offset, new_offset );
   416     if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) {
   417     {
   418       GST_OBJECT_UNLOCK(src);
   419       if ( src->live_tv )
   420       	goto change_progchain;
   421       else
   422       	goto eos;
   423     }
   424 
   425     src->read_offset = offset;
   426   }
   427   GST_OBJECT_UNLOCK(src);
   428   
   429   /* Create the buffer. */
   430   ret = gst_pad_alloc_buffer (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
   431       src->read_offset, size,
   432       //src->icy_caps ? src->icy_caps :
   433       GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf);
   434 
   435   if (G_UNLIKELY (ret != GST_FLOW_OK))
   436     goto done;
   437   
   438   read = do_read_request_response ( src, src->read_offset, size, outbuf );
   439 
   440   if (G_UNLIKELY (src->update_prog_chain) )
   441     goto change_progchain;
   442 
   443   if (G_UNLIKELY (read <= 0) || *outbuf == NULL) {
   444   	if ( src->live_tv )
   445     	goto change_progchain;
   446     else
   447     	goto read_error;
   448   }
   449 
   450 done:
   451  {
   452     const gchar *reason = gst_flow_get_name (ret);
   453 
   454     GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
   455   	return ret;
   456  }
   457 eos:
   458   {
   459     const gchar *reason = gst_flow_get_name (ret);
   460 
   461     GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
   462     return GST_FLOW_UNEXPECTED;
   463   }
   464   /* ERRORS */
   465 read_error:
   466   {
   467     GST_ELEMENT_ERROR (src, RESOURCE, READ,
   468 	(NULL), ("Could not read any bytes (%i, %s)", read,
   469 	  src->uri_name));
   470     return GST_FLOW_ERROR;
   471   }
   472 change_progchain:
   473   {
   474     GST_ELEMENT_ERROR (src, RESOURCE, READ,
   475 		(NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
   476 		  src->uri_name));
   477 		// go to the next program chain
   478 		src->unique_setup = FALSE;
   479 		src->update_prog_chain = TRUE;
   480 		//gst_mythtv_src_next_program_chain( src );  
   481     return -101;
   482   }
   483 
   484 }
   485 
   486 void
   487 update_size_func( void *mythtv_data ) 
   488 {
   489   GstMythtvSrc *src;
   490 
   491   g_return_if_fail( mythtv_data != NULL );
   492 
   493   src = GST_MYTHTV_SRC ( mythtv_data );
   494 
   495   g_static_mutex_lock( &update_size_mutex );
   496 
   497   if ( src->do_start ) {
   498     if ( src->enable_timing_position ) {
   499       gint64 size_tmp = 0;
   500       if (src->live_tv == TRUE) {
   501 get_file_pos:
   502 	g_usleep( 50 );
   503 	size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   504 	if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   505 	  src->content_size = size_tmp;
   506 	else if ( size_tmp > 0 )
   507 	  goto get_file_pos;
   508 	g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   509 	    __FUNCTION__, size_tmp );
   510       }
   511     }
   512   }
   513   g_static_mutex_unlock( &update_size_mutex );
   514 
   515 }
   516 
   517 gint64
   518 gst_mythtv_src_get_position ( GstMythtvSrc* src ) 
   519 {
   520 
   521   gint64 size_tmp = 0;
   522   guint max_tries = 3;
   523   if (src->live_tv == TRUE && ( abs( src->content_size - src->prev_content_size ) < 
   524 	GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
   525     /* sets the last content size amount before it can be updated */
   526     src->prev_content_size = src->content_size;
   527 get_file_pos:
   528     g_usleep( 10 );
   529     size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   530     if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   531       src->content_size = size_tmp;
   532     else if ( size_tmp > 0 && --max_tries > 0 )
   533       goto get_file_pos;
   534     g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   535 	__FUNCTION__, size_tmp );
   536   }
   537 
   538   return src->content_size;	
   539 
   540 }
   541 
   542 /* create a socket for connecting to remote server */
   543 static gboolean
   544 gst_mythtv_src_start ( GstBaseSrc * bsrc )
   545 {
   546   GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
   547 
   548   GString *chain_id_local = NULL;
   549 
   550   gboolean ret = TRUE;
   551   
   552   if ( !src->do_start )
   553   	goto done;
   554 
   555   if (src->unique_setup == FALSE) {
   556     src->unique_setup = TRUE;
   557   } else {
   558     goto done;
   559   }
   560 
   561   GST_OBJECT_LOCK(src);
   562 
   563   if ( src->live_tv ) {
   564     src->spawn_livetv = gmyth_livetv_new( );
   565     if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) {
   566       ret = FALSE;
   567       GST_OBJECT_UNLOCK( src );
   568       goto init_failed;
   569     }
   570 
   571     /* set up the uri variable */
   572     src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
   573     chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
   574     if ( chain_id_local != NULL ) {
   575       src->live_chain_id = g_strdup( chain_id_local->str );
   576       g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
   577     }
   578     src->live_tv_id = src->spawn_livetv->remote_encoder->recorder_num;
   579     g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
   580   }
   581 
   582   src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, 
   583       g_string_new( src->uri_name ), -1, src->mythtv_version );
   584 
   585   if ( src->file_transfer == NULL ) {
   586     GST_OBJECT_UNLOCK(src);
   587 
   588     goto init_failed;
   589   }
   590 
   591   /* sets the Playback monitor connection */
   592   ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
   593 
   594   if ( src->live_tv == TRUE && ret == TRUE ) {
   595     /* loop finished, set the max tries variable to zero again... */
   596     wait_to_transfer = 0;
   597 
   598     while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE 
   599 	  /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
   600       g_usleep( 100 );
   601   }
   602 
   603   /* sets the FileTransfer instance connection (video/audio download) */
   604   ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
   605 
   606   if ( ret == FALSE ) {
   607     GST_OBJECT_UNLOCK(src);
   608 #ifndef GST_DISABLE_GST_DEBUG  
   609     if ( src->mythtv_msgs_dbg )
   610       g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );  	  
   611 #endif
   612     goto begin_req_failed;
   613   }
   614 
   615   src->content_size = src->file_transfer->filesize;
   616 
   617   GST_OBJECT_UNLOCK(src);
   618 
   619   src->do_start = FALSE;
   620 
   621 done:
   622   return TRUE;
   623 
   624   /* ERRORS */
   625 init_failed:
   626   {
   627     if (src->spawn_livetv != NULL )
   628       g_object_unref( src->spawn_livetv );
   629 
   630     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   631 	(NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
   632     return FALSE;
   633   }
   634 begin_req_failed:
   635   {
   636     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   637 	(NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
   638     return FALSE;
   639   }
   640 }
   641 
   642 /* create a new socket for connecting to the next program chain */
   643 static gboolean
   644 gst_mythtv_src_next_program_chain ( GstMythtvSrc *src )
   645 {
   646   GString *chain_id_local = NULL;
   647 
   648   gboolean ret = TRUE;
   649 
   650   if ( !src->live_tv )
   651     goto init_failed;
   652 
   653   src->update_prog_chain = FALSE;
   654 
   655   if (src->file_transfer) {
   656     g_object_unref (src->file_transfer);
   657     src->file_transfer = NULL;
   658   }
   659 
   660   if (src->uri_name) {
   661     g_free (src->uri_name);
   662   }
   663 
   664   if ( src->live_tv ) {
   665     if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) {
   666       ret = FALSE;
   667       goto init_failed;
   668     }
   669     /* set up the uri variable */
   670     src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
   671     chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
   672     if ( chain_id_local != NULL ) {
   673       src->live_chain_id = g_strdup( chain_id_local->str );
   674       g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
   675     }
   676     src->live_tv_id = src->spawn_livetv->remote_encoder->recorder_num;
   677     g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
   678   }
   679 
   680   src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, 
   681       g_string_new( src->uri_name ), -1, src->mythtv_version );
   682 
   683   if ( src->file_transfer == NULL ) {
   684     goto init_failed;
   685   }
   686 
   687   /* sets the Playback monitor connection */
   688   ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
   689 
   690   if ( src->live_tv == TRUE && ret == TRUE ) {
   691     /* loop finished, set the max tries variable to zero again... */
   692     wait_to_transfer = 0;
   693 
   694     g_usleep( 200 );
   695 
   696     while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && 
   697 	( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) )
   698       g_usleep( 1000 );
   699   }
   700 
   701   /* sets the FileTransfer instance connection (video/audio download) */
   702   ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
   703 
   704   if ( ret == FALSE ) {
   705 #ifndef GST_DISABLE_GST_DEBUG  
   706     if ( src->mythtv_msgs_dbg )
   707       g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );  	  
   708 #endif
   709     goto begin_req_failed;
   710   }
   711   src->content_size_last = src->content_size;
   712 
   713 #if 0
   714   if ( src->content_size < src->file_transfer->filesize ) {
   715     src->content_size = src->file_transfer->filesize;
   716   } else {
   717     //gint64 pos = gst_mythtv_src_get_position(src);
   718     //if ( pos > src->file_transfer->filesize )
   719     //	src->content_size = pos;  	
   720 
   721   }
   722 #endif
   723 
   724   src->content_size = src->file_transfer->filesize;
   725   while (  src->content_size < GMYTHTV_TRANSFER_MAX_BUFFER )
   726     src->content_size = gst_mythtv_src_get_position( src );
   727 
   728   //src->read_offset = 0;
   729 
   730   //src->update_prog_chain = FALSE;
   731 
   732   return TRUE;
   733 
   734   /* ERRORS */
   735 init_failed:
   736   {
   737     if (src->spawn_livetv != NULL )
   738       g_object_unref( src->spawn_livetv );
   739 
   740     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   741 	(NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
   742     return FALSE;
   743   }
   744 begin_req_failed:
   745   {
   746     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   747 	(NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
   748     return FALSE;
   749   }
   750 
   751 }
   752 
   753 #if 0
   754 /* handles queries for location in the stream in the requested format */
   755 static gboolean
   756 gst_mythtv_src_query ( GstPad * pad, GstQuery * query )
   757 {
   758   gboolean res = TRUE;
   759   GstMythtvSrc *mythtv;
   760 
   761   guint64 size = 0;
   762 
   763   mythtv = GST_GMYTHTV_SRC( GST_PAD_PARENT (pad) );
   764 
   765   size = gst_mythtv_src_get_position (mythtv);
   766 
   767   switch (GST_QUERY_TYPE (query)) {
   768 
   769     case GST_QUERY_POSITION:
   770       {
   771 
   772 	//GstFormat format;
   773 	gint64 cur = 0;
   774 
   775 	/* save requested format */
   776 	gst_query_parse_position (query, NULL, &cur);
   777 
   778 	/* query peer for current position in time */
   779 	g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__, 
   780 	    ( size > cur ) ? "greater" : "lower", size, cur );
   781 	gst_query_set_position (query, GST_FORMAT_BYTES, size);
   782 	if ( size < cur )
   783 	  goto error;
   784 
   785 	break;
   786       }
   787      #if 0
   788     case GST_QUERY_DURATION:
   789       {
   790 	//GstFormat format;
   791 	gint64 cur = 0;
   792 
   793 	/* save requested format */
   794 	gst_query_parse_position (query, NULL, &cur);
   795 
   796 	/* query peer for current position in time */
   797 	g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__, 
   798 	    ( size * GST_SECOND > cur * GST_SECOND ) ? "greater" : "lower", size * GST_SECOND, 
   799 	    cur * GST_SECOND );
   800 	gst_query_set_position (query, GST_FORMAT_TIME, size * GST_SECOND );
   801 
   802 	if ( size * GST_SECOND < cur * GST_SECOND )
   803 	  goto error;
   804 
   805 	break;
   806       }
   807 	#endif
   808     default:
   809       res = FALSE;
   810       break;
   811   }
   812 
   813   return res;
   814 
   815 error:
   816 
   817   return FALSE;
   818 }
   819 #endif
   820 
   821 static gboolean
   822 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
   823 {
   824   GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
   825   gboolean ret = TRUE;
   826   g_print( "[%s] Difference from previous content size: %d (max.: %d)\n", __FUNCTION__, 
   827   			abs( src->content_size - src->prev_content_size ), GMYTHTV_TRANSFER_MAX_BUFFER );
   828 
   829   if (src->content_size <= 0) {
   830     ret= FALSE;
   831   } else if ( src->live_tv && ( abs( src->content_size - src->bytes_read ) < 
   832 	GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
   833     //g_static_mutex_lock( &update_size_mutex );
   834     //GST_OBJECT_LOCK(src);
   835     src->prev_content_size = src->content_size;
   836     gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
   837     if ( new_offset > 0 ) {
   838       if ( src->content_size < new_offset ) {
   839 	src->content_size = new_offset;
   840       }
   841     } else {
   842       if ( src->live_tv )
   843 	src->update_prog_chain = TRUE;
   844     }
   845 
   846     if ( src->enable_timing_position ) {
   847       gint64 size_tmp = 0;
   848       if (src->live_tv == TRUE) {
   849 get_file_pos:
   850 	g_usleep( 5 );
   851 	size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   852 	if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   853 	  src->content_size = size_tmp;
   854 	else if ( size_tmp > 0  )
   855 	  goto get_file_pos;
   856 	g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   857 	    __FUNCTION__, size_tmp );
   858       }
   859     }
   860     //GST_OBJECT_UNLOCK(src);
   861     //g_static_mutex_unlock( &update_size_mutex );
   862   }
   863 
   864   *size = src->content_size;
   865   g_print( "[%s] Content size = %lld\n", __FUNCTION__, src->content_size );
   866 
   867   return ret;
   868 
   869 }
   870 
   871 /* close the socket and associated resources
   872  * used both to recover from errors and go to NULL state */
   873 static gboolean
   874 gst_mythtv_src_stop (GstBaseSrc * bsrc)
   875 {
   876   GstMythtvSrc *src;
   877 
   878   src = GST_MYTHTV_SRC (bsrc);
   879 
   880   if (src->uri_name) {
   881     g_free (src->uri_name);
   882     src->uri_name = NULL;
   883   }
   884 
   885   if (src->mythtv_caps) {
   886     gst_caps_unref (src->mythtv_caps);
   887     src->mythtv_caps = NULL;
   888   }
   889 
   890   src->eos = FALSE;
   891 
   892   return TRUE;
   893 }
   894 
   895 static gboolean
   896 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
   897 {
   898   GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
   899   gint64 cont_size = 0;
   900 
   901   switch (GST_EVENT_TYPE (event)) {
   902 #if 0
   903     case GST_EVENT_FLUSH_START:
   904       //src->eos = FALSE;
   905       g_print( "\n\n\n[%s]\t\tGot FLUSH_START event!!!\n\n\n", __FUNCTION__ );
   906       cont_size = gst_mythtv_src_get_position (src);
   907       if ( !src->live_tv ) {
   908 	if ( cont_size > src->content_size ) {
   909 	  src->content_size = cont_size;
   910 	  src->eos = FALSE;
   911 	} else {
   912 	  src->eos = TRUE;
   913 	  gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
   914 	  gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
   915 	}
   916       } else {
   917 	if ( cont_size <= 0 ) {
   918 	  src->update_prog_chain = TRUE;
   919 	  src->eos = TRUE;
   920 	  src->unique_setup = FALSE;
   921 	  src->do_start = TRUE;		  				  		
   922 	}		  	
   923       }
   924       break;
   925     case GST_EVENT_FLUSH_STOP:
   926       src->do_start = TRUE;
   927       src->eos = FALSE;
   928       gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL);
   929       //gst_element_set_locked_state (GST_ELEMENT(src), TRUE);
   930       break;
   931 #endif
   932     case GST_EVENT_EOS:
   933       g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
   934 
   935       if ( src->live_tv ) {
   936 	cont_size = gst_mythtv_src_get_position (src);
   937 	if ( cont_size > src->content_size ) {
   938 	  src->content_size = cont_size;
   939 	  src->eos = FALSE;
   940 	} else {
   941 	  src->eos = TRUE;
   942 	  gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
   943 	  gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
   944 	}
   945       } else 
   946 	src->eos = TRUE;
   947       break;
   948 #if 0
   949     case GST_EVENT_NEWSEGMENT:
   950       g_print( "[%s] Got NEWSEGMENT!!!\n", __FUNCTION__ );
   951       src->eos = FALSE;
   952       break;
   953     case GST_EVENT_SEEK:  	  
   954       {
   955 	g_print( "[%s] Got EVENT_SEEK!!!\n", __FUNCTION__ );
   956 	gdouble rate;
   957 	//gboolean update = TRUE;
   958 	GstFormat format;
   959 	GstSeekType cur_type, stop_type;
   960 	GstSeekFlags flags;
   961 	gint64 cur = 0, stop = 0;
   962 	gst_event_parse_seek ( event, &rate, &format,
   963 	    &flags, &cur_type, &cur,
   964 	    &stop_type, &stop );
   965 
   966 	g_print( "[%s] Got EVENT_SEEK.\n", __FUNCTION__ );
   967 	if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) {
   968 	  g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ );
   969 	}
   970 	//gboolean ret = gst_event_parse_new_segment ( event,
   971 	//    &update, &rate, &format, &start, &stop,
   972 	//    &position );
   973 	//GstFlowReturn flow_ret = gst_mythtv_src_create (GST_BASE_SRC( GST_PAD_PARENT( psrc ) ), 
   974 	//			cur, stop - cur + 1, GstBuffer)
   975       }
   976 #endif
   977     default:
   978       return gst_pad_event_default (pad, event);
   979   }
   980 
   981   return gst_pad_event_default (pad, event);
   982 }
   983 
   984 static gboolean
   985 gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
   986 {
   987   return TRUE;
   988 }
   989 
   990 #if 0
   991 static gboolean
   992 gst_nuv_demux_sink_activate (GstPad * sinkpad)
   993 {
   994   gboolean res = TRUE;
   995   GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
   996 
   997   if (gst_pad_check_pull_range (sinkpad)) {
   998     nuv->mode = 0;
   999     nuv->adapter = NULL;
  1000     res = gst_pad_activate_pull (sinkpad, TRUE);
  1001   } else {
  1002     nuv->mode = 1;
  1003     nuv->adapter = gst_adapter_new ();
  1004     res = gst_pad_activate_push (sinkpad, TRUE);
  1005   }
  1006 
  1007   g_object_unref (nuv);
  1008   return res;
  1009 }
  1010 
  1011 static gboolean
  1012 gst_nuv_demux_sink_activate_pull (GstPad * sinkpad, gboolean active)
  1013 {
  1014   GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
  1015 
  1016   if (active) {
  1017     gst_pad_start_task (sinkpad, (GstTaskFunction) gst_nuv_demux_loop, sinkpad);
  1018   } else {
  1019     gst_pad_stop_task (sinkpad);
  1020   }
  1021   gst_object_unref (nuv);
  1022 
  1023   return TRUE;
  1024 }
  1025 
  1026 static GstFlowReturn
  1027 gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf)
  1028 {
  1029   GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
  1030 
  1031   gst_adapter_push (nuv->adapter, buf);
  1032 
  1033   return gst_nuv_demux_play (pad);
  1034 }
  1035 
  1036 static void
  1037 gst_nuv_demux_loop (GstPad * pad)
  1038 {
  1039   gst_nuv_demux_play (pad);
  1040 }
  1041 #endif
  1042 
  1043 static GstStateChangeReturn
  1044 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
  1045 {
  1046   GstStateChangeReturn ret = GST_STATE_CHANGE_NO_PREROLL;
  1047   GstMythtvSrc *src = GST_MYTHTV_SRC (element);
  1048 
  1049   switch (transition) {
  1050     case GST_STATE_CHANGE_NULL_TO_READY:
  1051       src->do_start = TRUE;
  1052       src->unique_setup = FALSE;      
  1053       break;
  1054     case GST_STATE_CHANGE_READY_TO_PAUSED:
  1055     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
  1056       src->eos = FALSE;
  1057       break;
  1058     default:
  1059       break;
  1060   }
  1061 
  1062   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
  1063   if (ret == GST_STATE_CHANGE_FAILURE)
  1064     return ret;
  1065 
  1066   switch (transition) {
  1067     case GST_STATE_CHANGE_READY_TO_NULL:
  1068       g_print( "[%s] READY to NULL called!\n", __FUNCTION__ );
  1069       break;
  1070     case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
  1071       g_print( "[%s] PLAYING to PAUSED called!\n", __FUNCTION__ );
  1072       break;
  1073     case GST_STATE_CHANGE_PAUSED_TO_READY:
  1074       g_print( "[%s] PAUSED to READY called!\n", __FUNCTION__ );
  1075       if ( src->live_tv && src->update_prog_chain ) {
  1076 	src->read_offset = 0;
  1077 	src->bytes_read = 0;
  1078 	gst_mythtv_src_next_program_chain( src );
  1079       }
  1080       break;
  1081     default:
  1082       break;
  1083   }
  1084 
  1085   return ret;
  1086 }
  1087 
  1088 static void
  1089 gst_mythtv_src_set_property (GObject * object, guint prop_id,
  1090     const GValue * value, GParamSpec * pspec)
  1091 {
  1092   GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
  1093 
  1094   GST_OBJECT_LOCK (mythtvsrc);
  1095   switch (prop_id) {
  1096     case PROP_URI:
  1097     case PROP_LOCATION:
  1098       {
  1099 	if (!g_value_get_string (value)) {
  1100 	  GST_WARNING ("location property cannot be NULL");
  1101 	  goto done;
  1102 	}
  1103 
  1104 	if (mythtvsrc->uri_name != NULL) {
  1105 	  g_free (mythtvsrc->uri_name);
  1106 	  mythtvsrc->uri_name = NULL;
  1107 	}
  1108 	mythtvsrc->uri_name = g_value_dup_string (value);
  1109 
  1110 	break;
  1111       }
  1112 #ifndef GST_DISABLE_GST_DEBUG
  1113     case PROP_GMYTHTV_DBG:
  1114       {
  1115 	mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
  1116 	break;
  1117       }
  1118 #endif
  1119     case PROP_GMYTHTV_VERSION:
  1120       {
  1121 	mythtvsrc->mythtv_version = g_value_get_int (value);
  1122 	break;
  1123       }
  1124     case PROP_GMYTHTV_LIVEID:
  1125       {
  1126 	mythtvsrc->live_tv_id = g_value_get_int (value);
  1127 	break;
  1128       }
  1129     case PROP_GMYTHTV_LIVE:
  1130       {
  1131 	mythtvsrc->live_tv = g_value_get_boolean (value);
  1132 	break;
  1133       }
  1134     case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
  1135       {
  1136 	mythtvsrc->enable_timing_position = g_value_get_boolean (value);
  1137 	break;
  1138       }      
  1139     case PROP_GMYTHTV_LIVE_CHAINID:
  1140       {
  1141 	if (!g_value_get_string (value)) {
  1142 	  GST_WARNING ("MythTV Live chainid property cannot be NULL");
  1143 	  goto done;
  1144 	}
  1145 
  1146 	if (mythtvsrc->live_chain_id != NULL) {
  1147 	  g_free (mythtvsrc->live_chain_id);
  1148 	  mythtvsrc->live_chain_id = NULL;
  1149 	}
  1150 	mythtvsrc->live_chain_id = g_value_dup_string (value);
  1151 	break;
  1152       }
  1153 
  1154     default:
  1155       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  1156       break;
  1157   }
  1158   GST_OBJECT_UNLOCK (mythtvsrc);
  1159 done:
  1160   return;
  1161 }
  1162 
  1163   static void
  1164 gst_mythtv_src_get_property (GObject * object, guint prop_id,
  1165     GValue * value, GParamSpec * pspec)
  1166 {
  1167   GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
  1168 
  1169   GST_OBJECT_LOCK (mythtvsrc);
  1170   switch (prop_id) {
  1171     case PROP_URI:
  1172     case PROP_LOCATION:
  1173       {
  1174 	gchar *str = g_strdup( "" );
  1175 
  1176 	if ( mythtvsrc->uri_name == NULL ) {
  1177 	  g_free (mythtvsrc->uri_name);
  1178 	  mythtvsrc->uri_name = NULL;
  1179 	} else {
  1180 	  str = g_strdup( mythtvsrc->uri_name );
  1181 	}
  1182 	g_value_set_string ( value, str );
  1183 	break;
  1184       }
  1185 #ifndef GST_DISABLE_GST_DEBUG
  1186     case PROP_GMYTHTV_DBG:
  1187       g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
  1188       break;
  1189 #endif
  1190     case PROP_GMYTHTV_VERSION:
  1191       {
  1192 	g_value_set_int ( value, mythtvsrc->mythtv_version );
  1193 	break;
  1194       }
  1195     case PROP_GMYTHTV_LIVEID:
  1196       {
  1197 	g_value_set_int ( value, mythtvsrc->live_tv_id );
  1198 	break;
  1199       }
  1200     case PROP_GMYTHTV_LIVE:
  1201       g_value_set_boolean ( value, mythtvsrc->live_tv );
  1202       break;
  1203     case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
  1204       g_value_set_boolean ( value, mythtvsrc->enable_timing_position );
  1205       break;
  1206     case PROP_GMYTHTV_LIVE_CHAINID:
  1207       {
  1208 	gchar *str = g_strdup( "" );
  1209 
  1210 	if ( mythtvsrc->live_chain_id == NULL ) {
  1211 	  g_free (mythtvsrc->live_chain_id);
  1212 	  mythtvsrc->live_chain_id = NULL;
  1213 	} else {
  1214 	  str = g_strdup( mythtvsrc->live_chain_id );
  1215 	}
  1216 	g_value_set_string ( value, str );
  1217 	break;
  1218       }
  1219     default:
  1220       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  1221       break;
  1222   }
  1223   GST_OBJECT_UNLOCK (mythtvsrc);
  1224 }
  1225 
  1226 /* entry point to initialize the plug-in
  1227  * initialize the plug-in itself
  1228  * register the element factories and pad templates
  1229  * register the features
  1230  */
  1231 static gboolean
  1232 plugin_init (GstPlugin * plugin)
  1233 {
  1234   return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
  1235       GST_TYPE_MYTHTV_SRC);
  1236 }
  1237 
  1238 /* this is the structure that gst-register looks for
  1239  * so keep the name plugin_desc, or you cannot get your plug-in registered */
  1240 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
  1241     GST_VERSION_MINOR,
  1242     "mythtv",
  1243     "lib MythTV src",
  1244     plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
  1245 
  1246 
  1247 /*** GSTURIHANDLER INTERFACE *************************************************/
  1248   static guint 
  1249 gst_mythtv_src_uri_get_type (void)
  1250 {
  1251   return GST_URI_SRC;
  1252 }
  1253 
  1254   static gchar **
  1255 gst_mythtv_src_uri_get_protocols (void)
  1256 {
  1257   static gchar *protocols[] = { "myth", "myths", NULL };
  1258 
  1259   return protocols;
  1260 }
  1261 
  1262   static const gchar *
  1263 gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
  1264 {
  1265   GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
  1266 
  1267   return src->uri_name;
  1268 }
  1269 
  1270   static gboolean
  1271 gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
  1272 {
  1273   GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
  1274 
  1275   gchar *protocol;
  1276 
  1277   protocol = gst_uri_get_protocol (uri);
  1278   if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
  1279     g_free (protocol);
  1280     return FALSE;
  1281   }
  1282   g_free (protocol);
  1283   g_object_set (src, "location", uri, NULL);
  1284 
  1285   return TRUE;
  1286 }
  1287 
  1288   static void
  1289 gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
  1290 {
  1291   GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
  1292 
  1293   iface->get_type = gst_mythtv_src_uri_get_type;
  1294   iface->get_protocols = gst_mythtv_src_uri_get_protocols;
  1295   iface->get_uri = gst_mythtv_src_uri_get_uri;
  1296   iface->set_uri = gst_mythtv_src_uri_set_uri;
  1297 }
  1298 
  1299   void
  1300 size_header_handler (void *userdata, const char *value)
  1301 {
  1302   GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
  1303 
  1304   //src->content_size = g_ascii_strtoull (value, NULL, 10);
  1305 
  1306   GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);
  1307 }