diff --git a/cras/common/BUILD.bazel b/cras/common/BUILD.bazel
index 062b6a82a..c2ad03b46 100644
--- a/cras/common/BUILD.bazel
+++ b/cras/common/BUILD.bazel
@@ -56,6 +56,15 @@ cras_cbindgen(
lib = ":rust_common",
)
+filegroup(
+ name = "rust_common_h_generated",
+ srcs = ["rust_common.h"],
+ visibility = [
+ "//cras/src/common:__pkg__",
+ "//cras/src/tests:__pkg__",
+ ],
+)
+
cc_library(
name = "rust_common_cc",
hdrs = ["rust_common.h"],
diff --git a/cras/dbus_bindings/org.chromium.cras.Control.xml b/cras/dbus_bindings/org.chromium.cras.Control.xml
index 0f443603b..fbc66563f 100644
--- a/cras/dbus_bindings/org.chromium.cras.Control.xml
+++ b/cras/dbus_bindings/org.chromium.cras.Control.xml
@@ -723,6 +723,15 @@
+
+
+
+ Signal that indicates the audio effect ui appearance needs update. See also GetVoiceIsolationUIAppearance.
+
+
+
+
+
diff --git a/cras/server/s2/s2.h b/cras/server/s2/s2.h
index 9ad8304d9..ed69d112f 100644
--- a/cras/server/s2/s2.h
+++ b/cras/server/s2/s2.h
@@ -19,7 +19,7 @@ extern "C" {
#include
#include "cras/common/rust_common.h"
-typedef void (*NotifyAudioEffectUIAppearanceChanged)(bool);
+typedef void (*NotifyAudioEffectUIAppearanceChanged)(struct CrasEffectUIAppearance);
void cras_s2_set_ap_nc_featured_allowed(bool allowed);
diff --git a/cras/server/s2/src/global.rs b/cras/server/s2/src/global.rs
index 8c40680b8..80a291df7 100644
--- a/cras/server/s2/src/global.rs
+++ b/cras/server/s2/src/global.rs
@@ -48,7 +48,7 @@ pub extern "C" fn cras_s2_are_audio_effects_ready() -> bool {
// Called when audio_effects_ready is changed, with the following arguments:
// - bool: indicates whether the audio effects is ready.
-pub type NotifyAudioEffectUIAppearanceChanged = extern "C" fn(bool);
+pub type NotifyAudioEffectUIAppearanceChanged = extern "C" fn(CrasEffectUIAppearance);
#[no_mangle]
pub extern "C" fn cras_s2_set_notify_audio_effect_ui_appearance_changed(
diff --git a/cras/server/s2/src/lib.rs b/cras/server/s2/src/lib.rs
index c23d2c238..50adb127c 100644
--- a/cras/server/s2/src/lib.rs
+++ b/cras/server/s2/src/lib.rs
@@ -444,7 +444,7 @@ impl S2 {
if let Some(callback) = self.callbacks.notify_audio_effect_ui_appearance_changed {
if prev_audio_effects_ready != self.output.audio_effects_ready {
- callback(self.output.audio_effects_ready)
+ callback(self.output.audio_effect_ui_appearance)
}
}
}
@@ -459,9 +459,11 @@ mod tests {
use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::atomic::AtomicBool;
+ use std::sync::atomic::AtomicU32;
use std::sync::atomic::Ordering;
use cras_common::types_internal::CrasDlcId;
+ use cras_common::types_internal::CrasEffectUIAppearance;
use cras_common::types_internal::CRAS_NC_PROVIDER;
use cras_common::types_internal::EFFECT_TYPE;
@@ -622,11 +624,19 @@ mod tests {
let mut s = S2::new();
assert!(!s.output.audio_effects_ready);
+ // Simply verifies the callback is called.
static CALLED: AtomicBool = AtomicBool::new(false);
- static IS_READY: AtomicBool = AtomicBool::new(false);
- extern "C" fn fake_notify_audio_effect_ui_appearance_changed(ready: bool) {
+ static TOGGLE_TYPE: AtomicU32 = AtomicU32::new(0);
+ static EFFECT_MODE_OPTIONS: AtomicU32 = AtomicU32::new(0);
+ static SHOW_EFFECT_FALLBACK_MESSAGE: AtomicBool = AtomicBool::new(false);
+ extern "C" fn fake_notify_audio_effect_ui_appearance_changed(
+ appearance: CrasEffectUIAppearance,
+ ) {
CALLED.store(true, Ordering::SeqCst);
- IS_READY.store(ready, Ordering::SeqCst);
+ TOGGLE_TYPE.store(appearance.toggle_type.bits(), Ordering::SeqCst);
+ EFFECT_MODE_OPTIONS.store(appearance.effect_mode_options.bits(), Ordering::SeqCst);
+ SHOW_EFFECT_FALLBACK_MESSAGE
+ .store(appearance.show_effect_fallback_message, Ordering::SeqCst);
}
s.set_notify_audio_effect_ui_appearance_changed(
@@ -642,7 +652,6 @@ mod tests {
]));
assert!(!s.output.audio_effects_ready);
assert!(!CALLED.load(Ordering::SeqCst));
- assert!(!IS_READY.load(Ordering::SeqCst));
s.set_dlc_installed(CrasDlcId::CrasDlcNcAp, true);
assert!(!s.output.audio_effects_ready);
@@ -651,13 +660,45 @@ mod tests {
s.set_dlc_installed(CrasDlcId::CrasDlcIntelligoBeamforming, true);
assert!(s.output.audio_effects_ready);
assert!(CALLED.load(Ordering::SeqCst));
- assert!(IS_READY.load(Ordering::SeqCst));
+ assert_eq!(
+ TOGGLE_TYPE.load(Ordering::SeqCst),
+ s.output.audio_effect_ui_appearance.toggle_type.bits()
+ );
+ assert_eq!(
+ EFFECT_MODE_OPTIONS.load(Ordering::SeqCst),
+ s.output
+ .audio_effect_ui_appearance
+ .effect_mode_options
+ .bits()
+ );
+ assert_eq!(
+ SHOW_EFFECT_FALLBACK_MESSAGE.load(Ordering::SeqCst),
+ s.output
+ .audio_effect_ui_appearance
+ .show_effect_fallback_message
+ );
CALLED.store(false, Ordering::SeqCst);
s.set_dlc_installed(CrasDlcId::CrasDlcNcAp, false);
assert!(!s.output.audio_effects_ready);
assert!(CALLED.load(Ordering::SeqCst));
- assert!(!IS_READY.load(Ordering::SeqCst));
+ assert_eq!(
+ TOGGLE_TYPE.load(Ordering::SeqCst),
+ s.output.audio_effect_ui_appearance.toggle_type.bits()
+ );
+ assert_eq!(
+ EFFECT_MODE_OPTIONS.load(Ordering::SeqCst),
+ s.output
+ .audio_effect_ui_appearance
+ .effect_mode_options
+ .bits()
+ );
+ assert_eq!(
+ SHOW_EFFECT_FALLBACK_MESSAGE.load(Ordering::SeqCst),
+ s.output
+ .audio_effect_ui_appearance
+ .show_effect_fallback_message
+ );
}
#[test]
diff --git a/cras/src/common/BUILD.bazel b/cras/src/common/BUILD.bazel
index 5e94b261f..c18be7812 100644
--- a/cras/src/common/BUILD.bazel
+++ b/cras/src/common/BUILD.bazel
@@ -61,6 +61,7 @@ cc_library(
name = "cras_observer_ops",
hdrs = [
"cras_observer_ops.h",
+ "//cras/common:rust_common_h_generated",
],
visibility = [
"//cras/src/libcras:__pkg__",
diff --git a/cras/src/common/cras_observer_ops.h b/cras/src/common/cras_observer_ops.h
index a0c21e96c..643903115 100644
--- a/cras/src/common/cras_observer_ops.h
+++ b/cras/src/common/cras_observer_ops.h
@@ -6,6 +6,7 @@
#ifndef CRAS_SRC_COMMON_CRAS_OBSERVER_OPS_H_
#define CRAS_SRC_COMMON_CRAS_OBSERVER_OPS_H_
+#include "cras/common/rust_common.h"
#include "cras_types.h"
#ifdef __cplusplus
@@ -100,8 +101,9 @@ struct cras_observer_ops {
void (*sidetone_supported_changed)(void* context, bool supported);
// State regarding whether the audio effects are ready.
- void (*audio_effect_ui_appearance_changed)(void* context,
- bool audio_effects_ready);
+ void (*audio_effect_ui_appearance_changed)(
+ void* context,
+ struct CrasEffectUIAppearance ui_appearance);
};
#ifdef __cplusplus
diff --git a/cras/src/server/cras_dbus_control.c b/cras/src/server/cras_dbus_control.c
index d6a68d7fd..30da3a96d 100644
--- a/cras/src/server/cras_dbus_control.c
+++ b/cras/src/server/cras_dbus_control.c
@@ -1096,6 +1096,23 @@ static DBusHandlerResult handle_get_audio_effect_dlcs(DBusConnection* conn,
return ret;
}
+// Appends args for audio effect ui appearance.
+// Returns 0 if success. Otherwise, DBusHandlerResult is returned.
+static int append_args_audio_effect_ui_appearance(
+ DBusMessage* msg,
+ struct CrasEffectUIAppearance appearance) {
+ // boolean size must be fixed at 4 bytes due to wire protocol!
+ dbus_bool_t show_effect_fallback_message =
+ appearance.show_effect_fallback_message;
+ if (!dbus_message_append_args(
+ msg, DBUS_TYPE_UINT32, &appearance.toggle_type, DBUS_TYPE_UINT32,
+ &appearance.effect_mode_options, DBUS_TYPE_BOOLEAN,
+ &show_effect_fallback_message, DBUS_TYPE_INVALID)) {
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ }
+ return 0;
+}
+
static DBusHandlerResult handle_get_voice_isolation_ui_appearance(
DBusConnection* conn,
DBusMessage* message,
@@ -1109,18 +1126,8 @@ static DBusHandlerResult handle_get_voice_isolation_ui_appearance(
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
- struct CrasEffectUIAppearance appearance =
- cras_s2_get_audio_effect_ui_appearance();
- dbus_uint32_t toggle_type = appearance.toggle_type;
- dbus_uint32_t effect_mode_options = appearance.effect_mode_options;
- // boolean size must be fixed at 4 bytes due to wire protocol!
- dbus_bool_t show_effect_fallback_message =
- appearance.show_effect_fallback_message;
- if (!dbus_message_append_args(
- reply, DBUS_TYPE_UINT32, &toggle_type, DBUS_TYPE_UINT32,
- &effect_mode_options, DBUS_TYPE_BOOLEAN,
- &show_effect_fallback_message, DBUS_TYPE_INVALID)) {
- ret = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ if (append_args_audio_effect_ui_appearance(
+ reply, cras_s2_get_audio_effect_ui_appearance()) != 0) {
goto unref_reply;
}
if (!dbus_connection_send(conn, reply, &serial)) {
@@ -2389,17 +2396,17 @@ static void signal_sidetone_supported_changed(void* context, bool supported) {
static void signal_audio_effect_ui_appearance_changed(
void* context,
- bool audio_effects_ready) {
+ struct CrasEffectUIAppearance ui_appearance) {
struct cras_dbus_control* control = (struct cras_dbus_control*)context;
dbus_uint32_t serial = 0;
- dbus_bool_t ready = audio_effects_ready;
DBusMessage* msg = create_dbus_message("AudioEffectUIAppearanceChanged");
if (!msg) {
return;
}
-
- dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &ready, DBUS_TYPE_INVALID);
+ if (append_args_audio_effect_ui_appearance(msg, ui_appearance) != 0) {
+ return;
+ }
dbus_connection_send(control->conn, msg, &serial);
dbus_message_unref(msg);
}
diff --git a/cras/src/server/cras_observer.c b/cras/src/server/cras_observer.c
index 72f6da89d..6bdad8957 100644
--- a/cras/src/server/cras_observer.c
+++ b/cras/src/server/cras_observer.c
@@ -9,6 +9,7 @@
#include
#include
+#include "cras/common/rust_common.h"
#include "cras/src/common/cras_observer_ops.h"
#include "cras/src/server/cras_alert.h"
#include "cras/src/server/cras_iodev_list.h"
@@ -148,7 +149,7 @@ struct cras_observer_alert_data_sidetone_supported_changed {
};
struct cras_observer_alert_data_audio_effect_ui_appearance_changed {
- bool audio_effects_ready;
+ struct CrasEffectUIAppearance ui_appearance;
};
// Global observer instance.
@@ -496,8 +497,8 @@ static void audio_effect_ui_appearance_changed_alert(void* arg, void* data) {
DL_FOREACH (g_observer->clients, client) {
if (client->ops.audio_effect_ui_appearance_changed) {
- client->ops.audio_effect_ui_appearance_changed(
- client->context, report->audio_effects_ready);
+ client->ops.audio_effect_ui_appearance_changed(client->context,
+ report->ui_appearance);
}
}
}
@@ -903,9 +904,9 @@ void cras_observer_notify_sidetone_supported_changed(bool supported) {
}
void cras_observer_notify_audio_effect_ui_appearance_changed(
- bool audio_effects_ready) {
+ struct CrasEffectUIAppearance ui_appearance) {
struct cras_observer_alert_data_audio_effect_ui_appearance_changed data = {
- .audio_effects_ready = audio_effects_ready};
+ .ui_appearance = ui_appearance};
cras_alert_pending_data(g_observer->alerts.audio_effect_ui_appearance_changed,
&data, sizeof(data));
}
diff --git a/cras/src/server/cras_observer.h b/cras/src/server/cras_observer.h
index e8a3c1010..df879a0c4 100644
--- a/cras/src/server/cras_observer.h
+++ b/cras/src/server/cras_observer.h
@@ -6,6 +6,7 @@
#ifndef CRAS_SRC_SERVER_CRAS_OBSERVER_H_
#define CRAS_SRC_SERVER_CRAS_OBSERVER_H_
+#include "cras/common/rust_common.h"
#include "cras/src/common/cras_observer_ops.h"
#ifdef __cplusplus
@@ -150,7 +151,7 @@ void cras_observer_notify_sidetone_supported_changed(bool supported);
// Notify observers whether the audio effects are ready.
void cras_observer_notify_audio_effect_ui_appearance_changed(
- bool audio_effects_ready);
+ struct CrasEffectUIAppearance ui_appearance);
#ifdef __cplusplus
} // extern "C"
diff --git a/cras/src/tests/BUILD.bazel b/cras/src/tests/BUILD.bazel
index b0e08b6fb..b9eeb55ee 100644
--- a/cras/src/tests/BUILD.bazel
+++ b/cras/src/tests/BUILD.bazel
@@ -678,6 +678,7 @@ cc_test(
name = "cras_abi_unittest",
srcs = [
":cras_abi_unittest.cc",
+ "//cras/common:rust_common_h_generated",
"//cras/src/common:cras_audio_format.c",
"//cras/src/common:cras_config.c",
"//cras/src/common:cras_file_wait.c",
@@ -700,6 +701,7 @@ cc_test(
name = "cras_client_unittest",
srcs = [
":cras_client_unittest.cc",
+ "//cras/common:rust_common_h_generated",
"//cras/src/common:cras_config.c",
"//cras/src/common:cras_file_wait.c",
"//cras/src/common:cras_shm.c",
diff --git a/cras/src/tests/observer_unittest.cc b/cras/src/tests/observer_unittest.cc
index b4fb0f6d7..e301c3afc 100644
--- a/cras/src/tests/observer_unittest.cc
+++ b/cras/src/tests/observer_unittest.cc
@@ -8,6 +8,7 @@
#include
#include
+#include "cras/common/rust_common.h"
#include "cras/src/server/cras_observer.h"
#include "cras_types.h"
@@ -76,7 +77,8 @@ static std::vector cb_ewma_power_reported_values;
static size_t cb_sidetone_supported_changed_called;
static std::vector cb_sidetone_supported_changed_values;
static size_t cb_audio_effect_ui_appearance_changed_called;
-static std::vector cb_audio_effect_ui_appearance_changed_values;
+static std::vector
+ cb_audio_effect_ui_appearance_changed_values;
static void ResetStubData() {
cras_alert_destroy_called = 0;
@@ -282,10 +284,11 @@ void cb_sidetone_supported_changed(void* context, bool supported) {
cb_context.push_back(context);
}
-void cb_audio_effect_ui_appearance_changed(void* context,
- bool audio_effects_ready) {
+void cb_audio_effect_ui_appearance_changed(
+ void* context,
+ struct CrasEffectUIAppearance appearance) {
cb_audio_effect_ui_appearance_changed_called++;
- cb_audio_effect_ui_appearance_changed_values.push_back(audio_effects_ready);
+ cb_audio_effect_ui_appearance_changed_values.push_back(appearance);
cb_context.push_back(context);
}
@@ -891,25 +894,47 @@ TEST_F(ObserverTest, SidetoneSupportedChanged) {
}
TEST_F(ObserverTest, AudioEffectUIAppearanceChanged) {
- cras_observer_notify_audio_effect_ui_appearance_changed(true);
+ struct CrasEffectUIAppearance appearance {
+ .toggle_type = EFFECT_TYPE_STYLE_TRANSFER,
+ .effect_mode_options = EFFECT_TYPE_STYLE_TRANSFER,
+ .show_effect_fallback_message = true
+ };
+ cras_observer_notify_audio_effect_ui_appearance_changed(appearance);
EXPECT_EQ(cras_alert_pending_alert_value,
g_observer->alerts.audio_effect_ui_appearance_changed);
auto* data = reinterpret_cast<
struct cras_observer_alert_data_audio_effect_ui_appearance_changed*>(
cras_alert_pending_data_value);
- EXPECT_EQ(data->audio_effects_ready, true);
+ EXPECT_EQ(data->ui_appearance.toggle_type, appearance.toggle_type);
+ EXPECT_EQ(data->ui_appearance.effect_mode_options,
+ appearance.effect_mode_options);
+ EXPECT_EQ(data->ui_appearance.show_effect_fallback_message,
+ appearance.show_effect_fallback_message);
ops1_.audio_effect_ui_appearance_changed =
cb_audio_effect_ui_appearance_changed;
ops2_.audio_effect_ui_appearance_changed =
cb_audio_effect_ui_appearance_changed;
- DoObserverAlert(audio_effect_ui_appearance_changed_alert, data);
+ DoObserverAlert(audio_effect_ui_appearance_changed_alert, &appearance);
ASSERT_EQ(cb_audio_effect_ui_appearance_changed_called, 2);
- EXPECT_EQ(cb_audio_effect_ui_appearance_changed_values,
- (std::vector{true, true}));
-
- DoObserverRemoveClear(audio_effect_ui_appearance_changed_alert, data);
+ EXPECT_EQ(cb_audio_effect_ui_appearance_changed_values.size(), 2);
+ EXPECT_EQ(cb_audio_effect_ui_appearance_changed_values[0].toggle_type,
+ appearance.toggle_type);
+ EXPECT_EQ(cb_audio_effect_ui_appearance_changed_values[1].toggle_type,
+ appearance.toggle_type);
+ EXPECT_EQ(cb_audio_effect_ui_appearance_changed_values[0].effect_mode_options,
+ appearance.effect_mode_options);
+ EXPECT_EQ(cb_audio_effect_ui_appearance_changed_values[1].effect_mode_options,
+ appearance.effect_mode_options);
+ EXPECT_EQ(cb_audio_effect_ui_appearance_changed_values[0]
+ .show_effect_fallback_message,
+ appearance.show_effect_fallback_message);
+ EXPECT_EQ(cb_audio_effect_ui_appearance_changed_values[1]
+ .show_effect_fallback_message,
+ appearance.show_effect_fallback_message);
+
+ DoObserverRemoveClear(audio_effect_ui_appearance_changed_alert, &appearance);
}
// Stubs
diff --git a/cras/src/tests/system_state_unittest.cc b/cras/src/tests/system_state_unittest.cc
index 09fc0b0b1..fd49eba78 100644
--- a/cras/src/tests/system_state_unittest.cc
+++ b/cras/src/tests/system_state_unittest.cc
@@ -7,6 +7,7 @@
#include
#include
+#include "cras/common/rust_common.h"
#include "cras/server/feature_tier/feature_tier.h"
#include "cras/server/s2/s2.h"
#include "cras/src/common/cras_alsa_card_info.h"
@@ -823,7 +824,8 @@ void cras_iodev_list_reset_for_noise_cancellation() {
cras_iodev_list_reset_for_noise_cancellation_called++;
}
-void cras_observer_notify_audio_effect_ui_appearance_changed(bool) {}
+void cras_observer_notify_audio_effect_ui_appearance_changed(
+ struct CrasEffectUIAppearance ui_appearance) {}
} // extern "C"
} // namespace