• 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 
16 #include <chrono>
17 #include <thread>
18 #include <vector>
19 
20 #include "audio_errors.h"
21 #include "audio_log.h"
22 #include "audio_utils.h"
23 
24 #include "fast_audio_stream.h"
25 
26 using namespace std;
27 
28 namespace OHOS {
29 namespace AudioStandard {
FastAudioStream(AudioStreamType eStreamType,AudioMode eMode,int32_t appUid)30 FastAudioStream::FastAudioStream(AudioStreamType eStreamType, AudioMode eMode, int32_t appUid)
31     : eStreamType_(eStreamType),
32       eMode_(eMode),
33       state_(NEW),
34       renderMode_(RENDER_MODE_CALLBACK),
35       captureMode_(CAPTURE_MODE_CALLBACK)
36 {
37     AUDIO_INFO_LOG("FastAudioStream ctor, appUID = %{public}d", appUid);
38     audioStreamTracker_ =  std::make_unique<AudioStreamTracker>(eMode, appUid);
39     AUDIO_DEBUG_LOG("AudioStreamTracker created");
40 }
41 
~FastAudioStream()42 FastAudioStream::~FastAudioStream()
43 {
44     if (state_ != RELEASED && state_ != NEW) {
45         ReleaseAudioStream(false);
46     }
47 }
48 
SetClientID(int32_t clientPid,int32_t clientUid)49 void FastAudioStream::SetClientID(int32_t clientPid, int32_t clientUid)
50 {
51     AUDIO_INFO_LOG("Set client PID: %{public}d, UID: %{public}d", clientPid, clientUid);
52     clientPid_ = clientPid;
53     clientUid_ = clientUid;
54 }
55 
SetRendererInfo(const AudioRendererInfo & rendererInfo)56 void FastAudioStream::SetRendererInfo(const AudioRendererInfo &rendererInfo)
57 {
58     rendererInfo_ = rendererInfo;
59 }
60 
SetCapturerInfo(const AudioCapturerInfo & capturerInfo)61 void FastAudioStream::SetCapturerInfo(const AudioCapturerInfo &capturerInfo)
62 {
63     capturerInfo_ = capturerInfo;
64 }
65 
SetAudioStreamInfo(const AudioStreamParams info,const std::shared_ptr<AudioClientTracker> & proxyObj)66 int32_t FastAudioStream::SetAudioStreamInfo(const AudioStreamParams info,
67     const std::shared_ptr<AudioClientTracker> &proxyObj)
68 {
69     AUDIO_INFO_LOG("FastAudioStreamInfo, Sampling rate: %{public}d, channels: %{public}d, format: %{public}d,"
70         " stream type: %{public}d", info.samplingRate, info.channels, info.format, eStreamType_);
71     if (processClient_ != nullptr) {
72         AUDIO_ERR_LOG("Process is already inited, reset stream info is not supported.");
73         return ERR_INVALID_OPERATION;
74     }
75     streamInfo_ = info;
76     if (state_ != NEW) {
77         AUDIO_INFO_LOG("FastAudioStream: State is not new, release existing stream");
78         StopAudioStream();
79         ReleaseAudioStream(false);
80     }
81     AudioProcessConfig config;
82     config.appInfo.appPid = clientPid_;
83     config.appInfo.appUid = clientUid_;
84     config.audioMode = eMode_;
85     config.streamInfo.channels = static_cast<AudioChannel>(info.channels);
86     config.streamInfo.encoding = static_cast<AudioEncodingType>(info.encoding);
87     config.streamInfo.format = static_cast<AudioSampleFormat>(info.format);
88     config.streamInfo.samplingRate = static_cast<AudioSamplingRate>(info.samplingRate);
89     config.streamType = eStreamType_;
90     if (eMode_ == AUDIO_MODE_PLAYBACK) {
91         AUDIO_DEBUG_LOG("FastAudioStream: Initialize playback");
92         config.rendererInfo.contentType = rendererInfo_.contentType;
93         config.rendererInfo.streamUsage = rendererInfo_.streamUsage;
94         config.rendererInfo.rendererFlags = STREAM_FLAG_FAST;
95     } else if (eMode_ == AUDIO_MODE_RECORD) {
96         AUDIO_DEBUG_LOG("FastAudioStream: Initialize recording");
97         config.capturerInfo.sourceType = capturerInfo_.sourceType;
98         config.capturerInfo.capturerFlags = STREAM_FLAG_FAST;
99     } else {
100         AUDIO_ERR_LOG("FastAudioStream: error eMode.");
101         return ERR_INVALID_OPERATION;
102     }
103     CHECK_AND_RETURN_RET_LOG(AudioProcessInClient::CheckIfSupport(config), ERR_INVALID_PARAM,
104         "Stream is not supported.");
105     processconfig_ = config;
106     processClient_ = AudioProcessInClient::Create(config);
107     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, ERR_INVALID_PARAM,
108         "Client test creat process client fail.");
109     state_ = PREPARED;
110 
111     if (audioStreamTracker_ != nullptr && audioStreamTracker_.get()) {
112         processClient_->GetSessionID(sessionId_);
113         AUDIO_DEBUG_LOG("AudioStream:Calling register tracker, sessionid = %{public}d", sessionId_);
114         audioStreamTracker_->RegisterTracker(sessionId_, state_, rendererInfo_, capturerInfo_, proxyObj);
115     }
116     return SUCCESS;
117 }
118 
GetAudioStreamInfo(AudioStreamParams & audioStreamInfo)119 int32_t FastAudioStream::GetAudioStreamInfo(AudioStreamParams &audioStreamInfo)
120 {
121     AUDIO_INFO_LOG("GetAudioStreamInfo in");
122     audioStreamInfo = streamInfo_;
123     return SUCCESS;
124 }
125 
CheckRecordingCreate(uint32_t appTokenId,uint64_t appFullTokenId,int32_t appUid)126 bool FastAudioStream::CheckRecordingCreate(uint32_t appTokenId, uint64_t appFullTokenId, int32_t appUid)
127 {
128     AUDIO_INFO_LOG("CheckRecordingCreate in");
129     // note: add support later
130     return true;
131 }
132 
CheckRecordingStateChange(uint32_t appTokenId,uint64_t appFullTokenId,int32_t appUid,AudioPermissionState state)133 bool FastAudioStream::CheckRecordingStateChange(uint32_t appTokenId, uint64_t appFullTokenId, int32_t appUid,
134     AudioPermissionState state)
135 {
136     AUDIO_INFO_LOG("CheckRecordingStateChange in");
137     // note: add support later
138     return true;
139 }
140 
GetAudioSessionID(uint32_t & sessionID)141 int32_t FastAudioStream::GetAudioSessionID(uint32_t &sessionID)
142 {
143     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, ERR_OPERATION_FAILED,
144         "GetAudioSessionID failed: null process");
145     int32_t ret = processClient_->GetSessionID(sessionID);
146     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "GetSessionID error.");
147     return ret;
148 }
149 
GetState()150 State FastAudioStream::GetState()
151 {
152     return state_;
153 }
154 
GetAudioTime(Timestamp & timestamp,Timestamp::Timestampbase base)155 bool FastAudioStream::GetAudioTime(Timestamp &timestamp, Timestamp::Timestampbase base)
156 {
157     CHECK_AND_RETURN_RET_LOG(base == Timestamp::MONOTONIC, false, "GetAudioTime failed: invalid base");
158 
159     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, false, "GetAudioTime failed: null process");
160     int64_t timeSec = 0;
161     int64_t timeNsec = 0;
162     int32_t ret = processClient_->GetAudioTime(timestamp.framePosition, timeSec, timeNsec);
163     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, false, "GetBufferSize error.");
164     timestamp.time.tv_sec = timeSec;
165     timestamp.time.tv_nsec = timeNsec;
166     return true;
167 }
168 
GetBufferSize(size_t & bufferSize)169 int32_t FastAudioStream::GetBufferSize(size_t &bufferSize)
170 {
171     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, ERR_OPERATION_FAILED, "GetBufferSize failed: null process");
172     int32_t ret = processClient_->GetBufferSize(bufferSize);
173     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "GetBufferSize error.");
174     return ret;
175 }
176 
GetFrameCount(uint32_t & frameCount)177 int32_t FastAudioStream::GetFrameCount(uint32_t &frameCount)
178 {
179     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, ERR_OPERATION_FAILED, "GetFrameCount failed: null process");
180     int32_t ret = processClient_->GetFrameCount(frameCount);
181     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "GetFrameCount error.");
182     return ret;
183 }
184 
GetLatency(uint64_t & latency)185 int32_t FastAudioStream::GetLatency(uint64_t &latency)
186 {
187     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, ERR_OPERATION_FAILED, "GetLatency failed: null process");
188     int32_t ret = processClient_->GetLatency(latency);
189     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "GetLatency error.");
190     return ret;
191 }
192 
SetAudioStreamType(AudioStreamType audioStreamType)193 int32_t FastAudioStream::SetAudioStreamType(AudioStreamType audioStreamType)
194 {
195     // Stream type can only be set when create.
196     AUDIO_ERR_LOG("Unsupported operation: SetAudioStreamType");
197     return ERR_INVALID_OPERATION;
198 }
199 
SetVolume(float volume)200 int32_t FastAudioStream::SetVolume(float volume)
201 {
202     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, ERR_OPERATION_FAILED, "SetVolume failed: null process");
203     int32_t ret = processClient_->SetVolume(volume);
204     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "SetVolume error.");
205     return ret;
206 }
207 
GetVolume()208 float FastAudioStream::GetVolume()
209 {
210     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, 1.0f, "SetVolume failed: null process"); // 1.0f for default
211     return processClient_->GetVolume();
212 }
213 
SetRenderRate(AudioRendererRate renderRate)214 int32_t FastAudioStream::SetRenderRate(AudioRendererRate renderRate)
215 {
216     if (RENDER_RATE_NORMAL == renderRate) {
217         return SUCCESS;
218     }
219     AUDIO_ERR_LOG("Unsupported operation: SetRenderRate");
220     return ERR_INVALID_OPERATION;
221 }
222 
GetRenderRate()223 AudioRendererRate FastAudioStream::GetRenderRate()
224 {
225     return renderRate_;
226 }
227 
SetStreamCallback(const std::shared_ptr<AudioStreamCallback> & callback)228 int32_t FastAudioStream::SetStreamCallback(const std::shared_ptr<AudioStreamCallback> &callback)
229 {
230     AUDIO_INFO_LOG("SetStreamCallback in");
231     // note: need add support
232     return SUCCESS;
233 }
234 
SetRenderMode(AudioRenderMode renderMode)235 int32_t FastAudioStream::SetRenderMode(AudioRenderMode renderMode)
236 {
237     if (renderMode != RENDER_MODE_CALLBACK || eMode_ != AUDIO_MODE_PLAYBACK) {
238         AUDIO_ERR_LOG("SetRenderMode is not supported.");
239         return ERR_INVALID_OPERATION;
240     }
241     return SUCCESS;
242 }
243 
GetRenderMode()244 AudioRenderMode FastAudioStream::GetRenderMode()
245 {
246     AUDIO_INFO_LOG("GetRenderMode in");
247     return renderMode_;
248 }
249 
SetRendererWriteCallback(const std::shared_ptr<AudioRendererWriteCallback> & callback)250 int32_t FastAudioStream::SetRendererWriteCallback(const std::shared_ptr<AudioRendererWriteCallback> &callback)
251 {
252     AUDIO_INFO_LOG("SetRendererWriteCallback in.");
253     if (!callback || !processClient_ || eMode_ != AUDIO_MODE_PLAYBACK) {
254         AUDIO_ERR_LOG("SetRendererWriteCallback callback is nullptr");
255         return ERR_INVALID_PARAM;
256     }
257     spkProcClientCb_ = std::make_shared<FastAudioStreamRenderCallback>(callback);
258     int32_t ret = processClient_->SaveDataCallback(spkProcClientCb_);
259     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "Client test save data callback fail, ret %{public}d.", ret);
260     return SUCCESS;
261 }
262 
SetCaptureMode(AudioCaptureMode captureMode)263 int32_t FastAudioStream::SetCaptureMode(AudioCaptureMode captureMode)
264 {
265     if (captureMode != CAPTURE_MODE_CALLBACK || eMode_ != AUDIO_MODE_RECORD) {
266         AUDIO_ERR_LOG("SetCaptureMode is not supported.");
267         return ERR_INVALID_OPERATION;
268     }
269     return SUCCESS;
270 }
271 
GetCaptureMode()272 AudioCaptureMode FastAudioStream::GetCaptureMode()
273 {
274     return captureMode_;
275 }
276 
SetCapturerReadCallback(const std::shared_ptr<AudioCapturerReadCallback> & callback)277 int32_t FastAudioStream::SetCapturerReadCallback(const std::shared_ptr<AudioCapturerReadCallback> &callback)
278 {
279     AUDIO_INFO_LOG("SetCapturerReadCallback in.");
280     if (!callback || !processClient_ || eMode_ != AUDIO_MODE_RECORD) {
281         AUDIO_ERR_LOG("SetCapturerReadCallback, callback or client is nullptr or mode is not record.");
282         return ERR_INVALID_PARAM;
283     }
284     micProcClientCb_ = std::make_shared<FastAudioStreamCaptureCallback>(callback);
285     int32_t ret = processClient_->SaveDataCallback(micProcClientCb_);
286     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "Client save data callback fail, ret %{public}d.", ret);
287     return SUCCESS;
288 }
289 
GetBufferDesc(BufferDesc & bufDesc)290 int32_t FastAudioStream::GetBufferDesc(BufferDesc &bufDesc)
291 {
292     AUDIO_DEBUG_LOG("GetBufferDesc in.");
293     if (!processClient_) {
294         AUDIO_ERR_LOG("spkClient is null.");
295         return ERR_INVALID_OPERATION;
296     }
297     int32_t ret = processClient_->GetBufferDesc(bufDesc);
298     if (ret != SUCCESS || bufDesc.buffer == nullptr || bufDesc.bufLength ==0) {
299         AUDIO_ERR_LOG("GetBufferDesc failed.");
300         return -1;
301     }
302     return SUCCESS;
303 }
304 
GetBufQueueState(BufferQueueState & bufState)305 int32_t FastAudioStream::GetBufQueueState(BufferQueueState &bufState)
306 {
307     AUDIO_INFO_LOG("GetBufQueueState in.");
308     // note: add support
309     return SUCCESS;
310 }
311 
Enqueue(const BufferDesc & bufDesc)312 int32_t FastAudioStream::Enqueue(const BufferDesc &bufDesc)
313 {
314     AUDIO_DEBUG_LOG("Enqueue in");
315     if (!processClient_) {
316         AUDIO_ERR_LOG("spkClient is null.");
317         return ERR_INVALID_OPERATION;
318     }
319     int32_t ret = processClient_->Enqueue(bufDesc);
320     if (ret != SUCCESS) {
321         AUDIO_ERR_LOG("Enqueue failed.");
322         return -1;
323     }
324     return SUCCESS;
325 }
326 
Clear()327 int32_t FastAudioStream::Clear()
328 {
329     AUDIO_INFO_LOG("Clear will do nothing.");
330 
331     return SUCCESS;
332 }
333 
SetLowPowerVolume(float volume)334 int32_t FastAudioStream::SetLowPowerVolume(float volume)
335 {
336     AUDIO_INFO_LOG("SetLowPowerVolume in.");
337     return 1.0f;
338 }
339 
GetLowPowerVolume()340 float FastAudioStream::GetLowPowerVolume()
341 {
342     AUDIO_INFO_LOG("GetLowPowerVolume in.");
343     return 1.0f;
344 }
345 
GetSingleStreamVolume()346 float FastAudioStream::GetSingleStreamVolume()
347 {
348     AUDIO_INFO_LOG("GetSingleStreamVolume in.");
349     return 1.0f;
350 }
351 
GetAudioEffectMode()352 AudioEffectMode FastAudioStream::GetAudioEffectMode()
353 {
354     AUDIO_ERR_LOG("GetAudioEffectMode not supported");
355     return EFFECT_NONE;
356 }
357 
SetAudioEffectMode(AudioEffectMode effectMode)358 int32_t FastAudioStream::SetAudioEffectMode(AudioEffectMode effectMode)
359 {
360     AUDIO_ERR_LOG("SetAudioEffectMode not supported");
361     return ERR_NOT_SUPPORTED;
362 }
363 
GetFramesWritten()364 int64_t FastAudioStream::GetFramesWritten()
365 {
366     int64_t result = -1; // -1 invalid frame
367     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, result, "GetFramesWritten failed: null process");
368     result = processClient_->GetFramesWritten();
369     return result;
370 }
371 
GetFramesRead()372 int64_t FastAudioStream::GetFramesRead()
373 {
374     int64_t result = -1; // -1 invalid frame
375     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, result, "GetFramesRead failed: null process");
376     result = processClient_->GetFramesRead();
377     return result;
378 }
379 
StartAudioStream(StateChangeCmdType cmdType)380 bool FastAudioStream::StartAudioStream(StateChangeCmdType cmdType)
381 {
382     AUDIO_INFO_LOG("StartAudioStream in.");
383     if ((state_ != PREPARED) && (state_ != STOPPED) && (state_ != PAUSED)) {
384         AUDIO_ERR_LOG("StartAudioStream Illegal state:%{public}u", state_);
385         return false;
386     }
387 
388     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, false, "Start failed, process is null.");
389     int32_t ret = ERROR;
390     if (state_ == PAUSED) {
391         ret = processClient_->Resume();
392     } else {
393         ret = processClient_->Start();
394     }
395     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, false, "Client test stop fail, ret %{public}d.", ret);
396     state_ = RUNNING;
397 
398     AUDIO_DEBUG_LOG("StartAudioStream SUCCESS, sessionId: %{public}d", sessionId_);
399 
400     if (audioStreamTracker_ != nullptr && audioStreamTracker_.get()) {
401         AUDIO_DEBUG_LOG("AudioStream:Calling Update tracker for Running");
402         audioStreamTracker_->UpdateTracker(sessionId_, state_, rendererInfo_, capturerInfo_);
403     }
404     return true;
405 }
406 
PauseAudioStream(StateChangeCmdType cmdType)407 bool FastAudioStream::PauseAudioStream(StateChangeCmdType cmdType)
408 {
409     AUDIO_INFO_LOG("PauseAudioStream in");
410     if (state_ != RUNNING) {
411         AUDIO_ERR_LOG("PauseAudioStream: State is not RUNNING. Illegal state:%{public}u", state_);
412         return false;
413     }
414     State oldState = state_;
415 
416     state_ = PAUSED;
417     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, false, "Pause failed, process is null.");
418     int32_t ret = processClient_->Pause();
419     if (ret != SUCCESS) {
420         AUDIO_ERR_LOG("StreamPause fail,ret:%{public}d", ret);
421         state_ = oldState;
422         return false;
423     }
424 
425     AUDIO_DEBUG_LOG("PauseAudioStream SUCCESS, sessionId: %{public}d", sessionId_);
426     if (audioStreamTracker_ != nullptr && audioStreamTracker_.get()) {
427         AUDIO_DEBUG_LOG("AudioStream:Calling Update tracker for Pause");
428         audioStreamTracker_->UpdateTracker(sessionId_, state_, rendererInfo_, capturerInfo_);
429     }
430     return true;
431 }
432 
StopAudioStream()433 bool FastAudioStream::StopAudioStream()
434 {
435     if ((state_ != RUNNING) && (state_ != PAUSED)) {
436         AUDIO_ERR_LOG("StopAudioStream: State is not RUNNING. Illegal state:%{public}u", state_);
437         return false;
438     }
439     State oldState = state_;
440     state_ = STOPPED; // Set it before stopping as Read/Write and Stop can be called from different threads
441 
442     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, false, "Stop failed, process is null.");
443     int32_t ret = processClient_->Stop();
444     if (ret != SUCCESS) {
445         AUDIO_ERR_LOG("StreamStop fail,ret:%{public}d", ret);
446         state_ = oldState;
447         return false;
448     }
449 
450     AUDIO_INFO_LOG("StopAudioStream SUCCESS, sessionId: %{public}d", sessionId_);
451     if (audioStreamTracker_ != nullptr && audioStreamTracker_.get()) {
452         AUDIO_DEBUG_LOG("AudioStream:Calling Update tracker for stop");
453         audioStreamTracker_->UpdateTracker(sessionId_, state_, rendererInfo_, capturerInfo_);
454     }
455     return true;
456 }
457 
FlushAudioStream()458 bool FastAudioStream::FlushAudioStream()
459 {
460     AUDIO_INFO_LOG("FlushAudioStream in.");
461     return true;
462 }
463 
DrainAudioStream()464 bool FastAudioStream::DrainAudioStream()
465 {
466     AUDIO_INFO_LOG("Drain stream SUCCESS");
467     return true;
468 }
469 
ReleaseAudioStream(bool releaseRunner)470 bool FastAudioStream::ReleaseAudioStream(bool releaseRunner)
471 {
472     if (state_ == RELEASED || state_ == NEW) {
473         AUDIO_ERR_LOG("Illegal state: state = %{public}u", state_);
474         return false;
475     }
476     // If state_ is RUNNING try to Stop it first and Release
477     if (state_ == RUNNING) {
478         StopAudioStream();
479     }
480 
481     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, false, "Release failed, process is null.");
482     processClient_->Release();
483     state_ = RELEASED;
484     AUDIO_INFO_LOG("ReleaseAudiostream SUCCESS, sessionId: %{public}d", sessionId_);
485     if (audioStreamTracker_ != nullptr && audioStreamTracker_.get()) {
486         AUDIO_DEBUG_LOG("AudioStream:Calling Update tracker for release");
487         audioStreamTracker_->UpdateTracker(sessionId_, state_, rendererInfo_, capturerInfo_);
488     }
489     return true;
490 }
491 
Read(uint8_t & buffer,size_t userSize,bool isBlockingRead)492 int32_t FastAudioStream::Read(uint8_t &buffer, size_t userSize, bool isBlockingRead)
493 {
494     AUDIO_ERR_LOG("Unsupported operation: read");
495     return ERR_INVALID_OPERATION;
496 }
497 
Write(uint8_t * buffer,size_t buffer_size)498 size_t FastAudioStream::Write(uint8_t *buffer, size_t buffer_size)
499 {
500     AUDIO_ERR_LOG("Unsupported operation: Write");
501     return ERR_INVALID_OPERATION;
502 }
503 
GetUnderflowCount()504 uint32_t FastAudioStream::GetUnderflowCount()
505 {
506     AUDIO_INFO_LOG("GetUnderflowCount in.");
507     CHECK_AND_RETURN_RET_LOG(processClient_ != nullptr, 0, "process client is null.");
508     underflowCount_ = processClient_->GetUnderflowCount();
509     return underflowCount_;
510 }
511 
SetRendererPositionCallback(int64_t markPosition,const std::shared_ptr<RendererPositionCallback> & callback)512 void FastAudioStream::SetRendererPositionCallback(int64_t markPosition,
513     const std::shared_ptr<RendererPositionCallback> &callback)
514 {
515     AUDIO_INFO_LOG("Registering render frame position callback mark position");
516     // note: need support
517 }
518 
UnsetRendererPositionCallback()519 void FastAudioStream::UnsetRendererPositionCallback()
520 {
521     AUDIO_INFO_LOG("Unregistering render frame position callback");
522     // note: need support
523 }
524 
SetRendererPeriodPositionCallback(int64_t periodPosition,const std::shared_ptr<RendererPeriodPositionCallback> & callback)525 void FastAudioStream::SetRendererPeriodPositionCallback(int64_t periodPosition,
526     const std::shared_ptr<RendererPeriodPositionCallback> &callback)
527 {
528     AUDIO_INFO_LOG("Registering render period position callback");
529 }
530 
UnsetRendererPeriodPositionCallback()531 void FastAudioStream::UnsetRendererPeriodPositionCallback()
532 {
533     AUDIO_INFO_LOG("Unregistering render period position callback");
534 }
535 
SetCapturerPositionCallback(int64_t markPosition,const std::shared_ptr<CapturerPositionCallback> & callback)536 void FastAudioStream::SetCapturerPositionCallback(int64_t markPosition,
537     const std::shared_ptr<CapturerPositionCallback> &callback)
538 {
539     AUDIO_INFO_LOG("Registering capture frame position callback, mark position");
540 }
541 
UnsetCapturerPositionCallback()542 void FastAudioStream::UnsetCapturerPositionCallback()
543 {
544     AUDIO_INFO_LOG("Unregistering capture frame position callback");
545 }
546 
SetCapturerPeriodPositionCallback(int64_t periodPosition,const std::shared_ptr<CapturerPeriodPositionCallback> & callback)547 void FastAudioStream::SetCapturerPeriodPositionCallback(int64_t periodPosition,
548     const std::shared_ptr<CapturerPeriodPositionCallback> &callback)
549 {
550     AUDIO_INFO_LOG("Registering period position callback");
551 }
552 
UnsetCapturerPeriodPositionCallback()553 void FastAudioStream::UnsetCapturerPeriodPositionCallback()
554 {
555     AUDIO_INFO_LOG("Unregistering period position callback");
556 }
557 
SetRendererSamplingRate(uint32_t sampleRate)558 int32_t FastAudioStream::SetRendererSamplingRate(uint32_t sampleRate)
559 {
560     AUDIO_ERR_LOG("SetRendererSamplingRate  is not supported");
561 
562     return ERR_OPERATION_FAILED;
563 }
564 
GetRendererSamplingRate()565 uint32_t FastAudioStream::GetRendererSamplingRate()
566 {
567     AUDIO_INFO_LOG("GetRendererSamplingRate in");
568     return streamInfo_.samplingRate;
569 }
570 
SetBufferSizeInMsec(int32_t bufferSizeInMsec)571 int32_t FastAudioStream::SetBufferSizeInMsec(int32_t bufferSizeInMsec)
572 {
573     AUDIO_ERR_LOG("SetBufferSizeInMsec is not supported");
574     // note: add support
575     return ERR_NOT_SUPPORTED;
576 }
577 
SetApplicationCachePath(const std::string cachePath)578 void FastAudioStream::SetApplicationCachePath(const std::string cachePath)
579 {
580     AUDIO_INFO_LOG("SetApplicationCachePath to %{public}s", cachePath.c_str());
581 
582     cachePath_ = cachePath;
583 }
SetInnerCapturerState(bool isInnerCapturer)584 void FastAudioStream::SetInnerCapturerState(bool isInnerCapturer)
585 {
586     AUDIO_ERR_LOG("SetInnerCapturerState is not supported");
587 }
588 
SetWakeupCapturerState(bool isWakeupCapturer)589 void FastAudioStream::SetWakeupCapturerState(bool isWakeupCapturer)
590 {
591     AUDIO_ERR_LOG("SetWakeupCapturerState is not supported");
592 }
593 
SetPrivacyType(AudioPrivacyType privacyType)594 void FastAudioStream::SetPrivacyType(AudioPrivacyType privacyType)
595 {
596     AUDIO_ERR_LOG("SetPrivacyType is not supported");
597 }
598 
GetStreamClass()599 IAudioStream::StreamClass FastAudioStream::GetStreamClass()
600 {
601     return IAudioStream::StreamClass::FAST_STREAM;
602 }
603 
SetStreamTrackerState(bool trackerRegisteredState)604 void FastAudioStream::SetStreamTrackerState(bool trackerRegisteredState)
605 {
606     streamTrackerRegistered_ = trackerRegisteredState;
607 }
608 
GetSwitchInfo(IAudioStream::SwitchInfo & info)609 void FastAudioStream::GetSwitchInfo(IAudioStream::SwitchInfo& info)
610 {
611     GetAudioStreamInfo(info.params);
612     info.rendererInfo = rendererInfo_;
613     info.capturerInfo = capturerInfo_;
614     info.eStreamType = eStreamType_;
615     info.state = state_;
616     info.sessionId = sessionId_;
617     info.cachePath = cachePath_;
618 
619     info.clientPid = clientPid_;
620     info.clientUid = clientUid_;
621 
622     info.volume = GetVolume();
623     info.effectMode = GetAudioEffectMode();
624     info.renderMode = renderMode_;
625     info.captureMode = captureMode_;
626     info.renderRate = renderRate_;
627 
628     if (spkProcClientCb_) {
629         info.rendererWriteCallback = spkProcClientCb_->GetRendererWriteCallback();
630     }
631 }
632 
OnHandleData(size_t length)633 void FastAudioStreamRenderCallback::OnHandleData(size_t length)
634 {
635     CHECK_AND_RETURN_LOG(rendererWriteCallback_!= nullptr, "OnHandleData failed: rendererWriteCallback_ is null.");
636     rendererWriteCallback_->OnWriteData(length);
637 }
638 
GetRendererWriteCallback() const639 std::shared_ptr<AudioRendererWriteCallback> FastAudioStreamRenderCallback::GetRendererWriteCallback() const
640 {
641     return rendererWriteCallback_;
642 }
643 
OnHandleData(size_t length)644 void FastAudioStreamCaptureCallback::OnHandleData(size_t length)
645 {
646     CHECK_AND_RETURN_LOG(captureCallback_!= nullptr, "OnHandleData failed: captureCallback_ is null.");
647     captureCallback_->OnReadData(length);
648 }
649 } // namespace AudioStandard
650 } // namespace OHOS
651