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