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

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

Issue 2089503002: Merge M52: "Freeze media time and audio rendering when the system suspends." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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 | « no previous file | 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)
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 15 matching lines...) Expand all
81 // AudioRenderer implementation. 83 // AudioRenderer implementation.
82 void Initialize(DemuxerStream* stream, 84 void Initialize(DemuxerStream* stream,
83 CdmContext* cdm_context, 85 CdmContext* cdm_context,
84 RendererClient* client, 86 RendererClient* client,
85 const PipelineStatusCB& init_cb) override; 87 const PipelineStatusCB& init_cb) override;
86 TimeSource* GetTimeSource() override; 88 TimeSource* GetTimeSource() override;
87 void Flush(const base::Closure& callback) override; 89 void Flush(const base::Closure& callback) override;
88 void StartPlaying() override; 90 void StartPlaying() override;
89 void SetVolume(float volume) override; 91 void SetVolume(float volume) override;
90 92
93 // base::PowerObserver implementation.
94 void OnSuspend() override;
95 void OnResume() override;
96
91 private: 97 private:
92 friend class AudioRendererImplTest; 98 friend class AudioRendererImplTest;
93 99
94 // Important detail: being in kPlaying doesn't imply that audio is being 100 // Important detail: being in kPlaying doesn't imply that audio is being
95 // rendered. Rather, it means that the renderer is ready to go. The actual 101 // rendered. Rather, it means that the renderer is ready to go. The actual
96 // rendering of audio is controlled via Start/StopRendering(). 102 // rendering of audio is controlled via Start/StopRendering().
97 // 103 //
98 // kUninitialized 104 // kUninitialized
99 // | Initialize() 105 // | Initialize()
100 // | 106 // |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 base::TimeTicks stop_rendering_time_; 288 base::TimeTicks stop_rendering_time_;
283 289
284 // Set upon receipt of the first decoded buffer after a StartPlayingFrom(). 290 // Set upon receipt of the first decoded buffer after a StartPlayingFrom().
285 // Used to determine how long to delay playback. 291 // Used to determine how long to delay playback.
286 base::TimeDelta first_packet_timestamp_; 292 base::TimeDelta first_packet_timestamp_;
287 293
288 // Set by CurrentMediaTime(), used to prevent the current media time value as 294 // Set by CurrentMediaTime(), used to prevent the current media time value as
289 // reported to JavaScript from going backwards in time. 295 // reported to JavaScript from going backwards in time.
290 base::TimeDelta last_media_timestamp_; 296 base::TimeDelta last_media_timestamp_;
291 297
298 // Set by OnSuspend() and OnResume() to indicate when the system is about to
299 // suspend/is suspended and when it resumes.
300 bool is_suspending_;
301
292 // End variables which must be accessed under |lock_|. ---------------------- 302 // End variables which must be accessed under |lock_|. ----------------------
293 303
294 // NOTE: Weak pointers must be invalidated before all other member variables. 304 // NOTE: Weak pointers must be invalidated before all other member variables.
295 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; 305 base::WeakPtrFactory<AudioRendererImpl> weak_factory_;
296 306
297 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); 307 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl);
298 }; 308 };
299 309
300 } // namespace media 310 } // namespace media
301 311
302 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ 312 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | media/renderers/audio_renderer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698