From patchwork Mon Feb 12 21:15:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46227 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9002:b0:19e:cdac:8cce with SMTP id d2csp921899pzc; Mon, 12 Feb 2024 13:16:39 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWsmALQpRkhhvpymuTzL5sDgkx9FMslOqeNMyFocaJm/QeCKSoBlDRp6oSkTHFETyBugfDzPySeKLyHOCt6KvCSyVLm/4fLp8H02g== X-Google-Smtp-Source: AGHT+IEkP/q65i0ev4418ZdktIlzlckx8Xk5nUZfATfcstxH4dMnwrW00EnTzigcTZE417cMSmhS X-Received: by 2002:a17:906:81c5:b0:a3c:edc4:4abd with SMTP id e5-20020a17090681c500b00a3cedc44abdmr419103ejx.33.1707772599087; Mon, 12 Feb 2024 13:16:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707772599; cv=none; d=google.com; s=arc-20160816; b=p3XNNZKtga9mUvWG+SoOwOARvG65e+8RnUKP8C5sFehzpZRWZjepJ7Oc4r1c6RLJaz JJQTt46O1oJyFg0WFFvXFpFNc293Rnw6TpW7y2NnK3i/HLU03p2sLnX9fqYFLqs2aMUI tMaGsFNhgzs757djA8mCWuupnsvidIIohNnwugUuyhLO1CGiW3jXdRumcmAmp/KCPGDK X2IF8XwQCPocpif+P7fIvxjnyg6W2+Rn6P9q5sTfS3C7KLFVHeqoUDwiXZN6UBs4VjlD 5WpzwJvMxGIY6rmYyQxrrnOpE6XWfhPp1EuLlbjBdY4aDTG9IvVJTxw1f+UNfB3zFy/I LGpA== 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=eu0WrLUV8C9mQDXoTwg/2yClG7iFh0aFg8MGni953N0=; fh=N14Olm9UeodHp55+b9Q+ubaOsCjj23NQ3BzUjMiWcFc=; b=f/pB8rLVPMUoQdC/4JEjJfA6AJvQAH5h5FXdTqRivIo2qGooihuEFNKgMjD3ESXXgW zUkrLxAtI+EtbticZT3I49fwscvKa1hmVBFQQvehNF5Ub5Ih4ZK2JK9xhg0yhFz5G3Hf Vcta8Okexjl+n85EAFonqiQlAIx4fFU4vEdJ7qzZfJSxpKzSptVoat5SgXF11yDPsEJw yaHbbw1oORE7JsDqf+1dIdTfmqTgIfPghvPdLIebXwd4n1DziicdC6qp0WWhaYBLZiia wAX7Hi1kHmT65cF1X6ags1esSBaY0ilm+yVr7uFGbezeb2mt0+HXmV1QtAx9Ka0FlG67 4S+g==; 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 X-Forwarded-Encrypted: i=1; AJvYcCUw9UzUPjjaZ/xjB/+vXv5agUcTp29cl6N4KOP5883qrgl2V9QHEcYbt3sji94rcDXSt1fssuxP1Eh+1p8ErE13mF4Xo86x3vE8AQRZZ/hZ4+zA1TJgLz3RINLewB631Z4PDChScLPwYOicvdCQ2nojn9rUtuzxF79SIFBJmR8O660hjcE1OtCJktFg2aIz2mS9UfQ5REt8KNU3lZRe68PXKyQbVXf8jt6eB0b0ZKSQdIjviXAVCiqJVZNlNWdFCGKOpYABE9oqnXN8yjSGGsZPrXoDvu0pr5G1aCf7/wdrK+hp4e0YVhGkKzdvnGu9QC/JBm1nnDSAji70ACjA+g6bpJJE4x07Zmh9X/pq9GX6uxZvmzjpjsK5o7gbjw26Ft13828xd5Q+18iUUiMQFCWzLs9nSoM3wdS82qzvHrK3koM6pPHrNJegeu3f2WLXfZErkJ7v5iWzpnumSRPZS5jXZTP+CkKtfedv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i9Ng/5ym2dkY5GG28P4uyhwe2kjOD6S/Zpl/mCnDyoWqTcj8Bz Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e27-20020a1709062c1b00b00a3ce76f5e9csi292738ejh.884.2024.02.12.13.16.38; Mon, 12 Feb 2024 13:16:39 -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 9AA0568D155; Mon, 12 Feb 2024 23:16: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 854CC68D15C for ; Mon, 12 Feb 2024 23:16:08 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 59CBAE9F67; Mon, 12 Feb 2024 22:16: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 GOX2X1WJ4-pX; Mon, 12 Feb 2024 22:16:07 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B8F50E9F59; Mon, 12 Feb 2024 22:16:06 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Feb 2024 22:15:37 +0100 Message-Id: <20240212211537.18468-5-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240212211537.18468-1-cus@passwd.hu> References: <20240212211537.18468-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] avformat/mov: rework ff_mov_read_chnl 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: J7Phl0Pg1jIQ A lot of changes and fixes to channel layout parsing, notably - get rid of dynamic allocation of channel positions - signal unimplemented speaker positions as unknown instead of failure, but warn the user about it - native order, and that a single channel only appears once was always assumed for less than 64 channels, obviously this was incorrect Signed-off-by: Marton Balint --- libavformat/mov_chan.c | 106 ++++++++++------------------------------- libavformat/mov_chan.h | 6 --- 2 files changed, 26 insertions(+), 86 deletions(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index cce9d7a697..3e186b0837 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -804,66 +804,6 @@ int ff_mov_get_channel_positions_from_layout(const AVChannelLayout *layout, return 0; } -int ff_mov_get_layout_from_channel_positions(const uint8_t *position, int position_num, - AVChannelLayout *layout) -{ - int ret; - enum AVChannel channel; - - av_channel_layout_uninit(layout); - - if (position_num <= 63) { - layout->order = AV_CHANNEL_ORDER_NATIVE; - layout->nb_channels = position_num; - for (int i = 0; i < position_num; i++) { - if (position[i] >= FF_ARRAY_ELEMS(iso_channel_position)) { - ret = AVERROR_PATCHWELCOME; - goto error; - } - - channel = iso_channel_position[position[i]]; - // unsupported layout - if (channel == AV_CHAN_NONE) { - ret = AVERROR_PATCHWELCOME; - goto error; - } - - layout->u.mask |= 1ULL << channel; - } - } else { - layout->order = AV_CHANNEL_ORDER_CUSTOM; - layout->nb_channels = position_num; - layout->u.map = av_calloc(position_num, sizeof(*layout->u.map)); - if (!layout->u.map) { - ret = AVERROR(ENOMEM); - goto error; - } - - for (int i = 0; i < position_num; i++) { - if (position[i] >= FF_ARRAY_ELEMS(iso_channel_position)) { - ret = AVERROR_PATCHWELCOME; - goto error; - } - - channel = iso_channel_position[position[i]]; - // unsupported layout - if (channel == AV_CHAN_NONE) { - ret = AVERROR_PATCHWELCOME; - goto error; - } - - layout->u.map[i].id = channel; - } - } - - - return 0; - -error: - av_channel_layout_uninit(layout); - return ret; -} - int ff_mov_read_chnl(AVFormatContext *s, AVIOContext *pb, AVStream *st) { int stream_structure = avio_r8(pb); @@ -875,33 +815,39 @@ int ff_mov_read_chnl(AVFormatContext *s, AVIOContext *pb, AVStream *st) av_log(s, AV_LOG_TRACE, "'chnl' layout %d\n", layout); if (!layout) { - uint8_t *positions = av_malloc(st->codecpar->ch_layout.nb_channels); + AVChannelLayout *ch_layout = &st->codecpar->ch_layout; + int nb_channels = ch_layout->nb_channels; + + av_channel_layout_uninit(ch_layout); + ret = av_channel_layout_custom_init(ch_layout, nb_channels); + if (ret < 0) + return ret; - if (!positions) - return AVERROR(ENOMEM); - for (int i = 0; i < st->codecpar->ch_layout.nb_channels; i++) { + for (int i = 0; i < nb_channels; i++) { int speaker_pos = avio_r8(pb); + enum AVChannel channel; + + if (speaker_pos == 126) // explicit position + avio_skip(pb, 3); // azimuth, elevation - av_log(s, AV_LOG_TRACE, "speaker_position %d\n", speaker_pos); - if (speaker_pos == 126) { // explicit position - avpriv_request_sample(s, "explicit position"); - av_freep(&positions); - return AVERROR_PATCHWELCOME; - } else { - positions[i] = speaker_pos; + if (speaker_pos >= FF_ARRAY_ELEMS(iso_channel_position)) + channel = AV_CHAN_NONE; + else + channel = iso_channel_position[speaker_pos]; + + if (channel == AV_CHAN_NONE) { + av_log(s, AV_LOG_WARNING, "speaker position %d is not implemented\n", speaker_pos); + channel = AV_CHAN_UNKNOWN; } + + ch_layout->u.map[i].id = channel; } - ret = ff_mov_get_layout_from_channel_positions(positions, - st->codecpar->ch_layout.nb_channels, - &st->codecpar->ch_layout); - av_freep(&positions); - if (ret) { - av_log(s, AV_LOG_ERROR, - "get channel layout from speaker positions failed, %s\n", - av_err2str(ret)); + ret = av_channel_layout_retype(ch_layout, AV_CHANNEL_ORDER_NATIVE, AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS); + if (ret == AVERROR(ENOSYS)) + ret = av_channel_layout_retype(ch_layout, AV_CHANNEL_ORDER_UNSPEC, AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS); + if (ret < 0 && ret != AVERROR(ENOSYS)) return ret; - } } else { uint64_t omitted_channel_map = avio_rb64(pb); diff --git a/libavformat/mov_chan.h b/libavformat/mov_chan.h index b7d435b99f..e480809c44 100644 --- a/libavformat/mov_chan.h +++ b/libavformat/mov_chan.h @@ -183,12 +183,6 @@ int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout); int ff_mov_get_channel_positions_from_layout(const AVChannelLayout *layout, uint8_t *position, int position_num); -/** - * Get AVChannelLayout from ISO/IEC 23001-8 OutputChannelPosition. - */ -int ff_mov_get_layout_from_channel_positions(const uint8_t *position, int position_num, - AVChannelLayout *layout); - /** * Read 'chnl' tag from the input stream. *