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