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 // Audio rendering unit utilizing an AudioRendererSink to output data. | 5 // Audio rendering unit utilizing an AudioRendererSink to output data. |
6 // | 6 // |
7 // This class lives inside three threads during it's lifetime, namely: | 7 // This class lives inside three threads during it's lifetime, namely: |
8 // 1. Render thread. | 8 // 1. Render thread. |
9 // This object is created on the render thread. | 9 // This object is created on the render thread. |
10 // 2. Pipeline thread | 10 // 2. Pipeline thread |
11 // Initialize() is called here with the audio format. | 11 // Initialize() is called here with the audio format. |
12 // Play/Pause/Seek also happens here. | 12 // Play/Pause/Seek also happens here. |
13 // 3. Audio thread created by the AudioRendererSink. | 13 // 3. Audio thread created by the AudioRendererSink. |
14 // Render() is called here where audio data is decoded into raw PCM data. | 14 // Render() is called here where audio data is decoded into raw PCM data. |
15 // | 15 // |
16 // AudioRendererBase talks to an AudioRendererAlgorithmBase that takes care of | 16 // AudioRendererImpl talks to an AudioRendererAlgorithm that takes care of |
17 // queueing audio data and stretching/shrinking audio data when playback rate != | 17 // queueing audio data and stretching/shrinking audio data when playback rate != |
18 // 1.0 or 0.0. | 18 // 1.0 or 0.0. |
19 | 19 |
20 #ifndef MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ | 20 #ifndef MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
21 #define MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ | 21 #define MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
22 | 22 |
23 #include <deque> | 23 #include <deque> |
24 | 24 |
25 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
26 #include "media/base/audio_decoder.h" | 26 #include "media/base/audio_decoder.h" |
27 #include "media/base/audio_renderer_sink.h" | 27 #include "media/base/audio_renderer_sink.h" |
28 #include "media/base/buffers.h" | 28 #include "media/base/buffers.h" |
29 #include "media/base/filters.h" | 29 #include "media/base/filters.h" |
30 #include "media/filters/audio_renderer_algorithm_base.h" | 30 #include "media/filters/audio_renderer_algorithm.h" |
31 | 31 |
32 namespace media { | 32 namespace media { |
33 | 33 |
34 class MEDIA_EXPORT AudioRendererBase | 34 class MEDIA_EXPORT AudioRendererImpl |
35 : public AudioRenderer, | 35 : public AudioRenderer, |
36 NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback) { | 36 NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback) { |
37 public: | 37 public: |
38 // Methods called on Render thread ------------------------------------------ | 38 // Methods called on Render thread ------------------------------------------ |
39 // An AudioRendererSink is used as the destination for the rendered audio. | 39 // An AudioRendererSink is used as the destination for the rendered audio. |
40 explicit AudioRendererBase(media::AudioRendererSink* sink); | 40 explicit AudioRendererImpl(media::AudioRendererSink* sink); |
41 virtual ~AudioRendererBase(); | 41 virtual ~AudioRendererImpl(); |
42 | 42 |
43 // Methods called on pipeline thread ---------------------------------------- | 43 // Methods called on pipeline thread ---------------------------------------- |
44 // Filter implementation. | 44 // Filter implementation. |
45 virtual void Play(const base::Closure& callback) OVERRIDE; | 45 virtual void Play(const base::Closure& callback) OVERRIDE; |
46 virtual void Pause(const base::Closure& callback) OVERRIDE; | 46 virtual void Pause(const base::Closure& callback) OVERRIDE; |
47 virtual void Flush(const base::Closure& callback) OVERRIDE; | 47 virtual void Flush(const base::Closure& callback) OVERRIDE; |
48 virtual void Stop(const base::Closure& callback) OVERRIDE; | 48 virtual void Stop(const base::Closure& callback) OVERRIDE; |
49 virtual void SetPlaybackRate(float rate) OVERRIDE; | 49 virtual void SetPlaybackRate(float rate) OVERRIDE; |
50 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 50 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
51 | 51 |
52 // AudioRenderer implementation. | 52 // AudioRenderer implementation. |
53 virtual void Initialize(const scoped_refptr<AudioDecoder>& decoder, | 53 virtual void Initialize(const scoped_refptr<AudioDecoder>& decoder, |
54 const PipelineStatusCB& init_cb, | 54 const PipelineStatusCB& init_cb, |
55 const base::Closure& underflow_cb, | 55 const base::Closure& underflow_cb, |
56 const TimeCB& time_cb) OVERRIDE; | 56 const TimeCB& time_cb) OVERRIDE; |
57 virtual bool HasEnded() OVERRIDE; | 57 virtual bool HasEnded() OVERRIDE; |
58 virtual void ResumeAfterUnderflow(bool buffer_more_audio) OVERRIDE; | 58 virtual void ResumeAfterUnderflow(bool buffer_more_audio) OVERRIDE; |
59 virtual void SetVolume(float volume) OVERRIDE; | 59 virtual void SetVolume(float volume) OVERRIDE; |
60 | 60 |
61 private: | 61 private: |
62 friend class AudioRendererBaseTest; | 62 friend class AudioRendererImplTest; |
63 FRIEND_TEST_ALL_PREFIXES(AudioRendererBaseTest, EndOfStream); | 63 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, EndOfStream); |
64 FRIEND_TEST_ALL_PREFIXES(AudioRendererBaseTest, Underflow_EndOfStream); | 64 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, Underflow_EndOfStream); |
65 | 65 |
66 // Callback from the audio decoder delivering decoded audio samples. | 66 // Callback from the audio decoder delivering decoded audio samples. |
67 void DecodedAudioReady(scoped_refptr<Buffer> buffer); | 67 void DecodedAudioReady(scoped_refptr<Buffer> buffer); |
68 | 68 |
69 // Fills the given buffer with audio data by delegating to its |algorithm_|. | 69 // Fills the given buffer with audio data by delegating to its |algorithm_|. |
70 // FillBuffer() also takes care of updating the clock. Returns the number of | 70 // FillBuffer() also takes care of updating the clock. Returns the number of |
71 // frames copied into |dest|, which may be less than or equal to | 71 // frames copied into |dest|, which may be less than or equal to |
72 // |requested_frames|. | 72 // |requested_frames|. |
73 // | 73 // |
74 // If this method returns fewer frames than |requested_frames|, it could | 74 // If this method returns fewer frames than |requested_frames|, it could |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 // Returns true if the data in the buffer is all before | 126 // Returns true if the data in the buffer is all before |
127 // |seek_timestamp_|. This can only return true while | 127 // |seek_timestamp_|. This can only return true while |
128 // in the kSeeking state. | 128 // in the kSeeking state. |
129 bool IsBeforeSeekTime(const scoped_refptr<Buffer>& buffer); | 129 bool IsBeforeSeekTime(const scoped_refptr<Buffer>& buffer); |
130 | 130 |
131 // Audio decoder. | 131 // Audio decoder. |
132 scoped_refptr<AudioDecoder> decoder_; | 132 scoped_refptr<AudioDecoder> decoder_; |
133 | 133 |
134 // Algorithm for scaling audio. | 134 // Algorithm for scaling audio. |
135 scoped_ptr<AudioRendererAlgorithmBase> algorithm_; | 135 scoped_ptr<AudioRendererAlgorithm> algorithm_; |
136 | 136 |
137 base::Lock lock_; | 137 base::Lock lock_; |
138 | 138 |
139 // Simple state tracking variable. | 139 // Simple state tracking variable. |
140 enum State { | 140 enum State { |
141 kUninitialized, | 141 kUninitialized, |
142 kPaused, | 142 kPaused, |
143 kSeeking, | 143 kSeeking, |
144 kPlaying, | 144 kPlaying, |
145 kStopped, | 145 kStopped, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // remember when it should stop playing, and do not assume that buffer is | 196 // remember when it should stop playing, and do not assume that buffer is |
197 // empty till that time. Workaround is not bulletproof, as we don't exactly | 197 // empty till that time. Workaround is not bulletproof, as we don't exactly |
198 // know when that particular data would start playing, but it is much better | 198 // know when that particular data would start playing, but it is much better |
199 // than nothing. | 199 // than nothing. |
200 base::Time earliest_end_time_; | 200 base::Time earliest_end_time_; |
201 | 201 |
202 AudioParameters audio_parameters_; | 202 AudioParameters audio_parameters_; |
203 | 203 |
204 AudioDecoder::ReadCB read_cb_; | 204 AudioDecoder::ReadCB read_cb_; |
205 | 205 |
206 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase); | 206 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
207 }; | 207 }; |
208 | 208 |
209 } // namespace media | 209 } // namespace media |
210 | 210 |
211 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ | 211 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
OLD | NEW |