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 STREAM_COMMON_DATA_H 17 #define STREAM_COMMON_DATA_H 18 19 #include "i_stream.h" 20 21 namespace Communication { 22 namespace SoftBus { 23 class StreamCommonData : public IStream { 24 public: 25 StreamCommonData() = default; 26 StreamCommonData(uint32_t streamId, uint16_t seq, const StreamFrameInfo& frameInfo); 27 28 ~StreamCommonData() override = default; 29 30 // 应用调用生成流数据。 31 int InitStreamData(std::unique_ptr<char[]> inputBuf, ssize_t bufSize, std::unique_ptr<char[]> inputExt, 32 ssize_t extSize); 33 SetTimeStamp(uint32_t timestamp)34 void SetTimeStamp(uint32_t timestamp) override 35 { 36 static_cast<void>(timestamp); 37 } 38 GetTimeStamp()39 virtual uint32_t GetTimeStamp() const override 40 { 41 return 0; 42 } 43 GetBuffer()44 std::unique_ptr<char[]> GetBuffer() override 45 { 46 return std::unique_ptr<char[]>(streamData_.release()); 47 } 48 GetBufferLen()49 ssize_t GetBufferLen() const override 50 { 51 return streamLen_; 52 } 53 GetExtBuffer()54 std::unique_ptr<char[]> GetExtBuffer() override 55 { 56 return std::unique_ptr<char[]>(extBuf_.release()); 57 } 58 GetExtBufferLen()59 ssize_t GetExtBufferLen() const override 60 { 61 return extBufLen_; 62 } 63 GetSeqNum()64 int GetSeqNum() const override 65 { 66 return curSeqNum_; 67 } 68 GetStreamId()69 uint32_t GetStreamId() const override 70 { 71 return curStreamId_; 72 } 73 GetStreamFrameInfo()74 const StreamFrameInfo* GetStreamFrameInfo() const override 75 { 76 return &streamFrameInfo_; 77 } 78 79 protected: 80 std::unique_ptr<char[]> streamData_ = nullptr; 81 ssize_t streamLen_ = 0; 82 83 /* 84 * 额外buffer信息,随着帧一起传输到对端 85 */ 86 std::unique_ptr<char[]> extBuf_ = nullptr; 87 ssize_t extBufLen_ = 0; 88 89 uint16_t curSeqNum_ = 0; 90 uint32_t curStreamId_ = 0; 91 92 StreamFrameInfo streamFrameInfo_; 93 }; 94 } // namespace SoftBus 95 } // namespace Communication 96 97 #endif