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_TONE_H
17#define TELEPHONY_AUDIO_TONE_H
18
19#include <memory>
20
21#include "audio_renderer.h"
22
23#include "audio_player.h"
24#include "audio_proxy.h"
25#include "tone_player.h"
26
27namespace OHOS {
28namespace Telephony {
29enum ToneDescriptor {
30    TONE_UNKNOWN = 0,
31    TONE_ENGAGED,
32    TONE_FINISHED,
33    TONE_WAITING,
34    TONE_RINGBACK,
35    TONE_NO_SERVICE,
36    TONE_INVALID_NUMBER,
37    TONE_CALL_RECORDING,
38    TONE_DTMF_CHAR_0,
39    TONE_DTMF_CHAR_1,
40    TONE_DTMF_CHAR_2,
41    TONE_DTMF_CHAR_3,
42    TONE_DTMF_CHAR_4,
43    TONE_DTMF_CHAR_5,
44    TONE_DTMF_CHAR_6,
45    TONE_DTMF_CHAR_7,
46    TONE_DTMF_CHAR_8,
47    TONE_DTMF_CHAR_9,
48    TONE_DTMF_CHAR_P,
49    TONE_DTMF_CHAR_W
50};
51struct ToneStream {
52    ToneDescriptor toneDescriptor = ToneDescriptor::TONE_UNKNOWN;
53    int32_t duration = 0;
54    int32_t volume = 0;
55};
56enum class ToneState {
57    TONEING = 0,
58    STOPPED,
59    CALLENDED
60};
61
62static constexpr const char* TONE_PLAY_THREAD = "tonePlayThread";
63
64/**
65 * @class Tone
66 * plays the specific tone.
67 */
68class Tone {
69public:
70    Tone();
71    explicit Tone(ToneDescriptor tone);
72    virtual ~Tone();
73    void Init();
74    int32_t Play();
75    int32_t Stop();
76    static ToneDescriptor ConvertDigitToTone(char digit);
77    void ReleaseRenderer();
78    ToneDescriptor getCurrentToneType();
79
80private:
81    ToneDescriptor currentToneDescriptor_ = ToneDescriptor::TONE_UNKNOWN;
82    bool InitTonePlayer();
83    AudioStandard::ToneType ConvertToneDescriptorToToneType(ToneDescriptor tone);
84    std::string GetToneDescriptorPath(ToneDescriptor tone);
85    bool IsUseTonePlayer(ToneDescriptor tone);
86    std::mutex mutex_;
87    AudioPlayer *audioPlayer_ = nullptr;
88    std::shared_ptr<AudioStandard::TonePlayer> tonePlayer_;
89    AudioStandard::StreamUsage GetStreamUsageByToneType(ToneDescriptor tone);
90    AudioStandard::ToneType ConvertCallToneDescriptorToToneType(ToneDescriptor tone);
91};
92} // namespace Telephony
93} // namespace OHOS
94#endif // TELEPHONY_AUDIO_TONE_H