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

Side by Side Diff: content/renderer/media/media_stream_center.cc

Issue 1834323002: MediaStream audio: Refactor 3 separate "glue" implementations into one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: REBASE + Workaround to ensure MediaStreamAudioProcessor is destroyed on the main thread. Created 4 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "content/renderer/media/media_stream_center.h" 5 #include "content/renderer/media/media_stream_center.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "content/common/media/media_stream_messages.h" 13 #include "content/common/media/media_stream_messages.h"
14 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
15 #include "content/public/renderer/media_stream_audio_sink.h" 15 #include "content/public/renderer/media_stream_audio_sink.h"
16 #include "content/public/renderer/render_thread.h" 16 #include "content/public/renderer/render_thread.h"
17 #include "content/renderer/media/media_stream.h" 17 #include "content/renderer/media/media_stream.h"
18 #include "content/renderer/media/media_stream_audio_track.h" 18 #include "content/renderer/media/media_stream_audio_track.h"
19 #include "content/renderer/media/media_stream_source.h" 19 #include "content/renderer/media/media_stream_source.h"
20 #include "content/renderer/media/media_stream_video_source.h" 20 #include "content/renderer/media/media_stream_video_source.h"
21 #include "content/renderer/media/media_stream_video_track.h" 21 #include "content/renderer/media/media_stream_video_track.h"
22 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" 22 #include "content/renderer/media/webaudio_media_stream_source.h"
23 #include "content/renderer/media/webrtc_local_audio_source_provider.h" 23 #include "content/renderer/media/webrtc_local_audio_source_provider.h"
24 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 24 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
25 #include "third_party/WebKit/public/platform/WebMediaStream.h" 25 #include "third_party/WebKit/public/platform/WebMediaStream.h"
26 #include "third_party/WebKit/public/platform/WebMediaStreamCenterClient.h" 26 #include "third_party/WebKit/public/platform/WebMediaStreamCenterClient.h"
27 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 27 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
28 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 28 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
29 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h " 29 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h "
30 #include "third_party/WebKit/public/platform/WebSourceInfo.h" 30 #include "third_party/WebKit/public/platform/WebSourceInfo.h"
31 #include "third_party/WebKit/public/platform/WebVector.h" 31 #include "third_party/WebKit/public/platform/WebVector.h"
32 #include "third_party/WebKit/public/web/WebFrame.h" 32 #include "third_party/WebKit/public/web/WebFrame.h"
33 33
34 using blink::WebFrame; 34 using blink::WebFrame;
35 using blink::WebView; 35 using blink::WebView;
36 36
37 namespace content { 37 namespace content {
38 38
39 namespace { 39 namespace {
40 40
41 void CreateNativeAudioMediaStreamTrack( 41 void CreateNativeAudioMediaStreamTrack(
42 const blink::WebMediaStreamTrack& track, 42 const blink::WebMediaStreamTrack& track) {
43 PeerConnectionDependencyFactory* factory) {
44 DCHECK(!MediaStreamAudioTrack::From(track));
45 blink::WebMediaStreamSource source = track.source(); 43 blink::WebMediaStreamSource source = track.source();
46 DCHECK_EQ(source.getType(), blink::WebMediaStreamSource::TypeAudio); 44 MediaStreamAudioSource* media_stream_source =
47 if (source.remote()) { 45 MediaStreamAudioSource::From(source);
48 factory->CreateRemoteAudioTrack(track); 46
49 } else { 47 // At this point, a MediaStreamAudioSource instance must exist. The one
50 factory->CreateLocalAudioTrack(track); 48 // exception is when a WebAudio destination node is acting as a source of
49 // audio.
50 //
51 // TODO(miu): This needs to be moved to an appropriate location. A WebAudio
52 // source should have been created before this method was called so that this
53 // special case code isn't needed here.
54 if (!media_stream_source && source.requiresAudioConsumer()) {
55 DVLOG(1) << "Creating WebAudio media stream source.";
56 media_stream_source = new WebAudioMediaStreamSource(&source);
57 source.setExtraData(media_stream_source); // Takes ownership.
51 } 58 }
59
60 if (media_stream_source)
61 media_stream_source->ConnectToTrack(track);
62 else
63 LOG(DFATAL) << "WebMediaStreamSource missing its MediaStreamAudioSource.";
52 } 64 }
53 65
54 void CreateNativeVideoMediaStreamTrack( 66 void CreateNativeVideoMediaStreamTrack(
55 const blink::WebMediaStreamTrack& track) { 67 const blink::WebMediaStreamTrack& track) {
56 DCHECK(track.getExtraData() == NULL); 68 DCHECK(track.getExtraData() == NULL);
57 blink::WebMediaStreamSource source = track.source(); 69 blink::WebMediaStreamSource source = track.source();
58 DCHECK_EQ(source.getType(), blink::WebMediaStreamSource::TypeVideo); 70 DCHECK_EQ(source.getType(), blink::WebMediaStreamSource::TypeVideo);
59 MediaStreamVideoSource* native_source = 71 MediaStreamVideoSource* native_source =
60 MediaStreamVideoSource::GetVideoSource(source); 72 MediaStreamVideoSource::GetVideoSource(source);
61 DCHECK(native_source); 73 DCHECK(native_source);
62 blink::WebMediaStreamTrack writable_track(track); 74 blink::WebMediaStreamTrack writable_track(track);
63 // TODO(perkj): The constraints to use here should be passed from blink when 75 // TODO(perkj): The constraints to use here should be passed from blink when
64 // a new track is created. For cloning, it should be the constraints of the 76 // a new track is created. For cloning, it should be the constraints of the
65 // cloned track and not the originating source. 77 // cloned track and not the originating source.
66 // Also - source.constraints() returns an uninitialized constraint if the 78 // Also - source.constraints() returns an uninitialized constraint if the
67 // source is coming from a remote video track. See http://crbug/287805. 79 // source is coming from a remote video track. See http://crbug/287805.
68 blink::WebMediaConstraints constraints = source.constraints(); 80 blink::WebMediaConstraints constraints = source.constraints();
69 if (constraints.isNull()) 81 if (constraints.isNull())
70 constraints.initialize(); 82 constraints.initialize();
71 writable_track.setExtraData( 83 writable_track.setExtraData(
72 new MediaStreamVideoTrack(native_source, constraints, 84 new MediaStreamVideoTrack(native_source, constraints,
73 MediaStreamVideoSource::ConstraintsCallback(), 85 MediaStreamVideoSource::ConstraintsCallback(),
74 track.isEnabled())); 86 track.isEnabled()));
75 } 87 }
76 88
77 void CreateNativeMediaStreamTrack(const blink::WebMediaStreamTrack& track, 89 } // namespace
78 PeerConnectionDependencyFactory* factory) { 90
91 MediaStreamCenter::MediaStreamCenter(
92 blink::WebMediaStreamCenterClient* client,
93 PeerConnectionDependencyFactory* factory) {}
94
95 MediaStreamCenter::~MediaStreamCenter() {}
96
97 void MediaStreamCenter::didCreateMediaStreamTrack(
98 const blink::WebMediaStreamTrack& track) {
99 DVLOG(1) << "MediaStreamCenter::didCreateMediaStreamTrack";
79 DCHECK(!track.isNull() && !track.getExtraData()); 100 DCHECK(!track.isNull() && !track.getExtraData());
80 DCHECK(!track.source().isNull()); 101 DCHECK(!track.source().isNull());
81 102
82 switch (track.source().getType()) { 103 switch (track.source().getType()) {
83 case blink::WebMediaStreamSource::TypeAudio: 104 case blink::WebMediaStreamSource::TypeAudio:
84 CreateNativeAudioMediaStreamTrack(track, factory); 105 CreateNativeAudioMediaStreamTrack(track);
85 break; 106 break;
86 case blink::WebMediaStreamSource::TypeVideo: 107 case blink::WebMediaStreamSource::TypeVideo:
87 CreateNativeVideoMediaStreamTrack(track); 108 CreateNativeVideoMediaStreamTrack(track);
88 break; 109 break;
89 } 110 }
90 } 111 }
91 112
92 } // namespace
93
94 MediaStreamCenter::MediaStreamCenter(blink::WebMediaStreamCenterClient* client,
95 PeerConnectionDependencyFactory* factory)
96 : rtc_factory_(factory) {}
97
98 MediaStreamCenter::~MediaStreamCenter() {}
99
100 void MediaStreamCenter::didCreateMediaStreamTrack(
101 const blink::WebMediaStreamTrack& track) {
102 DVLOG(1) << "MediaStreamCenter::didCreateMediaStreamTrack";
103 CreateNativeMediaStreamTrack(track, rtc_factory_);
104 }
105
106 void MediaStreamCenter::didEnableMediaStreamTrack( 113 void MediaStreamCenter::didEnableMediaStreamTrack(
107 const blink::WebMediaStreamTrack& track) { 114 const blink::WebMediaStreamTrack& track) {
108 MediaStreamTrack* native_track = 115 MediaStreamTrack* native_track =
109 MediaStreamTrack::GetTrack(track); 116 MediaStreamTrack::GetTrack(track);
110 if (native_track) 117 if (native_track)
111 native_track->SetEnabled(true); 118 native_track->SetEnabled(true);
112 } 119 }
113 120
114 void MediaStreamCenter::didDisableMediaStreamTrack( 121 void MediaStreamCenter::didDisableMediaStreamTrack(
115 const blink::WebMediaStreamTrack& track) { 122 const blink::WebMediaStreamTrack& track) {
(...skipping 19 matching lines...) Expand all
135 static_cast<MediaStreamTrack*>(track.getExtraData()); 142 static_cast<MediaStreamTrack*>(track.getExtraData());
136 if (!media_stream_track) { 143 if (!media_stream_track) {
137 DLOG(ERROR) << "Native track missing for webaudio source."; 144 DLOG(ERROR) << "Native track missing for webaudio source.";
138 return nullptr; 145 return nullptr;
139 } 146 }
140 147
141 blink::WebMediaStreamSource source = track.source(); 148 blink::WebMediaStreamSource source = track.source();
142 DCHECK_EQ(source.getType(), blink::WebMediaStreamSource::TypeAudio); 149 DCHECK_EQ(source.getType(), blink::WebMediaStreamSource::TypeAudio);
143 150
144 // TODO(tommi): Rename WebRtcLocalAudioSourceProvider to 151 // TODO(tommi): Rename WebRtcLocalAudioSourceProvider to
145 // WebRtcAudioSourceProvider since it's not specific to local. 152 // WebAudioMediaStreamSink since it's not specific to any particular source.
153 // http://crbug.com/577874
146 return new WebRtcLocalAudioSourceProvider(track); 154 return new WebRtcLocalAudioSourceProvider(track);
147 } 155 }
148 156
149 void MediaStreamCenter::didStopLocalMediaStream( 157 void MediaStreamCenter::didStopLocalMediaStream(
150 const blink::WebMediaStream& stream) { 158 const blink::WebMediaStream& stream) {
151 DVLOG(1) << "MediaStreamCenter::didStopLocalMediaStream"; 159 DVLOG(1) << "MediaStreamCenter::didStopLocalMediaStream";
152 MediaStream* native_stream = MediaStream::GetMediaStream(stream); 160 MediaStream* native_stream = MediaStream::GetMediaStream(stream);
153 if (!native_stream) { 161 if (!native_stream) {
154 NOTREACHED(); 162 NOTREACHED();
155 return; 163 return;
(...skipping 29 matching lines...) Expand all
185 193
186 bool MediaStreamCenter::didRemoveMediaStreamTrack( 194 bool MediaStreamCenter::didRemoveMediaStreamTrack(
187 const blink::WebMediaStream& stream, 195 const blink::WebMediaStream& stream,
188 const blink::WebMediaStreamTrack& track) { 196 const blink::WebMediaStreamTrack& track) {
189 DVLOG(1) << "MediaStreamCenter::didRemoveMediaStreamTrack"; 197 DVLOG(1) << "MediaStreamCenter::didRemoveMediaStreamTrack";
190 MediaStream* native_stream = MediaStream::GetMediaStream(stream); 198 MediaStream* native_stream = MediaStream::GetMediaStream(stream);
191 return native_stream->RemoveTrack(track); 199 return native_stream->RemoveTrack(track);
192 } 200 }
193 201
194 } // namespace content 202 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_center.h ('k') | content/renderer/media/media_stream_renderer_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698