From patchwork Mon Apr 1 18:56:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 47701 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp922718pzb; Mon, 1 Apr 2024 11:57:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWk42OvZGZql6T+Np0ZSrtA+sp9OE/r2gyR3+oCasOcREgq4R8anXhmzLMRQ4CBycActADDs8pWF7SwnVtQEz9AK3yLFpwG9a8faw== X-Google-Smtp-Source: AGHT+IEmPoiNVq8PIamLPekAp+MVHaPR2428JxXguCqNys1MaeWaYeZASfzBRUnnX35db/t8XzWc X-Received: by 2002:a50:ed01:0:b0:56c:5a49:731 with SMTP id j1-20020a50ed01000000b0056c5a490731mr6484855eds.1.1711997826185; Mon, 01 Apr 2024 11:57:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711997826; cv=none; d=google.com; s=arc-20160816; b=yQUh2C+/Udm0lyM/poCfb1Wepg7envPh2n2PD5ABBY+OSIbkX2+qQHwJm8iFIiY1iO +8ffFpGzw8Ep39TLX3PsciTYgM2vUU0AxZXvi0ev+rewFmSPgPoITBrigX6+HziOGt0P y7neiASiXBl7JrqluOA97ogJ0AoSzmvXyASHxxFho6VPK2xm/BsCyxMcgPwmWaNFfhzu IR6SEvEh1TTeh1PJ3n2J0fblsFZoTCN7Rqt3X1BFPmcvVtmFpzwXUgWtnc0J49Tz06xO lFyYRs3ZGWXsikqrXDnSXsZf41yPvX4N43BLEhFdIjPUl8YsJzwSTl3+A9sAFplvmIFQ O9XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=LVbzQkZSCu2V4yErLPdLciTM4TDdMV2malQavCtTQeA=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=FSj48tVu/s5qbwwIqyvLrUm4yMYvOVTv884GDoGap+ToMu2npL1TO3VB6ZEQ8leBP0 mkrk2pYkiFklbuUjpkdPcdb7gigWYxjW1JecxSC7aVzoeHAOo2p1cQvq0C1583Bb322W xIUAfpZgoWvTtTls+EyPclHuRr1NhD6mqAZkhfaWKyvGEgu+XYXvJpRcmJRspURSqiz6 5/PV8y1OWYiH5Nznsz4msL6ehZmqAbNiakdnxe/ueTf9GEVM5ky/I4QXVRz2UnCz9JAr +yctpT2teEfaGhXVRxMZ/6PkIgSrq139E8gqRV9OQZr1V5esnOnK6kNUfnZXXp5npDTR AHbw==; dara=google.com ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r9-20020a056402234900b00568c171cc3fsi4877215eda.19.2024.04.01.11.57.05; Mon, 01 Apr 2024 11:57:06 -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 558AB68CAA7; Mon, 1 Apr 2024 21:56:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 686D868CAA7 for ; Mon, 1 Apr 2024 21:56:42 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 4CBB8EA2A1; Mon, 1 Apr 2024 20:56:42 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FBKDW6xYzRc4; Mon, 1 Apr 2024 20:56:40 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 4931EEA292; Mon, 1 Apr 2024 20:56:40 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 1 Apr 2024 20:56:21 +0200 Message-Id: <20240401185621.15297-4-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240401185621.15297-1-cus@passwd.hu> References: <20240401185621.15297-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] avformat/mov_chan: add support for omitted_channel bitmask in chnl atom X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: kHqa/9yYhgI1 Signed-off-by: Marton Balint --- libavformat/mov_chan.c | 43 ++++++++++++++++++++++-------------------- libavformat/mov_chan.h | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index e3cef3f4e8..e591ff031b 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -367,25 +367,33 @@ static const struct MovChannelLayoutMap* find_layout_map(uint32_t tag, const str * @param[in] tag channel layout tag * @return <0 on error */ -static int mov_get_channel_layout(AVChannelLayout *ch_layout, uint32_t tag, const struct MovChannelLayoutMap *map) +static int mov_get_channel_layout(AVChannelLayout *ch_layout, uint32_t tag, uint64_t omitted_channel_map, const struct MovChannelLayoutMap *map) { - int i, channels; const struct MovChannelLayoutMap *layout_map; - channels = tag & 0xFFFF; - /* find the channel layout for the specified layout tag */ layout_map = find_layout_map(tag, map); if (layout_map) { int ret; + int map_layout_nb_channels = tag & 0xFFFF; + int nb_channels = ch_layout->nb_channels; + + /* Omitted channel bits must not exceed number of channels in map */ + if (omitted_channel_map >> map_layout_nb_channels) + return AVERROR_INVALIDDATA; + av_channel_layout_uninit(ch_layout); - ret = av_channel_layout_custom_init(ch_layout, channels); + ret = av_channel_layout_custom_init(ch_layout, nb_channels); if (ret < 0) return ret; - for (i = 0; i < channels; i++) { - enum AVChannel id = layout_map[i].id; - ch_layout->u.map[i].id = (id != AV_CHAN_NONE ? id : AV_CHAN_UNKNOWN); + + for (int i = 0, idx = 0; i < map_layout_nb_channels && idx < nb_channels; i++, omitted_channel_map >>= 1) { + if (!(omitted_channel_map & 1)) { + enum AVChannel id = layout_map[i].id; + ch_layout->u.map[idx++].id = (id != AV_CHAN_NONE ? id : AV_CHAN_UNKNOWN); + } } + return av_channel_layout_retype(ch_layout, 0, AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL); } return 0; @@ -580,7 +588,7 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, if (!ch_layout->nb_channels) ch_layout->nb_channels = nb_channels; if (nb_channels == ch_layout->nb_channels) { - ret = mov_get_channel_layout(ch_layout, layout_tag, mov_ch_layout_map); + ret = mov_get_channel_layout(ch_layout, layout_tag, 0, mov_ch_layout_map); if (ret < 0) return ret; } else { @@ -741,16 +749,17 @@ int ff_mov_get_channel_config_from_layout(const AVChannelLayout *layout, int *co return 0; } -int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout) +int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout, uint64_t omitted_channel_map) { if (config > 0) { uint32_t layout_tag; + int nb_omitted_channels = av_popcount64(omitted_channel_map); - if (layout->nb_channels <= 0 || layout->nb_channels > UINT16_MAX) + if (layout->nb_channels <= 0 || layout->nb_channels > UINT16_MAX - nb_omitted_channels) return AVERROR_INVALIDDATA; - layout_tag = (config << 16) | layout->nb_channels; - return mov_get_channel_layout(layout, layout_tag, iso_ch_layout_map); + layout_tag = (config << 16) | (layout->nb_channels + nb_omitted_channels); + return mov_get_channel_layout(layout, layout_tag, omitted_channel_map, iso_ch_layout_map); } return 1; } @@ -826,13 +835,7 @@ int ff_mov_read_chnl(AVFormatContext *s, AVIOContext *pb, AVStream *st) return ret; } else { uint64_t omitted_channel_map = avio_rb64(pb); - - if (omitted_channel_map) { - avpriv_request_sample(s, "omitted_channel_map 0x%" PRIx64 " != 0", - omitted_channel_map); - return AVERROR_PATCHWELCOME; - } - ret = ff_mov_get_channel_layout_from_config(layout, &st->codecpar->ch_layout); + ret = ff_mov_get_channel_layout_from_config(layout, &st->codecpar->ch_layout, omitted_channel_map); if (ret < 0) return ret; } diff --git a/libavformat/mov_chan.h b/libavformat/mov_chan.h index 604395d7d3..ea8be47196 100644 --- a/libavformat/mov_chan.h +++ b/libavformat/mov_chan.h @@ -176,7 +176,7 @@ int ff_mov_get_channel_config_from_layout(const AVChannelLayout *layout, int *co * 0 if the config was found * <0 on error */ -int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout); +int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout, uint64_t omitted_channel_map); /** * Get ISO/IEC 23001-8 OutputChannelPosition from AVChannelLayout.