| 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) |
| 11 // All AudioDecoder methods are called on this thread. | 11 // All AudioDecoder methods are called on this thread. |
| 12 // 3. Audio thread created by the AudioRendererSink. | 12 // 3. Audio thread created by the AudioRendererSink. |
| 13 // Render() is called here where audio data is decoded into raw PCM data. | 13 // Render() is called here where audio data is decoded into raw PCM data. |
| 14 // | 14 // |
| 15 // AudioRendererImpl talks to an AudioRendererAlgorithm that takes care of | 15 // AudioRendererImpl talks to an AudioRendererAlgorithm that takes care of |
| 16 // queueing audio data and stretching/shrinking audio data when playback rate != | 16 // queueing audio data and stretching/shrinking audio data when playback rate != |
| 17 // 1.0 or 0.0. | 17 // 1.0 or 0.0. |
| 18 | 18 |
| 19 #ifndef MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ | 19 #ifndef MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ |
| 20 #define MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ | 20 #define MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ |
| 21 | 21 |
| 22 #include <stdint.h> | 22 #include <stdint.h> |
| 23 | 23 |
| 24 #include <deque> | 24 #include <deque> |
| 25 #include <memory> | 25 #include <memory> |
| 26 | 26 |
| 27 #include "base/macros.h" | 27 #include "base/macros.h" |
| 28 #include "base/memory/weak_ptr.h" | 28 #include "base/memory/weak_ptr.h" |
| 29 #include "base/power_monitor/power_observer.h" |
| 29 #include "base/synchronization/lock.h" | 30 #include "base/synchronization/lock.h" |
| 30 #include "media/base/audio_decoder.h" | 31 #include "media/base/audio_decoder.h" |
| 31 #include "media/base/audio_renderer.h" | 32 #include "media/base/audio_renderer.h" |
| 32 #include "media/base/audio_renderer_sink.h" | 33 #include "media/base/audio_renderer_sink.h" |
| 33 #include "media/base/decryptor.h" | 34 #include "media/base/decryptor.h" |
| 34 #include "media/base/media_log.h" | 35 #include "media/base/media_log.h" |
| 35 #include "media/base/time_source.h" | 36 #include "media/base/time_source.h" |
| 36 #include "media/filters/audio_renderer_algorithm.h" | 37 #include "media/filters/audio_renderer_algorithm.h" |
| 37 #include "media/filters/decoder_stream.h" | 38 #include "media/filters/decoder_stream.h" |
| 38 | 39 |
| 39 namespace base { | 40 namespace base { |
| 40 class SingleThreadTaskRunner; | 41 class SingleThreadTaskRunner; |
| 41 class TickClock; | 42 class TickClock; |
| 42 } | 43 } |
| 43 | 44 |
| 44 namespace media { | 45 namespace media { |
| 45 | 46 |
| 46 class AudioBufferConverter; | 47 class AudioBufferConverter; |
| 47 class AudioBus; | 48 class AudioBus; |
| 48 class AudioClock; | 49 class AudioClock; |
| 49 class AudioHardwareConfig; | 50 class AudioHardwareConfig; |
| 50 class AudioSplicer; | 51 class AudioSplicer; |
| 51 class DecryptingDemuxerStream; | 52 class DecryptingDemuxerStream; |
| 52 | 53 |
| 53 class MEDIA_EXPORT AudioRendererImpl | 54 class MEDIA_EXPORT AudioRendererImpl |
| 54 : public AudioRenderer, | 55 : public AudioRenderer, |
| 55 public TimeSource, | 56 public TimeSource, |
| 57 public base::PowerObserver, |
| 56 NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { | 58 NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { |
| 57 public: | 59 public: |
| 58 // |task_runner| is the thread on which AudioRendererImpl will execute. | 60 // |task_runner| is the thread on which AudioRendererImpl will execute. |
| 59 // | 61 // |
| 60 // |sink| is used as the destination for the rendered audio. | 62 // |sink| is used as the destination for the rendered audio. |
| 61 // | 63 // |
| 62 // |decoders| contains the AudioDecoders to use when initializing. | 64 // |decoders| contains the AudioDecoders to use when initializing. |
| 63 AudioRendererImpl( | 65 AudioRendererImpl( |
| 64 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 66 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 65 AudioRendererSink* sink, | 67 AudioRendererSink* sink, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 80 // AudioRenderer implementation. | 82 // AudioRenderer implementation. |
| 81 void Initialize(DemuxerStream* stream, | 83 void Initialize(DemuxerStream* stream, |
| 82 CdmContext* cdm_context, | 84 CdmContext* cdm_context, |
| 83 RendererClient* client, | 85 RendererClient* client, |
| 84 const PipelineStatusCB& init_cb) override; | 86 const PipelineStatusCB& init_cb) override; |
| 85 TimeSource* GetTimeSource() override; | 87 TimeSource* GetTimeSource() override; |
| 86 void Flush(const base::Closure& callback) override; | 88 void Flush(const base::Closure& callback) override; |
| 87 void StartPlaying() override; | 89 void StartPlaying() override; |
| 88 void SetVolume(float volume) override; | 90 void SetVolume(float volume) override; |
| 89 | 91 |
| 92 // base::PowerObserver implementation. |
| 93 void OnSuspend() override; |
| 94 void OnResume() override; |
| 95 |
| 90 private: | 96 private: |
| 91 friend class AudioRendererImplTest; | 97 friend class AudioRendererImplTest; |
| 92 | 98 |
| 93 // Important detail: being in kPlaying doesn't imply that audio is being | 99 // Important detail: being in kPlaying doesn't imply that audio is being |
| 94 // rendered. Rather, it means that the renderer is ready to go. The actual | 100 // rendered. Rather, it means that the renderer is ready to go. The actual |
| 95 // rendering of audio is controlled via Start/StopRendering(). | 101 // rendering of audio is controlled via Start/StopRendering(). |
| 96 // | 102 // |
| 97 // kUninitialized | 103 // kUninitialized |
| 98 // | Initialize() | 104 // | Initialize() |
| 99 // | | 105 // | |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 base::TimeTicks stop_rendering_time_; | 284 base::TimeTicks stop_rendering_time_; |
| 279 | 285 |
| 280 // Set upon receipt of the first decoded buffer after a StartPlayingFrom(). | 286 // Set upon receipt of the first decoded buffer after a StartPlayingFrom(). |
| 281 // Used to determine how long to delay playback. | 287 // Used to determine how long to delay playback. |
| 282 base::TimeDelta first_packet_timestamp_; | 288 base::TimeDelta first_packet_timestamp_; |
| 283 | 289 |
| 284 // Set by CurrentMediaTime(), used to prevent the current media time value as | 290 // Set by CurrentMediaTime(), used to prevent the current media time value as |
| 285 // reported to JavaScript from going backwards in time. | 291 // reported to JavaScript from going backwards in time. |
| 286 base::TimeDelta last_media_timestamp_; | 292 base::TimeDelta last_media_timestamp_; |
| 287 | 293 |
| 294 // Set by OnSuspend() and OnResume() to indicate when the system is about to |
| 295 // suspend/is suspended and when it resumes. |
| 296 bool is_suspending_; |
| 297 |
| 288 // End variables which must be accessed under |lock_|. ---------------------- | 298 // End variables which must be accessed under |lock_|. ---------------------- |
| 289 | 299 |
| 290 // NOTE: Weak pointers must be invalidated before all other member variables. | 300 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 291 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; | 301 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; |
| 292 | 302 |
| 293 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 303 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
| 294 }; | 304 }; |
| 295 | 305 |
| 296 } // namespace media | 306 } // namespace media |
| 297 | 307 |
| 298 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ | 308 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ |
| OLD | NEW |