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