1 /* 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 * 10 */ 11 12 #ifndef WEBRTC_TEST_RTCP_PACKET_PARSER_H_ 13 #define WEBRTC_TEST_RTCP_PACKET_PARSER_H_ 14 15 #include <map> 16 #include <string> 17 #include <vector> 18 19 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" 20 #include "webrtc/typedefs.h" 21 22 namespace webrtc { 23 namespace test { 24 25 class RtcpPacketParser; 26 27 class PacketType { 28 public: 29 virtual ~PacketType() {} 30 31 int num_packets() const { return num_packets_; } 32 33 protected: 34 PacketType() : num_packets_(0) {} 35 36 int num_packets_; 37 }; 38 39 class SenderReport : public PacketType { 40 public: 41 SenderReport() {} 42 virtual ~SenderReport() {} 43 44 uint32_t Ssrc() const { return sr_.SenderSSRC; } 45 uint32_t NtpSec() const { return sr_.NTPMostSignificant; } 46 uint32_t NtpFrac() const { return sr_.NTPLeastSignificant; } 47 uint32_t RtpTimestamp() const { return sr_.RTPTimestamp; } 48 uint32_t PacketCount() const { return sr_.SenderPacketCount; } 49 uint32_t OctetCount() const { return sr_.SenderOctetCount; } 50 51 private: 52 friend class RtcpPacketParser; 53 54 void Set(const RTCPUtility::RTCPPacketSR& sr) { 55 sr_ = sr; 56 ++num_packets_; 57 } 58 59 RTCPUtility::RTCPPacketSR sr_; 60 }; 61 62 class ReceiverReport : public PacketType { 63 public: 64 ReceiverReport() {} 65 virtual ~ReceiverReport() {} 66 67 uint32_t Ssrc() const { return rr_.SenderSSRC; } 68 69 private: 70 friend class RtcpPacketParser; 71 72 void Set(const RTCPUtility::RTCPPacketRR& rr) { 73 rr_ = rr; 74 ++num_packets_; 75 } 76 77 RTCPUtility::RTCPPacketRR rr_; 78 }; 79 80 class ReportBlock : public PacketType { 81 public: 82 ReportBlock() {} 83 virtual ~ReportBlock() {} 84 85 uint32_t Ssrc() const { return rb_.SSRC; } 86 uint8_t FractionLost() const { return rb_.FractionLost; } 87 uint32_t CumPacketLost() const { return rb_.CumulativeNumOfPacketsLost; } 88 uint32_t ExtHighestSeqNum() const { return rb_.ExtendedHighestSequenceNumber;} 89 uint32_t Jitter() const { return rb_.Jitter; } 90 uint32_t LastSr() const { return rb_.LastSR; } 91 uint32_t DelayLastSr()const { return rb_.DelayLastSR; } 92 93 private: 94 friend class RtcpPacketParser; 95 96 void Set(const RTCPUtility::RTCPPacketReportBlockItem& rb) { 97 rb_ = rb; 98 ++num_packets_; 99 } 100 101 RTCPUtility::RTCPPacketReportBlockItem rb_; 102 }; 103 104 class Ij : public PacketType { 105 public: 106 Ij() {} 107 virtual ~Ij() {} 108 109 private: 110 friend class RtcpPacketParser; 111 112 void Set() { ++num_packets_; } 113 }; 114 115 class IjItem : public PacketType { 116 public: 117 IjItem() {} 118 virtual ~IjItem() {} 119 120 uint32_t Jitter() const { return ij_item_.Jitter; } 121 122 private: 123 friend class RtcpPacketParser; 124 125 void Set(const RTCPUtility::RTCPPacketExtendedJitterReportItem& ij_item) { 126 ij_item_ = ij_item; 127 ++num_packets_; 128 } 129 130 RTCPUtility::RTCPPacketExtendedJitterReportItem ij_item_; 131 }; 132 133 class Sdes : public PacketType { 134 public: 135 Sdes() {} 136 virtual ~Sdes() {} 137 138 private: 139 friend class RtcpPacketParser; 140 141 void Set() { ++num_packets_; } 142 }; 143 144 class SdesChunk : public PacketType { 145 public: 146 SdesChunk() {} 147 virtual ~SdesChunk() {} 148 149 uint32_t Ssrc() const { return cname_.SenderSSRC; } 150 std::string Cname() const { return cname_.CName; } 151 152 private: 153 friend class RtcpPacketParser; 154 155 void Set(const RTCPUtility::RTCPPacketSDESCName& cname) { 156 cname_ = cname; 157 ++num_packets_; 158 } 159 160 RTCPUtility::RTCPPacketSDESCName cname_; 161 }; 162 163 class Bye : public PacketType { 164 public: 165 Bye() {} 166 virtual ~Bye() {} 167 168 uint32_t Ssrc() const { return bye_.SenderSSRC; } 169 170 private: 171 friend class RtcpPacketParser; 172 173 void Set(const RTCPUtility::RTCPPacketBYE& bye) { 174 bye_ = bye; 175 ++num_packets_; 176 } 177 178 RTCPUtility::RTCPPacketBYE bye_; 179 }; 180 181 class Rpsi : public PacketType { 182 public: 183 Rpsi() {} 184 virtual ~Rpsi() {} 185 186 uint32_t Ssrc() const { return rpsi_.SenderSSRC; } 187 uint32_t MediaSsrc() const { return rpsi_.MediaSSRC; } 188 uint8_t PayloadType() const { return rpsi_.PayloadType; } 189 uint16_t NumberOfValidBits() const { return rpsi_.NumberOfValidBits; } 190 uint64_t PictureId() const; 191 192 private: 193 friend class RtcpPacketParser; 194 195 void Set(const RTCPUtility::RTCPPacketPSFBRPSI& rpsi) { 196 rpsi_ = rpsi; 197 ++num_packets_; 198 } 199 200 RTCPUtility::RTCPPacketPSFBRPSI rpsi_; 201 }; 202 203 class App : public PacketType { 204 public: 205 App() {} 206 virtual ~App() {} 207 208 uint8_t SubType() const { return app_.SubType; } 209 uint32_t Name() const { return app_.Name; } 210 211 private: 212 friend class RtcpPacketParser; 213 214 void Set(const RTCPUtility::RTCPPacketAPP& app) { 215 app_ = app; 216 ++num_packets_; 217 } 218 219 RTCPUtility::RTCPPacketAPP app_; 220 }; 221 222 class AppItem : public PacketType { 223 public: 224 AppItem() {} 225 virtual ~AppItem() {} 226 227 uint8_t* Data() { return app_item_.Data; } 228 uint16_t DataLength() const { return app_item_.Size; } 229 230 private: 231 friend class RtcpPacketParser; 232 233 void Set(const RTCPUtility::RTCPPacketAPP& app) { 234 app_item_ = app; 235 ++num_packets_; 236 } 237 238 RTCPUtility::RTCPPacketAPP app_item_; 239 }; 240 241 class Pli : public PacketType { 242 public: 243 Pli() {} 244 virtual ~Pli() {} 245 246 uint32_t Ssrc() const { return pli_.SenderSSRC; } 247 uint32_t MediaSsrc() const { return pli_.MediaSSRC; } 248 249 private: 250 friend class RtcpPacketParser; 251 252 void Set(const RTCPUtility::RTCPPacketPSFBPLI& pli) { 253 pli_ = pli; 254 ++num_packets_; 255 } 256 257 RTCPUtility::RTCPPacketPSFBPLI pli_; 258 }; 259 260 class Sli : public PacketType { 261 public: 262 Sli() {} 263 virtual ~Sli() {} 264 265 uint32_t Ssrc() const { return sli_.SenderSSRC; } 266 uint32_t MediaSsrc() const { return sli_.MediaSSRC; } 267 268 private: 269 friend class RtcpPacketParser; 270 271 void Set(const RTCPUtility::RTCPPacketPSFBSLI& sli) { 272 sli_ = sli; 273 ++num_packets_; 274 } 275 276 RTCPUtility::RTCPPacketPSFBSLI sli_; 277 }; 278 279 class SliItem : public PacketType { 280 public: 281 SliItem() {} 282 virtual ~SliItem() {} 283 284 uint16_t FirstMb() const { return sli_item_.FirstMB; } 285 uint16_t NumberOfMb() const { return sli_item_.NumberOfMB; } 286 uint8_t PictureId() const { return sli_item_.PictureId; } 287 288 private: 289 friend class RtcpPacketParser; 290 291 void Set(const RTCPUtility::RTCPPacketPSFBSLIItem& sli_item) { 292 sli_item_ = sli_item; 293 ++num_packets_; 294 } 295 296 RTCPUtility::RTCPPacketPSFBSLIItem sli_item_; 297 }; 298 299 class Fir : public PacketType { 300 public: 301 Fir() {} 302 virtual ~Fir() {} 303 304 uint32_t Ssrc() const { return fir_.SenderSSRC; } 305 306 private: 307 friend class RtcpPacketParser; 308 309 void Set(const RTCPUtility::RTCPPacketPSFBFIR& fir) { 310 fir_ = fir; 311 ++num_packets_; 312 } 313 314 RTCPUtility::RTCPPacketPSFBFIR fir_; 315 }; 316 317 class FirItem : public PacketType { 318 public: 319 FirItem() {} 320 virtual ~FirItem() {} 321 322 uint32_t Ssrc() const { return fir_item_.SSRC; } 323 uint8_t SeqNum() const { return fir_item_.CommandSequenceNumber; } 324 325 private: 326 friend class RtcpPacketParser; 327 328 void Set(const RTCPUtility::RTCPPacketPSFBFIRItem& fir_item) { 329 fir_item_ = fir_item; 330 ++num_packets_; 331 } 332 333 RTCPUtility::RTCPPacketPSFBFIRItem fir_item_; 334 }; 335 336 class Nack : public PacketType { 337 public: 338 Nack() {} 339 virtual ~Nack() {} 340 341 uint32_t Ssrc() const { return nack_.SenderSSRC; } 342 uint32_t MediaSsrc() const { return nack_.MediaSSRC; } 343 344 private: 345 friend class RtcpPacketParser; 346 347 void Set(const RTCPUtility::RTCPPacketRTPFBNACK& nack) { 348 nack_ = nack; 349 ++num_packets_; 350 } 351 352 RTCPUtility::RTCPPacketRTPFBNACK nack_; 353 }; 354 355 class NackItem : public PacketType { 356 public: 357 NackItem() {} 358 virtual ~NackItem() {} 359 360 std::vector<uint16_t> last_nack_list() const { 361 return last_nack_list_; 362 } 363 364 private: 365 friend class RtcpPacketParser; 366 367 void Set(const RTCPUtility::RTCPPacketRTPFBNACKItem& nack_item) { 368 last_nack_list_.push_back(nack_item.PacketID); 369 for (int i = 0; i < 16; ++i) { 370 if (nack_item.BitMask & (1 << i)) { 371 last_nack_list_.push_back(nack_item.PacketID + i + 1); 372 } 373 } 374 ++num_packets_; 375 } 376 void Clear() { last_nack_list_.clear(); } 377 378 std::vector<uint16_t> last_nack_list_; 379 }; 380 381 class PsfbApp : public PacketType { 382 public: 383 PsfbApp() {} 384 virtual ~PsfbApp() {} 385 386 uint32_t Ssrc() const { return psfb_app_.SenderSSRC; } 387 388 private: 389 friend class RtcpPacketParser; 390 391 void Set(const RTCPUtility::RTCPPacketPSFBAPP& psfb_app) { 392 psfb_app_ = psfb_app; 393 ++num_packets_; 394 } 395 396 RTCPUtility::RTCPPacketPSFBAPP psfb_app_; 397 }; 398 399 class RembItem : public PacketType { 400 public: 401 RembItem() : last_bitrate_bps_(0) {} 402 virtual ~RembItem() {} 403 404 int last_bitrate_bps() const { return last_bitrate_bps_; } 405 std::vector<uint32_t> last_ssrc_list() { 406 return last_ssrc_list_; 407 } 408 409 private: 410 friend class RtcpPacketParser; 411 412 void Set(const RTCPUtility::RTCPPacketPSFBREMBItem& remb_item) { 413 last_bitrate_bps_ = remb_item.BitRate; 414 last_ssrc_list_.clear(); 415 last_ssrc_list_.insert( 416 last_ssrc_list_.end(), 417 remb_item.SSRCs, 418 remb_item.SSRCs + remb_item.NumberOfSSRCs); 419 ++num_packets_; 420 } 421 422 uint32_t last_bitrate_bps_; 423 std::vector<uint32_t> last_ssrc_list_; 424 }; 425 426 class Tmmbr : public PacketType { 427 public: 428 Tmmbr() {} 429 virtual ~Tmmbr() {} 430 431 uint32_t Ssrc() const { return tmmbr_.SenderSSRC; } 432 433 private: 434 friend class RtcpPacketParser; 435 436 void Set(const RTCPUtility::RTCPPacketRTPFBTMMBR& tmmbr) { 437 tmmbr_ = tmmbr; 438 ++num_packets_; 439 } 440 441 RTCPUtility::RTCPPacketRTPFBTMMBR tmmbr_; 442 }; 443 444 class TmmbrItem : public PacketType { 445 public: 446 TmmbrItem() {} 447 virtual ~TmmbrItem() {} 448 449 uint32_t Ssrc() const { return tmmbr_item_.SSRC; } 450 uint32_t BitrateKbps() const { return tmmbr_item_.MaxTotalMediaBitRate; } 451 uint32_t Overhead() const { return tmmbr_item_.MeasuredOverhead; } 452 453 private: 454 friend class RtcpPacketParser; 455 456 void Set(const RTCPUtility::RTCPPacketRTPFBTMMBRItem& tmmbr_item) { 457 tmmbr_item_ = tmmbr_item; 458 ++num_packets_; 459 } 460 461 RTCPUtility::RTCPPacketRTPFBTMMBRItem tmmbr_item_; 462 }; 463 464 465 class Tmmbn : public PacketType { 466 public: 467 Tmmbn() {} 468 virtual ~Tmmbn() {} 469 470 uint32_t Ssrc() const { return tmmbn_.SenderSSRC; } 471 472 private: 473 friend class RtcpPacketParser; 474 475 void Set(const RTCPUtility::RTCPPacketRTPFBTMMBN& tmmbn) { 476 tmmbn_ = tmmbn; 477 ++num_packets_; 478 } 479 480 RTCPUtility::RTCPPacketRTPFBTMMBN tmmbn_; 481 }; 482 483 class TmmbnItems : public PacketType { 484 public: 485 TmmbnItems() {} 486 virtual ~TmmbnItems() {} 487 488 uint32_t Ssrc(uint8_t num) const { 489 assert(num < tmmbns_.size()); 490 return tmmbns_[num].SSRC; 491 } 492 uint32_t BitrateKbps(uint8_t num) const { 493 assert(num < tmmbns_.size()); 494 return tmmbns_[num].MaxTotalMediaBitRate; 495 } 496 uint32_t Overhead(uint8_t num) const { 497 assert(num < tmmbns_.size()); 498 return tmmbns_[num].MeasuredOverhead; 499 } 500 501 private: 502 friend class RtcpPacketParser; 503 504 void Set(const RTCPUtility::RTCPPacketRTPFBTMMBNItem& tmmbn_item) { 505 tmmbns_.push_back(tmmbn_item); 506 ++num_packets_; 507 } 508 void Clear() { tmmbns_.clear(); } 509 510 std::vector<RTCPUtility::RTCPPacketRTPFBTMMBNItem> tmmbns_; 511 }; 512 513 class XrHeader : public PacketType { 514 public: 515 XrHeader() {} 516 virtual ~XrHeader() {} 517 518 uint32_t Ssrc() const { return xr_header_.OriginatorSSRC; } 519 520 private: 521 friend class RtcpPacketParser; 522 523 void Set(const RTCPUtility::RTCPPacketXR& xr_header) { 524 xr_header_ = xr_header; 525 ++num_packets_; 526 } 527 528 RTCPUtility::RTCPPacketXR xr_header_; 529 }; 530 531 class Rrtr : public PacketType { 532 public: 533 Rrtr() {} 534 virtual ~Rrtr() {} 535 536 uint32_t NtpSec() const { return rrtr_.NTPMostSignificant; } 537 uint32_t NtpFrac() const { return rrtr_.NTPLeastSignificant; } 538 539 private: 540 friend class RtcpPacketParser; 541 542 void Set(const RTCPUtility::RTCPPacketXRReceiverReferenceTimeItem& rrtr) { 543 rrtr_ = rrtr; 544 ++num_packets_; 545 } 546 547 RTCPUtility::RTCPPacketXRReceiverReferenceTimeItem rrtr_; 548 }; 549 550 class Dlrr : public PacketType { 551 public: 552 Dlrr() {} 553 virtual ~Dlrr() {} 554 555 private: 556 friend class RtcpPacketParser; 557 558 void Set() { ++num_packets_; } 559 }; 560 561 class DlrrItems : public PacketType { 562 public: 563 DlrrItems() {} 564 virtual ~DlrrItems() {} 565 566 uint32_t Ssrc(uint8_t num) const { 567 assert(num < dlrrs_.size()); 568 return dlrrs_[num].SSRC; 569 } 570 uint32_t LastRr(uint8_t num) const { 571 assert(num < dlrrs_.size()); 572 return dlrrs_[num].LastRR; 573 } 574 uint32_t DelayLastRr(uint8_t num) const { 575 assert(num < dlrrs_.size()); 576 return dlrrs_[num].DelayLastRR; 577 } 578 579 private: 580 friend class RtcpPacketParser; 581 582 void Set(const RTCPUtility::RTCPPacketXRDLRRReportBlockItem& dlrr) { 583 dlrrs_.push_back(dlrr); 584 ++num_packets_; 585 } 586 void Clear() { dlrrs_.clear(); } 587 588 std::vector<RTCPUtility::RTCPPacketXRDLRRReportBlockItem> dlrrs_; 589 }; 590 591 class VoipMetric : public PacketType { 592 public: 593 VoipMetric() {} 594 virtual ~VoipMetric() {} 595 596 uint32_t Ssrc() const { return voip_metric_.SSRC; } 597 uint8_t LossRate() { return voip_metric_.lossRate; } 598 uint8_t DiscardRate() { return voip_metric_.discardRate; } 599 uint8_t BurstDensity() { return voip_metric_.burstDensity; } 600 uint8_t GapDensity() { return voip_metric_.gapDensity; } 601 uint16_t BurstDuration() { return voip_metric_.burstDuration; } 602 uint16_t GapDuration() { return voip_metric_.gapDuration; } 603 uint16_t RoundTripDelay() { return voip_metric_.roundTripDelay; } 604 uint16_t EndSystemDelay() { return voip_metric_.endSystemDelay; } 605 uint8_t SignalLevel() { return voip_metric_.signalLevel; } 606 uint8_t NoiseLevel() { return voip_metric_.noiseLevel; } 607 uint8_t Rerl() { return voip_metric_.RERL; } 608 uint8_t Gmin() { return voip_metric_.Gmin; } 609 uint8_t Rfactor() { return voip_metric_.Rfactor; } 610 uint8_t ExtRfactor() { return voip_metric_.extRfactor; } 611 uint8_t MosLq() { return voip_metric_.MOSLQ; } 612 uint8_t MosCq() { return voip_metric_.MOSCQ; } 613 uint8_t RxConfig() { return voip_metric_.RXconfig; } 614 uint16_t JbNominal() { return voip_metric_.JBnominal; } 615 uint16_t JbMax() { return voip_metric_.JBmax; } 616 uint16_t JbAbsMax() { return voip_metric_.JBabsMax; } 617 618 private: 619 friend class RtcpPacketParser; 620 621 void Set(const RTCPUtility::RTCPPacketXRVOIPMetricItem& voip_metric) { 622 voip_metric_ = voip_metric; 623 ++num_packets_; 624 } 625 626 RTCPUtility::RTCPPacketXRVOIPMetricItem voip_metric_; 627 }; 628 629 class RtcpPacketParser { 630 public: 631 RtcpPacketParser(); 632 ~RtcpPacketParser(); 633 634 void Parse(const void *packet, size_t packet_len); 635 636 SenderReport* sender_report() { return &sender_report_; } 637 ReceiverReport* receiver_report() { return &receiver_report_; } 638 ReportBlock* report_block() { return &report_block_; } 639 Sdes* sdes() { return &sdes_; } 640 SdesChunk* sdes_chunk() { return &sdes_chunk_; } 641 Bye* bye() { return &bye_; } 642 App* app() { return &app_; } 643 AppItem* app_item() { return &app_item_; } 644 Ij* ij() { return &ij_; } 645 IjItem* ij_item() { return &ij_item_; } 646 Pli* pli() { return &pli_; } 647 Sli* sli() { return &sli_; } 648 SliItem* sli_item() { return &sli_item_; } 649 Rpsi* rpsi() { return &rpsi_; } 650 Fir* fir() { return &fir_; } 651 FirItem* fir_item() { return &fir_item_; } 652 Nack* nack() { return &nack_; } 653 NackItem* nack_item() { return &nack_item_; } 654 PsfbApp* psfb_app() { return &psfb_app_; } 655 RembItem* remb_item() { return &remb_item_; } 656 Tmmbr* tmmbr() { return &tmmbr_; } 657 TmmbrItem* tmmbr_item() { return &tmmbr_item_; } 658 Tmmbn* tmmbn() { return &tmmbn_; } 659 TmmbnItems* tmmbn_items() { return &tmmbn_items_; } 660 XrHeader* xr_header() { return &xr_header_; } 661 Rrtr* rrtr() { return &rrtr_; } 662 Dlrr* dlrr() { return &dlrr_; } 663 DlrrItems* dlrr_items() { return &dlrr_items_; } 664 VoipMetric* voip_metric() { return &voip_metric_; } 665 666 int report_blocks_per_ssrc(uint32_t ssrc) { 667 return report_blocks_per_ssrc_[ssrc]; 668 } 669 670 private: 671 SenderReport sender_report_; 672 ReceiverReport receiver_report_; 673 ReportBlock report_block_; 674 Sdes sdes_; 675 SdesChunk sdes_chunk_; 676 Bye bye_; 677 App app_; 678 AppItem app_item_; 679 Ij ij_; 680 IjItem ij_item_; 681 Pli pli_; 682 Sli sli_; 683 SliItem sli_item_; 684 Rpsi rpsi_; 685 Fir fir_; 686 FirItem fir_item_; 687 Nack nack_; 688 NackItem nack_item_; 689 PsfbApp psfb_app_; 690 RembItem remb_item_; 691 Tmmbr tmmbr_; 692 TmmbrItem tmmbr_item_; 693 Tmmbn tmmbn_; 694 TmmbnItems tmmbn_items_; 695 XrHeader xr_header_; 696 Rrtr rrtr_; 697 Dlrr dlrr_; 698 DlrrItems dlrr_items_; 699 VoipMetric voip_metric_; 700 701 std::map<uint32_t, int> report_blocks_per_ssrc_; 702 }; 703 } // namespace test 704 } // namespace webrtc 705 #endif // WEBRTC_TEST_RTCP_PACKET_PARSER_H_ 706