[pulseaudio-discuss] [PATCH 2/2] pactl: Show the default sink/source in the list command.

David Henningsson david.henningsson at canonical.com
Tue Jan 29 17:05:29 PST 2013


On 01/29/2013 05:41 PM, poljar (Damir Jelić) wrote:
> This includes exposing the information in the protocol for the
> get sink/source info commands and adding 2 new reply fields for
> these commands.
>
> Update protocol to 28.
> ---
>   PROTOCOL                        | 10 ++++++++++
>   configure.ac                    |  2 +-
>   src/modules/module-tunnel.c     | 10 ++++++++++
>   src/pulse/introspect.c          | 14 ++++++++++++++
>   src/pulse/introspect.h          |  2 ++
>   src/pulsecore/protocol-native.c | 18 ++++++++++++++++++
>   src/utils/pactl.c               |  4 ++++
>   7 files changed, 59 insertions(+), 1 deletion(-)
>
> diff --git a/PROTOCOL b/PROTOCOL
> index 01abeed..d0ea360 100644
> --- a/PROTOCOL
> +++ b/PROTOCOL
> @@ -333,6 +333,16 @@ PA_COMMAND_GET_CARD_INFO(_LIST)):
>
>   The field is added once for every port.
>
> +## v28, implemented by >= 3.0

You probably mean >= 4.0 ?

Otherwise looks good (I did a quick read review only, no testing).

(Slightly cleaner to have the pactl changes in a separate patch but I'm 
not picky about that.)

