• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef OHOS_DAUDIO_RING_BUFFER_H
17 #define OHOS_DAUDIO_RING_BUFFER_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "daudio_constants.h"
23 #include "daudio_errorcode.h"
24 #include "daudio_log.h"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
28 class DaudioRingBuffer {
29 public:
30     DaudioRingBuffer() = default;
31     ~DaudioRingBuffer();
32     int32_t RingBufferInit(uint8_t *&data);
33     int32_t RingBufferInsert(uint8_t *data, int32_t len);
34     int32_t RingBufferGetData(uint8_t *data, int32_t len);
35     bool CanBufferReadLen(int32_t readLen);
36 
37 private:
38     bool GetFullState();
39     bool GetEmptyState();
40     int32_t RingBufferInsertOnce(uint8_t *data, int32_t len);
41     int32_t RingBufferGetDataOnce(uint8_t *data, int32_t len);
42 
43 private:
44     const int32_t RINGBUFFERLEN = 40960;
45     const int32_t DAUDIO_DATA_SIZE = 4096;
46     uint8_t *array_ = nullptr;
47     int32_t writePos_ = 0;
48     int32_t readPos_ = 0;
49     int32_t tag_ = 0;
50 };
51 } // namespace DistributedHardware
52 } // namespace OHOS
53 #endif // OHOS_DAUDIO_RING_BUFFER_H