[vlc-commits] avcodec: simplify audio sample format mapping
Rémi Denis-Courmont
git at videolan.org
Fri Dec 21 23:34:55 CET 2012
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Dec 22 00:30:25 2012 +0200| [4fef4b6d00b9297ccfb3d533405dc6c3ab8c0ca7] | committer: Rémi Denis-Courmont
avcodec: simplify audio sample format mapping
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4fef4b6d00b9297ccfb3d533405dc6c3ab8c0ca7
---
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 eed46de..44731da 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -407,33 +407,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] =
@@ -464,9 +449,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;
/* */
@@ -518,6 +502,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 1e40c36..8c8dd20 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 ** );
block_t * DecodeAudio( decoder_t *, block_t ** );
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 54b7fed..da26dc0 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -807,9 +807,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