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 |
Raymond Toy
2016/12/22 16:59:59
s/and the/and/
hongchan
2016/12/22 17:19:49
Acknowledged.
hongchan
2016/12/22 18:59:46
Done.
| |
49 // different frequency of WebAudio renderer and the actual hardware audio | |
Raymond Toy
2016/12/22 16:59:59
"frequency" may not be the right word here. Maybe
hongchan
2016/12/22 17:19:49
Acknowledged.
hongchan
2016/12/22 18:59:46
Done.
| |
50 // 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(); |
Raymond Toy
2016/12/22 17:00:00
Why move these around?
hongchan
2016/12/22 17:19:49
render() and provideInput() are the core methods o
| |
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; } | |
Raymond Toy
2016/12/22 16:59:59
Why are these no longer static? And why change th
hongchan
2016/12/22 17:19:49
They have never been static. These are regular mem
Raymond Toy
2016/12/22 17:29:38
Sorry. I misread this and the following functions.
| |
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 size_t hardwareBufferSize(); |
97 // configured and that only stereo (2-channel) destinations can be created. | 89 static float hardwareSampleRate(); |
Raymond Toy
2016/12/22 18:38:39
This is a new public API. Who needs it?
hongchan
2016/12/22 18:59:46
This class does. Here's what I am thinking:
- Aud
Raymond Toy
2016/12/22 21:46:06
Yes, but these could be private.
hongchan
2017/01/03 18:50:26
I'll make hardwareBufferSize private, but leave ha
| |
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. | |
Raymond Toy
2016/12/22 17:00:00
Where did this comment go?
hongchan
2016/12/22 17:19:49
First, not sure what these comments mean here. Non
| |
101 static unsigned long maxChannelCount(); | 90 static unsigned long maxChannelCount(); |
102 | 91 |
103 private: | 92 private: |
104 AudioIOCallback& m_callback; | 93 std::unique_ptr<WebAudioDevice> m_webAudioDevice; |
105 unsigned m_numberOfOutputChannels; | 94 unsigned m_numberOfOutputChannels; |
106 RefPtr<AudioBus> m_renderBus; | 95 size_t m_callbackBufferSize; |
107 float m_sampleRate; | 96 float m_sampleRate; |
108 bool m_isPlaying; | 97 bool m_isPlaying; |
109 std::unique_ptr<WebAudioDevice> m_audioDevice; | |
110 size_t m_callbackBufferSize; | |
Raymond Toy
2016/12/22 17:00:00
Why move these things around? The order isn't imp
hongchan
2016/12/22 17:19:49
The right/meaningful order is certainly important
| |
111 | 98 |
99 // The render callback function of WebAudio engine. (i.e. DestinationNode) | |
100 AudioIOCallback& m_callback; | |
101 | |
102 RefPtr<AudioBus> m_outputBus; | |
112 std::unique_ptr<AudioPullFIFO> m_fifo; | 103 std::unique_ptr<AudioPullFIFO> m_fifo; |
113 | 104 |
114 size_t m_framesElapsed; | 105 size_t m_framesElapsed; |
115 AudioIOPosition m_outputPosition; | 106 AudioIOPosition m_outputPosition; |
116 base::TimeTicks m_outputPositionReceivedTimestamp; | 107 base::TimeTicks m_outputPositionReceivedTimestamp; |
108 | |
109 // Calculate the optimum buffer size for a given platform. Return false if the | |
110 // buffer size calculation fails. | |
111 bool calculateBufferSize(); | |
117 }; | 112 }; |
118 | 113 |
119 } // namespace blink | 114 } // namespace blink |
120 | 115 |
121 #endif // AudioDestination_h | 116 #endif // AudioDestination_h |
OLD | NEW |