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