From patchwork Fri Sep 18 12:04:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 22470 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 194D244A11F for ; Fri, 18 Sep 2020 15:05:00 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 095DD68B8F8; Fri, 18 Sep 2020 15:05:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3126C68B78A for ; Fri, 18 Sep 2020 15:04:53 +0300 (EEST) Date: Fri, 18 Sep 2020 12:04:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail2; t=1600430692; bh=HT880qD7N1Zbw4qW3W0tqT3xgcybxOFI8wqe0TrTjYk=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=FnU+AXpoLUFHKN1ReNvXy2k5ZWJAfOZo5qXU4HrCiEl7vH7/tl8aKsh06tNCnA8Vf laPs0zMN8QaKJSkgemmUri/5a1NQ7KJAgyuCrG4C+ewixTeD42EEG6nLkN03dgxQDU Te0lvYEXu4c8h4Ahs9o0aY6BAG+qZGQVtWbm29l6YDJG7zWcJ/NI2gc8iGSRtYCl4e KPF5rZ/jQWSJrazNYTnAqCy8NAjv4PJ0eWtA8VM2HKzekfArHibLupe9xKe27E1j6q uQBrA7cR0zJJZEp8LKcYbZeCMFFxZQ/164+aes1A8pg7TuHojLQDA0mrbBldsQSHei C1d+zbKBY+moA== To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200918120416.7319-2-zane@zanevaniperen.com> In-Reply-To: <20200918120416.7319-1-zane@zanevaniperen.com> References: <20200918120416.7319-1-zane@zanevaniperen.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Subject: [FFmpeg-devel] [PATCH v2 1/7] avcodec/adpcm_argo: support decoding multiple frames X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Increases decode speed significantly. Signed-off-by: Zane van Iperen --- libavcodec/adpcm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index e409a3aa6a..14be1f4f88 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -181,7 +181,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) c->vqa_version = AV_RL16(avctx->extradata); break; case AV_CODEC_ID_ADPCM_ARGO: - if (avctx->bits_per_coded_sample != 4) + if (avctx->bits_per_coded_sample != 4 || avctx->block_align != 17 * avctx->channels) return AVERROR_INVALIDDATA; break; case AV_CODEC_ID_ADPCM_ZORK: @@ -745,11 +745,6 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, return 0; nb_samples = 64; break; - case AV_CODEC_ID_ADPCM_ARGO: - if (buf_size < 17 * ch) - return 0; - nb_samples = 32; - break; /* simple 4-bit adpcm */ case AV_CODEC_ID_ADPCM_CT: case AV_CODEC_ID_ADPCM_IMA_APC: @@ -922,6 +917,9 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, case AV_CODEC_ID_ADPCM_PSX: nb_samples = buf_size / (16 * ch) * 28; break; + case AV_CODEC_ID_ADPCM_ARGO: + nb_samples = buf_size / avctx->block_align * 32; + break; case AV_CODEC_ID_ADPCM_ZORK: nb_samples = buf_size / ch; break; @@ -2023,22 +2021,24 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, * Each block relies on the previous two samples of each channel. * They should be 0 initially. */ + for (int block = 0; block < avpkt->size / avctx->block_align; block++) { for (channel = 0; channel < avctx->channels; channel++) { int control, shift; - samples = samples_p[channel]; + samples = samples_p[channel] + block * 32; cs = c->status + channel; /* Get the control byte and decode the samples, 2 at a time. */ control = bytestream2_get_byteu(&gb); shift = (control >> 4) + 2; - for (n = 0; n < nb_samples / 2; n++) { + for (n = 0; n < 16; n++) { int sample = bytestream2_get_byteu(&gb); *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 4, shift, control & 0x04); *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 0, shift, control & 0x04); } } + } break; case AV_CODEC_ID_ADPCM_ZORK: if (!c->has_status) { From patchwork Fri Sep 18 12:04:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 22469 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2D5DC44A11F for ; Fri, 18 Sep 2020 15:04:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1BF3768B8CF; Fri, 18 Sep 2020 15:04:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D3FF068B877 for ; Fri, 18 Sep 2020 15:04:51 +0300 (EEST) Date: Fri, 18 Sep 2020 12:04:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail2; t=1600430691; bh=xoZvNiElvyFmIvij5rBqbV4nhsJGRhxFyJy/uU320+0=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=jbtP6xW5cUuSIcMsf+bIRwDXdmjF8bBQ1SE0ATavob7ZzSu43FZkgZHkW3sqZcL7J fMC10SRhkWPa068iohiXCC8uPEp+o00PLKYbAjhl1XQ+bpwNDJWvVtLyguD1+Okbj4 eUdneJqo90mdARKbhbDGpQG7pezEcFIPJsNXepQtYCGfEb64BFKdSJGE3HT9JEC44J IL+/8hRrxN6OSjCN83+elWq+yssBYIpDMth/4bmc9qnELQ4ZAFlGjNx+Qe+UDpbvNi UCc6edvK5ZIHIzyXV2BBgiG8cX4QHsBxvetOu6KSqpjd/qYaKXZHy+YZxvk2wCW79F 1hD2h/ISUeLkg== To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200918120416.7319-3-zane@zanevaniperen.com> In-Reply-To: <20200918120416.7319-1-zane@zanevaniperen.com> References: <20200918120416.7319-1-zane@zanevaniperen.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Subject: [FFmpeg-devel] [PATCH v2 2/7] avcodec/adpcm_{psx, argo}: add missing indent X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Zane van Iperen --- libavcodec/adpcm.c | 86 +++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index 14be1f4f88..4755308824 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -1966,42 +1966,42 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, case AV_CODEC_ID_ADPCM_PSX: for (int block = 0; block < avpkt->size / FFMAX(avctx->block_align, 16 * avctx->channels); block++) { int nb_samples_per_block = 28 * FFMAX(avctx->block_align, 16 * avctx->channels) / (16 * avctx->channels); - for (channel = 0; channel < avctx->channels; channel++) { - samples = samples_p[channel] + block * nb_samples_per_block; - - /* Read in every sample for this channel. */ - for (i = 0; i < nb_samples_per_block / 28; i++) { - int filter, shift, flag, byte; - - filter = bytestream2_get_byteu(&gb); - shift = filter & 0xf; - filter = filter >> 4; - if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) - return AVERROR_INVALIDDATA; - flag = bytestream2_get_byteu(&gb); - - /* Decode 28 samples. */ - for (n = 0; n < 28; n++) { - int sample = 0, scale; - - if (flag < 0x07) { - if (n & 1) { - scale = sign_extend(byte >> 4, 4); - } else { - byte = bytestream2_get_byteu(&gb); - scale = sign_extend(byte, 4); + for (channel = 0; channel < avctx->channels; channel++) { + samples = samples_p[channel] + block * nb_samples_per_block; + + /* Read in every sample for this channel. */ + for (i = 0; i < nb_samples_per_block / 28; i++) { + int filter, shift, flag, byte; + + filter = bytestream2_get_byteu(&gb); + shift = filter & 0xf; + filter = filter >> 4; + if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) + return AVERROR_INVALIDDATA; + flag = bytestream2_get_byteu(&gb); + + /* Decode 28 samples. */ + for (n = 0; n < 28; n++) { + int sample = 0, scale; + + if (flag < 0x07) { + if (n & 1) { + scale = sign_extend(byte >> 4, 4); + } else { + byte = bytestream2_get_byteu(&gb); + scale = sign_extend(byte, 4); + } + + scale = scale * (1 << 12); + sample = (int)((scale >> shift) + (c->status[channel].sample1 * xa_adpcm_table[filter][0] + c->status[channel].sample2 * xa_adpcm_table[filter][1]) / 64); } - - scale = scale * (1 << 12); - sample = (int)((scale >> shift) + (c->status[channel].sample1 * xa_adpcm_table[filter][0] + c->status[channel].sample2 * xa_adpcm_table[filter][1]) / 64); + *samples++ = av_clip_int16(sample); + c->status[channel].sample2 = c->status[channel].sample1; + c->status[channel].sample1 = sample; } - *samples++ = av_clip_int16(sample); - c->status[channel].sample2 = c->status[channel].sample1; - c->status[channel].sample1 = sample; } } } - } break; case AV_CODEC_ID_ADPCM_ARGO: /* @@ -2022,23 +2022,23 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, * They should be 0 initially. */ for (int block = 0; block < avpkt->size / avctx->block_align; block++) { - for (channel = 0; channel < avctx->channels; channel++) { - int control, shift; + for (channel = 0; channel < avctx->channels; channel++) { + int control, shift; - samples = samples_p[channel] + block * 32; - cs = c->status + channel; + samples = samples_p[channel] + block * 32; + cs = c->status + channel; - /* Get the control byte and decode the samples, 2 at a time. */ - control = bytestream2_get_byteu(&gb); - shift = (control >> 4) + 2; + /* Get the control byte and decode the samples, 2 at a time. */ + control = bytestream2_get_byteu(&gb); + shift = (control >> 4) + 2; - for (n = 0; n < 16; n++) { - int sample = bytestream2_get_byteu(&gb); - *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 4, shift, control & 0x04); - *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 0, shift, control & 0x04); + for (n = 0; n < 16; n++) { + int sample = bytestream2_get_byteu(&gb); + *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 4, shift, control & 0x04); + *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 0, shift, control & 0x04); + } } } - } break; case AV_CODEC_ID_ADPCM_ZORK: if (!c->has_status) { From patchwork Fri Sep 18 12:04:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 22472 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3CA0A44A787 for ; Fri, 18 Sep 2020 15:05:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2815168B96E; Fri, 18 Sep 2020 15:05:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.protonmail.ch (mail1.protonmail.ch [185.70.40.18]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C295068B87D for ; Fri, 18 Sep 2020 15:05:01 +0300 (EEST) Date: Fri, 18 Sep 2020 12:04:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail2; t=1600430700; bh=i+FyMpi4gwf0RFUHfFGTLaoIt6DoIe0x9wTa4+CrwX4=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=fHl6yhpNoiPrqYzFuKGIvbK++pJ3aCKWM1aBo4dP2Xa9SDBqI+YTpV5CA5Sjfq3W0 nfBIAgOiK9i7yrepmz6jMuvelNjGkVP34RCN8dFrOD/32ZBhsIxWQ8FmFZ5x+MUhME oBBZGux93g/kEyfuX0DmNWCdrJ7vVGLzvyeMupbeIOobK4N2gCuvUm6B68pLNq0HAk 1dlDKL/JoqiRCe55LOAWfCQLvVPgDk/E6JQmIpce9VZFXUGmuV+VVF/llR/Icun6QA iFNU20ezehV9lFFJium7fVg9BFRry3WIBIoz5McZ3sApjXmSbUYprOvjZ9h12F6rMd hjWOTalFAm/oQ== To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200918120416.7319-4-zane@zanevaniperen.com> In-Reply-To: <20200918120416.7319-1-zane@zanevaniperen.com> References: <20200918120416.7319-1-zane@zanevaniperen.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Subject: [FFmpeg-devel] [PATCH v2 3/7] avformat/argo_asf: read/write multiple blocks at once X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Zane van Iperen --- libavformat/argo_asf.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c index b1632f3ba5..048e5441d6 100644 --- a/libavformat/argo_asf.c +++ b/libavformat/argo_asf.c @@ -26,6 +26,9 @@ #include "libavutil/opt.h" #include "argo_asf.h" +/* Maximum number of blocks to read at once. */ +#define ASF_NB_BLOCKS 32 + typedef struct ArgoASFDemuxContext { ArgoASFFileHeader fhdr; ArgoASFChunkHeader ckhdr; @@ -37,6 +40,7 @@ typedef struct ArgoASFMuxContext { int version_major; int version_minor; const char *name; + int64_t nb_blocks; } ArgoASFMuxContext; void ff_argo_asf_parse_file_header(ArgoASFFileHeader *hdr, const uint8_t *buf) @@ -125,12 +129,10 @@ int ff_argo_asf_fill_stream(AVStream *st, const ArgoASFFileHeader *fhdr, * (nchannel control bytes) + ((bytes_per_channel) * nchannel) * For mono, this is 17. For stereo, this is 34. */ - st->codecpar->frame_size = st->codecpar->channels + + st->codecpar->block_align = st->codecpar->channels + (ckhdr->num_samples / 2) * st->codecpar->channels; - st->codecpar->block_align = st->codecpar->frame_size; - st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample; @@ -221,15 +223,21 @@ static int argo_asf_read_packet(AVFormatContext *s, AVPacket *pkt) if (asf->blocks_read >= asf->ckhdr.num_blocks) return AVERROR_EOF; - if ((ret = av_get_packet(pb, pkt, st->codecpar->frame_size)) < 0) + ret = av_get_packet(pb, pkt, st->codecpar->block_align * + FFMIN(ASF_NB_BLOCKS, asf->ckhdr.num_blocks - asf->blocks_read)); + if (ret < 0) return ret; - else if (ret != st->codecpar->frame_size) + + /* Something real screwy is going on. */ + if (ret % st->codecpar->block_align != 0) return AVERROR_INVALIDDATA; + pkt->stream_index = st->index; - pkt->duration = asf->ckhdr.num_samples; + pkt->duration = asf->ckhdr.num_samples * (ret / st->codecpar->block_align); + asf->blocks_read += (ret / st->codecpar->block_align); - ++asf->blocks_read; + pkt->flags &= ~AV_PKT_FLAG_CORRUPT; return 0; } @@ -277,6 +285,9 @@ static int argo_asf_write_init(AVFormatContext *s) return AVERROR(EINVAL); } + if (par->block_align != 17 * par->channels) + return AVERROR(EINVAL); + if (par->sample_rate > UINT16_MAX) { av_log(s, AV_LOG_ERROR, "Sample rate too large\n"); return AVERROR(EINVAL); @@ -364,24 +375,31 @@ static int argo_asf_write_header(AVFormatContext *s) static int argo_asf_write_packet(AVFormatContext *s, AVPacket *pkt) { - if (pkt->size != 17 * s->streams[0]->codecpar->channels) + ArgoASFMuxContext *ctx = s->priv_data; + AVCodecParameters *par = s->streams[0]->codecpar; + int nb_blocks = pkt->size / par->block_align; + + if (pkt->size % par->block_align != 0) return AVERROR_INVALIDDATA; - if (s->streams[0]->nb_frames >= UINT32_MAX) + if (ctx->nb_blocks + nb_blocks > UINT32_MAX) return AVERROR_INVALIDDATA; avio_write(s->pb, pkt->data, pkt->size); + + ctx->nb_blocks += nb_blocks; return 0; } static int argo_asf_write_trailer(AVFormatContext *s) { + ArgoASFMuxContext *ctx = s->priv_data; int64_t ret; if ((ret = avio_seek(s->pb, ASF_FILE_HEADER_SIZE, SEEK_SET) < 0)) return ret; - avio_wl32(s->pb, (uint32_t)s->streams[0]->nb_frames); + avio_wl32(s->pb, (uint32_t)ctx->nb_blocks); return 0; } From patchwork Fri Sep 18 12:04:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 22471 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5ABD044A787 for ; Fri, 18 Sep 2020 15:05:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 48BC768B921; Fri, 18 Sep 2020 15:05:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7342268B878 for ; Fri, 18 Sep 2020 15:05:00 +0300 (EEST) Date: Fri, 18 Sep 2020 12:04:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail2; t=1600430699; bh=V9DNeHd69AeP0IxOA5glxK6L+i1BqS3nI3xeKNN7eFI=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=JtI58wB0aQ2p5U5WYiZP9h13FVxGs9O69veMlkhsbcaTiZWIubXobT2rc3SASxdIh OUzprB9KlexWWpOr+SPjHFjyCdIC0Ggl1EyWElCwsPqnFy1VN2P/KxCc+7ffI6lmkL 3h/a2JJdJxpAFTtq512Q8CY/aELaIePfAm8ejlv9mTnu4dkr6lLSSdXCNUxfa+AAhd OKxuQYDBGqJYNQAqnKe/Geq7O7uZVlzX7CN5jDcg7S6Mjd6AjAeVV1B3z7MpX00him bU49feJ6uPo175sfLZppFhd7G8by8KTYlEvwc0s8uQZ5yb54WQG98LvjISgtVphrVx t54ViV7v4jXbg== To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200918120416.7319-5-zane@zanevaniperen.com> In-Reply-To: <20200918120416.7319-1-zane@zanevaniperen.com> References: <20200918120416.7319-1-zane@zanevaniperen.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Subject: [FFmpeg-devel] [PATCH v2 4/7] avformat/argo_asf: add ff_argo_asf_read() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" For the argo_brp demuxer. Signed-off-by: Zane van Iperen --- libavformat/argo_asf.c | 45 ++++++++++++++++++++++++------------------ libavformat/argo_asf.h | 2 ++ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c index 048e5441d6..0e9ccbd02f 100644 --- a/libavformat/argo_asf.c +++ b/libavformat/argo_asf.c @@ -144,6 +144,30 @@ int ff_argo_asf_fill_stream(AVStream *st, const ArgoASFFileHeader *fhdr, return 0; } +int ff_argo_asf_read(AVIOContext *pb, AVStream *st, AVPacket *pkt, + const ArgoASFChunkHeader *ckhdr, uint32_t blocks_read) +{ + int64_t ret; + + if (blocks_read >= ckhdr->num_blocks) + return AVERROR_EOF; + + ret = av_get_packet(pb, pkt, st->codecpar->block_align * + FFMIN(ASF_NB_BLOCKS, ckhdr->num_blocks - blocks_read)); + if (ret < 0) + return ret; + + /* Something real screwy is going on. */ + if (ret % st->codecpar->block_align != 0) + return AVERROR_INVALIDDATA; + + pkt->stream_index = st->index; + pkt->duration = ckhdr->num_samples * (ret / st->codecpar->block_align); + + pkt->flags &= ~AV_PKT_FLAG_CORRUPT; + return ret / st->codecpar->block_align; +} + #if CONFIG_ARGO_ASF_DEMUXER /* * Known versions: @@ -215,29 +239,12 @@ static int argo_asf_read_header(AVFormatContext *s) static int argo_asf_read_packet(AVFormatContext *s, AVPacket *pkt) { ArgoASFDemuxContext *asf = s->priv_data; - - AVStream *st = s->streams[0]; - AVIOContext *pb = s->pb; int ret; - if (asf->blocks_read >= asf->ckhdr.num_blocks) - return AVERROR_EOF; - - ret = av_get_packet(pb, pkt, st->codecpar->block_align * - FFMIN(ASF_NB_BLOCKS, asf->ckhdr.num_blocks - asf->blocks_read)); - if (ret < 0) + if ((ret = ff_argo_asf_read(s->pb, s->streams[0], pkt, &asf->ckhdr, asf->blocks_read)) < 0) return ret; - /* Something real screwy is going on. */ - if (ret % st->codecpar->block_align != 0) - return AVERROR_INVALIDDATA; - - - pkt->stream_index = st->index; - pkt->duration = asf->ckhdr.num_samples * (ret / st->codecpar->block_align); - asf->blocks_read += (ret / st->codecpar->block_align); - - pkt->flags &= ~AV_PKT_FLAG_CORRUPT; + asf->blocks_read += ret; return 0; } diff --git a/libavformat/argo_asf.h b/libavformat/argo_asf.h index eb2669a63f..e676dfb882 100644 --- a/libavformat/argo_asf.h +++ b/libavformat/argo_asf.h @@ -67,5 +67,7 @@ int ff_argo_asf_validate_file_header(AVFormatContext *s, const ArgoASFFileHeade void ff_argo_asf_parse_chunk_header(ArgoASFChunkHeader *hdr, const uint8_t *buf); int ff_argo_asf_fill_stream(AVStream *st, const ArgoASFFileHeader *fhdr, const ArgoASFChunkHeader *ckhdr); +int ff_argo_asf_read(AVIOContext *pb, AVStream *st, AVPacket *pkt, + const ArgoASFChunkHeader *ckhdr, uint32_t blocks_read); #endif /* AVFORMAT_ARGO_ASF_H */ From patchwork Fri Sep 18 12:05:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 22473 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 635DD44A787 for ; Fri, 18 Sep 2020 15:05:11 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5209968B9A3; Fri, 18 Sep 2020 15:05:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A265668B920 for ; Fri, 18 Sep 2020 15:05:09 +0300 (EEST) Date: Fri, 18 Sep 2020 12:05:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail2; t=1600430708; bh=FJ8i+/MVupiFAgt4lO/ZFK5P+Wt9XYU0bQgMZjxom4Y=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=JxmSf5lVvacI0nlKSTSl9Hs5061XbK3QOryFkeegs69nVmJ1q6Z3S7CEdVoNJXU1p 1ZqGEXoUSZECriqmlSNiEo0MRcwc3vv1vmxv8srK4IndBqNoA6Wy5zVbBDOSkBYhYg bWxux4L7/9W2ZN8DeyWg7ABk007nyS+XY/NgP9PybPamIJcbRp6TChx/mMDbTsofy+ auqYWLpfhWOUbz66PzdnFZz4cVFBwb6k2HJNNXhMGCxQvui6Oigqn7KWHyRiibYv9x udhN/qgcTezFpcHOPY3dRgDr0yRvM8a+DTfwB5rA8kKHoX65RIboVBXurHaIdzWux4 NTMncdvSy33Bg== To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200918120416.7319-6-zane@zanevaniperen.com> In-Reply-To: <20200918120416.7319-1-zane@zanevaniperen.com> References: <20200918120416.7319-1-zane@zanevaniperen.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Subject: [FFmpeg-devel] [PATCH v2 5/7] avformat/argo_brp: support reading multiple ASF blocks at once X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Zane van Iperen --- libavformat/argo_brp.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c index 122f616ecc..a3e9846c74 100644 --- a/libavformat/argo_brp.c +++ b/libavformat/argo_brp.c @@ -86,7 +86,7 @@ typedef struct ArgoBRPDemuxContext { struct { int index; ArgoASFChunkHeader ckhdr; - int64_t blocks_read; + uint32_t blocks_read; int64_t offset; /* ms, not samples. */ int64_t lastpts; @@ -340,13 +340,14 @@ static int argo_brp_read_basf(AVFormatContext *s, AVPacket *pkt, ArgoBRPDemuxContext *brp, int ignorepts) { ArgoASFChunkHeader *ckhdr = &brp->basf.ckhdr; - AVCodecParameters *par; + AVStream *st; int64_t ret, old; + uint32_t blocks_read; if (brp->basf.index < 0) return 0; - par = s->streams[brp->basf.index]->codecpar; + st = s->streams[brp->basf.index]; if (brp->basf.blocks_read >= ckhdr->num_blocks) return 0; @@ -364,21 +365,20 @@ static int argo_brp_read_basf(AVFormatContext *s, AVPacket *pkt, else if (ret != brp->basf.offset) return AVERROR(EIO); - if ((ret = av_get_packet(s->pb, pkt, par->frame_size)) < 0) + if ((ret = ff_argo_asf_read(s->pb, st, pkt, ckhdr, brp->basf.blocks_read)) < 0) return ret; + blocks_read = ret; + if ((ret = avio_seek(s->pb, old, SEEK_SET)) < 0) return ret; else if (ret != old) return AVERROR(EIO); - pkt->stream_index = brp->basf.index; - pkt->duration = ckhdr->num_samples; - brp->basf.offset += pkt->size; - brp->basf.blocks_read += 1; - /* Need the ceil() because ((32 * 1000) / 44100) < 1 */ - brp->basf.lastpts += ceilf((ckhdr->num_samples * 1000.0f) / ckhdr->sample_rate); + brp->basf.blocks_read += blocks_read; + /* Need the ceil() because ((1 * 32 * 1000) / 44100) < 1 */ + brp->basf.lastpts += ceilf((blocks_read * ckhdr->num_samples * 1000.0f) / ckhdr->sample_rate); return 1; } From patchwork Fri Sep 18 12:05:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 22474 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 37F8544A787 for ; Fri, 18 Sep 2020 15:05:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1D0D968B9C7; Fri, 18 Sep 2020 15:05:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail2.protonmail.ch (mail2.protonmail.ch [185.70.40.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A53BC68B94F for ; Fri, 18 Sep 2020 15:05:15 +0300 (EEST) Date: Fri, 18 Sep 2020 12:05:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail2; t=1600430714; bh=86ozy6Bigk2Ha1D8YCpLitzNDicQJZxQne9rj7zUiP0=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=jPBwSaI1LOldVv6PUQ5AK7p0ArhuqGmj0XXqBKBb7LjrfXG1Ryr4pf6OUBUt74lh/ D2yzW2vx4wMVvFoinJHwnaKHB4CATiY6nnoFoQ05otTu2vp2Q0WNW3UR1ZpdyzVBRI YTmS2gAIURJjxX/Fl74p08ADJo2I+r88fuS4P/vZprjdcsa3g58uCDlSsIsv/5OYun XkugbSn3vI6ZMnAdF0Xm4HCVeZ1Jy6ifQXO6SFJ151wpwq48Ui8Vo0GClaxVyP4r3P duQKOZAUPT1H6tYNe2Vecce5EWZdNVNO00B1Unq/s/ElzdQ8klsa1KfC2Z6E7rS8Dg 71GA9RzoOgZSg== To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200918120416.7319-7-zane@zanevaniperen.com> In-Reply-To: <20200918120416.7319-1-zane@zanevaniperen.com> References: <20200918120416.7319-1-zane@zanevaniperen.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Subject: [FFmpeg-devel] [PATCH v2 6/7] avformat/argo_brp: remove usage of floats X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Zane van Iperen --- libavformat/argo_brp.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c index a3e9846c74..3a5a0c0497 100644 --- a/libavformat/argo_brp.c +++ b/libavformat/argo_brp.c @@ -78,8 +78,8 @@ typedef struct ArgoBRPStreamHeader { typedef struct ArgoBRPDemuxContext { ArgoBRPFileHeader fhdr; ArgoBRPStreamHeader *streams; - /* To know how much of a BASF to give. */ - int64_t lastpts; + /* Current PTS converted into BASF timebase (samples). */ + int64_t currpts; int hit_eof; /* BASF-specific fields. */ @@ -88,7 +88,6 @@ typedef struct ArgoBRPDemuxContext { ArgoASFChunkHeader ckhdr; uint32_t blocks_read; int64_t offset; - /* ms, not samples. */ int64_t lastpts; } basf; } ArgoBRPDemuxContext; @@ -352,7 +351,7 @@ static int argo_brp_read_basf(AVFormatContext *s, AVPacket *pkt, if (brp->basf.blocks_read >= ckhdr->num_blocks) return 0; - if (!ignorepts && brp->lastpts < brp->basf.lastpts) + if (!ignorepts && brp->currpts < brp->basf.lastpts) return 0; if ((ret = avio_tell(s->pb)) < 0) @@ -377,8 +376,7 @@ static int argo_brp_read_basf(AVFormatContext *s, AVPacket *pkt, brp->basf.offset += pkt->size; brp->basf.blocks_read += blocks_read; - /* Need the ceil() because ((1 * 32 * 1000) / 44100) < 1 */ - brp->basf.lastpts += ceilf((blocks_read * ckhdr->num_samples * 1000.0f) / ckhdr->sample_rate); + brp->basf.lastpts += blocks_read * brp->basf.ckhdr.num_samples; return 1; } @@ -434,7 +432,13 @@ static int argo_brp_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->stream_index = blk.stream_id; pkt->pts = blk.start_ms; - brp->lastpts = FFMAX(brp->lastpts, blk.start_ms); + + if (brp->basf.index >= 0) { + int64_t pts = av_rescale_rnd(blk.start_ms, brp->basf.ckhdr.sample_rate, + 1000, AV_ROUND_UP); + brp->currpts = FFMAX(brp->currpts, pts); + } + return 0; } From patchwork Fri Sep 18 12:05:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 22475 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 17C4944A787 for ; Fri, 18 Sep 2020 15:05:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F199768B9C4; Fri, 18 Sep 2020 15:05:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D079268B976 for ; Fri, 18 Sep 2020 15:05:21 +0300 (EEST) Date: Fri, 18 Sep 2020 12:05:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail2; t=1600430721; bh=dmRxASJrA1p8WwMkKUXGaIOJqlEDl1qF+flj2IX+AJY=; h=Date:To:From:Cc:Reply-To:Subject:From; b=jDewuxIMZySoHH5bbJdSfodzS3l27cbdrYHYGUaSvU1xeSSXH8Ly0V1kuD82/RpIe GunCTX1mEY1AFF8G6GhngPKM/NgEGvtIWkuuZckpNSz5G3aznDlnxi8LhxpdSQ0quM 3Tvn5ENnpQmKIRuYw2WKvrCPARr+6fwTnU2IrJfu+5cPIuqH1R7/khYE56izsoWkff i0Hg/bF2D5ykrlhSFOyyJOPOi/8hNGQ1a28XY96kNeFJNf9VEGhjXTXrmn0S7m7ioh SjXzh/K9e9M86P0ubjQH5TER+ncb+Wh7ICxlulyVPJXGWjqSab5G+HnTmVu3pidTGK U5CoP2jWTot3Q== To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200918120416.7319-8-zane@zanevaniperen.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Subject: [FFmpeg-devel] [PATCH v2 7/7] fate: add argo_adpcm via argo_brp demux test X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Zane van Iperen --- tests/fate/adpcm.mak | 3 +++ tests/ref/fate/adpcm-argo-brp | 1 + 2 files changed, 4 insertions(+) create mode 100644 tests/ref/fate/adpcm-argo-brp diff --git a/tests/fate/adpcm.mak b/tests/fate/adpcm.mak index c75a756bc3..0d6a671d34 100644 --- a/tests/fate/adpcm.mak +++ b/tests/fate/adpcm.mak @@ -94,6 +94,9 @@ fate-adpcm-argo-mono: CMD = md5 -i $(TARGET_SAMPLES)/argo-asf/PWIN22M.ASF -f s16 FATE_ADPCM-$(call DEMDEC, ARGO_ASF, ADPCM_ARGO) += fate-adpcm-argo-stereo fate-adpcm-argo-stereo: CMD = md5 -i $(TARGET_SAMPLES)/argo-asf/CBK2_cut.asf -f s16le -af aresample +FATE_ADPCM-$(call DEMDEC, ARGO_BRP, ADPCM_ARGO) += fate-adpcm-argo-brp +fate-adpcm-argo-brp: CMD = md5 -i $(TARGET_SAMPLES)/argo-brp/CROCLOGO_CUT.BRP -f s16le -af aresample + FATE_ADPCM-$(call DEMDEC, KVAG, ADPCM_IMA_SSI) += fate-adpcm-ima-ssi-mono fate-adpcm-ima-ssi-mono: CMD = md5 -i $(TARGET_SAMPLES)/kvag/mull1_cut.vag -f s16le diff --git a/tests/ref/fate/adpcm-argo-brp b/tests/ref/fate/adpcm-argo-brp new file mode 100644 index 0000000000..8fcc3183ba --- /dev/null +++ b/tests/ref/fate/adpcm-argo-brp @@ -0,0 +1 @@ +81183a0037984d6d0e84809e59ae80d7