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

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

Issue 1195633003: Add a silent audio sink to consume WebAudio data on silence detection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ifdef android only constants Created 5 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 | 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 "base/cancelable_callback.h"
8 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
9 #include "base/threading/thread_checker.h" 10 #include "base/threading/thread_checker.h"
10 #include "media/audio/audio_parameters.h" 11 #include "media/audio/audio_parameters.h"
11 #include "media/base/audio_renderer_sink.h" 12 #include "media/base/audio_renderer_sink.h"
12 #include "third_party/WebKit/public/platform/WebAudioDevice.h" 13 #include "third_party/WebKit/public/platform/WebAudioDevice.h"
13 #include "third_party/WebKit/public/platform/WebVector.h" 14 #include "third_party/WebKit/public/platform/WebVector.h"
14 15
16 namespace base {
17 class SingleThreadTaskRunner;
18 }
19
15 namespace media { 20 namespace media {
16 class AudioOutputDevice; 21 class AudioOutputDevice;
22 class NullAudioSink;
17 } 23 }
18 24
19 namespace content { 25 namespace content {
20 26
21 class RendererWebAudioDeviceImpl 27 class RendererWebAudioDeviceImpl
22 : public blink::WebAudioDevice, 28 : public blink::WebAudioDevice,
23 public media::AudioRendererSink::RenderCallback { 29 public media::AudioRendererSink::RenderCallback {
24 public: 30 public:
25 RendererWebAudioDeviceImpl(const media::AudioParameters& params, 31 RendererWebAudioDeviceImpl(const media::AudioParameters& params,
26 blink::WebAudioDevice::RenderCallback* callback, 32 blink::WebAudioDevice::RenderCallback* callback,
(...skipping 19 matching lines...) Expand all
46 // To avoid the need for locking, ensure the control methods of the 52 // To avoid the need for locking, ensure the control methods of the
47 // blink::WebAudioDevice implementation are called on the same thread. 53 // blink::WebAudioDevice implementation are called on the same thread.
48 base::ThreadChecker thread_checker_; 54 base::ThreadChecker thread_checker_;
49 55
50 // When non-NULL, we are started. When NULL, we are stopped. 56 // When non-NULL, we are started. When NULL, we are stopped.
51 scoped_refptr<media::AudioOutputDevice> output_device_; 57 scoped_refptr<media::AudioOutputDevice> output_device_;
52 58
53 // ID to allow browser to select the correct input device for unified IO. 59 // ID to allow browser to select the correct input device for unified IO.
54 int session_id_; 60 int session_id_;
55 61
62 // Timeticks when the silence starts.
63 base::TimeTicks first_silence_time_ ;
64
65 // TaskRunner to post callbacks to the render thread.
66 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
67
68 // A fake audio sink object that consumes data when long period of silence
69 // audio is detected. This object lives on the render thread.
70 scoped_refptr<media::NullAudioSink> null_audio_sink_;
71
72 // Whether audio output is directed to |null_audio_sink_|.
73 bool is_using_null_audio_sink_;
74
75 // First audio buffer after silence finishes. We store this buffer so that
76 // it can be sent to the |output_device_| later after switching from
77 // |null_audio_sink_|.
78 scoped_ptr<media::AudioBus> first_buffer_after_silence_;
79
80 bool is_first_buffer_after_silence_;
81
82 // A cancelable task that is posted to start the |null_audio_sink_| after a
83 // period of silence. We do this on android to save battery consumption.
84 base::CancelableClosure start_null_audio_sink_callback_;
85
56 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl); 86 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl);
57 }; 87 };
58 88
59 } // namespace content 89 } // namespace content
60 90
61 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ 91 #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