Skip to content

Commit

Permalink
workaround for null demuxer.formatContext(). wang-bin#458
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jun 2, 2015
1 parent a5dc36d commit 178acc3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions src/AVPlayerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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?
Expand Down
2 changes: 0 additions & 2 deletions src/AVPlayerPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/*
Expand Down
1 change: 1 addition & 0 deletions src/Statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void Statistics::reset()
video = Common();
audio_only = AudioOnly();
video_only = VideoOnly();
metadata.clear();
}

} //namespace QtAV

0 comments on commit 178acc3

Please sign in to comment.