From e335e3323932ca7e27ffbe99e7dc2447a83ba857 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 18 Apr 2017 05:35:50 +0200 Subject: codec_tags: minor simplification At least this doesn't duplicate the libavcodec PCM codec names. --- demux/codec_tags.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'demux/codec_tags.c') diff --git a/demux/codec_tags.c b/demux/codec_tags.c index 5b0b3465e6..e520161b87 100644 --- a/demux/codec_tags.c +++ b/demux/codec_tags.c @@ -48,20 +48,20 @@ static const char *lookup_tag(int type, uint32_t tag) return id == AV_CODEC_ID_NONE ? NULL : mp_codec_from_av_codec_id(id); } -static const char *const pcm_le[] = {"pcm_u8", "pcm_s16le", "pcm_s24le", "pcm_s32le"}; - -static const char *map_audio_pcm_tag(uint32_t tag, int bits) +static void map_audio_pcm_tag(struct mp_codec_params *c) { + int bits = c->bits_per_coded_sample; int bytes = (bits + 7) / 8; - switch (tag) { + switch (c->codec_tag) { case 0x0: // Microsoft PCM case 0x1: case 0xfffe: // MS PCM, Extended - return bytes >= 1 && bytes <= 4 ? pcm_le[bytes - 1] : NULL; + if (bytes >= 1 && bytes <= 4) + mp_set_pcm_codec(c, bytes > 1, false, bytes * 8, false); + break; case 0x3: // IEEE float - return bits == 64 ? "pcm_f64le" : "pcm_f32le"; - default: - return NULL; + mp_set_pcm_codec(c, true, true, bits == 64 ? 64 : 32, false); + break; } } @@ -69,12 +69,8 @@ void mp_set_codec_from_tag(struct mp_codec_params *c) { c->codec = lookup_tag(c->type, c->codec_tag); - if (c->type == STREAM_AUDIO && c->bits_per_coded_sample) { - const char *codec = - map_audio_pcm_tag(c->codec_tag, c->bits_per_coded_sample); - if (codec) - c->codec = codec; - } + if (c->type == STREAM_AUDIO && c->bits_per_coded_sample) + map_audio_pcm_tag(c); } void mp_set_pcm_codec(struct mp_codec_params *c, bool sign, bool is_float, -- cgit v1.2.3