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 // Where the object is created. | 9 // Where the object is created. |
10 // 2. Media thread (provided via constructor) | 10 // 2. Media thread (provided via constructor) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // | 60 // |
61 // |set_decryptor_ready_cb| is fired when the audio decryptor is available | 61 // |set_decryptor_ready_cb| is fired when the audio decryptor is available |
62 // (only applicable if the stream is encrypted and we have a decryptor). | 62 // (only applicable if the stream is encrypted and we have a decryptor). |
63 AudioRendererImpl( | 63 AudioRendererImpl( |
64 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 64 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
65 AudioRendererSink* sink, | 65 AudioRendererSink* sink, |
66 ScopedVector<AudioDecoder> decoders, | 66 ScopedVector<AudioDecoder> decoders, |
67 const SetDecryptorReadyCB& set_decryptor_ready_cb, | 67 const SetDecryptorReadyCB& set_decryptor_ready_cb, |
68 const AudioHardwareConfig& hardware_params, | 68 const AudioHardwareConfig& hardware_params, |
69 const scoped_refptr<MediaLog>& media_log); | 69 const scoped_refptr<MediaLog>& media_log); |
70 virtual ~AudioRendererImpl(); | 70 ~AudioRendererImpl() override; |
71 | 71 |
72 // TimeSource implementation. | 72 // TimeSource implementation. |
73 virtual void StartTicking() override; | 73 void StartTicking() override; |
74 virtual void StopTicking() override; | 74 void StopTicking() override; |
75 virtual void SetPlaybackRate(float rate) override; | 75 void SetPlaybackRate(float rate) override; |
76 virtual void SetMediaTime(base::TimeDelta time) override; | 76 void SetMediaTime(base::TimeDelta time) override; |
77 virtual base::TimeDelta CurrentMediaTime() override; | 77 base::TimeDelta CurrentMediaTime() override; |
78 virtual base::TimeDelta CurrentMediaTimeForSyncingVideo() override; | 78 base::TimeDelta CurrentMediaTimeForSyncingVideo() override; |
79 | 79 |
80 // AudioRenderer implementation. | 80 // AudioRenderer implementation. |
81 virtual void Initialize(DemuxerStream* stream, | 81 void Initialize(DemuxerStream* stream, |
82 const PipelineStatusCB& init_cb, | 82 const PipelineStatusCB& init_cb, |
83 const StatisticsCB& statistics_cb, | 83 const StatisticsCB& statistics_cb, |
84 const BufferingStateCB& buffering_state_cb, | 84 const BufferingStateCB& buffering_state_cb, |
85 const base::Closure& ended_cb, | 85 const base::Closure& ended_cb, |
86 const PipelineStatusCB& error_cb) override; | 86 const PipelineStatusCB& error_cb) override; |
87 virtual TimeSource* GetTimeSource() override; | 87 TimeSource* GetTimeSource() override; |
88 virtual void Flush(const base::Closure& callback) override; | 88 void Flush(const base::Closure& callback) override; |
89 virtual void StartPlaying() override; | 89 void StartPlaying() override; |
90 virtual void SetVolume(float volume) override; | 90 void SetVolume(float volume) override; |
91 | 91 |
92 private: | 92 private: |
93 friend class AudioRendererImplTest; | 93 friend class AudioRendererImplTest; |
94 | 94 |
95 // Important detail: being in kPlaying doesn't imply that audio is being | 95 // Important detail: being in kPlaying doesn't imply that audio is being |
96 // rendered. Rather, it means that the renderer is ready to go. The actual | 96 // rendered. Rather, it means that the renderer is ready to go. The actual |
97 // rendering of audio is controlled via Start/StopRendering(). | 97 // rendering of audio is controlled via Start/StopRendering(). |
98 // | 98 // |
99 // kUninitialized | 99 // kUninitialized |
100 // | Initialize() | 100 // | Initialize() |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // If this method returns fewer frames than the initial number of frames in | 144 // If this method returns fewer frames than the initial number of frames in |
145 // |audio_bus|, it could be a sign that the pipeline is stalled or unable to | 145 // |audio_bus|, it could be a sign that the pipeline is stalled or unable to |
146 // stream the data fast enough. In such scenarios, the callee should zero out | 146 // stream the data fast enough. In such scenarios, the callee should zero out |
147 // unused portions of their buffer to play back silence. | 147 // unused portions of their buffer to play back silence. |
148 // | 148 // |
149 // Render() updates the pipeline's playback timestamp. If Render() is | 149 // Render() updates the pipeline's playback timestamp. If Render() is |
150 // not called at the same rate as audio samples are played, then the reported | 150 // not called at the same rate as audio samples are played, then the reported |
151 // timestamp in the pipeline will be ahead of the actual audio playback. In | 151 // timestamp in the pipeline will be ahead of the actual audio playback. In |
152 // this case |audio_delay_milliseconds| should be used to indicate when in the | 152 // this case |audio_delay_milliseconds| should be used to indicate when in the |
153 // future should the filled buffer be played. | 153 // future should the filled buffer be played. |
154 virtual int Render(AudioBus* audio_bus, | 154 int Render(AudioBus* audio_bus, int audio_delay_milliseconds) override; |
155 int audio_delay_milliseconds) override; | 155 void OnRenderError() override; |
156 virtual void OnRenderError() override; | |
157 | 156 |
158 // Helper methods that schedule an asynchronous read from the decoder as long | 157 // Helper methods that schedule an asynchronous read from the decoder as long |
159 // as there isn't a pending read. | 158 // as there isn't a pending read. |
160 // | 159 // |
161 // Must be called on |task_runner_|. | 160 // Must be called on |task_runner_|. |
162 void AttemptRead(); | 161 void AttemptRead(); |
163 void AttemptRead_Locked(); | 162 void AttemptRead_Locked(); |
164 bool CanRead_Locked(); | 163 bool CanRead_Locked(); |
165 void ChangeState_Locked(State new_state); | 164 void ChangeState_Locked(State new_state); |
166 | 165 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 264 |
266 // NOTE: Weak pointers must be invalidated before all other member variables. | 265 // NOTE: Weak pointers must be invalidated before all other member variables. |
267 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; | 266 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; |
268 | 267 |
269 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 268 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
270 }; | 269 }; |
271 | 270 |
272 } // namespace media | 271 } // namespace media |
273 | 272 |
274 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ | 273 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
OLD | NEW |