1 /* 2 * Copyright (C) 2021 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 A2DP_SHARED_BUFFER_H 16 #define A2DP_SHARED_BUFFER_H 17 #include <cstdint> 18 #include <cstdlib> 19 #include <mutex> 20 #include "a2dp_encoder_sbc.h" 21 22 namespace OHOS { 23 namespace bluetooth { 24 class A2dpSharedBuffer { 25 public: 26 A2dpSharedBuffer(); 27 uint32_t Read(uint8_t *buf, uint32_t len); 28 uint32_t Write(const uint8_t *buf, uint32_t len); 29 void Reset(); 30 void SetValid(bool isValid); 31 ~A2dpSharedBuffer(); 32 private: 33 uint32_t cap_; 34 uint8_t buf_[A2DP_SBC_MAX_PACKET_SIZE * FRAME_THREE] = {}; 35 uint8_t shiftBuf_[A2DP_SBC_MAX_PACKET_SIZE * FRAME_THREE] = {}; 36 uint32_t size_; 37 std::mutex mutex_; 38 bool isValid_ = false; 39 }; 40 } // namespace bluetooth 41 } // namespace OHOS 42 43 #endif // A2DP_SHARED_BUFFER_H