added video timing

This commit is contained in:
scrawl 2012-09-25 02:54:29 +02:00
parent 73c69e8eda
commit 05eb307bfb
3 changed files with 19 additions and 1 deletions

View file

@ -372,6 +372,7 @@ void WindowManager::updateVisible()
MyGUI::PointerManager::getInstance().setVisible(false);
break;
case GM_Video:
MyGUI::PointerManager::getInstance().setVisible(false);
mHud->setVisible(false);
break;
default:

View file

@ -109,6 +109,7 @@ namespace MWRender
mVideoStreamId = -1;
mEOF = false;
mDisplayedFrameCount = 0;
// if something is already playing, close it
if (mAvContext)
@ -236,6 +237,8 @@ namespace MWRender
mTextureUnit->setTextureName ("VideoTexture");
mTimer.reset();
}
void VideoPlayer::throwError(int error)
@ -309,6 +312,14 @@ namespace MWRender
if (!mAvContext)
return;
// Time elapsed since the video started
float realTime = mTimer.getMilliseconds ()/1000.f;
// Here is the time we're at in the video
float movieTime = mDisplayedFrameCount * mWantedFrameTime;
if (movieTime >= realTime)
return;
if (!mVideoPacketQueue.size() && mEOF)
close();
@ -353,10 +364,11 @@ namespace MWRender
Ogre::PixelBox pb(mVideoCodecContext->width, mVideoCodecContext->height, 1, Ogre::PF_BYTE_RGBA, mRGBAFrame->data[0]);
pixelBuffer->blitFromMemory(pb);
//m_displayedFrameCount++;
av_free_packet(mVideoPacketQueue.front());
av_free(mVideoPacketQueue.front());
mVideoPacketQueue.pop();
++mDisplayedFrameCount;
}
void VideoPlayer::close ()

View file

@ -9,6 +9,7 @@
#include <OgreDataStream.h>
#include <OgreTexture.h>
#include <OgreTimer.h>
namespace Ogre
{
@ -53,6 +54,8 @@ namespace MWRender
bool mEOF;
Ogre::Timer mTimer;
// VIDEO
AVCodecContext* mVideoCodecContext;
AVCodec* mVideoCodec;
@ -64,6 +67,8 @@ namespace MWRender
float mDecodingTime;
std::queue <AVPacket *> mVideoPacketQueue;
int mDisplayedFrameCount;
bool readFrameAndQueue();
bool saveFrame(AVPacket* frame);