From 6faf8679253a6e082cc578b967dd67492099de3d Mon Sep 17 00:00:00 2001 From: wang-bin Date: Thu, 18 May 2017 17:13:01 +0800 Subject: [PATCH] qml: add bufferSize & internalVideoTracks property from @Killerbeans --- qml/QmlAV/QmlAVPlayer.h | 21 ++++++++++++++++++++- qml/QmlAVPlayer.cpp | 40 +++++++++++++++++++++++++++++++++++++++- qml/Video.qml | 10 ++++++++++ qml/plugins.qmltypes | 1 + 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/qml/QmlAV/QmlAVPlayer.h b/qml/QmlAV/QmlAVPlayer.h index 3e5d2fe5f..02580a1d8 100644 --- a/qml/QmlAV/QmlAVPlayer.h +++ b/qml/QmlAV/QmlAVPlayer.h @@ -1,6 +1,6 @@ /****************************************************************************** QtAV: Multimedia framework based on Qt and FFmpeg - Copyright (C) 2012-2016 Wang Bin + Copyright (C) 2012-2017 Wang Bin * This file is part of QtAV (from 2013) @@ -78,8 +78,11 @@ class QmlAVPlayer : public QObject, public QQmlParserStatus 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(int videoTrack READ videoTrack WRITE setVideoTrack NOTIFY videoTrackChanged) + Q_PROPERTY(int bufferSize READ bufferSize WRITE setBufferSize NOTIFY bufferSizeChanged) Q_PROPERTY(QUrl externalAudio READ externalAudio WRITE setExternalAudio NOTIFY externalAudioChanged) Q_PROPERTY(QVariantList internalAudioTracks READ internalAudioTracks NOTIFY internalAudioTracksChanged) + Q_PROPERTY(QVariantList internalVideoTracks READ internalVideoTracks NOTIFY internalVideoTracksChanged) Q_PROPERTY(QVariantList externalAudioTracks READ externalAudioTracks NOTIFY externalAudioTracksChanged) Q_PROPERTY(QVariantList internalSubtitleTracks READ internalSubtitleTracks NOTIFY internalSubtitleTracksChanged) // internal subtitle, e.g. mkv embedded subtitles @@ -221,6 +224,18 @@ class QmlAVPlayer : public QObject, public QQmlParserStatus int audioTrack() const; void setAudioTrack(int value); QVariantList internalAudioTracks() const; + /*! + /*! + * \brief videoTrack + * The video stream number in current media. + * Value can be: 0, 1, 2.... 0 means the 1st video stream in current media + */ + int videoTrack() const; + void setVideoTrack(int value); + QVariantList internalVideoTracks() const; + + int bufferSize() const; + void setBufferSize(int value); /*! * \brief externalAudio * If externalAudio url is valid, player will use audioTrack of external audio as audio source. @@ -285,10 +300,13 @@ public Q_SLOTS: void abortOnTimeoutChanged(); void audioTrackChanged(); void internalAudioTracksChanged(); + void videoTrackChanged(); + void internalVideoTracksChanged(); void externalAudioChanged(); void externalAudioTracksChanged(); void internalSubtitleTrackChanged(); void internalSubtitleTracksChanged(); + void bufferSizeChanged(); void errorChanged(); void error(Error error, const QString &errorString); @@ -341,6 +359,7 @@ private Q_SLOTS: int m_timeout; bool m_abort_timeout; int m_audio_track; + int m_video_track; QUrl m_audio; int m_sub_track; diff --git a/qml/QmlAVPlayer.cpp b/qml/QmlAVPlayer.cpp index 2e8af732d..cb01ee0fe 100644 --- a/qml/QmlAVPlayer.cpp +++ b/qml/QmlAVPlayer.cpp @@ -1,6 +1,6 @@ /****************************************************************************** QtAV: Multimedia framework based on Qt and FFmpeg - Copyright (C) 2012-2016 Wang Bin + Copyright (C) 2012-2017 Wang Bin * This file is part of QtAV (from 2013) @@ -63,6 +63,7 @@ QmlAVPlayer::QmlAVPlayer(QObject *parent) : , m_timeout(30000) , m_abort_timeout(true) , m_audio_track(0) + , m_video_track(0) , m_sub_track(0) , m_ao(AudioOutput::backendsAvailable()) { @@ -76,6 +77,7 @@ void QmlAVPlayer::classBegin() mpPlayer = new AVPlayer(this); connect(mpPlayer, SIGNAL(internalSubtitleTracksChanged(QVariantList)), SIGNAL(internalSubtitleTracksChanged())); connect(mpPlayer, SIGNAL(internalAudioTracksChanged(QVariantList)), SIGNAL(internalAudioTracksChanged())); + connect(mpPlayer, SIGNAL(internalVideoTracksChanged(QVariantList)), SIGNAL(internalVideoTracksChanged())); connect(mpPlayer, SIGNAL(externalAudioTracksChanged(QVariantList)), SIGNAL(externalAudioTracksChanged())); connect(mpPlayer, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged())); connect(mpPlayer, SIGNAL(mediaStatusChanged(QtAV::MediaStatus)), SLOT(_q_statusChanged())); @@ -393,6 +395,36 @@ void QmlAVPlayer::setAudioTrack(int value) mpPlayer->setAudioStream(value); } +int QmlAVPlayer::videoTrack() const +{ + return m_video_track; +} + +void QmlAVPlayer::setVideoTrack(int value) +{ + if (m_video_track == value) + return; + m_video_track = value; + Q_EMIT videoTrackChanged(); + if (mpPlayer) + mpPlayer->setVideoStream(value); +} + +int QmlAVPlayer::bufferSize() const +{ + return mpPlayer->bufferValue(); +} + +void QmlAVPlayer::setBufferSize(int value) +{ + if (mpPlayer->bufferValue() == value) + return; + if (mpPlayer) { + mpPlayer->setBufferValue(value); + Q_EMIT bufferSizeChanged(); + } +} + QUrl QmlAVPlayer::externalAudio() const { return m_audio; @@ -417,6 +449,11 @@ QVariantList QmlAVPlayer::internalAudioTracks() const return mpPlayer ? mpPlayer->internalAudioTracks() : QVariantList(); } +QVariantList QmlAVPlayer::internalVideoTracks() const +{ + return mpPlayer ? mpPlayer->internalVideoTracks() : QVariantList(); +} + int QmlAVPlayer::internalSubtitleTrack() const { return m_sub_track; @@ -686,6 +723,7 @@ void QmlAVPlayer::setPlaybackState(PlaybackState playbackState) mpPlayer->setInterruptOnTimeout(m_abort_timeout); mpPlayer->setRepeat(mLoopCount - 1); mpPlayer->setAudioStream(m_audio_track); + mpPlayer->setVideoStream(m_video_track); // will check in case of error mpPlayer->setSubtitleStream(m_sub_track); if (!vcodec_opt.isEmpty()) { QVariantHash vcopt; diff --git a/qml/Video.qml b/qml/Video.qml index cb1e85494..495be85f4 100644 --- a/qml/Video.qml +++ b/qml/Video.qml @@ -84,9 +84,11 @@ Item { property alias subtitleText: text_sub // not for ass. property alias videoCapture: player.videoCapture property alias audioTrack: player.audioTrack + property alias videoTrack: player.videoTrack property alias externalAudio: player.externalAudio property alias internalAudioTracks: player.internalAudioTracks property alias externalAudioTracks: player.externalAudioTracks + property alias internalVideoTracks: player.internalVideoTracks /*** Properties of VideoOutput ***/ /*! \qmlproperty enumeration Video::fillMode @@ -162,6 +164,13 @@ Item { */ property alias bufferProgress: player.bufferProgress + /*! + \qmlproperty int Video::bufferSize + + This property holds the buffer value. + */ + property alias bufferSize: player.bufferSize + /*! \qmlproperty int Video::duration @@ -344,6 +353,7 @@ Item { anchors.fill: video source: player } + SubtitleItem { id: ass_sub rotation: -videoOut.orientation diff --git a/qml/plugins.qmltypes b/qml/plugins.qmltypes index a850e4cf0..3db30cb1a 100644 --- a/qml/plugins.qmltypes +++ b/qml/plugins.qmltypes @@ -229,6 +229,7 @@ Module { Property { name: "useWallclockAsTimestamps"; type: "bool" } Property { name: "videoCapture"; type: "QtAV::VideoCapture"; isReadonly: true; isPointer: true } Property { name: "audioTrack"; type: "int" } + Property { name: "bufferSize"; type: "int" } Property { name: "externalAudio"; type: "QUrl" } Property { name: "internalAudioTracks"; type: "QVariantList"; isReadonly: true } Property { name: "externalAudioTracks"; type: "QVariantList"; isReadonly: true }