Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Side by Side Diff: media/renderers/audio_renderer_impl.h

Issue 2684103005: Allow media track switching. (Closed)
Patch Set: Fixed comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | media/renderers/audio_renderer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 #include "base/power_monitor/power_observer.h" 29 #include "base/power_monitor/power_observer.h"
30 #include "base/synchronization/lock.h" 30 #include "base/synchronization/lock.h"
31 #include "media/base/audio_decoder.h" 31 #include "media/base/audio_decoder.h"
32 #include "media/base/audio_renderer.h" 32 #include "media/base/audio_renderer.h"
33 #include "media/base/audio_renderer_sink.h" 33 #include "media/base/audio_renderer_sink.h"
34 #include "media/base/decryptor.h" 34 #include "media/base/decryptor.h"
35 #include "media/base/media_log.h" 35 #include "media/base/media_log.h"
36 #include "media/base/time_source.h" 36 #include "media/base/time_source.h"
37 #include "media/filters/audio_renderer_algorithm.h" 37 #include "media/filters/audio_renderer_algorithm.h"
38 #include "media/filters/decoder_stream.h" 38 #include "media/filters/decoder_stream.h"
39 #include "media/renderers/default_renderer_factory.h"
39 40
40 namespace base { 41 namespace base {
41 class SingleThreadTaskRunner; 42 class SingleThreadTaskRunner;
42 class TickClock; 43 class TickClock;
43 } 44 }
44 45
45 namespace media { 46 namespace media {
46 47
47 class AudioBufferConverter; 48 class AudioBufferConverter;
48 class AudioBus; 49 class AudioBus;
49 class AudioClock; 50 class AudioClock;
50 51
51 class MEDIA_EXPORT AudioRendererImpl 52 class MEDIA_EXPORT AudioRendererImpl
52 : public AudioRenderer, 53 : public AudioRenderer,
53 public TimeSource, 54 public TimeSource,
54 public base::PowerObserver, 55 public base::PowerObserver,
55 NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { 56 NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) {
56 public: 57 public:
57 // |task_runner| is the thread on which AudioRendererImpl will execute. 58 // |task_runner| is the thread on which AudioRendererImpl will execute.
58 // 59 //
59 // |sink| is used as the destination for the rendered audio. 60 // |sink| is used as the destination for the rendered audio.
60 // 61 //
61 // |decoders| contains the AudioDecoders to use when initializing. 62 // |decoders| contains the AudioDecoders to use when initializing.
62 AudioRendererImpl( 63 AudioRendererImpl(
63 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 64 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
64 AudioRendererSink* sink, 65 AudioRendererSink* sink,
65 ScopedVector<AudioDecoder> decoders, 66 const CreateAudioDecodersCB& create_audio_decoders_cb,
66 const scoped_refptr<MediaLog>& media_log); 67 const scoped_refptr<MediaLog>& media_log);
67 ~AudioRendererImpl() override; 68 ~AudioRendererImpl() override;
68 69
69 // TimeSource implementation. 70 // TimeSource implementation.
70 void StartTicking() override; 71 void StartTicking() override;
71 void StopTicking() override; 72 void StopTicking() override;
72 void SetPlaybackRate(double rate) override; 73 void SetPlaybackRate(double rate) override;
73 void SetMediaTime(base::TimeDelta time) override; 74 void SetMediaTime(base::TimeDelta time) override;
74 base::TimeDelta CurrentMediaTime() override; 75 base::TimeDelta CurrentMediaTime() override;
75 bool GetWallClockTimes( 76 bool GetWallClockTimes(
(...skipping 13 matching lines...) Expand all
89 // base::PowerObserver implementation. 90 // base::PowerObserver implementation.
90 void OnSuspend() override; 91 void OnSuspend() override;
91 void OnResume() override; 92 void OnResume() override;
92 93
93 private: 94 private:
94 friend class AudioRendererImplTest; 95 friend class AudioRendererImplTest;
95 96
96 // Important detail: being in kPlaying doesn't imply that audio is being 97 // Important detail: being in kPlaying doesn't imply that audio is being
97 // rendered. Rather, it means that the renderer is ready to go. The actual 98 // rendered. Rather, it means that the renderer is ready to go. The actual
98 // rendering of audio is controlled via Start/StopRendering(). 99 // rendering of audio is controlled via Start/StopRendering().
100 // Audio renderer can be reinitialized completely by calling Initialize again
101 // when it is in a kFlushed state.
99 // 102 //
100 // kUninitialized 103 // kUninitialized
101 // | Initialize() 104 // +----> | Initialize()
102 // | 105 // | |
103 // V 106 // | V
104 // kInitializing 107 // | kInitializing
105 // | Decoders initialized 108 // | | Decoders initialized
106 // | 109 // | |
107 // V Decoders reset 110 // | V Decoders reset
108 // kFlushed <------------------ kFlushing 111 // +- kFlushed <------------------ kFlushing
109 // | StartPlaying() ^ 112 // | StartPlaying() ^
110 // | | 113 // | |
111 // | | Flush() 114 // | | Flush()
112 // `---------> kPlaying --------' 115 // `---------> kPlaying --------'
113 enum State { 116 enum State {
114 kUninitialized, 117 kUninitialized,
115 kInitializing, 118 kInitializing,
116 kFlushing, 119 kFlushing,
117 kFlushed, 120 kFlushed,
118 kPlaying 121 kPlaying
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // under |lock_|. ------------------------------------------------------------ 249 // under |lock_|. ------------------------------------------------------------
247 base::Lock lock_; 250 base::Lock lock_;
248 251
249 // Algorithm for scaling audio. 252 // Algorithm for scaling audio.
250 double playback_rate_; 253 double playback_rate_;
251 std::unique_ptr<AudioRendererAlgorithm> algorithm_; 254 std::unique_ptr<AudioRendererAlgorithm> algorithm_;
252 255
253 // Simple state tracking variable. 256 // Simple state tracking variable.
254 State state_; 257 State state_;
255 258
259 // TODO(servolk): Consider using DecoderFactory here instead of the
260 // CreateAudioDecodersCB.
261 CreateAudioDecodersCB create_audio_decoders_cb_;
262
256 BufferingState buffering_state_; 263 BufferingState buffering_state_;
257 264
258 // Keep track of whether or not the sink is playing and whether we should be 265 // Keep track of whether or not the sink is playing and whether we should be
259 // rendering. 266 // rendering.
260 bool rendering_; 267 bool rendering_;
261 bool sink_playing_; 268 bool sink_playing_;
262 269
263 // Keep track of our outstanding read to |decoder_|. 270 // Keep track of our outstanding read to |decoder_|.
264 bool pending_read_; 271 bool pending_read_;
265 272
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 305
299 // NOTE: Weak pointers must be invalidated before all other member variables. 306 // NOTE: Weak pointers must be invalidated before all other member variables.
300 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; 307 base::WeakPtrFactory<AudioRendererImpl> weak_factory_;
301 308
302 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); 309 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl);
303 }; 310 };
304 311
305 } // namespace media 312 } // namespace media
306 313
307 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ 314 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | media/renderers/audio_renderer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698