From patchwork Thu Jan 13 01:56:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33388 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp27278iog; Wed, 12 Jan 2022 18:15:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwjHNFeZzkItq1faUgQPO9+6QNVD+Y/1UPpjMYuWLnk8Z9f6Im9iuvBmmYZWTLE+V/TeLw X-Received: by 2002:a17:907:86ac:: with SMTP id qa44mr1869353ejc.728.1642040137693; Wed, 12 Jan 2022 18:15:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642040137; cv=none; d=google.com; s=arc-20160816; b=bCubFDyq07sE/Xw894IsCuw0OuqaT0Z1p7GF94MmbVaA14M95exConJ4U440UPsVWs Te2NY7uVFA0C+T6FfrNpFLd5lZtzuyOfrqebLewed5k8a/j0/veI57UDriTGHwsrfja7 sAIjYNTHJfhfmn90K13o2v3hjNd+pACrgllBnaECdDd0JzWC/fyiv3bWDGepa6b782Mx +PZ6EfFSpgKiVGTmHN1GUvA2zsZsQxM8ByExZSs4BiYGL6am0YcZpgTdAReiiFC3uWx0 252ipuiBlJ/rOLHvlnY+zkW4YgAxH9EOWrELfT9J7dpHHwVF05ogj39m+eU/0fsL3WXt fdUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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:dkim-signature:delivered-to; bh=C+dHRSZW+5SyLTkuQn1qwXnDHz5HmClta91s0Y6rAaU=; b=HKBEuYuVbGaqlCREE5cUUWajyjVHzuexdZyZzFiQr1CTtnfl+wwIKfA8yNyKoEuumf oaJI1JJ5MhRdcBmoUprV9hWsCwoLlSa+eMy6CGe74zbYO5BgOxmTTUSKgCzaUH91DrvB XWmNfgiobapWGvIkng1310AXrB5Ka5IWjNZBD9ivthcb/AJMRrvAncGJTDtQaCFwRQwW Y/Qel6wFcGWNk9GxhUi4PI6QrCOg7IsOhzeoCzx400XrfKIq2dSvyhHO4akc6dohInVk Y9tEjkM8ReTaAp5MT7+kf+horedhCRZGcxuxanRmubMwLsRL+yfnTHqwNay0/9mF+nIz qFaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=CxjnuZxs; 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 sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i30si862329eda.468.2022.01.12.18.15.37; Wed, 12 Jan 2022 18:15:37 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=CxjnuZxs; 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 sp=QUARANTINE 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 705D868B2C8; Thu, 13 Jan 2022 03:56:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3549568B2AF for ; Thu, 13 Jan 2022 03:56:51 +0200 (EET) Received: by mail-qt1-f182.google.com with SMTP id l17so5331803qtk.7 for ; Wed, 12 Jan 2022 17:56:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=rzm/JMlfaaLZh8GHaRxJpt5fyl3Uw2rf6EbbnBJT90U=; b=CxjnuZxs6pUZO3TqF5QmjmssUirVzHJGX+aE49YCadnBfzNku1qXR35aa8ZVfmXrqn PIYzPdbk2IfXIt+cEnpN0VbjegAP3GVJc9GA6scoBjXXDJ/4V+WOy/oFaqHXI04seEVe ZOTAOcJAxdr98ESUI8db9nBo/gkyRu8+/CrXiHW8/i4oJ1ehCrm+vxUUXbo6hAE5y5xM dvxVgM81NmnAe2XVW2UjmysH1o9EtPJJAxsNUFqsIoYVY3JAAKBrOPnC2Ic1cupeM6Sj x85ubnSodW9/rZWrqZQGkf+Jzk7R5w7x/GnSVZQzFp7Zgj7RKez+nLGWzyv4OeEkzMf6 oDnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rzm/JMlfaaLZh8GHaRxJpt5fyl3Uw2rf6EbbnBJT90U=; b=Nk6uBQXsBDWl6gHLYB4c0ViXx2YE8Zx+z6q55UdfHdKhQQn1aONKw7eIIRtO/nOLor +GnQQhG4D4ISoRo4wjNxMFILaoFjKZi7slXPcxa/rEEAp7xV0aO3uYOD0EsjfENwBrVc 5eRSWINfAeXa1P97SoRDZDiVZ1umdTdQhtpE6+RLg4LVOyQiWS/w0b9+87eWzRFVytz1 IEDEk8aAAP+AhzK2GcbJVfYPydh5375Ni5sPxrUgQRL2P1btVeGtIFSKb1TFvjJZx72k BHDCU/Mt1O+GeznVL4nQbXk5aPKvhKDxnKOLV0DS/9SLSngLdrmj4KlRYSH4Cjfo0uGt h1dw== X-Gm-Message-State: AOAM531bEct7G77bOfOWGA4uMTNcDMG9xNSB+6r2cL2QA4XFt6aUVOzK I1QOYli2UVbi3MJOD4szc3B3TryErpI= X-Received: by 2002:a05:622a:4c7:: with SMTP id q7mr2037936qtx.226.1642039009423; Wed, 12 Jan 2022 17:56:49 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id t11sm906506qkm.77.2022.01.12.17.56.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 17:56:49 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 22:56:02 -0300 Message-Id: <20220113015612.448-21-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113015101.4-1-jamrial@gmail.com> References: <20220113015101.4-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 109/281] mxf: convert to new channel layout API 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: poRxDVdonCQx From: Vittorio Giovara Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavformat/mxfdec.c | 34 +++++++++++++++++++++------------- libavformat/mxfenc.c | 20 +++++++++++--------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index b85c10bf19..2db32255ab 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -591,18 +591,19 @@ static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket *pkt, end_ptr = pkt->data + length; buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */ - if (st->codecpar->channels > 8) + if (st->codecpar->ch_layout.nb_channels > 8) return AVERROR_INVALIDDATA; - for (; end_ptr - buf_ptr >= st->codecpar->channels * 4; ) { - for (i = 0; i < st->codecpar->channels; i++) { + for (; end_ptr - buf_ptr >= st->codecpar->ch_layout.nb_channels * 4; ) { + for (i = 0; i < st->codecpar->ch_layout.nb_channels; i++) { uint32_t sample = bytestream_get_le32(&buf_ptr); if (st->codecpar->bits_per_coded_sample == 24) bytestream_put_le24(&data_ptr, (sample >> 4) & 0xffffff); else bytestream_put_le16(&data_ptr, (sample >> 12) & 0xffff); } - buf_ptr += 32 - st->codecpar->channels*4; // always 8 channels stored SMPTE 331M + // always 8 channels stored SMPTE 331M + buf_ptr += 32 - st->codecpar->ch_layout.nb_channels * 4; } av_shrink_packet(pkt, data_ptr - pkt->data); return 0; @@ -2536,6 +2537,7 @@ static int parse_mca_labels(MXFContext *mxf, MXFTrack *source_track, MXFDescript if (has_channel_label) { uint64_t channel_layout = 0; + int ret; for (int i = 0; i < descriptor->channels; i++) { if (!routing[i]) { @@ -2544,9 +2546,11 @@ static int parse_mca_labels(MXFContext *mxf, MXFTrack *source_track, MXFDescript return 0; } if (channel_layout & routing[i]) { + char buf[32]; + av_channel_name(buf, sizeof(buf), routing[i]); av_log(mxf->fc, AV_LOG_WARNING, "%s audio channel is used multiple times in stream #%d, " "falling back to unknown channel layout\n", - av_get_channel_name(routing[i]), st->index); + buf, st->index); return 0; } if (routing[i] < channel_layout) { @@ -2557,9 +2561,11 @@ static int parse_mca_labels(MXFContext *mxf, MXFTrack *source_track, MXFDescript channel_layout |= routing[i]; } - av_assert0(descriptor->channels == av_get_channel_layout_nb_channels(channel_layout)); + av_assert0(descriptor->channels == av_popcount64(channel_layout)); - st->codecpar->channel_layout = channel_layout; + ret = av_channel_layout_from_mask(&st->codecpar->ch_layout, channel_layout); + if (ret < 0) + return ret; } return 0; @@ -2927,7 +2933,8 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) /* Only overwrite existing codec ID if it is unset or A-law, which is the default according to SMPTE RP 224. */ if (st->codecpar->codec_id == AV_CODEC_ID_NONE || (st->codecpar->codec_id == AV_CODEC_ID_PCM_ALAW && (enum AVCodecID)container_ul->id != AV_CODEC_ID_NONE)) st->codecpar->codec_id = (enum AVCodecID)container_ul->id; - st->codecpar->channels = descriptor->channels; + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = descriptor->channels; if (descriptor->sample_rate.den > 0) { st->codecpar->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den; @@ -3553,7 +3560,8 @@ static int mxf_handle_missing_index_segment(MXFContext *mxf, AVStream *st) return 0; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && is_pcm(st->codecpar->codec_id)) { - edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3; + edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * + st->codecpar->ch_layout.nb_channels) >> 3; } else if (st->duration > 0 && p->first_essence_klv.length > 0 && p->first_essence_klv.length % st->duration == 0) { edit_unit_byte_count = p->first_essence_klv.length / st->duration; } @@ -3858,12 +3866,12 @@ static int mxf_set_audio_pts(MXFContext *mxf, AVCodecParameters *par, pkt->pts = track->sample_count; - if ( par->channels <= 0 - || bits_per_sample <= 0 - || par->channels * (int64_t)bits_per_sample < 8) + if (par->ch_layout.nb_channels <= 0 || + bits_per_sample <= 0 || + par->ch_layout.nb_channels * (int64_t)bits_per_sample < 8) track->sample_count = mxf_compute_sample_count(mxf, st, av_rescale_q(track->sample_count, st->time_base, av_inv_q(track->edit_rate)) + 1); else - track->sample_count += pkt->size / (par->channels * (int64_t)bits_per_sample / 8); + track->sample_count += pkt->size / (par->ch_layout.nb_channels * (int64_t)bits_per_sample / 8); return 0; } diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 5e068c8220..5fa234c5c0 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -1455,17 +1455,19 @@ static int64_t mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, mxf_write_local_tag(s, 4, 0x3D07); if (mxf->channel_count == -1) { - if (show_warnings && (s->oformat == &ff_mxf_d10_muxer) && (st->codecpar->channels != 4) && (st->codecpar->channels != 8)) + if (show_warnings && (s->oformat == &ff_mxf_d10_muxer) && + (st->codecpar->ch_layout.nb_channels != 4) && + (st->codecpar->ch_layout.nb_channels != 8)) av_log(s, AV_LOG_WARNING, "the number of audio channels shall be 4 or 8 : the output will not comply to MXF D-10 specs, use -d10_channelcount to fix this\n"); - avio_wb32(pb, st->codecpar->channels); + avio_wb32(pb, st->codecpar->ch_layout.nb_channels); } else if (s->oformat == &ff_mxf_d10_muxer) { - if (show_warnings && (mxf->channel_count < st->codecpar->channels)) + if (show_warnings && (mxf->channel_count < st->codecpar->ch_layout.nb_channels)) av_log(s, AV_LOG_WARNING, "d10_channelcount < actual number of audio channels : some channels will be discarded\n"); if (show_warnings && (mxf->channel_count != 4) && (mxf->channel_count != 8)) av_log(s, AV_LOG_WARNING, "d10_channelcount shall be set to 4 or 8 : the output will not comply to MXF D-10 specs\n"); avio_wb32(pb, mxf->channel_count); } else { - avio_wb32(pb, st->codecpar->channels); + avio_wb32(pb, st->codecpar->ch_layout.nb_channels); } mxf_write_local_tag(s, 4, 0x3D01); @@ -2624,7 +2626,7 @@ static int mxf_init(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "Only pcm_s16le and pcm_s24le audio codecs are implemented\n"); return AVERROR_PATCHWELCOME; } - if (st->codecpar->channels != 1) { + if (st->codecpar->ch_layout.nb_channels != 1) { av_log(s, AV_LOG_ERROR, "MXF OPAtom only supports single channel audio\n"); return AVERROR(EINVAL); } @@ -2633,11 +2635,11 @@ static int mxf_init(AVFormatContext *s) if((ret = mxf_init_timecode(s, st, tbc)) < 0) return ret; - mxf->edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3; + mxf->edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->ch_layout.nb_channels) >> 3; sc->index = INDEX_WAV; } else { mxf->slice_count = 1; - sc->frame_size = st->codecpar->channels * + sc->frame_size = st->codecpar->ch_layout.nb_channels * av_rescale_rnd(st->codecpar->sample_rate, mxf->time_base.num, mxf->time_base.den, AV_ROUND_UP) * av_get_bits_per_sample(st->codecpar->codec_id) / 8; } @@ -2783,10 +2785,10 @@ static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacke avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1)); avio_wl16(pb, frame_size); - avio_w8(pb, (1<codecpar->channels)-1); + avio_w8(pb, (1 << st->codecpar->ch_layout.nb_channels)-1); while (samples < end) { - for (i = 0; i < st->codecpar->channels; i++) { + for (i = 0; i < st->codecpar->ch_layout.nb_channels; i++) { uint32_t sample; if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE) { sample = AV_RL24(samples)<< 4;