1 /**
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /** \addtogroup  RTP_Stack
18  *  @{
19  */
20 
21 #ifndef __RTP_RECEIVER_INFO_H__
22 #define __RTP_RECEIVER_INFO_H__
23 
24 #include <RtpGlobal.h>
25 #include <RtcpReportBlock.h>
26 
27 #define RTP_SEQ_MOD        (RTP_ONE << RTP_16)
28 #define RTP_MAX_DROPOUT    3000
29 #define RTP_MAX_MISORDER   100
30 #define RTP_MIN_SEQUENTIAL 0
31 
32 /**
33  * @class   RtpReceiverInfo
34  * @brief   It maintains the receiver list for RTP session.
35  * This class stores the content of a RTP packet.
36  * It can encode and decode a RTP packet based on the information it has.
37  */
38 class RtpReceiverInfo
39 {
40     // SSRC of the source
41     RtpDt_UInt32 m_uiSsrc;
42 
43     // Status of this SSRC as a sender or receiver
44     eRtp_Bool m_bSender;
45 
46     // number of Received RTP packets
47     RtpDt_UInt32 m_uiTotalRcvdRtpPkts;
48 
49     // number of Received octets
50     RtpDt_UInt32 m_uiTotalRcvdRtpOcts;
51 
52     // IPaddr of this ssrc
53     RtpBuffer* m_pobjIpAddr;
54 
55     // Port of this ssrc
56     RtpDt_UInt16 m_usPort;
57 
58     // remote ssrc information
59     tRTP_SOURCE m_stRtpSource;
60 
61     /** enables m_bIsCsrcFlag if the entry is creted @
62         processing of CSRC list in RTP processing */
63     eRtp_Bool m_bIsCsrcFlag;
64 
65     // Previous Ntp Timestamp
66     tRTP_NTP_TIME m_stPrevNtpTimestamp;
67 
68     // Previous RTP timestamp
69     RtpDt_UInt32 m_prevRtpTimestamp;
70 
71     /**
72      * The middle 32 bits out of 64 in the NTP timestamp
73      * received as part of the most recent RTCP sender report
74      * (SR) packet.
75      */
76     // tRTP_NTP_TIME m_stPreSrTimestamp;
77     RtpDt_UInt32 m_stPreSrTimestamp;
78 
79     // previous SR NtpTimestamp
80     RtpDt_UInt32 m_stLastSrNtpTimestamp;
81 
82     // check for first RTP packet
83     eRtp_Bool m_bIsFirstRtp;
84 
85     // It calculates the fraction Lost
86     RtpDt_UInt16 fractionLost();
87 
88     /**
89      * It determines the number of lost packets after rtcp timer expiry.
90      */
91     RtpDt_UInt32 findLostRtpPkts();
92 
93     /**
94      * It calculates delay since last SR
95      */
96     RtpDt_UInt32 delaySinceLastSR();
97 
98 public:
99     RtpReceiverInfo();
100 
101     ~RtpReceiverInfo();
102 
103     RtpDt_UInt32 getExtSeqNum();
104 
105     eRtp_Bool getCsrcFlag();
106 
107     RtpDt_Void setCsrcFlag(IN eRtp_Bool bIsCsrcFlag);
108 
109     RtpDt_UInt32 getSsrc();
110 
111     RtpDt_Void setSsrc(IN RtpDt_UInt32 uiSsrc);
112 
113     eRtp_Bool isSender();
114 
115     RtpDt_Void setSenderFlag(IN eRtp_Bool bSender);
116 
117     RtpDt_UInt32 getTotalRcvdRtpPkts();
118 
119     RtpDt_Void incrTotalRcvdRtpPkts();
120 
121     RtpDt_Void incrTotalRcvdRtpOcts(IN RtpDt_UInt32 uiRcvdOcts);
122 
123     RtpBuffer* getIpAddr();
124 
125     eRTP_STATUS_CODE setIpAddr(IN RtpBuffer* pobjIpAddr);
126 
127     RtpDt_UInt16 getPort();
128 
129     RtpDt_Void setPort(IN RtpDt_UInt16 usPort);
130 
131     RtpDt_UInt32 updateSeq(IN RtpDt_UInt16 usSeq);
132 
133     RtpDt_Void initSeq(IN RtpDt_UInt16 usSeq);
134 
135     tRTP_NTP_TIME* getpreSrTimestamp();
136 
137     RtpDt_Void setpreSrTimestamp(IN tRTP_NTP_TIME* pstNtpTs);
138 
139     RtpDt_Void setLastSrNtpTimestamp(IN tRTP_NTP_TIME* pstNtpTs);
140 
141     RtpDt_Void setprevRtpTimestamp(IN RtpDt_UInt32 pstRtpTs);
142 
143     RtpDt_Void setprevNtpTimestamp(IN tRTP_NTP_TIME* pstNtpTs);
144 
145     /**
146      * It populates Report Block information
147      */
148     eRTP_STATUS_CODE populateReportBlock(IN RtcpReportBlock* pobjRepBlk);
149 
150     /**
151      * It calculates the inter arrival jitter after receiving the RTP packet
152      */
153     RtpDt_Void calcJitter(IN RtpDt_UInt32 uiRcvRtpTs, IN RtpDt_UInt32 uiSamplingRate);
154 };
155 
156 #endif  //__RTP_RECEIVER_INFO_H__
157 
158 /** @}*/
159