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