diff mbox series

[FFmpeg-devel] avisynth: fix audio on big endian

Message ID 20210217230054.5650-1-qyot27@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel] avisynth: fix audio on big endian
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Stephen Hutchinson Feb. 17, 2021, 11 p.m. UTC
---
Open for bikeshedding, as I'm not too sure of
the names, but I didn't want to use anything
too close to regular AV_CODEC_ID* defines.
 libavformat/avisynth.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

Comments

Andreas Rheinhardt Feb. 17, 2021, 11:14 p.m. UTC | #1
Stephen Hutchinson:
> ---
> Open for bikeshedding, as I'm not too sure of
> the names, but I didn't want to use anything
> too close to regular AV_CODEC_ID* defines.
>  libavformat/avisynth.c | 21 +++++++++++++++++----
>  1 file changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
> index f029a0e842..fbebb6707c 100644
> --- a/libavformat/avisynth.c
> +++ b/libavformat/avisynth.c
> @@ -42,6 +42,19 @@
>    #define AVISYNTH_LIB AVISYNTH_NAME SLIBSUF
>  #endif
>  
> +/* Endianness guards for audio */
> +#if HAVE_BIGENDIAN
> +    #define AVISYNTH_PCM_OUT_S16 AV_CODEC_ID_PCM_S16BE
> +    #define AVISYNTH_PCM_OUT_S24 AV_CODEC_ID_PCM_S24BE
> +    #define AVISYNTH_PCM_OUT_S32 AV_CODEC_ID_PCM_S32BE
> +    #define AVISYNTH_PCM_OUT_F32 AV_CODEC_ID_PCM_F32BE
> +#else
> +    #define AVISYNTH_PCM_OUT_S16 AV_CODEC_ID_PCM_S16LE
> +    #define AVISYNTH_PCM_OUT_S24 AV_CODEC_ID_PCM_S24LE
> +    #define AVISYNTH_PCM_OUT_S32 AV_CODEC_ID_PCM_S32LE
> +    #define AVISYNTH_PCM_OUT_F32 AV_CODEC_ID_PCM_F32LE
> +#endif
#if HAVE_BIGENDION
#define PCM(format) (AV_CODEC_ID_PCM_ ## format ## BE)
#else
#define PCM(format) (AV_CODEC_ID_PCM_ ## format ## LE)
#endif

With this the above lines would become
st->codecpar->codec_id = PCM(S16) etc.

Alternatively one could also use AV_NE directly.


> +
>  #include <avisynth/avisynth_c.h>
>  
>  typedef struct AviSynthLibrary {
> @@ -496,16 +509,16 @@ static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st)
>          st->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
>          break;
>      case AVS_SAMPLE_INT16:
> -        st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
> +        st->codecpar->codec_id = AVISYNTH_PCM_OUT_S16;
>          break;
>      case AVS_SAMPLE_INT24:
> -        st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
> +        st->codecpar->codec_id = AVISYNTH_PCM_OUT_S24;
>          break;
>      case AVS_SAMPLE_INT32:
> -        st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE;
> +        st->codecpar->codec_id = AVISYNTH_PCM_OUT_S32;
>          break;
>      case AVS_SAMPLE_FLOAT:
> -        st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE;
> +        st->codecpar->codec_id = AVISYNTH_PCM_OUT_F32;
>          break;
>      default:
>          av_log(s, AV_LOG_ERROR,
>
diff mbox series

Patch

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index f029a0e842..fbebb6707c 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -42,6 +42,19 @@ 
   #define AVISYNTH_LIB AVISYNTH_NAME SLIBSUF
 #endif
 
+/* Endianness guards for audio */
+#if HAVE_BIGENDIAN
+    #define AVISYNTH_PCM_OUT_S16 AV_CODEC_ID_PCM_S16BE
+    #define AVISYNTH_PCM_OUT_S24 AV_CODEC_ID_PCM_S24BE
+    #define AVISYNTH_PCM_OUT_S32 AV_CODEC_ID_PCM_S32BE
+    #define AVISYNTH_PCM_OUT_F32 AV_CODEC_ID_PCM_F32BE
+#else
+    #define AVISYNTH_PCM_OUT_S16 AV_CODEC_ID_PCM_S16LE
+    #define AVISYNTH_PCM_OUT_S24 AV_CODEC_ID_PCM_S24LE
+    #define AVISYNTH_PCM_OUT_S32 AV_CODEC_ID_PCM_S32LE
+    #define AVISYNTH_PCM_OUT_F32 AV_CODEC_ID_PCM_F32LE
+#endif
+
 #include <avisynth/avisynth_c.h>
 
 typedef struct AviSynthLibrary {
@@ -496,16 +509,16 @@  static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st)
         st->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
         break;
     case AVS_SAMPLE_INT16:
-        st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
+        st->codecpar->codec_id = AVISYNTH_PCM_OUT_S16;
         break;
     case AVS_SAMPLE_INT24:
-        st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
+        st->codecpar->codec_id = AVISYNTH_PCM_OUT_S24;
         break;
     case AVS_SAMPLE_INT32:
-        st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE;
+        st->codecpar->codec_id = AVISYNTH_PCM_OUT_S32;
         break;
     case AVS_SAMPLE_FLOAT:
-        st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE;
+        st->codecpar->codec_id = AVISYNTH_PCM_OUT_F32;
         break;
     default:
         av_log(s, AV_LOG_ERROR,