[vlc-devel] [PATCH] speex: assume default settings if header is missing

Tristan Matthews le.businessman at gmail.com
Mon Apr 21 05:11:36 CEST 2014


Fixes #2973
---
 modules/codec/speex.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 69 insertions(+), 1 deletion(-)

diff --git a/modules/codec/speex.c b/modules/codec/speex.c
index 488b9c2..f366055 100644
--- a/modules/codec/speex.c
+++ b/modules/codec/speex.c
@@ -265,6 +265,64 @@ static int OpenPacketizer( vlc_object_t *p_this )
     return i_ret;
 }
 
+static int CreateDefaultHeader( decoder_t *p_dec )
+{
+    ogg_packet oggpacket;
+    SpeexHeader *p_header = malloc( sizeof(SpeexHeader) );
+    if( !p_header )
+        return VLC_ENOMEM;
+
+    const int rate = p_dec->fmt_in.audio.i_rate;
+    const unsigned i_mode = (rate / 8000) >> 1;
+
+    const SpeexMode *mode;
+    int ret = VLC_SUCCESS;
+    oggpacket.packet = NULL;
+
+    switch( rate )
+    {
+        case 8000:
+        case 16000:
+        case 32000:
+            mode = speex_lib_get_mode( i_mode );
+            break;
+        default:
+            msg_Err( p_dec, "Unexpected rate %d", rate );
+            ret = VLC_EGENERIC;
+            goto cleanup;
+    }
+
+    speex_init_header( p_header, rate, p_dec->fmt_in.audio.i_channels, mode );
+    p_header->frames_per_packet = 160 << i_mode;
+
+    oggpacket.packet = (unsigned char *) speex_header_to_packet( p_header,
+            (int *) &oggpacket.bytes );
+    if( !oggpacket.packet )
+    {
+        ret = VLC_ENOMEM;
+        goto cleanup;
+    }
+
+    oggpacket.b_o_s = 1;
+    oggpacket.e_o_s = 0;
+    oggpacket.granulepos = -1;
+    oggpacket.packetno = 0;
+
+    ret = ProcessInitialHeader( p_dec, &oggpacket );
+
+    if( ret != VLC_SUCCESS )
+    {
+        msg_Err( p_dec, "default Speex header is corrupted" );
+    }
+
+cleanup:
+    free( oggpacket.packet );
+    free( p_header );
+
+    return ret;
+}
+
+
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************
@@ -300,7 +358,17 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     /* Check for headers */
     if( !p_sys->b_has_headers )
     {
-        if( ProcessHeaders( p_dec ) )
+        if( !p_dec->fmt_in.p_extra )
+        {
+            msg_Warn( p_dec, "Header missing, using default settings" );
+
+            if( CreateDefaultHeader( p_dec ) )
+            {
+                block_Release( *pp_block );
+                return NULL;
+            }
+        }
+        else if( ProcessHeaders( p_dec ) )
         {
             block_Release( *pp_block );
             return NULL;
-- 
1.9.1




More information about the vlc-devel mailing list