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

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

Issue 391703002: Implement ConstraintNotSatisfiedError for getusermedia (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_video_source.h" 5 #include "content/renderer/media/media_stream_video_source.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 format_it = formats->erase(format_it); 213 format_it = formats->erase(format_it);
214 } else { 214 } else {
215 ++format_it; 215 ++format_it;
216 } 216 }
217 } 217 }
218 } 218 }
219 219
220 // Returns the media::VideoCaptureFormats that matches |constraints|. 220 // Returns the media::VideoCaptureFormats that matches |constraints|.
221 media::VideoCaptureFormats FilterFormats( 221 media::VideoCaptureFormats FilterFormats(
222 const blink::WebMediaConstraints& constraints, 222 const blink::WebMediaConstraints& constraints,
223 const media::VideoCaptureFormats& supported_formats) { 223 const media::VideoCaptureFormats& supported_formats,
224 blink::WebString* unsatisfied_constraint) {
224 if (constraints.isNull()) { 225 if (constraints.isNull()) {
225 return supported_formats; 226 return supported_formats;
226 } 227 }
227 228
228 double max_aspect_ratio; 229 double max_aspect_ratio;
229 double min_aspect_ratio; 230 double min_aspect_ratio;
230 GetDesiredMinAndMaxAspectRatio(constraints, 231 GetDesiredMinAndMaxAspectRatio(constraints,
231 &min_aspect_ratio, 232 &min_aspect_ratio,
232 &max_aspect_ratio); 233 &max_aspect_ratio);
233 234
(...skipping 29 matching lines...) Expand all
263 DLOG(WARNING) << "Wrong requested frame rate."; 264 DLOG(WARNING) << "Wrong requested frame rate.";
264 return media::VideoCaptureFormats(); 265 return media::VideoCaptureFormats();
265 } 266 }
266 } 267 }
267 268
268 blink::WebVector<blink::WebMediaConstraint> mandatory; 269 blink::WebVector<blink::WebMediaConstraint> mandatory;
269 blink::WebVector<blink::WebMediaConstraint> optional; 270 blink::WebVector<blink::WebMediaConstraint> optional;
270 constraints.getMandatoryConstraints(mandatory); 271 constraints.getMandatoryConstraints(mandatory);
271 constraints.getOptionalConstraints(optional); 272 constraints.getOptionalConstraints(optional);
272 media::VideoCaptureFormats candidates = supported_formats; 273 media::VideoCaptureFormats candidates = supported_formats;
273 for (size_t i = 0; i < mandatory.size(); ++i) 274 for (size_t i = 0; i < mandatory.size(); ++i) {
274 FilterFormatsByConstraint(mandatory[i], true, &candidates); 275 FilterFormatsByConstraint(mandatory[i], true, &candidates);
276 if (candidates.empty()) {
277 *unsatisfied_constraint = mandatory[i].m_name;
278 return candidates;
279 }
280 }
275 281
276 if (candidates.empty()) 282 if (candidates.empty())
277 return candidates; 283 return candidates;
278 284
279 // Ok - all mandatory checked and we still have candidates. 285 // Ok - all mandatory checked and we still have candidates.
280 // Let's try filtering using the optional constraints. The optional 286 // Let's try filtering using the optional constraints. The optional
281 // constraints must be filtered in the order they occur in |optional|. 287 // constraints must be filtered in the order they occur in |optional|.
282 // But if a constraint produce zero candidates, the constraint is ignored and 288 // But if a constraint produce zero candidates, the constraint is ignored and
283 // the next constraint is tested. 289 // the next constraint is tested.
284 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html#idl-def-Constraints 290 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html#idl-def-Constraints
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 const blink::WebMediaConstraints& requested_constraints = 499 const blink::WebMediaConstraints& requested_constraints =
494 request_it->constraints; 500 request_it->constraints;
495 501
496 // If the source doesn't support capability enumeration it is still ok if 502 // If the source doesn't support capability enumeration it is still ok if
497 // no mandatory constraints have been specified. That just means that 503 // no mandatory constraints have been specified. That just means that
498 // we will start with whatever format is native to the source. 504 // we will start with whatever format is native to the source.
499 if (formats.empty() && !HasMandatoryConstraints(requested_constraints)) { 505 if (formats.empty() && !HasMandatoryConstraints(requested_constraints)) {
500 *best_format = media::VideoCaptureFormat(); 506 *best_format = media::VideoCaptureFormat();
501 return true; 507 return true;
502 } 508 }
509 blink::WebString unsatisfied_constraint;
503 media::VideoCaptureFormats filtered_formats = 510 media::VideoCaptureFormats filtered_formats =
504 FilterFormats(requested_constraints, formats); 511 FilterFormats(requested_constraints, formats, &unsatisfied_constraint);
505 if (filtered_formats.size() > 0) { 512 if (filtered_formats.size() > 0) {
506 // A request with constraints that can be fulfilled. 513 // A request with constraints that can be fulfilled.
507 GetBestCaptureFormat(filtered_formats, 514 GetBestCaptureFormat(filtered_formats,
508 requested_constraints, 515 requested_constraints,
509 best_format); 516 best_format);
510 return true; 517 return true;
511 } 518 }
512 } 519 }
513 return false; 520 return false;
514 } 521 }
515 522
516 void MediaStreamVideoSource::OnStartDone(bool success) { 523 void MediaStreamVideoSource::OnStartDone(MediaStreamRequestResult result) {
517 DCHECK(CalledOnValidThread()); 524 DCHECK(CalledOnValidThread());
518 DVLOG(3) << "OnStartDone({success =" << success << "})"; 525 DVLOG(3) << "OnStartDone({result =" << result << "})";
519 if (success) { 526 if (result == MEDIA_DEVICE_OK) {
520 DCHECK_EQ(STARTING, state_); 527 DCHECK_EQ(STARTING, state_);
521 state_ = STARTED; 528 state_ = STARTED;
522 SetReadyState(blink::WebMediaStreamSource::ReadyStateLive); 529 SetReadyState(blink::WebMediaStreamSource::ReadyStateLive);
523 } else { 530 } else {
524 StopSource(); 531 StopSource();
525 } 532 }
526 533
527 // This object can be deleted after calling FinalizeAddTrack. See comment in 534 // This object can be deleted after calling FinalizeAddTrack. See comment in
528 // the header file. 535 // the header file.
529 FinalizeAddTrack(); 536 FinalizeAddTrack();
530 } 537 }
531 538
532 void MediaStreamVideoSource::FinalizeAddTrack() { 539 void MediaStreamVideoSource::FinalizeAddTrack() {
533 DCHECK(CalledOnValidThread()); 540 DCHECK(CalledOnValidThread());
534 media::VideoCaptureFormats formats; 541 media::VideoCaptureFormats formats;
535 formats.push_back(current_format_); 542 formats.push_back(current_format_);
536 543
537 std::vector<RequestedConstraints> callbacks; 544 std::vector<RequestedConstraints> callbacks;
538 callbacks.swap(requested_constraints_); 545 callbacks.swap(requested_constraints_);
539 for (std::vector<RequestedConstraints>::iterator it = callbacks.begin(); 546 for (std::vector<RequestedConstraints>::iterator it = callbacks.begin();
540 it != callbacks.end(); ++it) { 547 it != callbacks.end(); ++it) {
541 // The track has been added successfully if the source has started and 548 blink::WebString unsatisfied_constraint;
miu 2014/08/05 03:35:53 nit: Please swap this line and the next line, for
jiajia.qin 2014/08/05 05:39:25 Done.
542 // there are either no mandatory constraints and the source doesn't expose 549 MediaStreamRequestResult result = MEDIA_DEVICE_OK;
543 // its format capabilities, or the constraints and the format match.
544 // For example, a remote source doesn't expose its format capabilities.
545 bool success =
546 state_ == STARTED &&
547 ((!current_format_.IsValid() && !HasMandatoryConstraints(
548 it->constraints)) ||
549 !FilterFormats(it->constraints, formats).empty());
550 550
551 if (success) { 551 if (HasMandatoryConstraints(it->constraints) &&
552 FilterFormats(it->constraints, formats,
553 &unsatisfied_constraint).empty())
miu 2014/08/05 03:35:53 nit: indentation: Align this to the right of the o
jiajia.qin 2014/08/05 05:39:25 Done.
554 result = MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED;
555
556 if (state_ != STARTED && result == MEDIA_DEVICE_OK)
557 result = MEDIA_DEVICE_TRACK_START_FAILURE;
558
559 if (result == MEDIA_DEVICE_OK) {
552 int max_width; 560 int max_width;
553 int max_height; 561 int max_height;
554 GetDesiredMaxWidthAndHeight(it->constraints, &max_width, &max_height); 562 GetDesiredMaxWidthAndHeight(it->constraints, &max_width, &max_height);
555 double max_aspect_ratio; 563 double max_aspect_ratio;
556 double min_aspect_ratio; 564 double min_aspect_ratio;
557 GetDesiredMinAndMaxAspectRatio(it->constraints, 565 GetDesiredMinAndMaxAspectRatio(it->constraints,
558 &min_aspect_ratio, 566 &min_aspect_ratio,
559 &max_aspect_ratio); 567 &max_aspect_ratio);
560 double max_frame_rate = 0.0f; 568 double max_frame_rate = 0.0f;
561 GetConstraintValueAsDouble(it->constraints, 569 GetConstraintValueAsDouble(it->constraints,
562 kMaxFrameRate, &max_frame_rate); 570 kMaxFrameRate, &max_frame_rate);
563 571
564 VideoTrackAdapter::OnMutedCallback on_mute_callback = 572 VideoTrackAdapter::OnMutedCallback on_mute_callback =
565 media::BindToCurrentLoop(base::Bind( 573 media::BindToCurrentLoop(base::Bind(
566 &MediaStreamVideoSource::SetMutedState, 574 &MediaStreamVideoSource::SetMutedState,
567 weak_factory_.GetWeakPtr())); 575 weak_factory_.GetWeakPtr()));
568 track_adapter_->AddTrack(it->track, it->frame_callback, 576 track_adapter_->AddTrack(it->track, it->frame_callback,
569 max_width, max_height, 577 max_width, max_height,
570 min_aspect_ratio, max_aspect_ratio, 578 min_aspect_ratio, max_aspect_ratio,
571 max_frame_rate, current_format_.frame_rate, 579 max_frame_rate, current_format_.frame_rate,
572 on_mute_callback); 580 on_mute_callback);
573 } 581 }
574 582
575 DVLOG(3) << "FinalizeAddTrack() success " << success; 583 DVLOG(3) << "FinalizeAddTrack() result " << result;
576 584
577 if (!it->callback.is_null()) 585 if (!it->callback.is_null()) {
578 it->callback.Run(this, success); 586 it->callback.Run(this, result, unsatisfied_constraint);
587 }
579 } 588 }
580 } 589 }
581 590
582 void MediaStreamVideoSource::SetReadyState( 591 void MediaStreamVideoSource::SetReadyState(
583 blink::WebMediaStreamSource::ReadyState state) { 592 blink::WebMediaStreamSource::ReadyState state) {
584 DVLOG(3) << "MediaStreamVideoSource::SetReadyState state " << state; 593 DVLOG(3) << "MediaStreamVideoSource::SetReadyState state " << state;
585 DCHECK(CalledOnValidThread()); 594 DCHECK(CalledOnValidThread());
586 if (!owner().isNull()) { 595 if (!owner().isNull()) {
587 owner().setReadyState(state); 596 owner().setReadyState(state);
588 } 597 }
(...skipping 21 matching lines...) Expand all
610 : track(track), 619 : track(track),
611 frame_callback(frame_callback), 620 frame_callback(frame_callback),
612 constraints(constraints), 621 constraints(constraints),
613 callback(callback) { 622 callback(callback) {
614 } 623 }
615 624
616 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { 625 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() {
617 } 626 }
618 627
619 } // namespace content 628 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_video_source.h ('k') | content/renderer/media/media_stream_video_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698