From patchwork Thu Jan 13 02:02:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33458 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp37392iog; Wed, 12 Jan 2022 18:33:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBpG259e+DlDkqN/aIKXM63fjIBVFNawiRz9t80g0lpAR/CsjwEI94nN6BScf/NLdxtT0y X-Received: by 2002:a17:906:314a:: with SMTP id e10mr1944065eje.672.1642041207539; Wed, 12 Jan 2022 18:33:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642041207; cv=none; d=google.com; s=arc-20160816; b=TA9mxOUN7lK+MRKA8UhMd+CwepNosGmeW5rsPwdE4e58e9faYfFKDqw0HnrWquvWdT DyWPgS7Of0jEQM2Z1SxGwCqPZmZmTV3+3qgCw7gLD5BJaXi6YK4Xnmi6D5rRSdDpEHWw VzPqF8zhCdB/9XuCre1TYWqRJep5+ZlUXbmEBakA2HKNEg6m4e7V8RomVRi/dQjuzdXh fiz2TKADyDUHeJeYBszbk3azbFY9yyRyR5DtBu5Q8cBB8JYt23aKC0qNZgL7dK91W5Ml 15dTkSai/0m6wb/fjR0SIST+JESMVLtuRgPkdnv69BWJHypVlfT94mGX+eXtlVvdbv/l Q3yg== 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=YYm3GGQ5sNdQ7nC3CJTgSJVx+1Y339RRNHRW5xM18K8=; b=VPgIR1tZhAz0Fkkfziu9ZLlq0ObAJksvDnpJOBjnmk0zNOJxtKAJ2QdLeZ94akJxic IIRjz/hNV+bxgqGrKWcjgNeMAQcNesfsqJbGRXEAtjwrkB2kSBk5zvOmpim2pcISNM1F CVBHXuA5DIs1hwRQgRgh2sZfVf2A0n1vCKMYy3i0w8rKYLszwQ5JWw4shDb2Um56jBsT eo4tMuqR+dtZU65Z81zsRad7357dQlhLYW9cAw7Y3mLYJMhesHUXEM78OdK33PXmy9EH 8CY0xDFtPj9sHAq5LQKaTPM6dtVpQIHD7OjrDKXAfbjHNvFMdq1qQflbnDO/zvaJJqFH kkZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=dRRqC0EL; 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 o10si957706edc.477.2022.01.12.18.33.27; Wed, 12 Jan 2022 18:33:27 -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=dRRqC0EL; 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 28BDD68B5E1; Thu, 13 Jan 2022 04:03:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D50868B5BB for ; Thu, 13 Jan 2022 04:03:07 +0200 (EET) Received: by mail-qv1-f50.google.com with SMTP id q4so5104591qvh.9 for ; Wed, 12 Jan 2022 18:03:07 -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=ZoBW0jkQp3QIhLMr9bmZ2zyCJcCByz8XzQhD2fAHpx0=; b=dRRqC0EL6bxTl5DPvVRa8wAq9DRXj2cfhQuK0YV6yBzSdDS16tbb1geUMuuYILaoYy fSrE8wQa0raRy/sPKWNbwFgCPXMbrlwiNSeoDgtGX2DmZeHFxOub8n13i0LoLp2alTfg XO4frqApeLflm55ErVMXk6uh20KhEZ18MVYfnYdtbUD6rWR4Gobdh1y3+f72hunv1gqC lxTKhhbpX3X83HnBb8YoB07Ud8Oh7aeZ3+FmtvGC671bMw3hkrBrHuQDVgcUci+wiZof 2l6i6WTvecMowQUOdYt0/Bagwm/v1W/z1kHSfwFiFBykzhX4cE2JdoTovbHSdKB9hJt9 hypg== 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=ZoBW0jkQp3QIhLMr9bmZ2zyCJcCByz8XzQhD2fAHpx0=; b=1KDwIp3YNrzeToYY8D4YcyCVqAmO2stWxThS9icj//SlchzUfXLdDq77u3ePHLBoZK FdfKBC39fBvQFjUskdwAflhCZ4VqeFrO9dMlG6k01hl/uyCn2yj/57l1zT9pEM1sLMfp IWdj9McCytwvRebaKazLeI25l8CaLNxjOmTfO6qWddXulsfvx9yGvkVw+njjbfhsXan7 TVq4cnKnVb+jR0NyowpqoN3iN0WjPOa97156c9xy2mD0BbOHPhch72pVNpv9u/aEMrya hioYziCdB4ajRDA1aVkJHc2lDWLXHWpxpQyVzFwyzdYFV7PM1UZSp4RNZVxThl37DvsK gByw== X-Gm-Message-State: AOAM530JH4q5t/WUy+ojY1X3zuWgjw1/GPGEgPifxjDxjw7wTWVJo5Mi Y77Hn1Y7Cu+xbV2SHmgrDA1uZdAwqQA= X-Received: by 2002:a05:6214:d85:: with SMTP id e5mr1596421qve.74.1642039385778; Wed, 12 Jan 2022 18:03:05 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id v1sm1045961qtc.95.2022.01.12.18.03.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:03:05 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:02:20 -0300 Message-Id: <20220113020242.661-8-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 187/281] als: 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: XDbEWwT5VG2a From: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/alsdec.c | 90 ++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index 9e1aaf065a..599c621366 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -319,7 +319,13 @@ static av_cold int read_specific_config(ALSDecContext *ctx) avctx->sample_rate = m4ac.sample_rate; skip_bits_long(&gb, 32); // sample rate already known sconf->samples = get_bits_long(&gb, 32); - avctx->channels = m4ac.channels; + + if (avctx->ch_layout.nb_channels != m4ac.channels) { + av_channel_layout_uninit(&avctx->ch_layout); + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = m4ac.channels; + } + skip_bits(&gb, 16); // number of channels already known skip_bits(&gb, 3); // skip file_type sconf->resolution = get_bits(&gb, 3); @@ -349,7 +355,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx) if (als_id != MKBETAG('A','L','S','\0')) return AVERROR_INVALIDDATA; - if (avctx->channels > FF_SANE_NB_CHANNELS) { + if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) { avpriv_request_sample(avctx, "Huge number of channels"); return AVERROR_PATCHWELCOME; } @@ -363,26 +369,26 @@ static av_cold int read_specific_config(ALSDecContext *ctx) // read channel sorting - if (sconf->chan_sort && avctx->channels > 1) { - int chan_pos_bits = av_ceil_log2(avctx->channels); - int bits_needed = avctx->channels * chan_pos_bits + 7; + if (sconf->chan_sort && avctx->ch_layout.nb_channels > 1) { + int chan_pos_bits = av_ceil_log2(avctx->ch_layout.nb_channels); + int bits_needed = avctx->ch_layout.nb_channels * chan_pos_bits + 7; if (get_bits_left(&gb) < bits_needed) return AVERROR_INVALIDDATA; - if (!(sconf->chan_pos = av_malloc_array(avctx->channels, sizeof(*sconf->chan_pos)))) + if (!(sconf->chan_pos = av_malloc_array(avctx->ch_layout.nb_channels, sizeof(*sconf->chan_pos)))) return AVERROR(ENOMEM); ctx->cs_switch = 1; - for (i = 0; i < avctx->channels; i++) { + for (i = 0; i < avctx->ch_layout.nb_channels; i++) { sconf->chan_pos[i] = -1; } - for (i = 0; i < avctx->channels; i++) { + for (i = 0; i < avctx->ch_layout.nb_channels; i++) { int idx; idx = get_bits(&gb, chan_pos_bits); - if (idx >= avctx->channels || sconf->chan_pos[idx] != -1) { + if (idx >= avctx->ch_layout.nb_channels || sconf->chan_pos[idx] != -1) { av_log(avctx, AV_LOG_WARNING, "Invalid channel reordering.\n"); ctx->cs_switch = 0; break; @@ -1228,7 +1234,7 @@ static int read_channel_data(ALSDecContext *ctx, ALSChannelData *cd, int c) { GetBitContext *gb = &ctx->gb; ALSChannelData *current = cd; - unsigned int channels = ctx->avctx->channels; + unsigned int channels = ctx->avctx->ch_layout.nb_channels; int entries = 0; while (entries < channels && !(current->stop_flag = get_bits1(gb))) { @@ -1277,7 +1283,7 @@ static int revert_channel_correlation(ALSDecContext *ctx, ALSBlockData *bd, { ALSChannelData *ch = cd[c]; unsigned int dep = 0; - unsigned int channels = ctx->avctx->channels; + unsigned int channels = ctx->avctx->ch_layout.nb_channels; unsigned int channel_size = ctx->sconf.frame_length + ctx->sconf.max_order; if (reverted[c]) @@ -1475,15 +1481,15 @@ static int read_diff_float_data(ALSDecContext *ctx, unsigned int ra_frame) { use_acf = get_bits1(gb); if (ra_frame) { - memset(last_acf_mantissa, 0, avctx->channels * sizeof(*last_acf_mantissa)); - memset(last_shift_value, 0, avctx->channels * sizeof(*last_shift_value) ); + memset(last_acf_mantissa, 0, avctx->ch_layout.nb_channels * sizeof(*last_acf_mantissa)); + memset(last_shift_value, 0, avctx->ch_layout.nb_channels * sizeof(*last_shift_value) ); ff_mlz_flush_dict(ctx->mlz); } - if (avctx->channels * 8 > get_bits_left(gb)) + if (avctx->ch_layout.nb_channels * 8 > get_bits_left(gb)) return AVERROR_INVALIDDATA; - for (c = 0; c < avctx->channels; ++c) { + for (c = 0; c < avctx->ch_layout.nb_channels; ++c) { if (use_acf) { //acf_flag if (get_bits1(gb)) { @@ -1634,6 +1640,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) unsigned int div_blocks[32]; ///< block sizes. int c; unsigned int js_blocks[2]; + int channels = avctx->ch_layout.nb_channels; uint32_t bs_info = 0; int ret; @@ -1649,7 +1656,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) if (!sconf->mc_coding || ctx->js_switch) { int independent_bs = !sconf->joint_stereo; - for (c = 0; c < avctx->channels; c++) { + for (c = 0; c < channels; c++) { js_blocks[0] = 0; js_blocks[1] = 0; @@ -1662,7 +1669,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) independent_bs = 2; // if this is the last channel, it has to be decoded independently - if (c == avctx->channels - 1 || (c & 1)) + if (c == channels - 1 || (c & 1)) independent_bs = 1; if (independent_bs) { @@ -1691,13 +1698,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) int *reverted_channels = ctx->reverted_channels; unsigned int offset = 0; - for (c = 0; c < avctx->channels; c++) + for (c = 0; c < channels; c++) if (ctx->chan_data[c] < ctx->chan_data_buffer) { av_log(ctx->avctx, AV_LOG_ERROR, "Invalid channel data.\n"); return AVERROR_INVALIDDATA; } - memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels); + memset(reverted_channels, 0, sizeof(*reverted_channels) * channels); bd.ra_block = ra_frame; bd.prev_raw_samples = ctx->prev_raw_samples; @@ -1713,7 +1720,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) continue; } - for (c = 0; c < avctx->channels; c++) { + for (c = 0; c < channels; c++) { bd.const_block = ctx->const_block + c; bd.shift_lsbs = ctx->shift_lsbs + c; bd.opt_order = ctx->opt_order + c; @@ -1732,13 +1739,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) return ret; } - for (c = 0; c < avctx->channels; c++) { + for (c = 0; c < channels; c++) { ret = revert_channel_correlation(ctx, &bd, ctx->chan_data, reverted_channels, offset, c); if (ret < 0) return ret; } - for (c = 0; c < avctx->channels; c++) { + for (c = 0; c < channels; c++) { bd.const_block = ctx->const_block + c; bd.shift_lsbs = ctx->shift_lsbs + c; bd.opt_order = ctx->opt_order + c; @@ -1756,13 +1763,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) ctx->highest_decoded_channel = FFMAX(ctx->highest_decoded_channel, c); } - memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels)); + memset(reverted_channels, 0, channels * sizeof(*reverted_channels)); offset += div_blocks[b]; bd.ra_block = 0; } // store carryover raw samples - for (c = 0; c < avctx->channels; c++) + for (c = 0; c < channels; c++) memmove(ctx->raw_samples[c] - sconf->max_order, ctx->raw_samples[c] - sconf->max_order + sconf->frame_length, sizeof(*ctx->raw_samples[c]) * sconf->max_order); @@ -1792,6 +1799,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, const uint8_t *buffer = avpkt->data; int buffer_size = avpkt->size; int invalid_frame, ret; + int channels = avctx->ch_layout.nb_channels; unsigned int c, sample, ra_frame, bytes_read, shift; if ((ret = init_get_bits8(&ctx->gb, buffer, buffer_size)) < 0) @@ -1833,7 +1841,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, #define INTERLEAVE_OUTPUT(bps) \ { \ int##bps##_t *dest = (int##bps##_t*)frame->data[0]; \ - int channels = avctx->channels; \ int32_t *raw_samples = ctx->raw_samples[0]; \ int raw_step = channels > 1 ? ctx->raw_samples[1] - raw_samples : 1; \ shift = bps - ctx->avctx->bits_per_raw_sample; \ @@ -1862,7 +1869,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, int32_t *src = (int32_t *)frame->data[0]; for (sample = 0; - sample < ctx->cur_frame_length * avctx->channels; + sample < ctx->cur_frame_length * channels; sample++) { int32_t v; @@ -1883,13 +1890,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, int16_t *src = (int16_t*) frame->data[0]; int16_t *dest = (int16_t*) ctx->crc_buffer; for (sample = 0; - sample < ctx->cur_frame_length * avctx->channels; + sample < ctx->cur_frame_length * channels; sample++) *dest++ = av_bswap16(src[sample]); } else { ctx->bdsp.bswap_buf((uint32_t *) ctx->crc_buffer, (uint32_t *) frame->data[0], - ctx->cur_frame_length * avctx->channels); + ctx->cur_frame_length * channels); } crc_source = ctx->crc_buffer; } else { @@ -1897,7 +1904,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, } ctx->crc = av_crc(ctx->crc_table, ctx->crc, crc_source, - ctx->cur_frame_length * avctx->channels * + ctx->cur_frame_length * channels * av_get_bytes_per_sample(avctx->sample_fmt)); } @@ -1960,7 +1967,7 @@ static av_cold int decode_end(AVCodecContext *avctx) av_freep(&ctx->shift_value); av_freep(&ctx->last_shift_value); if (ctx->raw_mantissa) { - for (i = 0; i < avctx->channels; i++) { + for (i = 0; i < avctx->ch_layout.nb_channels; i++) { av_freep(&ctx->raw_mantissa[i]); } av_freep(&ctx->raw_mantissa); @@ -1979,6 +1986,7 @@ static av_cold int decode_init(AVCodecContext *avctx) unsigned int c; unsigned int channel_size; int num_buffers, ret; + int channels = avctx->ch_layout.nb_channels; ALSDecContext *ctx = avctx->priv_data; ALSSpecificConfig *sconf = &ctx->sconf; ctx->avctx = avctx; @@ -2027,7 +2035,7 @@ static av_cold int decode_init(AVCodecContext *avctx) (avctx->sample_rate >= 192000); // allocate quantized parcor coefficient buffer - num_buffers = sconf->mc_coding ? avctx->channels : 1; + num_buffers = sconf->mc_coding ? channels : 1; if (num_buffers * (uint64_t)num_buffers > INT_MAX) // protect chan_data_buffer allocation return AVERROR_INVALIDDATA; @@ -2101,15 +2109,15 @@ static av_cold int decode_init(AVCodecContext *avctx) channel_size = sconf->frame_length + sconf->max_order; ctx->prev_raw_samples = av_malloc_array(sconf->max_order, sizeof(*ctx->prev_raw_samples)); - ctx->raw_buffer = av_calloc(avctx->channels * channel_size, sizeof(*ctx->raw_buffer)); - ctx->raw_samples = av_malloc_array(avctx->channels, sizeof(*ctx->raw_samples)); + ctx->raw_buffer = av_calloc(channels * channel_size, sizeof(*ctx->raw_buffer)); + ctx->raw_samples = av_malloc_array(channels, sizeof(*ctx->raw_samples)); if (sconf->floating) { - ctx->acf = av_malloc_array(avctx->channels, sizeof(*ctx->acf)); - ctx->shift_value = av_malloc_array(avctx->channels, sizeof(*ctx->shift_value)); - ctx->last_shift_value = av_malloc_array(avctx->channels, sizeof(*ctx->last_shift_value)); - ctx->last_acf_mantissa = av_malloc_array(avctx->channels, sizeof(*ctx->last_acf_mantissa)); - ctx->raw_mantissa = av_calloc(avctx->channels, sizeof(*ctx->raw_mantissa)); + ctx->acf = av_malloc_array(channels, sizeof(*ctx->acf)); + ctx->shift_value = av_malloc_array(channels, sizeof(*ctx->shift_value)); + ctx->last_shift_value = av_malloc_array(channels, sizeof(*ctx->last_shift_value)); + ctx->last_acf_mantissa = av_malloc_array(channels, sizeof(*ctx->last_acf_mantissa)); + ctx->raw_mantissa = av_calloc(channels, sizeof(*ctx->raw_mantissa)); ctx->larray = av_malloc_array(ctx->cur_frame_length * 4, sizeof(*ctx->larray)); ctx->nbits = av_malloc_array(ctx->cur_frame_length, sizeof(*ctx->nbits)); @@ -2125,7 +2133,7 @@ static av_cold int decode_init(AVCodecContext *avctx) ff_mlz_init_dict(avctx, ctx->mlz); ff_mlz_flush_dict(ctx->mlz); - for (c = 0; c < avctx->channels; ++c) { + for (c = 0; c < channels; ++c) { ctx->raw_mantissa[c] = av_calloc(ctx->cur_frame_length, sizeof(**ctx->raw_mantissa)); } } @@ -2139,14 +2147,14 @@ static av_cold int decode_init(AVCodecContext *avctx) // assign raw samples buffers ctx->raw_samples[0] = ctx->raw_buffer + sconf->max_order; - for (c = 1; c < avctx->channels; c++) + for (c = 1; c < channels; c++) ctx->raw_samples[c] = ctx->raw_samples[c - 1] + channel_size; // allocate crc buffer if (HAVE_BIGENDIAN != sconf->msb_first && sconf->crc_enabled && (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL))) { ctx->crc_buffer = av_malloc_array(ctx->cur_frame_length * - avctx->channels * + channels * av_get_bytes_per_sample(avctx->sample_fmt), sizeof(*ctx->crc_buffer)); if (!ctx->crc_buffer) {