From 4c53579af096631064d743874b42e9d75a10b00c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 20 Jan 2015 10:59:41 -0600 Subject: remove the 'loop' test when deciding whether or not to set the audio role. --- src/sound.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/sound.cpp b/src/sound.cpp index 3a4b26f..d99fcdd 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -110,7 +110,7 @@ private: GST_SEEK_TYPE_NONE, (gint64)GST_CLOCK_TIME_NONE); } - else if ((GST_MESSAGE_TYPE(msg) == GST_MESSAGE_STREAM_START) && (self->m_loop)) + else if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_STREAM_START) { /* Set the media role if audio sink is pulsesink */ GstElement *audio_sink = nullptr; -- cgit v1.2.3 From a4ffa788d2f92d1a446f8d6155b111bc79c51a4d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 20 Jan 2015 11:01:07 -0600 Subject: use a local temporary to avoid having to GST_MESSAGE_CAST() twice --- src/sound.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound.cpp b/src/sound.cpp index d99fcdd..be0c4f1 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -98,8 +98,9 @@ private: static gboolean bus_callback(GstBus*, GstMessage* msg, gpointer gself) { auto self = static_cast(gself); + const auto message_type = GST_MESSAGE_TYPE(msg); - if ((GST_MESSAGE_TYPE(msg) == GST_MESSAGE_EOS) && (self->m_loop)) + if ((message_type == GST_MESSAGE_EOS) && (self->m_loop)) { gst_element_seek(self->m_play, 1.0, @@ -110,7 +111,7 @@ private: GST_SEEK_TYPE_NONE, (gint64)GST_CLOCK_TIME_NONE); } - else if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_STREAM_START) + else if (message_type == GST_MESSAGE_STREAM_START) { /* Set the media role if audio sink is pulsesink */ GstElement *audio_sink = nullptr; -- cgit v1.2.3 From 392487de7ec4357f8f7b68105d9dd667d5b14d62 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 21 Jan 2015 14:25:52 -0600 Subject: first stab at AccountsService proxy. WIP; pushing to test on devices --- src/CMakeLists.txt | 3 ++ src/com.ubuntu.touch.AccountsService.Sound.xml | 42 +++++++++++++++++ src/snap.cpp | 63 +++++++++++++++++++++++--- 3 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 src/com.ubuntu.touch.AccountsService.Sound.xml (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 512cc5c..5fc822c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,6 +47,9 @@ set(SERVICE_GENERATED_SOURCES) add_gdbus_codegen(SERVICE_GENERATED_SOURCES dbus-alarm-properties com.canonical.indicator ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.datetime.AlarmProperties.xml) +add_gdbus_codegen(SERVICE_GENERATED_SOURCES dbus-accounts-sound + com.ubuntu.touch + ${CMAKE_SOURCE_DIR}/src/com.ubuntu.touch.AccountsService.Sound.xml) # add warnings/coverage info on handwritten files # but not the autogenerated ones... diff --git a/src/com.ubuntu.touch.AccountsService.Sound.xml b/src/com.ubuntu.touch.AccountsService.Sound.xml new file mode 100644 index 0000000..91d71dc --- /dev/null +++ b/src/com.ubuntu.touch.AccountsService.Sound.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/snap.cpp b/src/snap.cpp index ee96007..e916eff 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -17,6 +17,8 @@ * Charles Kerr */ +#include "dbus-accounts-sound.h" + #include #include // is_locale_12h() @@ -32,6 +34,9 @@ #include #include +#include // getuid() +#include // getuid() + namespace uin = unity::indicator::notifications; namespace unity { @@ -49,12 +54,26 @@ public: Impl(const std::shared_ptr& engine, const std::shared_ptr& settings): m_engine(engine), - m_settings(settings) + m_settings(settings), + m_cancellable(g_cancellable_new()) { + auto object_path = g_strdup_printf("/org/freedesktop/Accounts/User/%lu", (gulong)getuid()); + accounts_service_sound_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, + "org.freedesktop.Accounts", + object_path, + m_cancellable, + on_sound_proxy_ready, + this); + g_free(object_path); } ~Impl() { + g_cancellable_cancel(m_cancellable); + g_clear_object(&m_cancellable); + g_clear_object(&m_accounts_service_sound_proxy); + for (const auto& key : m_notifications) m_engine->close (key); } @@ -72,11 +91,16 @@ public: // force the system to stay awake auto awake = std::make_shared(m_engine->app_name()); - // create the sound... - const auto uri = get_alarm_uri(appointment, m_settings); - const auto volume = m_settings->alarm_volume.get(); - const bool loop = interactive; - auto sound = std::make_shared(uri, volume, loop); + // create the sound. + // calendar events are muted in silent mode; alarm clocks never are + std::shared_ptr sound; + g_message("silent_mode is %d", (int)silent_mode()); + if (appointment.is_ubuntu_alarm() || !silent_mode()) { + const auto uri = get_alarm_uri(appointment, m_settings); + const auto volume = m_settings->alarm_volume.get(); + const bool loop = interactive; + sound = std::make_shared(uri, volume, loop); + } // create the haptic feedback... const auto haptic_mode = m_settings->alarm_haptic.get(); @@ -131,6 +155,31 @@ public: private: + static void on_sound_proxy_ready(GObject* /*source_object*/, GAsyncResult* res, gpointer gself) + { + GError * error; + + error = nullptr; + auto accounts_service_sound_proxy = accounts_service_sound_proxy_new_for_bus_finish (res, &error); + if (error != nullptr) + { + if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning("%s Couldn't accounts service sound proxy: %s", G_STRLOC, error->message); + } + else + { + static_cast(gself)->m_accounts_service_sound_proxy = accounts_service_sound_proxy; + g_message("got accounts sound service proxy"); + } + } + + bool silent_mode() const + { + g_message("%s %s %p %d", G_STRLOC, G_STRFUNC, m_accounts_service_sound_proxy, (int)accounts_service_sound_get_silent_mode(m_accounts_service_sound_proxy)); + return (m_accounts_service_sound_proxy != nullptr) + && (!accounts_service_sound_get_silent_mode(m_accounts_service_sound_proxy)); + } + std::string get_alarm_uri(const Appointment& appointment, const std::shared_ptr& settings) const { @@ -167,6 +216,8 @@ private: const std::shared_ptr m_engine; const std::shared_ptr m_settings; std::set m_notifications; + GCancellable * m_cancellable {nullptr}; + AccountsServiceSound * m_accounts_service_sound_proxy {nullptr}; }; /*** -- cgit v1.2.3 From 9feba7c10f246f0341829f76a7d6f46867d25103 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 21 Jan 2015 15:07:29 -0600 Subject: in Snap, fix the code that checks AccountsService.Sound for Silent Mode --- src/snap.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index e916eff..832ba1c 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -57,7 +57,7 @@ public: m_settings(settings), m_cancellable(g_cancellable_new()) { - auto object_path = g_strdup_printf("/org/freedesktop/Accounts/User/%lu", (gulong)getuid()); + auto object_path = g_strdup_printf("/org/freedesktop/Accounts/User%lu", (gulong)getuid()); accounts_service_sound_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, "org.freedesktop.Accounts", @@ -91,11 +91,10 @@ public: // force the system to stay awake auto awake = std::make_shared(m_engine->app_name()); - // create the sound. // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; - g_message("silent_mode is %d", (int)silent_mode()); if (appointment.is_ubuntu_alarm() || !silent_mode()) { + // create the sound. const auto uri = get_alarm_uri(appointment, m_settings); const auto volume = m_settings->alarm_volume.get(); const bool loop = interactive; @@ -164,20 +163,20 @@ private: if (error != nullptr) { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning("%s Couldn't accounts service sound proxy: %s", G_STRLOC, error->message); + g_warning("%s Couldn't find accounts service sound proxy: %s", G_STRLOC, error->message); + + g_clear_error(&error); } else { static_cast(gself)->m_accounts_service_sound_proxy = accounts_service_sound_proxy; - g_message("got accounts sound service proxy"); } } bool silent_mode() const { - g_message("%s %s %p %d", G_STRLOC, G_STRFUNC, m_accounts_service_sound_proxy, (int)accounts_service_sound_get_silent_mode(m_accounts_service_sound_proxy)); return (m_accounts_service_sound_proxy != nullptr) - && (!accounts_service_sound_get_silent_mode(m_accounts_service_sound_proxy)); + && (accounts_service_sound_get_silent_mode(m_accounts_service_sound_proxy)); } std::string get_alarm_uri(const Appointment& appointment, -- cgit v1.2.3 From ba986b6071161b7f3179dfb524f6c8c5d3ea23d1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 21 Jan 2015 19:36:23 -0600 Subject: tweak an overly-verbose variable name --- src/snap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 832ba1c..ea14f30 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -159,7 +159,7 @@ private: GError * error; error = nullptr; - auto accounts_service_sound_proxy = accounts_service_sound_proxy_new_for_bus_finish (res, &error); + auto proxy = accounts_service_sound_proxy_new_for_bus_finish (res, &error); if (error != nullptr) { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -169,7 +169,7 @@ private: } else { - static_cast(gself)->m_accounts_service_sound_proxy = accounts_service_sound_proxy; + static_cast(gself)->m_accounts_service_sound_proxy = proxy; } } -- cgit v1.2.3 From c5f2b60893cd8a34a285d5e57484b498890b93e1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 21 Jan 2015 19:57:59 -0600 Subject: require an explicit role for the sound so that we can differentiate between eg 'alarm' and 'alert' --- src/sound.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/sound.cpp b/src/sound.cpp index be0c4f1..a768a29 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -38,9 +38,11 @@ class Sound::Impl { public: - Impl(const std::string& uri, + Impl(const std::string& role, + const std::string& uri, unsigned int volume, bool loop): + m_role(role), m_uri(uri), m_volume(volume), m_loop(loop) @@ -122,10 +124,11 @@ private: feature = GST_PLUGIN_FEATURE_CAST(GST_ELEMENT_GET_CLASS(audio_sink)->elementfactory); if (feature && g_strcmp0(gst_plugin_feature_get_name(feature), "pulsesink") == 0) { - std::string role_str("props,media.role=alarm"); - GstStructure *props = gst_structure_from_string(role_str.c_str(), nullptr); + auto role_str = g_strdup_printf("props,media.role=%s", self->m_role.c_str()); + GstStructure *props = gst_structure_from_string(role_str, nullptr); g_object_set(audio_sink, "stream-properties", props, nullptr); gst_structure_free(props); + g_free(role_str); } gst_object_unref(audio_sink); } @@ -138,6 +141,7 @@ private: **** ***/ + const std::string m_role; const std::string m_uri; const unsigned int m_volume; const bool m_loop; @@ -145,8 +149,8 @@ private: GstElement* m_play = nullptr; }; -Sound::Sound(const std::string& uri, unsigned int volume, bool loop): - impl (new Impl(uri, volume, loop)) +Sound::Sound(const std::string& role, const std::string& uri, unsigned int volume, bool loop): + impl (new Impl(role, uri, volume, loop)) { } -- cgit v1.2.3 From 12c742122d34578b23da54d49d4ae1b9bb6af87e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 21 Jan 2015 19:58:46 -0600 Subject: in Snap's Sound() ctor, use an 'alarm' role for the alarm clock and 'alert' for calendar events --- src/snap.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index ea14f30..e655d2d 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -95,10 +95,11 @@ public: std::shared_ptr sound; if (appointment.is_ubuntu_alarm() || !silent_mode()) { // create the sound. + const auto role = appointment.is_ubuntu_alarm() ? "alarm" : "alert"; const auto uri = get_alarm_uri(appointment, m_settings); const auto volume = m_settings->alarm_volume.get(); const bool loop = interactive; - sound = std::make_shared(uri, volume, loop); + sound = std::make_shared(role, uri, volume, loop); } // create the haptic feedback... -- cgit v1.2.3