From: JinWang An Date: Mon, 25 Nov 2019 01:02:03 +0000 (+0900) Subject: Add system, ringtone, notification volume at media plugin X-Git-Tag: submit/tizen/20200406.072014~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=312f264a89108267c6f074da20b37027c27884ac;p=platform%2Fcore%2Fsystem%2Fmodes-plugins.git Add system, ringtone, notification volume at media plugin --- diff --git a/media/MediaFactory.cpp b/media/MediaFactory.cpp index a54aa10..58ce479 100644 --- a/media/MediaFactory.cpp +++ b/media/MediaFactory.cpp @@ -16,14 +16,17 @@ #include "MediaFactory.h" #include "plugin-log.h" #include "MediaPlayer.h" -#include "MediaVolume.h" +#include "SoundVolume.h" MODES_NAMESPACE_USE; MediaFactory::MediaFactory() { actionMap[MediaPlayer::NAME] = PLAYER; - actionMap[MediaVolume::NAME] = VOLUME; + actionMap[SoundVolume::NAME[MEDIA_VOLUME]] = MEDIA_VOLUME; + actionMap[SoundVolume::NAME[SYSTEM_VOLUME]] = SYSTEM_VOLUME; + actionMap[SoundVolume::NAME[RINGTONE_VOLUME]] = RINGTONE_VOLUME; + actionMap[SoundVolume::NAME[NOTIFICATION_VOLUME]] = NOTIFICATION_VOLUME; } MediaAction* MediaFactory::createAction(const std::string &key) @@ -39,8 +42,17 @@ MediaAction* MediaFactory::createAction(const std::string &key) case PLAYER: action = new MediaPlayer(); break; - case VOLUME: - action = new MediaVolume(); + case MEDIA_VOLUME: + action = new SoundVolume(MEDIA_VOLUME, SOUND_TYPE_MEDIA); + break; + case SYSTEM_VOLUME: + action = new SoundVolume(SYSTEM_VOLUME, SOUND_TYPE_SYSTEM); + break; + case RINGTONE_VOLUME: + action = new SoundVolume(RINGTONE_VOLUME, SOUND_TYPE_RINGTONE); + break; + case NOTIFICATION_VOLUME: + action = new SoundVolume(NOTIFICATION_VOLUME, SOUND_TYPE_NOTIFICATION); break; default: action = nullptr; diff --git a/media/MediaFactory.h b/media/MediaFactory.h index 2e76df3..c7c01ce 100644 --- a/media/MediaFactory.h +++ b/media/MediaFactory.h @@ -30,8 +30,11 @@ public: void destroyAction(MediaAction *action); private: enum actionKey{ - PLAYER, - VOLUME + MEDIA_VOLUME, + SYSTEM_VOLUME, + RINGTONE_VOLUME, + NOTIFICATION_VOLUME, + PLAYER }; std::map actionMap; diff --git a/media/MediaVolume.cpp b/media/MediaVolume.cpp deleted file mode 100644 index ed2725f..0000000 --- a/media/MediaVolume.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 "MediaVolume.h" -#include -#include -#include -#include -#include "plugin-log.h" - -MODES_NAMESPACE_USE; - -const std::string MediaVolume::NAME = "volume"; - -MediaVolume::MediaVolume() - : MediaAction(NAME), oldVal(-1), volumeCallbackID(0), cb(NULL), cbData(NULL), requestVal(-1) -{ -} - -void MediaVolume::volumeChangedCB(sound_type_e type, unsigned int volume, void *user_data) -{ - MediaVolume *action = (MediaVolume*)user_data; - RET_IF(NULL == user_data); - - if (action->requestVal != (int)volume) - action->cb(action->cbData); -} - -int MediaVolume::set(int val) -{ - requestVal = val; - int ret = sound_manager_get_volume(SOUND_TYPE_MEDIA, &oldVal); - if (SOUND_MANAGER_ERROR_NONE != ret) { - ERR("sound_manager_get_volume() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - - if (val == oldVal) { - INFO("Already media volume is [%d]", val); - return MODES_ERROR_NONE; - } - - ret = sound_manager_set_volume(SOUND_TYPE_MEDIA, val); - if (SOUND_MANAGER_ERROR_NONE != ret) { - ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - - return MODES_ERROR_NONE; -} - -void MediaVolume::undo() -{ - int ret = sound_manager_set_volume(SOUND_TYPE_MEDIA, oldVal); - if (SOUND_MANAGER_ERROR_NONE != ret) { - ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret)); - } -} - -std::string MediaVolume::serialize() -{ - std::ostringstream ostr; - - ostr << oldVal; - return ostr.str(); -} - -int MediaVolume::parse(const std::string &archive) -{ - std::istringstream iss(archive); - iss >> oldVal; - - return MODES_ERROR_NONE; -} - -int MediaVolume::setChangedCallback(valueChangedCB callback, void *userData) -{ - int ret = sound_manager_add_volume_changed_cb(volumeChangedCB, this, &volumeCallbackID); - if (SOUND_MANAGER_ERROR_NONE != ret) { - ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - cb = callback; - cbData = userData; - return MODES_ERROR_NONE; -} - -void MediaVolume::unSetChangedCallback(valueChangedCB callback, void *userData) -{ - int ret = sound_manager_remove_volume_changed_cb(volumeCallbackID); - if (SOUND_MANAGER_ERROR_NONE != ret) { - ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret)); - } - cb = NULL; - cbData = NULL; -} diff --git a/media/MediaVolume.h b/media/MediaVolume.h deleted file mode 100644 index b9da085..0000000 --- a/media/MediaVolume.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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. - */ -#pragma once - -#include -#include -#include "plugin-def.h" -#include "MediaAction.h" - -MODES_NAMESPACE_BEGIN - -class MediaVolume : public MediaAction { -public: - static const std::string NAME; - MediaVolume(); - ~MediaVolume() = default; - - int set(int val) override; - void undo() override; - std::string serialize() override; - int parse(const std::string &archive) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback, void *userData) override; - -private: - static void volumeChangedCB(sound_type_e type, unsigned int volume, void *user_data); - int oldVal; - int volumeCallbackID; - valueChangedCB cb; - void *cbData; - int requestVal; -}; - -MODES_NAMESPACE_END diff --git a/media/SoundVolume.cpp b/media/SoundVolume.cpp new file mode 100644 index 0000000..960cc9c --- /dev/null +++ b/media/SoundVolume.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "SoundVolume.h" +#include +#include +#include +#include +#include "plugin-log.h" + +MODES_NAMESPACE_USE; + +// It should align with actionKey in MediaFactory +const std::string SoundVolume::NAME[4] = { + "mediaVolume", + "systemVolume", + "ringtoneVolume", + "notificationVolume" +}; + +SoundVolume::SoundVolume(int key, sound_type_e soundType) + : MediaAction(NAME[key]), oldVal(-1), volumeCallbackID(0), cb(NULL), cbData(NULL), requestVal(-1), type(soundType) +{ +} + +void SoundVolume::volumeChangedCB(sound_type_e type, unsigned int volume, void *user_data) +{ + SoundVolume *action = (SoundVolume*)user_data; + RET_IF(NULL == user_data); + + if (action->requestVal != (int)volume) + action->cb(action->cbData); +} + +int SoundVolume::set(int val) +{ + requestVal = val; + int ret = sound_manager_get_volume(type, &oldVal); + if (SOUND_MANAGER_ERROR_NONE != ret) { + ERR("sound_manager_get_volume() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + + if (val == oldVal) { + INFO("Already media volume is [%d]", val); + return MODES_ERROR_NONE; + } + + ret = sound_manager_set_volume(type, val); + if (SOUND_MANAGER_ERROR_NONE != ret) { + ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + + return MODES_ERROR_NONE; +} + +void SoundVolume::undo() +{ + int ret = sound_manager_set_volume(type, oldVal); + if (SOUND_MANAGER_ERROR_NONE != ret) { + ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret)); + } +} + +std::string SoundVolume::serialize() +{ + std::ostringstream ostr; + + ostr << oldVal; + return ostr.str(); +} + +int SoundVolume::parse(const std::string &archive) +{ + std::istringstream iss(archive); + iss >> oldVal; + + return MODES_ERROR_NONE; +} + +int SoundVolume::setChangedCallback(valueChangedCB callback, void *userData) +{ + int ret = sound_manager_add_volume_changed_cb(volumeChangedCB, this, &volumeCallbackID); + if (SOUND_MANAGER_ERROR_NONE != ret) { + ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + cb = callback; + cbData = userData; + return MODES_ERROR_NONE; +} + +void SoundVolume::unSetChangedCallback(valueChangedCB callback, void *userData) +{ + int ret = sound_manager_remove_volume_changed_cb(volumeCallbackID); + if (SOUND_MANAGER_ERROR_NONE != ret) { + ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret)); + } + cb = NULL; + cbData = NULL; +} diff --git a/media/SoundVolume.h b/media/SoundVolume.h new file mode 100644 index 0000000..86406c7 --- /dev/null +++ b/media/SoundVolume.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +#pragma once + +#include +#include +#include "plugin-def.h" +#include "MediaAction.h" + +MODES_NAMESPACE_BEGIN + +class SoundVolume : public MediaAction { +public: + static const std::string NAME[4]; + SoundVolume(int key, sound_type_e soundType); + ~SoundVolume() = default; + + int set(int val) override; + void undo() override; + std::string serialize() override; + int parse(const std::string &archive) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback, void *userData) override; + +private: + static void volumeChangedCB(sound_type_e type, unsigned int volume, void *user_data); + int oldVal; + int volumeCallbackID; + valueChangedCB cb; + void *cbData; + int requestVal; + sound_type_e type; +}; + +MODES_NAMESPACE_END diff --git a/media/tizen_media_rule.xml b/media/tizen_media_rule.xml index e796bce..747bd49 100644 --- a/media/tizen_media_rule.xml +++ b/media/tizen_media_rule.xml @@ -5,10 +5,25 @@ Audio/Video player Multimedia - + 0 Media volume Multimedia + + 0 + System volume + Multimedia + + + 0 + Ringtone volume + Multimedia + + + 0 + Notification volume + Multimedia + diff --git a/unittests/mdsp_test_media.cpp b/unittests/mdsp_test_media.cpp index 89073ee..b30ed8e 100644 --- a/unittests/mdsp_test_media.cpp +++ b/unittests/mdsp_test_media.cpp @@ -66,12 +66,23 @@ protected: return G_SOURCE_REMOVE; } - static gboolean mediaVolumeSetUndoIdler(gpointer data) + static gboolean VolumeSetUndoIdler(gpointer data) { PluginAction *action; - result = plugin->set("volume", 5, &action); + result = plugin->set("mediaVolume", 5, &action); EXPECT_EQ(MODES_ERROR_NONE, result); + plugin->undo(action); + + result = plugin->set("systemVolume", 2, &action); + EXPECT_EQ(MODES_ERROR_NONE, result); + plugin->undo(action); + result = plugin->set("ringtoneVolume", 9, &action); + EXPECT_EQ(MODES_ERROR_NONE, result); + plugin->undo(action); + + result = plugin->set("notificationVolume", 1, &action); + EXPECT_EQ(MODES_ERROR_NONE, result); plugin->undo(action); g_main_loop_quit(loop); @@ -96,7 +107,7 @@ TEST_F(MediaPluginTest, setUndoMediaPlay) TEST_F(MediaPluginTest, setUndoMediaVolume) { - g_idle_add(mediaVolumeSetUndoIdler, plugin); + g_idle_add(VolumeSetUndoIdler, plugin); g_main_loop_run(loop); }