• 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 
26 namespace OHOS {
27 namespace Telephony {
28 struct RingtoneStream {
29     std::string ringtonePath = "";
30     uint32_t playedPosition = 0;
31 };
32 enum class RingState {
33     RINGING = 0,
34     STOPPED,
35 };
36 
37 static constexpr const char* RING_PLAY_THREAD = "ringPlayThread";
38 
39 /**
40  * @class Ring
41  * plays the default or specific ringtone.
42  */
43 class Ring {
44 public:
45     Ring();
46     explicit Ring(const std::string &path);
47     virtual ~Ring();
48     void Init(const std::string &ringtonePath);
49     int32_t Play();
50     int32_t Stop();
51     int32_t StartVibrate();
52     int32_t CancelVibrate();
53     void ReleaseRenderer();
54 
55 private:
56     bool isVibrating_;
57     bool shouldRing_;
58     bool shouldVibrate_;
59     bool ShouldVibrate();
60     std::string ringtonePath_;
61     std::mutex mutex_;
62     AudioPlayer *audioPlayer_ = nullptr;
63 };
64 } // namespace Telephony
65 } // namespace OHOS
66 #endif // TELEPHONY_AUDIO_RING_H