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/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "content/renderer/media/capture_video_decoder.h" | 13 #include "content/renderer/media/capture_video_decoder.h" |
| 14 #include "content/renderer/media/local_video_capture.h" |
14 #include "content/renderer/media/media_stream_extra_data.h" | 15 #include "content/renderer/media/media_stream_extra_data.h" |
15 #include "content/renderer/media/media_stream_source_extra_data.h" | 16 #include "content/renderer/media/media_stream_source_extra_data.h" |
16 #include "content/renderer/media/media_stream_dependency_factory.h" | 17 #include "content/renderer/media/media_stream_dependency_factory.h" |
17 #include "content/renderer/media/media_stream_dispatcher.h" | 18 #include "content/renderer/media/media_stream_dispatcher.h" |
18 #include "content/renderer/media/rtc_video_decoder.h" | 19 #include "content/renderer/media/rtc_video_decoder.h" |
| 20 #include "content/renderer/media/rtc_video_renderer.h" |
19 #include "content/renderer/media/video_capture_impl_manager.h" | 21 #include "content/renderer/media/video_capture_impl_manager.h" |
20 #include "content/renderer/media/webrtc_uma_histograms.h" | 22 #include "content/renderer/media/webrtc_uma_histograms.h" |
21 #include "media/base/message_loop_factory.h" | 23 #include "media/base/message_loop_factory.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr
y.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr
y.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amComponent.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amComponent.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amDescriptor.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amDescriptor.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amSource.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amSource.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 media_stream_dispatcher_->CancelGenerateStream(it->first); | 138 media_stream_dispatcher_->CancelGenerateStream(it->first); |
137 user_media_requests_.erase(it); | 139 user_media_requests_.erase(it); |
138 } | 140 } |
139 } | 141 } |
140 | 142 |
141 WebKit::WebMediaStreamDescriptor MediaStreamImpl::GetMediaStream( | 143 WebKit::WebMediaStreamDescriptor MediaStreamImpl::GetMediaStream( |
142 const GURL& url) { | 144 const GURL& url) { |
143 return WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url); | 145 return WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url); |
144 } | 146 } |
145 | 147 |
| 148 bool MediaStreamImpl::IsMediaStream(const GURL& url) { |
| 149 DCHECK(CalledOnValidThread()); |
| 150 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); |
| 151 |
| 152 if (descriptor.isNull() || !descriptor.extraData()) |
| 153 return false; // This is not a valid stream. |
| 154 |
| 155 MediaStreamExtraData* extra_data = |
| 156 static_cast<MediaStreamExtraData*>(descriptor.extraData()); |
| 157 webrtc::MediaStreamInterface* stream = extra_data->local_stream(); |
| 158 if (stream && stream->video_tracks() && stream->video_tracks()->count() > 0) |
| 159 return true; |
| 160 stream = extra_data->remote_stream(); |
| 161 if (stream && stream->video_tracks() && stream->video_tracks()->count() > 0) |
| 162 return true; |
| 163 return false; |
| 164 } |
| 165 |
| 166 scoped_refptr<webkit_media::VideoFrameProvider> |
| 167 MediaStreamImpl::GetVideoFrameProvider( |
| 168 const GURL& url, |
| 169 const base::Closure& error_cb, |
| 170 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) { |
| 171 DCHECK(CalledOnValidThread()); |
| 172 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); |
| 173 |
| 174 if (descriptor.isNull() || !descriptor.extraData()) |
| 175 return NULL; // This is not a valid stream. |
| 176 |
| 177 DVLOG(1) << "MediaStreamImpl::GetVideoFrameProvider stream:" |
| 178 << UTF16ToUTF8(descriptor.label()); |
| 179 |
| 180 MediaStreamExtraData* extra_data = |
| 181 static_cast<MediaStreamExtraData*>(descriptor.extraData()); |
| 182 if (extra_data->local_stream()) |
| 183 return CreateLocalVideoFrameProvider(extra_data->local_stream(), |
| 184 error_cb, repaint_cb); |
| 185 if (extra_data->remote_stream()) |
| 186 return CreateRemoteVideoFrameProvider(extra_data->remote_stream(), |
| 187 error_cb, repaint_cb); |
| 188 NOTREACHED(); |
| 189 return NULL; |
| 190 } |
| 191 |
146 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( | 192 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( |
147 const GURL& url, | 193 const GURL& url, |
148 media::MessageLoopFactory* message_loop_factory) { | 194 media::MessageLoopFactory* message_loop_factory) { |
149 DCHECK(CalledOnValidThread()); | 195 DCHECK(CalledOnValidThread()); |
150 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); | 196 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); |
151 | 197 |
152 if (descriptor.isNull() || !descriptor.extraData()) | 198 if (descriptor.isNull() || !descriptor.extraData()) |
153 return NULL; // This is not a valid stream. | 199 return NULL; // This is not a valid stream. |
154 | 200 |
155 DVLOG(1) << "MediaStreamImpl::GetVideoDecoder stream:" | 201 DVLOG(1) << "MediaStreamImpl::GetVideoDecoder stream:" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 << "Stopping stream " << it->first; | 346 << "Stopping stream " << it->first; |
301 media_stream_dispatcher_->StopStream(it->first); | 347 media_stream_dispatcher_->StopStream(it->first); |
302 local_media_streams_.erase(it); | 348 local_media_streams_.erase(it); |
303 it = local_media_streams_.begin(); | 349 it = local_media_streams_.begin(); |
304 } else { | 350 } else { |
305 ++it; | 351 ++it; |
306 } | 352 } |
307 } | 353 } |
308 } | 354 } |
309 | 355 |
| 356 scoped_refptr<webkit_media::VideoFrameProvider> |
| 357 MediaStreamImpl::CreateLocalVideoFrameProvider( |
| 358 webrtc::MediaStreamInterface* stream, |
| 359 const base::Closure& error_cb, |
| 360 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) { |
| 361 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) |
| 362 return NULL; |
| 363 |
| 364 int video_session_id = |
| 365 media_stream_dispatcher_->video_session_id(stream->label(), 0); |
| 366 media::VideoCaptureCapability capability; |
| 367 capability.width = kVideoCaptureWidth; |
| 368 capability.height = kVideoCaptureHeight; |
| 369 capability.frame_rate = kVideoCaptureFramePerSecond; |
| 370 capability.color = media::VideoCaptureCapability::kI420; |
| 371 capability.expected_capture_delay = 0; |
| 372 capability.interlaced = false; |
| 373 |
| 374 DVLOG(1) << "MediaStreamImpl::CreateLocalVideoFrameProvider video_session_id:" |
| 375 << video_session_id; |
| 376 |
| 377 return new content::LocalVideoCapture( |
| 378 video_session_id, |
| 379 vc_manager_.get(), |
| 380 capability, |
| 381 error_cb, |
| 382 repaint_cb); |
| 383 } |
| 384 |
| 385 scoped_refptr<webkit_media::VideoFrameProvider> |
| 386 MediaStreamImpl::CreateRemoteVideoFrameProvider( |
| 387 webrtc::MediaStreamInterface* stream, |
| 388 const base::Closure& error_cb, |
| 389 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) { |
| 390 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) |
| 391 return NULL; |
| 392 |
| 393 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoFrameProvider label:" |
| 394 << stream->label(); |
| 395 |
| 396 return new content::RTCVideoRenderer( |
| 397 stream->video_tracks()->at(0), |
| 398 error_cb, |
| 399 repaint_cb); |
| 400 } |
| 401 |
310 scoped_refptr<media::VideoDecoder> MediaStreamImpl::CreateLocalVideoDecoder( | 402 scoped_refptr<media::VideoDecoder> MediaStreamImpl::CreateLocalVideoDecoder( |
311 webrtc::MediaStreamInterface* stream, | 403 webrtc::MediaStreamInterface* stream, |
312 media::MessageLoopFactory* message_loop_factory) { | 404 media::MessageLoopFactory* message_loop_factory) { |
313 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) | 405 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) |
314 return NULL; | 406 return NULL; |
315 | 407 |
316 int video_session_id = | 408 int video_session_id = |
317 media_stream_dispatcher_->video_session_id(stream->label(), 0); | 409 media_stream_dispatcher_->video_session_id(stream->label(), 0); |
318 media::VideoCaptureCapability capability; | 410 media::VideoCaptureCapability capability; |
319 capability.width = kVideoCaptureWidth; | 411 capability.width = kVideoCaptureWidth; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 456 |
365 void MediaStreamExtraData::SetLocalStreamStopCallback( | 457 void MediaStreamExtraData::SetLocalStreamStopCallback( |
366 const StreamStopCallback& stop_callback) { | 458 const StreamStopCallback& stop_callback) { |
367 stream_stop_callback_ = stop_callback; | 459 stream_stop_callback_ = stop_callback; |
368 } | 460 } |
369 | 461 |
370 void MediaStreamExtraData::OnLocalStreamStop() { | 462 void MediaStreamExtraData::OnLocalStreamStop() { |
371 if (!stream_stop_callback_.is_null()) | 463 if (!stream_stop_callback_.is_null()) |
372 stream_stop_callback_.Run(local_stream_->label()); | 464 stream_stop_callback_.Run(local_stream_->label()); |
373 } | 465 } |
OLD | NEW |