[pulseaudio-commits] r1666 - in /branches/lennart/src: pulse/introspect.c pulse/introspect.h pulsecore/native-common.h pulsecore/protocol-native.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed Aug 15 12:30:05 PDT 2007


Author: lennart
Date: Wed Aug 15 21:30:04 2007
New Revision: 1666

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1666&root=3Dpulseaudio&vi=
ew=3Drev
Log:
add protocol support for muting sink inputs and suspending sinks/sources

Modified:
    branches/lennart/src/pulse/introspect.c
    branches/lennart/src/pulse/introspect.h
    branches/lennart/src/pulsecore/native-common.h
    branches/lennart/src/pulsecore/protocol-native.c

Modified: branches/lennart/src/pulse/introspect.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/intr=
ospect.c?rev=3D1666&root=3Dpulseaudio&r1=3D1665&r2=3D1666&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulse/introspect.c (original)
+++ branches/lennart/src/pulse/introspect.c Wed Aug 15 21:30:04 2007
@@ -47,6 +47,8 @@
     assert(o);
     assert(o->ref >=3D 1);
 =

+    memset(&i, 0, sizeof(i));
+    =

     if (!o->context)
         goto finish;
 =

@@ -59,8 +61,7 @@
                pa_tagstruct_getu32(t, &i.memblock_total_size) < 0 ||
                pa_tagstruct_getu32(t, &i.memblock_allocated) < 0 ||
                pa_tagstruct_getu32(t, &i.memblock_allocated_size) < 0 ||
-               pa_tagstruct_getu32(t, &i.scache_size) < 0 ||
-               !pa_tagstruct_eof(t)) {
+               pa_tagstruct_getu32(t, &i.scache_size) < 0) {
         pa_context_fail(o->context, PA_ERR_PROTOCOL);
         goto finish;
     }
@@ -89,6 +90,8 @@
     assert(o);
     assert(o->ref >=3D 1);
 =

+    memset(&i, 0, sizeof(i));
+    =

     if (!o->context)
         goto finish;
 =

@@ -104,8 +107,7 @@
                pa_tagstruct_get_sample_spec(t, &i.sample_spec) < 0 ||
                pa_tagstruct_gets(t, &i.default_sink_name) < 0 ||
                pa_tagstruct_gets(t, &i.default_source_name) < 0 ||
