From patchwork Fri Jun 11 20:30:57 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: 28238 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bbc9:0:0:0:0:0 with SMTP id c9csp837360ybk; Fri, 11 Jun 2021 13:39:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbRl5TW8AkSxLzcKUIy2iXfqvP80teiA0oc/MRt/mH1l5dMbnmV1UdjxcukT9xCGHdVRn+ X-Received: by 2002:a05:6402:b76:: with SMTP id cb22mr5571538edb.112.1623443947287; Fri, 11 Jun 2021 13:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443947; cv=none; d=google.com; s=arc-20160816; b=CBqJ0Z6rrIktSofk0pn7JDHBkBIfqrSPciPq6Tqz4Hu97oa1STgjxpwpYc89T2OJx4 mJhHTRfs+YzPjkEvyDdgnrUEy9wloEeJdIy/nUwFMkf8S2SzN61oEY09DwU+JRJzukqV PEM2dqa7hB2aQ0Ods71BjFRB2rFCN89EfhvhxLrzwO/pOqSVNwgvjGLNpZxlyzIeHBTn cSnuQ9amaakIQdyxyQK1EQJz2Kmb8Zuj3M6Vol7fhezbGQPInHS3IPJwbf1WAONSc8cu +ew120CmkGEzfv6+eBTx5ppW1Zl/e1atAK8lTQ+DDV/EmQj++YX8A8nz40zjm2IbZVdW CE+A== 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=WfF5XpC15srTX2gClPycVo2bNkFzorkdz0kEPfdyCXA=; b=swndysGmvwWMYf/Lp0J5jcKWngOXAS9e8N9yiXAF/oSheewuMhZo8quVmUV3N8+yyX /IOc1YKHvRRInyl6NVeS522uW9w58yGHb/v/Ghx2AuG+bvPjmI2EI6Ou0j+ghGz3Wkda 0GrMelqEmwCHOuYOTGlyPSWZxPHZERseT/x9XzrzrYgkQUKQS8/T40nbFEz+H88aj+Ok KFae8PxdwlAkab1TJT5zisVJkwOoepXopsTgp0wTo9GTVTzK9r6l3AF2ia28qtFebbJH 0RabAV8iGKsMiHW1Tf53hTtTWVT7kWRqktGFqaaL9nKnnAiHBMb12oHCrAeK+oivr9pK bT4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=eXJLG5uC; 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 4si5404450ejr.126.2021.06.11.13.39.07; Fri, 11 Jun 2021 13:39:07 -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=eXJLG5uC; 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 DA9AD689A1C; Fri, 11 Jun 2021 23:39:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 57633687F49 for ; Fri, 11 Jun 2021 23:38:59 +0300 (EEST) Received: by mail-lf1-f52.google.com with SMTP id i10so10391685lfj.2 for ; Fri, 11 Jun 2021 13:38:59 -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=zOnyLsTJaUlPcwMzIJa5TFJ3p88iINfW6mWzFNoxVY4=; b=eXJLG5uC7j5CSmddNzrB0BXOsGgOoL2weIguNH4BtN6srbywww5nj/8AIF6gNQrnpo 1ee8mKg7abekSl3knbimTscKmbUo77fzGGm/URx0kGLTb3NElhE3NWYxBQvWJ+wytjnq SH4kBmOlQ3Fc/DBM4LbiNW9fw4XSpeNKj9NhFQbdZ/oJg959vDC9d3krY65jb7O3n4jd Scpy2OmyBTF71bk8VOZAZFNBKVgSp8jWqqAwiDc7CZ2gpe2YkVCRVghsCxQBpbKZcVwS g3IqGvtzDzqZ+FP62AC6Uegi7NsgnUGTfex0cX88eTL3mG23oyZytDgEILrhSsqhofxZ xQvA== 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=zOnyLsTJaUlPcwMzIJa5TFJ3p88iINfW6mWzFNoxVY4=; b=NELdyMADT+3iel1icXzWZC+hxnOtTV7IpcbI8w6lWQbgoMbWgUEjWJv8ZHBOzTYuby niq11ArgvFKjEFlJJpmsGKMLsbS/5ax8Ao9wVIBYlaucu+q9hE2+rLHMb36mCGrn/42h DyxfUGwSiEaPMwPrJBscmPfI3cCUoCO4B15H9bFy2Ne8HhAaaJyIZXgiLJoWGAFKQjiv /09lhlf2lZpv/Hfi4tCJwlkCu9r7+q9N2dowC8UwMavWB8fbgO9aHu7LTjdhVLWrNv8+ ipITg0+nyR4s3j7eAJl6OiGB3mgeS8KrS4L9bAZ6Bqq4B3a7dao/bo0FlKKdyys+ashr 7mXg== X-Gm-Message-State: AOAM532oGQgKv+z6hoQy18l9KQ+uq4/SYptzAZHub5dRTEG4t/lXEyXs hOhbn4L7rs7p2kyKkEkoQoyhOhhXORk5YA== X-Received: by 2002:a05:6512:3054:: with SMTP id b20mr3671491lfb.375.1623443938577; Fri, 11 Jun 2021 13:38:58 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id h19sm686508lfj.256.2021.06.11.13.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:38:58 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:57 +0200 Message-Id: <20210611203104.1692-27-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 26/33] 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: ixZ+lc2X3SDz Content-Length: 3391 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 4605bd6f8e..20f58aee63 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -291,14 +291,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; @@ -316,25 +320,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]); @@ -343,10 +356,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) { @@ -355,6 +371,7 @@ dshow_read_close(AVFormatContext *s) av_free(pktl); pktl = next; } + ctx->pktl = NULL; CoUninitialize();