Chromium Code Reviews| 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 65ece681c143ee4508ca57259ee322919b31d0e4..a2f6fc69c80aa081378ac620decb8084c32a749c 100644 |
| --- a/content/renderer/media/media_stream_video_source.cc |
| +++ b/content/renderer/media/media_stream_video_source.cc |
| @@ -219,7 +219,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* constraintName) { |
|
no longer working on chromium
2014/07/28 19:55:08
constraint_name or unsatisfied_constraint
jiajia.qin
2014/07/30 05:18:07
Done.
|
| if (constraints.isNull()) { |
| return supported_formats; |
| } |
| @@ -255,11 +256,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 |
| + // the ConstraintNotSatisfiedError |
| + if (candidates.empty()) { |
| + *constraintName = mandatory[i].m_name; |
| + return candidates; |
| + } |
| + } |
| // Ok - all mandatory checked and we still have candidates. |
| // Let's try filtering using the optional constraints. The optional |
| @@ -389,7 +394,7 @@ void MediaStreamVideoSource::AddTrack( |
| case ENDED: |
| case STARTED: { |
| // Currently, reconfiguring the source is not supported. |
| - FinalizeAddTrack(); |
| + FinalizeAddTrack(MEDIA_DEVICE_OK); |
| } |
| } |
| } |
| @@ -446,7 +451,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); |
| return; |
| } |
| @@ -481,7 +486,7 @@ bool MediaStreamVideoSource::FindBestFormatWithConstraints( |
| return true; |
| } |
| media::VideoCaptureFormats filtered_formats = |
| - FilterFormats(requested_constraints, formats); |
| + FilterFormats(requested_constraints, formats, &constraintName_); |
| if (filtered_formats.size() > 0) { |
| // A request with constraints that can be fulfilled. |
| GetBestCaptureFormat(filtered_formats, |
| @@ -493,10 +498,11 @@ bool MediaStreamVideoSource::FindBestFormatWithConstraints( |
| return false; |
| } |
| -void MediaStreamVideoSource::OnStartDone(bool success) { |
| +void MediaStreamVideoSource::OnStartDone( |
| + content::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); |
| @@ -508,10 +514,11 @@ 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( |
| + content::MediaStreamRequestResult result) { |
| media::VideoCaptureFormats formats; |
| formats.push_back(current_format_); |
| @@ -519,17 +526,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); |
| @@ -543,10 +540,10 @@ void MediaStreamVideoSource::FinalizeAddTrack() { |
| min_aspect_ratio, max_aspect_ratio); |
| } |
| - 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, constraintName_); |
| } |
| } |