From patchwork Thu Sep 8 11:36:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jyrki Vesterinen X-Patchwork-Id: 37761 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp224759pzh; Thu, 8 Sep 2022 04:39:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Km1QKA4TFeQwg429dFKaXrEvTACKXCAIW7dSFa+lI+p1K3IK9IILB+CrTjONbGUmQbybx X-Received: by 2002:a17:907:7e90:b0:770:87c4:530c with SMTP id qb16-20020a1709077e9000b0077087c4530cmr4402156ejc.356.1662637170444; Thu, 08 Sep 2022 04:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662637170; cv=none; d=google.com; s=arc-20160816; b=AwDBeF7uXK1fhExrsgUs2Dl4XpGIrqV8kv1Gx1MbnK7XmM7juSPbhUxisbgQrOhNtb QUcbYpcYelhD3Q4r5qfpYpZ83fgn36VuyTrREdCV6oEPp3hZVxt7ufA3Pef79W1vawSe UmPUREYxMx2iC15h5y2IwOoccZ/q2zjFwfICSLIlEudmRL5TNIaeSegpMgYiG/hGapj6 YQv/r6/NTRiSIo6HCS/fRPi0I6p2RmiYc/LkSyWk+GPjbXMhR2QRkeEqHe9/kV7aQI6i InRlXjJuyCFbOAGu5RfWCvnVyucY4PpBxip0LbzsfzTNd9BjF4oP6OAYGL+BEN+xqERL yfpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=Q1t2VCi1/6/NmDumlf0UKGsxYq8RNn+nBUnCCfPaJa4=; b=WknnxhPp3sS5VBPi9i/78BF2j1FacKq/CkkkQTFWKARhOMqHYdHhnHCkijjvntiDfE 81M3J7zzvTXIX0O45cQXKj1l/spWvggvlb5t6J50kVSh24ylQj1lBnGxGh4szHkZiI0J EpcUdKViuFxjqJ+W2Baj/XiogB0OaCxJv5Qd4TroYKS1PlKkZBpIgHZC5hx4qEfULc+H BstvX0P9uDS0IxFi7+tKGof1VR3OEsLKJuFQUXJCZuTtLIRGi1Cdh6yD7gwEjFPhs/hg ddLy+zCJdlmNu5zgIs9iDixVL4mtn3HYLZfgAUM2SSyKfqVxt0Z3FBSiS3EpDem4/AGk ffrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nekonyansoft.com header.s=default header.b=Hgol92YP; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ez16-20020a056402451000b0044e9ceecfcasi5825476edb.69.2022.09.08.04.39.29; Thu, 08 Sep 2022 04:39:30 -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=@nekonyansoft.com header.s=default header.b=Hgol92YP; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F1A1668BA6C; Thu, 8 Sep 2022 14:39:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from delivery24.mailspamprotection.com (delivery24.mailspamprotection.com [185.56.85.147]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CBD6E68B5FF for ; Thu, 8 Sep 2022 14:39:20 +0300 (EEST) Received: from 84.179.214.35.bc.googleusercontent.com ([35.214.179.84] helo=c48742.sgvps.net) by se24.mailspamprotection.com with esmtps (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1oWFsK-0005Y5-Sa for ffmpeg-devel@ffmpeg.org; Thu, 08 Sep 2022 06:39:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nekonyansoft.com; s=default; h=Date:Subject:Cc:To:From:list-help: list-unsubscribe:list-subscribe:list-post:list-owner:list-archive; bh=6CtaJjacg0Mu6997qRmmAFOJJrMuppGXf3qgk+Vtqzs=; b=Hgol92YPSfGpNUeqhlqjdLP7gR 9lafvVQb94Co1g4IlLqlaC3SfCkEsivoUoaAXqmlb2LCrtsv9yCDC1uwBv8HrvGVtni55f/0ztjph wPOtO5//AKG3+uEhOKrjtfCOvY/fRK6d2krBrbCqxjD/g/YvEDRtn2O3R6YNyy3uetYKVvlpXPoyY sDJspDmrLralP+ynUIjlAOQkGl8PtVhb2T/FuVhGydc/0mxdpS/u4s+pq6jPBUqrlXlcAuga+iR+h d2UQhhhlk7Wzd00aBGBjas5sCFDJ2taRJlgBSYzO66mTfzLE8mrKPA+6d2bvfWPUI7iGPWK5fayEF mGTqV87A==; Received: from [91.155.28.235] (port=22544 helo=localhost.localdomain) by c48742.sgvps.net with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1oWFsJ-000Gyh-0f; Thu, 08 Sep 2022 11:39:15 +0000 From: jyrkive@nekonyansoft.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Sep 2022 14:36:32 +0300 Message-Id: <20220908113632.1056-2-jyrkive@nekonyansoft.com> X-Mailer: git-send-email 2.37.2.windows.2 In-Reply-To: <20220908113632.1056-1-jyrkive@nekonyansoft.com> References: <20220908113632.1056-1-jyrkive@nekonyansoft.com> MIME-Version: 1.0 X-Originating-IP: 35.214.179.84 X-SpamExperts-Domain: c48742.sgvps.net X-SpamExperts-Username: 35.214.179.84 Authentication-Results: mailspamprotection.com; auth=pass smtp.auth=35.214.179.84@c48742.sgvps.net X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00884866704702) X-Recommended-Action: accept X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT9F1bJ4mdLLNAGrHgCU9o7rPUtbdvnXkggZ 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5wGCFY+AjIRjB/MjRwOktyH1tEYR2R5SyiZFi8HY1udE+fH zJ6mVE7ewsipSVIfs4b+9E0WmpTSpW6m2c46Ji3MABHVTw1lV42ob3hDgXVUNQA9aWzfhGZBVqCj 3n5LjLrsoSGHtY2FCzlTS6F/+Ijn9pP2iGeMkOesmXeAAVAJRungggsTCr1Q2fZdAqMwzJaU/xXC AhbcQGlvnWB9Qx3YX7FmoqNk/FPN9ta8ZcqdCU2znmgwNPolqJQG3AxT/YPw4NFIHfIpz8O/5qlP IqvrpUPbMf9O8CgYeYyUnjcYmKqtq91FtNaEifsIGx4HWl103qfAvdYY4Q+cvDw4EdcHTcWsqU26 dvDcYIYzaKVPzmqo+CiEiEUieTH4xPDmrp2RMmGH+05pSN4hHKlyuAOtQoRzEBwjBFk1/RxIcEj+ PzEpfpnr9DPXDtMT9vPdg9HiqWHpandwa23xIBX/5QDWmB6IPkXGG9JgOfqy+Vn9+9OBNmHuBD0x 1DOUblsk+Z51thv0hd9gZGlVL/SEDgzCZT1y7HRMh23/ZmvGhR+Ph3GlfXdmgJrKjBlTpWs78y/C kdUpn8A2iMkLHL7hKRavnHl2TRtBFGxCwNLr/WIXTuiLqQuUai4/5Ov8Jofs7uvDx9dgYfO2muGH 2bNdOKfOzon1aL1KuwjoHteKIt8tLa0jiD6XqsJZtjQxlyCdsewZj4ehUr2AA4bd36qmsDvqgneY l2CbmQ1c/RYOiDQqnuZTbIkw7OrgjG4YjznSVhSmBFjNJsRWaYlnhok/1lwDtkCt5fUn0xBNkOXz +TISHCzo6zsMBiN5CrtOSZw5b+4u1osW/yRYn9rKlSNZ13STJnrd1GHfm/8EfxEfJoN7y9/67G/L WUIEfx8LYBzzK2DND3zv8/U0LYqcc8B57rRavI4HKFvQVrsc8Hxb+exhFh0rgNoi22hXjxX1cMFL TLA9CI9WZAMCAIC+/DBPJpTeURFFqFgMUKTnkPlNoIewDvUf9oDBqtClgM5jH/om1Q5NyVWpuowZ cOk49R7WYjqocABNJQ5m9U9aj1IjdsdEkJPNryPhH4lKeinv12/T+iWceXZNG0EUbELA0uv9YhdO 7yCUgX8YuF5WBQr1Bq8618i3o+lX1LSl41CObu4hRe9Hp8CQCR/RQfam37OSH+Sv X-Report-Abuse-To: spam@quarantine1.mailspamprotection.com Subject: [FFmpeg-devel] [PATCH] avcodec: Vorbis decode: don't use a flag to determine if frames have been output 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: Jyrki Vesterinen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 2v2bPMrz6r4T From: Jyrki Vesterinen If a developer using FFmpeg libraries seeks into an earlier position and calls avcodec_flush_buffers() afterwards as recommended, the Vorbis decoder will drop the next frame, since buffer flushing clears the first_frame flag. As a result, the audio samples the calling code receives may be ahead of the requested seek position, which is unacceptable in some use cases such as playing a looping sound effect. This commit records the presentation timestamp of the first frame and determines after that if the new frame is the first frame (possible after seeking to the start) by comparing its pts to the stored pts. --- libavcodec/vorbisdec.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c index 4d03947c49..38a5367be3 100644 --- a/libavcodec/vorbisdec.c +++ b/libavcodec/vorbisdec.c @@ -131,6 +131,7 @@ typedef struct vorbis_context_s { FFTContext mdct[2]; uint8_t first_frame; + int64_t initial_pts; uint32_t version; uint8_t audio_channels; uint32_t audio_samplerate; @@ -1847,6 +1848,10 @@ static int vorbis_decode_frame(AVCodecContext *avctx, AVFrame *frame, if (!vc->first_frame) { vc->first_frame = 1; + vc->initial_pts = frame->pts; + } + + if (frame->pts == vc->initial_pts) { *got_frame_ptr = 0; av_frame_unref(frame); return buf_size; @@ -1881,7 +1886,6 @@ static av_cold void vorbis_decode_flush(AVCodecContext *avctx) sizeof(*vc->saved)); } vc->previous_window = -1; - vc->first_frame = 0; } const FFCodec ff_vorbis_decoder = {