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) , Width(0)
, VideoBuffer(NULL) , VideoBuffer(NULL)
, VideoBufferSize(0) , VideoBufferSize(0)
, MaxVideoBufferSize(0)
, FrameReady(false) , FrameReady(false)
, IsPlaying(false) , IsPlaying(false)
, PlayCount(0) , PlayCount(0)
@ -65,8 +66,12 @@ GStreamerVideo::~GStreamerVideo()
delete[] VideoBuffer; delete[] VideoBuffer;
VideoBuffer = NULL; VideoBuffer = NULL;
VideoBufferSize = 0; VideoBufferSize = 0;
MaxVideoBufferSize = 0;
} }
SDL_DestroyTexture(Texture);
Texture = NULL;
FreeElements(); FreeElements();
} }
@ -99,8 +104,14 @@ void GStreamerVideo::ProcessNewBuffer (GstElement *fakesink, GstBuffer *buf, Gst
if(video->Height && video->Width) 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 // 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) if(video->VideoBuffer)
{ {
@ -108,9 +119,11 @@ void GStreamerVideo::ProcessNewBuffer (GstElement *fakesink, GstBuffer *buf, Gst
} }
video->VideoBuffer = new char[map.size]; 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); memcpy(video->VideoBuffer, map.data, map.size);
gst_buffer_unmap(buf, &map); gst_buffer_unmap(buf, &map);
video->FrameReady = true; video->FrameReady = true;
@ -165,13 +178,6 @@ bool GStreamerVideo::Stop()
// FreeElements(); // FreeElements();
IsPlaying = false; IsPlaying = false;
if(Texture)
{
SDL_DestroyTexture(Texture);
Texture = NULL;
}
IsPlaying = false;
Height = 0; Height = 0;
Width = 0; Width = 0;
FrameReady = false; FrameReady = false;

View File

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

View File

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