Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(679)

Side by Side Diff: content/renderer/media/media_stream_impl.cc

Issue 446553002: Add histogram WebRTC.UserMediaRequest.NoResultState to track user media requests with no result. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b399835
Patch Set: Comments addressed (and diffbase is now submitted, so diffing to master now) Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/hash.h" 9 #include "base/hash.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 192 }
193 193
194 void MediaStreamImpl::cancelUserMediaRequest( 194 void MediaStreamImpl::cancelUserMediaRequest(
195 const blink::WebUserMediaRequest& user_media_request) { 195 const blink::WebUserMediaRequest& user_media_request) {
196 DCHECK(CalledOnValidThread()); 196 DCHECK(CalledOnValidThread());
197 UserMediaRequestInfo* request = FindUserMediaRequestInfo(user_media_request); 197 UserMediaRequestInfo* request = FindUserMediaRequestInfo(user_media_request);
198 if (request) { 198 if (request) {
199 // We can't abort the stream generation process. 199 // We can't abort the stream generation process.
200 // Instead, erase the request. Once the stream is generated we will stop the 200 // Instead, erase the request. Once the stream is generated we will stop the
201 // stream if the request does not exist. 201 // stream if the request does not exist.
202 LogUserMediaRequestWithNoResult(MEDIA_STREAM_REQUEST_EXPLICITLY_CANCELLED);
202 DeleteUserMediaRequestInfo(request); 203 DeleteUserMediaRequestInfo(request);
203 } 204 }
204 } 205 }
205 206
206 void MediaStreamImpl::requestMediaDevices( 207 void MediaStreamImpl::requestMediaDevices(
207 const blink::WebMediaDevicesRequest& media_devices_request) { 208 const blink::WebMediaDevicesRequest& media_devices_request) {
208 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES); 209 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES);
209 DCHECK(CalledOnValidThread()); 210 DCHECK(CalledOnValidThread());
210 211
211 int audio_input_request_id = g_next_request_id++; 212 int audio_input_request_id = g_next_request_id++;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 void MediaStreamImpl::OnStreamGenerated( 267 void MediaStreamImpl::OnStreamGenerated(
267 int request_id, 268 int request_id,
268 const std::string& label, 269 const std::string& label,
269 const StreamDeviceInfoArray& audio_array, 270 const StreamDeviceInfoArray& audio_array,
270 const StreamDeviceInfoArray& video_array) { 271 const StreamDeviceInfoArray& video_array) {
271 DCHECK(CalledOnValidThread()); 272 DCHECK(CalledOnValidThread());
272 DVLOG(1) << "MediaStreamImpl::OnStreamGenerated stream:" << label; 273 DVLOG(1) << "MediaStreamImpl::OnStreamGenerated stream:" << label;
273 274
274 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id); 275 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id);
275 if (!request_info) { 276 if (!request_info) {
276 // This can happen if the request is canceled or the frame reloads while
277 // MediaStreamDispatcher is processing the request.
278 // Only stop the device if the device is not used in another MediaStream.
279 for (StreamDeviceInfoArray::const_iterator device_it = audio_array.begin();
280 device_it != audio_array.end(); ++device_it) {
281 if (!FindLocalSource(*device_it))
282 media_stream_dispatcher_->StopStreamDevice(*device_it);
283 }
284
285 for (StreamDeviceInfoArray::const_iterator device_it = video_array.begin();
286 device_it != video_array.end(); ++device_it) {
287 if (!FindLocalSource(*device_it))
288 media_stream_dispatcher_->StopStreamDevice(*device_it);
289 }
290
291 DVLOG(1) << "Request ID not found"; 277 DVLOG(1) << "Request ID not found";
278 OnStreamGeneratedForCancelledRequest(audio_array, video_array);
292 return; 279 return;
293 } 280 }
294 request_info->generated = true; 281 request_info->generated = true;
295 282
296 // WebUserMediaRequest don't have an implementation in unit tests. 283 // WebUserMediaRequest don't have an implementation in unit tests.
297 // Therefore we need to check for isNull here and initialize the 284 // Therefore we need to check for isNull here and initialize the
298 // constraints. 285 // constraints.
299 blink::WebUserMediaRequest* request = &(request_info->request); 286 blink::WebUserMediaRequest* request = &(request_info->request);
300 blink::WebMediaConstraints audio_constraints; 287 blink::WebMediaConstraints audio_constraints;
301 blink::WebMediaConstraints video_constraints; 288 blink::WebMediaConstraints video_constraints;
(...skipping 23 matching lines...) Expand all
325 web_stream->setExtraData( 312 web_stream->setExtraData(
326 new MediaStream( 313 new MediaStream(
327 *web_stream)); 314 *web_stream));
328 315
329 // Wait for the tracks to be started successfully or to fail. 316 // Wait for the tracks to be started successfully or to fail.
330 request_info->CallbackOnTracksStarted( 317 request_info->CallbackOnTracksStarted(
331 base::Bind(&MediaStreamImpl::OnCreateNativeTracksCompleted, 318 base::Bind(&MediaStreamImpl::OnCreateNativeTracksCompleted,
332 weak_factory_.GetWeakPtr())); 319 weak_factory_.GetWeakPtr()));
333 } 320 }
334 321
322 // This can happen if the request is canceled or the frame reloads while
323 // MediaStreamDispatcher is processing the request.
324 // Only stop the device if the device is not used in another MediaStream.
tommi (sloooow) - chröme 2014/08/06 11:42:21 nit: documentation for methods tends to stay in th
andresp-chromium 2014/08/06 11:59:14 Split documentation to the relevant places.
325 void MediaStreamImpl::OnStreamGeneratedForCancelledRequest(
326 const StreamDeviceInfoArray& audio_array,
327 const StreamDeviceInfoArray& video_array) {
328 for (StreamDeviceInfoArray::const_iterator device_it = audio_array.begin();
329 device_it != audio_array.end(); ++device_it) {
330 if (!FindLocalSource(*device_it))
331 media_stream_dispatcher_->StopStreamDevice(*device_it);
332 }
333
334 for (StreamDeviceInfoArray::const_iterator device_it = video_array.begin();
335 device_it != video_array.end(); ++device_it) {
336 if (!FindLocalSource(*device_it))
337 media_stream_dispatcher_->StopStreamDevice(*device_it);
338 }
339 }
340
335 // Callback from MediaStreamDispatcher. 341 // Callback from MediaStreamDispatcher.
336 // The requested stream failed to be generated. 342 // The requested stream failed to be generated.
337 void MediaStreamImpl::OnStreamGenerationFailed( 343 void MediaStreamImpl::OnStreamGenerationFailed(
338 int request_id, 344 int request_id,
339 content::MediaStreamRequestResult result) { 345 content::MediaStreamRequestResult result) {
340 DCHECK(CalledOnValidThread()); 346 DCHECK(CalledOnValidThread());
341 DVLOG(1) << "MediaStreamImpl::OnStreamGenerationFailed(" 347 DVLOG(1) << "MediaStreamImpl::OnStreamGenerationFailed("
342 << request_id << ")"; 348 << request_id << ")";
343 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id); 349 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id);
344 if (!request_info) { 350 if (!request_info) {
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 UserMediaRequests::iterator it = user_media_requests_.begin(); 700 UserMediaRequests::iterator it = user_media_requests_.begin();
695 for (; it != user_media_requests_.end(); ++it) { 701 for (; it != user_media_requests_.end(); ++it) {
696 if ((*it) == request) { 702 if ((*it) == request) {
697 user_media_requests_.erase(it); 703 user_media_requests_.erase(it);
698 return; 704 return;
699 } 705 }
700 } 706 }
701 NOTREACHED(); 707 NOTREACHED();
702 } 708 }
703 709
710 void MediaStreamImpl::DeleteAllUserMediaRequests() {
711 UserMediaRequests::iterator request_it = user_media_requests_.begin();
712 while (request_it != user_media_requests_.end()) {
713 DVLOG(1) << "MediaStreamImpl@" << this << "::DeleteAllUserMediaRequests: "
714 << "Cancel user media request " << (*request_it)->request_id;
715 // If the request is not generated, it means that a request
716 // has been sent to the MediaStreamDispatcher to generate a stream
717 // but MediaStreamDispatcher has not yet responded and we need to cancel
718 // the request.
719 if (!(*request_it)->generated) {
720 media_stream_dispatcher_->CancelGenerateStream(
721 (*request_it)->request_id, weak_factory_.GetWeakPtr());
722 }
723 if ((*request_it)->generated) {
tommi (sloooow) - chröme 2014/08/06 11:42:21 should this be an else?
andresp-chromium 2014/08/06 11:59:14 Done.
724 DCHECK((*request_it)->HasPendingSources());
725 LogUserMediaRequestWithNoResult(
726 MEDIA_STREAM_REQUEST_PENDING_MEDIA_TRACKS);
727 } else {
728 DCHECK(!(*request_it)->HasPendingSources());
tommi (sloooow) - chröme 2014/08/06 11:42:21 ...and this looks like it should be in the scope w
andresp-chromium 2014/08/06 11:59:14 Done. Yeah you are right! Since I was looking as t
729 LogUserMediaRequestWithNoResult(MEDIA_STREAM_REQUEST_NOT_GENERATED);
730 }
731 request_it = user_media_requests_.erase(request_it);
732 }
733 }
734
704 MediaStreamImpl::MediaDevicesRequestInfo* 735 MediaStreamImpl::MediaDevicesRequestInfo*
705 MediaStreamImpl::FindMediaDevicesRequestInfo( 736 MediaStreamImpl::FindMediaDevicesRequestInfo(
706 int request_id) { 737 int request_id) {
707 MediaDevicesRequests::iterator it = media_devices_requests_.begin(); 738 MediaDevicesRequests::iterator it = media_devices_requests_.begin();
708 for (; it != media_devices_requests_.end(); ++it) { 739 for (; it != media_devices_requests_.end(); ++it) {
709 if ((*it)->audio_input_request_id == request_id || 740 if ((*it)->audio_input_request_id == request_id ||
710 (*it)->video_input_request_id == request_id || 741 (*it)->video_input_request_id == request_id ||
711 (*it)->audio_output_request_id == request_id) { 742 (*it)->audio_output_request_id == request_id) {
712 return (*it); 743 return (*it);
713 } 744 }
(...skipping 27 matching lines...) Expand all
741 772
742 media_devices_requests_.erase(it); 773 media_devices_requests_.erase(it);
743 return; 774 return;
744 } 775 }
745 } 776 }
746 NOTREACHED(); 777 NOTREACHED();
747 } 778 }
748 779
749 void MediaStreamImpl::FrameWillClose() { 780 void MediaStreamImpl::FrameWillClose() {
750 // Cancel all outstanding UserMediaRequests. 781 // Cancel all outstanding UserMediaRequests.
751 UserMediaRequests::iterator request_it = user_media_requests_.begin(); 782 DeleteAllUserMediaRequests();
752 while (request_it != user_media_requests_.end()) {
753 DVLOG(1) << "MediaStreamImpl@" << this << "::FrameWillClose: "
754 << "Cancel user media request " << (*request_it)->request_id;
755 // If the request is not generated, it means that a request
756 // has been sent to the MediaStreamDispatcher to generate a stream
757 // but MediaStreamDispatcher has not yet responded and we need to cancel
758 // the request.
759 if (!(*request_it)->generated) {
760 media_stream_dispatcher_->CancelGenerateStream(
761 (*request_it)->request_id, weak_factory_.GetWeakPtr());
762 }
763 request_it = user_media_requests_.erase(request_it);
764 }
765 783
766 // Loop through all current local sources and stop the sources. 784 // Loop through all current local sources and stop the sources.
767 LocalStreamSources::iterator sources_it = local_sources_.begin(); 785 LocalStreamSources::iterator sources_it = local_sources_.begin();
768 while (sources_it != local_sources_.end()) { 786 while (sources_it != local_sources_.end()) {
769 StopLocalSource(*sources_it, true); 787 StopLocalSource(*sources_it, true);
770 sources_it = local_sources_.erase(sources_it); 788 sources_it = local_sources_.erase(sources_it);
771 } 789 }
772 } 790 }
773 791
774 void MediaStreamImpl::OnLocalSourceStopped( 792 void MediaStreamImpl::OnLocalSourceStopped(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 for (std::vector<blink::WebMediaStreamSource>::iterator it = 921 for (std::vector<blink::WebMediaStreamSource>::iterator it =
904 sources_.begin(); 922 sources_.begin();
905 it != sources_.end(); ++it) { 923 it != sources_.end(); ++it) {
906 if (source.id() == it->id()) { 924 if (source.id() == it->id()) {
907 sources_.erase(it); 925 sources_.erase(it);
908 return; 926 return;
909 } 927 }
910 } 928 }
911 } 929 }
912 930
931 bool MediaStreamImpl::UserMediaRequestInfo::AreAllSourcesRemoved() const {
tommi (sloooow) - chröme 2014/08/06 11:42:21 ugh, grammar :-/ not sure we should fix that now
andresp-chromium 2014/08/06 11:59:14 This method is never called. Removing.
932 return sources_.empty();
933 }
934
935 bool MediaStreamImpl::UserMediaRequestInfo::HasPendingSources() const {
936 return !sources_waiting_for_callback_.empty();
937 }
913 } // namespace content 938 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698