OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 tmmbr_send_(0), | 163 tmmbr_send_(0), |
164 packet_oh_send_(0), | 164 packet_oh_send_(0), |
165 | 165 |
166 app_sub_type_(0), | 166 app_sub_type_(0), |
167 app_name_(0), | 167 app_name_(0), |
168 app_data_(nullptr), | 168 app_data_(nullptr), |
169 app_length_(0), | 169 app_length_(0), |
170 | 170 |
171 xr_send_receiver_reference_time_enabled_(false), | 171 xr_send_receiver_reference_time_enabled_(false), |
172 packet_type_counter_observer_(packet_type_counter_observer) { | 172 packet_type_counter_observer_(packet_type_counter_observer) { |
173 memset(cname_, 0, sizeof(cname_)); | |
174 memset(last_send_report_, 0, sizeof(last_send_report_)); | 173 memset(last_send_report_, 0, sizeof(last_send_report_)); |
175 memset(last_rtcp_time_, 0, sizeof(last_rtcp_time_)); | 174 memset(last_rtcp_time_, 0, sizeof(last_rtcp_time_)); |
176 | 175 |
177 builders_[kRtcpSr] = &RTCPSender::BuildSR; | 176 builders_[kRtcpSr] = &RTCPSender::BuildSR; |
178 builders_[kRtcpRr] = &RTCPSender::BuildRR; | 177 builders_[kRtcpRr] = &RTCPSender::BuildRR; |
179 builders_[kRtcpSdes] = &RTCPSender::BuildSDEC; | 178 builders_[kRtcpSdes] = &RTCPSender::BuildSDES; |
180 builders_[kRtcpTransmissionTimeOffset] = | 179 builders_[kRtcpTransmissionTimeOffset] = |
181 &RTCPSender::BuildExtendedJitterReport; | 180 &RTCPSender::BuildExtendedJitterReport; |
182 builders_[kRtcpPli] = &RTCPSender::BuildPLI; | 181 builders_[kRtcpPli] = &RTCPSender::BuildPLI; |
183 builders_[kRtcpFir] = &RTCPSender::BuildFIR; | 182 builders_[kRtcpFir] = &RTCPSender::BuildFIR; |
184 builders_[kRtcpSli] = &RTCPSender::BuildSLI; | 183 builders_[kRtcpSli] = &RTCPSender::BuildSLI; |
185 builders_[kRtcpRpsi] = &RTCPSender::BuildRPSI; | 184 builders_[kRtcpRpsi] = &RTCPSender::BuildRPSI; |
186 builders_[kRtcpRemb] = &RTCPSender::BuildREMB; | 185 builders_[kRtcpRemb] = &RTCPSender::BuildREMB; |
187 builders_[kRtcpBye] = &RTCPSender::BuildBYE; | 186 builders_[kRtcpBye] = &RTCPSender::BuildBYE; |
188 builders_[kRtcpApp] = &RTCPSender::BuildAPP; | 187 builders_[kRtcpApp] = &RTCPSender::BuildAPP; |
189 builders_[kRtcpTmmbr] = &RTCPSender::BuildTMMBR; | 188 builders_[kRtcpTmmbr] = &RTCPSender::BuildTMMBR; |
190 builders_[kRtcpTmmbn] = &RTCPSender::BuildTMMBN; | 189 builders_[kRtcpTmmbn] = &RTCPSender::BuildTMMBN; |
191 builders_[kRtcpNack] = &RTCPSender::BuildNACK; | 190 builders_[kRtcpNack] = &RTCPSender::BuildNACK; |
192 builders_[kRtcpXrVoipMetric] = &RTCPSender::BuildVoIPMetric; | 191 builders_[kRtcpXrVoipMetric] = &RTCPSender::BuildVoIPMetric; |
193 builders_[kRtcpXrReceiverReferenceTime] = | 192 builders_[kRtcpXrReceiverReferenceTime] = |
194 &RTCPSender::BuildReceiverReferenceTime; | 193 &RTCPSender::BuildReceiverReferenceTime; |
195 builders_[kRtcpXrDlrrReportBlock] = &RTCPSender::BuildDlrr; | 194 builders_[kRtcpXrDlrrReportBlock] = &RTCPSender::BuildDlrr; |
196 } | 195 } |
197 | 196 |
198 RTCPSender::~RTCPSender() { | 197 RTCPSender::~RTCPSender() { |
199 for (auto it : csrc_cnames_) | |
200 delete it.second; | |
201 } | 198 } |
202 | 199 |
203 int32_t RTCPSender::RegisterSendTransport(Transport* outgoingTransport) { | 200 int32_t RTCPSender::RegisterSendTransport(Transport* outgoingTransport) { |
204 CriticalSectionScoped lock(critical_section_transport_.get()); | 201 CriticalSectionScoped lock(critical_section_transport_.get()); |
205 cbTransport_ = outgoingTransport; | 202 cbTransport_ = outgoingTransport; |
206 return 0; | 203 return 0; |
207 } | 204 } |
208 | 205 |
209 RTCPMethod RTCPSender::Status() const { | 206 RTCPMethod RTCPSender::Status() const { |
210 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); | 207 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); | 323 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); |
327 remote_ssrc_ = ssrc; | 324 remote_ssrc_ = ssrc; |
328 } | 325 } |
329 | 326 |
330 int32_t RTCPSender::SetCNAME(const char* c_name) { | 327 int32_t RTCPSender::SetCNAME(const char* c_name) { |
331 if (!c_name) | 328 if (!c_name) |
332 return -1; | 329 return -1; |
333 | 330 |
334 DCHECK_LT(strlen(c_name), static_cast<size_t>(RTCP_CNAME_SIZE)); | 331 DCHECK_LT(strlen(c_name), static_cast<size_t>(RTCP_CNAME_SIZE)); |
335 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); | 332 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); |
336 cname_[RTCP_CNAME_SIZE - 1] = 0; | 333 cname_ = c_name; |
337 strncpy(cname_, c_name, RTCP_CNAME_SIZE - 1); | |
338 return 0; | 334 return 0; |
339 } | 335 } |
340 | 336 |
341 int32_t RTCPSender::AddMixedCNAME(uint32_t SSRC, | 337 int32_t RTCPSender::AddMixedCNAME(uint32_t SSRC, const char* c_name) { |
342 const char cName[RTCP_CNAME_SIZE]) { | 338 assert(c_name); |
343 assert(cName); | 339 DCHECK_LT(strlen(c_name), static_cast<size_t>(RTCP_CNAME_SIZE)); |
344 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); | 340 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); |
345 if (csrc_cnames_.size() >= kRtpCsrcSize) { | 341 if (csrc_cnames_.size() >= kRtpCsrcSize) |
346 return -1; | 342 return -1; |
347 } | 343 |
348 RTCPCnameInformation* ptr = new RTCPCnameInformation(); | 344 csrc_cnames_[SSRC] = c_name; |
349 ptr->name[RTCP_CNAME_SIZE - 1] = 0; | |
350 strncpy(ptr->name, cName, RTCP_CNAME_SIZE - 1); | |
351 csrc_cnames_[SSRC] = ptr; | |
352 return 0; | 345 return 0; |
353 } | 346 } |
354 | 347 |
355 int32_t RTCPSender::RemoveMixedCNAME(uint32_t SSRC) { | 348 int32_t RTCPSender::RemoveMixedCNAME(uint32_t SSRC) { |
356 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); | 349 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); |
357 std::map<uint32_t, RTCPCnameInformation*>::iterator it = | 350 auto it = csrc_cnames_.find(SSRC); |
358 csrc_cnames_.find(SSRC); | |
359 | 351 |
360 if (it == csrc_cnames_.end()) | 352 if (it == csrc_cnames_.end()) |
361 return -1; | 353 return -1; |
362 | 354 |
363 delete it->second; | |
364 csrc_cnames_.erase(it); | 355 csrc_cnames_.erase(it); |
365 return 0; | 356 return 0; |
366 } | 357 } |
367 | 358 |
368 bool RTCPSender::TimeToSendRTCPReport(bool sendKeyframeBeforeRTP) const { | 359 bool RTCPSender::TimeToSendRTCPReport(bool sendKeyframeBeforeRTP) const { |
369 /* | 360 /* |
370 For audio we use a fix 5 sec interval | 361 For audio we use a fix 5 sec interval |
371 | 362 |
372 For video we use 1 sec interval fo a BW smaller than 360 kbit/s, | 363 For video we use 1 sec interval fo a BW smaller than 360 kbit/s, |
373 technicaly we break the max 5% RTCP BW for video below 10 kbit/s but | 364 technicaly we break the max 5% RTCP BW for video below 10 kbit/s but |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 if (!report.BuildExternalBuffer(&ctx->buffer[ctx->position], | 519 if (!report.BuildExternalBuffer(&ctx->buffer[ctx->position], |
529 ctx->buffer_size - ctx->position, | 520 ctx->buffer_size - ctx->position, |
530 &callback)) { | 521 &callback)) { |
531 return BuildResult::kTruncated; | 522 return BuildResult::kTruncated; |
532 } | 523 } |
533 | 524 |
534 report_blocks_.clear(); | 525 report_blocks_.clear(); |
535 return BuildResult::kSuccess; | 526 return BuildResult::kSuccess; |
536 } | 527 } |
537 | 528 |
538 RTCPSender::BuildResult RTCPSender::BuildSDEC(RtcpContext* ctx) { | 529 RTCPSender::BuildResult RTCPSender::BuildSDES(RtcpContext* ctx) { |
539 size_t lengthCname = strlen(cname_); | 530 size_t length_cname = cname_.length(); |
540 assert(lengthCname < RTCP_CNAME_SIZE); | 531 CHECK_LT(length_cname, static_cast<size_t>(RTCP_CNAME_SIZE)); |
541 | 532 |
542 // sanity | 533 rtcp::Sdes sdes; |
543 if (ctx->position + 12 + lengthCname >= IP_PACKET_SIZE) { | 534 sdes.WithCName(ssrc_, cname_); |
544 LOG(LS_WARNING) << "Failed to build SDEC."; | 535 |
| 536 for (const auto it : csrc_cnames_) |
| 537 sdes.WithCName(it.first, it.second); |
| 538 |
| 539 PacketBuiltCallback callback(ctx); |
| 540 if (!sdes.BuildExternalBuffer(&ctx->buffer[ctx->position], |
| 541 ctx->buffer_size - ctx->position, &callback)) { |
545 return BuildResult::kTruncated; | 542 return BuildResult::kTruncated; |
546 } | 543 } |
547 // SDEC Source Description | |
548 | 544 |
549 // We always need to add SDES CNAME | |
550 size_t size = 0x80 + 1 + csrc_cnames_.size(); | |
551 DCHECK_LE(size, std::numeric_limits<uint8_t>::max()); | |
552 *ctx->AllocateData(1) = static_cast<uint8_t>(size); | |
553 *ctx->AllocateData(1) = 202; | |
554 | |
555 // handle SDES length later on | |
556 uint32_t SDESLengthPos = ctx->position; | |
557 ctx->AllocateData(2); | |
558 | |
559 // Add our own SSRC | |
560 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), ssrc_); | |
561 | |
562 // CNAME = 1 | |
563 *ctx->AllocateData(1) = 1; | |
564 DCHECK_LE(lengthCname, std::numeric_limits<uint8_t>::max()); | |
565 *ctx->AllocateData(1) = static_cast<uint8_t>(lengthCname); | |
566 | |
567 uint16_t SDESLength = 10; | |
568 | |
569 memcpy(ctx->AllocateData(lengthCname), cname_, lengthCname); | |
570 SDESLength += static_cast<uint16_t>(lengthCname); | |
571 | |
572 uint16_t padding = 0; | |
573 // We must have a zero field even if we have an even multiple of 4 bytes | |
574 do { | |
575 ++padding; | |
576 *ctx->AllocateData(1) = 0; | |
577 } while ((ctx->position % 4) != 0); | |
578 SDESLength += padding; | |
579 | |
580 for (auto it = csrc_cnames_.begin(); it != csrc_cnames_.end(); ++it) { | |
581 RTCPCnameInformation* cname = it->second; | |
582 uint32_t SSRC = it->first; | |
583 | |
584 // Add SSRC | |
585 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), SSRC); | |
586 | |
587 // CNAME = 1 | |
588 *ctx->AllocateData(1) = 1; | |
589 | |
590 size_t length = strlen(cname->name); | |
591 assert(length < RTCP_CNAME_SIZE); | |
592 | |
593 *ctx->AllocateData(1) = static_cast<uint8_t>(length); | |
594 SDESLength += 6; | |
595 | |
596 memcpy(ctx->AllocateData(length), cname->name, length); | |
597 | |
598 SDESLength += length; | |
599 uint16_t padding = 0; | |
600 | |
601 // We must have a zero field even if we have an even multiple of 4 bytes | |
602 do { | |
603 ++padding; | |
604 *ctx->AllocateData(1) = 0; | |
605 } while ((ctx->position % 4) != 0); | |
606 SDESLength += padding; | |
607 } | |
608 // in 32-bit words minus one and we don't count the header | |
609 uint16_t buffer_length = (SDESLength / 4) - 1; | |
610 ByteWriter<uint16_t>::WriteBigEndian(&ctx->buffer[SDESLengthPos], | |
611 buffer_length); | |
612 return BuildResult::kSuccess; | 545 return BuildResult::kSuccess; |
613 } | 546 } |
614 | 547 |
615 RTCPSender::BuildResult RTCPSender::BuildRR(RtcpContext* ctx) { | 548 RTCPSender::BuildResult RTCPSender::BuildRR(RtcpContext* ctx) { |
616 rtcp::ReceiverReport report; | 549 rtcp::ReceiverReport report; |
617 report.From(ssrc_); | 550 report.From(ssrc_); |
618 for (auto it : report_blocks_) | 551 for (auto it : report_blocks_) |
619 report.WithReportBlock(it.second); | 552 report.WithReportBlock(it.second); |
620 | 553 |
621 PacketBuiltCallback callback(ctx); | 554 PacketBuiltCallback callback(ctx); |
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 generate_report = true; | 1335 generate_report = true; |
1403 DCHECK(ConsumeFlag(kRtcpReport) == false); | 1336 DCHECK(ConsumeFlag(kRtcpReport) == false); |
1404 } else { | 1337 } else { |
1405 generate_report = | 1338 generate_report = |
1406 (ConsumeFlag(kRtcpReport) && method_ == kRtcpNonCompound) || | 1339 (ConsumeFlag(kRtcpReport) && method_ == kRtcpNonCompound) || |
1407 method_ == kRtcpCompound; | 1340 method_ == kRtcpCompound; |
1408 if (generate_report) | 1341 if (generate_report) |
1409 SetFlag(sending_ ? kRtcpSr : kRtcpRr, true); | 1342 SetFlag(sending_ ? kRtcpSr : kRtcpRr, true); |
1410 } | 1343 } |
1411 | 1344 |
1412 if (IsFlagPresent(kRtcpSr) || (IsFlagPresent(kRtcpRr) && cname_[0] != 0)) | 1345 if (IsFlagPresent(kRtcpSr) || (IsFlagPresent(kRtcpRr) && !cname_.empty())) |
1413 SetFlag(kRtcpSdes, true); | 1346 SetFlag(kRtcpSdes, true); |
1414 | 1347 |
1415 // We need to send our NTP even if we haven't received any reports. | 1348 // We need to send our NTP even if we haven't received any reports. |
1416 clock_->CurrentNtp(context.ntp_sec, context.ntp_frac); | 1349 clock_->CurrentNtp(context.ntp_sec, context.ntp_frac); |
1417 | 1350 |
1418 if (generate_report) { | 1351 if (generate_report) { |
1419 if (!sending_ && xr_send_receiver_reference_time_enabled_) | 1352 if (!sending_ && xr_send_receiver_reference_time_enabled_) |
1420 SetFlag(kRtcpXrReceiverReferenceTime, true); | 1353 SetFlag(kRtcpXrReceiverReferenceTime, true); |
1421 if (feedback_state.has_last_xr_rr) | 1354 if (feedback_state.has_last_xr_rr) |
1422 SetFlag(kRtcpXrDlrrReportBlock, true); | 1355 SetFlag(kRtcpXrDlrrReportBlock, true); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 while (it != report_flags_.end()) { | 1395 while (it != report_flags_.end()) { |
1463 auto builder = builders_.find(it->type); | 1396 auto builder = builders_.find(it->type); |
1464 DCHECK(builder != builders_.end()); | 1397 DCHECK(builder != builders_.end()); |
1465 if (it->is_volatile) { | 1398 if (it->is_volatile) { |
1466 report_flags_.erase(it++); | 1399 report_flags_.erase(it++); |
1467 } else { | 1400 } else { |
1468 ++it; | 1401 ++it; |
1469 } | 1402 } |
1470 | 1403 |
1471 uint32_t start_position = context.position; | 1404 uint32_t start_position = context.position; |
1472 BuildResult result = (*this.*(builder->second))(&context); | 1405 BuildResult result = (this->*(builder->second))(&context); |
1473 switch (result) { | 1406 switch (result) { |
1474 case BuildResult::kError: | 1407 case BuildResult::kError: |
1475 return -1; | 1408 return -1; |
1476 case BuildResult::kTruncated: | 1409 case BuildResult::kTruncated: |
1477 return context.position; | 1410 return context.position; |
1478 case BuildResult::kAborted: | 1411 case BuildResult::kAborted: |
1479 context.position = start_position; | 1412 context.position = start_position; |
1480 FALLTHROUGH(); | 1413 FALLTHROUGH(); |
1481 case BuildResult::kSuccess: | 1414 case BuildResult::kSuccess: |
1482 continue; | 1415 continue; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1625 | 1558 |
1626 bool RTCPSender::AllVolatileFlagsConsumed() const { | 1559 bool RTCPSender::AllVolatileFlagsConsumed() const { |
1627 for (const ReportFlag& flag : report_flags_) { | 1560 for (const ReportFlag& flag : report_flags_) { |
1628 if (flag.is_volatile) | 1561 if (flag.is_volatile) |
1629 return false; | 1562 return false; |
1630 } | 1563 } |
1631 return true; | 1564 return true; |
1632 } | 1565 } |
1633 | 1566 |
1634 } // namespace webrtc | 1567 } // namespace webrtc |
OLD | NEW |