Skip to content

Commit d249e8a

Browse files
committed
Fix camera release on Windows
1 parent 991d092 commit d249e8a

4 files changed

Lines changed: 12 additions & 1 deletion

File tree

examples/barcode-scanner/include/Camera.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <wrl/client.h>
3030
#include <dshow.h>
3131

32+
using Microsoft::WRL::ComPtr;
3233
#elif __linux__
3334
#include <linux/videodev2.h>
3435
#include <fcntl.h>
@@ -106,7 +107,7 @@ class CAMERA_API Camera
106107
private:
107108
#ifdef _WIN32
108109
void *reader;
109-
110+
ComPtr<IMFMediaSource> ms;
110111
bool initialized;
111112
void InitializeMediaFoundation();
112113
void ShutdownMediaFoundation();
292 Bytes
Binary file not shown.
291 Bytes
Binary file not shown.

examples/barcode-scanner/src/CameraWindows.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ void Camera::ShutdownMediaFoundation()
117117
{
118118
if (initialized)
119119
{
120+
if (ms)
121+
{
122+
ms->Shutdown();
123+
ms.Reset();
124+
}
125+
120126
MFShutdown();
121127
initialized = false;
122128
}
@@ -164,6 +170,8 @@ bool Camera::Open(int cameraIndex)
164170
if (FAILED(hr))
165171
return false;
166172

173+
this->ms = mediaSource;
174+
167175
ComPtr<IMFSourceReader> mfReader;
168176
hr = MFCreateSourceReaderFromMediaSource(mediaSource.Get(), nullptr, &mfReader);
169177
if (FAILED(hr))
@@ -200,6 +208,8 @@ void Camera::Release()
200208
{
201209
ComPtr<IMFSourceReader> mfReader(static_cast<IMFSourceReader *>(reader));
202210
reader = nullptr;
211+
212+
ShutdownMediaFoundation();
203213
}
204214
}
205215

0 commit comments

Comments
 (0)