Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Librem5
debs
callaudiod
Commits
bf77a184
Commit
bf77a184
authored
Jan 27, 2021
by
Arnaud Ferraris
Browse files
cad-pulse: select best available port for each new sink/source
parent
8244d3d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cad-pulse.c
View file @
bf77a184
...
...
@@ -61,7 +61,7 @@ static const gchar *get_available_output(const pa_sink_info *sink, const gchar *
pa_sink_port_info
*
available_port
=
NULL
;
guint
i
;
g_debug
(
"looking for available
por
t excluding '%s'"
,
exclude
);
g_debug
(
"looking for available
outpu
t excluding '%s'"
,
exclude
);
for
(
i
=
0
;
i
<
sink
->
n_ports
;
i
++
)
{
pa_sink_port_info
*
port
=
sink
->
ports
[
i
];
...
...
@@ -76,11 +76,40 @@ static const gchar *get_available_output(const pa_sink_info *sink, const gchar *
}
if
(
available_port
)
{
g_debug
(
"found available
por
t '%s'"
,
available_port
->
name
);
g_debug
(
"found available
outpu
t '%s'"
,
available_port
->
name
);
return
available_port
->
name
;
}
g_warning
(
"no available port found!"
);
g_warning
(
"no available output found!"
);
return
NULL
;
}
static
const
gchar
*
get_available_input
(
const
pa_source_info
*
source
,
const
gchar
*
exclude
)
{
pa_source_port_info
*
available_port
=
NULL
;
guint
i
;
g_debug
(
"looking for available input excluding '%s'"
,
exclude
);
for
(
i
=
0
;
i
<
source
->
n_ports
;
i
++
)
{
pa_source_port_info
*
port
=
source
->
ports
[
i
];
if
((
exclude
&&
strcmp
(
port
->
name
,
exclude
)
==
0
)
||
port
->
available
==
PA_PORT_AVAILABLE_NO
)
{
continue
;
}
if
(
!
available_port
||
port
->
priority
>
available_port
->
priority
)
available_port
=
port
;
}
if
(
available_port
)
{
g_debug
(
"found available input '%s'"
,
available_port
->
name
);
return
available_port
->
name
;
}
g_warning
(
"no available input found!"
);
return
NULL
;
}
...
...
@@ -165,6 +194,8 @@ static void process_new_sink(CadPulse *self, const pa_sink_info *info)
static
void
init_source_info
(
pa_context
*
ctx
,
const
pa_source_info
*
info
,
int
eol
,
void
*
data
)
{
CadPulse
*
self
=
data
;
const
gchar
*
target_port
;
pa_operation
*
op
;
if
(
eol
!=
0
)
return
;
...
...
@@ -175,11 +206,23 @@ static void init_source_info(pa_context *ctx, const pa_source_info *info, int eo
}
process_new_source
(
self
,
info
);
if
(
self
->
source_id
<
0
)
return
;
target_port
=
get_available_input
(
info
,
NULL
);
if
(
target_port
)
{
op
=
pa_context_set_source_port_by_index
(
ctx
,
self
->
source_id
,
target_port
,
NULL
,
NULL
);
if
(
op
)
pa_operation_unref
(
op
);
}
}
static
void
init_sink_info
(
pa_context
*
ctx
,
const
pa_sink_info
*
info
,
int
eol
,
void
*
data
)
{
CadPulse
*
self
=
data
;
const
gchar
*
target_port
;
pa_operation
*
op
;
if
(
eol
!=
0
)
return
;
...
...
@@ -190,6 +233,17 @@ static void init_sink_info(pa_context *ctx, const pa_sink_info *info, int eol, v
}
process_new_sink
(
self
,
info
);
if
(
self
->
sink_id
<
0
)
return
;
target_port
=
get_available_output
(
info
,
NULL
);
if
(
target_port
)
{
g_debug
(
" Using sink port '%s'"
,
target_port
);
op
=
pa_context_set_sink_port_by_index
(
ctx
,
self
->
sink_id
,
target_port
,
NULL
,
NULL
);
if
(
op
)
pa_operation_unref
(
op
);
}
}
static
void
init_card_info
(
pa_context
*
ctx
,
const
pa_card_info
*
info
,
int
eol
,
void
*
data
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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