From patchwork Fri Aug 5 10:25:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 96 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp1645780vsd; Fri, 5 Aug 2016 03:25:35 -0700 (PDT) X-Received: by 10.28.41.131 with SMTP id p125mr2625662wmp.15.1470392735599; Fri, 05 Aug 2016 03:25:35 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ag8si10995759wjc.126.2016.08.05.03.25.35; Fri, 05 Aug 2016 03:25:35 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3F51668A524; Fri, 5 Aug 2016 13:25:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe02-3.mx.upcmail.net (vie01a-dmta-pe02-3.mx.upcmail.net [62.179.121.159]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 16F3068A524 for ; Fri, 5 Aug 2016 13:25:11 +0300 (EEST) Received: from [172.31.216.44] (helo=vie01a-pemc-psmtp-pe02) by vie01a-dmta-pe02.mx.upcmail.net with esmtp (Exim 4.87) (envelope-from ) id 1bVcJa-0000EC-6f for ffmpeg-devel@ffmpeg.org; Fri, 05 Aug 2016 12:25:18 +0200 Received: from [192.168.1.3] ([80.110.106.27]) by vie01a-pemc-psmtp-pe02 with SMTP @ mailcloud.upcmail.net id TNRG1t01H0bVSe801NRJTF; Fri, 05 Aug 2016 12:25:18 +0200 X-SourceIP: 80.110.106.27 From: Carl Eugen Hoyos To: FFmpeg development discussions and patches Date: Fri, 5 Aug 2016 12:25:16 +0200 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Message-Id: <201608051225.16893.cehoyos@ag.or.at> Subject: [FFmpeg-devel] [PATCH]lavf/pcmdec: Map mime_type audio/L16 to the s16le demuxer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi! Attached patch implements RFC 2586. Please comment, Carl Eugen From ba470c643c836826d75854e3e3539eb09ddd288a Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Fri, 5 Aug 2016 12:22:17 +0200 Subject: [PATCH] lavf/pcmdec: Map mime_type audio/L16 to s16le as specified in RFC 2586. --- libavformat/pcmdec.c | 63 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c index df94345..36ef2c2 100644 --- a/libavformat/pcmdec.c +++ b/libavformat/pcmdec.c @@ -36,6 +36,7 @@ static int pcm_read_header(AVFormatContext *s) { PCMAudioDemuxerContext *s1 = s->priv_data; AVStream *st; + uint8_t *mime_type_opt = NULL; st = avformat_new_stream(s, NULL); if (!st) @@ -47,6 +48,25 @@ static int pcm_read_header(AVFormatContext *s) st->codecpar->sample_rate = s1->sample_rate; st->codecpar->channels = s1->channels; + av_opt_get(s->pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type_opt); + if (mime_type_opt) { + const char *mime_type = mime_type_opt; + size_t len = strlen(s->iformat->mime_type); + int rate, channels = 0; + if (!av_strncasecmp(s->iformat->mime_type, mime_type, len)) { + if ( !sscanf(mime_type + len, ";rate=%d;channels=%d", &rate, &channels) + || !rate) { + av_log(s, AV_LOG_ERROR, + "Invalid sample_rate found in mime_type \"%s\"\n", + mime_type); + return AVERROR_INVALIDDATA; + } + st->codecpar->sample_rate = rate; + if (channels) + st->codecpar->channels = channels; + } + } + st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id); @@ -65,7 +85,7 @@ static const AVOption pcm_options[] = { { NULL }, }; -#define PCMDEF(name_, long_name_, ext, codec) \ +#define PCMDEF(name_, long_name_, ext, codec, mime_type_) \ static const AVClass name_ ## _demuxer_class = { \ .class_name = #name_ " demuxer", \ .item_name = av_default_item_name, \ @@ -82,68 +102,69 @@ AVInputFormat ff_pcm_ ## name_ ## _demuxer = { \ .flags = AVFMT_GENERIC_INDEX, \ .extensions = ext, \ .raw_codec_id = codec, \ + .mime_type = mime_type_, \ .priv_class = &name_ ## _demuxer_class, \ }; PCMDEF(f64be, "PCM 64-bit floating-point big-endian", - NULL, AV_CODEC_ID_PCM_F64BE) + NULL, AV_CODEC_ID_PCM_F64BE, NULL) PCMDEF(f64le, "PCM 64-bit floating-point little-endian", - NULL, AV_CODEC_ID_PCM_F64LE) + NULL, AV_CODEC_ID_PCM_F64LE, NULL) PCMDEF(f32be, "PCM 32-bit floating-point big-endian", - NULL, AV_CODEC_ID_PCM_F32BE) + NULL, AV_CODEC_ID_PCM_F32BE, NULL) PCMDEF(f32le, "PCM 32-bit floating-point little-endian", - NULL, AV_CODEC_ID_PCM_F32LE) + NULL, AV_CODEC_ID_PCM_F32LE, NULL) PCMDEF(s32be, "PCM signed 32-bit big-endian", - NULL, AV_CODEC_ID_PCM_S32BE) + NULL, AV_CODEC_ID_PCM_S32BE, NULL) PCMDEF(s32le, "PCM signed 32-bit little-endian", - NULL, AV_CODEC_ID_PCM_S32LE) + NULL, AV_CODEC_ID_PCM_S32LE, NULL) PCMDEF(s24be, "PCM signed 24-bit big-endian", - NULL, AV_CODEC_ID_PCM_S24BE) + NULL, AV_CODEC_ID_PCM_S24BE, NULL) PCMDEF(s24le, "PCM signed 24-bit little-endian", - NULL, AV_CODEC_ID_PCM_S24LE) + NULL, AV_CODEC_ID_PCM_S24LE, NULL) PCMDEF(s16be, "PCM signed 16-bit big-endian", - AV_NE("sw", NULL), AV_CODEC_ID_PCM_S16BE) + AV_NE("sw", NULL), AV_CODEC_ID_PCM_S16BE, NULL) PCMDEF(s16le, "PCM signed 16-bit little-endian", - AV_NE(NULL, "sw"), AV_CODEC_ID_PCM_S16LE) + AV_NE(NULL, "sw"), AV_CODEC_ID_PCM_S16LE, "audio/L16") PCMDEF(s8, "PCM signed 8-bit", - "sb", AV_CODEC_ID_PCM_S8) + "sb", AV_CODEC_ID_PCM_S8, NULL) PCMDEF(u32be, "PCM unsigned 32-bit big-endian", - NULL, AV_CODEC_ID_PCM_U32BE) + NULL, AV_CODEC_ID_PCM_U32BE, NULL) PCMDEF(u32le, "PCM unsigned 32-bit little-endian", - NULL, AV_CODEC_ID_PCM_U32LE) + NULL, AV_CODEC_ID_PCM_U32LE, NULL) PCMDEF(u24be, "PCM unsigned 24-bit big-endian", - NULL, AV_CODEC_ID_PCM_U24BE) + NULL, AV_CODEC_ID_PCM_U24BE, NULL) PCMDEF(u24le, "PCM unsigned 24-bit little-endian", - NULL, AV_CODEC_ID_PCM_U24LE) + NULL, AV_CODEC_ID_PCM_U24LE, NULL) PCMDEF(u16be, "PCM unsigned 16-bit big-endian", - AV_NE("uw", NULL), AV_CODEC_ID_PCM_U16BE) + AV_NE("uw", NULL), AV_CODEC_ID_PCM_U16BE, NULL) PCMDEF(u16le, "PCM unsigned 16-bit little-endian", - AV_NE(NULL, "uw"), AV_CODEC_ID_PCM_U16LE) + AV_NE(NULL, "uw"), AV_CODEC_ID_PCM_U16LE, NULL) PCMDEF(u8, "PCM unsigned 8-bit", - "ub", AV_CODEC_ID_PCM_U8) + "ub", AV_CODEC_ID_PCM_U8, NULL) PCMDEF(alaw, "PCM A-law", - "al", AV_CODEC_ID_PCM_ALAW) + "al", AV_CODEC_ID_PCM_ALAW, NULL) PCMDEF(mulaw, "PCM mu-law", - "ul", AV_CODEC_ID_PCM_MULAW) + "ul", AV_CODEC_ID_PCM_MULAW, NULL) static const AVOption sln_options[] = { { "sample_rate", "", offsetof(PCMAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 8000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },