Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/public/renderer/media_stream_audio_sink.h" | 15 #include "content/public/renderer/media_stream_audio_sink.h" |
| 16 #include "media/base/audio_converter.h" | 16 #include "media/base/audio_converter.h" |
| 17 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" | 17 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" |
| 18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
| 18 #include "third_party/WebKit/public/platform/WebVector.h" | 19 #include "third_party/WebKit/public/platform/WebVector.h" |
| 19 | 20 |
| 20 namespace media { | 21 namespace media { |
| 21 class AudioBus; | 22 class AudioBus; |
| 22 class AudioConverter; | 23 class AudioConverter; |
| 23 class AudioFifo; | 24 class AudioFifo; |
| 24 class AudioParameters; | 25 class AudioParameters; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace blink { | 28 namespace blink { |
| 28 class WebAudioSourceProviderClient; | 29 class WebAudioSourceProviderClient; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace content { | 32 namespace content { |
| 32 | 33 |
| 33 // WebRtcLocalAudioSourceProvider provides a bridge between classes: | 34 // WebRtcLocalAudioSourceProvider provides a bridge between classes: |
| 34 // WebRtcAudioCapturer ---> blink::WebAudioSourceProvider | 35 // WebRtcLocalAudioTrack ---> blink::WebAudioSourceProvider |
| 35 // | 36 // |
| 36 // WebRtcLocalAudioSourceProvider works as a sink to the WebRtcAudiocapturer | 37 // WebRtcLocalAudioSourceProvider works as a sink to the WebRtcLocalAudioTrack |
| 37 // and store the capture data to a FIFO. When the media stream is connected to | 38 // and store the capture data to a FIFO. When the media stream is connected to |
| 38 // WebAudio as a source provider, WebAudio will periodically call | 39 // WebAudio MediaStreamAudioSourceNode as a source provider, |
| 39 // provideInput() to get the data from the FIFO. | 40 // MediaStreamAudioSourceNode will periodically call provideInput() to get the |
|
perkj_chrome
2014/04/03 09:42:06
Nothing to do now but isn't provideInput() a weird
no longer working on chromium
2014/04/03 09:48:20
It is an API designed by WebAudio to allow WebAudi
| |
| 41 // data from the FIFO. | |
| 40 // | 42 // |
| 41 // All calls are protected by a lock. | 43 // All calls are protected by a lock. |
| 42 class CONTENT_EXPORT WebRtcLocalAudioSourceProvider | 44 class CONTENT_EXPORT WebRtcLocalAudioSourceProvider |
| 43 : NON_EXPORTED_BASE(public blink::WebAudioSourceProvider), | 45 : NON_EXPORTED_BASE(public blink::WebAudioSourceProvider), |
| 44 NON_EXPORTED_BASE(public media::AudioConverter::InputCallback), | 46 NON_EXPORTED_BASE(public media::AudioConverter::InputCallback), |
| 45 NON_EXPORTED_BASE(public MediaStreamAudioSink) { | 47 NON_EXPORTED_BASE(public MediaStreamAudioSink) { |
| 46 public: | 48 public: |
| 47 static const size_t kWebAudioRenderBufferSize; | 49 static const size_t kWebAudioRenderBufferSize; |
| 48 | 50 |
| 49 WebRtcLocalAudioSourceProvider(); | 51 explicit WebRtcLocalAudioSourceProvider( |
| 52 const blink::WebMediaStreamTrack& track); | |
| 50 virtual ~WebRtcLocalAudioSourceProvider(); | 53 virtual ~WebRtcLocalAudioSourceProvider(); |
| 51 | 54 |
| 52 // MediaStreamAudioSink implementation. | 55 // MediaStreamAudioSink implementation. |
| 53 virtual void OnData(const int16* audio_data, | 56 virtual void OnData(const int16* audio_data, |
| 54 int sample_rate, | 57 int sample_rate, |
| 55 int number_of_channels, | 58 int number_of_channels, |
| 56 int number_of_frames) OVERRIDE; | 59 int number_of_frames) OVERRIDE; |
| 57 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; | 60 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; |
| 61 virtual void OnReadyStateChanged( | |
| 62 blink::WebMediaStreamSource::ReadyState state) OVERRIDE; | |
| 58 | 63 |
| 59 // blink::WebAudioSourceProvider implementation. | 64 // blink::WebAudioSourceProvider implementation. |
| 60 virtual void setClient(blink::WebAudioSourceProviderClient* client) OVERRIDE; | 65 virtual void setClient(blink::WebAudioSourceProviderClient* client) OVERRIDE; |
| 61 virtual void provideInput(const blink::WebVector<float*>& audio_data, | 66 virtual void provideInput(const blink::WebVector<float*>& audio_data, |
| 62 size_t number_of_frames) OVERRIDE; | 67 size_t number_of_frames) OVERRIDE; |
| 63 | 68 |
| 64 // media::AudioConverter::Inputcallback implementation. | 69 // media::AudioConverter::Inputcallback implementation. |
| 65 // This function is triggered by provideInput()on the WebAudio audio thread, | 70 // This function is triggered by provideInput()on the WebAudio audio thread, |
| 66 // so it has been under the protection of |lock_|. | 71 // so it has been under the protection of |lock_|. |
| 67 virtual double ProvideInput(media::AudioBus* audio_bus, | 72 virtual double ProvideInput(media::AudioBus* audio_bus, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 87 bool is_enabled_; | 92 bool is_enabled_; |
| 88 media::AudioParameters source_params_; | 93 media::AudioParameters source_params_; |
| 89 media::AudioParameters sink_params_; | 94 media::AudioParameters sink_params_; |
| 90 | 95 |
| 91 // Protects all the member variables above. | 96 // Protects all the member variables above. |
| 92 base::Lock lock_; | 97 base::Lock lock_; |
| 93 | 98 |
| 94 // Used to report the correct delay to |webaudio_source_|. | 99 // Used to report the correct delay to |webaudio_source_|. |
| 95 base::TimeTicks last_fill_; | 100 base::TimeTicks last_fill_; |
| 96 | 101 |
| 102 // The audio track that this source provider is connected to. | |
| 103 blink::WebMediaStreamTrack track_; | |
| 104 | |
| 105 // Flag to tell if the track has been stopped or not. | |
| 106 bool track_stopped_; | |
| 107 | |
| 97 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioSourceProvider); | 108 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioSourceProvider); |
| 98 }; | 109 }; |
| 99 | 110 |
| 100 } // namespace content | 111 } // namespace content |
| 101 | 112 |
| 102 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ | 113 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ |
| OLD | NEW |