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 // AudioRendererBase takes care of the tricky queuing work and provides simple | 5 // AudioRendererBase takes care of the tricky queuing work and provides simple |
6 // methods for subclasses to peek and poke at audio data. In addition to | 6 // methods for subclasses to peek and poke at audio data. In addition to |
7 // AudioRenderer interface methods this classes doesn't implement, subclasses | 7 // AudioRenderer interface methods this classes doesn't implement, subclasses |
8 // must also implement the following methods: | 8 // must also implement the following methods: |
9 // OnInitialized | 9 // OnInitialized |
10 // OnStop | 10 // OnStop |
(...skipping 55 matching lines...) Loading... |
66 // Method called by FillBuffer() when it finds that it reached end of stream. | 66 // Method called by FillBuffer() when it finds that it reached end of stream. |
67 // FillBuffer() cannot immediately signal end of stream event because browser | 67 // FillBuffer() cannot immediately signal end of stream event because browser |
68 // may have buffered data. | 68 // may have buffered data. |
69 virtual void OnRenderEndOfStream() = 0; | 69 virtual void OnRenderEndOfStream() = 0; |
70 | 70 |
71 // Callback from the audio decoder delivering decoded audio samples. | 71 // Callback from the audio decoder delivering decoded audio samples. |
72 void DecodedAudioReady(scoped_refptr<Buffer> buffer); | 72 void DecodedAudioReady(scoped_refptr<Buffer> buffer); |
73 | 73 |
74 // Fills the given buffer with audio data by delegating to its |algorithm_|. | 74 // Fills the given buffer with audio data by delegating to its |algorithm_|. |
75 // FillBuffer() also takes care of updating the clock. Returns the number of | 75 // FillBuffer() also takes care of updating the clock. Returns the number of |
76 // bytes copied into |dest|, which may be less than or equal to |len|. | 76 // frames copied into |dest|, which may be less than or equal to |
| 77 // |requested_frames|. |
77 // | 78 // |
78 // If this method is returns less bytes than |len| (including zero), it could | 79 // If this method returns fewer frames than |requested_frames|, it could |
79 // be a sign that the pipeline is stalled or unable to stream the data fast | 80 // be a sign that the pipeline is stalled or unable to stream the data fast |
80 // enough. In such scenarios, the callee should zero out unused portions | 81 // enough. In such scenarios, the callee should zero out unused portions |
81 // of their buffer to playback silence. | 82 // of their buffer to playback silence. |
82 // | 83 // |
83 // FillBuffer() updates the pipeline's playback timestamp. If FillBuffer() is | 84 // FillBuffer() updates the pipeline's playback timestamp. If FillBuffer() is |
84 // not called at the same rate as audio samples are played, then the reported | 85 // not called at the same rate as audio samples are played, then the reported |
85 // timestamp in the pipeline will be ahead of the actual audio playback. In | 86 // timestamp in the pipeline will be ahead of the actual audio playback. In |
86 // this case |playback_delay| should be used to indicate when in the future | 87 // this case |playback_delay| should be used to indicate when in the future |
87 // should the filled buffer be played. If FillBuffer() is called as the audio | 88 // should the filled buffer be played. If FillBuffer() is called as the audio |
88 // hardware plays the buffer, then |playback_delay| should be zero. | 89 // hardware plays the buffer, then |playback_delay| should be zero. |
89 // | 90 // |
90 // FillBuffer() calls OnRenderEndOfStream() when it reaches end of stream. | 91 // FillBuffer() calls OnRenderEndOfStream() when it reaches end of stream. |
91 // It is responsibility of derived class to provide implementation of | 92 // It is responsibility of derived class to provide implementation of |
92 // OnRenderEndOfStream() that calls SignalEndOfStream() when all the hardware | 93 // OnRenderEndOfStream() that calls SignalEndOfStream() when all the hardware |
93 // buffers become empty (i.e. when all the data written to the device has | 94 // buffers become empty (i.e. when all the data written to the device has |
94 // been played). | 95 // been played). |
95 // | 96 // |
96 // Safe to call on any thread. | 97 // Safe to call on any thread. |
97 uint32 FillBuffer(uint8* dest, | 98 uint32 FillBuffer(uint8* dest, |
98 uint32 len, | 99 uint32 requested_frames, |
99 const base::TimeDelta& playback_delay); | 100 const base::TimeDelta& playback_delay); |
100 | 101 |
101 // Called by OnRenderEndOfStream() or some callback scheduled by derived class | 102 // Called by OnRenderEndOfStream() or some callback scheduled by derived class |
102 // to signal end of stream. | 103 // to signal end of stream. |
103 void SignalEndOfStream(); | 104 void SignalEndOfStream(); |
104 | 105 |
105 // Get/Set the playback rate of |algorithm_|. | 106 // Get/Set the playback rate of |algorithm_|. |
106 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; | 107 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
107 virtual float GetPlaybackRate(); | 108 virtual float GetPlaybackRate(); |
108 | 109 |
(...skipping 28 matching lines...) Loading... |
137 kStopped, | 138 kStopped, |
138 kUnderflow, | 139 kUnderflow, |
139 kRebuffering, | 140 kRebuffering, |
140 }; | 141 }; |
141 State state_; | 142 State state_; |
142 | 143 |
143 // Keep track of our outstanding read to |decoder_|. | 144 // Keep track of our outstanding read to |decoder_|. |
144 bool pending_read_; | 145 bool pending_read_; |
145 | 146 |
146 // Keeps track of whether we received and rendered the end of stream buffer. | 147 // Keeps track of whether we received and rendered the end of stream buffer. |
147 bool recieved_end_of_stream_; | 148 bool received_end_of_stream_; |
148 bool rendered_end_of_stream_; | 149 bool rendered_end_of_stream_; |
149 | 150 |
150 // Audio time at end of last call to FillBuffer(). | 151 // Audio time at end of last call to FillBuffer(). |
151 // TODO(ralphl): Update this value after seeking. | 152 // TODO(ralphl): Update this value after seeking. |
152 base::TimeDelta last_fill_buffer_time_; | 153 base::TimeDelta last_fill_buffer_time_; |
153 | 154 |
154 // Filter callbacks. | 155 // Filter callbacks. |
155 base::Closure pause_callback_; | 156 base::Closure pause_callback_; |
156 FilterStatusCB seek_cb_; | 157 FilterStatusCB seek_cb_; |
157 | 158 |
158 base::Closure underflow_callback_; | 159 base::Closure underflow_callback_; |
159 | 160 |
160 AudioTimeCB audio_time_cb_; | 161 AudioTimeCB audio_time_cb_; |
161 | 162 |
162 base::TimeDelta seek_timestamp_; | 163 base::TimeDelta seek_timestamp_; |
163 | 164 |
| 165 uint32 bytes_per_frame_; |
| 166 |
164 AudioDecoder::ReadCB read_cb_; | 167 AudioDecoder::ReadCB read_cb_; |
165 | 168 |
166 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase); | 169 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase); |
167 }; | 170 }; |
168 | 171 |
169 } // namespace media | 172 } // namespace media |
170 | 173 |
171 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ | 174 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ |
OLD | NEW |