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/command_line.h" | |
mcasas
2014/05/27 12:08:23
Needed?
Henrik Grunell
2014/05/27 15:33:54
No, thanks.
| |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "content/public/common/content_switches.h" | |
mcasas
2014/05/27 12:08:23
Needed?
Henrik Grunell
2014/05/27 15:33:54
Nope. Removed.
| |
13 #include "content/renderer/media/media_stream.h" | 15 #include "content/renderer/media/media_stream.h" |
14 #include "content/renderer/media/media_stream_audio_renderer.h" | 16 #include "content/renderer/media/media_stream_audio_renderer.h" |
15 #include "content/renderer/media/media_stream_audio_source.h" | 17 #include "content/renderer/media/media_stream_audio_source.h" |
16 #include "content/renderer/media/media_stream_dispatcher.h" | 18 #include "content/renderer/media/media_stream_dispatcher.h" |
17 #include "content/renderer/media/media_stream_video_capturer_source.h" | 19 #include "content/renderer/media/media_stream_video_capturer_source.h" |
18 #include "content/renderer/media/media_stream_video_track.h" | 20 #include "content/renderer/media/media_stream_video_track.h" |
19 #include "content/renderer/media/peer_connection_tracker.h" | 21 #include "content/renderer/media/peer_connection_tracker.h" |
20 #include "content/renderer/media/rtc_video_renderer.h" | 22 #include "content/renderer/media/rtc_video_renderer.h" |
21 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" | 23 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" |
22 #include "content/renderer/media/webrtc_audio_capturer.h" | 24 #include "content/renderer/media/webrtc_audio_capturer.h" |
23 #include "content/renderer/media/webrtc_audio_renderer.h" | 25 #include "content/renderer/media/webrtc_audio_renderer.h" |
24 #include "content/renderer/media/webrtc_local_audio_renderer.h" | 26 #include "content/renderer/media/webrtc_local_audio_renderer.h" |
25 #include "content/renderer/media/webrtc_logging.h" | 27 #include "content/renderer/media/webrtc_logging.h" |
26 #include "content/renderer/media/webrtc_uma_histograms.h" | 28 #include "content/renderer/media/webrtc_uma_histograms.h" |
27 #include "content/renderer/render_thread_impl.h" | 29 #include "content/renderer/render_thread_impl.h" |
28 #include "media/base/audio_hardware_config.h" | 30 #include "media/base/audio_hardware_config.h" |
29 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 31 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
32 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" | |
30 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 33 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
31 #include "third_party/WebKit/public/web/WebDocument.h" | 34 #include "third_party/WebKit/public/web/WebDocument.h" |
32 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 35 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
33 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" | 36 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" |
34 | 37 |
35 namespace content { | 38 namespace content { |
36 namespace { | 39 namespace { |
37 | 40 |
38 void CopyStreamConstraints(const blink::WebMediaConstraints& constraints, | 41 void CopyStreamConstraints(const blink::WebMediaConstraints& constraints, |
39 StreamOptions::Constraints* mandatory, | 42 StreamOptions::Constraints* mandatory, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 MediaStreamDispatcher* media_stream_dispatcher, | 76 MediaStreamDispatcher* media_stream_dispatcher, |
74 PeerConnectionDependencyFactory* dependency_factory) | 77 PeerConnectionDependencyFactory* dependency_factory) |
75 : RenderViewObserver(render_view), | 78 : RenderViewObserver(render_view), |
76 dependency_factory_(dependency_factory), | 79 dependency_factory_(dependency_factory), |
77 media_stream_dispatcher_(media_stream_dispatcher) { | 80 media_stream_dispatcher_(media_stream_dispatcher) { |
78 } | 81 } |
79 | 82 |
80 MediaStreamImpl::~MediaStreamImpl() { | 83 MediaStreamImpl::~MediaStreamImpl() { |
81 } | 84 } |
82 | 85 |
86 // TODO(grunell): Device enumeration should probably be moved to its own class | |
87 // here or at other places in the code. | |
88 struct MediaStreamImpl::MediaDevicesRequestInfo { | |
89 MediaDevicesRequestInfo(blink::WebMediaDevicesRequest request, | |
90 int audio_input_request_id, | |
91 int video_input_request_id) | |
92 : request(request), | |
93 audio_input_request_id(audio_input_request_id), | |
94 video_input_request_id(video_input_request_id), | |
95 has_audio_input_returned(false), | |
96 has_video_input_returned(false) {} | |
97 | |
98 blink::WebMediaDevicesRequest request; | |
99 int audio_input_request_id; | |
100 int video_input_request_id; | |
101 bool has_audio_input_returned; | |
102 bool has_video_input_returned; | |
103 StreamDeviceInfoArray audio_input_devices; | |
mcasas
2014/05/27 12:08:23
I think this struct should be made a class
since i
Henrik Grunell
2014/05/27 15:33:54
What do you motivate that with, it's not clear to
| |
104 StreamDeviceInfoArray video_input_devices; | |
105 }; | |
106 | |
83 void MediaStreamImpl::requestUserMedia( | 107 void MediaStreamImpl::requestUserMedia( |
84 const blink::WebUserMediaRequest& user_media_request) { | 108 const blink::WebUserMediaRequest& user_media_request) { |
85 // Save histogram data so we can see how much GetUserMedia is used. | 109 // Save histogram data so we can see how much GetUserMedia is used. |
86 // The histogram counts the number of calls to the JS API | 110 // The histogram counts the number of calls to the JS API |
87 // webGetUserMedia. | 111 // webGetUserMedia. |
88 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); | 112 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); |
89 DCHECK(CalledOnValidThread()); | 113 DCHECK(CalledOnValidThread()); |
90 | 114 |
91 if (RenderThreadImpl::current()) { | 115 if (RenderThreadImpl::current()) { |
92 RenderThreadImpl::current()->peer_connection_tracker()->TrackGetUserMedia( | 116 RenderThreadImpl::current()->peer_connection_tracker()->TrackGetUserMedia( |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 DCHECK(CalledOnValidThread()); | 202 DCHECK(CalledOnValidThread()); |
179 UserMediaRequestInfo* request = FindUserMediaRequestInfo(user_media_request); | 203 UserMediaRequestInfo* request = FindUserMediaRequestInfo(user_media_request); |
180 if (request) { | 204 if (request) { |
181 // We can't abort the stream generation process. | 205 // We can't abort the stream generation process. |
182 // Instead, erase the request. Once the stream is generated we will stop the | 206 // Instead, erase the request. Once the stream is generated we will stop the |
183 // stream if the request does not exist. | 207 // stream if the request does not exist. |
184 DeleteUserMediaRequestInfo(request); | 208 DeleteUserMediaRequestInfo(request); |
185 } | 209 } |
186 } | 210 } |
187 | 211 |
212 void MediaStreamImpl::requestMediaDevices( | |
213 const blink::WebMediaDevicesRequest& media_devices_request) { | |
214 // TODO(grunell): UMA stats? | |
215 DCHECK(CalledOnValidThread()); | |
216 | |
217 int audio_input_request_id = g_next_request_id++; | |
218 int video_input_request_id = g_next_request_id++; | |
219 GURL security_origin = | |
220 GURL(media_devices_request.securityOrigin().toString()); | |
221 | |
222 media_devices_requests_.push_back(new MediaDevicesRequestInfo( | |
223 media_devices_request, audio_input_request_id, video_input_request_id)); | |
224 | |
225 media_stream_dispatcher_->EnumerateDevices( | |
226 audio_input_request_id, | |
227 AsWeakPtr(), | |
228 MEDIA_DEVICE_AUDIO_CAPTURE, | |
229 security_origin); | |
230 | |
231 media_stream_dispatcher_->EnumerateDevices( | |
232 video_input_request_id, | |
233 AsWeakPtr(), | |
234 MEDIA_DEVICE_VIDEO_CAPTURE, | |
235 security_origin); | |
236 } | |
237 | |
238 void MediaStreamImpl::cancelMediaDevicesRequest( | |
239 const blink::WebMediaDevicesRequest& media_devices_request) { | |
240 DCHECK(CalledOnValidThread()); | |
241 MediaDevicesRequestInfo* request = | |
242 FindMediaDevicesRequestInfo(media_devices_request); | |
243 if (request) { | |
mcasas
2014/05/27 12:08:23
if (!request)
return;
Henrik Grunell
2014/05/27 15:33:54
Done.
| |
244 // Cancel device enumeration. | |
245 media_stream_dispatcher_->StopEnumerateDevices( | |
246 request->audio_input_request_id, | |
247 AsWeakPtr()); | |
248 media_stream_dispatcher_->StopEnumerateDevices( | |
249 request->video_input_request_id, | |
250 AsWeakPtr()); | |
251 DeleteMediaDevicesRequestInfo(request); | |
252 } | |
253 } | |
254 | |
188 blink::WebMediaStream MediaStreamImpl::GetMediaStream( | 255 blink::WebMediaStream MediaStreamImpl::GetMediaStream( |
189 const GURL& url) { | 256 const GURL& url) { |
190 return blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url); | 257 return blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url); |
191 } | 258 } |
192 | 259 |
193 bool MediaStreamImpl::IsMediaStream(const GURL& url) { | 260 bool MediaStreamImpl::IsMediaStream(const GURL& url) { |
194 blink::WebMediaStream web_stream( | 261 blink::WebMediaStream web_stream( |
195 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url)); | 262 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url)); |
196 | 263 |
197 return (!web_stream.isNull() && | 264 return (!web_stream.isNull() && |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 GetUserMediaRequestSucceeded(request->web_stream, &request->request); | 586 GetUserMediaRequestSucceeded(request->web_stream, &request->request); |
520 else | 587 else |
521 GetUserMediaRequestFailed(&request->request, result); | 588 GetUserMediaRequestFailed(&request->request, result); |
522 | 589 |
523 DeleteUserMediaRequestInfo(request); | 590 DeleteUserMediaRequestInfo(request); |
524 } | 591 } |
525 | 592 |
526 void MediaStreamImpl::OnDevicesEnumerated( | 593 void MediaStreamImpl::OnDevicesEnumerated( |
527 int request_id, | 594 int request_id, |
528 const StreamDeviceInfoArray& device_array) { | 595 const StreamDeviceInfoArray& device_array) { |
529 DVLOG(1) << "MediaStreamImpl::OnDevicesEnumerated(" | 596 DVLOG(1) << "MediaStreamImpl::OnDevicesEnumerated(" |
mcasas
2014/05/27 12:08:23
Nit: fits in one line.
Henrik Grunell
2014/05/27 15:33:54
Done.
| |
530 << request_id << ")"; | 597 << request_id << ")"; |
531 NOTIMPLEMENTED(); | 598 |
599 MediaDevicesRequestInfo* request = FindMediaDevicesRequestInfo(request_id); | |
600 DCHECK(request); | |
601 | |
602 if (request_id == request->audio_input_request_id) { | |
603 request->has_audio_input_returned = true; | |
604 DCHECK(request->audio_input_devices.empty()); | |
605 request->audio_input_devices = device_array; | |
606 } else { | |
607 DCHECK(request_id == request->video_input_request_id); | |
608 request->has_video_input_returned = true; | |
609 DCHECK(request->video_input_devices.empty()); | |
610 request->video_input_devices = device_array; | |
611 } | |
612 | |
613 if (!request->has_audio_input_returned || | |
614 !request->has_video_input_returned) { | |
615 // Wait for the rest of the devices to complete. | |
616 return; | |
617 } | |
618 | |
619 // Both audio and video devices are ready for copying. | |
620 // TODO(grunell): Add support for output devices and group id. | |
621 blink::WebVector<blink::WebMediaDeviceInfo> | |
622 devices(request->audio_input_devices.size() + | |
623 request->video_input_devices.size()); | |
624 for (size_t i = 0; i < request->audio_input_devices.size(); ++i) { | |
625 const MediaStreamDevice& device = request->audio_input_devices[i].device; | |
626 DCHECK_EQ(device.type, MEDIA_DEVICE_AUDIO_CAPTURE); | |
627 devices[i].initialize(blink::WebString::fromUTF8(device.id), | |
628 blink::WebMediaDeviceInfo::MediaDeviceKindAudioInput, | |
629 blink::WebString::fromUTF8(device.name), | |
630 blink::WebString()); | |
631 } | |
632 size_t audio_size = request->audio_input_devices.size(); | |
633 for (size_t i = 0; i < request->video_input_devices.size(); ++i) { | |
634 const MediaStreamDevice& device = request->video_input_devices[i].device; | |
635 DCHECK_EQ(device.type, MEDIA_DEVICE_VIDEO_CAPTURE); | |
636 devices[audio_size + i].initialize( | |
637 blink::WebString::fromUTF8(device.id), | |
638 blink::WebMediaDeviceInfo::MediaDeviceKindVideoInput, | |
639 blink::WebString::fromUTF8(device.name), | |
640 blink::WebString()); | |
641 } | |
642 request->request.requestSucceeded(devices); | |
643 | |
644 // Cancel device enumeration. | |
645 media_stream_dispatcher_->StopEnumerateDevices( | |
perkj_chrome
2014/05/27 11:57:23
This is so silly. Can't we just change this now?
Henrik Grunell
2014/05/27 15:33:54
Seems pepper doesn't use the request as notificati
| |
646 request->audio_input_request_id, | |
647 AsWeakPtr()); | |
648 media_stream_dispatcher_->StopEnumerateDevices( | |
649 request->video_input_request_id, | |
650 AsWeakPtr()); | |
651 | |
652 DeleteMediaDevicesRequestInfo(request); | |
532 } | 653 } |
533 | 654 |
534 void MediaStreamImpl::OnDeviceOpened( | 655 void MediaStreamImpl::OnDeviceOpened( |
535 int request_id, | 656 int request_id, |
536 const std::string& label, | 657 const std::string& label, |
537 const StreamDeviceInfo& video_device) { | 658 const StreamDeviceInfo& video_device) { |
538 DVLOG(1) << "MediaStreamImpl::OnDeviceOpened(" | 659 DVLOG(1) << "MediaStreamImpl::OnDeviceOpened(" |
539 << request_id << ", " << label << ")"; | 660 << request_id << ", " << label << ")"; |
540 NOTIMPLEMENTED(); | 661 NOTIMPLEMENTED(); |
541 } | 662 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 UserMediaRequests::iterator it = user_media_requests_.begin(); | 756 UserMediaRequests::iterator it = user_media_requests_.begin(); |
636 for (; it != user_media_requests_.end(); ++it) { | 757 for (; it != user_media_requests_.end(); ++it) { |
637 if ((*it) == request) { | 758 if ((*it) == request) { |
638 user_media_requests_.erase(it); | 759 user_media_requests_.erase(it); |
639 return; | 760 return; |
640 } | 761 } |
641 } | 762 } |
642 NOTREACHED(); | 763 NOTREACHED(); |
643 } | 764 } |
644 | 765 |
766 MediaStreamImpl::MediaDevicesRequestInfo* | |
767 MediaStreamImpl::FindMediaDevicesRequestInfo( | |
768 int request_id) { | |
769 MediaDevicesRequests::iterator it = media_devices_requests_.begin(); | |
770 for (; it != media_devices_requests_.end(); ++it) { | |
771 if ((*it)->audio_input_request_id == request_id || | |
772 (*it)->video_input_request_id == request_id) { | |
773 return (*it); | |
774 } | |
775 } | |
776 return NULL; | |
777 } | |
778 | |
779 MediaStreamImpl::MediaDevicesRequestInfo* | |
780 MediaStreamImpl::FindMediaDevicesRequestInfo( | |
781 const blink::WebMediaDevicesRequest& request) { | |
782 MediaDevicesRequests::iterator it = media_devices_requests_.begin(); | |
mcasas
2014/05/27 12:08:23
I know this is copy-modified from previous code bu
Henrik Grunell
2014/05/27 15:33:54
It's a ScopedVector, can't use std::find.
| |
783 for (; it != media_devices_requests_.end(); ++it) { | |
784 if ((*it)->request == request) | |
785 return (*it); | |
786 } | |
787 return NULL; | |
788 } | |
789 | |
790 void MediaStreamImpl::DeleteMediaDevicesRequestInfo( | |
791 MediaDevicesRequestInfo* request) { | |
792 MediaDevicesRequests::iterator it = media_devices_requests_.begin(); | |
793 for (; it != media_devices_requests_.end(); ++it) { | |
794 if ((*it) == request) { | |
795 media_devices_requests_.erase(it); | |
796 return; | |
797 } | |
798 } | |
799 NOTREACHED(); | |
800 } | |
801 | |
645 void MediaStreamImpl::FrameDetached(blink::WebFrame* frame) { | 802 void MediaStreamImpl::FrameDetached(blink::WebFrame* frame) { |
646 // Do same thing as FrameWillClose. | 803 // Do same thing as FrameWillClose. |
647 FrameWillClose(frame); | 804 FrameWillClose(frame); |
648 } | 805 } |
649 | 806 |
650 void MediaStreamImpl::FrameWillClose(blink::WebFrame* frame) { | 807 void MediaStreamImpl::FrameWillClose(blink::WebFrame* frame) { |
651 // Loop through all UserMediaRequests and find the requests that belong to the | 808 // Loop through all UserMediaRequests and find the requests that belong to the |
652 // frame that is being closed. | 809 // frame that is being closed. |
653 UserMediaRequests::iterator request_it = user_media_requests_.begin(); | 810 UserMediaRequests::iterator request_it = user_media_requests_.begin(); |
654 while (request_it != user_media_requests_.end()) { | 811 while (request_it != user_media_requests_.end()) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
877 sources_.begin(); | 1034 sources_.begin(); |
878 it != sources_.end(); ++it) { | 1035 it != sources_.end(); ++it) { |
879 if (source.id() == it->id()) { | 1036 if (source.id() == it->id()) { |
880 sources_.erase(it); | 1037 sources_.erase(it); |
881 return; | 1038 return; |
882 } | 1039 } |
883 } | 1040 } |
884 } | 1041 } |
885 | 1042 |
886 } // namespace content | 1043 } // namespace content |
OLD | NEW |