OLD | NEW |
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/webaudio_media_stream_source.h" | 22 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.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)); |
43 blink::WebMediaStreamSource source = track.source(); | 45 blink::WebMediaStreamSource source = track.source(); |
44 MediaStreamAudioSource* media_stream_source = | 46 DCHECK_EQ(source.getType(), blink::WebMediaStreamSource::TypeAudio); |
45 MediaStreamAudioSource::From(source); | 47 if (source.remote()) { |
46 | 48 factory->CreateRemoteAudioTrack(track); |
47 // At this point, a MediaStreamAudioSource instance must exist. The one | 49 } else { |
48 // exception is when a WebAudio destination node is acting as a source of | 50 factory->CreateLocalAudioTrack(track); |
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. | |
58 } | 51 } |
59 | |
60 if (media_stream_source) | |
61 media_stream_source->ConnectToTrack(track); | |
62 else | |
63 LOG(DFATAL) << "WebMediaStreamSource missing its MediaStreamAudioSource."; | |
64 } | 52 } |
65 | 53 |
66 void CreateNativeVideoMediaStreamTrack( | 54 void CreateNativeVideoMediaStreamTrack( |
67 const blink::WebMediaStreamTrack& track) { | 55 const blink::WebMediaStreamTrack& track) { |
68 DCHECK(track.getExtraData() == NULL); | 56 DCHECK(track.getExtraData() == NULL); |
69 blink::WebMediaStreamSource source = track.source(); | 57 blink::WebMediaStreamSource source = track.source(); |
70 DCHECK_EQ(source.getType(), blink::WebMediaStreamSource::TypeVideo); | 58 DCHECK_EQ(source.getType(), blink::WebMediaStreamSource::TypeVideo); |
71 MediaStreamVideoSource* native_source = | 59 MediaStreamVideoSource* native_source = |
72 MediaStreamVideoSource::GetVideoSource(source); | 60 MediaStreamVideoSource::GetVideoSource(source); |
73 DCHECK(native_source); | 61 DCHECK(native_source); |
74 blink::WebMediaStreamTrack writable_track(track); | 62 blink::WebMediaStreamTrack writable_track(track); |
75 // TODO(perkj): The constraints to use here should be passed from blink when | 63 // TODO(perkj): The constraints to use here should be passed from blink when |
76 // a new track is created. For cloning, it should be the constraints of the | 64 // a new track is created. For cloning, it should be the constraints of the |
77 // cloned track and not the originating source. | 65 // cloned track and not the originating source. |
78 // Also - source.constraints() returns an uninitialized constraint if the | 66 // Also - source.constraints() returns an uninitialized constraint if the |
79 // source is coming from a remote video track. See http://crbug/287805. | 67 // source is coming from a remote video track. See http://crbug/287805. |
80 blink::WebMediaConstraints constraints = source.constraints(); | 68 blink::WebMediaConstraints constraints = source.constraints(); |
81 if (constraints.isNull()) | 69 if (constraints.isNull()) |
82 constraints.initialize(); | 70 constraints.initialize(); |
83 writable_track.setExtraData( | 71 writable_track.setExtraData( |
84 new MediaStreamVideoTrack(native_source, constraints, | 72 new MediaStreamVideoTrack(native_source, constraints, |
85 MediaStreamVideoSource::ConstraintsCallback(), | 73 MediaStreamVideoSource::ConstraintsCallback(), |
86 track.isEnabled())); | 74 track.isEnabled())); |
87 } | 75 } |
88 | 76 |
89 } // namespace | 77 void CreateNativeMediaStreamTrack(const blink::WebMediaStreamTrack& track, |
90 | 78 PeerConnectionDependencyFactory* factory) { |
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"; | |
100 DCHECK(!track.isNull() && !track.getExtraData()); | 79 DCHECK(!track.isNull() && !track.getExtraData()); |
101 DCHECK(!track.source().isNull()); | 80 DCHECK(!track.source().isNull()); |
102 | 81 |
103 switch (track.source().getType()) { | 82 switch (track.source().getType()) { |
104 case blink::WebMediaStreamSource::TypeAudio: | 83 case blink::WebMediaStreamSource::TypeAudio: |
105 CreateNativeAudioMediaStreamTrack(track); | 84 CreateNativeAudioMediaStreamTrack(track, factory); |
106 break; | 85 break; |
107 case blink::WebMediaStreamSource::TypeVideo: | 86 case blink::WebMediaStreamSource::TypeVideo: |
108 CreateNativeVideoMediaStreamTrack(track); | 87 CreateNativeVideoMediaStreamTrack(track); |
109 break; | 88 break; |
110 } | 89 } |
111 } | 90 } |
112 | 91 |
| 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 |
113 void MediaStreamCenter::didEnableMediaStreamTrack( | 106 void MediaStreamCenter::didEnableMediaStreamTrack( |
114 const blink::WebMediaStreamTrack& track) { | 107 const blink::WebMediaStreamTrack& track) { |
115 MediaStreamTrack* native_track = | 108 MediaStreamTrack* native_track = |
116 MediaStreamTrack::GetTrack(track); | 109 MediaStreamTrack::GetTrack(track); |
117 if (native_track) | 110 if (native_track) |
118 native_track->SetEnabled(true); | 111 native_track->SetEnabled(true); |
119 } | 112 } |
120 | 113 |
121 void MediaStreamCenter::didDisableMediaStreamTrack( | 114 void MediaStreamCenter::didDisableMediaStreamTrack( |
122 const blink::WebMediaStreamTrack& track) { | 115 const blink::WebMediaStreamTrack& track) { |
(...skipping 19 matching lines...) Expand all Loading... |
142 static_cast<MediaStreamTrack*>(track.getExtraData()); | 135 static_cast<MediaStreamTrack*>(track.getExtraData()); |
143 if (!media_stream_track) { | 136 if (!media_stream_track) { |
144 DLOG(ERROR) << "Native track missing for webaudio source."; | 137 DLOG(ERROR) << "Native track missing for webaudio source."; |
145 return nullptr; | 138 return nullptr; |
146 } | 139 } |
147 | 140 |
148 blink::WebMediaStreamSource source = track.source(); | 141 blink::WebMediaStreamSource source = track.source(); |
149 DCHECK_EQ(source.getType(), blink::WebMediaStreamSource::TypeAudio); | 142 DCHECK_EQ(source.getType(), blink::WebMediaStreamSource::TypeAudio); |
150 | 143 |
151 // TODO(tommi): Rename WebRtcLocalAudioSourceProvider to | 144 // TODO(tommi): Rename WebRtcLocalAudioSourceProvider to |
152 // WebAudioMediaStreamSink since it's not specific to any particular source. | 145 // WebRtcAudioSourceProvider since it's not specific to local. |
153 // http://crbug.com/577874 | |
154 return new WebRtcLocalAudioSourceProvider(track); | 146 return new WebRtcLocalAudioSourceProvider(track); |
155 } | 147 } |
156 | 148 |
157 void MediaStreamCenter::didStopLocalMediaStream( | 149 void MediaStreamCenter::didStopLocalMediaStream( |
158 const blink::WebMediaStream& stream) { | 150 const blink::WebMediaStream& stream) { |
159 DVLOG(1) << "MediaStreamCenter::didStopLocalMediaStream"; | 151 DVLOG(1) << "MediaStreamCenter::didStopLocalMediaStream"; |
160 MediaStream* native_stream = MediaStream::GetMediaStream(stream); | 152 MediaStream* native_stream = MediaStream::GetMediaStream(stream); |
161 if (!native_stream) { | 153 if (!native_stream) { |
162 NOTREACHED(); | 154 NOTREACHED(); |
163 return; | 155 return; |
(...skipping 29 matching lines...) Expand all Loading... |
193 | 185 |
194 bool MediaStreamCenter::didRemoveMediaStreamTrack( | 186 bool MediaStreamCenter::didRemoveMediaStreamTrack( |
195 const blink::WebMediaStream& stream, | 187 const blink::WebMediaStream& stream, |
196 const blink::WebMediaStreamTrack& track) { | 188 const blink::WebMediaStreamTrack& track) { |
197 DVLOG(1) << "MediaStreamCenter::didRemoveMediaStreamTrack"; | 189 DVLOG(1) << "MediaStreamCenter::didRemoveMediaStreamTrack"; |
198 MediaStream* native_stream = MediaStream::GetMediaStream(stream); | 190 MediaStream* native_stream = MediaStream::GetMediaStream(stream); |
199 return native_stream->RemoveTrack(track); | 191 return native_stream->RemoveTrack(track); |
200 } | 192 } |
201 | 193 |
202 } // namespace content | 194 } // namespace content |
OLD | NEW |