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

Side by Side Diff: content/renderer/media/renderer_webaudiodevice_impl.h

Issue 2382473002: Merge M54: "Break out WebAudio suspension code into new class. Add tests." (Closed)
Patch Set: Fix conflicts. Created 4 years, 2 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 | content/renderer/media/renderer_webaudiodevice_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 #ifndef CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ 6 #define CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/atomic_ref_count.h"
11 #include "base/cancelable_callback.h"
12 #include "base/macros.h" 10 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
14 #include "base/threading/thread_checker.h" 12 #include "base/threading/thread_checker.h"
15 #include "media/base/audio_parameters.h" 13 #include "media/base/audio_parameters.h"
16 #include "media/base/audio_renderer_sink.h" 14 #include "media/base/audio_renderer_sink.h"
17 #include "third_party/WebKit/public/platform/WebAudioDevice.h" 15 #include "third_party/WebKit/public/platform/WebAudioDevice.h"
18 #include "third_party/WebKit/public/platform/WebVector.h" 16 #include "third_party/WebKit/public/platform/WebVector.h"
19 #include "url/origin.h" 17 #include "url/origin.h"
20 18
21 namespace base { 19 namespace base {
22 class SingleThreadTaskRunner; 20 class SingleThreadTaskRunner;
23 } 21 }
24 22
25 namespace media { 23 namespace media {
26 class NullAudioSink; 24 class SilentSinkSuspender;
27 } 25 }
28 26
29 namespace content { 27 namespace content {
30
31 class RendererWebAudioDeviceImpl 28 class RendererWebAudioDeviceImpl
32 : public blink::WebAudioDevice, 29 : public blink::WebAudioDevice,
33 public media::AudioRendererSink::RenderCallback { 30 public media::AudioRendererSink::RenderCallback {
34 public: 31 public:
35 RendererWebAudioDeviceImpl(const media::AudioParameters& params, 32 RendererWebAudioDeviceImpl(const media::AudioParameters& params,
36 blink::WebAudioDevice::RenderCallback* callback, 33 blink::WebAudioDevice::RenderCallback* callback,
37 int session_id, 34 int session_id,
38 const url::Origin& security_origin); 35 const url::Origin& security_origin);
39 ~RendererWebAudioDeviceImpl() override; 36 ~RendererWebAudioDeviceImpl() override;
40 37
(...skipping 15 matching lines...) Expand all
56 // Weak reference to the callback into WebKit code. 53 // Weak reference to the callback into WebKit code.
57 blink::WebAudioDevice::RenderCallback* const client_callback_; 54 blink::WebAudioDevice::RenderCallback* const client_callback_;
58 55
59 // To avoid the need for locking, ensure the control methods of the 56 // To avoid the need for locking, ensure the control methods of the
60 // blink::WebAudioDevice implementation are called on the same thread. 57 // blink::WebAudioDevice implementation are called on the same thread.
61 base::ThreadChecker thread_checker_; 58 base::ThreadChecker thread_checker_;
62 59
63 // When non-NULL, we are started. When NULL, we are stopped. 60 // When non-NULL, we are started. When NULL, we are stopped.
64 scoped_refptr<media::AudioRendererSink> sink_; 61 scoped_refptr<media::AudioRendererSink> sink_;
65 62
66 // TODO(miu): Remove this temporary instrumentation to root-cause a memory
67 // use-after-free issue. http://crbug.com/619463
68 base::AtomicRefCount sink_is_running_;
69
70 // ID to allow browser to select the correct input device for unified IO. 63 // ID to allow browser to select the correct input device for unified IO.
71 int session_id_; 64 int session_id_;
72 65
73 // Timeticks when the silence starts.
74 base::TimeTicks first_silence_time_ ;
75
76 // TaskRunner to post callbacks to the render thread.
77 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
78
79 // A fake audio sink object that consumes data when long period of silence
80 // audio is detected. This object lives on the render thread.
81 scoped_refptr<media::NullAudioSink> null_audio_sink_;
82
83 // Whether audio output is directed to |null_audio_sink_|.
84 bool is_using_null_audio_sink_;
85
86 // First audio buffer after silence finishes. We store this buffer so that
87 // it can be sent to the |output_device_| later after switching from
88 // |null_audio_sink_|.
89 std::unique_ptr<media::AudioBus> first_buffer_after_silence_;
90
91 bool is_first_buffer_after_silence_;
92
93 // A cancelable task that is posted to start the |null_audio_sink_| after a
94 // period of silence. We do this on android to save battery consumption.
95 base::CancelableClosure start_null_audio_sink_callback_;
96
97 // Security origin, used to check permissions for |output_device_|. 66 // Security origin, used to check permissions for |output_device_|.
98 url::Origin security_origin_; 67 url::Origin security_origin_;
99 68
69 // Used to suspend |sink_| usage when silence has been detected for too long.
70 std::unique_ptr<media::SilentSinkSuspender> webaudio_suspender_;
71
100 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl); 72 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl);
101 }; 73 };
102 74
103 } // namespace content 75 } // namespace content
104 76
105 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ 77 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/renderer_webaudiodevice_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698