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 // FIFO calls back this function when more data is needed to fulfill the |
| 78 // request from AudioDeviceThread. |
| 79 void RequestRender(double delay, |
| 80 double delay_timestamp, |
| 81 size_t prior_frames_skipped, |
| 82 size_t frames_requested, |
| 83 size_t frames_to_render); |
| 84 |
| 85 // The actual render request to the WebAudio destination node. This triggers |
| 86 // the WebAudio rendering pipe line on the web thread. |
| 87 void RequestRenderOnWebThread(size_t frames_requested, |
| 88 size_t frames_to_render, |
| 89 double delay, |
| 90 double delay_timestamp, |
| 91 size_t prior_frames_skipped); |
| 92 |
76 virtual void Start(); | 93 virtual void Start(); |
77 virtual void Stop(); | 94 virtual void Stop(); |
78 | 95 |
79 size_t CallbackBufferSize() const { return callback_buffer_size_; } | 96 size_t CallbackBufferSize() const { return callback_buffer_size_; } |
80 bool IsPlaying() { return is_playing_; } | 97 bool IsPlaying() { return is_playing_; } |
81 | 98 |
82 double SampleRate() const { return web_audio_device_->SampleRate(); } | 99 double SampleRate() const { return web_audio_device_->SampleRate(); } |
83 | 100 |
84 // Returns the audio buffer size in frames used by the underlying audio | 101 // Returns the audio buffer size in frames used by the underlying audio |
85 // hardware. | 102 // hardware. |
(...skipping 15 matching lines...) Expand all Loading... |
101 // To pass the data from FIFO to the audio device callback. | 118 // To pass the data from FIFO to the audio device callback. |
102 RefPtr<AudioBus> output_bus_; | 119 RefPtr<AudioBus> output_bus_; |
103 | 120 |
104 // To push the rendered result from WebAudio graph into the FIFO. | 121 // To push the rendered result from WebAudio graph into the FIFO. |
105 RefPtr<AudioBus> render_bus_; | 122 RefPtr<AudioBus> render_bus_; |
106 | 123 |
107 // Resolves the buffer size mismatch between the WebAudio engine and | 124 // Resolves the buffer size mismatch between the WebAudio engine and |
108 // the callback function from the actual audio device. | 125 // the callback function from the actual audio device. |
109 std::unique_ptr<PushPullFIFO> fifo_; | 126 std::unique_ptr<PushPullFIFO> fifo_; |
110 | 127 |
| 128 // WebThread for WebAudio rendering. |
| 129 std::unique_ptr<WebThread> rendering_thread_; |
| 130 |
111 size_t frames_elapsed_; | 131 size_t frames_elapsed_; |
112 AudioIOPosition output_position_; | 132 AudioIOPosition output_position_; |
113 base::TimeTicks output_position_received_timestamp_; | 133 base::TimeTicks output_position_received_timestamp_; |
114 | 134 |
115 // Check if the buffer size chosen by the WebAudioDevice is too large. | 135 // Check if the buffer size chosen by the WebAudioDevice is too large. |
116 bool CheckBufferSize(); | 136 bool CheckBufferSize(); |
117 | 137 |
118 size_t HardwareBufferSize(); | 138 size_t HardwareBufferSize(); |
| 139 |
| 140 bool IsRenderingThread(); |
119 }; | 141 }; |
120 | 142 |
121 } // namespace blink | 143 } // namespace blink |
122 | 144 |
123 #endif // AudioDestination_h | 145 #endif // AudioDestination_h |
OLD | NEW |