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/decoder_buffer.h" |
12 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
13 | 14 |
14 namespace media { | 15 namespace media { |
15 | 16 |
16 class AudioBuffer; | 17 class AudioBuffer; |
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 decoded data which will be handed into |
| 23 // the ProcessBuffers() call. |
| 24 // |
| 25 // |decoder_delay| is the number of frames a decoder will output before data |
| 26 // corresponding to the first encoded buffer is output. Callers only need to |
| 27 // specify this if the decoder inserts frames which have no corresponding |
| 28 // encoded buffer. |
| 29 // |
| 30 // For example, most MP3 decoders will output 529 junk frames before the data |
| 31 // corresponding to the first encoded buffer is output. These frames are not |
| 32 // represented in the encoded data stream and instead are an artifact of how |
| 33 // most MP3 decoders work. See http://lame.sourceforge.net/tech-FAQ.txt |
| 34 // |
| 35 // NOTE: End discard is only supported when there is no |decoder_delay|. |
| 36 AudioDiscardHelper(int sample_rate, size_t decoder_delay); |
23 ~AudioDiscardHelper(); | 37 ~AudioDiscardHelper(); |
24 | 38 |
25 // Converts a TimeDelta to a frame count based on the constructed sample rate. | 39 // Converts a TimeDelta to a frame count based on the constructed sample rate. |
26 // |duration| must be positive. | 40 // |duration| must be positive. |
27 size_t TimeDeltaToFrames(base::TimeDelta duration) const; | 41 size_t TimeDeltaToFrames(base::TimeDelta duration) const; |
28 | 42 |
29 // Resets internal state and indicates that |initial_discard| of upcoming | 43 // Resets internal state and indicates that |initial_discard| of upcoming |
30 // frames should be discarded. | 44 // frames should be discarded. |
31 void Reset(size_t initial_discard); | 45 void Reset(size_t initial_discard); |
32 | 46 |
(...skipping 10 matching lines...) Expand all Loading... |
43 bool ProcessBuffers(const scoped_refptr<DecoderBuffer>& encoded_buffer, | 57 bool ProcessBuffers(const scoped_refptr<DecoderBuffer>& encoded_buffer, |
44 const scoped_refptr<AudioBuffer>& decoded_buffer); | 58 const scoped_refptr<AudioBuffer>& decoded_buffer); |
45 | 59 |
46 // Whether any buffers have been processed. | 60 // Whether any buffers have been processed. |
47 bool initialized() const { | 61 bool initialized() const { |
48 return timestamp_helper_.base_timestamp() != kNoTimestamp(); | 62 return timestamp_helper_.base_timestamp() != kNoTimestamp(); |
49 } | 63 } |
50 | 64 |
51 private: | 65 private: |
52 const int sample_rate_; | 66 const int sample_rate_; |
| 67 const size_t decoder_delay_; |
53 AudioTimestampHelper timestamp_helper_; | 68 AudioTimestampHelper timestamp_helper_; |
54 | 69 |
55 size_t discard_frames_; | 70 size_t discard_frames_; |
56 base::TimeDelta last_input_timestamp_; | 71 base::TimeDelta last_input_timestamp_; |
57 | 72 |
| 73 bool delayed_discard_; |
| 74 DecoderBuffer::DiscardPadding delayed_discard_padding_; |
| 75 |
58 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioDiscardHelper); | 76 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioDiscardHelper); |
59 }; | 77 }; |
60 | 78 |
61 } // namespace media | 79 } // namespace media |
62 | 80 |
63 #endif // MEDIA_BASE_AUDIO_DISCARD_HELPER_H_ | 81 #endif // MEDIA_BASE_AUDIO_DISCARD_HELPER_H_ |
OLD | NEW |