forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc15d1f
commit 090ebb2
Showing
2 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 1,4 @@ | ||
/****************************************************************************** | ||
/****************************************************************************** | ||
QtAV: Multimedia framework based on Qt and FFmpeg | ||
Copyright (C) 2012-2017 Wang Bin <[email protected]> | ||
|
@@ -45,6 45,9 @@ | |
#include "QtAV/private/AVCompat.h" | ||
#include "utils/internal.h" | ||
#include "utils/Logger.h" | ||
extern "C" { | ||
#include <libavutil/mathematics.h> | ||
} | ||
|
||
#define EOF_ISSUE_SOLVED 0 | ||
namespace QtAV { | ||
|
@@ -680,6 683,7 @@ void AVPlayer::loadInternal() | |
d->video_tracks = d->getTracksInfo(&d->demuxer, AVDemuxer::VideoStream); | ||
Q_EMIT internalVideoTracksChanged(d->video_tracks); | ||
Q_EMIT durationChanged(duration()); | ||
Q_EMIT chaptersChanged(chapters()); | ||
// setup parameters from loaded media | ||
d->media_start_pts = d->demuxer.startTime(); | ||
// TODO: what about other proctols? some vob duration() == 0 | ||
|
@@ -715,6 719,7 @@ void AVPlayer::unload() | |
d->vdec = 0; | ||
} | ||
d->demuxer.unload(); | ||
Q_EMIT chaptersChanged(0); | ||
Q_EMIT durationChanged(0LL); // for ui, slider is invalid. use stopped instead, and remove this signal here? | ||
// ?? | ||
d->audio_tracks = d->getTracksInfo(&d->demuxer, AVDemuxer::AudioStream); | ||
|
@@ -1385,6 1390,42 @@ void AVPlayer::tryClearVideoRenderers() | |
} | ||
} | ||
|
||
void AVPlayer::seekChapter(int incr) | ||
{ | ||
if (!chapters()) | ||
return; | ||
|
||
qint64 pos = masterClock()->value() * AV_TIME_BASE; | ||
int i = 0; | ||
|
||
AVFormatContext *ic = d->demuxer.formatContext(); | ||
|
||
AVRational av_time_base_q; | ||
av_time_base_q.num = 1; | ||
av_time_base_q.den = AV_TIME_BASE; | ||
|
||
/* find the current chapter */ | ||
for (i = 0; i < chapters(); i) { | ||
AVChapter *ch = ic->chapters[i]; | ||
if (av_compare_ts(pos, av_time_base_q, ch->start, ch->time_base) < 0) { | ||
--i; | ||
break; | ||
} | ||
} | ||
|
||
i = incr; | ||
//i = FFMAX(i, 0); | ||
if (i <= 0) | ||
i = 0; | ||
if (i >= chapters()) | ||
return; | ||
|
||
//av_log(NULL, AV_LOG_VERBOSE, "Seeking to chapter %d.\n", i); | ||
qDebug() << QString::fromLatin1("Seeking to chapter : ") << QString::number(i); | ||
setPosition(av_rescale_q(ic->chapters[i]->start, ic->chapters[i]->time_base, | ||
av_time_base_q) / 1000); | ||
} | ||
|
||
void AVPlayer::stop() | ||
{ | ||
// check d->timer_id, <0 return? | ||
|
@@ -1532,6 1573,20 @@ void AVPlayer::seekBackward() | |
seek(position() - kSeekMS); | ||
} | ||
|
||
void AVPlayer::seekNextChapter() | ||
{ | ||
if (chapters() <= 1) | ||
return; | ||
seekChapter(1); | ||
} | ||
|
||
void AVPlayer::seekPreviousChapter() | ||
{ | ||
if (chapters() <= 1) | ||
return; | ||
seekChapter(-1); | ||
} | ||
|
||
void AVPlayer::setSeekType(SeekType type) | ||
{ | ||
d->seek_type = type; | ||
|
@@ -1635,6 1690,11 @@ int AVPlayer::saturation() const | |
return d->saturation; | ||
} | ||
|
||
unsigned int AVPlayer::chapters() const | ||
{ | ||
return d->demuxer.formatContext()->nb_chapters; | ||
} | ||
|
||
void AVPlayer::setSaturation(int val) | ||
{ | ||
if (d->saturation == val) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 1,4 @@ | ||
/****************************************************************************** | ||
/****************************************************************************** | ||
QtAV: Multimedia framework based on Qt and FFmpeg | ||
Copyright (C) 2012-2017 Wang Bin <[email protected]> | ||
|
@@ -82,6 82,7 @@ class Q_AV_EXPORT AVPlayer : public QObject | |
Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged) | ||
Q_PROPERTY(QtAV::MediaStatus mediaStatus READ mediaStatus NOTIFY mediaStatusChanged) | ||
Q_PROPERTY(QtAV::MediaEndAction mediaEndAction READ mediaEndAction WRITE setMediaEndAction NOTIFY mediaEndActionChanged) | ||
Q_PROPERTY(qint64 chapters READ chapters NOTIFY chaptersChanged) | ||
Q_ENUMS(State) | ||
public: | ||
/*! | ||
|
@@ -374,6 375,7 @@ class Q_AV_EXPORT AVPlayer : public QObject | |
int contrast() const; | ||
int hue() const; //not implemented | ||
int saturation() const; | ||
unsigned int chapters() const; | ||
/*! | ||
* \sa AVDemuxer::setOptions() | ||
* example: | ||
|
@@ -489,6 491,8 @@ public Q_SLOTS: | |
void seek(qint64 pos); //ms. same as setPosition(pos) | ||
void seekForward(); | ||
void seekBackward(); | ||
void seekNextChapter(); | ||
void seekPreviousChapter(); | ||
void setSeekType(SeekType type); | ||
SeekType seekType() const; | ||
|
||
|
@@ -579,6 583,7 @@ public Q_SLOTS: | |
void contrastChanged(int val); | ||
void hueChanged(int val); | ||
void saturationChanged(int val); | ||
void chaptersChanged(unsigned int val); | ||
void subtitleStreamChanged(int value); | ||
/*! | ||
* \brief internalAudioTracksChanged | ||
|
@@ -611,6 616,7 @@ private Q_SLOTS: | |
void updateMediaStatus(QtAV::MediaStatus status); | ||
void onSeekFinished(qint64 value); | ||
void tryClearVideoRenderers(); | ||
void seekChapter(int incr); | ||
protected: | ||
// TODO: set position check timer interval | ||
virtual void timerEvent(QTimerEvent *); | ||
|