gst-gmyth/mythsrc/gstmythtvsrc.c
author rosfran
Wed May 16 23:21:58 2007 +0100 (2007-05-16)
branchtrunk
changeset 677 1b7b4d7f714c
parent 608 43ce4ea2f9fb
child 679 c9757033ccc6
permissions -rwxr-xr-x
[svn r683] More test configuration options.
     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   PROP_GMYTHTV_MAX_TRY
   136 };
   137 
   138 static void gst_mythtv_src_clear (GstMythtvSrc *mythtv_src);
   139 
   140 static void gst_mythtv_src_finalize (GObject * gobject);
   141 
   142 static GstFlowReturn gst_mythtv_src_create (GstPushSrc * psrc,
   143     GstBuffer ** outbuf);
   144 
   145 static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
   146 static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
   147 static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
   148 static gboolean gst_mythtv_src_is_seekable (GstBaseSrc * push_src);
   149 
   150 static gboolean gst_mythtv_src_do_seek (GstBaseSrc * base,
   151     GstSegment * segment);
   152 
   153 static GstStateChangeReturn
   154 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
   155 
   156 static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
   157     const GValue * value, GParamSpec * pspec);
   158 static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
   159     GValue * value, GParamSpec * pspec);
   160 
   161 static void gst_mythtv_src_uri_handler_init (gpointer g_iface,
   162     gpointer iface_data);
   163 
   164 static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query);
   165 
   166 static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
   167 
   168 static GMythFileReadResult do_read_request_response (GstMythtvSrc * src, guint size,
   169     GByteArray * data_ptr);
   170 
   171 static void
   172 _urihandler_init (GType type)
   173 {
   174   static const GInterfaceInfo urihandler_info = {
   175     gst_mythtv_src_uri_handler_init,
   176     NULL,
   177     NULL
   178   };
   179 
   180   g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
   181 
   182   GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV src");
   183 }
   184 
   185 GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
   186     GST_TYPE_PUSH_SRC, _urihandler_init)
   187 
   188      static void gst_mythtv_src_base_init (gpointer g_class)
   189 {
   190   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
   191 
   192   gst_element_class_add_pad_template (element_class,
   193       gst_static_pad_template_get (&srctemplate));
   194 
   195   gst_element_class_set_details (element_class, &gst_mythtv_src_details);
   196 
   197   element_class->change_state = gst_mythtv_src_change_state;
   198 
   199 }
   200 
   201 static void
   202 gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
   203 {
   204   GObjectClass *gobject_class;
   205   GstPushSrcClass *gstpushsrc_class;
   206   GstBaseSrcClass *gstbasesrc_class;
   207 
   208   gobject_class = (GObjectClass *) klass;
   209   gstbasesrc_class = (GstBaseSrcClass *) klass;
   210   gstpushsrc_class = (GstPushSrcClass *) klass;
   211 
   212   gobject_class->set_property = gst_mythtv_src_set_property;
   213   gobject_class->get_property = gst_mythtv_src_get_property;
   214   gobject_class->finalize = gst_mythtv_src_finalize;
   215 
   216   g_object_class_install_property
   217       (gobject_class, PROP_LOCATION,
   218       g_param_spec_string ("location", "Location",
   219           "The location. In the form:"
   220           "\n\t\t\tmyth://a.com/file.nuv"
   221           "\n\t\t\tmyth://a.com:23223/file.nuv "
   222           "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
   223           "", G_PARAM_READWRITE));
   224 
   225   g_object_class_install_property
   226       (gobject_class, PROP_GMYTHTV_VERSION,
   227       g_param_spec_int ("mythtv-version", "mythtv-version",
   228           "Change MythTV version", 26, 30, 26, G_PARAM_READWRITE));
   229 
   230   g_object_class_install_property
   231       (gobject_class, PROP_GMYTHTV_LIVEID,
   232       g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
   233           "Change MythTV version",
   234           0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
   235 
   236   g_object_class_install_property
   237       (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
   238       g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
   239           "Sets the MythTV chain ID (from TV Chain)", "", G_PARAM_READWRITE));
   240 
   241   g_object_class_install_property
   242       (gobject_class, PROP_GMYTHTV_LIVE,
   243       g_param_spec_boolean ("mythtv-live", "mythtv-live",
   244           "Enable MythTV Live TV content streaming", FALSE, G_PARAM_READWRITE));
   245 
   246   g_object_class_install_property
   247       (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
   248       g_param_spec_boolean ("mythtv-enable-timing-position",
   249           "mythtv-enable-timing-position",
   250           "Enable MythTV Live TV content size continuous updating", FALSE,
   251           G_PARAM_READWRITE));
   252 
   253   g_object_class_install_property
   254       (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
   255       g_param_spec_string ("mythtv-channel", "mythtv-channel",
   256           "Change MythTV channel number",
   257           "", G_PARAM_READWRITE));
   258 
   259   g_object_class_install_property
   260       (gobject_class, PROP_GMYTHTV_MAX_TRY,
   261       g_param_spec_int ("max-try", "max-try",
   262           "Set the max try for get MythTV free recorder",
   263           0, G_MAXINT, 10,  G_PARAM_READWRITE));
   264 
   265 
   266 #ifndef GST_DISABLE_GST_DEBUG
   267   g_object_class_install_property
   268       (gobject_class, PROP_GMYTHTV_DBG,
   269       g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
   270           "Enable MythTV debug messages", FALSE, G_PARAM_READWRITE));
   271 #endif
   272 
   273   gstbasesrc_class->start = gst_mythtv_src_start;
   274   gstbasesrc_class->stop = gst_mythtv_src_stop;
   275   gstbasesrc_class->get_size = gst_mythtv_src_get_size;
   276   gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
   277 
   278   gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
   279   gstpushsrc_class->create = gst_mythtv_src_create;
   280 
   281   GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
   282       "MythTV Client Source");
   283 }
   284 
   285 static void
   286 gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
   287 {
   288   this->file = NULL;
   289 
   290   this->unique_setup = FALSE;
   291 
   292   this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
   293 
   294   this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
   295 
   296   this->bytes_read = 0;
   297 
   298   this->prev_content_size = 0;
   299 
   300   this->content_size = 0;
   301   this->read_offset = 0;
   302 
   303   this->content_size_last = 0;
   304 
   305   this->live_tv = FALSE;
   306 
   307   this->enable_timing_position = FALSE;
   308   this->update_prog_chain = FALSE;
   309 
   310   this->user_agent = g_strdup ("mythtvsrc");
   311   this->update_prog_chain = FALSE;
   312 
   313   this->channel_name = NULL;
   314 
   315   this->eos = FALSE;
   316 
   317   this->bytes_queue = NULL;
   318 
   319   this->wait_to_transfer = 0;
   320 
   321   gst_base_src_set_format (GST_BASE_SRC (this), GST_FORMAT_BYTES);
   322 
   323   gst_pad_set_event_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
   324       gst_mythtv_src_handle_event);
   325   gst_pad_set_query_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
   326       gst_mythtv_src_handle_query);
   327 
   328 }
   329 
   330 static void
   331 gst_mythtv_src_clear (GstMythtvSrc *mythtv_src)
   332 {
   333   mythtv_src->unique_setup = FALSE;
   334 
   335   if (mythtv_src->spawn_livetv) {
   336     g_object_unref (mythtv_src->spawn_livetv);
   337     mythtv_src->spawn_livetv = NULL;
   338   }
   339 
   340   if (mythtv_src->file) {
   341     g_object_unref (mythtv_src->file);
   342     mythtv_src->file = NULL;
   343   }
   344 
   345   if (mythtv_src->backend_info) {
   346     g_object_unref (mythtv_src->backend_info);
   347     mythtv_src->backend_info = NULL;
   348   }
   349 
   350   if (mythtv_src->bytes_queue) {
   351     g_byte_array_free (mythtv_src->bytes_queue, TRUE);
   352     mythtv_src->bytes_queue = NULL;
   353   }
   354   
   355 }
   356 
   357 static void
   358 gst_mythtv_src_finalize (GObject * gobject)
   359 {
   360   GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
   361 
   362   gst_mythtv_src_clear (this);
   363 
   364   if (this->uri_name) {
   365     g_free (this->uri_name);
   366     this->uri_name = NULL;
   367   }
   368 
   369   if (this->user_agent) {
   370     g_free (this->user_agent);
   371     this->user_agent = NULL;
   372   }
   373 
   374   G_OBJECT_CLASS (parent_class)->finalize (gobject);
   375 }
   376 
   377 static GMythFileReadResult
   378 do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr)
   379 {
   380   gint read = 0;
   381   guint sizetoread = size;
   382   gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
   383   GMythFileReadResult result;
   384 
   385   GST_LOG_OBJECT (src, "Starting: Reading %d bytes...", sizetoread);
   386 
   387   /* Loop sending the Myth File Transfer request:
   388    * Retry whilst authentication fails and we supply it. */
   389 
   390   while (sizetoread == size && --max_iters > 0) {
   391     /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
   392     if ( IS_GMYTH_FILE_LOCAL(src->file) )
   393       result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(src->file),
   394           data_ptr, sizetoread, src->live_tv);      
   395     else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
   396       result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(src->file),
   397           data_ptr, sizetoread, src->live_tv);
   398 
   399     if (data_ptr->len > 0) {
   400       read += data_ptr->len;
   401       sizetoread -= data_ptr->len;
   402     } else if (data_ptr->len < 0) {
   403       if (src->live_tv == FALSE) {
   404         result = GMYTH_FILE_READ_EOF;
   405         goto eos;
   406       } else {
   407         if (result == GMYTH_FILE_READ_ERROR) {  /* -314 */
   408           GST_INFO_OBJECT (src, "[LiveTV] FileTransfer READ_ERROR!");
   409           goto done;
   410         } else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) {      /* -315 */
   411           GST_INFO_OBJECT (src,
   412               "[LiveTV] FileTransfer - Go to the next program chain!");
   413           continue;
   414         }
   415         goto done;
   416       }
   417 
   418     } else if (data_ptr->len == 0)
   419       goto done;
   420 
   421     if (read == sizetoread)
   422       goto done;
   423   }
   424 
   425   if ((read < 0 && !src->live_tv) || max_iters == 0){
   426     result = GMYTH_FILE_READ_EOF;
   427     goto eos;
   428   }
   429 
   430   goto done;
   431 
   432 eos:
   433   src->eos = TRUE;
   434 
   435 done:
   436   return result;
   437 }
   438 
   439 static GstFlowReturn
   440 gst_mythtv_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
   441 {
   442   GstMythtvSrc *src;
   443   GstFlowReturn ret = GST_FLOW_OK;
   444   guint buffer_size_inter = 0;
   445 
   446   src = GST_MYTHTV_SRC (psrc);
   447 
   448   /* The caller should know the number of bytes and not read beyond EOS. */
   449   if (G_UNLIKELY (src->eos))
   450     goto eos;
   451   if (G_UNLIKELY (src->update_prog_chain))
   452     goto change_progchain;
   453 
   454   /*
   455   GST_DEBUG_OBJECT (src, "offset = %" G_GUINT64_FORMAT ", size = %d...",
   456       src->read_offset, MAX_READ_SIZE);
   457 
   458   GST_DEBUG_OBJECT (src, "Create: buffer_remain: %d, buffer_size = %d.",
   459       (gint) src->buffer_remain, src->bytes_queue->len);
   460   */	  
   461 
   462 program_chain_changed:
   463   /* just get from the byte array, no network effort... */
   464   if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE) {
   465   	GByteArray *buffer;
   466     GMythFileReadResult result = GMYTH_FILE_READ_OK;
   467   	
   468     buffer = NULL;
   469     buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain);
   470 
   471     if (buffer_size_inter > REQUEST_MAX_SIZE)
   472       buffer_size_inter = REQUEST_MAX_SIZE;
   473 
   474     buffer = g_byte_array_new ();
   475 
   476     result = do_read_request_response (src, buffer_size_inter, buffer);
   477 
   478     if (G_UNLIKELY (buffer->len < 0)) {
   479     	
   480     	if (buffer != NULL) {
   481 	      g_byte_array_free (buffer, TRUE);
   482 	      buffer = NULL;
   483 	    }
   484 	    
   485       if (src->live_tv || ( result == GMYTH_FILE_READ_NEXT_PROG_CHAIN ))
   486         goto change_progchain;
   487       else
   488         goto read_error;
   489     } else if (G_UNLIKELY (read == 0)) {
   490     	
   491     	if (buffer != NULL) {
   492 	      g_byte_array_free (buffer, TRUE);
   493 	      buffer = NULL;
   494 	    }
   495 	    
   496       if (!src->live_tv)
   497         goto done;
   498       else
   499         goto program_chain_changed;
   500     }
   501 
   502     if (G_UNLIKELY (src->update_prog_chain))
   503     {
   504     	if (buffer != NULL) {
   505 	      g_byte_array_free (buffer, TRUE);
   506 	      buffer = NULL;
   507 	    }
   508       goto change_progchain;      
   509     }
   510 
   511     src->bytes_queue =
   512         g_byte_array_append (src->bytes_queue, buffer->data, buffer->len);
   513     if (buffer->len > buffer_size_inter)
   514       GST_WARNING_OBJECT (src,
   515           "INCREASED buffer size! Backend sent more than we ask him... (%d)",
   516           abs (buffer->len - buffer_size_inter));
   517 
   518     src->buffer_remain += buffer->len;
   519 
   520     if (buffer != NULL) {
   521       g_byte_array_free (buffer, TRUE);
   522       buffer = NULL;
   523     }
   524 
   525 	/*
   526     GST_DEBUG_OBJECT (src,
   527         "BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "
   528         "OFFSET = %llu, CONTENT SIZE = %llu.", read,
   529         src->bytes_read, src->read_offset, src->content_size);
   530 	*/		
   531 
   532   }
   533 
   534   guint buffer_size =
   535       (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
   536 
   537   *outbuf = gst_buffer_new ();
   538 
   539   /* gets the first buffer_size bytes from the byte array buffer variable */
   540   /* guint8 *buf = g_memdup( src->bytes_queue->data, buffer_size ); */
   541 
   542   /*
   543   GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d",
   544       (buffer_size_inter ==
   545           0) ? "NO, got from buffer" : "YES, go see the backend's log file",
   546       src->buffer_remain);
   547 	  */
   548 
   549   GST_BUFFER_SIZE (*outbuf) = buffer_size;
   550   GST_BUFFER_MALLOCDATA (*outbuf) = g_malloc0 (GST_BUFFER_SIZE (*outbuf));
   551   GST_BUFFER_DATA (*outbuf) = GST_BUFFER_MALLOCDATA (*outbuf);
   552   g_memmove (GST_BUFFER_DATA ((*outbuf)), src->bytes_queue->data,
   553       GST_BUFFER_SIZE (*outbuf));
   554   GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
   555   GST_BUFFER_OFFSET_END (*outbuf) =
   556       src->read_offset + GST_BUFFER_SIZE (*outbuf);
   557 
   558   src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
   559 
   560   src->read_offset += GST_BUFFER_SIZE (*outbuf);
   561   src->bytes_read += GST_BUFFER_SIZE (*outbuf);
   562   //GST_DEBUG_OBJECT (src, "Buffer output with size: %d",
   563   //    GST_BUFFER_SIZE (*outbuf));
   564 
   565   /* flushs the newly buffer got from byte array */
   566   src->bytes_queue =
   567       g_byte_array_remove_range (src->bytes_queue, 0, buffer_size);
   568 
   569   if ( G_UNLIKELY (src->eos) || ( !src->live_tv
   570           && ( src->bytes_read >= src->content_size ) ) )
   571     goto eos;
   572 
   573 done:
   574   {
   575     const gchar *reason = gst_flow_get_name (ret);
   576     return ret;
   577   }
   578 eos:
   579   {
   580     const gchar *reason = gst_flow_get_name (ret);
   581 
   582     GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
   583     return GST_FLOW_UNEXPECTED;
   584   }
   585   /* ERRORS */
   586 read_error:
   587   {
   588     GST_ELEMENT_ERROR (src, RESOURCE, READ,
   589         (NULL), ("Could not read any bytes (%i, %s)", read, src->uri_name));
   590     return GST_FLOW_ERROR;
   591   }
   592 change_progchain:
   593   {
   594     GST_ELEMENT_ERROR (src, RESOURCE, READ,
   595         (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
   596             src->uri_name));
   597 
   598 /*
   599     TODO: need to send a new segment event to NUVDemux? 
   600     gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
   601         gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0));
   602 */
   603 
   604     goto program_chain_changed;
   605   }
   606 
   607 }
   608 
   609 gint64
   610 gst_mythtv_src_get_position (GstMythtvSrc * src)
   611 {
   612 
   613   gint64 size_tmp = 0;
   614   guint max_tries = 2;
   615 
   616   if (src->live_tv == TRUE && (abs (src->content_size - src->bytes_read) <
   617           GMYTHTV_TRANSFER_MAX_BUFFER)) {
   618 
   619   get_file_pos:
   620     g_usleep (10);
   621     size_tmp = gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
   622     if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER))
   623       src->content_size = size_tmp;
   624     else if (size_tmp > 0 && --max_tries > 0)
   625       goto get_file_pos;
   626     GST_LOG_OBJECT (src, "GET_POSITION: file_position = %lld", size_tmp);
   627     /* sets the last content size amount before it can be updated */
   628     src->prev_content_size = src->content_size;
   629   }
   630 
   631   return src->content_size;
   632 
   633 }
   634 
   635 static gboolean
   636 gst_mythtv_src_do_seek (GstBaseSrc * base, GstSegment * segment)
   637 {
   638   GstMythtvSrc *src = GST_MYTHTV_SRC (base);
   639   gint64 new_offset = -1;
   640   gint64 actual_seek = segment->start;
   641   gboolean ret = TRUE;
   642 
   643   GST_LOG_OBJECT (src, "seek, segment: %" GST_SEGMENT_FORMAT, segment);
   644 
   645   if (segment->format == GST_FORMAT_TIME) {
   646     goto done;
   647   }
   648   GST_LOG_OBJECT (src,
   649       "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)",
   650       actual_seek, src->read_offset);
   651   /* verify if it needs to seek */
   652   if (src->read_offset != actual_seek) {
   653     
   654     /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
   655     if ( IS_GMYTH_FILE_LOCAL(src->file) )
   656       new_offset =
   657           gmyth_file_local_seek ( GMYTH_FILE_LOCAL(src->file), segment->start, G_SEEK_SET);
   658     else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
   659       new_offset =
   660           gmyth_file_transfer_seek ( GMYTH_FILE_TRANSFER(src->file), segment->start, SEEK_SET);
   661 
   662     GST_LOG_OBJECT (src,
   663         "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.",
   664         segment->start, src->read_offset, new_offset);
   665     if (G_UNLIKELY (new_offset < 0)) {
   666       ret = FALSE;
   667       if (!src->live_tv)
   668         goto eos;
   669     }
   670 
   671     src->read_offset = new_offset;
   672 
   673     if (ret == FALSE) {
   674       GST_INFO_OBJECT (src, "Failed to set the SEEK on segment!");
   675     }
   676 
   677   }
   678 
   679 done:
   680   return ret;
   681 
   682 eos:
   683   {
   684     GST_DEBUG_OBJECT (src, "EOS found on seeking!!!");
   685     return FALSE;
   686   }
   687 
   688 }
   689 
   690 /* create a socket for connecting to remote server */
   691 static gboolean
   692 gst_mythtv_src_start (GstBaseSrc * bsrc)
   693 {
   694   GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
   695 
   696   GString *chain_id_local = NULL;  
   697   GMythURI *gmyth_uri = NULL;
   698   gboolean ret = TRUE;
   699   GstMessage *msg;
   700 
   701   if (src->unique_setup == FALSE) {
   702     src->unique_setup = TRUE;
   703   } else {
   704     goto done;
   705   }
   706   
   707   gmyth_uri = gmyth_uri_new_with_value (src->uri_name);
   708   src->backend_info = gmyth_backend_info_new_with_uri (src->uri_name);
   709   src->live_tv = gmyth_uri_is_livetv( gmyth_uri );
   710   /* testing UPnP... */
   711   /* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */
   712   if ( src->live_tv ) {
   713     src->spawn_livetv = gmyth_livetv_new (src->backend_info);
   714     
   715     gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
   716     if ( ch != NULL )
   717     	src->channel_name = ch;
   718     	
   719     if (src->channel_name != NULL) {
   720       if (gmyth_livetv_channel_name_setup (src->spawn_livetv, src->channel_name) == FALSE) {
   721         GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
   722         ret = FALSE;
   723         goto init_failed;
   724       }
   725     } else {
   726       if (gmyth_livetv_setup (src->spawn_livetv) == FALSE) {
   727         GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
   728         ret = FALSE;
   729         goto init_failed;
   730       }
   731     }
   732 
   733     /* testing change channel... */
   734     /* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */
   735 
   736     src->file = GMYTH_FILE( gmyth_livetv_create_file_transfer (src->spawn_livetv) );
   737 
   738     if (NULL == src->file) {
   739       GST_INFO_OBJECT (src, "[LiveTV] FileTransfer equals to NULL");
   740       ret = FALSE;
   741       goto init_failed;
   742     }
   743     
   744     /* Check if the file is local to this specific client renderer */
   745     if ( gmyth_uri_is_local_file(gmyth_uri) )
   746       ret = gmyth_file_local_open( GMYTH_FILE_LOCAL(src->file) );
   747     else
   748       ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(src->file), src->spawn_livetv->uri != NULL ? 
   749                 gmyth_uri_get_path(src->spawn_livetv->uri) : 
   750                 src->spawn_livetv->proginfo->pathname->str );
   751     
   752     /* sets the mythtvsrc "location" property */
   753     g_object_set (src, "location", gmyth_file_get_uri (src->file), NULL);
   754 
   755 		if ( !ret )
   756 		{
   757 			GST_INFO_OBJECT (src, "Error: couldn't open the FileTransfer from LiveTV source!" );
   758 			g_object_unref( src->file );
   759 			src->file = NULL;
   760 			goto init_failed;
   761 		}
   762   } else {
   763     
   764     /* Check if the file is local to this specific client renderer, and tries to open
   765      * a local connection
   766      */
   767     if ( gmyth_uri_is_local_file(gmyth_uri) )
   768     {
   769       src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info));
   770       ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( src->file ) );
   771     } else {
   772       src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info));
   773       ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(src->file), src->uri_name );
   774     }
   775 
   776   } /* if (else) - recorded FileTransfer */
   777 
   778   if (NULL == src->file) {
   779     GST_INFO_OBJECT (src, "FileTransfer is NULL");
   780     goto init_failed;
   781   }
   782   /*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */
   783 
   784   if (ret == FALSE) {
   785 #ifndef GST_DISABLE_GST_DEBUG
   786     if (src->mythtv_msgs_dbg)
   787       GST_INFO_OBJECT (src,
   788           "MythTV FileTransfer request failed when setting up socket connection!");
   789 #endif
   790     goto begin_req_failed;
   791   }
   792 
   793   GST_INFO_OBJECT (src,
   794       "MythTV FileTransfer filesize = %lld, content_size = %lld!",
   795       gmyth_file_get_filesize( src->file ), src->content_size);
   796 
   797   src->content_size = gmyth_file_get_filesize (src->file);
   798 
   799   msg = gst_message_new_duration (GST_OBJECT (src), GST_FORMAT_BYTES, src->content_size);
   800   gst_element_post_message (GST_ELEMENT (src), msg);
   801 
   802 
   803   src->do_start = FALSE;
   804 
   805   /* this is used for the buffer cache */
   806   src->bytes_queue = g_byte_array_sized_new (INTERNAL_BUFFER_SIZE);
   807   src->buffer_remain = 0;
   808   
   809   gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
   810       gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
   811           src->content_size, 0));
   812 
   813 done:
   814 	if (gmyth_uri != NULL)
   815 	{
   816   	    g_object_unref (gmyth_uri);
   817       	gmyth_uri = NULL;
   818 	}
   819 
   820     if (chain_id_local != NULL) {
   821         g_string_free (chain_id_local, TRUE);
   822         chain_id_local = NULL;
   823     }
   824 
   825     return TRUE;
   826 
   827     /* ERRORS */
   828 init_failed:
   829 	if (gmyth_uri != NULL)
   830 	{
   831   	    g_object_unref (gmyth_uri);
   832       	gmyth_uri = NULL;
   833 	}
   834 
   835     if (src->spawn_livetv != NULL) {
   836         g_object_unref (src->spawn_livetv);
   837         src->spawn_livetv = NULL;
   838     }
   839     
   840     /*
   841     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   842             (NULL), ("Could not initialize MythTV library (%i, %s)", ret,
   843             src->uri_name));
   844     */            
   845 
   846     gst_mythtv_src_clear (src);
   847 
   848     return FALSE;
   849 begin_req_failed:
   850 	if (gmyth_uri != NULL)
   851 	{
   852   	    g_object_unref (gmyth_uri);
   853       	gmyth_uri = NULL;
   854 	}
   855 
   856     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
   857         (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret,
   858             src->uri_name));
   859     return FALSE;
   860 
   861 }
   862 
   863 static gboolean
   864 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
   865 {
   866   GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
   867   gboolean ret = TRUE;
   868 
   869   GST_LOG_OBJECT (src, "Differs from previous content size: %d (max.: %d)",
   870       abs (src->content_size - src->prev_content_size),
   871       GMYTHTV_TRANSFER_MAX_BUFFER);
   872 
   873   if (src->live_tv) {
   874     ret = FALSE;
   875   } else if (src->live_tv && src->enable_timing_position
   876       && (abs (src->content_size - src->bytes_read) <
   877           GMYTHTV_TRANSFER_MAX_BUFFER)) {
   878 
   879     gint64 new_offset =
   880         gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
   881     if (new_offset > 0 && new_offset > src->content_size) {
   882       src->content_size = new_offset;
   883     } else if (new_offset < src->content_size) {
   884       src->update_prog_chain = TRUE;
   885     }
   886 
   887   }
   888 
   889   *size = src->content_size;
   890   GST_LOG_OBJECT (src, "Content size = %lld", src->content_size);
   891 
   892   return ret;
   893 
   894 }
   895 
   896 /* close the socket and associated resources
   897  * used both to recover from errors and go to NULL state */
   898 static gboolean
   899 gst_mythtv_src_stop (GstBaseSrc * bsrc)
   900 {
   901   GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
   902   
   903   gst_mythtv_src_clear (src);
   904 
   905   /* src->eos = FALSE; */
   906 
   907   return TRUE;
   908 }
   909 
   910 static gboolean
   911 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
   912 {
   913   GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
   914   gint64 cont_size = 0;
   915   gboolean ret = FALSE;
   916 
   917   switch (GST_EVENT_TYPE (event)) {
   918     case GST_EVENT_EOS:
   919       GST_WARNING_OBJECT (src, "Got EOS event");
   920 
   921       if (src->live_tv) {
   922         cont_size = gst_mythtv_src_get_position (src);
   923         if (cont_size > src->content_size) {
   924           src->content_size = cont_size;
   925           src->eos = FALSE;
   926         } else {
   927           src->eos = TRUE;
   928           gst_element_set_state (GST_ELEMENT (src), GST_STATE_NULL);
   929           gst_element_set_locked_state (GST_ELEMENT (src), FALSE);
   930         }
   931       }
   932       break;
   933     default:
   934       ret = gst_pad_event_default (pad, event);
   935   }
   936 
   937   return ret;
   938 }
   939 
   940 static gboolean
   941 gst_mythtv_src_is_seekable (GstBaseSrc * push_src)
   942 {
   943   return TRUE;
   944 }
   945 
   946 static gboolean
   947 gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query)
   948 {
   949   gboolean res = FALSE;
   950   GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad));
   951   GstFormat formt;
   952 
   953 
   954   switch (GST_QUERY_TYPE (query)) {
   955     case GST_QUERY_POSITION:
   956     {
   957       gst_query_parse_position (query, &formt, NULL);
   958       if (formt == GST_FORMAT_BYTES) {
   959         gst_query_set_position (query, formt, myth->read_offset);
   960         GST_DEBUG_OBJECT (myth, "POS %" G_GINT64_FORMAT, myth->read_offset);
   961         res = TRUE;
   962       } else if (formt == GST_FORMAT_TIME) {
   963         res = gst_pad_query_default (pad, query);
   964       }
   965       break;
   966     }
   967     case GST_QUERY_DURATION:
   968     {
   969       gst_query_parse_duration (query, &formt, NULL);
   970       if (formt == GST_FORMAT_BYTES) {
   971 		gint64 size = myth->content_size;			  
   972         gst_query_set_duration (query, GST_FORMAT_BYTES, 10);
   973         GST_DEBUG_OBJECT (myth, "SIZE %" G_GINT64_FORMAT, size);
   974         res = TRUE;
   975       } else if (formt == GST_FORMAT_TIME) {
   976         res = gst_pad_query_default (pad, query);
   977       }
   978       break;
   979     }
   980     default:
   981     {
   982       res = gst_pad_query_default (pad, query);
   983       break;
   984     }
   985   }
   986 
   987   gst_object_unref (myth);
   988 
   989   return res;
   990 }
   991 
   992 static GstStateChangeReturn
   993 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
   994 {
   995   GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
   996   GstMythtvSrc *src = GST_MYTHTV_SRC (element);
   997 
   998   switch (transition) {
   999     case GST_STATE_CHANGE_NULL_TO_READY:
  1000       break;
  1001     case GST_STATE_CHANGE_READY_TO_PAUSED:
  1002     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
  1003       if (src->live_tv) {
  1004         if (!gmyth_recorder_send_frontend_ready_command (src->spawn_livetv->
  1005                 recorder))
  1006           GST_WARNING_OBJECT (src,
  1007               "Couldn't send the FRONTEND_READY message to the backend!");
  1008         else
  1009           GST_DEBUG_OBJECT (src, "FRONTEND_READY was sent to the backend");
  1010       }
  1011       break;
  1012     default:
  1013       break;
  1014   }
  1015 
  1016   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
  1017   if (ret == GST_STATE_CHANGE_FAILURE)
  1018     return ret;
  1019 
  1020   switch (transition) {
  1021     case GST_STATE_CHANGE_READY_TO_NULL:
  1022 	  gst_mythtv_src_clear (src);			
  1023       break;
  1024     case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
  1025     case GST_STATE_CHANGE_PAUSED_TO_READY:
  1026       break;
  1027     default:
  1028       break;
  1029   }
  1030 
  1031   return ret;
  1032 }
  1033 
  1034 static void
  1035 gst_mythtv_src_set_property (GObject * object, guint prop_id,
  1036     const GValue * value, GParamSpec * pspec)
  1037 {
  1038   GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
  1039 
  1040   GST_OBJECT_LOCK (mythtvsrc);
  1041   switch (prop_id) {
  1042     case PROP_LOCATION:
  1043     {
  1044       if (!g_value_get_string (value)) {
  1045         GST_WARNING ("location property cannot be NULL");
  1046 	break;
  1047       }
  1048 
  1049       if (mythtvsrc->uri_name != NULL) {
  1050         g_free (mythtvsrc->uri_name);
  1051         mythtvsrc->uri_name = NULL;
  1052       }
  1053       mythtvsrc->uri_name = g_value_dup_string (value);
  1054 
  1055       break;
  1056     }
  1057 #ifndef GST_DISABLE_GST_DEBUG
  1058     case PROP_GMYTHTV_DBG:
  1059     {
  1060       mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
  1061       break;
  1062     }
  1063 #endif
  1064     case PROP_GMYTHTV_VERSION:
  1065     {
  1066       mythtvsrc->mythtv_version = g_value_get_int (value);
  1067       break;
  1068     }
  1069     case PROP_GMYTHTV_LIVEID:
  1070     {
  1071       mythtvsrc->live_tv_id = g_value_get_int (value);
  1072       break;
  1073     }
  1074     case PROP_GMYTHTV_LIVE:
  1075     {
  1076       mythtvsrc->live_tv = g_value_get_boolean (value);
  1077       break;
  1078     }
  1079     case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
  1080     {
  1081       mythtvsrc->enable_timing_position = g_value_get_boolean (value);
  1082       break;
  1083     }
  1084     case PROP_GMYTHTV_LIVE_CHAINID:
  1085     {
  1086       if (!g_value_get_string (value)) {
  1087         GST_WARNING ("MythTV Live chainid property cannot be NULL");
  1088 	break;
  1089       }
  1090 
  1091       if (mythtvsrc->live_chain_id != NULL) {
  1092         g_free (mythtvsrc->live_chain_id);
  1093         mythtvsrc->live_chain_id = NULL;
  1094       }
  1095       mythtvsrc->live_chain_id = g_value_dup_string (value);
  1096       break;
  1097     }
  1098     case PROP_GMYTHTV_CHANNEL_NUM:
  1099     {
  1100       mythtvsrc->channel_name = g_value_dup_string (value);
  1101       break;
  1102     }
  1103     case PROP_GMYTHTV_MAX_TRY:
  1104     {
  1105       mythtvsrc->max_try = g_value_get_int (value);
  1106       break;
  1107     }
  1108     default:
  1109       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  1110       break;
  1111   }
  1112 
  1113   GST_OBJECT_UNLOCK (mythtvsrc);
  1114 }
  1115 
  1116 static void
  1117 gst_mythtv_src_get_property (GObject * object, guint prop_id,
  1118     GValue * value, GParamSpec * pspec)
  1119 {
  1120   GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
  1121 
  1122   GST_OBJECT_LOCK (mythtvsrc);
  1123   switch (prop_id) {
  1124     case PROP_LOCATION:
  1125     {
  1126       g_value_set_string (value, mythtvsrc->uri_name);
  1127       break;
  1128     }
  1129 #ifndef GST_DISABLE_GST_DEBUG
  1130     case PROP_GMYTHTV_DBG:
  1131       g_value_set_boolean (value, mythtvsrc->mythtv_msgs_dbg);
  1132       break;
  1133 #endif
  1134     case PROP_GMYTHTV_VERSION:
  1135     {
  1136       g_value_set_int (value, mythtvsrc->mythtv_version);
  1137       break;
  1138     }
  1139     case PROP_GMYTHTV_LIVEID:
  1140     {
  1141       g_value_set_int (value, mythtvsrc->live_tv_id);
  1142       break;
  1143     }
  1144     case PROP_GMYTHTV_LIVE:
  1145       g_value_set_boolean (value, mythtvsrc->live_tv);
  1146       break;
  1147     case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
  1148       g_value_set_boolean (value, mythtvsrc->enable_timing_position);
  1149       break;
  1150     case PROP_GMYTHTV_LIVE_CHAINID:
  1151     {
  1152       g_value_set_string (value, mythtvsrc->live_chain_id);
  1153       break;
  1154     }
  1155     case PROP_GMYTHTV_CHANNEL_NUM:
  1156     {
  1157       g_value_set_string (value, mythtvsrc->channel_name);
  1158       break;
  1159     }
  1160     case PROP_GMYTHTV_MAX_TRY:
  1161     {
  1162       g_value_set_int (value, mythtvsrc->max_try);
  1163       break;
  1164     }
  1165 
  1166     default:
  1167       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  1168       break;
  1169   }
  1170   GST_OBJECT_UNLOCK (mythtvsrc);
  1171 }
  1172 
  1173 static gboolean
  1174 plugin_init (GstPlugin * plugin)
  1175 {
  1176   return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
  1177       GST_TYPE_MYTHTV_SRC);
  1178 }
  1179 
  1180 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
  1181     GST_VERSION_MINOR,
  1182     "mythtv",
  1183     "lib MythTV src",
  1184     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
  1185 
  1186 
  1187 /*** GSTURIHANDLER INTERFACE *************************************************/
  1188 static guint
  1189 gst_mythtv_src_uri_get_type (void)
  1190 {
  1191   return GST_URI_SRC;
  1192 }
  1193 
  1194 static gchar **
  1195 gst_mythtv_src_uri_get_protocols (void)
  1196 {
  1197   static gchar *protocols[] = { "myth", "myths", NULL };
  1198 
  1199   return protocols;
  1200 }
  1201 
  1202 static const gchar *
  1203 gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
  1204 {
  1205   GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
  1206 
  1207   return src->uri_name;
  1208 }
  1209 
  1210 static gboolean
  1211 gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
  1212 {
  1213   GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
  1214 
  1215   gchar *protocol;
  1216 
  1217   protocol = gst_uri_get_protocol (uri);
  1218   if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
  1219     g_free (protocol);
  1220     return FALSE;
  1221   }
  1222   g_free (protocol);
  1223   g_object_set (src, "location", uri, NULL);
  1224 
  1225   return TRUE;
  1226 }
  1227 
  1228 static void
  1229 gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
  1230 {
  1231   GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
  1232 
  1233   iface->get_type = gst_mythtv_src_uri_get_type;
  1234   iface->get_protocols = gst_mythtv_src_uri_get_protocols;
  1235   iface->get_uri = gst_mythtv_src_uri_get_uri;
  1236   iface->set_uri = gst_mythtv_src_uri_set_uri;
  1237 }
  1238 
  1239 void
  1240 size_header_handler (void *userdata, const char *value)
  1241 {
  1242   GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
  1243 
  1244   GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);
  1245 }