OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BASE_AUDIO_TIMESTAMP_HELPER_H_ | 5 #ifndef MEDIA_BASE_AUDIO_TIMESTAMP_HELPER_H_ |
6 #define MEDIA_BASE_AUDIO_TIMESTAMP_HELPER_H_ | 6 #define MEDIA_BASE_AUDIO_TIMESTAMP_HELPER_H_ |
7 | 7 |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "media/base/media_export.h" | 9 #include "media/base/media_export.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 // determines the number of frames that need to be added/removed from the | 26 // determines the number of frames that need to be added/removed from the |
27 // accumulated frames to reach a target timestamp. | 27 // accumulated frames to reach a target timestamp. |
28 class MEDIA_EXPORT AudioTimestampHelper { | 28 class MEDIA_EXPORT AudioTimestampHelper { |
29 public: | 29 public: |
30 explicit AudioTimestampHelper(int samples_per_second); | 30 explicit AudioTimestampHelper(int samples_per_second); |
31 | 31 |
32 // Sets the base timestamp to |base_timestamp| and the sets count to 0. | 32 // Sets the base timestamp to |base_timestamp| and the sets count to 0. |
33 void SetBaseTimestamp(base::TimeDelta base_timestamp); | 33 void SetBaseTimestamp(base::TimeDelta base_timestamp); |
34 | 34 |
35 base::TimeDelta base_timestamp() const; | 35 base::TimeDelta base_timestamp() const; |
36 int64 frame_count() const { return frame_count_; } | 36 int64_t frame_count() const { return frame_count_; } |
37 | 37 |
38 // Adds |frame_count| to the frame counter. | 38 // Adds |frame_count| to the frame counter. |
39 // Note: SetBaseTimestamp() must be called with a value other than | 39 // Note: SetBaseTimestamp() must be called with a value other than |
40 // kNoTimestamp() before this method can be called. | 40 // kNoTimestamp() before this method can be called. |
41 void AddFrames(int frame_count); | 41 void AddFrames(int frame_count); |
42 | 42 |
43 // Get the current timestamp. This value is computed from the base_timestamp() | 43 // Get the current timestamp. This value is computed from the base_timestamp() |
44 // and the number of sample frames that have been added so far. | 44 // and the number of sample frames that have been added so far. |
45 base::TimeDelta GetTimestamp() const; | 45 base::TimeDelta GetTimestamp() const; |
46 | 46 |
47 // Gets the duration if |frame_count| frames were added to the current | 47 // Gets the duration if |frame_count| frames were added to the current |
48 // timestamp reported by GetTimestamp(). This method ensures that | 48 // timestamp reported by GetTimestamp(). This method ensures that |
49 // (GetTimestamp() + GetFrameDuration(n)) will equal the timestamp that | 49 // (GetTimestamp() + GetFrameDuration(n)) will equal the timestamp that |
50 // GetTimestamp() will return if AddFrames(n) is called. | 50 // GetTimestamp() will return if AddFrames(n) is called. |
51 base::TimeDelta GetFrameDuration(int frame_count) const; | 51 base::TimeDelta GetFrameDuration(int frame_count) const; |
52 | 52 |
53 // Returns the number of frames needed to reach the target timestamp. | 53 // Returns the number of frames needed to reach the target timestamp. |
54 // Note: |target| must be >= |base_timestamp_|. | 54 // Note: |target| must be >= |base_timestamp_|. |
55 int64 GetFramesToTarget(base::TimeDelta target) const; | 55 int64_t GetFramesToTarget(base::TimeDelta target) const; |
56 | 56 |
57 private: | 57 private: |
58 base::TimeDelta ComputeTimestamp(int64 frame_count) const; | 58 base::TimeDelta ComputeTimestamp(int64_t frame_count) const; |
59 | 59 |
60 double microseconds_per_frame_; | 60 double microseconds_per_frame_; |
61 | 61 |
62 base::TimeDelta base_timestamp_; | 62 base::TimeDelta base_timestamp_; |
63 | 63 |
64 // Number of frames accumulated by AddFrames() calls. | 64 // Number of frames accumulated by AddFrames() calls. |
65 int64 frame_count_; | 65 int64_t frame_count_; |
66 | 66 |
67 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioTimestampHelper); | 67 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioTimestampHelper); |
68 }; | 68 }; |
69 | 69 |
70 } // namespace media | 70 } // namespace media |
71 | 71 |
72 #endif | 72 #endif |
OLD | NEW |