]> git.sesse.net Git - vlc/commitdiff
Make aout_buffer_t an alias for block_t
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 23 Sep 2009 18:38:26 +0000 (21:38 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Wed, 23 Sep 2009 19:00:07 +0000 (22:00 +0300)
include/vlc_aout.h
include/vlc_common.h
modules/audio_filter/resampler/bandlimited.c
modules/audio_filter/resampler/linear.c
modules/audio_filter/scaletempo.c
modules/stream_out/transcode.c
src/audio_output/common.c

index bad59803f9ffe99e46c1a414b9044360a26dbe00..39b38d1d38f9add12e60e62f2c7431a79deeaa1c 100644 (file)
@@ -125,25 +125,7 @@ typedef int32_t vlc_fixed_t;
  * Main audio output structures
  *****************************************************************************/
 
-/** audio output buffer */
-struct aout_buffer_t
-{
-    uint8_t *               p_buffer;
-    /* i_size is the real size of the buffer (used for debug ONLY), i_nb_bytes
-     * is the number of significative bytes in it. */
-    size_t                  i_size, i_buffer;
-    unsigned int            i_nb_samples;
-    uint32_t                i_flags;
-    mtime_t                 i_pts, i_length;
-
-    struct aout_buffer_t *  p_next;
-    void                 *p_sys;
-};
-
-static inline void aout_BufferFree( aout_buffer_t *buffer )
-{
-    free( buffer );
-}
+#define aout_BufferFree( buffer ) block_Release( buffer )
 
 /* Size of a frame for S/PDIF output. */
 #define AOUT_SPDIF_SIZE 6144
@@ -171,6 +153,7 @@ struct aout_fifo_t
 
 /* FIXME to remove once aout.h is cleaned a bit more */
 #include <vlc_aout_mixer.h>
+#include <vlc_block.h>
 
 /* */
 typedef struct
index 0b2ef8799526143d8f335209e07fd2446c974159..87a0610955af20819abfe0446d8e9a672bc29713 100644 (file)
@@ -206,7 +206,7 @@ typedef struct aout_instance_t aout_instance_t;
 typedef struct aout_sys_t aout_sys_t;
 typedef struct aout_fifo_t aout_fifo_t;
 typedef struct aout_input_t aout_input_t;
-typedef struct aout_buffer_t aout_buffer_t;
+typedef struct block_t aout_buffer_t;
 typedef audio_format_t audio_sample_format_t;
 typedef struct audio_date_t audio_date_t;
 typedef struct aout_filter_t aout_filter_t;
index a721f8ebbf6dcc7d77e5a54d677f9ffed0e12c79..8167271fa1801ae2e4540794f8767afd9aa7fb23 100644 (file)
@@ -201,16 +201,16 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     /* Check if we really need to run the resampler */
     if( i_out_rate == p_filter->input.i_rate )
     {
+#if 0   /* FIXME: needs audio filter2 to use block_Realloc */
         if( /*p_filter->b_continuity && /--* What difference does it make ? :) */
-            p_sys->i_old_wing &&
-            p_in_buf->i_size >=
-              p_in_buf->i_buffer + p_sys->i_old_wing *
-              p_filter->input.i_bytes_per_frame )
+            p_sys->i_old_wing )
         {
             /* output the whole thing with the samples from last time */
-            memmove( ((float *)(p_in_buf->p_buffer)) +
-                     i_nb_channels * p_sys->i_old_wing,
-                     p_in_buf->p_buffer, p_in_buf->i_buffer );
+            p_in_buf = block_Realloc( p_in_buf,
+                p_sys->i_old_wing * p_filter->input.i_bytes_per_frame,
+                p_in_buf->i_buffer );
+            if( !p_in_buf )
+                abort();
             memcpy( p_in_buf->p_buffer, p_sys->p_buf +
                     i_nb_channels * p_sys->i_old_wing,
                     p_sys->i_old_wing *
@@ -227,6 +227,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
             p_out_buf->i_buffer = p_out_buf->i_nb_samples *
                 p_filter->input.i_bytes_per_frame;
         }
+#endif
         p_filter->b_continuity = false;
         p_sys->i_old_wing = 0;
         return;
@@ -269,7 +270,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
                 p_in_buf->i_nb_samples * p_filter->input.i_bytes_per_frame );
 
     /* Make sure the output buffer is reset */
-    memset( p_out, 0, p_out_buf->i_size );
+    memset( p_out, 0, p_out_buf->i_buffer );
 
     /* Calculate the new length of the filter wing */
     d_factor = (double)i_out_rate / p_filter->input.i_rate;
@@ -327,7 +328,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
 #endif
 
                 /* Sanity check */
-                if( p_out_buf->i_size/p_filter->input.i_bytes_per_frame
+                if( p_out_buf->i_buffer/p_filter->input.i_bytes_per_frame
                     <= (unsigned int)i_out+1 )
                 {
                     p_out += i_nb_channels;
@@ -402,7 +403,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
                 }
 #endif
                 /* Sanity check */
-                if( p_out_buf->i_size/p_filter->input.i_bytes_per_frame
+                if( p_out_buf->i_buffer/p_filter->input.i_bytes_per_frame
                     <= (unsigned int)i_out+1 )
                 {
                     p_out += i_nb_channels;
@@ -448,7 +449,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     }
 
 #if 0
-    msg_Err( p_filter, "p_out size: %i, nb bytes out: %i", p_out_buf->i_size,
+    msg_Err( p_filter, "p_out size: %i, nb bytes out: %i", p_out_buf->i_buffer,
              i_out * p_filter->input.i_bytes_per_frame );
 #endif
 
@@ -586,10 +587,10 @@ static block_t *Resample( filter_t *p_filter, block_t *p_block )
     p_filter->p_sys->b_first = false;
 
     in_buf.p_buffer = p_block->p_buffer;
-    in_buf.i_buffer = in_buf.i_size = p_block->i_buffer;
+    in_buf.i_buffer = p_block->i_buffer;
     in_buf.i_nb_samples = p_block->i_nb_samples;
     out_buf.p_buffer = p_out->p_buffer;
-    out_buf.i_buffer = out_buf.i_size = p_out->i_buffer;
+    out_buf.i_buffer = p_out->i_buffer;
     out_buf.i_nb_samples = p_out->i_nb_samples;
 
     DoWork( (aout_instance_t *)p_filter, &aout_filter, &in_buf, &out_buf );
index c97ad7365f10fed76f195a8164d3f0f043310017..d64d71e507e28b3fc5cb426fa11a09c55bc6ca87 100644 (file)
@@ -147,16 +147,18 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     /* Check if we really need to run the resampler */
     if( p_aout->mixer_format.i_rate == p_filter->input.i_rate )
     {
-        if( p_filter->b_continuity &&
-            p_in_buf->i_size >=
-              p_in_buf->i_buffer + sizeof(float) * i_nb_channels )
+#if 0   /* FIXME: needs audio filter2 for block_Realloc */
+        if( p_filter->b_continuity )
         {
-            /* output the whole thing with the last sample from last time */
-            memmove( ((float *)(p_in_buf->p_buffer)) + i_nb_channels,
-                     p_in_buf->p_buffer, p_in_buf->i_buffer );
+            p_in_buf = block_Realloc( p_in_buf, sizeof(float) * i_nb_channels,
+                                      p_in_buf->i_buffer );
+            if( !p_in_buf )
+                abort();
+
             memcpy( p_in_buf->p_buffer, p_prev_sample,
                     i_nb_channels * sizeof(float) );
         }
+#endif
         p_filter->b_continuity = false;
         return;
     }
index 5161e937b8049dd638e742db242fbccb7e403bc3..5eb18505b1e8f65202377f2b32801445a96db401 100644 (file)
@@ -501,7 +501,13 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     }
 
     size_t i_outsize = calculate_output_buffer_size ( p_filter, p_in_buf->i_buffer );
-    if( i_outsize > p_out_buf->i_size ) {
+    if( i_outsize > p_out_buf->i_buffer ) {
+#if 0   /* FIXME: This requires audio filter2 to work */
+        p_out_buf = block_Realloc( p_out_buf, i_outsize, 0 );
+        if( p_out_buf == NULL )
+            abort();
+#else   /* This fails horribly if we have more than two buffers in the
+         * pipeline, or if the buffer is passed to another thread... XXX */
         void *temp = realloc( p->p_buffers[ p->i_buf ], i_outsize );
         if( temp == NULL )
         {
@@ -510,6 +516,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
         p->p_buffers[ p->i_buf ] = temp;
         p_out_buf->p_buffer = p->p_buffers[ p->i_buf ];
         p->i_buf = ! p->i_buf;
+#endif
     }
 
     size_t bytes_out = transform_buffer( p_filter,
index e98822ae8ce5df8585b49f22a7adb356004cf2b1..5bd52ad895bb82caa0ad79fa3eca5a00c8424488 100644 (file)
@@ -1284,8 +1284,7 @@ static int transcode_audio_process( sout_stream_t *p_stream,
                                     block_t *in, block_t **out )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
-    aout_buffer_t *p_audio_buf;
-    block_t *p_block, *p_audio_block;
+    block_t *p_block, *p_audio_buf;
     *out = NULL;
 
     while( (p_audio_buf = id->p_decoder->pf_decode_audio( id->p_decoder,
@@ -1307,36 +1306,29 @@ static int transcode_audio_process( sout_stream_t *p_stream,
             p_audio_buf->i_pts -= p_sys->i_master_drift;
         }
 
-        p_audio_block = p_audio_buf->p_sys;
-        p_audio_block->i_buffer = p_audio_buf->i_buffer;
-        p_audio_block->i_dts = p_audio_block->i_pts =
-            p_audio_buf->i_pts;
-        p_audio_block->i_length = p_audio_buf->i_length;
-        p_audio_block->i_nb_samples = p_audio_buf->i_nb_samples;
+        p_audio_buf->i_dts = p_audio_buf->i_pts;
 
         /* Run filter chain */
         if( id->p_uf_chain )
         {
-            p_audio_block = filter_chain_AudioFilter( id->p_uf_chain, p_audio_block );
-            assert( p_audio_block );
+            p_audio_buf = filter_chain_AudioFilter( id->p_uf_chain,
+                                                    p_audio_buf );
+            if( !p_audio_buf )
+                abort();
         }
 
-        p_audio_block = filter_chain_AudioFilter( id->p_f_chain, p_audio_block );
-        assert( p_audio_block );
+        p_audio_buf = filter_chain_AudioFilter( id->p_f_chain, p_audio_buf );
+        if( !p_audio_buf )
+            abort();
 
-        p_audio_buf->p_buffer = p_audio_block->p_buffer;
-        p_audio_buf->i_buffer = p_audio_block->i_buffer;
-        p_audio_buf->i_nb_samples = p_audio_block->i_nb_samples;
-        p_audio_buf->i_pts = p_audio_block->i_dts;
-        p_audio_buf->i_length = p_audio_block->i_length;
+        p_audio_buf->i_pts = p_audio_buf->i_dts;
 
         audio_timer_start( id->p_encoder );
         p_block = id->p_encoder->pf_encode_audio( id->p_encoder, p_audio_buf );
         audio_timer_stop( id->p_encoder );
 
         block_ChainAppend( out, p_block );
-        block_Release( p_audio_block );
-        free( p_audio_buf );
+        block_Release( p_audio_buf );
     }
 
     return VLC_SUCCESS;
@@ -1344,7 +1336,6 @@ static int transcode_audio_process( sout_stream_t *p_stream,
 
 static aout_buffer_t *audio_new_buffer( decoder_t *p_dec, int i_samples )
 {
-    aout_buffer_t *p_buffer;
     block_t *p_block;
     int i_size;
 
@@ -1364,24 +1355,15 @@ static aout_buffer_t *audio_new_buffer( decoder_t *p_dec, int i_samples )
         i_size = i_samples * 4 * p_dec->fmt_out.audio.i_channels;
     }
 
-    p_buffer = malloc( sizeof(aout_buffer_t) );
-    if( !p_buffer ) return NULL;
-    p_buffer->i_flags = 0;
-    p_buffer->p_sys = p_block = block_New( p_dec, i_size );
-
-    p_buffer->p_buffer = p_block->p_buffer;
-    p_buffer->i_size = p_buffer->i_buffer = p_block->i_buffer;
-    p_buffer->i_nb_samples = i_samples;
+    p_block = block_New( p_dec, i_size );
     p_block->i_nb_samples = i_samples;
-
-    return p_buffer;
+    return p_block;
 }
 
 static void audio_del_buffer( decoder_t *p_dec, aout_buffer_t *p_buffer )
 {
     VLC_UNUSED(p_dec);
-    if( p_buffer && p_buffer->p_sys ) block_Release( p_buffer->p_sys );
-    free( p_buffer );
+    block_Release( p_buffer );
 }
 
 /*
index 8647c7702a98a6355a5db093f97d3880b47d49c1..62b11e8cc84b61eccfaa21765be03cb965966af9 100644 (file)
@@ -707,18 +707,8 @@ aout_buffer_t *aout_BufferAlloc(aout_alloc_t *allocation, mtime_t microseconds,
         return old_buffer;
     }
 
-    aout_buffer_t *buffer;
-    int i_alloc_size;
-
-    i_alloc_size = (int)( (uint64_t)allocation->i_bytes_per_sec
+    size_t i_alloc_size = (int)( (uint64_t)allocation->i_bytes_per_sec
                                         * (microseconds) / 1000000 + 1 );
 
-    buffer = malloc( i_alloc_size + sizeof(aout_buffer_t) );
-    if ( !buffer )
-        return NULL;
-
-    buffer->i_size = i_alloc_size;
-    buffer->p_buffer = (uint8_t *)buffer + sizeof(aout_buffer_t);
-    buffer->i_flags = 0;
-    return buffer;
+    return block_Alloc( i_alloc_size );
 }