summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Collard <louiscollard@chromium.org>2018-01-26 15:47:04 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-27 20:17:33 -0800
commitc4dd97d413aa90de3542d584722f9bc073ad695b (patch)
treee2bd824b69c7cedca0626efd44004ddb8a155e43
parent5094a7a806a203d1c84abfcda3f9e9df375c7ad4 (diff)
downloadadhd-c4dd97d413aa90de3542d584722f9bc073ad695b.tar.gz
CRAS: Add dbus interface for active status
The signals added here will be used to tell powerd when the state changes, so that it knows whether it can put the device to sleep. The method added to the interface will be used by powerd at startup to query the current status. BUG=chromium:753596 TEST=Ran locally on eve Change-Id: Icff42f7d71ea7bede2187a8d74682f1fad4b6178 Reviewed-on: https://chromium-review.googlesource.com/888186 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Louis Collard <louiscollard@chromium.org> Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
-rw-r--r--cras/README.dbus-api12
-rw-r--r--cras/src/common/cras_observer_ops.h3
-rw-r--r--cras/src/server/cras_dbus_control.c41
-rw-r--r--cras/src/server/cras_observer.c33
-rw-r--r--cras/src/server/cras_observer.h3
-rw-r--r--cras/src/tests/observer_unittest.cc20
6 files changed, 109 insertions, 3 deletions
diff --git a/cras/README.dbus-api b/cras/README.dbus-api
index 2059c8a9..beb0b85c 100644
--- a/cras/README.dbus-api
+++ b/cras/README.dbus-api
@@ -149,6 +149,13 @@ Methods void SetOutputVolume(int32 volume)
Returns the number of streams currently using output hardware.
+ int32 IsAudioOutputActive()
+
+ Returns 1 if there are currently any active output streams,
+ excluding 'dummy' streams that are not actually outputting any
+ audio. Returns 0 if there are no active streams, or all active
+ streams are 'dummy' streams.
+
void SetGlobalOutputChannelRemix(int32 num_channels,
array:double coefficient)
@@ -222,6 +229,11 @@ Signals OutputVolumeChanged(int32 volume)
Indicates the number of active streams has changed.
+ AudioOutputActiveStateChanged(boolean active)
+
+ Indicates active output state has changed.
+ See IsAudioOutputActive for details.
+
HotwordTriggered(int64 tv_sec, int64 tv_nsec)
Indicates that hotword was triggered at the given timestamp.
diff --git a/cras/src/common/cras_observer_ops.h b/cras/src/common/cras_observer_ops.h
index f257d9a8..108f1667 100644
--- a/cras/src/common/cras_observer_ops.h
+++ b/cras/src/common/cras_observer_ops.h
@@ -52,6 +52,9 @@ struct cras_observer_ops {
/* Hotword triggered. */
void (*hotword_triggered)(void *context,
int64_t tv_sec, int64_t tv_nsec);
+ /* State regarding whether non-empty audio is being played/captured has
+ * changed. */
+ void (*non_empty_audio_state_changed)(void *context, int non_empty);
};
#endif /* CRAS_OBSERVER_OPS_H */
diff --git a/cras/src/server/cras_dbus_control.c b/cras/src/server/cras_dbus_control.c
index bae52c30..f4bdd8a1 100644
--- a/cras/src/server/cras_dbus_control.c
+++ b/cras/src/server/cras_dbus_control.c
@@ -104,6 +104,9 @@
" <arg name=\"node_id\" type=\"t\" direction=\"in\"/>\n" \
" <arg name=\"model_name\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
+ " <method name=\"IsAudioOutputActive\">\n" \
+ " <arg name=\"active\" type=\"b\" direction=\"out\"/>\n" \
+ " </method>\n" \
" </interface>\n" \
" <interface name=\"" DBUS_INTERFACE_INTROSPECTABLE "\">\n" \
" <method name=\"Introspect\">\n" \
@@ -747,6 +750,18 @@ static DBusHandlerResult handle_set_hotword_model(
return DBUS_HANDLER_RESULT_HANDLED;
}
+static DBusHandlerResult handle_is_audio_active(
+ DBusConnection *conn,
+ DBusMessage *message,
+ void* arg)
+{
+ dbus_int32_t active = cras_system_state_get_non_empty_status();
+
+ send_int32_reply(conn, message, active);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
/* Handle incoming messages. */
static DBusHandlerResult handle_control_message(DBusConnection *conn,
DBusMessage *message,
@@ -877,9 +892,12 @@ static DBusHandlerResult handle_control_message(DBusConnection *conn,
CRAS_CONTROL_INTERFACE,
"SetHotwordModel")) {
return handle_set_hotword_model(conn, message, arg);
+ } else if (dbus_message_is_method_call(message,
+ CRAS_CONTROL_INTERFACE,
+ "IsAudioOutputActive")) {
+ return handle_is_audio_active(conn, message, arg);
}
-
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
@@ -1107,6 +1125,25 @@ static void signal_hotword_triggered(void *context,
dbus_message_unref(msg);
}
+static void signal_non_empty_audio_state_changed(void *context, int non_empty)
+{
+ struct cras_dbus_control *control = (struct cras_dbus_control *)context;
+
+ dbus_uint32_t serial = 0;
+ DBusMessage *msg;
+
+ msg = create_dbus_message("AudioOutputActiveStateChanged");
+ if (!msg)
+ return;
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_BOOLEAN, &non_empty,
+ DBUS_TYPE_INVALID);
+
+ dbus_connection_send(control->conn, msg, &serial);
+ dbus_message_unref(msg);
+}
+
/* Exported Interface */
void cras_dbus_control_start(DBusConnection *conn)
@@ -1146,6 +1183,8 @@ void cras_dbus_control_start(DBusConnection *conn)
observer_ops.node_left_right_swapped_changed =
signal_node_left_right_swapped_changed;
observer_ops.hotword_triggered = signal_hotword_triggered;
+ observer_ops.non_empty_audio_state_changed =
+ signal_non_empty_audio_state_changed;
dbus_control.observer = cras_observer_add(&observer_ops, &dbus_control);
}
diff --git a/cras/src/server/cras_observer.c b/cras/src/server/cras_observer.c
index a386f458..caff00d8 100644
--- a/cras/src/server/cras_observer.c
+++ b/cras/src/server/cras_observer.c
@@ -33,6 +33,7 @@ struct cras_observer_alerts {
* number of active streams per direction, make the alerts
* per-direciton. */
struct cras_alert *num_active_streams[CRAS_NUM_DIRECTIONS];
+ struct cras_alert *non_empty_audio_state_changed;
};
struct cras_observer_server {
@@ -79,6 +80,10 @@ struct cras_observer_alert_data_hotword_triggered {
int64_t tv_nsec;
};
+struct cras_observer_non_empty_audio_state {
+ int non_empty;
+};
+
/* Global observer instance. */
static struct cras_observer_server *g_observer;
@@ -267,6 +272,21 @@ static void hotword_triggered_alert(void *arg, void *data)
}
}
+static void non_empty_audio_state_changed_alert(void *arg, void *data)
+{
+ struct cras_observer_client *client;
+ struct cras_observer_non_empty_audio_state *non_empty_audio_data =
+ (struct cras_observer_non_empty_audio_state *)data;
+
+ DL_FOREACH(g_observer->clients, client) {
+ if (client->ops.non_empty_audio_state_changed) {
+ client->ops.non_empty_audio_state_changed(
+ client->context,
+ non_empty_audio_data->non_empty);
+ }
+ }
+}
+
static int cras_observer_server_set_alert(struct cras_alert **alert,
cras_alert_cb cb,
cras_alert_prepare prepare,
@@ -322,6 +342,7 @@ int cras_observer_server_init()
CRAS_OBSERVER_SET_ALERT(input_node_gain, NULL, 0);
CRAS_OBSERVER_SET_ALERT(suspend_changed, NULL, 0);
CRAS_OBSERVER_SET_ALERT(hotword_triggered, NULL, 0);
+ CRAS_OBSERVER_SET_ALERT(non_empty_audio_state_changed, NULL, 0);
CRAS_OBSERVER_SET_ALERT_WITH_DIRECTION(
num_active_streams, CRAS_STREAM_OUTPUT);
@@ -329,6 +350,7 @@ int cras_observer_server_init()
num_active_streams, CRAS_STREAM_INPUT);
CRAS_OBSERVER_SET_ALERT_WITH_DIRECTION(
num_active_streams, CRAS_STREAM_POST_MIX_PRE_DSP);
+
return 0;
error:
@@ -351,6 +373,7 @@ void cras_observer_server_free()
cras_alert_destroy(g_observer->alerts.input_node_gain);
cras_alert_destroy(g_observer->alerts.suspend_changed);
cras_alert_destroy(g_observer->alerts.hotword_triggered);
+ cras_alert_destroy(g_observer->alerts.non_empty_audio_state_changed);
cras_alert_destroy(g_observer->alerts.num_active_streams[
CRAS_STREAM_OUTPUT]);
cras_alert_destroy(g_observer->alerts.num_active_streams[
@@ -538,3 +561,13 @@ void cras_observer_notify_hotword_triggered(int64_t tv_sec, int64_t tv_nsec)
cras_alert_pending_data(g_observer->alerts.hotword_triggered,
&data, sizeof(data));
}
+
+void cras_observer_notify_non_empty_audio_state_changed(int non_empty)
+{
+ struct cras_observer_non_empty_audio_state data;
+
+ data.non_empty = non_empty;
+
+ cras_alert_pending_data(g_observer->alerts.non_empty_audio_state_changed,
+ &data, sizeof(data));
+} \ No newline at end of file
diff --git a/cras/src/server/cras_observer.h b/cras/src/server/cras_observer.h
index f6b5f6f6..440a8cee 100644
--- a/cras/src/server/cras_observer.h
+++ b/cras/src/server/cras_observer.h
@@ -97,4 +97,7 @@ void cras_observer_notify_num_active_streams(enum CRAS_STREAM_DIRECTION dir,
/* Notify observers of the timestamp when hotword triggered. */
void cras_observer_notify_hotword_triggered(int64_t tv_sec, int64_t tv_nsec);
+/* Notify observers the non-empty audio state changed. */
+void cras_observer_notify_non_empty_audio_state_changed(int active);
+
#endif /* CRAS_OBSERVER_H */
diff --git a/cras/src/tests/observer_unittest.cc b/cras/src/tests/observer_unittest.cc
index 2a29c025..0eaa8e12 100644
--- a/cras/src/tests/observer_unittest.cc
+++ b/cras/src/tests/observer_unittest.cc
@@ -196,7 +196,7 @@ class ObserverTest : public testing::Test {
ResetStubData();
rc = cras_observer_server_init();
ASSERT_EQ(0, rc);
- EXPECT_EQ(14, cras_alert_create_called);
+ EXPECT_EQ(15, cras_alert_create_called);
EXPECT_EQ(reinterpret_cast<void *>(output_volume_alert),
cras_alert_add_callback_map[g_observer->alerts.output_volume]);
EXPECT_EQ(reinterpret_cast<void *>(output_mute_alert),
@@ -232,6 +232,9 @@ class ObserverTest : public testing::Test {
cras_alert_add_callback_map[g_observer->alerts.suspend_changed]);
EXPECT_EQ(reinterpret_cast<void *>(hotword_triggered_alert),
cras_alert_add_callback_map[g_observer->alerts.hotword_triggered]);
+ EXPECT_EQ(reinterpret_cast<void *>(non_empty_audio_state_changed_alert),
+ cras_alert_add_callback_map[
+ g_observer->alerts.non_empty_audio_state_changed]);
cras_observer_get_ops(NULL, &ops1_);
EXPECT_NE(0, cras_observer_ops_are_empty(&ops1_));
@@ -245,7 +248,7 @@ class ObserverTest : public testing::Test {
virtual void TearDown() {
cras_observer_server_free();
- EXPECT_EQ(14, cras_alert_destroy_called);
+ EXPECT_EQ(15, cras_alert_destroy_called);
ResetStubData();
}
@@ -583,6 +586,19 @@ TEST_F(ObserverTest, NotifyHotwordTriggered) {
EXPECT_EQ(data->tv_nsec, 200);
}
+TEST_F(ObserverTest, NonEmpyAudioStateChanged) {
+ struct cras_observer_non_empty_audio_state *data;
+
+ cras_observer_notify_non_empty_audio_state_changed(1);
+ EXPECT_EQ(cras_alert_pending_alert_value,
+ g_observer->alerts.non_empty_audio_state_changed);
+ ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data));
+ ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void *>(NULL));
+ data = reinterpret_cast<struct cras_observer_non_empty_audio_state *>(
+ cras_alert_pending_data_value);
+ EXPECT_EQ(data->non_empty, 1);
+}
+
// Stubs
extern "C" {