From patchwork Fri Apr 26 21:58:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 12921 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 40168446EBD for ; Sat, 27 Apr 2019 00:58:38 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 26F9168A610; Sat, 27 Apr 2019 00:58:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B07F96882D6 for ; Sat, 27 Apr 2019 00:58:31 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id c12so6298024wrt.8 for ; Fri, 26 Apr 2019 14:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=UEu5u+VKYCrR/HwFqc55JbdGOQWS2DCM2chJNwlAGp4=; b=hXIJgG2OMY32C0qb4oZYXB7tCX1JPKK753loe4/X+S0+xPvjpzHCB81+rbHwHHBKXK jRovGmng/DQBbQEP5hAuWqU1zv7bhFwbEyCE5lOn6QLcSZki1vkgTLVS/y1q+n0BOO1X 98RYxKPhDgm3WeN5a8mb/DjZGY0W4wa2iY/UBAu1likuJagqg/M150YQM/9UczAYnzja 2LHFtTbdTPbm/JzfQ/cEpFlxjRGnXO/tSe0Dt886zEchDNaXQAc+8kJWiDisXcLI9Da5 Hx3ylBpragIyNQz/vVNFdMVOmib1fGENXUu1To2jSOfytPxW37/0MJvWbONoU6j+QWkU cnZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=UEu5u+VKYCrR/HwFqc55JbdGOQWS2DCM2chJNwlAGp4=; b=q1V7Z7wac8XfyddJ8QgwDYvNzQl+0yPA9j+b3EGxHupThpvChu2p0f8yJl7ctFVY8C /b2lTstLDxlSLYbSmRQcBj39tgXKpoBe9zlVPw521oCgOanFeu+DAJX3Uzqz9L2XNOhO Oa8IJXCYoOrzl5YRcZkg6ogzg7nAiPJ2HK2z40wzwd5geT/yt2ikR8bHZlpBFKt8FlnS pomrJc5vJwTiXsP2dl5q0uajGQAqOTlqxpCZOP31ozggz0dYAP++pQSmk1GvrTGayGqF LFO+l4TE0OlAuCyhPsOGRlihBzwM7Gmi+4C58/asWFjdBr+TaDNocnWnW4786rbEryFS d59g== X-Gm-Message-State: APjAAAU6VjjyGWvhACOtZcJfyV8xQ5CEOlDTVuYox4XGcdyvNyWD0naw plgmKu1UkSvLyBrL9EL8rawApeYJ X-Google-Smtp-Source: APXvYqyVvEf3n8g/64fdr5u9yKPSaElJK/i6Vb72L4Q/b6kvouTDc9ep49dJ7KQbGAFfoErTqKXnNA== X-Received: by 2002:adf:fcc8:: with SMTP id f8mr18411574wrs.250.1556315910729; Fri, 26 Apr 2019 14:58:30 -0700 (PDT) Received: from localhost.localdomain ([109.227.49.68]) by smtp.gmail.com with ESMTPSA id o1sm36592816wmh.47.2019.04.26.14.58.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Apr 2019 14:58:29 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 26 Apr 2019 23:58:21 +0200 Message-Id: <20190426215821.12388-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avformat/oggdec: improve playback of chained opus file 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Improves decoding of: https://jmvalin.ca/misc_stuff/chain_works.opus Signed-off-by: Paul B Mahol --- libavformat/oggdec.c | 10 +++++++++- libavformat/oggdec.h | 1 + libavformat/oggparseopus.c | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c index e815f42134..8f9ff69d70 100644 --- a/libavformat/oggdec.c +++ b/libavformat/oggdec.c @@ -177,6 +177,7 @@ static int ogg_reset(AVFormatContext *s) if (start_pos <= s->internal->data_offset) { os->lastpts = 0; } + os->start_trimming = 0; os->end_trimming = 0; av_freep(&os->new_metadata); os->new_metadata_size = 0; @@ -237,6 +238,11 @@ static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int nsegs) os = &ogg->streams[i]; os->serial = serial; + os->header = -1; + os->lastpts = 0; + os->lastdts = 0; + os->start_trimming = 0; + os->end_trimming = 0; return i; #if 0 @@ -846,13 +852,15 @@ retry: pkt->duration = os->pduration; pkt->pos = fpos; - if (os->end_trimming) { + if (os->end_trimming || os->start_trimming) { uint8_t *side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10); if(!side_data) goto fail; + AV_WL32(side_data + 0, os->start_trimming); AV_WL32(side_data + 4, os->end_trimming); + os->start_trimming = 0; os->end_trimming = 0; } diff --git a/libavformat/oggdec.h b/libavformat/oggdec.h index 4a2b6ddee8..b4eb6e31d2 100644 --- a/libavformat/oggdec.h +++ b/libavformat/oggdec.h @@ -84,6 +84,7 @@ struct ogg_stream { int got_start; int got_data; ///< 1 if the stream got some data (non-initial packets), 0 otherwise int nb_header; ///< set to the number of parsed headers + int start_trimming; ///< set the number of packets to drop from the end int end_trimming; ///< set the number of packets to drop from the end uint8_t *new_metadata; unsigned int new_metadata_size; diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c index cd34cf23ba..e6e0780df5 100644 --- a/libavformat/oggparseopus.c +++ b/libavformat/oggparseopus.c @@ -58,6 +58,7 @@ static int opus_header(AVFormatContext *avf, int idx) priv->pre_skip = AV_RL16(packet + 10); st->codecpar->initial_padding = priv->pre_skip; + os->start_trimming = priv->pre_skip; /*orig_sample_rate = AV_RL32(packet + 12);*/ /*gain = AV_RL16(packet + 16);*/ /*channel_map = AV_RL8 (packet + 18);*/