sound object will be released in passive mode.
Change-Id: I101cba28f0df5accd25cab669984f45fbe311bc9
#include "NavigationInterface.hpp"
#include "RowScanner.hpp"
#include "ScanningProperties.hpp"
-#include "Sound.hpp"
+#include "SoundFeedback.hpp"
#include "TextToSpeech.hpp"
#include "UniversalSwitch.hpp"
#include "UniversalSwitchLog.hpp"
auto uiElem = std::make_shared<UIElement>(std::move(elem));
Singleton<UniversalSwitch>::instance().getTextToSpeech()->speak(std::move(uiElem));
}
- Sound::playSoundFeedback(Sound::ID::NAVIGATION_ITERATED);
+ Singleton<UniversalSwitch>::instance().getSoundFeedback()->play(SoundFeedback::Sound::NAVIGATION_ITERATED);
}
static const std::string BACK_BUTTON_CODE = "XF86Back";
#include "ScreenScannerManager.hpp"
#include "UniversalSwitchLog.hpp"
#include "Window.hpp"
-#include "Sound.hpp"
+#include "SoundFeedback.hpp"
#include "TextToSpeech.hpp"
#include "UniversalSwitch.hpp"
{
DEBUG("Context changed callback invoked");
stopAutoscanning();
- Sound::playSoundFeedback(Sound::ID::NAVIGATION_CONTEXT_CHANGED);
+ Singleton<UniversalSwitch>::instance().getSoundFeedback()->play(SoundFeedback::Sound::NAVIGATION_CONTEXT_CHANGED);
mainWindow->bringToFront();
if (!obj) {
+++ /dev/null
-/*
- * Copyright 2017 Samsung Electronics Co., Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Sound.hpp"
-#include "UniversalSwitchLog.hpp"
-#include "VConf.hpp"
-#include "VConfKeys.hpp"
-
-#include <player.h>
-
-#include <memory>
-#include <unordered_map>
-#include <vector>
-
-static constexpr double DEFAULT_VOLUME_COEFFICIENT = 1.0;
-
-class SoundProperties
-{
-public:
- SoundProperties()
- {
- callbackHandles.push_back(Singleton<VConfInterface>::instance().registerAndGet<bool>(VCONF_KEY_FEEDBACK_SOUND_ENABLED, false,
- [this](auto state) {
- this->setCachedFeedbackEnabled(state);
- }));
-
- callbackHandles.push_back(Singleton<VConfInterface>::instance().registerAndGet<double>(VCONF_KEY_FEEDBACK_SOUND_VOLUME, DEFAULT_VOLUME_COEFFICIENT,
- [this](auto volumeCoefficient) {
- this->setVolumeCoefficient(volumeCoefficient);
- }));
- }
-
- bool isFeedbackEnabled() const
- {
- return feedbackEnabled;
- }
-
- double getVolumeCoefficient() const
- {
- return volumeCoefficient;
- }
-
-private:
- void setCachedFeedbackEnabled(bool state)
- {
- feedbackEnabled = state;
- DEBUG("isFeedbackEnabled: %s", (feedbackEnabled ? "enabled" : "disabled"));
- }
-
- void setVolumeCoefficient(double value)
- {
- volumeCoefficient = value;
- DEBUG("volumeCoefficient: %lf", volumeCoefficient);
- }
-
- std::vector<VConfInterface::CallbackHandle> callbackHandles;
-
- bool feedbackEnabled = false;
- double volumeCoefficient = DEFAULT_VOLUME_COEFFICIENT;
-};
-
-namespace
-{
- static const std::unordered_map<Sound::ID, const char *> soundPaths = {
- {Sound::ID::NAVIGATION_ITERATED, SOUNDS_DIR "navigation_iterated.ogg"},
- {Sound::ID::NAVIGATION_CONTEXT_CHANGED, SOUNDS_DIR "navigation_context_changed.ogg"},
- };
-
- void shutdownAndDestroyPlayer(player_h *player)
- {
- if (player_stop(*player) != PLAYER_ERROR_NONE)
- DEBUG("Error when stopping player");
-
- if (player_unprepare(*player) != PLAYER_ERROR_NONE)
- DEBUG("Error when shutting down player");
-
- if (player_destroy(*player) != PLAYER_ERROR_NONE)
- ERROR("Error when destroying player");
-
- delete player;
- }
-
- using PlayerUniquePtr = std::unique_ptr<player_h, void (*)(player_h *player)>;
- PlayerUniquePtr createPlayer()
- {
- PlayerUniquePtr player {new player_h, shutdownAndDestroyPlayer};
-
- if (player_create(player.get()) != PLAYER_ERROR_NONE)
- ERROR("Error on player_create");
- if (player_set_sound_type(*player.get(), SOUND_TYPE_MEDIA) != PLAYER_ERROR_NONE)
- ERROR("Error on player_set_sound_type");
-
- return player;
- }
-}
-
-void Sound::playSoundFeedback(ID id)
-{
- if (!Singleton<SoundProperties>::instance().isFeedbackEnabled())
- return;
-
- static auto playerPtr = createPlayer();
- auto &player = *playerPtr.get();
-
- player_state_e state;
- player_get_state(player, &state);
- if (state == PLAYER_STATE_PLAYING || state == PLAYER_STATE_PAUSED)
- player_unprepare(player);
-
- auto volumeCoefficient = Singleton<SoundProperties>::instance().getVolumeCoefficient();
- if (player_set_volume(player, volumeCoefficient, volumeCoefficient) != PLAYER_ERROR_NONE)
- ERROR("Error when setting volumeCoefficient");
- if (player_set_uri(player, soundPaths.at(id)) != PLAYER_ERROR_NONE)
- ERROR("Error when setting sound path");
- if (player_prepare(player) != PLAYER_ERROR_NONE)
- ERROR("Error when preparing player!");
- if (player_start(player) != PLAYER_ERROR_NONE)
- ERROR("Player do not started");
-}
--- /dev/null
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SoundFeedback.hpp"
+#include "UniversalSwitchLog.hpp"
+#include "VConfKeys.hpp"
+#include "utils.hpp"
+
+static constexpr double DEFAULT_VOLUME_COEFFICIENT = 1.0;
+
+SoundFeedback::SoundFeedback()
+ : player(), feedbackEnabled(false), volumeCoefficient(DEFAULT_VOLUME_COEFFICIENT)
+{
+ DEBUG("SoundFeedback class construction");
+
+ feedbackEnabledCallbackHandle = Singleton<VConfInterface>::instance().registerAndGet<bool>(VCONF_KEY_FEEDBACK_SOUND_ENABLED, false,
+ [this](auto state) {
+ feedbackEnabled = state;
+ });
+
+ volumeCoefficientCallbackHandle = Singleton<VConfInterface>::instance().registerAndGet<double>(VCONF_KEY_FEEDBACK_SOUND_VOLUME, DEFAULT_VOLUME_COEFFICIENT,
+ [this](auto value) {
+ volumeCoefficient = value;
+ });
+
+ auto error = player_create(&player);
+ if (error != PLAYER_ERROR_NONE) {
+ player = nullptr;
+ ERROR("player_create fail");
+ return;
+ }
+ error = player_set_sound_type(player, SOUND_TYPE_MEDIA);
+ if (error == PLAYER_ERROR_NONE)
+ return;
+
+ player_destroy(player);
+ player = nullptr;
+ ERROR("player_set_sound_stream_info fail");
+}
+
+SoundFeedback::~SoundFeedback()
+{
+ DEBUG("SoundFeedback class destruction");
+ int error;
+ if (feedbackEnabled) {
+ error = player_stop(player);
+ PRINT_ERROR_IF(error != PLAYER_ERROR_NONE);
+
+ error = player_unprepare(player);
+ PRINT_ERROR_IF(error != PLAYER_ERROR_NONE);
+ }
+
+ error = player_destroy(player);
+ PRINT_ERROR_IF(error != PLAYER_ERROR_NONE);
+}
+
+void SoundFeedback::play(Sound sound)
+{
+ RETURN_IF(!player);
+ if (!feedbackEnabled)
+ return;
+
+ player_state_e state;
+ auto error = player_get_state(player, &state);
+ RETURN_IF(error != PLAYER_ERROR_NONE);
+ if (state == PLAYER_STATE_PLAYING || state == PLAYER_STATE_PAUSED) {
+ error = player_unprepare(player);
+ RETURN_IF(error != PLAYER_ERROR_NONE);
+ }
+
+ error = player_set_volume(player, volumeCoefficient, volumeCoefficient);
+ RETURN_IF(error != PLAYER_ERROR_NONE);
+
+ error = player_set_uri(player, getSoundPath(sound).c_str());
+ RETURN_IF(error != PLAYER_ERROR_NONE);
+
+ error = player_prepare(player);
+ RETURN_IF(error != PLAYER_ERROR_NONE);
+
+ error = player_start(player);
+ PRINT_ERROR_IF(error != PLAYER_ERROR_NONE);
+}
+
+std::string SoundFeedback::getSoundPath(Sound sound) const
+{
+ switch (sound) {
+ case Sound::NAVIGATION_ITERATED:
+ return SOUNDS_DIR "navigation_iterated.ogg";
+ case Sound::NAVIGATION_CONTEXT_CHANGED:
+ return SOUNDS_DIR "navigation_context_changed.ogg";
+ }
+
+ ASSERT(0, "Should not be reached");
+ return {};
+}
* limitations under the License.
*/
-#ifndef SOUND_HPP
-#define SOUND_HPP
+#ifndef SOUND_FEEDBACK_HPP
+#define SOUND_FEEDBACK_HPP
-class Sound
+#include "VConf.hpp"
+#include <player.h>
+#include <vector>
+
+
+class SoundFeedback
{
public:
- enum class ID {
- NAVIGATION_ITERATED, NAVIGATION_CONTEXT_CHANGED
+ enum class Sound {
+ NAVIGATION_ITERATED,
+ NAVIGATION_CONTEXT_CHANGED
};
- static void playSoundFeedback(ID id);
+ SoundFeedback();
+ ~SoundFeedback();
+
+ void play(Sound sound);
+
+private:
+ std::string getSoundPath(Sound sound) const;
+
+ player_h player;
+ VConfInterface::CallbackHandle feedbackEnabledCallbackHandle;
+ VConfInterface::CallbackHandle volumeCoefficientCallbackHandle;
+ bool feedbackEnabled;
+ double volumeCoefficient;
};
#endif
#include "DBusInterface.hpp"
#include "ScreenScannerManager.hpp"
#include "ScreenSwitchProvider.hpp"
+#include "SoundFeedback.hpp"
#include "SQLiteConfiguration.hpp"
#include "SwitchConfigurationItem.hpp"
#include "SwitchManager.hpp"
switchManager = SwitchManager::create<SwitchManager>(compositeSwitchProvider, configuration, activityFactory);
textToSpeech = std::make_shared<TextToSpeech>();
+ soundFeedback = std::make_shared<SoundFeedback>();
screenScannerManager = std::make_shared<ScreenScannerManager>();
screenScannerManager->startAutoscanning();
{
DEBUG("Universal-switch passive mode");
screenScannerManager.reset();
+ soundFeedback.reset();
+ textToSpeech.reset();
if (switchManager) {
switchManager->terminate();
switchManager.reset();
}
- textToSpeech.reset();
navigationInterface.reset();
atspi.reset();
}
return textToSpeech;
}
+std::shared_ptr<SoundFeedback> UniversalSwitch::getSoundFeedback() const
+{
+ return soundFeedback;
+}
+
void UniversalSwitch::setSwitchManager(const std::shared_ptr<SwitchManager> &sm)
{
switchManager = sm;
class Window;
class NavigationInterface;
class ScrollActivitiesData;
+class SoundFeedback;
class UniversalSwitch
std::shared_ptr<Atspi> getAtspi() const;
std::shared_ptr<Window> getMainWindow();
std::shared_ptr<TextToSpeech> getTextToSpeech() const;
+ std::shared_ptr<SoundFeedback> getSoundFeedback() const;
std::shared_ptr<NavigationInterface> getNavigationInterface() const;
std::shared_ptr<ScrollActivitiesData> getScrollActivitiesData() const;
void setScrollActivitiesData(std::shared_ptr<ScrollActivitiesData>);
std::shared_ptr<Atspi> atspi;
std::shared_ptr<NavigationInterface> navigationInterface;
std::shared_ptr<TextToSpeech> textToSpeech;
+ std::shared_ptr<SoundFeedback> soundFeedback;
std::shared_ptr<ScreenScannerManager> screenScannerManager;
std::weak_ptr<Window> mainWindow;