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_; | |
94 unsigned number_of_output_channels_; | |
95 size_t callback_buffer_size_; | |
96 bool is_playing_; | |
97 | |
98 // The render callback function of WebAudio engine. (i.e. DestinationNode) | |
99 AudioIOCallback& callback_; | |
100 | |
101 // To pass the data from FIFO to the audio device callback. | |
102 RefPtr<AudioBus> output_bus_; | |
103 | |
104 // To push the rendered result from WebAudio graph into the FIFO. | |
105 RefPtr<AudioBus> render_bus_; | |
106 | |
107 // Resolves the buffer size mismatch between the WebAudio engine and | |
108 // the callback function from the actual audio device. | |
109 std::unique_ptr<PushPullFIFO> fifo_; | |
110 | |
111 size_t frames_elapsed_; | |
112 AudioIOPosition output_position_; | |
113 base::TimeTicks output_position_received_timestamp_; | |
114 | |
115 // Check if the buffer size chosen by the WebAudioDevice is too large. | 102 // Check if the buffer size chosen by the WebAudioDevice is too large. |
116 bool CheckBufferSize(); | 103 bool CheckBufferSize(); |
117 | 104 |
118 size_t HardwareBufferSize(); | 105 size_t HardwareBufferSize(); |
| 106 |
| 107 bool IsRenderingThread(); |
| 108 |
| 109 std::unique_ptr<WebAudioDevice> web_audio_device_; |
| 110 const unsigned number_of_output_channels_; |
| 111 size_t callback_buffer_size_; |
| 112 bool is_playing_; |
| 113 |
| 114 // Rendering thread for WebAudio graph. |
| 115 std::unique_ptr<WebThread> rendering_thread_; |
| 116 |
| 117 // Accessed by both threads: resolves the buffer size mismatch between the |
| 118 // WebAudio engine and the callback function from the actual audio device. |
| 119 std::unique_ptr<PushPullFIFO> fifo_; |
| 120 |
| 121 // Accessed by device thread: to pass the data from FIFO to the device. |
| 122 RefPtr<AudioBus> output_bus_; |
| 123 |
| 124 // Accessed by rendering thread: to push the rendered result from WebAudio |
| 125 // graph into the FIFO. |
| 126 RefPtr<AudioBus> render_bus_; |
| 127 |
| 128 // Accessed by rendering thread: the render callback function of WebAudio |
| 129 // engine. (i.e. DestinationNode) |
| 130 AudioIOCallback& callback_; |
| 131 |
| 132 // Accessed by rendering thread. |
| 133 size_t frames_elapsed_; |
119 }; | 134 }; |
120 | 135 |
121 } // namespace blink | 136 } // namespace blink |
122 | 137 |
123 #endif // AudioDestination_h | 138 #endif // AudioDestination_h |
OLD | NEW |