-               pa_tagstruct_getu32(t, &i.cookie) < 0 ||
-               !pa_tagstruct_eof(t)) {
+               pa_tagstruct_getu32(t, &i.cookie) < 0) {
 =

         pa_context_fail(o->context, PA_ERR_PROTOCOL);
         goto finish;
@@ -148,6 +150,7 @@
 =

         while (!pa_tagstruct_eof(t)) {
             pa_sink_info i;
+            memset(&i, 0, sizeof(i));
 =

             if (pa_tagstruct_getu32(t, &i.index) < 0 ||
                 pa_tagstruct_gets(t, &i.name) < 0 ||
@@ -258,6 +261,7 @@
         while (!pa_tagstruct_eof(t)) {
             pa_source_info i;
             uint32_t flags;
+            memset(&i, 0, sizeof(i));
 =

             if (pa_tagstruct_getu32(t, &i.index) < 0 ||
                 pa_tagstruct_gets(t, &i.name) < 0 ||
@@ -367,6 +371,7 @@
 =

         while (!pa_tagstruct_eof(t)) {
             pa_client_info i;
+            memset(&i, 0, sizeof(i));
 =

             if (pa_tagstruct_getu32(t, &i.index) < 0 ||
                 pa_tagstruct_gets(t, &i.name) < 0 ||
@@ -441,6 +446,7 @@
 =

         while (!pa_tagstruct_eof(t)) {
             pa_module_info i;
+            memset(&i, 0, sizeof(i));
 =

             if (pa_tagstruct_getu32(t, &i.index) < 0 ||
                 pa_tagstruct_gets(t, &i.name) < 0 ||
@@ -516,7 +522,8 @@
 =

         while (!pa_tagstruct_eof(t)) {
             pa_sink_input_info i;
-
+            memset(&i, 0, sizeof(i));
+            =

             if (pa_tagstruct_getu32(t, &i.index) < 0 ||
                 pa_tagstruct_gets(t, &i.name) < 0 ||
                 pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
@@ -528,7 +535,8 @@
                 pa_tagstruct_get_usec(t, &i.buffer_usec) < 0 ||
                 pa_tagstruct_get_usec(t, &i.sink_usec) < 0 ||
                 pa_tagstruct_gets(t, &i.resample_method) < 0 ||
-                pa_tagstruct_gets(t, &i.driver) < 0) {
+                pa_tagstruct_gets(t, &i.driver) < 0 ||
+                (o->context->version >=3D 11 && pa_tagstruct_get_boolean(t=
, &i.mute) < 0)) {
 =

                 pa_context_fail(o->context, PA_ERR_PROTOCOL);
                 goto finish;
@@ -600,6 +608,8 @@
         while (!pa_tagstruct_eof(t)) {
             pa_source_output_info i;
 =

+            memset(&i, 0, sizeof(i));
+            =

             if (pa_tagstruct_getu32(t, &i.index) < 0 ||
                 pa_tagstruct_gets(t, &i.name) < 0 ||
                 pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
@@ -781,6 +791,29 @@
     return o;
 }
 =

+pa_operation* pa_context_set_sink_input_mute(pa_context *c, uint32_t idx, =
int mute, pa_context_success_cb_t cb, void *userdata) {
+    pa_operation *o;
+    pa_tagstruct *t;
+    uint32_t tag;
+
+    assert(c);
+    assert(c->ref >=3D 1);
+
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state =3D=3D PA_CONTEXT_READY, PA_=
ERR_BADSTATE);
+    PA_CHECK_VALIDITY_RETURN_NULL(c, idx !=3D PA_INVALID_INDEX, PA_ERR_INV=
ALID);
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >=3D 11, PA_ERR_NOTSUPPORT=
ED);
+
+    o =3D pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+    t =3D pa_tagstruct_command(c, PA_COMMAND_SET_SINK_INPUT_MUTE, &tag);
+    pa_tagstruct_putu32(t, idx);
+    pa_tagstruct_put_boolean(t, mute);
+    pa_pstream_send_tagstruct(c->pstream, t);
+    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_con=
text_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_=
unref);
+
+    return o;
+}
+
 pa_operation* pa_context_set_source_volume_by_index(pa_context *c, uint32_=
t idx, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata=
) {
     pa_operation *o;
     pa_tagstruct *t;
@@ -899,6 +932,8 @@
 =

         while (!pa_tagstruct_eof(t)) {
             pa_sample_info i;
+
+            memset(&i, 0, sizeof(i));
 =

             if (pa_tagstruct_getu32(t, &i.index) < 0 ||
                 pa_tagstruct_gets(t, &i.name) < 0 ||
@@ -1096,6 +1131,8 @@
         while (!pa_tagstruct_eof(t)) {
             pa_autoload_info i;
 =

+            memset(&i, 0, sizeof(i));
+
             if (pa_tagstruct_getu32(t, &i.index) < 0 ||
                 pa_tagstruct_gets(t, &i.name) < 0 ||
                 pa_tagstruct_getu32(t, &i.type) < 0 ||
@@ -1341,3 +1378,97 @@
 =

     return o;
 }
+
+pa_operation* pa_context_suspend_sink_by_name(pa_context *c, char *sink_na=
me, int suspend, pa_context_success_cb_t cb, void* userdata) {
+    pa_operation *o;
+    pa_tagstruct *t;
+    uint32_t tag;
+
+    assert(c);
+    assert(c->ref >=3D 1);
+
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state =3D=3D PA_CONTEXT_READY, PA_=
ERR_BADSTATE);
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >=3D 11, PA_ERR_NOTSUPPORT=
ED);
+    PA_CHECK_VALIDITY_RETURN_NULL(c, !sink_name || *sink_name, PA_ERR_INVA=
LID);
+
+    o =3D pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+    t =3D pa_tagstruct_command(c, PA_COMMAND_SUSPEND_SINK, &tag);
+    pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+    pa_tagstruct_puts(t, sink_name);
+    pa_tagstruct_put_boolean(t, suspend);
+    pa_pstream_send_tagstruct(c->pstream, t);
+    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_con=
text_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_=
unref);
+
+    return o;
+}
+
+pa_operation* pa_context_suspend_sink_by_index(pa_context *c, uint32_t idx=
, int suspend, pa_context_success_cb_t cb, void* userdata) {
+    pa_operation *o;
+    pa_tagstruct *t;
+    uint32_t tag;
+
+    assert(c);
+    assert(c->ref >=3D 1);
+
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state =3D=3D PA_CONTEXT_READY, PA_=
ERR_BADSTATE);
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >=3D 11, PA_ERR_NOTSUPPORT=
ED);
+
+    o =3D pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+    t =3D pa_tagstruct_command(c, PA_COMMAND_SUSPEND_SINK, &tag);
+    pa_tagstruct_putu32(t, idx);
+    pa_tagstruct_puts(t, idx =3D=3D PA_INVALID_INDEX ? "" : NULL);
+    pa_tagstruct_put_boolean(t, suspend);
+    pa_pstream_send_tagstruct(c->pstream, t);
+    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_con=
text_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_=
unref);
+
+    return o;
+}
+
+pa_operation* pa_context_suspend_source_by_name(pa_context *c, char *sourc=
e_name, int suspend, pa_context_success_cb_t cb, void* userdata) {
+    pa_operation *o;
+    pa_tagstruct *t;
+    uint32_t tag;
+
+    assert(c);
+    assert(c->ref >=3D 1);
+
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state =3D=3D PA_CONTEXT_READY, PA_=
ERR_BADSTATE);
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >=3D 11, PA_ERR_NOTSUPPORT=
ED);
+    PA_CHECK_VALIDITY_RETURN_NULL(c, !source_name || *source_name, PA_ERR_=
INVALID);
+
+    o =3D pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+    t =3D pa_tagstruct_command(c, PA_COMMAND_SUSPEND_SOURCE, &tag);
+    pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+    pa_tagstruct_puts(t, source_name);
+    pa_tagstruct_put_boolean(t, suspend);
+    pa_pstream_send_tagstruct(c->pstream, t);
+    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_con=
text_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_=
unref);
+
+    return o;
+}
+
+pa_operation* pa_context_suspend_source_by_index(pa_context *c, uint32_t i=
dx, int suspend, pa_context_success_cb_t cb, void* userdata) {
+    pa_operation *o;
+    pa_tagstruct *t;
+    uint32_t tag;
+
+    assert(c);
+    assert(c->ref >=3D 1);
+
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state =3D=3D PA_CONTEXT_READY, PA_=
ERR_BADSTATE);
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >=3D 11, PA_ERR_NOTSUPPORT=
ED);
+
+    o =3D pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+    t =3D pa_tagstruct_command(c, PA_COMMAND_SUSPEND_SOURCE, &tag);
+    pa_tagstruct_putu32(t, idx);
+    pa_tagstruct_puts(t, idx =3D=3D PA_INVALID_INDEX ? "" : NULL);
+    pa_tagstruct_put_boolean(t, suspend);
+    pa_pstream_send_tagstruct(c->pstream, t);
+    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_con=
text_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_=
unref);
+
+    return o;
+}

Modified: branches/lennart/src/pulse/introspect.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/intr=
ospect.h?rev=3D1666&root=3Dpulseaudio&r1=3D1665&r2=3D1666&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulse/introspect.h (original)
+++ branches/lennart/src/pulse/introspect.h Wed Aug 15 21:30:04 2007
@@ -249,7 +249,7 @@
     const char *monitor_of_sink_name;   /**< Name of the owning sink, or P=
A_INVALID_INDEX */
     pa_usec_t latency;                  /**< Length of filled record buffe=
r of this source. \since 0.5 */
     const char *driver;                 /**< Driver name \since 0.8 */
-    pa_source_flags_t flags;            /**< Flags \since 0.8 */
+    pa_source_flags_t flags;            /**< Flags \since 0.8 */    =

 } pa_source_info;
 =

 /** Callback prototype for pa_context_get_source_info_by_name() and friend=
s */
@@ -331,6 +331,7 @@
     pa_usec_t sink_usec;                 /**< Latency of the sink device, =
see pa_latency_info for details */
     const char *resample_method;         /**< Thre resampling method used =
by this sink input. \since 0.7 */
     const char *driver;                  /**< Driver name \since 0.8 */
