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

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

Issue 1990303002: Moving FIFO from AudioDestination to RendererWebAudioDeviceImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix for android compilation error 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
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/cancelable_callback.h" 10 #include "base/cancelable_callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
14 #include "media/base/audio_parameters.h" 14 #include "media/base/audio_parameters.h"
15 #include "media/base/audio_renderer_sink.h" 15 #include "media/base/audio_renderer_sink.h"
16 #include "third_party/WebKit/public/platform/WebAudioDevice.h" 16 #include "third_party/WebKit/public/platform/WebAudioDevice.h"
17 #include "third_party/WebKit/public/platform/WebVector.h" 17 #include "third_party/WebKit/public/platform/WebVector.h"
18 #include "url/origin.h" 18 #include "url/origin.h"
19 19
20 namespace base { 20 namespace base {
21 class SingleThreadTaskRunner; 21 class SingleThreadTaskRunner;
22 } 22 }
23 23
24 namespace media { 24 namespace media {
25 class NullAudioSink; 25 class NullAudioSink;
26 class AudioPullFifo;
26 } 27 }
27 28
28 namespace content { 29 namespace content {
29 30
30 class RendererWebAudioDeviceImpl 31 class RendererWebAudioDeviceImpl
31 : public blink::WebAudioDevice, 32 : public blink::WebAudioDevice,
32 public media::AudioRendererSink::RenderCallback { 33 public media::AudioRendererSink::RenderCallback {
33 public: 34 public:
34 RendererWebAudioDeviceImpl(const media::AudioParameters& params, 35 RendererWebAudioDeviceImpl(const media::AudioParameters& params,
35 blink::WebAudioDevice::RenderCallback* callback, 36 blink::WebAudioDevice::RenderCallback* callback,
36 int session_id, 37 int session_id,
37 const url::Origin& security_origin); 38 const url::Origin& security_origin);
38 ~RendererWebAudioDeviceImpl() override; 39 ~RendererWebAudioDeviceImpl() override;
39 40
40 // blink::WebAudioDevice implementation. 41 // blink::WebAudioDevice implementation.
41 void start() override; 42 void start() override;
42 void stop() override; 43 void stop() override;
43 double sampleRate() override; 44 double sampleRate() override;
44 45
45 // AudioRendererSink::RenderCallback implementation. 46 // AudioRendererSink::RenderCallback implementation.
46 int Render(media::AudioBus* dest, 47 int Render(media::AudioBus* dest,
47 uint32_t frames_delayed, 48 uint32_t frames_delayed,
48 uint32_t frames_skipped) override; 49 uint32_t frames_skipped) override;
49 50
50 void OnRenderError() override; 51 void OnRenderError() override;
51 52
52 private: 53 private:
53 const media::AudioParameters params_; 54 // Called by AudioPullFifo when more data is necessary.
55 void SourceCallback(int fifo_frames_delay, media::AudioBus* audio_bus);
56
57 // Creates a FIFO to rebuffer audio between the client and the sink.
58 void CreateFifoIfRequired(int render_frames_per_buffer);
59
60 // Parameters of audio being pulled from the client.
61 const media::AudioParameters client_params_;
54 62
55 // Weak reference to the callback into WebKit code. 63 // Weak reference to the callback into WebKit code.
56 blink::WebAudioDevice::RenderCallback* const client_callback_; 64 blink::WebAudioDevice::RenderCallback* const client_callback_;
57 65
58 // To avoid the need for locking, ensure the control methods of the 66 // To avoid the need for locking, ensure the control methods of the
59 // blink::WebAudioDevice implementation are called on the same thread. 67 // blink::WebAudioDevice implementation are called on the same thread.
60 base::ThreadChecker thread_checker_; 68 base::ThreadChecker thread_checker_;
61 69
62 // When non-NULL, we are started. When NULL, we are stopped. 70 // When non-NULL, we are started. When NULL, we are stopped.
63 scoped_refptr<media::AudioRendererSink> sink_; 71 scoped_refptr<media::AudioRendererSink> sink_;
(...skipping 21 matching lines...) Expand all
85 93
86 bool is_first_buffer_after_silence_; 94 bool is_first_buffer_after_silence_;
87 95
88 // A cancelable task that is posted to start the |null_audio_sink_| after a 96 // A cancelable task that is posted to start the |null_audio_sink_| after a
89 // period of silence. We do this on android to save battery consumption. 97 // period of silence. We do this on android to save battery consumption.
90 base::CancelableClosure start_null_audio_sink_callback_; 98 base::CancelableClosure start_null_audio_sink_callback_;
91 99
92 // Security origin, used to check permissions for |output_device_|. 100 // Security origin, used to check permissions for |output_device_|.
93 url::Origin security_origin_; 101 url::Origin security_origin_;
94 102
103 // Used to buffer data between the client and the sink in cases where
104 // the client buffer size is not the same as rendering buffer size.
105 std::unique_ptr<media::AudioPullFifo> audio_fifo_;
106
95 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl); 107 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl);
96 }; 108 };
97 109
98 } // namespace content 110 } // namespace content
99 111
100 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ 112 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698