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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "media/base/message_loop_factory.h" | 21 #include "media/base/message_loop_factory.h" |
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints
.h" | 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints
.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr
y.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr
y.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amComponent.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amComponent.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amSource.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amSource.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
30 | 30 |
| 31 namespace content { |
31 namespace { | 32 namespace { |
32 | 33 |
33 std::string GetMandatoryStreamConstraint( | 34 std::string GetMandatoryStreamConstraint( |
34 const WebKit::WebMediaConstraints& constraints, const std::string& key) { | 35 const WebKit::WebMediaConstraints& constraints, const std::string& key) { |
35 if (constraints.isNull()) | 36 if (constraints.isNull()) |
36 return std::string(); | 37 return std::string(); |
37 | 38 |
38 WebKit::WebString value; | 39 WebKit::WebString value; |
39 constraints.getMandatoryConstraintValue(UTF8ToUTF16(key), value); | 40 constraints.getMandatoryConstraintValue(UTF8ToUTF16(key), value); |
40 return UTF16ToUTF8(value); | 41 return UTF16ToUTF8(value); |
41 } | 42 } |
42 | 43 |
43 void UpdateOptionsIfTabMediaRequest( | 44 void UpdateOptionsIfTabMediaRequest( |
44 const WebKit::WebUserMediaRequest& user_media_request, | 45 const WebKit::WebUserMediaRequest& user_media_request, |
45 media_stream::StreamOptions* options) { | 46 StreamOptions* options) { |
46 if (options->audio_type != content::MEDIA_NO_SERVICE && | 47 if (options->audio_type != content::MEDIA_NO_SERVICE && |
47 GetMandatoryStreamConstraint(user_media_request.audioConstraints(), | 48 GetMandatoryStreamConstraint(user_media_request.audioConstraints(), |
48 media_stream::kMediaStreamSource) == | 49 kMediaStreamSource) == |
49 media_stream::kMediaStreamSourceTab) { | 50 kMediaStreamSourceTab) { |
50 options->audio_type = content::MEDIA_TAB_AUDIO_CAPTURE; | 51 options->audio_type = content::MEDIA_TAB_AUDIO_CAPTURE; |
51 options->audio_device_id = GetMandatoryStreamConstraint( | 52 options->audio_device_id = GetMandatoryStreamConstraint( |
52 user_media_request.audioConstraints(), | 53 user_media_request.audioConstraints(), |
53 media_stream::kMediaStreamSourceId); | 54 kMediaStreamSourceId); |
54 } | 55 } |
55 | 56 |
56 if (options->video_type != content::MEDIA_NO_SERVICE && | 57 if (options->video_type != content::MEDIA_NO_SERVICE && |
57 GetMandatoryStreamConstraint(user_media_request.videoConstraints(), | 58 GetMandatoryStreamConstraint(user_media_request.videoConstraints(), |
58 media_stream::kMediaStreamSource) == | 59 kMediaStreamSource) == |
59 media_stream::kMediaStreamSourceTab) { | 60 kMediaStreamSourceTab) { |
60 options->video_type = content::MEDIA_TAB_VIDEO_CAPTURE; | 61 options->video_type = content::MEDIA_TAB_VIDEO_CAPTURE; |
61 options->video_device_id = GetMandatoryStreamConstraint( | 62 options->video_device_id = GetMandatoryStreamConstraint( |
62 user_media_request.videoConstraints(), | 63 user_media_request.videoConstraints(), |
63 media_stream::kMediaStreamSourceId); | 64 kMediaStreamSourceId); |
64 } | 65 } |
65 } | 66 } |
66 | 67 |
67 static int g_next_request_id = 0; | 68 static int g_next_request_id = 0; |
68 | 69 |
69 // Creates a WebKit representation of a stream sources based on | 70 // Creates a WebKit representation of a stream sources based on |
70 // |devices| from the MediaStreamDispatcher. | 71 // |devices| from the MediaStreamDispatcher. |
71 void CreateWebKitSourceVector( | 72 void CreateWebKitSourceVector( |
72 const std::string& label, | 73 const std::string& label, |
73 const media_stream::StreamDeviceInfoArray& devices, | 74 const StreamDeviceInfoArray& devices, |
74 WebKit::WebMediaStreamSource::Type type, | 75 WebKit::WebMediaStreamSource::Type type, |
75 WebKit::WebVector<WebKit::WebMediaStreamSource>& webkit_sources) { | 76 WebKit::WebVector<WebKit::WebMediaStreamSource>& webkit_sources) { |
76 CHECK_EQ(devices.size(), webkit_sources.size()); | 77 CHECK_EQ(devices.size(), webkit_sources.size()); |
77 for (size_t i = 0; i < devices.size(); ++i) { | 78 for (size_t i = 0; i < devices.size(); ++i) { |
78 std::string source_id = StringPrintf("%s%d%u", label.c_str(), type, | 79 std::string source_id = StringPrintf("%s%d%u", label.c_str(), type, |
79 static_cast<unsigned int>(i)); | 80 static_cast<unsigned int>(i)); |
80 webkit_sources[i].initialize( | 81 webkit_sources[i].initialize( |
81 UTF8ToUTF16(source_id), | 82 UTF8ToUTF16(source_id), |
82 type, | 83 type, |
83 UTF8ToUTF16(devices[i].name)); | 84 UTF8ToUTF16(devices[i].name)); |
84 webkit_sources[i].setExtraData( | 85 webkit_sources[i].setExtraData( |
85 new content::MediaStreamSourceExtraData(devices[i])); | 86 new content::MediaStreamSourceExtraData(devices[i])); |
86 } | 87 } |
87 } | 88 } |
88 | 89 |
89 webrtc::MediaStreamInterface* GetNativeMediaStream( | 90 webrtc::MediaStreamInterface* GetNativeMediaStream( |
90 const WebKit::WebMediaStreamDescriptor& descriptor) { | 91 const WebKit::WebMediaStreamDescriptor& descriptor) { |
91 content::MediaStreamExtraData* extra_data = | 92 content::MediaStreamExtraData* extra_data = |
92 static_cast<content::MediaStreamExtraData*>(descriptor.extraData()); | 93 static_cast<content::MediaStreamExtraData*>(descriptor.extraData()); |
93 if (!extra_data) | 94 if (!extra_data) |
94 return NULL; | 95 return NULL; |
95 webrtc::MediaStreamInterface* stream = extra_data->local_stream(); | 96 webrtc::MediaStreamInterface* stream = extra_data->local_stream(); |
96 if (!stream) | 97 if (!stream) |
97 stream = extra_data->remote_stream(); | 98 stream = extra_data->remote_stream(); |
98 return stream; | 99 return stream; |
99 } | 100 } |
100 | 101 |
101 } // namespace | 102 } // namespace |
102 | 103 |
103 namespace content { | |
104 | |
105 MediaStreamImpl::MediaStreamImpl( | 104 MediaStreamImpl::MediaStreamImpl( |
106 RenderView* render_view, | 105 RenderView* render_view, |
107 MediaStreamDispatcher* media_stream_dispatcher, | 106 MediaStreamDispatcher* media_stream_dispatcher, |
108 VideoCaptureImplManager* vc_manager, | 107 VideoCaptureImplManager* vc_manager, |
109 MediaStreamDependencyFactory* dependency_factory) | 108 MediaStreamDependencyFactory* dependency_factory) |
110 : RenderViewObserver(render_view), | 109 : RenderViewObserver(render_view), |
111 dependency_factory_(dependency_factory), | 110 dependency_factory_(dependency_factory), |
112 media_stream_dispatcher_(media_stream_dispatcher), | 111 media_stream_dispatcher_(media_stream_dispatcher), |
113 vc_manager_(vc_manager) { | 112 vc_manager_(vc_manager) { |
114 } | 113 } |
(...skipping 15 matching lines...) Expand all Loading... |
130 void MediaStreamImpl::requestUserMedia( | 129 void MediaStreamImpl::requestUserMedia( |
131 const WebKit::WebUserMediaRequest& user_media_request, | 130 const WebKit::WebUserMediaRequest& user_media_request, |
132 const WebKit::WebVector<WebKit::WebMediaStreamSource>& audio_sources, | 131 const WebKit::WebVector<WebKit::WebMediaStreamSource>& audio_sources, |
133 const WebKit::WebVector<WebKit::WebMediaStreamSource>& video_sources) { | 132 const WebKit::WebVector<WebKit::WebMediaStreamSource>& video_sources) { |
134 // Save histogram data so we can see how much GetUserMedia is used. | 133 // Save histogram data so we can see how much GetUserMedia is used. |
135 // The histogram counts the number of calls to the JS API | 134 // The histogram counts the number of calls to the JS API |
136 // webGetUserMedia. | 135 // webGetUserMedia. |
137 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); | 136 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); |
138 DCHECK(CalledOnValidThread()); | 137 DCHECK(CalledOnValidThread()); |
139 int request_id = g_next_request_id++; | 138 int request_id = g_next_request_id++; |
140 media_stream::StreamOptions options(MEDIA_NO_SERVICE, MEDIA_NO_SERVICE); | 139 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_NO_SERVICE); |
141 WebKit::WebFrame* frame = NULL; | 140 WebKit::WebFrame* frame = NULL; |
142 GURL security_origin; | 141 GURL security_origin; |
143 | 142 |
144 // |user_media_request| can't be mocked. So in order to test at all we check | 143 // |user_media_request| can't be mocked. So in order to test at all we check |
145 // if it isNull. | 144 // if it isNull. |
146 if (user_media_request.isNull()) { | 145 if (user_media_request.isNull()) { |
147 // We are in a test. | 146 // We are in a test. |
148 if (audio_sources.size() > 0) | 147 if (audio_sources.size() > 0) |
149 options.audio_type = MEDIA_DEVICE_AUDIO_CAPTURE; | 148 options.audio_type = MEDIA_DEVICE_AUDIO_CAPTURE; |
150 if (video_sources.size() > 0) | 149 if (video_sources.size() > 0) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 return CreateVideoDecoder(stream, message_loop_factory); | 252 return CreateVideoDecoder(stream, message_loop_factory); |
254 NOTREACHED(); | 253 NOTREACHED(); |
255 return NULL; | 254 return NULL; |
256 } | 255 } |
257 | 256 |
258 // Callback from MediaStreamDispatcher. | 257 // Callback from MediaStreamDispatcher. |
259 // The requested stream have been generated by the MediaStreamDispatcher. | 258 // The requested stream have been generated by the MediaStreamDispatcher. |
260 void MediaStreamImpl::OnStreamGenerated( | 259 void MediaStreamImpl::OnStreamGenerated( |
261 int request_id, | 260 int request_id, |
262 const std::string& label, | 261 const std::string& label, |
263 const media_stream::StreamDeviceInfoArray& audio_array, | 262 const StreamDeviceInfoArray& audio_array, |
264 const media_stream::StreamDeviceInfoArray& video_array) { | 263 const StreamDeviceInfoArray& video_array) { |
265 DCHECK(CalledOnValidThread()); | 264 DCHECK(CalledOnValidThread()); |
266 | 265 |
267 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id); | 266 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id); |
268 if (!request_info) { | 267 if (!request_info) { |
269 // This can happen if the request is canceled or the frame reloads while | 268 // This can happen if the request is canceled or the frame reloads while |
270 // MediaStreamDispatcher is processing the request. | 269 // MediaStreamDispatcher is processing the request. |
271 // We need to tell the dispatcher to stop the stream. | 270 // We need to tell the dispatcher to stop the stream. |
272 media_stream_dispatcher_->StopStream(label); | 271 media_stream_dispatcher_->StopStream(label); |
273 DVLOG(1) << "Request ID not found"; | 272 DVLOG(1) << "Request ID not found"; |
274 return; | 273 return; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 344 } |
346 CompleteGetUserMediaRequest(request_info->descriptor, &request_info->request, | 345 CompleteGetUserMediaRequest(request_info->descriptor, &request_info->request, |
347 request_succeeded); | 346 request_succeeded); |
348 if (!request_succeeded) { | 347 if (!request_succeeded) { |
349 OnLocalMediaStreamStop(UTF16ToUTF8(description->label())); | 348 OnLocalMediaStreamStop(UTF16ToUTF8(description->label())); |
350 } | 349 } |
351 } | 350 } |
352 | 351 |
353 void MediaStreamImpl::OnDevicesEnumerated( | 352 void MediaStreamImpl::OnDevicesEnumerated( |
354 int request_id, | 353 int request_id, |
355 const media_stream::StreamDeviceInfoArray& device_array) { | 354 const StreamDeviceInfoArray& device_array) { |
356 DVLOG(1) << "MediaStreamImpl::OnDevicesEnumerated(" | 355 DVLOG(1) << "MediaStreamImpl::OnDevicesEnumerated(" |
357 << request_id << ")"; | 356 << request_id << ")"; |
358 NOTIMPLEMENTED(); | 357 NOTIMPLEMENTED(); |
359 } | 358 } |
360 | 359 |
361 void MediaStreamImpl::OnDevicesEnumerationFailed(int request_id) { | 360 void MediaStreamImpl::OnDevicesEnumerationFailed(int request_id) { |
362 DVLOG(1) << "MediaStreamImpl::OnDevicesEnumerationFailed(" | 361 DVLOG(1) << "MediaStreamImpl::OnDevicesEnumerationFailed(" |
363 << request_id << ")"; | 362 << request_id << ")"; |
364 NOTIMPLEMENTED(); | 363 NOTIMPLEMENTED(); |
365 } | 364 } |
366 | 365 |
367 void MediaStreamImpl::OnDeviceOpened( | 366 void MediaStreamImpl::OnDeviceOpened( |
368 int request_id, | 367 int request_id, |
369 const std::string& label, | 368 const std::string& label, |
370 const media_stream::StreamDeviceInfo& video_device) { | 369 const StreamDeviceInfo& video_device) { |
371 DVLOG(1) << "MediaStreamImpl::OnDeviceOpened(" | 370 DVLOG(1) << "MediaStreamImpl::OnDeviceOpened(" |
372 << request_id << ", " << label << ")"; | 371 << request_id << ", " << label << ")"; |
373 NOTIMPLEMENTED(); | 372 NOTIMPLEMENTED(); |
374 } | 373 } |
375 | 374 |
376 void MediaStreamImpl::OnDeviceOpenFailed(int request_id) { | 375 void MediaStreamImpl::OnDeviceOpenFailed(int request_id) { |
377 DVLOG(1) << "MediaStreamImpl::VideoDeviceOpenFailed(" | 376 DVLOG(1) << "MediaStreamImpl::VideoDeviceOpenFailed(" |
378 << request_id << ")"; | 377 << request_id << ")"; |
379 NOTIMPLEMENTED(); | 378 NOTIMPLEMENTED(); |
380 } | 379 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoDecoder label:" | 494 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoDecoder label:" |
496 << stream->label(); | 495 << stream->label(); |
497 | 496 |
498 return new RTCVideoDecoder( | 497 return new RTCVideoDecoder( |
499 message_loop_factory->GetMessageLoop(media::MessageLoopFactory::kDecoder), | 498 message_loop_factory->GetMessageLoop(media::MessageLoopFactory::kDecoder), |
500 base::MessageLoopProxy::current(), | 499 base::MessageLoopProxy::current(), |
501 stream->video_tracks()->at(0)); | 500 stream->video_tracks()->at(0)); |
502 } | 501 } |
503 | 502 |
504 MediaStreamSourceExtraData::MediaStreamSourceExtraData( | 503 MediaStreamSourceExtraData::MediaStreamSourceExtraData( |
505 const media_stream::StreamDeviceInfo& device_info) | 504 const StreamDeviceInfo& device_info) |
506 : device_info_(device_info) { | 505 : device_info_(device_info) { |
507 } | 506 } |
508 | 507 |
509 MediaStreamSourceExtraData::~MediaStreamSourceExtraData() {} | 508 MediaStreamSourceExtraData::~MediaStreamSourceExtraData() {} |
510 | 509 |
511 MediaStreamExtraData::MediaStreamExtraData( | 510 MediaStreamExtraData::MediaStreamExtraData( |
512 webrtc::MediaStreamInterface* remote_stream) | 511 webrtc::MediaStreamInterface* remote_stream) |
513 : remote_stream_(remote_stream) { | 512 : remote_stream_(remote_stream) { |
514 } | 513 } |
515 | 514 |
516 MediaStreamExtraData::MediaStreamExtraData( | 515 MediaStreamExtraData::MediaStreamExtraData( |
517 webrtc::LocalMediaStreamInterface* local_stream) | 516 webrtc::LocalMediaStreamInterface* local_stream) |
518 : local_stream_(local_stream) { | 517 : local_stream_(local_stream) { |
519 } | 518 } |
520 | 519 |
521 MediaStreamExtraData::~MediaStreamExtraData() { | 520 MediaStreamExtraData::~MediaStreamExtraData() { |
522 } | 521 } |
523 | 522 |
524 void MediaStreamExtraData::SetLocalStreamStopCallback( | 523 void MediaStreamExtraData::SetLocalStreamStopCallback( |
525 const StreamStopCallback& stop_callback) { | 524 const StreamStopCallback& stop_callback) { |
526 stream_stop_callback_ = stop_callback; | 525 stream_stop_callback_ = stop_callback; |
527 } | 526 } |
528 | 527 |
529 void MediaStreamExtraData::OnLocalStreamStop() { | 528 void MediaStreamExtraData::OnLocalStreamStop() { |
530 if (!stream_stop_callback_.is_null()) | 529 if (!stream_stop_callback_.is_null()) |
531 stream_stop_callback_.Run(local_stream_->label()); | 530 stream_stop_callback_.Run(local_stream_->label()); |
532 } | 531 } |
533 | 532 |
534 } // namespace content | 533 } // namespace content |
OLD | NEW |