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 "wtf/Allocator.h" | 36 #include "wtf/Allocator.h" |
37 #include "wtf/Noncopyable.h" | 37 #include "wtf/Noncopyable.h" |
38 #include "wtf/text/WTFString.h" | 38 #include "wtf/text/WTFString.h" |
39 #include <memory> | 39 #include <memory> |
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*>& destinationData, | 71 void render(const WebVector<float*>& destinationData, |
71 size_t numberOfFrames, | 72 size_t numberOfFrames, |
72 double delay, | 73 double delay, |
73 double delayTimestamp, | 74 double delayTimestamp, |
74 size_t priorFramesSkipped) override; | 75 size_t priorFramesSkipped) override; |
75 | 76 |
| 77 void requestRenderOnWebThread(size_t numberOfFrames, |
| 78 double delay, |
| 79 double delayTimestamp, |
| 80 size_t priorFramesSkipped); |
| 81 |
76 virtual void start(); | 82 virtual void start(); |
77 virtual void stop(); | 83 virtual void stop(); |
78 | 84 |
79 size_t callbackBufferSize() const { return m_callbackBufferSize; } | 85 size_t callbackBufferSize() const { return m_callbackBufferSize; } |
80 bool isPlaying() { return m_isPlaying; } | 86 bool isPlaying() { return m_isPlaying; } |
81 | 87 |
82 double sampleRate() const { return m_webAudioDevice->sampleRate(); } | 88 double sampleRate() const { return m_webAudioDevice->sampleRate(); } |
83 | 89 |
84 // Returns the audio buffer size in frames used by the underlying audio | 90 // Returns the audio buffer size in frames used by the underlying audio |
85 // hardware. | 91 // hardware. |
86 int framesPerBuffer() const { return m_webAudioDevice->framesPerBuffer(); } | 92 int framesPerBuffer() const { return m_webAudioDevice->framesPerBuffer(); } |
87 | 93 |
88 // The information from the actual audio hardware. (via Platform::current) | 94 // The information from the actual audio hardware. (via Platform::current) |
89 static float hardwareSampleRate(); | 95 static float hardwareSampleRate(); |
90 static unsigned long maxChannelCount(); | 96 static unsigned long maxChannelCount(); |
91 | 97 |
92 private: | 98 private: |
93 std::unique_ptr<WebAudioDevice> m_webAudioDevice; | 99 std::unique_ptr<WebAudioDevice> m_webAudioDevice; |
94 unsigned m_numberOfOutputChannels; | 100 unsigned m_numberOfOutputChannels; |
95 size_t m_callbackBufferSize; | 101 size_t m_callbackBufferSize; |
96 bool m_isPlaying; | 102 bool m_isPlaying; |
97 | 103 |
| 104 // WebThread for WebAudio rendering. |
| 105 std::unique_ptr<WebThread> m_renderingThread; |
| 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& m_callback; | 108 AudioIOCallback& m_callback; |
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> m_outputBus; | 111 RefPtr<AudioBus> m_outputBus; |
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> m_renderBus; | 114 RefPtr<AudioBus> m_renderBus; |
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> m_fifo; | 118 std::unique_ptr<PushPullFIFO> m_fifo; |
110 | 119 |
111 size_t m_framesElapsed; | 120 size_t m_framesElapsed; |
112 AudioIOPosition m_outputPosition; | 121 AudioIOPosition m_outputPosition; |
113 base::TimeTicks m_outputPositionReceivedTimestamp; | 122 base::TimeTicks m_outputPositionReceivedTimestamp; |
114 | 123 |
115 // Check if the buffer size chosen by the WebAudioDevice is too large. | 124 // Check if the buffer size chosen by the WebAudioDevice is too large. |
116 bool checkBufferSize(); | 125 bool checkBufferSize(); |
117 | 126 |
118 size_t hardwareBufferSize(); | 127 size_t hardwareBufferSize(); |
119 }; | 128 }; |
120 | 129 |
121 } // namespace blink | 130 } // namespace blink |
122 | 131 |
123 #endif // AudioDestination_h | 132 #endif // AudioDestination_h |
OLD | NEW |