From patchwork Mon Jun 7 23:04:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 28138 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp3887040iof; Mon, 7 Jun 2021 16:06:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzomLdtEcCYEfJVJ5M9BELzVKcXtQiI/TyyQy6MqbyYJMLDCXqtwkzWUyx3lZf3GZ/H6lG7 X-Received: by 2002:a05:6402:754:: with SMTP id p20mr21822526edy.311.1623107199525; Mon, 07 Jun 2021 16:06:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623107199; cv=none; d=google.com; s=arc-20160816; b=Y1aXksiBJQQW03LA3HII+a5M0IkwG5VsAkzh340t/5Q8kE2LOY7eTv9IV3cAN3t3XK 5/I/e7ze0kt4Da4g+BHn2PsitIs1PWxKiXU0uakU5sHmoDTU+68aPvatItGbHe8po4Bc Sezqxl7k9GMJYp2lstqI2SFiKLCWwXbIwerBE59wHofB2NtFuXXs0jrE4jeVfyYx2ciE i3UEyX292MWzSx5Ew1JXTvh4i4ePEgicMWHKPU9SZh+ti7awgF/MubEs967tsVaR3/Qv +m+y6HZDkhsJruaLZL3MlYP53dI7EZJ556lxtcVMw7QIVjzNNqJoCbcIUefwsYZal6Wc O92w== 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=DR/j76K20adpgHhbdbpOA1NGtz49J/E8zLizEV0IubI=; b=Ep8ngf3Irk4wHuKz6OpPQWPJyMMfa9V9qe1WK4ZLQP4eNEwIma0pG6dGvzsLZcfDty 0deeHQD/snHNwVeqj+PoVYc44CnM4UBXXspwOzS6tSJ3x0hndg7L4HhnF2kgLGU/AJhX e6j+FIwEJ71EALVhNPp29jDjJliEkWbUDmKnIxKwclcjy/Iv9rtU8EsZzIuSXzIMnBIs CprZU8TXKlxcBf5PtByTwYt30s91jXN0wIKIFBtlr1TRJA4Hg14g+KPdC9hB+fCRh6vy 5jEqrKWf6V4p3h6aH7mOnaVc292tC/4mbBvN6ES0u4qe6PxXEB4WDvXVFkRU4/HAcTLy GI6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=CMtRDp6W; 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 l18si13085091edc.264.2021.06.07.16.06.37; Mon, 07 Jun 2021 16:06:39 -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=20161025 header.b=CMtRDp6W; 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 CE981687F8C; Tue, 8 Jun 2021 02:04:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BE446680C0F for ; Tue, 8 Jun 2021 02:04:53 +0300 (EEST) Received: by mail-lf1-f42.google.com with SMTP id m21so13272080lfg.13 for ; Mon, 07 Jun 2021 16:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9ocYUP/GphBKza6O+W1dpNazPJve7+uOBzeixMJAdsE=; b=CMtRDp6WkzQYJtVe5VJRb96dhAOluDGZYqdmUqPljvgMo0BZQbaSXnWDH96flHa3eg ScXfqUUQO/Ftb+NkQ/5UJQIR+4bHlTw9gBo+HP/ZY8Iejy4eLxMGm2w8x+Gyy6cYb+16 QXqMErdDKNYvS6slnKPDoYPLXUcC0zLbSeQkDeKEy2jHFWE6O4EtbUA4DDuXLGGFs71o Hs7D/3oAwtOaqknVMrnlj8XyIhrnDOWjuJO7hvyp0N4Oyj23mR1fSvKKFjG+dzR0drFe fC3dChaAzWAqLySWYbB1MZIEsW3opPek2VWDR0U/LcBUfh3F6Q/GoIAgqIZeneCJULzi DPzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9ocYUP/GphBKza6O+W1dpNazPJve7+uOBzeixMJAdsE=; b=oY9mCrfZu8XZmlzL01OPVOOpO4equGE9C8IQYUoMcWdo1UOHRqvM54gH5Yf9Fi2fM7 kTEY58WLZIKaSWUWM6jTAgchpuFBhwq2UEGY1/z2jXiTLfeeTFryBCcPmzEFvQU5wXrQ 991quWOAHsNI8m/mqqyU9TPmQ7w8KHb7UoOZRxJgfJuauml+nxc7IU7v9DKarCLXEUMf rE45/bbmPBdNs45TJC4jCbb2RG8W/nGuHKLtxg+zhxBaorEKRE2+/LHDyzme4JyMfeUE hMh1etiiPy2UTEUdlU7VCMSQGyegNh6M5yQKoK/aOk3eRIsJx4pxDc+3rjietwcdGp4s gUIQ== X-Gm-Message-State: AOAM532b0q5/8oHkweXEVgsMyDAOMmQhIAFe6yGpxF6z+LuIaZDyGvFr ryegwe8mPO3otzmvpVAHn2h3AfurKaiMLg== X-Received: by 2002:ac2:4542:: with SMTP id j2mr13170385lfm.435.1623107092852; Mon, 07 Jun 2021 16:04:52 -0700 (PDT) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id v9sm1999563ljv.131.2021.06.07.16.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 16:04:52 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Jun 2021 01:04:07 +0200 Message-Id: <20210607230414.612-29-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210607230414.612-1-dcnieho@gmail.com> References: <20210607230414.612-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 28/35] avdevice/dshow: when closing, set context fields back to zero 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: Diederick Niehorster Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: anjNzU2oKuax After the avdevice capabilities API is implemented, the format context may be reused after querying device capabilities in a later avformat_open_input call. To enable this reuse, after releasing resources, make sure to also set the corresponding pointers back to NULL. This correctly indicates their state. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 004b4e6154..40a492b787 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -272,14 +272,18 @@ dshow_read_close(AVFormatContext *s) ICaptureGraphBuilder2_Release(ctx->graph_builder2[VideoDevice]); if (ctx->graph_builder2[AudioDevice]) ICaptureGraphBuilder2_Release(ctx->graph_builder2[AudioDevice]); + ctx->graph_builder2[0] = NULL; + ctx->graph_builder2[1] = NULL; if (ctx->control) { IMediaControl_Stop(ctx->control); IMediaControl_Release(ctx->control); } + ctx->control = NULL; if (ctx->media_event) IMediaEvent_Release(ctx->media_event); + ctx->media_event = NULL; if (ctx->graph) { IEnumFilters *fenum; @@ -297,25 +301,34 @@ dshow_read_close(AVFormatContext *s) IEnumFilters_Release(fenum); } IGraphBuilder_Release(ctx->graph); + ctx->graph = NULL; } if (ctx->capture_pin[VideoDevice]) ff_dshow_pin_Release(ctx->capture_pin[VideoDevice]); if (ctx->capture_pin[AudioDevice]) ff_dshow_pin_Release(ctx->capture_pin[AudioDevice]); + ctx->capture_pin[0] = NULL; + ctx->capture_pin[1] = NULL; if (ctx->capture_filter[VideoDevice]) ff_dshow_filter_Release(ctx->capture_filter[VideoDevice]); if (ctx->capture_filter[AudioDevice]) ff_dshow_filter_Release(ctx->capture_filter[AudioDevice]); + ctx->capture_filter[0] = NULL; + ctx->capture_filter[1] = NULL; if (ctx->device_pin[VideoDevice]) IPin_Release(ctx->device_pin[VideoDevice]); if (ctx->device_pin[AudioDevice]) IPin_Release(ctx->device_pin[AudioDevice]); + ctx->device_pin[0] = NULL; + ctx->device_pin[1] = NULL; if (ctx->device_filter[VideoDevice]) IBaseFilter_Release(ctx->device_filter[VideoDevice]); if (ctx->device_filter[AudioDevice]) IBaseFilter_Release(ctx->device_filter[AudioDevice]); + ctx->device_filter[0] = NULL; + ctx->device_filter[1] = NULL; av_freep(&ctx->device_name[0]); av_freep(&ctx->device_name[1]); @@ -324,10 +337,13 @@ dshow_read_close(AVFormatContext *s) if(ctx->mutex) CloseHandle(ctx->mutex); + ctx->mutex = NULL; if(ctx->event[0]) CloseHandle(ctx->event[0]); if(ctx->event[1]) CloseHandle(ctx->event[1]); + ctx->event[0] = NULL; + ctx->event[1] = NULL; pktl = ctx->pktl; while (pktl) { @@ -336,6 +352,7 @@ dshow_read_close(AVFormatContext *s) av_free(pktl); pktl = next; } + ctx->pktl = NULL; CoUninitialize();