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 27 namespace OHOS { 28 namespace Telephony { 29 enum 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 }; 51 struct ToneStream { 52 ToneDescriptor toneDescriptor = ToneDescriptor::TONE_UNKNOWN; 53 int32_t duration = 0; 54 int32_t volume = 0; 55 }; 56 enum class ToneState { 57 TONEING = 0, 58 STOPPED, 59 }; 60 61 static constexpr const char* TONE_PLAY_THREAD = "tonePlayThread"; 62 63 /** 64 * @class Tone 65 * plays the specific tone. 66 */ 67 class Tone { 68 public: 69 Tone(); 70 explicit Tone(ToneDescriptor tone); 71 virtual ~Tone(); 72 void Init(); 73 int32_t Play(); 74 int32_t Stop(); 75 static ToneDescriptor ConvertDigitToTone(char digit); 76 void ReleaseRenderer(); 77 78 private: 79 ToneDescriptor currentToneDescriptor_ = ToneDescriptor::TONE_UNKNOWN; 80 bool InitTonePlayer(); 81 AudioStandard::ToneType ConvertToneDescriptorToToneType(ToneDescriptor tone); 82 std::string GetToneDescriptorPath(ToneDescriptor tone); 83 bool IsDtmf(ToneDescriptor tone); 84 std::mutex mutex_; 85 AudioPlayer *audioPlayer_ = nullptr; 86 std::shared_ptr<AudioStandard::TonePlayer> dtmfTonePlayer_; 87 }; 88 } // namespace Telephony 89 } // namespace OHOS 90 #endif // TELEPHONY_AUDIO_TONE_H