Video instance is now a singleton (checkin error previously). changed where video texture is destroyed to improve performance.

This commit is contained in:
emb 2015-01-08 23:55:28 -06:00
parent 4dd2c97fd6
commit 03b07cf126
3 changed files with 17 additions and 10 deletions

View File

@ -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;

View File

@ -42,6 +42,7 @@ private:
gint Width;
char *VideoBuffer;
gsize VideoBufferSize;
gsize MaxVideoBufferSize;
bool FrameReady;
bool IsPlaying;
static bool Initialized;

View File

@ -25,7 +25,7 @@ IVideo *VideoFactory::Instance = NULL;
IVideo *VideoFactory::CreateVideo()
{
if(Enabled)
if(Enabled && !Instance)
{
Instance = new GStreamerVideo();
Instance->Initialize();