Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
26328cc9
Commit
26328cc9
authored
Jul 30, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/pipewire: detect connection errors
parent
cd512f0b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
0 deletions
+24
-0
PipeWireOutputPlugin.cxx
src/output/plugins/PipeWireOutputPlugin.cxx
+24
-0
No files found.
src/output/plugins/PipeWireOutputPlugin.cxx
View file @
26328cc9
...
...
@@ -56,6 +56,7 @@ class PipeWireOutput final : AudioOutput {
const
uint32_t
target_id
;
bool
disconnected
;
bool
interrupted
;
explicit
PipeWireOutput
(
const
ConfigBlock
&
block
);
...
...
@@ -71,11 +72,29 @@ public:
static
constexpr
struct
pw_stream_events
MakeStreamEvents
()
noexcept
{
struct
pw_stream_events
events
{};
events
.
version
=
PW_VERSION_STREAM_EVENTS
;
events
.
state_changed
=
StateChanged
;
events
.
process
=
Process
;
return
events
;
}
private
:
void
StateChanged
(
enum
pw_stream_state
state
,
[[
maybe_unused
]]
const
char
*
error
)
noexcept
{
const
bool
was_disconnected
=
disconnected
;
disconnected
=
state
==
PW_STREAM_STATE_ERROR
||
state
==
PW_STREAM_STATE_UNCONNECTED
;
if
(
!
was_disconnected
&&
disconnected
)
pw_thread_loop_signal
(
thread_loop
,
false
);
}
static
void
StateChanged
(
void
*
data
,
[[
maybe_unused
]]
enum
pw_stream_state
old
,
enum
pw_stream_state
state
,
const
char
*
error
)
noexcept
{
auto
&
o
=
*
(
PipeWireOutput
*
)
data
;
o
.
StateChanged
(
state
,
error
);
}
void
Process
()
noexcept
;
static
void
Process
(
void
*
data
)
noexcept
{
...
...
@@ -186,6 +205,8 @@ ToPipeWireAudioFormat(AudioFormat &audio_format) noexcept
void
PipeWireOutput
::
Open
(
AudioFormat
&
audio_format
)
{
disconnected
=
false
;
auto
props
=
pw_properties_new
(
PW_KEY_MEDIA_TYPE
,
"Audio"
,
PW_KEY_MEDIA_CATEGORY
,
"Playback"
,
PW_KEY_MEDIA_ROLE
,
"Music"
,
...
...
@@ -277,6 +298,9 @@ PipeWireOutput::Play(const void *chunk, size_t size)
const
PipeWire
::
ThreadLoopLock
lock
(
thread_loop
);
while
(
true
)
{
if
(
disconnected
)
throw
std
::
runtime_error
(
"Disconnected from PipeWire"
);
std
::
size_t
bytes_written
=
ring_buffer
->
push
((
const
std
::
byte
*
)
chunk
,
size
);
if
(
bytes_written
>
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment