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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 // | 24 // |
25 // |decoder_delay| is the number of frames a decoder will output before data | 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 | 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 | 27 // specify this if the decoder inserts frames which have no corresponding |
28 // encoded buffer. | 28 // encoded buffer. |
29 // | 29 // |
30 // For example, most MP3 decoders will output 529 junk frames before the data | 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 | 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 | 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 | 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); | 34 AudioDiscardHelper(int sample_rate, size_t decoder_delay); |
37 ~AudioDiscardHelper(); | 35 ~AudioDiscardHelper(); |
38 | 36 |
39 // Converts a TimeDelta to a frame count based on the constructed sample rate. | 37 // Converts a TimeDelta to a frame count based on the constructed sample rate. |
40 // |duration| must be positive. | 38 // |duration| must be positive. |
41 size_t TimeDeltaToFrames(base::TimeDelta duration) const; | 39 size_t TimeDeltaToFrames(base::TimeDelta duration) const; |
42 | 40 |
43 // Resets internal state and indicates that |initial_discard| of upcoming | 41 // Resets internal state and indicates that |initial_discard| of upcoming |
44 // frames should be discarded. | 42 // frames should be discarded. |
45 void Reset(size_t initial_discard); | 43 void Reset(size_t initial_discard); |
(...skipping 10 matching lines...) Expand all Loading... |
56 // clamped to zero. | 54 // clamped to zero. |
57 bool ProcessBuffers(const scoped_refptr<DecoderBuffer>& encoded_buffer, | 55 bool ProcessBuffers(const scoped_refptr<DecoderBuffer>& encoded_buffer, |
58 const scoped_refptr<AudioBuffer>& decoded_buffer); | 56 const scoped_refptr<AudioBuffer>& decoded_buffer); |
59 | 57 |
60 // Whether any buffers have been processed. | 58 // Whether any buffers have been processed. |
61 bool initialized() const { | 59 bool initialized() const { |
62 return timestamp_helper_.base_timestamp() != kNoTimestamp(); | 60 return timestamp_helper_.base_timestamp() != kNoTimestamp(); |
63 } | 61 } |
64 | 62 |
65 private: | 63 private: |
| 64 // The sample rate of the decoded audio samples. Used by TimeDeltaToFrames() |
| 65 // and the timestamp helper. |
66 const int sample_rate_; | 66 const int sample_rate_; |
| 67 |
| 68 // Some codecs output extra samples during the first decode. In order to trim |
| 69 // DiscardPadding correctly the helper must know the offset into the decoded |
| 70 // buffers at which real samples start. |
67 const size_t decoder_delay_; | 71 const size_t decoder_delay_; |
| 72 |
| 73 // Used to regenerate sample accurate timestamps for decoded buffers. The |
| 74 // timestamp of the first encoded buffer seen by ProcessBuffers() is used as |
| 75 // the base timestamp. |
68 AudioTimestampHelper timestamp_helper_; | 76 AudioTimestampHelper timestamp_helper_; |
69 | 77 |
| 78 // The number of frames to discard from the front of the next buffer. Can be |
| 79 // set by Reset() and added to by a front DiscardPadding larger than its |
| 80 // associated buffer. |
70 size_t discard_frames_; | 81 size_t discard_frames_; |
| 82 |
| 83 // The last encoded buffer timestamp seen by ProcessBuffers() or kNoTimestamp |
| 84 // if no buffers have been seen thus far. Used to issue warnings for buffer |
| 85 // sequences with non-monotonic timestamps. |
71 base::TimeDelta last_input_timestamp_; | 86 base::TimeDelta last_input_timestamp_; |
72 | 87 |
| 88 // Certain codecs require two encoded buffers before they'll output the first |
| 89 // decoded buffer. In this case DiscardPadding must be carried over from the |
| 90 // previous encoded buffer. Enabled automatically if an encoded buffer is |
| 91 // given to ProcessBuffers() with a NULL decoded buffer. |
73 bool delayed_discard_; | 92 bool delayed_discard_; |
74 DecoderBuffer::DiscardPadding delayed_discard_padding_; | 93 DecoderBuffer::DiscardPadding delayed_discard_padding_; |
75 | 94 |
| 95 // When |decoder_delay_| > 0, the number of frames which should be discarded |
| 96 // from the next buffer. The index at which to start discarding is calculated |
| 97 // by subtracting |delayed_end_discard_| from |decoder_delay_|. |
| 98 size_t delayed_end_discard_; |
| 99 |
76 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioDiscardHelper); | 100 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioDiscardHelper); |
77 }; | 101 }; |
78 | 102 |
79 } // namespace media | 103 } // namespace media |
80 | 104 |
81 #endif // MEDIA_BASE_AUDIO_DISCARD_HELPER_H_ | 105 #endif // MEDIA_BASE_AUDIO_DISCARD_HELPER_H_ |
OLD | NEW |