| 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 cfe4a98ef9d291d96e0746833ecd3edcf2dab27e..5adc85a07ea6658ba3cf59428393c742539577c8 100644
|
| --- a/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h
|
| +++ b/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h
|
| @@ -11,13 +11,13 @@
|
| #include "base/memory/scoped_vector.h"
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/synchronization/lock.h"
|
| -#include "base/threading/thread_checker.h"
|
| #include "content/common/content_export.h"
|
| +#include "content/renderer/media/media_stream_audio_level_calculator.h"
|
| #include "third_party/webrtc/api/mediastreamtrack.h"
|
| -#include "third_party/webrtc/media/base/audiorenderer.h"
|
| +#include "third_party/webrtc/base/refcount.h"
|
|
|
| -namespace cricket {
|
| -class AudioRenderer;
|
| +namespace base {
|
| +class WaitableEvent;
|
| }
|
|
|
| namespace webrtc {
|
| @@ -28,80 +28,107 @@ 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
|
| +// adapter that sits between the media stream object graph and WebRtc's object
|
| +// graph and proxies between the two.
|
| +//
|
| +// TODO(miu): Rename to WebRtcAudioTrackAdapter since this can be used to proxy
|
| +// between any kind (local or remote) of MediaStreamAudioTrack.
|
| class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter
|
| : NON_EXPORTED_BASE(
|
| public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) {
|
| public:
|
| static scoped_refptr<WebRtcLocalAudioTrackAdapter> Create(
|
| const std::string& label,
|
| - webrtc::AudioSourceInterface* track_source);
|
| -
|
| - WebRtcLocalAudioTrackAdapter(
|
| - const std::string& label,
|
| webrtc::AudioSourceInterface* track_source,
|
| - const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread);
|
| -
|
| - ~WebRtcLocalAudioTrackAdapter() override;
|
| -
|
| - void Initialize(WebRtcLocalAudioTrack* owner);
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& signaling_task_runner);
|
|
|
| - // Called on the audio thread by the WebRtcLocalAudioTrack to set the signal
|
| - // level of the audio data.
|
| - void SetSignalLevel(int signal_level);
|
| + // Set the |track| that manages the MediaStreamAudioSinks. It is the client's
|
| + // responsibility to call this method with null before the track's destruction
|
| + // time. This is needed because WebRtcLocalAudioTrackAdapter is ref-counted
|
| + // and could potentially out-live |track|.
|
| + //
|
| + // This method must only be called on the main thread.
|
| + void SetMediaStreamAudioTrack(MediaStreamAudioTrack* track);
|
|
|
| - // Method called by the WebRtcLocalAudioTrack to set the processor that
|
| - // applies signal processing on the data of the track.
|
| + // Set the processor that applies signal processing on the data of the track.
|
| // This class will keep a reference of the |processor|.
|
| // Called on the main render thread.
|
| void SetAudioProcessor(
|
| const scoped_refptr<MediaStreamAudioProcessor>& processor);
|
|
|
| + // Set the object that provides shared access to the current audio signal
|
| + // level.
|
| + void SetReportedLevel(
|
| + const scoped_refptr<MediaStreamAudioLevelCalculator::ReportedLevel>&
|
| + reported_level);
|
| +
|
| // webrtc::MediaStreamTrack implementation.
|
| - std::string kind() const override;
|
| - bool set_enabled(bool enable) override;
|
| + std::string kind() const final;
|
| + bool set_enabled(bool enable) final;
|
| +
|
| + protected:
|
| + friend class rtc::RefCountedObject<WebRtcLocalAudioTrackAdapter>;
|
| +
|
| + WebRtcLocalAudioTrackAdapter(
|
| + const std::string& label,
|
| + webrtc::AudioSourceInterface* track_source,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& signaling_task_runner);
|
| +
|
| + ~WebRtcLocalAudioTrackAdapter() override;
|
|
|
| private:
|
| - // webrtc::AudioTrackInterface implementation.
|
| - void AddSink(webrtc::AudioTrackSinkInterface* sink) override;
|
| - void RemoveSink(webrtc::AudioTrackSinkInterface* sink) override;
|
| - bool GetSignalLevel(int* level) override;
|
| - rtc::scoped_refptr<webrtc::AudioProcessorInterface> GetAudioProcessor()
|
| - override;
|
| - webrtc::AudioSourceInterface* GetSource() const override;
|
| + // 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 (on the signaling thread).
|
| + void RemoveSinkOnMainThread(webrtc::AudioTrackSinkInterface* sink,
|
| + base::WaitableEvent* done_event);
|
|
|
| - // Weak reference.
|
| - WebRtcLocalAudioTrack* owner_;
|
| + // webrtc::AudioTrackInterface implementation.
|
| + void AddSink(webrtc::AudioTrackSinkInterface* sink) final;
|
| + void RemoveSink(webrtc::AudioTrackSinkInterface* sink) final;
|
| + bool GetSignalLevel(int* level) final;
|
| + rtc::scoped_refptr<webrtc::AudioProcessorInterface> GetAudioProcessor() final;
|
| + webrtc::AudioSourceInterface* GetSource() const final;
|
|
|
| // 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.
|
| - const scoped_refptr<base::SingleThreadTaskRunner> 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_;
|
|
|
| - // The audio processsor that applies audio processing on the data of audio
|
| - // track.
|
| - scoped_refptr<MediaStreamAudioProcessor> audio_processor_;
|
| + // 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_;
|
|
|
| - // A vector of WebRtc VoE channels that the capturer sends data to.
|
| - std::vector<int> voe_channels_;
|
| + // The track to add/remove sinks to/from. When the
|
| + // webrtc::AudioTrackInterface::Add/RemoveSink() methods are called, they
|
| + // create a proxy that implements the MediaStreamAudioSink interface to call
|
| + // into the webrtc::AudioTrackSinkInterface. This must only be accessed on
|
| + // the main thread.
|
| + MediaStreamAudioTrack* track_;
|
|
|
| // A vector of the peer connection sink adapters which receive the audio data
|
| - // from the audio track.
|
| + // from the audio track. This must only be accessed on the main thread.
|
| ScopedVector<WebRtcAudioSinkAdapter> sink_adapters_;
|
|
|
| - // The amplitude of the signal.
|
| - int signal_level_;
|
| + // Protects |audio_processor_|, |voe_channels_|, and |signal_level_|.
|
| + mutable base::Lock lock_;
|
| +
|
| + // The audio processsor that applies audio processing on the data of audio
|
| + // track.
|
| + scoped_refptr<MediaStreamAudioProcessor> audio_processor_;
|
|
|
| - // Thread checker for libjingle's signaling thread.
|
| - base::ThreadChecker signaling_thread_checker_;
|
| - base::ThreadChecker capture_thread_;
|
| + // Thread-safe accessor to current audio signal level.
|
| + scoped_refptr<MediaStreamAudioLevelCalculator::ReportedLevel> reported_level_;
|
|
|
| - // Protects |voe_channels_|, |audio_processor_| and |signal_level_|.
|
| - mutable base::Lock lock_;
|
| + // A vector of WebRtc VoE channels that the capturer sends data to.
|
| + std::vector<int> voe_channels_;
|
| };
|
|
|
| } // namespace content
|
|
|