• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 #ifndef LOG_TAG
16 #define LOG_TAG "RemoteAudioRendererSinkInner"
17 #endif
18 
19 #include "remote_audio_renderer_sink.h"
20 
21 #include <chrono>
22 #include <cinttypes>
23 #include <cstdio>
24 #include <cstring>
25 #include <dlfcn.h>
26 #include <list>
27 #include <string>
28 #include <sstream>
29 #include <unistd.h>
30 #include <map>
31 #include <mutex>
32 #include "securec.h"
33 #include <algorithm>
34 
35 #include <v1_0/iaudio_manager.h>
36 
37 #include "audio_errors.h"
38 #include "audio_hdi_log.h"
39 #include "audio_utils.h"
40 #include "i_audio_device_adapter.h"
41 #include "i_audio_device_manager.h"
42 #include "volume_tools.h"
43 #include "audio_dump_pcm.h"
44 #include "audio_performance_monitor.h"
45 
46 using namespace std;
47 using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioAdapter;
48 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioAdapterDescriptor;
49 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioFormat;
50 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPort;
51 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortDirection;
52 using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioManager;
53 using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioRender;
54 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes;
55 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceDescriptor;
56 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioCategory;
57 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioRouteNode;
58 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioExtParamKey;
59 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioRoute;
60 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSceneDescriptor;
61 using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback;
62 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortPin;
63 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortType;
64 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortRole;
65 
66 namespace OHOS {
67 namespace AudioStandard {
68 namespace {
69 const int32_t HALF_FACTOR = 2;
70 const float DEFAULT_VOLUME_LEVEL = 1.0f;
71 const uint32_t AUDIO_CHANNELCOUNT = 2;
72 const uint32_t AUDIO_SAMPLE_RATE_48K = 48000;
73 const uint32_t DEEP_BUFFER_RENDER_PERIOD_SIZE = 4096;
74 const uint32_t INT_32_MAX = 0x7fffffff;
75 const uint32_t PCM_8_BIT = 8;
76 const uint32_t PCM_16_BIT = 16;
77 
78 const uint16_t GET_MAX_AMPLITUDE_FRAMES_THRESHOLD = 10;
79 
80 const string MEDIA_STREAM_TYPE = "1";
81 const string COMMUNICATION_STREAM_TYPE = "2";
82 const string NAVIGATION_STREAM_TYPE = "13";
83 uint32_t MEDIA_RENDERID = 0;
84 uint32_t NAVIGATION_RENDERID = 1;
85 uint32_t COMMUNICATION_RENDERID = 2;
86 const char* DUMP_REMOTE_RENDER_SINK_FILENAME = "dump_remote_audiosink";
87 constexpr uint32_t MAX_NUM_OF_SPLIT_STREAM_CATEGORY = 3;
88 const std::array<AudioCategory, MAX_NUM_OF_SPLIT_STREAM_CATEGORY> STREAM_SPLIT_CATEGORY = {
89     AudioCategory::AUDIO_IN_MEDIA,
90     AudioCategory::AUDIO_IN_NAVIGATION,
91     AudioCategory::AUDIO_IN_COMMUNICATION,
92 };
93 
94 /**
95  * @brief whether the arg is valid
96  * @param type audio type, it should in split audio stream type set [media, communication, navigation]
97  * @return return true if type in [media, communication, navigation], false otherwise
98  */
isValidStreamSplitAudioCategory(AudioCategory type)99 bool isValidStreamSplitAudioCategory(AudioCategory type)
100 {
101     for (uint32_t i = 0; i < MAX_NUM_OF_SPLIT_STREAM_CATEGORY; ++i) {
102         if (type == STREAM_SPLIT_CATEGORY[i]) {
103             return true;
104         }
105     }
106     return false;
107 }
108 }
109 
110 class RemoteAudioRendererSinkInner : public RemoteAudioRendererSink, public IAudioDeviceAdapterCallback {
111 public:
112     explicit RemoteAudioRendererSinkInner(const std::string &deviceNetworkId);
113     ~RemoteAudioRendererSinkInner();
114 
115     int32_t Init(const IAudioSinkAttr &attr) override;
116     bool IsInited(void) override;
117     void DeInit(void) override;
118 
119     int32_t Start(void) override;
120     int32_t Stop(void) override;
121     int32_t Flush(void) override;
122     int32_t Reset(void) override;
123     int32_t Pause(void) override;
124     int32_t Resume(void) override;
125     int32_t SuspendRenderSink(void) override;
126     int32_t RestoreRenderSink(void) override;
127 
128     int32_t RenderFrame(char &data, uint64_t len, uint64_t &writeLen) override;
129     int32_t SplitRenderFrame(char &data, uint64_t len, uint64_t &writeLen, char *streamType) override;
130     int32_t SetVolume(float left, float right) override;
131     int32_t GetVolume(float &left, float &right) override;
132     int32_t SetVoiceVolume(float volume) override;
133     int32_t GetTransactionId(uint64_t *transactionId) override;
134     int32_t GetLatency(uint32_t *latency) override;
135     int32_t GetAudioScene() override;
136     int32_t SetAudioScene(AudioScene audioScene, std::vector<DeviceType> &activeDevices) override;
137     int32_t SetOutputRoutes(std::vector<DeviceType> &outputDevices) override;
138     void SetAudioParameter(const AudioParamKey key, const std::string &condition, const std::string &value) override;
139     std::string GetAudioParameter(const AudioParamKey key, const std::string &condition) override;
140     void SetAudioMonoState(bool audioMono) override;
141     void SetAudioBalanceValue(float audioBalance) override;
142     int32_t GetPresentationPosition(uint64_t& frames, int64_t& timeSec, int64_t& timeNanoSec) override;
143     void RegisterAudioSinkCallback(IAudioSinkCallback* callback) override;
144     void ResetOutputRouteForDisconnect(DeviceType device) override;
145     int32_t SetPaPower(int32_t flag) override;
146     int32_t SetPriPaPower() override;
147 
148     void OnAudioParamChange(const std::string &adapterName, const AudioParamKey key, const std::string &condition,
149         const std::string &value) override;
150     float GetMaxAmplitude() override;
151 
152     int32_t UpdateAppsUid(const int32_t appsUid[MAX_MIX_CHANNELS], const size_t size) final;
153     int32_t UpdateAppsUid(const std::vector<int32_t> &appsUid) final;
154     int32_t GetRenderId(uint32_t &renderId) const override;
155 
156     std::string GetNetworkId();
157     IAudioSinkCallback* GetParamCallback();
158 
159 private:
160     int32_t CreateRender(const struct AudioPort &renderPort, AudioCategory type, uint32_t &renderId);
161     void InitAttrs(struct AudioSampleAttributes &attrs);
162     void splitStreamInit(const char *splitStreamString, vector<string> &splitStreamVector);
163     int32_t RenderFrameLogic(char &data, uint64_t len, uint64_t &writeLen, const char *streamType);
164     AudioFormat ConvertToHdiFormat(HdiAdapterFormat format);
165     int32_t OpenOutput(DeviceType outputDevice);
166     void ClearRender();
167 
168     void CheckUpdateState(char *frame, uint64_t replyBytes);
169 private:
170     std::string deviceNetworkId_ = "";
171     std::atomic<bool> rendererInited_ = false;
172     std::atomic<bool> isRenderCreated_ = false;
173     std::atomic<bool> started_ = false;
174     std::atomic<bool> paused_ = false;
175     float leftVolume_ = DEFAULT_VOLUME_LEVEL;
176     float rightVolume_ = DEFAULT_VOLUME_LEVEL;
177 
178     std::shared_ptr<IAudioDeviceManager> audioManager_ = nullptr;
179     std::mutex audioMangerMutex_;
180 
181     std::shared_ptr<IAudioDeviceAdapter> audioAdapter_ = nullptr;
182     std::mutex audioAdapterMutex_;
183 
184     IAudioSinkCallback *callback_ = nullptr;
185     unordered_map<AudioCategory, sptr<IAudioRender>> audioRenderMap_;
186     unordered_map<AudioCategory, AudioPort> audioPortMap_;
187     unordered_map<string, AudioCategory> splitStreamMap_;
188     IAudioSinkAttr attr_ = {};
189     unordered_map<AudioCategory, FILE*> dumpFileMap_;
190     unordered_map<AudioCategory, std::string> dumpFileNameMap_;
191     std::mutex createRenderMutex_;
192     vector<uint32_t> renderIdVector_ = {MEDIA_RENDERID, NAVIGATION_RENDERID, COMMUNICATION_RENDERID};
193     // for get amplitude
194     float maxAmplitude_ = 0;
195     int64_t lastGetMaxAmplitudeTime_ = 0;
196     int64_t last10FrameStartTime_ = 0;
197     bool startUpdate_ = false;
198     int renderFrameNum_ = 0;
199     std::string logUtilsTag_ = "Remote";
200     mutable int64_t volumeDataCount_ = 0;
201 };
202 
RemoteAudioRendererSinkInner(const std::string & deviceNetworkId)203 RemoteAudioRendererSinkInner::RemoteAudioRendererSinkInner(const std::string &deviceNetworkId)
204     :deviceNetworkId_(deviceNetworkId)
205 {
206     AUDIO_DEBUG_LOG("RemoteAudioRendererSinkInner constract.");
207 }
208 
~RemoteAudioRendererSinkInner()209 RemoteAudioRendererSinkInner::~RemoteAudioRendererSinkInner()
210 {
211     if (rendererInited_.load()) {
212         RemoteAudioRendererSinkInner::DeInit();
213     }
214     AudioPerformanceMonitor::GetInstance().DeleteOvertimeMonitor(ADAPTER_TYPE_REMOTE);
215     AUDIO_DEBUG_LOG("RemoteAudioRendererSink destruction.");
216 }
217 
218 std::mutex g_rendererSinksMutex;
219 std::map<std::string, RemoteAudioRendererSinkInner *> allsinks;
GetInstance(const std::string & deviceNetworkId)220 RemoteAudioRendererSink *RemoteAudioRendererSink::GetInstance(const std::string &deviceNetworkId)
221 {
222     std::lock_guard<std::mutex> lock(g_rendererSinksMutex);
223     AUDIO_INFO_LOG("RemoteAudioRendererSink::GetInstance");
224     CHECK_AND_RETURN_RET_LOG(!deviceNetworkId.empty(), nullptr, "Remote render device networkId is null.");
225 
226     if (allsinks.count(deviceNetworkId)) {
227         return allsinks[deviceNetworkId];
228     }
229     RemoteAudioRendererSinkInner *audioRenderer = new(std::nothrow) RemoteAudioRendererSinkInner(deviceNetworkId);
230     AUDIO_INFO_LOG("New daudio remote render device [%{public}s].", GetEncryptStr(deviceNetworkId).c_str());
231     allsinks[deviceNetworkId] = audioRenderer;
232     return audioRenderer;
233 }
234 
ClearRender()235 void RemoteAudioRendererSinkInner::ClearRender()
236 {
237     AUDIO_INFO_LOG("Clear remote audio render enter.");
238     rendererInited_.store(false);
239     isRenderCreated_.store(false);
240     started_.store(false);
241     paused_.store(false);
242 
243     auto renderId = renderIdVector_.begin();
244     std::shared_ptr<IAudioDeviceAdapter> audioAdapter;
245     {
246         std::lock_guard<std::mutex> lock(audioAdapterMutex_);
247         audioAdapter = std::move(audioAdapter_);
248         audioAdapter_ = nullptr;
249     }
250 
251     if (audioAdapter != nullptr) {
252         for (auto &audioRender : audioRenderMap_) {
253             CHECK_AND_RETURN_LOG(renderId != renderIdVector_.end(), "renderId out range");
254             audioAdapter->DestroyRender(audioRender.second, *renderId);
255             audioRender.second = nullptr;
256             renderId++;
257             FILE *dumpFile = dumpFileMap_[audioRender.first];
258             DumpFileUtil::CloseDumpFile(&dumpFile);
259         }
260         audioAdapter->Release();
261     }
262     audioRenderMap_.clear();
263     audioAdapter = nullptr;
264 
265     std::shared_ptr<IAudioDeviceManager> audioManager;
266     {
267         std::lock_guard<std::mutex> lock(audioMangerMutex_);
268         audioManager = std::move(audioManager_);
269         audioManager_ = nullptr;
270     }
271 
272     if (audioManager != nullptr) {
273         audioManager->UnloadAdapter(deviceNetworkId_);
274     }
275     audioManager = nullptr;
276 
277     AudioDeviceManagerFactory::GetInstance().DestoryDeviceManager(REMOTE_DEV_MGR);
278 
279     dumpFileMap_.clear();
280     dumpFileNameMap_.clear();
281     AUDIO_INFO_LOG("Clear remote audio render end.");
282 }
283 
DeInit()284 void RemoteAudioRendererSinkInner::DeInit()
285 {
286     Trace trace("RemoteAudioRendererSinkInner::DeInit");
287     std::lock_guard<std::mutex> lock(g_rendererSinksMutex);
288     AUDIO_INFO_LOG("RemoteAudioRendererSinkInner::DeInit");
289     ClearRender();
290 
291     // remove map recorder.
292     CHECK_AND_RETURN_LOG(allsinks.count(this->deviceNetworkId_) > 0,
293         "not find %{public}s", this->deviceNetworkId_.c_str());
294     RemoteAudioRendererSinkInner *temp = allsinks[this->deviceNetworkId_];
295     allsinks.erase(this->deviceNetworkId_);
296     if (temp == nullptr) {
297         AUDIO_ERR_LOG("temp is nullptr");
298     } else {
299         delete temp;
300     }
301     AUDIO_INFO_LOG("end.");
302 }
303 
PrintRemoteAttr(const IAudioSinkAttr & attr)304 inline std::string PrintRemoteAttr(const IAudioSinkAttr &attr)
305 {
306     std::stringstream value;
307     value << "adapterName[" << attr.adapterName << "] openMicSpeaker[" << attr.openMicSpeaker << "] ";
308     value << "format[" << static_cast<int32_t>(attr.format) << "] ";
309     value << "sampleRate[" << attr.sampleRate << "] channel[" << attr.channel << "] ";
310     value << "volume[" << attr.volume << "] filePath[" << attr.filePath << "] ";
311     value << "deviceNetworkId[" << attr.deviceNetworkId << "] device_type[" << attr.deviceType << "]";
312     return value.str();
313 }
314 
IsInited()315 bool RemoteAudioRendererSinkInner::IsInited()
316 {
317     return rendererInited_.load();
318 }
319 
Init(const IAudioSinkAttr & attr)320 int32_t RemoteAudioRendererSinkInner::Init(const IAudioSinkAttr &attr)
321 {
322     AUDIO_INFO_LOG("RemoteAudioRendererSinkInner::Init");
323     attr_ = attr;
324     splitStreamMap_[MEDIA_STREAM_TYPE] = AudioCategory::AUDIO_IN_MEDIA;
325     splitStreamMap_[NAVIGATION_STREAM_TYPE] = AudioCategory::AUDIO_IN_NAVIGATION;
326     splitStreamMap_[COMMUNICATION_STREAM_TYPE] = AudioCategory::AUDIO_IN_COMMUNICATION;
327     vector<string> splitStreamVector;
328     splitStreamInit(attr_.aux, splitStreamVector);
329 
330     auto audioManager = AudioDeviceManagerFactory::GetInstance().CreatDeviceManager(REMOTE_DEV_MGR);
331     CHECK_AND_RETURN_RET_LOG(audioManager != nullptr, ERR_NOT_STARTED, "Init audio manager fail.");
332 
333     {
334         std::lock_guard<std::mutex> lock(audioMangerMutex_);
335         audioManager_ = audioManager;
336     }
337 
338     struct AudioAdapterDescriptor *desc = audioManager->GetTargetAdapterDesc(deviceNetworkId_, false);
339     CHECK_AND_RETURN_RET_LOG(desc != nullptr, ERR_NOT_STARTED, "Get target adapters descriptor fail.");
340     auto splitStreamTypeIter = splitStreamVector.begin();
341     for (uint32_t port = 0; port < desc->ports.size(); port++) {
342         if (desc->ports[port].portId == AudioPortPin::PIN_OUT_SPEAKER) {
343             AUDIO_INFO_LOG("current audio stream type is %{public}s, port index is %{public}d",
344                 splitStreamTypeIter->c_str(), port);
345             while (splitStreamTypeIter != splitStreamVector.end()) {
346                 audioPortMap_[splitStreamMap_[*splitStreamTypeIter]] = desc->ports[port];
347                 splitStreamTypeIter++;
348             }
349         }
350     }
351 
352     auto audioAdapter = audioManager->LoadAdapters(deviceNetworkId_, false);
353     CHECK_AND_RETURN_RET_LOG(audioAdapter != nullptr, ERR_NOT_STARTED, "Load audio device adapter failed.");
354 
355     {
356         std::lock_guard<std::mutex> lock(audioAdapterMutex_);
357         audioAdapter_ = audioAdapter;
358     }
359 
360     int32_t ret = audioAdapter->Init();
361     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "Audio adapter init fail, ret %{public}d.", ret);
362 
363     rendererInited_.store(true);
364 
365     AUDIO_DEBUG_LOG("RemoteAudioRendererSink: Init end.");
366     return SUCCESS;
367 }
368 
splitStreamInit(const char * splitStreamString,vector<string> & splitStreamVector)369 void RemoteAudioRendererSinkInner::splitStreamInit(const char *splitStreamString, vector<string> &splitStreamVector)
370 {
371     AUDIO_INFO_LOG("audio split stream is %{public}s", splitStreamString);
372     if (splitStreamString == nullptr) {
373         splitStreamVector.push_back("1");
374         AUDIO_INFO_LOG("audio split stream is default 1");
375         return;
376     }
377 
378     istringstream iss(splitStreamString);
379     std::string currentSplitStream;
380     while (getline(iss, currentSplitStream, ':')) {
381         splitStreamVector.push_back(currentSplitStream);
382         AUDIO_INFO_LOG("current split stream type is %{public}s", currentSplitStream.c_str());
383     }
384     sort(splitStreamVector.begin(), splitStreamVector.end());
385 }
386 
CreateRender(const struct AudioPort & renderPort,AudioCategory type,uint32_t & renderId)387 int32_t RemoteAudioRendererSinkInner::CreateRender(const struct AudioPort &renderPort, AudioCategory type,
388     uint32_t &renderId)
389 {
390     CHECK_AND_RETURN_RET_LOG(isValidStreamSplitAudioCategory(type), ERR_INVALID_PARAM, "type: %{public}d is valid",
391         static_cast<int32_t>(type));
392     int64_t start = ClockTime::GetCurNano();
393     struct AudioSampleAttributes param;
394     InitAttrs(param);
395     param.type = type;
396     param.sampleRate = attr_.sampleRate;
397     param.channelCount = attr_.channel;
398     param.format = ConvertToHdiFormat(attr_.format);
399     param.frameSize = PCM_16_BIT * param.channelCount / PCM_8_BIT;
400     param.startThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE / (param.frameSize);
401     AUDIO_DEBUG_LOG("Create render format: %{public}d", param.format);
402 
403     struct AudioDeviceDescriptor deviceDesc;
404     deviceDesc.portId = renderPort.portId;
405     deviceDesc.pins = AudioPortPin::PIN_OUT_SPEAKER;
406     deviceDesc.desc = "";
407 
408     std::shared_ptr<IAudioDeviceAdapter> audioAdapter;
409     {
410         std::lock_guard<std::mutex> lock(audioAdapterMutex_);
411         audioAdapter = audioAdapter_;
412     }
413 
414     CHECK_AND_RETURN_RET_LOG(audioAdapter != nullptr, ERR_INVALID_HANDLE, "CreateRender: Audio adapter is null.");
415     sptr<IAudioRender> audioRender = nullptr;
416     int32_t ret = audioAdapter->CreateRender(deviceDesc, param, audioRender, this, renderId);
417     audioRenderMap_[type] = audioRender;
418     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS && audioRender != nullptr, ret,
419         "AudioDeviceCreateRender fail, ret %{public}d.", ret);
420 
421     isRenderCreated_.store(true);
422     int64_t cost = (ClockTime::GetCurNano() - start) / AUDIO_US_PER_SECOND;
423     AUDIO_INFO_LOG("CreateRender cost[%{public}" PRId64 "]ms", cost);
424     return SUCCESS;
425 }
426 
InitAttrs(struct AudioSampleAttributes & attrs)427 void RemoteAudioRendererSinkInner::InitAttrs(struct AudioSampleAttributes &attrs)
428 {
429     /* Initialization of audio parameters for playback */
430     attrs.channelCount = AUDIO_CHANNELCOUNT;
431     attrs.sampleRate = AUDIO_SAMPLE_RATE_48K;
432     attrs.interleaved = 0;
433     attrs.streamId = static_cast<int32_t>(GenerateUniqueID(AUDIO_HDI_RENDER_ID_BASE, HDI_RENDER_OFFSET_REMOTE));
434     attrs.period = DEEP_BUFFER_RENDER_PERIOD_SIZE;
435     attrs.isBigEndian = false;
436     attrs.isSignedData = true;
437     attrs.stopThreshold = INT_32_MAX;
438     attrs.silenceThreshold = 0;
439 }
440 
ConvertToHdiFormat(HdiAdapterFormat format)441 AudioFormat RemoteAudioRendererSinkInner::ConvertToHdiFormat(HdiAdapterFormat format)
442 {
443     AudioFormat hdiFormat;
444     switch (format) {
445         case SAMPLE_U8:
446             hdiFormat = AudioFormat::AUDIO_FORMAT_TYPE_PCM_8_BIT;
447             break;
448         case SAMPLE_S16:
449             hdiFormat = AudioFormat::AUDIO_FORMAT_TYPE_PCM_16_BIT;
450             break;
451         case SAMPLE_S24:
452             hdiFormat = AudioFormat::AUDIO_FORMAT_TYPE_PCM_24_BIT;
453             break;
454         case SAMPLE_S32:
455             hdiFormat = AudioFormat::AUDIO_FORMAT_TYPE_PCM_32_BIT;
456             break;
457         default:
458             hdiFormat = AudioFormat::AUDIO_FORMAT_TYPE_PCM_16_BIT;
459             break;
460     }
461 
462     return hdiFormat;
463 }
464 
RenderFrame(char & data,uint64_t len,uint64_t & writeLen)465 int32_t RemoteAudioRendererSinkInner::RenderFrame(char &data, uint64_t len, uint64_t &writeLen)
466 {
467     AUDIO_DEBUG_LOG("RemoteAudioRendererSinkInner::RenderFrame");
468     const char *mediaStreamType = "1";
469     return RenderFrameLogic(data, len, writeLen, mediaStreamType);
470 }
471 
SplitRenderFrame(char & data,uint64_t len,uint64_t & writeLen,char * streamType)472 int32_t RemoteAudioRendererSinkInner::SplitRenderFrame(char &data, uint64_t len, uint64_t &writeLen, char *streamType)
473 {
474     AUDIO_DEBUG_LOG("RemoteAudioRendererSinkInner::SplitRenderFrame");
475     return RenderFrameLogic(data, len, writeLen, streamType);
476 }
477 
RenderFrameLogic(char & data,uint64_t len,uint64_t & writeLen,const char * streamType)478 int32_t RemoteAudioRendererSinkInner::RenderFrameLogic(char &data, uint64_t len, uint64_t &writeLen,
479     const char *streamType)
480 {
481     AUDIO_DEBUG_LOG("RemoteAudioRendererSinkInner::RenderFrameLogic, streamType is %{public}s", streamType);
482     Trace trace("RemoteAudioRendererSinkInner::RenderFrameLogic");
483     int64_t start = ClockTime::GetCurNano();
484     sptr<IAudioRender> audioRender_ = audioRenderMap_[splitStreamMap_[streamType]];
485     CHECK_AND_RETURN_RET_LOG(audioRender_ != nullptr, ERR_INVALID_HANDLE, "RenderFrame: Audio render is null.");
486 
487     if (!started_.load()) {
488         AUDIO_DEBUG_LOG("RemoteAudioRendererSinkInner::RenderFrameLogic invalid state not started!");
489     }
490     std::vector<int8_t> frameHal(len);
491     int32_t ret = memcpy_s(frameHal.data(), len, &data, len);
492     if (ret != EOK) {
493         AUDIO_ERR_LOG("Copy render frame failed, error code %d.", ret);
494         return ERR_OPERATION_FAILED;
495     }
496 
497     BufferDesc buffer = { reinterpret_cast<uint8_t*>(&data), len, len };
498     AudioStreamInfo streamInfo(static_cast<AudioSamplingRate>(attr_.sampleRate), AudioEncodingType::ENCODING_PCM,
499         static_cast<AudioSampleFormat>(attr_.format), static_cast<AudioChannel>(attr_.channel));
500     VolumeTools::DfxOperation(buffer, streamInfo, logUtilsTag_, volumeDataCount_);
501     Trace traceRenderFrame("audioRender_->RenderFrame");
502     ret = audioRender_->RenderFrame(frameHal, writeLen);
503     AudioPerformanceMonitor::GetInstance().RecordTimeStamp(ADAPTER_TYPE_REMOTE, ClockTime::GetCurNano());
504     CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_WRITE_FAILED, "Render frame fail, ret %{public}x.", ret);
505     writeLen = len;
506 
507     FILE *dumpFile = dumpFileMap_[splitStreamMap_[streamType]];
508     std::string dumpFileName = dumpFileNameMap_[splitStreamMap_[streamType]];
509     DumpFileUtil::WriteDumpFile(dumpFile, static_cast<void *>(&data), len);
510     AudioCacheMgr::GetInstance().CacheData(dumpFileName, static_cast<void *>(&data), len);
511 
512     CheckUpdateState(&data, len);
513 
514     int64_t cost = (ClockTime::GetCurNano() - start) / AUDIO_US_PER_SECOND;
515     AUDIO_DEBUG_LOG("RenderFrame len[%{public}" PRIu64 "] cost[%{public}" PRId64 "]ms", len, cost);
516 
517     int64_t stampThreshold = 50; // 50ms
518     if (cost >= stampThreshold) {
519         AUDIO_WARNING_LOG("RenderFrame len[%{public}" PRIu64 "] cost[%{public}" PRId64 "]ms", len, cost);
520     }
521 
522     return SUCCESS;
523 }
524 
CheckUpdateState(char * frame,uint64_t replyBytes)525 void RemoteAudioRendererSinkInner::CheckUpdateState(char *frame, uint64_t replyBytes)
526 {
527     if (startUpdate_) {
528         if (renderFrameNum_ == 0) {
529             last10FrameStartTime_ = ClockTime::GetCurNano();
530         }
531         renderFrameNum_++;
532         maxAmplitude_ = UpdateMaxAmplitude(static_cast<ConvertHdiFormat>(attr_.format), frame, replyBytes);
533         if (renderFrameNum_ == GET_MAX_AMPLITUDE_FRAMES_THRESHOLD) {
534             renderFrameNum_ = 0;
535             if (last10FrameStartTime_ > lastGetMaxAmplitudeTime_) {
536                 startUpdate_ = false;
537                 maxAmplitude_ = 0;
538             }
539         }
540     }
541 }
542 
GetMaxAmplitude()543 float RemoteAudioRendererSinkInner::GetMaxAmplitude()
544 {
545     lastGetMaxAmplitudeTime_ = ClockTime::GetCurNano();
546     startUpdate_ = true;
547     return maxAmplitude_;
548 }
549 
Start(void)550 int32_t RemoteAudioRendererSinkInner::Start(void)
551 {
552     Trace trace("RemoteAudioRendererSinkInner::Start");
553     AUDIO_INFO_LOG("RemoteAudioRendererSinkInner::Start");
554     std::lock_guard<std::mutex> lock(createRenderMutex_);
555     auto renderId = renderIdVector_.begin();
556     if (!isRenderCreated_.load()) {
557         for (const auto &audioPort : audioPortMap_) {
558             CHECK_AND_RETURN_RET(renderId != renderIdVector_.end(), ERR_OPERATION_FAILED);
559             CHECK_AND_RETURN_RET_LOG(CreateRender(audioPort.second, audioPort.first, *renderId) == SUCCESS,
560                 ERR_NOT_STARTED, "Create render fail, audio port %{public}d", audioPort.second.portId);
561             renderId++;
562         }
563     }
564 
565     if (started_.load()) {
566         AUDIO_INFO_LOG("Remote render is already started.");
567         return SUCCESS;
568     }
569 
570     for (const auto &audioPort : audioPortMap_) {
571         FILE *dumpFile = nullptr;
572         std::string dumpFileName = std::string(DUMP_REMOTE_RENDER_SINK_FILENAME) + "_" + GetTime() + "_" +
573             std::to_string(attr_.sampleRate) + "_" + std::to_string(attr_.channel) + "_" +
574             std::to_string(attr_.format) + ".pcm";
575         DumpFileUtil::OpenDumpFile(DumpFileUtil::DUMP_SERVER_PARA, dumpFileName, &dumpFile);
576         dumpFileMap_[audioPort.first] = dumpFile;
577         dumpFileNameMap_[audioPort.first] = dumpFileName;
578     }
579 
580     for (const auto &audioRender : audioRenderMap_) {
581         CHECK_AND_RETURN_RET_LOG(audioRender.second != nullptr, ERR_INVALID_HANDLE,
582             "Start: Audio render is null. Audio steam type is %{public}d", audioRender.first);
583         int32_t ret = audioRender.second->Start();
584         CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_NOT_STARTED, "Start fail, ret %{public}d.", ret);
585     }
586     started_.store(true);
587     AudioPerformanceMonitor::GetInstance().RecordTimeStamp(ADAPTER_TYPE_REMOTE, INIT_LASTWRITTEN_TIME);
588     return SUCCESS;
589 }
590 
Stop(void)591 int32_t RemoteAudioRendererSinkInner::Stop(void)
592 {
593     Trace trace("RemoteAudioRendererSinkInner::Stop");
594     AUDIO_INFO_LOG("RemoteAudioRendererSinkInner::Stop");
595     if (!started_.load()) {
596         AUDIO_INFO_LOG("Remote render is already stopped.");
597         return SUCCESS;
598     }
599 
600     for (const auto &audioRender : audioRenderMap_) {
601         CHECK_AND_RETURN_RET_LOG(audioRender.second != nullptr, ERR_INVALID_HANDLE,
602             "Stop: Audio render is null.Audio stream type is %{public}d", audioRender.first);
603         int32_t ret = audioRender.second->Stop();
604         CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_OPERATION_FAILED, "Stop fail, ret %{public}d.", ret);
605     }
606     started_.store(false);
607     return SUCCESS;
608 }
609 
Pause(void)610 int32_t RemoteAudioRendererSinkInner::Pause(void)
611 {
612     AUDIO_INFO_LOG("RemoteAudioRendererSinkInner::Pause");
613     CHECK_AND_RETURN_RET_LOG(started_.load(), ERR_ILLEGAL_STATE, "Pause invalid state!");
614 
615     if (paused_.load()) {
616         AUDIO_INFO_LOG("Remote render is already paused.");
617         return SUCCESS;
618     }
619 
620     for (const auto &audioRender : audioRenderMap_) {
621         CHECK_AND_RETURN_RET_LOG(audioRender.second != nullptr, ERR_INVALID_HANDLE,
622             "Pause: Audio render is null. Audio stream type is %{public}d", audioRender.first);
623         int32_t ret = audioRender.second->Pause();
624         CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_OPERATION_FAILED, "Pause fail, ret %{public}d.", ret);
625     }
626     paused_.store(true);
627     return SUCCESS;
628 }
629 
Resume(void)630 int32_t RemoteAudioRendererSinkInner::Resume(void)
631 {
632     Trace trace("RemoteAudioRendererSinkInner::Resume");
633     AUDIO_INFO_LOG("RemoteAudioRendererSinkInner::Resume");
634     CHECK_AND_RETURN_RET_LOG(started_.load(), ERR_ILLEGAL_STATE, "Resume invalid state!");
635 
636     if (!paused_.load()) {
637         AUDIO_INFO_LOG("Remote render is already resumed.");
638         return SUCCESS;
639     }
640 
641     for (const auto &audioRender : audioRenderMap_) {
642         CHECK_AND_RETURN_RET_LOG(audioRender.second != nullptr, ERR_INVALID_HANDLE,
643             "Resume: Audio render is null.Audio stream type is %{public}d", audioRender.first);
644         int32_t ret = audioRender.second->Resume();
645         CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_OPERATION_FAILED, "Resume fail, ret %{public}d.", ret);
646     }
647 
648     paused_.store(false);
649     AudioPerformanceMonitor::GetInstance().RecordTimeStamp(ADAPTER_TYPE_REMOTE, INIT_LASTWRITTEN_TIME);
650     return SUCCESS;
651 }
652 
Reset(void)653 int32_t RemoteAudioRendererSinkInner::Reset(void)
654 {
655     Trace trace("RemoteAudioRendererSinkInner::Reset");
656     AUDIO_INFO_LOG("RemoteAudioRendererSinkInner::Reset");
657     CHECK_AND_RETURN_RET_LOG(started_.load(), ERR_ILLEGAL_STATE, "Reset invalid state!");
658 
659     for (const auto &audioRender : audioRenderMap_) {
660         CHECK_AND_RETURN_RET_LOG(audioRender.second != nullptr, ERR_INVALID_HANDLE,
661             "Reset: Audio render is null.Audio stream type is %{public}d", audioRender.first);
662         int32_t ret = audioRender.second->Flush();
663         CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_OPERATION_FAILED, "Reset fail, ret %{public}d.", ret);
664     }
665     return SUCCESS;
666 }
667 
Flush(void)668 int32_t RemoteAudioRendererSinkInner::Flush(void)
669 {
670     Trace trace("RemoteAudioRendererSinkInner::Flush");
671     AUDIO_INFO_LOG("RemoteAudioRendererSinkInner::Flush");
672     CHECK_AND_RETURN_RET_LOG(started_.load(), ERR_ILLEGAL_STATE, "Flush invalid state!");
673 
674     for (const auto &audioRender : audioRenderMap_) {
675         CHECK_AND_RETURN_RET_LOG(audioRender.second != nullptr, ERR_INVALID_HANDLE,
676             "Flush: Audio render is null.Audio stream type is %{public}d", audioRender.first);
677         int32_t ret = audioRender.second->Flush();
678         CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_OPERATION_FAILED, "Flush fail, ret %{public}d.", ret);
679     }
680     return SUCCESS;
681 }
682 
SuspendRenderSink(void)683 int32_t RemoteAudioRendererSinkInner::SuspendRenderSink(void)
684 {
685     return SUCCESS;
686 }
687 
RestoreRenderSink(void)688 int32_t RemoteAudioRendererSinkInner::RestoreRenderSink(void)
689 {
690     return SUCCESS;
691 }
692 
SetVolume(float left,float right)693 int32_t RemoteAudioRendererSinkInner::SetVolume(float left, float right)
694 {
695     leftVolume_ = left;
696     rightVolume_ = right;
697     float volume;
698     if ((leftVolume_ == 0) && (rightVolume_ != 0)) {
699         volume = rightVolume_;
700     } else if ((leftVolume_ != 0) && (rightVolume_ == 0)) {
701         volume = leftVolume_;
702     } else {
703         volume = (leftVolume_ + rightVolume_) / HALF_FACTOR;
704     }
705     for (const auto &audioRender : audioRenderMap_) {
706         CHECK_AND_RETURN_RET_LOG(audioRender.second != nullptr, ERR_INVALID_HANDLE,
707             "SetVolume: Audio render is null. Audio stream type is %{public}d", audioRender.first);
708         int32_t ret = audioRender.second->SetVolume(volume);
709         CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_OPERATION_FAILED, "Set volume fail, ret %{public}d.", ret);
710     }
711     return SUCCESS;
712 }
713 
GetVolume(float & left,float & right)714 int32_t RemoteAudioRendererSinkInner::GetVolume(float &left, float &right)
715 {
716     left = leftVolume_;
717     right = rightVolume_;
718     return SUCCESS;
719 }
720 
GetLatency(uint32_t * latency)721 int32_t RemoteAudioRendererSinkInner::GetLatency(uint32_t *latency)
722 {
723     CHECK_AND_RETURN_RET_LOG(latency, ERR_INVALID_PARAM,
724         "GetLatency failed latency null");
725 
726     uint32_t hdiLatency = 0;
727     for (const auto &audioRender : audioRenderMap_) {
728         CHECK_AND_RETURN_RET_LOG(audioRender.second != nullptr, ERR_INVALID_HANDLE,
729             "GetLatency: Audio render is null. Audio stream type is %{public}d", audioRender.first);
730         int32_t ret = audioRender.second->GetLatency(hdiLatency);
731         CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_OPERATION_FAILED, "Get latency fail, ret %{public}d.", ret);
732     }
733 
734     *latency = hdiLatency;
735     return SUCCESS;
736 }
737 
GetAudioCategory(AudioScene audioScene)738 static AudioCategory GetAudioCategory(AudioScene audioScene)
739 {
740     AudioCategory audioCategory;
741     switch (audioScene) {
742         case AUDIO_SCENE_DEFAULT:
743             audioCategory = AudioCategory::AUDIO_IN_MEDIA;
744             break;
745         case AUDIO_SCENE_RINGING:
746         case AUDIO_SCENE_VOICE_RINGING:
747             audioCategory = AudioCategory::AUDIO_IN_RINGTONE;
748             break;
749         case AUDIO_SCENE_PHONE_CALL:
750             audioCategory = AudioCategory::AUDIO_IN_CALL;
751             break;
752         case AUDIO_SCENE_PHONE_CHAT:
753             audioCategory = AudioCategory::AUDIO_IN_COMMUNICATION;
754             break;
755         default:
756             audioCategory = AudioCategory::AUDIO_IN_MEDIA;
757             break;
758     }
759     AUDIO_DEBUG_LOG("Audio category returned is: %{public}d", audioCategory);
760 
761     return audioCategory;
762 }
763 
SetOutputPortPin(DeviceType outputDevice,AudioRouteNode & sink)764 static int32_t SetOutputPortPin(DeviceType outputDevice, AudioRouteNode &sink)
765 {
766     int32_t ret = SUCCESS;
767 
768     switch (outputDevice) {
769         case DEVICE_TYPE_SPEAKER:
770             sink.ext.device.type = AudioPortPin::PIN_OUT_SPEAKER;
771             sink.ext.device.desc = "pin_out_speaker";
772             break;
773         case DEVICE_TYPE_WIRED_HEADSET:
774             sink.ext.device.type = AudioPortPin::PIN_OUT_HEADSET;
775             sink.ext.device.desc = "pin_out_headset";
776             break;
777         case DEVICE_TYPE_USB_HEADSET:
778             sink.ext.device.type = AudioPortPin::PIN_OUT_USB_EXT;
779             sink.ext.device.desc = "pin_out_usb_ext";
780             break;
781         default:
782             ret = ERR_NOT_SUPPORTED;
783             break;
784     }
785 
786     return ret;
787 }
788 
OpenOutput(DeviceType outputDevice)789 int32_t RemoteAudioRendererSinkInner::OpenOutput(DeviceType outputDevice)
790 {
791     AudioRouteNode source = {};
792     AudioRouteNode sink = {};
793 
794     int32_t ret = SetOutputPortPin(outputDevice, sink);
795     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "Set output port pin fail, ret %{public}d", ret);
796 
797     source.portId = 0;
798     source.role = AudioPortRole::AUDIO_PORT_SOURCE_ROLE;
799     source.type = AudioPortType::AUDIO_PORT_MIX_TYPE;
800     source.ext.mix.moduleId = 0;
801     source.ext.mix.streamId = static_cast<int32_t>(
802         GenerateUniqueID(AUDIO_HDI_RENDER_ID_BASE, HDI_RENDER_OFFSET_REMOTE));
803 
804     if (audioPortMap_.find(AudioCategory::AUDIO_IN_MEDIA) == audioPortMap_.end()) {
805         AUDIO_WARNING_LOG("audioPortMap_ is null, ret %{public}d.", ret);
806         return ERR_INVALID_HANDLE;
807     }
808     sink.portId = static_cast<int32_t>(audioPortMap_[AudioCategory::AUDIO_IN_MEDIA].portId);
809     sink.role = AudioPortRole::AUDIO_PORT_SINK_ROLE;
810     sink.type = AudioPortType::AUDIO_PORT_DEVICE_TYPE;
811     sink.ext.device.moduleId = 0;
812 
813     AudioRoute route;
814     route.sources.push_back(source);
815     route.sinks.push_back(sink);
816 
817     std::shared_ptr<IAudioDeviceAdapter> audioAdapter;
818     {
819         std::lock_guard<std::mutex> lock(audioAdapterMutex_);
820         audioAdapter = audioAdapter_;
821     }
822 
823     CHECK_AND_RETURN_RET_LOG(audioAdapter != nullptr, ERR_INVALID_HANDLE, "OpenOutput: Audio adapter is null.");
824     ret = audioAdapter->UpdateAudioRoute(route);
825     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "Update audio route fail, ret %{public}d", ret);
826     return SUCCESS;
827 }
828 
GetAudioScene()829 int32_t RemoteAudioRendererSinkInner::GetAudioScene()
830 {
831     AUDIO_WARNING_LOG("not supported.");
832     return ERR_NOT_SUPPORTED;
833 }
834 
SetAudioScene(AudioScene audioScene,std::vector<DeviceType> & activeDevices)835 int32_t RemoteAudioRendererSinkInner::SetAudioScene(AudioScene audioScene, std::vector<DeviceType> &activeDevices)
836 {
837     CHECK_AND_RETURN_RET_LOG(!activeDevices.empty() && activeDevices.size() <= AUDIO_CONCURRENT_ACTIVE_DEVICES_LIMIT,
838         ERR_INVALID_PARAM, "Invalid audio devices.");
839     DeviceType activeDevice = activeDevices.front();
840     AUDIO_INFO_LOG("SetAudioScene scene: %{public}d, device: %{public}d", audioScene, activeDevice);
841     CHECK_AND_RETURN_RET_LOG(audioScene >= AUDIO_SCENE_DEFAULT && audioScene < AUDIO_SCENE_MAX,
842         ERR_INVALID_PARAM, "invalid audioScene");
843 
844     int32_t ret = OpenOutput(DEVICE_TYPE_SPEAKER);
845     if (ret != SUCCESS) {
846         AUDIO_WARNING_LOG("Audio adapter update audio route fail, ret %{public}d.", ret);
847     }
848 
849     struct AudioSceneDescriptor scene;
850     scene.scene.id = GetAudioCategory(audioScene);
851     scene.desc.pins = AudioPortPin::PIN_OUT_SPEAKER;
852 
853     AUDIO_DEBUG_LOG("SelectScene start");
854     for (const auto &audioRender : audioRenderMap_) {
855         CHECK_AND_RETURN_RET_LOG(audioRender.second != nullptr, ERR_INVALID_HANDLE,
856             "SetAudioScene: Audio render is null. Audio stream type is %{public}d", audioRender.first);
857         ret = audioRender.second->SelectScene(scene);
858         CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_OPERATION_FAILED,
859             "Audio render Select scene fail, ret %{public}d.", ret);
860     }
861     AUDIO_DEBUG_LOG("Select audio scene SUCCESS: %{public}d", audioScene);
862     return SUCCESS;
863 }
864 
SetAudioParameter(const AudioParamKey key,const std::string & condition,const std::string & value)865 void RemoteAudioRendererSinkInner::SetAudioParameter(const AudioParamKey key, const std::string &condition,
866     const std::string &value)
867 {
868 #ifdef FEATURE_DISTRIBUTE_AUDIO
869     AUDIO_INFO_LOG("SetParameter: key %{public}d, condition: %{public}s, value: %{public}s",
870         key, condition.c_str(), value.c_str());
871 
872     std::shared_ptr<IAudioDeviceAdapter> audioAdapter;
873     {
874         std::lock_guard<std::mutex> lock(audioAdapterMutex_);
875         audioAdapter = audioAdapter_;
876     }
877 
878     CHECK_AND_RETURN_LOG(audioAdapter != nullptr, "SetAudioParameter: Audio adapter is null.");
879     audioAdapter->SetAudioParameter(key, condition.c_str(), value.c_str());
880 #endif
881 }
882 
GetAudioParameter(const AudioParamKey key,const std::string & condition)883 std::string RemoteAudioRendererSinkInner::GetAudioParameter(const AudioParamKey key, const std::string &condition)
884 {
885 #ifdef FEATURE_DISTRIBUTE_AUDIO
886     AUDIO_INFO_LOG("key %{public}d, condition: %{public}s", key, condition.c_str());
887 
888     std::shared_ptr<IAudioDeviceAdapter> audioAdapter;
889     {
890         std::lock_guard<std::mutex> lock(audioAdapterMutex_);
891         audioAdapter = audioAdapter_;
892     }
893 
894     CHECK_AND_RETURN_RET_LOG(audioAdapter != nullptr, "", "Audio adapter is null.");
895     return audioAdapter->GetAudioParameter(key, condition);
896 #else
897     return "";
898 #endif
899 }
900 
RegisterAudioSinkCallback(IAudioSinkCallback * callback)901 void RemoteAudioRendererSinkInner::RegisterAudioSinkCallback(IAudioSinkCallback* callback)
902 {
903     AUDIO_INFO_LOG("register sink audio param callback.");
904     callback_ = callback;
905 #ifdef FEATURE_DISTRIBUTE_AUDIO
906     // register to remote audio adapter
907 
908     std::shared_ptr<IAudioDeviceAdapter> audioAdapter;
909     {
910         std::lock_guard<std::mutex> lock(audioAdapterMutex_);
911         audioAdapter = audioAdapter_;
912     }
913 
914     CHECK_AND_RETURN_LOG(audioAdapter != nullptr, "RegisterAudioSinkCallback: Audio adapter is null.");
915     int32_t ret = audioAdapter->RegExtraParamObserver();
916     CHECK_AND_RETURN_LOG(ret == SUCCESS, "RegisterAudioSinkCallback failed, ret %{public}d.", ret);
917 #endif
918 }
919 
OnAudioParamChange(const std::string & adapterName,const AudioParamKey key,const std::string & condition,const std::string & value)920 void RemoteAudioRendererSinkInner::OnAudioParamChange(const std::string &adapterName, const AudioParamKey key,
921     const std::string &condition, const std::string &value)
922 {
923     AUDIO_INFO_LOG("Audio param change event, key:%{public}d, condition:%{public}s, value:%{public}s",
924         key, condition.c_str(), value.c_str());
925     if (key == AudioParamKey::PARAM_KEY_STATE) {
926         ClearRender();
927     }
928 
929     CHECK_AND_RETURN_LOG(callback_ != nullptr, "Sink audio param callback is null.");
930     callback_->OnAudioSinkParamChange(adapterName, key, condition, value);
931 }
932 
GetTransactionId(uint64_t * transactionId)933 int32_t RemoteAudioRendererSinkInner::GetTransactionId(uint64_t *transactionId)
934 {
935     (void)transactionId;
936     AUDIO_ERR_LOG("GetTransactionId not supported");
937     return ERR_NOT_SUPPORTED;
938 }
939 
SetVoiceVolume(float volume)940 int32_t RemoteAudioRendererSinkInner::SetVoiceVolume(float volume)
941 {
942     (void)volume;
943     AUDIO_ERR_LOG("SetVoiceVolume not supported");
944     return ERR_NOT_SUPPORTED;
945 }
946 
SetOutputRoutes(std::vector<DeviceType> & outputDevices)947 int32_t RemoteAudioRendererSinkInner::SetOutputRoutes(std::vector<DeviceType> &outputDevices)
948 {
949     (void)outputDevices;
950     AUDIO_DEBUG_LOG("SetOutputRoutes not supported.");
951     return ERR_NOT_SUPPORTED;
952 }
953 
SetAudioMonoState(bool audioMono)954 void RemoteAudioRendererSinkInner::SetAudioMonoState(bool audioMono)
955 {
956     (void)audioMono;
957     AUDIO_ERR_LOG("SetAudioMonoState not supported");
958     return;
959 }
960 
SetAudioBalanceValue(float audioBalance)961 void RemoteAudioRendererSinkInner::SetAudioBalanceValue(float audioBalance)
962 {
963     (void)audioBalance;
964     AUDIO_ERR_LOG("SetAudioBalanceValue not supported");
965     return;
966 }
967 
GetPresentationPosition(uint64_t & frames,int64_t & timeSec,int64_t & timeNanoSec)968 int32_t RemoteAudioRendererSinkInner::GetPresentationPosition(uint64_t& frames, int64_t& timeSec, int64_t& timeNanoSec)
969 {
970     AUDIO_ERR_LOG("GetPresentationPosition not supported");
971     return ERR_NOT_SUPPORTED;
972 }
973 
GetNetworkId()974 std::string RemoteAudioRendererSinkInner::GetNetworkId()
975 {
976     return deviceNetworkId_;
977 }
978 
ResetOutputRouteForDisconnect(DeviceType device)979 void RemoteAudioRendererSinkInner::ResetOutputRouteForDisconnect(DeviceType device)
980 {
981     AUDIO_WARNING_LOG("not supported.");
982 }
983 
GetParamCallback()984 OHOS::AudioStandard::IAudioSinkCallback* RemoteAudioRendererSinkInner::GetParamCallback()
985 {
986     return callback_;
987 }
988 
SetPaPower(int32_t flag)989 int32_t RemoteAudioRendererSinkInner::SetPaPower(int32_t flag)
990 {
991     (void)flag;
992     return ERR_NOT_SUPPORTED;
993 }
994 
SetPriPaPower()995 int32_t RemoteAudioRendererSinkInner::SetPriPaPower()
996 {
997     return ERR_NOT_SUPPORTED;
998 }
999 
UpdateAppsUid(const int32_t appsUid[MAX_MIX_CHANNELS],const size_t size)1000 int32_t RemoteAudioRendererSinkInner::UpdateAppsUid(const int32_t appsUid[MAX_MIX_CHANNELS], const size_t size)
1001 {
1002     return ERR_NOT_SUPPORTED;
1003 }
1004 
UpdateAppsUid(const std::vector<int32_t> & appsUid)1005 int32_t RemoteAudioRendererSinkInner::UpdateAppsUid(const std::vector<int32_t> &appsUid)
1006 {
1007     return ERR_NOT_SUPPORTED;
1008 }
1009 
GetRenderId(uint32_t & renderId) const1010 int32_t RemoteAudioRendererSinkInner::GetRenderId(uint32_t &renderId) const
1011 {
1012     renderId = GenerateUniqueID(AUDIO_HDI_RENDER_ID_BASE, HDI_RENDER_OFFSET_REMOTE);
1013     return SUCCESS;
1014 }
1015 } // namespace AudioStandard
1016 } // namespace OHOS
1017