1 /* 2 * Copyright (c) 2021-2022 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 AUDIO_RENDERER_SINK_H 17 #define AUDIO_RENDERER_SINK_H 18 19 #include "audio_info.h" 20 #include "audio_manager.h" 21 #include "audio_sink_callback.h" 22 #include "running_lock.h" 23 24 #include <cstdio> 25 #include <list> 26 27 namespace OHOS { 28 namespace AudioStandard { 29 typedef struct { 30 const char *adapterName; 31 uint32_t openMicSpeaker; 32 AudioFormat format; 33 uint32_t sampleFmt; 34 uint32_t sampleRate; 35 uint32_t channel; 36 float volume; 37 const char *filePath; 38 } AudioSinkAttr; 39 40 class AudioRendererSink { 41 public: 42 int32_t Init(AudioSinkAttr &attr); 43 void DeInit(void); 44 int32_t Flush(void); 45 int32_t Pause(void); 46 int32_t Reset(void); 47 int32_t Resume(void); 48 int32_t Start(void); 49 int32_t Stop(void); 50 int32_t RenderFrame(char &data, uint64_t len, uint64_t &writeLen); 51 int32_t SetVolume(float left, float right); 52 int32_t GetVolume(float &left, float &right); 53 int32_t SetVoiceVolume(float volume); 54 int32_t GetLatency(uint32_t *latency); 55 int32_t GetTransactionId(uint64_t *transactionId); 56 int32_t SetAudioScene(AudioScene audioScene, DeviceType activeDevice); 57 int32_t SetOutputRoute(DeviceType outputDevice, AudioPortPin &outputPortPin); 58 int32_t SetOutputRoute(DeviceType outputDevice); 59 static AudioRendererSink *GetInstance(void); 60 void SetAudioParameter(const AudioParamKey key, const std::string& condition, const std::string& value); 61 std::string GetAudioParameter(const AudioParamKey key, const std::string& condition); 62 void SetAudioMonoState(bool audioMono); 63 void SetAudioBalanceValue(float audioBalance); 64 bool rendererInited_; 65 66 private: 67 AudioRendererSink(); 68 ~AudioRendererSink(); 69 AudioSinkAttr attr_; 70 bool started_; 71 bool paused_; 72 float leftVolume_; 73 float rightVolume_; 74 int32_t routeHandle_ = -1; 75 uint32_t openSpeaker_; 76 std::string adapterNameCase_; 77 struct AudioManager *audioManager_; 78 struct AudioAdapter *audioAdapter_; 79 struct AudioRender *audioRender_; 80 struct AudioPort audioPort_ = {}; 81 bool audioMonoState_ = false; 82 bool audioBalanceState_ = false; 83 float leftBalanceCoef_ = 1.0f; 84 float rightBalanceCoef_ = 1.0f; 85 86 std::shared_ptr<PowerMgr::RunningLock> mKeepRunningLock; 87 88 int32_t CreateRender(const struct AudioPort &renderPort); 89 int32_t InitAudioManager(); 90 void AdjustStereoToMono(char *data, uint64_t len); 91 void AdjustAudioBalance(char *data, uint64_t len); 92 #ifdef DUMPFILE 93 FILE *pfd; 94 #endif // DUMPFILE 95 }; 96 } // namespace AudioStandard 97 } // namespace OHOS 98 #endif // AUDIO_RENDERER_SINK_H 99