[vlc-commits] avcodec: zero copy audio decoding

Rémi Denis-Courmont git at videolan.org
Sat Mar 9 10:42:00 CET 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Mar  9 11:28:08 2013 +0200| [ebc321e8526e9399191c3fa26429b536dcc62a56] | committer: Rémi Denis-Courmont

avcodec: zero copy audio decoding

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

 modules/codec/avcodec/audio.c |   38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 0182d72..2c74220 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -353,31 +353,37 @@ block_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
                          p_dec->fmt_out.audio.i_format );
         if( ctx->channels > AV_NUM_DATA_POINTERS )
             free( frame.extended_data );
+        block_Release( p_block );
+        p_block = p_buffer;
     }
-    else /* TODO: zero copy... need to replace decoder_NewAudioBuffer() */
-        memcpy( p_buffer->p_buffer, p_block->p_buffer, p_block->i_buffer );
+    else /* FIXME: improve decoder_NewAudioBuffer(), avoid useless buffer... */
+        block_Release( p_buffer );
 
     if (p_sys->b_extract)
     {   /* TODO: do not drop channels... at least not here */
-        aout_ChannelExtract( p_block->p_buffer,
+        p_buffer = block_Alloc( p_dec->fmt_out.audio.i_bytes_per_frame
+                                * frame.nb_samples );
+        if( unlikely(p_buffer == NULL) )
+        {
+            block_Release( p_block );
+            return NULL;
+        }
+        aout_ChannelExtract( p_buffer->p_buffer,
                              p_dec->fmt_out.audio.i_channels,
-                             p_buffer->p_buffer, ctx->channels,
+                             p_block->p_buffer, ctx->channels,
                              frame.nb_samples, p_sys->pi_extraction,
                              p_dec->fmt_out.audio.i_bitspersample );
-        block_Release( p_buffer );
-        p_buffer = p_block;
-    }
-    else
         block_Release( p_block );
+        p_block = p_buffer;
+    }
 
-    p_buffer->i_nb_samples = frame.nb_samples;
-    p_buffer->i_buffer = frame.nb_samples
-                         * p_dec->fmt_out.audio.i_bytes_per_frame;
-    p_buffer->i_pts = date_Get( &p_sys->end_date );
-    p_buffer->i_length = date_Increment( &p_sys->end_date, frame.nb_samples )
-                         - p_buffer->i_pts;
-
-    return p_buffer;
+    p_block->i_nb_samples = frame.nb_samples;
+    p_block->i_buffer = frame.nb_samples
+                        * p_dec->fmt_out.audio.i_bytes_per_frame;
+    p_block->i_pts = date_Get( &p_sys->end_date );
+    p_block->i_length = date_Increment( &p_sys->end_date, frame.nb_samples )
+                        - p_block->i_pts;
+    return p_block;
 
 end:
     block_Release(p_block);



More information about the vlc-commits mailing list