From 178acc3f5c4cae559f5d5c1026bafa51384ab913 Mon Sep 17 00:00:00 2001 From: wang-bin Date: Tue, 2 Jun 2015 11:37:14 +0800 Subject: [PATCH] workaround for null demuxer.formatContext(). #458 --- src/AVPlayer.cpp | 1 - src/AVPlayerPrivate.cpp | 17 +++++++++++++---- src/AVPlayerPrivate.h | 2 -- src/Statistics.cpp | 1 + 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/AVPlayer.cpp b/src/AVPlayer.cpp index 63fc4582c..5831963ab 100644 --- a/src/AVPlayer.cpp +++ b/src/AVPlayer.cpp @@ -617,7 +617,6 @@ void AVPlayer::loadInternal() Q_EMIT internalAudioTracksChanged(d->audio_tracks); Q_EMIT durationChanged(duration()); // setup parameters from loaded media - d->fmt_ctx = d->demuxer.formatContext(); d->media_start_pts = d->demuxer.startTime(); // TODO: what about other proctols? some vob duration() == 0 if (duration() > 0) diff --git a/src/AVPlayerPrivate.cpp b/src/AVPlayerPrivate.cpp index 874e5f708..83a2a0bd4 100644 --- a/src/AVPlayerPrivate.cpp +++ b/src/AVPlayerPrivate.cpp @@ -67,7 +67,6 @@ AVPlayer::Private::Private() , async_load(true) , loaded(false) , relative_time_mode(true) - , fmt_ctx(0) , media_start_pts(0) , media_end(kInvalidPosition) , last_position(0) @@ -184,13 +183,18 @@ void AVPlayer::Private::initBaseStatistics() { statistics.reset(); statistics.url = current_source.type() == QVariant::String ? current_source.toString() : QString(); + statistics.start_time = QTime(0, 0, 0).addMSecs(int(demuxer.startTime())); + statistics.duration = QTime(0, 0, 0).addMSecs((int)demuxer.duration()); + AVFormatContext *fmt_ctx = demuxer.formatContext(); + if (!fmt_ctx) { + qWarning("demuxer.formatContext()==null. internal error"); + updateNotifyInterval(); + return; + } statistics.bit_rate = fmt_ctx->bit_rate; statistics.format = QString().sprintf("%s - %s", fmt_ctx->iformat->name, fmt_ctx->iformat->long_name); //AV_TIME_BASE_Q: msvc error C2143 //fmt_ctx->duration may be AV_NOPTS_VALUE. AVDemuxer.duration deals with this case - statistics.start_time = QTime(0, 0, 0).addMSecs(int(demuxer.startTime())); - statistics.duration = QTime(0, 0, 0).addMSecs((int)demuxer.duration()); - statistics.metadata.clear(); AVDictionaryEntry *tag = NULL; while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { statistics.metadata.insert(tag->key, tag->value); @@ -200,6 +204,11 @@ void AVPlayer::Private::initBaseStatistics() void AVPlayer::Private::initCommonStatistics(int s, Statistics::Common *st, AVCodecContext *avctx) { + AVFormatContext *fmt_ctx = demuxer.formatContext(); + if (!fmt_ctx) { + qWarning("demuxer.formatContext()==null. internal error"); + return; + } AVStream *stream = fmt_ctx->streams[s]; qDebug("stream: %d, duration=%lld (%lld ms), time_base=%f", s, stream->duration, qint64(qreal(stream->duration)*av_q2d(stream->time_base)*1000.0), av_q2d(stream->time_base)); // AVCodecContext.codec_name is deprecated. use avcodec_get_name. check null avctx->codec? diff --git a/src/AVPlayerPrivate.h b/src/AVPlayerPrivate.h index 0f929b579..1de46b41e 100644 --- a/src/AVPlayerPrivate.h +++ b/src/AVPlayerPrivate.h @@ -104,8 +104,6 @@ class AVPlayer::Private QVariant current_source, pendding_source; bool loaded; // for current source bool relative_time_mode; - // TODO: remove - AVFormatContext *fmt_ctx; //changed when reading a packet qint64 media_start_pts; // read from media stream qint64 media_end; /* diff --git a/src/Statistics.cpp b/src/Statistics.cpp index f94cc7749..b8b9f566f 100644 --- a/src/Statistics.cpp +++ b/src/Statistics.cpp @@ -126,6 +126,7 @@ void Statistics::reset() video = Common(); audio_only = AudioOnly(); video_only = VideoOnly(); + metadata.clear(); } } //namespace QtAV