From patchwork Wed Mar 30 12:18:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35069 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774582pzb; Wed, 30 Mar 2022 05:20:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrkf8cWl+mhWJNC29GF6a+lgpAJ8lATVVGCzFMXu+VW9vwj3fhZj1Gj6vbJbWkHXNHooPc X-Received: by 2002:a05:6402:1385:b0:413:2bc6:4400 with SMTP id b5-20020a056402138500b004132bc64400mr10583659edv.94.1648642858683; Wed, 30 Mar 2022 05:20:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642858; cv=none; d=google.com; s=arc-20160816; b=Apv4WQfDJOh/D3wU6APLIAbcuZSz0pKmX58sdJxPDQqbbOq08cPsDT4bRLzbIpOjeu EIYIBIFFrSQrjIj2zUYOQDal49729KxBuLM8KEwl3rJYlOiUSDdQE9GRHkFkqV/Z9PGT QHAEVsCX4NzXEU5nSN7rZ9xvRjj5PBkUHAG0HmFQUVNpcP9tTwkMxMAL+M5E3F70PVuk md3xEx+ghN/Sq19vFYPAdFGWEXAkP4fOEWW2UxfbG+Pva9U+JOn7O4p7ZYqydqQIcD/H qIDosg42lUROODNgberCf2IYX2TEAUY2QhbKzWXG9IHbWeo7mChKPURNiWRNo+jc2Fiz OleA== 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=CClGl678/vkJZEzh0zBJsqU/ddMSJj3H8A68MKwD7ho=; b=q4IJCFRDkXonxnH0fkJjESgX+2YQO/Gfjin4xTBcXGMGW8Qy7fPsg4AYpeBCnRTf5A T9+dscj+CI+vbjgCarBFfMDttK9WRhXl114d3QI+p8CdKeEaOZ6fm2QYpqAzQxVDgynC 7MJGQdFF3Wfo/8l2QpYb3vg9njNFGMBL0vHueKAw9zpOfEVBy1Vjt1QkxIQk8EuA4UGR GztZsVavqRvVBcllLa9Xx6ZJ0dQZA/gaPnrx4ISgr9vg5tWHYbCl2fMnV/NMByDO7WqB W12jQTOSy+EC6F11LOG+vkd2q6+qHp+yh+024yeLmdkbBUyOGdD35aOhwPsfTovPVjqt lRnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=NXrAkBxW; 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 t17-20020a170906065100b006dfa8b9bc20si20910404ejb.894.2022.03.30.05.20.57; Wed, 30 Mar 2022 05:20:58 -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=20210112 header.b=NXrAkBxW; 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 01BBC68B1EB; Wed, 30 Mar 2022 15:20:03 +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 6709B68B280 for ; Wed, 30 Mar 2022 15:20:00 +0300 (EEST) Received: by mail-lf1-f42.google.com with SMTP id bq24so19522266lfb.5 for ; Wed, 30 Mar 2022 05:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NK/QrJEeth1MSuzhPObWDUazu7iR/OBn1N+cSzfeM/U=; b=NXrAkBxWGY5TrlVzdjwnIB6LUAWzaS/kf01BrfZeLSwOdF/zd3Dz/3wxWOtAoJxJHa dhJBxTvhXIu38AfTi4bGE+0ElKJkXK4Gg8QIJcQ5bBDderTLpdXdTxvpHJfDHgGS/tub ON67nwhWKTDFP4KbTjJWXBcfY78t+piWerVxEjHmuOLJR/fGuXbkZcqkNHpg3fluw/LJ sZL97lzaKlLzYl9tLpos29Uwa2dIrMZHU60MO//MbFlk51+j4tqy5oKHTfFd2Ii+rkxl 4il/1tirNw06nnp1l2J1cOUTMi5lXFDLYx/4Y1KR9kuVDYZIRiU3CNnK7dQFdXFKbsKH wYlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NK/QrJEeth1MSuzhPObWDUazu7iR/OBn1N+cSzfeM/U=; b=n8hVslHkkXBawOAlhn2O+s9v6i2VftRt1DZ3qEwOR2g9uyU0OkbzEHWPF7g7HwJPgD +r8bkedMRng/C81fO0qvtgrrgz1LMB0yNldw7gJjzFPcTW9rfHime6W6cpQTFS8/coGg dxr52FO3qeNF2VHlRaGnwZD1oEGVOJV8Wd440sDeUGQLnYWkMd0BLBKSyU6IWVbvshv+ lviggFb8XYp+adeU+NPkzkvZ6Vp5Dh8qfFB8wUBHBD1DyBk3yeQcL+JAflYNmX3Jr06o CiwdkBWwBCPGxZADJZlLZ1Oy4dzu3pkaJjwUrHAAGxyJ3+YVFaWetmBZKImbXjMTGfrj oNEQ== X-Gm-Message-State: AOAM532TldLAVhxRelhGeV58cm3srts2iOlxuUGwkFI5I++qRCbDHjpx spOvSP7SU8FH96ZW7RQO4J1rIyhqpyY= X-Received: by 2002:a05:6512:555:b0:44a:a75c:885c with SMTP id h21-20020a056512055500b0044aa75c885cmr6508200lfl.80.1648642798721; Wed, 30 Mar 2022 05:19:58 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id g36-20020a0565123ba400b0044a2a1ccd99sm2319993lfv.20.2022.03.30.05.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:19:58 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:18:00 +0200 Message-Id: <20220330121806.822-16-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 15/21] 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: ZJz+lNp3I7kS 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 d35224beb5..0d5f731030 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -264,14 +264,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; @@ -289,25 +293,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]); @@ -316,10 +329,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) { @@ -328,6 +344,7 @@ dshow_read_close(AVFormatContext *s) av_free(pktl); pktl = next; } + ctx->pktl = NULL; CoUninitialize();