From patchwork Mon Aug 8 22:51:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 123 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp363077vsd; Mon, 8 Aug 2016 15:52:04 -0700 (PDT) X-Received: by 10.28.37.71 with SMTP id l68mr19288846wml.50.1470696724867; Mon, 08 Aug 2016 15:52:04 -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 x25si328411wma.24.2016.08.08.15.52.01; Mon, 08 Aug 2016 15:52:04 -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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9283268A176; Tue, 9 Aug 2016 01:51:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua0-f174.google.com (mail-ua0-f174.google.com [209.85.217.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0312168A097 for ; Tue, 9 Aug 2016 01:51:23 +0300 (EEST) Received: by mail-ua0-f174.google.com with SMTP id 74so91423771uau.0 for ; Mon, 08 Aug 2016 15:51:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=k1V1GkvE0ClkVJA36mOjBGjG/goiXmk738cdGTlywA0=; b=rlU4/tyO2EnXSPUSNn0W+RzOxi1+gMymMOOcfg4VHQF08DHkqzlHphbtvZVF6N5ihq Q4P48fhdOXxAeQDyRte1wSz3psW6j8RenB0F6AIiBj81wznZMG7Fpy3fcKLNFtUJm/pd FPhd92+Rshzp0ndssAYknZZO1U5CtBxrUtfhymm/5FsrU/I4oyGAflSWeYfC7c02CMMs LkIZxvzUWyk2RFI090QqytMJOmGeiZt5MAGUFGGmEbiPOTWDsVb2H0gNXkJc8PsbZyK/ a0ZBLdUQl1ILe4V8NJd7NWLMqsRyZOs06bc7Vl16lh5WcJ2N6i97U+mzASd+TiY02vLz bMxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=k1V1GkvE0ClkVJA36mOjBGjG/goiXmk738cdGTlywA0=; b=RAUIfFDCiCuZowcruEFno8LPPfdhl2u8ubcqXyG56+1vIs2ivlLGJbYpEeRxHb5ydY CrjmLDYm4Nh0Az7tKR/yvlp+Oub7c/RgP1wisVPwfBHszQRzETKnTcOEiz+GRE/K+gX0 GD+Q9q7ZeTx46deNTMl3yKVt96XUnLc6lmfG3af3Yh3kgxt9sMHfDVWeUCKYvJ+0zPRF qh99QuErhVkRT84bho6ERMltIxL02b6nnp0qZFDjyc/XpGdZvZTVyegh0zNh4gwDHPTX qUYRi+pxDaNBMtfpox+cy+0knhjS6nxoCwFl/CvG1cnQ9ZgpP+U3Dvi2f8jEYYwosQkr OJBw== X-Gm-Message-State: AEkoousjhoiUvdM/zw+BzuMWceIsFWrePF5+cGa193hX9kWRgoZYY7Go2kvOvI27WDjLLZlouZR2Ky5+C4+/8w== X-Received: by 10.159.32.66 with SMTP id 60mr51193287uam.100.1470696690734; Mon, 08 Aug 2016 15:51:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.2.11 with HTTP; Mon, 8 Aug 2016 15:51:30 -0700 (PDT) In-Reply-To: <20160805104445.GA3130915@phare.normalesup.org> References: <201608051225.16893.cehoyos@ag.or.at> <20160805104445.GA3130915@phare.normalesup.org> From: Carl Eugen Hoyos Date: Tue, 9 Aug 2016 00:51:30 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [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! 2016-08-05 12:44 GMT+02:00 Nicolas George : > Le nonidi 19 thermidor, an CCXXIV, Carl Eugen Hoyos a écrit : >> 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; > > I do not understand the need for that line. Removed. >> + size_t len = strlen(s->iformat->mime_type); > > Maybe I am missing something obvious, but I think s->iformat->mime_type is > NULL for all the other formats. It needs to be checked. Added the check. >> + 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) > > If I understand the way MIME type works, ";channels=2;rate=48000" would be > exactly as valid, and spaces can surround the semicolons. I changed this hunk. >> + || !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_) \ > > Instead of changing PCMDEF and all the subsequent declarations, you can > create a new macro PCMDEF_WITH_MIME. > > Even simpler: make PCMDEF varadic, add __ARGS__ in the structure definition. > Then, adding the MIME type is just a matter of adding ".mime_type = ..." in > the macro call. Yes, much simpler. New patch attached. Thank you, Carl Eugen From 3ef0951db492f1425a574aac71fe73f144c2d99a Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Tue, 9 Aug 2016 00:46:57 +0200 Subject: [PATCH 2/2] lavf/pcmdec: Map mime_type audio/L16 to the s16le demuxer as specified in RFC 2586. --- libavformat/pcmdec.c | 34 ++++++++++++++++++++++++++++++++-- libavformat/version.h | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c index df94345..e3cc2ae 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 = NULL; st = avformat_new_stream(s, NULL); if (!st) @@ -47,6 +48,34 @@ 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); + if (mime_type && s->iformat->mime_type) { + int rate = 0, channels = 0; + size_t len = strlen(s->iformat->mime_type); + if (!strncmp(s->iformat->mime_type, mime_type, len)) { + uint8_t *options = mime_type + len; + len = strlen(mime_type); + while (options < mime_type + len) { + options = strstr(options, ";"); + if (!options++) + break; + if (!rate) + sscanf(options, " rate=%d", &rate); + if (!channels) + sscanf(options, " channels=%d", &channels); + } + if (!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 +94,7 @@ static const AVOption pcm_options[] = { { NULL }, }; -#define PCMDEF(name_, long_name_, ext, codec) \ +#define PCMDEF(name_, long_name_, ext, codec, ...) \ static const AVClass name_ ## _demuxer_class = { \ .class_name = #name_ " demuxer", \ .item_name = av_default_item_name, \ @@ -82,6 +111,7 @@ AVInputFormat ff_pcm_ ## name_ ## _demuxer = { \ .flags = AVFMT_GENERIC_INDEX, \ .extensions = ext, \ .raw_codec_id = codec, \ + __VA_ARGS__ \ .priv_class = &name_ ## _demuxer_class, \ }; @@ -113,7 +143,7 @@ PCMDEF(s16be, "PCM signed 16-bit big-endian", AV_NE("sw", NULL), AV_CODEC_ID_PCM_S16BE) 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, .mime_type = "audio/L16",) PCMDEF(s8, "PCM signed 8-bit", "sb", AV_CODEC_ID_PCM_S8) diff --git a/libavformat/version.h b/libavformat/version.h index 6f47a2f..590902d 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -33,7 +33,7 @@ // Also please add any ticket numbers that you belive might be affected here #define LIBAVFORMAT_VERSION_MAJOR 57 #define LIBAVFORMAT_VERSION_MINOR 46 -#define LIBAVFORMAT_VERSION_MICRO 101 +#define LIBAVFORMAT_VERSION_MICRO 102 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ -- 1.7.10.4