openmw-tes3coop/extern/ogre-ffmpeg-videoplayer/videoplayer.cpp
scrawl b39d69e98c Videoplayer fixes, play/pause & seeking
- Fix rindex overflow
 - Fix audio sample size bugs (was using sample_fmt and channel count of the decoder, instead of the resampled settings). We didn't notice this bug before, because the OpenAL MovieAudioFactory tries to resample to a format of the same byte size.
 - Add support for play/pause and seeking controls (not used by cutscenes in OpenMW)
 - Closing the video when arriving at the stream end is now handled by the user (we may also want to keep the video open and seek back)

The video player now has a standalone demo, at https://github.com/scrawl/ogre-ffmpeg-videoplayer
2014-10-24 21:31:11 +02:00

127 lines
2 KiB
C++

#include "videoplayer.hpp"
#include "videostate.hpp"
namespace Video
{
VideoPlayer::VideoPlayer()
: mState(NULL)
{
}
VideoPlayer::~VideoPlayer()
{
if(mState)
close();
}
void VideoPlayer::setAudioFactory(MovieAudioFactory *factory)
{
mAudioFactory.reset(factory);
}
void VideoPlayer::playVideo(const std::string &resourceName)
{
if(mState)
close();
try {
mState = new VideoState;
mState->setAudioFactory(mAudioFactory.get());
mState->init(resourceName);
}
catch(std::exception& e) {
std::cerr<< "Failed to play video: "<<e.what() <<std::endl;
close();
}
}
bool VideoPlayer::update ()
{
if(mState)
return mState->update();
return false;
}
std::string VideoPlayer::getTextureName()
{
std::string name;
if (mState && !mState->mTexture.isNull())
name = mState->mTexture->getName();
return name;
}
int VideoPlayer::getVideoWidth()
{
int width=0;
if (mState && !mState->mTexture.isNull())
width = mState->mTexture->getWidth();
return width;
}
int VideoPlayer::getVideoHeight()
{
int height=0;
if (mState && !mState->mTexture.isNull())
height = mState->mTexture->getHeight();
return height;
}
void VideoPlayer::close()
{
if(mState)
{
mState->deinit();
delete mState;
mState = NULL;
}
}
bool VideoPlayer::hasAudioStream()
{
return mState && mState->audio_st != NULL;
}
void VideoPlayer::play()
{
if (mState)
mState->setPaused(false);
}
void VideoPlayer::pause()
{
if (mState)
mState->setPaused(true);
}
bool VideoPlayer::isPaused()
{
if (mState)
return mState->mPaused;
return true;
}
double VideoPlayer::getCurrentTime()
{
if (mState)
return mState->get_master_clock();
return 0.0;
}
void VideoPlayer::seek(double time)
{
if (mState)
mState->seekTo(time);
}
double VideoPlayer::getDuration()
{
if (mState)
return mState->getDuration();
return 0.0;
}
}