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

Side by Side Diff: content/renderer/media/media_stream_constraints_util_audio_unittest.cc

Issue 2940553005: Remove support for some device constraints from SelectSettings. (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « content/renderer/media/media_stream_constraints_util_audio.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_audio.h" 5 #include "content/renderer/media/media_stream_constraints_util_audio.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 ::mojom::AudioInputDeviceCapabilitiesPtr device = 61 ::mojom::AudioInputDeviceCapabilitiesPtr device =
62 ::mojom::AudioInputDeviceCapabilities::New(); 62 ::mojom::AudioInputDeviceCapabilities::New();
63 device->device_id = "default_device"; 63 device->device_id = "default_device";
64 device->parameters = media::AudioParameters( 64 device->parameters = media::AudioParameters(
65 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 65 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
66 media::CHANNEL_LAYOUT_STEREO, 66 media::CHANNEL_LAYOUT_STEREO,
67 media::AudioParameters::kAudioCDSampleRate, 16, 1000); 67 media::AudioParameters::kAudioCDSampleRate, 16, 1000);
68 capabilities_.push_back(std::move(device)); 68 capabilities_.push_back(std::move(device));
69 69
70 device = ::mojom::AudioInputDeviceCapabilities::New(); 70 device = ::mojom::AudioInputDeviceCapabilities::New();
71 device->device_id = "mono_phone_device";
72 device->parameters = media::AudioParameters(
73 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
74 media::CHANNEL_LAYOUT_MONO,
75 media::AudioParameters::kTelephoneSampleRate, 16, 1000);
76 capabilities_.push_back(std::move(device));
77
78 device = ::mojom::AudioInputDeviceCapabilities::New();
79 device->device_id = "hw_echo_canceller_device"; 71 device->device_id = "hw_echo_canceller_device";
80 device->parameters = media::AudioParameters( 72 device->parameters = media::AudioParameters(
81 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 73 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
82 media::CHANNEL_LAYOUT_STEREO, 74 media::CHANNEL_LAYOUT_STEREO,
83 media::AudioParameters::kAudioCDSampleRate, 24, 1000); 75 media::AudioParameters::kAudioCDSampleRate, 24, 1000);
84 device->parameters.set_effects(media::AudioParameters::ECHO_CANCELLER); 76 device->parameters.set_effects(media::AudioParameters::ECHO_CANCELLER);
85 capabilities_.push_back(std::move(device)); 77 capabilities_.push_back(std::move(device));
86 78
87 device = ::mojom::AudioInputDeviceCapabilities::New(); 79 device = ::mojom::AudioInputDeviceCapabilities::New();
88 device->device_id = "octagonal_device";
89 device->parameters = media::AudioParameters(
90 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
91 media::CHANNEL_LAYOUT_OCTAGONAL, 100000, 8, 1000);
92 capabilities_.push_back(std::move(device));
93
94 device = ::mojom::AudioInputDeviceCapabilities::New();
95 device->device_id = "geometry device"; 80 device->device_id = "geometry device";
96 device->parameters = media::AudioParameters( 81 device->parameters = media::AudioParameters(
97 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 82 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
98 media::CHANNEL_LAYOUT_STEREO, 83 media::CHANNEL_LAYOUT_STEREO,
99 media::AudioParameters::kAudioCDSampleRate, 16, 1000); 84 media::AudioParameters::kAudioCDSampleRate, 16, 1000);
100 device->parameters.set_mic_positions(kMicPositions); 85 device->parameters.set_mic_positions(kMicPositions);
101 capabilities_.push_back(std::move(device)); 86 capabilities_.push_back(std::move(device));
102 87
103 default_device_ = capabilities_[0].get(); 88 default_device_ = capabilities_[0].get();
104 mono_phone_device_ = capabilities_[1].get(); 89 hw_echo_canceller_device_ = capabilities_[1].get();
105 hw_echo_canceller_device_ = capabilities_[2].get(); 90 geometry_device_ = capabilities_[2].get();
106 octagonal_device_ = capabilities_[3].get();
107 geometry_device_ = capabilities_[4].get();
108 } 91 }
109 92
110 protected: 93 protected:
111 void SetMediaStreamSource(const std::string& source) {} 94 void SetMediaStreamSource(const std::string& source) {}
112 95
113 void ResetFactory() { 96 void ResetFactory() {
114 constraint_factory_.Reset(); 97 constraint_factory_.Reset();
115 constraint_factory_.basic().media_stream_source.SetExact( 98 constraint_factory_.basic().media_stream_source.SetExact(
116 blink::WebString::FromASCII(GetParam())); 99 blink::WebString::FromASCII(GetParam()));
117 } 100 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 const AudioPropertiesBoolMembers& exclude_audio_properties, 299 const AudioPropertiesBoolMembers& exclude_audio_properties,
317 const AudioCaptureSettings& result) { 300 const AudioCaptureSettings& result) {
318 CheckBoolDefaults(exclude_main_settings, exclude_audio_properties, result); 301 CheckBoolDefaults(exclude_main_settings, exclude_audio_properties, result);
319 CheckDeviceDefaults(result); 302 CheckDeviceDefaults(result);
320 CheckGeometryDefaults(result); 303 CheckGeometryDefaults(result);
321 } 304 }
322 305
323 MockConstraintFactory constraint_factory_; 306 MockConstraintFactory constraint_factory_;
324 AudioDeviceCaptureCapabilities capabilities_; 307 AudioDeviceCaptureCapabilities capabilities_;
325 const mojom::AudioInputDeviceCapabilities* default_device_ = nullptr; 308 const mojom::AudioInputDeviceCapabilities* default_device_ = nullptr;
326 const mojom::AudioInputDeviceCapabilities* mono_phone_device_ = nullptr;
327 const mojom::AudioInputDeviceCapabilities* hw_echo_canceller_device_ = 309 const mojom::AudioInputDeviceCapabilities* hw_echo_canceller_device_ =
328 nullptr; 310 nullptr;
329 const mojom::AudioInputDeviceCapabilities* octagonal_device_ = nullptr;
330 const mojom::AudioInputDeviceCapabilities* geometry_device_ = nullptr; 311 const mojom::AudioInputDeviceCapabilities* geometry_device_ = nullptr;
331 const std::vector<media::Point> kMicPositions = {{8, 8, 8}, {4, 4, 4}}; 312 const std::vector<media::Point> kMicPositions = {{8, 8, 8}, {4, 4, 4}};
332 }; 313 };
333 314
334 // The Unconstrained test checks the default selection criteria. 315 // The Unconstrained test checks the default selection criteria.
335 TEST_P(MediaStreamConstraintsUtilAudioTest, Unconstrained) { 316 TEST_P(MediaStreamConstraintsUtilAudioTest, Unconstrained) {
336 auto result = SelectSettings(); 317 auto result = SelectSettings();
337 318
338 // All settings should have default values. 319 // All settings should have default values.
339 EXPECT_TRUE(result.HasValue()); 320 EXPECT_TRUE(result.HasValue());
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 result.audio_processing_properties().enable_sw_echo_cancellation); 472 result.audio_processing_properties().enable_sw_echo_cancellation);
492 if (&*device == geometry_device_) { 473 if (&*device == geometry_device_) {
493 EXPECT_EQ(kMicPositions, 474 EXPECT_EQ(kMicPositions,
494 result.audio_processing_properties().goog_array_geometry); 475 result.audio_processing_properties().goog_array_geometry);
495 } else { 476 } else {
496 CheckGeometryDefaults(result); 477 CheckGeometryDefaults(result);
497 } 478 }
498 } 479 }
499 } 480 }
500 481
501 TEST_P(MediaStreamConstraintsUtilAudioTest, ExactValidSampleRate) {
502 constraint_factory_.basic().sample_rate.SetExact(
503 media::AudioParameters::kTelephoneSampleRate);
504 auto result = SelectSettings();
505 EXPECT_TRUE(result.HasValue());
506 if (IsDeviceCapture()) {
507 CheckDevice(*mono_phone_device_, result);
508 } else {
509 // Content capture ignores the sample_rate constraint.
510 EXPECT_TRUE(result.device_id().empty());
511 }
512 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
513 result);
514 CheckGeometryDefaults(result);
515 }
516
517 // SampleRate, SampleSize, ChannelCount tests check that numeric device-related
518 // constraints are handled correctly.
519 TEST_P(MediaStreamConstraintsUtilAudioTest, ExactInvalidSampleRate) {
520 constraint_factory_.basic().sample_rate.SetExact(666);
521 auto result = SelectSettings();
522 if (IsDeviceCapture()) {
523 EXPECT_FALSE(result.HasValue());
524 EXPECT_EQ(std::string(constraint_factory_.basic().sample_rate.GetName()),
525 std::string(result.failed_constraint_name()));
526 } else {
527 // Content capture ignores the sample_rate constraint.
528 EXPECT_TRUE(result.HasValue());
529 EXPECT_TRUE(result.device_id().empty());
530 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
531 result);
532 CheckGeometryDefaults(result);
533 }
534 }
535
536 TEST_P(MediaStreamConstraintsUtilAudioTest, MinValidSampleRate) {
537 constraint_factory_.basic().sample_rate.SetMin(80000);
538 auto result = SelectSettings();
539 EXPECT_TRUE(result.HasValue());
540 if (IsDeviceCapture()) {
541 // The octagonal device is the only one with a large-enough sample rate.
542 CheckDevice(*octagonal_device_, result);
543 } else {
544 // Content capture ignores the sample_rate constraint.
545 EXPECT_TRUE(result.device_id().empty());
546 }
547 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
548 result);
549 CheckGeometryDefaults(result);
550 }
551
552 TEST_P(MediaStreamConstraintsUtilAudioTest, MaxValidSampleRate) {
553 constraint_factory_.basic().sample_rate.SetMax(10000);
554 auto result = SelectSettings();
555 EXPECT_TRUE(result.HasValue());
556 if (IsDeviceCapture()) {
557 // The mono device is the only one with a small-enough sample rate.
558 CheckDevice(*mono_phone_device_, result);
559 } else {
560 // Content capture ignores the sample_rate constraint.
561 EXPECT_TRUE(result.device_id().empty());
562 }
563 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
564 result);
565 CheckGeometryDefaults(result);
566 }
567
568 TEST_P(MediaStreamConstraintsUtilAudioTest, RangeValidSampleRate) {
569 constraint_factory_.basic().sample_rate.SetMin(1000);
570 constraint_factory_.basic().sample_rate.SetMax(10000);
571 auto result = SelectSettings();
572 EXPECT_TRUE(result.HasValue());
573 if (IsDeviceCapture()) {
574 // The mono device is the only one with a sample rate in the range.
575 CheckDevice(*mono_phone_device_, result);
576 } else {
577 // Content capture ignores the sample_rate constraint.
578 EXPECT_TRUE(result.device_id().empty());
579 }
580 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
581 result);
582 CheckGeometryDefaults(result);
583 }
584
585 TEST_P(MediaStreamConstraintsUtilAudioTest, InvalidRangeSampleRate) {
586 constraint_factory_.basic().sample_rate.SetMin(9000);
587 constraint_factory_.basic().sample_rate.SetMax(10000);
588 auto result = SelectSettings();
589 if (IsDeviceCapture()) {
590 EXPECT_FALSE(result.HasValue());
591 EXPECT_EQ(std::string(constraint_factory_.basic().sample_rate.GetName()),
592 std::string(result.failed_constraint_name()));
593 } else {
594 // Content capture ignores the sample_rate constraint.
595 EXPECT_TRUE(result.HasValue());
596 EXPECT_TRUE(result.device_id().empty());
597 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
598 result);
599 CheckGeometryDefaults(result);
600 }
601 }
602
603 TEST_P(MediaStreamConstraintsUtilAudioTest, IdealSampleRate) {
604 constraint_factory_.basic().sample_rate.SetIdeal(10000);
605 auto result = SelectSettings();
606 EXPECT_TRUE(result.HasValue());
607 if (IsDeviceCapture()) {
608 // The mono device is the one a sample rate closest to ideal.
609 CheckDevice(*mono_phone_device_, result);
610 } else {
611 // Content capture ignores the sample_rate constraint.
612 EXPECT_TRUE(result.device_id().empty());
613 }
614 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
615 result);
616 CheckGeometryDefaults(result);
617 }
618
619 // Sample size tests.
620 TEST_P(MediaStreamConstraintsUtilAudioTest, ExactValidSampleSize) {
621 constraint_factory_.basic().sample_size.SetExact(8);
622 auto result = SelectSettings();
623 EXPECT_TRUE(result.HasValue());
624 if (IsDeviceCapture()) {
625 CheckDevice(*octagonal_device_, result);
626 } else {
627 // Content capture ignores the sample_size constraint.
628 EXPECT_TRUE(result.device_id().empty());
629 }
630 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
631 result);
632 CheckGeometryDefaults(result);
633 }
634
635 TEST_P(MediaStreamConstraintsUtilAudioTest, ExactInvalidSampleSize) {
636 constraint_factory_.basic().sample_size.SetExact(666);
637 auto result = SelectSettings();
638 if (IsDeviceCapture()) {
639 EXPECT_FALSE(result.HasValue());
640 EXPECT_EQ(std::string(constraint_factory_.basic().sample_size.GetName()),
641 std::string(result.failed_constraint_name()));
642 } else {
643 // Content capture ignores the sample_size constraint.
644 EXPECT_TRUE(result.HasValue());
645 EXPECT_TRUE(result.device_id().empty());
646 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
647 result);
648 CheckGeometryDefaults(result);
649 }
650 }
651
652 TEST_P(MediaStreamConstraintsUtilAudioTest, MinValidSampleSize) {
653 constraint_factory_.basic().sample_size.SetMin(20);
654 auto result = SelectSettings();
655 EXPECT_TRUE(result.HasValue());
656 if (IsDeviceCapture()) {
657 // The device with echo canceller is the only one with a sample size that
658 // is greater than the requested minimum.
659 CheckDevice(*hw_echo_canceller_device_, result);
660 CheckBoolDefaults(AudioSettingsBoolMembers(),
661 {&AudioProcessingProperties::enable_sw_echo_cancellation},
662 result);
663 } else {
664 // Content capture ignores the sample_size constraint.
665 EXPECT_TRUE(result.device_id().empty());
666 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
667 result);
668 }
669 CheckGeometryDefaults(result);
670 }
671
672 TEST_P(MediaStreamConstraintsUtilAudioTest, MaxValidSampleSize) {
673 constraint_factory_.basic().sample_size.SetMax(10);
674 auto result = SelectSettings();
675 EXPECT_TRUE(result.HasValue());
676 if (IsDeviceCapture()) {
677 // The octagonal device is the only one with a small-enough sample size.
678 CheckDevice(*octagonal_device_, result);
679 } else {
680 // Content capture ignores the sample_size constraint.
681 EXPECT_TRUE(result.device_id().empty());
682 }
683 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
684 result);
685 CheckGeometryDefaults(result);
686 }
687
688 TEST_P(MediaStreamConstraintsUtilAudioTest, RangeValidSampleSize) {
689 constraint_factory_.basic().sample_size.SetMin(3);
690 constraint_factory_.basic().sample_size.SetMax(15);
691 auto result = SelectSettings();
692 EXPECT_TRUE(result.HasValue());
693 if (IsDeviceCapture()) {
694 // The octagonal device is the only one with a sample size in the range.
695 CheckDevice(*octagonal_device_, result);
696 } else {
697 // Content capture ignores the sample_size constraint.
698 EXPECT_TRUE(result.device_id().empty());
699 }
700 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
701 result);
702 CheckGeometryDefaults(result);
703 }
704
705 TEST_P(MediaStreamConstraintsUtilAudioTest, InvalidRangeSampleSize) {
706 constraint_factory_.basic().sample_size.SetMin(10);
707 constraint_factory_.basic().sample_size.SetMax(15);
708 auto result = SelectSettings();
709 if (IsDeviceCapture()) {
710 EXPECT_FALSE(result.HasValue());
711 EXPECT_EQ(std::string(constraint_factory_.basic().sample_size.GetName()),
712 std::string(result.failed_constraint_name()));
713 } else {
714 // Content capture ignores the sample_size constraint.
715 EXPECT_TRUE(result.HasValue());
716 EXPECT_TRUE(result.device_id().empty());
717 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
718 result);
719 CheckGeometryDefaults(result);
720 }
721 }
722
723 TEST_P(MediaStreamConstraintsUtilAudioTest, IdealSampleSize) {
724 constraint_factory_.basic().sample_size.SetIdeal(10);
725 auto result = SelectSettings();
726 EXPECT_TRUE(result.HasValue());
727 if (IsDeviceCapture()) {
728 // The octagonal device is the one a sample size closest to ideal.
729 CheckDevice(*octagonal_device_, result);
730 } else {
731 // Content capture ignores the sample_size constraint.
732 EXPECT_TRUE(result.device_id().empty());
733 }
734 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
735 result);
736 CheckGeometryDefaults(result);
737 }
738
739 // ChannelCount tests.
740 TEST_P(MediaStreamConstraintsUtilAudioTest, ExactValidChannelCount) {
741 constraint_factory_.basic().channel_count.SetExact(8);
742 auto result = SelectSettings();
743 EXPECT_TRUE(result.HasValue());
744 if (IsDeviceCapture()) {
745 CheckDevice(*octagonal_device_, result);
746 } else {
747 // Content capture ignores the channel_count constraint.
748 EXPECT_TRUE(result.device_id().empty());
749 }
750 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
751 result);
752 CheckGeometryDefaults(result);
753 }
754
755 TEST_P(MediaStreamConstraintsUtilAudioTest, ExactInvalidChannelCount) {
756 constraint_factory_.basic().channel_count.SetExact(666);
757 auto result = SelectSettings();
758 if (IsDeviceCapture()) {
759 EXPECT_FALSE(result.HasValue());
760 EXPECT_EQ(std::string(constraint_factory_.basic().channel_count.GetName()),
761 std::string(result.failed_constraint_name()));
762 } else {
763 // Content capture ignores the channel_count constraint.
764 EXPECT_TRUE(result.HasValue());
765 EXPECT_TRUE(result.device_id().empty());
766 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
767 result);
768 CheckGeometryDefaults(result);
769 }
770 }
771
772 TEST_P(MediaStreamConstraintsUtilAudioTest, MinValidChannelCount) {
773 constraint_factory_.basic().channel_count.SetMin(7);
774 auto result = SelectSettings();
775 EXPECT_TRUE(result.HasValue());
776 if (IsDeviceCapture()) {
777 // The device with echo canceller is the only one with a channel count that
778 // is greater than the requested minimum.
779 CheckDevice(*octagonal_device_, result);
780 } else {
781 // Content capture ignores the channel_count constraint.
782 EXPECT_TRUE(result.device_id().empty());
783 }
784 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
785 result);
786 CheckGeometryDefaults(result);
787 }
788
789 TEST_P(MediaStreamConstraintsUtilAudioTest, MaxValidChannelCount) {
790 constraint_factory_.basic().channel_count.SetMax(1);
791 auto result = SelectSettings();
792 EXPECT_TRUE(result.HasValue());
793 if (IsDeviceCapture()) {
794 // The octagonal device is the only one with a small-enough channel count.
795 CheckDevice(*mono_phone_device_, result);
796 } else {
797 // Content capture ignores the channel_count constraint.
798 EXPECT_TRUE(result.device_id().empty());
799 }
800 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
801 result);
802 CheckGeometryDefaults(result);
803 }
804
805 TEST_P(MediaStreamConstraintsUtilAudioTest, RangeValidChannelCount) {
806 constraint_factory_.basic().channel_count.SetMin(3);
807 constraint_factory_.basic().channel_count.SetMax(15);
808 auto result = SelectSettings();
809 EXPECT_TRUE(result.HasValue());
810 if (IsDeviceCapture()) {
811 // The octagonal device is the only one with a channel count in the range.
812 CheckDevice(*octagonal_device_, result);
813 } else {
814 // Content capture ignores the channel_count constraint.
815 EXPECT_TRUE(result.device_id().empty());
816 }
817 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
818 result);
819 CheckGeometryDefaults(result);
820 }
821
822 TEST_P(MediaStreamConstraintsUtilAudioTest, InvalidRangeChannelCount) {
823 constraint_factory_.basic().channel_count.SetMin(3);
824 constraint_factory_.basic().channel_count.SetMax(7);
825 auto result = SelectSettings();
826 if (IsDeviceCapture()) {
827 EXPECT_FALSE(result.HasValue());
828 EXPECT_EQ(std::string(constraint_factory_.basic().channel_count.GetName()),
829 std::string(result.failed_constraint_name()));
830 } else {
831 // Content capture ignores the channel_count constraint.
832 EXPECT_TRUE(result.HasValue());
833 EXPECT_TRUE(result.device_id().empty());
834 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
835 result);
836 CheckGeometryDefaults(result);
837 }
838 }
839
840 TEST_P(MediaStreamConstraintsUtilAudioTest, IdealChannelCount) {
841 constraint_factory_.basic().channel_count.SetIdeal(6);
842 auto result = SelectSettings();
843 EXPECT_TRUE(result.HasValue());
844 if (IsDeviceCapture()) {
845 // The octagonal device is the one the number of channels closest to ideal.
846 CheckDevice(*octagonal_device_, result);
847 } else {
848 // Content capture ignores the channel_count constraint.
849 EXPECT_TRUE(result.device_id().empty());
850 }
851 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
852 result);
853 CheckGeometryDefaults(result);
854 }
855
856 // Tests the echoCancellation constraint with a device without hardware echo 482 // Tests the echoCancellation constraint with a device without hardware echo
857 // cancellation. 483 // cancellation.
858 TEST_P(MediaStreamConstraintsUtilAudioTest, EchoCancellationWithSw) { 484 TEST_P(MediaStreamConstraintsUtilAudioTest, EchoCancellationWithSw) {
859 for (auto set_function : kBoolSetFunctions) { 485 for (auto set_function : kBoolSetFunctions) {
860 for (auto accessor : kFactoryAccessors) { 486 for (auto accessor : kFactoryAccessors) {
861 // Ideal advanced is ignored by the SelectSettings algorithm. 487 // Ideal advanced is ignored by the SelectSettings algorithm.
862 if (set_function == &blink::BooleanConstraint::SetIdeal && 488 if (set_function == &blink::BooleanConstraint::SetIdeal &&
863 accessor == &MockConstraintFactory::AddAdvanced) { 489 accessor == &MockConstraintFactory::AddAdvanced) {
864 continue; 490 continue;
865 } 491 }
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 EXPECT_FALSE(result.audio_processing_properties().* 745 EXPECT_FALSE(result.audio_processing_properties().*
1120 kAudioProcessingProperties[j]); 746 kAudioProcessingProperties[j]);
1121 } 747 }
1122 } 748 }
1123 } 749 }
1124 } 750 }
1125 } 751 }
1126 752
1127 // Test advanced constraints sets that can be satisfied. 753 // Test advanced constraints sets that can be satisfied.
1128 TEST_P(MediaStreamConstraintsUtilAudioTest, AdvancedCompatibleConstraints) { 754 TEST_P(MediaStreamConstraintsUtilAudioTest, AdvancedCompatibleConstraints) {
1129 constraint_factory_.AddAdvanced().sample_size.SetExact(8);
1130 constraint_factory_.AddAdvanced().render_to_associated_sink.SetExact(true); 755 constraint_factory_.AddAdvanced().render_to_associated_sink.SetExact(true);
1131 constraint_factory_.AddAdvanced().goog_audio_mirroring.SetExact(true); 756 constraint_factory_.AddAdvanced().goog_audio_mirroring.SetExact(true);
1132 auto result = SelectSettings(); 757 auto result = SelectSettings();
1133 EXPECT_TRUE(result.HasValue()); 758 EXPECT_TRUE(result.HasValue());
1134 if (IsDeviceCapture()) { 759 CheckDeviceDefaults(result);
1135 // The octagonal device is the only one that matches the first advanced
1136 // constraint set.
1137 CheckDevice(*octagonal_device_, result);
1138 } else {
1139 // Content capture ignores device-related constraints.
1140 EXPECT_TRUE(result.device_id().empty());
1141 }
1142 CheckBoolDefaults({&AudioCaptureSettings::render_to_associated_sink}, 760 CheckBoolDefaults({&AudioCaptureSettings::render_to_associated_sink},
1143 {&AudioProcessingProperties::goog_audio_mirroring}, result); 761 {&AudioProcessingProperties::goog_audio_mirroring}, result);
1144 CheckGeometryDefaults(result); 762 CheckGeometryDefaults(result);
1145 EXPECT_TRUE(result.render_to_associated_sink()); 763 EXPECT_TRUE(result.render_to_associated_sink());
1146 EXPECT_TRUE(result.audio_processing_properties().goog_audio_mirroring); 764 EXPECT_TRUE(result.audio_processing_properties().goog_audio_mirroring);
1147 } 765 }
1148 766
1149 // Test that an advanced constraint set that cannot be satisfied is ignored.
1150 TEST_P(MediaStreamConstraintsUtilAudioTest, AdvancedSelfConflictingConstraint) {
hbos_chromium 2017/06/16 15:58:39 Conflicting constraints is still useful to test. C
Guido Urdaneta 2017/06/16 16:09:19 There are conflicting tests with other constraints
1151 auto& advanced = constraint_factory_.AddAdvanced();
1152 advanced.sample_size.SetExact(8);
1153 advanced.sample_rate.SetExact(8);
1154 auto result = SelectSettings();
1155 EXPECT_TRUE(result.HasValue());
1156 // The advanced constraint is self conflicting and ignored. The default
1157 // device is selected.
1158 CheckDeviceDefaults(result);
1159 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
1160 result);
1161 CheckGeometryDefaults(result);
1162 }
1163
1164 // Test that an advanced constraint set that contradicts a previous constraint
1165 // set with a device-related constraint is ignored.
1166 TEST_P(MediaStreamConstraintsUtilAudioTest,
1167 AdvancedConflictingDeviceConstraint) {
hbos_chromium 2017/06/16 15:58:39 Ditto.
1168 constraint_factory_.AddAdvanced().sample_size.SetExact(8);
1169 constraint_factory_.AddAdvanced().sample_size.SetExact(
1170 media::AudioParameters::kAudioCDSampleRate);
1171 auto result = SelectSettings();
1172 EXPECT_TRUE(result.HasValue());
1173 if (IsDeviceCapture()) {
1174 // The octagonal device is the only one that matches the first advanced
1175 // constraint set. The second set is ignored.
1176 CheckDevice(*octagonal_device_, result);
1177 EXPECT_NE(media::AudioParameters::kAudioCDSampleRate,
1178 result.device_parameters().sample_rate());
1179 } else {
1180 // Content capture ignores device-related constraints.
1181 EXPECT_TRUE(result.device_id().empty());
1182 }
1183 CheckBoolDefaults(AudioSettingsBoolMembers(), AudioPropertiesBoolMembers(),
1184 result);
1185 CheckGeometryDefaults(result);
1186 }
1187
1188 // Test that an advanced constraint set that contradicts a previous constraint 767 // Test that an advanced constraint set that contradicts a previous constraint
1189 // set is ignored, but that further constraint sets that can be satisfied are 768 // set is ignored, but that further constraint sets that can be satisfied are
1190 // applied. 769 // applied.
1191 TEST_P(MediaStreamConstraintsUtilAudioTest, 770 TEST_P(MediaStreamConstraintsUtilAudioTest,
1192 AdvancedConflictingMiddleConstraints) { 771 AdvancedConflictingMiddleConstraints) {
1193 constraint_factory_.AddAdvanced().sample_size.SetExact(8); 772 constraint_factory_.AddAdvanced().goog_highpass_filter.SetExact(true);
1194 auto& advanced2 = constraint_factory_.AddAdvanced(); 773 auto& advanced2 = constraint_factory_.AddAdvanced();
1195 advanced2.sample_rate.SetExact(123456); 774 advanced2.goog_highpass_filter.SetExact(false);
1196 advanced2.hotword_enabled.SetExact(true); 775 advanced2.hotword_enabled.SetExact(true);
1197 constraint_factory_.AddAdvanced().goog_audio_mirroring.SetExact(true); 776 constraint_factory_.AddAdvanced().goog_audio_mirroring.SetExact(true);
1198 auto result = SelectSettings(); 777 auto result = SelectSettings();
1199 EXPECT_TRUE(result.HasValue()); 778 EXPECT_TRUE(result.HasValue());
1200 if (IsDeviceCapture()) { 779 CheckDeviceDefaults(result);
1201 // The octagonal device is the only one that matches the first advanced 780 EXPECT_FALSE(result.hotword_enabled());
1202 // constraint set. 781 CheckBoolDefaults({&AudioCaptureSettings::hotword_enabled},
1203 CheckDevice(*octagonal_device_, result); 782 {&AudioProcessingProperties::goog_audio_mirroring,
1204 // Second advanced set is discarded because no device has the requested 783 &AudioProcessingProperties::goog_highpass_filter},
1205 // sample rate. 784 result);
1206 EXPECT_NE(123456, result.device_parameters().sample_rate());
1207 EXPECT_FALSE(result.hotword_enabled());
1208 } else {
1209 // Content capture ignores device-related constraints. Thus, it does not
1210 // discard the second advanced set.
1211 EXPECT_TRUE(result.device_id().empty());
1212 EXPECT_TRUE(result.hotword_enabled());
1213 }
1214 CheckBoolDefaults({&AudioCaptureSettings::render_to_associated_sink,
1215 &AudioCaptureSettings::hotword_enabled},
1216 {&AudioProcessingProperties::goog_audio_mirroring}, result);
1217 CheckGeometryDefaults(result); 785 CheckGeometryDefaults(result);
786 EXPECT_FALSE(result.hotword_enabled());
1218 EXPECT_TRUE(result.audio_processing_properties().goog_audio_mirroring); 787 EXPECT_TRUE(result.audio_processing_properties().goog_audio_mirroring);
788 EXPECT_TRUE(result.audio_processing_properties().goog_highpass_filter);
1219 } 789 }
1220 790
1221 // Test that an advanced constraint set that contradicts a previous constraint 791 // Test that an advanced constraint set that contradicts a previous constraint
1222 // set with a boolean constraint is ignored. 792 // set with a boolean constraint is ignored.
1223 TEST_P(MediaStreamConstraintsUtilAudioTest, AdvancedConflictingLastConstraint) { 793 TEST_P(MediaStreamConstraintsUtilAudioTest, AdvancedConflictingLastConstraint) {
1224 constraint_factory_.AddAdvanced().sample_size.SetExact(8); 794 constraint_factory_.AddAdvanced().goog_highpass_filter.SetExact(true);
1225 constraint_factory_.AddAdvanced().hotword_enabled.SetExact(true); 795 constraint_factory_.AddAdvanced().hotword_enabled.SetExact(true);
1226 constraint_factory_.AddAdvanced().goog_audio_mirroring.SetExact(true); 796 constraint_factory_.AddAdvanced().goog_audio_mirroring.SetExact(true);
1227 constraint_factory_.AddAdvanced().hotword_enabled.SetExact(false); 797 constraint_factory_.AddAdvanced().hotword_enabled.SetExact(false);
1228 auto result = SelectSettings(); 798 auto result = SelectSettings();
1229 EXPECT_TRUE(result.HasValue()); 799 EXPECT_TRUE(result.HasValue());
1230 if (IsDeviceCapture()) { 800 CheckDeviceDefaults(result);
1231 // The octagonal device is the only one that matches the first advanced
1232 // constraint set.
1233 CheckDevice(*octagonal_device_, result);
1234 } else {
1235 // Content capture ignores device-related constraints.
1236 EXPECT_TRUE(result.device_id().empty());
1237 }
1238 CheckBoolDefaults({&AudioCaptureSettings::hotword_enabled}, 801 CheckBoolDefaults({&AudioCaptureSettings::hotword_enabled},
1239 {&AudioProcessingProperties::goog_audio_mirroring}, result); 802 {&AudioProcessingProperties::goog_audio_mirroring,
803 &AudioProcessingProperties::goog_highpass_filter},
804 result);
1240 CheckGeometryDefaults(result); 805 CheckGeometryDefaults(result);
1241 // The fourth advanced set is ignored because it contradicts the second set. 806 // The fourth advanced set is ignored because it contradicts the second set.
1242 EXPECT_TRUE(result.hotword_enabled()); 807 EXPECT_TRUE(result.hotword_enabled());
1243 EXPECT_TRUE(result.audio_processing_properties().goog_audio_mirroring); 808 EXPECT_TRUE(result.audio_processing_properties().goog_audio_mirroring);
809 EXPECT_TRUE(result.audio_processing_properties().goog_highpass_filter);
1244 } 810 }
1245 811
1246 // Test that a valid geometry is interpreted correctly in all the ways it can 812 // Test that a valid geometry is interpreted correctly in all the ways it can
1247 // be set. 813 // be set.
1248 TEST_P(MediaStreamConstraintsUtilAudioTest, ValidGeometry) { 814 TEST_P(MediaStreamConstraintsUtilAudioTest, ValidGeometry) {
1249 const blink::WebString kGeometry = 815 const blink::WebString kGeometry =
1250 blink::WebString::FromASCII("-0.02 0 0 0.02 0 1.01"); 816 blink::WebString::FromASCII("-0.02 0 0 0.02 0 1.01");
1251 817
1252 for (auto set_function : kStringSetFunctions) { 818 for (auto set_function : kStringSetFunctions) {
1253 for (auto accessor : kFactoryAccessors) { 819 for (auto accessor : kFactoryAccessors) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 } 953 }
1388 954
1389 INSTANTIATE_TEST_CASE_P(, 955 INSTANTIATE_TEST_CASE_P(,
1390 MediaStreamConstraintsUtilAudioTest, 956 MediaStreamConstraintsUtilAudioTest,
1391 testing::Values("", 957 testing::Values("",
1392 kMediaStreamSourceTab, 958 kMediaStreamSourceTab,
1393 kMediaStreamSourceSystem, 959 kMediaStreamSourceSystem,
1394 kMediaStreamSourceDesktop)); 960 kMediaStreamSourceDesktop));
1395 961
1396 } // namespace content 962 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_constraints_util_audio.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698