From patchwork Fri May 5 13:28:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Beauxis X-Patchwork-Id: 41495 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp490781pzb; Fri, 5 May 2023 06:35:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4tMnpHScs7+/LsedfvbRlB8jwzfd7yr5gTYBXweytz7JyG7d2v6UqcZwfDBAH9QE7mpl7P X-Received: by 2002:a17:907:36c1:b0:94e:e082:15b2 with SMTP id bj1-20020a17090736c100b0094ee08215b2mr1175046ejc.55.1683293754366; Fri, 05 May 2023 06:35:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683293754; cv=none; d=google.com; s=arc-20160816; b=OQNHDXWF0SwqEe4aAXtUfGjSu1zK3WnpaFTKZpJ45JSulgRiKEm7fbGr7lgk59Op6n KcEVa1j2w9ayA96XvJUetL3DFvCQFm/H3e+htnOsjLhPL5zEf2b78fgZh5Pd83NJUyWX Evn67VYikVPH3wrVpwVGrsvHpxLD8+IcB/s6iOIGAzkpn0gndwXsKk6b+N/SVo1Z+vGY y+mkR/wUXVXPMTaFlbYFKhA4myYwazsAcYiHRLbCiHNZfzbcHklT8nis5FKyvbShoP2n +HKJSd1fntFcTY2Ot/9Kksxim50nTGhTEf0WkheNgEVx7mKAy2yZSxYB2SDsgQJmiBZL 9EzQ== 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:delivered-to; bh=N3a4ttKjRO8RlzTJaJXfYCNz4KXreKSAaGgncvZgIfA=; b=H424G9No0ZrE81tDcn1IOiIfbFQN86ru/hx0rwlR+8ksgpQSOQesrJzZMOlOrlN7Ny 7S3lgpOuRk+DtLe8A/YjkxeWVruaNznFqgHv76QXgzMEcKCbJogvP+JHUv7z7E/it1YQ aCXRiRsLs6+ybsA9YqoWG59KIa2hf1b6xT4u/t767cH8IoZ5Lk3Bk0ulbIL5QK0vuAiG /qmloXRPFZuzn1FFdamQKxMuRMv56yFvhQwfS3lCmvc+/1oDJvscxiMP5PigjKAfpS4o 8VD739mT+KKZKnUITGPN6dIFtXcfJe0N7a+TAVNxnpqGu6h9xARvkby9zKVWSq9p7t9d dBkQ== ARC-Authentication-Results: i=1; mx.google.com; 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 t20-20020a170906a11400b009657d1363aesi1204563ejy.720.2023.05.05.06.35.53; Fri, 05 May 2023 06:35:54 -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; 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 A9E7868BF84; Fri, 5 May 2023 16:35:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 506B6689C6C for ; Fri, 5 May 2023 16:35:44 +0300 (EEST) Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-6a5fbc19fe1so245828a34.0 for ; Fri, 05 May 2023 06:35:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683293742; x=1685885742; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/0badzPwzBismL4bSUmp/Lygn9Neap+39r0ZDR6ilz0=; b=hx4HJp1SgUnqrRhOU+3rekw0GSEryttaf6v1DjRXtDYZ8iWHtK1qCVg4RQ2cE/bHFH nFjlQF0zRrxUVADhUafmXTpaNZSIS5ypS+RLwqR0YBixvXdF+pqNuU8liCn+Tp8ebByA Hwvog3Us/5che2xl64YjhRdk40q77ks6z/ZupVKMbm6n/fFwZMmkN9jOUKr7fwv7W49b RSoTl5lZjN+rpGx8gs6iSaCe5zC3DnDdcOhjdATzAIE3mMWM/gamMxS6wDsmYBrj2phF x3gSHMQ/QQiiWWMgN7J0C0kDak3+nZjnBvpz4Cm3MO/6YUfhycT6G2tLp6YC/HNTs9yL La7A== X-Gm-Message-State: AC+VfDyWd52don4179nFxaidyLd++5vXKH6MrxWpkuC0NrcPhzRGs9XV EsJTOK0AD+xYwdrQ0Q7Sm9LQhu3nHi6G2Q== X-Received: by 2002:a05:6830:3585:b0:6a5:e5a0:dd71 with SMTP id bd5-20020a056830358500b006a5e5a0dd71mr460568otb.2.1683293742479; Fri, 05 May 2023 06:35:42 -0700 (PDT) Received: from romains-mbp.lan (ip24-252-77-224.no.no.cox.net. [24.252.77.224]) by smtp.gmail.com with ESMTPSA id h5-20020a9d6405000000b006a632c6af05sm801469otl.54.2023.05.05.06.35.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 05 May 2023 06:35:42 -0700 (PDT) From: toots@rastageeks.org To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 May 2023 08:28:51 -0500 Message-Id: <20230505132848.18011-3-toots@rastageeks.org> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230505132848.18011-1-toots@rastageeks.org> References: <20230505132848.18011-1-toots@rastageeks.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/3] libavformat/oggdec.c: keep reading on empty packets to accommodate for chained bitstreams. 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: Romain Beauxis Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: SeJfwckRkA6m From: Romain Beauxis This patch is the last of a series of patch to enhance FFmpeg's handling of chained ogg streams. Documentation for chained (and multiplexed) ogg bitstream can be found here: https://xiph.org/ogg/doc/oggstream.html My understanding of the current code is that the ogg demuxer will process all pages from the current ogg track and, after reaching the last page, if another page follows, will try to match the new stream with the previous one using its codec. (See ogg_replace_stream in libavformat/oggdec.c). Meanwhile, the underlying resources for the old stream are destroyed and new resources are created. There seems to be issues with flushing remaining data in such cases (see oggvorbis_decode_frame in libavcodec/libvorbisdec.c). However, on the ogg bitstream side, sending an empty packet as the last packet of the stream is common practice in ogg/opus streams. For this reason, the previous patch in this series allowed opus_packet in libavformat/oggparseopus.c to process empty EOS packets without failing the stream for having invalid data. However, if this packet is allowed to go through ogg_read_packet in libavformat/oggdec.c, then the returned size from the function is 0, which results in a EINVAL error while reading the stream. Thus, this patch makes it so that empty packets are ignored. The bitstream is read further and, if it ends, a proper EOF is returned. Otherwise, a new chained bitream can begin and the demuxer can try to match it. Without this patch, typically, decoding a chained ogg/opus stream with a final empty ogg packet (very common) raises an error on each end of track. To reproduce or test: - Try this command: ffmpeg -re -i http://content.radiosega.net:8006/rs-opus-low.ogg \ -loglevel verbose -f null - This a typical log on track change before this series of patch is applied: <---- LOG BEGIN HERE ----> [ogg @ 0x13b004080] Packet processing failed: Invalid data found when processing input Error demuxing input file 0: Invalid data found when processing input Terminating demuxer thread 0 http://content.radiosega.net:8006/rs-opus-low.ogg: Invalid data found when processing input No more output streams to write to, finishing. [out#0/null @ 0x600000b5c180] All streams finished [out#0/null @ 0x600000b5c180] Terminating muxer thread size=N/A time=00:00:43.12 bitrate=N/A speed= 1x video:0kB audio:8089kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown Input file #0 (http://content.radiosega.net:8006/rs-opus-low.ogg): Input stream #0:0 (audio): 2161 packets read (229129 bytes); 2157 frames decoded (2070720 samples); Total: 2161 packets (229129 bytes) demuxed Output file #0 (pipe:): Output stream #0:0 (audio): 2157 frames encoded (2070720 samples); 2157 packets muxed (8282880 bytes); Total: 2157 packets (8282880 bytes) muxed [AVIOContext @ 0x13b104080] Statistics: 273900 bytes read, 0 seeks <---- LOG END HERE ----> (stream processing stops afterward) This means that, currently, the ffmpeg command line is not able to process chained ogg/opus that typically end with an empty packet beyong its first track. After the patch series is applied: processing continues sucessfully. --- libavformat/oggdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c index 3b19e0bd89..b0d850a406 100644 --- a/libavformat/oggdec.c +++ b/libavformat/oggdec.c @@ -835,7 +835,7 @@ retry: ret = ogg_packet(s, &idx, &pstart, &psize, &fpos); if (ret < 0) return ret; - } while (idx < 0 || !s->streams[idx]); + } while (idx < 0 || !s->streams[idx] || psize == 0); ogg = s->priv_data; os = ogg->streams + idx;