From patchwork Thu Jan 13 01:50:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33327 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp16908iog; Wed, 12 Jan 2022 18:00:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpqV8Rr6DWkEAST9UmUCmwNwyhbtK9tlxgFtj6iTUR/HmO4XbEKvf2QZTxInqNz0NNKS+B X-Received: by 2002:aa7:d9c9:: with SMTP id v9mr2150891eds.270.1642039241701; Wed, 12 Jan 2022 18:00:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642039241; cv=none; d=google.com; s=arc-20160816; b=UNR/d0vaWp+jzLLu0e/90CBoh8vlCv9rBqtJPW3Bb9ousCwFr0cS1nlcUWf8Vm6lt1 lCbxd/3DSJOzZi8B8UScfhC/QPYb3YTUqr5Ciyicyg4722RNl6CXRML5Gb37l3wp6u16 zG+POScILuBvREqchYlJ59+/fVRC1tUdY3pkUKcck+6lGLjc/auC7PP4gbUcySIY8trw IB+SemVB5oI/8eBQ9D7wbf9oiFFTzfZQOF/wbQ+OAWq2P3KNqHtQdr9MA8lr6AGF8Za9 5uSuJuMI1wfpRiQVnZZvN2SYvNHLdVXHR2P+hahH2TlpPuK2zuu/lSdDMzWPuXsPWkLZ TQbQ== 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=92kODm7b3B2MZkSYQnO7btclKd1lB4nVL+Ixa31w3KE=; b=HUxyTqBpqmMjHWm5JEJrsC8yWJlVRfUMS+HHGjWcZQCnYVbmLGVungcpO1gvu/saKr JYpRMCx1KpeWydPojCvFhAQ8fscJJzkhmHWmrzPu4hzl2v9mKQ/Maskf9QYQfGtQi7F3 RfZnuBCoUNSk9Xa8wetZ26Kq/tCM7jSCzz+DaxlYnDlEp3CNuXfQbJYs78WVePOhehV+ Mn7tjaHjgWO6+b9YUIivQm4kaYcudXibc+463rRPhFuPQemNboJ8SufCFas3/IEdkhr1 1M3Bv6GUC8wl3urCDPlGAkGnAMyAatvuXI87egOkGLQ4fLeumD6jBMuxDuLUBLuVRFR8 VqBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="V3RO/u+B"; 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 cw13si782495edb.268.2022.01.12.18.00.41; Wed, 12 Jan 2022 18:00:41 -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="V3RO/u+B"; 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 36C4C68B098; Thu, 13 Jan 2022 03:52:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DE0C568B08E for ; Thu, 13 Jan 2022 03:52:50 +0200 (EET) Received: by mail-qt1-f175.google.com with SMTP id q14so5300283qtx.10 for ; Wed, 12 Jan 2022 17:52:50 -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=5oKd1E8ZEH55c+RiHP1ItHkB9ttgq2VxhCPmw7zhGLI=; b=V3RO/u+BJrMzfTp96l2tU73IQkzUY/fkdk4A/do6oJc+GmrVQ4DTGY2rN6m2fDmH6m xd+GZeYPss1Ex197t27zWGCyv+8ro5OM2YPggIZUJp8q+LDb9IwnGGalnfiv7es+64dJ 6T5idCefurDFwQ91PdnU1gfLIK/lzicQMwbZt7Ypm6EEn6XJKP9OWkFTB2qmyA1j4AIF 3f55XX5Ei5QEF+db+YRXgLs2GwmT7rOBHO4FQ56fs5AyNYbMGGcLdtgQRYRM1ocIQrWi Wda/guls0eKxC20U6JP87QX7thg2DaBWj5/hxdCml0cM7YmnLNAzjTp9cGI0sDP46OQn U0wg== 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=5oKd1E8ZEH55c+RiHP1ItHkB9ttgq2VxhCPmw7zhGLI=; b=ShZdR4yTrS40gwTx7N3W8KsMk/uOtMV52cZ+N3gADrF4JBDxAsS3eaCSBrDX0aiC2m dqnboeEDqlKj4xgD7UyuT/y2n+0dqvr/fKn+luJgp6fndHc/N/n3T2f9M6A0JsjKnfsl ZTyh1btvQ51hYwy4CdadXMkbOc6gq+YFdoQLYVS5UyOwDbpqQ06q5RLuUbZMYjnv3uyH 67t9WO1N8OwioPK7LsqdaC+aw1OWl/QGdng1dSIr+i1hsUiTqNqzVxurAXhZuI7AnCI9 4GJ3NgPnd2NdnoLRKq1DW1NPWIbMzRj/S1gcl7t1Glz1ovRoiVy59oJc0ekID/2kNs3c ShsA== X-Gm-Message-State: AOAM530MPyOLQRz6G8V/7jliUN5/YDtsLbubx9C/g4MtETxoen0MNwN7 kTl9rvH01Pt0jstxXUmkrpH6t1mZfc8= X-Received: by 2002:a05:622a:118b:: with SMTP id m11mr2081316qtk.524.1642038769465; Wed, 12 Jan 2022 17:52:49 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id i21sm1204710qti.31.2022.01.12.17.52.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 17:52:49 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 22:50:03 -0300 Message-Id: <20220113015101.4-42-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 041/281] brstm: 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: 6n9BJKzuHCbj From: Anton Khirnov Signed-off-by: James Almer --- libavformat/brstm.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/libavformat/brstm.c b/libavformat/brstm.c index 338491d9ef..89d5dcc344 100644 --- a/libavformat/brstm.c +++ b/libavformat/brstm.c @@ -209,8 +209,9 @@ static int read_header(AVFormatContext *s) loop = avio_r8(s->pb); // loop flag st->codecpar->codec_id = codec; - st->codecpar->channels = avio_r8(s->pb); - if (!st->codecpar->channels) + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = avio_r8(s->pb); + if (!st->codecpar->ch_layout.nb_channels) return AVERROR_INVALIDDATA; avio_skip(s->pb, 1); // padding @@ -246,14 +247,14 @@ static int read_header(AVFormatContext *s) } b->block_size = read32(s); - if (b->block_size > UINT32_MAX / st->codecpar->channels) + if (b->block_size > UINT32_MAX / st->codecpar->ch_layout.nb_channels) return AVERROR_INVALIDDATA; b->samples_per_block = read32(s); b->last_block_used_bytes = read32(s); b->last_block_samples = read32(s); b->last_block_size = read32(s); - if (b->last_block_size > UINT32_MAX / st->codecpar->channels) + if (b->last_block_size > UINT32_MAX / st->codecpar->ch_layout.nb_channels) return AVERROR_INVALIDDATA; if (b->last_block_used_bytes > b->last_block_size) return AVERROR_INVALIDDATA; @@ -266,24 +267,24 @@ static int read_header(AVFormatContext *s) if (!bfstm) toffset = read32(s) + 16LL; else - toffset = toffset + read32(s) + st->codecpar->channels * 8 - 8; + toffset = toffset + read32(s) + st->codecpar->ch_layout.nb_channels * 8 - 8; if (toffset > size) return AVERROR_INVALIDDATA; if (!bfstm) { - avio_skip(s->pb, pos + toffset - avio_tell(s->pb) - 8LL * (st->codecpar->channels + 1)); - for (ch = 0; ch < st->codecpar->channels; ch++) { + avio_skip(s->pb, pos + toffset - avio_tell(s->pb) - 8LL * (st->codecpar->ch_layout.nb_channels + 1)); + for (ch = 0; ch < st->codecpar->ch_layout.nb_channels; ch++) { avio_skip(s->pb, 4); b->offsets[ch].channel = ch; b->offsets[ch].offset = read32(s); } - qsort(b->offsets, st->codecpar->channels, sizeof(*b->offsets), sort_offsets); + qsort(b->offsets, st->codecpar->ch_layout.nb_channels, sizeof(*b->offsets), sort_offsets); } avio_skip(s->pb, pos + toffset - avio_tell(s->pb)); - for (ch = 0; ch < st->codecpar->channels; ch++) { + for (ch = 0; ch < st->codecpar->ch_layout.nb_channels; ch++) { if (!bfstm) avio_skip(s->pb, pos + 16LL + b->offsets[ch].offset - avio_tell(s->pb)); @@ -313,7 +314,7 @@ static int read_header(AVFormatContext *s) codec != AV_CODEC_ID_ADPCM_THP_LE) goto skip; - asize = b->block_count * st->codecpar->channels * 4; + asize = b->block_count * st->codecpar->ch_layout.nb_channels * 4; if (size < asize) return AVERROR_INVALIDDATA; if (b->adpc) { @@ -369,6 +370,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) AVCodecParameters *par = s->streams[0]->codecpar; BRSTMDemuxContext *b = s->priv_data; uint32_t samples, size, skip = 0; + int channels = par->ch_layout.nb_channels; int ret, i; if (avio_feof(s->pb)) @@ -404,24 +406,24 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) } if (size > (INT_MAX - 32 - 4) || - (32 + 4 + size) > (INT_MAX / par->channels) || - (32 + 4 + size) * par->channels > INT_MAX - 8) + (32 + 4 + size) > (INT_MAX / channels) || + (32 + 4 + size) * channels > INT_MAX - 8) return AVERROR_INVALIDDATA; - if ((ret = av_new_packet(pkt, 8 + (32 + 4 + size) * par->channels)) < 0) + if ((ret = av_new_packet(pkt, 8 + (32 + 4 + size) * channels)) < 0) return ret; dst = pkt->data; if (par->codec_id == AV_CODEC_ID_ADPCM_THP_LE) { - bytestream_put_le32(&dst, size * par->channels); + bytestream_put_le32(&dst, size * channels); bytestream_put_le32(&dst, samples); } else { - bytestream_put_be32(&dst, size * par->channels); + bytestream_put_be32(&dst, size * channels); bytestream_put_be32(&dst, samples); } - bytestream_put_buffer(&dst, b->table, 32 * par->channels); - bytestream_put_buffer(&dst, b->adpc + 4 * par->channels * - (b->current_block - 1), 4 * par->channels); + bytestream_put_buffer(&dst, b->table, 32 * channels); + bytestream_put_buffer(&dst, b->adpc + 4 * channels * + (b->current_block - 1), 4 * channels); - for (i = 0; i < par->channels; i++) { + for (i = 0; i < channels; i++) { ret = avio_read(s->pb, dst, size); dst += size; avio_skip(s->pb, skip); @@ -431,7 +433,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) } pkt->duration = samples; } else { - size *= par->channels; + size *= channels; ret = av_get_packet(s->pb, pkt, size); } @@ -456,7 +458,7 @@ static int read_seek(AVFormatContext *s, int stream_index, if (timestamp >= b->block_count) timestamp = b->block_count - 1; ret = avio_seek(s->pb, b->data_start + timestamp * b->block_size * - st->codecpar->channels, SEEK_SET); + st->codecpar->ch_layout.nb_channels, SEEK_SET); if (ret < 0) return ret;