From 03b07cf1260e8b25c155b15dd8de8b4d31e19af6 Mon Sep 17 00:00:00 2001 From: emb <> Date: Thu, 8 Jan 2015 23:55:28 -0600 Subject: [PATCH] Video instance is now a singleton (checkin error previously). changed where video texture is destroyed to improve performance. --- RetroFE/Source/Video/GStreamerVideo.cpp | 24 +++++++++++++++--------- RetroFE/Source/Video/GStreamerVideo.h | 1 + RetroFE/Source/Video/VideoFactory.cpp | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/RetroFE/Source/Video/GStreamerVideo.cpp b/RetroFE/Source/Video/GStreamerVideo.cpp index 23f24d3..b0a1466 100644 --- a/RetroFE/Source/Video/GStreamerVideo.cpp +++ b/RetroFE/Source/Video/GStreamerVideo.cpp @@ -50,6 +50,7 @@ GStreamerVideo::GStreamerVideo() , Width(0) , VideoBuffer(NULL) , VideoBufferSize(0) + , MaxVideoBufferSize(0) , FrameReady(false) , IsPlaying(false) , PlayCount(0) @@ -65,8 +66,12 @@ GStreamerVideo::~GStreamerVideo() delete[] VideoBuffer; VideoBuffer = NULL; VideoBufferSize = 0; + MaxVideoBufferSize = 0; } + SDL_DestroyTexture(Texture); + Texture = NULL; + FreeElements(); } @@ -99,8 +104,14 @@ void GStreamerVideo::ProcessNewBuffer (GstElement *fakesink, GstBuffer *buf, Gst if(video->Height && video->Width) { + if(video->Texture && video->VideoBufferSize != map.size) + { + SDL_DestroyTexture(video->Texture); + video->Texture = NULL; + } + // keep the largest video buffer allocated to avoid the penalty of reallocating and deallocating - if(!video->VideoBuffer || video->VideoBufferSize < map.size) + if(!video->VideoBuffer || video->MaxVideoBufferSize < map.size) { if(video->VideoBuffer) { @@ -108,9 +119,11 @@ void GStreamerVideo::ProcessNewBuffer (GstElement *fakesink, GstBuffer *buf, Gst } video->VideoBuffer = new char[map.size]; - video->VideoBufferSize = map.size; + video->MaxVideoBufferSize = map.size; } + video->VideoBufferSize = map.size; + memcpy(video->VideoBuffer, map.data, map.size); gst_buffer_unmap(buf, &map); video->FrameReady = true; @@ -165,13 +178,6 @@ bool GStreamerVideo::Stop() // FreeElements(); IsPlaying = false; - - if(Texture) - { - SDL_DestroyTexture(Texture); - Texture = NULL; - } - IsPlaying = false; Height = 0; Width = 0; FrameReady = false; diff --git a/RetroFE/Source/Video/GStreamerVideo.h b/RetroFE/Source/Video/GStreamerVideo.h index 853c68b..7cb21a9 100644 --- a/RetroFE/Source/Video/GStreamerVideo.h +++ b/RetroFE/Source/Video/GStreamerVideo.h @@ -42,6 +42,7 @@ private: gint Width; char *VideoBuffer; gsize VideoBufferSize; + gsize MaxVideoBufferSize; bool FrameReady; bool IsPlaying; static bool Initialized; diff --git a/RetroFE/Source/Video/VideoFactory.cpp b/RetroFE/Source/Video/VideoFactory.cpp index 99fa76b..4c655ca 100644 --- a/RetroFE/Source/Video/VideoFactory.cpp +++ b/RetroFE/Source/Video/VideoFactory.cpp @@ -25,7 +25,7 @@ IVideo *VideoFactory::Instance = NULL; IVideo *VideoFactory::CreateVideo() { - if(Enabled) + if(Enabled && !Instance) { Instance = new GStreamerVideo(); Instance->Initialize();