From patchwork Mon Jan 29 23:27:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 45893 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp1839919pzb; Mon, 29 Jan 2024 15:28:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0s3bZ91F9fspF78vyvVofa59z2T2EY88WHL9eq9UCfQ283dakwrQHkwGR+uVn13tTmsHG X-Received: by 2002:a17:906:3913:b0:a35:34a7:af1d with SMTP id f19-20020a170906391300b00a3534a7af1dmr5162006eje.13.1706570892561; Mon, 29 Jan 2024 15:28:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706570892; cv=none; d=google.com; s=arc-20160816; b=wxf1VoSa6OigaXJfzS3mo1LjT63UJxywkhAM1eWS2YLWPYYVV7VPzKvCthrmBkH41D 9b/EsuVFeXaagvFShpX+8APLVbcNVYCaJXr3qGwOl/hL7iw0nwX9VXNMtQH/7/okP2lS 3F3/gKZAm6GMGhnV//tenJnkMQkhMh05TZgaGXc4tyvRNGAfmglBAknXNXkl1m1cQB2L 7dUH7eBaxYsHnR7Mb4CNBygrpWy41e0SQ177gLjq8I5wqJTUsU9zgM6myZPsqNSsFvIq qytGvjUfXWOcZr4yoyKbwtSdm6uvRvflX21ANghLQvjaqgBR++KFGE2+t0M6oZF9f0eS 8w6w== 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:message-id:date:to:from :delivered-to; bh=16NtmJU3Eq1CaBRSFdVuAZd+zUFW2H9aV+iav7wSRMU=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=ooUh8cBx6Hp8VMPODdvzjU6zv1WQFbVcHZU5R6au+BOeDCj3sy7e79NRBGovEbbSt9 HzBVtnNwZbUpndN76CVzw97Sj/QQ8dDwuoPBHyRnRlCvAkV26pvGM/OpO712Fk/tn75S 9jTV4FXG/vZYir+6ikX0l8Rpce5d4cOOw4mPMmhdvaP4d3+0xADlmQ9uik22r3b3sGqF bNt5kPYh0STXA5TyHziOCYdyOJ4hWQn6rWKAmX2YCmRFaGMGk46JOGwCYnxQ0sERai2L Fn2PisyQMgIdTz0hKxKAHtzpPcWjz+m9UwXEkobH6d4LYxNyzjCCx20siKFSASGbnvcr Uazg== 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 l13-20020a17090612cd00b00a35a4074919si1665260ejb.450.2024.01.29.15.28.12; Mon, 29 Jan 2024 15:28:12 -0800 (PST) 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 5DE1768D286; Tue, 30 Jan 2024 01:28:09 +0200 (EET) 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 7945F68D22F for ; Tue, 30 Jan 2024 01:28:02 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 15891E9CAA; Tue, 30 Jan 2024 00:28:02 +0100 (CET) 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 ZeBJlGaaVeUh; Tue, 30 Jan 2024 00:28:00 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id CBEADE95E9; Tue, 30 Jan 2024 00:27:59 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Jan 2024 00:27:51 +0100 Message-Id: <20240129232755.9622-1-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] avformat/mov_chan: do not assume channels are in native order 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: pMAF63UCPn+E Existing code could have caused wrong channel order signalling or reduced channel count if a channel designation appeared multiple times. This is actually an old bug, but the conversion to the new channel layout API made it visible, because now the code overrides the proper channel count with the one calculated from the mask. Signed-off-by: Marton Balint --- libavformat/mov_chan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index f3d51899e1..5cb2de3820 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -530,7 +530,7 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, size -= 20; if (layout_tag == 0) { uint64_t mask_incr = mov_get_channel_mask(label); - if (mask_incr == 0) { + if (mask_incr == 0 || mask_incr <= label_mask) { label_mask = 0; break; } From patchwork Mon Jan 29 23:27:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 45897 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp1840145pzb; Mon, 29 Jan 2024 15:28:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHehuF2LHd8yojmim0+TCfviKnFSlLU7XeeQJ5ObdHYyQpI0jAwGORio0AqECAOtcj4/eh2 X-Received: by 2002:a19:6916:0:b0:50e:84f9:22dc with SMTP id e22-20020a196916000000b0050e84f922dcmr4630977lfc.2.1706570930960; Mon, 29 Jan 2024 15:28:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706570930; cv=none; d=google.com; s=arc-20160816; b=E2Nur/HK8eUbEx06JWGZogGVwSnOUEF7MK4A6yZ2tLbYTri2RlI+hRuk5MYNtZl+aV VVpcDxmN4v//cFOnLjVrDeez5iiOqYtJQy65MY2RQbBE6gcPZSdoRM0f43cbhzQJ2M7L qWGrJOd5LfDoJjJCME4MRAlJkn9AZ/H4LcqqnYoRd6+QmcVIRcmXF1Ibho9fJARa5YQ3 Sb5PwFGrn4Y3XdDjN+tmuY8hRcPa+Bq8fJ+U8buiorTgQtan2qcwv242ZIsHKUrJT04j CeiW14ZgWC2UvcjhX9H8IfPsQHZP0w7pmki036Af4WfS6iutzUSUGf8mf+/sXEVeKHem hkKA== 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=54/OHlyM65FmFzwsCLhf7wGq7cKG4fZzA0Y2+657zgQ=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=HkZaGePmaOJEbkeBzqDnwrVEe+Ursx84M4rS9lw5F9/WRpuL74hqNWCWrCrhLOee0q CN0EgNaAfBpZGt17AYnsndB5qa4DtKns0PIHXhj4mtGlwli2+30N0+oTtcx5Ctf2x+eM oH6L0KwyJzTiZIiCotzXnzSs6DXGPXd3XEgPDl1TOsP09VI6v9akFX90HfETO9BvmQoc YFfUwruc2B48mg8LF7nnCoFucYrHy3Iy14zXNGrwGSiRFMf/+mmUPiIJRA3wMnkPuKez TkUT+MLn/00hPX1WCowzh7X3MZOGVIonyrr/Ssu411as9rr+EZ1/copkTsbaqyHLNxZU XClw== 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 ov10-20020a170906fc0a00b00a35d95990bdsi958957ejb.745.2024.01.29.15.28.20; Mon, 29 Jan 2024 15:28:50 -0800 (PST) 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 5424968D28C; Tue, 30 Jan 2024 01:28:13 +0200 (EET) 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 9193A68D22F for ; Tue, 30 Jan 2024 01:28:06 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 56B6AE95E9; Tue, 30 Jan 2024 00:28:06 +0100 (CET) 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 ccEUOYWMOEfN; Tue, 30 Jan 2024 00:28:04 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 408C4E9D12; Tue, 30 Jan 2024 00:28:04 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Jan 2024 00:27:52 +0100 Message-Id: <20240129232755.9622-2-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240129232755.9622-1-cus@passwd.hu> References: <20240129232755.9622-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] avformat/mov_chan: never override number of channels based on chan 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: ZLl8d2tr4Bxs The channel designation metadata should not override the number of channels. Let's warn the user if it is inconsistent, and keep the channel layout unspecified. Before the conversion to the channel layout API the code only set the mask, but never overridden the channel count, so this restores the old behaviour. Signed-off-by: Marton Balint --- libavformat/mov_chan.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index 5cb2de3820..6b206745b4 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -544,8 +544,13 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, mask = mov_get_channel_layout(layout_tag, bitmap); if (mask) { - av_channel_layout_uninit(&st->codecpar->ch_layout); - av_channel_layout_from_mask(&st->codecpar->ch_layout, mask); + if (!st->codecpar->ch_layout.nb_channels || av_popcount64(mask) == st->codecpar->ch_layout.nb_channels) { + av_channel_layout_uninit(&st->codecpar->ch_layout); + av_channel_layout_from_mask(&st->codecpar->ch_layout, mask); + } else { + av_log(s, AV_LOG_WARNING, "ignoring channel layout with %d channels because the real number of channels is %d\n", + av_popcount64(mask), st->codecpar->ch_layout.nb_channels); + } } avio_skip(pb, size - 12); From patchwork Mon Jan 29 23:27:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 45894 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp1840010pzb; Mon, 29 Jan 2024 15:28:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0C1Xa6r7BsiT1PnvAhBhkJJT2yaqY27XPiyQGA6lziHNNd//+ifMWlrluin1di6BZZXPp X-Received: by 2002:a50:fc10:0:b0:55f:2854:c55f with SMTP id i16-20020a50fc10000000b0055f2854c55fmr1235132edr.0.1706570909196; Mon, 29 Jan 2024 15:28:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706570909; cv=none; d=google.com; s=arc-20160816; b=Ce9R+LgQHQE24/F+I7VP37mhmJrm7Zl9pRvBs02DnK/inaVZxPtEASCD6OgbDEewqr JWsC0f5ue5kNcR44QazXkHeuWGhfm/QgUQPpAdXCqi/qG4FjzY2c+mE6/Pu1VZe5jpHB gmqbkfJHy4/tQeoH2YsOsLZTopahGW6IH6EWnG/cF2uRqJjVopZT7bBibKnKHhBQJLvZ w/UYGBtGAaccJn2Vq+TRhS6uz5axXYu2Nr5ZoYxu8/fClfh2Ru7kZqsvYdLA5Xq0/oLn +aEK4UyiDPTWKK+LBC4ZhzLmTNWqF7n05QR5ivAhfYvQL1Srcvh0CASQePQ2wlXkhJ2Q IKjw== 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=cAbnd4wLhktmntsP4+dqOXGk24DDoCxd8qfn78kbVKw=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=xfSKdRi1ltRTpTELG9pVT/0XuvawfC0OKZ4nfBiWU6gEoWI5Fuu+R2bMLpC2UOjASJ jaeSxGNg4in/V4GIAjKwn9Keh8szUbt//GG87o+GKoZaqFZUCd7KO//V7+B9dE1F4P4C S1t44MSxZwEkXd7jw1C+4ERkbTE184agGUhgB5XchOf+jZ6WKQoG2NC1htbc73cS6bhx dfJZp3nUEtkWxd7Fah3em+qAjzzKErRUlMomDQtJ4h4F2ckQb4zdELMdg68RCx70QDfN w2kHA9nm0kFRah+zkh76vSUD//WDvDik2enoDUJG6ShsI6hCDvXpWifnvEfNEsFsfHTn stKA== 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 eo8-20020a056402530800b0055400f1f188si3972027edb.41.2024.01.29.15.28.28; Mon, 29 Jan 2024 15:28:29 -0800 (PST) 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 5A42268D289; Tue, 30 Jan 2024 01:28:15 +0200 (EET) 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 75B2968D28D for ; Tue, 30 Jan 2024 01:28:08 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 43318E9CAA; Tue, 30 Jan 2024 00:28:08 +0100 (CET) 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 x51vE-84-oKr; Tue, 30 Jan 2024 00:28:06 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 4D967E9D8A; Tue, 30 Jan 2024 00:28:06 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Jan 2024 00:27:53 +0100 Message-Id: <20240129232755.9622-3-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240129232755.9622-1-cus@passwd.hu> References: <20240129232755.9622-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avutil/channel_layout: add av_channel_layout_from_custom() 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: d5t1uUO+chTS Signed-off-by: Marton Balint --- doc/APIchanges | 3 +++ libavutil/channel_layout.c | 20 ++++++++++++++++++++ libavutil/channel_layout.h | 13 +++++++++++++ libavutil/version.h | 4 ++-- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index e477ed78e0..8e8498f803 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 API changes, most recent first: +2024-02-xx - xxxxxxxxxx - lavu 58.37.100 - channel_layout.h + Add av_channel_layout_from_custom(). + 2023-11-xx - xxxxxxxxxx - lavfi 9.16.100 - buffersink.h buffersrc.h Add av_buffersink_get_colorspace and av_buffersink_get_color_range. Add AVBufferSrcParameters.color_space and AVBufferSrcParameters.color_range. diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index b59d798f29..0810d32bf6 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -398,6 +398,26 @@ int av_get_standard_channel_layout(unsigned index, uint64_t *layout, FF_ENABLE_DEPRECATION_WARNINGS #endif +int av_channel_layout_from_custom(AVChannelLayout *channel_layout, int nb_channels) +{ + AVChannelCustom *map; + + if (nb_channels <= 0) + return AVERROR(EINVAL); + + map = av_calloc(nb_channels, sizeof(*channel_layout->u.map)); + if (!map) + return AVERROR(ENOMEM); + for (int i = 0; i < nb_channels; i++) + map[i].id = AV_CHAN_UNKNOWN; + + channel_layout->order = AV_CHANNEL_ORDER_CUSTOM; + channel_layout->nb_channels = nb_channels; + channel_layout->u.map = map; + + return 0; +} + int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask) { diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index 8dc1a91401..37629ab5d2 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -617,6 +617,19 @@ void av_channel_description_bprint(struct AVBPrint *bp, enum AVChannel channel_i */ enum AVChannel av_channel_from_string(const char *name); +/** + * Initialize a custom channel layout with the specified number of channels. + * The designation of all channels will be unknown. + * + * @param channel_layout the layout structure to be initialized + * @param nb_channels the number of channels + * + * @return 0 on success + * AVERROR(EINVAL) if the number of channels <= 0 + * AVERROR(ENOMEM) if the channel map could not be allocated + */ +int av_channel_layout_from_custom(AVChannelLayout *channel_layout, int nb_channels); + /** * Initialize a native channel layout from a bitmask indicating which channels * are present. diff --git a/libavutil/version.h b/libavutil/version.h index 772c4e209c..3b38f8f5da 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,8 +79,8 @@ */ #define LIBAVUTIL_VERSION_MAJOR 58 -#define LIBAVUTIL_VERSION_MINOR 36 -#define LIBAVUTIL_VERSION_MICRO 101 +#define LIBAVUTIL_VERSION_MINOR 37 +#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ From patchwork Mon Jan 29 23:27:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 45895 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp1840063pzb; Mon, 29 Jan 2024 15:28:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFP9qnNnXyS8b131UpHNB9O8+f2sGSUqTlqk/50dtoaV+0NsjW1e64gE0lKGKnUrr23Tt1M X-Received: by 2002:aa7:d985:0:b0:55e:f6c5:4e44 with SMTP id u5-20020aa7d985000000b0055ef6c54e44mr2529895eds.40.1706570916974; Mon, 29 Jan 2024 15:28:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706570916; cv=none; d=google.com; s=arc-20160816; b=llZ1ns0AHf0DHxHM4K8NNQR4cHNrSDDnPjYBJLEm24PwruAFkP8ZEwXXE8LfmTDHdc sTmeh8i4jkd/3zvnWY14rj4M1w01deNgcxPUuUZfQ74upFlO5MJZyRumICmMSzBoCCbL zZfpjvKDQGX1Vfw+yOSyshOj2vRohocWo2meR3fD//0IsWJUhK9/YcqdRO41O4N4FgO1 KOW8h/48eD4kpeq5/wbTWpgP1JwgIvnxH+jeG/nmiTsHcLpJ8gld5ikjXFN50Jfy5iZj GeoLETdYYmKGSOc0e3IzrQmy5Wi9EnRzM4s/HQu89/X49G5H/EaEj6EXxGWT6cbHd6ji VRpQ== 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=53n6KukAgu1ndu2+f08KtNN/VOT8qNpfcL1IVZpTkYI=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=XntMkG2J3J/TxMFqRVcIF99m2BwjRmAYmpDdexk7LP65G+mSJ+jzN3TfFbprp7Q/Y1 wJgSAV2CvkpFbS3lZfx50fJQEYWqIPkoekPStzUi4IxAewok99/ZHPHmE2BwrKONM7g9 6RO3gGgvp3MxmD0onKdDbQ4B0qRDigXAzrRjZH9R7PBDyC1SXVX8cw5WuUVOZ5kfOrvf pZHK/TUy4MJs3zeGxAJXcWJ+0+BRAfIh6S7GyEO/yhruW7AUlc3ChaU+cHfZkIWowk/l 4fNF+10qs8MQKP7j6SNFQJTTrco6wL0WelTUFhkADDCP6xZdB53EEBsBzY+x/o2Zd5x8 KwWw== 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 di25-20020a056402319900b0055f00aa7576si1324382edb.259.2024.01.29.15.28.36; Mon, 29 Jan 2024 15:28:36 -0800 (PST) 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 6A97668D29A; Tue, 30 Jan 2024 01:28:16 +0200 (EET) 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 B133768D28A for ; Tue, 30 Jan 2024 01:28:09 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 86AF3E9D8A; Tue, 30 Jan 2024 00:28:09 +0100 (CET) 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 zhRlxHrp8VUV; Tue, 30 Jan 2024 00:28:08 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 622DFE9D12; Tue, 30 Jan 2024 00:28:07 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Jan 2024 00:27:54 +0100 Message-Id: <20240129232755.9622-4-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240129232755.9622-1-cus@passwd.hu> References: <20240129232755.9622-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] avutil/channel_layout: add av_channel_layout_retype() 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: 0Ai9+qRL6bb6 Signed-off-by: Marton Balint --- doc/APIchanges | 3 +++ libavutil/channel_layout.c | 48 ++++++++++++++++++++++++++++++++++++++ libavutil/channel_layout.h | 11 +++++++++ libavutil/version.h | 2 +- 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 8e8498f803..ce1e816fa5 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 API changes, most recent first: +2024-02-xx - xxxxxxxxxx - lavu 58.38.100 - channel_layout.h + Add av_channel_layout_retype(). + 2024-02-xx - xxxxxxxxxx - lavu 58.37.100 - channel_layout.h Add av_channel_layout_from_custom(). diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 0810d32bf6..cc8c208080 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -1036,3 +1036,51 @@ uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout, return ret; } + +int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order) +{ + if (!av_channel_layout_check(channel_layout)) + return AVERROR(EINVAL); + + if (channel_layout->order == order) + return 0; + + switch (order) { + case AV_CHANNEL_ORDER_UNSPEC: { + int nb_channels = channel_layout->nb_channels; + av_channel_layout_uninit(channel_layout); + channel_layout->order = AV_CHANNEL_ORDER_UNSPEC; + channel_layout->nb_channels = nb_channels; + return 0; + } + case AV_CHANNEL_ORDER_CUSTOM: { + AVChannelLayout custom = { 0 }; + int ret = av_channel_layout_from_custom(&custom, channel_layout->nb_channels); + if (ret < 0) + return ret; + if (channel_layout->order != AV_CHANNEL_ORDER_UNSPEC) + for (int i = 0; i < channel_layout->nb_channels; i++) + custom.u.map[i].id = av_channel_layout_channel_from_index(channel_layout, i); + av_channel_layout_uninit(channel_layout); + *channel_layout = custom; + return 0; + } + case AV_CHANNEL_ORDER_NATIVE: + if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { + uint64_t mask = 0; + for (int i = 0; i < channel_layout->nb_channels; i++) { + enum AVChannel ch = channel_layout->u.map[i].id; + if (ch >= 0 && ch < 63 && mask < (1ULL << ch)) + mask |= (1ULL << ch); + else + return 1; + } + av_channel_layout_uninit(channel_layout); + return av_channel_layout_from_mask(channel_layout, mask); + } else { + return 1; + } + default: + return 1; + } +} diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index 37629ab5d2..7e27a00d39 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -817,6 +817,17 @@ int av_channel_layout_check(const AVChannelLayout *channel_layout); */ int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1); +/** + * Try changing the AVChannelOrder of a channel layout. + * + * @param channel_layout channel layout which will be changed + * @param order the desired channel layout order + * @return 0 on success or if the channel layout is already in the desired order + * 1 if using the desired order is not possible for the specified layout + * AVERROR code on error + */ +int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order); + /** * @} */ diff --git a/libavutil/version.h b/libavutil/version.h index 3b38f8f5da..cebf4a0acd 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 58 -#define LIBAVUTIL_VERSION_MINOR 37 +#define LIBAVUTIL_VERSION_MINOR 38 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ From patchwork Mon Jan 29 23:27:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 45896 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp1840115pzb; Mon, 29 Jan 2024 15:28:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEGLqepXPUzqPhnRPwlfFafv+k4+/ZrH8sRVC6G5Uc6FJy0MB7V5Mukqpju9e4eimdHhHu X-Received: by 2002:a17:907:7284:b0:a31:7e9c:60bf with SMTP id dt4-20020a170907728400b00a317e9c60bfmr6589677ejc.0.1706570925491; Mon, 29 Jan 2024 15:28:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706570925; cv=none; d=google.com; s=arc-20160816; b=vl4F8GDmDPVHP9cSIjQyrjIXIksxjIQ4FmgCcAaXUVe63npGyfZGmzWjnD2ZsxxRRG MUEfsfmgYENckuoneKNqz2eQ9gTosz0focEIGUi8BsQVydWN4iCdkzp4NN59BIg1/VGC wNx+1d8t0C5au5RrAbOgjP5JUfHXqZkNxzjsgbwAT4Me3hOVZPWlRpfyV0OV3urRtA+i FvKnNq4CQSKfocLfmVpvblV379vaeZM8p3yJJQL38oeiAMkHd45gWVSUdqELp5RGrxs+ StVsIMwnmdw9wjehmKbf6MPc/fpkaenFymHmHU7Ht48SyAtSqSxVI5G7Z1y4BVOaKCaL Z68w== 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=fMmf58lQGDiAo0HllmwH0Q2I6+8txGTeSYSxaODT2Fw=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=BZnQmndwRPIOcqMB/1rJ9ZiZJHXWN07HbUfwrpfn3OUO335cdkptvJJVu+nj0QzXDX oxl/uG8GdCF/uWes8chr7Q3kK1WJjfxlW6R1i/ndwMyjeS/Mym4Gb0i4g6onCe1VeeQg WPhd1I9HbfaQo9MGL3/0Z8McqkIFmqiFyZISA4q0wWDFuTVBxef4FGE/0uVpBMq83Pal sQr4ctf8jVIl3MiE8KVmMYD1p9vhc3zNVTiLnEgmT8ysJHt367bfmQhGbcjwsXqjT23e QOr2H/7iqExgYycbKTFb3fxwoS1TLek86TxrRKQuuTAw39OCH2f2SC+VR/RCknDJNgIG 8x6Q== 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 u14-20020a1709063b8e00b00a35d99b68d5si959386ejf.38.2024.01.29.15.28.45; Mon, 29 Jan 2024 15:28:45 -0800 (PST) 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 7B01B68D295; Tue, 30 Jan 2024 01:28:19 +0200 (EET) 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 B01A268D295 for ; Tue, 30 Jan 2024 01:28:12 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 88CF9E95E9; Tue, 30 Jan 2024 00:28:12 +0100 (CET) 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 1OjDtob1G8i3; Tue, 30 Jan 2024 00:28:10 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C3A85E9D12; Tue, 30 Jan 2024 00:28:09 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Jan 2024 00:27:55 +0100 Message-Id: <20240129232755.9622-5-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240129232755.9622-1-cus@passwd.hu> References: <20240129232755.9622-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] avformat/mov_chan: add support for reading custom channel layouts when layout_tag == 0 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: 50MgbjRxw4vK Signed-off-by: Marton Balint --- libavformat/mov_chan.c | 99 +++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index 6b206745b4..ce1e462dd1 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -377,23 +377,23 @@ static uint64_t mov_get_channel_layout(uint32_t tag, uint32_t bitmap) return layout_map[i].layout; } -static uint64_t mov_get_channel_mask(uint32_t label) +static enum AVChannel mov_get_channel_id(uint32_t label) { if (label == 0) - return 0; + return AV_CHAN_UNUSED; if (label <= 18) - return 1U << (label - 1); + return (label - 1); if (label == 35) - return AV_CH_WIDE_LEFT; + return AV_CHAN_WIDE_LEFT; if (label == 36) - return AV_CH_WIDE_RIGHT; + return AV_CHAN_WIDE_RIGHT; if (label == 37) - return AV_CH_LOW_FREQUENCY_2; + return AV_CHAN_LOW_FREQUENCY_2; if (label == 38) - return AV_CH_STEREO_LEFT; + return AV_CHAN_STEREO_LEFT; if (label == 39) - return AV_CH_STEREO_RIGHT; - return 0; + return AV_CHAN_STEREO_RIGHT; + return AV_CHAN_UNKNOWN; } static uint32_t mov_get_channel_label(enum AVChannel channel) @@ -497,8 +497,8 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, int64_t size) { uint32_t layout_tag, bitmap, num_descr; - uint64_t label_mask, mask = 0; - int i; + int ret; + AVChannelLayout *ch_layout = &st->codecpar->ch_layout; if (size < 12) return AVERROR_INVALIDDATA; @@ -514,47 +514,56 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, if (size < 12ULL + num_descr * 20ULL) return 0; - label_mask = 0; - for (i = 0; i < num_descr; i++) { - uint32_t label; - if (pb->eof_reached) { - av_log(s, AV_LOG_ERROR, - "reached EOF while reading channel layout\n"); - return AVERROR_INVALIDDATA; + if (layout_tag == 0) { + int nb_channels = ch_layout->nb_channels ? ch_layout->nb_channels : num_descr; + if (num_descr > nb_channels) { + av_log(s, AV_LOG_WARNING, "got %d channel descriptions, capping to the number of channels %d\n", + num_descr, nb_channels); + num_descr = nb_channels; } - label = avio_rb32(pb); // mChannelLabel - avio_rb32(pb); // mChannelFlags - avio_rl32(pb); // mCoordinates[0] - avio_rl32(pb); // mCoordinates[1] - avio_rl32(pb); // mCoordinates[2] - size -= 20; - if (layout_tag == 0) { - uint64_t mask_incr = mov_get_channel_mask(label); - if (mask_incr == 0 || mask_incr <= label_mask) { - label_mask = 0; - break; + + av_channel_layout_uninit(ch_layout); + ret = av_channel_layout_from_custom(ch_layout, nb_channels); + if (ret < 0) + goto out; + + for (int i = 0; i < num_descr; i++) { + uint32_t label; + if (pb->eof_reached) { + av_log(s, AV_LOG_ERROR, + "reached EOF while reading channel layout\n"); + return AVERROR_INVALIDDATA; } - label_mask |= mask_incr; + label = avio_rb32(pb); // mChannelLabel + avio_rb32(pb); // mChannelFlags + avio_rl32(pb); // mCoordinates[0] + avio_rl32(pb); // mCoordinates[1] + avio_rl32(pb); // mCoordinates[2] + size -= 20; + ch_layout->u.map[i].id = mov_get_channel_id(label); } - } - if (layout_tag == 0) { - if (label_mask) - mask = label_mask; - } else - mask = mov_get_channel_layout(layout_tag, bitmap); - - if (mask) { - if (!st->codecpar->ch_layout.nb_channels || av_popcount64(mask) == st->codecpar->ch_layout.nb_channels) { - av_channel_layout_uninit(&st->codecpar->ch_layout); - av_channel_layout_from_mask(&st->codecpar->ch_layout, mask); - } else { - av_log(s, AV_LOG_WARNING, "ignoring channel layout with %d channels because the real number of channels is %d\n", - av_popcount64(mask), st->codecpar->ch_layout.nb_channels); + + ret = av_channel_layout_retype(ch_layout, AV_CHANNEL_ORDER_NATIVE); + if (ret < 0) + goto out; + } else { + uint64_t mask = mov_get_channel_layout(layout_tag, bitmap); + if (mask) { + if (!ch_layout->nb_channels || av_popcount64(mask) == ch_layout->nb_channels) { + av_channel_layout_uninit(ch_layout); + av_channel_layout_from_mask(ch_layout, mask); + } else { + av_log(s, AV_LOG_WARNING, "ignoring channel layout with %d channels because number of channels is %d\n", + av_popcount64(mask), ch_layout->nb_channels); + } } } + ret = 0; + +out: avio_skip(pb, size - 12); - return 0; + return ret; } /* ISO/IEC 23001-8, 8.2 */