OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 25 matching lines...) Expand all Loading... | |
36 #include "platform/wtf/Noncopyable.h" | 36 #include "platform/wtf/Noncopyable.h" |
37 #include "platform/wtf/text/WTFString.h" | 37 #include "platform/wtf/text/WTFString.h" |
38 #include "public/platform/WebAudioDevice.h" | 38 #include "public/platform/WebAudioDevice.h" |
39 #include "public/platform/WebVector.h" | 39 #include "public/platform/WebVector.h" |
40 | 40 |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
43 class PushPullFIFO; | 43 class PushPullFIFO; |
44 class SecurityOrigin; | 44 class SecurityOrigin; |
45 class WebAudioLatencyHint; | 45 class WebAudioLatencyHint; |
46 class WebThread; | |
46 | 47 |
47 // The AudioDestination class is an audio sink interface between the media | 48 // The AudioDestination class is an audio sink interface between the media |
48 // renderer and the Blink's WebAudio module. It has a FIFO to adapt the | 49 // renderer and the Blink's WebAudio module. It has a FIFO to adapt the |
49 // different processing block sizes of WebAudio renderer and actual hardware | 50 // different processing block sizes of WebAudio renderer and actual hardware |
50 // audio callback. | 51 // audio callback. |
51 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback { | 52 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback { |
52 USING_FAST_MALLOC(AudioDestination); | 53 USING_FAST_MALLOC(AudioDestination); |
53 WTF_MAKE_NONCOPYABLE(AudioDestination); | 54 WTF_MAKE_NONCOPYABLE(AudioDestination); |
54 | 55 |
55 public: | 56 public: |
(...skipping 10 matching lines...) Expand all Loading... | |
66 PassRefPtr<SecurityOrigin>); | 67 PassRefPtr<SecurityOrigin>); |
67 | 68 |
68 // The actual render function (WebAudioDevice::RenderCallback) isochronously | 69 // The actual render function (WebAudioDevice::RenderCallback) isochronously |
69 // invoked by the media renderer. | 70 // invoked by the media renderer. |
70 void Render(const WebVector<float*>& destination_data, | 71 void Render(const WebVector<float*>& destination_data, |
71 size_t number_of_frames, | 72 size_t number_of_frames, |
72 double delay, | 73 double delay, |
73 double delay_timestamp, | 74 double delay_timestamp, |
74 size_t prior_frames_skipped) override; | 75 size_t prior_frames_skipped) override; |
75 | 76 |
77 // The actual render request to the WebAudio destination node. This triggers | |
78 // the WebAudio rendering pipe line on the web thread. | |
79 void RequestRenderOnWebThread(size_t frames_requested, | |
80 size_t frames_to_render, | |
81 double delay, | |
82 double delay_timestamp, | |
83 size_t prior_frames_skipped); | |
84 | |
76 virtual void Start(); | 85 virtual void Start(); |
77 virtual void Stop(); | 86 virtual void Stop(); |
78 | 87 |
79 size_t CallbackBufferSize() const { return callback_buffer_size_; } | 88 size_t CallbackBufferSize() const { return callback_buffer_size_; } |
80 bool IsPlaying() { return is_playing_; } | 89 bool IsPlaying() { return is_playing_; } |
81 | 90 |
82 double SampleRate() const { return web_audio_device_->SampleRate(); } | 91 double SampleRate() const { return web_audio_device_->SampleRate(); } |
83 | 92 |
84 // Returns the audio buffer size in frames used by the underlying audio | 93 // Returns the audio buffer size in frames used by the underlying audio |
85 // hardware. | 94 // hardware. |
86 int FramesPerBuffer() const { return web_audio_device_->FramesPerBuffer(); } | 95 int FramesPerBuffer() const { return web_audio_device_->FramesPerBuffer(); } |
87 | 96 |
88 // The information from the actual audio hardware. (via Platform::current) | 97 // The information from the actual audio hardware. (via Platform::current) |
89 static float HardwareSampleRate(); | 98 static float HardwareSampleRate(); |
90 static unsigned long MaxChannelCount(); | 99 static unsigned long MaxChannelCount(); |
91 | 100 |
92 private: | 101 private: |
93 std::unique_ptr<WebAudioDevice> web_audio_device_; | 102 std::unique_ptr<WebAudioDevice> web_audio_device_; |
94 unsigned number_of_output_channels_; | 103 unsigned number_of_output_channels_; |
o1ka
2017/04/18 14:14:57
Make it const? (I know it's an old code - we can m
hongchan
2017/04/18 18:16:08
Done.
| |
95 size_t callback_buffer_size_; | 104 size_t callback_buffer_size_; |
96 bool is_playing_; | 105 bool is_playing_; |
97 | 106 |
98 // The render callback function of WebAudio engine. (i.e. DestinationNode) | 107 // The render callback function of WebAudio engine. (i.e. DestinationNode) |
99 AudioIOCallback& callback_; | 108 AudioIOCallback& callback_; |
o1ka
2017/04/18 14:14:57
Side comment: Is it WebKit style to use references
hongchan
2017/04/18 18:16:08
I haven't checked why it was written like this. If
| |
100 | 109 |
101 // To pass the data from FIFO to the audio device callback. | 110 // To pass the data from FIFO to the audio device callback. |
102 RefPtr<AudioBus> output_bus_; | 111 RefPtr<AudioBus> output_bus_; |
103 | 112 |
104 // To push the rendered result from WebAudio graph into the FIFO. | 113 // To push the rendered result from WebAudio graph into the FIFO. |
105 RefPtr<AudioBus> render_bus_; | 114 RefPtr<AudioBus> render_bus_; |
106 | 115 |
107 // Resolves the buffer size mismatch between the WebAudio engine and | 116 // Resolves the buffer size mismatch between the WebAudio engine and |
108 // the callback function from the actual audio device. | 117 // the callback function from the actual audio device. |
109 std::unique_ptr<PushPullFIFO> fifo_; | 118 std::unique_ptr<PushPullFIFO> fifo_; |
110 | 119 |
120 // WebThread for WebAudio rendering. | |
121 std::unique_ptr<WebThread> rendering_thread_; | |
o1ka
2017/04/18 14:14:57
Could you group data members by thread they are ac
hongchan
2017/04/18 18:16:08
Done.
| |
122 | |
111 size_t frames_elapsed_; | 123 size_t frames_elapsed_; |
112 AudioIOPosition output_position_; | 124 AudioIOPosition output_position_; |
113 base::TimeTicks output_position_received_timestamp_; | 125 base::TimeTicks output_position_received_timestamp_; |
114 | 126 |
115 // Check if the buffer size chosen by the WebAudioDevice is too large. | 127 // Check if the buffer size chosen by the WebAudioDevice is too large. |
116 bool CheckBufferSize(); | 128 bool CheckBufferSize(); |
117 | 129 |
118 size_t HardwareBufferSize(); | 130 size_t HardwareBufferSize(); |
o1ka
2017/04/18 14:14:57
Chromium style is first methods, then members. Is
hongchan
2017/04/18 18:16:08
Not that I know of. Eventually we're merging to Ch
| |
131 | |
132 bool IsRenderingThread(); | |
119 }; | 133 }; |
120 | 134 |
121 } // namespace blink | 135 } // namespace blink |
122 | 136 |
123 #endif // AudioDestination_h | 137 #endif // AudioDestination_h |
OLD | NEW |