From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id DDBF24972C for ; Tue, 19 Mar 2024 21:15:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 319EE68D44E; Tue, 19 Mar 2024 23:15:28 +0200 (EET) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2591E68D44B for ; Tue, 19 Mar 2024 23:15:22 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 10B8CEA1C9; Tue, 19 Mar 2024 22:15:22 +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 ZYG5Rw4Cxl07; Tue, 19 Mar 2024 22:15:20 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 6BCA3EA212; Tue, 19 Mar 2024 22:15:18 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Mar 2024 22:15:03 +0100 Message-Id: <20240319211504.8342-5-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240319211504.8342-1-cus@passwd.hu> References: <20240319211504.8342-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/6] avfilter/af_channelmap: add some additional checks for the mappings 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: - Properly initialize all the mappings to -1 by default. - Make sure every output channel is assigned exactly once - Autodetect a native layout when only native channels are present - Always honor the user specified layout, but make sure the mapping is compatible with it The last item is a regression from 4af412be7153405e43930ac73fc7d91d7ded19eb. Signed-off-by: Marton Balint --- libavfilter/af_channelmap.c | 53 +++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c index 62e11103ad..64efacb576 100644 --- a/libavfilter/af_channelmap.c +++ b/libavfilter/af_channelmap.c @@ -146,7 +146,8 @@ static av_cold int channelmap_init(AVFilterContext *ctx) char *mapping, separator = '|'; int map_entries = 0; enum MappingMode mode; - uint64_t out_ch_mask = 0; + int64_t out_ch_mask = 0; + uint64_t presence_mask; int i; mapping = s->mapping_str; @@ -187,6 +188,13 @@ static av_cold int channelmap_init(AVFilterContext *ctx) return AVERROR(EINVAL); } + for (i = 0; i < MAX_CH; i++) { + s->map[i].in_channel_idx = -1; + s->map[i].out_channel_idx = -1; + s->map[i].in_channel = -1; + s->map[i].out_channel = -1; + } + for (i = 0; i < map_entries; i++) { int in_ch_idx = -1, out_ch_idx = -1; int in_ch = -1, out_ch = -1; @@ -219,14 +227,16 @@ static av_cold int channelmap_init(AVFilterContext *ctx) break; case MAP_PAIR_INT_STR: if (get_channel_idx(&mapping, &in_ch_idx, '-', MAX_CH) < 0 || - get_channel(&mapping, &out_ch, separator) < 0 || - (1ULL << out_ch) & out_ch_mask) { + get_channel(&mapping, &out_ch, separator) < 0) { av_log(ctx, AV_LOG_ERROR, err); return AVERROR(EINVAL); } s->map[i].in_channel_idx = in_ch_idx; s->map[i].out_channel = out_ch; - out_ch_mask |= 1ULL << out_ch; + if (out_ch < 63) + out_ch_mask |= 1ULL << out_ch; + else + out_ch_mask = -1; break; case MAP_PAIR_STR_INT: if (get_channel(&mapping, &in_ch, '-') < 0 || @@ -239,23 +249,27 @@ static av_cold int channelmap_init(AVFilterContext *ctx) break; case MAP_PAIR_STR_STR: if (get_channel(&mapping, &in_ch, '-') < 0 || - get_channel(&mapping, &out_ch, separator) < 0 || - (1ULL << out_ch) & out_ch_mask) { + get_channel(&mapping, &out_ch, separator) < 0) { av_log(ctx, AV_LOG_ERROR, err); return AVERROR(EINVAL); } s->map[i].in_channel = in_ch; s->map[i].out_channel = out_ch; - out_ch_mask |= 1ULL << out_ch; + if (out_ch < 63) + out_ch_mask |= 1ULL << out_ch; + else + out_ch_mask = -1; break; } } s->mode = mode; s->nch = map_entries; - if (out_ch_mask) - av_channel_layout_from_mask(&s->output_layout, out_ch_mask); - else if (map_entries && s->output_layout.nb_channels == 0) - av_channel_layout_default(&s->output_layout, map_entries); + if (s->output_layout.nb_channels == 0) { + if (out_ch_mask > 0) + av_channel_layout_from_mask(&s->output_layout, out_ch_mask); + else if (map_entries) + av_channel_layout_default(&s->output_layout, map_entries); + } if (mode == MAP_NONE) { int i; @@ -286,6 +300,23 @@ static av_cold int channelmap_init(AVFilterContext *ctx) } } + presence_mask = 0; + for (i = 0; i < s->nch; i++) { + uint64_t idx_mask; + int ret = check_idx_and_id(ctx, s->map[i].out_channel_idx, s->map[i].out_channel, &s->output_layout, "out"); + if (ret < 0) + return ret; + idx_mask = (1ULL << s->map[i].out_channel_idx); + if (presence_mask & idx_mask) { + char layout_name[256]; + av_channel_layout_describe(&s->output_layout, layout_name, sizeof(layout_name)); + av_log(ctx, AV_LOG_ERROR, "Mapping %d assigns channel #%d twice in output layout '%s'.\n", + i + 1, s->map[i].out_channel_idx, layout_name); + return AVERROR(EINVAL); + } + presence_mask |= idx_mask; + } + return 0; } -- 2.35.3 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".