gst-plugins-mythtv/src/gstmythtvsrc.c
branchtrunk
changeset 35 a615ba8f8804
parent 31 eb4a812d4073
child 37 324e04989738
     1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c	Tue Oct 17 01:03:06 2006 +0100
     1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c	Fri Oct 20 22:48:04 2006 +0100
     1.3 @@ -36,14 +36,14 @@
     1.4  
     1.5  #define MYTHTV_TRANSFER_MAX_WAITS	100
     1.6  
     1.7 -#define MYTHTV_TRANSFER_MAX_BUFFER	4*1024
     1.8 +#define MYTHTV_TRANSFER_MAX_BUFFER	1024*1024
     1.9  //( 32*1024  )
    1.10  
    1.11  /* 4*1024 ??? */
    1.12  #define MAX_READ_SIZE              	12*1024
    1.13  //( 32*1024 )
    1.14  
    1.15 -#define ENABLE_TIMING_POSITION		1
    1.16 +#define ENABLE_TIMING_POSITION		0
    1.17  
    1.18  /* stablish a maximum iteration value to the IS_RECORDING message */
    1.19  static guint wait_to_transfer = 0;
    1.20 @@ -289,7 +289,7 @@
    1.21     * Retry whilst authentication fails and we supply it. */
    1.22    guint len = 0;
    1.23  
    1.24 -  GST_OBJECT_LOCK(src);
    1.25 +  //GST_OBJECT_LOCK(src);
    1.26  
    1.27    while ( sizetoread > 0 ) {
    1.28    	
    1.29 @@ -297,17 +297,36 @@
    1.30  			GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE );
    1.31  
    1.32      if ( len > 0 ) {
    1.33 -      read += len;
    1.34 -      src->read_offset += read;
    1.35 +      read += len;      
    1.36        sizetoread -= len;
    1.37      } else if ( len <= 0 ) {
    1.38      	
    1.39        if ( src->live_tv == FALSE ) {
    1.40  		goto done;
    1.41 -      } else if ( src->content_size >= src->read_offset && 
    1.42 -      			abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) {
    1.43 -      				goto done;
    1.44 -      }
    1.45 +      } else if ( /*src->content_size >= src->read_offset && 
    1.46 +      			abs ( src->content_size - src->read_offset ) <= 1024 ) ||*/
    1.47 +      			( src->content_size <= ( src->read_offset + size + MYTHTV_TRANSFER_MAX_BUFFER ) ) )
    1.48 +  {
    1.49 +#if ENABLE_TIMING_POSITION == 1
    1.50 +    guint64 size_tmp = 0;
    1.51 +    if (src->live_tv == TRUE) {
    1.52 +get_file_pos:
    1.53 +      size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
    1.54 +      if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
    1.55 +	src->content_size = size_tmp;
    1.56 +      else
    1.57 +	goto get_file_pos;
    1.58 +      g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n",
    1.59 +	  __FUNCTION__, size_tmp );
    1.60 +    }
    1.61 +#else
    1.62 +  	guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
    1.63 +  	if ( src->content_size < new_offset ) {
    1.64 +  	  src->content_size = new_offset;
    1.65 +  	}
    1.66 +#endif
    1.67 +	goto done;
    1.68 +  }
    1.69  
    1.70      }
    1.71      
    1.72 @@ -316,6 +335,7 @@
    1.73    }
    1.74    
    1.75    if ( read > 0 ) {
    1.76 +  	src->read_offset += read;
    1.77      src->bytes_read += read;
    1.78    
    1.79    g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
    1.80 @@ -333,7 +353,7 @@
    1.81        "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), 
    1.82        GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
    1.83        
    1.84 -  } else
    1.85 +  } else if ( !src->live_tv )
    1.86    	goto eos;
    1.87    
    1.88    goto done;
    1.89 @@ -343,7 +363,7 @@
    1.90    src->eos = TRUE;
    1.91    
    1.92  done:
    1.93 -  GST_OBJECT_UNLOCK(src);
    1.94 +  //GST_OBJECT_UNLOCK(src);
    1.95  
    1.96    return read;
    1.97  }
    1.98 @@ -361,33 +381,13 @@
    1.99      goto eos;
   1.100    
   1.101    //GST_OBJECT_LOCK(src);
   1.102 -  if ( /*src->content_size >= src->read_offset && 
   1.103 -      			abs ( src->content_size - src->read_offset ) <= 1024 ) ||*/
   1.104 -      			( src->content_size <= ( src->read_offset + size ) ) )
   1.105 -  {
   1.106 -#if ENABLE_TIMING_POSITION == 1
   1.107 -    guint64 size_tmp = 0;
   1.108 -    if (src->live_tv == TRUE) {
   1.109 -get_file_pos:
   1.110 -      size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
   1.111 -      if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
   1.112 -	src->content_size = size_tmp;
   1.113 -      else
   1.114 -	goto get_file_pos;
   1.115 -      g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n",
   1.116 -	  __FUNCTION__, size_tmp );
   1.117 -    }
   1.118 -#endif
   1.119 -  	//guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
   1.120 -  	//if ( src->content_size < new_offset ) {
   1.121 -  	//  src->content_size = new_offset;
   1.122 -  	//}
   1.123 -  }
   1.124  
   1.125    if (G_UNLIKELY (src->read_offset != offset)) {
   1.126      guint64 new_offset = myth_file_transfer_seek(src->file_transfer, offset, SEEK_SET);
   1.127 -
   1.128 -    if (G_UNLIKELY (new_offset < 0 || new_offset != offset)) {
   1.129 +    g_print( "[%s] SRC Offset = %llu, NEW actual backend SEEK Offset = %llu.\n",
   1.130 +    	__FUNCTION__, src->read_offset, new_offset );
   1.131 +    if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) {
   1.132 +    {
   1.133        //GST_OBJECT_UNLOCK(src);
   1.134        goto read_error;
   1.135      }
   1.136 @@ -446,15 +446,6 @@
   1.137      return GST_FLOW_ERROR;
   1.138    }
   1.139  
   1.140 -#if 0
   1.141 -need_pause:
   1.142 -  {
   1.143 -    const gchar *reason = gst_flow_get_name (ret);
   1.144 -
   1.145 -    GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
   1.146 -    return GST_FLOW_UNEXPECTED;
   1.147 -  }
   1.148 -#endif
   1.149  }
   1.150  
   1.151  void
   1.152 @@ -690,16 +681,14 @@
   1.153  
   1.154    if (src->content_size <= 0) {
   1.155      ret= FALSE;
   1.156 -  } else if ( src->content_size >= src->read_offset && 
   1.157 -      			abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) {
   1.158 -    g_static_mutex_lock( &update_size_mutex );
   1.159 +  } else if ( abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) {
   1.160 +    //g_static_mutex_lock( &update_size_mutex );
   1.161  
   1.162    	guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
   1.163    	if ( src->content_size < new_offset ) {
   1.164    	  src->content_size = new_offset;
   1.165    	}
   1.166   
   1.167 -#if 0
   1.168  #if ENABLE_TIMING_POSITION == 1
   1.169      guint64 size_tmp = 0;
   1.170      if (src->live_tv == TRUE) {
   1.171 @@ -714,8 +703,7 @@
   1.172  	  __FUNCTION__, size_tmp );
   1.173      }
   1.174  #endif
   1.175 -#endif
   1.176 -    g_static_mutex_unlock( &update_size_mutex );
   1.177 +    //g_static_mutex_unlock( &update_size_mutex );
   1.178  
   1.179    }
   1.180  
   1.181 @@ -771,14 +759,17 @@
   1.182      case GST_EVENT_EOS:
   1.183        g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
   1.184  	  guint64 cont_size = gst_mythtv_src_get_position (src);
   1.185 -	  if ( cont_size > src->content_size ) {
   1.186 -	  	src->content_size = cont_size;
   1.187 -	  	src->eos = FALSE;
   1.188 -  	  } else {
   1.189 -      	src->eos = TRUE;
   1.190 -      	gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
   1.191 -      	gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
   1.192 -  	  }
   1.193 +	  if ( !src->live_tv ) {
   1.194 +		  if ( cont_size > src->content_size ) {
   1.195 +		  	src->content_size = cont_size;
   1.196 +		  	src->eos = FALSE;
   1.197 +	  	  } else {
   1.198 +	      	src->eos = TRUE;
   1.199 +	      	gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
   1.200 +	      	gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
   1.201 +	  	  }
   1.202 +	  } else 
   1.203 +	  	src->eos = TRUE;
   1.204        break;
   1.205  #if 0
   1.206      case GST_EVENT_NEWSEGMENT: