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 24 matching lines...) Expand all Loading... |
35 #include "public/platform/WebVector.h" | 35 #include "public/platform/WebVector.h" |
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 | 46 |
46 // The AudioDestination class is an audio sink interface between the media | 47 // The AudioDestination class is an audio sink interface between the media |
47 // renderer and the Blink's WebAudio module. It has a FIFO to adapt the | 48 // renderer and the Blink's WebAudio module. It has a FIFO to adapt the |
48 // different processing block sizes of WebAudio renderer and actual hardware | 49 // different processing block sizes of WebAudio renderer and actual hardware |
49 // audio callback. | 50 // audio callback. |
50 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback { | 51 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback { |
51 USING_FAST_MALLOC(AudioDestination); | 52 USING_FAST_MALLOC(AudioDestination); |
52 WTF_MAKE_NONCOPYABLE(AudioDestination); | 53 WTF_MAKE_NONCOPYABLE(AudioDestination); |
53 | 54 |
54 public: | 55 public: |
55 AudioDestination(AudioIOCallback&, | 56 AudioDestination(AudioIOCallback&, |
56 unsigned numberOfOutputChannels, | 57 unsigned numberOfOutputChannels, |
57 float sampleRate, | 58 const WebAudioLatencyHint&, |
58 PassRefPtr<SecurityOrigin>); | 59 PassRefPtr<SecurityOrigin>); |
59 ~AudioDestination() override; | 60 ~AudioDestination() override; |
60 | 61 |
61 static std::unique_ptr<AudioDestination> create( | 62 static std::unique_ptr<AudioDestination> create( |
62 AudioIOCallback&, | 63 AudioIOCallback&, |
63 unsigned numberOfOutputChannels, | 64 unsigned numberOfOutputChannels, |
64 float sampleRate, | 65 const WebAudioLatencyHint&, |
65 PassRefPtr<SecurityOrigin>); | 66 PassRefPtr<SecurityOrigin>); |
66 | 67 |
67 // The actual render function (WebAudioDevice::RenderCallback) isochronously | 68 // The actual render function (WebAudioDevice::RenderCallback) isochronously |
68 // invoked by the media renderer. | 69 // invoked by the media renderer. |
69 void render(const WebVector<float*>& destinationData, | 70 void render(const WebVector<float*>& destinationData, |
70 size_t numberOfFrames, | 71 size_t numberOfFrames, |
71 double delay, | 72 double delay, |
72 double delayTimestamp, | 73 double delayTimestamp, |
73 size_t priorFramesSkipped) override; | 74 size_t priorFramesSkipped) override; |
74 | 75 |
75 virtual void start(); | 76 virtual void start(); |
76 virtual void stop(); | 77 virtual void stop(); |
77 | 78 |
78 size_t callbackBufferSize() const { return m_callbackBufferSize; } | 79 size_t callbackBufferSize() const { return m_callbackBufferSize; } |
79 float sampleRate() const { return m_sampleRate; } | |
80 bool isPlaying() { return m_isPlaying; } | 80 bool isPlaying() { return m_isPlaying; } |
81 | 81 |
| 82 double sampleRate() const { return m_webAudioDevice->sampleRate(); } |
| 83 |
| 84 // Returns the audio buffer size in frames used by the underlying audio |
| 85 // hardware. |
| 86 int framesPerBuffer() const { return m_webAudioDevice->framesPerBuffer(); } |
| 87 |
82 // The information from the actual audio hardware. (via Platform::current) | 88 // The information from the actual audio hardware. (via Platform::current) |
83 static float hardwareSampleRate(); | 89 static float hardwareSampleRate(); |
84 static unsigned long maxChannelCount(); | 90 static unsigned long maxChannelCount(); |
85 | 91 |
86 private: | 92 private: |
87 std::unique_ptr<WebAudioDevice> m_webAudioDevice; | 93 std::unique_ptr<WebAudioDevice> m_webAudioDevice; |
88 unsigned m_numberOfOutputChannels; | 94 unsigned m_numberOfOutputChannels; |
89 size_t m_callbackBufferSize; | 95 size_t m_callbackBufferSize; |
90 float m_sampleRate; | |
91 bool m_isPlaying; | 96 bool m_isPlaying; |
92 | 97 |
93 // The render callback function of WebAudio engine. (i.e. DestinationNode) | 98 // The render callback function of WebAudio engine. (i.e. DestinationNode) |
94 AudioIOCallback& m_callback; | 99 AudioIOCallback& m_callback; |
95 | 100 |
96 // To pass the data from FIFO to the audio device callback. | 101 // To pass the data from FIFO to the audio device callback. |
97 RefPtr<AudioBus> m_outputBus; | 102 RefPtr<AudioBus> m_outputBus; |
98 | 103 |
99 // To push the rendered result from WebAudio graph into the FIFO. | 104 // To push the rendered result from WebAudio graph into the FIFO. |
100 RefPtr<AudioBus> m_renderBus; | 105 RefPtr<AudioBus> m_renderBus; |
101 | 106 |
102 // Resolves the buffer size mismatch between the WebAudio engine and | 107 // Resolves the buffer size mismatch between the WebAudio engine and |
103 // the callback function from the actual audio device. | 108 // the callback function from the actual audio device. |
104 std::unique_ptr<PushPullFIFO> m_fifo; | 109 std::unique_ptr<PushPullFIFO> m_fifo; |
105 | 110 |
106 size_t m_framesElapsed; | 111 size_t m_framesElapsed; |
107 AudioIOPosition m_outputPosition; | 112 AudioIOPosition m_outputPosition; |
108 base::TimeTicks m_outputPositionReceivedTimestamp; | 113 base::TimeTicks m_outputPositionReceivedTimestamp; |
109 | 114 |
110 // Calculate the optimum buffer size for a given platform. Return false if the | 115 // Check if the buffer size chosen by the WebAudioDevice is too large. |
111 // buffer size calculation fails. | 116 bool checkBufferSize(); |
112 bool calculateBufferSize(); | |
113 | 117 |
114 size_t hardwareBufferSize(); | 118 size_t hardwareBufferSize(); |
115 }; | 119 }; |
116 | 120 |
117 } // namespace blink | 121 } // namespace blink |
118 | 122 |
119 #endif // AudioDestination_h | 123 #endif // AudioDestination_h |
OLD | NEW |