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
f3a16003
Commit
f3a16003
authored
Jan 04, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/pulse: move more code into the struct
parent
f016eef4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
148 additions
and
75 deletions
+148
-75
PulseOutputPlugin.cxx
src/output/plugins/PulseOutputPlugin.cxx
+148
-75
No files found.
src/output/plugins/PulseOutputPlugin.cxx
View file @
f3a16003
...
@@ -62,6 +62,37 @@ struct PulseOutput {
...
@@ -62,6 +62,37 @@ struct PulseOutput {
mixer
(
nullptr
),
mixer
(
nullptr
),
mainloop
(
nullptr
),
stream
(
nullptr
)
{}
mainloop
(
nullptr
),
stream
(
nullptr
)
{}
public
:
void
SetMixer
(
PulseMixer
&
_mixer
);
void
ClearMixer
(
gcc_unused
PulseMixer
&
old_mixer
)
{
assert
(
mixer
==
&
old_mixer
);
mixer
=
nullptr
;
}
bool
SetVolume
(
const
pa_cvolume
&
volume
,
Error
&
error
);
void
Lock
()
{
pa_threaded_mainloop_lock
(
mainloop
);
}
void
Unlock
()
{
pa_threaded_mainloop_unlock
(
mainloop
);
}
void
OnContextStateChanged
(
pa_context_state_t
new_state
);
void
OnServerLayoutChanged
(
pa_subscription_event_type_t
t
,
uint32_t
idx
);
void
OnStreamSuspended
(
pa_stream
*
_stream
);
void
OnStreamStateChanged
(
pa_stream
*
_stream
,
pa_stream_state_t
new_state
);
void
OnStreamWrite
(
size_t
nbytes
);
void
OnStreamSuccess
()
{
pa_threaded_mainloop_signal
(
mainloop
,
0
);
}
gcc_const
gcc_const
static
bool
TestDefaultDevice
();
static
bool
TestDefaultDevice
();
...
@@ -146,64 +177,66 @@ private:
...
@@ -146,64 +177,66 @@ private:
void
void
pulse_output_lock
(
PulseOutput
&
po
)
pulse_output_lock
(
PulseOutput
&
po
)
{
{
p
a_threaded_mainloop_lock
(
po
.
mainloop
);
p
o
.
Lock
(
);
}
}
void
void
pulse_output_unlock
(
PulseOutput
&
po
)
pulse_output_unlock
(
PulseOutput
&
po
)
{
{
p
a_threaded_mainloop_unlock
(
po
.
mainloop
);
p
o
.
Unlock
(
);
}
}
void
inline
void
pulse_output_set_mixer
(
PulseOutput
&
po
,
PulseMixer
&
pm
)
PulseOutput
::
SetMixer
(
PulseMixer
&
_mixer
)
{
{
assert
(
po
.
mixer
==
nullptr
);
assert
(
mixer
==
nullptr
);
po
.
mixer
=
&
pm
;
mixer
=
&
_mixer
;
if
(
po
.
mainloop
==
nullptr
)
if
(
mainloop
==
nullptr
)
return
;
return
;
pa_threaded_mainloop_lock
(
po
.
mainloop
);
pa_threaded_mainloop_lock
(
mainloop
);
if
(
po
.
context
!=
nullptr
&&
if
(
context
!=
nullptr
&&
pa_context_get_state
(
po
.
context
)
==
PA_CONTEXT_READY
)
{
pa_context_get_state
(
context
)
==
PA_CONTEXT_READY
)
{
pulse_mixer_on_connect
(
pm
,
po
.
context
);
pulse_mixer_on_connect
(
_mixer
,
context
);
if
(
po
.
stream
!=
nullptr
&&
if
(
stream
!=
nullptr
&&
pa_stream_get_state
(
po
.
stream
)
==
PA_STREAM_READY
)
pa_stream_get_state
(
stream
)
==
PA_STREAM_READY
)
pulse_mixer_on_change
(
pm
,
po
.
context
,
po
.
stream
);
pulse_mixer_on_change
(
_mixer
,
context
,
stream
);
}
}
pa_threaded_mainloop_unlock
(
po
.
mainloop
);
pa_threaded_mainloop_unlock
(
mainloop
);
}
}
void
void
pulse_output_
clear_mixer
(
PulseOutput
&
po
,
gcc_unused
PulseMixer
&
pm
)
pulse_output_
set_mixer
(
PulseOutput
&
po
,
PulseMixer
&
pm
)
{
{
assert
(
po
.
mixer
==
&
pm
);
po
.
SetMixer
(
pm
);
po
.
mixer
=
nullptr
;
}
}
bool
void
pulse_output_set_volume
(
PulseOutput
&
po
,
const
pa_cvolume
*
volume
,
pulse_output_clear_mixer
(
PulseOutput
&
po
,
PulseMixer
&
pm
)
Error
&
error
)
{
{
pa_operation
*
o
;
po
.
ClearMixer
(
pm
);
}
if
(
po
.
context
==
nullptr
||
po
.
stream
==
nullptr
||
inline
bool
pa_stream_get_state
(
po
.
stream
)
!=
PA_STREAM_READY
)
{
PulseOutput
::
SetVolume
(
const
pa_cvolume
&
volume
,
Error
&
error
)
{
if
(
context
==
nullptr
||
stream
==
nullptr
||
pa_stream_get_state
(
stream
)
!=
PA_STREAM_READY
)
{
error
.
Set
(
pulse_domain
,
"disconnected"
);
error
.
Set
(
pulse_domain
,
"disconnected"
);
return
false
;
return
false
;
}
}
o
=
pa_context_set_sink_input_volume
(
po
.
context
,
pa_operation
*
o
=
pa_stream_get_index
(
po
.
stream
),
pa_context_set_sink_input_volume
(
context
,
volume
,
nullptr
,
nullptr
);
pa_stream_get_index
(
stream
),
&
volume
,
nullptr
,
nullptr
);
if
(
o
==
nullptr
)
{
if
(
o
==
nullptr
)
{
SetPulseError
(
error
,
po
.
context
,
SetPulseError
(
error
,
context
,
"failed to set PulseAudio volume"
);
"failed to set PulseAudio volume"
);
return
false
;
return
false
;
}
}
...
@@ -212,6 +245,13 @@ pulse_output_set_volume(PulseOutput &po, const pa_cvolume *volume,
...
@@ -212,6 +245,13 @@ pulse_output_set_volume(PulseOutput &po, const pa_cvolume *volume,
return
true
;
return
true
;
}
}
bool
pulse_output_set_volume
(
PulseOutput
&
po
,
const
pa_cvolume
*
volume
,
Error
&
error
)
{
return
po
.
SetVolume
(
*
volume
,
error
);
}
/**
/**
* \brief waits for a pulseaudio operation to finish, frees it and
* \brief waits for a pulseaudio operation to finish, frees it and
* unlocks the mainloop
* unlocks the mainloop
...
@@ -244,32 +284,30 @@ static void
...
@@ -244,32 +284,30 @@ static void
pulse_output_stream_success_cb
(
gcc_unused
pa_stream
*
s
,
pulse_output_stream_success_cb
(
gcc_unused
pa_stream
*
s
,
gcc_unused
int
success
,
void
*
userdata
)
gcc_unused
int
success
,
void
*
userdata
)
{
{
PulseOutput
*
po
=
(
PulseOutput
*
)
userdata
;
PulseOutput
&
po
=
*
(
PulseOutput
*
)
userdata
;
p
a_threaded_mainloop_signal
(
po
->
mainloop
,
0
);
p
o
.
OnStreamSuccess
(
);
}
}
static
void
inline
void
pulse_output_context_state_cb
(
struct
pa_context
*
context
,
void
*
userdata
)
PulseOutput
::
OnContextStateChanged
(
pa_context_state_t
new_state
)
{
{
PulseOutput
*
po
=
(
PulseOutput
*
)
userdata
;
switch
(
new_state
)
{
switch
(
pa_context_get_state
(
context
))
{
case
PA_CONTEXT_READY
:
case
PA_CONTEXT_READY
:
if
(
po
->
mixer
!=
nullptr
)
if
(
mixer
!=
nullptr
)
pulse_mixer_on_connect
(
*
po
->
mixer
,
context
);
pulse_mixer_on_connect
(
*
mixer
,
context
);
pa_threaded_mainloop_signal
(
po
->
mainloop
,
0
);
pa_threaded_mainloop_signal
(
mainloop
,
0
);
break
;
break
;
case
PA_CONTEXT_TERMINATED
:
case
PA_CONTEXT_TERMINATED
:
case
PA_CONTEXT_FAILED
:
case
PA_CONTEXT_FAILED
:
if
(
po
->
mixer
!=
nullptr
)
if
(
mixer
!=
nullptr
)
pulse_mixer_on_disconnect
(
*
po
->
mixer
);
pulse_mixer_on_disconnect
(
*
mixer
);
/* the caller thread might be waiting for these
/* the caller thread might be waiting for these
states */
states */
pa_threaded_mainloop_signal
(
po
->
mainloop
,
0
);
pa_threaded_mainloop_signal
(
mainloop
,
0
);
break
;
break
;
case
PA_CONTEXT_UNCONNECTED
:
case
PA_CONTEXT_UNCONNECTED
:
...
@@ -281,24 +319,40 @@ pulse_output_context_state_cb(struct pa_context *context, void *userdata)
...
@@ -281,24 +319,40 @@ pulse_output_context_state_cb(struct pa_context *context, void *userdata)
}
}
static
void
static
void
pulse_output_subscribe_cb
(
pa_context
*
context
,
pulse_output_context_state_cb
(
struct
pa_context
*
context
,
void
*
userdata
)
pa_subscription_event_type_t
t
,
{
uint32_t
idx
,
void
*
userdata
)
PulseOutput
&
po
=
*
(
PulseOutput
*
)
userdata
;
po
.
OnContextStateChanged
(
pa_context_get_state
(
context
));
}
inline
void
PulseOutput
::
OnServerLayoutChanged
(
pa_subscription_event_type_t
t
,
uint32_t
idx
)
{
{
PulseOutput
*
po
=
(
PulseOutput
*
)
userdata
;
pa_subscription_event_type_t
facility
=
pa_subscription_event_type_t
facility
=
pa_subscription_event_type_t
(
t
&
PA_SUBSCRIPTION_EVENT_FACILITY_MASK
);
pa_subscription_event_type_t
(
t
&
PA_SUBSCRIPTION_EVENT_FACILITY_MASK
);
pa_subscription_event_type_t
type
=
pa_subscription_event_type_t
type
=
pa_subscription_event_type_t
(
t
&
PA_SUBSCRIPTION_EVENT_TYPE_MASK
);
pa_subscription_event_type_t
(
t
&
PA_SUBSCRIPTION_EVENT_TYPE_MASK
);
if
(
po
->
mixer
!=
nullptr
&&
if
(
mixer
!=
nullptr
&&
facility
==
PA_SUBSCRIPTION_EVENT_SINK_INPUT
&&
facility
==
PA_SUBSCRIPTION_EVENT_SINK_INPUT
&&
po
->
stream
!=
nullptr
&&
stream
!=
nullptr
&&
pa_stream_get_state
(
po
->
stream
)
==
PA_STREAM_READY
&&
pa_stream_get_state
(
stream
)
==
PA_STREAM_READY
&&
idx
==
pa_stream_get_index
(
po
->
stream
)
&&
idx
==
pa_stream_get_index
(
stream
)
&&
(
type
==
PA_SUBSCRIPTION_EVENT_NEW
||
(
type
==
PA_SUBSCRIPTION_EVENT_NEW
||
type
==
PA_SUBSCRIPTION_EVENT_CHANGE
))
type
==
PA_SUBSCRIPTION_EVENT_CHANGE
))
pulse_mixer_on_change
(
*
po
->
mixer
,
context
,
po
->
stream
);
pulse_mixer_on_change
(
*
mixer
,
context
,
stream
);
}
static
void
pulse_output_subscribe_cb
(
gcc_unused
pa_context
*
context
,
pa_subscription_event_type_t
t
,
uint32_t
idx
,
void
*
userdata
)
{
PulseOutput
&
po
=
*
(
PulseOutput
*
)
userdata
;
po
.
OnServerLayoutChanged
(
t
,
idx
);
}
}
inline
bool
inline
bool
...
@@ -485,42 +539,47 @@ PulseOutput::WaitConnection(Error &error)
...
@@ -485,42 +539,47 @@ PulseOutput::WaitConnection(Error &error)
}
}
}
}
static
void
inline
void
pulse_output_stream_suspended_cb
(
gcc_unused
pa_stream
*
stream
,
void
*
userdata
)
PulseOutput
::
OnStreamSuspended
(
gcc_unused
pa_stream
*
_stream
)
{
{
PulseOutput
*
po
=
(
PulseOutput
*
)
userdata
;
assert
(
_stream
==
stream
||
stream
==
nullptr
);
assert
(
mainloop
!=
nullptr
);
assert
(
stream
==
po
->
stream
||
po
->
stream
==
nullptr
);
assert
(
po
->
mainloop
!=
nullptr
);
/* wake up the main loop to break out of the loop in
/* wake up the main loop to break out of the loop in
pulse_output_play() */
pulse_output_play() */
pa_threaded_mainloop_signal
(
po
->
mainloop
,
0
);
pa_threaded_mainloop_signal
(
mainloop
,
0
);
}
}
static
void
static
void
pulse_output_stream_s
tate
_cb
(
pa_stream
*
stream
,
void
*
userdata
)
pulse_output_stream_s
uspended
_cb
(
pa_stream
*
stream
,
void
*
userdata
)
{
{
PulseOutput
*
po
=
(
PulseOutput
*
)
userdata
;
PulseOutput
&
po
=
*
(
PulseOutput
*
)
userdata
;
assert
(
stream
==
po
->
stream
||
po
->
stream
==
nullptr
);
po
.
OnStreamSuspended
(
stream
);
assert
(
po
->
mainloop
!=
nullptr
);
}
assert
(
po
->
context
!=
nullptr
);
inline
void
PulseOutput
::
OnStreamStateChanged
(
pa_stream
*
_stream
,
pa_stream_state_t
new_state
)
{
assert
(
_stream
==
stream
||
stream
==
nullptr
);
assert
(
mainloop
!=
nullptr
);
assert
(
context
!=
nullptr
);
switch
(
pa_stream_get_state
(
stream
)
)
{
switch
(
new_state
)
{
case
PA_STREAM_READY
:
case
PA_STREAM_READY
:
if
(
po
->
mixer
!=
nullptr
)
if
(
mixer
!=
nullptr
)
pulse_mixer_on_change
(
*
po
->
mixer
,
po
->
context
,
stream
);
pulse_mixer_on_change
(
*
mixer
,
context
,
_
stream
);
pa_threaded_mainloop_signal
(
po
->
mainloop
,
0
);
pa_threaded_mainloop_signal
(
mainloop
,
0
);
break
;
break
;
case
PA_STREAM_FAILED
:
case
PA_STREAM_FAILED
:
case
PA_STREAM_TERMINATED
:
case
PA_STREAM_TERMINATED
:
if
(
po
->
mixer
!=
nullptr
)
if
(
mixer
!=
nullptr
)
pulse_mixer_on_disconnect
(
*
po
->
mixer
);
pulse_mixer_on_disconnect
(
*
mixer
);
pa_threaded_mainloop_signal
(
po
->
mainloop
,
0
);
pa_threaded_mainloop_signal
(
mainloop
,
0
);
break
;
break
;
case
PA_STREAM_UNCONNECTED
:
case
PA_STREAM_UNCONNECTED
:
...
@@ -530,15 +589,29 @@ pulse_output_stream_state_cb(pa_stream *stream, void *userdata)
...
@@ -530,15 +589,29 @@ pulse_output_stream_state_cb(pa_stream *stream, void *userdata)
}
}
static
void
static
void
pulse_output_stream_state_cb
(
pa_stream
*
stream
,
void
*
userdata
)
{
PulseOutput
&
po
=
*
(
PulseOutput
*
)
userdata
;
return
po
.
OnStreamStateChanged
(
stream
,
pa_stream_get_state
(
stream
));
}
inline
void
PulseOutput
::
OnStreamWrite
(
size_t
nbytes
)
{
assert
(
mainloop
!=
nullptr
);
writable
=
nbytes
;
pa_threaded_mainloop_signal
(
mainloop
,
0
);
}
static
void
pulse_output_stream_write_cb
(
gcc_unused
pa_stream
*
stream
,
size_t
nbytes
,
pulse_output_stream_write_cb
(
gcc_unused
pa_stream
*
stream
,
size_t
nbytes
,
void
*
userdata
)
void
*
userdata
)
{
{
PulseOutput
*
po
=
(
PulseOutput
*
)
userdata
;
PulseOutput
&
po
=
*
(
PulseOutput
*
)
userdata
;
assert
(
po
->
mainloop
!=
nullptr
);
po
->
writable
=
nbytes
;
return
po
.
OnStreamWrite
(
nbytes
);
pa_threaded_mainloop_signal
(
po
->
mainloop
,
0
);
}
}
inline
bool
inline
bool
...
...
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