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