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