1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_DEFINES_H_
6 #define MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_DEFINES_H_
12 #include "base/basictypes.h"
13 #include "base/time/time.h"
19 // TODO(mikhal): Implement and add more types.
20 enum CastTransportStatus {
21 TRANSPORT_UNINITIALIZED = 0,
22 TRANSPORT_INITIALIZED,
23 TRANSPORT_INVALID_CRYPTO_CONFIG,
24 TRANSPORT_SOCKET_ERROR
27 const size_t kMaxIpPacketSize = 1500;
28 // Each uint16 represents one packet id within a cast frame.
29 typedef std::set<uint16> PacketIdSet;
30 // Each uint8 represents one cast frame.
31 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
35 enum RtcpPacketTypes {
36 kPacketTypeLow = 194, // SMPTE time-code mapping.
37 kPacketTypeInterArrivalJitterReport = 195,
38 kPacketTypeSenderReport = 200,
39 kPacketTypeReceiverReport = 201,
40 kPacketTypeSdes = 202,
42 kPacketTypeApplicationDefined = 204,
43 kPacketTypeGenericRtpFeedback = 205,
44 kPacketTypePayloadSpecific = 206,
46 kPacketTypeHigh = 210, // Port Mapping.
49 // Each uint16 represents one packet id within a cast frame.
50 typedef std::set<uint16> PacketIdSet;
51 // Each uint8 represents one cast frame.
52 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
55 class FrameIdWrapHelper {
59 frame_id_wrap_count_(0),
62 uint32 MapTo32bitsFrameId(const uint8 over_the_wire_frame_id) {
65 if (over_the_wire_frame_id == 0xff) {
66 // Special case for startup.
71 uint32 wrap_count = frame_id_wrap_count_;
74 if (over_the_wire_frame_id > kLowRangeThreshold &&
75 over_the_wire_frame_id < kHighRangeThreshold) {
76 range_ = kMiddleRange;
78 if (over_the_wire_frame_id > kHighRangeThreshold) {
79 // Wrap count was incremented in High->Low transition, but this frame
80 // is 'old', actually from before the wrap count got incremented.
85 if (over_the_wire_frame_id > kHighRangeThreshold) {
90 if (over_the_wire_frame_id < kLowRangeThreshold) {
91 // Wrap-around detected.
93 ++frame_id_wrap_count_;
94 // Frame triggering wrap-around so wrap count should be incremented as
95 // as well to match |frame_id_wrap_count_|.
100 return (wrap_count << 8) + over_the_wire_frame_id;
110 static const uint8 kLowRangeThreshold = 0x0f;
111 static const uint8 kHighRangeThreshold = 0xf0;
112 static const uint32 kStartFrameId = GG_UINT32_C(0xffffffff);
115 uint32 frame_id_wrap_count_;
119 inline uint32 GetVideoRtpTimestamp(const base::TimeTicks& time_ticks) {
120 base::TimeTicks zero_time;
121 base::TimeDelta recorded_delta = time_ticks - zero_time;
122 // Timestamp is in 90 KHz for video.
123 return static_cast<uint32>(recorded_delta.InMilliseconds() * 90);
126 } // namespace transport
130 #endif // MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_DEFINES_H_