From patchwork Thu Jun 17 02:31:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 28456 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp201447iol; Wed, 16 Jun 2021 19:36:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBnqF8KDpj1Bn6bol+WoCZtppKWIZ2cEz51pL4/r+VgZF+6A0vlZ5QI3JE5bvJJd9UBkWk X-Received: by 2002:a17:906:5053:: with SMTP id e19mr2636338ejk.251.1623897377079; Wed, 16 Jun 2021 19:36:17 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z15si3430577edd.488.2021.06.16.19.36.16; Wed, 16 Jun 2021 19:36:17 -0700 (PDT) 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=@outlook.com header.s=selector1 header.b=gjB7FXPr; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 43CFB689D53; Thu, 17 Jun 2021 05:33:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073052.outbound.protection.outlook.com [40.92.73.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DC6CE689A61 for ; Thu, 17 Jun 2021 05:33:21 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fgwCkzbpu4dKwajilqbHDjH3GZyQxuG2CaN5411RLibLpnTAveKFqz/Zz/WCQdWiYztmcfjVSwvWDCfnPYwKvkEFNcCr/7NeMKNTziHmNQp/qjAztNOjUE84YdHd3UfewELvz7FlF1vpl+K6vlysqRsiJCTm75NAKI673vHipZ1t3CXhGBVfeXJLgw6qwMkbdYo/gtpcrgaQqH0dBogO8SLrNUpSSa66YcR2fqv/mqZJ27MvzQgAyd7iuWTNbys5lJKfQiUI+da9M1dfD2o1tT4sD+rNHWSl/Jx3XAkWjkHEbutXc9hNwYvBwi66d4t06g7EB5ay05C2wTkRHilSTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9MTzDN8emSAJfibnjY3mDFXUb1ko4XSyucNj6YUiF3A=; b=Pma9ipio6mcgB84ychUWQfrb3gUTYxeIKuUfOV+cmomkgQcQnrQB/GW29JxzsLHTihg11edj/CyK4YSi4uSfIr2Gb5qRYYbTuQQsPlBCtihZP08mnqZwmWmiHtKY0iCFf15/AdQMxUK3PblBLuarZlF+EOkkLHQmk/lr57s2Oa+9U4iboUW2N8M/eAfqiRHantxTWokuT15rCSJadq4bhB0leBAxqSb4PwpQub/RoCLEkY+1aWd1xQdFips0IDwAhSSiSPyHBRFlShPlVrvMojgEaBJSPR8keZ7HNqxuJmgtv0uzWZyYWmWd30oGRLGvBoWM2c1V8mLVlMHDmMQFIw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9MTzDN8emSAJfibnjY3mDFXUb1ko4XSyucNj6YUiF3A=; b=gjB7FXPrKaa3wQ8SX7sv6UBhSEZ1PWCF3TyN8FHrbDweV2aaGVi67tWQG5NDdnHfDh0X3etmNZ+r8s/f1/w9En/qa+GxHd/IVJq0G+EsyCp+mCWuOWztfVlluoWHtdqqePW5OI/8b7V1pBnHWs50vpECOhHT9JXDXdtidKiXa/k0L5qsZjEvFepBv1VCsaeG0ZfqWUYhngqYiaTfwuuBtuL0xpHYa5oeqGEXul/BxUN6DeM3kJbSmxz9G2DnJrCBXG2BPWdTYfO9ChTK5+NSUHjap9FltQNxOfIs75OFCiHJ/jA4S4aW08A08s/pVU9ZsS9KMQXs8m3LEzo1ksklcQ== Received: from HE1EUR04FT053.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0d::4a) by HE1EUR04HT004.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0d::107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16; Thu, 17 Jun 2021 02:33:21 +0000 Received: from VI1PR0301MB2159.eurprd03.prod.outlook.com (2a01:111:e400:7e0d::4b) by HE1EUR04FT053.mail.protection.outlook.com (2a01:111:e400:7e0d::298) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16 via Frontend Transport; Thu, 17 Jun 2021 02:33:20 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:6A9CAF460785C048790A825B6A390CED4A6785BAF51F54B76506D14CF8F39686; UpperCasedChecksum:CDF5CC70873E594383B61F0E29B15993D4BD71E9BD5A595420AF70266DB300AE; SizeAsReceived:7597; Count:48 Received: from VI1PR0301MB2159.eurprd03.prod.outlook.com ([fe80::d9b:66ba:63ad:967b]) by VI1PR0301MB2159.eurprd03.prod.outlook.com ([fe80::d9b:66ba:63ad:967b%5]) with mapi id 15.20.4242.019; Thu, 17 Jun 2021 02:33:20 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Jun 2021 04:31:45 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [CzBRAcgIggM7YcjjvRJ5S6KaCptTe8HJ] X-ClientProxiedBy: AM0PR04CA0115.eurprd04.prod.outlook.com (2603:10a6:208:55::20) To VI1PR0301MB2159.eurprd03.prod.outlook.com (2603:10a6:800:26::20) X-Microsoft-Original-Message-ID: <20210617023202.1318312-23-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.97.82) by AM0PR04CA0115.eurprd04.prod.outlook.com (2603:10a6:208:55::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16 via Frontend Transport; Thu, 17 Jun 2021 02:33:20 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: abb7b9bc-6b0d-470b-602f-08d9313845b3 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiSz7Gd0YLSftKT0G4ETHQtWEHzfetLs7TP5Yj0qMh+OvffQAAoJClamqRIExBP+aqPjeEsG6Z6jH29LQeVRfrcCfFUAVevy4WvUedNJyLssxawlIMZRcHrHymZdhUfWr705NIEY6uQ6/HumIqt3U53rlQNk+Tzi+7S0fPLuVE4iloTtVwR1ezCkPXiXIZTSX2QDP46YN4jzLX84IZ3QPg7R0xbyfSkFYT/YTN/whI024vg8zqRTmkmTi+jrpsUG61xqIF+2SG4LPQZx8iM6VgswSrPZpUpEL7RFHL32vWE/uKz5QyzOwMy7jvb6iUKv2GQoMQZyY6GOCDvWKXwAgk5nk6b07jKuwArwZ34fFyjLFG1afl0HaoiTi+94bZT960FlbIHvhz2qYlrNX/mPNeASWCQvBdMzb+exOnvbQVzRHUrmFkyQ8scWHlamQyylDyD878M7oyeoGb4vmF9Yaqoyyho7iOuYuvMbnFJdQttzg/g8HDsM6WLjzOX4tTcvqz7l3OLRhgSk2+wJ2AJY2J68+/b0uPUxYz74F0FqCwSlJAob6X2CHeKPtIzJRlPIRI/F3cIRrIm9DKl8+K5HKZXgzteA68U18YdvS3ucgzV8/OLDZg9GyRh2ZZCNWY7YWRN1WI3pAdQ5J4SJGiDW5pDPwuILTmMs7ar+zbPsuvpsDFvxX6u2i8jWWHCK8LKVm2B8njjZZKAe7UX5X+raNFbZesH0i3ALAMi3VeqPWzSVKUssYQBR09sWGEyj7GavYdo= X-MS-TrafficTypeDiagnostic: HE1EUR04HT004: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Nd/5EX9c579px55O57qy4nbrIZJkxmOJ0FBQOlf0TTMUQHCBJ7e9I3f7aisy5F+s6HPc64GJ7th9gbBsMM/GHgFoHeDyF+8f4G+kHICdAg1zOHcrNU7dtC2b9Kt+u44V3cvsyqgI+NXRf+XK2saSP4n2TmnxguoDjqSVbleWL3kpuSdydo5hGvyRhUZlOYvZ7Dgy2bxoewB3f+RWvo/If3TbISFt+ogvl9oG+IzsuDgWQIALuAybMEKD+/U8ab7jxNwz50Ktamr++vL344YjPKJf2FeogXWORcD+3w4iJIo+aHiDJ8alYZzsfQdd2rFLrDdSJOfREuLF5JjA2Mh+k8Epni/T9VIS3KQ4Kan/BZsrnKK0OYKV+jITPB+hsDoXSjBlB6FlCt/QVKkp1Yx3+Q== X-MS-Exchange-AntiSpam-MessageData: w/LPKStbIKU2ldPjdUKJRTg1P6rjHa0+dtbCyIl7EmMCprNRmd+BadaBBmmRRjAX6qm/wE9Y+ZxuASLTkT+ZT0C1Hr/LjIBDcAaaJd+T/XAjINyLQstuBPQrrYn3gwrRXlO3b0S/SRaSmnW79fSBVw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: abb7b9bc-6b0d-470b-602f-08d9313845b3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2021 02:33:20.9277 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: HE1EUR04FT053.eop-eur04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR04HT004 Subject: [FFmpeg-devel] [PATCH 24/41] avcodec/adpcmenc: Use smaller scope for some variables 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ycryxkVuarYv This is to avoid unused variables warnings if the code for disabled encoders is #if'ed away which will happen in a subsequent commit. In case of buf it also avoids shadowing. Signed-off-by: Andreas Rheinhardt --- libavcodec/adpcmenc.c | 105 ++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 2b5a606699..b95a9822e5 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -67,8 +67,6 @@ typedef struct ADPCMEncodeContext { static av_cold int adpcm_encode_init(AVCodecContext *avctx) { ADPCMEncodeContext *s = avctx->priv_data; - uint8_t *extradata; - int i; if (avctx->channels > 2) { av_log(avctx, AV_LOG_ERROR, "only stereo or mono is supported\n"); @@ -132,6 +130,8 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) avctx->block_align = 34 * avctx->channels; break; case AV_CODEC_ID_ADPCM_MS: + { + uint8_t *extradata; /* each 16 bits sample gives one nibble and we have 7 bytes per channel overhead */ avctx->frame_size = (s->block_size - 7 * avctx->channels) * 2 / avctx->channels + 2; @@ -143,11 +143,12 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) extradata = avctx->extradata; bytestream_put_le16(&extradata, avctx->frame_size); bytestream_put_le16(&extradata, 7); /* wNumCoef */ - for (i = 0; i < 7; i++) { + for (int i = 0; i < 7; i++) { bytestream_put_le16(&extradata, ff_adpcm_AdaptCoeff1[i] * 4); bytestream_put_le16(&extradata, ff_adpcm_AdaptCoeff2[i] * 4); } break; + } case AV_CODEC_ID_ADPCM_YAMAHA: avctx->frame_size = s->block_size * 2 / avctx->channels; avctx->block_align = s->block_size; @@ -588,12 +589,11 @@ static int64_t adpcm_argo_compress_block(ADPCMChannelStatus *cs, PutBitContext * static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { - int n, i, ch, st, pkt_size, ret; + int st, pkt_size, ret; const int16_t *samples; int16_t **samples_p; uint8_t *dst; ADPCMEncodeContext *c = avctx->priv_data; - uint8_t *buf; samples = (const int16_t *)frame->data[0]; samples_p = (int16_t **)frame->extended_data; @@ -613,11 +613,9 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, switch(avctx->codec->id) { case AV_CODEC_ID_ADPCM_IMA_WAV: { - int blocks, j; - - blocks = (frame->nb_samples - 1) / 8; + int blocks = (frame->nb_samples - 1) / 8; - for (ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < avctx->channels; ch++) { ADPCMChannelStatus *status = &c->status[ch]; status->prev_sample = samples_p[ch][0]; /* status->step_index = 0; @@ -629,27 +627,28 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, /* stereo: 4 bytes (8 samples) for left, 4 bytes for right */ if (avctx->trellis > 0) { + uint8_t *buf; if (!FF_ALLOC_TYPED_ARRAY(buf, avctx->channels * blocks * 8)) return AVERROR(ENOMEM); - for (ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < avctx->channels; ch++) { adpcm_compress_trellis(avctx, &samples_p[ch][1], buf + ch * blocks * 8, &c->status[ch], blocks * 8, 1); } - for (i = 0; i < blocks; i++) { - for (ch = 0; ch < avctx->channels; ch++) { + for (int i = 0; i < blocks; i++) { + for (int ch = 0; ch < avctx->channels; ch++) { uint8_t *buf1 = buf + ch * blocks * 8 + i * 8; - for (j = 0; j < 8; j += 2) + for (int j = 0; j < 8; j += 2) *dst++ = buf1[j] | (buf1[j + 1] << 4); } } av_free(buf); } else { - for (i = 0; i < blocks; i++) { - for (ch = 0; ch < avctx->channels; ch++) { + for (int i = 0; i < blocks; i++) { + for (int ch = 0; ch < avctx->channels; ch++) { ADPCMChannelStatus *status = &c->status[ch]; const int16_t *smp = &samples_p[ch][1 + i * 8]; - for (j = 0; j < 8; j += 2) { + for (int j = 0; j < 8; j += 2) { uint8_t v = adpcm_ima_compress_sample(status, smp[j ]); v |= adpcm_ima_compress_sample(status, smp[j + 1]) << 4; *dst++ = v; @@ -664,7 +663,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, PutBitContext pb; init_put_bits(&pb, dst, pkt_size); - for (ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < avctx->channels; ch++) { ADPCMChannelStatus *status = &c->status[ch]; put_bits(&pb, 9, (status->prev_sample & 0xFFFF) >> 7); put_bits(&pb, 7, status->step_index); @@ -672,11 +671,11 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, uint8_t buf[64]; adpcm_compress_trellis(avctx, &samples_p[ch][0], buf, status, 64, 1); - for (i = 0; i < 64; i++) + for (int i = 0; i < 64; i++) put_bits(&pb, 4, buf[i ^ 1]); status->prev_sample = status->predictor; } else { - for (i = 0; i < 64; i += 2) { + for (int i = 0; i < 64; i += 2) { int t1, t2; t1 = adpcm_ima_qt_compress_sample(status, samples_p[ch][i ]); t2 = adpcm_ima_qt_compress_sample(status, samples_p[ch][i + 1]); @@ -696,8 +695,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_assert0(avctx->trellis == 0); - for (i = 0; i < frame->nb_samples; i++) { - for (ch = 0; ch < avctx->channels; ch++) { + for (int i = 0; i < frame->nb_samples; i++) { + for (int ch = 0; ch < avctx->channels; ch++) { put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, *samples++)); } } @@ -712,8 +711,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_assert0(avctx->trellis == 0); - for (n = frame->nb_samples / 2; n > 0; n--) { - for (ch = 0; ch < avctx->channels; ch++) { + for (int n = frame->nb_samples / 2; n > 0; n--) { + for (int ch = 0; ch < avctx->channels; ch++) { put_bits(&pb, 4, adpcm_ima_alp_compress_sample(c->status + ch, *samples++)); put_bits(&pb, 4, adpcm_ima_alp_compress_sample(c->status + ch, samples[st])); } @@ -725,11 +724,10 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } case AV_CODEC_ID_ADPCM_SWF: { + const int n = frame->nb_samples - 1; PutBitContext pb; init_put_bits(&pb, dst, pkt_size); - n = frame->nb_samples - 1; - /* NB: This is safe as we don't have AV_CODEC_CAP_SMALL_LAST_FRAME. */ av_assert0(n == 4095); @@ -737,7 +735,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, put_bits(&pb, 2, 2); // set 4-bit flash adpcm format // init the encoder state - for (i = 0; i < avctx->channels; i++) { + for (int i = 0; i < avctx->channels; i++) { // clip step so it fits 6 bits c->status[i].step_index = av_clip_uintp2(c->status[i].step_index, 6); put_sbits(&pb, 16, samples[i]); @@ -753,13 +751,13 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, adpcm_compress_trellis(avctx, samples + avctx->channels + 1, buf + n, &c->status[1], n, avctx->channels); - for (i = 0; i < n; i++) { + for (int i = 0; i < n; i++) { put_bits(&pb, 4, buf[i]); if (avctx->channels == 2) put_bits(&pb, 4, buf[n + i]); } } else { - for (i = 1; i < frame->nb_samples; i++) { + for (int i = 1; i < frame->nb_samples; i++) { put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * i])); if (avctx->channels == 2) @@ -771,46 +769,47 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, break; } case AV_CODEC_ID_ADPCM_MS: - for (i = 0; i < avctx->channels; i++) { + for (int i = 0; i < avctx->channels; i++) { int predictor = 0; *dst++ = predictor; c->status[i].coeff1 = ff_adpcm_AdaptCoeff1[predictor]; c->status[i].coeff2 = ff_adpcm_AdaptCoeff2[predictor]; } - for (i = 0; i < avctx->channels; i++) { + for (int i = 0; i < avctx->channels; i++) { if (c->status[i].idelta < 16) c->status[i].idelta = 16; bytestream_put_le16(&dst, c->status[i].idelta); } - for (i = 0; i < avctx->channels; i++) + for (int i = 0; i < avctx->channels; i++) c->status[i].sample2= *samples++; - for (i = 0; i < avctx->channels; i++) { + for (int i = 0; i < avctx->channels; i++) { c->status[i].sample1 = *samples++; bytestream_put_le16(&dst, c->status[i].sample1); } - for (i = 0; i < avctx->channels; i++) + for (int i = 0; i < avctx->channels; i++) bytestream_put_le16(&dst, c->status[i].sample2); if (avctx->trellis > 0) { - n = avctx->block_align - 7 * avctx->channels; - if (!(buf = av_malloc(2 * n))) + const int n = avctx->block_align - 7 * avctx->channels; + uint8_t *buf = av_malloc(2 * n); + if (!buf) return AVERROR(ENOMEM); if (avctx->channels == 1) { adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n, avctx->channels); - for (i = 0; i < n; i += 2) + for (int i = 0; i < n; i += 2) *dst++ = (buf[i] << 4) | buf[i + 1]; } else { adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n, avctx->channels); adpcm_compress_trellis(avctx, samples + 1, buf + n, &c->status[1], n, avctx->channels); - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) *dst++ = (buf[i] << 4) | buf[n + i]; } av_free(buf); } else { - for (i = 7 * avctx->channels; i < avctx->block_align; i++) { + for (int i = 7 * avctx->channels; i < avctx->block_align; i++) { int nibble; nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++) << 4; nibble |= adpcm_ms_compress_sample(&c->status[st], *samples++); @@ -819,22 +818,24 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } break; case AV_CODEC_ID_ADPCM_YAMAHA: - n = frame->nb_samples / 2; + { + int n = frame->nb_samples / 2; if (avctx->trellis > 0) { - if (!(buf = av_malloc(2 * n * 2))) + uint8_t *buf = av_malloc(2 * n * 2); + if (!buf) return AVERROR(ENOMEM); n *= 2; if (avctx->channels == 1) { adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n, avctx->channels); - for (i = 0; i < n; i += 2) + for (int i = 0; i < n; i += 2) *dst++ = buf[i] | (buf[i + 1] << 4); } else { adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n, avctx->channels); adpcm_compress_trellis(avctx, samples + 1, buf + n, &c->status[1], n, avctx->channels); - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) *dst++ = buf[i] | (buf[n + i] << 4); } av_free(buf); @@ -846,6 +847,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, *dst++ = nibble; } break; + } case AV_CODEC_ID_ADPCM_IMA_APM: { PutBitContext pb; @@ -853,8 +855,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_assert0(avctx->trellis == 0); - for (n = frame->nb_samples / 2; n > 0; n--) { - for (ch = 0; ch < avctx->channels; ch++) { + for (int n = frame->nb_samples / 2; n > 0; n--) { + for (int ch = 0; ch < avctx->channels; ch++) { put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, *samples++)); put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, samples[st])); } @@ -875,18 +877,19 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, bytestream_put_le32(&dst, avctx->frame_size); if (avctx->trellis > 0) { - n = frame->nb_samples >> 1; + const int n = frame->nb_samples >> 1; + uint8_t *buf = av_malloc(2 * n); - if (!(buf = av_malloc(2 * n))) + if (!buf) return AVERROR(ENOMEM); adpcm_compress_trellis(avctx, samples, buf, &c->status[0], 2 * n, avctx->channels); - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) bytestream_put_byte(&dst, (buf[2 * i] << 4) | buf[2 * i + 1]); samples += 2 * n; av_free(buf); - } else for (n = frame->nb_samples >> 1; n > 0; n--) { + } else for (int n = frame->nb_samples >> 1; n > 0; n--) { int nibble; nibble = adpcm_ima_compress_sample(&c->status[0], *samples++) << 4; nibble |= adpcm_ima_compress_sample(&c->status[0], *samples++) & 0x0F; @@ -906,7 +909,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_assert0(frame->nb_samples == 32); - for (ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < avctx->channels; ch++) { int64_t error = INT64_MAX, tmperr = INT64_MAX; int shift = 2, flag = 0; int saved1 = c->status[ch].sample1; @@ -943,9 +946,9 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, init_put_bits(&pb, dst, pkt_size); av_assert0(avctx->trellis == 0); - for (n = frame->nb_samples / 2; n > 0; n--) { + for (int n = frame->nb_samples / 2; n > 0; n--) { /* stereo: 1 byte (2 samples) for left, 1 byte for right */ - for (ch = 0; ch < avctx->channels; ch++) { + for (int ch = 0; ch < avctx->channels; ch++) { int t1, t2; t1 = adpcm_ima_compress_sample(&c->status[ch], *samples++); t2 = adpcm_ima_compress_sample(&c->status[ch], samples[st]);