diff options
author | Jonas Dreßler <verdre@v0yd.nl> | 2022-02-03 11:26:59 +0100 |
---|---|---|
committer | Jonas Dreßler <verdre@v0yd.nl> | 2023-04-25 18:57:51 +0200 |
commit | cad01d154c3da966d9679bd1dbf7f030416c2911 (patch) | |
tree | f24152dc718e84e34aeb86710c27d90986230b29 /js/dbusServices/screencast | |
parent | 42af7e53a2aaa995840bb8cd9baf233feaac7c1f (diff) | |
download | gnome-shell-cad01d154c3da966d9679bd1dbf7f030416c2911.tar.gz |
screencastService: Set PipelineState to PLAYING on actual state-change
Right now when we tell gstreamer to move the pipeline to the state
PLAYING, we pretend that happens immediately and set our PipelineState
to PLAYING right afterwards.
In reality though it's more complicated than that: Gstreamer changes
states asynchronously and set_state() returns a Gst.StateChangeReturn.ASYNC.
In that case we should wait until the according STATE_CHANGED event happens
on the bus, and only then set our PipelineState to PLAYING.
Since the STATE_CHANGED event will also happen when set_state() returns
SUCCESS, we can use the same async logic for that.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2197>
Diffstat (limited to 'js/dbusServices/screencast')
-rw-r--r-- | js/dbusServices/screencast/screencastService.js | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/js/dbusServices/screencast/screencastService.js b/js/dbusServices/screencast/screencastService.js index 497b7d206..32af1e320 100644 --- a/js/dbusServices/screencast/screencastService.js +++ b/js/dbusServices/screencast/screencastService.js @@ -183,11 +183,14 @@ var Recorder = class { const bus = this._pipeline.get_bus(); bus.add_watch(bus, this._onBusMessage.bind(this)); - this._pipeline.set_state(Gst.State.PLAYING); - this._pipelineState = PipelineState.PLAYING; + const retval = this._pipeline.set_state(Gst.State.PLAYING); - this._startRequest.resolve(); - delete this._startRequest; + if (retval === Gst.StateChangeReturn.SUCCESS || + retval === Gst.StateChangeReturn.ASYNC) { + // We'll wait for the state change message to PLAYING on the bus + } else { + this._handleFatalPipelineError('Failed to start pipeline'); + } } startRecording() { @@ -230,6 +233,21 @@ var Recorder = class { _onBusMessage(bus, message, _) { switch (message.type) { + case Gst.MessageType.STATE_CHANGED: { + const [, newState] = message.parse_state_changed(); + + if (this._pipelineState === PipelineState.INIT && + message.src === this._pipeline && + newState === Gst.State.PLAYING) { + this._pipelineState = PipelineState.PLAYING; + + this._startRequest.resolve(); + delete this._startRequest; + } + + break; + } + case Gst.MessageType.EOS: switch (this._pipelineState) { case PipelineState.STOPPED: |