diff mbox series

[FFmpeg-devel,v2,26/33] avdevice/dshow: when closing, set context fields back to zero

Message ID 20210611203104.1692-27-dcnieho@gmail.com
State Superseded, archived
Headers show
Series avdevice (mostly dshow) enhancements | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Diederick C. Niehorster June 11, 2021, 8:30 p.m. UTC
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 <dcnieho@gmail.com>
---
 libavdevice/dshow.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox series

Patch

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();