1 /*
2 * Copyright (C) 2022 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 FILLP_FRAME_H
17 #define FILLP_FRAME_H
18
19 #include "hlist.h"
20 #include "fillptypes.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #define FILLP_FRAME_IS_VIDEO(_type) ((_type) == VIDEO_I || (_type) == VIDEO_P)
27
28 #pragma pack(1)
29 struct FillpFrameDataOption {
30 FILLP_UINT8 frameType;
31 FILLP_UINT8 level;
32 FILLP_UINT16 seqNum;
33 FILLP_UINT8 subSeqNum;
34 FILLP_UINT8 bitMap;
35 FILLP_UINT32 fragSize; /* the size of the fragment to which the pkt belongs */
36 FILLP_UINT32 txTimestamp; /* tx timestamp of the frame in struct FrameInfo */
37 };
38 #pragma pack()
39
40 struct FillpFrag {
41 FILLP_UINT32 size; /* size of the fragment */
42 FILLP_UINT32 procSize; /* current size of received data of this fragment,
43 procSize == size means the slice is completed */
44 FILLP_UINT32 seqNum; /* fragment sequence number of the frame */
45 };
46
47 struct FillpFrameInfo {
48 FILLP_UINT32 seqNum;
49 FILLP_INT type; /* frame type, I or P */
50 FILLP_UINT32 size; /* frame size */
51 FILLP_UINT32 fragCnt; /* fragment count of the frame */
52 FILLP_UINT32 totalItemCnt; /* packet count of the frame */
53 FILLP_UINT32 txTimestamp; /* tx timestamp of the frame in struct FrameInfo */
54 FILLP_LLONG firstPktRxTime; /* rx time of the first pkt of the frame */
55 FILLP_LLONG lastPktRxTime; /* rx time of the last pkt of the frame */
56 };
57
58 struct FillpFrame {
59 struct FillpFrameInfo info;
60 struct FillpFrag curFrag;
61 FILLP_BOOL rxStarted; /* first pkt of the first fragment has been received */
62 FILLP_BOOL lastFragRecvd; /* the last fragment has been received */
63 };
64
65 typedef void (*FillpFrameRxCompleteCb)(void *cbArg, FILLP_CONST struct FillpFrameInfo *rxInfo);
66
67 struct FillpFrameStats {
68 FILLP_UINT32 iFrameCount;
69 FILLP_ULLONG iFrameTotalSize;
70
71 FILLP_UINT32 pFrameCount;
72 FILLP_ULLONG pFrameTotalSize;
73 };
74
75 struct FillpFrameHandle {
76 FillpFrameRxCompleteCb rxCb;
77 void *rxCbArg;
78
79 struct FillpFrame curFrame; /* for sending, store the frame from uplayer,
80 * used to recognize the boundary of the frame.
81 * warning: should be only accessed in the FtSendFrame */
82
83 struct FillpFrameStats stats;
84 };
85
86 struct FillpPcbItem;
87
88 /* frame info shared by all the items in same frame fragment */
89 struct FillpFrameItem {
90 struct FrameInfo info;
91 FILLP_UINT32 fragSize; /* size of the fragment the item belongs to */
92 SysArchAtomic refCnt;
93 };
94
FillpFrameSetRxCb(struct FillpFrameHandle * h,FillpFrameRxCompleteCb cb,void * cbArg)95 static inline void FillpFrameSetRxCb(struct FillpFrameHandle *h,
96 FillpFrameRxCompleteCb cb, void *cbArg)
97 {
98 if (h != FILLP_NULL_PTR) {
99 h->rxCb = cb;
100 h->rxCbArg = cbArg;
101 }
102 }
103
104 void FillpFrameInit(struct FillpFrameHandle *h);
105 void FillpFrameFreeItem(struct FillpPcbItem *item);
106 FILLP_INT FillpFrameAddItem(struct FillpFrameHandle *h, struct FillpPcbItem *item);
107 void FillpFrameItemPut(struct FillpFrameItem *frameItem);
108 struct FillpFrameItem *FillpFrameItemAlloc(FILLP_CONST struct FrameInfo *frame);
109 void FillpFrameItemReference(struct FillpPcbItem *item, struct FillpFrameItem *frameItem);
110 void FillpFrameTxInitItem(struct FillpFrameHandle *h, struct FillpPcbItem *item,
111 const struct FrameInfo *info, FILLP_UINT32 sliceSize, FILLP_BOOL firstPkt);
112 FILLP_UINT32 FillpFrameGetPktDataOptLen(FILLP_UINT32 flag, FILLP_UINT32 pktDataOptLen);
113 FILLP_UINT16 FillpFrameBuildOption(const struct FillpPcbItem *item, FILLP_UINT8 *option);
114 FILLP_INT FillpFrameParseOption(struct FillpFrameHandle *h,
115 struct FillpPcbItem *item, FILLP_UINT8 *option, FILLP_UINT8 optLen);
116 void FillpFrameRx(struct FillpFrameHandle *h, const struct FillpPcbItem *item);
117
118 #ifdef __cplusplus
119 }
120 #endif
121
122 #endif /* FILLP_FRAME_H */
123