OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 * | 9 * |
10 */ | 10 */ |
11 | 11 |
12 #ifndef WEBRTC_MODULES_RTP_RTCP_RTCP_PACKET_H_ | 12 #ifndef WEBRTC_MODULES_RTP_RTCP_RTCP_PACKET_H_ |
13 #define WEBRTC_MODULES_RTP_RTCP_RTCP_PACKET_H_ | 13 #define WEBRTC_MODULES_RTP_RTCP_RTCP_PACKET_H_ |
14 | 14 |
15 #include <map> | 15 #include <map> |
16 #include <string> | 16 #include <string> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
| 19 #include "webrtc/base/scoped_ptr.h" |
19 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
20 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" | 21 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
21 #include "webrtc/typedefs.h" | 22 #include "webrtc/typedefs.h" |
22 | 23 |
23 namespace webrtc { | 24 namespace webrtc { |
24 namespace rtcp { | 25 namespace rtcp { |
25 | 26 |
26 enum { kCommonFbFmtLength = 12 }; | 27 static const int kCommonFbFmtLength = 12; |
27 enum { kReportBlockLength = 24 }; | 28 static const int kReportBlockLength = 24; |
28 | 29 |
29 class Dlrr; | 30 class Dlrr; |
30 class RawPacket; | 31 class RawPacket; |
31 class Rrtr; | 32 class Rrtr; |
32 class VoipMetric; | 33 class VoipMetric; |
33 | 34 |
34 // Class for building RTCP packets. | 35 // Class for building RTCP packets. |
35 // | 36 // |
36 // Example: | 37 // Example: |
37 // ReportBlock report_block; | 38 // ReportBlock report_block; |
(...skipping 19 matching lines...) Expand all Loading... |
57 // rr.Append(&fir) // Builds a compound RTCP packet with | 58 // rr.Append(&fir) // Builds a compound RTCP packet with |
58 // RawPacket packet = rr.Build(); // a receiver report, report block | 59 // RawPacket packet = rr.Build(); // a receiver report, report block |
59 // // and fir message. | 60 // // and fir message. |
60 | 61 |
61 class RtcpPacket { | 62 class RtcpPacket { |
62 public: | 63 public: |
63 virtual ~RtcpPacket() {} | 64 virtual ~RtcpPacket() {} |
64 | 65 |
65 void Append(RtcpPacket* packet); | 66 void Append(RtcpPacket* packet); |
66 | 67 |
67 RawPacket Build() const; | 68 // Callback used to signal that an RTCP packet is ready. Note that this may |
| 69 // not contain all data in this RtcpPacket; if a packet cannot fit in |
| 70 // max_length bytes, it will be fragmented and multiple calls to this |
| 71 // callback will be made. |
| 72 class PacketReadyCallback { |
| 73 public: |
| 74 PacketReadyCallback() {} |
| 75 virtual ~PacketReadyCallback() {} |
68 | 76 |
69 void Build(uint8_t* packet, size_t* length, size_t max_length) const; | 77 virtual void OnPacketReady(uint8_t* data, size_t length) = 0; |
| 78 }; |
| 79 |
| 80 // Convenience method mostly used for test. Max length of IP_PACKET_SIZE is |
| 81 // used, will cause assertion error if fragmentation occurs. |
| 82 rtc::scoped_ptr<RawPacket> Build() const; |
| 83 |
| 84 // Returns true if all calls to Create succeeded. A buffer of size |
| 85 // IP_PACKET_SIZE will be allocated and reused between calls to callback. |
| 86 bool Build(PacketReadyCallback* callback) const; |
| 87 |
| 88 // Returns true if all calls to Create succeeded. Provided buffer reference |
| 89 // will be used for all calls to callback. |
| 90 bool BuildExternalBuffer(uint8_t* buffer, |
| 91 size_t max_length, |
| 92 PacketReadyCallback* callback) const; |
70 | 93 |
71 protected: | 94 protected: |
72 RtcpPacket() : kHeaderLength(4) {} | 95 RtcpPacket() : kHeaderLength(4) {} |
73 | 96 |
74 virtual void Create( | 97 virtual bool Create(uint8_t* packet, |
75 uint8_t* packet, size_t* length, size_t max_length) const = 0; | 98 size_t* index, |
| 99 size_t max_length, |
| 100 PacketReadyCallback* callback) const = 0; |
| 101 |
| 102 bool OnBufferFull(uint8_t* packet, |
| 103 size_t* index, |
| 104 RtcpPacket::PacketReadyCallback* callback) const; |
76 | 105 |
77 const size_t kHeaderLength; | 106 const size_t kHeaderLength; |
78 | 107 |
79 private: | 108 private: |
80 void CreateAndAddAppended( | 109 bool CreateAndAddAppended(uint8_t* packet, |
81 uint8_t* packet, size_t* length, size_t max_length) const; | 110 size_t* index, |
| 111 size_t max_length, |
| 112 PacketReadyCallback* callback) const; |
82 | 113 |
83 std::vector<RtcpPacket*> appended_packets_; | 114 std::vector<RtcpPacket*> appended_packets_; |
84 }; | 115 }; |
85 | 116 |
86 class Empty : public RtcpPacket { | 117 class Empty : public RtcpPacket { |
87 public: | 118 public: |
88 Empty() : RtcpPacket() {} | 119 Empty() : RtcpPacket() {} |
89 | 120 |
90 virtual ~Empty() {} | 121 virtual ~Empty() {} |
91 | 122 |
92 protected: | 123 protected: |
93 void Create(uint8_t* packet, | 124 bool Create(uint8_t* packet, |
94 size_t* length, | 125 size_t* index, |
95 size_t max_length) const override; | 126 size_t max_length, |
| 127 RtcpPacket::PacketReadyCallback* callback) const override; |
96 | 128 |
97 private: | 129 private: |
98 DISALLOW_COPY_AND_ASSIGN(Empty); | 130 DISALLOW_COPY_AND_ASSIGN(Empty); |
99 }; | 131 }; |
100 | 132 |
101 // From RFC 3550, RTP: A Transport Protocol for Real-Time Applications. | 133 // From RFC 3550, RTP: A Transport Protocol for Real-Time Applications. |
102 // | 134 // |
103 // RTCP report block (RFC 3550). | 135 // RTCP report block (RFC 3550). |
104 // | 136 // |
105 // 0 1 2 3 | 137 // 0 1 2 3 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 227 } |
196 void WithRtpTimestamp(uint32_t rtp_timestamp) { | 228 void WithRtpTimestamp(uint32_t rtp_timestamp) { |
197 sr_.RTPTimestamp = rtp_timestamp; | 229 sr_.RTPTimestamp = rtp_timestamp; |
198 } | 230 } |
199 void WithPacketCount(uint32_t packet_count) { | 231 void WithPacketCount(uint32_t packet_count) { |
200 sr_.SenderPacketCount = packet_count; | 232 sr_.SenderPacketCount = packet_count; |
201 } | 233 } |
202 void WithOctetCount(uint32_t octet_count) { | 234 void WithOctetCount(uint32_t octet_count) { |
203 sr_.SenderOctetCount = octet_count; | 235 sr_.SenderOctetCount = octet_count; |
204 } | 236 } |
205 void WithReportBlock(ReportBlock* block); | 237 bool WithReportBlock(ReportBlock* block); |
206 | 238 |
207 protected: | 239 protected: |
208 void Create(uint8_t* packet, | 240 bool Create(uint8_t* packet, |
209 size_t* length, | 241 size_t* index, |
210 size_t max_length) const override; | 242 size_t max_length, |
| 243 RtcpPacket::PacketReadyCallback* callback) const override; |
211 | 244 |
212 private: | 245 private: |
213 enum { kMaxNumberOfReportBlocks = 0x1f }; | 246 static const int kMaxNumberOfReportBlocks = 0x1f; |
214 | 247 |
215 size_t BlockLength() const { | 248 size_t BlockLength() const { |
216 const size_t kSrHeaderLength = 8; | 249 const size_t kSrHeaderLength = 8; |
217 const size_t kSenderInfoLength = 20; | 250 const size_t kSenderInfoLength = 20; |
218 return kSrHeaderLength + kSenderInfoLength + | 251 return kSrHeaderLength + kSenderInfoLength + |
219 report_blocks_.size() * kReportBlockLength; | 252 report_blocks_.size() * kReportBlockLength; |
220 } | 253 } |
221 | 254 |
222 RTCPUtility::RTCPPacketSR sr_; | 255 RTCPUtility::RTCPPacketSR sr_; |
223 std::vector<RTCPUtility::RTCPPacketReportBlockItem> report_blocks_; | 256 std::vector<RTCPUtility::RTCPPacketReportBlockItem> report_blocks_; |
(...skipping 18 matching lines...) Expand all Loading... |
242 public: | 275 public: |
243 ReceiverReport() : RtcpPacket() { | 276 ReceiverReport() : RtcpPacket() { |
244 memset(&rr_, 0, sizeof(rr_)); | 277 memset(&rr_, 0, sizeof(rr_)); |
245 } | 278 } |
246 | 279 |
247 virtual ~ReceiverReport() {} | 280 virtual ~ReceiverReport() {} |
248 | 281 |
249 void From(uint32_t ssrc) { | 282 void From(uint32_t ssrc) { |
250 rr_.SenderSSRC = ssrc; | 283 rr_.SenderSSRC = ssrc; |
251 } | 284 } |
252 void WithReportBlock(ReportBlock* block); | 285 bool WithReportBlock(ReportBlock* block); |
253 | 286 |
254 protected: | 287 protected: |
255 void Create(uint8_t* packet, | 288 bool Create(uint8_t* packet, |
256 size_t* length, | 289 size_t* index, |
257 size_t max_length) const override; | 290 size_t max_length, |
| 291 RtcpPacket::PacketReadyCallback* callback) const override; |
258 | 292 |
259 private: | 293 private: |
260 enum { kMaxNumberOfReportBlocks = 0x1f }; | 294 static const int kMaxNumberOfReportBlocks = 0x1F; |
261 | 295 |
262 size_t BlockLength() const { | 296 size_t BlockLength() const { |
263 const size_t kRrHeaderLength = 8; | 297 const size_t kRrHeaderLength = 8; |
264 return kRrHeaderLength + report_blocks_.size() * kReportBlockLength; | 298 return kRrHeaderLength + report_blocks_.size() * kReportBlockLength; |
265 } | 299 } |
266 | 300 |
267 RTCPUtility::RTCPPacketRR rr_; | 301 RTCPUtility::RTCPPacketRR rr_; |
268 std::vector<RTCPUtility::RTCPPacketReportBlockItem> report_blocks_; | 302 std::vector<RTCPUtility::RTCPPacketReportBlockItem> report_blocks_; |
269 | 303 |
270 DISALLOW_COPY_AND_ASSIGN(ReceiverReport); | 304 DISALLOW_COPY_AND_ASSIGN(ReceiverReport); |
(...skipping 17 matching lines...) Expand all Loading... |
288 // If present, this RTCP packet must be placed after a receiver report | 322 // If present, this RTCP packet must be placed after a receiver report |
289 // (inside a compound RTCP packet), and MUST have the same value for RC | 323 // (inside a compound RTCP packet), and MUST have the same value for RC |
290 // (reception report count) as the receiver report. | 324 // (reception report count) as the receiver report. |
291 | 325 |
292 class Ij : public RtcpPacket { | 326 class Ij : public RtcpPacket { |
293 public: | 327 public: |
294 Ij() : RtcpPacket() {} | 328 Ij() : RtcpPacket() {} |
295 | 329 |
296 virtual ~Ij() {} | 330 virtual ~Ij() {} |
297 | 331 |
298 void WithJitterItem(uint32_t jitter); | 332 bool WithJitterItem(uint32_t jitter); |
299 | 333 |
300 protected: | 334 protected: |
301 void Create(uint8_t* packet, | 335 bool Create(uint8_t* packet, |
302 size_t* length, | 336 size_t* index, |
303 size_t max_length) const override; | 337 size_t max_length, |
| 338 RtcpPacket::PacketReadyCallback* callback) const override; |
304 | 339 |
305 private: | 340 private: |
306 enum { kMaxNumberOfIjItems = 0x1f }; | 341 static const int kMaxNumberOfIjItems = 0x1f; |
307 | 342 |
308 size_t BlockLength() const { | 343 size_t BlockLength() const { |
309 return kHeaderLength + 4 * ij_items_.size(); | 344 return kHeaderLength + 4 * ij_items_.size(); |
310 } | 345 } |
311 | 346 |
312 std::vector<uint32_t> ij_items_; | 347 std::vector<uint32_t> ij_items_; |
313 | 348 |
314 DISALLOW_COPY_AND_ASSIGN(Ij); | 349 DISALLOW_COPY_AND_ASSIGN(Ij); |
315 }; | 350 }; |
316 | 351 |
(...skipping 22 matching lines...) Expand all Loading... |
339 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 374 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
340 // | CNAME=1 | length | user and domain name ... | 375 // | CNAME=1 | length | user and domain name ... |
341 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 376 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
342 | 377 |
343 class Sdes : public RtcpPacket { | 378 class Sdes : public RtcpPacket { |
344 public: | 379 public: |
345 Sdes() : RtcpPacket() {} | 380 Sdes() : RtcpPacket() {} |
346 | 381 |
347 virtual ~Sdes() {} | 382 virtual ~Sdes() {} |
348 | 383 |
349 void WithCName(uint32_t ssrc, std::string cname); | 384 bool WithCName(uint32_t ssrc, const std::string& cname); |
350 | 385 |
351 struct Chunk { | 386 struct Chunk { |
352 uint32_t ssrc; | 387 uint32_t ssrc; |
353 std::string name; | 388 std::string name; |
354 int null_octets; | 389 int null_octets; |
355 }; | 390 }; |
356 | 391 |
357 protected: | 392 protected: |
358 void Create(uint8_t* packet, | 393 bool Create(uint8_t* packet, |
359 size_t* length, | 394 size_t* index, |
360 size_t max_length) const override; | 395 size_t max_length, |
| 396 RtcpPacket::PacketReadyCallback* callback) const override; |
361 | 397 |
362 private: | 398 private: |
363 enum { kMaxNumberOfChunks = 0x1f }; | 399 static const int kMaxNumberOfChunks = 0x1f; |
364 | 400 |
365 size_t BlockLength() const; | 401 size_t BlockLength() const; |
366 | 402 |
367 std::vector<Chunk> chunks_; | 403 std::vector<Chunk> chunks_; |
368 | 404 |
369 DISALLOW_COPY_AND_ASSIGN(Sdes); | 405 DISALLOW_COPY_AND_ASSIGN(Sdes); |
370 }; | 406 }; |
371 | 407 |
372 // | 408 // |
373 // Bye packet (BYE) (RFC 3550). | 409 // Bye packet (BYE) (RFC 3550). |
(...skipping 13 matching lines...) Expand all Loading... |
387 public: | 423 public: |
388 Bye() : RtcpPacket() { | 424 Bye() : RtcpPacket() { |
389 memset(&bye_, 0, sizeof(bye_)); | 425 memset(&bye_, 0, sizeof(bye_)); |
390 } | 426 } |
391 | 427 |
392 virtual ~Bye() {} | 428 virtual ~Bye() {} |
393 | 429 |
394 void From(uint32_t ssrc) { | 430 void From(uint32_t ssrc) { |
395 bye_.SenderSSRC = ssrc; | 431 bye_.SenderSSRC = ssrc; |
396 } | 432 } |
397 void WithCsrc(uint32_t csrc); | 433 |
| 434 bool WithCsrc(uint32_t csrc); |
| 435 |
| 436 // TODO(sprang): Add support for reason field? |
398 | 437 |
399 protected: | 438 protected: |
400 void Create(uint8_t* packet, | 439 bool Create(uint8_t* packet, |
401 size_t* length, | 440 size_t* index, |
402 size_t max_length) const override; | 441 size_t max_length, |
| 442 RtcpPacket::PacketReadyCallback* callback) const override; |
403 | 443 |
404 private: | 444 private: |
405 enum { kMaxNumberOfCsrcs = 0x1f - 1 }; | 445 static const int kMaxNumberOfCsrcs = 0x1f - 1; // First item is sender SSRC. |
406 | 446 |
407 size_t BlockLength() const { | 447 size_t BlockLength() const { |
408 size_t source_count = 1 + csrcs_.size(); | 448 size_t source_count = 1 + csrcs_.size(); |
409 return kHeaderLength + 4 * source_count; | 449 return kHeaderLength + 4 * source_count; |
410 } | 450 } |
411 | 451 |
412 RTCPUtility::RTCPPacketBYE bye_; | 452 RTCPUtility::RTCPPacketBYE bye_; |
413 std::vector<uint32_t> csrcs_; | 453 std::vector<uint32_t> csrcs_; |
414 | 454 |
415 DISALLOW_COPY_AND_ASSIGN(Bye); | 455 DISALLOW_COPY_AND_ASSIGN(Bye); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 } | 491 } |
452 void WithData(const uint8_t* data, uint16_t data_length) { | 492 void WithData(const uint8_t* data, uint16_t data_length) { |
453 assert(data); | 493 assert(data); |
454 assert(data_length <= kRtcpAppCode_DATA_SIZE); | 494 assert(data_length <= kRtcpAppCode_DATA_SIZE); |
455 assert(data_length % 4 == 0); | 495 assert(data_length % 4 == 0); |
456 memcpy(app_.Data, data, data_length); | 496 memcpy(app_.Data, data, data_length); |
457 app_.Size = data_length; | 497 app_.Size = data_length; |
458 } | 498 } |
459 | 499 |
460 protected: | 500 protected: |
461 void Create(uint8_t* packet, | 501 bool Create(uint8_t* packet, |
462 size_t* length, | 502 size_t* index, |
463 size_t max_length) const override; | 503 size_t max_length, |
| 504 RtcpPacket::PacketReadyCallback* callback) const override; |
464 | 505 |
465 private: | 506 private: |
466 size_t BlockLength() const { | 507 size_t BlockLength() const { |
467 return 12 + app_.Size; | 508 return 12 + app_.Size; |
468 } | 509 } |
469 | 510 |
470 uint32_t ssrc_; | 511 uint32_t ssrc_; |
471 RTCPUtility::RTCPPacketAPP app_; | 512 RTCPUtility::RTCPPacketAPP app_; |
472 | 513 |
473 DISALLOW_COPY_AND_ASSIGN(App); | 514 DISALLOW_COPY_AND_ASSIGN(App); |
(...skipping 28 matching lines...) Expand all Loading... |
502 virtual ~Pli() {} | 543 virtual ~Pli() {} |
503 | 544 |
504 void From(uint32_t ssrc) { | 545 void From(uint32_t ssrc) { |
505 pli_.SenderSSRC = ssrc; | 546 pli_.SenderSSRC = ssrc; |
506 } | 547 } |
507 void To(uint32_t ssrc) { | 548 void To(uint32_t ssrc) { |
508 pli_.MediaSSRC = ssrc; | 549 pli_.MediaSSRC = ssrc; |
509 } | 550 } |
510 | 551 |
511 protected: | 552 protected: |
512 void Create(uint8_t* packet, | 553 bool Create(uint8_t* packet, |
513 size_t* length, | 554 size_t* index, |
514 size_t max_length) const override; | 555 size_t max_length, |
| 556 RtcpPacket::PacketReadyCallback* callback) const override; |
515 | 557 |
516 private: | 558 private: |
517 size_t BlockLength() const { | 559 size_t BlockLength() const { |
518 return kCommonFbFmtLength; | 560 return kCommonFbFmtLength; |
519 } | 561 } |
520 | 562 |
521 RTCPUtility::RTCPPacketPSFBPLI pli_; | 563 RTCPUtility::RTCPPacketPSFBPLI pli_; |
522 | 564 |
523 DISALLOW_COPY_AND_ASSIGN(Pli); | 565 DISALLOW_COPY_AND_ASSIGN(Pli); |
524 }; | 566 }; |
(...skipping 29 matching lines...) Expand all Loading... |
554 void WithNumberOfMb(uint16_t number_mb) { | 596 void WithNumberOfMb(uint16_t number_mb) { |
555 assert(number_mb <= 0x1fff); | 597 assert(number_mb <= 0x1fff); |
556 sli_item_.NumberOfMB = number_mb; | 598 sli_item_.NumberOfMB = number_mb; |
557 } | 599 } |
558 void WithPictureId(uint8_t picture_id) { | 600 void WithPictureId(uint8_t picture_id) { |
559 assert(picture_id <= 0x3f); | 601 assert(picture_id <= 0x3f); |
560 sli_item_.PictureId = picture_id; | 602 sli_item_.PictureId = picture_id; |
561 } | 603 } |
562 | 604 |
563 protected: | 605 protected: |
564 void Create(uint8_t* packet, | 606 bool Create(uint8_t* packet, |
565 size_t* length, | 607 size_t* index, |
566 size_t max_length) const override; | 608 size_t max_length, |
| 609 RtcpPacket::PacketReadyCallback* callback) const override; |
567 | 610 |
568 private: | 611 private: |
569 size_t BlockLength() const { | 612 size_t BlockLength() const { |
570 const size_t kFciLength = 4; | 613 const size_t kFciLength = 4; |
571 return kCommonFbFmtLength + kFciLength; | 614 return kCommonFbFmtLength + kFciLength; |
572 } | 615 } |
573 | 616 |
574 RTCPUtility::RTCPPacketPSFBSLI sli_; | 617 RTCPUtility::RTCPPacketPSFBSLI sli_; |
575 RTCPUtility::RTCPPacketPSFBSLIItem sli_item_; | 618 RTCPUtility::RTCPPacketPSFBSLIItem sli_item_; |
576 | 619 |
(...skipping 19 matching lines...) Expand all Loading... |
596 | 639 |
597 void From(uint32_t ssrc) { | 640 void From(uint32_t ssrc) { |
598 nack_.SenderSSRC = ssrc; | 641 nack_.SenderSSRC = ssrc; |
599 } | 642 } |
600 void To(uint32_t ssrc) { | 643 void To(uint32_t ssrc) { |
601 nack_.MediaSSRC = ssrc; | 644 nack_.MediaSSRC = ssrc; |
602 } | 645 } |
603 void WithList(const uint16_t* nack_list, int length); | 646 void WithList(const uint16_t* nack_list, int length); |
604 | 647 |
605 protected: | 648 protected: |
606 void Create(uint8_t* packet, | 649 bool Create(uint8_t* packet, |
607 size_t* length, | 650 size_t* index, |
608 size_t max_length) const override; | 651 size_t max_length, |
| 652 RtcpPacket::PacketReadyCallback* callback) const override; |
609 | 653 |
610 private: | 654 private: |
611 size_t BlockLength() const { | |
612 size_t fci_length = 4 * nack_fields_.size(); | |
613 return kCommonFbFmtLength + fci_length; | |
614 } | |
615 | 655 |
616 RTCPUtility::RTCPPacketRTPFBNACK nack_; | 656 RTCPUtility::RTCPPacketRTPFBNACK nack_; |
617 std::vector<RTCPUtility::RTCPPacketRTPFBNACKItem> nack_fields_; | 657 std::vector<RTCPUtility::RTCPPacketRTPFBNACKItem> nack_fields_; |
618 | 658 |
619 DISALLOW_COPY_AND_ASSIGN(Nack); | 659 DISALLOW_COPY_AND_ASSIGN(Nack); |
620 }; | 660 }; |
621 | 661 |
622 // Reference picture selection indication (RPSI) (RFC 4585). | 662 // Reference picture selection indication (RPSI) (RFC 4585). |
623 // | 663 // |
624 // FCI: | 664 // FCI: |
(...skipping 22 matching lines...) Expand all Loading... |
647 void To(uint32_t ssrc) { | 687 void To(uint32_t ssrc) { |
648 rpsi_.MediaSSRC = ssrc; | 688 rpsi_.MediaSSRC = ssrc; |
649 } | 689 } |
650 void WithPayloadType(uint8_t payload) { | 690 void WithPayloadType(uint8_t payload) { |
651 assert(payload <= 0x7f); | 691 assert(payload <= 0x7f); |
652 rpsi_.PayloadType = payload; | 692 rpsi_.PayloadType = payload; |
653 } | 693 } |
654 void WithPictureId(uint64_t picture_id); | 694 void WithPictureId(uint64_t picture_id); |
655 | 695 |
656 protected: | 696 protected: |
657 void Create(uint8_t* packet, | 697 bool Create(uint8_t* packet, |
658 size_t* length, | 698 size_t* index, |
659 size_t max_length) const override; | 699 size_t max_length, |
| 700 RtcpPacket::PacketReadyCallback* callback) const override; |
660 | 701 |
661 private: | 702 private: |
662 size_t BlockLength() const { | 703 size_t BlockLength() const { |
663 size_t fci_length = 2 + (rpsi_.NumberOfValidBits / 8) + padding_bytes_; | 704 size_t fci_length = 2 + (rpsi_.NumberOfValidBits / 8) + padding_bytes_; |
664 return kCommonFbFmtLength + fci_length; | 705 return kCommonFbFmtLength + fci_length; |
665 } | 706 } |
666 | 707 |
667 uint8_t padding_bytes_; | 708 uint8_t padding_bytes_; |
668 RTCPUtility::RTCPPacketPSFBRPSI rpsi_; | 709 RTCPUtility::RTCPPacketPSFBRPSI rpsi_; |
669 | 710 |
(...skipping 25 matching lines...) Expand all Loading... |
695 fir_.SenderSSRC = ssrc; | 736 fir_.SenderSSRC = ssrc; |
696 } | 737 } |
697 void To(uint32_t ssrc) { | 738 void To(uint32_t ssrc) { |
698 fir_item_.SSRC = ssrc; | 739 fir_item_.SSRC = ssrc; |
699 } | 740 } |
700 void WithCommandSeqNum(uint8_t seq_num) { | 741 void WithCommandSeqNum(uint8_t seq_num) { |
701 fir_item_.CommandSequenceNumber = seq_num; | 742 fir_item_.CommandSequenceNumber = seq_num; |
702 } | 743 } |
703 | 744 |
704 protected: | 745 protected: |
705 void Create(uint8_t* packet, | 746 bool Create(uint8_t* packet, |
706 size_t* length, | 747 size_t* index, |
707 size_t max_length) const override; | 748 size_t max_length, |
| 749 RtcpPacket::PacketReadyCallback* callback) const override; |
708 | 750 |
709 private: | 751 private: |
710 size_t BlockLength() const { | 752 size_t BlockLength() const { |
711 const size_t kFciLength = 8; | 753 const size_t kFciLength = 8; |
712 return kCommonFbFmtLength + kFciLength; | 754 return kCommonFbFmtLength + kFciLength; |
713 } | 755 } |
714 | 756 |
715 RTCPUtility::RTCPPacketPSFBFIR fir_; | 757 RTCPUtility::RTCPPacketPSFBFIR fir_; |
716 RTCPUtility::RTCPPacketPSFBFIRItem fir_item_; | 758 RTCPUtility::RTCPPacketPSFBFIRItem fir_item_; |
717 }; | 759 }; |
(...skipping 27 matching lines...) Expand all Loading... |
745 } | 787 } |
746 void WithBitrateKbps(uint32_t bitrate_kbps) { | 788 void WithBitrateKbps(uint32_t bitrate_kbps) { |
747 tmmbr_item_.MaxTotalMediaBitRate = bitrate_kbps; | 789 tmmbr_item_.MaxTotalMediaBitRate = bitrate_kbps; |
748 } | 790 } |
749 void WithOverhead(uint16_t overhead) { | 791 void WithOverhead(uint16_t overhead) { |
750 assert(overhead <= 0x1ff); | 792 assert(overhead <= 0x1ff); |
751 tmmbr_item_.MeasuredOverhead = overhead; | 793 tmmbr_item_.MeasuredOverhead = overhead; |
752 } | 794 } |
753 | 795 |
754 protected: | 796 protected: |
755 void Create(uint8_t* packet, | 797 bool Create(uint8_t* packet, |
756 size_t* length, | 798 size_t* index, |
757 size_t max_length) const override; | 799 size_t max_length, |
| 800 RtcpPacket::PacketReadyCallback* callback) const override; |
758 | 801 |
759 private: | 802 private: |
760 size_t BlockLength() const { | 803 size_t BlockLength() const { |
761 const size_t kFciLen = 8; | 804 const size_t kFciLen = 8; |
762 return kCommonFbFmtLength + kFciLen; | 805 return kCommonFbFmtLength + kFciLen; |
763 } | 806 } |
764 | 807 |
765 RTCPUtility::RTCPPacketRTPFBTMMBR tmmbr_; | 808 RTCPUtility::RTCPPacketRTPFBTMMBR tmmbr_; |
766 RTCPUtility::RTCPPacketRTPFBTMMBRItem tmmbr_item_; | 809 RTCPUtility::RTCPPacketRTPFBTMMBRItem tmmbr_item_; |
767 | 810 |
(...skipping 16 matching lines...) Expand all Loading... |
784 public: | 827 public: |
785 Tmmbn() : RtcpPacket() { | 828 Tmmbn() : RtcpPacket() { |
786 memset(&tmmbn_, 0, sizeof(tmmbn_)); | 829 memset(&tmmbn_, 0, sizeof(tmmbn_)); |
787 } | 830 } |
788 | 831 |
789 virtual ~Tmmbn() {} | 832 virtual ~Tmmbn() {} |
790 | 833 |
791 void From(uint32_t ssrc) { | 834 void From(uint32_t ssrc) { |
792 tmmbn_.SenderSSRC = ssrc; | 835 tmmbn_.SenderSSRC = ssrc; |
793 } | 836 } |
794 void WithTmmbr(uint32_t ssrc, uint32_t bitrate_kbps, uint16_t overhead); | 837 // Max 50 TMMBR can be added per TMMBN. |
| 838 bool WithTmmbr(uint32_t ssrc, uint32_t bitrate_kbps, uint16_t overhead); |
795 | 839 |
796 protected: | 840 protected: |
797 void Create(uint8_t* packet, | 841 bool Create(uint8_t* packet, |
798 size_t* length, | 842 size_t* index, |
799 size_t max_length) const override; | 843 size_t max_length, |
| 844 RtcpPacket::PacketReadyCallback* callback) const override; |
800 | 845 |
801 private: | 846 private: |
802 enum { kMaxNumberOfTmmbrs = 50 }; | 847 static const int kMaxNumberOfTmmbrs = 50; |
803 | 848 |
804 size_t BlockLength() const { | 849 size_t BlockLength() const { |
805 const size_t kFciLen = 8; | 850 const size_t kFciLen = 8; |
806 return kCommonFbFmtLength + kFciLen * tmmbn_items_.size(); | 851 return kCommonFbFmtLength + kFciLen * tmmbn_items_.size(); |
807 } | 852 } |
808 | 853 |
809 RTCPUtility::RTCPPacketRTPFBTMMBN tmmbn_; | 854 RTCPUtility::RTCPPacketRTPFBTMMBN tmmbn_; |
810 std::vector<RTCPUtility::RTCPPacketRTPFBTMMBRItem> tmmbn_items_; | 855 std::vector<RTCPUtility::RTCPPacketRTPFBTMMBRItem> tmmbn_items_; |
811 | 856 |
812 DISALLOW_COPY_AND_ASSIGN(Tmmbn); | 857 DISALLOW_COPY_AND_ASSIGN(Tmmbn); |
(...skipping 30 matching lines...) Expand all Loading... |
843 void From(uint32_t ssrc) { | 888 void From(uint32_t ssrc) { |
844 remb_.SenderSSRC = ssrc; | 889 remb_.SenderSSRC = ssrc; |
845 } | 890 } |
846 void AppliesTo(uint32_t ssrc); | 891 void AppliesTo(uint32_t ssrc); |
847 | 892 |
848 void WithBitrateBps(uint32_t bitrate_bps) { | 893 void WithBitrateBps(uint32_t bitrate_bps) { |
849 remb_item_.BitRate = bitrate_bps; | 894 remb_item_.BitRate = bitrate_bps; |
850 } | 895 } |
851 | 896 |
852 protected: | 897 protected: |
853 void Create(uint8_t* packet, | 898 bool Create(uint8_t* packet, |
854 size_t* length, | 899 size_t* index, |
855 size_t max_length) const override; | 900 size_t max_length, |
| 901 RtcpPacket::PacketReadyCallback* callback) const override; |
856 | 902 |
857 private: | 903 private: |
858 enum { kMaxNumberOfSsrcs = 0xff }; | 904 static const int kMaxNumberOfSsrcs = 0xff; |
859 | 905 |
860 size_t BlockLength() const { | 906 size_t BlockLength() const { |
861 return (remb_item_.NumberOfSSRCs + 5) * 4; | 907 return (remb_item_.NumberOfSSRCs + 5) * 4; |
862 } | 908 } |
863 | 909 |
864 RTCPUtility::RTCPPacketPSFBAPP remb_; | 910 RTCPUtility::RTCPPacketPSFBAPP remb_; |
865 RTCPUtility::RTCPPacketPSFBREMBItem remb_item_; | 911 RTCPUtility::RTCPPacketPSFBREMBItem remb_item_; |
866 | 912 |
867 DISALLOW_COPY_AND_ASSIGN(Remb); | 913 DISALLOW_COPY_AND_ASSIGN(Remb); |
868 }; | 914 }; |
(...skipping 17 matching lines...) Expand all Loading... |
886 typedef std::vector<RTCPUtility::RTCPPacketXRDLRRReportBlockItem> DlrrBlock; | 932 typedef std::vector<RTCPUtility::RTCPPacketXRDLRRReportBlockItem> DlrrBlock; |
887 Xr() : RtcpPacket() { | 933 Xr() : RtcpPacket() { |
888 memset(&xr_header_, 0, sizeof(xr_header_)); | 934 memset(&xr_header_, 0, sizeof(xr_header_)); |
889 } | 935 } |
890 | 936 |
891 virtual ~Xr() {} | 937 virtual ~Xr() {} |
892 | 938 |
893 void From(uint32_t ssrc) { | 939 void From(uint32_t ssrc) { |
894 xr_header_.OriginatorSSRC = ssrc; | 940 xr_header_.OriginatorSSRC = ssrc; |
895 } | 941 } |
896 void WithRrtr(Rrtr* rrtr); | 942 |
897 void WithDlrr(Dlrr* dlrr); | 943 // Max 50 items of each of {Rrtr, Dlrr, VoipMetric} allowed per Xr. |
898 void WithVoipMetric(VoipMetric* voip_metric); | 944 bool WithRrtr(Rrtr* rrtr); |
| 945 bool WithDlrr(Dlrr* dlrr); |
| 946 bool WithVoipMetric(VoipMetric* voip_metric); |
899 | 947 |
900 protected: | 948 protected: |
901 void Create(uint8_t* packet, | 949 bool Create(uint8_t* packet, |
902 size_t* length, | 950 size_t* index, |
903 size_t max_length) const override; | 951 size_t max_length, |
| 952 RtcpPacket::PacketReadyCallback* callback) const override; |
904 | 953 |
905 private: | 954 private: |
906 enum { kMaxNumberOfRrtrBlocks = 50 }; | 955 static const int kMaxNumberOfRrtrBlocks = 50; |
907 enum { kMaxNumberOfDlrrBlocks = 50 }; | 956 static const int kMaxNumberOfDlrrBlocks = 50; |
908 enum { kMaxNumberOfVoipMetricBlocks = 50 }; | 957 static const int kMaxNumberOfVoipMetricBlocks = 50; |
909 | 958 |
910 size_t BlockLength() const { | 959 size_t BlockLength() const { |
911 const size_t kXrHeaderLength = 8; | 960 const size_t kXrHeaderLength = 8; |
912 return kXrHeaderLength + RrtrLength() + DlrrLength() + VoipMetricLength(); | 961 return kXrHeaderLength + RrtrLength() + DlrrLength() + VoipMetricLength(); |
913 } | 962 } |
914 | 963 |
915 size_t RrtrLength() const { | 964 size_t RrtrLength() const { |
916 const size_t kRrtrBlockLength = 12; | 965 const size_t kRrtrBlockLength = 12; |
917 return kRrtrBlockLength * rrtr_blocks_.size(); | 966 return kRrtrBlockLength * rrtr_blocks_.size(); |
918 } | 967 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | 1029 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
981 // | SSRC_2 (SSRC of second receiver) | sub- | 1030 // | SSRC_2 (SSRC of second receiver) | sub- |
982 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block | 1031 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block |
983 // : ... : 2 | 1032 // : ... : 2 |
984 | 1033 |
985 class Dlrr { | 1034 class Dlrr { |
986 public: | 1035 public: |
987 Dlrr() {} | 1036 Dlrr() {} |
988 ~Dlrr() {} | 1037 ~Dlrr() {} |
989 | 1038 |
990 void WithDlrrItem(uint32_t ssrc, uint32_t last_rr, uint32_t delay_last_rr); | 1039 // Max 100 DLRR Items can be added per DLRR report block. |
| 1040 bool WithDlrrItem(uint32_t ssrc, uint32_t last_rr, uint32_t delay_last_rr); |
991 | 1041 |
992 private: | 1042 private: |
993 friend class Xr; | 1043 friend class Xr; |
994 enum { kMaxNumberOfDlrrItems = 100 }; | 1044 static const int kMaxNumberOfDlrrItems = 100; |
995 | 1045 |
996 std::vector<RTCPUtility::RTCPPacketXRDLRRReportBlockItem> dlrr_block_; | 1046 std::vector<RTCPUtility::RTCPPacketXRDLRRReportBlockItem> dlrr_block_; |
997 | 1047 |
998 DISALLOW_COPY_AND_ASSIGN(Dlrr); | 1048 DISALLOW_COPY_AND_ASSIGN(Dlrr); |
999 }; | 1049 }; |
1000 | 1050 |
1001 // VoIP Metrics Report Block (RFC 3611). | 1051 // VoIP Metrics Report Block (RFC 3611). |
1002 // | 1052 // |
1003 // 0 1 2 3 | 1053 // 0 1 2 3 |
1004 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | 1054 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 | 1117 |
1068 DISALLOW_COPY_AND_ASSIGN(VoipMetric); | 1118 DISALLOW_COPY_AND_ASSIGN(VoipMetric); |
1069 }; | 1119 }; |
1070 | 1120 |
1071 // Class holding a RTCP packet. | 1121 // Class holding a RTCP packet. |
1072 // | 1122 // |
1073 // Takes a built rtcp packet. | 1123 // Takes a built rtcp packet. |
1074 // RawPacket raw_packet(buffer, length); | 1124 // RawPacket raw_packet(buffer, length); |
1075 // | 1125 // |
1076 // To access the raw packet: | 1126 // To access the raw packet: |
1077 // raw_packet.buffer(); - pointer to the raw packet | 1127 // raw_packet.Buffer(); - pointer to the raw packet |
1078 // raw_packet.buffer_length(); - the length of the raw packet | 1128 // raw_packet.BufferLength(); - the length of the raw packet |
1079 | 1129 |
1080 class RawPacket { | 1130 class RawPacket { |
1081 public: | 1131 public: |
1082 RawPacket(const uint8_t* packet, size_t length) { | 1132 explicit RawPacket(size_t buffer_length); |
1083 assert(length <= IP_PACKET_SIZE); | 1133 RawPacket(const uint8_t* packet, size_t packet_length); |
1084 memcpy(buffer_, packet, length); | |
1085 buffer_length_ = length; | |
1086 } | |
1087 | 1134 |
1088 const uint8_t* buffer() { | 1135 const uint8_t* Buffer() const; |
1089 return buffer_; | 1136 uint8_t* MutableBuffer(); |
1090 } | 1137 size_t BufferLength() const; |
1091 size_t buffer_length() const { | 1138 size_t Length() const; |
1092 return buffer_length_; | 1139 void SetLength(size_t length); |
1093 } | |
1094 | 1140 |
1095 private: | 1141 private: |
1096 size_t buffer_length_; | 1142 const size_t buffer_length_; |
1097 uint8_t buffer_[IP_PACKET_SIZE]; | 1143 size_t length_; |
| 1144 rtc::scoped_ptr<uint8_t[]> buffer_; |
1098 }; | 1145 }; |
1099 | 1146 |
1100 } // namespace rtcp | 1147 } // namespace rtcp |
1101 } // namespace webrtc | 1148 } // namespace webrtc |
1102 #endif // WEBRTC_MODULES_RTP_RTCP_RTCP_PACKET_H_ | 1149 #endif // WEBRTC_MODULES_RTP_RTCP_RTCP_PACKET_H_ |
OLD | NEW |