OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_DISCARD_HELPER_H_ | 5 #ifndef MEDIA_BASE_AUDIO_DISCARD_HELPER_H_ |
6 #define MEDIA_BASE_AUDIO_DISCARD_HELPER_H_ | 6 #define MEDIA_BASE_AUDIO_DISCARD_HELPER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "media/base/audio_timestamp_helper.h" | 10 #include "media/base/audio_timestamp_helper.h" |
11 #include "media/base/buffers.h" | 11 #include "media/base/buffers.h" |
12 #include "media/base/media_export.h" | 12 #include "media/base/media_export.h" |
13 | 13 |
14 namespace media { | 14 namespace media { |
15 | 15 |
16 class AudioBuffer; | 16 class AudioBuffer; |
17 class DecoderBuffer; | 17 class DecoderBuffer; |
18 | 18 |
19 // Helper class for managing timestamps and discard events around decoding. | 19 // Helper class for managing timestamps and discard events around decoding. |
20 class MEDIA_EXPORT AudioDiscardHelper { | 20 class MEDIA_EXPORT AudioDiscardHelper { |
21 public: | 21 public: |
22 explicit AudioDiscardHelper(int sample_rate); | 22 // |sample_rate| is the sample rate of decode data which will be handed into |
| 23 // the ProcessBuffers() call. |
| 24 // |
| 25 // |codec_delay| is used to figure out the the start of decoded data from each |
| 26 // corresponding encoded buffer. End discard is only supported when there is |
| 27 // no |codec_delay|. |
| 28 AudioDiscardHelper(int sample_rate, size_t codec_delay); |
23 ~AudioDiscardHelper(); | 29 ~AudioDiscardHelper(); |
24 | 30 |
25 // Converts a TimeDelta to a frame count based on the constructed sample rate. | 31 // Converts a TimeDelta to a frame count based on the constructed sample rate. |
26 // |duration| must be postive. | 32 // |duration| must be postive. |
27 int TimeDeltaToFrames(base::TimeDelta duration) const; | 33 int TimeDeltaToFrames(base::TimeDelta duration) const; |
28 | 34 |
29 // Resets internal state and indicates that |initial_discard| of upcoming | 35 // Resets internal state and indicates that |initial_discard| of upcoming |
30 // frames should be discarded. | 36 // frames should be discarded. |
31 void Reset(size_t initial_discard); | 37 void Reset(size_t initial_discard); |
32 | 38 |
33 // Applies discard padding from the encoded buffer along with any initial | 39 // Applies discard padding from the encoded buffer along with any initial |
34 // discards. |decoded_buffer| may be NULL, if not the timestamp and duration | 40 // discards. |decoded_buffer| may be NULL, if not the timestamp and duration |
35 // will be set after discards are applied. | 41 // will be set after discards are applied. |
36 bool ProcessBuffers(const scoped_refptr<DecoderBuffer>& encoded_buffer, | 42 bool ProcessBuffers(const scoped_refptr<DecoderBuffer>& encoded_buffer, |
37 const scoped_refptr<AudioBuffer>& decoded_buffer); | 43 const scoped_refptr<AudioBuffer>& decoded_buffer); |
38 | 44 |
39 // Whether any buffers have been processed. | 45 // Whether any buffers have been processed. |
40 bool initialized() const { | 46 bool initialized() const { |
41 return timestamp_helper_.base_timestamp() != kNoTimestamp(); | 47 return timestamp_helper_.base_timestamp() != kNoTimestamp(); |
42 } | 48 } |
43 | 49 |
44 private: | 50 private: |
45 const int sample_rate_; | 51 const int sample_rate_; |
| 52 const size_t codec_delay_; |
46 AudioTimestampHelper timestamp_helper_; | 53 AudioTimestampHelper timestamp_helper_; |
47 | 54 |
48 size_t discard_frames_; | 55 size_t discard_frames_; |
49 base::TimeDelta last_input_timestamp_; | 56 base::TimeDelta last_input_timestamp_; |
| 57 scoped_refptr<DecoderBuffer> delayed_discard_; |
50 | 58 |
51 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioDiscardHelper); | 59 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioDiscardHelper); |
52 }; | 60 }; |
53 | 61 |
54 } // namespace media | 62 } // namespace media |
55 | 63 |
56 #endif | 64 #endif |
OLD | NEW |