| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_constraints_util_video_source.h" | 5 #include "content/renderer/media/media_stream_constraints_util_video_source.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // device ID, power-line frequency, resolution and frame rate. | 23 // device ID, power-line frequency, resolution and frame rate. |
| 24 const int kNumDefaultDistanceEntries = 4; | 24 const int kNumDefaultDistanceEntries = 4; |
| 25 | 25 |
| 26 // The default resolution to be preferred as tie-breaking criterion. | 26 // The default resolution to be preferred as tie-breaking criterion. |
| 27 const int kDefaultResolutionArea = MediaStreamVideoSource::kDefaultWidth * | 27 const int kDefaultResolutionArea = MediaStreamVideoSource::kDefaultWidth * |
| 28 MediaStreamVideoSource::kDefaultHeight; | 28 MediaStreamVideoSource::kDefaultHeight; |
| 29 | 29 |
| 30 // The minimum aspect ratio to be supported by sources. | 30 // The minimum aspect ratio to be supported by sources. |
| 31 const double kMinSourceAspectRatio = 0.05; | 31 const double kMinSourceAspectRatio = 0.05; |
| 32 | 32 |
| 33 // VideoKind enum values. See https://w3c.github.io/mediacapture-depth. |
| 34 const char kVideoKindColor[] = "color"; |
| 35 const char kVideoKindDepth[] = "depth"; |
| 36 |
| 33 blink::WebString ToWebString(::mojom::FacingMode facing_mode) { | 37 blink::WebString ToWebString(::mojom::FacingMode facing_mode) { |
| 34 switch (facing_mode) { | 38 switch (facing_mode) { |
| 35 case ::mojom::FacingMode::USER: | 39 case ::mojom::FacingMode::USER: |
| 36 return blink::WebString::fromASCII("user"); | 40 return blink::WebString::fromASCII("user"); |
| 37 case ::mojom::FacingMode::ENVIRONMENT: | 41 case ::mojom::FacingMode::ENVIRONMENT: |
| 38 return blink::WebString::fromASCII("environment"); | 42 return blink::WebString::fromASCII("environment"); |
| 39 case ::mojom::FacingMode::LEFT: | 43 case ::mojom::FacingMode::LEFT: |
| 40 return blink::WebString::fromASCII("left"); | 44 return blink::WebString::fromASCII("left"); |
| 41 case ::mojom::FacingMode::RIGHT: | 45 case ::mojom::FacingMode::RIGHT: |
| 42 return blink::WebString::fromASCII("right"); | 46 return blink::WebString::fromASCII("right"); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 failed_constraint_name) + | 304 failed_constraint_name) + |
| 301 ResolutionConstraintSourceDistance(format.frame_size.width(), | 305 ResolutionConstraintSourceDistance(format.frame_size.width(), |
| 302 constraint_set.width, | 306 constraint_set.width, |
| 303 failed_constraint_name) + | 307 failed_constraint_name) + |
| 304 AspectRatioConstraintSourceDistance( | 308 AspectRatioConstraintSourceDistance( |
| 305 format.frame_size.height(), format.frame_size.width(), | 309 format.frame_size.height(), format.frame_size.width(), |
| 306 constraint_set.height, constraint_set.width, | 310 constraint_set.height, constraint_set.width, |
| 307 constraint_set.aspectRatio, failed_constraint_name) + | 311 constraint_set.aspectRatio, failed_constraint_name) + |
| 308 FrameRateConstraintSourceDistance(format.frame_rate, | 312 FrameRateConstraintSourceDistance(format.frame_rate, |
| 309 constraint_set.frameRate, | 313 constraint_set.frameRate, |
| 310 failed_constraint_name); | 314 failed_constraint_name) + |
| 315 StringConstraintSourceDistance(GetVideoKindForFormat(format), |
| 316 constraint_set.videoKind, |
| 317 failed_constraint_name); |
| 311 } | 318 } |
| 312 | 319 |
| 313 // Returns a custom distance between a set of candidate settings and a | 320 // Returns a custom distance between a set of candidate settings and a |
| 314 // constraint set. It is simply the sum of the distances for each individual | 321 // constraint set. It is simply the sum of the distances for each individual |
| 315 // setting in |candidate|. | 322 // setting in |candidate|. |
| 316 // If |candidate| cannot satisfy constraint, the distance is HUGE_VAL. | 323 // If |candidate| cannot satisfy constraint, the distance is HUGE_VAL. |
| 317 // Otherwise the distance is a finite value. Candidates with lower distance | 324 // Otherwise the distance is a finite value. Candidates with lower distance |
| 318 // satisfy |constraint_set| in a "better" way. | 325 // satisfy |constraint_set| in a "better" way. |
| 319 double CandidateSourceDistance( | 326 double CandidateSourceDistance( |
| 320 const VideoCaptureSourceSettings& candidate, | 327 const VideoCaptureSourceSettings& candidate, |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 double fitness = 0.0; | 477 double fitness = 0.0; |
| 471 fitness += AspectRatioConstraintFitnessDistance( | 478 fitness += AspectRatioConstraintFitnessDistance( |
| 472 candidate.GetHeight(), candidate.GetWidth(), constraint_set.height, | 479 candidate.GetHeight(), candidate.GetWidth(), constraint_set.height, |
| 473 constraint_set.width, constraint_set.aspectRatio); | 480 constraint_set.width, constraint_set.aspectRatio); |
| 474 fitness += StringConstraintFitnessDistance(candidate.GetDeviceId(), | 481 fitness += StringConstraintFitnessDistance(candidate.GetDeviceId(), |
| 475 constraint_set.deviceId); | 482 constraint_set.deviceId); |
| 476 fitness += StringConstraintFitnessDistance(candidate.GetFacingMode(), | 483 fitness += StringConstraintFitnessDistance(candidate.GetFacingMode(), |
| 477 constraint_set.facingMode); | 484 constraint_set.facingMode); |
| 478 fitness += FrameRateConstraintFitnessDistance(candidate.GetFrameRate(), | 485 fitness += FrameRateConstraintFitnessDistance(candidate.GetFrameRate(), |
| 479 constraint_set.frameRate); | 486 constraint_set.frameRate); |
| 487 fitness += StringConstraintFitnessDistance(candidate.GetVideoKind(), |
| 488 constraint_set.videoKind); |
| 480 fitness += PowerLineFrequencyConstraintFitnessDistance( | 489 fitness += PowerLineFrequencyConstraintFitnessDistance( |
| 481 candidate.GetPowerLineFrequency(), constraint_set.googPowerLineFrequency); | 490 candidate.GetPowerLineFrequency(), constraint_set.googPowerLineFrequency); |
| 482 fitness += ResolutionConstraintFitnessDistance(candidate.GetHeight(), | 491 fitness += ResolutionConstraintFitnessDistance(candidate.GetHeight(), |
| 483 constraint_set.height); | 492 constraint_set.height); |
| 484 fitness += ResolutionConstraintFitnessDistance(candidate.GetWidth(), | 493 fitness += ResolutionConstraintFitnessDistance(candidate.GetWidth(), |
| 485 constraint_set.width); | 494 constraint_set.width); |
| 486 | 495 |
| 487 return fitness; | 496 return fitness; |
| 488 } | 497 } |
| 489 | 498 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 double frame_rate_distance = | 556 double frame_rate_distance = |
| 548 candidate.format().frame_rate == MediaStreamVideoSource::kDefaultFrameRate | 557 candidate.format().frame_rate == MediaStreamVideoSource::kDefaultFrameRate |
| 549 ? 0.0 | 558 ? 0.0 |
| 550 : Distance(candidate.format().frame_rate, | 559 : Distance(candidate.format().frame_rate, |
| 551 MediaStreamVideoSource::kDefaultFrameRate); | 560 MediaStreamVideoSource::kDefaultFrameRate); |
| 552 distance_vector->push_back(frame_rate_distance); | 561 distance_vector->push_back(frame_rate_distance); |
| 553 } | 562 } |
| 554 | 563 |
| 555 } // namespace | 564 } // namespace |
| 556 | 565 |
| 566 blink::WebString GetVideoKindForFormat( |
| 567 const media::VideoCaptureFormat& format) { |
| 568 return (format.pixel_format == media::PIXEL_FORMAT_Y16) |
| 569 ? blink::WebString::fromASCII(kVideoKindDepth) |
| 570 : blink::WebString::fromASCII(kVideoKindColor); |
| 571 } |
| 572 |
| 557 VideoCaptureCapabilities::VideoCaptureCapabilities() = default; | 573 VideoCaptureCapabilities::VideoCaptureCapabilities() = default; |
| 558 VideoCaptureCapabilities::VideoCaptureCapabilities( | 574 VideoCaptureCapabilities::VideoCaptureCapabilities( |
| 559 VideoCaptureCapabilities&& other) = default; | 575 VideoCaptureCapabilities&& other) = default; |
| 560 VideoCaptureCapabilities::~VideoCaptureCapabilities() = default; | 576 VideoCaptureCapabilities::~VideoCaptureCapabilities() = default; |
| 561 VideoCaptureCapabilities& VideoCaptureCapabilities::operator=( | 577 VideoCaptureCapabilities& VideoCaptureCapabilities::operator=( |
| 562 VideoCaptureCapabilities&& other) = default; | 578 VideoCaptureCapabilities&& other) = default; |
| 563 | 579 |
| 564 VideoCaptureSourceSettings::VideoCaptureSourceSettings( | 580 VideoCaptureSourceSettings::VideoCaptureSourceSettings( |
| 565 const VideoCaptureSourceSettings& other) = default; | 581 const VideoCaptureSourceSettings& other) = default; |
| 566 VideoCaptureSourceSettings::VideoCaptureSourceSettings( | 582 VideoCaptureSourceSettings::VideoCaptureSourceSettings( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 } | 618 } |
| 603 | 619 |
| 604 double VideoCaptureSourceSettings::GetFrameRate() const { | 620 double VideoCaptureSourceSettings::GetFrameRate() const { |
| 605 return format_.frame_rate; | 621 return format_.frame_rate; |
| 606 } | 622 } |
| 607 | 623 |
| 608 blink::WebString VideoCaptureSourceSettings::GetDeviceId() const { | 624 blink::WebString VideoCaptureSourceSettings::GetDeviceId() const { |
| 609 return blink::WebString::fromASCII(device_id_.data()); | 625 return blink::WebString::fromASCII(device_id_.data()); |
| 610 } | 626 } |
| 611 | 627 |
| 628 blink::WebString VideoCaptureSourceSettings::GetVideoKind() const { |
| 629 return GetVideoKindForFormat(format_); |
| 630 } |
| 631 |
| 612 const char kDefaultFailedConstraintName[] = ""; | 632 const char kDefaultFailedConstraintName[] = ""; |
| 613 | 633 |
| 614 VideoCaptureSourceSelectionResult::VideoCaptureSourceSelectionResult() | 634 VideoCaptureSourceSelectionResult::VideoCaptureSourceSelectionResult() |
| 615 : failed_constraint_name(kDefaultFailedConstraintName) {} | 635 : failed_constraint_name(kDefaultFailedConstraintName) {} |
| 616 VideoCaptureSourceSelectionResult::VideoCaptureSourceSelectionResult( | 636 VideoCaptureSourceSelectionResult::VideoCaptureSourceSelectionResult( |
| 617 const VideoCaptureSourceSelectionResult& other) = default; | 637 const VideoCaptureSourceSelectionResult& other) = default; |
| 618 VideoCaptureSourceSelectionResult::VideoCaptureSourceSelectionResult( | 638 VideoCaptureSourceSelectionResult::VideoCaptureSourceSelectionResult( |
| 619 VideoCaptureSourceSelectionResult&& other) = default; | 639 VideoCaptureSourceSelectionResult&& other) = default; |
| 620 VideoCaptureSourceSelectionResult::~VideoCaptureSourceSelectionResult() = | 640 VideoCaptureSourceSelectionResult::~VideoCaptureSourceSelectionResult() = |
| 621 default; | 641 default; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 } | 743 } |
| 724 } | 744 } |
| 725 | 745 |
| 726 if (!result.has_value()) | 746 if (!result.has_value()) |
| 727 result.failed_constraint_name = failed_constraint_name; | 747 result.failed_constraint_name = failed_constraint_name; |
| 728 | 748 |
| 729 return result; | 749 return result; |
| 730 } | 750 } |
| 731 | 751 |
| 732 } // namespace content | 752 } // namespace content |
| OLD | NEW |