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 BA13842DA2 for ; Thu, 13 Jan 2022 02:15:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 41A4868B2C6; Thu, 13 Jan 2022 03:56:53 +0200 (EET) 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-Google-Smtp-Source: ABdhPJwPAIquPxlMGjVjvR/RcBdRYMYXyGCgKEXBSoY03fYe7Gq5HgUlENonYGsO+kdpKvpeTSP8ug== 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 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: 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; -- 2.34.1 _______________________________________________ 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".