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 27 matching lines...) Expand all Loading... | |
38 #include "wtf/Noncopyable.h" | 38 #include "wtf/Noncopyable.h" |
39 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
40 #include "wtf/text/WTFString.h" | 40 #include "wtf/text/WTFString.h" |
41 #include <memory> | 41 #include <memory> |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 class AudioFIFO; | 45 class AudioFIFO; |
46 class AudioPullFIFO; | 46 class AudioPullFIFO; |
47 class SecurityOrigin; | 47 class SecurityOrigin; |
48 class WebAudioLatencyHint; | |
48 | 49 |
49 // An AudioDestination using Chromium's audio system | 50 // An AudioDestination using Chromium's audio system |
50 | 51 |
51 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback, | 52 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback, |
52 public AudioSourceProvider { | 53 public AudioSourceProvider { |
53 USING_FAST_MALLOC(AudioDestination); | 54 USING_FAST_MALLOC(AudioDestination); |
54 WTF_MAKE_NONCOPYABLE(AudioDestination); | 55 WTF_MAKE_NONCOPYABLE(AudioDestination); |
55 | 56 |
56 public: | 57 public: |
57 AudioDestination(AudioIOCallback&, | 58 AudioDestination(AudioIOCallback&, |
58 const String& inputDeviceId, | 59 const String& inputDeviceId, |
59 unsigned numberOfInputChannels, | 60 unsigned numberOfInputChannels, |
60 unsigned numberOfOutputChannels, | 61 unsigned numberOfOutputChannels, |
61 float sampleRate, | 62 const WebAudioLatencyHint&, |
62 PassRefPtr<SecurityOrigin>); | 63 PassRefPtr<SecurityOrigin>); |
63 ~AudioDestination() override; | 64 ~AudioDestination() override; |
64 | 65 |
65 // Pass in (numberOfInputChannels > 0) if live/local audio input is desired. | 66 // Pass in (numberOfInputChannels > 0) if live/local audio input is desired. |
66 // Port-specific device identification information for live/local input | 67 // Port-specific device identification information for live/local input |
67 // streams can be passed in the inputDeviceId. | 68 // streams can be passed in the inputDeviceId. |
68 static std::unique_ptr<AudioDestination> create( | 69 static std::unique_ptr<AudioDestination> create( |
69 AudioIOCallback&, | 70 AudioIOCallback&, |
70 const String& inputDeviceId, | 71 const String& inputDeviceId, |
71 unsigned numberOfInputChannels, | 72 unsigned numberOfInputChannels, |
72 unsigned numberOfOutputChannels, | 73 unsigned numberOfOutputChannels, |
73 float sampleRate, | 74 const WebAudioLatencyHint&, |
74 PassRefPtr<SecurityOrigin>); | 75 PassRefPtr<SecurityOrigin>); |
75 | 76 |
76 virtual void start(); | 77 virtual void start(); |
77 virtual void stop(); | 78 virtual void stop(); |
78 bool isPlaying() { return m_isPlaying; } | 79 bool isPlaying() { return m_isPlaying; } |
79 | 80 |
80 float sampleRate() const { return m_sampleRate; } | |
81 | |
82 // WebAudioDevice::RenderCallback | 81 // WebAudioDevice::RenderCallback |
83 void render(const WebVector<float*>& sourceData, | 82 void render(const WebVector<float*>& sourceData, |
84 const WebVector<float*>& audioData, | 83 const WebVector<float*>& audioData, |
85 size_t numberOfFrames) override; | 84 size_t numberOfFrames) override; |
86 | 85 |
87 // AudioSourceProvider | 86 // AudioSourceProvider |
88 void provideInput(AudioBus*, size_t framesToProcess) override; | 87 void provideInput(AudioBus*, size_t framesToProcess) override; |
89 | 88 |
90 static float hardwareSampleRate(); | 89 static float hardwareSampleRate(); |
91 | 90 |
92 // maxChannelCount() returns the total number of output channels of the audio | 91 // maxChannelCount() returns the total number of output channels of the audio |
93 // hardware. A value of 0 indicates that the number of channels cannot be | 92 // hardware. A value of 0 indicates that the number of channels cannot be |
94 // configured and that only stereo (2-channel) destinations can be created. | 93 // configured and that only stereo (2-channel) destinations can be created. |
95 // The numberOfOutputChannels parameter of AudioDestination::create() is | 94 // The numberOfOutputChannels parameter of AudioDestination::create() is |
96 // allowed to be a value: 1 <= numberOfOutputChannels <= maxChannelCount(), | 95 // allowed to be a value: 1 <= numberOfOutputChannels <= maxChannelCount(), |
97 // or if maxChannelCount() equals 0, then numberOfOutputChannels must be 2. | 96 // or if maxChannelCount() equals 0, then numberOfOutputChannels must be 2. |
98 static unsigned long maxChannelCount(); | 97 static unsigned long maxChannelCount(); |
99 | 98 |
100 private: | 99 private: |
101 AudioIOCallback& m_callback; | 100 AudioIOCallback& m_callback; |
102 unsigned m_numberOfOutputChannels; | 101 unsigned m_numberOfOutputChannels; |
103 RefPtr<AudioBus> m_inputBus; | 102 RefPtr<AudioBus> m_inputBus; |
104 RefPtr<AudioBus> m_renderBus; | 103 RefPtr<AudioBus> m_renderBus; |
105 float m_sampleRate; | |
hongchan
2016/11/15 23:46:01
How do I query the sample rate of the destination
Andrew MacPherson
2016/11/16 10:58:30
My understanding is that this should be queried us
| |
106 bool m_isPlaying; | 104 bool m_isPlaying; |
107 std::unique_ptr<WebAudioDevice> m_audioDevice; | 105 std::unique_ptr<WebAudioDevice> m_audioDevice; |
108 size_t m_callbackBufferSize; | 106 size_t m_callbackBufferSize; |
109 | 107 |
110 std::unique_ptr<AudioFIFO> m_inputFifo; | 108 std::unique_ptr<AudioFIFO> m_inputFifo; |
111 std::unique_ptr<AudioPullFIFO> m_fifo; | 109 std::unique_ptr<AudioPullFIFO> m_fifo; |
112 }; | 110 }; |
113 | 111 |
114 } // namespace blink | 112 } // namespace blink |
115 | 113 |
116 #endif // AudioDestination_h | 114 #endif // AudioDestination_h |
OLD | NEW |