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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 // constructed, SetBaseTimestamp() must be called to specify the starting | 23 // constructed, SetBaseTimestamp() must be called to specify the starting |
24 // timestamp of the audio sequence. As audio samples are received, their frame | 24 // timestamp of the audio sequence. As audio samples are received, their frame |
25 // counts are added using AddFrames(). These frame counts are accumulated by | 25 // counts are added using AddFrames(). These frame counts are accumulated by |
26 // this class so GetTimestamp() can be used to determine the timestamp for the | 26 // this class so GetTimestamp() can be used to determine the timestamp for the |
27 // samples that have been added. GetDuration() calculates the proper duration | 27 // samples that have been added. GetDuration() calculates the proper duration |
28 // values for samples added to the current timestamp. GetFramesToTarget() | 28 // values for samples added to the current timestamp. GetFramesToTarget() |
29 // determines the number of frames that need to be added/removed from the | 29 // determines the number of frames that need to be added/removed from the |
30 // accumulated frames to reach a target timestamp. | 30 // accumulated frames to reach a target timestamp. |
31 class MEDIA_EXPORT AudioTimestampHelper { | 31 class MEDIA_EXPORT AudioTimestampHelper { |
32 public: | 32 public: |
| 33 // Returns the time duration of the given number of frames of audio with the |
| 34 // given sample rate (in samples per second). |
| 35 static base::TimeDelta FramesToTime(int64_t frames, int samples_per_second); |
| 36 |
| 37 // Returns the number of frames in the given duration of audio with the given |
| 38 // sample rate (in samples per second). |
| 39 static int64_t TimeToFrames(base::TimeDelta time, int samples_per_second); |
| 40 |
33 explicit AudioTimestampHelper(int samples_per_second); | 41 explicit AudioTimestampHelper(int samples_per_second); |
34 | 42 |
35 // Sets the base timestamp to |base_timestamp| and the sets count to 0. | 43 // Sets the base timestamp to |base_timestamp| and the sets count to 0. |
36 void SetBaseTimestamp(base::TimeDelta base_timestamp); | 44 void SetBaseTimestamp(base::TimeDelta base_timestamp); |
37 | 45 |
38 base::TimeDelta base_timestamp() const; | 46 base::TimeDelta base_timestamp() const; |
39 int64_t frame_count() const { return frame_count_; } | 47 int64_t frame_count() const { return frame_count_; } |
40 | 48 |
41 // Adds |frame_count| to the frame counter. | 49 // Adds |frame_count| to the frame counter. |
42 // Note: SetBaseTimestamp() must be called with a value other than | 50 // Note: SetBaseTimestamp() must be called with a value other than |
(...skipping 23 matching lines...) Expand all Loading... |
66 | 74 |
67 // Number of frames accumulated by AddFrames() calls. | 75 // Number of frames accumulated by AddFrames() calls. |
68 int64_t frame_count_; | 76 int64_t frame_count_; |
69 | 77 |
70 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioTimestampHelper); | 78 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioTimestampHelper); |
71 }; | 79 }; |
72 | 80 |
73 } // namespace media | 81 } // namespace media |
74 | 82 |
75 #endif // MEDIA_BASE_AUDIO_TIMESTAMP_HELPER_H_ | 83 #endif // MEDIA_BASE_AUDIO_TIMESTAMP_HELPER_H_ |
OLD | NEW |