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 26 namespace OHOS { 27 namespace Telephony { 28 enum ToneDescriptor { 29 TONE_UNKNOWN = 0, 30 TONE_ENGAGED, 31 TONE_FINISHED, 32 TONE_WAITING, 33 TONE_RINGBACK, 34 TONE_NO_SERVICE, 35 TONE_INVALID_NUMBER, 36 TONE_CALL_RECORDING, 37 TONE_DTMF_CHAR_0, 38 TONE_DTMF_CHAR_1, 39 TONE_DTMF_CHAR_2, 40 TONE_DTMF_CHAR_3, 41 TONE_DTMF_CHAR_4, 42 TONE_DTMF_CHAR_5, 43 TONE_DTMF_CHAR_6, 44 TONE_DTMF_CHAR_7, 45 TONE_DTMF_CHAR_8, 46 TONE_DTMF_CHAR_9, 47 TONE_DTMF_CHAR_P, 48 TONE_DTMF_CHAR_W 49 }; 50 struct ToneStream { 51 ToneDescriptor toneDescriptor; 52 int32_t duration; 53 int32_t volume; 54 }; 55 56 /** 57 * @class Tone 58 * plays the specific tone. 59 */ 60 class Tone { 61 public: 62 Tone(); 63 Tone(ToneDescriptor tone); 64 virtual ~Tone(); 65 void Init(); 66 int32_t Play(); 67 int32_t Stop(); 68 static ToneDescriptor ConvertDigitToTone(char digit); 69 70 private: 71 ToneDescriptor currentToneDescriptor_ = ToneDescriptor::TONE_UNKNOWN; 72 std::string GetToneDescriptorPath(ToneDescriptor tone); 73 bool IsDtmf(ToneDescriptor tone); 74 std::mutex mutex_; 75 }; 76 } // namespace Telephony 77 } // namespace OHOS 78 #endif // TELEPHONY_AUDIO_TONE_H