Skip to content

Commit

Permalink
Add useWallclockAsTimerstamps property to AVPlayer for media stream has
Browse files Browse the repository at this point in the history
no timestamp info
  • Loading branch information
cfsghost committed Jun 23, 2015
1 parent 27057db commit deae22e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions qml/QmlAV/QmlAVPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class QmlAVPlayer : public QObject, public QQmlParserStatus
Q_PROPERTY(QStringList videoCodecs READ videoCodecs)
Q_PROPERTY(QStringList videoCodecPriority READ videoCodecPriority WRITE setVideoCodecPriority NOTIFY videoCodecPriorityChanged)
Q_PROPERTY(QVariantMap videoCodecOptions READ videoCodecOptions WRITE setVideoCodecOptions NOTIFY videoCodecOptionsChanged)
Q_PROPERTY(bool useWallclockAsTimestamps READ useWallclockAsTimestamps WRITE setWallclockAsTimestamps NOTIFY useWallclockAsTimestampsChanged)
Q_PROPERTY(QtAV::VideoCapture *videoCapture READ videoCapture CONSTANT)
Q_PROPERTY(int audioTrack READ audioTrack WRITE setAudioTrack NOTIFY audioTrackChanged)
Q_PROPERTY(QUrl externalAudio READ externalAudio WRITE setExternalAudio NOTIFY externalAudioChanged)
Expand Down Expand Up @@ -168,6 +169,9 @@ class QmlAVPlayer : public QObject, public QQmlParserStatus
QVariantMap videoCodecOptions() const;
void setVideoCodecOptions(const QVariantMap& value);

bool useWallclockAsTimestamps() const;
void setWallclockAsTimestamps(bool use_wallclock_as_timestamps);

void setAudioChannels(int channels);
int audioChannels() const;
void setChannelLayout(ChannelLayout channel);
Expand Down Expand Up @@ -229,6 +233,7 @@ public Q_SLOTS:
void bufferProgressChanged();
void videoCodecPriorityChanged();
void videoCodecOptionsChanged();
void useWallclockAsTimestampsChanged();
void channelLayoutChanged();
void timeoutChanged();
void abortOnTimeoutChanged();
Expand Down Expand Up @@ -257,6 +262,7 @@ private Q_SLOTS:
private:
Q_DISABLE_COPY(QmlAVPlayer)

bool mUseWallclockAsTimestamps;
bool m_complete;
bool m_mute;
bool mAutoPlay;
Expand Down
27 changes: 27 additions & 0 deletions qml/QmlAVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QtAV/AVPlayer.h>
#include <QtAV/AudioOutput.h>
#include <QtAV/VideoCapture.h>
#include <QDebug>

template<typename ID, typename Factory>
static QStringList idsToNames(QVector<ID> ids) {
Expand Down Expand Up @@ -57,6 +58,7 @@ static inline QVector<VideoDecoderId> VideoDecodersFromNames(const QStringList&

QmlAVPlayer::QmlAVPlayer(QObject *parent) :
QObject(parent)
, mUseWallclockAsTimestamps(false)
, m_complete(false)
, m_mute(false)
, mAutoPlay(false)
Expand Down Expand Up @@ -250,6 +252,31 @@ void QmlAVPlayer::setVideoCodecOptions(const QVariantMap &value)
// player maybe not ready
}

bool QmlAVPlayer::useWallclockAsTimestamps() const
{
return mUseWallclockAsTimestamps;
}

void QmlAVPlayer::setWallclockAsTimestamps(bool use_wallclock_as_timestamps)
{
if (mUseWallclockAsTimestamps == use_wallclock_as_timestamps)
return;

mUseWallclockAsTimestamps = use_wallclock_as_timestamps;

QVariantHash opt = mpPlayer->optionsForFormat();

if (use_wallclock_as_timestamps) {
opt["use_wallclock_as_timestamps"] = 1;
mpPlayer->setBufferValue(1);
} else {
opt.remove("use_wallclock_as_timestamps");
mpPlayer->setBufferValue(-1);
}
mpPlayer->setOptionsForFormat(opt);
emit useWallclockAsTimestampsChanged();
}

static AudioFormat::ChannelLayout toAudioFormatChannelLayout(QmlAVPlayer::ChannelLayout ch)
{
struct {
Expand Down
1 change: 1 addition & 0 deletions qml/plugins.qmltypes
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ Module {
Property { name: "videoCodecPriority"; type: "QStringList" }
Property { name: "videoCodecOptions"; type: "QVariantMap" }
Property { name: "videoCapture"; type: "QtAV::VideoCapture"; isReadonly: true; isPointer: true }
Property { name: "useWallclockAsTimestamps"; type: "bool" }
Property { name: "audioTrack"; type: "int" }
Property { name: "externalAudio"; type: "QUrl" }
Property { name: "internalAudioTracks"; type: "QVariantList"; isReadonly: true }
Expand Down

0 comments on commit deae22e

Please sign in to comment.