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 18 matching lines...) Expand all Loading... |
29 #ifndef AudioDestination_h | 29 #ifndef AudioDestination_h |
30 #define AudioDestination_h | 30 #define AudioDestination_h |
31 | 31 |
32 #include "platform/audio/AudioBus.h" | 32 #include "platform/audio/AudioBus.h" |
33 #include "platform/audio/AudioIOCallback.h" | 33 #include "platform/audio/AudioIOCallback.h" |
34 #include "platform/audio/AudioSourceProvider.h" | 34 #include "platform/audio/AudioSourceProvider.h" |
35 #include "public/platform/WebAudioDevice.h" | 35 #include "public/platform/WebAudioDevice.h" |
36 #include "public/platform/WebVector.h" | 36 #include "public/platform/WebVector.h" |
37 #include "wtf/Allocator.h" | 37 #include "wtf/Allocator.h" |
38 #include "wtf/Noncopyable.h" | 38 #include "wtf/Noncopyable.h" |
39 #include "wtf/PassRefPtr.h" | |
40 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
41 #include <memory> | 40 #include <memory> |
42 | 41 |
43 namespace blink { | 42 namespace blink { |
44 | 43 |
45 class AudioPullFIFO; | 44 class AudioPullFIFO; |
46 class SecurityOrigin; | 45 class SecurityOrigin; |
47 | 46 |
48 // An AudioDestination using Chromium's audio system | 47 // The AudioDestination class is an audio sink interface between the media |
49 | 48 // 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 // audio callback. |
50 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback, | 51 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback, |
51 public AudioSourceProvider { | 52 public AudioSourceProvider { |
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: |
56 AudioDestination(AudioIOCallback&, | 57 AudioDestination(AudioIOCallback&, |
57 const String& inputDeviceId, | |
58 unsigned numberOfInputChannels, | |
59 unsigned numberOfOutputChannels, | 58 unsigned numberOfOutputChannels, |
60 float sampleRate, | 59 float sampleRate, |
61 PassRefPtr<SecurityOrigin>); | 60 PassRefPtr<SecurityOrigin>); |
62 ~AudioDestination() override; | 61 ~AudioDestination() override; |
63 | 62 |
64 // Pass in (numberOfInputChannels > 0) if live/local audio input is desired. | |
65 // Port-specific device identification information for live/local input | |
66 // streams can be passed in the inputDeviceId. | |
67 static std::unique_ptr<AudioDestination> create( | 63 static std::unique_ptr<AudioDestination> create( |
68 AudioIOCallback&, | 64 AudioIOCallback&, |
69 const String& inputDeviceId, | |
70 unsigned numberOfInputChannels, | |
71 unsigned numberOfOutputChannels, | 65 unsigned numberOfOutputChannels, |
72 float sampleRate, | 66 float sampleRate, |
73 PassRefPtr<SecurityOrigin>); | 67 PassRefPtr<SecurityOrigin>); |
74 | 68 |
75 virtual void start(); | 69 // The actual render function (WebAudioDevice::RenderCallback) isochronously |
76 virtual void stop(); | 70 // invoked by the media renderer. |
77 bool isPlaying() { return m_isPlaying; } | 71 void render(const WebVector<float*>& destinationData, |
78 | |
79 float sampleRate() const { return m_sampleRate; } | |
80 | |
81 // WebAudioDevice::RenderCallback | |
82 void render(const WebVector<float*>& audioData, | |
83 size_t numberOfFrames, | 72 size_t numberOfFrames, |
84 double delay, | 73 double delay, |
85 double delayTimestamp, | 74 double delayTimestamp, |
86 size_t priorFramesSkipped) override; | 75 size_t priorFramesSkipped) override; |
87 | 76 |
88 // AudioSourceProvider | 77 // AudioSourceProvider (FIFO) |
89 void provideInput(AudioBus*, size_t framesToProcess) override; | 78 void provideInput(AudioBus* outputBus, size_t framesToProcess) override; |
90 | 79 |
91 static float hardwareSampleRate(); | 80 virtual void start(); |
| 81 virtual void stop(); |
92 | 82 |
93 size_t callbackBufferSize() const { return m_callbackBufferSize; } | 83 size_t callbackBufferSize() const { return m_callbackBufferSize; } |
| 84 float sampleRate() const { return m_sampleRate; } |
| 85 bool isPlaying() { return m_isPlaying; } |
94 | 86 |
95 // maxChannelCount() returns the total number of output channels of the audio | 87 // The information from the actual audio hardware. (via Platform::current) |
96 // hardware. A value of 0 indicates that the number of channels cannot be | 88 static float hardwareSampleRate(); |
97 // configured and that only stereo (2-channel) destinations can be created. | |
98 // The numberOfOutputChannels parameter of AudioDestination::create() is | |
99 // allowed to be a value: 1 <= numberOfOutputChannels <= maxChannelCount(), | |
100 // or if maxChannelCount() equals 0, then numberOfOutputChannels must be 2. | |
101 static unsigned long maxChannelCount(); | 89 static unsigned long maxChannelCount(); |
102 | 90 |
103 private: | 91 private: |
104 AudioIOCallback& m_callback; | 92 std::unique_ptr<WebAudioDevice> m_webAudioDevice; |
105 unsigned m_numberOfOutputChannels; | 93 unsigned m_numberOfOutputChannels; |
106 RefPtr<AudioBus> m_renderBus; | 94 size_t m_callbackBufferSize; |
107 float m_sampleRate; | 95 float m_sampleRate; |
108 bool m_isPlaying; | 96 bool m_isPlaying; |
109 std::unique_ptr<WebAudioDevice> m_audioDevice; | |
110 size_t m_callbackBufferSize; | |
111 | 97 |
| 98 // The render callback function of WebAudio engine. (i.e. DestinationNode) |
| 99 AudioIOCallback& m_callback; |
| 100 |
| 101 RefPtr<AudioBus> m_outputBus; |
112 std::unique_ptr<AudioPullFIFO> m_fifo; | 102 std::unique_ptr<AudioPullFIFO> m_fifo; |
113 | 103 |
114 size_t m_framesElapsed; | 104 size_t m_framesElapsed; |
115 AudioIOPosition m_outputPosition; | 105 AudioIOPosition m_outputPosition; |
116 base::TimeTicks m_outputPositionReceivedTimestamp; | 106 base::TimeTicks m_outputPositionReceivedTimestamp; |
| 107 |
| 108 // Calculate the optimum buffer size for a given platform. Return false if the |
| 109 // buffer size calculation fails. |
| 110 bool calculateBufferSize(); |
| 111 |
| 112 size_t hardwareBufferSize(); |
117 }; | 113 }; |
118 | 114 |
119 } // namespace blink | 115 } // namespace blink |
120 | 116 |
121 #endif // AudioDestination_h | 117 #endif // AudioDestination_h |
OLD | NEW |