pactl: add get_default_sink command

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/430>
This commit is contained in:
Jason Nader 2020-12-07 23:28:34 +09:00 committed by PulseAudio Marge Bot
parent d9db47bdb5
commit 0e4a92ca69
2 changed files with 26 additions and 0 deletions

View file

@ -161,6 +161,11 @@ License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
<optdesc><p>Set the specified card (identified by its symbolic name or numerical index) to the specified profile (identified by its symbolic name).</p></optdesc> <optdesc><p>Set the specified card (identified by its symbolic name or numerical index) to the specified profile (identified by its symbolic name).</p></optdesc>
</option> </option>
<option>
<p><opt>get-default-sink</opt></p>
<optdesc><p>Returns the symbolic name of the default sink.</p></optdesc>
</option>
<option> <option>
<p><opt>set-default-sink</opt> <arg>SINK</arg></p> <p><opt>set-default-sink</opt> <arg>SINK</arg></p>
<optdesc><p>Make the specified sink (identified by its symbolic name or numerical index) the default sink.</p></optdesc> <optdesc><p>Make the specified sink (identified by its symbolic name or numerical index) the default sink.</p></optdesc>

View file

@ -121,6 +121,7 @@ static enum {
SUSPEND_SOURCE, SUSPEND_SOURCE,
SET_CARD_PROFILE, SET_CARD_PROFILE,
SET_SINK_PORT, SET_SINK_PORT,
GET_DEFAULT_SINK,
SET_DEFAULT_SINK, SET_DEFAULT_SINK,
SET_SOURCE_PORT, SET_SOURCE_PORT,
SET_DEFAULT_SOURCE, SET_DEFAULT_SOURCE,
@ -189,6 +190,18 @@ static void stat_callback(pa_context *c, const pa_stat_info *i, void *userdata)
complete_action(); complete_action();
} }
static void get_default_sink(pa_context *c, const pa_server_info *i, void *userdata) {
if (!i) {
pa_log(_("Failed to get server information: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
printf(_("%s\n"), i->default_sink_name);
complete_action();
}
static void get_server_info_callback(pa_context *c, const pa_server_info *i, void *useerdata) { static void get_server_info_callback(pa_context *c, const pa_server_info *i, void *useerdata) {
char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX]; char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
@ -1481,6 +1494,10 @@ static void context_state_callback(pa_context *c, void *userdata) {
o = pa_context_set_sink_port_by_name(c, sink_name, port_name, simple_callback, NULL); o = pa_context_set_sink_port_by_name(c, sink_name, port_name, simple_callback, NULL);
break; break;
case GET_DEFAULT_SINK:
o = pa_context_get_server_info(c, get_default_sink, NULL);
break;
case SET_DEFAULT_SINK: case SET_DEFAULT_SINK:
o = pa_context_set_default_sink(c, sink_name, simple_callback, NULL); o = pa_context_set_default_sink(c, sink_name, simple_callback, NULL);
break; break;
@ -1717,6 +1734,7 @@ static void help(const char *argv0) {
printf("%s %s %s %s\n", argv0, _("[options]"), "move-(sink-input|source-output)", _("#N SINK|SOURCE")); printf("%s %s %s %s\n", argv0, _("[options]"), "move-(sink-input|source-output)", _("#N SINK|SOURCE"));
printf("%s %s %s %s\n", argv0, _("[options]"), "suspend-(sink|source)", _("NAME|#N 1|0")); printf("%s %s %s %s\n", argv0, _("[options]"), "suspend-(sink|source)", _("NAME|#N 1|0"));
printf("%s %s %s %s\n", argv0, _("[options]"), "set-card-profile ", _("CARD PROFILE")); printf("%s %s %s %s\n", argv0, _("[options]"), "set-card-profile ", _("CARD PROFILE"));
printf("%s %s %s %s\n", argv0, _("[options]"), "get-default-(sink|source)", _("NAME"));
printf("%s %s %s %s\n", argv0, _("[options]"), "set-default-(sink|source)", _("NAME")); printf("%s %s %s %s\n", argv0, _("[options]"), "set-default-(sink|source)", _("NAME"));
printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT")); printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT"));
printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME [VOLUME ...]")); printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME [VOLUME ...]"));
@ -2017,6 +2035,9 @@ int main(int argc, char *argv[]) {
sink_name = pa_xstrdup(argv[optind+1]); sink_name = pa_xstrdup(argv[optind+1]);
} else if (pa_streq(argv[optind], "get-default-sink")) {
action = GET_DEFAULT_SINK;
} else if (pa_streq(argv[optind], "set-source-port")) { } else if (pa_streq(argv[optind], "set-source-port")) {
action = SET_SOURCE_PORT; action = SET_SOURCE_PORT;