From patchwork Thu Jan 13 02:09: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: 33530 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp46603iog; Wed, 12 Jan 2022 18:51:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJymVL/G9SbmBNr9pDlmjP14MJ60QD0xpP3TzWhuSJC7zag5bBAuSgGqqrAhTWvDEk7cUMIb X-Received: by 2002:a17:906:a42:: with SMTP id x2mr2131437ejf.125.1642042297043; Wed, 12 Jan 2022 18:51:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642042297; cv=none; d=google.com; s=arc-20160816; b=dWNmlFaPB6FksF/iLQmG3QhxzhUugdf/ppzK1Rbyu5wbJqp36x4NYfcJEn5uaQXGD+ TSg4X+QPT1d77bqEAIJiC0N2uxMcoqKvl01Uwt2IuJ7rRQIGrdtee4mCzvhhuJudMP1V 7wN08kGTX3AEJcH3VQHB7siHgJQhy/9amCuqXwfPuqvMNRTGCI2Iq8GGFeeIFfmoYbB2 GareKWXyFDvEzb8zNKhmRL7Iqtqn6ZWceGHKHUT7Yutio50Y+B1L9SJlovLrqldOpqBg 6Y0LeJNe55WEItovX47vfrTuVNUJ+aze3+og1F8O8Grj6mQShaKo/SfA455KuFclBWpA LF4w== 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=+VZerDVAuTarL/Sh2aZeTl8btgJFu52174Lm846A4Uw=; b=iz/k/USswbdBDI3Ispwlovqpt0qkdMpiy+0bVLm9zbkaoTVE8tRieAw4PJeXkTDnVu WEwX36p74jgX5zFUxpo+33BqrYGJWHrK596o+A5jTVeFJz1yHASoP5V7r1f3dzUZuCor zneLns1PIAZrW/xln+9b/jGibQsnwiSDsIO3negVarZcd/oufIcCLdCV4CSsS9APHKjJ DOn8s1C+3zNEF/x/GGTirugWqGjlrIFnFvwMUxvI2l/MzRIk3pgPyLNeknJJa4nMnu29 7Hvy8l6mnRkI4AwmC3DIoWhxeJGmON0z9y6x1mgHrBPXC1+lyMf4Z2iVlHkIO6HXP25j 3Eew== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="G8AIV/gs"; 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 nb41si810638ejc.104.2022.01.12.18.51.36; Wed, 12 Jan 2022 18:51: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="G8AIV/gs"; 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 F0A0A68BA76; Thu, 13 Jan 2022 04:09:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3814768BA6F for ; Thu, 13 Jan 2022 04:09:29 +0200 (EET) Received: by mail-qk1-f170.google.com with SMTP id h16so5630786qkp.3 for ; Wed, 12 Jan 2022 18:09:29 -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=VEcJ26BE1glOHtSHxpMe+e3FOEIRGkS3hLhdAHeBqMk=; b=G8AIV/gs7dc/LhwlZzr/N2YjBTHphjDVxACEWDdVSpbA4pFyOPoEJOlJrQ40FxGqaU w3gpINcdbH4K0VI9/mxVYYfrgxkBeQOQF7b8p5bz3pNdyBeJQmKfjWD4oLx4Y8IE2IbL ubSD9kYkMeU5Fka3OR4DHTlnq6pK5oPyq4ETldSCIxPr8b97AyG8IoU9DlLzKCBTntok DBwnS49EXe+y1J7iRn9db67dFQvdmsLgQGkDzQymCRNAKhEVBTuWTGzwAauhLWqjPYwn k11MoXc12cUb3Qd844yrG9aACDHY0BxaXhxAZAmlGXqmMeU5239uCEj4nITjbH4sIPAZ rQ2A== 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=VEcJ26BE1glOHtSHxpMe+e3FOEIRGkS3hLhdAHeBqMk=; b=r5pfJZOx77ZG+nwAq4kpVvjJCE2bS5hDuYFl0V4Tu9HCsAcd/T83UIroQX5/hGhExN vBkjxzRtkPiJFw7RAeOXvAp+oBUYbXKEAEM1NtkV5SoUMwEmibK62wF8PIIGCHHPwegs yc6lCBO0E87q9O4C97BbAOYeoAfNN5T7yjSVKjr7p4At3UsVph/ot/GBrzl8qXlOYIle +NUoASR7/nIGeFzSSXXbV6hR3t7rjV0qIez/ma0KhzHwLLym0LT8ZrA8j6bRdwASJCsu bOweRtAuB3Kymf7pY2fhr9EESRn7GzZ7Zotdyl5sVkubCPlr7aQJAyiOs2yR/D+HENLw rFtw== X-Gm-Message-State: AOAM531ZMxGvDYOA/YQMhgZkiQJu8kmK/Aj447rN4qJF+beL+49n4ueu s5KsnvV5Bpiq1FVv8mIx36eSAbuGjdk= X-Received: by 2002:a37:9ec9:: with SMTP id h192mr1872327qke.737.1642039767559; Wed, 12 Jan 2022 18:09:27 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id u6sm1068031qko.83.2022.01.12.18.09.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:09:27 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:09:02 -0300 Message-Id: <20220113020913.870-1-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 270/281] wma: 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: LWhnPnSY/tTm From: Anton Khirnov Signed-off-by: James Almer --- libavcodec/wma.c | 11 ++++++----- libavcodec/wmadec.c | 29 +++++++++++++++-------------- libavcodec/wmaenc.c | 27 ++++++++++++++------------- libavcodec/wmalosslessdec.c | 13 +++++++------ libavcodec/wmaprodec.c | 30 ++++++++++++++++++++---------- libavcodec/wmavoice.c | 4 ++-- 6 files changed, 64 insertions(+), 50 deletions(-) diff --git a/libavcodec/wma.c b/libavcodec/wma.c index d9fda2dbfa..4cd60cc35e 100644 --- a/libavcodec/wma.c +++ b/libavcodec/wma.c @@ -79,6 +79,7 @@ static av_cold int init_coef_vlc(VLC *vlc, uint16_t **prun_table, av_cold int ff_wma_init(AVCodecContext *avctx, int flags2) { WMACodecContext *s = avctx->priv_data; + int channels = avctx->ch_layout.nb_channels; int i, ret; float bps1, high_freq; float bps; @@ -86,7 +87,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2) int coef_vlc_table; if (avctx->sample_rate <= 0 || avctx->sample_rate > 50000 || - avctx->channels <= 0 || avctx->channels > 2 || + channels <= 0 || channels > 2 || avctx->bit_rate <= 0) return -1; @@ -107,7 +108,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2) if (s->use_variable_block_len) { int nb_max, nb; nb = ((flags2 >> 3) & 3) + 1; - if ((avctx->bit_rate / avctx->channels) >= 32000) + if ((avctx->bit_rate / channels) >= 32000) nb += 2; nb_max = s->frame_len_bits - BLOCK_MIN_BITS; if (nb > nb_max) @@ -136,7 +137,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2) } bps = (float) avctx->bit_rate / - (float) (avctx->channels * avctx->sample_rate); + (float) (channels * avctx->sample_rate); s->byte_offset_bits = av_log2((int) (bps * s->frame_len / 8.0 + 0.5)) + 2; if (s->byte_offset_bits + 3 > MIN_CACHE_BITS) { av_log(avctx, AV_LOG_ERROR, "byte_offset_bits %d is too large\n", s->byte_offset_bits); @@ -146,7 +147,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2) /* compute high frequency value and choose if noise coding should * be activated */ bps1 = bps; - if (avctx->channels == 2) + if (channels == 2) bps1 = bps * 1.6; if (sample_rate1 == 44100) { if (bps1 >= 0.61) @@ -184,7 +185,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2) } ff_dlog(s->avctx, "flags2=0x%x\n", flags2); ff_dlog(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%"PRId64" block_align=%d\n", - s->version, avctx->channels, avctx->sample_rate, avctx->bit_rate, + s->version, channels, avctx->sample_rate, avctx->bit_rate, avctx->block_align); ff_dlog(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n", bps, bps1, high_freq, s->byte_offset_bits); diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c index 9955aaa7d6..8b0893c74e 100644 --- a/libavcodec/wmadec.c +++ b/libavcodec/wmadec.c @@ -439,6 +439,7 @@ static void wma_window(WMACodecContext *s, float *out) */ static int wma_decode_block(WMACodecContext *s) { + int channels = s->avctx->ch_layout.nb_channels; int n, v, a, ch, bsize; int coef_nb_bits, total_gain; int nb_coefs[MAX_CHANNELS]; @@ -504,10 +505,10 @@ static int wma_decode_block(WMACodecContext *s) return -1; } - if (s->avctx->channels == 2) + if (channels == 2) s->ms_stereo = get_bits1(&s->gb); v = 0; - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { a = get_bits1(&s->gb); s->channel_coded[ch] = a; v |= a; @@ -538,12 +539,12 @@ static int wma_decode_block(WMACodecContext *s) /* compute number of coefficients */ n = s->coefs_end[bsize] - s->coefs_start; - for (ch = 0; ch < s->avctx->channels; ch++) + for (ch = 0; ch < channels; ch++) nb_coefs[ch] = n; /* complex coding */ if (s->use_noise_coding) { - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { if (s->channel_coded[ch]) { int i, n, a; n = s->exponent_high_sizes[bsize]; @@ -556,7 +557,7 @@ static int wma_decode_block(WMACodecContext *s) } } } - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { if (s->channel_coded[ch]) { int i, n, val; @@ -579,7 +580,7 @@ static int wma_decode_block(WMACodecContext *s) /* exponents can be reused in short blocks. */ if ((s->block_len_bits == s->frame_len_bits) || get_bits1(&s->gb)) { - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { if (s->channel_coded[ch]) { if (s->use_exp_vlc) { if (decode_exp_vlc(s, ch) < 0) @@ -593,13 +594,13 @@ static int wma_decode_block(WMACodecContext *s) } } - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { if (s->channel_coded[ch] && !s->exponents_initialized[ch]) return AVERROR_INVALIDDATA; } /* parse spectral coefficients : just RLE encoding */ - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { if (s->channel_coded[ch]) { int tindex; WMACoef *ptr = &s->coefs1[ch][0]; @@ -616,7 +617,7 @@ static int wma_decode_block(WMACodecContext *s) if (ret < 0) return ret; } - if (s->version == 1 && s->avctx->channels >= 2) + if (s->version == 1 && channels >= 2) align_get_bits(&s->gb); } @@ -629,7 +630,7 @@ static int wma_decode_block(WMACodecContext *s) } /* finally compute the MDCT coefficients */ - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { if (s->channel_coded[ch]) { WMACoef *coefs1; float *coefs, *exponents, mult, mult1, noise; @@ -730,7 +731,7 @@ static int wma_decode_block(WMACodecContext *s) } #ifdef TRACE - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { if (s->channel_coded[ch]) { dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len); dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len); @@ -754,7 +755,7 @@ static int wma_decode_block(WMACodecContext *s) next: mdct = &s->mdct_ctx[bsize]; - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { int n4, index; n4 = s->block_len / 2; @@ -799,7 +800,7 @@ static int wma_decode_frame(WMACodecContext *s, float **samples, break; } - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) { /* copy current block to output */ memcpy(samples[ch] + samples_offset, s->frame_out[ch], s->frame_len * sizeof(*s->frame_out[ch])); @@ -838,7 +839,7 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data, if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; - for (i = 0; i < s->avctx->channels; i++) + for (i = 0; i < s->avctx->ch_layout.nb_channels; i++) memcpy(frame->extended_data[i], &s->frame_out[i][0], frame->nb_samples * sizeof(s->frame_out[i][0])); diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c index 66e3537cb0..4eeaefffba 100644 --- a/libavcodec/wmaenc.c +++ b/libavcodec/wmaenc.c @@ -38,10 +38,10 @@ static av_cold int encode_init(AVCodecContext *avctx) s->avctx = avctx; - if (avctx->channels > MAX_CHANNELS) { + if (avctx->ch_layout.nb_channels > MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "too many channels: got %i, need %i or fewer\n", - avctx->channels, MAX_CHANNELS); + avctx->ch_layout.nb_channels, MAX_CHANNELS); return AVERROR(EINVAL); } @@ -82,7 +82,7 @@ static av_cold int encode_init(AVCodecContext *avctx) s->use_exp_vlc = flags2 & 0x0001; s->use_bit_reservoir = flags2 & 0x0002; s->use_variable_block_len = flags2 & 0x0004; - if (avctx->channels == 2) + if (avctx->ch_layout.nb_channels == 2) s->ms_stereo = 1; if ((ret = ff_wma_init(avctx, flags2)) < 0) @@ -116,7 +116,7 @@ static int apply_window_and_mdct(AVCodecContext *avctx, const AVFrame *frame) int window_len = 1 << s->block_len_bits; float n = 2.0 * 32768.0 / window_len; - for (ch = 0; ch < avctx->channels; ch++) { + for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) { memcpy(s->output, s->frame_out[ch], window_len * sizeof(*s->output)); s->fdsp->vector_fmul_scalar(s->frame_out[ch], audio[ch], n, len); s->fdsp->vector_fmul_reverse(&s->output[window_len], s->frame_out[ch], @@ -186,6 +186,7 @@ static void encode_exp_vlc(WMACodecContext *s, int ch, const int *exp_param) static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], int total_gain) { + int channels = s->avctx->ch_layout.nb_channels; int v, bsize, ch, coef_nb_bits, parse_exponents; float mdct_norm; int nb_coefs[MAX_CHANNELS]; @@ -213,7 +214,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], // FIXME factor v = s->coefs_end[bsize] - s->coefs_start; - for (ch = 0; ch < s->avctx->channels; ch++) + for (ch = 0; ch < channels; ch++) nb_coefs[ch] = v; { int n4 = s->block_len / 2; @@ -222,17 +223,17 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], mdct_norm *= sqrt(n4); } - if (s->avctx->channels == 2) + if (channels == 2) put_bits(&s->pb, 1, !!s->ms_stereo); - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { // FIXME only set channel_coded when needed, instead of always s->channel_coded[ch] = 1; if (s->channel_coded[ch]) init_exp(s, ch, fixed_exp); } - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { if (s->channel_coded[ch]) { WMACoef *coefs1; float *coefs, *exponents, mult; @@ -260,7 +261,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], } v = 0; - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { int a = s->channel_coded[ch]; put_bits(&s->pb, 1, a); v |= a; @@ -276,7 +277,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], coef_nb_bits = ff_wma_total_gain_to_bits(total_gain); if (s->use_noise_coding) { - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { if (s->channel_coded[ch]) { int i, n; n = s->exponent_high_sizes[bsize]; @@ -294,7 +295,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], put_bits(&s->pb, 1, parse_exponents); if (parse_exponents) { - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { if (s->channel_coded[ch]) { if (s->use_exp_vlc) { encode_exp_vlc(s, ch, fixed_exp); @@ -307,7 +308,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], } else av_assert0(0); // FIXME not implemented - for (ch = 0; ch < s->avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { if (s->channel_coded[ch]) { int run, tindex; WMACoef *ptr, *eptr; @@ -346,7 +347,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1], s->coef_vlcs[tindex]->huffcodes[1]); } - if (s->version == 1 && s->avctx->channels >= 2) + if (s->version == 1 && channels >= 2) align_put_bits(&s->pb); } return 0; diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c index 74c91f4f7e..cd05b22689 100644 --- a/libavcodec/wmalosslessdec.c +++ b/libavcodec/wmalosslessdec.c @@ -190,14 +190,14 @@ static av_cold int decode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - av_assert0(avctx->channels >= 0); - if (avctx->channels > WMALL_MAX_CHANNELS) { + av_assert0(avctx->ch_layout.nb_channels >= 0); + if (avctx->ch_layout.nb_channels > WMALL_MAX_CHANNELS) { avpriv_request_sample(avctx, "More than " AV_STRINGIFY(WMALL_MAX_CHANNELS) " channels"); return AVERROR_PATCHWELCOME; } - s->max_frame_size = MAX_FRAMESIZE * avctx->channels; + s->max_frame_size = MAX_FRAMESIZE * avctx->ch_layout.nb_channels; s->frame_data = av_mallocz(s->max_frame_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!s->frame_data) return AVERROR(ENOMEM); @@ -244,7 +244,7 @@ static av_cold int decode_init(AVCodecContext *avctx) av_assert0(s->samples_per_frame <= WMALL_BLOCK_MAX_SIZE); /* init previous block len */ - for (i = 0; i < avctx->channels; i++) + for (i = 0; i < avctx->ch_layout.nb_channels; i++) s->channel[i].prev_block_len = s->samples_per_frame; /* subframe info */ @@ -263,7 +263,7 @@ static av_cold int decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } - s->num_channels = avctx->channels; + s->num_channels = avctx->ch_layout.nb_channels; /* extract lfe channel position */ s->lfe_channel = -1; @@ -279,7 +279,8 @@ static av_cold int decode_init(AVCodecContext *avctx) if (!s->frame) return AVERROR(ENOMEM); - avctx->channel_layout = channel_mask; + av_channel_layout_uninit(&avctx->ch_layout); + av_channel_layout_from_mask(&avctx->ch_layout, channel_mask); return 0; } diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c index ba7bddc51c..5c1d38eca5 100644 --- a/libavcodec/wmaprodec.c +++ b/libavcodec/wmaprodec.c @@ -384,7 +384,7 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu s->decode_flags = 0x10d6; s->bits_per_sample = 16; channel_mask = 0; //AV_RL32(edata_ptr+2); /* not always in expected order */ - if ((num_stream+1) * XMA_MAX_CHANNELS_STREAM > avctx->channels) /* stream config is 2ch + 2ch + ... + 1/2ch */ + if ((num_stream+1) * XMA_MAX_CHANNELS_STREAM > avctx->ch_layout.nb_channels) /* stream config is 2ch + 2ch + ... + 1/2ch */ s->nb_channels = 1; else s->nb_channels = 2; @@ -402,7 +402,7 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu s->decode_flags = AV_RL16(edata_ptr+14); channel_mask = AV_RL32(edata_ptr+2); s->bits_per_sample = AV_RL16(edata_ptr); - s->nb_channels = avctx->channels; + s->nb_channels = avctx->ch_layout.nb_channels; if (s->bits_per_sample > 32 || s->bits_per_sample < 1) { avpriv_request_sample(avctx, "bits per sample is %d", s->bits_per_sample); @@ -474,7 +474,7 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu av_log(avctx, AV_LOG_ERROR, "invalid number of channels per XMA stream %d\n", s->nb_channels); return AVERROR_INVALIDDATA; - } else if (s->nb_channels > WMAPRO_MAX_CHANNELS || s->nb_channels > avctx->channels) { + } else if (s->nb_channels > WMAPRO_MAX_CHANNELS || s->nb_channels > avctx->ch_layout.nb_channels) { avpriv_request_sample(avctx, "More than %d channels", WMAPRO_MAX_CHANNELS); return AVERROR_PATCHWELCOME; @@ -575,8 +575,13 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu if (avctx->debug & FF_DEBUG_BITSTREAM) dump_context(s); - if (avctx->codec_id == AV_CODEC_ID_WMAPRO) - avctx->channel_layout = channel_mask; + if (avctx->codec_id == AV_CODEC_ID_WMAPRO) { + if (channel_mask) { + av_channel_layout_uninit(&avctx->ch_layout); + av_channel_layout_from_mask(&avctx->ch_layout, channel_mask); + } else + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + } ff_thread_once(&init_static_once, decode_init_static); @@ -1775,7 +1780,7 @@ static int decode_packet(AVCodecContext *avctx, WMAProDecodeCtx *s, AVFrame *frame = data; if (s->trim_start < frame->nb_samples) { - for (int ch = 0; ch < frame->channels; ch++) + for (int ch = 0; ch < frame->ch_layout.nb_channels; ch++) frame->extended_data[ch] += s->trim_start * 4; frame->nb_samples -= s->trim_start; @@ -1952,13 +1957,18 @@ static av_cold int xma_decode_init(AVCodecContext *avctx) XMADecodeCtx *s = avctx->priv_data; int i, ret, start_channels = 0; - if (avctx->channels <= 0 || avctx->extradata_size == 0) + if (avctx->ch_layout.nb_channels <= 0 || avctx->extradata_size == 0) return AVERROR_INVALIDDATA; /* get stream config */ if (avctx->codec_id == AV_CODEC_ID_XMA2 && avctx->extradata_size == 34) { /* XMA2WAVEFORMATEX */ + unsigned int channel_mask = AV_RL32(avctx->extradata + 2); + if (channel_mask) { + av_channel_layout_uninit(&avctx->ch_layout); + av_channel_layout_from_mask(&avctx->ch_layout, channel_mask); + } else + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; s->num_streams = AV_RL16(avctx->extradata); - avctx->channel_layout = AV_RL32(avctx->extradata + 2); } else if (avctx->codec_id == AV_CODEC_ID_XMA2 && avctx->extradata_size >= 2) { /* XMA2WAVEFORMAT */ s->num_streams = avctx->extradata[1]; if (avctx->extradata_size != (32 + ((avctx->extradata[0]==3)?0:8) + 4*s->num_streams)) { @@ -1979,7 +1989,7 @@ static av_cold int xma_decode_init(AVCodecContext *avctx) } /* encoder supports up to 64 streams / 64*2 channels (would have to alloc arrays) */ - if (avctx->channels > XMA_MAX_CHANNELS || s->num_streams > XMA_MAX_STREAMS || + if (avctx->ch_layout.nb_channels > XMA_MAX_CHANNELS || s->num_streams > XMA_MAX_STREAMS || s->num_streams <= 0 ) { avpriv_request_sample(avctx, "More than %d channels in %d streams", XMA_MAX_CHANNELS, s->num_streams); @@ -1999,7 +2009,7 @@ static av_cold int xma_decode_init(AVCodecContext *avctx) s->start_channel[i] = start_channels; start_channels += s->xma[i].nb_channels; } - if (start_channels != avctx->channels) + if (start_channels != avctx->ch_layout.nb_channels) return AVERROR_INVALIDDATA; for (int i = 0; i < XMA_MAX_STREAMS; i++) { diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c index e096b8029d..47fc0947c5 100644 --- a/libavcodec/wmavoice.c +++ b/libavcodec/wmavoice.c @@ -475,8 +475,8 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx) 2 * (s->block_conv_table[1] - 2 * s->min_pitch_val); s->block_pitch_nbits = av_ceil_log2(s->block_pitch_range); - ctx->channels = 1; - ctx->channel_layout = AV_CH_LAYOUT_MONO; + av_channel_layout_uninit(&ctx->ch_layout); + ctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; ctx->sample_fmt = AV_SAMPLE_FMT_FLT; return 0;