[vlc-commits] araw: zero copy for native audio sample formats

Rémi Denis-Courmont git at videolan.org
Fri Jul 26 18:50:50 CEST 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Jul 26 19:49:23 2013 +0300| [46f782a9f775156c1f9e53a39632e28e9854c6ef] | committer: Rémi Denis-Courmont

araw: zero copy for native audio sample formats

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=46f782a9f775156c1f9e53a39632e28e9854c6ef
---

 modules/codec/araw.c |   57 ++++++++++++++++++++++----------------------------
 1 file changed, 25 insertions(+), 32 deletions(-)

diff --git a/modules/codec/araw.c b/modules/codec/araw.c
index b8064ef..87d853d 100644
--- a/modules/codec/araw.c
+++ b/modules/codec/araw.c
@@ -297,10 +297,13 @@ static int DecoderOpen( vlc_object_t *p_this )
 static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
-
-    if( !pp_block || !*pp_block ) return NULL;
+    if( pp_block == NULL )
+        return NULL;
 
     block_t *p_block = *pp_block;
+    if( p_block == NULL )
+        return NULL;
+    *pp_block = NULL;
 
     if( p_block->i_pts > VLC_TS_INVALID &&
         p_block->i_pts != date_Get( &p_sys->end_date ) )
@@ -308,47 +311,37 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         date_Set( &p_sys->end_date, p_block->i_pts );
     }
     else if( !date_Get( &p_sys->end_date ) )
-    {
         /* We've just started the stream, wait for the first PTS. */
-        block_Release( p_block );
-        return NULL;
-    }
-
-    /* Don't re-use the same pts twice */
-    p_block->i_pts = VLC_TS_INVALID;
+        goto skip;
 
     unsigned samples = (8 * p_block->i_buffer) / p_sys->framebits;
     if( samples == 0 )
-    {
-        block_Release( p_block );
-        return NULL;
-    }
+        goto skip;
 
-    /* Create chunks of max 1024 samples */
-    if( samples > 1024 ) samples = 1024;
-
-    block_t *p_out = decoder_NewAudioBuffer( p_dec, samples );
-    if( p_out == NULL )
+    if( p_sys->decode != NULL )
     {
-        block_Release( p_block );
-        return NULL;
-    }
-
-    p_out->i_pts = date_Get( &p_sys->end_date );
-    p_out->i_length = date_Increment( &p_sys->end_date, samples )
-                      - p_out->i_pts;
+        block_t *p_out = decoder_NewAudioBuffer( p_dec, samples );
+        if( p_out == NULL )
+            goto skip;
 
-    if( p_sys->decode != NULL )
         p_sys->decode( p_out->p_buffer, p_block->p_buffer,
                        samples * p_dec->fmt_in.audio.i_channels );
+        block_Release( p_block );
+        p_block = p_out;
+    }
     else
-        memcpy( p_out->p_buffer, p_block->p_buffer, p_out->i_buffer );
-
-    samples = (samples * p_sys->framebits) / 8;
-    p_block->p_buffer += samples;
-    p_block->i_buffer -= samples;
+    {
+        decoder_UpdateAudioFormat( p_dec );
+        p_block->i_buffer = samples * (p_sys->framebits / 8);
+    }
 
-    return p_out;
+    p_block->i_pts = date_Get( &p_sys->end_date );
+    p_block->i_length = date_Increment( &p_sys->end_date, samples )
+                      - p_block->i_pts;
+    return p_block;
+skip:
+    block_Release( p_block );
+    return NULL;
 }
 
 static void S8Decode( void *outp, const uint8_t *in, unsigned samples )



More information about the vlc-commits mailing list