• 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 "OHAudioBuffer"
17 #endif
18 
19 #include "oh_audio_buffer.h"
20 
21 #include <cinttypes>
22 #include <climits>
23 #include <memory>
24 #include <sys/mman.h>
25 #include "ashmem.h"
26 
27 #include "audio_errors.h"
28 #include "audio_service_log.h"
29 #include "futex_tool.h"
30 #include "audio_utils.h"
31 #include "audio_parcel_helper.h"
32 
33 namespace OHOS {
34 namespace AudioStandard {
OHAudioBuffer(AudioBufferHolder bufferHolder,uint32_t totalSizeInFrame,uint32_t spanSizeInFrame,uint32_t byteSizePerFrame)35 OHAudioBuffer::OHAudioBuffer(AudioBufferHolder bufferHolder, uint32_t totalSizeInFrame, uint32_t spanSizeInFrame,
36     uint32_t byteSizePerFrame) : ohAudioBufferBase_(bufferHolder, totalSizeInFrame, byteSizePerFrame),
37     spanBasicInfo_(spanSizeInFrame, totalSizeInFrame, byteSizePerFrame),
38     spanInfoList_(nullptr)
39 {
40     AUDIO_DEBUG_LOG("ctor with holder:%{public}d", bufferHolder);
41 }
42 
~OHAudioBuffer()43 OHAudioBuffer::~OHAudioBuffer()
44 {
45     AUDIO_DEBUG_LOG("enter ~OHAudioBuffer()");
46     spanInfoList_ = nullptr;
47 }
48 
SizeCheck(uint32_t totalSizeInFrame) const49 int32_t OHAudioBuffer::SpanBasicInfo::SizeCheck(uint32_t totalSizeInFrame) const
50 {
51     if (spanSizeInFrame_ == 0 || spanSizeInByte_ == 0 || spanConut_ == 0) {
52         AUDIO_ERR_LOG("failed: invalid var.");
53         return ERR_INVALID_PARAM;
54     }
55 
56     if (totalSizeInFrame < spanSizeInFrame_ || ((spanConut_ * spanSizeInFrame_) != totalSizeInFrame)) {
57         AUDIO_ERR_LOG("failed: invalid size.");
58         return ERR_INVALID_PARAM;
59     }
60 
61     return SUCCESS;
62 }
63 
SizeCheck()64 int32_t OHAudioBuffer::SizeCheck()
65 {
66     auto ret = spanBasicInfo_.SizeCheck(ohAudioBufferBase_.GetTotalSizeInFrame());
67     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "failed: invalid");
68 
69     return SUCCESS;
70 }
71 
Init(int dataFd,int infoFd)72 int32_t OHAudioBuffer::Init(int dataFd, int infoFd)
73 {
74     int32_t ret = SizeCheck();
75     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERR_INVALID_PARAM, "failed: invalid size.");
76 
77     auto spanCount = spanBasicInfo_.spanConut_;
78     size_t statusInfoExtSize = spanCount * sizeof(SpanInfo);
79     ret = ohAudioBufferBase_.Init(dataFd, infoFd, statusInfoExtSize);
80     CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERR_INVALID_PARAM, "init base failed.");
81 
82     spanInfoList_ = reinterpret_cast<SpanInfo *>(ohAudioBufferBase_.GetStatusInfoExtPtr());
83     CHECK_AND_RETURN_RET_LOG(spanInfoList_ != nullptr, ERR_INVALID_PARAM, "spaninfolist nullptr");
84 
85     AudioBufferHolder bufferHolder = ohAudioBufferBase_.GetBufferHolder();
86     if (bufferHolder == AUDIO_SERVER_SHARED || bufferHolder == AUDIO_SERVER_ONLY ||bufferHolder ==
87             AUDIO_SERVER_ONLY_WITH_SYNC) {
88         for (uint32_t i = 0; i < spanCount; i++) {
89             spanInfoList_[i].spanStatus.store(SPAN_INVALID);
90         }
91     }
92 
93     AUDIO_DEBUG_LOG("Init done.");
94     return SUCCESS;
95 }
96 
CreateFromLocal(uint32_t totalSizeInFrame,uint32_t spanSizeInFrame,uint32_t byteSizePerFrame)97 std::shared_ptr<OHAudioBuffer> OHAudioBuffer::CreateFromLocal(uint32_t totalSizeInFrame,
98     uint32_t spanSizeInFrame, uint32_t byteSizePerFrame)
99 {
100     AUDIO_DEBUG_LOG("totalSizeInFrame %{public}u, spanSizeInFrame %{public}u, byteSizePerFrame"
101         " %{public}u", totalSizeInFrame, spanSizeInFrame, byteSizePerFrame);
102 
103     AudioBufferHolder bufferHolder = AudioBufferHolder::AUDIO_SERVER_SHARED;
104     std::shared_ptr<OHAudioBuffer> buffer = std::make_shared<OHAudioBuffer>(bufferHolder, totalSizeInFrame,
105         spanSizeInFrame, byteSizePerFrame);
106     CHECK_AND_RETURN_RET_LOG(buffer->Init(INVALID_FD, INVALID_FD) == SUCCESS,
107         nullptr, "failed to init.");
108     return buffer;
109 }
110 
CreateFromRemote(uint32_t totalSizeInFrame,uint32_t spanSizeInFrame,uint32_t byteSizePerFrame,AudioBufferHolder bufferHolder,int dataFd,int infoFd)111 std::shared_ptr<OHAudioBuffer> OHAudioBuffer::CreateFromRemote(uint32_t totalSizeInFrame,
112     uint32_t spanSizeInFrame, uint32_t byteSizePerFrame, AudioBufferHolder bufferHolder,
113     int dataFd, int infoFd)
114 {
115     AUDIO_DEBUG_LOG("dataFd %{public}d, infoFd %{public}d", dataFd, infoFd);
116 
117     int minfd = 2; // ignore stdout, stdin and stderr.
118     CHECK_AND_RETURN_RET_LOG(dataFd > minfd, nullptr, "invalid dataFd: %{public}d", dataFd);
119 
120     if (infoFd != INVALID_FD) {
121         CHECK_AND_RETURN_RET_LOG(infoFd > minfd, nullptr, "invalid infoFd: %{public}d", infoFd);
122     }
123     std::shared_ptr<OHAudioBuffer> buffer = std::make_shared<OHAudioBuffer>(bufferHolder, totalSizeInFrame,
124         spanSizeInFrame, byteSizePerFrame);
125     if (buffer->Init(dataFd, infoFd) != SUCCESS) {
126         AUDIO_ERR_LOG("failed to init.");
127         return nullptr;
128     }
129     return buffer;
130 }
131 
WriteToParcel(const std::shared_ptr<OHAudioBuffer> & buffer,MessageParcel & parcel)132 int32_t OHAudioBuffer::WriteToParcel(const std::shared_ptr<OHAudioBuffer> &buffer, MessageParcel &parcel)
133 {
134     AUDIO_DEBUG_LOG("WriteToParcel start.");
135     AudioBufferHolder bufferHolder = buffer->GetBufferHolder();
136     CHECK_AND_RETURN_RET_LOG(bufferHolder == AudioBufferHolder::AUDIO_SERVER_SHARED ||
137         bufferHolder == AudioBufferHolder::AUDIO_SERVER_INDEPENDENT,
138         ERROR_INVALID_PARAM, "buffer holder error:%{public}d", bufferHolder);
139 
140     auto initInfo = buffer->ohAudioBufferBase_.GetInitializationInfo();
141 
142     parcel.WriteUint32(bufferHolder);
143     parcel.WriteUint32(initInfo.totalSizeInFrame);
144     parcel.WriteUint32(buffer->spanBasicInfo_.spanSizeInFrame_);
145     parcel.WriteUint32(initInfo.byteSizePerFrame);
146 
147     parcel.WriteFileDescriptor(initInfo.dataFd);
148     parcel.WriteFileDescriptor(initInfo.infoFd);
149 
150     AUDIO_DEBUG_LOG("WriteToParcel done.");
151     return SUCCESS;
152 }
153 
ReadFromParcel(MessageParcel & parcel)154 std::shared_ptr<OHAudioBuffer> OHAudioBuffer::ReadFromParcel(MessageParcel &parcel)
155 {
156     AUDIO_DEBUG_LOG("ReadFromParcel start.");
157     uint32_t holder = parcel.ReadUint32();
158     AudioBufferHolder bufferHolder = static_cast<AudioBufferHolder>(holder);
159     if (bufferHolder != AudioBufferHolder::AUDIO_SERVER_SHARED &&
160         bufferHolder != AudioBufferHolder::AUDIO_SERVER_INDEPENDENT) {
161         AUDIO_ERR_LOG("ReadFromParcel buffer holder error:%{public}d", bufferHolder);
162         return nullptr;
163     }
164     bufferHolder = bufferHolder == AudioBufferHolder::AUDIO_SERVER_SHARED ?
165          AudioBufferHolder::AUDIO_CLIENT : bufferHolder;
166     uint32_t totalSizeInFrame = parcel.ReadUint32();
167     uint32_t spanSizeInFrame = parcel.ReadUint32();
168     uint32_t byteSizePerFrame = parcel.ReadUint32();
169 
170     int dataFd = parcel.ReadFileDescriptor();
171     int infoFd = parcel.ReadFileDescriptor();
172 
173     std::shared_ptr<OHAudioBuffer> buffer = OHAudioBuffer::CreateFromRemote(totalSizeInFrame, spanSizeInFrame,
174         byteSizePerFrame, bufferHolder, dataFd, infoFd);
175     if (buffer == nullptr) {
176         AUDIO_ERR_LOG("ReadFromParcel failed.");
177     } else if ((totalSizeInFrame != buffer->ohAudioBufferBase_.basicBufferInfo_->totalSizeInFrame) ||
178         (byteSizePerFrame != buffer->ohAudioBufferBase_.basicBufferInfo_->byteSizePerFrame)) {
179         AUDIO_WARNING_LOG("data in shared memory diff.");
180     } else {
181         AUDIO_DEBUG_LOG("Read some data done.");
182     }
183     CloseFd(dataFd);
184     CloseFd(infoFd);
185     AUDIO_DEBUG_LOG("ReadFromParcel done.");
186     return buffer;
187 }
188 
Marshalling(Parcel & parcel) const189 bool OHAudioBuffer::Marshalling(Parcel &parcel) const
190 {
191     AudioBufferHolder bufferHolder = ohAudioBufferBase_.GetBufferHolder();
192     CHECK_AND_RETURN_RET_LOG(bufferHolder == AudioBufferHolder::AUDIO_SERVER_SHARED ||
193         bufferHolder == AudioBufferHolder::AUDIO_SERVER_INDEPENDENT,
194         false, "buffer holder error:%{public}d", bufferHolder);
195     MessageParcel &messageParcel = static_cast<MessageParcel &>(parcel);
196 
197     auto initInfo = ohAudioBufferBase_.GetInitializationInfo();
198 
199     return messageParcel.WriteUint32(bufferHolder) &&
200         messageParcel.WriteUint32(initInfo.totalSizeInFrame) &&
201         messageParcel.WriteUint32(spanBasicInfo_.spanSizeInFrame_) &&
202         messageParcel.WriteUint32(initInfo.byteSizePerFrame) &&
203         messageParcel.WriteFileDescriptor(initInfo.dataFd) &&
204         messageParcel.WriteFileDescriptor(initInfo.infoFd);
205 }
206 
Unmarshalling(Parcel & parcel)207 OHAudioBuffer *OHAudioBuffer::Unmarshalling(Parcel &parcel)
208 {
209     MessageParcel &messageParcel = static_cast<MessageParcel &>(parcel);
210     uint32_t holder = messageParcel.ReadUint32();
211     AudioBufferHolder bufferHolder = static_cast<AudioBufferHolder>(holder);
212     if (bufferHolder != AudioBufferHolder::AUDIO_SERVER_SHARED &&
213         bufferHolder != AudioBufferHolder::AUDIO_SERVER_INDEPENDENT) {
214         AUDIO_ERR_LOG("ReadFromParcel buffer holder error:%{public}d", bufferHolder);
215         return nullptr;
216     }
217 
218     bufferHolder = bufferHolder == AudioBufferHolder::AUDIO_SERVER_SHARED ?
219          AudioBufferHolder::AUDIO_CLIENT : bufferHolder;
220     uint32_t totalSizeInFrame = messageParcel.ReadUint32();
221     uint32_t spanSizeInFrame = messageParcel.ReadUint32();
222     uint32_t byteSizePerFrame = messageParcel.ReadUint32();
223 
224     int dataFd = messageParcel.ReadFileDescriptor();
225     int infoFd = messageParcel.ReadFileDescriptor();
226 
227     int minfd = 2; // ignore stdout, stdin and stderr.
228     CHECK_AND_RETURN_RET_LOG(dataFd > minfd, nullptr, "invalid dataFd: %{public}d", dataFd);
229 
230     if (infoFd != INVALID_FD) {
231         CHECK_AND_RETURN_RET_LOG(infoFd > minfd, nullptr, "invalid infoFd: %{public}d", infoFd);
232     }
233     auto buffer = new(std::nothrow) OHAudioBuffer(bufferHolder, totalSizeInFrame,
234         spanSizeInFrame, byteSizePerFrame);
235     CHECK_AND_RETURN_RET_LOG(buffer != nullptr, nullptr, "failed to create");
236     if (buffer == nullptr || buffer->Init(dataFd, infoFd) != SUCCESS ||
237         buffer->ohAudioBufferBase_.basicBufferInfo_ == nullptr) {
238         AUDIO_ERR_LOG("failed to init.");
239         if (buffer != nullptr) delete buffer;
240         CloseFd(dataFd);
241         CloseFd(infoFd);
242         return nullptr;
243     }
244 
245     if ((totalSizeInFrame != buffer->ohAudioBufferBase_.basicBufferInfo_->totalSizeInFrame) ||
246         (byteSizePerFrame != buffer->ohAudioBufferBase_.basicBufferInfo_->byteSizePerFrame)) {
247         AUDIO_WARNING_LOG("data in shared memory diff.");
248     } else {
249         AUDIO_DEBUG_LOG("Read some data done.");
250     }
251     CloseFd(dataFd);
252     CloseFd(infoFd);
253     return buffer;
254 }
255 
256 
GetBufferHolder()257 AudioBufferHolder OHAudioBuffer::GetBufferHolder()
258 {
259     return ohAudioBufferBase_.GetBufferHolder();
260 }
261 
GetSizeParameter(uint32_t & totalSizeInFrame,uint32_t & spanSizeInFrame,uint32_t & byteSizePerFrame)262 int32_t OHAudioBuffer::GetSizeParameter(uint32_t &totalSizeInFrame, uint32_t &spanSizeInFrame,
263     uint32_t &byteSizePerFrame)
264 {
265     ohAudioBufferBase_.GetSizeParameter(totalSizeInFrame, byteSizePerFrame);
266     spanSizeInFrame = spanBasicInfo_.spanSizeInFrame_;
267 
268     return SUCCESS;
269 }
270 
GetStreamStatus()271 std::atomic<StreamStatus> *OHAudioBuffer::GetStreamStatus()
272 {
273     return ohAudioBufferBase_.GetStreamStatus();
274 }
275 
276 
GetStreamVolume()277 float OHAudioBuffer::GetStreamVolume()
278 {
279     return ohAudioBufferBase_.GetStreamVolume();
280 }
281 
SetStreamVolume(float streamVolume)282 bool OHAudioBuffer::SetStreamVolume(float streamVolume)
283 {
284     return ohAudioBufferBase_.SetStreamVolume(streamVolume);
285 }
286 
GetMuteFactor()287 float OHAudioBuffer::GetMuteFactor()
288 {
289     return ohAudioBufferBase_.GetMuteFactor();
290 }
291 
SetMuteFactor(float muteFactor)292 bool OHAudioBuffer::SetMuteFactor(float muteFactor)
293 {
294     return ohAudioBufferBase_.SetMuteFactor(muteFactor);
295 }
296 
GetDuckFactor()297 float OHAudioBuffer::GetDuckFactor()
298 {
299     return ohAudioBufferBase_.GetDuckFactor();
300 }
301 
SetDuckFactor(float duckFactor)302 bool OHAudioBuffer::SetDuckFactor(float duckFactor)
303 {
304     return ohAudioBufferBase_.SetDuckFactor(duckFactor);
305 }
306 
GetUnderrunCount()307 uint32_t OHAudioBuffer::GetUnderrunCount()
308 {
309     return ohAudioBufferBase_.GetUnderrunCount();
310 }
311 
SetUnderrunCount(uint32_t count)312 bool OHAudioBuffer::SetUnderrunCount(uint32_t count)
313 {
314     return ohAudioBufferBase_.SetUnderrunCount(count);
315 }
316 
GetHandleInfo(uint64_t & frames,int64_t & nanoTime)317 bool OHAudioBuffer::GetHandleInfo(uint64_t &frames, int64_t &nanoTime)
318 {
319     return ohAudioBufferBase_.GetHandleInfo(frames, nanoTime);
320 }
321 
SetHandleInfo(uint64_t frames,int64_t nanoTime)322 void OHAudioBuffer::SetHandleInfo(uint64_t frames, int64_t nanoTime)
323 {
324     ohAudioBufferBase_.SetHandleInfo(frames, nanoTime);
325 }
326 
GetWritableDataFrames()327 int32_t OHAudioBuffer::GetWritableDataFrames()
328 {
329     return ohAudioBufferBase_.GetWritableDataFrames();
330 }
331 
ResetCurReadWritePos(uint64_t readFrame,uint64_t writeFrame,bool wakeFutex)332 int32_t OHAudioBuffer::ResetCurReadWritePos(uint64_t readFrame, uint64_t writeFrame, bool wakeFutex)
333 {
334     return ohAudioBufferBase_.ResetCurReadWritePos(readFrame, writeFrame, wakeFutex);
335 }
336 
CheckWriteOrReadFrame(uint64_t writeOrReadFrame)337 bool OHAudioBuffer::CheckWriteOrReadFrame(uint64_t writeOrReadFrame)
338 {
339     uint32_t spanSizeInFrame = spanBasicInfo_.spanSizeInFrame_;
340 
341     if ((spanSizeInFrame == 0) || ((writeOrReadFrame % spanSizeInFrame) != 0)) {
342         AUDIO_ERR_LOG("spanSizeInFrame: %{public}u writeOrReadFrame: %{public}" PRIu64 "", spanSizeInFrame,
343             writeOrReadFrame);
344         return false;
345     }
346 
347     return true;
348 }
349 
GetCurWriteFrame()350 uint64_t OHAudioBuffer::GetCurWriteFrame()
351 {
352     return ohAudioBufferBase_.GetCurWriteFrame();
353 }
354 
GetCurReadFrame()355 uint64_t OHAudioBuffer::GetCurReadFrame()
356 {
357     return ohAudioBufferBase_.GetCurReadFrame();
358 }
359 
SetCurWriteFrame(uint64_t writeFrame,bool wakeFutex)360 int32_t OHAudioBuffer::SetCurWriteFrame(uint64_t writeFrame, bool wakeFutex)
361 {
362     CHECK_AND_RETURN_RET_LOG(CheckWriteOrReadFrame(writeFrame), ERR_INVALID_PARAM,
363         "Invalid writeFrame: %{public}" PRIu64 "", writeFrame);
364     return ohAudioBufferBase_.SetCurWriteFrame(writeFrame, wakeFutex);
365 }
366 
SetCurReadFrame(uint64_t readFrame,bool wakeFutex)367 int32_t OHAudioBuffer::SetCurReadFrame(uint64_t readFrame, bool wakeFutex)
368 {
369     CHECK_AND_RETURN_RET_LOG(CheckWriteOrReadFrame(readFrame), ERR_INVALID_PARAM,
370         "Invalid readFrame: %{public}" PRIu64 "", readFrame);
371     return ohAudioBufferBase_.SetCurReadFrame(readFrame, wakeFutex);
372 }
373 
GetSessionId()374 uint32_t OHAudioBuffer::GetSessionId()
375 {
376     return ohAudioBufferBase_.GetSessionId();
377 }
378 
SetSessionId(uint32_t sessionId)379 int32_t OHAudioBuffer::SetSessionId(uint32_t sessionId)
380 {
381     return ohAudioBufferBase_.SetSessionId(sessionId);
382 }
383 
GetWriteBuffer(uint64_t writePosInFrame,BufferDesc & bufferDesc)384 int32_t OHAudioBuffer::GetWriteBuffer(uint64_t writePosInFrame, BufferDesc &bufferDesc)
385 {
386     size_t offset;
387     int32_t ret = ohAudioBufferBase_.GetOffsetByFrameForWrite(writePosInFrame, offset);
388     if (ret != SUCCESS) {
389         return ret;
390     }
391 
392     auto spanSizeInByte = spanBasicInfo_.spanSizeInByte_;
393     size_t fixedOffset = (offset / spanSizeInByte) * spanSizeInByte;
394 
395     return ohAudioBufferBase_.TryGetContinuousBufferByOffset(fixedOffset, spanSizeInByte, bufferDesc);
396 }
397 
GetReadbuffer(uint64_t readPosInFrame,BufferDesc & bufferDesc)398 int32_t OHAudioBuffer::GetReadbuffer(uint64_t readPosInFrame, BufferDesc &bufferDesc)
399 {
400     size_t offset;
401     int32_t ret = ohAudioBufferBase_.GetOffsetByFrameForRead(readPosInFrame, offset);
402     if (ret != SUCCESS) {
403         return ret;
404     }
405 
406     auto spanSizeInByte = spanBasicInfo_.spanSizeInByte_;
407     size_t fixedOffset = (offset / spanSizeInByte) * spanSizeInByte;
408 
409     return ohAudioBufferBase_.TryGetContinuousBufferByOffset(fixedOffset, spanSizeInByte, bufferDesc);
410 }
411 
GetSpanInfo(uint64_t posInFrame)412 SpanInfo *OHAudioBuffer::GetSpanInfo(uint64_t posInFrame)
413 {
414     uint64_t basePos = ohAudioBufferBase_.GetBasePosInFrame();
415     uint32_t totalSizeInFrame = ohAudioBufferBase_.GetTotalSizeInFrame();
416     uint64_t maxPos = basePos + totalSizeInFrame + totalSizeInFrame;
417     CHECK_AND_RETURN_RET_LOG((basePos <= posInFrame && posInFrame < maxPos), nullptr, "posInFrame %{public}" PRIu64" "
418         "out of range, basePos %{public}" PRIu64", maxPos %{public}" PRIu64".", posInFrame, basePos, maxPos);
419 
420     uint64_t deltaToBase = posInFrame - basePos;
421     if (deltaToBase >= totalSizeInFrame) {
422         deltaToBase -= totalSizeInFrame;
423     }
424     CHECK_AND_RETURN_RET_LOG(deltaToBase < UINT32_MAX && deltaToBase < totalSizeInFrame, nullptr,"invalid "
425         "deltaToBase, posInFrame %{public}"  PRIu64" basePos %{public}" PRIu64".", posInFrame, basePos);
426 
427     auto spanSizeInFrame = spanBasicInfo_.spanSizeInFrame_;
428     if (spanSizeInFrame > 0) {
429         uint32_t spanIndex = deltaToBase / spanSizeInFrame;
430         auto spanCount = spanBasicInfo_.spanConut_;
431         CHECK_AND_RETURN_RET_LOG(spanIndex < spanCount, nullptr, "invalid spanIndex:%{public}d", spanIndex);
432         return &spanInfoList_[spanIndex];
433     }
434     return nullptr;
435 }
436 
GetSpanInfoByIndex(uint32_t spanIndex)437 SpanInfo *OHAudioBuffer::GetSpanInfoByIndex(uint32_t spanIndex)
438 {
439     auto spanCount = spanBasicInfo_.spanConut_;
440     CHECK_AND_RETURN_RET_LOG(spanIndex < spanCount, nullptr, "invalid spanIndex:%{public}d", spanIndex);
441     return &spanInfoList_[spanIndex];
442 }
443 
GetSpanCount()444 uint32_t OHAudioBuffer::GetSpanCount()
445 {
446     return spanBasicInfo_.spanConut_;
447 }
448 
GetLastWrittenTime()449 int64_t OHAudioBuffer::GetLastWrittenTime()
450 {
451     return ohAudioBufferBase_.GetLastWrittenTime();
452 }
453 
SetLastWrittenTime(int64_t time)454 void OHAudioBuffer::SetLastWrittenTime(int64_t time)
455 {
456     ohAudioBufferBase_.SetLastWrittenTime(time);
457 }
458 
GetSyncWriteFrame()459 uint32_t OHAudioBuffer::GetSyncWriteFrame()
460 {
461     return ohAudioBufferBase_.GetSyncWriteFrame();
462 }
463 
SetSyncWriteFrame(uint32_t writeFrame)464 bool OHAudioBuffer::SetSyncWriteFrame(uint32_t writeFrame)
465 {
466     return ohAudioBufferBase_.SetSyncWriteFrame(writeFrame);
467 }
468 
GetSyncReadFrame()469 uint32_t OHAudioBuffer::GetSyncReadFrame()
470 {
471     return ohAudioBufferBase_.GetSyncReadFrame();
472 }
473 
SetSyncReadFrame(uint32_t readFrame)474 bool OHAudioBuffer::SetSyncReadFrame(uint32_t readFrame)
475 {
476     return ohAudioBufferBase_.SetSyncReadFrame(readFrame);
477 }
478 
GetFutex()479 std::atomic<uint32_t> *OHAudioBuffer::GetFutex()
480 {
481     return ohAudioBufferBase_.GetFutex();
482 }
483 
GetDataBase()484 uint8_t *OHAudioBuffer::GetDataBase()
485 {
486     return ohAudioBufferBase_.GetDataBase();
487 }
488 
GetDataSize()489 size_t OHAudioBuffer::GetDataSize()
490 {
491     return ohAudioBufferBase_.GetDataSize();
492 }
493 
GetRestoreInfo(RestoreInfo & restoreInfo)494 void OHAudioBuffer::GetRestoreInfo(RestoreInfo &restoreInfo)
495 {
496     ohAudioBufferBase_.GetRestoreInfo(restoreInfo);
497 }
498 
SetRestoreInfo(RestoreInfo restoreInfo)499 void OHAudioBuffer::SetRestoreInfo(RestoreInfo restoreInfo)
500 {
501     ohAudioBufferBase_.SetRestoreInfo(restoreInfo);
502 }
503 
GetTimeStampInfo(uint64_t & position,uint64_t & timeStamp)504 void OHAudioBuffer::GetTimeStampInfo(uint64_t &position, uint64_t &timeStamp)
505 {
506     ohAudioBufferBase_.GetTimeStampInfo(position, timeStamp);
507 }
508 
SetTimeStampInfo(uint64_t position,uint64_t timeStamp)509 void OHAudioBuffer::SetTimeStampInfo(uint64_t position, uint64_t timeStamp)
510 {
511     ohAudioBufferBase_.SetTimeStampInfo(position, timeStamp);
512 }
513 
514 // Compare and swap restore status. If current restore status is NEED_RESTORE, turn it into RESTORING
515 // to avoid multiple restore.
CheckRestoreStatus()516 RestoreStatus OHAudioBuffer::CheckRestoreStatus()
517 {
518     return ohAudioBufferBase_.CheckRestoreStatus();
519 }
520 
521 // Allow client to set restore status to NO_NEED_FOR_RESTORE if unnecessary restore happens. Restore status
522 // can be set to NEED_RESTORE only when it is currently NO_NEED_FOR_RESTORE(and vice versa).
SetRestoreStatus(RestoreStatus restoreStatus)523 RestoreStatus OHAudioBuffer::SetRestoreStatus(RestoreStatus restoreStatus)
524 {
525     return ohAudioBufferBase_.SetRestoreStatus(restoreStatus);
526 }
527 
SetStopFlag(bool isNeedStop)528 void OHAudioBuffer::SetStopFlag(bool isNeedStop)
529 {
530     ohAudioBufferBase_.SetStopFlag(isNeedStop);
531 }
532 
GetStopFlag() const533 bool OHAudioBuffer::GetStopFlag() const
534 {
535     return ohAudioBufferBase_.GetStopFlag();
536 }
537 
WaitFor(int64_t timeoutInNs,const OnIndexChange & pred)538 FutexCode OHAudioBuffer::WaitFor(int64_t timeoutInNs, const OnIndexChange &pred)
539 {
540     return ohAudioBufferBase_.WaitFor(timeoutInNs, pred);
541 }
542 } // namespace AudioStandard
543 } // namespace OHOS
544