| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "platform/RuntimeEnabledFeatures.h" | 40 #include "platform/RuntimeEnabledFeatures.h" |
| 41 #include "wtf/Assertions.h" | 41 #include "wtf/Assertions.h" |
| 42 #include "wtf/HashMap.h" | 42 #include "wtf/HashMap.h" |
| 43 #include "wtf/Vector.h" | 43 #include "wtf/Vector.h" |
| 44 #include "wtf/text/StringHash.h" | 44 #include "wtf/text/StringHash.h" |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 namespace MediaConstraintsImpl { | 48 namespace MediaConstraintsImpl { |
| 49 | 49 |
| 50 // A naked value is treated as an "ideal" value in the basic constraints, |
| 51 // but as an exact value in "advanced" constraints. |
| 52 // https://w3c.github.io/mediacapture-main/#constrainable-interface |
| 53 enum class NakedValueDisposition { kTreatAsIdeal, kTreatAsExact }; |
| 54 |
| 50 // Old type/value form of constraint. Used in parsing old-style constraints. | 55 // Old type/value form of constraint. Used in parsing old-style constraints. |
| 51 struct NameValueStringConstraint { | 56 struct NameValueStringConstraint { |
| 52 NameValueStringConstraint() {} | 57 NameValueStringConstraint() {} |
| 53 | 58 |
| 54 NameValueStringConstraint(WebString name, WebString value) | 59 NameValueStringConstraint(WebString name, WebString value) |
| 55 : m_name(name), m_value(value) {} | 60 : m_name(name), m_value(value) {} |
| 56 | 61 |
| 57 WebString m_name; | 62 WebString m_name; |
| 58 WebString m_value; | 63 WebString m_value; |
| 59 }; | 64 }; |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 Vector<NameValueStringConstraint> mandatory; | 483 Vector<NameValueStringConstraint> mandatory; |
| 479 if (!parse(constraintsDictionary, optional, mandatory)) { | 484 if (!parse(constraintsDictionary, optional, mandatory)) { |
| 480 errorState.throwTypeError("Malformed constraints object."); | 485 errorState.throwTypeError("Malformed constraints object."); |
| 481 return WebMediaConstraints(); | 486 return WebMediaConstraints(); |
| 482 } | 487 } |
| 483 UseCounter::count(context, UseCounter::MediaStreamConstraintsFromDictionary); | 488 UseCounter::count(context, UseCounter::MediaStreamConstraintsFromDictionary); |
| 484 return createFromNamedConstraints(context, mandatory, optional, errorState); | 489 return createFromNamedConstraints(context, mandatory, optional, errorState); |
| 485 } | 490 } |
| 486 | 491 |
| 487 void copyLongConstraint(const LongOrConstrainLongRange& blinkUnionForm, | 492 void copyLongConstraint(const LongOrConstrainLongRange& blinkUnionForm, |
| 493 NakedValueDisposition nakedTreatment, |
| 488 LongConstraint& webForm) { | 494 LongConstraint& webForm) { |
| 489 if (blinkUnionForm.isLong()) { | 495 if (blinkUnionForm.isLong()) { |
| 490 webForm.setIdeal(blinkUnionForm.getAsLong()); | 496 switch (nakedTreatment) { |
| 497 case NakedValueDisposition::kTreatAsIdeal: |
| 498 webForm.setIdeal(blinkUnionForm.getAsLong()); |
| 499 break; |
| 500 case NakedValueDisposition::kTreatAsExact: |
| 501 webForm.setExact(blinkUnionForm.getAsLong()); |
| 502 break; |
| 503 } |
| 491 return; | 504 return; |
| 492 } | 505 } |
| 493 const auto& blinkForm = blinkUnionForm.getAsConstrainLongRange(); | 506 const auto& blinkForm = blinkUnionForm.getAsConstrainLongRange(); |
| 494 if (blinkForm.hasMin()) { | 507 if (blinkForm.hasMin()) { |
| 495 webForm.setMin(blinkForm.min()); | 508 webForm.setMin(blinkForm.min()); |
| 496 } | 509 } |
| 497 if (blinkForm.hasMax()) { | 510 if (blinkForm.hasMax()) { |
| 498 webForm.setMax(blinkForm.max()); | 511 webForm.setMax(blinkForm.max()); |
| 499 } | 512 } |
| 500 if (blinkForm.hasIdeal()) { | 513 if (blinkForm.hasIdeal()) { |
| 501 webForm.setIdeal(blinkForm.ideal()); | 514 webForm.setIdeal(blinkForm.ideal()); |
| 502 } | 515 } |
| 503 if (blinkForm.hasExact()) { | 516 if (blinkForm.hasExact()) { |
| 504 webForm.setExact(blinkForm.exact()); | 517 webForm.setExact(blinkForm.exact()); |
| 505 } | 518 } |
| 506 } | 519 } |
| 507 | 520 |
| 508 void copyDoubleConstraint(const DoubleOrConstrainDoubleRange& blinkUnionForm, | 521 void copyDoubleConstraint(const DoubleOrConstrainDoubleRange& blinkUnionForm, |
| 522 NakedValueDisposition nakedTreatment, |
| 509 DoubleConstraint& webForm) { | 523 DoubleConstraint& webForm) { |
| 510 if (blinkUnionForm.isDouble()) { | 524 if (blinkUnionForm.isDouble()) { |
| 511 webForm.setIdeal(blinkUnionForm.getAsDouble()); | 525 switch (nakedTreatment) { |
| 526 case NakedValueDisposition::kTreatAsIdeal: |
| 527 webForm.setIdeal(blinkUnionForm.getAsDouble()); |
| 528 break; |
| 529 case NakedValueDisposition::kTreatAsExact: |
| 530 webForm.setExact(blinkUnionForm.getAsDouble()); |
| 531 break; |
| 532 } |
| 512 return; | 533 return; |
| 513 } | 534 } |
| 514 const auto& blinkForm = blinkUnionForm.getAsConstrainDoubleRange(); | 535 const auto& blinkForm = blinkUnionForm.getAsConstrainDoubleRange(); |
| 515 if (blinkForm.hasMin()) { | 536 if (blinkForm.hasMin()) { |
| 516 webForm.setMin(blinkForm.min()); | 537 webForm.setMin(blinkForm.min()); |
| 517 } | 538 } |
| 518 if (blinkForm.hasMax()) { | 539 if (blinkForm.hasMax()) { |
| 519 webForm.setMax(blinkForm.max()); | 540 webForm.setMax(blinkForm.max()); |
| 520 } | 541 } |
| 521 if (blinkForm.hasIdeal()) { | 542 if (blinkForm.hasIdeal()) { |
| 522 webForm.setIdeal(blinkForm.ideal()); | 543 webForm.setIdeal(blinkForm.ideal()); |
| 523 } | 544 } |
| 524 if (blinkForm.hasExact()) { | 545 if (blinkForm.hasExact()) { |
| 525 webForm.setExact(blinkForm.exact()); | 546 webForm.setExact(blinkForm.exact()); |
| 526 } | 547 } |
| 527 } | 548 } |
| 528 | 549 |
| 529 void copyStringConstraint( | 550 void copyStringConstraint( |
| 530 const StringOrStringSequenceOrConstrainDOMStringParameters& blinkUnionForm, | 551 const StringOrStringSequenceOrConstrainDOMStringParameters& blinkUnionForm, |
| 552 NakedValueDisposition nakedTreatment, |
| 531 StringConstraint& webForm) { | 553 StringConstraint& webForm) { |
| 532 if (blinkUnionForm.isString()) { | 554 if (blinkUnionForm.isString()) { |
| 533 webForm.setIdeal(Vector<String>(1, blinkUnionForm.getAsString())); | 555 switch (nakedTreatment) { |
| 556 case NakedValueDisposition::kTreatAsIdeal: |
| 557 webForm.setIdeal(Vector<String>(1, blinkUnionForm.getAsString())); |
| 558 break; |
| 559 case NakedValueDisposition::kTreatAsExact: |
| 560 webForm.setExact(Vector<String>(1, blinkUnionForm.getAsString())); |
| 561 |
| 562 break; |
| 563 } |
| 534 return; | 564 return; |
| 535 } | 565 } |
| 536 if (blinkUnionForm.isStringSequence()) { | 566 if (blinkUnionForm.isStringSequence()) { |
| 537 webForm.setIdeal(blinkUnionForm.getAsStringSequence()); | 567 switch (nakedTreatment) { |
| 568 case NakedValueDisposition::kTreatAsIdeal: |
| 569 webForm.setIdeal(blinkUnionForm.getAsStringSequence()); |
| 570 break; |
| 571 case NakedValueDisposition::kTreatAsExact: |
| 572 webForm.setExact(blinkUnionForm.getAsStringSequence()); |
| 573 break; |
| 574 } |
| 538 return; | 575 return; |
| 539 } | 576 } |
| 540 const auto& blinkForm = blinkUnionForm.getAsConstrainDOMStringParameters(); | 577 const auto& blinkForm = blinkUnionForm.getAsConstrainDOMStringParameters(); |
| 541 if (blinkForm.hasIdeal()) { | 578 if (blinkForm.hasIdeal()) { |
| 542 if (blinkForm.ideal().isStringSequence()) { | 579 if (blinkForm.ideal().isStringSequence()) { |
| 543 webForm.setIdeal(blinkForm.ideal().getAsStringSequence()); | 580 webForm.setIdeal(blinkForm.ideal().getAsStringSequence()); |
| 544 } else if (blinkForm.ideal().isString()) { | 581 } else if (blinkForm.ideal().isString()) { |
| 545 webForm.setIdeal(Vector<String>(1, blinkForm.ideal().getAsString())); | 582 webForm.setIdeal(Vector<String>(1, blinkForm.ideal().getAsString())); |
| 546 } | 583 } |
| 547 } | 584 } |
| 548 if (blinkForm.hasExact()) { | 585 if (blinkForm.hasExact()) { |
| 549 if (blinkForm.exact().isStringSequence()) { | 586 if (blinkForm.exact().isStringSequence()) { |
| 550 webForm.setExact(blinkForm.exact().getAsStringSequence()); | 587 webForm.setExact(blinkForm.exact().getAsStringSequence()); |
| 551 } else if (blinkForm.exact().isString()) { | 588 } else if (blinkForm.exact().isString()) { |
| 552 webForm.setExact(Vector<String>(1, blinkForm.exact().getAsString())); | 589 webForm.setExact(Vector<String>(1, blinkForm.exact().getAsString())); |
| 553 } | 590 } |
| 554 } | 591 } |
| 555 } | 592 } |
| 556 | 593 |
| 557 void copyBooleanConstraint( | 594 void copyBooleanConstraint( |
| 558 const BooleanOrConstrainBooleanParameters& blinkUnionForm, | 595 const BooleanOrConstrainBooleanParameters& blinkUnionForm, |
| 596 NakedValueDisposition nakedTreatment, |
| 559 BooleanConstraint& webForm) { | 597 BooleanConstraint& webForm) { |
| 560 if (blinkUnionForm.isBoolean()) { | 598 if (blinkUnionForm.isBoolean()) { |
| 561 webForm.setIdeal(blinkUnionForm.getAsBoolean()); | 599 switch (nakedTreatment) { |
| 600 case NakedValueDisposition::kTreatAsIdeal: |
| 601 webForm.setIdeal(blinkUnionForm.getAsBoolean()); |
| 602 break; |
| 603 case NakedValueDisposition::kTreatAsExact: |
| 604 webForm.setExact(blinkUnionForm.getAsBoolean()); |
| 605 break; |
| 606 } |
| 562 return; | 607 return; |
| 563 } | 608 } |
| 564 const auto& blinkForm = blinkUnionForm.getAsConstrainBooleanParameters(); | 609 const auto& blinkForm = blinkUnionForm.getAsConstrainBooleanParameters(); |
| 565 if (blinkForm.hasIdeal()) { | 610 if (blinkForm.hasIdeal()) { |
| 566 webForm.setIdeal(blinkForm.ideal()); | 611 webForm.setIdeal(blinkForm.ideal()); |
| 567 } | 612 } |
| 568 if (blinkForm.hasExact()) { | 613 if (blinkForm.hasExact()) { |
| 569 webForm.setExact(blinkForm.exact()); | 614 webForm.setExact(blinkForm.exact()); |
| 570 } | 615 } |
| 571 } | 616 } |
| 572 | 617 |
| 573 void copyConstraintSet(const MediaTrackConstraintSet& constraintsIn, | 618 void copyConstraintSet(const MediaTrackConstraintSet& constraintsIn, |
| 619 NakedValueDisposition nakedTreatment, |
| 574 WebMediaTrackConstraintSet& constraintBuffer) { | 620 WebMediaTrackConstraintSet& constraintBuffer) { |
| 575 if (constraintsIn.hasWidth()) { | 621 if (constraintsIn.hasWidth()) { |
| 576 copyLongConstraint(constraintsIn.width(), constraintBuffer.width); | 622 copyLongConstraint(constraintsIn.width(), nakedTreatment, |
| 623 constraintBuffer.width); |
| 577 } | 624 } |
| 578 if (constraintsIn.hasHeight()) { | 625 if (constraintsIn.hasHeight()) { |
| 579 copyLongConstraint(constraintsIn.height(), constraintBuffer.height); | 626 copyLongConstraint(constraintsIn.height(), nakedTreatment, |
| 627 constraintBuffer.height); |
| 580 } | 628 } |
| 581 if (constraintsIn.hasAspectRatio()) { | 629 if (constraintsIn.hasAspectRatio()) { |
| 582 copyDoubleConstraint(constraintsIn.aspectRatio(), | 630 copyDoubleConstraint(constraintsIn.aspectRatio(), nakedTreatment, |
| 583 constraintBuffer.aspectRatio); | 631 constraintBuffer.aspectRatio); |
| 584 } | 632 } |
| 585 if (constraintsIn.hasFrameRate()) { | 633 if (constraintsIn.hasFrameRate()) { |
| 586 copyDoubleConstraint(constraintsIn.frameRate(), constraintBuffer.frameRate); | 634 copyDoubleConstraint(constraintsIn.frameRate(), nakedTreatment, |
| 635 constraintBuffer.frameRate); |
| 587 } | 636 } |
| 588 if (constraintsIn.hasFacingMode()) { | 637 if (constraintsIn.hasFacingMode()) { |
| 589 copyStringConstraint(constraintsIn.facingMode(), | 638 copyStringConstraint(constraintsIn.facingMode(), nakedTreatment, |
| 590 constraintBuffer.facingMode); | 639 constraintBuffer.facingMode); |
| 591 } | 640 } |
| 592 if (constraintsIn.hasVolume()) { | 641 if (constraintsIn.hasVolume()) { |
| 593 copyDoubleConstraint(constraintsIn.volume(), constraintBuffer.volume); | 642 copyDoubleConstraint(constraintsIn.volume(), nakedTreatment, |
| 643 constraintBuffer.volume); |
| 594 } | 644 } |
| 595 if (constraintsIn.hasSampleRate()) { | 645 if (constraintsIn.hasSampleRate()) { |
| 596 copyLongConstraint(constraintsIn.sampleRate(), constraintBuffer.sampleRate); | 646 copyLongConstraint(constraintsIn.sampleRate(), nakedTreatment, |
| 647 constraintBuffer.sampleRate); |
| 597 } | 648 } |
| 598 if (constraintsIn.hasSampleSize()) { | 649 if (constraintsIn.hasSampleSize()) { |
| 599 copyLongConstraint(constraintsIn.sampleSize(), constraintBuffer.sampleSize); | 650 copyLongConstraint(constraintsIn.sampleSize(), nakedTreatment, |
| 651 constraintBuffer.sampleSize); |
| 600 } | 652 } |
| 601 if (constraintsIn.hasEchoCancellation()) { | 653 if (constraintsIn.hasEchoCancellation()) { |
| 602 copyBooleanConstraint(constraintsIn.echoCancellation(), | 654 copyBooleanConstraint(constraintsIn.echoCancellation(), nakedTreatment, |
| 603 constraintBuffer.echoCancellation); | 655 constraintBuffer.echoCancellation); |
| 604 } | 656 } |
| 605 if (constraintsIn.hasLatency()) { | 657 if (constraintsIn.hasLatency()) { |
| 606 copyDoubleConstraint(constraintsIn.latency(), constraintBuffer.latency); | 658 copyDoubleConstraint(constraintsIn.latency(), nakedTreatment, |
| 659 constraintBuffer.latency); |
| 607 } | 660 } |
| 608 if (constraintsIn.hasChannelCount()) { | 661 if (constraintsIn.hasChannelCount()) { |
| 609 copyLongConstraint(constraintsIn.channelCount(), | 662 copyLongConstraint(constraintsIn.channelCount(), nakedTreatment, |
| 610 constraintBuffer.channelCount); | 663 constraintBuffer.channelCount); |
| 611 } | 664 } |
| 612 if (constraintsIn.hasDeviceId()) { | 665 if (constraintsIn.hasDeviceId()) { |
| 613 copyStringConstraint(constraintsIn.deviceId(), constraintBuffer.deviceId); | 666 copyStringConstraint(constraintsIn.deviceId(), nakedTreatment, |
| 667 constraintBuffer.deviceId); |
| 614 } | 668 } |
| 615 if (constraintsIn.hasGroupId()) { | 669 if (constraintsIn.hasGroupId()) { |
| 616 copyStringConstraint(constraintsIn.groupId(), constraintBuffer.groupId); | 670 copyStringConstraint(constraintsIn.groupId(), nakedTreatment, |
| 671 constraintBuffer.groupId); |
| 617 } | 672 } |
| 618 } | 673 } |
| 619 | 674 |
| 620 WebMediaConstraints convertConstraintsToWeb( | 675 WebMediaConstraints convertConstraintsToWeb( |
| 621 const MediaTrackConstraints& constraintsIn) { | 676 const MediaTrackConstraints& constraintsIn) { |
| 622 WebMediaConstraints constraints; | 677 WebMediaConstraints constraints; |
| 623 WebMediaTrackConstraintSet constraintBuffer; | 678 WebMediaTrackConstraintSet constraintBuffer; |
| 624 Vector<WebMediaTrackConstraintSet> advancedBuffer; | 679 Vector<WebMediaTrackConstraintSet> advancedBuffer; |
| 625 copyConstraintSet(constraintsIn, constraintBuffer); | 680 copyConstraintSet(constraintsIn, NakedValueDisposition::kTreatAsIdeal, |
| 681 constraintBuffer); |
| 626 if (constraintsIn.hasAdvanced()) { | 682 if (constraintsIn.hasAdvanced()) { |
| 627 for (const auto& element : constraintsIn.advanced()) { | 683 for (const auto& element : constraintsIn.advanced()) { |
| 628 WebMediaTrackConstraintSet advancedElement; | 684 WebMediaTrackConstraintSet advancedElement; |
| 629 copyConstraintSet(element, advancedElement); | 685 copyConstraintSet(element, NakedValueDisposition::kTreatAsExact, |
| 686 advancedElement); |
| 630 advancedBuffer.append(advancedElement); | 687 advancedBuffer.append(advancedElement); |
| 631 } | 688 } |
| 632 } | 689 } |
| 633 constraints.initialize(constraintBuffer, advancedBuffer); | 690 constraints.initialize(constraintBuffer, advancedBuffer); |
| 634 return constraints; | 691 return constraints; |
| 635 } | 692 } |
| 636 | 693 |
| 637 WebMediaConstraints create(ExecutionContext* context, | 694 WebMediaConstraints create(ExecutionContext* context, |
| 638 const MediaTrackConstraints& constraintsIn, | 695 const MediaTrackConstraints& constraintsIn, |
| 639 MediaErrorState& errorState) { | 696 MediaErrorState& errorState) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 658 UseCounter::count(context, UseCounter::MediaStreamConstraintsConformant); | 715 UseCounter::count(context, UseCounter::MediaStreamConstraintsConformant); |
| 659 return standardForm; | 716 return standardForm; |
| 660 } | 717 } |
| 661 | 718 |
| 662 WebMediaConstraints create() { | 719 WebMediaConstraints create() { |
| 663 WebMediaConstraints constraints; | 720 WebMediaConstraints constraints; |
| 664 constraints.initialize(); | 721 constraints.initialize(); |
| 665 return constraints; | 722 return constraints; |
| 666 } | 723 } |
| 667 | 724 |
| 668 LongOrConstrainLongRange convertLong(const LongConstraint& input) { | 725 template <class T> |
| 726 bool useNakedNumeric(T input, NakedValueDisposition which) { |
| 727 switch (which) { |
| 728 case NakedValueDisposition::kTreatAsIdeal: |
| 729 return input.hasIdeal() && |
| 730 !(input.hasExact() || input.hasMin() || input.hasMax()); |
| 731 break; |
| 732 case NakedValueDisposition::kTreatAsExact: |
| 733 return input.hasExact() && |
| 734 !(input.hasIdeal() || input.hasMin() || input.hasMax()); |
| 735 break; |
| 736 } |
| 737 NOTREACHED(); |
| 738 return false; |
| 739 }; |
| 740 |
| 741 template <class T> |
| 742 bool useNakedNonNumeric(T input, NakedValueDisposition which) { |
| 743 switch (which) { |
| 744 case NakedValueDisposition::kTreatAsIdeal: |
| 745 return input.hasIdeal() && !input.hasExact(); |
| 746 break; |
| 747 case NakedValueDisposition::kTreatAsExact: |
| 748 return input.hasExact() && !input.hasIdeal(); |
| 749 break; |
| 750 } |
| 751 NOTREACHED(); |
| 752 return false; |
| 753 }; |
| 754 |
| 755 template <typename U, class T> |
| 756 U getNakedValue(T input, NakedValueDisposition which) { |
| 757 switch (which) { |
| 758 case NakedValueDisposition::kTreatAsIdeal: |
| 759 return input.ideal(); |
| 760 break; |
| 761 case NakedValueDisposition::kTreatAsExact: |
| 762 return input.exact(); |
| 763 break; |
| 764 } |
| 765 NOTREACHED(); |
| 766 return input.exact(); |
| 767 }; |
| 768 |
| 769 LongOrConstrainLongRange convertLong(const LongConstraint& input, |
| 770 NakedValueDisposition nakedTreatment) { |
| 669 LongOrConstrainLongRange outputUnion; | 771 LongOrConstrainLongRange outputUnion; |
| 670 if (input.hasExact() || input.hasMin() || input.hasMax()) { | 772 if (useNakedNumeric(input, nakedTreatment)) { |
| 773 outputUnion.setLong(getNakedValue<long>(input, nakedTreatment)); |
| 774 } else if (!input.isEmpty()) { |
| 671 ConstrainLongRange output; | 775 ConstrainLongRange output; |
| 672 if (input.hasExact()) | 776 if (input.hasExact()) |
| 673 output.setExact(input.exact()); | 777 output.setExact(input.exact()); |
| 674 if (input.hasMin()) | 778 if (input.hasMin()) |
| 675 output.setMin(input.min()); | 779 output.setMin(input.min()); |
| 676 if (input.hasMax()) | 780 if (input.hasMax()) |
| 677 output.setMax(input.max()); | 781 output.setMax(input.max()); |
| 678 if (input.hasIdeal()) | 782 if (input.hasIdeal()) |
| 679 output.setIdeal(input.ideal()); | 783 output.setIdeal(input.ideal()); |
| 680 outputUnion.setConstrainLongRange(output); | 784 outputUnion.setConstrainLongRange(output); |
| 681 } else { | |
| 682 if (input.hasIdeal()) { | |
| 683 outputUnion.setLong(input.ideal()); | |
| 684 } | |
| 685 } | 785 } |
| 686 return outputUnion; | 786 return outputUnion; |
| 687 } | 787 } |
| 688 | 788 |
| 689 DoubleOrConstrainDoubleRange convertDouble(const DoubleConstraint& input) { | 789 DoubleOrConstrainDoubleRange convertDouble( |
| 790 const DoubleConstraint& input, |
| 791 NakedValueDisposition nakedTreatment) { |
| 690 DoubleOrConstrainDoubleRange outputUnion; | 792 DoubleOrConstrainDoubleRange outputUnion; |
| 691 if (input.hasExact() || input.hasMin() || input.hasMax()) { | 793 if (useNakedNumeric(input, nakedTreatment)) { |
| 794 outputUnion.setDouble(getNakedValue<double>(input, nakedTreatment)); |
| 795 } else if (!input.isEmpty()) { |
| 692 ConstrainDoubleRange output; | 796 ConstrainDoubleRange output; |
| 693 if (input.hasExact()) | 797 if (input.hasExact()) |
| 694 output.setExact(input.exact()); | 798 output.setExact(input.exact()); |
| 695 if (input.hasIdeal()) | 799 if (input.hasIdeal()) |
| 696 output.setIdeal(input.ideal()); | 800 output.setIdeal(input.ideal()); |
| 697 if (input.hasMin()) | 801 if (input.hasMin()) |
| 698 output.setMin(input.min()); | 802 output.setMin(input.min()); |
| 699 if (input.hasMax()) | 803 if (input.hasMax()) |
| 700 output.setMax(input.max()); | 804 output.setMax(input.max()); |
| 701 outputUnion.setConstrainDoubleRange(output); | 805 outputUnion.setConstrainDoubleRange(output); |
| 702 } else { | |
| 703 if (input.hasIdeal()) { | |
| 704 outputUnion.setDouble(input.ideal()); | |
| 705 } | |
| 706 } | 806 } |
| 707 return outputUnion; | 807 return outputUnion; |
| 708 } | 808 } |
| 709 | 809 |
| 710 StringOrStringSequence convertStringSequence( | 810 StringOrStringSequence convertStringSequence( |
| 711 const WebVector<WebString>& input) { | 811 const WebVector<WebString>& input) { |
| 712 StringOrStringSequence theStrings; | 812 StringOrStringSequence theStrings; |
| 713 if (input.size() > 1) { | 813 if (input.size() > 1) { |
| 714 Vector<String> buffer; | 814 Vector<String> buffer; |
| 715 for (const auto& scanner : input) | 815 for (const auto& scanner : input) |
| 716 buffer.append(scanner); | 816 buffer.append(scanner); |
| 717 theStrings.setStringSequence(buffer); | 817 theStrings.setStringSequence(buffer); |
| 718 } else if (input.size() > 0) { | 818 } else if (input.size() > 0) { |
| 719 theStrings.setString(input[0]); | 819 theStrings.setString(input[0]); |
| 720 } | 820 } |
| 721 return theStrings; | 821 return theStrings; |
| 722 } | 822 } |
| 723 | 823 |
| 724 StringOrStringSequenceOrConstrainDOMStringParameters convertString( | 824 StringOrStringSequenceOrConstrainDOMStringParameters convertString( |
| 725 const StringConstraint& input) { | 825 const StringConstraint& input, |
| 826 NakedValueDisposition nakedTreatment) { |
| 726 StringOrStringSequenceOrConstrainDOMStringParameters outputUnion; | 827 StringOrStringSequenceOrConstrainDOMStringParameters outputUnion; |
| 727 if (input.hasExact()) { | 828 if (useNakedNonNumeric(input, nakedTreatment)) { |
| 728 ConstrainDOMStringParameters output; | 829 WebVector<WebString> inputBuffer( |
| 729 output.setExact(convertStringSequence(input.exact())); | 830 getNakedValue<WebVector<WebString>>(input, nakedTreatment)); |
| 730 if (input.hasIdeal()) { | 831 if (inputBuffer.size() > 1) { |
| 731 output.setIdeal(convertStringSequence(input.ideal())); | |
| 732 } | |
| 733 outputUnion.setConstrainDOMStringParameters(output); | |
| 734 } else if (input.hasIdeal()) { | |
| 735 if (input.ideal().size() > 1) { | |
| 736 Vector<String> buffer; | 832 Vector<String> buffer; |
| 737 for (const auto& scanner : input.ideal()) | 833 for (const auto& scanner : inputBuffer) |
| 738 buffer.append(scanner); | 834 buffer.append(scanner); |
| 739 outputUnion.setStringSequence(buffer); | 835 outputUnion.setStringSequence(buffer); |
| 740 } else if (input.ideal().size() == 1) { | 836 } else if (inputBuffer.size() > 0) { |
| 741 outputUnion.setString(input.ideal()[0]); | 837 outputUnion.setString(inputBuffer[0]); |
| 742 } | 838 } |
| 839 } else if (!input.isEmpty()) { |
| 840 ConstrainDOMStringParameters output; |
| 841 if (input.hasExact()) |
| 842 output.setExact(convertStringSequence(input.exact())); |
| 843 if (input.hasIdeal()) |
| 844 output.setIdeal(convertStringSequence(input.ideal())); |
| 845 outputUnion.setConstrainDOMStringParameters(output); |
| 743 } | 846 } |
| 744 return outputUnion; | 847 return outputUnion; |
| 745 } | 848 } |
| 746 | 849 |
| 747 BooleanOrConstrainBooleanParameters convertBoolean( | 850 BooleanOrConstrainBooleanParameters convertBoolean( |
| 748 const BooleanConstraint& input) { | 851 const BooleanConstraint& input, |
| 852 NakedValueDisposition nakedTreatment) { |
| 749 BooleanOrConstrainBooleanParameters outputUnion; | 853 BooleanOrConstrainBooleanParameters outputUnion; |
| 750 if (input.hasExact()) { | 854 if (useNakedNonNumeric(input, nakedTreatment)) { |
| 855 outputUnion.setBoolean(getNakedValue<bool>(input, nakedTreatment)); |
| 856 } else if (!input.isEmpty()) { |
| 751 ConstrainBooleanParameters output; | 857 ConstrainBooleanParameters output; |
| 752 if (input.hasExact()) | 858 if (input.hasExact()) |
| 753 output.setExact(input.exact()); | 859 output.setExact(input.exact()); |
| 754 if (input.hasIdeal()) | 860 if (input.hasIdeal()) |
| 755 output.setIdeal(input.ideal()); | 861 output.setIdeal(input.ideal()); |
| 756 outputUnion.setConstrainBooleanParameters(output); | 862 outputUnion.setConstrainBooleanParameters(output); |
| 757 } else if (input.hasIdeal()) { | |
| 758 outputUnion.setBoolean(input.ideal()); | |
| 759 } | 863 } |
| 760 return outputUnion; | 864 return outputUnion; |
| 761 } | 865 } |
| 762 | 866 |
| 763 void convertConstraintSet(const WebMediaTrackConstraintSet& input, | 867 void convertConstraintSet(const WebMediaTrackConstraintSet& input, |
| 868 NakedValueDisposition nakedTreatment, |
| 764 MediaTrackConstraintSet& output) { | 869 MediaTrackConstraintSet& output) { |
| 765 if (!input.width.isEmpty()) | 870 if (!input.width.isEmpty()) |
| 766 output.setWidth(convertLong(input.width)); | 871 output.setWidth(convertLong(input.width, nakedTreatment)); |
| 767 if (!input.height.isEmpty()) | 872 if (!input.height.isEmpty()) |
| 768 output.setHeight(convertLong(input.height)); | 873 output.setHeight(convertLong(input.height, nakedTreatment)); |
| 769 if (!input.aspectRatio.isEmpty()) | 874 if (!input.aspectRatio.isEmpty()) |
| 770 output.setAspectRatio(convertDouble(input.aspectRatio)); | 875 output.setAspectRatio(convertDouble(input.aspectRatio, nakedTreatment)); |
| 771 if (!input.frameRate.isEmpty()) | 876 if (!input.frameRate.isEmpty()) |
| 772 output.setFrameRate(convertDouble(input.frameRate)); | 877 output.setFrameRate(convertDouble(input.frameRate, nakedTreatment)); |
| 773 if (!input.facingMode.isEmpty()) | 878 if (!input.facingMode.isEmpty()) |
| 774 output.setFacingMode(convertString(input.facingMode)); | 879 output.setFacingMode(convertString(input.facingMode, nakedTreatment)); |
| 775 if (!input.volume.isEmpty()) | 880 if (!input.volume.isEmpty()) |
| 776 output.setVolume(convertDouble(input.volume)); | 881 output.setVolume(convertDouble(input.volume, nakedTreatment)); |
| 777 if (!input.sampleRate.isEmpty()) | 882 if (!input.sampleRate.isEmpty()) |
| 778 output.setSampleRate(convertLong(input.sampleRate)); | 883 output.setSampleRate(convertLong(input.sampleRate, nakedTreatment)); |
| 779 if (!input.sampleSize.isEmpty()) | 884 if (!input.sampleSize.isEmpty()) |
| 780 output.setSampleSize(convertLong(input.sampleSize)); | 885 output.setSampleSize(convertLong(input.sampleSize, nakedTreatment)); |
| 781 if (!input.echoCancellation.isEmpty()) | 886 if (!input.echoCancellation.isEmpty()) { |
| 782 output.setEchoCancellation(convertBoolean(input.echoCancellation)); | 887 output.setEchoCancellation( |
| 888 convertBoolean(input.echoCancellation, nakedTreatment)); |
| 889 } |
| 783 if (!input.latency.isEmpty()) | 890 if (!input.latency.isEmpty()) |
| 784 output.setLatency(convertDouble(input.latency)); | 891 output.setLatency(convertDouble(input.latency, nakedTreatment)); |
| 785 if (!input.channelCount.isEmpty()) | 892 if (!input.channelCount.isEmpty()) |
| 786 output.setChannelCount(convertLong(input.channelCount)); | 893 output.setChannelCount(convertLong(input.channelCount, nakedTreatment)); |
| 787 if (!input.deviceId.isEmpty()) | 894 if (!input.deviceId.isEmpty()) |
| 788 output.setDeviceId(convertString(input.deviceId)); | 895 output.setDeviceId(convertString(input.deviceId, nakedTreatment)); |
| 789 if (!input.groupId.isEmpty()) | 896 if (!input.groupId.isEmpty()) |
| 790 output.setGroupId(convertString(input.groupId)); | 897 output.setGroupId(convertString(input.groupId, nakedTreatment)); |
| 791 // TODO(hta): Decide the future of the nonstandard constraints. | 898 // TODO(hta): Decide the future of the nonstandard constraints. |
| 792 // If they go forward, they need to be added here. | 899 // If they go forward, they need to be added here. |
| 793 // https://crbug.com/605673 | 900 // https://crbug.com/605673 |
| 794 } | 901 } |
| 795 | 902 |
| 796 void convertConstraints(const WebMediaConstraints& input, | 903 void convertConstraints(const WebMediaConstraints& input, |
| 797 MediaTrackConstraints& output) { | 904 MediaTrackConstraints& output) { |
| 798 if (input.isNull()) | 905 if (input.isNull()) |
| 799 return; | 906 return; |
| 800 convertConstraintSet(input.basic(), output); | 907 convertConstraintSet(input.basic(), NakedValueDisposition::kTreatAsIdeal, |
| 908 output); |
| 801 HeapVector<MediaTrackConstraintSet> advancedVector; | 909 HeapVector<MediaTrackConstraintSet> advancedVector; |
| 802 for (const auto& it : input.advanced()) { | 910 for (const auto& it : input.advanced()) { |
| 803 MediaTrackConstraintSet element; | 911 MediaTrackConstraintSet element; |
| 804 convertConstraintSet(it, element); | 912 convertConstraintSet(it, NakedValueDisposition::kTreatAsExact, element); |
| 805 advancedVector.append(element); | 913 advancedVector.append(element); |
| 806 } | 914 } |
| 807 if (!advancedVector.isEmpty()) | 915 if (!advancedVector.isEmpty()) |
| 808 output.setAdvanced(advancedVector); | 916 output.setAdvanced(advancedVector); |
| 809 } | 917 } |
| 810 | 918 |
| 811 } // namespace MediaConstraintsImpl | 919 } // namespace MediaConstraintsImpl |
| 812 } // namespace blink | 920 } // namespace blink |
| OLD | NEW |