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_impl.h" | 5 #include "content/renderer/media/media_stream_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "content/public/renderer/media_stream_audio_renderer.h" |
13 #include "content/renderer/media/media_stream_dependency_factory.h" | 14 #include "content/renderer/media/media_stream_dependency_factory.h" |
14 #include "content/renderer/media/media_stream_dispatcher.h" | 15 #include "content/renderer/media/media_stream_dispatcher.h" |
15 #include "content/renderer/media/media_stream_extra_data.h" | 16 #include "content/renderer/media/media_stream_extra_data.h" |
16 #include "content/renderer/media/media_stream_source_extra_data.h" | 17 #include "content/renderer/media/media_stream_source_extra_data.h" |
17 #include "content/renderer/media/rtc_video_renderer.h" | 18 #include "content/renderer/media/rtc_video_renderer.h" |
18 #include "content/renderer/media/webrtc_audio_capturer.h" | 19 #include "content/renderer/media/webrtc_audio_capturer.h" |
19 #include "content/renderer/media/webrtc_audio_renderer.h" | 20 #include "content/renderer/media/webrtc_audio_renderer.h" |
20 #include "content/renderer/media/webrtc_local_audio_renderer.h" | 21 #include "content/renderer/media/webrtc_local_audio_renderer.h" |
21 #include "content/renderer/media/webrtc_uma_histograms.h" | 22 #include "content/renderer/media/webrtc_uma_histograms.h" |
22 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 23 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
23 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 24 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
24 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 25 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
25 #include "third_party/WebKit/public/platform/WebVector.h" | 26 #include "third_party/WebKit/public/platform/WebVector.h" |
26 #include "third_party/WebKit/public/web/WebDocument.h" | 27 #include "third_party/WebKit/public/web/WebDocument.h" |
27 #include "third_party/WebKit/public/web/WebFrame.h" | 28 #include "third_party/WebKit/public/web/WebFrame.h" |
28 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" | 29 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" |
29 #include "webkit/renderer/media/media_stream_audio_renderer.h" | |
30 | 30 |
31 namespace content { | 31 namespace content { |
32 namespace { | 32 namespace { |
33 | 33 |
34 std::string GetMandatoryStreamConstraint( | 34 std::string GetMandatoryStreamConstraint( |
35 const WebKit::WebMediaConstraints& constraints, const std::string& key) { | 35 const WebKit::WebMediaConstraints& constraints, const std::string& key) { |
36 if (constraints.isNull()) | 36 if (constraints.isNull()) |
37 return std::string(); | 37 return std::string(); |
38 | 38 |
39 WebKit::WebString value; | 39 WebKit::WebString value; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 DeleteUserMediaRequestInfo(request); | 195 DeleteUserMediaRequestInfo(request); |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
199 WebKit::WebMediaStream MediaStreamImpl::GetMediaStream( | 199 WebKit::WebMediaStream MediaStreamImpl::GetMediaStream( |
200 const GURL& url) { | 200 const GURL& url) { |
201 return WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url); | 201 return WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url); |
202 } | 202 } |
203 | 203 |
204 bool MediaStreamImpl::IsMediaStream(const GURL& url) { | 204 bool MediaStreamImpl::IsMediaStream(const GURL& url) { |
205 return CheckMediaStream(url); | |
206 } | |
207 | |
208 // static | |
209 bool MediaStreamImpl::CheckMediaStream(const GURL& url) { | |
210 WebKit::WebMediaStream descriptor( | 205 WebKit::WebMediaStream descriptor( |
211 WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url)); | 206 WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url)); |
212 | 207 |
213 if (descriptor.isNull() || !descriptor.extraData()) | 208 if (descriptor.isNull() || !descriptor.extraData()) |
214 return false; // This is not a valid stream. | 209 return false; // This is not a valid stream. |
215 | 210 |
216 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor); | 211 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor); |
217 return (stream && | 212 return (stream && |
218 (!stream->GetVideoTracks().empty() || !stream->GetAudioTracks().empty())); | 213 (!stream->GetVideoTracks().empty() || !stream->GetAudioTracks().empty())); |
219 } | 214 } |
220 | 215 |
221 scoped_refptr<webkit_media::VideoFrameProvider> | 216 scoped_refptr<VideoFrameProvider> |
222 MediaStreamImpl::GetVideoFrameProvider( | 217 MediaStreamImpl::GetVideoFrameProvider( |
223 const GURL& url, | 218 const GURL& url, |
224 const base::Closure& error_cb, | 219 const base::Closure& error_cb, |
225 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) { | 220 const VideoFrameProvider::RepaintCB& repaint_cb) { |
226 DCHECK(CalledOnValidThread()); | 221 DCHECK(CalledOnValidThread()); |
227 WebKit::WebMediaStream descriptor(GetMediaStream(url)); | 222 WebKit::WebMediaStream descriptor(GetMediaStream(url)); |
228 | 223 |
229 if (descriptor.isNull() || !descriptor.extraData()) | 224 if (descriptor.isNull() || !descriptor.extraData()) |
230 return NULL; // This is not a valid stream. | 225 return NULL; // This is not a valid stream. |
231 | 226 |
232 DVLOG(1) << "MediaStreamImpl::GetVideoFrameProvider stream:" | 227 DVLOG(1) << "MediaStreamImpl::GetVideoFrameProvider stream:" |
233 << UTF16ToUTF8(descriptor.label()); | 228 << UTF16ToUTF8(descriptor.label()); |
234 | 229 |
235 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor); | 230 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor); |
236 if (stream) | 231 if (stream) |
237 return CreateVideoFrameProvider(stream, error_cb, repaint_cb); | 232 return CreateVideoFrameProvider(stream, error_cb, repaint_cb); |
238 NOTREACHED(); | 233 NOTREACHED(); |
239 return NULL; | 234 return NULL; |
240 } | 235 } |
241 | 236 |
242 scoped_refptr<webkit_media::MediaStreamAudioRenderer> | 237 scoped_refptr<MediaStreamAudioRenderer> |
243 MediaStreamImpl::GetAudioRenderer(const GURL& url) { | 238 MediaStreamImpl::GetAudioRenderer(const GURL& url) { |
244 DCHECK(CalledOnValidThread()); | 239 DCHECK(CalledOnValidThread()); |
245 WebKit::WebMediaStream descriptor(GetMediaStream(url)); | 240 WebKit::WebMediaStream descriptor(GetMediaStream(url)); |
246 | 241 |
247 if (descriptor.isNull() || !descriptor.extraData()) | 242 if (descriptor.isNull() || !descriptor.extraData()) |
248 return NULL; // This is not a valid stream. | 243 return NULL; // This is not a valid stream. |
249 | 244 |
250 DVLOG(1) << "MediaStreamImpl::GetAudioRenderer stream:" | 245 DVLOG(1) << "MediaStreamImpl::GetAudioRenderer stream:" |
251 << UTF16ToUTF8(descriptor.label()); | 246 << UTF16ToUTF8(descriptor.label()); |
252 | 247 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 media_stream_dispatcher_->CancelGenerateStream( | 495 media_stream_dispatcher_->CancelGenerateStream( |
501 (*request_it)->request_id); | 496 (*request_it)->request_id); |
502 } | 497 } |
503 request_it = user_media_requests_.erase(request_it); | 498 request_it = user_media_requests_.erase(request_it); |
504 } else { | 499 } else { |
505 ++request_it; | 500 ++request_it; |
506 } | 501 } |
507 } | 502 } |
508 } | 503 } |
509 | 504 |
510 scoped_refptr<webkit_media::VideoFrameProvider> | 505 scoped_refptr<VideoFrameProvider> |
511 MediaStreamImpl::CreateVideoFrameProvider( | 506 MediaStreamImpl::CreateVideoFrameProvider( |
512 webrtc::MediaStreamInterface* stream, | 507 webrtc::MediaStreamInterface* stream, |
513 const base::Closure& error_cb, | 508 const base::Closure& error_cb, |
514 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) { | 509 const VideoFrameProvider::RepaintCB& repaint_cb) { |
515 if (stream->GetVideoTracks().empty()) | 510 if (stream->GetVideoTracks().empty()) |
516 return NULL; | 511 return NULL; |
517 | 512 |
518 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoFrameProvider label:" | 513 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoFrameProvider label:" |
519 << stream->label(); | 514 << stream->label(); |
520 | 515 |
521 return new RTCVideoRenderer( | 516 return new RTCVideoRenderer( |
522 stream->GetVideoTracks()[0], | 517 stream->GetVideoTracks()[0], |
523 error_cb, | 518 error_cb, |
524 repaint_cb); | 519 repaint_cb); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 } | 617 } |
623 | 618 |
624 for (size_t i = 0; i < video_sources.size(); ++i) { | 619 for (size_t i = 0; i < video_sources.size(); ++i) { |
625 video_sources[i].setReadyState( | 620 video_sources[i].setReadyState( |
626 WebKit::WebMediaStreamSource::ReadyStateEnded); | 621 WebKit::WebMediaStreamSource::ReadyStateEnded); |
627 video_sources[i].setExtraData(NULL); | 622 video_sources[i].setExtraData(NULL); |
628 } | 623 } |
629 } | 624 } |
630 | 625 |
631 } // namespace content | 626 } // namespace content |
OLD | NEW |