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

Tristan Matthews git at videolan.org
Mon Apr 21 17:13:53 CEST 2014


vlc | branch: master | Tristan Matthews <le.businessman at gmail.com> | Sun Apr 20 19:56:04 2014 -0400| [1a9bda43fc869ecc286e88e707a6098b05e138f1] | committer: Tristan Matthews

speex: assume default settings if header is missing

Fixes #2973

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

 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;



More information about the vlc-commits mailing list