1 /*
2  * Copyright (c) 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 "AudioProcessInServer"
17 #endif
18 
19 #include "audio_process_in_server.h"
20 #include "policy_handler.h"
21 
22 #include "securec.h"
23 
24 #include "audio_errors.h"
25 #include "audio_capturer_log.h"
26 #include "audio_service.h"
27 #include "audio_schedule.h"
28 #include "audio_utils.h"
29 #include "media_monitor_manager.h"
30 #include "audio_dump_pcm.h"
31 
32 namespace OHOS {
33 namespace AudioStandard {
34 namespace {
35 static constexpr int32_t VOLUME_SHIFT_NUMBER = 16; // 1 >> 16 = 65536, max volume
36 }
37 
Create(const AudioProcessConfig & processConfig,ProcessReleaseCallback * releaseCallback)38 sptr<AudioProcessInServer> AudioProcessInServer::Create(const AudioProcessConfig &processConfig,
39     ProcessReleaseCallback *releaseCallback)
40 {
41     sptr<AudioProcessInServer> process = new(std::nothrow) AudioProcessInServer(processConfig, releaseCallback);
42 
43     return process;
44 }
45 
AudioProcessInServer(const AudioProcessConfig & processConfig,ProcessReleaseCallback * releaseCallback)46 AudioProcessInServer::AudioProcessInServer(const AudioProcessConfig &processConfig,
47     ProcessReleaseCallback *releaseCallback) : processConfig_(processConfig), releaseCallback_(releaseCallback)
48 {
49     if (processConfig.originalSessionId < MIN_SESSIONID || processConfig.originalSessionId > MAX_SESSIONID) {
50         sessionId_ = PolicyHandler::GetInstance().GenerateSessionId(processConfig_.appInfo.appUid);
51     } else {
52         sessionId_ = processConfig.originalSessionId;
53     }
54 
55     const auto [samplingRate, encoding, format, channels, channelLayout] = processConfig.streamInfo;
56     // eg: 100005_dump_process_server_audio_48000_2_1.pcm
57     dumpFileName_ = std::to_string(sessionId_) + '_' + "_dump_process_server_audio_" +
58         std::to_string(samplingRate) + '_' + std::to_string(channels) + '_' + std::to_string(format) +
59         ".pcm";
60     DumpFileUtil::OpenDumpFile(DUMP_SERVER_PARA, dumpFileName_, &dumpFile_);
61 }
62 
~AudioProcessInServer()63 AudioProcessInServer::~AudioProcessInServer()
64 {
65     AUDIO_INFO_LOG("~AudioProcessInServer()");
66     if (convertedBuffer_.buffer != nullptr) {
67         delete [] convertedBuffer_.buffer;
68     }
69     if (processConfig_.audioMode == AUDIO_MODE_RECORD && needCheckBackground_) {
70         uint32_t tokenId = processConfig_.appInfo.appTokenId;
71         PermissionUtil::NotifyStop(tokenId, sessionId_);
72     }
73     DumpFileUtil::CloseDumpFile(&dumpFile_);
74 }
75 
GetSessionId(uint32_t & sessionId)76 int32_t AudioProcessInServer::GetSessionId(uint32_t &sessionId)
77 {
78     sessionId = sessionId_;
79     return SUCCESS;
80 }
81 
SetNonInterruptMute(const bool muteFlag)82 void AudioProcessInServer::SetNonInterruptMute(const bool muteFlag)
83 {
84     muteFlag_ = muteFlag;
85     AUDIO_INFO_LOG("muteFlag_: %{public}d", muteFlag);
86     AudioService::GetInstance()->UpdateMuteControlSet(sessionId_, muteFlag);
87 }
88 
GetMuteState()89 bool AudioProcessInServer::GetMuteState()
90 {
91     return muteFlag_ || silentModeAndMixWithOthers_;
92 }
93 
GetSessionId()94 uint32_t AudioProcessInServer::GetSessionId()
95 {
96     return sessionId_;
97 }
98 
ResolveBuffer(std::shared_ptr<OHAudioBuffer> & buffer)99 int32_t AudioProcessInServer::ResolveBuffer(std::shared_ptr<OHAudioBuffer> &buffer)
100 {
101     AUDIO_INFO_LOG("ResolveBuffer start");
102     CHECK_AND_RETURN_RET_LOG(isBufferConfiged_, ERR_ILLEGAL_STATE,
103         "ResolveBuffer failed, buffer is not configed.");
104 
105     if (processBuffer_ == nullptr) {
106         AUDIO_ERR_LOG("ResolveBuffer failed, buffer is nullptr.");
107     }
108     buffer = processBuffer_;
109     CHECK_AND_RETURN_RET_LOG(buffer != nullptr, ERR_ILLEGAL_STATE, "ResolveBuffer failed, processBuffer_ is null.");
110 
111     return SUCCESS;
112 }
113 
RequestHandleInfo(bool isAsync)114 int32_t AudioProcessInServer::RequestHandleInfo(bool isAsync)
115 {
116     CHECK_AND_RETURN_RET_LOG(isInited_, ERR_ILLEGAL_STATE, "not inited!");
117     CHECK_AND_RETURN_RET_LOG(processBuffer_ != nullptr, ERR_ILLEGAL_STATE, "buffer not inited!");
118 
119     for (size_t i = 0; i < listenerList_.size(); i++) {
120         listenerList_[i]->OnUpdateHandleInfo(this);
121     }
122     return SUCCESS;
123 }
124 
Start()125 int32_t AudioProcessInServer::Start()
126 {
127     CHECK_AND_RETURN_RET_LOG(isInited_, ERR_ILLEGAL_STATE, "not inited!");
128 
129     std::lock_guard<std::mutex> lock(statusLock_);
130     CHECK_AND_RETURN_RET_LOG(streamStatus_->load() == STREAM_STARTING || streamStatus_->load() == STREAM_STAND_BY,
131         ERR_ILLEGAL_STATE, "Start failed, invalid status.");
132 
133     if (processConfig_.audioMode != AUDIO_MODE_PLAYBACK && !needCheckBackground_ &&
134         PermissionUtil::NeedVerifyBackgroundCapture(processConfig_.callerUid, processConfig_.capturerInfo.sourceType)) {
135         AUDIO_INFO_LOG("set needCheckBackground_: true");
136         needCheckBackground_ = true;
137     }
138     if (processConfig_.audioMode != AUDIO_MODE_PLAYBACK && needCheckBackground_) {
139         CHECK_AND_RETURN_RET_LOG(PermissionUtil::VerifyBackgroundCapture(processConfig_.appInfo.appTokenId,
140             processConfig_.appInfo.appFullTokenId), ERR_OPERATION_FAILED, "VerifyBackgroundCapture failed!");
141         CHECK_AND_RETURN_RET_LOG(PermissionUtil::NotifyStart(processConfig_.appInfo.appTokenId, sessionId_),
142             ERR_PERMISSION_DENIED, "NotifyPrivacy failed!");
143     }
144 
145     for (size_t i = 0; i < listenerList_.size(); i++) {
146         listenerList_[i]->OnStart(this);
147     }
148 
149     if (streamStatus_->load() == STREAM_STAND_BY) {
150         AUDIO_INFO_LOG("Call start while in stand-by, session %{public}u", sessionId_);
151         WriterRenderStreamStandbySysEvent(sessionId_, 0);
152         streamStatus_->store(STREAM_STARTING);
153     }
154     processBuffer_->SetLastWrittenTime(ClockTime::GetCurNano());
155 
156     AUDIO_INFO_LOG("Start in server success!");
157     return SUCCESS;
158 }
159 
Pause(bool isFlush)160 int32_t AudioProcessInServer::Pause(bool isFlush)
161 {
162     CHECK_AND_RETURN_RET_LOG(isInited_, ERR_ILLEGAL_STATE, "not inited!");
163 
164     (void)isFlush;
165     std::lock_guard<std::mutex> lock(statusLock_);
166     CHECK_AND_RETURN_RET_LOG(streamStatus_->load() == STREAM_PAUSING,
167         ERR_ILLEGAL_STATE, "Pause failed, invalid status.");
168     if (processConfig_.audioMode != AUDIO_MODE_PLAYBACK && needCheckBackground_) {
169         uint32_t tokenId = processConfig_.appInfo.appTokenId;
170         PermissionUtil::NotifyStop(tokenId, sessionId_);
171     }
172     for (size_t i = 0; i < listenerList_.size(); i++) {
173         listenerList_[i]->OnPause(this);
174     }
175 
176     AUDIO_PRERELEASE_LOGI("Pause in server success!");
177     return SUCCESS;
178 }
179 
Resume()180 int32_t AudioProcessInServer::Resume()
181 {
182     CHECK_AND_RETURN_RET_LOG(isInited_, ERR_ILLEGAL_STATE, "not inited!");
183     std::lock_guard<std::mutex> lock(statusLock_);
184     CHECK_AND_RETURN_RET_LOG(streamStatus_->load() == STREAM_STARTING,
185         ERR_ILLEGAL_STATE, "Resume failed, invalid status.");
186     if (processConfig_.audioMode != AUDIO_MODE_PLAYBACK && !needCheckBackground_ &&
187         PermissionUtil::NeedVerifyBackgroundCapture(processConfig_.callerUid, processConfig_.capturerInfo.sourceType)) {
188         AUDIO_INFO_LOG("set needCheckBackground_: true");
189         needCheckBackground_ = true;
190     }
191     if (processConfig_.audioMode != AUDIO_MODE_PLAYBACK && needCheckBackground_) {
192         uint32_t tokenId = processConfig_.appInfo.appTokenId;
193         uint64_t fullTokenId = processConfig_.appInfo.appFullTokenId;
194         CHECK_AND_RETURN_RET_LOG(PermissionUtil::VerifyBackgroundCapture(tokenId, fullTokenId), ERR_OPERATION_FAILED,
195             "VerifyBackgroundCapture failed!");
196         CHECK_AND_RETURN_RET_LOG(PermissionUtil::NotifyStart(tokenId, sessionId_), ERR_PERMISSION_DENIED,
197             "NotifyPrivacy failed!");
198     }
199 
200     for (size_t i = 0; i < listenerList_.size(); i++) {
201         listenerList_[i]->OnStart(this);
202     }
203 
204     AUDIO_PRERELEASE_LOGI("Resume in server success!");
205     return SUCCESS;
206 }
207 
Stop()208 int32_t AudioProcessInServer::Stop()
209 {
210     CHECK_AND_RETURN_RET_LOG(isInited_, ERR_ILLEGAL_STATE, "not inited!");
211 
212     std::lock_guard<std::mutex> lock(statusLock_);
213     CHECK_AND_RETURN_RET_LOG(streamStatus_->load() == STREAM_STOPPING,
214         ERR_ILLEGAL_STATE, "Stop failed, invalid status.");
215     if (processConfig_.audioMode != AUDIO_MODE_PLAYBACK && needCheckBackground_) {
216         uint32_t tokenId = processConfig_.appInfo.appTokenId;
217         PermissionUtil::NotifyStop(tokenId, sessionId_);
218     }
219     for (size_t i = 0; i < listenerList_.size(); i++) {
220         listenerList_[i]->OnPause(this); // notify endpoint?
221     }
222 
223     AUDIO_INFO_LOG("Stop in server success!");
224     return SUCCESS;
225 }
226 
Release(bool isSwitchStream)227 int32_t AudioProcessInServer::Release(bool isSwitchStream)
228 {
229     CHECK_AND_RETURN_RET_LOG(isInited_, ERR_ILLEGAL_STATE, "not inited or already released");
230     UnscheduleReportData(processConfig_.appInfo.appPid, clientTid_, clientBundleName_.c_str());
231     clientThreadPriorityRequested_ = false;
232     isInited_ = false;
233     std::lock_guard<std::mutex> lock(statusLock_);
234     CHECK_AND_RETURN_RET_LOG(releaseCallback_ != nullptr, ERR_OPERATION_FAILED, "Failed: no service to notify.");
235 
236     if (processConfig_.audioMode != AUDIO_MODE_PLAYBACK && needCheckBackground_) {
237         uint32_t tokenId = processConfig_.appInfo.appTokenId;
238         PermissionUtil::NotifyStop(tokenId, sessionId_);
239     }
240     int32_t ret = releaseCallback_->OnProcessRelease(this, isSwitchStream);
241     AUDIO_INFO_LOG("notify service release result: %{public}d", ret);
242     return SUCCESS;
243 }
244 
ProcessDeathRecipient(AudioProcessInServer * processInServer,ProcessReleaseCallback * processHolder)245 ProcessDeathRecipient::ProcessDeathRecipient(AudioProcessInServer *processInServer,
246     ProcessReleaseCallback *processHolder)
247 {
248     processInServer_ = processInServer;
249     processHolder_ = processHolder;
250 }
251 
OnRemoteDied(const wptr<IRemoteObject> & remote)252 void ProcessDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
253 {
254     CHECK_AND_RETURN_LOG(processHolder_ != nullptr, "processHolder_ is null.");
255     int32_t ret = processHolder_->OnProcessRelease(processInServer_);
256     AUDIO_INFO_LOG("OnRemoteDied, call release ret: %{public}d", ret);
257 }
258 
RegisterProcessCb(sptr<IRemoteObject> object)259 int32_t AudioProcessInServer::RegisterProcessCb(sptr<IRemoteObject> object)
260 {
261     sptr<IProcessCb> processCb = iface_cast<IProcessCb>(object);
262     CHECK_AND_RETURN_RET_LOG(processCb != nullptr, ERR_INVALID_PARAM, "RegisterProcessCb obj cast failed");
263     bool result = object->AddDeathRecipient(new ProcessDeathRecipient(this, releaseCallback_));
264     CHECK_AND_RETURN_RET_LOG(result, ERR_OPERATION_FAILED, "AddDeathRecipient failed.");
265 
266     return SUCCESS;
267 }
268 
SetInnerCapState(bool isInnerCapped)269 void AudioProcessInServer::SetInnerCapState(bool isInnerCapped)
270 {
271     AUDIO_INFO_LOG("process[%{public}u] innercapped: %{public}s", sessionId_, isInnerCapped ? "true" : "false");
272     isInnerCapped_ = isInnerCapped;
273 }
274 
GetInnerCapState()275 bool AudioProcessInServer::GetInnerCapState()
276 {
277     return isInnerCapped_;
278 }
279 
GetAppInfo()280 AppInfo AudioProcessInServer::GetAppInfo()
281 {
282     return processConfig_.appInfo;
283 }
284 
GetConvertedBuffer()285 BufferDesc &AudioProcessInServer::GetConvertedBuffer()
286 {
287     return convertedBuffer_;
288 }
289 
Dump(int fd,const std::vector<std::u16string> & args)290 int AudioProcessInServer::Dump(int fd, const std::vector<std::u16string> &args)
291 {
292     return SUCCESS;
293 }
294 
Dump(std::string & dumpString)295 void AudioProcessInServer::Dump(std::string &dumpString)
296 {
297     AppendFormat(dumpString, "\n  - uid: %d\n", processConfig_.appInfo.appUid);
298     AppendFormat(dumpString, "- pid: %d\n", processConfig_.appInfo.appUid);
299     dumpString += "process info:\n";
300     dumpString += "stream info:\n";
301     AppendFormat(dumpString, "  - samplingRate: %d\n", processConfig_.streamInfo.samplingRate);
302     AppendFormat(dumpString, "  - channels: %d\n", processConfig_.streamInfo.channels);
303     AppendFormat(dumpString, "  - format: %d\n", processConfig_.streamInfo.format);
304     AppendFormat(dumpString, "  - encoding: %d\n", processConfig_.streamInfo.encoding);
305     if (streamStatus_ != nullptr) {
306         AppendFormat(dumpString, "  - Status: %d\n", streamStatus_->load());
307     }
308     dumpString += "\n";
309 }
310 
GetStreamBuffer()311 std::shared_ptr<OHAudioBuffer> AudioProcessInServer::GetStreamBuffer()
312 {
313     CHECK_AND_RETURN_RET_LOG(isBufferConfiged_ && processBuffer_ != nullptr,
314         nullptr, "GetStreamBuffer failed:process buffer not config.");
315     return processBuffer_;
316 }
317 
GetStreamInfo()318 AudioStreamInfo AudioProcessInServer::GetStreamInfo()
319 {
320     return processConfig_.streamInfo;
321 }
322 
GetAudioSessionId()323 uint32_t AudioProcessInServer::GetAudioSessionId()
324 {
325     return sessionId_;
326 }
327 
GetAudioStreamType()328 AudioStreamType AudioProcessInServer::GetAudioStreamType()
329 {
330     return processConfig_.streamType;
331 }
332 
GetAudioProcessConfig()333 AudioProcessConfig AudioProcessInServer::GetAudioProcessConfig()
334 {
335     return processConfig_;
336 }
337 
PcmFormatToBits(AudioSampleFormat format)338 inline uint32_t PcmFormatToBits(AudioSampleFormat format)
339 {
340     switch (format) {
341         case SAMPLE_U8:
342             return 1; // 1 byte
343         case SAMPLE_S16LE:
344             return 2; // 2 byte
345         case SAMPLE_S24LE:
346             return 3; // 3 byte
347         case SAMPLE_S32LE:
348             return 4; // 4 byte
349         case SAMPLE_F32LE:
350             return 4; // 4 byte
351         default:
352             return 2; // 2 byte
353     }
354 }
355 
InitBufferStatus()356 int32_t AudioProcessInServer::InitBufferStatus()
357 {
358     CHECK_AND_RETURN_RET_LOG(processBuffer_ != nullptr, ERR_ILLEGAL_STATE,
359         "InitBufferStatus failed, null buffer.");
360 
361     uint32_t spanCount = processBuffer_->GetSpanCount();
362     for (uint32_t i = 0; i < spanCount; i++) {
363         SpanInfo *spanInfo = processBuffer_->GetSpanInfoByIndex(i);
364         CHECK_AND_RETURN_RET_LOG(spanInfo != nullptr, ERR_ILLEGAL_STATE,
365             "InitBufferStatus failed, null spaninfo");
366         spanInfo->spanStatus = SPAN_READ_DONE;
367         spanInfo->offsetInFrame = 0;
368 
369         spanInfo->readStartTime = 0;
370         spanInfo->readDoneTime = 0;
371 
372         spanInfo->writeStartTime = 0;
373         spanInfo->writeDoneTime = 0;
374 
375         spanInfo->volumeStart = 1 << VOLUME_SHIFT_NUMBER; // 65536 for initialize
376         spanInfo->volumeEnd = 1 << VOLUME_SHIFT_NUMBER; // 65536 for initialize
377         spanInfo->isMute = false;
378     }
379     processBuffer_->SetLastWrittenTime(ClockTime::GetCurNano());
380     return SUCCESS;
381 }
382 
ConfigProcessBuffer(uint32_t & totalSizeInframe,uint32_t & spanSizeInframe,DeviceStreamInfo & serverStreamInfo,const std::shared_ptr<OHAudioBuffer> & buffer)383 int32_t AudioProcessInServer::ConfigProcessBuffer(uint32_t &totalSizeInframe,
384     uint32_t &spanSizeInframe, DeviceStreamInfo &serverStreamInfo, const std::shared_ptr<OHAudioBuffer> &buffer)
385 {
386     if (processBuffer_ != nullptr) {
387         AUDIO_INFO_LOG("ConfigProcessBuffer: process buffer already configed!");
388         return SUCCESS;
389     }
390     // check
391     CHECK_AND_RETURN_RET_LOG(totalSizeInframe != 0 && spanSizeInframe != 0 && totalSizeInframe % spanSizeInframe == 0,
392         ERR_INVALID_PARAM, "ConfigProcessBuffer failed: ERR_INVALID_PARAM");
393     CHECK_AND_RETURN_RET_LOG(serverStreamInfo.samplingRate.size() > 0 && serverStreamInfo.channels.size() > 0,
394         ERR_INVALID_PARAM, "Invalid stream info in server");
395     uint32_t spanTime = spanSizeInframe * AUDIO_MS_PER_SECOND / *serverStreamInfo.samplingRate.rbegin();
396     spanSizeInframe_ = spanTime * processConfig_.streamInfo.samplingRate / AUDIO_MS_PER_SECOND;
397     totalSizeInframe_ = totalSizeInframe / spanSizeInframe * spanSizeInframe_;
398 
399     uint32_t channel = processConfig_.streamInfo.channels;
400     uint32_t formatbyte = PcmFormatToBits(processConfig_.streamInfo.format);
401     byteSizePerFrame_ = channel * formatbyte;
402     if (*serverStreamInfo.channels.rbegin() != processConfig_.streamInfo.channels) {
403         size_t spanSizeInByte = 0;
404         if (processConfig_.audioMode == AUDIO_MODE_PLAYBACK) {
405             uint32_t serverByteSize = *serverStreamInfo.channels.rbegin() * PcmFormatToBits(serverStreamInfo.format);
406             spanSizeInByte = static_cast<size_t>(spanSizeInframe * serverByteSize);
407         } else {
408             spanSizeInByte = static_cast<size_t>(spanSizeInframe_ * byteSizePerFrame_);
409         }
410         convertedBuffer_.buffer = new uint8_t[spanSizeInByte];
411         convertedBuffer_.bufLength = spanSizeInByte;
412         convertedBuffer_.dataLength = spanSizeInByte;
413     }
414 
415     if (buffer == nullptr) {
416         // create OHAudioBuffer in server.
417         processBuffer_ = OHAudioBuffer::CreateFromLocal(totalSizeInframe_, spanSizeInframe_, byteSizePerFrame_);
418         CHECK_AND_RETURN_RET_LOG(processBuffer_ != nullptr, ERR_OPERATION_FAILED, "Create process buffer failed.");
419 
420         CHECK_AND_RETURN_RET_LOG(processBuffer_->GetBufferHolder() == AudioBufferHolder::AUDIO_SERVER_SHARED,
421             ERR_ILLEGAL_STATE, "CreateFormLocal in server failed.");
422         AUDIO_INFO_LOG("Config: totalSizeInframe:%{public}d spanSizeInframe:%{public}d byteSizePerFrame:%{public}d",
423             totalSizeInframe_, spanSizeInframe_, byteSizePerFrame_);
424 
425         // we need to clear data buffer to avoid dirty data.
426         memset_s(processBuffer_->GetDataBase(), processBuffer_->GetDataSize(), 0, processBuffer_->GetDataSize());
427         int32_t ret = InitBufferStatus();
428         AUDIO_DEBUG_LOG("clear data buffer, ret:%{public}d", ret);
429     } else {
430         processBuffer_ = buffer;
431         AUDIO_INFO_LOG("ConfigBuffer in server separate, base: %{public}d", *processBuffer_->GetDataBase());
432     }
433 
434     streamStatus_ = processBuffer_->GetStreamStatus();
435     CHECK_AND_RETURN_RET_LOG(streamStatus_ != nullptr, ERR_OPERATION_FAILED, "Create process buffer failed.");
436     isBufferConfiged_ = true;
437     isInited_ = true;
438     return SUCCESS;
439 }
440 
AddProcessStatusListener(std::shared_ptr<IProcessStatusListener> listener)441 int32_t AudioProcessInServer::AddProcessStatusListener(std::shared_ptr<IProcessStatusListener> listener)
442 {
443     std::lock_guard<std::mutex> lock(listenerListLock_);
444     listenerList_.push_back(listener);
445     return SUCCESS;
446 }
447 
RemoveProcessStatusListener(std::shared_ptr<IProcessStatusListener> listener)448 int32_t AudioProcessInServer::RemoveProcessStatusListener(std::shared_ptr<IProcessStatusListener> listener)
449 {
450     std::lock_guard<std::mutex> lock(listenerListLock_);
451     std::vector<std::shared_ptr<IProcessStatusListener>>::iterator it = listenerList_.begin();
452     bool isFind = false;
453     while (it != listenerList_.end()) {
454         if (*it == listener) {
455             listenerList_.erase(it);
456             isFind = true;
457             break;
458         } else {
459             it++;
460         }
461     }
462 
463     AUDIO_INFO_LOG("%{public}s the endpoint.", (isFind ? "find and remove" : "not find"));
464     return SUCCESS;
465 }
466 
RegisterThreadPriority(uint32_t tid,const std::string & bundleName)467 int32_t AudioProcessInServer::RegisterThreadPriority(uint32_t tid, const std::string &bundleName)
468 {
469     if (!clientThreadPriorityRequested_) {
470         clientTid_ = tid;
471         clientBundleName_ = bundleName;
472         ScheduleReportData(processConfig_.appInfo.appPid, tid, bundleName.c_str());
473         return SUCCESS;
474     } else {
475         AUDIO_ERR_LOG("client thread priority requested");
476         return ERR_OPERATION_FAILED;
477     }
478 }
479 
WriterRenderStreamStandbySysEvent(uint32_t sessionId,int32_t standby)480 void AudioProcessInServer::WriterRenderStreamStandbySysEvent(uint32_t sessionId, int32_t standby)
481 {
482     std::shared_ptr<Media::MediaMonitor::EventBean> bean = std::make_shared<Media::MediaMonitor::EventBean>(
483         Media::MediaMonitor::AUDIO, Media::MediaMonitor::STREAM_STANDBY,
484         Media::MediaMonitor::BEHAVIOR_EVENT);
485     bean->Add("STREAMID", static_cast<int32_t>(sessionId));
486     bean->Add("STANDBY", standby);
487     Media::MediaMonitor::MediaMonitorManager::GetInstance().WriteLogMsg(bean);
488 }
489 
WriteDumpFile(void * buffer,size_t bufferSize)490 void AudioProcessInServer::WriteDumpFile(void *buffer, size_t bufferSize)
491 {
492     if (AudioDump::GetInstance().GetVersionType() == BETA_VERSION) {
493         DumpFileUtil::WriteDumpFile(dumpFile_, buffer, bufferSize);
494         AudioCacheMgr::GetInstance().CacheData(dumpFileName_, buffer, bufferSize);
495     }
496 }
497 
SetSilentModeAndMixWithOthers(bool on)498 int32_t AudioProcessInServer::SetSilentModeAndMixWithOthers(bool on)
499 {
500     silentModeAndMixWithOthers_ = on;
501     AUDIO_INFO_LOG("%{public}d", on);
502     return SUCCESS;
503 }
504 
505 } // namespace AudioStandard
506 } // namespace OHOS
507