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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/media_stream_video_source.cc
diff --git a/content/renderer/media/media_stream_video_source.cc b/content/renderer/media/media_stream_video_source.cc
index 42c5b1b4c558aeb7bfcd849c274e95f79d7960a5..2b19bcba15c56ecbdba7d8f96c19c7e7e3d0203a 100644
--- a/content/renderer/media/media_stream_video_source.cc
+++ b/content/renderer/media/media_stream_video_source.cc
@@ -220,7 +220,8 @@ void FilterFormatsByConstraint(
// Returns the media::VideoCaptureFormats that matches |constraints|.
media::VideoCaptureFormats FilterFormats(
const blink::WebMediaConstraints& constraints,
- const media::VideoCaptureFormats& supported_formats) {
+ const media::VideoCaptureFormats& supported_formats,
+ blink::WebString* unsatisfied_constraint) {
if (constraints.isNull()) {
return supported_formats;
}
@@ -270,11 +271,15 @@ media::VideoCaptureFormats FilterFormats(
constraints.getMandatoryConstraints(mandatory);
constraints.getOptionalConstraints(optional);
media::VideoCaptureFormats candidates = supported_formats;
- for (size_t i = 0; i < mandatory.size(); ++i)
+ for (size_t i = 0; i < mandatory.size(); ++i) {
FilterFormatsByConstraint(mandatory[i], true, &candidates);
-
- if (candidates.empty())
- return candidates;
+ // Here we record the name of constraint that causes
miu 2014/07/30 19:37:23 This comment is stating the obvious, so you should
jiajia.qin 2014/07/31 13:43:01 Done.
+ // the ConstraintNotSatisfiedError
+ if (candidates.empty()) {
+ *unsatisfied_constraint = mandatory[i].m_name;
+ return candidates;
miu 2014/07/30 19:37:23 Sanity-check: With this change, you're now abortin
jiajia.qin 2014/07/31 13:43:01 Yes, I am sure. According to the spec, 'Constraint
+ }
+ }
// Ok - all mandatory checked and we still have candidates.
// Let's try filtering using the optional constraints. The optional
@@ -405,7 +410,7 @@ void MediaStreamVideoSource::AddTrack(
case ENDED:
case STARTED: {
// Currently, reconfiguring the source is not supported.
- FinalizeAddTrack();
+ FinalizeAddTrack(MEDIA_DEVICE_OK);
}
}
}
@@ -462,7 +467,7 @@ void MediaStreamVideoSource::OnSupportedFormats(
SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded);
// This object can be deleted after calling FinalizeAddTrack. See comment
// in the header file.
- FinalizeAddTrack();
+ FinalizeAddTrack(MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED);
miu 2014/07/30 19:37:23 re: My comment in the .h file: The call to FindBe
jiajia.qin 2014/07/31 13:43:01 Done.
return;
}
@@ -501,7 +506,7 @@ bool MediaStreamVideoSource::FindBestFormatWithConstraints(
return true;
}
media::VideoCaptureFormats filtered_formats =
- FilterFormats(requested_constraints, formats);
+ FilterFormats(requested_constraints, formats, &unsatisfied_constraint_);
if (filtered_formats.size() > 0) {
// A request with constraints that can be fulfilled.
GetBestCaptureFormat(filtered_formats,
@@ -513,10 +518,10 @@ bool MediaStreamVideoSource::FindBestFormatWithConstraints(
return false;
}
-void MediaStreamVideoSource::OnStartDone(bool success) {
+void MediaStreamVideoSource::OnStartDone(MediaStreamRequestResult result) {
DCHECK(CalledOnValidThread());
- DVLOG(3) << "OnStartDone({success =" << success << "})";
- if (success) {
+ DVLOG(3) << "OnStartDone({result =" << result << "})";
+ if (result == MEDIA_DEVICE_OK) {
DCHECK_EQ(STARTING, state_);
state_ = STARTED;
SetReadyState(blink::WebMediaStreamSource::ReadyStateLive);
@@ -526,10 +531,10 @@ void MediaStreamVideoSource::OnStartDone(bool success) {
// This object can be deleted after calling FinalizeAddTrack. See comment in
// the header file.
- FinalizeAddTrack();
+ FinalizeAddTrack(result);
}
-void MediaStreamVideoSource::FinalizeAddTrack() {
+void MediaStreamVideoSource::FinalizeAddTrack(MediaStreamRequestResult result) {
DCHECK(CalledOnValidThread());
media::VideoCaptureFormats formats;
formats.push_back(current_format_);
@@ -538,17 +543,7 @@ void MediaStreamVideoSource::FinalizeAddTrack() {
callbacks.swap(requested_constraints_);
for (std::vector<RequestedConstraints>::iterator it = callbacks.begin();
it != callbacks.end(); ++it) {
- // The track has been added successfully if the source has started and
- // there are either no mandatory constraints and the source doesn't expose
- // its format capabilities, or the constraints and the format match.
- // For example, a remote source doesn't expose its format capabilities.
- bool success =
- state_ == STARTED &&
- ((!current_format_.IsValid() && !HasMandatoryConstraints(
- it->constraints)) ||
- !FilterFormats(it->constraints, formats).empty());
-
- if (success) {
+ if (result == MEDIA_DEVICE_OK) {
int max_width;
int max_height;
GetDesiredMaxWidthAndHeight(it->constraints, &max_width, &max_height);
@@ -572,10 +567,10 @@ void MediaStreamVideoSource::FinalizeAddTrack() {
on_mute_callback);
}
- DVLOG(3) << "FinalizeAddTrack() success " << success;
+ DVLOG(3) << "FinalizeAddTrack() result " << result;
if (!it->callback.is_null())
- it->callback.Run(this, success);
+ it->callback.Run(this, result, unsatisfied_constraint_);
}
}

Powered by Google App Engine
This is Rietveld 408576698