[vlc-devel] [PATCH 1/3] decoder: audio: don't update format when creating a buffer

Thomas Guillem thomas at gllm.fr
Thu Sep 22 10:20:43 CEST 2016


---
 modules/codec/adpcm.c        | 2 ++
 modules/codec/aes3.c         | 2 ++
 modules/codec/araw.c         | 2 ++
 modules/codec/dmo/dmo.c      | 6 ++++++
 modules/codec/faad.c         | 5 ++++-
 modules/codec/flac.c         | 3 +++
 modules/codec/fluidsynth.c   | 2 ++
 modules/codec/g711.c         | 5 +++++
 modules/codec/lpcm.c         | 2 ++
 modules/codec/mft.c          | 2 ++
 modules/codec/mpeg_audio.c   | 2 ++
 modules/codec/mpg123.c       | 2 ++
 modules/codec/omxil/omxil.c  | 2 ++
 modules/codec/opus.c         | 2 ++
 modules/codec/speex.c        | 9 +++++++--
 modules/codec/uleaddvaudio.c | 2 ++
 modules/codec/vorbis.c       | 1 +
 modules/codec/wmafixed/wma.c | 2 ++
 src/input/decoder.c          | 3 ---
 19 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/modules/codec/adpcm.c b/modules/codec/adpcm.c
