OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 MEDIA_BASE_AUDIO_DISCARD_HELPER_H_ |
| 6 #define MEDIA_BASE_AUDIO_DISCARD_HELPER_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/time/time.h" |
| 10 #include "media/base/audio_timestamp_helper.h" |
| 11 #include "media/base/buffers.h" |
| 12 #include "media/base/media_export.h" |
| 13 |
| 14 namespace media { |
| 15 |
| 16 class AudioBuffer; |
| 17 class DecoderBuffer; |
| 18 |
| 19 // Helper class for managing timestamps and discard events around decoding. |
| 20 class MEDIA_EXPORT AudioDiscardHelper { |
| 21 public: |
| 22 explicit AudioDiscardHelper(int sample_rate); |
| 23 ~AudioDiscardHelper(); |
| 24 |
| 25 // Converts a TimeDelta to a frame count based on the constructed sample rate. |
| 26 // |duration| must be positive. |
| 27 size_t TimeDeltaToFrames(base::TimeDelta duration) const; |
| 28 |
| 29 // Resets internal state and indicates that |initial_discard| of upcoming |
| 30 // frames should be discarded. |
| 31 void Reset(size_t initial_discard); |
| 32 |
| 33 // Applies discard padding from the encoded buffer along with any initial |
| 34 // discards. |decoded_buffer| may be NULL, if not the timestamp and duration |
| 35 // will be set after discards are applied. Returns true if |decoded_buffer| |
| 36 // exists after processing discard events. Returns false if |decoded_buffer| |
| 37 // was NULL, is completely discarded, or a processing error occurs. |
| 38 // |
| 39 // If AudioDiscardHelper is not initialized() the timestamp of the first |
| 40 // |encoded_buffer| will be used as the basis for all future timestamps set on |
| 41 // |decoded_buffer|s. If the first buffer has a negative timestamp it will be |
| 42 // clamped to zero. |
| 43 bool ProcessBuffers(const scoped_refptr<DecoderBuffer>& encoded_buffer, |
| 44 const scoped_refptr<AudioBuffer>& decoded_buffer); |
| 45 |
| 46 // Whether any buffers have been processed. |
| 47 bool initialized() const { |
| 48 return timestamp_helper_.base_timestamp() != kNoTimestamp(); |
| 49 } |
| 50 |
| 51 private: |
| 52 const int sample_rate_; |
| 53 AudioTimestampHelper timestamp_helper_; |
| 54 |
| 55 size_t discard_frames_; |
| 56 base::TimeDelta last_input_timestamp_; |
| 57 |
| 58 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioDiscardHelper); |
| 59 }; |
| 60 |
| 61 } // namespace media |
| 62 |
| 63 #endif // MEDIA_BASE_AUDIO_DISCARD_HELPER_H_ |
OLD | NEW |