| Index: content/renderer/media/webrtc/peer_connection_remote_audio_source.h
|
| diff --git a/content/renderer/media/webrtc/media_stream_remote_audio_track.h b/content/renderer/media/webrtc/peer_connection_remote_audio_source.h
|
| similarity index 14%
|
| rename from content/renderer/media/webrtc/media_stream_remote_audio_track.h
|
| rename to content/renderer/media/webrtc/peer_connection_remote_audio_source.h
|
| index 9e48dfb40d7350b241d8a6db9466aed2272ec5f3..aa4f15d5b0e472d5d671b0352e7d50975a9794da 100644
|
| --- a/content/renderer/media/webrtc/media_stream_remote_audio_track.h
|
| +++ b/content/renderer/media/webrtc/peer_connection_remote_audio_source.h
|
| @@ -2,88 +2,101 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_AUDIO_TRACK_H_
|
| -#define CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_AUDIO_TRACK_H_
|
| +#ifndef CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_REMOTE_AUDIO_SOURCE_H_
|
| +#define CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_REMOTE_AUDIO_SOURCE_H_
|
| +
|
| +#include <memory>
|
|
|
| #include "base/memory/ref_counted.h"
|
| -#include "base/threading/thread_checker.h"
|
| +#include "base/synchronization/lock.h"
|
| +#include "content/renderer/media/media_stream_audio_source.h"
|
| #include "content/renderer/media/media_stream_audio_track.h"
|
| -#include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
|
| +#include "third_party/webrtc/api/mediastreaminterface.h"
|
|
|
| -namespace content {
|
| +namespace media {
|
| +class AudioBus;
|
| +}
|
|
|
| -class MediaStreamRemoteAudioSource;
|
| +namespace content {
|
|
|
| -// MediaStreamRemoteAudioTrack is a WebRTC specific implementation of an
|
| -// audio track received from a PeerConnection.
|
| -// TODO(tommi): Chrome shouldn't have to care about remote vs local so
|
| -// we should have a single track implementation that delegates to the
|
| -// sources that do different things depending on the type of source.
|
| -class MediaStreamRemoteAudioTrack : public MediaStreamAudioTrack {
|
| +// PeerConnectionRemoteAudioTrack is a WebRTC specific implementation of an
|
| +// audio track whose data is sourced from a PeerConnection.
|
| +class PeerConnectionRemoteAudioTrack final
|
| + : NON_EXPORTED_BASE(public MediaStreamAudioTrack) {
|
| public:
|
| - explicit MediaStreamRemoteAudioTrack(
|
| - const blink::WebMediaStreamSource& source, bool enabled);
|
| - ~MediaStreamRemoteAudioTrack() override;
|
| + explicit PeerConnectionRemoteAudioTrack(
|
| + scoped_refptr<webrtc::AudioTrackInterface> track_interface);
|
| + ~PeerConnectionRemoteAudioTrack() final;
|
|
|
| - // MediaStreamTrack override.
|
| - void SetEnabled(bool enabled) override;
|
| + // If |track| is an instance of PeerConnectionRemoteAudioTrack, return a
|
| + // type-casted pointer to it. Otherwise, return null.
|
| + static PeerConnectionRemoteAudioTrack* From(MediaStreamAudioTrack* track);
|
|
|
| - // MediaStreamAudioTrack overrides.
|
| - void AddSink(MediaStreamAudioSink* sink) override;
|
| - void RemoveSink(MediaStreamAudioSink* sink) override;
|
| - media::AudioParameters GetOutputFormat() const override;
|
| + webrtc::AudioTrackInterface* track_interface() const {
|
| + return track_interface_.get();
|
| + }
|
|
|
| - webrtc::AudioTrackInterface* GetAudioAdapter() override;
|
| + // MediaStreamAudioTrack override.
|
| + void SetEnabled(bool enabled) override;
|
|
|
| private:
|
| - // MediaStreamAudioTrack override.
|
| - void OnStop() final;
|
| + // MediaStreamAudioTrack overrides.
|
| + void* GetClassIdentifier() const final;
|
| +
|
| + const scoped_refptr<webrtc::AudioTrackInterface> track_interface_;
|
|
|
| - MediaStreamRemoteAudioSource* source() const;
|
| + // In debug builds, check that all methods that could cause object graph
|
| + // or data flow changes are being called on the main thread.
|
| + base::ThreadChecker thread_checker_;
|
|
|
| - blink::WebMediaStreamSource source_;
|
| - bool enabled_;
|
| + DISALLOW_COPY_AND_ASSIGN(PeerConnectionRemoteAudioTrack);
|
| };
|
|
|
| -// Inheriting from ExtraData directly since MediaStreamAudioSource has
|
| -// too much unrelated bloat.
|
| -// TODO(tommi): MediaStreamAudioSource needs refactoring.
|
| -// TODO(miu): On it! ;-)
|
| -class MediaStreamRemoteAudioSource
|
| - : public blink::WebMediaStreamSource::ExtraData {
|
| +// Represents the audio provided by the receiving end of a PeerConnection.
|
| +class PeerConnectionRemoteAudioSource final
|
| + : NON_EXPORTED_BASE(public MediaStreamAudioSource),
|
| + NON_EXPORTED_BASE(protected webrtc::AudioTrackSinkInterface) {
|
| public:
|
| - explicit MediaStreamRemoteAudioSource(
|
| - const scoped_refptr<webrtc::AudioTrackInterface>& track);
|
| - ~MediaStreamRemoteAudioSource() override;
|
| + explicit PeerConnectionRemoteAudioSource(
|
| + scoped_refptr<webrtc::AudioTrackInterface> track_interface);
|
| + ~PeerConnectionRemoteAudioSource() final;
|
| +
|
| + protected:
|
| + // MediaStreamAudioSource implementation.
|
| + std::unique_ptr<MediaStreamAudioTrack> CreateMediaStreamAudioTrack(
|
| + const std::string& id) final;
|
| + bool EnsureSourceIsStarted() final;
|
| + void EnsureSourceIsStopped() final;
|
|
|
| - // Controls whether or not the source is included in the main, mixed, audio
|
| - // output from WebRTC as rendered by WebRtcAudioRenderer (media players).
|
| - void SetEnabledForMixing(bool enabled);
|
| + // webrtc::AudioTrackSinkInterface implementation.
|
| + void OnData(const void* audio_data, int bits_per_sample, int sample_rate,
|
| + size_t number_of_channels, size_t number_of_frames) final;
|
|
|
| - // Adds an audio sink for a track belonging to this source.
|
| - // |enabled| is the enabled state of the track and can be updated via
|
| - // a call to SetSinksEnabled.
|
| - void AddSink(MediaStreamAudioSink* sink, MediaStreamAudioTrack* track,
|
| - bool enabled);
|
| + private:
|
| + // Interface to the implementation that calls OnData().
|
| + const scoped_refptr<webrtc::AudioTrackInterface> track_interface_;
|
|
|
| - // Removes an audio sink for a track belonging to this source.
|
| - void RemoveSink(MediaStreamAudioSink* sink, MediaStreamAudioTrack* track);
|
| + // In debug builds, check that all methods that could cause object graph
|
| + // or data flow changes are being called on the main thread.
|
| + base::ThreadChecker thread_checker_;
|
|
|
| - // Turns audio callbacks on/off for all sinks belonging to a track.
|
| - void SetSinksEnabled(MediaStreamAudioTrack* track, bool enabled);
|
| + // True if |this| is receiving an audio flow as a sink of the remote
|
| + // PeerConnection via |track_interface_|.
|
| + bool is_sink_of_peer_connection_;
|
|
|
| - // Removes all sinks belonging to a track.
|
| - void RemoveAll(MediaStreamAudioTrack* track);
|
| + // Buffer for converting from interleaved signed-integer PCM samples to the
|
| + // planar float format. Only used on the thread that calls OnData().
|
| + std::unique_ptr<media::AudioBus> audio_bus_;
|
|
|
| - webrtc::AudioTrackInterface* GetAudioAdapter();
|
| + // In debug builds, use a "try lock" to sanity-check that there are no
|
| + // concurrent calls to OnData(). See notes in OnData() implementation.
|
| +#ifndef NDEBUG
|
| + base::Lock single_audio_thread_guard_;
|
| +#endif
|
|
|
| - private:
|
| - class AudioSink;
|
| - std::unique_ptr<AudioSink> sink_;
|
| - const scoped_refptr<webrtc::AudioTrackInterface> track_;
|
| - base::ThreadChecker thread_checker_;
|
| + DISALLOW_COPY_AND_ASSIGN(PeerConnectionRemoteAudioSource);
|
| };
|
|
|
| } // namespace content
|
|
|
| -#endif // CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_AUDIO_TRACK_H_
|
| +#endif // CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_REMOTE_AUDIO_SOURCE_H_
|
|
|