forked from mirror/openmw-tes3mp
eb1c24ffe6
- Split video player to separate source files. - Move video player engine sources to extern/ (repository will be set up on github soon). - Audio is handled in a MovieAudioFactory, implemented by the user (here in MWSound subsystem). - Handle conversion of unsupported channel layouts via ffmpeg's swresample.
95 lines
1.4 KiB
C++
95 lines
1.4 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();
|
|
}
|
|
}
|
|
|
|
void VideoPlayer::update ()
|
|
{
|
|
if(mState)
|
|
{
|
|
if(!mState->update())
|
|
close();
|
|
}
|
|
}
|
|
|
|
std::string VideoPlayer::getTextureName()
|
|
{
|
|
std::string name;
|
|
if (mState)
|
|
name = mState->mTexture->getName();
|
|
return name;
|
|
}
|
|
|
|
int VideoPlayer::getVideoWidth()
|
|
{
|
|
int width=0;
|
|
if (mState)
|
|
width = mState->mTexture->getWidth();
|
|
return width;
|
|
}
|
|
|
|
int VideoPlayer::getVideoHeight()
|
|
{
|
|
int height=0;
|
|
if (mState)
|
|
height = mState->mTexture->getHeight();
|
|
return height;
|
|
}
|
|
|
|
void VideoPlayer::close()
|
|
{
|
|
if(mState)
|
|
{
|
|
mState->deinit();
|
|
|
|
delete mState;
|
|
mState = NULL;
|
|
}
|
|
}
|
|
|
|
bool VideoPlayer::isPlaying ()
|
|
{
|
|
return mState != NULL;
|
|
}
|
|
|
|
bool VideoPlayer::hasAudioStream()
|
|
{
|
|
return mState && mState->audio_st != NULL;
|
|
}
|
|
|
|
}
|