Merge "Add error type for converting string" into tizen
[platform/core/uifw/tts.git] / server / BackgroundVolume.h
1 /*
2 *  Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3 *  Licensed under the Apache License, Version 2.0 (the "License");
4 *  you may not use this file except in compliance with the License.
5 *  You may obtain a copy of the License at
6 *  http://www.apache.org/licenses/LICENSE-2.0
7 *  Unless required by applicable law or agreed to in writing, software
8 *  distributed under the License is distributed on an "AS IS" BASIS,
9 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 *  See the License for the specific language governing permissions and
11 *  limitations under the License.
12 */
13
14 #ifndef __TTSD_BACKGROUND_VOLUME_H_
15 #define __TTSD_BACKGROUND_VOLUME_H_
16
17
18 #include <mutex>
19 #include <chrono>
20 #include <atomic>
21 #include <Ecore.h>
22
23 #include <sound_manager.h>
24
25 #include "ttse.h"
26
27 class BackgroundVolume {
28 public:
29         BackgroundVolume(long long int duckingDuration);
30         ~BackgroundVolume();
31
32         void setVolumeRatio(double ratio);
33         double getVolumeRatio();
34         void applyVolumeRatio();
35         void recoverVolumeRatio();
36
37 private:
38         static void changeVolumeOnMainThread(void* data);
39         static void modifyVolumeOnMainThread(void* data);
40         static void recoverVolumeOnMainThread(void* data);
41         static Eina_Bool postponedRecoverTimerCb(void* data);
42         static Eina_Bool postponedModifyTimerCb(void* data);
43
44         long long int getDurationAfterDucking();
45         sound_stream_ducking_h getStreamDuckingHandle(sound_stream_type_e type);
46
47         void activateDuckingAll(unsigned int duration, double ratio);
48         bool activateDucking(sound_stream_type_e type, unsigned int duration, double ratio);
49         void deactivateDuckingAll();
50         void deactivateDucking(sound_stream_type_e type);
51
52 private:
53         const long long int __duckingDuration;
54         sound_stream_ducking_h __mediaStream;
55         sound_stream_ducking_h __notificationStream;
56         sound_stream_ducking_h __alarmStream;
57         std::atomic<double> __volumeRatio;
58         std::atomic<bool> __isVolumeDucked;
59
60         std::chrono::time_point<std::chrono::steady_clock> __changeVolumeTime;
61         Ecore_Timer* __postponedRecoverTimer;
62         Ecore_Timer* __postponedModifyTimer;
63 };
64
65
66 #endif /* __TTSD_BACKGROUND_VOLUME_H_ */