From patchwork Tue Jul 6 09:20:13 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: 28813 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp4922483ios; Tue, 6 Jul 2021 02:26:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDbf74C+nH/TfBmWjKttw+45EIXDA0ZLoLO6s1N9lHZIDVTuFfAq8t0LixFAsgK8GyyHuG X-Received: by 2002:a17:907:7d8c:: with SMTP id oz12mr17215631ejc.202.1625563576541; Tue, 06 Jul 2021 02:26:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625563576; cv=none; d=google.com; s=arc-20160816; b=MejBZmWeDPsoC7N20qRWcN7tbY1NWElY9bAERFMn6hwd+F03f9mioj286SDJINGCv3 ekExtvW/NrtbhIDvQzN4vWi87lh1F+FCIWUv//d1Gk1iLziF64mCKA905CyO+Cp1ICPY dZC1AQtQ3tcWfbJDbOvTPpaMcEetYlkrwA+lXBvi5Bvgk/tCL3WzFIWUf4KJ+hLTzKgX jt9IUTSu6mdVL/oVB6VyFT6FRWeoWXNMM1mD3OZjs1RRogeWMrlGC/P0g+Xwvx3m4BdE 6o1LgnGtjrBVW5bQ71v6/1sZg8BoBf2GfI6qxPI4D+0NnSMpG9OHPh3uAZop/aopGjap 7NOw== 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=Y7Aat5a282cXo8nZAcT0WGY700lrn5//VhRmRN+nXWA=; b=fzLmp9ZJEDl+g+3DrONL4LZXCQOvNL8YB+NENJwqftXELTxR8kpOrgslX+P5zomm+e 98UkmRQpCz7SjKIBrQA0n6sbYQIg86ewQ1rpr7n9B4h21U4S78dyrD6HwyIP/eXtt0GZ zEzqBlmMDvVMtqxkuwhFqLkhh5cytZGT9QztIGs2EnZJLGfyNkz3BIzj8oY3zlnRGVOC tul+yUC/7z61sr8uX6X8wE6VAbToSy3iwcQhkwt9XGqY8lGoFm0FS5/IGnmLob7Y1HPv v4kb9I64/EXzHffk/Bv7zW4+tcKiri4VuPaPtwIRP9Hu/pZ/dhJqU8NfZwLyWSOTyyD5 8weA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=V5VkyoYp; 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 nd35si15043738ejc.274.2021.07.06.02.26.16; Tue, 06 Jul 2021 02:26:16 -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=V5VkyoYp; 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 6932E68A8DC; Tue, 6 Jul 2021 12:26:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4C83568A8C1 for ; Tue, 6 Jul 2021 12:26:06 +0300 (EEST) Received: by mail-lj1-f171.google.com with SMTP id k8so28209651lja.4 for ; Tue, 06 Jul 2021 02:26:06 -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=Ts0bCc27D4k9N/McLoqplW8dex7IEwqUuePWUje50YA=; b=V5VkyoYpbAZaufg6xUP47Aqvpa050n2P19ZQqidKEE8+qkfwhPNuZuJWDDEugt3cZ1 NF4agH1bM67/PTqguce3bvO3mJG3SrQ8RMJyeRgC3nl6UFp+84/GLJ8cZF2Q4f34Wr6O dTAMI0uneQyzCBOjMaUK6a1Bdp8ziN3ATjfgpwmkD3UpQ+hNJtehryAlCqONQzRjpQfD nXrr7+g9LCdEJwSnGhAx5zik0kl5nvlcjvu4JL2wzwLo83tcROqLWeEsm1qKrpyM9tsM Nx/Up5o/Tqs1pxPEAmtxK8DJbOKJ5su3gEEHFRnvr1TvZVh9Nw3kO27xNObRYWehGzt1 rQ8w== 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=Ts0bCc27D4k9N/McLoqplW8dex7IEwqUuePWUje50YA=; b=rCrELHTz6TRXJDyAFSTW1sGBwndCWeiFBr6F2J/3HYHAsrbaQlJyfvi4RdLbBEb90s E9oXIxIrVM1iNA8ccMhMrKXfhF9ArqbrJWA5Vn3lB5Qs5Pi+v0GbZ2yXqNS6Y8KcRAii zzgKP+kdPKpli1ocNDGOVvqsFJNRmq+CddccDna+ss5MWezEf6+J8qJJwyzlCxDqzJoy MvUAbHk/xgyST8ynJ/9Quya/0OYcIlzbKZilNjGbusitD6gDogFgc3MnD/InZcX+x0jP vzSK9lEvERTXrAFNdZP2qhlZMfo0kj+WcTivWK5heFVRhT6ONcDpgOV7LCkcqsM6w5bJ UqYw== X-Gm-Message-State: AOAM531ytrCfdrDNFLkyQBr2yCemMW0QHq0cZddzLvcMUwbrc/VAFI1Z /umJvVyCi6imtHZ/324RhJLpDu8zuko= X-Received: by 2002:a2e:8708:: with SMTP id m8mr14499336lji.244.1625563565404; Tue, 06 Jul 2021 02:26:05 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id g22sm1339593lfr.227.2021.07.06.02.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 02:26:04 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Jul 2021 11:20:13 +0200 Message-Id: <20210706092020.1057-28-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210706092020.1057-1-dcnieho@gmail.com> References: <20210706092020.1057-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 27/34] 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: lnXLiO5S7dms 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 after cleanup. 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 bc3cc2caa2..046c39cc24 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -296,14 +296,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; @@ -321,25 +325,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]); @@ -348,10 +361,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) { @@ -360,6 +376,7 @@ dshow_read_close(AVFormatContext *s) av_free(pktl); pktl = next; } + ctx->pktl = NULL; CoUninitialize();