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

Side by Side Diff: media/cast/cast_defines.h

Issue 34623008: Change to calculate the real NTP in TimeTicks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 2 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 #ifndef MEDIA_CAST_CAST_DEFINES_H_ 5 #ifndef MEDIA_CAST_CAST_DEFINES_H_
6 #define MEDIA_CAST_CAST_DEFINES_H_ 6 #define MEDIA_CAST_CAST_DEFINES_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // Each uint8 represents one cast frame. 51 // Each uint8 represents one cast frame.
52 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap; 52 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
53 53
54 // TODO(pwestin): Re-factor the functions bellow into a class with static 54 // TODO(pwestin): Re-factor the functions bellow into a class with static
55 // methods. 55 // methods.
56 56
57 // Magic fractional unit. Used to convert time (in microseconds) to/from 57 // Magic fractional unit. Used to convert time (in microseconds) to/from
58 // fractional NTP seconds. 58 // fractional NTP seconds.
59 static const double kMagicFractionalUnit = 4.294967296E3; 59 static const double kMagicFractionalUnit = 4.294967296E3;
60 60
61 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on
62 // 1 January 1900.
63 static const int64 kNtpEpochDeltaSeconds = GG_INT64_C(9435484800);
64 static const int64 kNtpEpochDeltaMicroseconds =
65 kNtpEpochDeltaSeconds * base::Time::kMicrosecondsPerSecond;
66
67 inline bool IsNewerFrameId(uint8 frame_id, uint8 prev_frame_id) { 61 inline bool IsNewerFrameId(uint8 frame_id, uint8 prev_frame_id) {
68 return (frame_id != prev_frame_id) && 62 return (frame_id != prev_frame_id) &&
69 static_cast<uint8>(frame_id - prev_frame_id) < 0x80; 63 static_cast<uint8>(frame_id - prev_frame_id) < 0x80;
70 } 64 }
71 65
72 inline bool IsOlderFrameId(uint8 frame_id, uint8 prev_frame_id) { 66 inline bool IsOlderFrameId(uint8 frame_id, uint8 prev_frame_id) {
73 return (frame_id == prev_frame_id) || IsNewerFrameId(prev_frame_id, frame_id); 67 return (frame_id == prev_frame_id) || IsNewerFrameId(prev_frame_id, frame_id);
74 } 68 }
75 69
76 inline bool IsNewerPacketId(uint16 packet_id, uint16 prev_packet_id) { 70 inline bool IsNewerPacketId(uint16 packet_id, uint16 prev_packet_id) {
(...skipping 26 matching lines...) Expand all
103 uint32* fractions) { 97 uint32* fractions) {
104 DCHECK_GE(time_us, 0) << "Time must NOT be negative"; 98 DCHECK_GE(time_us, 0) << "Time must NOT be negative";
105 *seconds = static_cast<uint32>(time_us / base::Time::kMicrosecondsPerSecond); 99 *seconds = static_cast<uint32>(time_us / base::Time::kMicrosecondsPerSecond);
106 *fractions = static_cast<uint32>( 100 *fractions = static_cast<uint32>(
107 (time_us % base::Time::kMicrosecondsPerSecond) * kMagicFractionalUnit); 101 (time_us % base::Time::kMicrosecondsPerSecond) * kMagicFractionalUnit);
108 } 102 }
109 103
110 inline void ConvertTimeToNtp(const base::TimeTicks& time, 104 inline void ConvertTimeToNtp(const base::TimeTicks& time,
111 uint32* ntp_seconds, 105 uint32* ntp_seconds,
112 uint32* ntp_fractions) { 106 uint32* ntp_fractions) {
113 int64 time_us = time.ToInternalValue() - kNtpEpochDeltaMicroseconds; 107 int64 time_us = time.ToInternalValue();
miu 2013/10/23 18:24:02 IMHO, it's much cleaner to work with only one time
pwestin 2013/10/23 21:07:49 Removed this function since it did not provide any
114 ConvertTimeToFractions(time_us, ntp_seconds, ntp_fractions); 108 ConvertTimeToFractions(time_us, ntp_seconds, ntp_fractions);
115 } 109 }
116 110
117 inline base::TimeTicks ConvertNtpToTime(uint32 ntp_seconds, 111 inline base::TimeTicks ConvertNtpToTime(uint32 ntp_seconds,
118 uint32 ntp_fractions) { 112 uint32 ntp_fractions) {
119 int64 ntp_time_us = static_cast<int64>(ntp_seconds) * 113 int64 ntp_time_us = static_cast<int64>(ntp_seconds) *
120 base::Time::kMicrosecondsPerSecond; 114 base::Time::kMicrosecondsPerSecond;
121 ntp_time_us += static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; 115 ntp_time_us += static_cast<int64>(ntp_fractions) / kMagicFractionalUnit;
122 return base::TimeTicks::FromInternalValue(ntp_time_us + 116 return base::TimeTicks::FromInternalValue(ntp_time_us);
123 kNtpEpochDeltaMicroseconds);
124 } 117 }
125 118
126 } // namespace cast 119 } // namespace cast
127 } // namespace media 120 } // namespace media
128 121
129 #endif // MEDIA_CAST_CAST_DEFINES_H_ 122 #endif // MEDIA_CAST_CAST_DEFINES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698