[vlc-commits] avcodec: simplify audio sample format mapping

Rémi Denis-Courmont git at videolan.org
Fri Jan 25 16:28:36 CET 2013


vlc/vlc-2.0 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Dec 22 00:30:25 2012 +0200| [b0c0b8948e90bff73a43bb5256ed28c5d7ae7e0e] | committer: Jean-Baptiste Kempf

avcodec: simplify audio sample format mapping
(cherry picked from commit 4fef4b6d00b9297ccfb3d533405dc6c3ab8c0ca7)

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/codec/avcodec/audio.c   |   44 +++++++++++++--------------------------
 modules/codec/avcodec/avcodec.h |    2 +-
 modules/codec/avcodec/encoder.c |    6 +++---
 3 files changed, 18 insertions(+), 34 deletions(-)

diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 7132960..46be029 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -416,33 +416,18 @@ void EndAudioDec( decoder_t *p_dec )
  *
  *****************************************************************************/
 
-void GetVlcAudioFormat( vlc_fourcc_t *pi_codec, unsigned *pi_bits, int i_sample_fmt )
+vlc_fourcc_t GetVlcAudioFormat( int fmt )
 {
-    switch( i_sample_fmt )
-    {
-    case AV_SAMPLE_FMT_U8:
-        *pi_codec = VLC_CODEC_U8;
-        *pi_bits = 8;
-        break;
-    case AV_SAMPLE_FMT_S32:
-        *pi_codec = VLC_CODEC_S32N;
-        *pi_bits = 32;
-        break;
-    case AV_SAMPLE_FMT_FLT:
-        *pi_codec = VLC_CODEC_FL32;
-        *pi_bits = 32;
-        break;
-    case AV_SAMPLE_FMT_DBL:
-        *pi_codec = VLC_CODEC_FL64;
-        *pi_bits = 64;
-        break;
-
-    case AV_SAMPLE_FMT_S16:
-    default:
-        *pi_codec = VLC_CODEC_S16N;
-        *pi_bits = 16;
-        break;
-    }
+    static const vlc_fourcc_t fcc[] = {
+        [AV_SAMPLE_FMT_U8]   = VLC_CODEC_U8,
+        [AV_SAMPLE_FMT_S16]  = VLC_CODEC_S16N,
+        [AV_SAMPLE_FMT_S32]  = VLC_CODEC_S32N,
+        [AV_SAMPLE_FMT_FLT]  = VLC_CODEC_FL32,
+        [AV_SAMPLE_FMT_DBL]  = VLC_CODEC_FL64,
+    };
+    if( sizeof(fcc) / sizeof(fcc[0]) < (unsigned)fmt )
+        return fcc[fmt];
+    return VLC_CODEC_S16N;
 }
 
 static const uint64_t pi_channels_map[][2] =
@@ -473,9 +458,8 @@ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
 
-    GetVlcAudioFormat( &p_dec->fmt_out.i_codec,
-                       &p_dec->fmt_out.audio.i_bitspersample,
-                       p_sys->p_context->sample_fmt );
+    p_dec->fmt_out.i_codec = GetVlcAudioFormat( p_sys->p_context->sample_fmt );
+    p_dec->fmt_out.audio.i_format = p_dec->fmt_out.i_codec;
     p_dec->fmt_out.audio.i_rate = p_sys->p_context->sample_rate;
 
     /* */
@@ -527,6 +511,6 @@ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
 
     p_dec->fmt_out.audio.i_physical_channels =
     p_dec->fmt_out.audio.i_original_channels = i_layout_dst;
-    p_dec->fmt_out.audio.i_channels = i_channels_dst;
+    aout_FormatPrepare( &p_dec->fmt_out.audio );
 }
 
diff --git a/modules/codec/avcodec/avcodec.h b/modules/codec/avcodec/avcodec.h
index 59f3bb5..0005e90 100644
--- a/modules/codec/avcodec/avcodec.h
+++ b/modules/codec/avcodec/avcodec.h
@@ -27,7 +27,7 @@ int GetFfmpegCodec( vlc_fourcc_t i_fourcc, int *pi_cat,
                     int *pi_ffmpeg_codec, const char **ppsz_name );
 int GetVlcFourcc( int i_ffmpeg_codec, int *pi_cat,
                   vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
-void GetVlcAudioFormat( vlc_fourcc_t *, unsigned *pi_bits, int i_sample_fmt );
+vlc_fourcc_t GetVlcAudioFormat( int i_sample_fmt );
 
 picture_t * DecodeVideo    ( decoder_t *, block_t ** );
 aout_buffer_t * DecodeAudio( decoder_t *, block_t ** );
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index f1357cb..617275c 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -826,9 +826,9 @@ int OpenEncoder( vlc_object_t *p_this )
 
     if( p_enc->fmt_in.i_cat == AUDIO_ES )
     {
-        GetVlcAudioFormat( &p_enc->fmt_in.i_codec,
-                           &p_enc->fmt_in.audio.i_bitspersample,
-                           p_sys->p_context->sample_fmt );
+        p_enc->fmt_in.i_codec = GetVlcAudioFormat( p_sys->p_context->sample_fmt );
+        p_enc->fmt_in.audio.i_bitspersample = aout_BitsPerSample( p_enc->fmt_in.i_codec );
+
         p_sys->i_sample_bytes = (p_enc->fmt_in.audio.i_bitspersample / 8) *
                                 p_context->channels;
         p_sys->i_frame_size = p_context->frame_size > 1 ?



More information about the vlc-commits mailing list