pactl: Fix crash with older servers

Servers older than 0.9.15 don't know anything about cards, and card
operations will return a NULL pa_operation object when connected to
that old server. We must check the pa_operation pointer before passing
it to pa_operation_unref(), otherwise a NULL operation will result in
a crash.

Change-Id: Idc258479c077aafaff6254b76acb18034a158107
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
volume: Increase PA_SW_VOLUME_SNPRINT_DB_MAX

10 bytes isn't enough for "-123.45 dB", including the terminating null
byte.

Change-Id: I865060befd01d3dde69556c1f90b7de55350501a
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
sink-input, source-output: Fix mute saving

Change-Id: I2298ab51a384c3ddfa33da3e941e03f5027b4d77
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
direction: Add a couple of direction helper functions

Change-Id: I365acd7ce3e7abcbcb8a532c79016fca558238e8
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
core-util: Add pa_join()

Change-Id: I84ac0ee7a3097fce8ed9bad26b210fc97db9e9a7
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
dynarray: Add pa_dynarray_get_raw_array()

Change-Id: I6e40c2a20586d13c99c9d98059e4dbb1d0e9e562
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
dynarray: Add PA_DYNARRAY_FOREACH

The PA_DYNARRAY_FOREACH macro requires that pa_dynarray_get() returns
NULL if the index is out of bounds.

Change-Id: If9db312516fbb079e8b67d94d35a44783ab3395a
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
dynarray: Add pa_dynarray_remove_last()

Change-Id: I9098df96aac57a3ee2084061aa174f7ee02b1588
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
dynarray: Add pa_dynarray_remove_all()

Change-Id: I35079f8fe4b361221a1bdc1fececbe318bf3ee0e
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
hashmap: Add pa_hashmap_remove_and_free()

Change-Id: Ia3530c29cecf8964989aec4f0527fc982e80e34a
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
device-port: Add pa_device_port.active

In the Tizen volume API, I create and delete volume control objects
for ports based on their state (only active ports have volume
controls). Having the pa_device_port.active flag directly accessible
is much nicer than figuring out the state by iterating through sinks
and checking what their active port is. It's also safer to get a
notification for a deactivated port before the port switch is
executed, compared to using the SINK_PORT_CHANGED hook that is fired
only after the port switch is complete.

Change-Id: I3f7f8855721c8dc3a643708a72f6e35341ff7117
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
sink, source: Assign to reference_volume from only one place

Forcing all reference volume changes to go through
set_reference_volume_direct() makes it easier to check where the
reference volume is changed, and it also allows us to have only one
place where notifications for changed reference volume are sent.

Change-Id: I2e769b8a2b0d7031a02446dead8ca2e0c3402751
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
sink-input, source-output: Assign to volume from only one place

Forcing all volume changes to go through set_volume_direct() makes
it easier to check where the stream volume is changed, and it also
allows us to have only one place where notifications for changed
volume are sent.

Change-Id: Ie61bcc5747b419bb83c19a3ed78fd9f4d8a73cce
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
sink, source: Return early from set_mute()

This avoids redundant set_mute() callback calls.

Some logging was added too.

Change-Id: I10188c3b43d61fe751abe0f9940015af35c4a137
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
sink-input, source-output: Add logging to set_mute()

Change-Id: Ie10aa76cae75c7b6a52ea4a9039b8e3e37a748b2
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
sink, source: Allow calling set_mute() during initialization

Currently the alsa sink and source write directly to s->muted during
initialization, but I think it's better to avoid direct writes, and
use the set_mute() function instead, because that makes it easier to
figure out where s->muted is modified. This patch prevents the
set_mute() call from crashing in the state assertion.

Change-Id: I12220fb2668723931bebbe1484f115016f1edf25
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
echo-cancel: Remove redundant get_mute() callback

The callback just called pa_source_output_get_mute(), which doesn't
have any side effects, and the return value wasn't used either, so
the callback was essentially a no-op.

Change-Id: Ic16824b06393f59b55087842da64c7d09035b9e8
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
sink, source: Call set_mute() from mute_changed()

This refactoring reduces duplication, as mute_changed() used to do the
same things as set_mute(). Other benefits are improved logging
(set_mute() logs the mute change, mute_changed() used to not do that)
and the soft mute state is kept up to date, because set_mute() sends
the SET_MUTE message to the IO thread.

The set_mute_in_progress flag is an extra precaution for preventing
recursion in case a sink/source implementation's set_mute() callback
causes mute_changed() to be called. Currently there are no such
implementations, but I think that would be a valid thing to do, so
some day there might be such implementation.

Change-Id: I33c81f4034001f777c4533c2c63eada67548c683
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
sink, source: Assign to s->muted from only one place

Forcing all mute changes to go through set_mute() makes it easier to
check where the muted field is changed, and it also allows us to have
only one place where notifications for changed mute are sent.

Change-Id: Idb1bd6ef923a165e249d42265ebedc30a6c8fca4
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
sink-input, source-output: Remove redundant get_mute() functions

The functions just return the muted value. Callers can as well read
the struct field directly, it's simpler that way.

Change-Id: I368f7e09cdf522039a6573e5002f7544b4e840d3
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>