Merge remote-tracking branch 'origin/5.5' into 5.6

Change-Id: I6d88b17f44479a522d181374023648dd007112bd
This commit is contained in:
Liang Qi
2016-01-21 08:00:31 +01:00
11 changed files with 51 additions and 36 deletions

View File

@@ -41,7 +41,6 @@ QGstAppSrc::QGstAppSrc(QObject *parent)
,m_appSrc(0) ,m_appSrc(0)
,m_sequential(false) ,m_sequential(false)
,m_maxBytes(0) ,m_maxBytes(0)
,m_setup(false)
,m_dataRequestSize(~0) ,m_dataRequestSize(~0)
,m_dataRequested(false) ,m_dataRequested(false)
,m_enoughData(false) ,m_enoughData(false)
@@ -60,11 +59,13 @@ QGstAppSrc::~QGstAppSrc()
bool QGstAppSrc::setup(GstElement* appsrc) bool QGstAppSrc::setup(GstElement* appsrc)
{ {
if (m_setup || m_stream == 0 || appsrc == 0) if (m_appSrc) {
return false;
if (m_appSrc)
gst_object_unref(G_OBJECT(m_appSrc)); gst_object_unref(G_OBJECT(m_appSrc));
m_appSrc = 0;
}
if (!appsrc || !m_stream)
return false;
m_appSrc = GST_APP_SRC(appsrc); m_appSrc = GST_APP_SRC(appsrc);
gst_object_ref(G_OBJECT(m_appSrc)); gst_object_ref(G_OBJECT(m_appSrc));
@@ -79,32 +80,35 @@ bool QGstAppSrc::setup(GstElement* appsrc)
gst_app_src_set_stream_type(m_appSrc, m_streamType); gst_app_src_set_stream_type(m_appSrc, m_streamType);
gst_app_src_set_size(m_appSrc, (m_sequential) ? -1 : m_stream->size()); gst_app_src_set_size(m_appSrc, (m_sequential) ? -1 : m_stream->size());
return m_setup = true; return true;
} }
void QGstAppSrc::setStream(QIODevice *stream) void QGstAppSrc::setStream(QIODevice *stream)
{ {
if (stream == 0)
return;
if (m_stream) { if (m_stream) {
disconnect(m_stream, SIGNAL(readyRead()), this, SLOT(onDataReady())); disconnect(m_stream, SIGNAL(readyRead()), this, SLOT(onDataReady()));
disconnect(m_stream, SIGNAL(destroyed()), this, SLOT(streamDestroyed())); disconnect(m_stream, SIGNAL(destroyed()), this, SLOT(streamDestroyed()));
m_stream = 0;
} }
if (m_appSrc)
if (m_appSrc) {
gst_object_unref(G_OBJECT(m_appSrc)); gst_object_unref(G_OBJECT(m_appSrc));
m_appSrc = 0;
}
m_dataRequestSize = ~0; m_dataRequestSize = ~0;
m_dataRequested = false; m_dataRequested = false;
m_enoughData = false; m_enoughData = false;
m_forceData = false; m_forceData = false;
m_sequential = false;
m_maxBytes = 0; m_maxBytes = 0;
m_appSrc = 0; if (stream) {
m_stream = stream; m_stream = stream;
connect(m_stream, SIGNAL(destroyed()), SLOT(streamDestroyed())); connect(m_stream, SIGNAL(destroyed()), SLOT(streamDestroyed()));
connect(m_stream, SIGNAL(readyRead()), this, SLOT(onDataReady())); connect(m_stream, SIGNAL(readyRead()), this, SLOT(onDataReady()));
m_sequential = m_stream->isSequential(); m_sequential = m_stream->isSequential();
m_setup = false; }
} }
QIODevice *QGstAppSrc::stream() const QIODevice *QGstAppSrc::stream() const
@@ -135,7 +139,7 @@ void QGstAppSrc::streamDestroyed()
void QGstAppSrc::pushDataToAppSrc() void QGstAppSrc::pushDataToAppSrc()
{ {
if (!isStreamValid() || !m_setup) if (!isStreamValid() || !m_appSrc)
return; return;
if (m_dataRequested && !m_enoughData) { if (m_dataRequested && !m_enoughData) {
@@ -242,6 +246,9 @@ void QGstAppSrc::destroy_notify(gpointer data)
void QGstAppSrc::sendEOS() void QGstAppSrc::sendEOS()
{ {
if (!m_appSrc)
return;
gst_app_src_end_of_stream(GST_APP_SRC(m_appSrc)); gst_app_src_end_of_stream(GST_APP_SRC(m_appSrc));
if (isStreamValid() && !stream()->isSequential()) if (isStreamValid() && !stream()->isSequential())
stream()->reset(); stream()->reset();

View File

@@ -65,7 +65,6 @@ public:
~QGstAppSrc(); ~QGstAppSrc();
bool setup(GstElement *); bool setup(GstElement *);
bool isReady() const { return m_setup; }
void setStream(QIODevice *); void setStream(QIODevice *);
QIODevice *stream() const; QIODevice *stream() const;
@@ -104,7 +103,6 @@ private:
GstAppStreamType m_streamType; GstAppStreamType m_streamType;
GstAppSrcCallbacks m_callbacks; GstAppSrcCallbacks m_callbacks;
qint64 m_maxBytes; qint64 m_maxBytes;
bool m_setup;
unsigned int m_dataRequestSize; unsigned int m_dataRequestSize;
bool m_dataRequested; bool m_dataRequested;
bool m_enoughData; bool m_enoughData;

View File

@@ -651,7 +651,7 @@ void QAlsaAudioOutput::resume()
} }
resuming = true; resuming = true;
deviceState = QAudio::ActiveState; deviceState = pullMode ? QAudio::ActiveState : QAudio::IdleState;
errorState = QAudio::NoError; errorState = QAudio::NoError;
timer->start(period_time/1000); timer->start(period_time/1000);

View File

@@ -187,6 +187,7 @@ private:
QTimer *m_intervalTimer; QTimer *m_intervalTimer;
CoreAudioDeviceInfo *m_audioDeviceInfo; CoreAudioDeviceInfo *m_audioDeviceInfo;
qreal m_cachedVolume; qreal m_cachedVolume;
bool m_pullMode;
QAudio::Error m_errorCode; QAudio::Error m_errorCode;
QAudio::State m_stateCode; QAudio::State m_stateCode;

View File

@@ -222,6 +222,7 @@ CoreAudioOutput::CoreAudioOutput(const QByteArray &device)
, m_startTime(0) , m_startTime(0)
, m_audioBuffer(0) , m_audioBuffer(0)
, m_cachedVolume(1.0) , m_cachedVolume(1.0)
, m_pullMode(false)
, m_errorCode(QAudio::NoError) , m_errorCode(QAudio::NoError)
, m_stateCode(QAudio::StoppedState) , m_stateCode(QAudio::StoppedState)
{ {
@@ -271,6 +272,7 @@ void CoreAudioOutput::start(QIODevice *device)
m_stateCode = QAudio::ActiveState; m_stateCode = QAudio::ActiveState;
// Start // Start
m_pullMode = true;
m_errorCode = QAudio::NoError; m_errorCode = QAudio::NoError;
m_totalFrames = 0; m_totalFrames = 0;
m_startTime = CoreAudioUtils::currentTime(); m_startTime = CoreAudioUtils::currentTime();
@@ -296,6 +298,7 @@ QIODevice *CoreAudioOutput::start()
m_stateCode = QAudio::IdleState; m_stateCode = QAudio::IdleState;
// Start // Start
m_pullMode = false;
m_errorCode = QAudio::NoError; m_errorCode = QAudio::NoError;
m_totalFrames = 0; m_totalFrames = 0;
m_startTime = CoreAudioUtils::currentTime(); m_startTime = CoreAudioUtils::currentTime();
@@ -347,7 +350,7 @@ void CoreAudioOutput::resume()
if (m_stateCode == QAudio::SuspendedState) { if (m_stateCode == QAudio::SuspendedState) {
audioThreadStart(); audioThreadStart();
m_stateCode = QAudio::ActiveState; m_stateCode = m_pullMode ? QAudio::ActiveState : QAudio::IdleState;
m_errorCode = QAudio::NoError; m_errorCode = QAudio::NoError;
emit stateChanged(m_stateCode); emit stateChanged(m_stateCode);
} }

View File

@@ -142,9 +142,6 @@ void QGstreamerAudioDecoderSession::configureAppSrcElement(GObject* object, GObj
if (!self->appsrc()) if (!self->appsrc())
return; return;
if (self->appsrc()->isReady())
return;
GstElement *appsrc; GstElement *appsrc;
g_object_get(orig, "source", &appsrc, NULL); g_object_get(orig, "source", &appsrc, NULL);
@@ -350,9 +347,8 @@ void QGstreamerAudioDecoderSession::start()
return; return;
} }
if (m_appSrc) if (!m_appSrc)
m_appSrc->deleteLater(); m_appSrc = new QGstAppSrc(this);
m_appSrc = new QGstAppSrc(this);
m_appSrc->setStream(mDevice); m_appSrc->setStream(mDevice);
g_object_set(G_OBJECT(m_playbin), "uri", "appsrc://", NULL); g_object_set(G_OBJECT(m_playbin), "uri", "appsrc://", NULL);

View File

@@ -241,6 +241,10 @@ QGstreamerPlayerSession::QGstreamerPlayerSession(QObject *parent)
g_signal_connect(G_OBJECT(m_playbin), "video-changed", G_CALLBACK(handleStreamsChange), this); g_signal_connect(G_OBJECT(m_playbin), "video-changed", G_CALLBACK(handleStreamsChange), this);
g_signal_connect(G_OBJECT(m_playbin), "audio-changed", G_CALLBACK(handleStreamsChange), this); g_signal_connect(G_OBJECT(m_playbin), "audio-changed", G_CALLBACK(handleStreamsChange), this);
g_signal_connect(G_OBJECT(m_playbin), "text-changed", G_CALLBACK(handleStreamsChange), this); g_signal_connect(G_OBJECT(m_playbin), "text-changed", G_CALLBACK(handleStreamsChange), this);
#if defined(HAVE_GST_APPSRC)
g_signal_connect(G_OBJECT(m_playbin), "deep-notify::source", G_CALLBACK(configureAppSrcElement), this);
#endif
} }
} }
@@ -274,7 +278,7 @@ void QGstreamerPlayerSession::configureAppSrcElement(GObject* object, GObject *o
Q_UNUSED(object); Q_UNUSED(object);
Q_UNUSED(pspec); Q_UNUSED(pspec);
if (self->appsrc()->isReady()) if (!self->appsrc())
return; return;
GstElement *appsrc; GstElement *appsrc;
@@ -298,16 +302,14 @@ void QGstreamerPlayerSession::loadFromStream(const QNetworkRequest &request, QIO
m_lastPosition = 0; m_lastPosition = 0;
m_isPlaylist = false; m_isPlaylist = false;
if (m_appSrc) if (!m_appSrc)
m_appSrc->deleteLater(); m_appSrc = new QGstAppSrc(this);
m_appSrc = new QGstAppSrc(this);
m_appSrc->setStream(appSrcStream); m_appSrc->setStream(appSrcStream);
if (m_playbin) { if (m_playbin) {
m_tags.clear(); m_tags.clear();
emit tagsChanged(); emit tagsChanged();
g_signal_connect(G_OBJECT(m_playbin), "deep-notify::source", (GCallback) &QGstreamerPlayerSession::configureAppSrcElement, (gpointer)this);
g_object_set(G_OBJECT(m_playbin), "uri", "appsrc://", NULL); g_object_set(G_OBJECT(m_playbin), "uri", "appsrc://", NULL);
if (!m_streamTypes.isEmpty()) { if (!m_streamTypes.isEmpty()) {
@@ -330,6 +332,13 @@ void QGstreamerPlayerSession::loadFromUri(const QNetworkRequest &request)
m_lastPosition = 0; m_lastPosition = 0;
m_isPlaylist = false; m_isPlaylist = false;
#if defined(HAVE_GST_APPSRC)
if (m_appSrc) {
m_appSrc->deleteLater();
m_appSrc = 0;
}
#endif
if (m_playbin) { if (m_playbin) {
m_tags.clear(); m_tags.clear();
emit tagsChanged(); emit tagsChanged();

View File

@@ -248,7 +248,7 @@ void QOpenSLESAudioOutput::resume()
return; return;
} }
setState(QAudio::ActiveState); setState(m_pullMode ? QAudio::ActiveState : QAudio::IdleState);
setError(QAudio::NoError); setError(QAudio::NoError);
} }

View File

@@ -555,7 +555,7 @@ void QPulseAudioOutput::resume()
m_tickTimer->start(m_periodTime); m_tickTimer->start(m_periodTime);
setState(QAudio::ActiveState); setState(m_pullMode ? QAudio::ActiveState : QAudio::IdleState);
setError(QAudio::NoError); setError(QAudio::NoError);
} }
} }

View File

@@ -434,7 +434,7 @@ qint64 QWindowsAudioOutput::write( const char *data, qint64 len )
void QWindowsAudioOutput::resume() void QWindowsAudioOutput::resume()
{ {
if(deviceState == QAudio::SuspendedState) { if(deviceState == QAudio::SuspendedState) {
deviceState = QAudio::ActiveState; deviceState = pullMode ? QAudio::ActiveState : QAudio::IdleState;
errorState = QAudio::NoError; errorState = QAudio::NoError;
waveOutRestart(hWaveOut); waveOutRestart(hWaveOut);
QTimer::singleShot(10, this, SLOT(feedback())); QTimer::singleShot(10, this, SLOT(feedback()));

View File

@@ -825,10 +825,10 @@ void tst_QAudioOutput::pushSuspendResume()
// but not too much or the rest of the file may be processed // but not too much or the rest of the file may be processed
QTest::qWait(20); QTest::qWait(20);
// Check that QAudioOutput immediately transitions to ActiveState // Check that QAudioOutput immediately transitions to IdleState
QVERIFY2((stateSignal.count() == 1), QVERIFY2((stateSignal.count() == 1),
QString("didn't emit signal after resume(), got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData()); QString("didn't emit signal after resume(), got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
QVERIFY2((audioOutput.state() == QAudio::ActiveState), "didn't transition to ActiveState after resume()"); QVERIFY2((audioOutput.state() == QAudio::IdleState), "didn't transition to IdleState after resume()");
QVERIFY2((audioOutput.error() == QAudio::NoError), "error state is not equal to QAudio::NoError after resume()"); QVERIFY2((audioOutput.error() == QAudio::NoError), "error state is not equal to QAudio::NoError after resume()");
stateSignal.clear(); stateSignal.clear();
@@ -837,6 +837,7 @@ void tst_QAudioOutput::pushSuspendResume()
if (audioOutput.bytesFree() >= audioOutput.periodSize()) { if (audioOutput.bytesFree() >= audioOutput.periodSize()) {
qint64 len = audioFile->read(buffer.data(),audioOutput.periodSize()); qint64 len = audioFile->read(buffer.data(),audioOutput.periodSize());
written += feed->write(buffer.constData(), len); written += feed->write(buffer.constData(), len);
QVERIFY2((audioOutput.state() == QAudio::ActiveState), "didn't transition to ActiveState after writing audio data");
} else } else
QTest::qWait(20); QTest::qWait(20);
} }