[svn r94] Changed to use GstAdapter, instead of using the guint pointer. trunk
authorrosfran
Fri Nov 17 15:20:28 2006 +0000 (2006-11-17)
branchtrunk
changeset 93ae73b4837eed
parent 92 e594fc21deef
child 94 da398435732b
[svn r94] Changed to use GstAdapter, instead of using the guint pointer.
gst-plugins-mythtv/src/gstmythtvsrc.c
     1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c	Fri Nov 17 14:46:38 2006 +0000
     1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c	Fri Nov 17 15:20:28 2006 +0000
     1.3 @@ -42,12 +42,12 @@
     1.4  //( 32*1024  )
     1.5  
     1.6  /* 4*1024 ??? */
     1.7 -#define MAX_READ_SIZE              		12*1024
     1.8 +#define MAX_READ_SIZE              		6*1024
     1.9  //( 32*1024 )
    1.10  
    1.11  #define GST_FLOW_ERROR_NO_DATA  		-101
    1.12  
    1.13 -#define INTERNAL_BUFFER_SIZE			18*1024
    1.14 +#define INTERNAL_BUFFER_SIZE			28*1024
    1.15  
    1.16  /* stablish a maximum iteration value to the IS_RECORDING message */
    1.17  static guint wait_to_transfer = 0;
    1.18 @@ -113,7 +113,7 @@
    1.19  static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
    1.20  
    1.21  static gint do_read_request_response (GstMythtvSrc * src, guint64 offset, 
    1.22 -    guint size, gint8 **data_ptr);
    1.23 +    guint size, guint8 **data_ptr);
    1.24  
    1.25  GStaticRecMutex th_mutex = G_STATIC_REC_MUTEX_INIT;
    1.26  
    1.27 @@ -328,7 +328,7 @@
    1.28  }
    1.29  
    1.30  static gint
    1.31 -do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, gint8 **data_ptr)
    1.32 +do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, guint8 **data_ptr)
    1.33  {
    1.34    gint read = 0;
    1.35    guint sizetoread = size;
    1.36 @@ -572,20 +572,23 @@
    1.37      goto change_progchain;
    1.38    
    1.39    //g_static_rec_mutex_lock( &th_mutex );
    1.40 +  g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size );
    1.41  
    1.42    while ( src->adapter != NULL && ( ( adapter_size = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) &&
    1.43        --max_adapter_rep > 0 )
    1.44    {
    1.45 -    g_print ( "[%s] %d - Waiting for read_ahead task...\n", __FUNCTION__, max_adapter_rep );
    1.46 +    g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size );
    1.47      //GST_TASK_WAIT( src->th_read_ahead );
    1.48    }
    1.49  
    1.50 +  g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size );
    1.51 +
    1.52    //gst_task_pause( src->th_read_ahead );
    1.53  
    1.54    //g_static_rec_mutex_unlock( &th_mutex );
    1.55  
    1.56    /* just get from the adapter, no network effort... */
    1.57 -  if ( adapter_size > 0 )	
    1.58 +  if ( FALSE )	
    1.59    {
    1.60      //g_static_rec_mutex_lock( &th_mutex );
    1.61  
    1.62 @@ -597,6 +600,7 @@
    1.63      //g_static_rec_mutex_unlock( &th_mutex );
    1.64  
    1.65    } else { 
    1.66 +    GstBuffer *buffer;
    1.67      guint size = (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
    1.68  
    1.69      g_print ( "[%s]\t\tCreate: buffer_offset: %d, buffer_remain: %d\n", __FUNCTION__, 
    1.70 @@ -615,12 +619,14 @@
    1.71  	goto done;
    1.72      }
    1.73  
    1.74 -    if (src->buffer_remain < MAX_READ_SIZE) {
    1.75 -      gint8 *tmp_buffer = g_malloc0( INTERNAL_BUFFER_SIZE ); // FIXME: DON'T ALLOC EVERY TIME
    1.76 +    if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) {
    1.77 +      //gint8 *tmp_buffer = g_malloc0( INTERNAL_BUFFER_SIZE ); // FIXME: DON'T ALLOC EVERY TIME
    1.78 +      buffer = gst_buffer_new_and_alloc( INTERNAL_BUFFER_SIZE - src->buffer_remain );
    1.79  
    1.80 -      memcpy (tmp_buffer, src->buffer + src->buffer_offset, src->buffer_remain);
    1.81 +      //g_memmove (tmp_buffer, src->buffer + src->buffer_offset, src->buffer_remain);
    1.82 +      //g_memmove( tmp_buffer, src->buffer, src->buffer_remain );
    1.83  
    1.84 -      read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &tmp_buffer );
    1.85 +      read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) );
    1.86  
    1.87        if (G_UNLIKELY (read < 0)) {
    1.88  	if ( src->live_tv )
    1.89 @@ -632,24 +638,30 @@
    1.90        if ( G_UNLIKELY (src->update_prog_chain) )
    1.91  	goto change_progchain;
    1.92  
    1.93 +      gst_adapter_push( src->adapter, buffer );
    1.94 +
    1.95        //len = gmyth_file_transfer_read( src->file_transfer,
    1.96        //  tmp_buffer + src->buffer_remain, INTERNAL_BUFFER_SIZE - src->buffer_remain, TRUE );
    1.97        // fixme: handle eos
    1.98        // fixme: can I deallocate the previous buffer here?
    1.99 -      g_memmove( src->buffer + src->buffer_remain, tmp_buffer, read);
   1.100 +      //g_memmove( src->buffer, tmp_buffer, INTERNAL_BUFFER_SIZE );
   1.101        src->buffer_offset = 0;
   1.102        src->buffer_remain = src->buffer_remain + read;
   1.103  
   1.104 -      // g_free( tmp_buffer );
   1.105 +      //g_free( tmp_buffer );
   1.106  
   1.107      }
   1.108  
   1.109 +    size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
   1.110 +
   1.111 +    buffer = gst_adapter_take_buffer( src->adapter, size );
   1.112 +
   1.113      g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain );
   1.114  
   1.115 -    GST_BUFFER_SIZE (*outbuf) = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
   1.116 +    GST_BUFFER_SIZE (*outbuf) = size;
   1.117      GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
   1.118      GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
   1.119 -    g_memmove( GST_BUFFER_DATA( (*outbuf) ), src->buffer + src->buffer_offset, GST_BUFFER_SIZE(*outbuf) );
   1.120 +    g_memmove( GST_BUFFER_DATA( (*outbuf) ), GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(*outbuf) );
   1.121      GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
   1.122      GST_BUFFER_OFFSET_END (*outbuf) = src->read_offset + GST_BUFFER_SIZE (*outbuf);
   1.123  
   1.124 @@ -660,6 +672,9 @@
   1.125      src->bytes_read += GST_BUFFER_SIZE (*outbuf);
   1.126      g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) );
   1.127  
   1.128 +    //gst_adapter_flush( src->adapter, size );
   1.129 +    gst_buffer_unref( buffer );
   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 );