Give a name to video streams for logging purposes

c++11
scrawl 10 years ago
parent 77f733362c
commit 00f4f78717

@ -30,7 +30,7 @@ void VideoWidget::playVideo(const std::string &video)
{ {
mPlayer->setAudioFactory(new MWSound::MovieAudioFactory()); mPlayer->setAudioFactory(new MWSound::MovieAudioFactory());
mPlayer->playVideo(mVFS->get(video)); mPlayer->playVideo(mVFS->get(video), video);
osg::ref_ptr<osg::Texture2D> texture = mPlayer->getVideoTexture(); osg::ref_ptr<osg::Texture2D> texture = mPlayer->getVideoTexture();
if (!texture) if (!texture)

@ -25,7 +25,7 @@ void VideoPlayer::setAudioFactory(MovieAudioFactory *factory)
mAudioFactory.reset(factory); mAudioFactory.reset(factory);
} }
void VideoPlayer::playVideo(boost::shared_ptr<std::istream> inputstream) void VideoPlayer::playVideo(boost::shared_ptr<std::istream> inputstream, const std::string& name)
{ {
if(mState) if(mState)
close(); close();
@ -33,7 +33,7 @@ void VideoPlayer::playVideo(boost::shared_ptr<std::istream> inputstream)
try { try {
mState = new VideoState; mState = new VideoState;
mState->setAudioFactory(mAudioFactory.get()); mState->setAudioFactory(mAudioFactory.get());
mState->init(inputstream); mState->init(inputstream, name);
// wait until we have the first picture // wait until we have the first picture
while (mState->video_st && !mState->mTexture.get()) while (mState->video_st && !mState->mTexture.get())

@ -41,7 +41,8 @@ namespace Video
/// Play the given video. If a video is already playing, the old video is closed first. /// Play the given video. If a video is already playing, the old video is closed first.
/// @note The video will be unpaused by default. Use the pause() and play() methods to control pausing. /// @note The video will be unpaused by default. Use the pause() and play() methods to control pausing.
void playVideo (boost::shared_ptr<std::istream> inputstream); /// @param name A name for the video stream - only used for logging purposes.
void playVideo (boost::shared_ptr<std::istream> inputstream, const std::string& name);
/// Get the current playback time position in the video, in seconds /// Get the current playback time position in the video, in seconds
double getCurrentTime(); double getCurrentTime();

@ -602,7 +602,7 @@ int VideoState::stream_open(int stream_index, AVFormatContext *pFormatCtx)
return 0; return 0;
} }
void VideoState::init(boost::shared_ptr<std::istream> inputstream) void VideoState::init(boost::shared_ptr<std::istream> inputstream, const std::string &name)
{ {
int video_index = -1; int video_index = -1;
int audio_index = -1; int audio_index = -1;
@ -622,8 +622,6 @@ void VideoState::init(boost::shared_ptr<std::istream> inputstream)
if(this->format_ctx) if(this->format_ctx)
this->format_ctx->pb = ioCtx; this->format_ctx->pb = ioCtx;
std::string videoName;
// Open video file // Open video file
/// ///
/// format_ctx->pb->buffer must be freed by hand, /// format_ctx->pb->buffer must be freed by hand,
@ -631,7 +629,7 @@ void VideoState::init(boost::shared_ptr<std::istream> inputstream)
/// ///
/// https://trac.ffmpeg.org/ticket/1357 /// https://trac.ffmpeg.org/ticket/1357
/// ///
if(!this->format_ctx || avformat_open_input(&this->format_ctx, videoName.c_str(), NULL, NULL)) if(!this->format_ctx || avformat_open_input(&this->format_ctx, name.c_str(), NULL, NULL))
{ {
if (this->format_ctx != NULL) if (this->format_ctx != NULL)
{ {
@ -655,7 +653,7 @@ void VideoState::init(boost::shared_ptr<std::istream> inputstream)
throw std::runtime_error("Failed to retrieve stream information"); throw std::runtime_error("Failed to retrieve stream information");
// Dump information about file onto standard error // Dump information about file onto standard error
av_dump_format(this->format_ctx, 0, videoName.c_str(), 0); av_dump_format(this->format_ctx, 0, name.c_str(), 0);
for(i = 0;i < this->format_ctx->nb_streams;i++) for(i = 0;i < this->format_ctx->nb_streams;i++)
{ {

@ -84,7 +84,7 @@ struct VideoState {
void setAudioFactory(MovieAudioFactory* factory); void setAudioFactory(MovieAudioFactory* factory);
void init(boost::shared_ptr<std::istream> inputstream); void init(boost::shared_ptr<std::istream> inputstream, const std::string& name);
void deinit(); void deinit();
void setPaused(bool isPaused); void setPaused(bool isPaused);

Loading…
Cancel
Save