libspeexenc: Use speex_lib_get_mode instead of the speex_foo_mode data symbols

Message ID 20171103100505.18105-1-martin@martin.st
State Committed
Commit 1746c7c8f2f9a6c5eacb486426dd0a579b4b7498
Headers show

Commit Message

Martin Storsjö Nov. 3, 2017, 10:05 a.m.
This avoids issues linking to a DLL version of libspeex, since the
libspeex headers lack proper dllimport declarations for the data
symbols.

This isn't an issue when building with mingw with GNU binutils, since
GNU ld can fix up that kind of data import automatically.
---
 libavcodec/libspeexenc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Martin Storsjö Nov. 3, 2017, 10:13 a.m. | #1
On Fri, 3 Nov 2017, Martin Storsjö wrote:

> This avoids issues linking to a DLL version of libspeex, since the
> libspeex headers lack proper dllimport declarations for the data
> symbols.
>
> This isn't an issue when building with mingw with GNU binutils, since
> GNU ld can fix up that kind of data import automatically.
> ---
> libavcodec/libspeexenc.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)

Locally amended the commit message with "libspeexdec.c already uses 
speex_lib_get_mode as well.", as a further argument for why this might be 
a good idea.

// Martin
Luca Barbato Nov. 3, 2017, 11:30 a.m. | #2
On 03/11/2017 11:05, Martin Storsjö wrote:
> This avoids issues linking to a DLL version of libspeex, since the
> libspeex headers lack proper dllimport declarations for the data
> symbols.
> 
> This isn't an issue when building with mingw with GNU binutils, since
> GNU ld can fix up that kind of data import automatically.
> ---
>   libavcodec/libspeexenc.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
> index f3a31e9879..eb02e8ec6d 100644
> --- a/libavcodec/libspeexenc.c
> +++ b/libavcodec/libspeexenc.c
> @@ -158,9 +158,9 @@ static av_cold int encode_init(AVCodecContext *avctx)
>   
>       /* sample rate and encoding mode */
>       switch (avctx->sample_rate) {
> -    case  8000: mode = &speex_nb_mode;  break;
> -    case 16000: mode = &speex_wb_mode;  break;
> -    case 32000: mode = &speex_uwb_mode; break;
> +    case  8000: mode = speex_lib_get_mode(SPEEX_MODEID_NB);  break;
> +    case 16000: mode = speex_lib_get_mode(SPEEX_MODEID_WB);  break;
> +    case 32000: mode = speex_lib_get_mode(SPEEX_MODEID_UWB); break;
>       default:
>           av_log(avctx, AV_LOG_ERROR, "Sample rate of %d Hz is not supported. "
>                  "Resample to 8, 16, or 32 kHz.\n", avctx->sample_rate);
> 

Ok.

Patch

diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index f3a31e9879..eb02e8ec6d 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -158,9 +158,9 @@  static av_cold int encode_init(AVCodecContext *avctx)
 
     /* sample rate and encoding mode */
     switch (avctx->sample_rate) {
-    case  8000: mode = &speex_nb_mode;  break;
-    case 16000: mode = &speex_wb_mode;  break;
-    case 32000: mode = &speex_uwb_mode; break;
+    case  8000: mode = speex_lib_get_mode(SPEEX_MODEID_NB);  break;
+    case 16000: mode = speex_lib_get_mode(SPEEX_MODEID_WB);  break;
+    case 32000: mode = speex_lib_get_mode(SPEEX_MODEID_UWB); break;
     default:
         av_log(avctx, AV_LOG_ERROR, "Sample rate of %d Hz is not supported. "
                "Resample to 8, 16, or 32 kHz.\n", avctx->sample_rate);