Skip to content

Commit

Permalink
added avFormatOptions property for qml AVPlayer
Browse files Browse the repository at this point in the history
now it's possible to set audio and video format options inside AVPlayer QML
object
  • Loading branch information
ddaletski committed Jul 27, 2016
1 parent 09e6e40 commit e7f1e64
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions qml/QmlAV/QmlAVPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 74,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(QVariantMap avFormatOptions READ avFormatOptions WRITE setAVFormatOptions NOTIFY avFormatOptionsChanged)
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)
Expand Down Expand Up @@ -196,6 197,8 @@ class QmlAVPlayer : public QObject, public QQmlParserStatus
void setVideoCodecPriority(const QStringList& p);
QVariantMap videoCodecOptions() const;
void setVideoCodecOptions(const QVariantMap& value);
QVariantMap avFormatOptions() const;
void setAVFormatOptions(const QVariantMap& value);

bool useWallclockAsTimestamps() const;
void setWallclockAsTimestamps(bool use_wallclock_as_timestamps);
Expand Down Expand Up @@ -275,6 278,7 @@ public Q_SLOTS:
void bufferProgressChanged();
void videoCodecPriorityChanged();
void videoCodecOptionsChanged();
void avFormatOptionsChanged();
void useWallclockAsTimestampsChanged();
void channelLayoutChanged();
void timeoutChanged();
Expand Down Expand Up @@ -342,6 346,7 @@ private Q_SLOTS:

QScopedPointer<MediaMetaData> m_metaData;
QVariantMap vcodec_opt;
QVariantMap avfmt_opt;

QList<QuickAudioFilter*> m_afilters;
QList<QuickVideoFilter*> m_vfilters;
Expand Down
32 changes: 32 additions & 0 deletions qml/QmlAVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 264,29 @@ void QmlAVPlayer::setVideoCodecOptions(const QVariantMap &value)
mpPlayer->setVideoDecoderPriority(videoCodecPriority());
}

QVariantMap QmlAVPlayer::avFormatOptions() const
{
return avfmt_opt;
}

void QmlAVPlayer::setAVFormatOptions(const QVariantMap &value)
{
if (value == avfmt_opt)
return;
avfmt_opt = value;
Q_EMIT avFormatOptionsChanged();
if (!mpPlayer) {
qWarning("player not ready");
return;
}
QVariantHash avfopt;
for (QVariantMap::const_iterator cit = avfmt_opt.cbegin(); cit != avfmt_opt.cend(); cit) {
avfopt[cit.key()] = cit.value();
}
if (!avfopt.isEmpty())
mpPlayer->setOptionsForFormat(avfopt);
}

bool QmlAVPlayer::useWallclockAsTimestamps() const
{
return mUseWallclockAsTimestamps;
Expand Down Expand Up @@ -668,6 691,15 @@ void QmlAVPlayer::setPlaybackState(PlaybackState playbackState)
if (!vcopt.isEmpty())
mpPlayer->setOptionsForVideoCodec(vcopt);
}
if (!avfmt_opt.isEmpty()) {
QVariantHash avfopt;
for (QVariantMap::const_iterator cit = avfmt_opt.cbegin(); cit != avfmt_opt.cend(); cit) {
avfopt[cit.key()] = cit.value();
}
if (!avfopt.isEmpty())
mpPlayer->setOptionsForFormat(avfopt);
}

mpPlayer->setStartPosition(startPosition());
if (stopPosition() == PositionMax)
mpPlayer->setStopPosition();
Expand Down

0 comments on commit e7f1e64

Please sign in to comment.