| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_WEBAUDIO_CAPTURER_SOURCE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "media/audio/audio_parameters.h" | 14 #include "media/audio/audio_parameters.h" |
| 15 #include "media/base/audio_bus.h" |
| 15 #include "media/base/audio_capturer_source.h" | 16 #include "media/base/audio_capturer_source.h" |
| 16 #include "media/base/audio_fifo.h" | 17 #include "media/base/audio_rechunker.h" |
| 17 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h" | 18 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h" |
| 18 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 19 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 19 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 23 class WebRtcLocalAudioTrack; | 24 class WebRtcLocalAudioTrack; |
| 24 | 25 |
| 25 // WebAudioCapturerSource is the missing link between | 26 // WebAudioCapturerSource is the missing link between |
| 26 // WebAudio's MediaStreamAudioDestinationNode and WebRtcLocalAudioTrack. | 27 // WebAudio's MediaStreamAudioDestinationNode and WebRtcLocalAudioTrack. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 51 void Start(WebRtcLocalAudioTrack* track); | 52 void Start(WebRtcLocalAudioTrack* track); |
| 52 | 53 |
| 53 // Called when the media audio track is stopping. | 54 // Called when the media audio track is stopping. |
| 54 void Stop(); | 55 void Stop(); |
| 55 | 56 |
| 56 protected: | 57 protected: |
| 57 friend class base::RefCountedThreadSafe<WebAudioCapturerSource>; | 58 friend class base::RefCountedThreadSafe<WebAudioCapturerSource>; |
| 58 ~WebAudioCapturerSource() override; | 59 ~WebAudioCapturerSource() override; |
| 59 | 60 |
| 60 private: | 61 private: |
| 62 // Called by AudioRechunker zero or more times during the call to |
| 63 // consumeAudio(). Delivers re-chunked audio data to the track. |
| 64 void DeliverRechunkedAudio(const media::AudioBus& audio_bus, |
| 65 base::TimeDelta reference_timestamp); |
| 66 |
| 61 // Removes this object from a blink::WebMediaStreamSource with which it | 67 // Removes this object from a blink::WebMediaStreamSource with which it |
| 62 // might be registered. The goal is to avoid dangling pointers. | 68 // might be registered. The goal is to avoid dangling pointers. |
| 63 void removeFromBlinkSource(); | 69 void removeFromBlinkSource(); |
| 64 | 70 |
| 65 // Used to DCHECK that some methods are called on the correct thread. | 71 // Used to DCHECK that some methods are called on the correct thread. |
| 66 base::ThreadChecker thread_checker_; | 72 base::ThreadChecker thread_checker_; |
| 67 | 73 |
| 68 // The audio track this WebAudioCapturerSource is feeding data to. | 74 // The audio track this WebAudioCapturerSource is feeding data to. |
| 69 // WebRtcLocalAudioTrack is reference counted, and owning this object. | 75 // WebRtcLocalAudioTrack is reference counted, and owning this object. |
| 70 // To avoid circular reference, a raw pointer is kept here. | 76 // To avoid circular reference, a raw pointer is kept here. |
| 71 WebRtcLocalAudioTrack* track_; | 77 WebRtcLocalAudioTrack* track_; |
| 72 | 78 |
| 73 media::AudioParameters params_; | 79 media::AudioParameters params_; |
| 74 | 80 |
| 75 // Flag to help notify the |track_| when the audio format has changed. | 81 // Flag to help notify the |track_| when the audio format has changed. |
| 76 bool audio_format_changed_; | 82 bool audio_format_changed_; |
| 77 | 83 |
| 78 // Wraps data coming from HandleCapture(). | 84 // A wrapper used for providing audio to |rechunker_|. |
| 79 scoped_ptr<media::AudioBus> wrapper_bus_; | 85 scoped_ptr<media::AudioBus> wrapper_bus_; |
| 80 | 86 |
| 81 // Bus for reading from FIFO and calling the CaptureCallback. | 87 // Takes in the audio data passed to consumeAudio() and re-chunks it into 10 |
| 82 scoped_ptr<media::AudioBus> capture_bus_; | 88 // ms chunks for the track. This ensures each chunk of audio delivered to the |
| 83 | 89 // track has the required buffer size, regardless of the amount of audio |
| 84 // Handles mismatch between WebAudio buffer size and WebRTC. | 90 // provided via each consumeAudio() call. |
| 85 scoped_ptr<media::AudioFifo> fifo_; | 91 media::AudioRechunker rechunker_; |
| 86 | 92 |
| 87 // Synchronizes HandleCapture() with AudioCapturerSource calls. | 93 // Synchronizes HandleCapture() with AudioCapturerSource calls. |
| 88 base::Lock lock_; | 94 base::Lock lock_; |
| 89 bool started_; | 95 bool started_; |
| 90 | 96 |
| 91 // This object registers with a blink::WebMediaStreamSource. We keep track of | 97 // This object registers with a blink::WebMediaStreamSource. We keep track of |
| 92 // that in order to be able to deregister before stopping the audio track. | 98 // that in order to be able to deregister before stopping the audio track. |
| 93 blink::WebMediaStreamSource blink_source_; | 99 blink::WebMediaStreamSource blink_source_; |
| 94 | 100 |
| 95 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource); | 101 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource); |
| 96 }; | 102 }; |
| 97 | 103 |
| 98 } // namespace content | 104 } // namespace content |
| 99 | 105 |
| 100 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ | 106 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ |
| OLD | NEW |