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

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: Rebased Created 4 years, 11 months 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
« no previous file with comments | « media/cast/net/rtcp/rtcp_utility.h ('k') | media/cast/net/rtcp/sender_rtcp_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "media/cast/net/cast_transport_defines.h" 12 #include "media/cast/net/cast_transport_defines.h"
13 13
14 namespace media { 14 namespace media {
15 namespace cast { 15 namespace cast {
16 16
17 namespace { 17 namespace {
18 18
19 // January 1970, in NTP seconds. 19 // January 1970, in NTP seconds.
20 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on 20 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on
21 // 1 January 1900. 21 // 1 January 1900.
22 const int64_t kUnixEpochInNtpSeconds = INT64_C(2208988800); 22 const int64_t kUnixEpochInNtpSeconds = INT64_C(2208988800);
23 23
24 // Magic fractional unit. Used to convert time (in microseconds) to/from 24 // Magic fractional unit. Used to convert time (in microseconds) to/from
25 // fractional NTP seconds. 25 // fractional NTP seconds.
26 const double kMagicFractionalUnit = 4.294967296E3; 26 const double kMagicFractionalUnit = 4.294967296E3;
27 } 27
28 } // namespace
28 29
29 RtcpParser::RtcpParser(uint32_t local_ssrc, uint32_t remote_ssrc) 30 RtcpParser::RtcpParser(uint32_t local_ssrc, uint32_t remote_ssrc)
30 : local_ssrc_(local_ssrc), 31 : local_ssrc_(local_ssrc),
31 remote_ssrc_(remote_ssrc), 32 remote_ssrc_(remote_ssrc),
32 has_sender_report_(false), 33 has_sender_report_(false),
33 has_last_report_(false), 34 has_last_report_(false),
34 has_cast_message_(false), 35 has_cast_message_(false),
35 has_receiver_reference_time_report_(false) {} 36 has_receiver_reference_time_report_(false) {}
36 37
37 RtcpParser::~RtcpParser() {} 38 RtcpParser::~RtcpParser() {}
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 if (!reader->ReadU32(&sender_ssrc) || 191 if (!reader->ReadU32(&sender_ssrc) ||
191 !reader->ReadU32(&name)) 192 !reader->ReadU32(&name))
192 return false; 193 return false;
193 194
194 if (sender_ssrc != remote_ssrc_) 195 if (sender_ssrc != remote_ssrc_)
195 return true; 196 return true;
196 197
197 if (name != kCast) 198 if (name != kCast)
198 return false; 199 return false;
199 200
200 switch (header.IC /* subtype */ ) { 201 switch (header.IC) { // subtype
201 case kReceiverLogSubtype: 202 case kReceiverLogSubtype:
202 if (!ParseCastReceiverLogFrameItem(reader)) 203 if (!ParseCastReceiverLogFrameItem(reader))
203 return false; 204 return false;
204 break; 205 break;
205 } 206 }
206 return true; 207 return true;
207 } 208 }
208 209
209 bool RtcpParser::ParseCastReceiverLogFrameItem( 210 bool RtcpParser::ParseCastReceiverLogFrameItem(
210 base::BigEndianReader* reader) { 211 base::BigEndianReader* reader) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 } 348 }
348 } 349 }
349 350
350 return true; 351 return true;
351 } 352 }
352 353
353 bool RtcpParser::ParseExtendedReportReceiverReferenceTimeReport( 354 bool RtcpParser::ParseExtendedReportReceiverReferenceTimeReport(
354 base::BigEndianReader* reader, 355 base::BigEndianReader* reader,
355 uint32_t remote_ssrc) { 356 uint32_t remote_ssrc) {
356 receiver_reference_time_report_.remote_ssrc = remote_ssrc; 357 receiver_reference_time_report_.remote_ssrc = remote_ssrc;
357 if(!reader->ReadU32(&receiver_reference_time_report_.ntp_seconds) || 358 if (!reader->ReadU32(&receiver_reference_time_report_.ntp_seconds) ||
358 !reader->ReadU32(&receiver_reference_time_report_.ntp_fraction)) 359 !reader->ReadU32(&receiver_reference_time_report_.ntp_fraction))
359 return false; 360 return false;
360 361
361 has_receiver_reference_time_report_ = true; 362 has_receiver_reference_time_report_ = true;
362 return true; 363 return true;
363 } 364 }
364 365
365 // Converts a log event type to an integer value. 366 // Converts a log event type to an integer value.
366 // NOTE: We have only allocated 4 bits to represent the type of event over the 367 // NOTE: We have only allocated 4 bits to represent the type of event over the
367 // wire. Therefore, this function can only return values from 0 to 15. 368 // wire. Therefore, this function can only return values from 0 to 15.
368 uint8_t ConvertEventTypeToWireFormat(CastLoggingEvent event) { 369 uint8_t ConvertEventTypeToWireFormat(CastLoggingEvent event) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 int64_t ntp_time_us = 448 int64_t ntp_time_us =
448 ntp_seconds * base::Time::kMicrosecondsPerSecond + 449 ntp_seconds * base::Time::kMicrosecondsPerSecond +
449 static_cast<int64_t>(std::ceil(ntp_fractions / kMagicFractionalUnit)); 450 static_cast<int64_t>(std::ceil(ntp_fractions / kMagicFractionalUnit));
450 451
451 base::TimeDelta elapsed_since_unix_epoch = base::TimeDelta::FromMicroseconds( 452 base::TimeDelta elapsed_since_unix_epoch = base::TimeDelta::FromMicroseconds(
452 ntp_time_us - 453 ntp_time_us -
453 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); 454 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond));
454 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; 455 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch;
455 } 456 }
456 457
458 namespace {
459 enum {
460 // Minimum number of bytes required to make a valid RTCP packet.
461 kMinLengthOfRtcp = 8,
462 };
463 } // namespace
464
465 bool IsRtcpPacket(const uint8_t* packet, size_t length) {
466 if (length < kMinLengthOfRtcp) {
467 LOG(ERROR) << "Invalid RTCP packet received.";
468 return false;
469 }
470
471 uint8_t packet_type = packet[1];
472 return packet_type >= kPacketTypeLow && packet_type <= kPacketTypeHigh;
473 }
474
475 uint32_t GetSsrcOfSender(const uint8_t* rtcp_buffer, size_t length) {
476 if (length < kMinLengthOfRtcp)
477 return 0;
478 uint32_t ssrc_of_sender;
479 base::BigEndianReader big_endian_reader(
480 reinterpret_cast<const char*>(rtcp_buffer), length);
481 big_endian_reader.Skip(4); // Skip header.
482 big_endian_reader.ReadU32(&ssrc_of_sender);
483 return ssrc_of_sender;
484 }
485
457 } // namespace cast 486 } // namespace cast
458 } // namespace media 487 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/net/rtcp/rtcp_utility.h ('k') | media/cast/net/rtcp/sender_rtcp_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698