Skip to content

Commit

Permalink
qml: add bufferSize & internalVideoTracks property
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed May 18, 2017
1 parent 2277a4e commit 6faf867
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
21 changes: 20 additions & 1 deletion qml/QmlAV/QmlAVPlayer.h
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2017 Wang Bin <[email protected]>
* This file is part of QtAV (from 2013)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
40 changes: 39 additions & 1 deletion qml/QmlAVPlayer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2017 Wang Bin <[email protected]>
* This file is part of QtAV (from 2013)
Expand Down Expand Up @@ -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())
{
Expand All @@ -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()));
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions qml/Video.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -344,6 353,7 @@ Item {
anchors.fill: video
source: player
}

SubtitleItem {
id: ass_sub
rotation: -videoOut.orientation
Expand Down
1 change: 1 addition & 0 deletions qml/plugins.qmltypes
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 6faf867

Please sign in to comment.