[vlc-commits] transcode: send NULL packet to audio encoder when closing

Ilkka Ollakka git at videolan.org
Fri Oct 19 11:24:24 CEST 2012


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Fri Oct 19 12:20:58 2012 +0300| [940cf07d668f41d3d01ff87f4647afc37b4dca80] | committer: Ilkka Ollakka

transcode: send NULL packet to audio encoder when closing

As with Video-encoders, audio encoder can flush buffers in that case.
Currently avcodec doesn't handle flushing and other encoders in this
changeset (flac,speex,twolame,vorbis) have only boilerplate to check
against NULL input so they don't crash.

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

 modules/codec/avcodec/encoder.c          |    3 +++
 modules/codec/flac.c                     |    3 +++
 modules/codec/speex.c                    |    3 +++
 modules/codec/twolame.c                  |    4 ++++
 modules/codec/vorbis.c                   |    3 +++
 modules/stream_out/transcode/transcode.c |    1 +
 6 files changed, 17 insertions(+)

diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 22a3697..a5d10ba 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -1061,6 +1061,9 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
 
     block_t *p_block, *p_chain = NULL;
 
+    /*FIXME: change to use  avcodec_encode_audio2 to be able to flush*/
+    if( unlikely( !p_aout_buf ) ) return NULL;
+
     uint8_t *p_buffer = p_aout_buf->p_buffer;
     int i_samples = p_aout_buf->i_nb_samples;
     int i_samples_delay = p_sys->i_samples_delay;
diff --git a/modules/codec/flac.c b/modules/codec/flac.c
index dda9fd3..64a3f9e 100644
--- a/modules/codec/flac.c
+++ b/modules/codec/flac.c
@@ -755,6 +755,9 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
     block_t *p_chain;
     unsigned int i;
 
+    /* FIXME: p_aout_buf is NULL when it's time to flush*/
+    if( unlikely( !p_aout_buf ) ) return NULL;
+
     p_sys->i_pts = p_aout_buf->i_pts -
                 (mtime_t)1000000 * (mtime_t)p_sys->i_samples_delay /
                 (mtime_t)p_enc->fmt_in.audio.i_rate;
diff --git a/modules/codec/speex.c b/modules/codec/speex.c
index 40eac1a..03ccd1f 100644
--- a/modules/codec/speex.c
+++ b/modules/codec/speex.c
@@ -989,6 +989,9 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
     encoder_sys_t *p_sys = p_enc->p_sys;
     block_t *p_block, *p_chain = NULL;
 
+    /* Encoder gets NULL when it's time to flush */
+    if( unlikely( !p_aout_buf ) ) return NULL;
+
     unsigned char *p_buffer = p_aout_buf->p_buffer;
     int i_samples = p_aout_buf->i_nb_samples;
     int i_samples_delay = p_sys->i_samples_delay;
diff --git a/modules/codec/twolame.c b/modules/codec/twolame.c
index 9fe3665..fb515c7 100644
--- a/modules/codec/twolame.c
+++ b/modules/codec/twolame.c
@@ -261,6 +261,10 @@ static void Bufferize( encoder_t *p_enc, int16_t *p_in, int i_nb_samples )
 static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
 {
     encoder_sys_t *p_sys = p_enc->p_sys;
+
+    /* FIXME:p_aout_buf is NULL when it's time to flush, does twolame has buffer to flush?*/
+    if( unlikely( !p_aout_buf ) ) return NULL;
+
     int16_t *p_buffer = (int16_t *)p_aout_buf->p_buffer;
     int i_nb_samples = p_aout_buf->i_nb_samples;
     block_t *p_chain = NULL;
diff --git a/modules/codec/vorbis.c b/modules/codec/vorbis.c
index 0e49377..524d79a 100644
--- a/modules/codec/vorbis.c
+++ b/modules/codec/vorbis.c
@@ -848,6 +848,9 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
     block_t *p_block, *p_chain = NULL;
     float **buffer;
 
+    /* FIXME: flush buffers in here */
+    if( unlikely( !p_aout_buf ) ) return NULL;
+
     mtime_t i_pts = p_aout_buf->i_pts -
                 (mtime_t)1000000 * (mtime_t)p_sys->i_samples_delay /
                 (mtime_t)p_enc->fmt_in.audio.i_rate;
diff --git a/modules/stream_out/transcode/transcode.c b/modules/stream_out/transcode/transcode.c
index e6db2de..568f795 100644
--- a/modules/stream_out/transcode/transcode.c
+++ b/modules/stream_out/transcode/transcode.c
@@ -601,6 +601,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
         switch( id->p_decoder->fmt_in.i_cat )
         {
         case AUDIO_ES:
+            Send( p_stream, id, NULL );
             transcode_audio_close( id );
             break;
         case VIDEO_ES:



More information about the vlc-commits mailing list