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 #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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/weak_ptr.h" | |
DaleCurtis
2015/06/22 22:49:42
Remove?
qinmin
2015/06/23 00:01:54
Done.
| |
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 AudioTimestampHelper; | |
DaleCurtis
2015/06/22 22:49:42
Remove?
qinmin
2015/06/23 00:01:54
Done.
| |
23 class NullAudioSink; | |
17 } | 24 } |
18 | 25 |
19 namespace content { | 26 namespace content { |
20 | 27 |
21 class RendererWebAudioDeviceImpl | 28 class RendererWebAudioDeviceImpl |
22 : public blink::WebAudioDevice, | 29 : public blink::WebAudioDevice, |
23 public media::AudioRendererSink::RenderCallback { | 30 public media::AudioRendererSink::RenderCallback { |
24 public: | 31 public: |
25 RendererWebAudioDeviceImpl(const media::AudioParameters& params, | 32 RendererWebAudioDeviceImpl(const media::AudioParameters& params, |
26 blink::WebAudioDevice::RenderCallback* callback, | 33 blink::WebAudioDevice::RenderCallback* callback, |
27 int session_id); | 34 int session_id); |
28 virtual ~RendererWebAudioDeviceImpl(); | 35 virtual ~RendererWebAudioDeviceImpl(); |
29 | 36 |
30 // blink::WebAudioDevice implementation. | 37 // blink::WebAudioDevice implementation. |
31 virtual void start(); | 38 virtual void start(); |
32 virtual void stop(); | 39 virtual void stop(); |
33 virtual double sampleRate(); | 40 virtual double sampleRate(); |
34 | 41 |
35 // AudioRendererSink::RenderCallback implementation. | 42 // AudioRendererSink::RenderCallback implementation. |
36 int Render(media::AudioBus* dest, int audio_delay_milliseconds) override; | 43 int Render(media::AudioBus* dest, int audio_delay_milliseconds) override; |
37 | 44 |
38 void OnRenderError() override; | 45 void OnRenderError() override; |
39 | 46 |
40 private: | 47 private: |
48 // Helper method to start and stop the |null_audio_sink_|. | |
DaleCurtis
2015/06/22 22:49:43
Remove?
qinmin
2015/06/23 00:01:54
Done.
| |
49 void StartNullAudioSink(); | |
50 void StopNullAudioSink(); | |
51 | |
41 const media::AudioParameters params_; | 52 const media::AudioParameters params_; |
42 | 53 |
43 // Weak reference to the callback into WebKit code. | 54 // Weak reference to the callback into WebKit code. |
44 blink::WebAudioDevice::RenderCallback* const client_callback_; | 55 blink::WebAudioDevice::RenderCallback* const client_callback_; |
45 | 56 |
46 // To avoid the need for locking, ensure the control methods of the | 57 // To avoid the need for locking, ensure the control methods of the |
47 // blink::WebAudioDevice implementation are called on the same thread. | 58 // blink::WebAudioDevice implementation are called on the same thread. |
48 base::ThreadChecker thread_checker_; | 59 base::ThreadChecker thread_checker_; |
49 | 60 |
50 // When non-NULL, we are started. When NULL, we are stopped. | 61 // When non-NULL, we are started. When NULL, we are stopped. |
51 scoped_refptr<media::AudioOutputDevice> output_device_; | 62 scoped_refptr<media::AudioOutputDevice> output_device_; |
52 | 63 |
53 // ID to allow browser to select the correct input device for unified IO. | 64 // ID to allow browser to select the correct input device for unified IO. |
54 int session_id_; | 65 int session_id_; |
55 | 66 |
67 // Timeticks when the silence starts. | |
68 base::TimeTicks first_silence_time_ ; | |
69 | |
70 // TaskRunner to post callbacks to the render thread. | |
71 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
72 | |
73 // A fake audio sink object that consumes data when long period of silence | |
74 // audio is detected. This object lives on the render thread. | |
75 scoped_refptr<media::NullAudioSink> null_audio_sink_; | |
76 | |
77 // Whether audio output is directed to |null_audio_sink_|. | |
78 bool is_using_null_audio_sink_; | |
79 | |
80 // First audio buffer after silence finishes. We store this buffer so that | |
81 // it can be sent to the |output_device_| later after switching from | |
82 // |null_audio_sink_|. | |
83 scoped_ptr<media::AudioBus> first_buffer_after_silence_; | |
84 | |
85 // Weak pointer for posting callbacks. | |
DaleCurtis
2015/06/22 22:49:42
Remove these?
qinmin
2015/06/23 00:01:54
Done.
| |
86 base::WeakPtr<RendererWebAudioDeviceImpl> weak_this_; | |
87 // NOTE: Weak pointers must be invalidated before all other member variables. | |
88 base::WeakPtrFactory<RendererWebAudioDeviceImpl> weak_factory_; | |
89 | |
56 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl); | 90 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl); |
57 }; | 91 }; |
58 | 92 |
59 } // namespace content | 93 } // namespace content |
60 | 94 |
61 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ | 95 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ |
OLD | NEW |