gst-plugins-mythtv/src/gstmythtvsrc.c
author rosfran
Fri Oct 27 00:22:59 2006 +0100 (2006-10-27)
branchtrunk
changeset 59 b2b0169716dc
parent 58 3f9efc6c27bd
child 61 dedcca2fe529
permissions -rwxr-xr-x
[svn r60] Some another minor fix, regarding live content.
     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	512*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->content_size = 0;
   230   this->read_offset = 0;
   231 
   232   this->live_tv = FALSE;
   233   
   234   this->enable_timing_position = FALSE;
   235   this->update_prog_chain = FALSE;    
   236 
   237   this->user_agent = g_strdup ("mythtvsrc");
   238   this->mythtv_caps = NULL;
   239   this->update_prog_chain = FALSE;
   240   
   241   this->eos = FALSE;
   242   
   243   gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES );  
   244 
   245   gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE );
   246 
   247   gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
   248       gst_mythtv_src_handle_event );
   249 /*
   250   gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
   251       gst_mythtv_src_query );
   252 */
   253 
   254 }
   255 
   256 static void
   257 gst_mythtv_src_finalize (GObject * gobject)
   258 {
   259   GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
   260 
   261   if (this->mythtv_caps) {
   262     gst_caps_unref (this->mythtv_caps);
   263     this->mythtv_caps = NULL;
   264   }
   265 
   266   if (this->file_transfer) {
   267     g_object_unref (this->file_transfer);
   268     this->file_transfer = NULL;
   269   }
   270 
   271 	if (this->spawn_livetv) {
   272     //g_object_unref (this->spawn_livetv);
   273     this->spawn_livetv = NULL;
   274   }
   275 
   276   if (this->uri_name) {
   277     g_free (this->uri_name);
   278   }
   279 
   280   if (this->user_agent) {
   281     g_free (this->user_agent);
   282   }
   283 
   284   G_OBJECT_CLASS (parent_class)->finalize (gobject);
   285 }
   286 
   287 static gint
   288 do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, GstBuffer **outbuf)
   289 {
   290   gint read = 0;
   291   guint sizetoread = size;
   292 
   293   g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread ); 
   294 
   295   /* Loop sending the Myth File Transfer request:
   296    * Retry whilst authentication fails and we supply it. */
   297   gint len = 0;
   298 
   299   GST_OBJECT_LOCK(src);
   300 
   301   while ( sizetoread > 0 ) {
   302   	
   303   	len = gmyth_file_transfer_read( src->file_transfer,
   304 			GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE );
   305 
   306     if ( len > 0 ) {
   307       read += len;      
   308       sizetoread -= len;
   309     } 
   310     else if ( len <= 0 ) 
   311     {
   312     	
   313       if ( src->live_tv == FALSE ) 
   314       {
   315 				goto done;
   316       } 
   317       else  
   318       {
   319       	if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
   320 	      	src->update_prog_chain = TRUE;
   321 	      	if ( gst_mythtv_src_next_program_chain ( src ) )
   322 	      		continue;
   323 	      	else
   324 	      		goto done;
   325 	      } else 
   326 	      	if ( src->content_size <= 
   327 	      					( src->read_offset + size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
   328 	      		src->update_prog_chain = TRUE;
   329 						if ( src->enable_timing_position ) {
   330 						    gint64 size_tmp = 0;
   331 						    if (src->live_tv == TRUE) {
   332 						get_file_pos:
   333 						      size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   334 						      if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   335 										src->content_size = size_tmp;
   336 						      else if ( size_tmp > 0 )
   337 							goto get_file_pos;
   338 						      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   339 							  __FUNCTION__, size_tmp );
   340 						    }
   341 						} else {
   342 						  	gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
   343 								if ( new_offset > 0 ) {
   344 								  if ( src->content_size < new_offset ) {
   345 								    src->content_size = new_offset;
   346 								  }
   347 								} else {
   348 								  src->update_prog_chain = TRUE;
   349 								}
   350 						}
   351 						goto done;
   352 		  		}
   353 	      }
   354 
   355   	}
   356     
   357     if ( read == sizetoread )
   358       break;
   359   }
   360   
   361   if ( read > 0 ) {
   362   	src->read_offset += read;
   363     src->bytes_read += read;
   364   
   365   g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
   366       "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, 
   367       src->read_offset, src->content_size );
   368       
   369   GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
   370   GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
   371   GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
   372      
   373   g_print( "Stopping: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
   374       "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), 
   375       GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
   376       
   377   } else if ( !src->live_tv )
   378   	goto eos;
   379   
   380   goto done;
   381 
   382 eos:
   383   src->eos = TRUE;
   384   
   385 done:
   386   GST_OBJECT_UNLOCK(src);
   387 
   388   return read;
   389 }
   390 
   391 static GstFlowReturn
   392 gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf)
   393 {
   394   GstMythtvSrc *src;
   395   GstFlowReturn ret = GST_FLOW_OK;
   396   gint read = -1;
   397   
   398   src = GST_MYTHTV_SRC (psrc);
   399   /* The caller should know the number of bytes and not read beyond EOS. */
   400   if (G_UNLIKELY (src->eos))
   401     goto eos;
   402   if ( G_UNLIKELY (src->update_prog_chain) )
   403     goto change_progchain;
   404   
   405   GST_OBJECT_LOCK(src);
   406 
   407   if (G_UNLIKELY (src->read_offset != offset)) {
   408     gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset, SEEK_SET);
   409     g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
   410     	__FUNCTION__, src->read_offset, new_offset );
   411     if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) {
   412     {
   413       GST_OBJECT_UNLOCK(src);
   414       if ( src->live_tv )
   415       	goto change_progchain;
   416       else
   417       	goto eos;
   418     }
   419 
   420     src->read_offset = offset;
   421   }
   422   GST_OBJECT_UNLOCK(src);
   423   
   424   /* Create the buffer. */
   425   ret = gst_pad_alloc_buffer (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
   426       src->read_offset, size,
   427       //src->icy_caps ? src->icy_caps :
   428       GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf);
   429 
   430   if (G_UNLIKELY (ret != GST_FLOW_OK))
   431     goto done;
   432   
   433   //g_static_mutex_lock( &update_size_mutex );
   434   read = do_read_request_response ( src, src->read_offset, size, outbuf );
   435   //g_static_mutex_unlock( &update_size_mutex );  
   436 
   437   if (G_UNLIKELY (src->update_prog_chain) )
   438     goto change_progchain;
   439 
   440   if (G_UNLIKELY (read <= 0) || *outbuf == NULL) {
   441   	if ( src->live_tv )
   442     	goto change_progchain;
   443     else
   444     	goto read_error;
   445   }
   446 
   447 done:
   448  {
   449     const gchar *reason = gst_flow_get_name (ret);
   450 
   451     GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
   452   	return ret;
   453  }
   454 eos:
   455   {
   456     const gchar *reason = gst_flow_get_name (ret);
   457 
   458     GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
   459     return GST_FLOW_UNEXPECTED;
   460   }
   461   /* ERRORS */
   462 read_error:
   463   {
   464     GST_ELEMENT_ERROR (src, RESOURCE, READ,
   465 	(NULL), ("Could not read any bytes (%i, %s)", read,
   466 	  src->uri_name));
   467     return GST_FLOW_ERROR;
   468   }
   469 change_progchain:
   470   {
   471     GST_ELEMENT_ERROR (src, RESOURCE, READ,
   472 		(NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
   473 		  src->uri_name));
   474 		// go to the next program chain
   475 		src->unique_setup = FALSE;
   476 		src->update_prog_chain = TRUE;
   477 		gst_mythtv_src_next_program_chain( src );  
   478     return -101;
   479   }
   480 
   481 }
   482 
   483 void
   484 update_size_func( void *mythtv_data ) 
   485 {
   486   GstMythtvSrc *src;
   487 
   488   g_return_if_fail( mythtv_data != NULL );
   489 
   490   src = GST_MYTHTV_SRC ( mythtv_data );
   491 
   492   g_static_mutex_lock( &update_size_mutex );
   493 
   494   if ( src->do_start ) {
   495 	if ( src->enable_timing_position ) {
   496 	    gint64 size_tmp = 0;
   497 	    if (src->live_tv == TRUE) {
   498 	get_file_pos:
   499 	      g_usleep( 50 );
   500 	      size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   501 	      if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   502 		src->content_size = size_tmp;
   503 	      else if ( size_tmp > 0 )
   504 		goto get_file_pos;
   505 	      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   506 		  __FUNCTION__, size_tmp );
   507 	    }
   508 	}
   509   }
   510   g_static_mutex_unlock( &update_size_mutex );
   511 
   512 }
   513 
   514 gint64
   515 gst_mythtv_src_get_position ( GstMythtvSrc* src ) 
   516 {
   517 
   518   gint64 size_tmp = 0;
   519   if (src->live_tv == TRUE) {
   520 get_file_pos:
   521     g_usleep( 50 );
   522     size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   523     if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   524 			src->content_size = size_tmp;
   525     else if ( size_tmp > 0 )
   526 			goto get_file_pos;
   527     g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   528   __FUNCTION__, size_tmp );
   529   }
   530 
   531   return src->content_size;	
   532 
   533 }
   534 
   535 /* create a socket for connecting to remote server */
   536 static gboolean
   537 gst_mythtv_src_start ( GstBaseSrc * bsrc )
   538 {
   539   GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
   540 
   541   GString *chain_id_local = NULL;
   542 
   543   gboolean ret = TRUE;
   544   
   545   if ( !src->do_start )
   546   	goto done;
   547 
   548   if (src->unique_setup == FALSE) {
   549     src->unique_setup = TRUE;
   550   } else {
   551     goto done;
   552   }
   553 
   554   GST_OBJECT_LOCK(src);
   555 
   556   if ( src->live_tv ) {
   557     src->spawn_livetv = gmyth_livetv_new( );
   558     if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) {
   559       ret = FALSE;
   560       GST_OBJECT_UNLOCK( src );
   561       goto init_failed;
   562     }
   563 
   564     /* set up the uri variable */
   565     src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
   566     chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
   567     if ( chain_id_local != NULL ) {
   568       src->live_chain_id = g_strdup( chain_id_local->str );
   569       g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
   570     }
   571     src->live_tv_id = src->spawn_livetv->remote_encoder->recorder_num;
   572     g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
   573   }
   574 
   575   src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, 
   576       g_string_new( src->uri_name ), -1, src->mythtv_version );
   577 
   578   if ( src->file_transfer == NULL ) {
   579     GST_OBJECT_UNLOCK(src);
   580 
   581     goto init_failed;
   582   }
   583 
   584   /* sets the Playback monitor connection */
   585   ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
   586 
   587   if ( src->live_tv == TRUE && ret == TRUE ) {
   588     /* loop finished, set the max tries variable to zero again... */
   589     wait_to_transfer = 0;
   590 
   591     while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE 
   592 	  /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
   593       g_usleep( 100 );
   594   }
   595 
   596   /* sets the FileTransfer instance connection (video/audio download) */
   597   ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
   598 
   599   if ( ret == FALSE ) {
   600     GST_OBJECT_UNLOCK(src);
   601 #ifndef GST_DISABLE_GST_DEBUG  
   602     if ( src->mythtv_msgs_dbg )
   603       g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );  	  
   604 #endif
   605     goto begin_req_failed;
   606   }
   607 
   608   src->content_size = src->file_transfer->filesize;
   609 
   610   GST_OBJECT_UNLOCK(src);
   611 
   612   src->do_start = FALSE;
   613 
   614 done:
   615   return TRUE;
   616 
   617   /* ERRORS */
   618 init_failed:
   619   {
   620     if (src->spawn_livetv != NULL )
   621       g_object_unref( src->spawn_livetv );
   622 
   623     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   624 	(NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
   625     return FALSE;
   626   }
   627 begin_req_failed:
   628   {
   629     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   630 	(NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
   631     return FALSE;
   632   }
   633 }
   634 
   635 /* create a new socket for connecting to the next program chain */
   636 static gboolean
   637 gst_mythtv_src_next_program_chain ( GstMythtvSrc *src )
   638 {
   639   GString *chain_id_local = NULL;
   640 
   641   gboolean ret = TRUE;
   642   
   643   if ( !src->live_tv )
   644   	goto init_failed;
   645   
   646   if (src->file_transfer) {
   647     g_object_unref (src->file_transfer);
   648     src->file_transfer = NULL;
   649   }
   650   
   651   if (src->uri_name) {
   652     g_free (src->uri_name);
   653   }
   654   
   655   if ( src->live_tv ) {
   656   	if ( src->update_prog_chain )
   657   	{
   658     	if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) {
   659 	      ret = FALSE;
   660 	      goto init_failed;
   661     	}
   662     	src->update_prog_chain = FALSE;
   663     }
   664     /* set up the uri variable */
   665     src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
   666     chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
   667     if ( chain_id_local != NULL ) {
   668       src->live_chain_id = g_strdup( chain_id_local->str );
   669       g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
   670     }
   671     src->live_tv_id = src->spawn_livetv->remote_encoder->recorder_num;
   672     g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
   673   }
   674 
   675   src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, 
   676       g_string_new( src->uri_name ), -1, src->mythtv_version );
   677 
   678   if ( src->file_transfer == NULL ) {
   679     goto init_failed;
   680   }
   681 
   682   /* sets the Playback monitor connection */
   683   ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
   684 
   685   if ( src->live_tv == TRUE && ret == TRUE ) {
   686     /* loop finished, set the max tries variable to zero again... */
   687     wait_to_transfer = 0;
   688     
   689     g_usleep( 500 );
   690 
   691     while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && 
   692     		( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) )
   693       		g_usleep( 100 );
   694   }
   695 
   696   /* sets the FileTransfer instance connection (video/audio download) */
   697   ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
   698 
   699   if ( ret == FALSE ) {
   700 #ifndef GST_DISABLE_GST_DEBUG  
   701     if ( src->mythtv_msgs_dbg )
   702       g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );  	  
   703 #endif
   704     goto begin_req_failed;
   705   }
   706   
   707   if ( src->content_size < src->file_transfer->filesize ) {
   708   	src->content_size = src->file_transfer->filesize;
   709   } else {
   710   	gint64 pos = gst_mythtv_src_get_position(src);
   711   	if ( pos > src->file_transfer->filesize )
   712   		src->content_size = pos;  	
   713   }
   714   
   715   src->read_offset = 0;
   716   
   717   src->update_prog_chain = FALSE;
   718 
   719   return TRUE;
   720 
   721   /* ERRORS */
   722 init_failed:
   723   {
   724     if (src->spawn_livetv != NULL )
   725       g_object_unref( src->spawn_livetv );
   726 
   727     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   728 	(NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
   729     return FALSE;
   730   }
   731 begin_req_failed:
   732   {
   733     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   734 	(NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
   735     return FALSE;
   736   }
   737   
   738 }
   739 
   740 #if 0
   741 /* handles queries for location in the stream in the requested format */
   742 static gboolean
   743 gst_mythtv_src_query ( GstPad * pad, GstQuery * query )
   744 {
   745   gboolean res = TRUE;
   746   GstMythtvSrc *mythtv;
   747 
   748   guint64 size = 0;
   749 
   750   mythtv = GST_GMYTHTV_SRC( GST_PAD_PARENT (pad) );
   751 
   752   size = gst_mythtv_src_get_position (mythtv);
   753 
   754   switch (GST_QUERY_TYPE (query)) {
   755 
   756     case GST_QUERY_POSITION:
   757       {
   758 
   759 	//GstFormat format;
   760 	gint64 cur = 0;
   761 
   762 	/* save requested format */
   763 	gst_query_parse_position (query, NULL, &cur);
   764 
   765 	/* query peer for current position in time */
   766 	g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__, 
   767 	    ( size > cur ) ? "greater" : "lower", size, cur );
   768 	gst_query_set_position (query, GST_FORMAT_BYTES, size);
   769 	if ( size < cur )
   770 	  goto error;
   771 
   772 	break;
   773       }
   774      #if 0
   775     case GST_QUERY_DURATION:
   776       {
   777 	//GstFormat format;
   778 	gint64 cur = 0;
   779 
   780 	/* save requested format */
   781 	gst_query_parse_position (query, NULL, &cur);
   782 
   783 	/* query peer for current position in time */
   784 	g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__, 
   785 	    ( size * GST_SECOND > cur * GST_SECOND ) ? "greater" : "lower", size * GST_SECOND, 
   786 	    cur * GST_SECOND );
   787 	gst_query_set_position (query, GST_FORMAT_TIME, size * GST_SECOND );
   788 
   789 	if ( size * GST_SECOND < cur * GST_SECOND )
   790 	  goto error;
   791 
   792 	break;
   793       }
   794 	#endif
   795     default:
   796       res = FALSE;
   797       break;
   798   }
   799 
   800   return res;
   801 
   802 error:
   803 
   804   return FALSE;
   805 }
   806 #endif
   807 
   808 static gboolean
   809 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
   810 {
   811   GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
   812   gboolean ret = TRUE;
   813 
   814   if (src->content_size <= 0) {
   815     ret= FALSE;
   816   } else {
   817   //g_static_mutex_lock( &update_size_mutex );
   818   //GST_OBJECT_LOCK(src);
   819 
   820 	gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
   821 	if ( new_offset > 0 ) {
   822 	  if ( src->content_size < new_offset ) {
   823 	    src->content_size = new_offset;
   824 	  }
   825 	} else {
   826 		if ( src->live_tv )
   827 			src->update_prog_chain = TRUE;
   828 	}
   829  
   830 	if ( src->enable_timing_position ) {
   831 	    gint64 size_tmp = 0;
   832 	    if (src->live_tv == TRUE) {
   833 	get_file_pos:
   834 	      g_usleep( 5 );
   835 	      size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   836 	      if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   837 					src->content_size = size_tmp;
   838 	      else if ( size_tmp > 0  )
   839 					goto get_file_pos;
   840 	      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   841 		  __FUNCTION__, size_tmp );
   842 	    }
   843 	}
   844 	//GST_OBJECT_UNLOCK(src);
   845   //g_static_mutex_unlock( &update_size_mutex );
   846   }
   847 
   848   *size = src->content_size;
   849   g_print( "[%s] Content size = %lld\n", __FUNCTION__, src->content_size );
   850 
   851   return ret;
   852 
   853 }
   854 
   855 /* close the socket and associated resources
   856  * used both to recover from errors and go to NULL state */
   857 static gboolean
   858 gst_mythtv_src_stop (GstBaseSrc * bsrc)
   859 {
   860   GstMythtvSrc *src;
   861 
   862   src = GST_MYTHTV_SRC (bsrc);
   863 
   864   if (src->uri_name) {
   865     g_free (src->uri_name);
   866     src->uri_name = NULL;
   867   }
   868 
   869   if (src->mythtv_caps) {
   870     gst_caps_unref (src->mythtv_caps);
   871     src->mythtv_caps = NULL;
   872   }
   873 
   874   src->eos = FALSE;
   875 
   876   return TRUE;
   877 }
   878 
   879 static gboolean
   880 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
   881 {
   882   GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
   883   gint64 cont_size = 0;
   884 
   885   switch (GST_EVENT_TYPE (event)) {
   886 #if 0
   887     case GST_EVENT_FLUSH_START:
   888       //src->eos = FALSE;
   889       g_print( "\n\n\n[%s]\t\tGot FLUSH_START event!!!\n\n\n", __FUNCTION__ );
   890 		  cont_size = gst_mythtv_src_get_position (src);
   891 		  if ( !src->live_tv ) {
   892 			  if ( cont_size > src->content_size ) {
   893 			  	src->content_size = cont_size;
   894 			  	src->eos = FALSE;
   895 	  	  } else {
   896 	      	src->eos = TRUE;
   897 	      	gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
   898 	      	gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
   899 	  	  }
   900 		  } else {
   901 		  	if ( cont_size <= 0 ) {
   902 		  		src->update_prog_chain = TRUE;
   903 		  		src->eos = TRUE;
   904 		  		src->unique_setup = FALSE;
   905 		  		src->do_start = TRUE;		  				  		
   906 		  	}		  	
   907 		  }
   908 	    break;
   909     case GST_EVENT_FLUSH_STOP:
   910       src->do_start = TRUE;
   911       src->eos = FALSE;
   912       gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL);
   913       //gst_element_set_locked_state (GST_ELEMENT(src), TRUE);
   914       break;
   915 #endif
   916     case GST_EVENT_EOS:
   917       g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
   918 	  cont_size = gst_mythtv_src_get_position (src);
   919 	  if ( !src->live_tv ) {
   920 		  if ( cont_size > src->content_size ) {
   921 		  	src->content_size = cont_size;
   922 		  	src->eos = FALSE;
   923 	  	  } else {
   924 	      	src->eos = TRUE;
   925 	      	gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
   926 	      	gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
   927 	  	  }
   928 	  } else 
   929 	  	src->eos = TRUE;
   930       break;
   931 #if 0
   932     case GST_EVENT_NEWSEGMENT:
   933       g_print( "[%s] Got NEWSEGMENT!!!\n", __FUNCTION__ );
   934       src->eos = FALSE;
   935       break;
   936     case GST_EVENT_SEEK:  	  
   937       {
   938 	g_print( "[%s] Got EVENT_SEEK!!!\n", __FUNCTION__ );
   939 	gdouble rate;
   940 	//gboolean update = TRUE;
   941 	GstFormat format;
   942 	GstSeekType cur_type, stop_type;
   943 	GstSeekFlags flags;
   944 	gint64 cur = 0, stop = 0;
   945 	gst_event_parse_seek ( event, &rate, &format,
   946 	    &flags, &cur_type, &cur,
   947 	    &stop_type, &stop );
   948 
   949 	g_print( "[%s] Got EVENT_SEEK.\n", __FUNCTION__ );
   950 	if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) {
   951 	  g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ );
   952 	}
   953 	//gboolean ret = gst_event_parse_new_segment ( event,
   954 	//    &update, &rate, &format, &start, &stop,
   955 	//    &position );
   956 	//GstFlowReturn flow_ret = gst_mythtv_src_create (GST_BASE_SRC( GST_PAD_PARENT( psrc ) ), 
   957 	//			cur, stop - cur + 1, GstBuffer)
   958       }
   959 #endif
   960     default:
   961       return gst_pad_event_default (pad, event);
   962   }
   963 
   964   return gst_pad_event_default (pad, event);
   965 }
   966 
   967 static gboolean
   968 gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
   969 {
   970   return TRUE;
   971 }
   972 
   973 static GstStateChangeReturn
   974 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
   975 {
   976   GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
   977   GstMythtvSrc *src = GST_MYTHTV_SRC (element);
   978 
   979   switch (transition) {
   980     case GST_STATE_CHANGE_NULL_TO_READY:
   981       src->content_size = 0;
   982       src->read_offset = 0;
   983       src->bytes_read = 0;
   984       src->do_start = TRUE;
   985       src->unique_setup = FALSE;      
   986       src->eos = TRUE;
   987       break;
   988     case GST_STATE_CHANGE_READY_TO_PAUSED:
   989     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
   990       src->eos = FALSE;
   991       break;
   992     default:
   993       break;
   994   }
   995   
   996  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
   997   if (ret == GST_STATE_CHANGE_FAILURE)
   998     return ret;
   999 
  1000   switch (transition) {
  1001     case GST_STATE_CHANGE_READY_TO_NULL:
  1002       break;
  1003     case GST_STATE_CHANGE_PAUSED_TO_READY:
  1004     	if ( src->live_tv && src->update_prog_chain )
  1005     		gst_mythtv_src_next_program_chain( src );
  1006     	break;
  1007     default:
  1008       break;
  1009   }
  1010 
  1011   return ret;
  1012 }
  1013 
  1014 static void
  1015 gst_mythtv_src_set_property (GObject * object, guint prop_id,
  1016     const GValue * value, GParamSpec * pspec)
  1017 {
  1018   GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
  1019 
  1020   GST_OBJECT_LOCK (mythtvsrc);
  1021   switch (prop_id) {
  1022     case PROP_URI:
  1023     case PROP_LOCATION:
  1024       {
  1025 	if (!g_value_get_string (value)) {
  1026 	  GST_WARNING ("location property cannot be NULL");
  1027 	  goto done;
  1028 	}
  1029 
  1030 	if (mythtvsrc->uri_name != NULL) {
  1031 	  g_free (mythtvsrc->uri_name);
  1032 	  mythtvsrc->uri_name = NULL;
  1033 	}
  1034 	mythtvsrc->uri_name = g_value_dup_string (value);
  1035 
  1036 	break;
  1037       }
  1038 #ifndef GST_DISABLE_GST_DEBUG
  1039     case PROP_GMYTHTV_DBG:
  1040       {
  1041 	mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
  1042 	break;
  1043       }
  1044 #endif
  1045     case PROP_GMYTHTV_VERSION:
  1046       {
  1047 	mythtvsrc->mythtv_version = g_value_get_int (value);
  1048 	break;
  1049       }
  1050     case PROP_GMYTHTV_LIVEID:
  1051       {
  1052 	mythtvsrc->live_tv_id = g_value_get_int (value);
  1053 	break;
  1054       }
  1055     case PROP_GMYTHTV_LIVE:
  1056       {
  1057 	mythtvsrc->live_tv = g_value_get_boolean (value);
  1058 	break;
  1059       }
  1060     case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
  1061       {
  1062 	mythtvsrc->enable_timing_position = g_value_get_boolean (value);
  1063 	break;
  1064       }      
  1065     case PROP_GMYTHTV_LIVE_CHAINID:
  1066       {
  1067 	if (!g_value_get_string (value)) {
  1068 	  GST_WARNING ("MythTV Live chainid property cannot be NULL");
  1069 	  goto done;
  1070 	}
  1071 
  1072 	if (mythtvsrc->live_chain_id != NULL) {
  1073 	  g_free (mythtvsrc->live_chain_id);
  1074 	  mythtvsrc->live_chain_id = NULL;
  1075 	}
  1076 	mythtvsrc->live_chain_id = g_value_dup_string (value);
  1077 	break;
  1078       }
  1079 
  1080     default:
  1081       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  1082       break;
  1083   }
  1084   GST_OBJECT_UNLOCK (mythtvsrc);
  1085 done:
  1086   return;
  1087 }
  1088 
  1089   static void
  1090 gst_mythtv_src_get_property (GObject * object, guint prop_id,
  1091     GValue * value, GParamSpec * pspec)
  1092 {
  1093   GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
  1094 
  1095   GST_OBJECT_LOCK (mythtvsrc);
  1096   switch (prop_id) {
  1097     case PROP_URI:
  1098     case PROP_LOCATION:
  1099       {
  1100 	gchar *str = g_strdup( "" );
  1101 
  1102 	if ( mythtvsrc->uri_name == NULL ) {
  1103 	  g_free (mythtvsrc->uri_name);
  1104 	  mythtvsrc->uri_name = NULL;
  1105 	} else {
  1106 	  str = g_strdup( mythtvsrc->uri_name );
  1107 	}
  1108 	g_value_set_string ( value, str );
  1109 	break;
  1110       }
  1111 #ifndef GST_DISABLE_GST_DEBUG
  1112     case PROP_GMYTHTV_DBG:
  1113       g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
  1114       break;
  1115 #endif
  1116     case PROP_GMYTHTV_VERSION:
  1117       {
  1118 	g_value_set_int ( value, mythtvsrc->mythtv_version );
  1119 	break;
  1120       }
  1121     case PROP_GMYTHTV_LIVEID:
  1122       {
  1123 	g_value_set_int ( value, mythtvsrc->live_tv_id );
  1124 	break;
  1125       }
  1126     case PROP_GMYTHTV_LIVE:
  1127       g_value_set_boolean ( value, mythtvsrc->live_tv );
  1128       break;
  1129     case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
  1130       g_value_set_boolean ( value, mythtvsrc->enable_timing_position );
  1131       break;
  1132     case PROP_GMYTHTV_LIVE_CHAINID:
  1133       {
  1134 	gchar *str = g_strdup( "" );
  1135 
  1136 	if ( mythtvsrc->live_chain_id == NULL ) {
  1137 	  g_free (mythtvsrc->live_chain_id);
  1138 	  mythtvsrc->live_chain_id = NULL;
  1139 	} else {
  1140 	  str = g_strdup( mythtvsrc->live_chain_id );
  1141 	}
  1142 	g_value_set_string ( value, str );
  1143 	break;
  1144       }
  1145     default:
  1146       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  1147       break;
  1148   }
  1149   GST_OBJECT_UNLOCK (mythtvsrc);
  1150 }
  1151 
  1152 /* entry point to initialize the plug-in
  1153  * initialize the plug-in itself
  1154  * register the element factories and pad templates
  1155  * register the features
  1156  */
  1157 static gboolean
  1158 plugin_init (GstPlugin * plugin)
  1159 {
  1160   return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
  1161       GST_TYPE_MYTHTV_SRC);
  1162 }
  1163 
  1164 /* this is the structure that gst-register looks for
  1165  * so keep the name plugin_desc, or you cannot get your plug-in registered */
  1166 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
  1167     GST_VERSION_MINOR,
  1168     "mythtv",
  1169     "lib MythTV src",
  1170     plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
  1171 
  1172 
  1173 /*** GSTURIHANDLER INTERFACE *************************************************/
  1174   static guint 
  1175 gst_mythtv_src_uri_get_type (void)
  1176 {
  1177   return GST_URI_SRC;
  1178 }
  1179 
  1180   static gchar **
  1181 gst_mythtv_src_uri_get_protocols (void)
  1182 {
  1183   static gchar *protocols[] = { "myth", "myths", NULL };
  1184 
  1185   return protocols;
  1186 }
  1187 
  1188   static const gchar *
  1189 gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
  1190 {
  1191   GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
  1192 
  1193   return src->uri_name;
  1194 }
  1195 
  1196   static gboolean
  1197 gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
  1198 {
  1199   GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
  1200 
  1201   gchar *protocol;
  1202 
  1203   protocol = gst_uri_get_protocol (uri);
  1204   if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
  1205     g_free (protocol);
  1206     return FALSE;
  1207   }
  1208   g_free (protocol);
  1209   g_object_set (src, "location", uri, NULL);
  1210 
  1211   return TRUE;
  1212 }
  1213 
  1214   static void
  1215 gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
  1216 {
  1217   GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
  1218 
  1219   iface->get_type = gst_mythtv_src_uri_get_type;
  1220   iface->get_protocols = gst_mythtv_src_uri_get_protocols;
  1221   iface->get_uri = gst_mythtv_src_uri_get_uri;
  1222   iface->set_uri = gst_mythtv_src_uri_set_uri;
  1223 }
  1224 
  1225   void
  1226 size_header_handler (void *userdata, const char *value)
  1227 {
  1228   GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
  1229 
  1230   //src->content_size = g_ascii_strtoull (value, NULL, 10);
  1231 
  1232   GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);
  1233 }