Add system, ringtone, notification volume at media plugin
authorJinWang An <jinwang.an@samsung.com>
Mon, 25 Nov 2019 01:02:03 +0000 (10:02 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 19 Mar 2020 04:30:37 +0000 (13:30 +0900)
media/MediaFactory.cpp
media/MediaFactory.h
media/MediaVolume.cpp [deleted file]
media/MediaVolume.h [deleted file]
media/SoundVolume.cpp [new file with mode: 0644]
media/SoundVolume.h [new file with mode: 0644]
media/tizen_media_rule.xml
unittests/mdsp_test_media.cpp

index a54aa109cf108c1918909c4f599080b0e1e20e1b..58ce47954c0bbb664414a3b2d2a2ff599e5d3438 100644 (file)
 #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;
index 2e76df3b8f4982217c6d0668472ca0be6f7553c4..c7c01cec58197424f4fd3bb42c1a9f9627225609 100644 (file)
@@ -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<std::string, enum actionKey> actionMap;
diff --git a/media/MediaVolume.cpp b/media/MediaVolume.cpp
deleted file mode 100644 (file)
index ed2725f..0000000
+++ /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 <string>
-#include <sstream>
-#include <modes_errors.h>
-#include <player.h>
-#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 (file)
index b9da085..0000000
+++ /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 <string>
-#include <sound_manager.h>
-#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 (file)
index 0000000..960cc9c
--- /dev/null
@@ -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 <string>
+#include <sstream>
+#include <modes_errors.h>
+#include <player.h>
+#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 (file)
index 0000000..86406c7
--- /dev/null
@@ -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 <string>
+#include <sound_manager.h>
+#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
index e796bce2157bf81c17ba4848de7b9ace6e3eee3b..747bd49d5d04f2f67ee15e93518cfb4cdf83ca49 100644 (file)
@@ -5,10 +5,25 @@
       <desc>Audio/Video player</desc>
       <domain>Multimedia</domain>
     </rule>
-    <rule name="media.volume" type="int" since="6.0" plugin="media">
+    <rule name="media.mediaVolume" type="int" since="6.0" plugin="media">
       <alias name="MEDIA_MUTE">0</alias>
       <desc>Media volume</desc>
       <domain>Multimedia</domain>
     </rule>
+    <rule name="media.systemVolume" type="int" since="6.0" plugin="media">
+      <alias name="SYSTEM_MUTE">0</alias>
+      <desc>System volume</desc>
+      <domain>Multimedia</domain>
+    </rule>
+    <rule name="media.ringtoneVolume" type="int" since="6.0" plugin="media">
+      <alias name="RINGTONE_MUTE">0</alias>
+      <desc>Ringtone volume</desc>
+      <domain>Multimedia</domain>
+    </rule>
+    <rule name="media.notificationVolume" type="int" since="6.0" plugin="media">
+      <alias name="NOTIFICATION_MUTE">0</alias>
+      <desc>Notification volume</desc>
+      <domain>Multimedia</domain>
+    </rule>
   </actionRule>
 </tizenModes>
index 89073ee82c59f9af95490757049dd26a734a24df..b30ed8e9bc9e0938fc2fd152a22275edddad45f0 100644 (file)
@@ -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);
 }