Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: content/renderer/media/webrtc/peer_connection_remote_audio_source.h

Issue 1834323002: MediaStream audio: Refactor 3 separate "glue" implementations into one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from PS2: AudioInputDevice --> AudioCapturerSource, and refptr foo in WebRtcMedi… Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_WEBRTC_MEDIA_STREAM_REMOTE_AUDIO_TRACK_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_REMOTE_AUDIO_SOURCE_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_AUDIO_TRACK_H_ 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_REMOTE_AUDIO_SOURCE_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/threading/thread_checker.h" 9 #include "content/renderer/media/media_stream_audio_source.h"
10 #include "content/renderer/media/media_stream_audio_track.h" 10 #include "content/renderer/media/media_stream_audio_track.h"
11 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 11 #include "third_party/webrtc/api/mediastreaminterface.h"
12
13 namespace media {
14 class AudioBus;
15 }
12 16
13 namespace content { 17 namespace content {
14 18
15 class MediaStreamRemoteAudioSource; 19 // PeerConnectionRemoteAudioTrack is a WebRTC specific implementation of an
20 // audio track whose data is sourced from a PeerConnection.
21 class PeerConnectionRemoteAudioTrack final
22 : NON_EXPORTED_BASE(public MediaStreamAudioTrack) {
23 public:
24 explicit PeerConnectionRemoteAudioTrack(
25 scoped_refptr<webrtc::AudioTrackInterface> track_interface);
26 ~PeerConnectionRemoteAudioTrack() final;
16 27
17 // MediaStreamRemoteAudioTrack is a WebRTC specific implementation of an 28 // If |track| is an instance of PeerConnectionRemoteAudioTrack, return a
18 // audio track received from a PeerConnection. 29 // type-casted pointer to it. Otherwise, return null.
19 // TODO(tommi): Chrome shouldn't have to care about remote vs local so 30 static PeerConnectionRemoteAudioTrack* From(MediaStreamAudioTrack* track);
20 // we should have a single track implementation that delegates to the
21 // sources that do different things depending on the type of source.
22 class MediaStreamRemoteAudioTrack : public MediaStreamAudioTrack {
23 public:
24 explicit MediaStreamRemoteAudioTrack(
25 const blink::WebMediaStreamSource& source, bool enabled);
26 ~MediaStreamRemoteAudioTrack() override;
27 31
28 // MediaStreamTrack override. 32 webrtc::AudioTrackInterface* track_interface() const {
33 return track_interface_.get();
34 }
35
36 // MediaStreamAudioTrack override.
29 void SetEnabled(bool enabled) override; 37 void SetEnabled(bool enabled) override;
30 38
39 private:
31 // MediaStreamAudioTrack overrides. 40 // MediaStreamAudioTrack overrides.
32 void AddSink(MediaStreamAudioSink* sink) override; 41 void* GetClassIdentifier() const final;
33 void RemoveSink(MediaStreamAudioSink* sink) override; 42 void OnStop() final;
34 media::AudioParameters GetOutputFormat() const override;
35 43
36 webrtc::AudioTrackInterface* GetAudioAdapter() override; 44 const scoped_refptr<webrtc::AudioTrackInterface> track_interface_;
45
46 // In debug builds, check that all methods that could cause object graph
47 // or data flow changes are being called on the main thread.
48 base::ThreadChecker thread_checker_;
49 };
50
51 // Represents the audio provided by the receiving end of a PeerConnection.
52 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.
53 : NON_EXPORTED_BASE(public MediaStreamAudioSource),
54 NON_EXPORTED_BASE(protected webrtc::AudioTrackSinkInterface) {
55 public:
56 explicit PeerConnectionRemoteAudioSource(
57 scoped_refptr<webrtc::AudioTrackInterface> track_interface);
58 ~PeerConnectionRemoteAudioSource() final;
59
60 protected:
61 // MediaStreamAudioSource implementation.
62 scoped_ptr<MediaStreamAudioTrack> CreateMediaStreamAudioTrack(
63 const std::string& id) final;
64 bool EnsureSourceIsStarted() final;
65 void EnsureSourceIsStopped() final;
66
67 // webrtc::AudioTrackSinkInterface implementation.
68 void OnData(const void* audio_data, int bits_per_sample, int sample_rate,
69 size_t number_of_channels, size_t number_of_frames) final;
37 70
38 private: 71 private:
39 // MediaStreamAudioTrack override. 72 // Interface to the implementation that calls OnData().
40 void OnStop() final; 73 const scoped_refptr<webrtc::AudioTrackInterface> track_interface_;
41 74
42 MediaStreamRemoteAudioSource* source() const; 75 // In debug builds, check that all methods that could cause object graph
76 // or data flow changes are being called on the main thread.
77 base::ThreadChecker thread_checker_;
43 78
44 blink::WebMediaStreamSource source_; 79 // True if |this| is receiving an audio flow as a sink of the remote
45 bool enabled_; 80 // PeerConnection via |track_interface_|.
46 }; 81 bool is_sink_of_peer_connection_;
47 82
48 // Inheriting from ExtraData directly since MediaStreamAudioSource has 83 // Buffer for converting from interleaved signed-integer PCM samples to the
49 // too much unrelated bloat. 84 // planar float format. Only used on the thread that calls OnData().
50 // TODO(tommi): MediaStreamAudioSource needs refactoring. 85 scoped_ptr<media::AudioBus> audio_bus_;
51 // TODO(miu): On it! ;-)
52 class MediaStreamRemoteAudioSource
53 : public blink::WebMediaStreamSource::ExtraData {
54 public:
55 explicit MediaStreamRemoteAudioSource(
56 const scoped_refptr<webrtc::AudioTrackInterface>& track);
57 ~MediaStreamRemoteAudioSource() override;
58
59 // Controls whether or not the source is included in the main, mixed, audio
60 // output from WebRTC as rendered by WebRtcAudioRenderer (media players).
61 void SetEnabledForMixing(bool enabled);
62
63 // Adds an audio sink for a track belonging to this source.
64 // |enabled| is the enabled state of the track and can be updated via
65 // a call to SetSinksEnabled.
66 void AddSink(MediaStreamAudioSink* sink, MediaStreamAudioTrack* track,
67 bool enabled);
68
69 // Removes an audio sink for a track belonging to this source.
70 void RemoveSink(MediaStreamAudioSink* sink, MediaStreamAudioTrack* track);
71
72 // Turns audio callbacks on/off for all sinks belonging to a track.
73 void SetSinksEnabled(MediaStreamAudioTrack* track, bool enabled);
74
75 // Removes all sinks belonging to a track.
76 void RemoveAll(MediaStreamAudioTrack* track);
77
78 webrtc::AudioTrackInterface* GetAudioAdapter();
79
80 private:
81 class AudioSink;
82 scoped_ptr<AudioSink> sink_;
83 const scoped_refptr<webrtc::AudioTrackInterface> track_;
84 base::ThreadChecker thread_checker_;
85 }; 86 };
86 87
87 } // namespace content 88 } // namespace content
88 89
89 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_AUDIO_TRACK_H_ 90 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_REMOTE_AUDIO_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698