| 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 double sampleRate() const { return m_audioDevice->sampleRate(); } |
| 82 |
| 83 // Returns the audio buffer size in frames used by the underlying audio |
| 84 // hardware. |
| 85 int framesPerBuffer() const { return m_audioDevice->framesPerBuffer(); } |
| 81 | 86 |
| 82 // WebAudioDevice::RenderCallback | 87 // WebAudioDevice::RenderCallback |
| 83 void render(const WebVector<float*>& sourceData, | 88 void render(const WebVector<float*>& sourceData, |
| 84 const WebVector<float*>& audioData, | 89 const WebVector<float*>& audioData, |
| 85 size_t numberOfFrames) override; | 90 size_t numberOfFrames) override; |
| 86 | 91 |
| 87 // AudioSourceProvider | 92 // AudioSourceProvider |
| 88 void provideInput(AudioBus*, size_t framesToProcess) override; | 93 void provideInput(AudioBus*, size_t framesToProcess) override; |
| 89 | 94 |
| 90 static float hardwareSampleRate(); | 95 static float hardwareSampleRate(); |
| 91 | 96 |
| 92 // maxChannelCount() returns the total number of output channels of the audio | 97 // 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 | 98 // 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. | 99 // configured and that only stereo (2-channel) destinations can be created. |
| 95 // The numberOfOutputChannels parameter of AudioDestination::create() is | 100 // The numberOfOutputChannels parameter of AudioDestination::create() is |
| 96 // allowed to be a value: 1 <= numberOfOutputChannels <= maxChannelCount(), | 101 // allowed to be a value: 1 <= numberOfOutputChannels <= maxChannelCount(), |
| 97 // or if maxChannelCount() equals 0, then numberOfOutputChannels must be 2. | 102 // or if maxChannelCount() equals 0, then numberOfOutputChannels must be 2. |
| 98 static unsigned long maxChannelCount(); | 103 static unsigned long maxChannelCount(); |
| 99 | 104 |
| 100 private: | 105 private: |
| 101 AudioIOCallback& m_callback; | 106 AudioIOCallback& m_callback; |
| 102 unsigned m_numberOfOutputChannels; | 107 unsigned m_numberOfOutputChannels; |
| 103 RefPtr<AudioBus> m_inputBus; | 108 RefPtr<AudioBus> m_inputBus; |
| 104 RefPtr<AudioBus> m_renderBus; | 109 RefPtr<AudioBus> m_renderBus; |
| 105 float m_sampleRate; | |
| 106 bool m_isPlaying; | 110 bool m_isPlaying; |
| 107 std::unique_ptr<WebAudioDevice> m_audioDevice; | 111 std::unique_ptr<WebAudioDevice> m_audioDevice; |
| 108 size_t m_callbackBufferSize; | 112 size_t m_callbackBufferSize; |
| 109 | 113 |
| 110 std::unique_ptr<AudioFIFO> m_inputFifo; | 114 std::unique_ptr<AudioFIFO> m_inputFifo; |
| 111 std::unique_ptr<AudioPullFIFO> m_fifo; | 115 std::unique_ptr<AudioPullFIFO> m_fifo; |
| 112 }; | 116 }; |
| 113 | 117 |
| 114 } // namespace blink | 118 } // namespace blink |
| 115 | 119 |
| 116 #endif // AudioDestination_h | 120 #endif // AudioDestination_h |
| OLD | NEW |