Fixed two memory leaks in VideoVlcComponent.

This commit is contained in:
Leon Styhre 2021-03-22 18:12:25 +01:00
parent e96f8b9c0a
commit 28c66225c9
3 changed files with 17 additions and 0 deletions

View file

@ -11,6 +11,7 @@
#include "components/HelpComponent.h" #include "components/HelpComponent.h"
#include "components/ImageComponent.h" #include "components/ImageComponent.h"
#include "components/VideoVlcComponent.h"
#include "resources/Font.h" #include "resources/Font.h"
#include "Sound.h" #include "Sound.h"
#include "InputManager.h" #include "InputManager.h"
@ -131,6 +132,7 @@ void Window::deinit()
InputManager::getInstance()->deinit(); InputManager::getInstance()->deinit();
ResourceManager::getInstance()->unloadAll(); ResourceManager::getInstance()->unloadAll();
VideoVlcComponent::deinit();
Renderer::deinit(); Renderer::deinit();
} }

View file

@ -34,6 +34,7 @@ VideoVlcComponent::VideoVlcComponent(
Window* window) Window* window)
: VideoComponent(window), : VideoComponent(window),
mMediaPlayer(nullptr), mMediaPlayer(nullptr),
mMedia(nullptr),
mContext({}), mContext({}),
mHasSetAudioVolume(false) mHasSetAudioVolume(false)
{ {
@ -50,6 +51,14 @@ VideoVlcComponent::~VideoVlcComponent()
mTexture.reset(); mTexture.reset();
} }
void VideoVlcComponent::deinit()
{
if (mVLC) {
libvlc_release(mVLC);
mVLC = nullptr;
}
}
void VideoVlcComponent::setResize(float width, float height) void VideoVlcComponent::setResize(float width, float height)
{ {
// This resize function is used when stretching videos to full screen in the video screensaver. // This resize function is used when stretching videos to full screen in the video screensaver.
@ -358,6 +367,9 @@ void VideoVlcComponent::startVideo()
} }
} }
libvlc_media_tracks_release(tracks, track_count); libvlc_media_tracks_release(tracks, track_count);
libvlc_media_parse_stop(mMedia);
libvlc_event_detach(libvlc_media_event_manager(mMedia),
libvlc_MediaParsedChanged, VlcMediaParseCallback, 0);
// Make sure we found a valid video track. // Make sure we found a valid video track.
if ((mVideoWidth > 0) && (mVideoHeight > 0)) { if ((mVideoWidth > 0) && (mVideoHeight > 0)) {
@ -466,6 +478,7 @@ void VideoVlcComponent::stopVideo()
libvlc_media_player_release(mMediaPlayer); libvlc_media_player_release(mMediaPlayer);
libvlc_media_release(mMedia); libvlc_media_release(mMedia);
mMediaPlayer = nullptr; mMediaPlayer = nullptr;
mMedia = nullptr;
freeContext(); freeContext();
} }
} }

View file

@ -31,6 +31,8 @@ public:
VideoVlcComponent(Window* window); VideoVlcComponent(Window* window);
virtual ~VideoVlcComponent(); virtual ~VideoVlcComponent();
static void deinit();
// Resize the video to fit this size. If one axis is zero, scale that axis to maintain // Resize the video to fit this size. If one axis is zero, scale that axis to maintain
// aspect ratio. If both are non-zero, potentially break the aspect ratio. If both are // aspect ratio. If both are non-zero, potentially break the aspect ratio. If both are
// zero, no resizing. This can be set before or after a video is loaded. // zero, no resizing. This can be set before or after a video is loaded.