From patchwork Sun Apr 21 15:18:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 48200 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c906:b0:1a9:af23:56c1 with SMTP id gx6csp1790412pzb; Sun, 21 Apr 2024 08:19:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUPVPD19R2oVx4zjTdUrT+ndTS9qPgPGS9uOWD68YQvzpOd74ZeeBtpaYC+nUNacQQDFGEGUtzz3u69HBRMTsgMZdSc9uGU66j7hw== X-Google-Smtp-Source: AGHT+IGjdWz8GPQjhxIQtfg663v+yBgDjGYZYNvLJY/K+KrNaw3OipYTOtsnsVge7JAxvPiytwqb X-Received: by 2002:a19:6908:0:b0:515:d5e6:d48c with SMTP id e8-20020a196908000000b00515d5e6d48cmr4203162lfc.0.1713712775413; Sun, 21 Apr 2024 08:19:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713712775; cv=none; d=google.com; s=arc-20160816; b=ceA6VRQjdeGaxnLVVHm9Szm1KYvcDmZwHONWFkmwhp7UByBJCjXCa5iu7o+kuxjcUb +QvjRHLFsiO+x+gsPi/6VxpbqVne9RrNBrp23iOwtb/kSupfO+Uo/ZaRS8u4441BGrkW FwQp3CemBzE5TQj+xbVUfj5mkY8OUn0GU7m8aaULH9IxcMFP7OxaiBmHt+yKy2FHr5U3 kXmAyJ2n6PTxMVwCPAE8YKCpRCsyaSrBQPh0bxeqHWtvyqr60RLxW/23e2pxBcCBHy8q ug2lSgcHUPtz5PXdPgyk/43ODr1yZ9kVTr7NZiSyKACKXpmSFMWp9E4fNIX6o0wmOonc nhdA== 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=x5BgFjyz8xF0Gzd2tqd1PkdakFDAN/lkKL/D5u+RV20=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=duD/N9hjOebCGUxMoFm4FDf537soePrFfSntDuauH8pHhCANc1DItoRpqGxviJq2H0 EzsjVVTuKoKwEPGmlB1NVOLPPVeNsKnFCPSE56Fq3tNOz1KicScUcbakyo1asn2Mtivv PreXe6kgHRjUs4ll8K+wXZxL0b9rpMs33tQfYPOR0PhSFU2KqHD1jzuaIso3orsrLhuo jdhKJW+lFNprHsR2DXqPK5UaAfcnRbS/uw52yroExd5NVEH9JupXgiT3jQbwOn5HhL+7 ++KBPZralEt/JZ6L2UCevs8O+JfDgmmKRGlU+cHyMUhNlIzP8QA+ztDsJC7Y4qG4yzIf nIlQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=EYVJDN72; 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 w1-20020a05651204c100b005178a7762c7si2571015lfq.371.2024.04.21.08.19.35; Sun, 21 Apr 2024 08:19:35 -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=@gmail.com header.s=20230601 header.b=EYVJDN72; 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 AB8A968C89D; Sun, 21 Apr 2024 18:19:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C0BBF68C89D for ; Sun, 21 Apr 2024 18:19:24 +0300 (EEST) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6edb76d83d0so3018485b3a.0 for ; Sun, 21 Apr 2024 08:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713712762; x=1714317562; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ONMXhVCY3dce5KIg7K7DCW3aBR55xh1PCpHrAy4LmVk=; b=EYVJDN7274CZdlDIscmRpiTP6qsReQXmZs1XP6Ownq/GPmDBlT4EuBuS+693Yp9XYV aKN3CbGpizT2ig2zhX5CYZpuby+0qPVvZXGRWEdOUGCZFqqPN3wWcjWu+Xud7gRb/PRu T+u6Z+53K9Om3Ze7GnZqfxn5ywij9DrwcWFro1W1IjVw0i1BCmN6wwWHYmmtGsQrH7w1 dlQrPpXyCVJefDKEh6V/LFI/1JsFCUaepSMQIpfoJHnU8PaEZWdmZGCXQqin1UvSejtr NxW4SN1Z+V3bbymSlsnVEu6sfpeGSVQMdlJYUzKsO8HfbZ1ebMz5Mq3khnQRlVJO+KPm GHbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713712762; x=1714317562; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ONMXhVCY3dce5KIg7K7DCW3aBR55xh1PCpHrAy4LmVk=; b=KzbUKbAZrwuqFDTuynAm+lnQNsW6ZsYVoF1wlGSX5UWm2b1Cf2OHgwWtMu66jVE7IE pLlmJp1lmf26QdSgSM/tCO0BY6UoCuOY1ENVifL+dEvQFOFaX4/B84rECLC3z16obSZ6 pPyxjcMA00W8XTiMSEfGhQqUnIytizItHsNYMVzWnWMiEFuprkv/x5oTauyuysSi8RPN oZ2Lmn9HY4QsDOuDu6CfbtmVgwrwedECnL3/JHNUqr67OUMtdXAqAPyj7EWQ6ZkE9dL8 VGp1YvTMVnDGriMHe+lkDE8Nd7sz2jwSXXfXIhwTxHkr6lC20N/NnM1BZMW0pGCWCIWC 59Iw== X-Gm-Message-State: AOJu0YwucaNSXgEUWcPkYNwuZzlbPuH5Hn+NIeBmROe9JuCTb9yY7IOO RK5gu4s7qs2PZLH74A+Tbf5kFFuo0gQyeF+evPLzgYCU6vKSQHXqzp1viA== X-Received: by 2002:a05:6a00:d48:b0:6ed:5655:a094 with SMTP id n8-20020a056a000d4800b006ed5655a094mr9207015pfv.32.1713712761822; Sun, 21 Apr 2024 08:19:21 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id c7-20020aa78e07000000b006ed048a7323sm6263325pfr.86.2024.04.21.08.19.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 08:19:21 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 Apr 2024 12:18:51 -0300 Message-ID: <20240421151851.1165-1-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240420234312.36464-2-jamrial@gmail.com> References: <20240420234312.36464-2-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2 v2] avformat/demux: extract extradata from packets when context update is requested 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: R+uEddMX4Ncq If the demuxer doesn't set extradata in the stream's codecpar, a need_context_update request will delete the previously extracted extradata in the stream's internal AVCodecContext. As we can't ensure the old extradata is valid for the stream in its post context update request state, try to get extradata from the new packet instead of attempting to preserve the old in some form. Signed-off-by: James Almer --- libavformat/demux.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index abfd5fee7d..39aa1cd4e3 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -1319,6 +1319,8 @@ fail: return ret; } +static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt); + static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) { FFFormatContext *const si = ffformatcontext(s); @@ -1373,6 +1375,11 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) return ret; } + if (!sti->avctx->extradata && + (ret = extract_extradata(si, st, pkt)) < 0) { + av_packet_unref(pkt); + return ret; + } sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id); sti->need_context_update = 0; @@ -2470,6 +2477,8 @@ static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket * if (ret < 0) return ret; + av_bsf_flush(sti->extract_extradata.bsf); + ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref); if (ret < 0) { av_packet_unref(pkt_ref); @@ -3090,7 +3099,8 @@ find_stream_info_err: err = codec_close(sti); if (err < 0 && ret >= 0) ret = err; - av_bsf_free(&sti->extract_extradata.bsf); + if (sti->extract_extradata.bsf) + av_bsf_flush(sti->extract_extradata.bsf); } if (ic->pb) { FFIOContext *const ctx = ffiocontext(ic->pb);