[vlc-commits] codec/mpg123: fix opening when the fmt_in.rate is unknown

Thomas Guillem git at videolan.org
Thu Oct 20 18:54:30 CEST 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Oct 20 18:53:52 2016 +0200| [c39252f15741625d6247877e56e82821890c3a07] | committer: Thomas Guillem

codec/mpg123: fix opening when the fmt_in.rate is unknown

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

 modules/codec/mpg123.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/modules/codec/mpg123.c b/modules/codec/mpg123.c
index 5706a77..3e806ab 100644
--- a/modules/codec/mpg123.c
+++ b/modules/codec/mpg123.c
@@ -89,10 +89,30 @@ static int MPG123Open( decoder_t *p_dec )
     /* Setup output format */
     mpg123_format_none( p_sys->p_handle );
 
-    if( MPG123_OK != mpg123_format( p_sys->p_handle,
-                                    p_dec->fmt_in.audio.i_rate,
+    int i_ret = MPG123_OK;
+    if( p_dec->fmt_in.audio.i_rate != 0 )
+    {
+        i_ret =  mpg123_format( p_sys->p_handle, p_dec->fmt_in.audio.i_rate,
+                                MPG123_MONO | MPG123_STEREO,
+                                MPG123_ENC_FLOAT_32 );
+    }
+    else
+    {
+        /* The rate from the input is unknown. Tell mpg123 to accept all rates
+         * to avoid conversion on their side */
+        static const long mp3_rates[] = {
+            8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000,
+        };
+        for( size_t i = 0;
+            i < sizeof(mp3_rates) / sizeof(*mp3_rates) && i_ret == MPG123_OK;
+            ++i )
+        {
+            i_ret =  mpg123_format( p_sys->p_handle, mp3_rates[i],
                                     MPG123_MONO | MPG123_STEREO,
-                                    MPG123_ENC_FLOAT_32 ) )
+                                    MPG123_ENC_FLOAT_32 );
+        }
+    }
+    if( i_ret != MPG123_OK )
     {
         msg_Err( p_dec, "mpg123 error: %s",
                  mpg123_strerror( p_sys->p_handle ) );



More information about the vlc-commits mailing list