<divclass="line"><aname="l00032"></a><spanclass="lineno"> 32</span>  uint32_t received_pkts; <spanclass="comment">/* Number of packets received */</span></div>
<divclass="line"><aname="l00033"></a><spanclass="lineno"> 33</span>  uint32_t dropped_pkts; <spanclass="comment">/* Number of dropped RTP packets */</span></div>
<divclass="line"><aname="l00034"></a><spanclass="lineno"> 34</span>  uint32_t received_bytes; <spanclass="comment">/* Number of bytes received excluding RTP Header */</span></div>
<divclass="line"><aname="l00037"></a><spanclass="lineno"> 37</span>  uint32_t sent_pkts; <spanclass="comment">/* Number of sent RTP packets */</span></div>
<divclass="line"><aname="l00038"></a><spanclass="lineno"> 38</span>  uint32_t sent_bytes; <spanclass="comment">/* Number of sent bytes excluding RTP Header */</span></div>
<divclass="line"><aname="l00043"></a><spanclass="lineno"> 43</span> <spanclass="comment">/* Receiver clock related stuff */</span></div>
<divclass="line"><aname="l00044"></a><spanclass="lineno"> 44</span>  uint64_t initial_ntp; <spanclass="comment">/* Wallclock reading when the first RTP packet was received */</span></div>
<divclass="line"><aname="l00045"></a><spanclass="lineno"> 45</span>  uint32_t initial_rtp; <spanclass="comment">/* RTP timestamp of the first RTP packet received */</span></div>
<divclass="line"><aname="l00046"></a><spanclass="lineno"> 46</span>  uint32_t clock_rate; <spanclass="comment">/* Rate of the clock (used for jitter calculations) */</span></div>
<divclass="line"><aname="l00048"></a><spanclass="lineno"> 48</span>  uint32_t lsr; <spanclass="comment">/* Middle 32 bits of the 64-bit NTP timestamp of previous SR */</span></div>
<divclass="line"><aname="l00049"></a><spanclass="lineno"> 49</span>  uvgrtp::clock::hrc::hrc_t sr_ts; <spanclass="comment">/* When the last SR was received (used to calculate delay) */</span></div>
<divclass="line"><aname="l00051"></a><spanclass="lineno"> 51</span>  uint16_t max_seq; <spanclass="comment">/* Highest sequence number received */</span></div>
<divclass="line"><aname="l00052"></a><spanclass="lineno"> 52</span>  uint16_t base_seq; <spanclass="comment">/* First sequence number received */</span></div>
<divclass="line"><aname="l00054"></a><spanclass="lineno"> 54</span>  uint16_t cycles; <spanclass="comment">/* Number of sequence cycles */</span></div>
<divclass="line"><aname="l00059"></a><spanclass="lineno"> 59</span>  sockaddr_in address; <spanclass="comment">/* address of the participant */</span></div>
<divclass="line"><aname="l00060"></a><spanclass="lineno"> 60</span> <spanclass="keyword">struct </span>rtcp_statistics stats; <spanclass="comment">/* RTCP session statistics of the participant */</span></div>
<divclass="line"><aname="l00062"></a><spanclass="lineno"> 62</span> <spanclass="keywordtype">int</span> probation; <spanclass="comment">/* has the participant been fully accepted to the session */</span></div>
<divclass="line"><aname="l00063"></a><spanclass="lineno"> 63</span> <spanclass="keywordtype">int</span> role; <spanclass="comment">/* is the participant a sender or a receiver */</span></div>
<divclass="line"><aname="l00065"></a><spanclass="lineno"> 65</span> <spanclass="comment">/* Save the latest RTCP packets received from this participant</span></div>
<divclass="line"><aname="l00066"></a><spanclass="lineno"> 66</span> <spanclass="comment"> * Users can query these packets using the SSRC of participant */</span></div>
<divclass="line"><aname="l00083"></a><spanclass="lineno"> 83</span> <spanclass="comment"> * return RTP_OK on success and RTP_MEMORY_ERROR if the allocation fails */</span></div>
<divclass="line"><aname="l00086"></a><spanclass="lineno"> 86</span> <spanclass="comment">/* End the RTCP session and send RTCP BYE to all participants</span></div>
<divclass="line"><aname="l00091"></a><spanclass="lineno"> 91</span> <spanclass="comment">/* Generate either RTCP Sender or Receiver report and sent it to all participants</span></div>
<divclass="line"><aname="l00092"></a><spanclass="lineno"> 92</span> <spanclass="comment"> * Return RTP_OK on success and RTP_ERROR on error */</span></div>
<divclass="line"><aname="l00095"></a><spanclass="lineno"> 95</span> <spanclass="comment">/* Handle different kinds of incoming packets</span></div>
<divclass="line"><aname="l00097"></a><spanclass="lineno"> 97</span> <spanclass="comment"> * These routines will convert the fields of "frame" from network to host byte order</span></div>
<divclass="line"><aname="l00099"></a><spanclass="lineno"> 99</span> <spanclass="comment"> * Currently nothing's done with valid packets, at some point an API for</span></div>
<divclass="line"><aname="l00100"></a><spanclass="lineno"> 100</span> <spanclass="comment"> * querying these reports is implemented</span></div>
<divclass="line"><aname="l00102"></a><spanclass="lineno"> 102</span> <spanclass="comment"> * Return RTP_OK on success and RTP_ERROR on error */</span></div>
<divclass="line"><aname="l00109"></a><spanclass="lineno"> 109</span> <spanclass="comment">/* Handle incoming RTCP packet (first make sure it's a valid RTCP packet)</span></div>
<divclass="line"><aname="l00110"></a><spanclass="lineno"> 110</span> <spanclass="comment"> * This function will call one of the above functions internally</span></div>
<divclass="line"><aname="l00112"></a><spanclass="lineno"> 112</span> <spanclass="comment"> * Return RTP_OK on success and RTP_ERROR on error */</span></div>
<divclass="line"><aname="l00116"></a><spanclass="lineno"> 116</span> <spanclass="comment">/* Send "frame" to all participants</span></div>
<divclass="line"><aname="l00118"></a><spanclass="lineno"> 118</span> <spanclass="comment"> * These routines will convert all necessary fields to network byte order</span></div>
<divclass="line"><aname="l00120"></a><spanclass="lineno"> 120</span> <spanclass="comment"> * Return RTP_OK on success</span></div>
<divclass="line"><aname="l00121"></a><spanclass="lineno"> 121</span> <spanclass="comment"> * Return RTP_INVALID_VALUE if "frame" is in some way invalid</span></div>
<divclass="line"><aname="l00122"></a><spanclass="lineno"> 122</span> <spanclass="comment"> * Return RTP_SEND_ERROR if sending "frame" did not succeed (see socket.hh for details) */</span></div>
<divclass="line"><aname="l00128"></a><spanclass="lineno"> 128</span> <spanclass="comment">/* Return the latest RTCP packet received from participant of "ssrc"</span></div>
<divclass="line"><aname="l00129"></a><spanclass="lineno"> 129</span> <spanclass="comment"> * Return nullptr if we haven't received this kind of packet or if "ssrc" doesn't exist</span></div>
<divclass="line"><aname="l00131"></a><spanclass="lineno"> 131</span> <spanclass="comment"> * NOTE: Caller is responsible for deallocating the memory */</span></div>
<divclass="line"><aname="l00137"></a><spanclass="lineno"> 137</span> <spanclass="comment">/* Return a reference to vector that contains the sockets of all participants */</span></div>
<divclass="line"><aname="l00140"></a><spanclass="lineno"> 140</span> <spanclass="comment">/* Somebody joined the multicast group the owner of this RTCP instance is part of</span></div>
<divclass="line"><aname="l00141"></a><spanclass="lineno"> 141</span> <spanclass="comment"> * Add it to RTCP participant list so we can start listening for reports</span></div>
<divclass="line"><aname="l00143"></a><spanclass="lineno"> 143</span> <spanclass="comment"> * "clock_rate" tells how much the RTP timestamp advances, this information is needed</span></div>
<divclass="line"><aname="l00144"></a><spanclass="lineno"> 144</span> <spanclass="comment"> * to calculate the interarrival jitter correctly. It has nothing do with our clock rate,</span></div>
<divclass="line"><aname="l00145"></a><spanclass="lineno"> 145</span> <spanclass="comment"> * (or whether we're even sending anything)</span></div>
<divclass="line"><aname="l00147"></a><spanclass="lineno"> 147</span> <spanclass="comment"> * Return RTP_OK on success and RTP_ERROR on error */</span></div>
<divclass="line"><aname="l00150"></a><spanclass="lineno"> 150</span> <spanclass="comment">/* Functions for updating various RTP sender statistics */</span></div>
<divclass="line"><aname="l00161"></a><spanclass="lineno"> 161</span> <spanclass="comment">/* Update the RTCP statistics regarding this packet</span></div>
<divclass="line"><aname="l00163"></a><spanclass="lineno"> 163</span> <spanclass="comment"> * Return RTP_OK if packet is valid</span></div>
<divclass="line"><aname="l00164"></a><spanclass="lineno"> 164</span> <spanclass="comment"> * Return RTP_INVALID_VALUE if SSRCs of remotes have collided or the packet is invalid in some way</span></div>
<divclass="line"><aname="l00165"></a><spanclass="lineno"> 165</span> <spanclass="comment"> * return RTP_SSRC_COLLISION if our own SSRC has collided and we need to reinitialize it */</span></div>
<divclass="line"><aname="l00168"></a><spanclass="lineno"> 168</span> <spanclass="comment">/* If we've detected that our SSRC has collided with someone else's SSRC, we need to</span></div>
<divclass="line"><aname="l00169"></a><spanclass="lineno"> 169</span> <spanclass="comment"> * generate new random SSRC and reinitialize our own RTCP state.</span></div>
<divclass="line"><aname="l00170"></a><spanclass="lineno"> 170</span> <spanclass="comment"> * RTCP object still has the participants of "last session", we can use their SSRCs</span></div>
<divclass="line"><aname="l00171"></a><spanclass="lineno"> 171</span> <spanclass="comment"> * to detected new collision</span></div>
<divclass="line"><aname="l00173"></a><spanclass="lineno"> 173</span> <spanclass="comment"> * Return RTP_OK if reinitialization succeeded</span></div>
<divclass="line"><aname="l00174"></a><spanclass="lineno"> 174</span> <spanclass="comment"> * Return RTP_SSRC_COLLISION if our new SSRC has collided and we need to generate new SSRC */</span></div>
<divclass="line"><aname="l00200"></a><spanclass="lineno"> 200</span> <spanclass="comment">/* Alternate way to get RTCP packets is to install a hook for them. So instead of</span></div>
<divclass="line"><aname="l00201"></a><spanclass="lineno"> 201</span> <spanclass="comment"> * polling an RTCP packet, user can install a function that is called when</span></div>
<divclass="line"><aname="l00202"></a><spanclass="lineno"> 202</span> <spanclass="comment"> * a specific RTCP packet is received. */</span></div>
<divclass="line"><aname="l00222"></a><spanclass="lineno"> 222</span> <spanclass="comment">/* when we start the RTCP instance, we don't know what the SSRC of the remote is</span></div>
<divclass="line"><aname="l00223"></a><spanclass="lineno"> 223</span> <spanclass="comment"> * when an RTP packet is received, we must check if we've already received a packet</span></div>
<divclass="line"><aname="l00224"></a><spanclass="lineno"> 224</span> <spanclass="comment"> * from this sender and if not, create new entry to receiver_stats_ map */</span></div>
<divclass="line"><aname="l00227"></a><spanclass="lineno"> 227</span> <spanclass="comment">/* When we receive an RTP or RTCP packet, we need to check the source address and see if it's</span></div>
<divclass="line"><aname="l00228"></a><spanclass="lineno"> 228</span> <spanclass="comment"> * the same address where we've received packets before.</span></div>
<divclass="line"><aname="l00230"></a><spanclass="lineno"> 230</span> <spanclass="comment"> * If the address is new, it means we have detected an SSRC collision and the paket should</span></div>
<divclass="line"><aname="l00231"></a><spanclass="lineno"> 231</span> <spanclass="comment"> * be dropped We also need to check whether this SSRC matches with our own SSRC and if it does</span></div>
<divclass="line"><aname="l00232"></a><spanclass="lineno"> 232</span> <spanclass="comment"> * we need to send RTCP BYE and rejoin to the session */</span></div>
<divclass="line"><aname="l00235"></a><spanclass="lineno"> 235</span> <spanclass="comment">/* Move participant from initial_peers_ to participants_ */</span></div>
<divclass="line"><aname="l00238"></a><spanclass="lineno"> 238</span> <spanclass="comment">/* We've got a message from new source (the SSRC of the frame is not known to us)</span></div>
<divclass="line"><aname="l00239"></a><spanclass="lineno"> 239</span> <spanclass="comment"> * Initialize statistics for the peer and move it to participants_ */</span></div>
<divclass="line"><aname="l00242"></a><spanclass="lineno"> 242</span> <spanclass="comment">/* Initialize the RTP Sequence related stuff of peer</span></div>
<divclass="line"><aname="l00243"></a><spanclass="lineno"> 243</span> <spanclass="comment"> * This function assumes that the peer already exists in the participants_ map */</span></div>
<divclass="line"><aname="l00246"></a><spanclass="lineno"> 246</span> <spanclass="comment">/* Update the SSRC's sequence related data in participants_ map</span></div>
<divclass="line"><aname="l00248"></a><spanclass="lineno"> 248</span> <spanclass="comment"> * Return RTP_OK if the received packet was OK</span></div>
<divclass="line"><aname="l00249"></a><spanclass="lineno"> 249</span> <spanclass="comment"> * Return RTP_GENERIC_ERROR if it wasn't and</span></div>
<divclass="line"><aname="l00250"></a><spanclass="lineno"> 250</span> <spanclass="comment"> * packet-related statistics should not be updated */</span></div>
<divclass="line"><aname="l00255"></a><spanclass="lineno"> 255</span> <spanclass="comment"> * "pkt_size" tells how much rtcp_byte_count_</span></div>
<divclass="line"><aname="l00256"></a><spanclass="lineno"> 256</span> <spanclass="comment"> * should be increased before calculating the new average */</span></div>
<divclass="line"><aname="l00259"></a><spanclass="lineno"> 259</span> <spanclass="comment">/* Functions for generating different kinds of reports.</span></div>
<divclass="line"><aname="l00260"></a><spanclass="lineno"> 260</span> <spanclass="comment"> * These functions will both generate the report and send it</span></div>
<divclass="line"><aname="l00262"></a><spanclass="lineno"> 262</span> <spanclass="comment"> * Return RTP_OK on success and RTP_ERROR on error */</span></div>
<divclass="line"><aname="l00266"></a><spanclass="lineno"> 266</span> <spanclass="comment">/* Because struct statistics contains uvgRTP clock object we cannot</span></div>
<divclass="line"><aname="l00267"></a><spanclass="lineno"> 267</span> <spanclass="comment"> * zero it out without compiler complaining about it so all the fields</span></div>
<divclass="line"><aname="l00268"></a><spanclass="lineno"> 268</span> <spanclass="comment"> * must be set to zero manually */</span></div>
<divclass="line"><aname="l00271"></a><spanclass="lineno"> 271</span> <spanclass="comment">/* Pointer to RTP context from which clock rate etc. info is collected and which is</span></div>
<divclass="line"><aname="l00272"></a><spanclass="lineno"> 272</span> <spanclass="comment"> * used to change SSRC if a collision is detected */</span></div>
<divclass="line"><aname="l00285"></a><spanclass="lineno"> 285</span> <spanclass="keywordtype">size_t</span> tp_; <spanclass="comment">/* the last time an RTCP packet was transmitted */</span></div>
<divclass="line"><aname="l00286"></a><spanclass="lineno"> 286</span> <spanclass="keywordtype">size_t</span> tc_; <spanclass="comment">/* the current time */</span></div>
<divclass="line"><aname="l00287"></a><spanclass="lineno"> 287</span> <spanclass="keywordtype">size_t</span> tn_; <spanclass="comment">/* the next scheduled transmission time of an RTCP packet */</span></div>
<divclass="line"><aname="l00288"></a><spanclass="lineno"> 288</span> <spanclass="keywordtype">size_t</span> pmembers_; <spanclass="comment">/* the estimated number of session members at the time tn was last recomputed */</span></div>
<divclass="line"><aname="l00289"></a><spanclass="lineno"> 289</span> <spanclass="keywordtype">size_t</span> members_; <spanclass="comment">/* the most current estimate for the number of session members */</span></div>
<divclass="line"><aname="l00290"></a><spanclass="lineno"> 290</span> <spanclass="keywordtype">size_t</span> senders_; <spanclass="comment">/* the most current estimate for the number of senders in the session */</span></div>
<divclass="line"><aname="l00292"></a><spanclass="lineno"> 292</span> <spanclass="comment">/* The target RTCP bandwidth, i.e., the total bandwidth</span></div>
<divclass="line"><aname="l00293"></a><spanclass="lineno"> 293</span> <spanclass="comment"> * that will be used for RTCP packets by all members of this session,</span></div>
<divclass="line"><aname="l00294"></a><spanclass="lineno"> 294</span> <spanclass="comment"> * in octets per second. This will be a specified fraction of the</span></div>
<divclass="line"><aname="l00295"></a><spanclass="lineno"> 295</span> <spanclass="comment"> * "session bandwidth" parameter supplied to the application at startup. */</span></div>
<divclass="line"><aname="l00298"></a><spanclass="lineno"> 298</span> <spanclass="comment">/* Flag that is true if the application has sent data since</span></div>
<divclass="line"><aname="l00299"></a><spanclass="lineno"> 299</span> <spanclass="comment"> * the 2nd previous RTCP report was transmitted. */</span></div>
<divclass="line"><aname="l00302"></a><spanclass="lineno"> 302</span> <spanclass="comment">/* The average compound RTCP packet size, in octets,</span></div>
<divclass="line"><aname="l00303"></a><spanclass="lineno"> 303</span> <spanclass="comment"> * over all RTCP packets sent and received by this participant. The</span></div>
<divclass="line"><aname="l00304"></a><spanclass="lineno"> 304</span> <spanclass="comment"> * size includes lower-layer transport and network protocol headers</span></div>
<divclass="line"><aname="l00305"></a><spanclass="lineno"> 305</span> <spanclass="comment"> * (e.g., UDP and IP) as explained in Section 6.2 */</span></div>
<divclass="line"><aname="l00308"></a><spanclass="lineno"> 308</span> <spanclass="comment">/* Number of RTCP packets and bytes sent and received by this participant */</span></div>
<divclass="line"><aname="l00315"></a><spanclass="lineno"> 315</span> <spanclass="comment">/* Flag that is true if the application has not yet sent an RTCP packet. */</span></div>
<divclass="line"><aname="l00324"></a><spanclass="lineno"> 324</span> <spanclass="comment">/* Clock rate of the media ie. how fast does the time increase */</span></div>
<divclass="line"><aname="l00327"></a><spanclass="lineno"> 327</span> <spanclass="comment">/* The first value of RTP timestamp (aka t = 0) */</span></div>
<divclass="line"><aname="l00333"></a><spanclass="lineno"> 333</span> <spanclass="comment">/* statistics for RTCP Sender and Receiver Reports */</span></div>
<divclass="line"><aname="l00336"></a><spanclass="lineno"> 336</span> <spanclass="comment">/* If we expect frames from remote but haven't received anything from remote yet,</span></div>
<divclass="line"><aname="l00337"></a><spanclass="lineno"> 337</span> <spanclass="comment"> * the participant resides in this vector until he's moved to participants_ */</span></div>
<divclass="line"><aname="l00340"></a><spanclass="lineno"> 340</span> <spanclass="comment">/* Vector of sockets the RTCP runner is listening to</span></div>
<divclass="line"><aname="l00342"></a><spanclass="lineno"> 342</span> <spanclass="comment"> * The socket are also stored here (in addition to participants_ map) so they're easier</span></div>
<divclass="line"><aname="l00343"></a><spanclass="lineno"> 343</span> <spanclass="comment"> * to pass to poll when RTCP runner is listening to incoming packets */</span></div>