Chromium Code Reviews

Side by Side Diff: mojo/services/media/common/cpp/timeline.h

Issue 1986303002: Motown: Use new TimelineTransform and related definitions (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fixes per feedback. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(Empty)
1 // Copyright 2016 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 #ifndef MOJO_SERVICES_MEDIA_COMMON_CPP_TIMELINE_H_
6 #define MOJO_SERVICES_MEDIA_COMMON_CPP_TIMELINE_H_
7
8 #include <stdint.h>
9 #include <chrono> // NOLINT(build/c++11)
10
11 // TODO(johngro): As we add support for other environments, extend this list.
12 #if defined(OS_POSIX)
13 #include "mojo/services/media/common/cpp/platform/posix/local_time.h"
14 #else
15 // TODO(johngro): consider adding a #warning or #info to inform the user that
16 // they are using the generic implementation of LocalTime, and really should get
17 // around to implementing proper platform support ASAP.
18 #include "mojo/services/media/common/cpp/platform/generic/local_time.h"
19 #endif
20
21 namespace mojo {
22 namespace media {
23
24 // Some helpful constants and static methods relating to timelines.
25 class Timeline {
26 public:
27 // Returns the current local time in nanoseconds since epoch.
28 static int64_t local_now() {
29 return local_time::Clock::now().time_since_epoch().count();
30 }
31
32 template <typename T>
33 static constexpr int64_t ns_from_seconds(T seconds) {
34 return static_cast<int64_t>(seconds * std::nano::den);
35 }
36
37 template <typename T>
38 static constexpr int64_t ns_from_ms(T milliseconds) {
39 return static_cast<int64_t>(milliseconds *
40 (std::nano::den / std::milli::den));
41 }
42
43 template <typename T>
44 static constexpr int64_t ns_from_us(T microseconds) {
45 return static_cast<int64_t>(microseconds *
46 (std::nano::den / std::micro::den));
47 }
48 };
49
50 } // namespace media
51 } // namespace mojo
52
53 #endif // MOJO_SERVICES_MEDIA_COMMON_CPP_TIMELINE_H_
OLDNEW
« no previous file with comments | « mojo/services/media/common/cpp/BUILD.gn ('k') | mojo/services/media/common/cpp/timeline_function.h » ('j') | no next file with comments »

Powered by Google App Engine