• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
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  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef TELEPHONY_AUDIO_RING_H
17 #define TELEPHONY_AUDIO_RING_H
18 
19 #include <memory>
20 
21 #include "audio_renderer.h"
22 
23 #include "audio_player.h"
24 #include "audio_proxy.h"
25 #include "ringtone_player.h"
26 #include "system_sound_manager.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 struct RingtoneStream {
31     std::string ringtonePath = "";
32     uint32_t playedPosition = 0;
33 };
34 enum class RingState {
35     RINGING = 0,
36     STOPPED,
37 };
38 
39 static constexpr const char* RING_PLAY_THREAD = "ringPlayThread";
40 
41 /**
42  * @class Ring
43  * plays the default or specific ringtone.
44  */
45 class Ring {
46 public:
47     Ring();
48     explicit Ring(const std::string &path);
49     virtual ~Ring();
50     void Init(const std::string &ringtonePath);
51     int32_t Play(int32_t slotId);
52     int32_t Stop();
53     int32_t StartVibrate();
54     int32_t CancelVibrate();
55     void ReleaseRenderer();
56     int32_t SetMute();
57 
58 private:
59     bool isVibrating_;
60     bool shouldRing_;
61     bool shouldVibrate_;
62     bool ShouldVibrate();
63     std::string ringtonePath_;
64     std::mutex mutex_;
65     AudioPlayer *audioPlayer_ = nullptr;
66     std::shared_ptr<Media::SystemSoundManager> SystemSoundManager_ = nullptr;
67     std::shared_ptr<Media::RingtonePlayer> RingtonePlayer_ = nullptr;
68     int32_t defaultVolume_ = 1;
69 };
70 } // namespace Telephony
71 } // namespace OHOS
72 #endif // TELEPHONY_AUDIO_RING_H