> +
> +New field in reply from PA_COMMAND_GET_SINK_INFO (and thus
> +PA_COMMAND_GET_SINK_INFO_LIST)
> +    bool sink_default
> +
> +New field in reply from PA_COMMAND_GET_SOURCE_INFO (and thus
> +PA_COMMAND_GET_SOURCE_INFO_LIST)
> +    bool source_default
> +
>   #### If you just changed the protocol, read this
>   ## module-tunnel depends on the sink/source/sink-input/source-input protocol
>   ## internals, so if you changed these, you might have broken module-tunnel.
> diff --git a/configure.ac b/configure.ac
> index 6d340fd..89d7ee3 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -40,7 +40,7 @@ AC_SUBST(PA_MINOR, pa_minor)
>   AC_SUBST(PA_MAJORMINOR, pa_major.pa_minor)
>
>   AC_SUBST(PA_API_VERSION, 12)
> -AC_SUBST(PA_PROTOCOL_VERSION, 27)
> +AC_SUBST(PA_PROTOCOL_VERSION, 28)
>
>   # The stable ABI for client applications, for the version info x:y:z
>   # always will hold y=z
> diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c
> index 66b9617..993bbb0 100644
> --- a/src/modules/module-tunnel.c
> +++ b/src/modules/module-tunnel.c
> @@ -1063,6 +1063,7 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa_t
>       pa_channel_map cm;
>       pa_cvolume volume;
>       pa_bool_t mute;
> +    bool sink_default;
>       pa_usec_t latency;
>
>       pa_assert(pd);
> @@ -1125,6 +1126,10 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa_t
>       if (u->version >= 21 && read_formats(u, t) < 0)
>           goto fail;
>
> +    if (u->version >=28)
> +        if (pa_tagstruct_get_boolean(t, &sink_default) < 0)
> +            goto fail;
> +
>       if (!pa_tagstruct_eof(t)) {
>           pa_log("Packet too long");
>           goto fail;
> @@ -1264,6 +1269,7 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa
>       pa_channel_map cm;
>       pa_cvolume volume;
>       pa_bool_t mute;
> +    bool source_default;
>       pa_usec_t latency, configured_latency;
>
>       pa_assert(pd);
> @@ -1324,6 +1330,10 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa
>       if (u->version >= 22 && read_formats(u, t) < 0)
>           goto fail;
>
> +    if (u->version >=28)
> +        if (pa_tagstruct_get_boolean(t, &source_default) < 0)
> +            goto fail;
> +
>       if (!pa_tagstruct_eof(t)) {
>           pa_log("Packet too long");
>           goto fail;
> diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c
> index e959e96..ff86022 100644
> --- a/src/pulse/introspect.c
> +++ b/src/pulse/introspect.c
> @@ -253,6 +253,13 @@ static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, u
>                   }
>               }
>
> +            if (o->context->version >= 28) {
> +                bool sink_default;
> +                if (pa_tagstruct_get_boolean(t, &sink_default) < 0)
> +                    goto fail;
> +                i.sink_default = (int) sink_default;
> +            }
> +
>               i.mute = (int) mute;
>               i.flags = (pa_sink_flags_t) flags;
>               i.state = (pa_sink_state_t) state;
> @@ -548,6 +555,13 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
>                   }
>               }
>
> +            if (o->context->version >= 28) {
> +                bool source_default;
> +                if (pa_tagstruct_get_boolean(t, &source_default) < 0)
> +                    goto fail;
> +                i.source_default = (int) source_default;
> +            }
> +
>               i.mute = (int) mute;
>               i.flags = (pa_source_flags_t) flags;
>               i.state = (pa_source_state_t) state;
> diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h
> index fd6f289..f546955 100644
> --- a/src/pulse/introspect.h
> +++ b/src/pulse/introspect.h
> @@ -233,6 +233,7 @@ typedef struct pa_sink_info {
>       pa_sink_port_info* active_port;    /**< Pointer to active port in the array, or NULL. \since 0.9.16 */
>       uint8_t n_formats;                 /**< Number of formats supported by the sink. \since 1.0 */
>       pa_format_info **formats;          /**< Array of formats supported by the sink. \since 1.0 */
> +    int sink_default;                  /**< Default sink flag. \since 4.0 */
>   } pa_sink_info;
>
>   /** Callback prototype for pa_context_get_sink_info_by_name() and friends */
> @@ -316,6 +317,7 @@ typedef struct pa_source_info {
>       pa_source_port_info* active_port;   /**< Pointer to active port in the array, or NULL. \since 0.9.16  */
>       uint8_t n_formats;                  /**< Number of formats supported by the source. \since 1.0 */
>       pa_format_info **formats;           /**< Array of formats supported by the source. \since 1.0 */
> +    int source_default;                 /**< Default source flag. \since 4.0 */
>   } pa_source_info;
>
>   /** Callback prototype for pa_context_get_source_info_by_name() and friends */
> diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
> index 88808bf..37d2c17 100644
> --- a/src/pulsecore/protocol-native.c
> +++ b/src/pulsecore/protocol-native.c
> @@ -3145,6 +3145,15 @@ static void sink_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_sin
>
>           pa_idxset_free(formats, (pa_free2_cb_t) pa_format_info_free2, NULL);
>       }
> +
> +    if (c->version >= 28) {
> +        bool sink_default = false;
> +
> +        if (sink == pa_namereg_get_default_sink(sink->core))
> +            sink_default = true;
> +
> +        pa_tagstruct_put_boolean(t, sink_default);
> +    }
>   }
>
>   static void source_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_source *source) {
> @@ -3215,6 +3224,15 @@ static void source_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_s
>
>           pa_idxset_free(formats, (pa_free2_cb_t) pa_format_info_free2, NULL);
>       }
> +
> +    if (c->version >= 28) {
> +        bool source_default = false;
> +
> +        if (source == pa_namereg_get_default_source(source->core))
> +            source_default = true;
> +
> +        pa_tagstruct_put_boolean(t, source_default);
> +    }
>   }
>
>   static void client_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_client *client) {
> diff --git a/src/utils/pactl.c b/src/utils/pactl.c
> index b255ca2..6ec4211 100644
> --- a/src/utils/pactl.c
> +++ b/src/utils/pactl.c
> @@ -282,6 +282,7 @@ static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_
>                "\tState: %s\n"
>                "\tName: %s\n"
>                "\tDescription: %s\n"
> +             "\tDefault: %s\n"
>                "\tDriver: %s\n"
>                "\tSample Specification: %s\n"
>                "\tChannel Map: %s\n"
> @@ -298,6 +299,7 @@ static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_
>              state_table[1+i->state],
>              i->name,
>              pa_strnull(i->description),
> +           pa_yes_no(i->sink_default),
>              pa_strnull(i->driver),
>              pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
>              pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
> @@ -395,6 +397,7 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
>                "\tState: %s\n"
>                "\tName: %s\n"
>                "\tDescription: %s\n"
> +             "\tDefault: %s\n"
>                "\tDriver: %s\n"
>                "\tSample Specification: %s\n"
>                "\tChannel Map: %s\n"
> @@ -411,6 +414,7 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
>              state_table[1+i->state],
>              i->name,
>              pa_strnull(i->description),
> +           pa_yes_no(i->source_default),
>              pa_strnull(i->driver),
>              pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
>              pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
>



-- 
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic


More information about the pulseaudio-discuss mailing list