| 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 |
| 11 namespace media { | 11 namespace media { |
| 12 | 12 |
| 13 // Generates timestamps for a sequence of audio sample frames. This class should | 13 // Generates timestamps for a sequence of audio sample frames. This class should |
| 14 // be used any place timestamps need to be calculated for a sequence of audio | 14 // be used any place timestamps need to be calculated for a sequence of audio |
| 15 // samples. It helps avoid timestamps inaccuracies caused by rounding/truncation | 15 // samples. It helps avoid timestamps inaccuracies caused by rounding/truncation |
| 16 // in repeated sample count to timestamp conversions. | 16 // in repeated sample count to timestamp conversions. |
| 17 // | 17 // |
| 18 // The class is constructed with samples_per_second information so that it can | 18 // The class is constructed with samples_per_second information so that it can |
| 19 // convert audio sample frame counts into timestamps. After the object is | 19 // convert audio sample frame counts into timestamps. After the object is |
| 20 // constructed, SetBaseTimestamp() must be called to specify the starting | 20 // constructed, SetBaseTimestamp() must be called to specify the starting |
| 21 // timestamp of the audio sequence. As audio samples are received, their frame | 21 // timestamp of the audio sequence. As audio samples are received, their frame |
| 22 // counts are added using AddFrames(). These frame counts are accumulated by | 22 // counts are added using AddFrames(). These frame counts are accumulated by |
| 23 // this class so GetTimestamp() can be used to determine the timestamp for the | 23 // this class so GetTimestamp() can be used to determine the timestamp for the |
| 24 // samples that have been added. GetDuration() calculates the proper duration | 24 // samples that have been added. GetDuration() calculates the proper duration |
| 25 // values for samples added to the current timestamp. GetFramesToTarget() | 25 // values for samples added to the current timestamp. GetFramesToTarget() |
| 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 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 | 37 |
| 37 // Adds |frame_count| to the frame counter. | 38 // Adds |frame_count| to the frame counter. |
| 38 // Note: SetBaseTimestamp() must be called with a value other than | 39 // Note: SetBaseTimestamp() must be called with a value other than |
| 39 // kNoTimestamp() before this method can be called. | 40 // kNoTimestamp() before this method can be called. |
| 40 void AddFrames(int frame_count); | 41 void AddFrames(int frame_count); |
| 41 | 42 |
| 42 // 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() |
| 43 // 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. |
| 44 base::TimeDelta GetTimestamp() const; | 45 base::TimeDelta GetTimestamp() const; |
| 45 | 46 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 62 | 63 |
| 63 // Number of frames accumulated by AddFrames() calls. | 64 // Number of frames accumulated by AddFrames() calls. |
| 64 int64 frame_count_; | 65 int64 frame_count_; |
| 65 | 66 |
| 66 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioTimestampHelper); | 67 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioTimestampHelper); |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 } // namespace media | 70 } // namespace media |
| 70 | 71 |
| 71 #endif | 72 #endif |
| OLD | NEW |