index ce89b2d..34a2417 100644
--- a/modules/codec/adpcm.c
+++ b/modules/codec/adpcm.c
@@ -317,6 +317,8 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     {
         block_t *p_out;
 
+        if( decoder_UpdateAudioFormat( p_dec ) )
+            goto drop;
         p_out = decoder_NewAudioBuffer( p_dec, p_sys->i_samplesperblock );
         if( p_out == NULL )
             goto drop;
diff --git a/modules/codec/aes3.c b/modules/codec/aes3.c
index 48278ea..70b02c3 100644
--- a/modules/codec/aes3.c
+++ b/modules/codec/aes3.c
@@ -146,6 +146,8 @@ static block_t *Decode( decoder_t *p_dec, block_t **pp_block )
     if( !p_block )
         return NULL;
 
+    if( decoder_UpdateAudioFormat( p_dec ) )
+        goto exit;
     p_aout_buffer = decoder_NewAudioBuffer( p_dec, i_frame_length );
     if( p_aout_buffer == NULL )
         goto exit;
diff --git a/modules/codec/araw.c b/modules/codec/araw.c
index 7b076e6..5e323f6 100644
--- a/modules/codec/araw.c
+++ b/modules/codec/araw.c
@@ -347,6 +347,8 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
     if( p_sys->decode != NULL )
     {
+        if( decoder_UpdateAudioFormat( p_dec ) )
+            goto skip;
         block_t *p_out = decoder_NewAudioBuffer( p_dec, samples );
         if( p_out == NULL )
             goto skip;
diff --git a/modules/codec/dmo/dmo.c b/modules/codec/dmo/dmo.c
index b969781..663a9f9 100644
--- a/modules/codec/dmo/dmo.c
+++ b/modules/codec/dmo/dmo.c
@@ -972,6 +972,12 @@ static void *DecBlock( decoder_t *p_dec, block_t **pp_block )
     }
     else
     {
+        if( decoder_UpdateAudioFormat( p_dec ) )
+        {
+            p_out->vt->Release( (IUnknown *)p_out );
+            return NULL;
+        }
+
         block_t *p_aout_buffer;
         int i_samples = block_out.i_buffer /
             ( p_dec->fmt_out.audio.i_bitspersample *
diff --git a/modules/codec/faad.c b/modules/codec/faad.c
index 642e08b..137188c 100644
--- a/modules/codec/faad.c
+++ b/modules/codec/faad.c
@@ -492,7 +492,10 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 p_dec->fmt_out.audio.i_physical_channels;
         }
         p_dec->fmt_out.audio.i_channels = nbChannels;
-        p_out = decoder_NewAudioBuffer( p_dec, frame.samples / nbChannels );
+        if( decoder_UpdateAudioFormat( p_dec ) )
+            p_out = NULL;
+        else
+            p_out = decoder_NewAudioBuffer( p_dec, frame.samples / nbChannels );
         if( p_out == NULL )
         {
             p_sys->i_buffer = 0;
diff --git a/modules/codec/flac.c b/modules/codec/flac.c
index 3aca417..a308cb4 100644
--- a/modules/codec/flac.c
+++ b/modules/codec/flac.c
@@ -180,6 +180,9 @@ DecoderWriteCallback( const FLAC__StreamDecoder *decoder,
 
     const unsigned char *pi_reorder = ppi_reorder[p_dec->fmt_out.audio.i_channels];
 
+    if( decoder_UpdateAudioFormat( p_dec ) )
+        return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+
     p_sys->p_aout_buffer =
         decoder_NewAudioBuffer( p_dec, frame->header.blocksize );
 
diff --git a/modules/codec/fluidsynth.c b/modules/codec/fluidsynth.c
index e0fd620..b7e43b3 100644
--- a/modules/codec/fluidsynth.c
+++ b/modules/codec/fluidsynth.c
@@ -297,6 +297,8 @@ static block_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block)
     if (samples == 0)
         goto drop;
 
+    if (decoder_UpdateAudioFormat (p_dec))
+        goto drop;
     p_out = decoder_NewAudioBuffer (p_dec, samples);
     if (p_out == NULL)
         goto drop;
diff --git a/modules/codec/g711.c b/modules/codec/g711.c
index 613cebd..ec7292d 100644
--- a/modules/codec/g711.c
+++ b/modules/codec/g711.c
@@ -263,6 +263,11 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
 
+    if( decoder_UpdateAudioFormat( p_dec ) )
+    {
+        block_Release( p_block );
+        return NULL;
+    }
     block_t *p_out = decoder_NewAudioBuffer( p_dec, samples );
     if( p_out == NULL )
     {
diff --git a/modules/codec/lpcm.c b/modules/codec/lpcm.c
index a380252..801f12e 100644
--- a/modules/codec/lpcm.c
+++ b/modules/codec/lpcm.c
@@ -454,6 +454,8 @@ static block_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
 
         /* */
         block_t *p_aout_buffer;
+        if( decoder_UpdateAudioFormat( p_dec ) )
+            return NULL;
         p_aout_buffer = decoder_NewAudioBuffer( p_dec, i_frame_length );
         if( !p_aout_buffer )
             return NULL;
diff --git a/modules/codec/mft.c b/modules/codec/mft.c
index 55c19c1..39a45e1 100644
--- a/modules/codec/mft.c
+++ b/modules/codec/mft.c
@@ -688,6 +688,8 @@ static int ProcessOutputStream(decoder_t *p_dec, DWORD stream_id, void **result)
         }
         else
         {
+            if (decoder_UpdateAudioFormat(p_dec))
+                goto error;
             if (p_dec->fmt_out.audio.i_bitspersample == 0 || p_dec->fmt_out.audio.i_channels == 0)
                 goto error;
             int samples = total_length / (p_dec->fmt_out.audio.i_bitspersample * p_dec->fmt_out.audio.i_channels / 8);
diff --git a/modules/codec/mpeg_audio.c b/modules/codec/mpeg_audio.c
index 9cb4f4f..6c9f09d 100644
--- a/modules/codec/mpeg_audio.c
+++ b/modules/codec/mpeg_audio.c
@@ -563,6 +563,8 @@ static block_t *GetAoutBuffer( decoder_t *p_dec )
     decoder_sys_t *p_sys = p_dec->p_sys;
     block_t *p_buf;
 
+    if( decoder_UpdateAudioFormat( p_dec ) )
+        return NULL;
     p_buf = decoder_NewAudioBuffer( p_dec, p_sys->i_frame_length );
     if( p_buf == NULL ) return NULL;
 
diff --git a/modules/codec/mpg123.c b/modules/codec/mpg123.c
index 9480bc6..f857da4 100644
--- a/modules/codec/mpg123.c
+++ b/modules/codec/mpg123.c
@@ -175,6 +175,8 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     }
 
     /* Request a new audio buffer */
+    if( decoder_UpdateAudioFormat( p_dec ) )
+        goto error;
     block_t *p_out = decoder_NewAudioBuffer( p_dec, p_block->i_nb_samples );
     if( unlikely( !p_out ) )
         goto error;
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index 7626054..089d14a 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -1706,6 +1706,8 @@ block_t *DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
             i_samples = p_header->nFilledLen / p_sys->out.p_fmt->audio.i_channels / 2;
         if(i_samples)
         {
+            if( decoder_UpdateAudioFormat( p_dec ) )
+                break;
             p_buffer = decoder_NewAudioBuffer( p_dec, i_samples );
             if( !p_buffer ) break; /* No audio buffer available */
 
diff --git a/modules/codec/opus.c b/modules/codec/opus.c
index 8c055ab..dba885d 100644
--- a/modules/codec/opus.c
+++ b/modules/codec/opus.c
@@ -436,6 +436,8 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
     if(!i_nb_samples)
         i_nb_samples = spp;
 
+    if( decoder_UpdateAudioFormat( p_dec ) )
+        return NULL;
     block_t *p_aout_buffer=decoder_NewAudioBuffer( p_dec, spp );
     if ( !p_aout_buffer )
     {
diff --git a/modules/codec/speex.c b/modules/codec/speex.c
index 9adf28b..a3acad7 100644
--- a/modules/codec/speex.c
+++ b/modules/codec/speex.c
@@ -732,8 +732,11 @@ static block_t *DecodeRtpSpeexPacket( decoder_t *p_dec, block_t **pp_block )
       Ask for a new audio output buffer and make sure
       we get one.
     */
-    p_aout_buffer = decoder_NewAudioBuffer( p_dec,
-        p_sys->p_header->frame_size );
+    if( decoder_UpdateAudioFormat( p_dec ) )
+        p_aout_buffer = NULL;
+    else
+        p_aout_buffer = decoder_NewAudioBuffer( p_dec,
+            p_sys->p_header->frame_size );
     if ( !p_aout_buffer || p_aout_buffer->i_buffer == 0 )
     {
         msg_Err(p_dec, "Oops: No new buffer was returned!");
@@ -795,6 +798,8 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
         if( p_sys->p_header->frame_size == 0 )
             return NULL;
 
+        if( decoder_UpdateAudioFormat( p_dec ) )
+            return NULL;
         p_aout_buffer =
             decoder_NewAudioBuffer( p_dec, p_sys->p_header->frame_size );
         if( !p_aout_buffer )
diff --git a/modules/codec/uleaddvaudio.c b/modules/codec/uleaddvaudio.c
index a8f6165..c578682 100644
--- a/modules/codec/uleaddvaudio.c
+++ b/modules/codec/uleaddvaudio.c
@@ -97,6 +97,8 @@ static block_t *Decode(decoder_t *dec, block_t **block_ptr)
 
         int sample_count = dv_get_audio_sample_count(&src[244], sys->is_pal);
 
+        if( decoder_UpdateAudioFormat(dec))
+            return NULL;
         block_t *output = decoder_NewAudioBuffer(dec, sample_count);
         if (!output)
             return NULL;
diff --git a/modules/codec/vorbis.c b/modules/codec/vorbis.c
index 147da32..c637869 100644
--- a/modules/codec/vorbis.c
+++ b/modules/codec/vorbis.c
@@ -536,6 +536,7 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
 
         block_t *p_aout_buffer;
 
+        if( decoder_UpdateAudioFormat( p_dec ) ) return NULL;
         p_aout_buffer =
             decoder_NewAudioBuffer( p_dec, i_samples );
 
diff --git a/modules/codec/wmafixed/wma.c b/modules/codec/wmafixed/wma.c
index 42d38b8..f8a8b4c 100644
--- a/modules/codec/wmafixed/wma.c
+++ b/modules/codec/wmafixed/wma.c
@@ -98,6 +98,8 @@ static block_t *SplitBuffer( decoder_t *p_dec )
 
     if( i_samples == 0 ) return NULL;
 
+    if( decoder_UpdateAudioFormat( p_dec ) )
+        return NULL;
     if( !( p_buffer = decoder_NewAudioBuffer( p_dec, i_samples ) ) )
         return NULL;
 
diff --git a/src/input/decoder.c b/src/input/decoder.c
index eafc065..dee8003 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -594,9 +594,6 @@ static int DecoderGetDisplayRate( decoder_t *p_dec )
  *****************************************************************************/
 block_t *decoder_NewAudioBuffer( decoder_t *dec, int samples )
 {
-    if( decoder_UpdateAudioFormat( dec ) )
-        return NULL;
-
     size_t length = samples * dec->fmt_out.audio.i_bytes_per_frame
                             / dec->fmt_out.audio.i_frame_length;
     block_t *block = block_Alloc( length );
-- 
2.9.3



More information about the vlc-devel mailing list