gst-plugins-mythtv/src/gstmythtvsrc.c
branchtrunk
changeset 98 d0f379fc4173
parent 95 51d013028674
child 100 f4be69980934
     1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c	Fri Nov 17 18:39:47 2006 +0000
     1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c	Wed Nov 22 00:16:33 2006 +0000
     1.3 @@ -24,6 +24,8 @@
     1.4  #include <gmyth/gmyth_socket.h>
     1.5  #include <gmyth/gmyth_tvchain.h>
     1.6  
     1.7 +#include <gmyth/gmyth_context.h>
     1.8 +
     1.9  #include <string.h>
    1.10  #include <unistd.h>
    1.11  
    1.12 @@ -42,12 +44,12 @@
    1.13  //( 32*1024  )
    1.14  
    1.15  /* 4*1024 ??? */
    1.16 -#define MAX_READ_SIZE              		6*1024
    1.17 +#define MAX_READ_SIZE              		4*1024
    1.18  //( 32*1024 )
    1.19  
    1.20 -#define GST_FLOW_ERROR_NO_DATA  		-101
    1.21 +#define GST_FLOW_ERROR_NO_DATA  			-101
    1.22  
    1.23 -#define INTERNAL_BUFFER_SIZE			30*1024
    1.24 +#define INTERNAL_BUFFER_SIZE					64*1024
    1.25  
    1.26  /* stablish a maximum iteration value to the IS_RECORDING message */
    1.27  static guint wait_to_transfer = 0;
    1.28 @@ -81,20 +83,20 @@
    1.29  
    1.30  static void gst_mythtv_src_finalize (GObject * gobject);
    1.31  
    1.32 -/*
    1.33  static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset, 
    1.34  	guint size, GstBuffer ** outbuf);
    1.35 -*/
    1.36  
    1.37 -//static GstFlowReturn gst_mythtv_src_chain ( GstPad* pad, GstBuffer* outbuf );
    1.38 -static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf );
    1.39 +//static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf );
    1.40  
    1.41  static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
    1.42  static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
    1.43  static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
    1.44  static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src );
    1.45  
    1.46 -static gboolean gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment );
    1.47 +//static void gst_mythtv_src_get_times (GstBaseSrc * src, GstBuffer * buffer,
    1.48 +//   GstClockTime * start, GstClockTime * end);
    1.49 +
    1.50 +//static gboolean gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment );
    1.51  
    1.52  static gboolean gst_mythtv_src_next_program_chain ( GstMythtvSrc *src );
    1.53  
    1.54 @@ -135,8 +137,8 @@
    1.55  //GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
    1.56  //    GST_TYPE_BASE_SRC, _urihandler_init)
    1.57      
    1.58 -GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
    1.59 -    GST_TYPE_PUSH_SRC, _urihandler_init)
    1.60 +GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
    1.61 +    GST_TYPE_BASE_SRC, _urihandler_init)
    1.62      
    1.63  static void
    1.64  gst_mythtv_src_base_init (gpointer g_class)
    1.65 @@ -156,12 +158,12 @@
    1.66  gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
    1.67  {
    1.68    GObjectClass *gobject_class; 
    1.69 -  GstPushSrcClass *gstpushsrc_class;
    1.70 +  //GstPushSrcClass *gstpushsrc_class;
    1.71    GstBaseSrcClass *gstbasesrc_class;
    1.72  
    1.73    gobject_class = (GObjectClass *) klass;
    1.74    gstbasesrc_class = (GstBaseSrcClass *) klass;
    1.75 -  gstpushsrc_class = (GstPushSrcClass *) klass;
    1.76 +  //gstpushsrc_class = (GstPushSrcClass *) klass;
    1.77  
    1.78    gobject_class->set_property = gst_mythtv_src_set_property;
    1.79    gobject_class->get_property = gst_mythtv_src_get_property;
    1.80 @@ -231,8 +233,10 @@
    1.81    gstbasesrc_class->get_size = gst_mythtv_src_get_size;
    1.82    gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
    1.83    
    1.84 -  gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
    1.85 -  gstpushsrc_class->create = gst_mythtv_src_create;
    1.86 +  //gstbasesrc_class->get_times = gst_mythtv_src_get_times;
    1.87 +  
    1.88 +  //gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
    1.89 +  gstbasesrc_class->create = gst_mythtv_src_create;
    1.90      
    1.91    GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
    1.92        "MythTV Client Source");
    1.93 @@ -271,14 +275,14 @@
    1.94    
    1.95    this->eos = FALSE;
    1.96    
    1.97 -  this->adapter = NULL;
    1.98 +  this->bytes_queue = NULL;
    1.99    
   1.100    //this->th_read_ahead = NULL;
   1.101    
   1.102    this->th_mutex = NULL;
   1.103    
   1.104 -  this->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
   1.105 -  gst_element_add_pad (GST_ELEMENT (this), this->srcpad);
   1.106 +  //this->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
   1.107 +  //gst_element_add_pad (GST_ELEMENT (this), this->srcpad);
   1.108    
   1.109    gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES );  
   1.110  
   1.111 @@ -338,7 +342,6 @@
   1.112    /* Loop sending the Myth File Transfer request:
   1.113     * Retry whilst authentication fails and we supply it. */
   1.114    gint len = 0;
   1.115 -  //*data_ptr = g_malloc0( size );
   1.116    
   1.117    //while ( sizetoread > 0 ) {
   1.118  
   1.119 @@ -362,7 +365,7 @@
   1.120  	if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
   1.121  	  src->update_prog_chain = TRUE;
   1.122  	  goto done;	  	
   1.123 -	} else if ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) {
   1.124 +	} /*if ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) {
   1.125  	    src->update_prog_chain = TRUE;
   1.126  	    if ( src->enable_timing_position ) {
   1.127  	      gint64 size_tmp = 0;
   1.128 @@ -375,7 +378,7 @@
   1.129  	      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   1.130  		  __FUNCTION__, size_tmp );
   1.131  	    }
   1.132 -	  }
   1.133 +	  }*/
   1.134  	goto done;
   1.135        }
   1.136  
   1.137 @@ -400,161 +403,6 @@
   1.138  
   1.139  #if 0
   1.140  static GstFlowReturn
   1.141 -gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf)
   1.142 -{
   1.143 -  GstMythtvSrc *src;
   1.144 -  GstFlowReturn ret = GST_FLOW_OK;
   1.145 -  gint read = -1;
   1.146 -  gint adapter_size = -1;
   1.147 -  
   1.148 -  guint max_adapter_rep = 40;
   1.149 -  
   1.150 -  src = GST_MYTHTV_SRC (psrc);
   1.151 -  
   1.152 -  /* The caller should know the number of bytes and not read beyond EOS. */
   1.153 -  if (G_UNLIKELY (src->eos))
   1.154 -    goto eos;
   1.155 -  if ( G_UNLIKELY (src->update_prog_chain) )
   1.156 -    goto change_progchain;
   1.157 -
   1.158 -  g_static_rec_mutex_lock( th_mutexth_mutex );
   1.159 -  
   1.160 -  while ( ( ( adapter_size = gst_adapter_available_fast( src->adapter ) ) < size ) &&
   1.161 -  		--max_adapter_rep > 0 )
   1.162 -  {
   1.163 -  	g_print ( "[%s] %d - Waiting for read_ahead task...\n", __FUNCTION__, max_adapter_rep );
   1.164 -  	GST_TASK_WAIT( src->th_read_ahead );
   1.165 -  }
   1.166 -  	
   1.167 -  g_static_rec_mutex_unlock( th_mutexth_mutex );
   1.168 -
   1.169 -	gint64 new_offset = -1;
   1.170 -	/* just get from the adapter, no network effort... */
   1.171 -	if ( offset > src->adapter_offset && size <= adapter_size )	
   1.172 -	{
   1.173 -		
   1.174 -		GstBuffer *buf = gst_adapter_take_buffer( src->adapter, size );
   1.175 -		*outbuf = gst_buffer_create_sub( buf, offset, size );
   1.176 -		src->read_offset = new_offset = offset;
   1.177 -		read = size;
   1.178 -		
   1.179 -		gst_adapter_flush( src->adapter, size );
   1.180 -		
   1.181 -	} else {
   1.182 -		/* no data on adapter... do all these mythtv network calls! */
   1.183 -		
   1.184 -		/* verify if it needs to seek */
   1.185 -		if ( src->read_offset != offset ) 
   1.186 -  	{
   1.187 -		
   1.188 -	  	new_offset = gmyth_file_transfer_seek( src->file_transfer, offset, SEEK_SET );
   1.189 -	  	
   1.190 -	    g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
   1.191 -	    	__FUNCTION__, src->read_offset, new_offset );
   1.192 -	    if ( G_UNLIKELY (new_offset < 0 ) )
   1.193 -	    {
   1.194 -	      if ( src->live_tv )
   1.195 -	      	goto change_progchain;
   1.196 -	      else
   1.197 -	      	goto eos;
   1.198 -	    }
   1.199 -	    
   1.200 -  	}
   1.201 -	
   1.202 -    src->read_offset = offset;
   1.203 -  	
   1.204 -	  /* Create the buffer. */
   1.205 -	  ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
   1.206 -	      src->read_offset, size,
   1.207 -	      GST_PAD_CAPS ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)) ), outbuf);
   1.208 -	
   1.209 -	  if (G_UNLIKELY (ret != GST_FLOW_OK)) {
   1.210 -	    if ( src->live_tv )
   1.211 -	    	goto change_progchain;
   1.212 -	    else
   1.213 -	    	goto done;
   1.214 -	  }
   1.215 -	  
   1.216 -	  read = do_read_request_response ( src, src->read_offset, size, outbuf ); 
   1.217 -  	
   1.218 -	}
   1.219 -
   1.220 -  if (G_UNLIKELY (src->update_prog_chain) )
   1.221 -    goto change_progchain;
   1.222 -
   1.223 -  if (G_UNLIKELY (read <= 0) || *outbuf == NULL) {
   1.224 -  	if ( src->live_tv )
   1.225 -    	goto change_progchain;
   1.226 -    else
   1.227 -    	goto read_error;
   1.228 -  }
   1.229 -  
   1.230 -  if ( read > 0 ) {
   1.231 -    src->read_offset += read;
   1.232 -    src->bytes_read += read;
   1.233 -    
   1.234 -    #if 0
   1.235 -    g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
   1.236 -			"OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, 
   1.237 -			src->read_offset, src->content_size );
   1.238 -
   1.239 -    GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
   1.240 -    //GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
   1.241 -    //GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
   1.242 -    //g_memmove( GST_BUFFER_DATA( *outbuf ), data_ptr, read );
   1.243 -    GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
   1.244 -    GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
   1.245 -
   1.246 -    g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
   1.247 -			"OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), 
   1.248 -			GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
   1.249 -		#endif
   1.250 -			
   1.251 -  }
   1.252 -
   1.253 -done:
   1.254 - {
   1.255 -    const gchar *reason = gst_flow_get_name (ret);
   1.256 -
   1.257 -    GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
   1.258 -  	return ret;
   1.259 - }
   1.260 -eos:
   1.261 -  {
   1.262 -    const gchar *reason = gst_flow_get_name (ret);
   1.263 -
   1.264 -    GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
   1.265 -    return GST_FLOW_UNEXPECTED;
   1.266 -  }
   1.267 -  /* ERRORS */
   1.268 -read_error:
   1.269 -  {
   1.270 -    GST_ELEMENT_ERROR (src, RESOURCE, READ,
   1.271 -	(NULL), ("Could not read any bytes (%i, %s)", read,
   1.272 -	  src->uri_name));
   1.273 -    return GST_FLOW_ERROR;
   1.274 -  }
   1.275 -change_progchain:
   1.276 -  {
   1.277 -    GST_ELEMENT_ERROR (src, RESOURCE, READ,
   1.278 -		(NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
   1.279 -		  src->uri_name));
   1.280 -		  
   1.281 -		gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
   1.282 -  			gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
   1.283 -		// go to the next program chain
   1.284 -		src->unique_setup = FALSE;
   1.285 -		src->update_prog_chain = TRUE;
   1.286 -		
   1.287 -		gst_mythtv_src_next_program_chain( src );
   1.288 -		
   1.289 -    return GST_FLOW_ERROR_NO_DATA;
   1.290 -  }
   1.291 -
   1.292 -}
   1.293 -#endif
   1.294 -
   1.295 -static GstFlowReturn
   1.296  gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf )
   1.297  {
   1.298    GstMythtvSrc *src;
   1.299 @@ -595,7 +443,9 @@
   1.300  
   1.301    if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) {
   1.302  
   1.303 -    buffer = gst_buffer_new_and_alloc( INTERNAL_BUFFER_SIZE - src->buffer_remain );
   1.304 +    ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
   1.305 +      src->read_offset /*GST_BUFFER_OFFSET_NONE*/, INTERNAL_BUFFER_SIZE - src->buffer_remain,
   1.306 +      GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), &buffer );
   1.307  
   1.308      read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) );
   1.309  
   1.310 @@ -618,6 +468,11 @@
   1.311  	src->read_offset, src->content_size );
   1.312  
   1.313    }
   1.314 +  
   1.315 +  if ( now == -1 )
   1.316 +  	now = gst_element_get_base_time( GST_ELEMENT( src ) );
   1.317 +  //else
   1.318 +  //	now;
   1.319  
   1.320    size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
   1.321  
   1.322 @@ -629,6 +484,7 @@
   1.323    GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
   1.324    GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
   1.325    g_memmove( GST_BUFFER_DATA( (*outbuf) ), GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(*outbuf) );
   1.326 +  //GST_BUFFER_TIMESTAMP( *outbuf ) = now;
   1.327    GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
   1.328    GST_BUFFER_OFFSET_END (*outbuf) = src->read_offset + GST_BUFFER_SIZE (*outbuf);
   1.329  
   1.330 @@ -690,6 +546,142 @@
   1.331    }
   1.332  
   1.333  }
   1.334 +#endif
   1.335 +
   1.336 +static GstFlowReturn
   1.337 +gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf )
   1.338 +{
   1.339 +  GstMythtvSrc *src;
   1.340 +  GstFlowReturn ret = GST_FLOW_OK;
   1.341 +  gint read = -1;
   1.342 +  gint adapter_size = 0;
   1.343 +  guint max_adapter_rep = 1;
   1.344 +
   1.345 +  src = GST_MYTHTV_SRC ( psrc );
   1.346 +
   1.347 +  /* The caller should know the number of bytes and not read beyond EOS. */
   1.348 +  if (G_UNLIKELY (src->eos))
   1.349 +    goto eos;
   1.350 +  if ( G_UNLIKELY (src->update_prog_chain) )
   1.351 +    goto change_progchain;
   1.352 +
   1.353 +  //g_static_rec_mutex_lock( &th_mutex );
   1.354 +  g_print ( "[%s] %d - Adapter size = (%d), offset = %llu, size = %d...\n", __FUNCTION__, 
   1.355 +  		max_adapter_rep, adapter_size, offset, size );
   1.356 +
   1.357 +  /* just get from the adapter, no network effort... */
   1.358 +  //GstBuffer *buffer = NULL;
   1.359 +
   1.360 +  g_print ( "[%s]\t\tCreate: buffer_remain: %d\n", __FUNCTION__, 
   1.361 +      (gint) src->buffer_remain);
   1.362 +
   1.363 +  if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE ) {
   1.364 +  	guint8 *buffer = g_malloc0( INTERNAL_BUFFER_SIZE - src->buffer_remain );
   1.365 +
   1.366 +    read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(buffer) );
   1.367 +
   1.368 +    if (G_UNLIKELY (read < 0)) {
   1.369 +      if ( src->live_tv )
   1.370 +	goto change_progchain;
   1.371 +      else
   1.372 +	goto read_error;
   1.373 +    }
   1.374 +
   1.375 +    if ( G_UNLIKELY (src->update_prog_chain) )
   1.376 +      goto change_progchain;
   1.377 +      
   1.378 +    src->bytes_queue = g_byte_array_append( src->bytes_queue, buffer, read );
   1.379 +
   1.380 +    src->buffer_remain = src->buffer_remain + read;
   1.381 +
   1.382 +    g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
   1.383 +	"OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, 
   1.384 +	src->read_offset, src->content_size );
   1.385 +	
   1.386 +  }
   1.387 +  
   1.388 +  guint buffer_size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
   1.389 +  
   1.390 +  /* Create the buffer. */
   1.391 +  ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
   1.392 +      offset, buffer_size,
   1.393 +      GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );    
   1.394 +
   1.395 +  if (G_UNLIKELY (ret != GST_FLOW_OK)) {
   1.396 +    if ( src->live_tv )
   1.397 +      goto change_progchain;
   1.398 +    else
   1.399 +      goto done;
   1.400 +  }
   1.401 +  
   1.402 +  guint8 *buf = g_memdup( src->bytes_queue->data, buffer_size );
   1.403 +
   1.404 +  g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain );
   1.405 +  //src->read_offset = offset;
   1.406 +
   1.407 +  GST_BUFFER_SIZE (*outbuf) = buffer_size;
   1.408 +  GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
   1.409 +  GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
   1.410 +  g_memmove( GST_BUFFER_DATA( (*outbuf) ), buf, GST_BUFFER_SIZE(*outbuf) );
   1.411 +  GST_BUFFER_OFFSET (*outbuf) = offset;
   1.412 +  GST_BUFFER_OFFSET_END (*outbuf) = offset + GST_BUFFER_SIZE (*outbuf);
   1.413 +
   1.414 +  src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
   1.415 +
   1.416 +  src->read_offset += GST_BUFFER_SIZE (*outbuf);
   1.417 +  src->bytes_read += GST_BUFFER_SIZE (*outbuf);
   1.418 +  g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) );
   1.419 +
   1.420 +  src->bytes_queue = g_byte_array_remove_range( src->bytes_queue, 0, buffer_size );
   1.421 +
   1.422 +  g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
   1.423 +      "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), 
   1.424 +      GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
   1.425 +
   1.426 +  /* just get from the adapter, no network effort... */
   1.427 +
   1.428 +  return ret;
   1.429 +
   1.430 +done:
   1.431 +  {
   1.432 +    const gchar *reason = gst_flow_get_name (ret);
   1.433 +
   1.434 +    GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
   1.435 +    return ret;
   1.436 +  }
   1.437 +eos:
   1.438 +  {
   1.439 +    const gchar *reason = gst_flow_get_name (ret);
   1.440 +
   1.441 +    GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
   1.442 +    return GST_FLOW_UNEXPECTED;
   1.443 +  }
   1.444 +  /* ERRORS */
   1.445 +read_error:
   1.446 +  {
   1.447 +    GST_ELEMENT_ERROR (src, RESOURCE, READ,
   1.448 +	(NULL), ("Could not read any bytes (%i, %s)", read,
   1.449 +		 src->uri_name));
   1.450 +    return GST_FLOW_ERROR;
   1.451 +  }
   1.452 +change_progchain:
   1.453 +  {
   1.454 +    GST_ELEMENT_ERROR (src, RESOURCE, READ,
   1.455 +	(NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
   1.456 +		 src->uri_name));
   1.457 +
   1.458 +    gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
   1.459 +	gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
   1.460 +    // go to the next program chain
   1.461 +    src->unique_setup = FALSE;
   1.462 +    src->update_prog_chain = TRUE;
   1.463 +
   1.464 +    gst_mythtv_src_next_program_chain( src );
   1.465 +
   1.466 +    return GST_FLOW_ERROR_NO_DATA;
   1.467 +  }
   1.468 +
   1.469 +}
   1.470  
   1.471  gint64
   1.472  gst_mythtv_src_get_position ( GstMythtvSrc* src ) 
   1.473 @@ -717,6 +709,7 @@
   1.474  
   1.475  }
   1.476  
   1.477 +#if 0
   1.478  static gboolean
   1.479  gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment )
   1.480  {
   1.481 @@ -792,6 +785,7 @@
   1.482    }
   1.483  
   1.484  }
   1.485 +#endif
   1.486  
   1.487  #if 0
   1.488  static void 
   1.489 @@ -871,6 +865,7 @@
   1.490    }
   1.491  
   1.492    if ( src->live_tv ) {
   1.493 +  	gmyth_context_initialize();
   1.494      src->spawn_livetv = gmyth_livetv_new( );
   1.495      if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) {
   1.496        ret = FALSE;
   1.497 @@ -907,6 +902,8 @@
   1.498  	  /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
   1.499        g_usleep( 100 );
   1.500    }
   1.501 +  
   1.502 +  //sleep( 30 );
   1.503  
   1.504    /* sets the FileTransfer instance connection (video/audio download) */
   1.505    ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
   1.506 @@ -924,7 +921,7 @@
   1.507    src->do_start = FALSE;
   1.508  
   1.509    //if ( src->live_tv ) {
   1.510 -  src->adapter = gst_adapter_new();
   1.511 +  src->bytes_queue = g_byte_array_new();
   1.512    //src->th_read_ahead = gst_task_create( (GstTaskFunction)gst_mythtv_src_read_ahead, src );
   1.513    //gst_task_set_lock( src->th_read_ahead, &th_mutex );
   1.514    //gst_task_start( src->th_read_ahead );
   1.515 @@ -970,6 +967,16 @@
   1.516    }
   1.517  }
   1.518  
   1.519 +#if 0
   1.520 +static void
   1.521 +gst_mythtv_src_get_times (GstBaseSrc * src, GstBuffer * buffer,
   1.522 +    GstClockTime * start, GstClockTime * end)
   1.523 +{
   1.524 +  *start = -1;
   1.525 +  *end = -1;
   1.526 +}
   1.527 +#endif
   1.528 +
   1.529  /* create a new socket for connecting to the next program chain */
   1.530  static gboolean
   1.531  gst_mythtv_src_next_program_chain ( GstMythtvSrc *src )
   1.532 @@ -1101,8 +1108,11 @@
   1.533    gboolean ret = TRUE;
   1.534    g_print( "[%s] Differs from previous content size: %d (max.: %d)\n", __FUNCTION__, 
   1.535    			abs( src->content_size - src->prev_content_size ), GMYTHTV_TRANSFER_MAX_BUFFER );
   1.536 -
   1.537 -  if (src->content_size == -1) {
   1.538 +  			
   1.539 +  if ( src->live_tv )
   1.540 +  	//src->content_size = (guint64)-1;
   1.541 +  	ret = FALSE;
   1.542 +	else if (src->content_size == -1) {
   1.543      //ret= FALSE;
   1.544    } else if ( src->live_tv && ( abs( src->content_size - src->bytes_read ) < 
   1.545  				GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
   1.546 @@ -1262,7 +1272,7 @@
   1.547  static gboolean
   1.548  gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
   1.549  {
   1.550 -  return TRUE;
   1.551 +  return FALSE;
   1.552  }
   1.553  
   1.554  static gboolean
   1.555 @@ -1332,8 +1342,11 @@
   1.556        g_print( "[%s] PLAYING to PAUSED called!\n", __FUNCTION__ );
   1.557      case GST_STATE_CHANGE_PAUSED_TO_READY:
   1.558        g_print( "[%s] PAUSED to READY called!\n", __FUNCTION__ );
   1.559 +      
   1.560        if ( src->live_tv && src->update_prog_chain ) {
   1.561        	
   1.562 +      /*
   1.563 +      	
   1.564    			gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
   1.565        			gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
   1.566  
   1.567 @@ -1341,7 +1354,9 @@
   1.568  				src->bytes_read = 0;
   1.569  				src->unique_setup = FALSE;				
   1.570  				gst_mythtv_src_next_program_chain( src );
   1.571 +				*/
   1.572        }
   1.573 +      
   1.574        break;
   1.575      default:
   1.576        break;