1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 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 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 /* */ 19 /*********************************************************************************/ 20 21 /* 22 ** File: rtcp.h 23 ** 24 ** Description: 25 ** This module defines the RTCP class. This class is used to encode and 26 ** decode RTCP packets. Please refer to the RTCP design document for 27 ** details. 28 */ 29 30 #ifndef RTCP_H 31 #define RTCP_H 32 33 /* 34 ** Includes 35 */ 36 #ifndef OSCL_MEM_H_INCLUDED 37 #include "oscl_mem.h" 38 #endif 39 #ifndef OSCL_MEDIA_DATA_H 40 #include "oscl_media_data.h" 41 #endif 42 #ifndef RTPRTCP_H 43 #include "rtprtcp.h" 44 #endif 45 46 /* 47 ** Constants 48 */ 49 50 const int32 RTCP_BYE_SSRC_ARRAY_SIZE = 31; 51 const int32 RTCP_MAX_REPORT_BLOCKS = 31; 52 53 // This number determines how many RTCP report blocks are 54 // preallocated and how many are allocated dynamically 55 const uint NUM_PREALLOCATED_RTCP_RR_REPORT_BLOCKS = 1; 56 const uint NUM_PREALLOCATED_RTCP_SR_REPORT_BLOCKS = 1; 57 const uint NUM_PREALLOCATED_RTCP_CHUNK_ITEMS = 1; 58 const uint NUM_PREALLOCATED_RTCP_CHUNKS = 1; 59 60 61 // SDES item types 62 const uint8 NULL_RTCP_SDES = 0; 63 const uint8 CNAME_RTCP_SDES = 1; 64 const uint8 USERNAME_RTCP_SDES = 2; 65 const uint8 EMAIL_RTCP_SDES = 3; 66 const uint8 PHONE_RTCP_SDES = 4; 67 const uint8 LOC_RTCP_SDES = 5; 68 const uint8 TOOL_RTCP_SDES = 6; 69 const uint8 NOTE_RTCP_SDES = 7; 70 const uint8 PRIV_RTCP_SDES = 8; 71 72 // PVSS APP Packet Subtypes 73 const char PVSS_APP_RTCP_NAME[] = "PVSS"; 74 const char PSS0_APP_RTCP_NAME[] = "PSS0"; 75 const uint8 RTCP_NADU_APP_SUBTYPE = 0; 76 const uint16 RTCP_NADU_APP_DEFAULT_PLAYOUT_DELAY = 0xFFFF; 77 const uint16 RTCP_NADU_APP_DEFAULT_NUN = 0; 78 const uint8 DRC_REPORT = 0; 79 const uint8 LOW_BUF_WARNING = 1; 80 const uint8 HIGH_BUF_WARNING = 2; 81 const int16 RTCP_PVSS_APP_MAX_SUPPORTED_SUBTYPE = 2; /* this should always 82 * equal the last value 83 * in the list above. 84 */ 85 86 /* 87 * The report block is the basic component structure of 88 * the RTCP SR and RR 89 * 90 */ 91 struct RTCP_ReportBlock 92 { 93 uint32 sourceSSRC; 94 uint8 fractionLost; 95 int32 cumulativeNumberOfPacketsLost; 96 uint32 highestSequenceNumberReceived; 97 uint32 interarrivalJitter; 98 uint32 lastSR; 99 uint32 delaySinceLastSR; 100 }; 101 102 enum RTCPPacketType 103 { 104 SR_RTCP_PACKET, 105 RR_RTCP_PACKET, 106 SDES_RTCP_PACKET, 107 PVSS_APP_RTCP_PACKET, 108 APP_RTCP_PACKET, 109 BYE_RTCP_PACKET, 110 UNKNOWN_RTCP_PACKET 111 }; 112 113 114 115 /* 116 * This structure is used to hold the receiver report (RR) information 117 * 118 */ 119 class RTCP_RR 120 { 121 122 public: 123 RTCP_RR(uint in_max_report_blocks = RTCP_MAX_REPORT_BLOCKS) : senderSSRC(0), num_report_blocks(0), 124 max_report_blocks(in_max_report_blocks) 125 { 126 additional_reports = NULL; 127 }; 128 129 130 ~RTCP_RR() 131 { 132 if (additional_reports) 133 { 134 delete[] additional_reports; 135 } 136 }; 137 138 OSCL_IMPORT_REF RTCP_ReportBlock* get_report_block(uint index); 139 const RTCP_ReportBlock* read_report_block(uint index) const; 140 141 bool set_max_report_blocks(uint new_max_report_blocks); 142 143 bool set_report_block(uint index, const RTCP_ReportBlock& report_block); 144 145 uint get_num_report_blocks() const 146 { 147 return num_report_blocks; 148 }; 149 150 uint32 senderSSRC; 151 152 private: 153 uint num_report_blocks; 154 uint max_report_blocks; 155 RTCP_ReportBlock preallocated_reports[NUM_PREALLOCATED_RTCP_RR_REPORT_BLOCKS]; 156 RTCP_ReportBlock *additional_reports; 157 158 }; 159 160 161 class RTCP_SR 162 { 163 164 public: 165 RTCP_SR(uint in_max_report_blocks = RTCP_MAX_REPORT_BLOCKS) : senderSSRC(0), num_report_blocks(0), 166 max_report_blocks(in_max_report_blocks) 167 { 168 additional_reports = NULL; 169 }; 170 171 172 ~RTCP_SR() 173 { 174 if (additional_reports) 175 { 176 delete[] additional_reports; 177 } 178 }; 179 180 RTCP_ReportBlock* get_report_block(uint index); 181 const RTCP_ReportBlock* read_report_block(uint index) const; 182 183 bool set_max_report_blocks(uint new_max_report_blocks); 184 185 bool set_report_block(uint index, const RTCP_ReportBlock& report_block); 186 187 uint get_num_report_blocks() const 188 { 189 return num_report_blocks; 190 }; 191 192 uint32 senderSSRC; 193 uint32 NTP_timestamp_high; 194 uint32 NTP_timestamp_low; 195 uint32 RTP_timestamp; 196 uint32 packet_count; 197 uint32 octet_count; 198 199 private: 200 uint num_report_blocks; 201 uint max_report_blocks; 202 RTCP_ReportBlock preallocated_reports[NUM_PREALLOCATED_RTCP_SR_REPORT_BLOCKS]; 203 RTCP_ReportBlock *additional_reports; 204 205 }; 206 207 208 209 struct SDES_item 210 { 211 uint8 type; 212 OsclMemoryFragment content; 213 214 SDES_item() 215 { 216 type = 0; 217 content.ptr = NULL; 218 content.len = 0; 219 } 220 221 ~SDES_item() {}; 222 }; 223 224 class SDES_chunk 225 { 226 227 public: 228 SDES_chunk(uint32 in_ssrc = 0): ssrc(in_ssrc), 229 max_sdes_items(NUM_PREALLOCATED_RTCP_CHUNK_ITEMS), num_sdes_items(0), 230 chunk_size(0) 231 { 232 additional_items = NULL; 233 }; 234 ~SDES_chunk() 235 { 236 delete[] additional_items; 237 }; 238 uint32 ssrc; 239 240 void set_max_items(uint num_items); 241 242 SDES_item* get_item(uint item_index); 243 244 const SDES_item* read_item(uint item_index) const; 245 246 uint get_num_items() const 247 { 248 return num_sdes_items; 249 }; 250 251 bool add_item(const SDES_item& item); 252 uint get_chunk_size() const 253 { 254 return chunk_size; 255 }; 256 257 private: 258 uint max_sdes_items; 259 uint num_sdes_items; 260 uint chunk_size; 261 SDES_item chunk_items[NUM_PREALLOCATED_RTCP_CHUNK_ITEMS]; 262 SDES_item *additional_items; 263 264 }; 265 266 const int32 RTCP_SDES_MAX_NUM_CHUNKS = 32; 267 class RTCP_SDES 268 { 269 270 public: 271 RTCP_SDES(): chunk_count(0), 272 max_chunks(NUM_PREALLOCATED_RTCP_CHUNKS) 273 { 274 additional_chunks = NULL; 275 }; 276 277 ~RTCP_SDES() 278 { 279 delete[] additional_chunks; 280 }; 281 void set_max_chunks(uint new_max_chunks); 282 283 SDES_chunk* get_chunk(uint item_index); 284 285 const SDES_chunk* read_chunk(uint item_index) const; 286 287 uint get_num_chunks() const 288 { 289 return chunk_count; 290 }; 291 292 bool add_chunk(const SDES_chunk& chunk); 293 294 295 private: 296 uint chunk_count; 297 uint max_chunks; 298 299 SDES_chunk chunk_array[NUM_PREALLOCATED_RTCP_CHUNKS]; 300 SDES_chunk* additional_chunks; 301 302 }; 303 304 struct RTCP_BYE 305 { 306 uint8 src_count; 307 uint32 ssrc_array[RTCP_BYE_SSRC_ARRAY_SIZE]; 308 OsclMemoryFragment reason_string; 309 }; 310 311 struct APP_Common 312 { 313 uint32 sendTime; 314 uint32 recvRate; // bits/sec 315 uint32 recvRateInterval; 316 uint32 playbackBufDepth; 317 uint32 highestCtrlMediaSeqNum; 318 uint32 cumulativeBytes; 319 }; 320 321 struct APP_Extra_DRC 322 { 323 uint16 rebufCount; 324 uint16 missingPackets; 325 uint32 cumulativePacketsReceived; 326 uint32 totalProcessedFrames; 327 uint32 totalSkippedFrames; 328 uint32 cumulativePacketsLost; 329 }; 330 331 struct APP_Extra_BufLow 332 { 333 uint16 depletionRateInteger; 334 uint16 depletionRateFraction; 335 }; 336 337 struct APP_Extra_BufHigh 338 { 339 uint16 fillRateInteger; 340 uint16 fillRateFraction; 341 }; 342 343 344 struct RTCP_PVSS_APP 345 { 346 uint8 subtype; 347 APP_Common common; 348 union 349 { 350 APP_Extra_DRC extraDRC; 351 APP_Extra_BufLow extraBufLow; 352 APP_Extra_BufHigh extraBufHigh; 353 }; 354 }; 355 356 struct RTCP_PSS0_APP 357 { 358 uint32 sourcessrc; 359 uint16 playoutdelayinms; 360 uint16 nsn; 361 uint16 nun; 362 uint16 freebufferspace; 363 }; 364 365 struct RTCP_APP 366 { 367 uint8 subtype; 368 uint32 ssrc; 369 char type[4]; 370 union 371 { 372 RTCP_PVSS_APP pvss_app_data; 373 RTCP_PSS0_APP pss0_app_data; 374 OsclMemoryFragment app_data; // this for APPs other than "PVSS" & "PSS0" 375 }; 376 }; 377 378 379 380 /* 381 ** Classes 382 */ 383 class RTCP_Base 384 { 385 public: 386 RTCP_Base(const uint8 version); 387 OSCL_IMPORT_REF virtual ~RTCP_Base(); 388 389 protected: 390 uint8 rtcpVersion; 391 }; 392 393 #endif 394