diff options
Diffstat (limited to 'media/cast')
64 files changed, 381 insertions, 310 deletions
diff --git a/media/cast/BUILD.gn b/media/cast/BUILD.gn index 59fb7f8..51d9783 100644 --- a/media/cast/BUILD.gn +++ b/media/cast/BUILD.gn @@ -26,6 +26,7 @@ source_set("common") { "common/clock_drift_smoother.h", "common/transport_encryption_handler.cc", "common/transport_encryption_handler.h", + "constants.h", "logging/encoding_event_subscriber.cc", "logging/encoding_event_subscriber.h", "logging/log_deserializer.cc", diff --git a/media/cast/cast.gyp b/media/cast/cast.gyp index 213ee9b..bdd2bd2 100644 --- a/media/cast/cast.gyp +++ b/media/cast/cast.gyp @@ -40,6 +40,7 @@ 'common/clock_drift_smoother.h', 'common/transport_encryption_handler.cc', 'common/transport_encryption_handler.h', + 'constants.h', 'logging/encoding_event_subscriber.cc', 'logging/encoding_event_subscriber.h', 'logging/log_deserializer.cc', diff --git a/media/cast/cast_config.cc b/media/cast/cast_config.cc index d251016b..4004807 100644 --- a/media/cast/cast_config.cc +++ b/media/cast/cast_config.cc @@ -5,7 +5,19 @@ #include "media/cast/cast_config.h" namespace { + const float kDefaultCongestionControlBackOff = 0.875f; + +enum { + // Minimum and Maximum VP8 quantizer in default configuration. + kDefaultMaxQp = 63, + kDefaultMinQp = 4, + + // Number of video buffers in default configuration (applies only to certain + // external codecs). + kDefaultNumberOfVideoBuffers = 1, +}; + } // namespace namespace media { @@ -33,9 +45,9 @@ VideoSenderConfig::VideoSenderConfig() rtp_payload_type(0), use_external_encoder(false), congestion_control_back_off(kDefaultCongestionControlBackOff), - max_bitrate(5000000), - min_bitrate(1000000), - start_bitrate(5000000), + max_bitrate(kDefaultMaxVideoKbps * 1000), + min_bitrate(kDefaultMinVideoKbps * 1000), + start_bitrate(kDefaultMaxVideoKbps * 1000), max_qp(kDefaultMaxQp), min_qp(kDefaultMinQp), max_frame_rate(kDefaultMaxFrameRate), @@ -54,7 +66,7 @@ AudioSenderConfig::AudioSenderConfig() use_external_encoder(false), frequency(0), channels(0), - bitrate(0), + bitrate(kDefaultAudioEncoderBitrate), codec(CODEC_AUDIO_OPUS) {} AudioSenderConfig::~AudioSenderConfig() {} diff --git a/media/cast/cast_config.h b/media/cast/cast_config.h index f352186..6e6b283 100644 --- a/media/cast/cast_config.h +++ b/media/cast/cast_config.h @@ -5,9 +5,7 @@ #ifndef MEDIA_CAST_CAST_CONFIG_H_ #define MEDIA_CAST_CAST_CONFIG_H_ -#include <list> #include <string> -#include <vector> #include "base/basictypes.h" #include "base/callback.h" @@ -15,7 +13,6 @@ #include "base/memory/shared_memory.h" #include "base/single_thread_task_runner.h" #include "base/time/time.h" -#include "media/cast/cast_defines.h" #include "media/cast/net/cast_transport_config.h" namespace media { @@ -23,8 +20,41 @@ class VideoEncodeAccelerator; namespace cast { +// TODO(miu): Eliminate these after moving "default config" into the top-level +// media/cast directory. http://crbug.com/530839 +enum SuggestedDefaults { + // Audio encoder bitrate. Zero means "auto," which asks the encoder to select + // a bitrate that dynamically adjusts to the content. Otherwise, a constant + // bitrate is used. + kDefaultAudioEncoderBitrate = 0, + + // Suggested default audio sampling rate. + kDefaultAudioSamplingRate = 48000, + + // Suggested default maximum video frame rate. + kDefaultMaxFrameRate = 30, + + // End-to-end latency in milliseconds. + // + // DO NOT USE THIS (400 ms is proven as ideal for general-purpose use). + // + // TODO(miu): Change to 400, and confirm nothing has broken in later change. + // http://crbug.com/530839 + kDefaultRtpMaxDelayMs = 100, + + // RTP payload types that identify an RTP stream as audio or video. + kDefaultRtpAudioPayloadType = 127, + kDefaultRtpVideoPayloadType = 96, + + // Suggested minimum and maximum video bitrates for general-purpose use (up to + // 1080p, 30 FPS). + kDefaultMinVideoKbps = 300, + kDefaultMaxVideoKbps = 5000, +}; + // TODO(miu): Merge AudioSenderConfig and VideoSenderConfig and make their // naming/documentation consistent with FrameReceiverConfig. +// http://crbug.com/530839 struct AudioSenderConfig { AudioSenderConfig(); ~AudioSenderConfig(); @@ -159,23 +189,12 @@ struct FrameReceiverConfig { std::string aes_iv_mask; }; -// Import from media::cast. - -typedef Packet Packet; -typedef PacketList PacketList; - -// Callback that is run to update the client with current status. This is used -// to allow the client to wait for asynchronous initialization to complete -// before sending frames, and also to be notified of any runtime errors that -// have halted the session. -typedef base::Callback<void(OperationalStatus)> StatusChangeCallback; - +// TODO(miu): Remove the CreateVEA callbacks. http://crbug.com/454029 typedef base::Callback<void(scoped_refptr<base::SingleThreadTaskRunner>, scoped_ptr<media::VideoEncodeAccelerator>)> ReceiveVideoEncodeAcceleratorCallback; typedef base::Callback<void(const ReceiveVideoEncodeAcceleratorCallback&)> CreateVideoEncodeAcceleratorCallback; - typedef base::Callback<void(scoped_ptr<base::SharedMemory>)> ReceiveVideoEncodeMemoryCallback; typedef base::Callback<void(size_t size, diff --git a/media/cast/cast_defines.h b/media/cast/cast_defines.h index 11a1bfd..6860797 100644 --- a/media/cast/cast_defines.h +++ b/media/cast/cast_defines.h @@ -5,125 +5,13 @@ #ifndef MEDIA_CAST_CAST_DEFINES_H_ #define MEDIA_CAST_CAST_DEFINES_H_ -#include <stdint.h> - -#include <cmath> -#include <map> -#include <set> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/logging.h" #include "base/time/time.h" -#include "media/cast/net/cast_transport_config.h" namespace media { namespace cast { -const uint32 kVideoFrequency = 90000; -const int kMinSampleRateForEncoding = 8000; -const uint32 kStartFrameId = UINT32_C(0xffffffff); - -// This is an important system-wide constant. This limits how much history the -// implementation must retain in order to process the acknowledgements of past -// frames. -// This value is carefully choosen such that it fits in the 8-bits range for -// frame IDs. It is also less than half of the full 8-bits range such that we -// can handle wrap around and compare two frame IDs. -const int kMaxUnackedFrames = 120; - -const int64 kCastMessageUpdateIntervalMs = 33; -const int64 kNackRepeatIntervalMs = 30; - -// Success/in-progress/failure status codes bubbled up to clients via -// StatusChangeCallbacks. -enum OperationalStatus { - // Client should not send frames yet (sender), or should not expect to receive - // frames yet (receiver). - STATUS_UNINITIALIZED, - - // Client may now send or receive frames. - STATUS_INITIALIZED, - - // Codec is being re-initialized. Client may continue sending frames, but - // some may be ignored/dropped until a transition back to STATUS_INITIALIZED. - STATUS_CODEC_REINIT_PENDING, - - // Session has halted due to invalid configuration. - STATUS_INVALID_CONFIGURATION, - - // Session has halted due to an unsupported codec. - STATUS_UNSUPPORTED_CODEC, - - // Session has halted due to a codec initialization failure. Note that this - // can be reported after STATUS_INITIALIZED/STATUS_CODEC_REINIT_PENDING if the - // codec was re-initialized during the session. - STATUS_CODEC_INIT_FAILED, - - // Session has halted due to a codec runtime failure. - STATUS_CODEC_RUNTIME_ERROR, -}; - -enum DefaultSettings { - kDefaultAudioEncoderBitrate = 0, // This means "auto," and may mean VBR. - kDefaultAudioSamplingRate = 48000, - kDefaultMaxQp = 63, - kDefaultMinQp = 4, - kDefaultMaxFrameRate = 30, - kDefaultNumberOfVideoBuffers = 1, - kDefaultRtcpIntervalMs = 500, - kDefaultRtpHistoryMs = 1000, - kDefaultRtpMaxDelayMs = 100, - kDefaultRtpAudioPayloadType = 127, - kDefaultRtpVideoPayloadType = 96, - kDefaultMinVideoBitRate = 50, - kDefaultMaxVideoBitRate = 2000, -}; - -enum PacketType { - kNewPacket, - kNewPacketCompletingFrame, - kDuplicatePacket, - kTooOldPacket, -}; - -// kRtcpCastAllPacketsLost is used in PacketIDSet and -// on the wire to mean that ALL packets for a particular -// frame are lost. -const uint16 kRtcpCastAllPacketsLost = 0xffff; - -// kRtcpCastLastPacket is used in PacketIDSet to ask for -// the last packet of a frame to be retransmitted. -const uint16 kRtcpCastLastPacket = 0xfffe; - -const size_t kMinLengthOfRtcp = 8; - -// Basic RTP header + cast header. -const size_t kMinLengthOfRtp = 12 + 6; - -// Each uint16 represents one packet id within a cast frame. -// Can also contain kRtcpCastAllPacketsLost and kRtcpCastLastPacket. -typedef std::set<uint16> PacketIdSet; -// Each uint8 represents one cast frame. -typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap; - -// TODO(pwestin): Re-factor the functions bellow into a class with static -// methods. - -// January 1970, in NTP seconds. -// Network Time Protocol (NTP), which is in seconds relative to 0h UTC on -// 1 January 1900. -static const int64 kUnixEpochInNtpSeconds = INT64_C(2208988800); - -// Magic fractional unit. Used to convert time (in microseconds) to/from -// fractional NTP seconds. -static const double kMagicFractionalUnit = 4.294967296E3; - -// The maximum number of Cast receiver events to keep in history for the -// purpose of sending the events through RTCP. -// The number chosen should be more than the number of events that can be -// stored in a RTCP packet. -static const size_t kReceiverRtcpEventHistorySize = 512; +// TODO(miu): All remaining functions in this file are to be replaced with +// methods in well-defined data types. http://crbug.com/530839 inline bool IsNewerFrameId(uint32 frame_id, uint32 prev_frame_id) { return (frame_id != prev_frame_id) && @@ -150,64 +38,6 @@ inline bool IsNewerSequenceNumber(uint16 sequence_number, return IsNewerPacketId(sequence_number, prev_sequence_number); } -// Create a NTP diff from seconds and fractions of seconds; delay_fraction is -// fractions of a second where 0x80000000 is half a second. -inline uint32 ConvertToNtpDiff(uint32 delay_seconds, uint32 delay_fraction) { - return ((delay_seconds & 0x0000FFFF) << 16) + - ((delay_fraction & 0xFFFF0000) >> 16); -} - -inline base::TimeDelta ConvertFromNtpDiff(uint32 ntp_delay) { - uint32 delay_ms = (ntp_delay & 0x0000ffff) * 1000; - delay_ms >>= 16; - delay_ms += ((ntp_delay & 0xffff0000) >> 16) * 1000; - return base::TimeDelta::FromMilliseconds(delay_ms); -} - -inline void ConvertTimeToFractions(int64 ntp_time_us, - uint32* seconds, - uint32* fractions) { - DCHECK_GE(ntp_time_us, 0) << "Time must NOT be negative"; - const int64 seconds_component = - ntp_time_us / base::Time::kMicrosecondsPerSecond; - // NTP time will overflow in the year 2036. Also, make sure unit tests don't - // regress and use an origin past the year 2036. If this overflows here, the - // inverse calculation fails to compute the correct TimeTicks value, throwing - // off the entire system. - DCHECK_LT(seconds_component, INT64_C(4263431296)) - << "One year left to fix the NTP year 2036 wrap-around issue!"; - *seconds = static_cast<uint32>(seconds_component); - *fractions = static_cast<uint32>( - (ntp_time_us % base::Time::kMicrosecondsPerSecond) * - kMagicFractionalUnit); -} - -inline void ConvertTimeTicksToNtp(const base::TimeTicks& time, - uint32* ntp_seconds, - uint32* ntp_fractions) { - base::TimeDelta elapsed_since_unix_epoch = - time - base::TimeTicks::UnixEpoch(); - - int64 ntp_time_us = - elapsed_since_unix_epoch.InMicroseconds() + - (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond); - - ConvertTimeToFractions(ntp_time_us, ntp_seconds, ntp_fractions); -} - -inline base::TimeTicks ConvertNtpToTimeTicks(uint32 ntp_seconds, - uint32 ntp_fractions) { - // We need to ceil() here because the calculation of |fractions| in - // ConvertTimeToFractions() effectively does a floor(). - int64 ntp_time_us = ntp_seconds * base::Time::kMicrosecondsPerSecond + - static_cast<int64>(std::ceil(ntp_fractions / kMagicFractionalUnit)); - - base::TimeDelta elapsed_since_unix_epoch = base::TimeDelta::FromMicroseconds( - ntp_time_us - - (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); - return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; -} - inline base::TimeDelta RtpDeltaToTimeDelta(int64 rtp_delta, int rtp_timebase) { DCHECK_GT(rtp_timebase, 0); return rtp_delta * base::TimeDelta::FromSeconds(1) / rtp_timebase; diff --git a/media/cast/cast_sender.h b/media/cast/cast_sender.h index 7c68913..99d3c86 100644 --- a/media/cast/cast_sender.h +++ b/media/cast/cast_sender.h @@ -19,6 +19,7 @@ #include "media/base/audio_bus.h" #include "media/cast/cast_config.h" #include "media/cast/cast_environment.h" +#include "media/cast/constants.h" #include "media/cast/net/cast_transport_sender.h" namespace gfx { @@ -78,6 +79,12 @@ class AudioFrameInput : public base::RefCountedThreadSafe<AudioFrameInput> { friend class base::RefCountedThreadSafe<AudioFrameInput>; }; +// Callback that is run to update the client with current status. This is used +// to allow the client to wait for asynchronous initialization to complete +// before sending frames, and also to be notified of any runtime errors that +// have halted the session. +using StatusChangeCallback = base::Callback<void(OperationalStatus)>; + // All methods of CastSender must be called on the main thread. // Provided CastTransportSender will also be called on the main thread. class CastSender { diff --git a/media/cast/cast_sender_impl.h b/media/cast/cast_sender_impl.h index 341bcbc..6ada926 100644 --- a/media/cast/cast_sender_impl.h +++ b/media/cast/cast_sender_impl.h @@ -6,8 +6,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "media/cast/cast_config.h" -#include "media/cast/cast_defines.h" #include "media/cast/cast_environment.h" #include "media/cast/cast_sender.h" #include "media/cast/sender/audio_sender.h" diff --git a/media/cast/constants.h b/media/cast/constants.h new file mode 100644 index 0000000..e4b8044 --- /dev/null +++ b/media/cast/constants.h @@ -0,0 +1,75 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MEDIA_CAST_CONSTANTS_H_ +#define MEDIA_CAST_CONSTANTS_H_ + +//////////////////////////////////////////////////////////////////////////////// +// NOTE: This file should only contain constants that are reasonably globally +// used (i.e., by many modules, and in all or nearly all subdirs). Do NOT add +// non-POD constants, functions, interfaces, or any logic to this module. +//////////////////////////////////////////////////////////////////////////////// + +#include <stdint.h> + +namespace media { +namespace cast { + +// The first frame ID in an RTP stream. +enum : uint32_t { kFirstFrameId = UINT32_C(0) }; + +// Integer constants set either by the Cast Streaming Protocol Spec or due to +// design limitations. +enum Specifications { + // Target number of milliseconds between the sending of RTCP reports. Both + // senders and receivers regularly send RTCP reports to their peer. + kRtcpReportIntervalMs = 500, + + // This is an important system-wide constant. This limits how much history + // the implementation must retain in order to process the acknowledgements of + // past frames. + // + // This value is carefully choosen such that it fits in the 8-bits range for + // frame IDs. It is also less than half of the full 8-bits range such that + // logic can handle wrap around and compare two frame IDs meaningfully. + kMaxUnackedFrames = 120, + + // The spec declares RTP timestamps must always have a timebase of 90000 ticks + // per second for video. + kVideoFrequency = 90000, +}; + +// Success/in-progress/failure status codes reported to clients to indicate +// readiness state. +enum OperationalStatus { + // Client should not send frames yet (sender), or should not expect to receive + // frames yet (receiver). + STATUS_UNINITIALIZED, + + // Client may now send or receive frames. + STATUS_INITIALIZED, + + // Codec is being re-initialized. Client may continue sending frames, but + // some may be ignored/dropped until a transition back to STATUS_INITIALIZED. + STATUS_CODEC_REINIT_PENDING, + + // Session has halted due to invalid configuration. + STATUS_INVALID_CONFIGURATION, + + // Session has halted due to an unsupported codec. + STATUS_UNSUPPORTED_CODEC, + + // Session has halted due to a codec initialization failure. Note that this + // can be reported after STATUS_INITIALIZED/STATUS_CODEC_REINIT_PENDING if the + // codec was re-initialized during the session. + STATUS_CODEC_INIT_FAILED, + + // Session has halted due to a codec runtime failure. + STATUS_CODEC_RUNTIME_ERROR, +}; + +} // namespace cast +} // namespace media + +#endif // MEDIA_CAST_CONSTANTS_H_ diff --git a/media/cast/net/DEPS b/media/cast/net/DEPS index 3fa74fa..adada95 100644 --- a/media/cast/net/DEPS +++ b/media/cast/net/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+media/cast/cast_defines.h", "+media/cast/cast_environment.h", "+media/cast/common", + "+media/cast/constants.h", "+media/cast/logging", "+media/cast/net", "+net", diff --git a/media/cast/net/cast_transport_config.h b/media/cast/net/cast_transport_config.h index dd94137..7cdeec9 100644 --- a/media/cast/net/cast_transport_config.h +++ b/media/cast/net/cast_transport_config.h @@ -6,12 +6,9 @@ #define MEDIA_CAST_NET_CAST_TRANSPORT_CONFIG_H_ #include <string> -#include <vector> #include "base/basictypes.h" #include "base/callback.h" -#include "base/memory/linked_ptr.h" -#include "base/memory/ref_counted.h" #include "base/stl_util.h" #include "media/cast/net/cast_transport_defines.h" @@ -122,10 +119,6 @@ struct EncodedFrame { std::string data; }; -typedef std::vector<uint8> Packet; -typedef scoped_refptr<base::RefCountedData<Packet> > PacketRef; -typedef std::vector<PacketRef> PacketList; - typedef base::Callback<void(scoped_ptr<Packet> packet)> PacketReceiverCallback; typedef base::Callback<bool(scoped_ptr<Packet> packet)> PacketReceiverCallbackWithStatus; diff --git a/media/cast/net/cast_transport_defines.h b/media/cast/net/cast_transport_defines.h index c8b9fc1..bdd5494 100644 --- a/media/cast/net/cast_transport_defines.h +++ b/media/cast/net/cast_transport_defines.h @@ -10,14 +10,16 @@ #include <map> #include <set> #include <string> +#include <vector> #include "base/basictypes.h" +#include "base/memory/ref_counted.h" #include "base/time/time.h" namespace media { namespace cast { -// TODO(mikhal): Implement and add more types. +// Enums used to indicate transport readiness state. enum CastTransportStatus { TRANSPORT_AUDIO_UNINITIALIZED = 0, TRANSPORT_VIDEO_UNINITIALIZED, @@ -28,38 +30,35 @@ enum CastTransportStatus { CAST_TRANSPORT_STATUS_LAST = TRANSPORT_SOCKET_ERROR }; +// kRtcpCastAllPacketsLost is used in PacketIDSet and +// on the wire to mean that ALL packets for a particular +// frame are lost. +const uint16_t kRtcpCastAllPacketsLost = 0xffff; + +// kRtcpCastLastPacket is used in PacketIDSet to ask for +// the last packet of a frame to be retransmitted. +const uint16_t kRtcpCastLastPacket = 0xfffe; + const size_t kMaxIpPacketSize = 1500; -// Each uint16 represents one packet id within a cast frame. -typedef std::set<uint16> PacketIdSet; -// Each uint8 represents one cast frame. -typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap; - -// Rtcp defines. - -enum RtcpPacketFields { - kPacketTypeLow = 194, // SMPTE time-code mapping. - kPacketTypeSenderReport = 200, - kPacketTypeReceiverReport = 201, - kPacketTypeApplicationDefined = 204, - kPacketTypeGenericRtpFeedback = 205, - kPacketTypePayloadSpecific = 206, - kPacketTypeXr = 207, - kPacketTypeHigh = 210, // Port Mapping. -}; // Each uint16 represents one packet id within a cast frame. -typedef std::set<uint16> PacketIdSet; +// Can also contain kRtcpCastAllPacketsLost and kRtcpCastLastPacket. +using PacketIdSet = std::set<uint16_t>; // Each uint8 represents one cast frame. -typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap; +using MissingFramesAndPacketsMap = std::map<uint8_t, PacketIdSet>; + +using Packet = std::vector<uint8_t>; +using PacketRef = scoped_refptr<base::RefCountedData<Packet>>; +using PacketList = std::vector<PacketRef>; class FrameIdWrapHelperTest; // TODO(miu): UGLY IN-LINE DEFINITION IN HEADER FILE! Move to appropriate -// location, separated into .h and .cc files. +// location, separated into .h and .cc files. http://crbug.com/530839 class FrameIdWrapHelper { public: - FrameIdWrapHelper() - : largest_frame_id_seen_(kStartFrameId) {} + explicit FrameIdWrapHelper(uint32_t start_frame_id) + : largest_frame_id_seen_(start_frame_id) {} uint32 MapTo32bitsFrameId(const uint8 over_the_wire_frame_id) { uint32 ret = (largest_frame_id_seen_ & ~0xff) | over_the_wire_frame_id; @@ -77,7 +76,6 @@ class FrameIdWrapHelper { private: friend class FrameIdWrapHelperTest; - static const uint32 kStartFrameId = UINT32_C(0xffffffff); uint32 largest_frame_id_seen_; diff --git a/media/cast/net/cast_transport_sender_impl_unittest.cc b/media/cast/net/cast_transport_sender_impl_unittest.cc index 9758f3e..fecf820 100644 --- a/media/cast/net/cast_transport_sender_impl_unittest.cc +++ b/media/cast/net/cast_transport_sender_impl_unittest.cc @@ -10,7 +10,6 @@ #include "base/memory/scoped_ptr.h" #include "base/test/simple_test_tick_clock.h" #include "base/values.h" -#include "media/cast/cast_config.h" #include "media/cast/net/cast_transport_config.h" #include "media/cast/net/cast_transport_sender_impl.h" #include "media/cast/net/rtcp/rtcp.h" diff --git a/media/cast/net/frame_id_wrap_helper_test.cc b/media/cast/net/frame_id_wrap_helper_test.cc index 499d7de..9be52bd 100644 --- a/media/cast/net/frame_id_wrap_helper_test.cc +++ b/media/cast/net/frame_id_wrap_helper_test.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include <gtest/gtest.h> -#include "media/cast/cast_defines.h" +#include "media/cast/constants.h" #include "media/cast/net/cast_transport_defines.h" namespace media { @@ -11,7 +11,7 @@ namespace cast { class FrameIdWrapHelperTest : public ::testing::Test { protected: - FrameIdWrapHelperTest() {} + FrameIdWrapHelperTest() : frame_id_wrap_helper_(kFirstFrameId - 1) {} ~FrameIdWrapHelperTest() override {} void RunOneTest(uint32 starting_point, int iterations) { @@ -39,7 +39,10 @@ class FrameIdWrapHelperTest : public ::testing::Test { }; TEST_F(FrameIdWrapHelperTest, FirstFrame) { - EXPECT_EQ(kStartFrameId, frame_id_wrap_helper_.MapTo32bitsFrameId(255u)); + uint32_t expected_frame_id = kFirstFrameId; + EXPECT_EQ(expected_frame_id, frame_id_wrap_helper_.MapTo32bitsFrameId(0u)); + --expected_frame_id; + EXPECT_EQ(expected_frame_id, frame_id_wrap_helper_.MapTo32bitsFrameId(255u)); } TEST_F(FrameIdWrapHelperTest, Rollover) { diff --git a/media/cast/net/rtcp/receiver_rtcp_event_subscriber.cc b/media/cast/net/rtcp/receiver_rtcp_event_subscriber.cc index c96b71f..6ada1e4 100644 --- a/media/cast/net/rtcp/receiver_rtcp_event_subscriber.cc +++ b/media/cast/net/rtcp/receiver_rtcp_event_subscriber.cc @@ -4,6 +4,7 @@ #include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h" +#include <algorithm> #include <utility> namespace media { diff --git a/media/cast/net/rtcp/rtcp.cc b/media/cast/net/rtcp/rtcp.cc index 7b413d3..60f69656 100644 --- a/media/cast/net/rtcp/rtcp.cc +++ b/media/cast/net/rtcp/rtcp.cc @@ -4,9 +4,12 @@ #include "media/cast/net/rtcp/rtcp.h" -#include "media/cast/cast_config.h" -#include "media/cast/cast_defines.h" +#include <limits> + +#include "base/time/time.h" #include "media/cast/cast_environment.h" +#include "media/cast/constants.h" +#include "media/cast/net/cast_transport_config.h" #include "media/cast/net/cast_transport_defines.h" #include "media/cast/net/pacing/paced_sender.h" #include "media/cast/net/rtcp/rtcp_builder.h" @@ -18,14 +21,37 @@ using base::TimeDelta; namespace media { namespace cast { -static const int32 kStatsHistoryWindowMs = 10000; // 10 seconds. -// Reject packets that are older than 0.5 seconds older than -// the newest packet we've seen so far. This protect internal -// states from crazy routers. (Based on RRTR) -static const int32 kOutOfOrderMaxAgeMs = 500; - namespace { +enum { + kStatsHistoryWindowMs = 10000, // 10 seconds. + + // Reject packets that are older than 0.5 seconds older than + // the newest packet we've seen so far. This protects internal + // states from crazy routers. (Based on RRTR) + kOutOfOrderMaxAgeMs = 500, + + // Minimum number of bytes required to make a valid RTCP packet. + kMinLengthOfRtcp = 8, +}; + +// Create a NTP diff from seconds and fractions of seconds; delay_fraction is +// fractions of a second where 0x80000000 is half a second. +uint32_t ConvertToNtpDiff(uint32_t delay_seconds, uint32_t delay_fraction) { + return ((delay_seconds & 0x0000FFFF) << 16) + + ((delay_fraction & 0xFFFF0000) >> 16); +} + +// Parse a NTP diff value into a base::TimeDelta. +base::TimeDelta ConvertFromNtpDiff(uint32_t ntp_delay) { + int64_t delay_us = + (ntp_delay & 0x0000ffff) * base::Time::kMicrosecondsPerSecond; + delay_us >>= 16; + delay_us += + ((ntp_delay & 0xffff0000) >> 16) * base::Time::kMicrosecondsPerSecond; + return base::TimeDelta::FromMicroseconds(delay_us); +} + // A receiver frame event is identified by frame RTP timestamp, event timestamp // and event type. // A receiver packet event is identified by all of the above plus packet id. @@ -72,9 +98,9 @@ Rtcp::Rtcp(const RtcpCastMessageCallback& cast_callback, local_clock_ahead_by_(ClockDriftSmoother::GetDefaultTimeConstant()), lip_sync_rtp_timestamp_(0), lip_sync_ntp_timestamp_(0), - largest_seen_timestamp_( - base::TimeTicks::FromInternalValue(kint64min)) { -} + largest_seen_timestamp_(base::TimeTicks::FromInternalValue( + std::numeric_limits<int64_t>::min())), + ack_frame_id_wrap_helper_(kFirstFrameId - 1) {} Rtcp::~Rtcp() {} diff --git a/media/cast/net/rtcp/rtcp.h b/media/cast/net/rtcp/rtcp.h index 35608e0..7ddf62e 100644 --- a/media/cast/net/rtcp/rtcp.h +++ b/media/cast/net/rtcp/rtcp.h @@ -17,8 +17,6 @@ #include "base/memory/weak_ptr.h" #include "base/time/tick_clock.h" #include "base/time/time.h" -#include "media/cast/cast_config.h" -#include "media/cast/cast_defines.h" #include "media/cast/common/clock_drift_smoother.h" #include "media/cast/net/cast_transport_defines.h" #include "media/cast/net/cast_transport_sender.h" diff --git a/media/cast/net/rtcp/rtcp_builder.h b/media/cast/net/rtcp/rtcp_builder.h index 2f22c39..e6890d2 100644 --- a/media/cast/net/rtcp/rtcp_builder.h +++ b/media/cast/net/rtcp/rtcp_builder.h @@ -10,8 +10,7 @@ #include <string> #include "base/big_endian.h" -#include "media/cast/cast_config.h" -#include "media/cast/cast_defines.h" +#include "media/cast/net/cast_transport_config.h" #include "media/cast/net/cast_transport_defines.h" #include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h" #include "media/cast/net/rtcp/rtcp_defines.h" diff --git a/media/cast/net/rtcp/rtcp_builder_unittest.cc b/media/cast/net/rtcp/rtcp_builder_unittest.cc index 6bd9d05..63083ff 100644 --- a/media/cast/net/rtcp/rtcp_builder_unittest.cc +++ b/media/cast/net/rtcp/rtcp_builder_unittest.cc @@ -4,8 +4,8 @@ #include "base/memory/scoped_ptr.h" #include "base/test/simple_test_tick_clock.h" -#include "media/cast/cast_defines.h" #include "media/cast/cast_environment.h" +#include "media/cast/net/cast_transport_config.h" #include "media/cast/net/cast_transport_defines.h" #include "media/cast/net/pacing/paced_sender.h" #include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h" diff --git a/media/cast/net/rtcp/rtcp_defines.cc b/media/cast/net/rtcp/rtcp_defines.cc index f0ceef3..128682b 100644 --- a/media/cast/net/rtcp/rtcp_defines.cc +++ b/media/cast/net/rtcp/rtcp_defines.cc @@ -23,9 +23,6 @@ RtcpReceiverFrameLogMessage::RtcpReceiverFrameLogMessage(uint32 timestamp) : rtp_timestamp_(timestamp) {} RtcpReceiverFrameLogMessage::~RtcpReceiverFrameLogMessage() {} -RtcpNackMessage::RtcpNackMessage() : remote_ssrc(0u) {} -RtcpNackMessage::~RtcpNackMessage() {} - RtcpReceiverReferenceTimeReport::RtcpReceiverReferenceTimeReport() : remote_ssrc(0u), ntp_seconds(0u), ntp_fraction(0u) {} RtcpReceiverReferenceTimeReport::~RtcpReceiverReferenceTimeReport() {} diff --git a/media/cast/net/rtcp/rtcp_defines.h b/media/cast/net/rtcp/rtcp_defines.h index b35e14b..72fdc31 100644 --- a/media/cast/net/rtcp/rtcp_defines.h +++ b/media/cast/net/rtcp/rtcp_defines.h @@ -5,11 +5,10 @@ #ifndef MEDIA_CAST_RTCP_RTCP_DEFINES_H_ #define MEDIA_CAST_RTCP_RTCP_DEFINES_H_ -#include <map> -#include <set> +#include <list> -#include "media/cast/cast_config.h" -#include "media/cast/cast_defines.h" +#include "base/callback_forward.h" +#include "base/memory/scoped_ptr.h" #include "media/cast/logging/logging_defines.h" #include "media/cast/net/cast_transport_defines.h" @@ -20,6 +19,23 @@ static const size_t kRtcpCastLogHeaderSize = 12; static const size_t kRtcpReceiverFrameLogSize = 8; static const size_t kRtcpReceiverEventLogSize = 4; +// The maximum number of Cast receiver events to keep in history for the +// purpose of sending the events through RTCP. +// The number chosen should be more than the number of events that can be +// stored in a RTCP packet. +const size_t kReceiverRtcpEventHistorySize = 512; + +enum RtcpPacketFields { + kPacketTypeLow = 194, // SMPTE time-code mapping. + kPacketTypeSenderReport = 200, + kPacketTypeReceiverReport = 201, + kPacketTypeApplicationDefined = 204, + kPacketTypeGenericRtpFeedback = 205, + kPacketTypePayloadSpecific = 206, + kPacketTypeXr = 207, + kPacketTypeHigh = 210, // Port Mapping. +}; + // Handle the per frame ACK and NACK messages. struct RtcpCastMessage { explicit RtcpCastMessage(uint32 ssrc); @@ -59,16 +75,6 @@ struct RtcpReceiverFrameLogMessage { typedef std::list<RtcpReceiverFrameLogMessage> RtcpReceiverLogMessage; -struct RtcpNackMessage { - RtcpNackMessage(); - ~RtcpNackMessage(); - - uint32 remote_ssrc; - std::list<uint16> nack_list; - - DISALLOW_COPY_AND_ASSIGN(RtcpNackMessage); -}; - struct RtcpReceiverReferenceTimeReport { RtcpReceiverReferenceTimeReport(); ~RtcpReceiverReferenceTimeReport(); diff --git a/media/cast/net/rtcp/rtcp_unittest.cc b/media/cast/net/rtcp/rtcp_unittest.cc index ce6c3b2..88b7d45 100644 --- a/media/cast/net/rtcp/rtcp_unittest.cc +++ b/media/cast/net/rtcp/rtcp_unittest.cc @@ -7,10 +7,10 @@ #include "base/bind.h" #include "base/test/simple_test_tick_clock.h" -#include "media/cast/cast_defines.h" #include "media/cast/net/cast_transport_config.h" #include "media/cast/net/pacing/paced_sender.h" #include "media/cast/net/rtcp/rtcp.h" +#include "media/cast/net/rtcp/rtcp_utility.h" #include "media/cast/test/skewed_tick_clock.h" #include "testing/gmock/include/gmock/gmock.h" diff --git a/media/cast/net/rtcp/rtcp_utility.cc b/media/cast/net/rtcp/rtcp_utility.cc index 3cfb8ea..f299258 100644 --- a/media/cast/net/rtcp/rtcp_utility.cc +++ b/media/cast/net/rtcp/rtcp_utility.cc @@ -4,12 +4,26 @@ #include "media/cast/net/rtcp/rtcp_utility.h" +#include <cmath> + #include "base/logging.h" #include "media/cast/net/cast_transport_defines.h" namespace media { namespace cast { +namespace { + +// January 1970, in NTP seconds. +// Network Time Protocol (NTP), which is in seconds relative to 0h UTC on +// 1 January 1900. +const int64_t kUnixEpochInNtpSeconds = INT64_C(2208988800); + +// Magic fractional unit. Used to convert time (in microseconds) to/from +// fractional NTP seconds. +const double kMagicFractionalUnit = 4.294967296E3; +} + RtcpParser::RtcpParser(uint32 local_ssrc, uint32 remote_ssrc) : local_ssrc_(local_ssrc), remote_ssrc_(remote_ssrc), @@ -381,5 +395,50 @@ CastLoggingEvent TranslateToLogEventFromWireFormat(uint8 event) { } } +void ConvertTimeToFractions(int64_t ntp_time_us, + uint32_t* seconds, + uint32_t* fractions) { + DCHECK_GE(ntp_time_us, 0) << "Time must NOT be negative"; + const int64_t seconds_component = + ntp_time_us / base::Time::kMicrosecondsPerSecond; + // NTP time will overflow in the year 2036. Also, make sure unit tests don't + // regress and use an origin past the year 2036. If this overflows here, the + // inverse calculation fails to compute the correct TimeTicks value, throwing + // off the entire system. + DCHECK_LT(seconds_component, INT64_C(4263431296)) + << "One year left to fix the NTP year 2036 wrap-around issue!"; + *seconds = static_cast<uint32>(seconds_component); + *fractions = + static_cast<uint32>((ntp_time_us % base::Time::kMicrosecondsPerSecond) * + kMagicFractionalUnit); +} + +void ConvertTimeTicksToNtp(const base::TimeTicks& time, + uint32_t* ntp_seconds, + uint32_t* ntp_fractions) { + base::TimeDelta elapsed_since_unix_epoch = + time - base::TimeTicks::UnixEpoch(); + + int64_t ntp_time_us = + elapsed_since_unix_epoch.InMicroseconds() + + (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond); + + ConvertTimeToFractions(ntp_time_us, ntp_seconds, ntp_fractions); +} + +base::TimeTicks ConvertNtpToTimeTicks(uint32_t ntp_seconds, + uint32_t ntp_fractions) { + // We need to ceil() here because the calculation of |fractions| in + // ConvertTimeToFractions() effectively does a floor(). + int64_t ntp_time_us = + ntp_seconds * base::Time::kMicrosecondsPerSecond + + static_cast<int64_t>(std::ceil(ntp_fractions / kMagicFractionalUnit)); + + base::TimeDelta elapsed_since_unix_epoch = base::TimeDelta::FromMicroseconds( + ntp_time_us - + (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); + return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; +} + } // namespace cast } // namespace media diff --git a/media/cast/net/rtcp/rtcp_utility.h b/media/cast/net/rtcp/rtcp_utility.h index 8fd8edc..a0a2abff 100644 --- a/media/cast/net/rtcp/rtcp_utility.h +++ b/media/cast/net/rtcp/rtcp_utility.h @@ -6,9 +6,8 @@ #define MEDIA_CAST_RTCP_RTCP_UTILITY_H_ #include "base/big_endian.h" -#include "media/cast/cast_config.h" -#include "media/cast/cast_defines.h" #include "media/cast/logging/logging_defines.h" +#include "media/cast/net/cast_transport_config.h" #include "media/cast/net/rtcp/rtcp_defines.h" namespace media { @@ -115,6 +114,22 @@ uint8 ConvertEventTypeToWireFormat(CastLoggingEvent event); // The inverse of |ConvertEventTypeToWireFormat()|. CastLoggingEvent TranslateToLogEventFromWireFormat(uint8 event); +// Splits an NTP timestamp having a microsecond timebase into the standard two +// 32-bit integer wire format. +void ConvertTimeToFractions(int64_t ntp_time_us, + uint32_t* seconds, + uint32_t* fractions); + +// Maps a base::TimeTicks value to an NTP timestamp comprised of two components. +void ConvertTimeTicksToNtp(const base::TimeTicks& time, + uint32_t* ntp_seconds, + uint32_t* ntp_fractions); + +// Maps an NTP timestamp, comprised of two components, to a base::TimeTicks +// value. +base::TimeTicks ConvertNtpToTimeTicks(uint32_t ntp_seconds, + uint32_t ntp_fractions); + } // namespace cast } // namespace media diff --git a/media/cast/net/rtcp/test_rtcp_packet_builder.h b/media/cast/net/rtcp/test_rtcp_packet_builder.h index 3fab3b5..948f7a0 100644 --- a/media/cast/net/rtcp/test_rtcp_packet_builder.h +++ b/media/cast/net/rtcp/test_rtcp_packet_builder.h @@ -8,7 +8,6 @@ #define MEDIA_CAST_RTCP_TEST_RTCP_PACKET_BUILDER_H_ #include "base/big_endian.h" -#include "media/cast/cast_config.h" #include "media/cast/net/cast_transport_defines.h" #include "media/cast/net/rtcp/rtcp_defines.h" diff --git a/media/cast/net/rtp/cast_message_builder.cc b/media/cast/net/rtp/cast_message_builder.cc index 3d1d7a7..da851ee 100644 --- a/media/cast/net/rtp/cast_message_builder.cc +++ b/media/cast/net/rtp/cast_message_builder.cc @@ -5,11 +5,28 @@ #include "media/cast/net/rtp/cast_message_builder.h" #include "media/cast/cast_defines.h" +#include "media/cast/constants.h" #include "media/cast/net/rtp/framer.h" namespace media { namespace cast { +namespace { + +// TODO(miu): These should probably be dynamic and computed base on configured +// end-to-end latency and packet loss rates. http://crbug.com/563784 +enum { + // Number of milliseconds between sending of ACK/NACK Cast Message RTCP + // packets back to the sender. + kCastMessageUpdateIntervalMs = 33, + + // Number of milliseconds between repeating a NACK for packets in the same + // frame. + kNackRepeatIntervalMs = 30, +}; + +} // namespace + CastMessageBuilder::CastMessageBuilder( base::TickClock* clock, RtpPayloadFeedback* incoming_payload_feedback, @@ -26,8 +43,8 @@ CastMessageBuilder::CastMessageBuilder( cast_msg_(media_ssrc), slowing_down_ack_(false), acked_last_frame_(true), - last_acked_frame_id_(kStartFrameId) { - cast_msg_.ack_frame_id = kStartFrameId; + last_acked_frame_id_(kFirstFrameId - 1) { + cast_msg_.ack_frame_id = kFirstFrameId - 1; } CastMessageBuilder::~CastMessageBuilder() {} @@ -114,7 +131,7 @@ void CastMessageBuilder::UpdateCastMessage() { } void CastMessageBuilder::Reset() { - cast_msg_.ack_frame_id = kStartFrameId; + cast_msg_.ack_frame_id = kFirstFrameId - 1; cast_msg_.missing_frames_and_packets.clear(); time_last_nacked_map_.clear(); } diff --git a/media/cast/net/rtp/frame_buffer.h b/media/cast/net/rtp/frame_buffer.h index b7cd320..dedd82e 100644 --- a/media/cast/net/rtp/frame_buffer.h +++ b/media/cast/net/rtp/frame_buffer.h @@ -8,7 +8,7 @@ #include <map> #include <vector> -#include "media/cast/cast_config.h" +#include "media/cast/net/cast_transport_config.h" #include "media/cast/net/rtp/rtp_defines.h" namespace media { diff --git a/media/cast/net/rtp/framer.cc b/media/cast/net/rtp/framer.cc index e807e94..a79ce79 100644 --- a/media/cast/net/rtp/framer.cc +++ b/media/cast/net/rtp/framer.cc @@ -5,6 +5,8 @@ #include "media/cast/net/rtp/framer.h" #include "base/logging.h" +#include "media/cast/cast_defines.h" +#include "media/cast/constants.h" namespace media { namespace cast { @@ -25,8 +27,8 @@ Framer::Framer(base::TickClock* clock, decoder_faster_than_max_frame_rate, max_unacked_frames)), waiting_for_key_(true), - last_released_frame_(kStartFrameId), - newest_frame_id_(kStartFrameId) { + last_released_frame_(kFirstFrameId - 1), + newest_frame_id_(kFirstFrameId - 1) { DCHECK(incoming_payload_feedback) << "Invalid argument"; } @@ -117,8 +119,8 @@ void Framer::AckFrame(uint32 frame_id) { void Framer::Reset() { waiting_for_key_ = true; - last_released_frame_ = kStartFrameId; - newest_frame_id_ = kStartFrameId; + last_released_frame_ = kFirstFrameId - 1; + newest_frame_id_ = kFirstFrameId - 1; frames_.clear(); cast_msg_builder_->Reset(); } diff --git a/media/cast/net/rtp/packet_storage.cc b/media/cast/net/rtp/packet_storage.cc index 0408eb1..bd242e6 100644 --- a/media/cast/net/rtp/packet_storage.cc +++ b/media/cast/net/rtp/packet_storage.cc @@ -5,7 +5,7 @@ #include "media/cast/net/rtp/packet_storage.h" #include "base/logging.h" -#include "media/cast/cast_defines.h" +#include "media/cast/constants.h" namespace media { namespace cast { diff --git a/media/cast/net/rtp/packet_storage_unittest.cc b/media/cast/net/rtp/packet_storage_unittest.cc index ddebb7e..5407dbf 100644 --- a/media/cast/net/rtp/packet_storage_unittest.cc +++ b/media/cast/net/rtp/packet_storage_unittest.cc @@ -11,7 +11,7 @@ #include "base/test/simple_test_tick_clock.h" #include "base/time/time.h" -#include "media/cast/cast_defines.h" +#include "media/cast/constants.h" #include "testing/gmock/include/gmock/gmock.h" namespace media { diff --git a/media/cast/net/rtp/receiver_stats.cc b/media/cast/net/rtp/receiver_stats.cc index c9b386d..bceb8add 100644 --- a/media/cast/net/rtp/receiver_stats.cc +++ b/media/cast/net/rtp/receiver_stats.cc @@ -5,6 +5,7 @@ #include "media/cast/net/rtp/receiver_stats.h" #include "base/logging.h" +#include "media/cast/cast_defines.h" #include "media/cast/net/rtp/rtp_defines.h" namespace media { diff --git a/media/cast/net/rtp/rtp_packetizer_unittest.cc b/media/cast/net/rtp/rtp_packetizer_unittest.cc index 12cafd6..07eb419 100644 --- a/media/cast/net/rtp/rtp_packetizer_unittest.cc +++ b/media/cast/net/rtp/rtp_packetizer_unittest.cc @@ -120,7 +120,7 @@ class RtpPacketizerTest : public ::testing::Test { pacer_.get(), &packet_storage_, config_)); video_frame_.dependency = EncodedFrame::DEPENDENT; video_frame_.frame_id = 0; - video_frame_.referenced_frame_id = kStartFrameId; + video_frame_.referenced_frame_id = video_frame_.frame_id - 1; video_frame_.data.assign(kFrameSize, 123); video_frame_.rtp_timestamp = 0x0055aa11; } diff --git a/media/cast/net/rtp/rtp_parser.cc b/media/cast/net/rtp/rtp_parser.cc index b481764..a59aa99 100644 --- a/media/cast/net/rtp/rtp_parser.cc +++ b/media/cast/net/rtp/rtp_parser.cc @@ -6,7 +6,7 @@ #include "base/big_endian.h" #include "base/logging.h" -#include "media/cast/cast_defines.h" +#include "media/cast/constants.h" #include "media/cast/net/rtp/rtp_defines.h" namespace media { @@ -23,7 +23,8 @@ bool RtpParser::ParseSsrc(const uint8* packet, RtpParser::RtpParser(uint32 expected_sender_ssrc, uint8 expected_payload_type) : expected_sender_ssrc_(expected_sender_ssrc), - expected_payload_type_(expected_payload_type) {} + expected_payload_type_(expected_payload_type), + frame_id_wrap_helper_(kFirstFrameId - 1) {} RtpParser::~RtpParser() {} diff --git a/media/cast/net/rtp/rtp_sender.cc b/media/cast/net/rtp/rtp_sender.cc index 2ecabcb..f24f346 100644 --- a/media/cast/net/rtp/rtp_sender.cc +++ b/media/cast/net/rtp/rtp_sender.cc @@ -7,6 +7,7 @@ #include "base/big_endian.h" #include "base/logging.h" #include "base/rand_util.h" +#include "media/cast/constants.h" namespace media { namespace cast { diff --git a/media/cast/net/rtp/rtp_sender.h b/media/cast/net/rtp/rtp_sender.h index 6756581..32083d0 100644 --- a/media/cast/net/rtp/rtp_sender.h +++ b/media/cast/net/rtp/rtp_sender.h @@ -13,7 +13,6 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/time/time.h" -#include "media/cast/cast_config.h" #include "media/cast/cast_environment.h" #include "media/cast/net/cast_transport_defines.h" #include "media/cast/net/cast_transport_sender.h" diff --git a/media/cast/receiver/audio_decoder.cc b/media/cast/receiver/audio_decoder.cc index 929deb5..1956ace 100644 --- a/media/cast/receiver/audio_decoder.cc +++ b/media/cast/receiver/audio_decoder.cc @@ -9,7 +9,6 @@ #include "base/location.h" #include "base/logging.h" #include "base/sys_byteorder.h" -#include "media/cast/cast_defines.h" #include "third_party/opus/src/include/opus.h" namespace media { diff --git a/media/cast/receiver/audio_decoder.h b/media/cast/receiver/audio_decoder.h index a68b6fb..d437069 100644 --- a/media/cast/receiver/audio_decoder.h +++ b/media/cast/receiver/audio_decoder.h @@ -8,8 +8,8 @@ #include "base/callback.h" #include "base/memory/ref_counted.h" #include "media/base/audio_bus.h" -#include "media/cast/cast_config.h" #include "media/cast/cast_environment.h" +#include "media/cast/constants.h" #include "media/cast/net/cast_transport_config.h" namespace media { @@ -32,9 +32,9 @@ class AudioDecoder { Codec codec); virtual ~AudioDecoder(); - // Returns STATUS_INITIALIZED if the decoder was successfully constructed from - // the given FrameReceiverConfig. If this method returns any other value, - // calls to DecodeFrame() will not succeed. + // Returns STATUS_INITIALIZED if the decoder was successfully constructed. If + // this method returns any other value, calls to DecodeFrame() will not + // succeed. OperationalStatus InitializationResult() const; // Decode the payload in |encoded_frame| asynchronously. |callback| will be diff --git a/media/cast/receiver/cast_receiver_impl.h b/media/cast/receiver/cast_receiver_impl.h index 6cd6ba3..6a6592a 100644 --- a/media/cast/receiver/cast_receiver_impl.h +++ b/media/cast/receiver/cast_receiver_impl.h @@ -7,7 +7,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "media/cast/cast_config.h" #include "media/cast/cast_environment.h" #include "media/cast/cast_receiver.h" #include "media/cast/net/pacing/paced_sender.h" diff --git a/media/cast/receiver/frame_receiver.cc b/media/cast/receiver/frame_receiver.cc index 3d89594..b9d5a6e 100644 --- a/media/cast/receiver/frame_receiver.cc +++ b/media/cast/receiver/frame_receiver.cc @@ -10,7 +10,10 @@ #include "base/bind.h" #include "base/logging.h" #include "base/message_loop/message_loop.h" +#include "media/cast/cast_config.h" +#include "media/cast/cast_defines.h" #include "media/cast/cast_environment.h" +#include "media/cast/constants.h" namespace { const int kMinSchedulingDelayMs = 1; @@ -336,7 +339,7 @@ void FrameReceiver::ScheduleNextRtcpReport() { CastEnvironment::MAIN, FROM_HERE, base::Bind(&FrameReceiver::SendNextRtcpReport, weak_factory_.GetWeakPtr()), - base::TimeDelta::FromMilliseconds(kDefaultRtcpIntervalMs)); + base::TimeDelta::FromMilliseconds(kRtcpReportIntervalMs)); } void FrameReceiver::SendNextRtcpReport() { diff --git a/media/cast/receiver/frame_receiver.h b/media/cast/receiver/frame_receiver.h index 96f29f4..ec3175f 100644 --- a/media/cast/receiver/frame_receiver.h +++ b/media/cast/receiver/frame_receiver.h @@ -11,7 +11,6 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/time/time.h" -#include "media/cast/cast_config.h" #include "media/cast/cast_receiver.h" #include "media/cast/common/clock_drift_smoother.h" #include "media/cast/common/transport_encryption_handler.h" diff --git a/media/cast/receiver/frame_receiver_unittest.cc b/media/cast/receiver/frame_receiver_unittest.cc index 79a6ef2..6e6a3915 100644 --- a/media/cast/receiver/frame_receiver_unittest.cc +++ b/media/cast/receiver/frame_receiver_unittest.cc @@ -9,11 +9,11 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/test/simple_test_tick_clock.h" -#include "media/cast/cast_defines.h" #include "media/cast/cast_environment.h" #include "media/cast/logging/simple_event_subscriber.h" #include "media/cast/net/cast_transport_sender_impl.h" #include "media/cast/net/mock_cast_transport_sender.h" +#include "media/cast/net/rtcp/rtcp_utility.h" #include "media/cast/net/rtcp/test_rtcp_packet_builder.h" #include "media/cast/receiver/frame_receiver.h" #include "media/cast/test/fake_single_thread_task_runner.h" diff --git a/media/cast/receiver/video_decoder.cc b/media/cast/receiver/video_decoder.cc index dca038c..e942380 100644 --- a/media/cast/receiver/video_decoder.cc +++ b/media/cast/receiver/video_decoder.cc @@ -12,7 +12,6 @@ #include "base/values.h" #include "media/base/video_frame_pool.h" #include "media/base/video_util.h" -#include "media/cast/cast_defines.h" #include "media/cast/cast_environment.h" // VPX_CODEC_DISABLE_COMPAT excludes parts of the libvpx API that provide // backwards compatibility for legacy applications using the library. diff --git a/media/cast/receiver/video_decoder.h b/media/cast/receiver/video_decoder.h index 2b6c859..97dfa2a 100644 --- a/media/cast/receiver/video_decoder.h +++ b/media/cast/receiver/video_decoder.h @@ -9,7 +9,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "media/base/video_frame.h" -#include "media/cast/cast_config.h" +#include "media/cast/constants.h" #include "media/cast/net/cast_transport_config.h" namespace media { @@ -31,9 +31,9 @@ class VideoDecoder { Codec codec); virtual ~VideoDecoder(); - // Returns STATUS_INITIALIZED if the decoder was successfully constructed from - // the given FrameReceiverConfig. If this method returns any other value, - // calls to DecodeFrame() will not succeed. + // Returns STATUS_INITIALIZED if the decoder was successfully constructed. If + // this method returns any other value, calls to DecodeFrame() will not + // succeed. OperationalStatus InitializationResult() const; // Decode the payload in |encoded_frame| asynchronously. |callback| will be diff --git a/media/cast/sender/audio_encoder.cc b/media/cast/sender/audio_encoder.cc index 80d69fe9..bf18118 100644 --- a/media/cast/sender/audio_encoder.cc +++ b/media/cast/sender/audio_encoder.cc @@ -15,7 +15,6 @@ #include "base/sys_byteorder.h" #include "base/time/time.h" #include "base/trace_event/trace_event.h" -#include "media/cast/cast_defines.h" #if !defined(OS_IOS) #include "third_party/opus/src/include/opus.h" diff --git a/media/cast/sender/audio_encoder.h b/media/cast/sender/audio_encoder.h index aac20d7..4cb0315 100644 --- a/media/cast/sender/audio_encoder.h +++ b/media/cast/sender/audio_encoder.h @@ -9,8 +9,8 @@ #include "base/memory/scoped_ptr.h" #include "base/threading/thread_checker.h" #include "media/base/audio_bus.h" -#include "media/cast/cast_defines.h" #include "media/cast/cast_environment.h" +#include "media/cast/constants.h" #include "media/cast/sender/sender_encoded_frame.h" namespace base { diff --git a/media/cast/sender/audio_encoder_unittest.cc b/media/cast/sender/audio_encoder_unittest.cc index 5fd80f1..48ebdc1 100644 --- a/media/cast/sender/audio_encoder_unittest.cc +++ b/media/cast/sender/audio_encoder_unittest.cc @@ -12,6 +12,7 @@ #include "base/memory/scoped_ptr.h" #include "media/base/audio_bus.h" #include "media/base/media.h" +#include "media/cast/cast_config.h" #include "media/cast/cast_environment.h" #include "media/cast/sender/audio_encoder.h" #include "media/cast/test/fake_single_thread_task_runner.h" diff --git a/media/cast/sender/audio_sender.cc b/media/cast/sender/audio_sender.cc index 5126750..4d57d48 100644 --- a/media/cast/sender/audio_sender.cc +++ b/media/cast/sender/audio_sender.cc @@ -7,7 +7,6 @@ #include "base/bind.h" #include "base/logging.h" #include "base/message_loop/message_loop.h" -#include "media/cast/cast_defines.h" #include "media/cast/net/cast_transport_config.h" #include "media/cast/sender/audio_encoder.h" diff --git a/media/cast/sender/audio_sender.h b/media/cast/sender/audio_sender.h index aa45020..2991b03 100644 --- a/media/cast/sender/audio_sender.h +++ b/media/cast/sender/audio_sender.h @@ -14,6 +14,8 @@ #include "base/time/time.h" #include "media/base/audio_bus.h" #include "media/cast/cast_config.h" +#include "media/cast/cast_defines.h" +#include "media/cast/cast_sender.h" #include "media/cast/sender/frame_sender.h" namespace media { diff --git a/media/cast/sender/audio_sender_unittest.cc b/media/cast/sender/audio_sender_unittest.cc index 5596ee2..edbee2e 100644 --- a/media/cast/sender/audio_sender_unittest.cc +++ b/media/cast/sender/audio_sender_unittest.cc @@ -12,6 +12,7 @@ #include "media/base/media.h" #include "media/cast/cast_config.h" #include "media/cast/cast_environment.h" +#include "media/cast/constants.h" #include "media/cast/net/cast_transport_config.h" #include "media/cast/net/cast_transport_sender_impl.h" #include "media/cast/sender/audio_sender.h" @@ -150,7 +151,7 @@ TEST_F(AudioSenderTest, RtcpTimer) { // Make sure that we send at least one RTCP packet. base::TimeDelta max_rtcp_timeout = - base::TimeDelta::FromMilliseconds(1 + kDefaultRtcpIntervalMs * 3 / 2); + base::TimeDelta::FromMilliseconds(1 + kRtcpReportIntervalMs * 3 / 2); testing_clock_->Advance(max_rtcp_timeout); task_runner_->RunTasks(); EXPECT_LE(1, transport_.number_of_rtp_packets()); diff --git a/media/cast/sender/congestion_control.cc b/media/cast/sender/congestion_control.cc index 0b0aa25..0c37056 100644 --- a/media/cast/sender/congestion_control.cc +++ b/media/cast/sender/congestion_control.cc @@ -15,12 +15,13 @@ #include "media/cast/sender/congestion_control.h" +#include <algorithm> #include <deque> #include "base/logging.h" #include "base/trace_event/trace_event.h" -#include "media/cast/cast_config.h" #include "media/cast/cast_defines.h" +#include "media/cast/constants.h" namespace media { namespace cast { @@ -175,10 +176,9 @@ void AdaptiveCongestionControl::UpdateRtt(base::TimeDelta rtt) { void AdaptiveCongestionControl::UpdateTargetPlayoutDelay( base::TimeDelta delay) { - const int max_unacked_frames = - std::min(kMaxUnackedFrames, - 1 + static_cast<int>(delay * max_frame_rate_ / - base::TimeDelta::FromSeconds(1))); + const int max_unacked_frames = std::min<int>( + kMaxUnackedFrames, 1 + static_cast<int>(delay * max_frame_rate_ / + base::TimeDelta::FromSeconds(1))); DCHECK_GT(max_unacked_frames, 0); history_size_ = max_unacked_frames + kHistorySize; PruneFrameStats(); diff --git a/media/cast/sender/congestion_control_unittest.cc b/media/cast/sender/congestion_control_unittest.cc index 5293b58..b435b9a 100644 --- a/media/cast/sender/congestion_control_unittest.cc +++ b/media/cast/sender/congestion_control_unittest.cc @@ -6,7 +6,6 @@ #include "base/bind.h" #include "base/test/simple_test_tick_clock.h" -#include "media/cast/cast_defines.h" #include "media/cast/sender/congestion_control.h" #include "media/cast/test/fake_single_thread_task_runner.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/media/cast/sender/external_video_encoder.cc b/media/cast/sender/external_video_encoder.cc index 4b15b1a..11484c0 100644 --- a/media/cast/sender/external_video_encoder.cc +++ b/media/cast/sender/external_video_encoder.cc @@ -19,6 +19,7 @@ #include "media/base/video_frame.h" #include "media/base/video_types.h" #include "media/base/video_util.h" +#include "media/cast/cast_config.h" #include "media/cast/cast_defines.h" #include "media/cast/logging/logging_defines.h" #include "media/cast/net/cast_transport_config.h" diff --git a/media/cast/sender/external_video_encoder.h b/media/cast/sender/external_video_encoder.h index 73f5fed..23e50e5 100644 --- a/media/cast/sender/external_video_encoder.h +++ b/media/cast/sender/external_video_encoder.h @@ -7,7 +7,6 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "media/cast/cast_config.h" #include "media/cast/cast_environment.h" #include "media/cast/sender/size_adaptable_video_encoder_base.h" #include "media/cast/sender/video_encoder.h" diff --git a/media/cast/sender/fake_software_video_encoder.cc b/media/cast/sender/fake_software_video_encoder.cc index 88c6cf6..3c33152 100644 --- a/media/cast/sender/fake_software_video_encoder.cc +++ b/media/cast/sender/fake_software_video_encoder.cc @@ -7,6 +7,8 @@ #include "base/json/json_writer.h" #include "base/values.h" #include "media/base/video_frame.h" +#include "media/cast/cast_defines.h" +#include "media/cast/constants.h" #ifndef OFFICIAL_BUILD diff --git a/media/cast/sender/frame_sender.cc b/media/cast/sender/frame_sender.cc index e4936c8..44f505e 100644 --- a/media/cast/sender/frame_sender.cc +++ b/media/cast/sender/frame_sender.cc @@ -5,6 +5,8 @@ #include "media/cast/sender/frame_sender.h" #include "base/trace_event/trace_event.h" +#include "media/cast/cast_defines.h" +#include "media/cast/constants.h" #include "media/cast/sender/sender_encoded_frame.h" namespace media { @@ -66,7 +68,7 @@ void FrameSender::ScheduleNextRtcpReport() { CastEnvironment::MAIN, FROM_HERE, base::Bind(&FrameSender::SendRtcpReport, weak_factory_.GetWeakPtr(), true), - base::TimeDelta::FromMilliseconds(kDefaultRtcpIntervalMs)); + base::TimeDelta::FromMilliseconds(kRtcpReportIntervalMs)); } void FrameSender::SendRtcpReport(bool schedule_future_reports) { diff --git a/media/cast/sender/h264_vt_encoder.cc b/media/cast/sender/h264_vt_encoder.cc index 6185a63..c9f9330 100644 --- a/media/cast/sender/h264_vt_encoder.cc +++ b/media/cast/sender/h264_vt_encoder.cc @@ -17,6 +17,8 @@ #include "base/synchronization/lock.h" #include "media/base/mac/corevideo_glue.h" #include "media/base/mac/video_frame_mac.h" +#include "media/cast/cast_defines.h" +#include "media/cast/constants.h" #include "media/cast/sender/video_frame_factory.h" namespace media { @@ -320,7 +322,7 @@ H264VideoToolboxEncoder::H264VideoToolboxEncoder( videotoolbox_glue_(VideoToolboxGlue::Get()), video_config_(video_config), status_change_cb_(status_change_cb), - last_frame_id_(kStartFrameId), + last_frame_id_(kFirstFrameId - 1), encode_next_frame_as_keyframe_(false), power_suspended_(false), weak_factory_(this) { diff --git a/media/cast/sender/h264_vt_encoder_unittest.cc b/media/cast/sender/h264_vt_encoder_unittest.cc index ebdda907..19dd3d1 100644 --- a/media/cast/sender/h264_vt_encoder_unittest.cc +++ b/media/cast/sender/h264_vt_encoder_unittest.cc @@ -17,6 +17,8 @@ #include "media/base/media.h" #include "media/base/media_switches.h" #include "media/base/media_util.h" +#include "media/cast/cast_defines.h" +#include "media/cast/constants.h" #include "media/cast/sender/h264_vt_encoder.h" #include "media/cast/sender/video_frame_factory.h" #include "media/cast/test/utility/default_config.h" diff --git a/media/cast/sender/size_adaptable_video_encoder_base.cc b/media/cast/sender/size_adaptable_video_encoder_base.cc index b626760..733b50c 100644 --- a/media/cast/sender/size_adaptable_video_encoder_base.cc +++ b/media/cast/sender/size_adaptable_video_encoder_base.cc @@ -19,7 +19,7 @@ SizeAdaptableVideoEncoderBase::SizeAdaptableVideoEncoderBase( video_config_(video_config), status_change_cb_(status_change_cb), frames_in_encoder_(0), - last_frame_id_(kStartFrameId), + last_frame_id_(kFirstFrameId - 1), weak_factory_(this) { cast_environment_->PostTask( CastEnvironment::MAIN, diff --git a/media/cast/sender/size_adaptable_video_encoder_base.h b/media/cast/sender/size_adaptable_video_encoder_base.h index ee7e1fa..237e3ab 100644 --- a/media/cast/sender/size_adaptable_video_encoder_base.h +++ b/media/cast/sender/size_adaptable_video_encoder_base.h @@ -10,6 +10,7 @@ #include "base/memory/weak_ptr.h" #include "media/cast/cast_config.h" #include "media/cast/cast_environment.h" +#include "media/cast/constants.h" #include "media/cast/sender/video_encoder.h" #include "ui/gfx/geometry/size.h" diff --git a/media/cast/sender/video_encoder.h b/media/cast/sender/video_encoder.h index 1fba17a..3e01c40 100644 --- a/media/cast/sender/video_encoder.h +++ b/media/cast/sender/video_encoder.h @@ -12,6 +12,7 @@ #include "media/base/video_frame.h" #include "media/cast/cast_config.h" #include "media/cast/cast_environment.h" +#include "media/cast/cast_sender.h" #include "media/cast/sender/sender_encoded_frame.h" #include "media/cast/sender/video_frame_factory.h" diff --git a/media/cast/sender/video_encoder_impl.cc b/media/cast/sender/video_encoder_impl.cc index 5bc7f44..87776e5 100644 --- a/media/cast/sender/video_encoder_impl.cc +++ b/media/cast/sender/video_encoder_impl.cc @@ -10,7 +10,6 @@ #include "base/logging.h" #include "base/message_loop/message_loop.h" #include "media/base/video_frame.h" -#include "media/cast/cast_defines.h" #include "media/cast/sender/fake_software_video_encoder.h" #include "media/cast/sender/vp8_encoder.h" diff --git a/media/cast/sender/video_sender.h b/media/cast/sender/video_sender.h index a75bafb..ab31e7b 100644 --- a/media/cast/sender/video_sender.h +++ b/media/cast/sender/video_sender.h @@ -13,6 +13,7 @@ #include "base/time/tick_clock.h" #include "base/time/time.h" #include "media/cast/cast_config.h" +#include "media/cast/cast_sender.h" #include "media/cast/sender/congestion_control.h" #include "media/cast/sender/frame_sender.h" diff --git a/media/cast/sender/video_sender_unittest.cc b/media/cast/sender/video_sender_unittest.cc index 5655a0f..60f15a5 100644 --- a/media/cast/sender/video_sender_unittest.cc +++ b/media/cast/sender/video_sender_unittest.cc @@ -11,6 +11,7 @@ #include "base/test/simple_test_tick_clock.h" #include "media/base/video_frame.h" #include "media/cast/cast_environment.h" +#include "media/cast/constants.h" #include "media/cast/logging/simple_event_subscriber.h" #include "media/cast/net/cast_transport_config.h" #include "media/cast/net/cast_transport_sender_impl.h" @@ -339,7 +340,7 @@ TEST_F(VideoSenderTest, RtcpTimer) { // Make sure that we send at least one RTCP packet. base::TimeDelta max_rtcp_timeout = - base::TimeDelta::FromMilliseconds(1 + kDefaultRtcpIntervalMs * 3 / 2); + base::TimeDelta::FromMilliseconds(1 + kRtcpReportIntervalMs * 3 / 2); RunTasks(max_rtcp_timeout.InMilliseconds()); EXPECT_LE(1, transport_.number_of_rtp_packets()); diff --git a/media/cast/sender/vp8_encoder.cc b/media/cast/sender/vp8_encoder.cc index d586fa5..a7298e7 100644 --- a/media/cast/sender/vp8_encoder.cc +++ b/media/cast/sender/vp8_encoder.cc @@ -11,6 +11,7 @@ #include "base/strings/stringprintf.h" #include "media/base/video_frame.h" #include "media/cast/cast_defines.h" +#include "media/cast/constants.h" #include "third_party/libvpx_new/source/libvpx/vpx/vp8cx.h" namespace media { @@ -30,7 +31,7 @@ Vp8Encoder::Vp8Encoder(const VideoSenderConfig& video_config) : cast_config_(video_config), key_frame_requested_(true), bitrate_kbit_(cast_config_.start_bitrate / 1000), - last_encoded_frame_id_(kStartFrameId), + last_encoded_frame_id_(kFirstFrameId - 1), has_seen_zero_length_encoded_frame_(false) { config_.g_timebase.den = 0; // Not initialized. diff --git a/media/cast/test/utility/default_config.cc b/media/cast/test/utility/default_config.cc index b1b0cc2..9101705 100644 --- a/media/cast/test/utility/default_config.cc +++ b/media/cast/test/utility/default_config.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "media/cast/cast_config.h" +#include "media/cast/constants.h" #include "media/cast/net/cast_transport_config.h" namespace { |