gst-plugins-mythtv/src/gstmythtvsrc.c
branchtrunk
changeset 146 07951674b0c0
parent 124 d2d5fe1c3997
child 151 1799c8782451
     1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c	Tue Nov 28 00:54:53 2006 +0000
     1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c	Thu Nov 30 15:20:37 2006 +0000
     1.3 @@ -61,7 +61,7 @@
     1.4  
     1.5  #define REQUEST_MAX_SIZE							64*1024
     1.6  
     1.7 -#define INTERNAL_BUFFER_SIZE					200*1024
     1.8 +#define INTERNAL_BUFFER_SIZE					90*1024
     1.9  
    1.10  /* stablish a maximum iteration value to the IS_RECORDING message */
    1.11  static guint wait_to_transfer = 0;
    1.12 @@ -348,7 +348,7 @@
    1.13  {
    1.14    gint read = 0;
    1.15    guint sizetoread = size;
    1.16 -  guint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
    1.17 +  gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
    1.18    
    1.19    GST_LOG_OBJECT( src, "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread ); 
    1.20  
    1.21 @@ -382,7 +382,8 @@
    1.22  	goto done;
    1.23        }
    1.24  
    1.25 -    }
    1.26 +    } else if ( len == 0 )
    1.27 +    	goto done;
    1.28  
    1.29      if ( read == sizetoread )
    1.30        goto done;
    1.31 @@ -423,46 +424,40 @@
    1.32        (gint) src->buffer_remain, src->bytes_queue->len );
    1.33  
    1.34    /* just get from the byte array, no network effort... */
    1.35 -  if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE ) { 
    1.36 +  if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE  &&
    1.37 +  			abs( src->content_size - src->bytes_read ) > MAX_READ_SIZE ) { 
    1.38    			//( ( INTERNAL_BUFFER_SIZE - src->buffer_remain )  >=  REQUEST_MAX_SIZE ) ) {
    1.39    	GByteArray *buffer = NULL;
    1.40 -  	guint amount_to_fill = ( INTERNAL_BUFFER_SIZE - src->buffer_remain );
    1.41 -  	guint buffer_size_inter = 0;
    1.42 +  	guint buffer_size_inter = ( INTERNAL_BUFFER_SIZE - src->buffer_remain );
    1.43 +  	if ( buffer_size_inter > REQUEST_MAX_SIZE )
    1.44 +  		buffer_size_inter = REQUEST_MAX_SIZE;
    1.45    		
    1.46 -  	//do {
    1.47 -	  	if ( amount_to_fill < REQUEST_MAX_SIZE )
    1.48 -	  		buffer_size_inter = amount_to_fill;
    1.49 -	  	else
    1.50 -	  		buffer_size_inter = REQUEST_MAX_SIZE;
    1.51 +  	buffer = g_byte_array_new();
    1.52  
    1.53 -	  	buffer = g_byte_array_new();
    1.54 -	
    1.55 -	    read = do_read_request_response( src, buffer_size_inter, buffer );
    1.56 -	
    1.57 -	    if (G_UNLIKELY (read < 0)) {
    1.58 -	      if ( src->live_tv )
    1.59 -		goto change_progchain;
    1.60 -	      else
    1.61 -		goto read_error;
    1.62 -	    }
    1.63 -	
    1.64 -	    if ( G_UNLIKELY (src->update_prog_chain) )
    1.65 -	      goto change_progchain;
    1.66 -	      
    1.67 -	    src->bytes_queue = g_byte_array_append( src->bytes_queue, g_memdup( buffer->data, read ), read );
    1.68 -	    if ( read > buffer_size_inter )
    1.69 -	    	GST_WARNING_OBJECT( src, "[%s] INCREASED buffer size! Backend sent more than we ask him... (%d)\n", 
    1.70 -	    			__FUNCTION__, abs( read - buffer_size_inter ) );
    1.71 -	
    1.72 -	    src->buffer_remain += read;
    1.73 -	    amount_to_fill -= read;
    1.74 -	
    1.75 -	  	//} while ( amount_to_fill > 0 );
    1.76 -	    
    1.77 -	    if ( buffer != NULL ) {
    1.78 -	    	g_byte_array_free( buffer, TRUE );
    1.79 -	    	buffer = NULL;    	
    1.80 -	    }
    1.81 +    read = do_read_request_response( src, buffer_size_inter, buffer );
    1.82 +
    1.83 +    if (G_UNLIKELY (read < 0)) {
    1.84 +      if ( src->live_tv )
    1.85 +	goto change_progchain;
    1.86 +      else
    1.87 +	goto read_error;
    1.88 +    } else if (G_UNLIKELY (read == 0) && !src->live_tv )
    1.89 +    	goto eos;
    1.90 +
    1.91 +    if ( G_UNLIKELY (src->update_prog_chain) )
    1.92 +      goto change_progchain;
    1.93 +    
    1.94 +    src->bytes_queue = g_byte_array_append( src->bytes_queue, g_memdup( buffer->data, read ), read );
    1.95 +    if ( read > buffer_size_inter )
    1.96 +    	GST_WARNING_OBJECT( src, "\n\n\n[%s]\t\tINCREASED buffer size! Backend sent more than we ask him... (%d)\n\n\n", 
    1.97 +    			__FUNCTION__, abs( read - buffer_size_inter ) );
    1.98 +
    1.99 +    src->buffer_remain += read;
   1.100 +
   1.101 +    if ( buffer != NULL ) {
   1.102 +    	g_byte_array_free( buffer, TRUE );
   1.103 +    	buffer = NULL;    	
   1.104 +    }
   1.105  	
   1.106  	    GST_DEBUG_OBJECT( src, "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
   1.107  		"OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, 
   1.108 @@ -510,7 +505,11 @@
   1.109        "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), 
   1.110        GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
   1.111  
   1.112 -  return ret;
   1.113 +  GST_DEBUG_OBJECT( src, "[%s]\tCONTENT_SIZE = %llu, BYTES_READ = %llu.\n", __FUNCTION__, 
   1.114 +  		src->content_size, src->bytes_read );
   1.115 +      
   1.116 +  if ( G_UNLIKELY (src->eos) || ( !src->live_tv && ( src->bytes_read >= src->content_size ) ) )
   1.117 +   goto eos;
   1.118  
   1.119  done:
   1.120    {