+    int mute;                            /**< Stream muted \since 0.9.7 */
 } pa_sink_input_info;
 =

 /** Callback prototype for pa_context_get_sink_input_info() and firends*/
@@ -381,6 +382,9 @@
 /** Set the volume of a sink input stream */
 pa_operation* pa_context_set_sink_input_volume(pa_context *c, uint32_t idx=
, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
 =

+/** Set the mute switch of a sink input stream \since 0.9.7 */
+pa_operation* pa_context_set_sink_input_mute(pa_context *c, uint32_t idx, =
int mute, pa_context_success_cb_t cb, void *userdata);
+
 /** Set the volume of a source device specified by its index \since 0.8 */
 pa_operation* pa_context_set_source_volume_by_index(pa_context *c, uint32_=
t idx, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata=
);
 =

@@ -499,6 +503,18 @@
 /** Move the specified source output to a different source. \since 0.9.5 */
 pa_operation* pa_context_move_source_output_by_index(pa_context *c, uint32=
_t idx, uint32_t source_idx, pa_context_success_cb_t cb, void* userdata);
 =

+/** Suspend/Resume a sink. \since 0.9.7 */
+pa_operation* pa_context_suspend_sink_by_name(pa_context *c, char *sink_na=
me, int suspend, pa_context_success_cb_t cb, void* userdata);
+
+/** Suspend/Resume a sink. If idx is PA_INVALID_INDEX all sinks will be su=
spended. \since 0.9.7 */
+pa_operation* pa_context_suspend_sink_by_index(pa_context *c, uint32_t idx=
, int suspend,  pa_context_success_cb_t cb, void* userdata);
+
+/** Suspend/Resume a source. \since 0.9.7 */
+pa_operation* pa_context_suspend_source_by_name(pa_context *c, char *sourc=
e_name, int suspend, pa_context_success_cb_t cb, void* userdata);
+
+/** Suspend/Resume a source. If idx is PA_INVALID_INDEX all sources will b=
e suspended. \since 0.9.7 */
+pa_operation* pa_context_suspend_source_by_index(pa_context *c, uint32_t i=
dx, int suspend, pa_context_success_cb_t cb, void* userdata);
+
 PA_C_DECL_END
 =

 #endif

Modified: branches/lennart/src/pulsecore/native-common.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
native-common.h?rev=3D1666&root=3Dpulseaudio&r1=3D1665&r2=3D1666&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/native-common.h (original)
+++ branches/lennart/src/pulsecore/native-common.h Wed Aug 15 21:30:04 2007
@@ -117,6 +117,9 @@
 =

     PA_COMMAND_SET_SINK_INPUT_MUTE,
 =

+    PA_COMMAND_SUSPEND_SINK,
+    PA_COMMAND_SUSPEND_SOURCE,
+
     PA_COMMAND_MAX
 };
 =


