mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-27 03:35:27 +00:00
Merge remote-tracking branch 'scrawl/videoplayback' into videoplayback
This commit is contained in:
commit
e291d0943d
@ -796,13 +796,14 @@ public:
|
||||
}
|
||||
|
||||
void init_state(VideoState *is, const std::string& resourceName)
|
||||
{
|
||||
try
|
||||
{
|
||||
int video_index = -1;
|
||||
int audio_index = -1;
|
||||
unsigned int i;
|
||||
|
||||
is->av_sync_type = DEFAULT_AV_SYNC_TYPE;
|
||||
is->format_ctx = avformat_alloc_context();
|
||||
is->videoStream = -1;
|
||||
is->audioStream = -1;
|
||||
is->refresh = 0;
|
||||
@ -812,14 +813,23 @@ public:
|
||||
if(is->stream.isNull())
|
||||
throw std::runtime_error("Failed to open video resource");
|
||||
|
||||
is->format_ctx = avformat_alloc_context();
|
||||
|
||||
is->format_ctx->pb = avio_alloc_context(NULL, 0, 0, is, OgreResource_Read, OgreResource_Write, OgreResource_Seek);
|
||||
if(!is->format_ctx->pb)
|
||||
{
|
||||
avformat_free_context(is->format_ctx);
|
||||
throw std::runtime_error("Failed to allocate ioContext ");
|
||||
}
|
||||
|
||||
// Open video file
|
||||
/// \todo leak here, ffmpeg or valgrind bug ?
|
||||
if (avformat_open_input(&is->format_ctx, resourceName.c_str(), NULL, NULL))
|
||||
{
|
||||
// "Note that a user-supplied AVFormatContext will be freed on failure."
|
||||
is->format_ctx = NULL;
|
||||
throw std::runtime_error("Failed to open video input");
|
||||
}
|
||||
|
||||
// Retrieve stream information
|
||||
if(avformat_find_stream_info(is->format_ctx, NULL) < 0)
|
||||
@ -841,6 +851,17 @@ public:
|
||||
if(video_index >= 0)
|
||||
stream_component_open(is, video_index, is->format_ctx);
|
||||
}
|
||||
catch (std::runtime_error& e)
|
||||
{
|
||||
is->quit = 1;
|
||||
throw;
|
||||
}
|
||||
catch (Ogre::Exception& e)
|
||||
{
|
||||
is->quit = 1;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
void deinit_state(VideoState *is)
|
||||
{
|
||||
@ -855,12 +876,16 @@ public:
|
||||
if(is->videoStream >= 0)
|
||||
avcodec_close(is->video_st->codec);
|
||||
|
||||
if (is->sws_context)
|
||||
sws_freeContext(is->sws_context);
|
||||
|
||||
if (is->format_ctx)
|
||||
{
|
||||
AVIOContext *ioContext = is->format_ctx->pb;
|
||||
avformat_close_input(&is->format_ctx);
|
||||
av_free(ioContext);
|
||||
}
|
||||
}
|
||||
|
||||
VideoPlayer::VideoPlayer(Ogre::SceneManager* sceneMgr)
|
||||
: mState(NULL)
|
||||
|
Loading…
x
Reference in New Issue
Block a user