Commit 4eadf1fe authored by Ghislain MARY's avatar Ghislain MARY

Fix some memory leaks.

parent a28095fe
......@@ -85,6 +85,13 @@ void libmswinrtvid::MediaStreamSource::Feed(Windows::Storage::Streams::IBuffer^
mMutex.unlock();
}
void libmswinrtvid::MediaStreamSource::Stop()
{
mMediaStreamSource = nullptr;
mVideoDesc = nullptr;
mDeferralQueue = nullptr;
}
void libmswinrtvid::MediaStreamSource::AnswerSampleRequest(Windows::Media::Core::MediaStreamSourceSampleRequest^ sampleRequest)
{
ComPtr<IMFMediaStreamSourceSampleRequest> spRequest;
......
......@@ -96,6 +96,7 @@ namespace libmswinrtvid
static MediaStreamSource^ CreateMediaSource();
void Feed(Windows::Storage::Streams::IBuffer^ pBuffer, int width, int height);
void Stop();
property Windows::Media::Core::MediaStreamSource^ Source
{
......@@ -116,7 +117,6 @@ namespace libmswinrtvid
Sample^ mSample;
uint64 mTimeStamp;
uint64 mInitialTimeStamp;
BYTE *mFrame;
std::mutex mMutex;
};
}
......@@ -148,6 +148,11 @@ void MSWinRTRenderer::SetSwapChainPanel(Platform::String ^swapChainPanelName)
void MSWinRTRenderer::Close()
{
if (mMediaEngineNotify != nullptr)
{
mMediaEngineNotify->SetCallback(nullptr);
mMediaEngineNotify.Detach();
}
if (mMediaEngine != nullptr)
{
mMediaEngine->Shutdown();
......@@ -162,6 +167,11 @@ void MSWinRTRenderer::Close()
MSWinRTExtensionManager::Instance->UnregisterUrl(mUrl);
mUrl = nullptr;
}
if (mMediaStreamSource != nullptr)
{
mMediaStreamSource->Stop();
mMediaStreamSource = nullptr;
}
if (mSharedData != nullptr)
{
......@@ -251,6 +261,11 @@ bool MSWinRTRenderer::Start()
return true;
}
void MSWinRTRenderer::Stop()
{
Close();
}
void MSWinRTRenderer::Feed(Windows::Storage::Streams::IBuffer^ pBuffer, int width, int height)
{
if (mMediaStreamSource != nullptr) {
......@@ -315,15 +330,14 @@ HRESULT MSWinRTRenderer::SetupDirectX()
ms_error("MSWinRTRenderer::SetupDirectX: Set MF_MEDIA_ENGINE_DXGI_MANAGER attribute failed %x", hr);
return hr;
}
ComPtr<MediaEngineNotify> notify;
notify = Make<MediaEngineNotify>();
notify->SetCallback(this);
mMediaEngineNotify = Make<MediaEngineNotify>();
mMediaEngineNotify->SetCallback(this);
hr = attributes->SetUINT32(MF_MEDIA_ENGINE_VIDEO_OUTPUT_FORMAT, DXGI_FORMAT_NV12);
if (FAILED(hr)) {
ms_error("MSWinRTRenderer::SetupDirectX: Set MF_MEDIA_ENGINE_VIDEO_OUTPUT_FORMAT attribute failed %x", hr);
return hr;
}
hr = attributes->SetUnknown(MF_MEDIA_ENGINE_CALLBACK, (IUnknown*)notify.Get());
hr = attributes->SetUnknown(MF_MEDIA_ENGINE_CALLBACK, (IUnknown*)mMediaEngineNotify.Get());
if (FAILED(hr)) {
ms_error("MSWinRTRenderer::SetupDirectX: Set MF_MEDIA_ENGINE_CALLBACK attribute failed %x", hr);
return hr;
......
......@@ -84,6 +84,7 @@ namespace libmswinrtvid
void SetSwapChainPanel(Platform::String ^swapChainPanelName);
bool Start();
void Stop();
void Feed(Windows::Storage::Streams::IBuffer^ pBuffer, int width, int height);
virtual void OnMediaEngineEvent(uint32 meEvent, uintptr_t param1, uint32 param2);
......@@ -127,5 +128,6 @@ namespace libmswinrtvid
Microsoft::WRL::ComPtr<IMFDXGIDeviceManager> mDxGIManager;
Microsoft::WRL::ComPtr<IMFMediaEngine> mMediaEngine;
Microsoft::WRL::ComPtr<IMFMediaEngineEx> mMediaEngineEx;
Microsoft::WRL::ComPtr<MediaEngineNotify> mMediaEngineNotify;
};
}
......@@ -80,6 +80,7 @@ MSWinRTCapHelper::~MSWinRTCapHelper()
ms_yuv_buf_allocator_free(mAllocator);
mAllocator = NULL;
}
mEncodingProfile = nullptr;
ms_mutex_destroy(&mMutex);
}
......
......@@ -63,6 +63,7 @@ void MSWinRTDis::start()
void MSWinRTDis::stop()
{
if (mIsStarted) {
mRenderer->Stop();
mIsStarted = false;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment