OLD | NEW |
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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 state_ = ENDED; | 457 state_ = ENDED; |
458 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 458 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); |
459 } | 459 } |
460 | 460 |
461 void MediaStreamVideoSource::OnSupportedFormats( | 461 void MediaStreamVideoSource::OnSupportedFormats( |
462 const media::VideoCaptureFormats& formats) { | 462 const media::VideoCaptureFormats& formats) { |
463 DCHECK(CalledOnValidThread()); | 463 DCHECK(CalledOnValidThread()); |
464 DCHECK_EQ(RETRIEVING_CAPABILITIES, state_); | 464 DCHECK_EQ(RETRIEVING_CAPABILITIES, state_); |
465 | 465 |
466 supported_formats_ = formats; | 466 supported_formats_ = formats; |
| 467 blink::WebMediaConstraints fulfilled_constraints; |
467 if (!FindBestFormatWithConstraints(supported_formats_, | 468 if (!FindBestFormatWithConstraints(supported_formats_, |
468 ¤t_format_)) { | 469 ¤t_format_, |
| 470 &fulfilled_constraints)) { |
469 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 471 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); |
470 // This object can be deleted after calling FinalizeAddTrack. See comment | 472 // This object can be deleted after calling FinalizeAddTrack. See comment |
471 // in the header file. | 473 // in the header file. |
472 FinalizeAddTrack(); | 474 FinalizeAddTrack(); |
473 return; | 475 return; |
474 } | 476 } |
475 | 477 |
476 state_ = STARTING; | 478 state_ = STARTING; |
477 DVLOG(3) << "Starting the capturer with " << current_format_.ToString(); | 479 DVLOG(3) << "Starting the capturer with " << current_format_.ToString(); |
478 | 480 |
479 StartSourceImpl( | 481 StartSourceImpl( |
480 current_format_, | 482 current_format_, |
| 483 fulfilled_constraints, |
481 base::Bind(&VideoTrackAdapter::DeliverFrameOnIO, track_adapter_)); | 484 base::Bind(&VideoTrackAdapter::DeliverFrameOnIO, track_adapter_)); |
482 } | 485 } |
483 | 486 |
484 bool MediaStreamVideoSource::FindBestFormatWithConstraints( | 487 bool MediaStreamVideoSource::FindBestFormatWithConstraints( |
485 const media::VideoCaptureFormats& formats, | 488 const media::VideoCaptureFormats& formats, |
486 media::VideoCaptureFormat* best_format) { | 489 media::VideoCaptureFormat* best_format, |
| 490 blink::WebMediaConstraints* fulfilled_constraints) { |
487 DCHECK(CalledOnValidThread()); | 491 DCHECK(CalledOnValidThread()); |
488 // Find the first constraints that we can fulfill. | 492 // Find the first constraints that we can fulfill. |
489 for (const auto& request : requested_constraints_) { | 493 for (const auto& request : requested_constraints_) { |
490 const blink::WebMediaConstraints& requested_constraints = | 494 const blink::WebMediaConstraints& requested_constraints = |
491 request.constraints; | 495 request.constraints; |
492 | 496 |
493 // If the source doesn't support capability enumeration it is still ok if | 497 // If the source doesn't support capability enumeration it is still ok if |
494 // no mandatory constraints have been specified. That just means that | 498 // no mandatory constraints have been specified. That just means that |
495 // we will start with whatever format is native to the source. | 499 // we will start with whatever format is native to the source. |
496 if (formats.empty() && !HasMandatoryConstraints(requested_constraints)) { | 500 if (formats.empty() && !HasMandatoryConstraints(requested_constraints)) { |
| 501 *fulfilled_constraints = requested_constraints; |
497 *best_format = media::VideoCaptureFormat(); | 502 *best_format = media::VideoCaptureFormat(); |
498 return true; | 503 return true; |
499 } | 504 } |
500 blink::WebString unsatisfied_constraint; | 505 blink::WebString unsatisfied_constraint; |
501 media::VideoCaptureFormats filtered_formats = | 506 media::VideoCaptureFormats filtered_formats = |
502 FilterFormats(requested_constraints, formats, &unsatisfied_constraint); | 507 FilterFormats(requested_constraints, formats, &unsatisfied_constraint); |
503 if (filtered_formats.size() > 0) { | 508 if (filtered_formats.size() > 0) { |
504 // A request with constraints that can be fulfilled. | 509 // A request with constraints that can be fulfilled. |
| 510 *fulfilled_constraints = requested_constraints; |
505 GetBestCaptureFormat(filtered_formats, | 511 GetBestCaptureFormat(filtered_formats, |
506 requested_constraints, | 512 requested_constraints, |
507 best_format); | 513 best_format); |
508 return true; | 514 return true; |
509 } | 515 } |
510 } | 516 } |
511 return false; | 517 return false; |
512 } | 518 } |
513 | 519 |
514 void MediaStreamVideoSource::OnStartDone(MediaStreamRequestResult result) { | 520 void MediaStreamVideoSource::OnStartDone(MediaStreamRequestResult result) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 : track(track), | 614 : track(track), |
609 frame_callback(frame_callback), | 615 frame_callback(frame_callback), |
610 constraints(constraints), | 616 constraints(constraints), |
611 callback(callback) { | 617 callback(callback) { |
612 } | 618 } |
613 | 619 |
614 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { | 620 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { |
615 } | 621 } |
616 | 622 |
617 } // namespace content | 623 } // namespace content |
OLD | NEW |