gst-plugins-mythtv/src/gstmythtvsrc.c
branchtrunk
changeset 62 2a552f003c4e
parent 59 b2b0169716dc
child 63 957b55b3f630
     1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c	Fri Oct 27 00:22:59 2006 +0100
     1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c	Fri Oct 27 23:42:34 2006 +0100
     1.3 @@ -33,7 +33,7 @@
     1.4  #define GST_GMYTHTV_ID_NUM		1
     1.5  
     1.6  #define GMYTHTV_VERSION_DEFAULT			30
     1.7 -
     1.8 + 
     1.9  #define GMYTHTV_TRANSFER_MAX_WAITS	100
    1.10  
    1.11  #define GMYTHTV_TRANSFER_MAX_BUFFER	512*1024
    1.12 @@ -229,6 +229,8 @@
    1.13    this->content_size = 0;
    1.14    this->read_offset = 0;
    1.15  
    1.16 +  this->content_size_last = 0;
    1.17 +
    1.18    this->live_tv = FALSE;
    1.19    
    1.20    this->enable_timing_position = FALSE;
    1.21 @@ -299,9 +301,9 @@
    1.22    GST_OBJECT_LOCK(src);
    1.23  
    1.24    while ( sizetoread > 0 ) {
    1.25 -  	
    1.26 -  	len = gmyth_file_transfer_read( src->file_transfer,
    1.27 -			GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE );
    1.28 +
    1.29 +    len = gmyth_file_transfer_read( src->file_transfer,
    1.30 +	GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE );
    1.31  
    1.32      if ( len > 0 ) {
    1.33        read += len;      
    1.34 @@ -309,79 +311,79 @@
    1.35      } 
    1.36      else if ( len <= 0 ) 
    1.37      {
    1.38 -    	
    1.39 +
    1.40        if ( src->live_tv == FALSE ) 
    1.41        {
    1.42 -				goto done;
    1.43 +	goto done;
    1.44        } 
    1.45        else  
    1.46        {
    1.47 -      	if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
    1.48 -	      	src->update_prog_chain = TRUE;
    1.49 -	      	if ( gst_mythtv_src_next_program_chain ( src ) )
    1.50 -	      		continue;
    1.51 -	      	else
    1.52 -	      		goto done;
    1.53 -	      } else 
    1.54 -	      	if ( src->content_size <= 
    1.55 -	      					( src->read_offset + size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
    1.56 -	      		src->update_prog_chain = TRUE;
    1.57 -						if ( src->enable_timing_position ) {
    1.58 -						    gint64 size_tmp = 0;
    1.59 -						    if (src->live_tv == TRUE) {
    1.60 -						get_file_pos:
    1.61 -						      size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
    1.62 -						      if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
    1.63 -										src->content_size = size_tmp;
    1.64 -						      else if ( size_tmp > 0 )
    1.65 -							goto get_file_pos;
    1.66 -						      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
    1.67 -							  __FUNCTION__, size_tmp );
    1.68 -						    }
    1.69 -						} else {
    1.70 -						  	gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
    1.71 -								if ( new_offset > 0 ) {
    1.72 -								  if ( src->content_size < new_offset ) {
    1.73 -								    src->content_size = new_offset;
    1.74 -								  }
    1.75 -								} else {
    1.76 -								  src->update_prog_chain = TRUE;
    1.77 -								}
    1.78 -						}
    1.79 -						goto done;
    1.80 -		  		}
    1.81 +	if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
    1.82 +	  src->update_prog_chain = TRUE;
    1.83 +	  if ( gst_mythtv_src_next_program_chain ( src ) )
    1.84 +	    continue;
    1.85 +	  else
    1.86 +	    goto done;
    1.87 +	} else 
    1.88 +	  if ( src->content_size <= 
    1.89 +	      ( src->read_offset + size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
    1.90 +	    src->update_prog_chain = TRUE;
    1.91 +	    if ( src->enable_timing_position ) {
    1.92 +	      gint64 size_tmp = 0;
    1.93 +	      if (src->live_tv == TRUE) {
    1.94 +get_file_pos:
    1.95 +		size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
    1.96 +		if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
    1.97 +		  src->content_size = size_tmp;
    1.98 +		else if ( size_tmp > 0 )
    1.99 +		  goto get_file_pos;
   1.100 +		g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   1.101 +		    __FUNCTION__, size_tmp );
   1.102  	      }
   1.103 +	    } else {
   1.104 +	      gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.105 +	      if ( new_offset > 0 ) {
   1.106 +		if ( src->content_size < new_offset ) {
   1.107 +		  src->content_size = new_offset;
   1.108 +		}
   1.109 +	      } else {
   1.110 +		src->update_prog_chain = TRUE;
   1.111 +	      }
   1.112 +	    }
   1.113 +	    goto done;
   1.114 +	  }
   1.115 +      }
   1.116  
   1.117 -  	}
   1.118 -    
   1.119 +    }
   1.120 +
   1.121      if ( read == sizetoread )
   1.122        break;
   1.123    }
   1.124 -  
   1.125 +
   1.126    if ( read > 0 ) {
   1.127 -  	src->read_offset += read;
   1.128 +    src->read_offset += read;
   1.129      src->bytes_read += read;
   1.130 -  
   1.131 -  g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
   1.132 -      "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, 
   1.133 -      src->read_offset, src->content_size );
   1.134 -      
   1.135 -  GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
   1.136 -  GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
   1.137 -  GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
   1.138 -     
   1.139 -  g_print( "Stopping: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
   1.140 -      "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), 
   1.141 -      GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
   1.142 -      
   1.143 +
   1.144 +    g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
   1.145 +	"OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, 
   1.146 +	src->read_offset, src->content_size );
   1.147 +
   1.148 +    GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
   1.149 +    GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
   1.150 +    GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
   1.151 +
   1.152 +    g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
   1.153 +	"OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), 
   1.154 +	GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
   1.155 +
   1.156    } else if ( !src->live_tv )
   1.157 -  	goto eos;
   1.158 -  
   1.159 +    goto eos;
   1.160 +
   1.161    goto done;
   1.162  
   1.163  eos:
   1.164    src->eos = TRUE;
   1.165 -  
   1.166 +
   1.167  done:
   1.168    GST_OBJECT_UNLOCK(src);
   1.169  
   1.170 @@ -405,7 +407,7 @@
   1.171    GST_OBJECT_LOCK(src);
   1.172  
   1.173    if (G_UNLIKELY (src->read_offset != offset)) {
   1.174 -    gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset, SEEK_SET);
   1.175 +    gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset - src->content_size_last, SEEK_SET);
   1.176      g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
   1.177      	__FUNCTION__, src->read_offset, new_offset );
   1.178      if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) {
   1.179 @@ -430,9 +432,7 @@
   1.180    if (G_UNLIKELY (ret != GST_FLOW_OK))
   1.181      goto done;
   1.182    
   1.183 -  //g_static_mutex_lock( &update_size_mutex );
   1.184    read = do_read_request_response ( src, src->read_offset, size, outbuf );
   1.185 -  //g_static_mutex_unlock( &update_size_mutex );  
   1.186  
   1.187    if (G_UNLIKELY (src->update_prog_chain) )
   1.188      goto change_progchain;
   1.189 @@ -492,20 +492,20 @@
   1.190    g_static_mutex_lock( &update_size_mutex );
   1.191  
   1.192    if ( src->do_start ) {
   1.193 -	if ( src->enable_timing_position ) {
   1.194 -	    gint64 size_tmp = 0;
   1.195 -	    if (src->live_tv == TRUE) {
   1.196 -	get_file_pos:
   1.197 -	      g_usleep( 50 );
   1.198 -	      size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.199 -	      if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   1.200 -		src->content_size = size_tmp;
   1.201 -	      else if ( size_tmp > 0 )
   1.202 -		goto get_file_pos;
   1.203 -	      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   1.204 -		  __FUNCTION__, size_tmp );
   1.205 -	    }
   1.206 -	}
   1.207 +    if ( src->enable_timing_position ) {
   1.208 +      gint64 size_tmp = 0;
   1.209 +      if (src->live_tv == TRUE) {
   1.210 +get_file_pos:
   1.211 +	g_usleep( 50 );
   1.212 +	size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.213 +	if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   1.214 +	  src->content_size = size_tmp;
   1.215 +	else if ( size_tmp > 0 )
   1.216 +	  goto get_file_pos;
   1.217 +	g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   1.218 +	    __FUNCTION__, size_tmp );
   1.219 +      }
   1.220 +    }
   1.221    }
   1.222    g_static_mutex_unlock( &update_size_mutex );
   1.223  
   1.224 @@ -516,16 +516,17 @@
   1.225  {
   1.226  
   1.227    gint64 size_tmp = 0;
   1.228 +  guint max_tries = 3;
   1.229    if (src->live_tv == TRUE) {
   1.230  get_file_pos:
   1.231 -    g_usleep( 50 );
   1.232 +    g_usleep( 10 );
   1.233      size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.234      if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   1.235 -			src->content_size = size_tmp;
   1.236 -    else if ( size_tmp > 0 )
   1.237 -			goto get_file_pos;
   1.238 +      src->content_size = size_tmp;
   1.239 +    else if ( size_tmp > 0 && --max_tries > 0 )
   1.240 +      goto get_file_pos;
   1.241      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   1.242 -  __FUNCTION__, size_tmp );
   1.243 +	__FUNCTION__, size_tmp );
   1.244    }
   1.245  
   1.246    return src->content_size;	
   1.247 @@ -639,27 +640,25 @@
   1.248    GString *chain_id_local = NULL;
   1.249  
   1.250    gboolean ret = TRUE;
   1.251 -  
   1.252 +
   1.253    if ( !src->live_tv )
   1.254 -  	goto init_failed;
   1.255 -  
   1.256 +    goto init_failed;
   1.257 +
   1.258 +  src->update_prog_chain = FALSE;
   1.259 +
   1.260    if (src->file_transfer) {
   1.261      g_object_unref (src->file_transfer);
   1.262      src->file_transfer = NULL;
   1.263    }
   1.264 -  
   1.265 +
   1.266    if (src->uri_name) {
   1.267      g_free (src->uri_name);
   1.268    }
   1.269 -  
   1.270 +
   1.271    if ( src->live_tv ) {
   1.272 -  	if ( src->update_prog_chain )
   1.273 -  	{
   1.274 -    	if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) {
   1.275 -	      ret = FALSE;
   1.276 -	      goto init_failed;
   1.277 -    	}
   1.278 -    	src->update_prog_chain = FALSE;
   1.279 +    if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) {
   1.280 +      ret = FALSE;
   1.281 +      goto init_failed;
   1.282      }
   1.283      /* set up the uri variable */
   1.284      src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
   1.285 @@ -685,12 +684,12 @@
   1.286    if ( src->live_tv == TRUE && ret == TRUE ) {
   1.287      /* loop finished, set the max tries variable to zero again... */
   1.288      wait_to_transfer = 0;
   1.289 -    
   1.290 -    g_usleep( 500 );
   1.291 +
   1.292 +    g_usleep( 200 );
   1.293  
   1.294      while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && 
   1.295 -    		( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) )
   1.296 -      		g_usleep( 100 );
   1.297 +	( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) )
   1.298 +      g_usleep( 1000 );
   1.299    }
   1.300  
   1.301    /* sets the FileTransfer instance connection (video/audio download) */
   1.302 @@ -703,18 +702,23 @@
   1.303  #endif
   1.304      goto begin_req_failed;
   1.305    }
   1.306 -  
   1.307 +  src->content_size_last = src->content_size;
   1.308 +
   1.309 +#if 0
   1.310    if ( src->content_size < src->file_transfer->filesize ) {
   1.311 -  	src->content_size = src->file_transfer->filesize;
   1.312 +    src->content_size = src->file_transfer->filesize;
   1.313    } else {
   1.314 -  	gint64 pos = gst_mythtv_src_get_position(src);
   1.315 -  	if ( pos > src->file_transfer->filesize )
   1.316 -  		src->content_size = pos;  	
   1.317 +    //gint64 pos = gst_mythtv_src_get_position(src);
   1.318 +    //if ( pos > src->file_transfer->filesize )
   1.319 +    //	src->content_size = pos;  	
   1.320 +
   1.321    }
   1.322 -  
   1.323 -  src->read_offset = 0;
   1.324 -  
   1.325 -  src->update_prog_chain = FALSE;
   1.326 +#endif
   1.327 +
   1.328 +  src->content_size = src->file_transfer->filesize;
   1.329 +  //src->read_offset = 0;
   1.330 +
   1.331 +  //src->update_prog_chain = FALSE;
   1.332  
   1.333    return TRUE;
   1.334  
   1.335 @@ -734,7 +738,7 @@
   1.336  	(NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
   1.337      return FALSE;
   1.338    }
   1.339 -  
   1.340 +
   1.341  }
   1.342  
   1.343  #if 0
   1.344 @@ -813,36 +817,36 @@
   1.345  
   1.346    if (src->content_size <= 0) {
   1.347      ret= FALSE;
   1.348 -  } else {
   1.349 -  //g_static_mutex_lock( &update_size_mutex );
   1.350 -  //GST_OBJECT_LOCK(src);
   1.351 +  } else if ( src->live_tv ) {
   1.352 +    //g_static_mutex_lock( &update_size_mutex );
   1.353 +    //GST_OBJECT_LOCK(src);
   1.354  
   1.355 -	gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.356 -	if ( new_offset > 0 ) {
   1.357 -	  if ( src->content_size < new_offset ) {
   1.358 -	    src->content_size = new_offset;
   1.359 -	  }
   1.360 -	} else {
   1.361 -		if ( src->live_tv )
   1.362 -			src->update_prog_chain = TRUE;
   1.363 -	}
   1.364 - 
   1.365 -	if ( src->enable_timing_position ) {
   1.366 -	    gint64 size_tmp = 0;
   1.367 -	    if (src->live_tv == TRUE) {
   1.368 -	get_file_pos:
   1.369 -	      g_usleep( 5 );
   1.370 -	      size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.371 -	      if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   1.372 -					src->content_size = size_tmp;
   1.373 -	      else if ( size_tmp > 0  )
   1.374 -					goto get_file_pos;
   1.375 -	      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   1.376 -		  __FUNCTION__, size_tmp );
   1.377 -	    }
   1.378 -	}
   1.379 -	//GST_OBJECT_UNLOCK(src);
   1.380 -  //g_static_mutex_unlock( &update_size_mutex );
   1.381 +    gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.382 +    if ( new_offset > 0 ) {
   1.383 +      if ( src->content_size < new_offset ) {
   1.384 +	src->content_size = new_offset;
   1.385 +      }
   1.386 +    } else {
   1.387 +      if ( src->live_tv )
   1.388 +	src->update_prog_chain = TRUE;
   1.389 +    }
   1.390 +
   1.391 +    if ( src->enable_timing_position ) {
   1.392 +      gint64 size_tmp = 0;
   1.393 +      if (src->live_tv == TRUE) {
   1.394 +get_file_pos:
   1.395 +	g_usleep( 5 );
   1.396 +	size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.397 +	if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   1.398 +	  src->content_size = size_tmp;
   1.399 +	else if ( size_tmp > 0  )
   1.400 +	  goto get_file_pos;
   1.401 +	g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   1.402 +	    __FUNCTION__, size_tmp );
   1.403 +      }
   1.404 +    }
   1.405 +    //GST_OBJECT_UNLOCK(src);
   1.406 +    //g_static_mutex_unlock( &update_size_mutex );
   1.407    }
   1.408  
   1.409    *size = src->content_size;
   1.410 @@ -887,25 +891,25 @@
   1.411      case GST_EVENT_FLUSH_START:
   1.412        //src->eos = FALSE;
   1.413        g_print( "\n\n\n[%s]\t\tGot FLUSH_START event!!!\n\n\n", __FUNCTION__ );
   1.414 -		  cont_size = gst_mythtv_src_get_position (src);
   1.415 -		  if ( !src->live_tv ) {
   1.416 -			  if ( cont_size > src->content_size ) {
   1.417 -			  	src->content_size = cont_size;
   1.418 -			  	src->eos = FALSE;
   1.419 -	  	  } else {
   1.420 -	      	src->eos = TRUE;
   1.421 -	      	gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
   1.422 -	      	gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
   1.423 -	  	  }
   1.424 -		  } else {
   1.425 -		  	if ( cont_size <= 0 ) {
   1.426 -		  		src->update_prog_chain = TRUE;
   1.427 -		  		src->eos = TRUE;
   1.428 -		  		src->unique_setup = FALSE;
   1.429 -		  		src->do_start = TRUE;		  				  		
   1.430 -		  	}		  	
   1.431 -		  }
   1.432 -	    break;
   1.433 +      cont_size = gst_mythtv_src_get_position (src);
   1.434 +      if ( !src->live_tv ) {
   1.435 +	if ( cont_size > src->content_size ) {
   1.436 +	  src->content_size = cont_size;
   1.437 +	  src->eos = FALSE;
   1.438 +	} else {
   1.439 +	  src->eos = TRUE;
   1.440 +	  gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
   1.441 +	  gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
   1.442 +	}
   1.443 +      } else {
   1.444 +	if ( cont_size <= 0 ) {
   1.445 +	  src->update_prog_chain = TRUE;
   1.446 +	  src->eos = TRUE;
   1.447 +	  src->unique_setup = FALSE;
   1.448 +	  src->do_start = TRUE;		  				  		
   1.449 +	}		  	
   1.450 +      }
   1.451 +      break;
   1.452      case GST_EVENT_FLUSH_STOP:
   1.453        src->do_start = TRUE;
   1.454        src->eos = FALSE;
   1.455 @@ -915,18 +919,19 @@
   1.456  #endif
   1.457      case GST_EVENT_EOS:
   1.458        g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
   1.459 -	  cont_size = gst_mythtv_src_get_position (src);
   1.460 -	  if ( !src->live_tv ) {
   1.461 -		  if ( cont_size > src->content_size ) {
   1.462 -		  	src->content_size = cont_size;
   1.463 -		  	src->eos = FALSE;
   1.464 -	  	  } else {
   1.465 -	      	src->eos = TRUE;
   1.466 -	      	gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
   1.467 -	      	gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
   1.468 -	  	  }
   1.469 -	  } else 
   1.470 -	  	src->eos = TRUE;
   1.471 +
   1.472 +      if ( src->live_tv ) {
   1.473 +	cont_size = gst_mythtv_src_get_position (src);
   1.474 +	if ( cont_size > src->content_size ) {
   1.475 +	  src->content_size = cont_size;
   1.476 +	  src->eos = FALSE;
   1.477 +	} else {
   1.478 +	  src->eos = TRUE;
   1.479 +	  gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
   1.480 +	  gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
   1.481 +	}
   1.482 +      } else 
   1.483 +	src->eos = TRUE;
   1.484        break;
   1.485  #if 0
   1.486      case GST_EVENT_NEWSEGMENT:
   1.487 @@ -970,6 +975,59 @@
   1.488    return TRUE;
   1.489  }
   1.490  
   1.491 +#if 0
   1.492 +static gboolean
   1.493 +gst_nuv_demux_sink_activate (GstPad * sinkpad)
   1.494 +{
   1.495 +  gboolean res = TRUE;
   1.496 +  GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
   1.497 +
   1.498 +  if (gst_pad_check_pull_range (sinkpad)) {
   1.499 +    nuv->mode = 0;
   1.500 +    nuv->adapter = NULL;
   1.501 +    res = gst_pad_activate_pull (sinkpad, TRUE);
   1.502 +  } else {
   1.503 +    nuv->mode = 1;
   1.504 +    nuv->adapter = gst_adapter_new ();
   1.505 +    res = gst_pad_activate_push (sinkpad, TRUE);
   1.506 +  }
   1.507 +
   1.508 +  g_object_unref (nuv);
   1.509 +  return res;
   1.510 +}
   1.511 +
   1.512 +static gboolean
   1.513 +gst_nuv_demux_sink_activate_pull (GstPad * sinkpad, gboolean active)
   1.514 +{
   1.515 +  GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
   1.516 +
   1.517 +  if (active) {
   1.518 +    gst_pad_start_task (sinkpad, (GstTaskFunction) gst_nuv_demux_loop, sinkpad);
   1.519 +  } else {
   1.520 +    gst_pad_stop_task (sinkpad);
   1.521 +  }
   1.522 +  gst_object_unref (nuv);
   1.523 +
   1.524 +  return TRUE;
   1.525 +}
   1.526 +
   1.527 +static GstFlowReturn
   1.528 +gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf)
   1.529 +{
   1.530 +  GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
   1.531 +
   1.532 +  gst_adapter_push (nuv->adapter, buf);
   1.533 +
   1.534 +  return gst_nuv_demux_play (pad);
   1.535 +}
   1.536 +
   1.537 +static void
   1.538 +gst_nuv_demux_loop (GstPad * pad)
   1.539 +{
   1.540 +  gst_nuv_demux_play (pad);
   1.541 +}
   1.542 +#endif
   1.543 +
   1.544  static GstStateChangeReturn
   1.545  gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
   1.546  {
   1.547 @@ -978,12 +1036,8 @@
   1.548  
   1.549    switch (transition) {
   1.550      case GST_STATE_CHANGE_NULL_TO_READY:
   1.551 -      src->content_size = 0;
   1.552 -      src->read_offset = 0;
   1.553 -      src->bytes_read = 0;
   1.554        src->do_start = TRUE;
   1.555        src->unique_setup = FALSE;      
   1.556 -      src->eos = TRUE;
   1.557        break;
   1.558      case GST_STATE_CHANGE_READY_TO_PAUSED:
   1.559      case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
   1.560 @@ -992,18 +1046,22 @@
   1.561      default:
   1.562        break;
   1.563    }
   1.564 -  
   1.565 - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
   1.566 +
   1.567 +  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
   1.568    if (ret == GST_STATE_CHANGE_FAILURE)
   1.569      return ret;
   1.570  
   1.571    switch (transition) {
   1.572      case GST_STATE_CHANGE_READY_TO_NULL:
   1.573        break;
   1.574 +    case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
   1.575      case GST_STATE_CHANGE_PAUSED_TO_READY:
   1.576 -    	if ( src->live_tv && src->update_prog_chain )
   1.577 -    		gst_mythtv_src_next_program_chain( src );
   1.578 -    	break;
   1.579 +      if ( src->live_tv && src->update_prog_chain ) {
   1.580 +	src->read_offset = 0;
   1.581 +	src->bytes_read = 0;
   1.582 +	gst_mythtv_src_next_program_chain( src );
   1.583 +      }
   1.584 +      break;
   1.585      default:
   1.586        break;
   1.587    }