Not specifying height/width uses videos native size.

This commit is contained in:
emb 2015-02-09 21:25:26 -06:00
parent a81b1bc5ad
commit a4c29eeb7b
6 changed files with 44 additions and 9 deletions

View File

@ -65,6 +65,14 @@ void ReloadableMedia::Update(float dt)
if(LoadedComponent)
{
// video needs to run a frame to start getting size info
if(GetBaseViewInfo()->GetImageHeight() == 0 && GetBaseViewInfo()->GetImageWidth() == 0)
{
GetBaseViewInfo()->SetImageWidth(LoadedComponent->GetBaseViewInfo()->GetImageWidth());
GetBaseViewInfo()->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
}
LoadedComponent->Update(dt);
}
@ -147,6 +155,8 @@ void ReloadableMedia::ReloadTexture()
if(LoadedComponent)
{
LoadedComponent->AllocateGraphicsMemory();
GetBaseViewInfo()->SetImageWidth(LoadedComponent->GetBaseViewInfo()->GetImageWidth());
GetBaseViewInfo()->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
found = true;
}
}

View File

@ -45,6 +45,13 @@ void VideoComponent::Update(float dt)
if(IsPlaying)
{
VideoInst->Update(dt);
// video needs to run a frame to start getting size info
if(GetBaseViewInfo()->GetImageHeight() == 0 && GetBaseViewInfo()->GetImageWidth() == 0)
{
GetBaseViewInfo()->SetImageHeight(static_cast<float>(VideoInst->GetHeight()));
GetBaseViewInfo()->SetImageWidth(static_cast<float>(VideoInst->GetWidth()));
}
}
Component::Update(dt);
@ -69,6 +76,15 @@ void VideoComponent::FreeGraphicsMemory()
Component::FreeGraphicsMemory();
}
void VideoComponent::LaunchEnter()
{
FreeGraphicsMemory();
}
void VideoComponent::LaunchExit()
{
AllocateGraphicsMemory();
}
void VideoComponent::Draw()
{
ViewInfo *info = GetBaseViewInfo();

View File

@ -30,14 +30,8 @@ public:
void Draw();
void FreeGraphicsMemory();
void AllocateGraphicsMemory();
void LaunchEnter()
{
FreeGraphicsMemory();
}
void LaunchExit()
{
AllocateGraphicsMemory();
}
void LaunchEnter();
void LaunchExit();
private:
std::string VideoFile;

View File

@ -323,9 +323,20 @@ void GStreamerVideo::FreeElements()
gst_object_unref(Playbin);
Playbin = NULL;
}
}
int GStreamerVideo::GetHeight()
{
return static_cast<int>(Height);
}
int GStreamerVideo::GetWidth()
{
return static_cast<int>(Width);
}
void GStreamerVideo::Draw()
{
FrameReady = false;

View File

@ -38,6 +38,8 @@ public:
void Draw();
void SetNumLoops(int n);
void FreeElements();
int GetHeight();
int GetWidth();
private:
static void ProcessNewBuffer (GstElement *fakesink, GstBuffer *buf, GstPad *pad, gpointer data);

View File

@ -29,4 +29,6 @@ public:
virtual SDL_Texture *GetTexture() const = 0;
virtual void Update(float dt) = 0;
virtual void Draw() = 0;
virtual int GetHeight() = 0;
virtual int GetWidth() = 0;
};