summaryrefslogtreecommitdiffstats
path: root/chromium/media/cast/cast_defines.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/media/cast/cast_defines.h')
-rw-r--r--chromium/media/cast/cast_defines.h111
1 files changed, 74 insertions, 37 deletions
diff --git a/chromium/media/cast/cast_defines.h b/chromium/media/cast/cast_defines.h
index aad7ae2b1d8..64b20c96da6 100644
--- a/chromium/media/cast/cast_defines.h
+++ b/chromium/media/cast/cast_defines.h
@@ -5,6 +5,8 @@
#ifndef MEDIA_CAST_CAST_DEFINES_H_
#define MEDIA_CAST_CAST_DEFINES_H_
+#include <stdint.h>
+
#include <map>
#include <set>
@@ -12,6 +14,7 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/time/time.h"
+#include "media/cast/transport/cast_transport_config.h"
namespace media {
namespace cast {
@@ -19,16 +22,33 @@ namespace cast {
const int64 kDontShowTimeoutMs = 33;
const float kDefaultCongestionControlBackOff = 0.875f;
const uint32 kVideoFrequency = 90000;
-const int64 kSkippedFramesCheckPeriodkMs = 10000;
-const uint32 kStartFrameId = GG_UINT32_C(0xffffffff);
+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.
+const int kMaxUnackedFrames = 255;
-// Number of skipped frames threshold in fps (as configured) per period above.
-const int kSkippedFramesThreshold = 3;
-const size_t kIpPacketSize = 1500;
+const size_t kMaxIpPacketSize = 1500;
const int kStartRttMs = 20;
const int64 kCastMessageUpdateIntervalMs = 33;
const int64 kNackRepeatIntervalMs = 30;
+enum CastInitializationStatus {
+ STATUS_AUDIO_UNINITIALIZED,
+ STATUS_VIDEO_UNINITIALIZED,
+ STATUS_AUDIO_INITIALIZED,
+ STATUS_VIDEO_INITIALIZED,
+ STATUS_INVALID_CAST_ENVIRONMENT,
+ STATUS_INVALID_CRYPTO_CONFIGURATION,
+ STATUS_UNSUPPORTED_AUDIO_CODEC,
+ STATUS_UNSUPPORTED_VIDEO_CODEC,
+ STATUS_INVALID_AUDIO_CONFIGURATION,
+ STATUS_INVALID_VIDEO_CONFIGURATION,
+ STATUS_GPU_ACCELERATION_NOT_SUPPORTED,
+ STATUS_GPU_ACCELERATION_ERROR,
+};
+
enum DefaultSettings {
kDefaultAudioEncoderBitrate = 0, // This means "auto," and may mean VBR.
kDefaultAudioSamplingRate = 48000,
@@ -41,17 +61,29 @@ enum DefaultSettings {
kDefaultRtpMaxDelayMs = 100,
};
+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;
-const size_t kAesBlockSize = 16;
-const size_t kAesKeySize = 16;
-
// 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;
@@ -62,20 +94,26 @@ typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
// 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 = GG_INT64_C(2208988800);
+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;
+
inline bool IsNewerFrameId(uint32 frame_id, uint32 prev_frame_id) {
return (frame_id != prev_frame_id) &&
- static_cast<uint32>(frame_id - prev_frame_id) < 0x80000000;
+ static_cast<uint32>(frame_id - prev_frame_id) < 0x80000000;
}
inline bool IsNewerRtpTimestamp(uint32 timestamp, uint32 prev_timestamp) {
return (timestamp != prev_timestamp) &&
- static_cast<uint32>(timestamp - prev_timestamp) < 0x80000000;
+ static_cast<uint32>(timestamp - prev_timestamp) < 0x80000000;
}
inline bool IsOlderFrameId(uint32 frame_id, uint32 prev_frame_id) {
@@ -84,7 +122,7 @@ inline bool IsOlderFrameId(uint32 frame_id, uint32 prev_frame_id) {
inline bool IsNewerPacketId(uint16 packet_id, uint16 prev_packet_id) {
return (packet_id != prev_packet_id) &&
- static_cast<uint16>(packet_id - prev_packet_id) < 0x8000;
+ static_cast<uint16>(packet_id - prev_packet_id) < 0x8000;
}
inline bool IsNewerSequenceNumber(uint16 sequence_number,
@@ -107,13 +145,22 @@ inline base::TimeDelta ConvertFromNtpDiff(uint32 ntp_delay) {
return base::TimeDelta::FromMilliseconds(delay_ms);
}
-inline void ConvertTimeToFractions(int64 time_us,
+inline void ConvertTimeToFractions(int64 ntp_time_us,
uint32* seconds,
uint32* fractions) {
- DCHECK_GE(time_us, 0) << "Time must NOT be negative";
- *seconds = static_cast<uint32>(time_us / base::Time::kMicrosecondsPerSecond);
+ 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>(
- (time_us % base::Time::kMicrosecondsPerSecond) * kMagicFractionalUnit);
+ (ntp_time_us % base::Time::kMicrosecondsPerSecond) *
+ kMagicFractionalUnit);
}
inline void ConvertTimeTicksToNtp(const base::TimeTicks& time,
@@ -122,7 +169,8 @@ inline void ConvertTimeTicksToNtp(const base::TimeTicks& time,
base::TimeDelta elapsed_since_unix_epoch =
time - base::TimeTicks::UnixEpoch();
- int64 ntp_time_us = elapsed_since_unix_epoch.InMicroseconds() +
+ int64 ntp_time_us =
+ elapsed_since_unix_epoch.InMicroseconds() +
(kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond);
ConvertTimeToFractions(ntp_time_us, ntp_seconds, ntp_fractions);
@@ -130,30 +178,19 @@ inline void ConvertTimeTicksToNtp(const base::TimeTicks& time,
inline base::TimeTicks ConvertNtpToTimeTicks(uint32 ntp_seconds,
uint32 ntp_fractions) {
- int64 ntp_time_us = static_cast<int64>(ntp_seconds) *
- base::Time::kMicrosecondsPerSecond +
- static_cast<int64>(ntp_fractions) / kMagicFractionalUnit;
+ int64 ntp_time_us =
+ static_cast<int64>(ntp_seconds) * base::Time::kMicrosecondsPerSecond +
+ static_cast<int64>(ntp_fractions) / kMagicFractionalUnit;
- base::TimeDelta elapsed_since_unix_epoch =
- base::TimeDelta::FromMicroseconds(ntp_time_us -
- (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond));
+ 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 std::string GetAesNonce(uint32 frame_id, const std::string& iv_mask) {
- std::string aes_nonce(kAesBlockSize, 0);
-
- // Serializing frame_id in big-endian order (aes_nonce[8] is the most
- // significant byte of frame_id).
- aes_nonce[11] = frame_id & 0xff;
- aes_nonce[10] = (frame_id >> 8) & 0xff;
- aes_nonce[9] = (frame_id >> 16) & 0xff;
- aes_nonce[8] = (frame_id >> 24) & 0xff;
-
- for (size_t i = 0; i < kAesBlockSize; ++i) {
- aes_nonce[i] ^= iv_mask[i];
- }
- return aes_nonce;
+inline base::TimeDelta RtpDeltaToTimeDelta(int64 rtp_delta, int rtp_timebase) {
+ DCHECK_GT(rtp_timebase, 0);
+ return rtp_delta * base::TimeDelta::FromSeconds(1) / rtp_timebase;
}
inline uint32 GetVideoRtpTimestamp(const base::TimeTicks& time_ticks) {