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.
14 #ifndef __TTSD_BACKGROUND_VOLUME_H_
15 #define __TTSD_BACKGROUND_VOLUME_H_
23 #include <sound_manager.h>
27 class BackgroundVolume {
29 BackgroundVolume(long long int duckingDuration);
32 void setVolumeRatio(double ratio);
33 double getVolumeRatio();
34 void applyVolumeRatio();
35 void recoverVolumeRatio();
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);
45 bool isDuckingHandleValid();
46 long long int getMsecDurationAfterDucking();
47 sound_stream_ducking_h getStreamDuckingHandle(sound_stream_type_e type);
49 void activateDuckingAll(unsigned int duration, double ratio);
50 bool activateDucking(sound_stream_type_e type, unsigned int duration, double ratio);
51 bool deactivateDuckingAll();
52 bool deactivateDucking(sound_stream_type_e type);
55 const long long int mDuckingDuration;
56 sound_stream_ducking_h mMediaStream;
57 sound_stream_ducking_h mNotificationStream;
58 sound_stream_ducking_h mAlarmStream;
59 std::atomic<double> mVolumeRatio;
60 std::atomic<bool> mVolumeDucked;
62 std::chrono::time_point<std::chrono::steady_clock> mChangeVolumeTime;
63 Ecore_Timer* mPostponedRecoverTimer;
64 Ecore_Timer* mPostponedModifyTimer;
68 #endif /* __TTSD_BACKGROUND_VOLUME_H_ */