Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: media/cast/net/rtcp/rtcp_utility.cc

Issue 1520613004: cast: Split Rtcp into two for sender and receiver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@timestamp
Patch Set: Add missing rtcp_session.h and a few comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cast/net/rtcp/rtcp_utility.h" 5 #include "media/cast/net/rtcp/rtcp_utility.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/cast/net/cast_transport_defines.h" 10 #include "media/cast/net/cast_transport_defines.h"
11 11
12 namespace media { 12 namespace media {
13 namespace cast { 13 namespace cast {
14 14
15 namespace { 15 namespace {
16 16
17 // January 1970, in NTP seconds. 17 // January 1970, in NTP seconds.
18 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on 18 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on
19 // 1 January 1900. 19 // 1 January 1900.
20 const int64_t kUnixEpochInNtpSeconds = INT64_C(2208988800); 20 const int64_t kUnixEpochInNtpSeconds = INT64_C(2208988800);
21 21
22 // Magic fractional unit. Used to convert time (in microseconds) to/from 22 // Magic fractional unit. Used to convert time (in microseconds) to/from
23 // fractional NTP seconds. 23 // fractional NTP seconds.
24 const double kMagicFractionalUnit = 4.294967296E3; 24 const double kMagicFractionalUnit = 4.294967296E3;
25 } 25
26 } // namespace
26 27
27 RtcpParser::RtcpParser(uint32 local_ssrc, uint32 remote_ssrc) : 28 RtcpParser::RtcpParser(uint32 local_ssrc, uint32 remote_ssrc) :
28 local_ssrc_(local_ssrc), 29 local_ssrc_(local_ssrc),
29 remote_ssrc_(remote_ssrc), 30 remote_ssrc_(remote_ssrc),
30 has_sender_report_(false), 31 has_sender_report_(false),
31 has_last_report_(false), 32 has_last_report_(false),
32 has_cast_message_(false), 33 has_cast_message_(false),
33 has_receiver_reference_time_report_(false) { 34 has_receiver_reference_time_report_(false) {
34 } 35 }
35 36
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (!reader->ReadU32(&sender_ssrc) || 190 if (!reader->ReadU32(&sender_ssrc) ||
190 !reader->ReadU32(&name)) 191 !reader->ReadU32(&name))
191 return false; 192 return false;
192 193
193 if (sender_ssrc != remote_ssrc_) 194 if (sender_ssrc != remote_ssrc_)
194 return true; 195 return true;
195 196
196 if (name != kCast) 197 if (name != kCast)
197 return false; 198 return false;
198 199
199 switch (header.IC /* subtype */ ) { 200 switch (header.IC) { // subtype
200 case kReceiverLogSubtype: 201 case kReceiverLogSubtype:
201 if (!ParseCastReceiverLogFrameItem(reader)) 202 if (!ParseCastReceiverLogFrameItem(reader))
202 return false; 203 return false;
203 break; 204 break;
204 } 205 }
205 return true; 206 return true;
206 } 207 }
207 208
208 bool RtcpParser::ParseCastReceiverLogFrameItem( 209 bool RtcpParser::ParseCastReceiverLogFrameItem(
209 base::BigEndianReader* reader) { 210 base::BigEndianReader* reader) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 347 }
347 } 348 }
348 349
349 return true; 350 return true;
350 } 351 }
351 352
352 bool RtcpParser::ParseExtendedReportReceiverReferenceTimeReport( 353 bool RtcpParser::ParseExtendedReportReceiverReferenceTimeReport(
353 base::BigEndianReader* reader, 354 base::BigEndianReader* reader,
354 uint32 remote_ssrc) { 355 uint32 remote_ssrc) {
355 receiver_reference_time_report_.remote_ssrc = remote_ssrc; 356 receiver_reference_time_report_.remote_ssrc = remote_ssrc;
356 if(!reader->ReadU32(&receiver_reference_time_report_.ntp_seconds) || 357 if (!reader->ReadU32(&receiver_reference_time_report_.ntp_seconds) ||
357 !reader->ReadU32(&receiver_reference_time_report_.ntp_fraction)) 358 !reader->ReadU32(&receiver_reference_time_report_.ntp_fraction))
358 return false; 359 return false;
359 360
360 has_receiver_reference_time_report_ = true; 361 has_receiver_reference_time_report_ = true;
361 return true; 362 return true;
362 } 363 }
363 364
364 // Converts a log event type to an integer value. 365 // Converts a log event type to an integer value.
365 // NOTE: We have only allocated 4 bits to represent the type of event over the 366 // NOTE: We have only allocated 4 bits to represent the type of event over the
366 // wire. Therefore, this function can only return values from 0 to 15. 367 // wire. Therefore, this function can only return values from 0 to 15.
367 uint8 ConvertEventTypeToWireFormat(CastLoggingEvent event) { 368 uint8 ConvertEventTypeToWireFormat(CastLoggingEvent event) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 int64_t ntp_time_us = 447 int64_t ntp_time_us =
447 ntp_seconds * base::Time::kMicrosecondsPerSecond + 448 ntp_seconds * base::Time::kMicrosecondsPerSecond +
448 static_cast<int64_t>(std::ceil(ntp_fractions / kMagicFractionalUnit)); 449 static_cast<int64_t>(std::ceil(ntp_fractions / kMagicFractionalUnit));
449 450
450 base::TimeDelta elapsed_since_unix_epoch = base::TimeDelta::FromMicroseconds( 451 base::TimeDelta elapsed_since_unix_epoch = base::TimeDelta::FromMicroseconds(
451 ntp_time_us - 452 ntp_time_us -
452 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); 453 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond));
453 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; 454 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch;
454 } 455 }
455 456
457 namespace {
458 enum {
459 // Minimum number of bytes required to make a valid RTCP packet.
460 kMinLengthOfRtcp = 8,
461 };
462 } // namespace
463
464 bool IsRtcpPacket(const uint8_t* packet, size_t length) {
465 if (length < kMinLengthOfRtcp) {
466 LOG(ERROR) << "Invalid RTCP packet received.";
467 return false;
468 }
469
470 uint8_t packet_type = packet[1];
471 return packet_type >= kPacketTypeLow && packet_type <= kPacketTypeHigh;
472 }
473
474 uint32_t GetSsrcOfSender(const uint8_t* rtcp_buffer, size_t length) {
475 if (length < kMinLengthOfRtcp)
476 return 0;
477 uint32_t ssrc_of_sender;
478 base::BigEndianReader big_endian_reader(
479 reinterpret_cast<const char*>(rtcp_buffer), length);
480 big_endian_reader.Skip(4); // Skip header.
481 big_endian_reader.ReadU32(&ssrc_of_sender);
482 return ssrc_of_sender;
483 }
484
456 } // namespace cast 485 } // namespace cast
457 } // namespace media 486 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698