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 #include <RtpTimerInfo.h>
18 #include <RtpStackUtil.h>
19
20 /*********************************************************
21 * Function name : RtpTimerInfo
22 * Description : Constructor
23 * Return type : None
24 * Argument : None
25 * Preconditions : None
26 * Side Effects : None
27 ********************************************************/
RtpTimerInfo()28 RtpTimerInfo::RtpTimerInfo() :
29 m_uiTp(RTP_ZERO),
30 m_uiTc(RTP_ZERO),
31 m_uiTn(RTP_ZERO),
32 m_uiPmembers(RTP_ONE),
33 m_uiMembers(RTP_ONE),
34 m_uiSenders(RTP_ZERO),
35 m_uiRtcpBw(RTP_ZERO),
36 m_uiWeSent(RTP_ZERO),
37 m_ulAvgRtcpSize(RTP_ZERO),
38 m_bInitial(eRTP_TRUE)
39 {
40 }
41
42 /*********************************************************
43 * Function name : ~RtpTimerInfo
44 * Description : Destructor
45 * Return type : None
46 * Argument : None
47 * Preconditions : None
48 * Side Effects : None
49 ********************************************************/
~RtpTimerInfo()50 RtpTimerInfo::~RtpTimerInfo() {}
51
52 /*********************************************************
53 * Function name : cleanUp
54 * Description : It makes all members with default values
55 * Return type : None
56 * Argument : None
57 * Preconditions : None
58 * Side Effects : None
59 ********************************************************/
cleanUp()60 RtpDt_Void RtpTimerInfo::cleanUp()
61 {
62 m_uiTp = RTP_ZERO;
63 m_uiTc = RTP_ZERO;
64 m_uiTn = RTP_ZERO;
65 m_uiPmembers = RTP_ONE;
66 m_uiMembers = RTP_ONE;
67 m_uiSenders = RTP_ZERO;
68 m_uiRtcpBw = RTP_ZERO;
69 m_uiWeSent = RTP_ZERO;
70 m_ulAvgRtcpSize = RTP_ZERO;
71 m_bInitial = eRTP_TRUE;
72 }
73
74 /*********************************************************
75 * Function name : incrSndrCount
76 * Description : It increments the m_uiSenders variable by uiIncrVal
77 * Return type : RtpDt_Void
78 * Argument : RtpDt_UInt32 : In
79 * Preconditions : None
80 * Side Effects : None
81 ********************************************************/
incrSndrCount(IN RtpDt_UInt32 uiIncrVal)82 RtpDt_Void RtpTimerInfo::incrSndrCount(IN RtpDt_UInt32 uiIncrVal)
83 {
84 m_uiSenders = m_uiSenders + uiIncrVal;
85 }
86
87 /*********************************************************
88 * Function name : updateAvgRtcpSize
89 * Description : It updates AVG_RTCP_SIZE parameter
90 * Return type : RtpDt_Void
91 * Argument : RtpDt_UInt32 : In
92 * Received RTCP packet size
93 * Preconditions : None
94 * Side Effects : None
95 ********************************************************/
updateAvgRtcpSize(IN RtpDt_UInt32 uiRcvdPktSize)96 RtpDt_Void RtpTimerInfo::updateAvgRtcpSize(IN RtpDt_UInt32 uiRcvdPktSize)
97 {
98 // avg_rtcp_size = (1/16) * packet_size + (15/16) * avg_rtcp_size
99 m_ulAvgRtcpSize = (1.0 / 16) * uiRcvdPktSize + (15.0 / 16) * m_ulAvgRtcpSize;
100 }
101
102 /*********************************************************
103 * Function name : updateByePktInfo
104 * Description : It updates the timer information
105 * Return type : eRtp_Bool
106 * Argument : RtpDt_UInt32 : In
107 * size of the Receiver list.
108 * Preconditions : None
109 * Side Effects : None
110 ********************************************************/
updateByePktInfo(IN RtpDt_UInt32 uiMemSize)111 eRtp_Bool RtpTimerInfo::updateByePktInfo(IN RtpDt_UInt32 uiMemSize)
112 {
113 m_uiMembers = uiMemSize;
114 /*
115 if (*members < *pmembers) {
116 tn = tc +
117 (((RtpDt_Double) *members)/(*pmembers))*(tn - tc);
118 *tp = tc -
119 (((RtpDt_Double) *members)/(*pmembers))*(tc - *tp);
120 *pmembers = *members;
121 }
122 */
123
124 // Reference: RFC 3550, section A.7, page 93
125 if (m_uiMembers < m_uiPmembers)
126 {
127 m_uiTn = getTc() + (m_uiMembers / m_uiPmembers) * (m_uiTn - getTc());
128 m_uiTp = getTc() - (m_uiMembers / m_uiPmembers) * (getTc() - m_uiTp);
129 m_uiPmembers = m_uiMembers;
130 return eRTP_TRUE;
131 }
132
133 return eRTP_FALSE;
134 } // updateByePktInfo
135
136 /*********************************************************
137 * Function name : getTp
138 * Description : get method for m_uiTp
139 * Return type : RtpDt_UInt32
140 * Argument : None
141 * Preconditions : None
142 * Side Effects : None
143 ********************************************************/
getTp()144 RtpDt_UInt32 RtpTimerInfo::getTp()
145 {
146 return m_uiTp;
147 }
148
149 /*********************************************************
150 * Function name : setTp
151 * Description : set method for m_uiTp
152 * Return type : RtpDt_Void
153 * Argument : RtpDt_UInt32 : In
154 * Preconditions : None
155 * Side Effects : None
156 ********************************************************/
setTp(IN RtpDt_UInt32 uiTp)157 RtpDt_Void RtpTimerInfo::setTp(IN RtpDt_UInt32 uiTp)
158 {
159 m_uiTp = uiTp;
160 }
161
162 /*********************************************************
163 * Function name : getTc
164 * Description : get method for m_uiTc
165 * Return type : RtpDt_UInt32
166 * return value in Milliseconds
167 * Argument : None
168 * Preconditions : None
169 * Side Effects : None
170 ********************************************************/
getTc()171 RtpDt_UInt32 RtpTimerInfo::getTc()
172 {
173 tRTP_NTP_TIME stCurNtpRtcpTs = {RTP_ZERO, RTP_ZERO};
174 RtpOsUtil::GetNtpTime(stCurNtpRtcpTs);
175 RtpDt_UInt32 uiMidOctets = RtpStackUtil::getMidFourOctets(&stCurNtpRtcpTs);
176 RtpDt_UInt32 uiHigh = uiMidOctets >> RTP_BYTE2_BIT_SIZE;
177 uiHigh = uiHigh * RTP_SEC_TO_MILLISEC;
178 RtpDt_Double uiLow = uiMidOctets & RTP_HEX_16_BIT_MAX;
179 uiLow = uiLow / RTP_MILLISEC_MICRO;
180 uiMidOctets = uiHigh + (RtpDt_UInt32)uiLow; // it is in milliseconds
181 return uiMidOctets;
182 }
183
184 /*********************************************************
185 * Function name : getTn
186 * Description : get method for m_uiTn
187 * Return type : RtpDt_UInt32
188 * Argument : None
189 * Preconditions : None
190 * Side Effects : None
191 ********************************************************/
getTn()192 RtpDt_UInt32 RtpTimerInfo::getTn()
193 {
194 return m_uiTn;
195 }
196
197 /*********************************************************
198 * Function name : setTn
199 * Description : set method for m_uiTn
200 * Return type : RtpDt_Void
201 * Argument : RtpDt_UInt32 : In
202 * Preconditions : None
203 * Side Effects : None
204 ********************************************************/
setTn(IN RtpDt_UInt32 uiTn)205 RtpDt_Void RtpTimerInfo::setTn(IN RtpDt_UInt32 uiTn)
206 {
207 m_uiTn = uiTn;
208 }
209
210 /*********************************************************
211 * Function name : getPmembers
212 * Description : get method for m_uiPmembers
213 * Return type : RtpDt_UInt32
214 * Argument : None
215 * Preconditions : None
216 * Side Effects : None
217 ********************************************************/
getPmembers()218 RtpDt_UInt32 RtpTimerInfo::getPmembers()
219 {
220 return m_uiPmembers;
221 }
222
223 /*********************************************************
224 * Function name : setPmembers
225 * Description : set method for m_uiPmembers
226 * Return type : RtpDt_Void
227 * Argument : RtpDt_UInt32 : In
228 * Preconditions : None
229 * Side Effects : None
230 ********************************************************/
setPmembers(IN RtpDt_UInt32 uiPmembers)231 RtpDt_Void RtpTimerInfo::setPmembers(IN RtpDt_UInt32 uiPmembers)
232 {
233 m_uiPmembers = uiPmembers;
234 }
235
236 /*********************************************************
237 * Function name : getRtcpBw
238 * Description : get method for m_uiRtcpBw
239 * Return type : RtpDt_UInt32
240 * Argument : None
241 * Preconditions : None
242 * Side Effects : None
243 ********************************************************/
getRtcpBw()244 RtpDt_UInt32 RtpTimerInfo::getRtcpBw()
245 {
246 return m_uiRtcpBw;
247 }
248
249 /*********************************************************
250 * Function name : setRtcpBw
251 * Description : set method for m_uiRtcpBw
252 * Return type : RtpDt_Void
253 * Argument : RtpDt_UInt32 : In
254 * Preconditions : None
255 * Side Effects : None
256 ********************************************************/
setRtcpBw(IN RtpDt_UInt32 uiRtcpBw)257 RtpDt_Void RtpTimerInfo::setRtcpBw(IN RtpDt_UInt32 uiRtcpBw)
258 {
259 m_uiRtcpBw = uiRtcpBw;
260 }
261
262 /*********************************************************
263 * Function name : getWeSent
264 * Description : get method for m_uiWeSent
265 * Return type : RtpDt_UInt32
266 * Argument : None
267 * Preconditions : None
268 * Side Effects : None
269 ********************************************************/
getWeSent()270 RtpDt_UInt32 RtpTimerInfo::getWeSent()
271 {
272 return m_uiWeSent;
273 }
274
275 /*********************************************************
276 * Function name : setWeSent
277 * Description : set method for m_uiWeSent
278 * Return type : RtpDt_Void
279 * Argument : RtpDt_UInt32 : In
280 * Preconditions : None
281 * Side Effects : None
282 ********************************************************/
setWeSent(IN RtpDt_UInt32 uiWeSent)283 RtpDt_Void RtpTimerInfo::setWeSent(IN RtpDt_UInt32 uiWeSent)
284 {
285 m_uiWeSent = uiWeSent;
286 }
287
288 /*********************************************************
289 * Function name : getAvgRtcpSize
290 * Description : get method for m_ulAvgRtcpSize
291 * Return type : RtpDt_UInt32
292 * Argument : None
293 * Preconditions : None
294 * Side Effects : None
295 ********************************************************/
getAvgRtcpSize()296 RtpDt_Int32 RtpTimerInfo::getAvgRtcpSize()
297 {
298 return m_ulAvgRtcpSize;
299 }
300
301 /*********************************************************
302 * Function name : setAvgRtcpSize
303 * Description : set method for m_ulAvgRtcpSize
304 * Return type : RtpDt_Void
305 * Argument : RtpDt_Int32 : In
306 * Preconditions : None
307 * Side Effects : None
308 ********************************************************/
setAvgRtcpSize(IN RtpDt_Int32 uiAvgRtcpSize)309 RtpDt_Void RtpTimerInfo::setAvgRtcpSize(IN RtpDt_Int32 uiAvgRtcpSize)
310 {
311 m_ulAvgRtcpSize = uiAvgRtcpSize;
312 }
313
314 /*********************************************************
315 * Function name : isInitial
316 * Description : get method for m_bInitial
317 * Return type : eRtp_Bool
318 * Argument : None
319 * Preconditions : None
320 * Side Effects : None
321 ********************************************************/
isInitial()322 eRtp_Bool RtpTimerInfo::isInitial()
323 {
324 return m_bInitial;
325 }
326
327 /*********************************************************
328 * Function name : setInitial
329 * Description : set method for m_uiInitial
330 * Return type : RtpDt_Void
331 * Argument : eRtp_Bool : In
332 * Preconditions : None
333 * Side Effects : None
334 ********************************************************/
setInitial(IN eRtp_Bool bSetInitial)335 RtpDt_Void RtpTimerInfo::setInitial(IN eRtp_Bool bSetInitial)
336 {
337 m_bInitial = bSetInitial;
338 }
339