1 /* 2 * Copyright (c) 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 REMOTE_AUDIO_RENDERER_SINK_H 17 #define REMOTE_AUDIO_RENDERER_SINK_H 18 19 #include "audio_info.h" 20 #include "audio_manager.h" 21 #include "audio_sink_callback.h" 22 23 #include <cstdio> 24 #include <list> 25 #include <string> 26 #include <map> 27 28 namespace OHOS { 29 namespace AudioStandard { 30 typedef struct { 31 const char *adapterName; 32 uint32_t openMicSpeaker; 33 AudioFormat format; 34 uint32_t sampleFmt; 35 uint32_t sampleRate; 36 uint32_t channel; 37 float volume; 38 const char *filePath; 39 const char *deviceNetworkId; 40 int32_t device_type; 41 } RemoteAudioSinkAttr; 42 43 class RemoteAudioRendererSink { 44 public: 45 int32_t Init(RemoteAudioSinkAttr &attr); 46 void DeInit(void); 47 int32_t Start(void); 48 int32_t Stop(void); 49 int32_t Flush(void); 50 int32_t Reset(void); 51 int32_t Pause(void); 52 int32_t Resume(void); 53 int32_t RenderFrame(char &data, uint64_t len, uint64_t &writeLen); 54 int32_t SetVolume(float left, float right); 55 int32_t GetVolume(float &left, float &right); 56 int32_t GetLatency(uint32_t *latency); 57 int32_t SetAudioScene(AudioScene audioScene); 58 int32_t OpenOutput(DeviceType outputDevice); 59 static RemoteAudioRendererSink *GetInstance(const char *deviceNetworkId); 60 bool rendererInited_; 61 void RegisterParameterCallback(AudioSinkCallback* callback); 62 void SetAudioParameter(const AudioParamKey key, const std::string& condition, const std::string& value); 63 std::string GetAudioParameter(const AudioParamKey key, const std::string& condition); 64 static int32_t ParamEventCallback(AudioExtParamKey key, const char *condition, const char *value, void *reserved, 65 void *cookie); 66 std::string GetNetworkId(); 67 AudioSinkCallback* GetParamCallback(); 68 private: 69 static std::map<std::string, RemoteAudioRendererSink *> allsinks; 70 explicit RemoteAudioRendererSink(const std::string& deviceNetworkId); 71 ~RemoteAudioRendererSink(); 72 RemoteAudioSinkAttr attr_; 73 std::string deviceNetworkId_; 74 bool isRenderCreated = false; 75 bool started_; 76 bool paused_; 77 float leftVolume_; 78 float rightVolume_; 79 int32_t routeHandle_ = -1; 80 int32_t openSpeaker_; 81 std::string adapterNameCase_; 82 struct AudioManager *audioManager_; 83 struct AudioAdapter *audioAdapter_; 84 struct AudioRender *audioRender_; 85 struct AudioPort audioPort_; 86 AudioSinkCallback* callback_; 87 bool paramCallbackRegistered_ = false; 88 89 int32_t GetTargetAdapterPort(struct AudioAdapterDescriptor *descs, int32_t size, const char *networkId); 90 int32_t CreateRender(const struct AudioPort &renderPort); 91 struct AudioManager *GetAudioManager(); 92 #ifdef DEBUG_DUMP_FILE 93 FILE *pfd; 94 #endif // DEBUG_DUMP_FILE 95 }; 96 } // namespace AudioStandard 97 } // namespace OHOS 98 #endif // AUDIO_RENDERER_SINK_H 99