gst-plugins-mythtv/src/gstmythtvsrc.c
author rosfran
Wed Apr 18 16:21:38 2007 +0100 (2007-04-18)
branchtrunk
changeset 566 25f194cfa60b
parent 553 424babd6b788
child 575 f7351f2fd6d8
permissions -rwxr-xr-x
[svn r571] Added test to the LiveTV module.
     1 /* GStreamer MythTV Plug-in
     2  * Copyright (C) <2006> Rosfran Borges <rosfran.borges@indt.org.br>
     3  *
     4  * This library is free software; you can redistribute it and/or
     5  * modify it under the terms of the GNU Library General Public
     6  * License as published by the Free Software Foundation; either
     7  * version 2 of the License, or (at your option) any later version.
     8  *
     9  * This library is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    12  * Library General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU Library General Public
    15  * License along with this library; if not, write to the
    16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    17  * Boston, MA 02111-1307, USA.
    18  */
    19 /**
    20  * SECTION:element-mythtvsrc
    21  *
    22  * <refsect2>
    23  * <para>
    24  * MythTVSrc allows to access a remote MythTV backend streaming Video/Audio server,
    25  * and to render audio and video content through a TCP/IP connection to a specific
    26  * port on this server, and based on a known MythTV protocol that is based on 
    27  * some message passing, such as REQUEST_BLOCK on a specified number of bytes, to get
    28  * some chunk of remote file data.
    29  * You should pass the information aboute the remote MythTV backend server 
    30  * through the <link linkend="GstMythTVSrc--location">location</link> property.
    31  * </para>
    32  * <title>Examples</title>
    33  * <para>
    34  * If you want to get the LiveTV content (set channel, TV tuner, RemoteEncoder, 
    35  * Recorder),
    36  * put the following URI:
    37  * 
    38  * <programlisting> 
    39  *  myth://xxx.xxx.xxx.xxx:6543/livetv?channel=BBC
    40  * </programlisting>
    41  *
    42  * This URI will say to the gmyth library to configure the Recorder instance (used to
    43  * change the channel, start the TV multimedia content transmition, etc.), using
    44  * the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend 
    45  * server, and setting the channel name to "BBC". 
    46  * 
    47  * To get a already recorded the MythTV NUV file, put the following URI:
    48  * 
    49  * <programlisting>
    50  *  myth://xxx.xxx.xxx.xxx:6543/filename.nuv
    51  * </programlisting>
    52  *
    53  * This URI will say to the gmyth library to configure the Recorder instance (used to
    54  * change the channel, start the TV multimedia content transmition, etc.), using
    55  * the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend 
    56  * server, and setting the channel name to "BBC".
    57  * 
    58  * Another possible way to use the LiveTV content, and just in the case you want to 
    59  * use the mysql database, put the location URI in the following format:
    60  * 
    61  * <programlisting> 
    62  *  myth://mythtv:mythtv@xxx.xxx.xxx.xxx:6543/?mythconverg&channel=9
    63  * </programlisting>
    64  * 
    65  * Where the first field is the protocol (myth), the second and third are user 
    66  * name (mythtv) and password (mythtv), then backend host name and port number, 
    67  * and the last field is the database name (mythconverg).
    68  * </para>
    69  * </refsect2>
    70  */
    71 #ifdef HAVE_CONFIG_H
    72 #include "config.h"
    73 #endif
    74 
    75 #include "gstmythtvsrc.h"
    76 #include <gmyth/gmyth_file.h>
    77 #include <gmyth/gmyth_file_transfer.h>
    78 #include <gmyth/gmyth_file_local.h>
    79 #include <gmyth/gmyth_livetv.h>
    80 
    81 #include <gmyth/gmyth_socket.h>
    82 #include <gmyth/gmyth_tvchain.h>
    83 
    84 #include <string.h>
    85 #include <unistd.h>
    86 
    87 GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
    88 #define GST_CAT_DEFAULT mythtvsrc_debug
    89 
    90 #define GST_GMYTHTV_ID_NUM                  1
    91 
    92 #define GST_GMYTHTV_CHANNEL_DEFAULT_NUM     (-1)
    93 
    94 #define GMYTHTV_VERSION_DEFAULT			        30
    95 
    96 #define GMYTHTV_TRANSFER_MAX_WAITS          100
    97 
    98 #define GMYTHTV_TRANSFER_MAX_RESENDS        2
    99 
   100 #define GMYTHTV_TRANSFER_MAX_BUFFER         (128*1024)
   101 
   102 #define MAX_READ_SIZE                       (4*1024)
   103 
   104 #define GST_FLOW_ERROR_NO_DATA              (-101)
   105 
   106 #define REQUEST_MAX_SIZE                    (64*1024)
   107 
   108 #define INTERNAL_BUFFER_SIZE                (90*1024)
   109 
   110 static const GstElementDetails gst_mythtv_src_details =
   111 GST_ELEMENT_DETAILS ("MythTV client source",
   112     "Source/Network",
   113     "Control and receive data as a client over the network "
   114     "via raw socket connections using the MythTV protocol",
   115     "Rosfran Borges <rosfran.borges@indt.org.br>");
   116 
   117 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
   118     GST_PAD_SRC,
   119     GST_PAD_ALWAYS,
   120     GST_STATIC_CAPS ("video/x-nuv"));
   121 
   122 enum
   123 {
   124   PROP_0,
   125   PROP_LOCATION,
   126 #ifndef GST_DISABLE_GST_DEBUG
   127   PROP_GMYTHTV_DBG,
   128 #endif
   129   PROP_GMYTHTV_VERSION,
   130   PROP_GMYTHTV_LIVE,
   131   PROP_GMYTHTV_LIVEID,
   132   PROP_GMYTHTV_LIVE_CHAINID,
   133   PROP_GMYTHTV_ENABLE_TIMING_POSITION,
   134   PROP_GMYTHTV_CHANNEL_NUM
   135 };
   136 
   137 static void gst_mythtv_src_clear (GstMythtvSrc *mythtv_src);
   138 
   139 static void gst_mythtv_src_finalize (GObject * gobject);
   140 
   141 static GstFlowReturn gst_mythtv_src_create (GstPushSrc * psrc,
   142     GstBuffer ** outbuf);
   143 
   144 static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
   145 static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
   146 static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
   147 static gboolean gst_mythtv_src_is_seekable (GstBaseSrc * push_src);
   148 
   149 static gboolean gst_mythtv_src_do_seek (GstBaseSrc * base,
   150     GstSegment * segment);
   151 
   152 static GstStateChangeReturn
   153 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
   154 
   155 static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
   156     const GValue * value, GParamSpec * pspec);
   157 static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
   158     GValue * value, GParamSpec * pspec);
   159 
   160 static void gst_mythtv_src_uri_handler_init (gpointer g_iface,
   161     gpointer iface_data);
   162 
   163 static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query);
   164 
   165 static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
   166 
   167 static GMythFileReadResult do_read_request_response (GstMythtvSrc * src, guint size,
   168     GByteArray * data_ptr);
   169 
   170 static void
   171 _urihandler_init (GType type)
   172 {
   173   static const GInterfaceInfo urihandler_info = {
   174     gst_mythtv_src_uri_handler_init,
   175     NULL,
   176     NULL
   177   };
   178 
   179   g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
   180 
   181   GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV src");
   182 }
   183 
   184 GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
   185     GST_TYPE_PUSH_SRC, _urihandler_init)
   186 
   187      static void gst_mythtv_src_base_init (gpointer g_class)
   188 {
   189   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
   190 
   191   gst_element_class_add_pad_template (element_class,
   192       gst_static_pad_template_get (&srctemplate));
   193 
   194   gst_element_class_set_details (element_class, &gst_mythtv_src_details);
   195 
   196   element_class->change_state = gst_mythtv_src_change_state;
   197 
   198 }
   199 
   200 static void
   201 gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
   202 {
   203   GObjectClass *gobject_class;
   204   GstPushSrcClass *gstpushsrc_class;
   205   GstBaseSrcClass *gstbasesrc_class;
   206 
   207   gobject_class = (GObjectClass *) klass;
   208   gstbasesrc_class = (GstBaseSrcClass *) klass;
   209   gstpushsrc_class = (GstPushSrcClass *) klass;
   210 
   211   gobject_class->set_property = gst_mythtv_src_set_property;
   212   gobject_class->get_property = gst_mythtv_src_get_property;
   213   gobject_class->finalize = gst_mythtv_src_finalize;
   214 
   215   g_object_class_install_property
   216       (gobject_class, PROP_LOCATION,
   217       g_param_spec_string ("location", "Location",
   218           "The location. In the form:"
   219           "\n\t\t\tmyth://a.com/file.nuv"
   220           "\n\t\t\tmyth://a.com:23223/file.nuv "
   221           "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
   222           "", G_PARAM_READWRITE));
   223 
   224   g_object_class_install_property
   225       (gobject_class, PROP_GMYTHTV_VERSION,
   226       g_param_spec_int ("mythtv-version", "mythtv-version",
   227           "Change MythTV version", 26, 30, 26, G_PARAM_READWRITE));
   228 
   229   g_object_class_install_property
   230       (gobject_class, PROP_GMYTHTV_LIVEID,
   231       g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
   232           "Change MythTV version",
   233           0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
   234 
   235   g_object_class_install_property
   236       (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
   237       g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
   238           "Sets the MythTV chain ID (from TV Chain)", "", G_PARAM_READWRITE));
   239 
   240   g_object_class_install_property
   241       (gobject_class, PROP_GMYTHTV_LIVE,
   242       g_param_spec_boolean ("mythtv-live", "mythtv-live",
   243           "Enable MythTV Live TV content streaming", FALSE, G_PARAM_READWRITE));
   244 
   245   g_object_class_install_property
   246       (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
   247       g_param_spec_boolean ("mythtv-enable-timing-position",
   248           "mythtv-enable-timing-position",
   249           "Enable MythTV Live TV content size continuous updating", FALSE,
   250           G_PARAM_READWRITE));
   251 
   252   g_object_class_install_property
   253       (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
   254       g_param_spec_string ("mythtv-channel", "mythtv-channel",
   255           "Change MythTV channel number",
   256           "", G_PARAM_READWRITE));
   257 
   258 #ifndef GST_DISABLE_GST_DEBUG
   259   g_object_class_install_property
   260       (gobject_class, PROP_GMYTHTV_DBG,
   261       g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
   262           "Enable MythTV debug messages", FALSE, G_PARAM_READWRITE));
   263 #endif
   264 
   265   gstbasesrc_class->start = gst_mythtv_src_start;
   266   gstbasesrc_class->stop = gst_mythtv_src_stop;
   267   gstbasesrc_class->get_size = gst_mythtv_src_get_size;
   268   gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
   269 
   270   gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
   271   gstpushsrc_class->create = gst_mythtv_src_create;
   272 
   273   GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
   274       "MythTV Client Source");
   275 }
   276 
   277 static void
   278 gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
   279 {
   280   this->file = NULL;
   281 
   282   this->unique_setup = FALSE;
   283 
   284   this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
   285 
   286   this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
   287 
   288   this->bytes_read = 0;
   289 
   290   this->prev_content_size = 0;
   291 
   292   this->content_size = 0;
   293   this->read_offset = 0;
   294 
   295   this->content_size_last = 0;
   296 
   297   this->live_tv = FALSE;
   298 
   299   this->enable_timing_position = FALSE;
   300   this->update_prog_chain = FALSE;
   301 
   302   this->user_agent = g_strdup ("mythtvsrc");
   303   this->update_prog_chain = FALSE;
   304 
   305   this->channel_name = NULL;
   306 
   307   this->eos = FALSE;
   308 
   309   this->bytes_queue = NULL;
   310 
   311   this->wait_to_transfer = 0;
   312 
   313   gst_base_src_set_format (GST_BASE_SRC (this), GST_FORMAT_BYTES);
   314 
   315   gst_pad_set_event_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
   316       gst_mythtv_src_handle_event);
   317   gst_pad_set_query_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
   318       gst_mythtv_src_handle_query);
   319 
   320 }
   321 
   322 static void
   323 gst_mythtv_src_clear (GstMythtvSrc *mythtv_src)
   324 {
   325     
   326   if (mythtv_src->spawn_livetv) {
   327     g_object_unref (mythtv_src->spawn_livetv);
   328     mythtv_src->spawn_livetv = NULL;
   329   }
   330 
   331   if (mythtv_src->file) {
   332     g_object_unref (mythtv_src->file);
   333     mythtv_src->file = NULL;
   334   }
   335 
   336   if (mythtv_src->backend_info) {
   337     g_object_unref (mythtv_src->backend_info);
   338     mythtv_src->backend_info = NULL;
   339   }
   340 
   341   if (mythtv_src->uri_name) {
   342     g_free (mythtv_src->uri_name);
   343   }
   344 
   345   if (mythtv_src->user_agent) {
   346     g_free (mythtv_src->user_agent);
   347   }
   348 
   349   if (mythtv_src->bytes_queue) {
   350     g_byte_array_free (mythtv_src->bytes_queue, TRUE);
   351     mythtv_src->bytes_queue = NULL;
   352   }
   353   
   354 }
   355 
   356 static void
   357 gst_mythtv_src_finalize (GObject * gobject)
   358 {
   359   GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
   360 
   361   gst_mythtv_src_clear (this);
   362 
   363   G_OBJECT_CLASS (parent_class)->finalize (gobject);
   364 }
   365 
   366 static GMythFileReadResult
   367 do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr)
   368 {
   369   gint read = 0;
   370   guint sizetoread = size;
   371   gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
   372   GMythFileReadResult result;
   373 
   374   GST_LOG_OBJECT (src, "Starting: Reading %d bytes...", sizetoread);
   375 
   376   /* Loop sending the Myth File Transfer request:
   377    * Retry whilst authentication fails and we supply it. */
   378 
   379   while (sizetoread == size && --max_iters > 0) {
   380     /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
   381     if ( IS_GMYTH_FILE_LOCAL(src->file) )
   382       result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(src->file),
   383           data_ptr, sizetoread, src->live_tv);      
   384     else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
   385       result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(src->file),
   386           data_ptr, sizetoread, src->live_tv);
   387 
   388     if (data_ptr->len > 0) {
   389       read += data_ptr->len;
   390       sizetoread -= data_ptr->len;
   391     } else if (data_ptr->len < 0) {
   392       if (src->live_tv == FALSE) {
   393         result = GMYTH_FILE_READ_EOF;
   394         goto eos;
   395       } else {
   396         if (result == GMYTH_FILE_READ_ERROR) {  /* -314 */
   397           GST_INFO_OBJECT (src, "[LiveTV] FileTransfer READ_ERROR!");
   398           goto done;
   399         } else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) {      /* -315 */
   400           GST_INFO_OBJECT (src,
   401               "[LiveTV] FileTransfer - Go to the next program chain!");
   402           continue;
   403         }
   404         goto done;
   405       }
   406 
   407     } else if (data_ptr->len == 0)
   408       goto done;
   409 
   410     if (read == sizetoread)
   411       goto done;
   412   }
   413 
   414   if ((read < 0 && !src->live_tv) || max_iters == 0){
   415     result = GMYTH_FILE_READ_EOF;
   416     goto eos;
   417   }
   418 
   419   goto done;
   420 
   421 eos:
   422   src->eos = TRUE;
   423 
   424 done:
   425   return result;
   426 }
   427 
   428 static GstFlowReturn
   429 gst_mythtv_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
   430 {
   431   GstMythtvSrc *src;
   432   GstFlowReturn ret = GST_FLOW_OK;
   433   guint buffer_size_inter = 0;
   434 
   435   src = GST_MYTHTV_SRC (psrc);
   436 
   437   /* The caller should know the number of bytes and not read beyond EOS. */
   438   if (G_UNLIKELY (src->eos))
   439     goto eos;
   440   if (G_UNLIKELY (src->update_prog_chain))
   441     goto change_progchain;
   442 
   443   GST_DEBUG_OBJECT (src, "offset = %" G_GUINT64_FORMAT ", size = %d...",
   444       src->read_offset, MAX_READ_SIZE);
   445 
   446   GST_DEBUG_OBJECT (src, "Create: buffer_remain: %d, buffer_size = %d.",
   447       (gint) src->buffer_remain, src->bytes_queue->len);
   448 
   449 program_chain_changed:
   450   /* just get from the byte array, no network effort... */
   451   if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE) {
   452   	GByteArray *buffer;
   453     GMythFileReadResult result = GMYTH_FILE_READ_OK;
   454   	
   455     buffer = NULL;
   456     buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain);
   457 
   458     if (buffer_size_inter > REQUEST_MAX_SIZE)
   459       buffer_size_inter = REQUEST_MAX_SIZE;
   460 
   461     buffer = g_byte_array_new ();
   462 
   463     result = do_read_request_response (src, buffer_size_inter, buffer);
   464 
   465     if (G_UNLIKELY (buffer->len < 0)) {
   466     	
   467     	if (buffer != NULL) {
   468 	      g_byte_array_free (buffer, TRUE);
   469 	      buffer = NULL;
   470 	    }
   471 	    
   472       if (src->live_tv || ( result == GMYTH_FILE_READ_NEXT_PROG_CHAIN ))
   473         goto change_progchain;
   474       else
   475         goto read_error;
   476     } else if (G_UNLIKELY (read == 0)) {
   477     	
   478     	if (buffer != NULL) {
   479 	      g_byte_array_free (buffer, TRUE);
   480 	      buffer = NULL;
   481 	    }
   482 	    
   483       if (!src->live_tv)
   484         goto done;
   485       else
   486         goto program_chain_changed;
   487     }
   488 
   489     if (G_UNLIKELY (src->update_prog_chain))
   490     {
   491     	if (buffer != NULL) {
   492 	      g_byte_array_free (buffer, TRUE);
   493 	      buffer = NULL;
   494 	    }
   495       goto change_progchain;      
   496     }
   497 
   498     src->bytes_queue =
   499         g_byte_array_append (src->bytes_queue, buffer->data, buffer->len);
   500     if (buffer->len > buffer_size_inter)
   501       GST_WARNING_OBJECT (src,
   502           "INCREASED buffer size! Backend sent more than we ask him... (%d)",
   503           abs (buffer->len - buffer_size_inter));
   504 
   505     src->buffer_remain += buffer->len;
   506 
   507     if (buffer != NULL) {
   508       g_byte_array_free (buffer, TRUE);
   509       buffer = NULL;
   510     }
   511 
   512     GST_DEBUG_OBJECT (src,
   513         "BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "
   514         "OFFSET = %llu, CONTENT SIZE = %llu.", read,
   515         src->bytes_read, src->read_offset, src->content_size);
   516 
   517   }
   518 
   519   guint buffer_size =
   520       (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
   521 
   522   *outbuf = gst_buffer_new ();
   523 
   524   /* gets the first buffer_size bytes from the byte array buffer variable */
   525   /* guint8 *buf = g_memdup( src->bytes_queue->data, buffer_size ); */
   526 
   527   GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d",
   528       (buffer_size_inter ==
   529           0) ? "NO, got from buffer" : "YES, go see the backend's log file",
   530       src->buffer_remain);
   531 
   532   GST_BUFFER_SIZE (*outbuf) = buffer_size;
   533   GST_BUFFER_MALLOCDATA (*outbuf) = g_malloc0 (GST_BUFFER_SIZE (*outbuf));
   534   GST_BUFFER_DATA (*outbuf) = GST_BUFFER_MALLOCDATA (*outbuf);
   535   g_memmove (GST_BUFFER_DATA ((*outbuf)), src->bytes_queue->data,
   536       GST_BUFFER_SIZE (*outbuf));
   537   GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
   538   GST_BUFFER_OFFSET_END (*outbuf) =
   539       src->read_offset + GST_BUFFER_SIZE (*outbuf);
   540 
   541   src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
   542 
   543   src->read_offset += GST_BUFFER_SIZE (*outbuf);
   544   src->bytes_read += GST_BUFFER_SIZE (*outbuf);
   545   GST_DEBUG_OBJECT (src, "Buffer output with size: %d",
   546       GST_BUFFER_SIZE (*outbuf));
   547 
   548   /* flushs the newly buffer got from byte array */
   549   src->bytes_queue =
   550       g_byte_array_remove_range (src->bytes_queue, 0, buffer_size);
   551 
   552   GST_DEBUG_OBJECT ( src, "Got buffer: BUFFER --->SIZE = %d, OFFSET = %llu, "
   553       "OFFSET_END = %llu.", GST_BUFFER_SIZE (*outbuf),
   554       GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
   555 
   556   GST_DEBUG_OBJECT (src, "CONTENT_SIZE = %llu, BYTES_READ = %llu.",
   557       src->content_size, src->bytes_read);
   558 
   559   if ( G_UNLIKELY (src->eos) || ( !src->live_tv
   560           && ( src->bytes_read >= src->content_size ) ) )
   561     goto eos;
   562 
   563 done:
   564   {
   565     const gchar *reason = gst_flow_get_name (ret);
   566 
   567     GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
   568     return ret;
   569   }
   570 eos:
   571   {
   572     const gchar *reason = gst_flow_get_name (ret);
   573 
   574     GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
   575     return GST_FLOW_UNEXPECTED;
   576   }
   577   /* ERRORS */
   578 read_error:
   579   {
   580     GST_ELEMENT_ERROR (src, RESOURCE, READ,
   581         (NULL), ("Could not read any bytes (%i, %s)", read, src->uri_name));
   582     return GST_FLOW_ERROR;
   583   }
   584 change_progchain:
   585   {
   586     GST_ELEMENT_ERROR (src, RESOURCE, READ,
   587         (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
   588             src->uri_name));
   589 
   590 /*
   591     TODO: need to send a new segment event to NUVDemux? 
   592     gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
   593         gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0));
   594 */
   595 
   596     goto program_chain_changed;
   597   }
   598 
   599 }
   600 
   601 gint64
   602 gst_mythtv_src_get_position (GstMythtvSrc * src)
   603 {
   604 
   605   gint64 size_tmp = 0;
   606   guint max_tries = 2;
   607 
   608   if (src->live_tv == TRUE && (abs (src->content_size - src->bytes_read) <
   609           GMYTHTV_TRANSFER_MAX_BUFFER)) {
   610 
   611   get_file_pos:
   612     g_usleep (10);
   613     size_tmp = gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
   614     if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER))
   615       src->content_size = size_tmp;
   616     else if (size_tmp > 0 && --max_tries > 0)
   617       goto get_file_pos;
   618     GST_LOG_OBJECT (src, "GET_POSITION: file_position = %lld", size_tmp);
   619     /* sets the last content size amount before it can be updated */
   620     src->prev_content_size = src->content_size;
   621   }
   622 
   623   return src->content_size;
   624 
   625 }
   626 
   627 static gboolean
   628 gst_mythtv_src_do_seek (GstBaseSrc * base, GstSegment * segment)
   629 {
   630   GstMythtvSrc *src = GST_MYTHTV_SRC (base);
   631   gint64 new_offset = -1;
   632   gint64 actual_seek = segment->start;
   633   gboolean ret = TRUE;
   634 
   635   GST_LOG_OBJECT (src, "seek, segment: %" GST_SEGMENT_FORMAT, segment);
   636 
   637   if (segment->format == GST_FORMAT_TIME) {
   638     goto done;
   639   }
   640   GST_LOG_OBJECT (src,
   641       "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)",
   642       actual_seek, src->read_offset);
   643   /* verify if it needs to seek */
   644   if (src->read_offset != actual_seek) {
   645     
   646     /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
   647     if ( IS_GMYTH_FILE_LOCAL(src->file) )
   648       new_offset =
   649           gmyth_file_local_seek ( GMYTH_FILE_LOCAL(src->file), segment->start, G_SEEK_SET);
   650     else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
   651       new_offset =
   652           gmyth_file_transfer_seek ( GMYTH_FILE_TRANSFER(src->file), segment->start, SEEK_SET);
   653 
   654     GST_LOG_OBJECT (src,
   655         "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.",
   656         segment->start, src->read_offset, new_offset);
   657     if (G_UNLIKELY (new_offset < 0)) {
   658       ret = FALSE;
   659       if (!src->live_tv)
   660         goto eos;
   661     }
   662 
   663     src->read_offset = new_offset;
   664 
   665     if (ret == FALSE) {
   666       GST_INFO_OBJECT (src, "Failed to set the SEEK on segment!");
   667     }
   668 
   669   }
   670 
   671 done:
   672   return ret;
   673 
   674 eos:
   675   {
   676     GST_DEBUG_OBJECT (src, "EOS found on seeking!!!");
   677     return FALSE;
   678   }
   679 
   680 }
   681 
   682 /* create a socket for connecting to remote server */
   683 static gboolean
   684 gst_mythtv_src_start (GstBaseSrc * bsrc)
   685 {
   686   GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
   687 
   688   GString *chain_id_local = NULL;  
   689   GMythURI *gmyth_uri = NULL;
   690   gboolean ret = TRUE;
   691 
   692   if (src->unique_setup == FALSE) {
   693     src->unique_setup = TRUE;
   694   } else {
   695     goto done;
   696   }
   697   
   698   gmyth_uri = gmyth_uri_new_with_value( src->uri_name );
   699 
   700   src->backend_info = gmyth_backend_info_new_with_uri (src->uri_name);
   701   src->live_tv |= gmyth_uri_is_livetv( gmyth_uri );
   702   /* testing UPnP... */
   703   /* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */
   704   if ( src->live_tv ) {
   705     src->spawn_livetv = gmyth_livetv_new (src->backend_info);
   706     
   707     gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
   708     if ( ch != NULL )
   709     	src->channel_name = ch;
   710     	
   711     if (src->channel_name != NULL) {
   712       if (gmyth_livetv_channel_name_setup (src->spawn_livetv, src->channel_name) == FALSE) {
   713         GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
   714         ret = FALSE;
   715         goto init_failed;
   716       }
   717     } else {
   718       if (gmyth_livetv_setup (src->spawn_livetv) == FALSE) {
   719         GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
   720         ret = FALSE;
   721         goto init_failed;
   722       }
   723     }
   724 
   725     /* testing change channel... */
   726     /* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */
   727 
   728     src->file = GMYTH_FILE( gmyth_livetv_create_file_transfer (src->spawn_livetv) );
   729 
   730     if (NULL == src->file) {
   731       GST_INFO_OBJECT (src, "[LiveTV] FileTransfer equals to NULL");
   732       ret = FALSE;
   733       goto init_failed;
   734     }
   735     
   736     /* Check if the file is local to this specific client renderer */
   737     if ( gmyth_uri_is_local_file(gmyth_uri) )
   738       ret = gmyth_file_local_open( GMYTH_FILE_LOCAL(src->file) );
   739     else
   740       ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(src->file), src->spawn_livetv->uri != NULL ? 
   741                 gmyth_uri_get_path(src->spawn_livetv->uri) : 
   742                 src->spawn_livetv->proginfo->pathname->str );
   743     
   744     /* sets the mythtvsrc "location" property */
   745     g_object_set (src, "location", gmyth_file_get_uri (src->file), NULL);
   746 
   747 		if ( !ret )
   748 		{
   749 			GST_INFO_OBJECT (src, "Error: couldn't open the FileTransfer from LiveTV source!" );
   750 			g_object_unref( src->file );
   751 			src->file = NULL;
   752 			goto init_failed;
   753 		}
   754   } else {
   755     
   756     /* Check if the file is local to this specific client renderer, and tries to open
   757      * a local connection
   758      */
   759     if ( gmyth_uri_is_local_file(gmyth_uri) )
   760     {
   761       src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info));
   762       ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( src->file ) );
   763     } else {
   764       src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info));
   765       ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(src->file), src->uri_name );
   766     }
   767 
   768   } /* if (else) - recorded FileTransfer */
   769 
   770   if (NULL == src->file) {
   771     GST_INFO_OBJECT (src, "FileTransfer is NULL");
   772     goto init_failed;
   773   }
   774   /*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */
   775 
   776   if (ret == FALSE) {
   777 #ifndef GST_DISABLE_GST_DEBUG
   778     if (src->mythtv_msgs_dbg)
   779       GST_INFO_OBJECT (src,
   780           "MythTV FileTransfer request failed when setting up socket connection!");
   781 #endif
   782     goto begin_req_failed;
   783   }
   784 
   785   GST_INFO_OBJECT (src,
   786       "MythTV FileTransfer filesize = %lld, content_size = %lld!",
   787       gmyth_file_get_filesize( src->file ), src->content_size);
   788 
   789   src->content_size = gmyth_file_get_filesize (src->file);
   790 
   791   src->do_start = FALSE;
   792 
   793   /* this is used for the buffer cache */
   794   src->bytes_queue = g_byte_array_sized_new (INTERNAL_BUFFER_SIZE);
   795   src->buffer_remain = 0;
   796   
   797   gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
   798       gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
   799           src->content_size, 0));
   800 
   801 done:
   802 	/*if ( gmyth_uri != NULL )
   803 	{
   804   	g_object_unref( gmyth_uri );
   805   	gmyth_uri = NULL;
   806 	}*/
   807 
   808   if (chain_id_local != NULL) {
   809     g_string_free (chain_id_local, TRUE);
   810     chain_id_local = NULL;
   811   }
   812 
   813   return TRUE;
   814 
   815   /* ERRORS */
   816 init_failed:
   817   {
   818     if (src->spawn_livetv != NULL)
   819       g_object_unref (src->spawn_livetv);
   820 
   821     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   822         (NULL), ("Could not initialize MythTV library (%i, %s)", ret,
   823             src->uri_name));
   824     return FALSE;
   825   }
   826 begin_req_failed:
   827   {
   828     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   829         (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret,
   830             src->uri_name));
   831     return FALSE;
   832   }
   833 
   834 }
   835 
   836 static gboolean
   837 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
   838 {
   839   GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
   840   gboolean ret = TRUE;
   841 
   842   GST_LOG_OBJECT (src, "Differs from previous content size: %d (max.: %d)",
   843       abs (src->content_size - src->prev_content_size),
   844       GMYTHTV_TRANSFER_MAX_BUFFER);
   845 
   846   if (src->live_tv) {
   847     ret = FALSE;
   848   } else if (src->live_tv && src->enable_timing_position
   849       && (abs (src->content_size - src->bytes_read) <
   850           GMYTHTV_TRANSFER_MAX_BUFFER)) {
   851 
   852     gint64 new_offset =
   853         gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
   854     if (new_offset > 0 && new_offset > src->content_size) {
   855       src->content_size = new_offset;
   856     } else if (new_offset < src->content_size) {
   857       src->update_prog_chain = TRUE;
   858     }
   859 
   860   }
   861 
   862   *size = src->content_size;
   863   GST_LOG_OBJECT (src, "Content size = %lld", src->content_size);
   864 
   865   return ret;
   866 
   867 }
   868 
   869 /* close the socket and associated resources
   870  * used both to recover from errors and go to NULL state */
   871 static gboolean
   872 gst_mythtv_src_stop (GstBaseSrc * bsrc)
   873 {
   874   GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
   875   
   876   gst_mythtv_src_clear (src);
   877 
   878   /* src->eos = FALSE; */
   879 
   880   return TRUE;
   881 }
   882 
   883 static gboolean
   884 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
   885 {
   886   GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
   887   gint64 cont_size = 0;
   888   gboolean ret = FALSE;
   889 
   890   switch (GST_EVENT_TYPE (event)) {
   891     case GST_EVENT_EOS:
   892       GST_WARNING_OBJECT (src, "Got EOS event");
   893 
   894       if (src->live_tv) {
   895         cont_size = gst_mythtv_src_get_position (src);
   896         if (cont_size > src->content_size) {
   897           src->content_size = cont_size;
   898           src->eos = FALSE;
   899         } else {
   900           src->eos = TRUE;
   901           gst_element_set_state (GST_ELEMENT (src), GST_STATE_NULL);
   902           gst_element_set_locked_state (GST_ELEMENT (src), FALSE);
   903         }
   904       }
   905       break;
   906     default:
   907       ret = gst_pad_event_default (pad, event);
   908   }
   909 
   910   return ret;
   911 }
   912 
   913 static gboolean
   914 gst_mythtv_src_is_seekable (GstBaseSrc * push_src)
   915 {
   916   return TRUE;
   917 }
   918 
   919 static gboolean
   920 gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query)
   921 {
   922   gboolean res = FALSE;
   923   GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad));
   924   GstFormat formt;
   925 
   926   switch (GST_QUERY_TYPE (query)) {
   927     case GST_QUERY_POSITION:
   928     {
   929       gst_query_parse_position (query, &formt, NULL);
   930       if (formt == GST_FORMAT_BYTES) {
   931         gst_query_set_position (query, formt, myth->read_offset);
   932         GST_DEBUG_OBJECT (myth, "POS %" G_GINT64_FORMAT, myth->read_offset);
   933         res = TRUE;
   934       } else if (formt == GST_FORMAT_TIME) {
   935         res = gst_pad_query_default (pad, query);
   936       }
   937       break;
   938     }
   939     case GST_QUERY_DURATION:
   940     {
   941 #if 0
   942       if (myth->duration != 0) {
   943         gint64 total;
   944         gint64 fps;
   945 
   946         fps = nuv->h->i_fpsn / nuv->h->i_fpsd;
   947         total =
   948             gst_util_uint64_scale_int (GST_SECOND, nuv->h->i_video_blocks, fps);
   949       }
   950 #endif
   951 
   952       gst_query_parse_duration (query, &formt, NULL);
   953       if (formt == GST_FORMAT_BYTES) {
   954         gst_query_set_duration (query, formt, myth->content_size);
   955         GST_DEBUG_OBJECT (myth, "SIZE %" G_GINT64_FORMAT, myth->content_size);
   956         res = TRUE;
   957       } else if (formt == GST_FORMAT_TIME) {
   958         res = gst_pad_query_default (pad, query);
   959       }
   960       break;
   961     }
   962     default:
   963     {
   964       res = gst_pad_query_default (pad, query);
   965       break;
   966     }
   967   }
   968 
   969   gst_object_unref (myth);
   970 
   971   return res;
   972 }
   973 
   974 static GstStateChangeReturn
   975 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
   976 {
   977   GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
   978   GstMythtvSrc *src = GST_MYTHTV_SRC (element);
   979 
   980   switch (transition) {
   981     case GST_STATE_CHANGE_NULL_TO_READY:
   982       break;
   983     case GST_STATE_CHANGE_READY_TO_PAUSED:
   984     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
   985       if (src->live_tv) {
   986         if (!gmyth_recorder_send_frontend_ready_command (src->spawn_livetv->
   987                 recorder))
   988           GST_WARNING_OBJECT (src,
   989               "Couldn't send the FRONTEND_READY message to the backend!");
   990         else
   991           GST_DEBUG_OBJECT (src, "FRONTEND_READY was sent to the backend");
   992       }
   993       break;
   994     default:
   995       break;
   996   }
   997 
   998   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
   999   if (ret == GST_STATE_CHANGE_FAILURE)
  1000     return ret;
  1001 
  1002   switch (transition) {
  1003     case GST_STATE_CHANGE_READY_TO_NULL:
  1004       break;
  1005     case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
  1006     case GST_STATE_CHANGE_PAUSED_TO_READY:
  1007       break;
  1008     default:
  1009       break;
  1010   }
  1011 
  1012   return ret;
  1013 }
  1014 
  1015 static void
  1016 gst_mythtv_src_set_property (GObject * object, guint prop_id,
  1017     const GValue * value, GParamSpec * pspec)
  1018 {
  1019   GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
  1020 
  1021   GST_OBJECT_LOCK (mythtvsrc);
  1022   switch (prop_id) {
  1023     case PROP_LOCATION:
  1024     {
  1025       if (!g_value_get_string (value)) {
  1026         GST_WARNING ("location property cannot be NULL");
  1027 	break;
  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 	break;
  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     case PROP_GMYTHTV_CHANNEL_NUM:
  1080     {
  1081       mythtvsrc->channel_name = g_value_dup_string (value);
  1082       break;
  1083     }
  1084     default:
  1085       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  1086       break;
  1087   }
  1088 
  1089   GST_OBJECT_UNLOCK (mythtvsrc);
  1090 }
  1091 
  1092 static void
  1093 gst_mythtv_src_get_property (GObject * object, guint prop_id,
  1094     GValue * value, GParamSpec * pspec)
  1095 {
  1096   GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
  1097 
  1098   GST_OBJECT_LOCK (mythtvsrc);
  1099   switch (prop_id) {
  1100     case PROP_LOCATION:
  1101     {
  1102       g_value_set_string (value, mythtvsrc->uri_name);
  1103       break;
  1104     }
  1105 #ifndef GST_DISABLE_GST_DEBUG
  1106     case PROP_GMYTHTV_DBG:
  1107       g_value_set_boolean (value, mythtvsrc->mythtv_msgs_dbg);
  1108       break;
  1109 #endif
  1110     case PROP_GMYTHTV_VERSION:
  1111     {
  1112       g_value_set_int (value, mythtvsrc->mythtv_version);
  1113       break;
  1114     }
  1115     case PROP_GMYTHTV_LIVEID:
  1116     {
  1117       g_value_set_int (value, mythtvsrc->live_tv_id);
  1118       break;
  1119     }
  1120     case PROP_GMYTHTV_LIVE:
  1121       g_value_set_boolean (value, mythtvsrc->live_tv);
  1122       break;
  1123     case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
  1124       g_value_set_boolean (value, mythtvsrc->enable_timing_position);
  1125       break;
  1126     case PROP_GMYTHTV_LIVE_CHAINID:
  1127     {
  1128       g_value_set_string (value, mythtvsrc->live_chain_id);
  1129       break;
  1130     }
  1131     case PROP_GMYTHTV_CHANNEL_NUM:
  1132     {
  1133       g_value_set_string (value, mythtvsrc->channel_name);
  1134       break;
  1135     }
  1136     default:
  1137       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  1138       break;
  1139   }
  1140   GST_OBJECT_UNLOCK (mythtvsrc);
  1141 }
  1142 
  1143 static gboolean
  1144 plugin_init (GstPlugin * plugin)
  1145 {
  1146   return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
  1147       GST_TYPE_MYTHTV_SRC);
  1148 }
  1149 
  1150 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
  1151     GST_VERSION_MINOR,
  1152     "mythtv",
  1153     "lib MythTV src",
  1154     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
  1155 
  1156 
  1157 /*** GSTURIHANDLER INTERFACE *************************************************/
  1158 static guint
  1159 gst_mythtv_src_uri_get_type (void)
  1160 {
  1161   return GST_URI_SRC;
  1162 }
  1163 
  1164 static gchar **
  1165 gst_mythtv_src_uri_get_protocols (void)
  1166 {
  1167   static gchar *protocols[] = { "myth", "myths", NULL };
  1168 
  1169   return protocols;
  1170 }
  1171 
  1172 static const gchar *
  1173 gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
  1174 {
  1175   GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
  1176 
  1177   return src->uri_name;
  1178 }
  1179 
  1180 static gboolean
  1181 gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
  1182 {
  1183   GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
  1184 
  1185   gchar *protocol;
  1186 
  1187   protocol = gst_uri_get_protocol (uri);
  1188   if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
  1189     g_free (protocol);
  1190     return FALSE;
  1191   }
  1192   g_free (protocol);
  1193   g_object_set (src, "location", uri, NULL);
  1194 
  1195   return TRUE;
  1196 }
  1197 
  1198 static void
  1199 gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
  1200 {
  1201   GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
  1202 
  1203   iface->get_type = gst_mythtv_src_uri_get_type;
  1204   iface->get_protocols = gst_mythtv_src_uri_get_protocols;
  1205   iface->get_uri = gst_mythtv_src_uri_get_uri;
  1206   iface->set_uri = gst_mythtv_src_uri_set_uri;
  1207 }
  1208 
  1209 void
  1210 size_header_handler (void *userdata, const char *value)
  1211 {
  1212   GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
  1213 
  1214   GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);
  1215 }