Modified: branches/lennart/src/pulsecore/protocol-native.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
protocol-native.c?rev=3D1666&root=3Dpulseaudio&r1=3D1665&r2=3D1666&view=3Dd=
iff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/protocol-native.c (original)
+++ branches/lennart/src/pulsecore/protocol-native.c Wed Aug 15 21:30:04 20=
07
@@ -247,6 +247,7 @@
 static void command_cork_record_stream(pa_pdispatch *pd, uint32_t command,=
 uint32_t tag, pa_tagstruct *t, void *userdata);
 static void command_flush_record_stream(pa_pdispatch *pd, uint32_t command=
, uint32_t tag, pa_tagstruct *t, void *userdata);
 static void command_move_stream(pa_pdispatch *pd, uint32_t command, uint32=
_t tag, pa_tagstruct *t, void *userdata);
+static void command_suspend(pa_pdispatch *pd, uint32_t command, uint32_t t=
ag, pa_tagstruct *t, void *userdata);
 =

 static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] =3D {
     [PA_COMMAND_ERROR] =3D NULL,
@@ -296,6 +297,9 @@
     [PA_COMMAND_SET_SINK_INPUT_MUTE] =3D command_set_mute,
     [PA_COMMAND_SET_SOURCE_MUTE] =3D command_set_mute,
 =

+    [PA_COMMAND_SUSPEND_SINK] =3D command_suspend,
+    [PA_COMMAND_SUSPEND_SOURCE] =3D command_suspend,
+    =

     [PA_COMMAND_CORK_PLAYBACK_STREAM] =3D command_cork_playback_stream,
     [PA_COMMAND_FLUSH_PLAYBACK_STREAM] =3D command_trigger_or_flush_or_pre=
buf_playback_stream,
     [PA_COMMAND_TRIGGER_PLAYBACK_STREAM] =3D command_trigger_or_flush_or_p=
rebuf_playback_stream,
@@ -1770,7 +1774,7 @@
     pa_tagstruct_put_boolean(t, module->auto_unload);
 }
 =

