Chromium Code Reviews| 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 16% |
| 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 4bc85d4257c3736cc270f0f8368b72cfeec1feeb..bb67b8dd930591df6a685a67b67a63bdc06a1743 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,89 @@ |
| // 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 "base/memory/ref_counted.h" |
| -#include "base/threading/thread_checker.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. |
| + // MediaStreamAudioTrack overrides. |
| + void* GetClassIdentifier() const final; |
| void OnStop() final; |
| - MediaStreamRemoteAudioSource* source() const; |
| + const scoped_refptr<webrtc::AudioTrackInterface> track_interface_; |
| - blink::WebMediaStreamSource source_; |
| - bool enabled_; |
| + // 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_; |
| }; |
| -// 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 |
|
perkj_chrome
2016/04/08 14:05:42
Suggest name MediaStreamRemoteAudioSource to match
miu
2016/04/19 00:40:22
I renamed it from that because this source is Peer
perkj_chrome
2016/04/20 13:34:53
Acknowledged.
|
| + : 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; |
| - // 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); |
| + protected: |
| + // MediaStreamAudioSource implementation. |
| + scoped_ptr<MediaStreamAudioTrack> CreateMediaStreamAudioTrack( |
| + const std::string& id) final; |
| + bool EnsureSourceIsStarted() final; |
| + void EnsureSourceIsStopped() 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); |
| + // 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; |
| - // Removes an audio sink for a track belonging to this source. |
| - void RemoveSink(MediaStreamAudioSink* sink, MediaStreamAudioTrack* track); |
| - |
| - // Turns audio callbacks on/off for all sinks belonging to a track. |
| - void SetSinksEnabled(MediaStreamAudioTrack* track, bool enabled); |
| + private: |
| + // Interface to the implementation that calls OnData(). |
| + const scoped_refptr<webrtc::AudioTrackInterface> track_interface_; |
| - // Removes all sinks belonging to a track. |
| - void RemoveAll(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_; |
| - webrtc::AudioTrackInterface* GetAudioAdapter(); |
| + // True if |this| is receiving an audio flow as a sink of the remote |
| + // PeerConnection via |track_interface_|. |
| + bool is_sink_of_peer_connection_; |
| - private: |
| - class AudioSink; |
| - scoped_ptr<AudioSink> sink_; |
| - const scoped_refptr<webrtc::AudioTrackInterface> track_; |
| - base::ThreadChecker thread_checker_; |
| + // Buffer for converting from interleaved signed-integer PCM samples to the |
| + // planar float format. Only used on the thread that calls OnData(). |
| + scoped_ptr<media::AudioBus> audio_bus_; |
| }; |
| } // namespace content |
| -#endif // CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_AUDIO_TRACK_H_ |
| +#endif // CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_REMOTE_AUDIO_SOURCE_H_ |