diff --git a/src/engines/gstengine.cpp b/src/engines/gstengine.cpp index 0c3ef8247..599dfbd54 100644 --- a/src/engines/gstengine.cpp +++ b/src/engines/gstengine.cpp @@ -827,16 +827,33 @@ int GstEngine::AddBackgroundStream(shared_ptr pipeline) { disconnect(pipeline.get(), SIGNAL(MetadataFound(Engine::SimpleMetaBundle)), this, 0); disconnect(pipeline.get(), SIGNAL(EndOfStreamReached(bool)), this, 0); connect(pipeline.get(), SIGNAL(EndOfStreamReached(bool)), SLOT(BackgroundStreamFinished())); - if (!pipeline->SetState(GST_STATE_PLAYING)) { - qWarning() << "Could not set thread to PLAYING."; - pipeline.reset(); - return -1; - } + const int stream_id = next_background_stream_id_++; background_streams_[stream_id] = pipeline; + + QFuture future = pipeline->SetState(GST_STATE_PLAYING); + BoundFutureWatcher* watcher = + new BoundFutureWatcher(stream_id, this); + watcher->setFuture(future); + connect(watcher, SIGNAL(finished()), SLOT(BackgroundStreamPlayDone())); + return stream_id; } +void GstEngine::BackgroundStreamPlayDone() { + BoundFutureWatcher* watcher = + static_cast*>(sender()); + watcher->deleteLater(); + + const int stream_id = watcher->data(); + GstStateChangeReturn ret = watcher->result(); + + if (ret == GST_STATE_CHANGE_FAILURE) { + qWarning() << "Could not set thread to PLAYING."; + background_streams_.remove(stream_id); + } +} + int GstEngine::AddBackgroundStream(const QUrl& url) { shared_ptr pipeline = CreatePipeline(url); if (!pipeline) { diff --git a/src/engines/gstengine.h b/src/engines/gstengine.h index 4f3e75e19..54059f53c 100644 --- a/src/engines/gstengine.h +++ b/src/engines/gstengine.h @@ -118,6 +118,7 @@ class GstEngine : public Engine::Base, public BufferConsumer { void FadeoutFinished(); void SeekNow(); void BackgroundStreamFinished(); + void BackgroundStreamPlayDone(); void PlayDone(); private: