Index: content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h |
diff --git a/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h b/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h |
index 72b80194b08ed09a01673c98c4ed9816aa4e6d74..899e1abf5584ae6ad1bd6d4ce7b3cb976671a28f 100644 |
--- a/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h |
+++ b/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h |
@@ -8,7 +8,7 @@ |
#include <vector> |
#include "base/memory/ref_counted.h" |
-#include "base/memory/scoped_vector.h" |
+#include "base/memory/weak_ptr.h" |
#include "base/single_thread_task_runner.h" |
#include "base/synchronization/lock.h" |
#include "content/common/content_export.h" |
@@ -17,8 +17,8 @@ |
#include "third_party/webrtc/api/mediastreamtrack.h" |
#include "third_party/webrtc/media/base/audiorenderer.h" |
-namespace cricket { |
-class AudioRenderer; |
+namespace base { |
+class WaitableEvent; |
} |
namespace webrtc { |
@@ -29,8 +29,8 @@ class AudioProcessorInterface; |
namespace content { |
class MediaStreamAudioProcessor; |
+class MediaStreamAudioTrack; |
class WebRtcAudioSinkAdapter; |
-class WebRtcLocalAudioTrack; |
// Provides an implementation of the webrtc::AudioTrackInterface that can be |
// bound/unbound to/from a MediaStreamAudioTrack. In other words, this is an |
@@ -51,7 +51,10 @@ class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter |
~WebRtcLocalAudioTrackAdapter() override; |
- void Initialize(WebRtcLocalAudioTrack* owner); |
+ // Set the |track| that manages the MediaStreamAudioSinks. The WeakPtr will |
+ // only be dereferenced on the main thread. This method must only be called |
+ // on the main thread. |
+ void SetMediaStreamAudioTrack(base::WeakPtr<MediaStreamAudioTrack> track); |
// Set the object that provides shared access to the current audio signal |
// level. This method may only be called once, before the audio data flow |
@@ -79,23 +82,38 @@ class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter |
override; |
webrtc::AudioSourceInterface* GetSource() const override; |
- // Weak reference. |
- WebRtcLocalAudioTrack* owner_; |
+ // Removes the |sink| from |track_| and then signals the |done_event| (if |
+ // provided). This is used by RemoveSink() to ensure the audio flow has |
+ // halted before it returns. |
+ void RemoveSinkOnMainThread(webrtc::AudioTrackSinkInterface* sink, |
+ base::WaitableEvent* done_event); |
// The source of the audio track which handles the audio constraints. |
- // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack. |
- rtc::scoped_refptr<webrtc::AudioSourceInterface> track_source_; |
+ const rtc::scoped_refptr<webrtc::AudioSourceInterface> track_source_; |
- // Libjingle's signaling thread. |
+ // Task runner for operations that must be done on libjingle's signaling |
+ // thread. May be null for single-threaded unit tests. |
const scoped_refptr<base::SingleThreadTaskRunner> signaling_task_runner_; |
+ // Task runner for operations that must be done on the main thread. May be |
+ // null for single-threaded unit tests. |
+ scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
+ |
+ // The track to add/remove sinks to/from. When the |
+ // webrtc::AudioTrackInterface::Add/RemoveSink() methods are called, they |
+ // create a proxy (WebRtcAudioSinkAdapter) that implements the |
+ // MediaStreamAudioSink interface to call into the |
+ // webrtc::AudioTrackSinkInterface. This must only be dereferenced on the |
+ // main thread. |
+ base::WeakPtr<MediaStreamAudioTrack> track_; |
+ |
// The audio processsor that applies audio processing on the data of audio |
// track. This must be set before calls to GetAudioProcessor() are made. |
scoped_refptr<MediaStreamAudioProcessor> audio_processor_; |
// A vector of the peer connection sink adapters which receive the audio data |
// from the audio track. |
- ScopedVector<WebRtcAudioSinkAdapter> sink_adapters_; |
+ std::vector<scoped_ptr<WebRtcAudioSinkAdapter>> sink_adapters_; |
// Thread-safe accessor to current audio signal level. This must be set |
// before calls to GetSignalLevel() are made. |