-static void sink_input_fill_tagstruct(pa_tagstruct *t, pa_sink_input *s) {
+static void sink_input_fill_tagstruct(connection *c, pa_tagstruct *t, pa_s=
ink_input *s) {
     pa_assert(t);
     pa_sink_input_assert_ref(s);
 =

@@ -1786,6 +1790,8 @@
     pa_tagstruct_put_usec(t, pa_sink_get_latency(s->sink));
     pa_tagstruct_puts(t, pa_resample_method_to_string(pa_sink_input_get_re=
sample_method(s)));
     pa_tagstruct_puts(t, s->driver);
+    if (c->version >=3D 11)
+        pa_tagstruct_put_boolean(t, pa_sink_input_get_mute(s));    =

 }
 =

 static void source_output_fill_tagstruct(pa_tagstruct *t, pa_source_output=
 *s) {
@@ -1891,7 +1897,7 @@
     else if (module)
         module_fill_tagstruct(reply, module);
     else if (si)
-        sink_input_fill_tagstruct(reply, si);
+        sink_input_fill_tagstruct(c, reply, si);
     else if (so)
         source_output_fill_tagstruct(reply, so);
     else
@@ -1946,7 +1952,7 @@
             else if (command =3D=3D PA_COMMAND_GET_MODULE_INFO_LIST)
                 module_fill_tagstruct(reply, p);
             else if (command =3D=3D PA_COMMAND_GET_SINK_INPUT_INFO_LIST)
-                sink_input_fill_tagstruct(reply, p);
+                sink_input_fill_tagstruct(c, reply, p);
             else if (command =3D=3D PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST)
                 source_output_fill_tagstruct(reply, p);
             else {
@@ -2620,6 +2626,8 @@
         pa_source_output *so =3D NULL;
         pa_source *source;
 =

+        pa_assert(command =3D=3D PA_COMMAND_MOVE_SOURCE_OUTPUT);
+
         so =3D pa_idxset_get_by_index(c->protocol->core->source_outputs, i=
dx);
 =

         if (idx_device !=3D PA_INVALID_INDEX)
@@ -2632,6 +2640,80 @@
         if (pa_source_output_move_to(so, source) < 0) {
             pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
             return;
+        }
+    }
+
+    pa_pstream_send_simple_ack(c->pstream, tag);
+}
+
+static void command_suspend(pa_pdispatch *pd, uint32_t command, uint32_t t=
ag, pa_tagstruct *t, void *userdata) {
+    connection *c =3D CONNECTION(userdata);
+    uint32_t idx =3D PA_INVALID_INDEX;
+    const char *name =3D NULL;
+    int b;
+
+    connection_assert_ref(c);
+    pa_assert(t);
+
+    if (pa_tagstruct_getu32(t, &idx) < 0 ||
+        pa_tagstruct_gets(t, &name) < 0 ||
+        pa_tagstruct_get_boolean(t, &b) < 0 ||
+        !pa_tagstruct_eof(t)) {
+        protocol_error(c);
+        return;
+    }
+
+    CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+    CHECK_VALIDITY(c->pstream, idx !=3D PA_INVALID_INDEX || !name || !*nam=
e || pa_utf8_valid(name), tag, PA_ERR_INVALID);
+
+    if (command =3D=3D PA_COMMAND_SUSPEND_SINK) {
+
+        if (idx =3D=3D PA_INVALID_INDEX && name && !*name) {
+
+            if (pa_sink_suspend_all(c->protocol->core, b) < 0) {
+                pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
+                return;
+            }
+        } else {
+            pa_sink *sink =3D NULL;
+
+            if (idx !=3D PA_INVALID_INDEX)
+                sink =3D pa_idxset_get_by_index(c->protocol->core->sinks, =
idx);
+            else =

+                sink =3D pa_namereg_get(c->protocol->core, name, PA_NAMERE=
G_SINK, 1);
+
+            CHECK_VALIDITY(c->pstream, sink, tag, PA_ERR_NOENTITY);
+
+            if (pa_sink_suspend(sink, b) < 0) {
+                pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
+                return;
+            }
+        }
+    } else {
+
+        pa_assert(command =3D=3D PA_COMMAND_SUSPEND_SOURCE);
+        =

+        if (idx =3D=3D PA_INVALID_INDEX && name && !*name) {
+            =

+            if (pa_source_suspend_all(c->protocol->core, b) < 0) {
+                pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
+                return;
+            }
+
+        } else {
+            pa_source *source;
+
+            if (idx !=3D PA_INVALID_INDEX)
+                source =3D pa_idxset_get_by_index(c->protocol->core->sourc=
es, idx);
+            else
+                source =3D pa_namereg_get(c->protocol->core, name, PA_NAME=
REG_SOURCE, 1);
+            =

+            CHECK_VALIDITY(c->pstream, source, tag, PA_ERR_NOENTITY);
+
+            if (pa_source_suspend(source, b) < 0) {
+                pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
+                return;
+            }
         }
     }
 =





More information about the pulseaudio-commits mailing list