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

Side by Side Diff: media/cast/common/rtp_time.cc

Issue 1515433002: Replace uses of raw uint32's with a type-checked RtpTimeTicks data type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
(Empty)
1 // Copyright 2015 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.
4
5 #include "media/cast/common/rtp_time.h"
6
7 #include <limits>
8
9 namespace media {
10 namespace cast {
11
12 namespace {
13
14 // Returns the base::TimeDelta nearest to the time represented by a tick count
15 // in the given timebase.
16 base::TimeDelta TicksToTimeDelta(int64_t ticks, int timebase) {
17 DCHECK_GT(timebase, 0);
18 const double micros = static_cast<double>(ticks) / timebase *
19 base::Time::kMicrosecondsPerSecond +
20 0.5 /* rounding */;
Irfan 2015/12/09 21:24:28 nit: alignment ?
miu 2015/12/10 00:38:36 This is what `git cl format media` produced. ;-)
21 DCHECK_LT(micros, static_cast<double>(std::numeric_limits<int64_t>::max()));
22 return base::TimeDelta::FromMicroseconds(static_cast<int64_t>(micros));
23 }
24
25 // Returns the tick count in the given timebase nearest to the base::TimeDelta.
26 int64_t TimeDeltaToTicks(base::TimeDelta delta, int timebase) {
27 DCHECK_GT(timebase, 0);
28 const double ticks = delta.InSecondsF() * timebase + 0.5 /* rounding */;
29 DCHECK_LT(ticks, static_cast<double>(std::numeric_limits<int64_t>::max()));
30 return static_cast<int64_t>(ticks);
31 }
32
33 } // namespace
34
35 base::TimeDelta RtpTimeDelta::ToTimeDelta(int rtp_timebase) const {
36 return TicksToTimeDelta(value_, rtp_timebase);
37 }
38
39 void RtpTimeDelta::OutputToLog(std::ostream& out) const {
40 if (value_ >= 0)
41 out << "RTPd+";
42 else
43 out << "RTPd";
44 out << value_;
45 }
46
47 // static
48 RtpTimeDelta RtpTimeDelta::FromTimeDelta(base::TimeDelta delta,
49 int rtp_timebase) {
50 return RtpTimeDelta(TimeDeltaToTicks(delta, rtp_timebase));
51 }
52
53 // static
54 RtpTimeDelta RtpTimeDelta::FromTicks(int64_t ticks) {
55 return RtpTimeDelta(ticks);
56 }
57
58 base::TimeDelta RtpTimeTicks::ToTimeDelta(int rtp_timebase) const {
59 return TicksToTimeDelta(value_, rtp_timebase);
60 }
61
62 void RtpTimeTicks::OutputToLog(std::ostream& out) const {
63 out << "RTP@" << value_;
64 }
65
66 // static
67 RtpTimeTicks RtpTimeTicks::FromTimeDelta(base::TimeDelta delta,
68 int rtp_timebase) {
69 return RtpTimeTicks(TimeDeltaToTicks(delta, rtp_timebase));
70 }
71
72 std::ostream& operator<<(std::ostream& out, RtpTimeDelta rhs) {
73 rhs.OutputToLog(out);
74 return out;
75 }
76
77 std::ostream& operator<<(std::ostream& out, RtpTimeTicks rhs) {
78 rhs.OutputToLog(out);
79 return out;
80 }
81
82 } // namespace cast
83 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698