From patchwork Thu Jan 13 02:06:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33518 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp44893iog; Wed, 12 Jan 2022 18:48:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVIlO0LUmP2lc+mpsThpqJ+9oA9BkeVLMW8+y6FZFg6nUUPSsV4Ne5fk1Up5Gbj+DiIqzB X-Received: by 2002:a05:6402:270c:: with SMTP id y12mr2351642edd.269.1642042084177; Wed, 12 Jan 2022 18:48:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642042084; cv=none; d=google.com; s=arc-20160816; b=FC4HDvFpanMMRTA8q2L6a1GWB8s5daWU/Xv4UHyKn/y4QXkyWCfUa8YjiEvBziyxYL HtRSP+yRl8sufznhHdCHLcSVnO7Al/agx6zGSNdIq2XUK17DC78fO0+jkyimuUYfrJ8I xsltp35DwJz66cxUxnqjr/nCrwqsq8vPtEdb5Yqv1Mn68sbPQdQguIGOBbWYu/MERdcY yBenjggl7oaytbvm0Dbj3+8Q41NVn+6+T2asw5hMsRW++A1a3matJfazZwEE0V2tbY0T zJ83JyRSL6uWujPMqGbhk7whqzr0s+h23R1LJ+nFai5oycYSSbe9abhWsTpi2bKH1Q1W 8F1w== 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=YvwCBpIDr3QQjLFZphxnqo8G+IYZ5PYY8BpN6+vjaJQ=; b=KiG/uuJBFc5zjSwfy+PJCwNRZEDR50KrUmX4IwIWFmqsaTed8yndrYtCOopzlrs5iN V6BQZe1f/k15AnZVoiHaxRBEtvtoQD0l5Gxb44UUa6v/HzVM4Zun1KnLsGpyJ/vZ1mc7 kWHmQAvmMyy5tLBq9V6NbY863JwjPAnreRdShJYzQ5MWM+fI9CNwI6jFUTg8mh+QU0rr xCT34E7gMwvEozqCdMAZ1r7G1+Oqg5hSOYHQgyFjwvT7c5l+3r3sgokzcCG39RhPXYk5 nEkA++CYqSOvwLRWCLgQNnkDZxWRQDg7zDBs4QCnAdkVJbew2769e03jBhALG9ogRgpp Tasw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=AF19K5gu; 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 s17si824114ejz.77.2022.01.12.18.48.03; Wed, 12 Jan 2022 18:48:04 -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=AF19K5gu; 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 3BCC368B9DC; Thu, 13 Jan 2022 04:07:49 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 54D1F68B9CB for ; Thu, 13 Jan 2022 04:07:47 +0200 (EET) Received: by mail-qt1-f176.google.com with SMTP id y17so5346419qtx.9 for ; Wed, 12 Jan 2022 18:07:47 -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=o6bfg8dJvODVp/6U+ZyXJ5uVpu3rgW5Hn48p4NvfcHc=; b=AF19K5guq60wqMLwMyhi9rnce8Nf+xCupq8AeUiXs4CC4wGVwF6s6pNRdGO43K6aE+ hONMQGe6z4PO5FQZk2ecgPoJUKmNhN6gnU2e27N53TU389e5PK5xpyV7Nm5LmujKHj7l MDko4VrvTSML8Mg4w8lQzp+/Gf0LvSlU4zJeLG3NfP8uP7gb3mphdTHT43sYbLa/QM8u ZQvxXP2C9tqICNs+TEEcdnBijT/TKYse6Nlx1pSP7BIKU6C336v1Ld1p4i5LflWSvRJo YST7dHw+zeUUdChxkl76jap7y02w+HXri2dFvYvdFqaTXuyvXipNmILfLdnYwbdmgcry 4sxw== 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=o6bfg8dJvODVp/6U+ZyXJ5uVpu3rgW5Hn48p4NvfcHc=; b=sT1W/IyZWW7k197u1ENI2ldRGuU5jTwQNakbRLOspyNuHjGihEQ4tU/MjBGsf4ivXS hb21DotA0PahjJ38Uyp+11holLv6UstEjXmkpcUkZ5J8Dk9Adgm2M4OGjAciqpbF61Nn evriyFe/XkNus2SCm2U9Q33K/VJ/FFSIgUpnBheU+ami/pGNcpbFko++yBOR/1iwkTKS KpTkbIYmaJrrYywilSWB9k/vtagFc181M0Wy7OYsIxgsVwi1vXPS0GsM4Bq+BrNNBQxW nDowJ5NRP+bOQGia5GIyVrVOkIzKuJmDx5Nk5S/PgPfsedNijF9Bf7c1M+tPz6QpRXMa TOgg== X-Gm-Message-State: AOAM531bf50wW/p5bjMRz2bR85bDRKA0YgQ/1iM8GhVgXnR+Nt2FnV2X BbLrExN/q+dyuYrywn4RwWAqC/qkLnc= X-Received: by 2002:ac8:7f4f:: with SMTP id g15mr1975479qtk.309.1642039665857; Wed, 12 Jan 2022 18:07:45 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id a16sm1085946qta.13.2022.01.12.18.07.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:07:45 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:06:58 -0300 Message-Id: <20220113020713.801-15-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 254/281] s302m: 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: LYoLrEMZ8u1A From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/s302m.c | 31 +++++++++++++++++++------------ libavcodec/s302menc.c | 18 +++++++++--------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c index b09c1293a0..868f2f99af 100644 --- a/libavcodec/s302m.c +++ b/libavcodec/s302m.c @@ -72,19 +72,25 @@ static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf, else avctx->sample_fmt = AV_SAMPLE_FMT_S16; - avctx->channels = channels; + av_channel_layout_uninit(&avctx->ch_layout); switch(channels) { case 2: - avctx->channel_layout = AV_CH_LAYOUT_STEREO; + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; break; case 4: - avctx->channel_layout = AV_CH_LAYOUT_QUAD; + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD; break; case 6: - avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK; + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK; break; case 8: - avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK | AV_CH_LAYOUT_STEREO_DOWNMIX; + av_channel_layout_from_mask(&avctx->ch_layout, + AV_CH_LAYOUT_5POINT1_BACK | AV_CH_LAYOUT_STEREO_DOWNMIX); + break; + default: + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = channels; + break; } return frame_size; @@ -97,7 +103,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data, AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; - int block_size, ret; + int block_size, ret, channels; int i; int non_pcm_data_type = -1; @@ -110,13 +116,14 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data, /* get output buffer */ block_size = (avctx->bits_per_raw_sample + 4) / 4; - frame->nb_samples = 2 * (buf_size / block_size) / avctx->channels; + channels = avctx->ch_layout.nb_channels; + frame->nb_samples = 2 * (buf_size / block_size) / channels; if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; - avctx->bit_rate = 48000 * avctx->channels * (avctx->bits_per_raw_sample + 4) + + avctx->bit_rate = 48000 * channels * (avctx->bits_per_raw_sample + 4) + 32 * 48000 / frame->nb_samples; - buf_size = (frame->nb_samples * avctx->channels / 2) * block_size; + buf_size = (frame->nb_samples * channels / 2) * block_size; if (avctx->bits_per_raw_sample == 24) { uint32_t *o = (uint32_t *)frame->data[0]; @@ -131,7 +138,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data, buf += 7; } o = (uint32_t *)frame->data[0]; - if (avctx->channels == 2) + if (channels == 2) for (i=0; inb_samples * 2 - 6; i+=2) { if (o[i] || o[i+1] || o[i+2] || o[i+3]) break; @@ -152,7 +159,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data, buf += 6; } o = (uint32_t *)frame->data[0]; - if (avctx->channels == 2) + if (channels == 2) for (i=0; inb_samples * 2 - 6; i+=2) { if (o[i] || o[i+1] || o[i+2] || o[i+3]) break; @@ -172,7 +179,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data, buf += 5; } o = (uint16_t *)frame->data[0]; - if (avctx->channels == 2) + if (channels == 2) for (i=0; inb_samples * 2 - 6; i+=2) { if (o[i] || o[i+1] || o[i+2] || o[i+3]) break; diff --git a/libavcodec/s302menc.c b/libavcodec/s302menc.c index 528d712e79..56db25c76b 100644 --- a/libavcodec/s302menc.c +++ b/libavcodec/s302menc.c @@ -37,10 +37,10 @@ static av_cold int s302m_encode_init(AVCodecContext *avctx) { S302MEncContext *s = avctx->priv_data; - if (avctx->channels & 1 || avctx->channels > 8) { + if (avctx->ch_layout.nb_channels & 1 || avctx->ch_layout.nb_channels > 8) { av_log(avctx, AV_LOG_ERROR, "Encoding %d channel(s) is not allowed. Only 2, 4, 6 and 8 channels are supported.\n", - avctx->channels); + avctx->ch_layout.nb_channels); return AVERROR(EINVAL); } @@ -61,7 +61,7 @@ static av_cold int s302m_encode_init(AVCodecContext *avctx) } avctx->frame_size = 0; - avctx->bit_rate = 48000 * avctx->channels * + avctx->bit_rate = 48000 * avctx->ch_layout.nb_channels * (avctx->bits_per_raw_sample + 4); s->framing_index = 0; @@ -72,9 +72,9 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { S302MEncContext *s = avctx->priv_data; + const int nb_channels = avctx->ch_layout.nb_channels; const int buf_size = AES3_HEADER_LEN + - (frame->nb_samples * - avctx->channels * + (frame->nb_samples * nb_channels * (avctx->bits_per_raw_sample + 4)) / 8; int ret, c, channels; uint8_t *o; @@ -91,7 +91,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, o = avpkt->data; init_put_bits(&pb, o, buf_size); put_bits(&pb, 16, buf_size - AES3_HEADER_LEN); - put_bits(&pb, 2, (avctx->channels - 2) >> 1); // number of channels + put_bits(&pb, 2, (nb_channels - 2) >> 1); // number of channels put_bits(&pb, 8, 0); // channel ID put_bits(&pb, 2, (avctx->bits_per_raw_sample - 16) / 4); // bits per samples (0 = 16bit, 1 = 20bit, 2 = 24bit) put_bits(&pb, 4, 0); // alignments @@ -104,7 +104,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, for (c = 0; c < frame->nb_samples; c++) { uint8_t vucf = s->framing_index == 0 ? 0x10: 0; - for (channels = 0; channels < avctx->channels; channels += 2) { + for (channels = 0; channels < nb_channels; channels += 2) { o[0] = ff_reverse[(samples[0] & 0x0000FF00) >> 8]; o[1] = ff_reverse[(samples[0] & 0x00FF0000) >> 16]; o[2] = ff_reverse[(samples[0] & 0xFF000000) >> 24]; @@ -126,7 +126,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, for (c = 0; c < frame->nb_samples; c++) { uint8_t vucf = s->framing_index == 0 ? 0x80: 0; - for (channels = 0; channels < avctx->channels; channels += 2) { + for (channels = 0; channels < nb_channels; channels += 2) { o[0] = ff_reverse[ (samples[0] & 0x000FF000) >> 12]; o[1] = ff_reverse[ (samples[0] & 0x0FF00000) >> 20]; o[2] = ff_reverse[((samples[0] & 0xF0000000) >> 28) | vucf]; @@ -147,7 +147,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, for (c = 0; c < frame->nb_samples; c++) { uint8_t vucf = s->framing_index == 0 ? 0x10 : 0; - for (channels = 0; channels < avctx->channels; channels += 2) { + for (channels = 0; channels < nb_channels; channels += 2) { o[0] = ff_reverse[ samples[0] & 0xFF]; o[1] = ff_reverse[(samples[0] & 0xFF00) >> 8]; o[2] = ff_reverse[(samples[1] & 0x0F) << 4] | vucf;