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 16 #ifndef RAW_STREAM_DATA_H 17 #define RAW_STREAM_DATA_H 18 19 #include "i_stream.h" 20 21 namespace Communication { 22 namespace SoftBus { 23 class RawStreamData : public IStream { 24 public: 25 RawStreamData() = default; 26 explicit RawStreamData(const StreamFrameInfo &frameInfo); 27 ~RawStreamData() override = default; 28 static constexpr int BYTE_TO_BIT = 8; 29 static constexpr int INT_TO_BYTE = 0xff; 30 static constexpr int FRAME_HEADER_LEN = 4; 31 32 int InitStreamData(std::unique_ptr<char[]> buffer, ssize_t bufLen, std::unique_ptr<char[]> extBuffer, 33 ssize_t extLen); 34 35 std::unique_ptr<char[]> GetBuffer() override; 36 ssize_t GetBufferLen() const override; 37 38 static void InsertBufferLength(int num, int length, uint8_t *output); 39 40 private: SetTimeStamp(uint32_t timestamp)41 void SetTimeStamp(uint32_t timestamp) override 42 { 43 static_cast<void>(timestamp); 44 } GetTimeStamp()45 uint32_t GetTimeStamp() const override 46 { 47 return 0; 48 } 49 GetExtBuffer()50 std::unique_ptr<char[]> GetExtBuffer() override 51 { 52 return nullptr; 53 } 54 GetExtBufferLen()55 ssize_t GetExtBufferLen() const override 56 { 57 return 0; 58 } 59 GetSeqNum()60 int GetSeqNum() const override 61 { 62 return 0; 63 } 64 GetStreamId()65 uint32_t GetStreamId() const override 66 { 67 return 0; 68 } 69 GetStreamFrameInfo()70 const StreamFrameInfo* GetStreamFrameInfo() const override 71 { 72 return &streamFrameInfo_; 73 } 74 75 std::unique_ptr<char[]> streamData_ = nullptr; 76 ssize_t streamLen_ = 0; 77 StreamFrameInfo streamFrameInfo_; 78 }; 79 } // namespace SoftBus 80 } // namespace Communication 81 #endif