GstEnginePipeline: Add separate set state async function
This commit is contained in:
@@ -349,7 +349,7 @@ void GstEngine::Pause() {
|
|||||||
StartFadeoutPause();
|
StartFadeoutPause();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
current_pipeline_->SetStateAsync(GST_STATE_PAUSED);
|
current_pipeline_->SetState(GST_STATE_PAUSED);
|
||||||
Q_EMIT StateChanged(State::Paused);
|
Q_EMIT StateChanged(State::Paused);
|
||||||
StopTimers();
|
StopTimers();
|
||||||
}
|
}
|
||||||
@@ -371,7 +371,7 @@ void GstEngine::Unpause() {
|
|||||||
has_faded_out_to_pause_ = false;
|
has_faded_out_to_pause_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_pipeline_->SetStateAsync(GST_STATE_PLAYING);
|
current_pipeline_->SetState(GST_STATE_PLAYING);
|
||||||
|
|
||||||
Q_EMIT StateChanged(State::Playing);
|
Q_EMIT StateChanged(State::Playing);
|
||||||
|
|
||||||
@@ -688,7 +688,7 @@ void GstEngine::FadeoutPauseFinished() {
|
|||||||
|
|
||||||
if (!fadeout_pause_pipeline_) return;
|
if (!fadeout_pause_pipeline_) return;
|
||||||
|
|
||||||
fadeout_pause_pipeline_->SetStateAsync(GST_STATE_PAUSED);
|
fadeout_pause_pipeline_->SetState(GST_STATE_PAUSED);
|
||||||
Q_EMIT StateChanged(State::Paused);
|
Q_EMIT StateChanged(State::Paused);
|
||||||
StopTimers();
|
StopTimers();
|
||||||
has_faded_out_to_pause_ = true;
|
has_faded_out_to_pause_ = true;
|
||||||
|
|||||||
@@ -408,7 +408,7 @@ bool GstEnginePipeline::Finish() {
|
|||||||
finished_ = true;
|
finished_ = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SetStateAsync(GST_STATE_NULL);
|
SetState(GST_STATE_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return finished_.value();
|
return finished_.value();
|
||||||
@@ -1793,7 +1793,13 @@ bool GstEnginePipeline::IsStateNull() const {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<GstStateChangeReturn> GstEnginePipeline::SetStateAsync(const GstState state) {
|
void GstEnginePipeline::SetStateAsync(const GstState state) {
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(this, "SetState", Qt::QueuedConnection, Q_ARG(GstState, state));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QFuture<GstStateChangeReturn> GstEnginePipeline::SetState(const GstState state) {
|
||||||
|
|
||||||
qLog(Debug) << "Setting pipeline" << id() << "state to" << GstStateText(state);
|
qLog(Debug) << "Setting pipeline" << id() << "state to" << GstStateText(state);
|
||||||
|
|
||||||
@@ -1801,7 +1807,7 @@ QFuture<GstStateChangeReturn> GstEnginePipeline::SetStateAsync(const GstState st
|
|||||||
QObject::connect(watcher, &QFutureWatcher<GstStateChangeReturn>::finished, this, [this, watcher, state]() {
|
QObject::connect(watcher, &QFutureWatcher<GstStateChangeReturn>::finished, this, [this, watcher, state]() {
|
||||||
const GstStateChangeReturn state_change_return = watcher->result();
|
const GstStateChangeReturn state_change_return = watcher->result();
|
||||||
watcher->deleteLater();
|
watcher->deleteLater();
|
||||||
SetStateAsyncFinished(state, state_change_return);
|
SetStateFinishedSlot(state, state_change_return);
|
||||||
});
|
});
|
||||||
QFuture<GstStateChangeReturn> future = QtConcurrent::run(&set_state_threadpool_, &gst_element_set_state, pipeline_, state);
|
QFuture<GstStateChangeReturn> future = QtConcurrent::run(&set_state_threadpool_, &gst_element_set_state, pipeline_, state);
|
||||||
watcher->setFuture(future);
|
watcher->setFuture(future);
|
||||||
@@ -1810,7 +1816,7 @@ QFuture<GstStateChangeReturn> GstEnginePipeline::SetStateAsync(const GstState st
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GstEnginePipeline::SetStateAsyncFinished(const GstState state, const GstStateChangeReturn state_change_return) {
|
void GstEnginePipeline::SetStateFinishedSlot(const GstState state, const GstStateChangeReturn state_change_return) {
|
||||||
|
|
||||||
switch (state_change_return) {
|
switch (state_change_return) {
|
||||||
case GST_STATE_CHANGE_SUCCESS:
|
case GST_STATE_CHANGE_SUCCESS:
|
||||||
@@ -1840,7 +1846,7 @@ QFuture<GstStateChangeReturn> GstEnginePipeline::Play(const bool pause, const qu
|
|||||||
pending_state_ = GST_STATE_PLAYING;
|
pending_state_ = GST_STATE_PLAYING;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SetStateAsync(GST_STATE_PAUSED);
|
return SetState(GST_STATE_PAUSED);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1858,7 +1864,7 @@ bool GstEnginePipeline::Seek(const qint64 nanosec) {
|
|||||||
|
|
||||||
if (next_uri_set_.value()) {
|
if (next_uri_set_.value()) {
|
||||||
pending_seek_nanosec_ = nanosec;
|
pending_seek_nanosec_ = nanosec;
|
||||||
SetStateAsync(GST_STATE_READY);
|
SetState(GST_STATE_READY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1873,7 +1879,7 @@ bool GstEnginePipeline::Seek(const qint64 nanosec) {
|
|||||||
qLog(Debug) << "Seek succeeded";
|
qLog(Debug) << "Seek succeeded";
|
||||||
if (pending_state_.value() != GST_STATE_NULL) {
|
if (pending_state_.value() != GST_STATE_NULL) {
|
||||||
qLog(Debug) << "Setting state from pending state" << GstStateText(pending_state_.value());
|
qLog(Debug) << "Setting state from pending state" << GstStateText(pending_state_.value());
|
||||||
SetStateAsync(pending_state_.value());
|
SetState(pending_state_.value());
|
||||||
pending_state_ = GST_STATE_NULL;
|
pending_state_ = GST_STATE_NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class GstEnginePipeline : public QObject {
|
|||||||
void RemoveAllBufferConsumers();
|
void RemoveAllBufferConsumers();
|
||||||
|
|
||||||
// Control the music playback
|
// Control the music playback
|
||||||
Q_INVOKABLE QFuture<GstStateChangeReturn> SetStateAsync(const GstState state);
|
Q_INVOKABLE QFuture<GstStateChangeReturn> SetState(const GstState state);
|
||||||
Q_INVOKABLE QFuture<GstStateChangeReturn> Play(const bool pause, const quint64 offset_nanosec);
|
Q_INVOKABLE QFuture<GstStateChangeReturn> Play(const bool pause, const quint64 offset_nanosec);
|
||||||
Q_INVOKABLE bool Seek(const qint64 nanosec);
|
Q_INVOKABLE bool Seek(const qint64 nanosec);
|
||||||
void SeekAsync(const qint64 nanosec);
|
void SeekAsync(const qint64 nanosec);
|
||||||
@@ -165,6 +165,7 @@ class GstEnginePipeline : public QObject {
|
|||||||
bool IsStateNull() const;
|
bool IsStateNull() const;
|
||||||
bool InitAudioBin(QString &error);
|
bool InitAudioBin(QString &error);
|
||||||
void SetupVolume(GstElement *element);
|
void SetupVolume(GstElement *element);
|
||||||
|
void SetStateAsync(const GstState state);
|
||||||
|
|
||||||
// Static callbacks. The GstEnginePipeline instance is passed in the last argument.
|
// Static callbacks. The GstEnginePipeline instance is passed in the last argument.
|
||||||
static GstPadProbeReturn UpstreamEventsProbeCallback(GstPad *pad, GstPadProbeInfo *info, gpointer self);
|
static GstPadProbeReturn UpstreamEventsProbeCallback(GstPad *pad, GstPadProbeInfo *info, gpointer self);
|
||||||
@@ -199,7 +200,7 @@ class GstEnginePipeline : public QObject {
|
|||||||
void ResumeFaderAsync();
|
void ResumeFaderAsync();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void SetStateAsyncFinished(const GstState state, const GstStateChangeReturn state_change_return);
|
void SetStateFinishedSlot(const GstState state, const GstStateChangeReturn state_change_return);
|
||||||
void SetFaderVolume(const qreal volume);
|
void SetFaderVolume(const qreal volume);
|
||||||
void FaderTimelineStateChanged(const QTimeLine::State state);
|
void FaderTimelineStateChanged(const QTimeLine::State state);
|
||||||
void FaderTimelineFinished();
|
void FaderTimelineFinished();
|
||||||
|
|||||||
Reference in New Issue
Block a user