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 <RtcpReportBlock.h>
18
RtcpReportBlock()19 RtcpReportBlock::RtcpReportBlock() :
20 m_uiSsrc(RTP_ZERO),
21 m_ucFracLost(RTP_ZERO),
22 m_uiCumNumPktLost(RTP_ZERO),
23 m_uiExtHighSeqRcv(RTP_ZERO),
24 m_uiJitter(RTP_ZERO),
25 m_uiLastSR(RTP_ZERO),
26 m_uiDelayLastSR(RTP_ZERO)
27 {
28 }
29
~RtcpReportBlock()30 RtcpReportBlock::~RtcpReportBlock() {}
31
setSsrc(IN RtpDt_UInt32 uiSsrc)32 RtpDt_Void RtcpReportBlock::setSsrc(IN RtpDt_UInt32 uiSsrc)
33 {
34 m_uiSsrc = uiSsrc;
35 }
36
getSsrc()37 RtpDt_UInt32 RtcpReportBlock::getSsrc()
38 {
39 return m_uiSsrc;
40 }
41
setFracLost(IN RtpDt_UChar ucFracLost)42 RtpDt_Void RtcpReportBlock::setFracLost(IN RtpDt_UChar ucFracLost)
43 {
44 m_ucFracLost = ucFracLost;
45 }
46
getFracLost()47 RtpDt_UChar RtcpReportBlock::getFracLost()
48 {
49 return m_ucFracLost;
50 }
51
setCumNumPktLost(IN RtpDt_Int32 uiCumNumPktLost)52 RtpDt_Void RtcpReportBlock::setCumNumPktLost(IN RtpDt_Int32 uiCumNumPktLost)
53 {
54 m_uiCumNumPktLost = uiCumNumPktLost;
55 }
56
getCumNumPktLost()57 RtpDt_Int32 RtcpReportBlock::getCumNumPktLost()
58 {
59 return m_uiCumNumPktLost;
60 }
61
setExtHighSeqRcv(IN RtpDt_UInt32 uiExtHighSeqRcv)62 RtpDt_Void RtcpReportBlock::setExtHighSeqRcv(IN RtpDt_UInt32 uiExtHighSeqRcv)
63 {
64 m_uiExtHighSeqRcv = uiExtHighSeqRcv;
65 }
66
getExtHighSeqRcv()67 RtpDt_UInt32 RtcpReportBlock::getExtHighSeqRcv()
68 {
69 return m_uiExtHighSeqRcv;
70 }
71
setJitter(IN RtpDt_UInt32 uiJitter)72 RtpDt_Void RtcpReportBlock::setJitter(IN RtpDt_UInt32 uiJitter)
73 {
74 m_uiJitter = uiJitter;
75 }
76
getJitter()77 RtpDt_UInt32 RtcpReportBlock::getJitter()
78 {
79 return m_uiJitter;
80 }
81
setLastSR(IN RtpDt_UInt32 uiLastSR)82 RtpDt_Void RtcpReportBlock::setLastSR(IN RtpDt_UInt32 uiLastSR)
83 {
84 m_uiLastSR = uiLastSR;
85 }
86
getLastSR()87 RtpDt_UInt32 RtcpReportBlock::getLastSR()
88 {
89 return m_uiLastSR;
90 }
91
setDelayLastSR(IN RtpDt_UInt32 uiDelayLastSR)92 RtpDt_Void RtcpReportBlock::setDelayLastSR(IN RtpDt_UInt32 uiDelayLastSR)
93 {
94 m_uiDelayLastSR = uiDelayLastSR;
95 }
96
getDelayLastSR()97 RtpDt_UInt32 RtcpReportBlock::getDelayLastSR()
98 {
99 return m_uiDelayLastSR;
100 }
101
decodeReportBlock(IN RtpDt_UChar * pcRepBlkBuf)102 eRtp_Bool RtcpReportBlock::decodeReportBlock(IN RtpDt_UChar* pcRepBlkBuf)
103 {
104 // SSRC
105 m_uiSsrc = RtpOsUtil::Ntohl(*(reinterpret_cast<RtpDt_UInt32*>(pcRepBlkBuf)));
106 pcRepBlkBuf = pcRepBlkBuf + RTP_WORD_SIZE;
107
108 RtpDt_UInt32 uiTemp4Data = RtpOsUtil::Ntohl(*(reinterpret_cast<RtpDt_UInt32*>(pcRepBlkBuf)));
109 pcRepBlkBuf = pcRepBlkBuf + RTP_WORD_SIZE;
110
111 // cumulative number of packets lost (3 bytes)
112 m_uiCumNumPktLost = uiTemp4Data & 0x00FFFFFF;
113 // fraction lost (1 byte)
114 uiTemp4Data = uiTemp4Data >> RTP_24;
115 m_ucFracLost = (RtpDt_UChar)(uiTemp4Data & 0x000000FF);
116
117 // extended highest sequence number received
118 m_uiExtHighSeqRcv = RtpOsUtil::Ntohl(*(reinterpret_cast<RtpDt_UInt32*>(pcRepBlkBuf)));
119 pcRepBlkBuf = pcRepBlkBuf + RTP_WORD_SIZE;
120
121 // interarrival jitter
122 m_uiJitter = RtpOsUtil::Ntohl(*(reinterpret_cast<RtpDt_UInt32*>(pcRepBlkBuf)));
123 pcRepBlkBuf = pcRepBlkBuf + RTP_WORD_SIZE;
124
125 // last SR
126 m_uiLastSR = RtpOsUtil::Ntohl(*(reinterpret_cast<RtpDt_UInt32*>(pcRepBlkBuf)));
127 pcRepBlkBuf = pcRepBlkBuf + RTP_WORD_SIZE;
128
129 // delay since last SR
130 m_uiDelayLastSR = RtpOsUtil::Ntohl(*(reinterpret_cast<RtpDt_UInt32*>(pcRepBlkBuf)));
131
132 return eRTP_SUCCESS;
133 } // decodeReportBlock
134
formReportBlock(OUT RtpBuffer * pobjRtcpPktBuf)135 eRtp_Bool RtcpReportBlock::formReportBlock(OUT RtpBuffer* pobjRtcpPktBuf)
136 {
137 RtpDt_UInt32 uiCurPos = pobjRtcpPktBuf->getLength();
138 RtpDt_UChar* pucBuffer = pobjRtcpPktBuf->getBuffer();
139 pucBuffer = pucBuffer + uiCurPos;
140
141 // m_uiSsrc
142 *(reinterpret_cast<RtpDt_UInt32*>(pucBuffer)) = RtpOsUtil::Ntohl(m_uiSsrc);
143 pucBuffer = pucBuffer + RTP_WORD_SIZE;
144 uiCurPos = uiCurPos + RTP_WORD_SIZE;
145
146 // m_ucFracLost
147 RtpDt_UInt32 uiTempData = m_ucFracLost;
148 uiTempData = uiTempData << RTP_24;
149 // m_uiCumNumPktLost
150 // consider only 24-bits of uiCumNumPktLost
151 uiTempData = uiTempData | (m_uiCumNumPktLost & 0X00FFFFFF);
152
153 *(reinterpret_cast<RtpDt_UInt32*>(pucBuffer)) = RtpOsUtil::Ntohl(uiTempData);
154 pucBuffer = pucBuffer + RTP_WORD_SIZE;
155 uiCurPos = uiCurPos + RTP_WORD_SIZE;
156
157 // m_uiExtHighSeqRcv
158 *(reinterpret_cast<RtpDt_UInt32*>(pucBuffer)) = RtpOsUtil::Ntohl(m_uiExtHighSeqRcv);
159 pucBuffer = pucBuffer + RTP_WORD_SIZE;
160 uiCurPos = uiCurPos + RTP_WORD_SIZE;
161
162 // m_uiJitter
163 *(reinterpret_cast<RtpDt_UInt32*>(pucBuffer)) = RtpOsUtil::Ntohl(m_uiJitter);
164 pucBuffer = pucBuffer + RTP_WORD_SIZE;
165 uiCurPos = uiCurPos + RTP_WORD_SIZE;
166
167 // m_uiLastSR
168 *(reinterpret_cast<RtpDt_UInt32*>(pucBuffer)) = RtpOsUtil::Ntohl(m_uiLastSR);
169 pucBuffer = pucBuffer + RTP_WORD_SIZE;
170 uiCurPos = uiCurPos + RTP_WORD_SIZE;
171
172 // m_uiDelayLastSR
173 *(reinterpret_cast<RtpDt_UInt32*>(pucBuffer)) = RtpOsUtil::Ntohl(m_uiDelayLastSR);
174 uiCurPos = uiCurPos + RTP_WORD_SIZE;
175
176 pobjRtcpPktBuf->setLength(uiCurPos);
177
178 return eRTP_SUCCESS;
179 } // formReportBlock
180