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_DEPACKETTIZER_H 17 #define STREAM_DEPACKETTIZER_H 18 19 #include <memory> 20 #include <utility> 21 22 #include "stream_packet_header.h" 23 #include "i_stream.h" 24 25 namespace Communication { 26 namespace SoftBus { 27 class StreamDepacketizer { 28 public: StreamDepacketizer(int type)29 explicit StreamDepacketizer(int type) : streamType_(type) {} 30 virtual ~StreamDepacketizer() = default; 31 32 void DepacketizeHeader(const char *header); 33 void DepacketizeBuffer(char *buffer, uint32_t bufferSize); 34 GetHeaderDataLen()35 uint32_t GetHeaderDataLen() const 36 { 37 return header_.GetDataLen(); 38 } 39 GetFrameInfo()40 StreamFrameInfo GetFrameInfo() const 41 { 42 StreamFrameInfo info; 43 info.streamId = header_.GetStreamId(); 44 info.seqNum = header_.GetSeqNum(); 45 info.level = header_.GetLevel(); 46 info.frameType = NONE; 47 info.seqSubNum = header_.GetSubSeqNum(); 48 info.bitMap = 0; 49 info.timeStamp = header_.GetTimestamp(); 50 info.bitrate = 0; 51 return info; 52 } 53 GetUserExt()54 std::unique_ptr<char[]> GetUserExt() 55 { 56 return tlvs_.GetExtBuffer(); 57 } 58 GetUserExtSize()59 ssize_t GetUserExtSize() const 60 { 61 return tlvs_.GetExtLen(); 62 } 63 GetData()64 std::unique_ptr<char[]> GetData() 65 { 66 return std::move(data_); 67 } 68 GetDataLength()69 int GetDataLength() const 70 { 71 return dataLength_; 72 } 73 74 private: 75 int streamType_; 76 StreamPacketHeader header_ {}; 77 TwoLevelsTlv tlvs_ {}; 78 std::unique_ptr<char[]> data_ = nullptr; 79 int dataLength_ = 0; 80 }; 81 } // namespace SoftBus 82 } // namespace Communication 83 84 #endif 85