1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
|
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h"
#include <assert.h>
#include <string.h>
#include "webrtc/common_types.h"
#include "webrtc/system_wrappers/interface/logging.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef _WIN32
// Disable warning C4355: 'this' : used in base member initializer list.
#pragma warning(disable : 4355)
#endif
namespace webrtc {
RtpRtcp::Configuration::Configuration()
: id(-1),
audio(false),
clock(NULL),
default_module(NULL),
receive_statistics(NullObjectReceiveStatistics()),
outgoing_transport(NULL),
intra_frame_callback(NULL),
bandwidth_callback(NULL),
rtt_stats(NULL),
audio_messages(NullObjectRtpAudioFeedback()),
remote_bitrate_estimator(NULL),
paced_sender(NULL),
send_bitrate_observer(NULL),
send_frame_count_observer(NULL),
send_side_delay_observer(NULL) {
}
RtpRtcp* RtpRtcp::CreateRtpRtcp(const RtpRtcp::Configuration& configuration) {
if (configuration.clock) {
return new ModuleRtpRtcpImpl(configuration);
} else {
// No clock implementation provided, use default clock.
RtpRtcp::Configuration configuration_copy;
memcpy(&configuration_copy, &configuration,
sizeof(RtpRtcp::Configuration));
configuration_copy.clock = Clock::GetRealTimeClock();
return new ModuleRtpRtcpImpl(configuration_copy);
}
}
ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration)
: rtp_sender_(configuration.id,
configuration.audio,
configuration.clock,
configuration.outgoing_transport,
configuration.audio_messages,
configuration.paced_sender,
configuration.send_bitrate_observer,
configuration.send_frame_count_observer,
configuration.send_side_delay_observer),
rtcp_sender_(configuration.id,
configuration.audio,
configuration.clock,
configuration.receive_statistics),
rtcp_receiver_(configuration.id, configuration.clock, this),
clock_(configuration.clock),
id_(configuration.id),
audio_(configuration.audio),
collision_detected_(false),
last_process_time_(configuration.clock->TimeInMilliseconds()),
last_bitrate_process_time_(configuration.clock->TimeInMilliseconds()),
last_rtt_process_time_(configuration.clock->TimeInMilliseconds()),
packet_overhead_(28), // IPV4 UDP.
critical_section_module_ptrs_(
CriticalSectionWrapper::CreateCriticalSection()),
critical_section_module_ptrs_feedback_(
CriticalSectionWrapper::CreateCriticalSection()),
default_module_(
static_cast<ModuleRtpRtcpImpl*>(configuration.default_module)),
padding_index_(static_cast<size_t>(-1)), // Start padding at first child.
nack_method_(kNackOff),
nack_last_time_sent_full_(0),
nack_last_time_sent_full_prev_(0),
nack_last_seq_number_sent_(0),
simulcast_(false),
key_frame_req_method_(kKeyFrameReqFirRtp),
remote_bitrate_(configuration.remote_bitrate_estimator),
rtt_stats_(configuration.rtt_stats),
critical_section_rtt_(CriticalSectionWrapper::CreateCriticalSection()),
rtt_ms_(0) {
send_video_codec_.codecType = kVideoCodecUnknown;
if (default_module_) {
default_module_->RegisterChildModule(this);
}
// TODO(pwestin) move to constructors of each rtp/rtcp sender/receiver object.
rtcp_receiver_.RegisterRtcpObservers(configuration.intra_frame_callback,
configuration.bandwidth_callback);
rtcp_sender_.RegisterSendTransport(configuration.outgoing_transport);
// Make sure that RTCP objects are aware of our SSRC.
uint32_t SSRC = rtp_sender_.SSRC();
rtcp_sender_.SetSSRC(SSRC);
SetRtcpReceiverSsrcs(SSRC);
}
ModuleRtpRtcpImpl::~ModuleRtpRtcpImpl() {
// All child modules MUST be deleted before deleting the default.
assert(child_modules_.empty());
// Deregister for the child modules.
// Will go in to the default and remove it self.
if (default_module_) {
default_module_->DeRegisterChildModule(this);
}
}
void ModuleRtpRtcpImpl::RegisterChildModule(RtpRtcp* module) {
CriticalSectionScoped lock(
critical_section_module_ptrs_.get());
CriticalSectionScoped double_lock(
critical_section_module_ptrs_feedback_.get());
// We use two locks for protecting child_modules_, one
// (critical_section_module_ptrs_feedback_) for incoming
// messages (BitrateSent) and critical_section_module_ptrs_
// for all outgoing messages sending packets etc.
child_modules_.push_back(static_cast<ModuleRtpRtcpImpl*>(module));
}
void ModuleRtpRtcpImpl::DeRegisterChildModule(RtpRtcp* remove_module) {
CriticalSectionScoped lock(
critical_section_module_ptrs_.get());
CriticalSectionScoped double_lock(
critical_section_module_ptrs_feedback_.get());
std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin();
while (it != child_modules_.end()) {
RtpRtcp* module = *it;
if (module == remove_module) {
child_modules_.erase(it);
return;
}
it++;
}
}
// Returns the number of milliseconds until the module want a worker thread
// to call Process.
int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() {
const int64_t now = clock_->TimeInMilliseconds();
const int64_t kRtpRtcpMaxIdleTimeProcessMs = 5;
return kRtpRtcpMaxIdleTimeProcessMs - (now - last_process_time_);
}
// Process any pending tasks such as timeouts (non time critical events).
int32_t ModuleRtpRtcpImpl::Process() {
const int64_t now = clock_->TimeInMilliseconds();
last_process_time_ = now;
const int64_t kRtpRtcpBitrateProcessTimeMs = 10;
if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) {
rtp_sender_.ProcessBitrate();
last_bitrate_process_time_ = now;
}
if (!IsDefaultModule()) {
const int64_t kRtpRtcpRttProcessTimeMs = 1000;
bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs;
if (rtcp_sender_.Sending()) {
// Process RTT if we have received a receiver report and we haven't
// processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds.
if (rtcp_receiver_.LastReceivedReceiverReport() >
last_rtt_process_time_ && process_rtt) {
std::vector<RTCPReportBlock> receive_blocks;
rtcp_receiver_.StatisticsReceived(&receive_blocks);
uint16_t max_rtt = 0;
for (std::vector<RTCPReportBlock>::iterator it = receive_blocks.begin();
it != receive_blocks.end(); ++it) {
uint16_t rtt = 0;
rtcp_receiver_.RTT(it->remoteSSRC, &rtt, NULL, NULL, NULL);
max_rtt = (rtt > max_rtt) ? rtt : max_rtt;
}
// Report the rtt.
if (rtt_stats_ && max_rtt != 0)
rtt_stats_->OnRttUpdate(max_rtt);
}
// Verify receiver reports are delivered and the reported sequence number
// is increasing.
int64_t rtcp_interval = RtcpReportInterval();
if (rtcp_receiver_.RtcpRrTimeout(rtcp_interval)) {
LOG_F(LS_WARNING) << "Timeout: No RTCP RR received.";
} else if (rtcp_receiver_.RtcpRrSequenceNumberTimeout(rtcp_interval)) {
LOG_F(LS_WARNING) <<
"Timeout: No increase in RTCP RR extended highest sequence number.";
}
if (remote_bitrate_ && rtcp_sender_.TMMBR()) {
unsigned int target_bitrate = 0;
std::vector<unsigned int> ssrcs;
if (remote_bitrate_->LatestEstimate(&ssrcs, &target_bitrate)) {
if (!ssrcs.empty()) {
target_bitrate = target_bitrate / ssrcs.size();
}
rtcp_sender_.SetTargetBitrate(target_bitrate);
}
}
} else {
// Report rtt from receiver.
if (process_rtt) {
uint16_t rtt_ms;
if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) {
rtt_stats_->OnRttUpdate(rtt_ms);
}
}
}
// Get processed rtt.
if (process_rtt) {
last_rtt_process_time_ = now;
if (rtt_stats_) {
set_rtt_ms(rtt_stats_->LastProcessedRtt());
}
}
if (rtcp_sender_.TimeToSendRTCPReport()) {
rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
}
}
if (UpdateRTCPReceiveInformationTimers()) {
// A receiver has timed out
rtcp_receiver_.UpdateTMMBR();
}
return 0;
}
void ModuleRtpRtcpImpl::SetRTXSendStatus(int mode) {
rtp_sender_.SetRTXStatus(mode);
}
void ModuleRtpRtcpImpl::RTXSendStatus(int* mode,
uint32_t* ssrc,
int* payload_type) const {
rtp_sender_.RTXStatus(mode, ssrc, payload_type);
}
void ModuleRtpRtcpImpl::SetRtxSsrc(uint32_t ssrc) {
rtp_sender_.SetRtxSsrc(ssrc);
}
void ModuleRtpRtcpImpl::SetRtxSendPayloadType(int payload_type) {
rtp_sender_.SetRtxPayloadType(payload_type);
}
int32_t ModuleRtpRtcpImpl::IncomingRtcpPacket(
const uint8_t* rtcp_packet,
const size_t length) {
// Allow receive of non-compound RTCP packets.
RTCPUtility::RTCPParserV2 rtcp_parser(rtcp_packet, length, true);
const bool valid_rtcpheader = rtcp_parser.IsValid();
if (!valid_rtcpheader) {
LOG(LS_WARNING) << "Incoming invalid RTCP packet";
return -1;
}
RTCPHelp::RTCPPacketInformation rtcp_packet_information;
int32_t ret_val = rtcp_receiver_.IncomingRTCPPacket(
rtcp_packet_information, &rtcp_parser);
if (ret_val == 0) {
rtcp_receiver_.TriggerCallbacksFromRTCPPacket(rtcp_packet_information);
}
return ret_val;
}
int32_t ModuleRtpRtcpImpl::RegisterSendPayload(
const CodecInst& voice_codec) {
return rtp_sender_.RegisterPayload(
voice_codec.plname,
voice_codec.pltype,
voice_codec.plfreq,
voice_codec.channels,
(voice_codec.rate < 0) ? 0 : voice_codec.rate);
}
int32_t ModuleRtpRtcpImpl::RegisterSendPayload(
const VideoCodec& video_codec) {
send_video_codec_ = video_codec;
{
// simulcast_ is accessed when accessing child_modules_, so this write needs
// to be protected by the same lock.
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
simulcast_ = video_codec.numberOfSimulcastStreams > 1;
}
return rtp_sender_.RegisterPayload(video_codec.plName,
video_codec.plType,
90000,
0,
video_codec.maxBitrate);
}
int32_t ModuleRtpRtcpImpl::DeRegisterSendPayload(
const int8_t payload_type) {
return rtp_sender_.DeRegisterSendPayload(payload_type);
}
int8_t ModuleRtpRtcpImpl::SendPayloadType() const {
return rtp_sender_.SendPayloadType();
}
uint32_t ModuleRtpRtcpImpl::StartTimestamp() const {
return rtp_sender_.StartTimestamp();
}
// Configure start timestamp, default is a random number.
void ModuleRtpRtcpImpl::SetStartTimestamp(const uint32_t timestamp) {
rtcp_sender_.SetStartTimestamp(timestamp);
rtp_sender_.SetStartTimestamp(timestamp, true);
}
uint16_t ModuleRtpRtcpImpl::SequenceNumber() const {
return rtp_sender_.SequenceNumber();
}
// Set SequenceNumber, default is a random number.
void ModuleRtpRtcpImpl::SetSequenceNumber(const uint16_t seq_num) {
rtp_sender_.SetSequenceNumber(seq_num);
}
void ModuleRtpRtcpImpl::SetRtpStateForSsrc(uint32_t ssrc,
const RtpState& rtp_state) {
if (rtp_sender_.SSRC() == ssrc) {
rtp_sender_.SetRtpState(rtp_state);
return;
}
if (rtp_sender_.RtxSsrc() == ssrc) {
rtp_sender_.SetRtxRtpState(rtp_state);
return;
}
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
for (size_t i = 0; i < child_modules_.size(); ++i) {
child_modules_[i]->SetRtpStateForSsrc(ssrc, rtp_state);
}
}
bool ModuleRtpRtcpImpl::GetRtpStateForSsrc(uint32_t ssrc, RtpState* rtp_state) {
if (rtp_sender_.SSRC() == ssrc) {
*rtp_state = rtp_sender_.GetRtpState();
return true;
}
if (rtp_sender_.RtxSsrc() == ssrc) {
*rtp_state = rtp_sender_.GetRtxRtpState();
return true;
}
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
for (size_t i = 0; i < child_modules_.size(); ++i) {
if (child_modules_[i]->GetRtpStateForSsrc(ssrc, rtp_state))
return true;
}
return false;
}
uint32_t ModuleRtpRtcpImpl::SSRC() const {
return rtp_sender_.SSRC();
}
// Configure SSRC, default is a random number.
void ModuleRtpRtcpImpl::SetSSRC(const uint32_t ssrc) {
rtp_sender_.SetSSRC(ssrc);
rtcp_sender_.SetSSRC(ssrc);
SetRtcpReceiverSsrcs(ssrc);
}
void ModuleRtpRtcpImpl::SetCsrcs(const std::vector<uint32_t>& csrcs) {
if (IsDefaultModule()) {
// For default we need to update all child modules too.
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin();
while (it != child_modules_.end()) {
RtpRtcp* module = *it;
if (module) {
module->SetCsrcs(csrcs);
}
it++;
}
return;
}
rtcp_sender_.SetCsrcs(csrcs);
rtp_sender_.SetCsrcs(csrcs);
}
// TODO(pbos): Handle media and RTX streams separately (separate RTCP
// feedbacks).
RTCPSender::FeedbackState ModuleRtpRtcpImpl::GetFeedbackState() {
StreamDataCounters rtp_stats;
StreamDataCounters rtx_stats;
rtp_sender_.GetDataCounters(&rtp_stats, &rtx_stats);
RTCPSender::FeedbackState state;
state.send_payload_type = SendPayloadType();
state.frequency_hz = CurrentSendFrequencyHz();
state.packets_sent = rtp_stats.packets + rtx_stats.packets;
state.media_bytes_sent = rtp_stats.bytes + rtx_stats.bytes;
state.module = this;
LastReceivedNTP(&state.last_rr_ntp_secs,
&state.last_rr_ntp_frac,
&state.remote_sr);
state.has_last_xr_rr = LastReceivedXrReferenceTimeInfo(&state.last_xr_rr);
uint32_t tmp;
BitrateSent(&state.send_bitrate, &tmp, &tmp, &tmp);
return state;
}
int ModuleRtpRtcpImpl::CurrentSendFrequencyHz() const {
return rtp_sender_.SendPayloadFrequency();
}
int32_t ModuleRtpRtcpImpl::SetSendingStatus(const bool sending) {
if (rtcp_sender_.Sending() != sending) {
// Sends RTCP BYE when going from true to false
if (rtcp_sender_.SetSendingStatus(GetFeedbackState(), sending) != 0) {
LOG(LS_WARNING) << "Failed to send RTCP BYE";
}
collision_detected_ = false;
// Generate a new time_stamp if true and not configured via API
// Generate a new SSRC for the next "call" if false
rtp_sender_.SetSendingStatus(sending);
if (sending) {
// Make sure the RTCP sender has the same timestamp offset.
rtcp_sender_.SetStartTimestamp(rtp_sender_.StartTimestamp());
}
// Make sure that RTCP objects are aware of our SSRC (it could have changed
// Due to collision)
uint32_t SSRC = rtp_sender_.SSRC();
rtcp_sender_.SetSSRC(SSRC);
SetRtcpReceiverSsrcs(SSRC);
return 0;
}
return 0;
}
bool ModuleRtpRtcpImpl::Sending() const {
return rtcp_sender_.Sending();
}
void ModuleRtpRtcpImpl::SetSendingMediaStatus(const bool sending) {
rtp_sender_.SetSendingMediaStatus(sending);
}
bool ModuleRtpRtcpImpl::SendingMedia() const {
if (!IsDefaultModule()) {
return rtp_sender_.SendingMedia();
}
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
std::vector<ModuleRtpRtcpImpl*>::const_iterator it = child_modules_.begin();
while (it != child_modules_.end()) {
RTPSender& rtp_sender = (*it)->rtp_sender_;
if (rtp_sender.SendingMedia()) {
return true;
}
it++;
}
return false;
}
int32_t ModuleRtpRtcpImpl::SendOutgoingData(
FrameType frame_type,
int8_t payload_type,
uint32_t time_stamp,
int64_t capture_time_ms,
const uint8_t* payload_data,
size_t payload_size,
const RTPFragmentationHeader* fragmentation,
const RTPVideoHeader* rtp_video_hdr) {
rtcp_sender_.SetLastRtpTime(time_stamp, capture_time_ms);
if (!IsDefaultModule()) {
// Don't send RTCP from default module.
if (rtcp_sender_.TimeToSendRTCPReport(kVideoFrameKey == frame_type)) {
rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
}
return rtp_sender_.SendOutgoingData(frame_type,
payload_type,
time_stamp,
capture_time_ms,
payload_data,
payload_size,
fragmentation,
NULL,
&(rtp_video_hdr->codecHeader));
}
int32_t ret_val = -1;
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
if (simulcast_) {
if (rtp_video_hdr == NULL) {
return -1;
}
int idx = 0;
std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin();
for (; idx < rtp_video_hdr->simulcastIdx; ++it) {
if (it == child_modules_.end()) {
return -1;
}
if ((*it)->SendingMedia()) {
++idx;
}
}
for (; it != child_modules_.end(); ++it) {
if ((*it)->SendingMedia()) {
break;
}
++idx;
}
if (it == child_modules_.end()) {
return -1;
}
return (*it)->SendOutgoingData(frame_type,
payload_type,
time_stamp,
capture_time_ms,
payload_data,
payload_size,
fragmentation,
rtp_video_hdr);
} else {
std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin();
// Send to all "child" modules
while (it != child_modules_.end()) {
if ((*it)->SendingMedia()) {
ret_val = (*it)->SendOutgoingData(frame_type,
payload_type,
time_stamp,
capture_time_ms,
payload_data,
payload_size,
fragmentation,
rtp_video_hdr);
}
it++;
}
}
return ret_val;
}
bool ModuleRtpRtcpImpl::TimeToSendPacket(uint32_t ssrc,
uint16_t sequence_number,
int64_t capture_time_ms,
bool retransmission) {
if (!IsDefaultModule()) {
// Don't send from default module.
if (SendingMedia() && ssrc == rtp_sender_.SSRC()) {
return rtp_sender_.TimeToSendPacket(sequence_number, capture_time_ms,
retransmission);
}
} else {
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin();
while (it != child_modules_.end()) {
if ((*it)->SendingMedia() && ssrc == (*it)->rtp_sender_.SSRC()) {
return (*it)->rtp_sender_.TimeToSendPacket(sequence_number,
capture_time_ms,
retransmission);
}
++it;
}
}
// No RTP sender is interested in sending this packet.
return true;
}
size_t ModuleRtpRtcpImpl::TimeToSendPadding(size_t bytes) {
if (!IsDefaultModule()) {
// Don't send from default module.
return rtp_sender_.TimeToSendPadding(bytes);
} else {
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
for (size_t i = 0; i < child_modules_.size(); ++i) {
// Send padding on one of the modules sending media.
if (child_modules_[i]->SendingMedia()) {
return child_modules_[i]->rtp_sender_.TimeToSendPadding(bytes);
}
}
}
return 0;
}
bool ModuleRtpRtcpImpl::GetSendSideDelay(int* avg_send_delay_ms,
int* max_send_delay_ms) const {
assert(avg_send_delay_ms);
assert(max_send_delay_ms);
if (IsDefaultModule()) {
// This API is only supported for child modules.
return false;
}
return rtp_sender_.GetSendSideDelay(avg_send_delay_ms, max_send_delay_ms);
}
uint16_t ModuleRtpRtcpImpl::MaxPayloadLength() const {
return rtp_sender_.MaxPayloadLength();
}
uint16_t ModuleRtpRtcpImpl::MaxDataPayloadLength() const {
// Assuming IP/UDP.
uint16_t min_data_payload_length = IP_PACKET_SIZE - 28;
if (IsDefaultModule()) {
// For default we need to update all child modules too.
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
std::vector<ModuleRtpRtcpImpl*>::const_iterator it = child_modules_.begin();
while (it != child_modules_.end()) {
RtpRtcp* module = *it;
if (module) {
uint16_t data_payload_length =
module->MaxDataPayloadLength();
if (data_payload_length < min_data_payload_length) {
min_data_payload_length = data_payload_length;
}
}
it++;
}
}
uint16_t data_payload_length = rtp_sender_.MaxDataPayloadLength();
if (data_payload_length < min_data_payload_length) {
min_data_payload_length = data_payload_length;
}
return min_data_payload_length;
}
int32_t ModuleRtpRtcpImpl::SetTransportOverhead(
const bool tcp,
const bool ipv6,
const uint8_t authentication_overhead) {
uint16_t packet_overhead = 0;
if (ipv6) {
packet_overhead = 40;
} else {
packet_overhead = 20;
}
if (tcp) {
// TCP.
packet_overhead += 20;
} else {
// UDP.
packet_overhead += 8;
}
packet_overhead += authentication_overhead;
if (packet_overhead == packet_overhead_) {
// Ok same as before.
return 0;
}
// Calc diff.
int16_t packet_over_head_diff = packet_overhead - packet_overhead_;
// Store new.
packet_overhead_ = packet_overhead;
uint16_t length =
rtp_sender_.MaxPayloadLength() - packet_over_head_diff;
return rtp_sender_.SetMaxPayloadLength(length, packet_overhead_);
}
int32_t ModuleRtpRtcpImpl::SetMaxTransferUnit(const uint16_t mtu) {
if (mtu > IP_PACKET_SIZE) {
LOG(LS_ERROR) << "Invalid mtu: " << mtu;
return -1;
}
return rtp_sender_.SetMaxPayloadLength(mtu - packet_overhead_,
packet_overhead_);
}
RTCPMethod ModuleRtpRtcpImpl::RTCP() const {
if (rtcp_sender_.Status() != kRtcpOff) {
return rtcp_receiver_.Status();
}
return kRtcpOff;
}
// Configure RTCP status i.e on/off.
void ModuleRtpRtcpImpl::SetRTCPStatus(const RTCPMethod method) {
rtcp_sender_.SetRTCPStatus(method);
rtcp_receiver_.SetRTCPStatus(method);
}
// Only for internal test.
uint32_t ModuleRtpRtcpImpl::LastSendReport(
uint32_t& last_rtcptime) {
return rtcp_sender_.LastSendReport(last_rtcptime);
}
int32_t ModuleRtpRtcpImpl::SetCNAME(const char c_name[RTCP_CNAME_SIZE]) {
return rtcp_sender_.SetCNAME(c_name);
}
int32_t ModuleRtpRtcpImpl::AddMixedCNAME(uint32_t ssrc,
const char c_name[RTCP_CNAME_SIZE]) {
return rtcp_sender_.AddMixedCNAME(ssrc, c_name);
}
int32_t ModuleRtpRtcpImpl::RemoveMixedCNAME(const uint32_t ssrc) {
return rtcp_sender_.RemoveMixedCNAME(ssrc);
}
int32_t ModuleRtpRtcpImpl::RemoteCNAME(
const uint32_t remote_ssrc,
char c_name[RTCP_CNAME_SIZE]) const {
return rtcp_receiver_.CNAME(remote_ssrc, c_name);
}
int32_t ModuleRtpRtcpImpl::RemoteNTP(
uint32_t* received_ntpsecs,
uint32_t* received_ntpfrac,
uint32_t* rtcp_arrival_time_secs,
uint32_t* rtcp_arrival_time_frac,
uint32_t* rtcp_timestamp) const {
return rtcp_receiver_.NTP(received_ntpsecs,
received_ntpfrac,
rtcp_arrival_time_secs,
rtcp_arrival_time_frac,
rtcp_timestamp)
? 0
: -1;
}
// Get RoundTripTime.
int32_t ModuleRtpRtcpImpl::RTT(const uint32_t remote_ssrc,
uint16_t* rtt,
uint16_t* avg_rtt,
uint16_t* min_rtt,
uint16_t* max_rtt) const {
int32_t ret = rtcp_receiver_.RTT(remote_ssrc, rtt, avg_rtt, min_rtt, max_rtt);
if (rtt && *rtt == 0) {
// Try to get RTT from RtcpRttStats class.
*rtt = static_cast<uint16_t>(rtt_ms());
}
return ret;
}
// Reset RTP data counters for the sending side.
int32_t ModuleRtpRtcpImpl::ResetSendDataCountersRTP() {
rtp_sender_.ResetDataCounters();
return 0; // TODO(pwestin): change to void.
}
// Force a send of an RTCP packet.
// Normal SR and RR are triggered via the process function.
int32_t ModuleRtpRtcpImpl::SendRTCP(uint32_t rtcp_packet_type) {
return rtcp_sender_.SendRTCP(GetFeedbackState(), rtcp_packet_type);
}
int32_t ModuleRtpRtcpImpl::SetRTCPApplicationSpecificData(
const uint8_t sub_type,
const uint32_t name,
const uint8_t* data,
const uint16_t length) {
return rtcp_sender_.SetApplicationSpecificData(sub_type, name, data, length);
}
// (XR) VOIP metric.
int32_t ModuleRtpRtcpImpl::SetRTCPVoIPMetrics(
const RTCPVoIPMetric* voip_metric) {
return rtcp_sender_.SetRTCPVoIPMetrics(voip_metric);
}
void ModuleRtpRtcpImpl::SetRtcpXrRrtrStatus(bool enable) {
return rtcp_sender_.SendRtcpXrReceiverReferenceTime(enable);
}
bool ModuleRtpRtcpImpl::RtcpXrRrtrStatus() const {
return rtcp_sender_.RtcpXrReceiverReferenceTime();
}
// TODO(asapersson): Replace this method with the one below.
int32_t ModuleRtpRtcpImpl::DataCountersRTP(
size_t* bytes_sent,
uint32_t* packets_sent) const {
StreamDataCounters rtp_stats;
StreamDataCounters rtx_stats;
rtp_sender_.GetDataCounters(&rtp_stats, &rtx_stats);
if (bytes_sent) {
*bytes_sent = rtp_stats.bytes + rtp_stats.padding_bytes +
rtp_stats.header_bytes + rtx_stats.bytes +
rtx_stats.padding_bytes + rtx_stats.header_bytes;
}
if (packets_sent) {
*packets_sent = rtp_stats.packets + rtx_stats.packets;
}
return 0;
}
void ModuleRtpRtcpImpl::GetSendStreamDataCounters(
StreamDataCounters* rtp_counters,
StreamDataCounters* rtx_counters) const {
rtp_sender_.GetDataCounters(rtp_counters, rtx_counters);
}
int32_t ModuleRtpRtcpImpl::RemoteRTCPStat(RTCPSenderInfo* sender_info) {
return rtcp_receiver_.SenderInfoReceived(sender_info);
}
// Received RTCP report.
int32_t ModuleRtpRtcpImpl::RemoteRTCPStat(
std::vector<RTCPReportBlock>* receive_blocks) const {
return rtcp_receiver_.StatisticsReceived(receive_blocks);
}
int32_t ModuleRtpRtcpImpl::AddRTCPReportBlock(
const uint32_t ssrc,
const RTCPReportBlock* report_block) {
return rtcp_sender_.AddExternalReportBlock(ssrc, report_block);
}
int32_t ModuleRtpRtcpImpl::RemoveRTCPReportBlock(
const uint32_t ssrc) {
return rtcp_sender_.RemoveExternalReportBlock(ssrc);
}
void ModuleRtpRtcpImpl::GetRtcpPacketTypeCounters(
RtcpPacketTypeCounter* packets_sent,
RtcpPacketTypeCounter* packets_received) const {
rtcp_sender_.GetPacketTypeCounter(packets_sent);
rtcp_receiver_.GetPacketTypeCounter(packets_received);
}
// (REMB) Receiver Estimated Max Bitrate.
bool ModuleRtpRtcpImpl::REMB() const {
return rtcp_sender_.REMB();
}
void ModuleRtpRtcpImpl::SetREMBStatus(const bool enable) {
rtcp_sender_.SetREMBStatus(enable);
}
void ModuleRtpRtcpImpl::SetREMBData(const uint32_t bitrate,
const std::vector<uint32_t>& ssrcs) {
rtcp_sender_.SetREMBData(bitrate, ssrcs);
}
// (IJ) Extended jitter report.
bool ModuleRtpRtcpImpl::IJ() const {
return rtcp_sender_.IJ();
}
void ModuleRtpRtcpImpl::SetIJStatus(const bool enable) {
rtcp_sender_.SetIJStatus(enable);
}
int32_t ModuleRtpRtcpImpl::RegisterSendRtpHeaderExtension(
const RTPExtensionType type,
const uint8_t id) {
return rtp_sender_.RegisterRtpHeaderExtension(type, id);
}
int32_t ModuleRtpRtcpImpl::DeregisterSendRtpHeaderExtension(
const RTPExtensionType type) {
return rtp_sender_.DeregisterRtpHeaderExtension(type);
}
// (TMMBR) Temporary Max Media Bit Rate.
bool ModuleRtpRtcpImpl::TMMBR() const {
return rtcp_sender_.TMMBR();
}
void ModuleRtpRtcpImpl::SetTMMBRStatus(const bool enable) {
rtcp_sender_.SetTMMBRStatus(enable);
}
int32_t ModuleRtpRtcpImpl::SetTMMBN(const TMMBRSet* bounding_set) {
uint32_t max_bitrate_kbit =
rtp_sender_.MaxConfiguredBitrateVideo() / 1000;
return rtcp_sender_.SetTMMBN(bounding_set, max_bitrate_kbit);
}
// Returns the currently configured retransmission mode.
int ModuleRtpRtcpImpl::SelectiveRetransmissions() const {
return rtp_sender_.SelectiveRetransmissions();
}
// Enable or disable a retransmission mode, which decides which packets will
// be retransmitted if NACKed.
int ModuleRtpRtcpImpl::SetSelectiveRetransmissions(uint8_t settings) {
return rtp_sender_.SetSelectiveRetransmissions(settings);
}
// Send a Negative acknowledgment packet.
int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list,
const uint16_t size) {
uint16_t nack_length = size;
uint16_t start_id = 0;
int64_t now = clock_->TimeInMilliseconds();
if (TimeToSendFullNackList(now)) {
nack_last_time_sent_full_ = now;
nack_last_time_sent_full_prev_ = now;
} else {
// Only send extended list.
if (nack_last_seq_number_sent_ == nack_list[size - 1]) {
// Last sequence number is the same, do not send list.
return 0;
}
// Send new sequence numbers.
for (int i = 0; i < size; ++i) {
if (nack_last_seq_number_sent_ == nack_list[i]) {
start_id = i + 1;
break;
}
}
nack_length = size - start_id;
}
// Our RTCP NACK implementation is limited to kRtcpMaxNackFields sequence
// numbers per RTCP packet.
if (nack_length > kRtcpMaxNackFields) {
nack_length = kRtcpMaxNackFields;
}
nack_last_seq_number_sent_ = nack_list[start_id + nack_length - 1];
return rtcp_sender_.SendRTCP(
GetFeedbackState(), kRtcpNack, nack_length, &nack_list[start_id]);
}
bool ModuleRtpRtcpImpl::TimeToSendFullNackList(int64_t now) const {
// Use RTT from RtcpRttStats class if provided.
uint16_t rtt = rtt_ms();
if (rtt == 0) {
rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
}
const int64_t kStartUpRttMs = 100;
int64_t wait_time = 5 + ((rtt * 3) >> 1); // 5 + RTT * 1.5.
if (rtt == 0) {
wait_time = kStartUpRttMs;
}
// Send a full NACK list once within every |wait_time|.
if (rtt_stats_) {
return now - nack_last_time_sent_full_ > wait_time;
}
return now - nack_last_time_sent_full_prev_ > wait_time;
}
// Store the sent packets, needed to answer to a Negative acknowledgment
// requests.
void ModuleRtpRtcpImpl::SetStorePacketsStatus(const bool enable,
const uint16_t number_to_store) {
rtp_sender_.SetStorePacketsStatus(enable, number_to_store);
}
bool ModuleRtpRtcpImpl::StorePackets() const {
return rtp_sender_.StorePackets();
}
void ModuleRtpRtcpImpl::RegisterRtcpStatisticsCallback(
RtcpStatisticsCallback* callback) {
rtcp_receiver_.RegisterRtcpStatisticsCallback(callback);
}
RtcpStatisticsCallback*
ModuleRtpRtcpImpl::GetRtcpStatisticsCallback() {
return rtcp_receiver_.GetRtcpStatisticsCallback();
}
// Send a TelephoneEvent tone using RFC 2833 (4733).
int32_t ModuleRtpRtcpImpl::SendTelephoneEventOutband(
const uint8_t key,
const uint16_t time_ms,
const uint8_t level) {
return rtp_sender_.SendTelephoneEvent(key, time_ms, level);
}
bool ModuleRtpRtcpImpl::SendTelephoneEventActive(
int8_t& telephone_event) const {
return rtp_sender_.SendTelephoneEventActive(&telephone_event);
}
// Set audio packet size, used to determine when it's time to send a DTMF
// packet in silence (CNG).
int32_t ModuleRtpRtcpImpl::SetAudioPacketSize(
const uint16_t packet_size_samples) {
return rtp_sender_.SetAudioPacketSize(packet_size_samples);
}
int32_t ModuleRtpRtcpImpl::SetAudioLevel(
const uint8_t level_d_bov) {
return rtp_sender_.SetAudioLevel(level_d_bov);
}
// Set payload type for Redundant Audio Data RFC 2198.
int32_t ModuleRtpRtcpImpl::SetSendREDPayloadType(
const int8_t payload_type) {
return rtp_sender_.SetRED(payload_type);
}
// Get payload type for Redundant Audio Data RFC 2198.
int32_t ModuleRtpRtcpImpl::SendREDPayloadType(
int8_t& payload_type) const {
return rtp_sender_.RED(&payload_type);
}
void ModuleRtpRtcpImpl::SetTargetSendBitrate(
const std::vector<uint32_t>& stream_bitrates) {
if (IsDefaultModule()) {
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
if (simulcast_) {
std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin();
for (size_t i = 0;
it != child_modules_.end() && i < stream_bitrates.size(); ++it) {
if ((*it)->SendingMedia()) {
RTPSender& rtp_sender = (*it)->rtp_sender_;
rtp_sender.SetTargetBitrate(stream_bitrates[i]);
++i;
}
}
} else {
if (stream_bitrates.size() > 1)
return;
std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin();
for (; it != child_modules_.end(); ++it) {
RTPSender& rtp_sender = (*it)->rtp_sender_;
rtp_sender.SetTargetBitrate(stream_bitrates[0]);
}
}
} else {
if (stream_bitrates.size() > 1)
return;
rtp_sender_.SetTargetBitrate(stream_bitrates[0]);
}
}
int32_t ModuleRtpRtcpImpl::SetKeyFrameRequestMethod(
const KeyFrameRequestMethod method) {
key_frame_req_method_ = method;
return 0;
}
int32_t ModuleRtpRtcpImpl::RequestKeyFrame() {
switch (key_frame_req_method_) {
case kKeyFrameReqFirRtp:
return rtp_sender_.SendRTPIntraRequest();
case kKeyFrameReqPliRtcp:
return SendRTCP(kRtcpPli);
case kKeyFrameReqFirRtcp:
return SendRTCP(kRtcpFir);
}
return -1;
}
int32_t ModuleRtpRtcpImpl::SendRTCPSliceLossIndication(
const uint8_t picture_id) {
return rtcp_sender_.SendRTCP(
GetFeedbackState(), kRtcpSli, 0, 0, false, picture_id);
}
int32_t ModuleRtpRtcpImpl::SetCameraDelay(const int32_t delay_ms) {
if (IsDefaultModule()) {
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin();
while (it != child_modules_.end()) {
RtpRtcp* module = *it;
if (module) {
module->SetCameraDelay(delay_ms);
}
it++;
}
return 0;
}
return rtcp_sender_.SetCameraDelay(delay_ms);
}
int32_t ModuleRtpRtcpImpl::SetGenericFECStatus(
const bool enable,
const uint8_t payload_type_red,
const uint8_t payload_type_fec) {
return rtp_sender_.SetGenericFECStatus(enable,
payload_type_red,
payload_type_fec);
}
int32_t ModuleRtpRtcpImpl::GenericFECStatus(
bool& enable,
uint8_t& payload_type_red,
uint8_t& payload_type_fec) {
bool child_enabled = false;
if (IsDefaultModule()) {
// For default we need to check all child modules too.
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin();
while (it != child_modules_.end()) {
RtpRtcp* module = *it;
if (module) {
bool enabled = false;
uint8_t dummy_ptype_red = 0;
uint8_t dummy_ptype_fec = 0;
if (module->GenericFECStatus(enabled,
dummy_ptype_red,
dummy_ptype_fec) == 0 && enabled) {
child_enabled = true;
break;
}
}
it++;
}
}
int32_t ret_val = rtp_sender_.GenericFECStatus(&enable,
&payload_type_red,
&payload_type_fec);
if (child_enabled) {
// Returns true if enabled for any child module.
enable = child_enabled;
}
return ret_val;
}
int32_t ModuleRtpRtcpImpl::SetFecParameters(
const FecProtectionParams* delta_params,
const FecProtectionParams* key_params) {
if (IsDefaultModule()) {
// For default we need to update all child modules too.
CriticalSectionScoped lock(critical_section_module_ptrs_.get());
std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin();
while (it != child_modules_.end()) {
RtpRtcp* module = *it;
if (module) {
module->SetFecParameters(delta_params, key_params);
}
it++;
}
return 0;
}
return rtp_sender_.SetFecParameters(delta_params, key_params);
}
void ModuleRtpRtcpImpl::SetRemoteSSRC(const uint32_t ssrc) {
// Inform about the incoming SSRC.
rtcp_sender_.SetRemoteSSRC(ssrc);
rtcp_receiver_.SetRemoteSSRC(ssrc);
// Check for a SSRC collision.
if (rtp_sender_.SSRC() == ssrc && !collision_detected_) {
// If we detect a collision change the SSRC but only once.
collision_detected_ = true;
uint32_t new_ssrc = rtp_sender_.GenerateNewSSRC();
if (new_ssrc == 0) {
// Configured via API ignore.
return;
}
if (kRtcpOff != rtcp_sender_.Status()) {
// Send RTCP bye on the current SSRC.
SendRTCP(kRtcpBye);
}
// Change local SSRC and inform all objects about the new SSRC.
rtcp_sender_.SetSSRC(new_ssrc);
SetRtcpReceiverSsrcs(new_ssrc);
}
}
void ModuleRtpRtcpImpl::BitrateSent(uint32_t* total_rate,
uint32_t* video_rate,
uint32_t* fec_rate,
uint32_t* nack_rate) const {
if (IsDefaultModule()) {
// For default we need to update the send bitrate.
CriticalSectionScoped lock(critical_section_module_ptrs_feedback_.get());
if (total_rate != NULL)
*total_rate = 0;
if (video_rate != NULL)
*video_rate = 0;
if (fec_rate != NULL)
*fec_rate = 0;
if (nack_rate != NULL)
*nack_rate = 0;
std::vector<ModuleRtpRtcpImpl*>::const_iterator it = child_modules_.begin();
while (it != child_modules_.end()) {
RtpRtcp* module = *it;
if (module) {
uint32_t child_total_rate = 0;
uint32_t child_video_rate = 0;
uint32_t child_fec_rate = 0;
uint32_t child_nack_rate = 0;
module->BitrateSent(&child_total_rate,
&child_video_rate,
&child_fec_rate,
&child_nack_rate);
if (total_rate != NULL && child_total_rate > *total_rate)
*total_rate = child_total_rate;
if (video_rate != NULL && child_video_rate > *video_rate)
*video_rate = child_video_rate;
if (fec_rate != NULL && child_fec_rate > *fec_rate)
*fec_rate = child_fec_rate;
if (nack_rate != NULL && child_nack_rate > *nack_rate)
*nack_rate = child_nack_rate;
}
it++;
}
return;
}
if (total_rate != NULL)
*total_rate = rtp_sender_.BitrateSent();
if (video_rate != NULL)
*video_rate = rtp_sender_.VideoBitrateSent();
if (fec_rate != NULL)
*fec_rate = rtp_sender_.FecOverheadRate();
if (nack_rate != NULL)
*nack_rate = rtp_sender_.NackOverheadRate();
}
void ModuleRtpRtcpImpl::OnRequestIntraFrame() {
RequestKeyFrame();
}
void ModuleRtpRtcpImpl::OnRequestSendReport() {
SendRTCP(kRtcpSr);
}
int32_t ModuleRtpRtcpImpl::SendRTCPReferencePictureSelection(
const uint64_t picture_id) {
return rtcp_sender_.SendRTCP(
GetFeedbackState(), kRtcpRpsi, 0, 0, false, picture_id);
}
uint32_t ModuleRtpRtcpImpl::SendTimeOfSendReport(
const uint32_t send_report) {
return rtcp_sender_.SendTimeOfSendReport(send_report);
}
bool ModuleRtpRtcpImpl::SendTimeOfXrRrReport(
uint32_t mid_ntp, int64_t* time_ms) const {
return rtcp_sender_.SendTimeOfXrRrReport(mid_ntp, time_ms);
}
void ModuleRtpRtcpImpl::OnReceivedNACK(
const std::list<uint16_t>& nack_sequence_numbers) {
if (!rtp_sender_.StorePackets() ||
nack_sequence_numbers.size() == 0) {
return;
}
// Use RTT from RtcpRttStats class if provided.
uint16_t rtt = rtt_ms();
if (rtt == 0) {
rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
}
rtp_sender_.OnReceivedNACK(nack_sequence_numbers, rtt);
}
bool ModuleRtpRtcpImpl::LastReceivedNTP(
uint32_t* rtcp_arrival_time_secs, // When we got the last report.
uint32_t* rtcp_arrival_time_frac,
uint32_t* remote_sr) const {
// Remote SR: NTP inside the last received (mid 16 bits from sec and frac).
uint32_t ntp_secs = 0;
uint32_t ntp_frac = 0;
if (!rtcp_receiver_.NTP(&ntp_secs,
&ntp_frac,
rtcp_arrival_time_secs,
rtcp_arrival_time_frac,
NULL)) {
return false;
}
*remote_sr =
((ntp_secs & 0x0000ffff) << 16) + ((ntp_frac & 0xffff0000) >> 16);
return true;
}
bool ModuleRtpRtcpImpl::LastReceivedXrReferenceTimeInfo(
RtcpReceiveTimeInfo* info) const {
return rtcp_receiver_.LastReceivedXrReferenceTimeInfo(info);
}
bool ModuleRtpRtcpImpl::UpdateRTCPReceiveInformationTimers() {
// If this returns true this channel has timed out.
// Periodically check if this is true and if so call UpdateTMMBR.
return rtcp_receiver_.UpdateRTCPReceiveInformationTimers();
}
// Called from RTCPsender.
int32_t ModuleRtpRtcpImpl::BoundingSet(bool& tmmbr_owner,
TMMBRSet*& bounding_set) {
return rtcp_receiver_.BoundingSet(tmmbr_owner, bounding_set);
}
int64_t ModuleRtpRtcpImpl::RtcpReportInterval() {
if (audio_)
return RTCP_INTERVAL_AUDIO_MS;
else
return RTCP_INTERVAL_VIDEO_MS;
}
void ModuleRtpRtcpImpl::SetRtcpReceiverSsrcs(uint32_t main_ssrc) {
std::set<uint32_t> ssrcs;
ssrcs.insert(main_ssrc);
int rtx_mode = kRtxOff;
uint32_t rtx_ssrc = 0;
int rtx_payload_type = 0;
rtp_sender_.RTXStatus(&rtx_mode, &rtx_ssrc, &rtx_payload_type);
if (rtx_mode != kRtxOff)
ssrcs.insert(rtx_ssrc);
rtcp_receiver_.SetSsrcs(main_ssrc, ssrcs);
}
void ModuleRtpRtcpImpl::set_rtt_ms(uint32_t rtt_ms) {
CriticalSectionScoped cs(critical_section_rtt_.get());
rtt_ms_ = rtt_ms;
}
uint32_t ModuleRtpRtcpImpl::rtt_ms() const {
CriticalSectionScoped cs(critical_section_rtt_.get());
return rtt_ms_;
}
void ModuleRtpRtcpImpl::RegisterSendChannelRtpStatisticsCallback(
StreamDataCountersCallback* callback) {
rtp_sender_.RegisterRtpStatisticsCallback(callback);
}
StreamDataCountersCallback*
ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const {
return rtp_sender_.GetRtpStatisticsCallback();
}
bool ModuleRtpRtcpImpl::IsDefaultModule() const {
CriticalSectionScoped cs(critical_section_module_ptrs_.get());
return !child_modules_.empty();
}
} // Namespace webrtc
|