1e1c44949Sopenharmony_ci/* 2e1c44949Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 3e1c44949Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e1c44949Sopenharmony_ci * you may not use this file except in compliance with the License. 5e1c44949Sopenharmony_ci * You may obtain a copy of the License at 6e1c44949Sopenharmony_ci * 7e1c44949Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e1c44949Sopenharmony_ci * 9e1c44949Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e1c44949Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e1c44949Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e1c44949Sopenharmony_ci * See the License for the specific language governing permissions and 13e1c44949Sopenharmony_ci * limitations under the License. 14e1c44949Sopenharmony_ci */ 15e1c44949Sopenharmony_ci 16e1c44949Sopenharmony_ci#ifndef TELEPHONY_AUDIO_TONE_H 17e1c44949Sopenharmony_ci#define TELEPHONY_AUDIO_TONE_H 18e1c44949Sopenharmony_ci 19e1c44949Sopenharmony_ci#include <memory> 20e1c44949Sopenharmony_ci 21e1c44949Sopenharmony_ci#include "audio_renderer.h" 22e1c44949Sopenharmony_ci 23e1c44949Sopenharmony_ci#include "audio_player.h" 24e1c44949Sopenharmony_ci#include "audio_proxy.h" 25e1c44949Sopenharmony_ci#include "tone_player.h" 26e1c44949Sopenharmony_ci 27e1c44949Sopenharmony_cinamespace OHOS { 28e1c44949Sopenharmony_cinamespace Telephony { 29e1c44949Sopenharmony_cienum ToneDescriptor { 30e1c44949Sopenharmony_ci TONE_UNKNOWN = 0, 31e1c44949Sopenharmony_ci TONE_ENGAGED, 32e1c44949Sopenharmony_ci TONE_FINISHED, 33e1c44949Sopenharmony_ci TONE_WAITING, 34e1c44949Sopenharmony_ci TONE_RINGBACK, 35e1c44949Sopenharmony_ci TONE_NO_SERVICE, 36e1c44949Sopenharmony_ci TONE_INVALID_NUMBER, 37e1c44949Sopenharmony_ci TONE_CALL_RECORDING, 38e1c44949Sopenharmony_ci TONE_DTMF_CHAR_0, 39e1c44949Sopenharmony_ci TONE_DTMF_CHAR_1, 40e1c44949Sopenharmony_ci TONE_DTMF_CHAR_2, 41e1c44949Sopenharmony_ci TONE_DTMF_CHAR_3, 42e1c44949Sopenharmony_ci TONE_DTMF_CHAR_4, 43e1c44949Sopenharmony_ci TONE_DTMF_CHAR_5, 44e1c44949Sopenharmony_ci TONE_DTMF_CHAR_6, 45e1c44949Sopenharmony_ci TONE_DTMF_CHAR_7, 46e1c44949Sopenharmony_ci TONE_DTMF_CHAR_8, 47e1c44949Sopenharmony_ci TONE_DTMF_CHAR_9, 48e1c44949Sopenharmony_ci TONE_DTMF_CHAR_P, 49e1c44949Sopenharmony_ci TONE_DTMF_CHAR_W 50e1c44949Sopenharmony_ci}; 51e1c44949Sopenharmony_cistruct ToneStream { 52e1c44949Sopenharmony_ci ToneDescriptor toneDescriptor = ToneDescriptor::TONE_UNKNOWN; 53e1c44949Sopenharmony_ci int32_t duration = 0; 54e1c44949Sopenharmony_ci int32_t volume = 0; 55e1c44949Sopenharmony_ci}; 56e1c44949Sopenharmony_cienum class ToneState { 57e1c44949Sopenharmony_ci TONEING = 0, 58e1c44949Sopenharmony_ci STOPPED, 59e1c44949Sopenharmony_ci CALLENDED 60e1c44949Sopenharmony_ci}; 61e1c44949Sopenharmony_ci 62e1c44949Sopenharmony_cistatic constexpr const char* TONE_PLAY_THREAD = "tonePlayThread"; 63e1c44949Sopenharmony_ci 64e1c44949Sopenharmony_ci/** 65e1c44949Sopenharmony_ci * @class Tone 66e1c44949Sopenharmony_ci * plays the specific tone. 67e1c44949Sopenharmony_ci */ 68e1c44949Sopenharmony_ciclass Tone { 69e1c44949Sopenharmony_cipublic: 70e1c44949Sopenharmony_ci Tone(); 71e1c44949Sopenharmony_ci explicit Tone(ToneDescriptor tone); 72e1c44949Sopenharmony_ci virtual ~Tone(); 73e1c44949Sopenharmony_ci void Init(); 74e1c44949Sopenharmony_ci int32_t Play(); 75e1c44949Sopenharmony_ci int32_t Stop(); 76e1c44949Sopenharmony_ci static ToneDescriptor ConvertDigitToTone(char digit); 77e1c44949Sopenharmony_ci void ReleaseRenderer(); 78e1c44949Sopenharmony_ci ToneDescriptor getCurrentToneType(); 79e1c44949Sopenharmony_ci 80e1c44949Sopenharmony_ciprivate: 81e1c44949Sopenharmony_ci ToneDescriptor currentToneDescriptor_ = ToneDescriptor::TONE_UNKNOWN; 82e1c44949Sopenharmony_ci bool InitTonePlayer(); 83e1c44949Sopenharmony_ci AudioStandard::ToneType ConvertToneDescriptorToToneType(ToneDescriptor tone); 84e1c44949Sopenharmony_ci std::string GetToneDescriptorPath(ToneDescriptor tone); 85e1c44949Sopenharmony_ci bool IsUseTonePlayer(ToneDescriptor tone); 86e1c44949Sopenharmony_ci std::mutex mutex_; 87e1c44949Sopenharmony_ci AudioPlayer *audioPlayer_ = nullptr; 88e1c44949Sopenharmony_ci std::shared_ptr<AudioStandard::TonePlayer> tonePlayer_; 89e1c44949Sopenharmony_ci AudioStandard::StreamUsage GetStreamUsageByToneType(ToneDescriptor tone); 90e1c44949Sopenharmony_ci AudioStandard::ToneType ConvertCallToneDescriptorToToneType(ToneDescriptor tone); 91e1c44949Sopenharmony_ci}; 92e1c44949Sopenharmony_ci} // namespace Telephony 93e1c44949Sopenharmony_ci} // namespace OHOS 94e1c44949Sopenharmony_ci#endif // TELEPHONY_AUDIO_TONE_H