From ca79d8d33adab3263e7ffa0ce10f799065b0a853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Mei=C3=9Fner?= Date: Tue, 28 Oct 2014 22:07:40 +0100 Subject: [PATCH] Implement Pause Also, do not show the plate before there is anything on it. --- .../pfMoviePlayer/plMoviePlayer.cpp | 42 ++++++++++++------- .../FeatureLib/pfMoviePlayer/plMoviePlayer.h | 8 ++-- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.cpp b/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.cpp index a1871e57..d5836c90 100644 --- a/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.cpp +++ b/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.cpp @@ -171,9 +171,11 @@ plMoviePlayer::plMoviePlayer() : fPlate(nullptr), fTexture(nullptr), fReader(nullptr), - fStartTime(0), + fMovieTime(0), + fLastFrameTime(0), fPosition(hsPoint2()), fPlaying(false), + fPaused(false), fOpusDecoder(nullptr) { fScale.Set(1.0f, 1.0f); @@ -195,11 +197,6 @@ plMoviePlayer::~plMoviePlayer() #endif } -int64_t plMoviePlayer::GetMovieTime() const -{ - return (int64_t)hsTimer::GetMilliSeconds() - fStartTime; -} - bool plMoviePlayer::IOpenMovie() { #ifdef VIDEO_AVAILABLE @@ -285,6 +282,7 @@ void plMoviePlayer::IProcessVideoFrame(const std::vector& frames) // Flush new data to the device if (fTexture->GetDeviceRef()) fTexture->GetDeviceRef()->SetDirty(true); + fPlate->SetVisible(true); } #endif } @@ -334,8 +332,7 @@ bool plMoviePlayer::Start() float height = (static_cast(video->GetHeight()) / static_cast(plateMgr.GetPipeHeight())) * fScale.fY; plateMgr.CreatePlate(&fPlate, fPosition.fX, fPosition.fY, width, height); - fPlate->SetVisible(true); - fTexture = fPlate->CreateMaterial(static_cast(video->GetWidth()), static_cast(video->GetHeight()), nullptr); + fTexture = fPlate->CreateMaterial(static_cast(video->GetWidth()), static_cast(video->GetHeight()), false); //initialize opus const mkvparser::AudioTrack* audio = static_cast(fAudioTrack->GetTrack()); @@ -352,6 +349,7 @@ bool plMoviePlayer::Start() if (error != OPUS_OK) hsAssert(false, "Error occured initalizing opus"); + fLastFrameTime = static_cast(hsTimer::GetMilliSeconds()); fPlaying = true; return true; @@ -365,25 +363,28 @@ bool plMoviePlayer::NextFrame() if (!fPlaying) return false; + int64_t frameTime = static_cast(hsTimer::GetMilliSeconds()); + int64_t frameTimeDelta = frameTime - fLastFrameTime; + fLastFrameTime = frameTime; + + if (fPaused) + return true; + #ifdef VIDEO_AVAILABLE // Get our current timecode - int64_t movieTime = 0; - if (fStartTime == 0) - fStartTime = static_cast(hsTimer::GetMilliSeconds()); - else - movieTime = GetMovieTime(); + fMovieTime += frameTimeDelta; std::vector audio; std::vector video; uint8_t tracksWithData = 0; if (fAudioTrack) { - if (fAudioTrack->GetFrames(fReader, movieTime, audio)) + if (fAudioTrack->GetFrames(fReader, fMovieTime, audio)) tracksWithData++; } if (fVideoTrack) { - if (fVideoTrack->GetFrames(fReader, movieTime, video)) + if (fVideoTrack->GetFrames(fReader, fMovieTime, video)) tracksWithData++; } if (!tracksWithData) @@ -402,11 +403,22 @@ bool plMoviePlayer::NextFrame() #endif // VIDEO_AVAILABLE } +bool plMoviePlayer::Pause(bool on) +{ + if (!fPlaying) + return false; + + fPaused = on; + return true; +} + bool plMoviePlayer::Stop() { fPlaying = false; if (fAudioSound) fAudioSound->Stop(); + if (fPlate) + fPlate->SetVisible(false); for (int i = 0; i < fCallbacks.size(); i++) fCallbacks[i]->Send(); fCallbacks.clear(); diff --git a/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.h b/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.h index 14401c21..59c11e26 100644 --- a/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.h +++ b/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.h @@ -79,13 +79,13 @@ protected: std::unique_ptr fVpx; class OpusDecoder* fOpusDecoder; - int64_t fStartTime; + int64_t fMovieTime, fLastFrameTime; hsPoint2 fPosition, fScale; plFileName fMoviePath; bool fPlaying; + bool fPaused; - int64_t GetMovieTime() const; bool IOpenMovie(); void IProcessVideoFrame(const std::vector& frames); void IProcessAudioFrame(const std::vector& frames); @@ -95,7 +95,7 @@ public: ~plMoviePlayer(); bool Start(); - bool Pause(bool on) { return false; } + bool Pause(bool on); bool Stop(); bool NextFrame(); @@ -108,6 +108,8 @@ public: void SetColor(const hsColorRGBA& c) { } const hsColorRGBA GetColor() const { return hsColorRGBA(); } + + /** The volume is handled by the options menu slider, as of now. */ void SetVolume(float v) { } hsPoint2 GetPosition() const { return fPosition; }