diff --git a/Windows/CaptureDevice.cpp b/Windows/CaptureDevice.cpp index 6ae0733e51..a475901137 100644 --- a/Windows/CaptureDevice.cpp +++ b/Windows/CaptureDevice.cpp @@ -111,13 +111,15 @@ MediaParam defaultAudioParam = { 44100, 2, 16, MFAudioFormat_PCM }; HRESULT GetDefaultStride(IMFMediaType *pType, LONG *plStride); -ReaderCallback::ReaderCallback(WindowsCaptureDevice *device): img_convert_ctx(nullptr), resample_ctx(nullptr){ - this->device = device; -} +ReaderCallback::ReaderCallback(WindowsCaptureDevice *_device) : device(_device) {} ReaderCallback::~ReaderCallback() { - sws_freeContext(img_convert_ctx); - swr_free(&resample_ctx); + if (img_convert_ctx) { + sws_freeContext(img_convert_ctx); + } + if (resample_ctx) { + swr_free(&resample_ctx); + } } HRESULT ReaderCallback::QueryInterface(REFIID riid, void** ppv) @@ -439,20 +441,10 @@ u32 ReaderCallback::doResample(u8 **dst, u32 &dstSampleRate, u32 &dstChannels, u return av_samples_get_buffer_size(nullptr, dstChannels, outSamplesCount, AV_SAMPLE_FMT_S16, 0); } -WindowsCaptureDevice::WindowsCaptureDevice(CAPTUREDEVIDE_TYPE type) : - type(type), - m_pCallback(nullptr), - m_pSource(nullptr), - m_pReader(nullptr), - imageRGB(nullptr), - imageJpeg(nullptr), - imgJpegSize(0), - resampleBuf(nullptr), - resampleBufSize(0), - rawAudioBuf(nullptr), +WindowsCaptureDevice::WindowsCaptureDevice(CAPTUREDEVIDE_TYPE _type) : + type(_type), error(CAPTUREDEVIDE_ERROR_NO_ERROR), errorMessage(""), - isDeviceChanged(false), state(CAPTUREDEVIDE_STATE::UNINITIALIZED) { param = { 0 }; deviceParam = { 0 }; @@ -482,6 +474,7 @@ WindowsCaptureDevice::~WindowsCaptureDevice() { break; } } + void WindowsCaptureDevice::CheckDevices() { isDeviceChanged = true; } diff --git a/Windows/CaptureDevice.h b/Windows/CaptureDevice.h index 60f9b61b05..0829bdb2bc 100644 --- a/Windows/CaptureDevice.h +++ b/Windows/CaptureDevice.h @@ -171,8 +171,8 @@ public: protected: WindowsCaptureDevice *device; - SwsContext *img_convert_ctx; - SwrContext *resample_ctx; + SwsContext *img_convert_ctx = nullptr; + SwrContext *resample_ctx = nullptr; }; class WindowsCaptureDevice { @@ -222,12 +222,12 @@ protected: CAPTUREDEVIDE_ERROR error; std::string errorMessage; - bool isDeviceChanged; + bool isDeviceChanged = false; // MF interface. - ReaderCallback *m_pCallback; - IMFSourceReader *m_pReader; - IMFMediaSource *m_pSource; + ReaderCallback *m_pCallback = nullptr; + IMFSourceReader *m_pReader = nullptr; + IMFMediaSource *m_pSource = nullptr; // Message loop. std::mutex mutex; @@ -241,15 +241,15 @@ protected: std::mutex paramMutex; // Camera only - unsigned char *imageRGB; - int imgRGBLineSizes[4]; - unsigned char *imageJpeg; - int imgJpegSize; + unsigned char *imageRGB = nullptr; + int imgRGBLineSizes[4]{}; + unsigned char *imageJpeg = nullptr; + int imgJpegSize = 0; //Microphone only - u8 *resampleBuf; - u32 resampleBufSize; - QueueBuf *rawAudioBuf; + u8 *resampleBuf = nullptr; + u32 resampleBufSize = 0; + QueueBuf *rawAudioBuf = nullptr; }; extern WindowsCaptureDevice *winCamera;