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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 int capture_height, | 115 int capture_height, |
116 const blink::WebMediaConstraints& constraints, | 116 const blink::WebMediaConstraints& constraints, |
117 int expected_width, | 117 int expected_width, |
118 int expected_height) { | 118 int expected_height) { |
119 // Expect the source to start capture with the supported resolution. | 119 // Expect the source to start capture with the supported resolution. |
120 blink::WebMediaStreamTrack track = | 120 blink::WebMediaStreamTrack track = |
121 CreateTrackAndStartSource(constraints, capture_width, capture_height, | 121 CreateTrackAndStartSource(constraints, capture_width, capture_height, |
122 30); | 122 30); |
123 | 123 |
124 MockMediaStreamVideoSink sink; | 124 MockMediaStreamVideoSink sink; |
125 MediaStreamVideoSink::AddToVideoTrack( | 125 sink.ConnectToTrack(track); |
126 &sink, sink.GetDeliverFrameCB(), track); | |
127 DeliverVideoFrameAndWaitForRenderer(capture_width, capture_height, &sink); | 126 DeliverVideoFrameAndWaitForRenderer(capture_width, capture_height, &sink); |
128 EXPECT_EQ(1, sink.number_of_frames()); | 127 EXPECT_EQ(1, sink.number_of_frames()); |
129 | 128 |
130 // Expect the delivered frame to be cropped. | 129 // Expect the delivered frame to be cropped. |
131 EXPECT_EQ(expected_height, sink.frame_size().height()); | 130 EXPECT_EQ(expected_height, sink.frame_size().height()); |
132 EXPECT_EQ(expected_width, sink.frame_size().width()); | 131 EXPECT_EQ(expected_width, sink.frame_size().width()); |
133 MediaStreamVideoSink::RemoveFromVideoTrack(&sink, track); | 132 sink.DisconnectFromTrack(); |
134 } | 133 } |
135 | 134 |
136 void DeliverVideoFrameAndWaitForRenderer(int width, int height, | 135 void DeliverVideoFrameAndWaitForRenderer(int width, int height, |
137 MockMediaStreamVideoSink* sink) { | 136 MockMediaStreamVideoSink* sink) { |
138 base::RunLoop run_loop; | 137 base::RunLoop run_loop; |
139 base::Closure quit_closure = run_loop.QuitClosure(); | 138 base::Closure quit_closure = run_loop.QuitClosure(); |
140 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce( | 139 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce( |
141 RunClosure(quit_closure)); | 140 RunClosure(quit_closure)); |
142 scoped_refptr<media::VideoFrame> frame = | 141 scoped_refptr<media::VideoFrame> frame = |
143 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); | 142 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); |
(...skipping 26 matching lines...) Expand all Loading... |
170 int expected_height1, | 169 int expected_height1, |
171 int expected_width2, | 170 int expected_width2, |
172 int expected_height2) { | 171 int expected_height2) { |
173 blink::WebMediaStreamTrack track1 = | 172 blink::WebMediaStreamTrack track1 = |
174 CreateTrackAndStartSource(constraints1, capture_width, capture_height, | 173 CreateTrackAndStartSource(constraints1, capture_width, capture_height, |
175 MediaStreamVideoSource::kDefaultFrameRate); | 174 MediaStreamVideoSource::kDefaultFrameRate); |
176 | 175 |
177 blink::WebMediaStreamTrack track2 = CreateTrack("dummy", constraints2); | 176 blink::WebMediaStreamTrack track2 = CreateTrack("dummy", constraints2); |
178 | 177 |
179 MockMediaStreamVideoSink sink1; | 178 MockMediaStreamVideoSink sink1; |
180 MediaStreamVideoSink::AddToVideoTrack(&sink1, sink1.GetDeliverFrameCB(), | 179 sink1.ConnectToTrack(track1); |
181 track1); | |
182 EXPECT_EQ(0, sink1.number_of_frames()); | 180 EXPECT_EQ(0, sink1.number_of_frames()); |
183 | 181 |
184 MockMediaStreamVideoSink sink2; | 182 MockMediaStreamVideoSink sink2; |
185 MediaStreamVideoSink::AddToVideoTrack(&sink2, sink2.GetDeliverFrameCB(), | 183 sink2.ConnectToTrack(track2); |
186 track2); | |
187 EXPECT_EQ(0, sink2.number_of_frames()); | 184 EXPECT_EQ(0, sink2.number_of_frames()); |
188 | 185 |
189 DeliverVideoFrameAndWaitForTwoRenderers(capture_width, | 186 DeliverVideoFrameAndWaitForTwoRenderers(capture_width, |
190 capture_height, | 187 capture_height, |
191 &sink1, | 188 &sink1, |
192 &sink2); | 189 &sink2); |
193 | 190 |
194 EXPECT_EQ(1, sink1.number_of_frames()); | 191 EXPECT_EQ(1, sink1.number_of_frames()); |
195 EXPECT_EQ(expected_width1, sink1.frame_size().width()); | 192 EXPECT_EQ(expected_width1, sink1.frame_size().width()); |
196 EXPECT_EQ(expected_height1, sink1.frame_size().height()); | 193 EXPECT_EQ(expected_height1, sink1.frame_size().height()); |
197 | 194 |
198 EXPECT_EQ(1, sink2.number_of_frames()); | 195 EXPECT_EQ(1, sink2.number_of_frames()); |
199 EXPECT_EQ(expected_width2, sink2.frame_size().width()); | 196 EXPECT_EQ(expected_width2, sink2.frame_size().width()); |
200 EXPECT_EQ(expected_height2, sink2.frame_size().height()); | 197 EXPECT_EQ(expected_height2, sink2.frame_size().height()); |
201 | 198 |
202 MediaStreamVideoSink::RemoveFromVideoTrack(&sink1, track1); | 199 sink1.DisconnectFromTrack(); |
203 MediaStreamVideoSink::RemoveFromVideoTrack(&sink2, track2); | 200 sink2.DisconnectFromTrack(); |
204 } | 201 } |
205 | 202 |
206 void SetSourceSupportedFormats(const media::VideoCaptureFormats& formats) { | 203 void SetSourceSupportedFormats(const media::VideoCaptureFormats& formats) { |
207 mock_source_->SetSupportedFormats(formats); | 204 mock_source_->SetSupportedFormats(formats); |
208 } | 205 } |
209 | 206 |
210 void ReleaseTrackAndSourceOnAddTrackCallback( | 207 void ReleaseTrackAndSourceOnAddTrackCallback( |
211 const blink::WebMediaStreamTrack& track_to_release) { | 208 const blink::WebMediaStreamTrack& track_to_release) { |
212 track_to_release_ = track_to_release; | 209 track_to_release_ = track_to_release; |
213 } | 210 } |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 MockConstraintFactory factory; | 648 MockConstraintFactory factory; |
652 factory.AddAdvanced().width.setMax(800); | 649 factory.AddAdvanced().width.setMax(800); |
653 factory.AddAdvanced().height.setMax(700); | 650 factory.AddAdvanced().height.setMax(700); |
654 | 651 |
655 // Expect the source to start capture with the supported resolution. | 652 // Expect the source to start capture with the supported resolution. |
656 blink::WebMediaStreamTrack track = | 653 blink::WebMediaStreamTrack track = |
657 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), | 654 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), |
658 640, 480, 30); | 655 640, 480, 30); |
659 | 656 |
660 MockMediaStreamVideoSink sink; | 657 MockMediaStreamVideoSink sink; |
661 MediaStreamVideoSink::AddToVideoTrack( | 658 sink.ConnectToTrack(track); |
662 &sink, sink.GetDeliverFrameCB(), track); | |
663 EXPECT_EQ(0, sink.number_of_frames()); | 659 EXPECT_EQ(0, sink.number_of_frames()); |
664 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink); | 660 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink); |
665 EXPECT_EQ(1, sink.number_of_frames()); | 661 EXPECT_EQ(1, sink.number_of_frames()); |
666 // Expect the delivered frame to be passed unchanged since its smaller than | 662 // Expect the delivered frame to be passed unchanged since its smaller than |
667 // max requested. | 663 // max requested. |
668 EXPECT_EQ(320, sink.frame_size().width()); | 664 EXPECT_EQ(320, sink.frame_size().width()); |
669 EXPECT_EQ(240, sink.frame_size().height()); | 665 EXPECT_EQ(240, sink.frame_size().height()); |
670 | 666 |
671 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); | 667 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); |
672 EXPECT_EQ(2, sink.number_of_frames()); | 668 EXPECT_EQ(2, sink.number_of_frames()); |
673 // Expect the delivered frame to be passed unchanged since its smaller than | 669 // Expect the delivered frame to be passed unchanged since its smaller than |
674 // max requested. | 670 // max requested. |
675 EXPECT_EQ(640, sink.frame_size().width()); | 671 EXPECT_EQ(640, sink.frame_size().width()); |
676 EXPECT_EQ(480, sink.frame_size().height()); | 672 EXPECT_EQ(480, sink.frame_size().height()); |
677 | 673 |
678 DeliverVideoFrameAndWaitForRenderer(1280, 720, &sink); | 674 DeliverVideoFrameAndWaitForRenderer(1280, 720, &sink); |
679 | 675 |
680 EXPECT_EQ(3, sink.number_of_frames()); | 676 EXPECT_EQ(3, sink.number_of_frames()); |
681 // Expect a frame to be cropped since its larger than max requested. | 677 // Expect a frame to be cropped since its larger than max requested. |
682 EXPECT_EQ(800, sink.frame_size().width()); | 678 EXPECT_EQ(800, sink.frame_size().width()); |
683 EXPECT_EQ(700, sink.frame_size().height()); | 679 EXPECT_EQ(700, sink.frame_size().height()); |
684 | 680 |
685 MediaStreamVideoSink::RemoveFromVideoTrack(&sink, track); | 681 sink.DisconnectFromTrack(); |
686 } | 682 } |
687 | 683 |
688 TEST_F(MediaStreamVideoSourceTest, IsConstraintSupported) { | 684 TEST_F(MediaStreamVideoSourceTest, IsConstraintSupported) { |
689 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( | 685 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( |
690 MediaStreamVideoSource::kMaxFrameRate)); | 686 MediaStreamVideoSource::kMaxFrameRate)); |
691 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( | 687 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( |
692 MediaStreamVideoSource::kMinFrameRate)); | 688 MediaStreamVideoSource::kMinFrameRate)); |
693 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( | 689 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( |
694 MediaStreamVideoSource::kMaxWidth)); | 690 MediaStreamVideoSource::kMaxWidth)); |
695 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( | 691 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( |
(...skipping 21 matching lines...) Expand all Loading... |
717 mock_source()->SetSupportedFormats(formats); | 713 mock_source()->SetSupportedFormats(formats); |
718 | 714 |
719 blink::WebMediaConstraints constraints; | 715 blink::WebMediaConstraints constraints; |
720 constraints.initialize(); | 716 constraints.initialize(); |
721 blink::WebMediaStreamTrack track = CreateTrack("123", constraints); | 717 blink::WebMediaStreamTrack track = CreateTrack("123", constraints); |
722 mock_source()->CompleteGetSupportedFormats(); | 718 mock_source()->CompleteGetSupportedFormats(); |
723 mock_source()->StartMockedSource(); | 719 mock_source()->StartMockedSource(); |
724 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); | 720 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); |
725 | 721 |
726 MockMediaStreamVideoSink sink; | 722 MockMediaStreamVideoSink sink; |
727 MediaStreamVideoSink::AddToVideoTrack( | 723 sink.ConnectToTrack(track); |
728 &sink, sink.GetDeliverFrameCB(), track); | |
729 EXPECT_EQ(0, sink.number_of_frames()); | 724 EXPECT_EQ(0, sink.number_of_frames()); |
730 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink); | 725 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink); |
731 EXPECT_EQ(1, sink.number_of_frames()); | 726 EXPECT_EQ(1, sink.number_of_frames()); |
732 // Expect the delivered frame to be passed unchanged since its smaller than | 727 // Expect the delivered frame to be passed unchanged since its smaller than |
733 // max requested. | 728 // max requested. |
734 EXPECT_EQ(320, sink.frame_size().width()); | 729 EXPECT_EQ(320, sink.frame_size().width()); |
735 EXPECT_EQ(240, sink.frame_size().height()); | 730 EXPECT_EQ(240, sink.frame_size().height()); |
736 MediaStreamVideoSink::RemoveFromVideoTrack(&sink, track); | 731 sink.DisconnectFromTrack(); |
737 } | 732 } |
738 | 733 |
739 // Test that a source producing no frames change the source ReadyState to muted. | 734 // Test that a source producing no frames change the source ReadyState to muted. |
740 // that in a reasonable time frame the muted state turns to false. | 735 // that in a reasonable time frame the muted state turns to false. |
741 TEST_F(MediaStreamVideoSourceTest, MutedSource) { | 736 TEST_F(MediaStreamVideoSourceTest, MutedSource) { |
742 // Setup the source for support a frame rate of 999 fps in order to test | 737 // Setup the source for support a frame rate of 999 fps in order to test |
743 // the muted event faster. This is since the frame monitoring uses | 738 // the muted event faster. This is since the frame monitoring uses |
744 // PostDelayedTask that is dependent on the source frame rate. | 739 // PostDelayedTask that is dependent on the source frame rate. |
745 // Note that media::limits::kMaxFramesPerSecond is 1000. | 740 // Note that media::limits::kMaxFramesPerSecond is 1000. |
746 media::VideoCaptureFormats formats; | 741 media::VideoCaptureFormats formats; |
747 formats.push_back(media::VideoCaptureFormat( | 742 formats.push_back(media::VideoCaptureFormat( |
748 gfx::Size(640, 480), media::limits::kMaxFramesPerSecond - 1, | 743 gfx::Size(640, 480), media::limits::kMaxFramesPerSecond - 1, |
749 media::PIXEL_FORMAT_I420)); | 744 media::PIXEL_FORMAT_I420)); |
750 SetSourceSupportedFormats(formats); | 745 SetSourceSupportedFormats(formats); |
751 | 746 |
752 MockConstraintFactory factory; | 747 MockConstraintFactory factory; |
753 blink::WebMediaStreamTrack track = | 748 blink::WebMediaStreamTrack track = |
754 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, | 749 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, |
755 media::limits::kMaxFramesPerSecond - 1); | 750 media::limits::kMaxFramesPerSecond - 1); |
756 MockMediaStreamVideoSink sink; | 751 MockMediaStreamVideoSink sink; |
757 MediaStreamVideoSink::AddToVideoTrack(&sink, sink.GetDeliverFrameCB(), track); | 752 sink.ConnectToTrack(track); |
758 EXPECT_EQ(track.source().getReadyState(), | 753 EXPECT_EQ(track.source().getReadyState(), |
759 blink::WebMediaStreamSource::ReadyStateLive); | 754 blink::WebMediaStreamSource::ReadyStateLive); |
760 | 755 |
761 base::RunLoop run_loop; | 756 base::RunLoop run_loop; |
762 base::Closure quit_closure = run_loop.QuitClosure(); | 757 base::Closure quit_closure = run_loop.QuitClosure(); |
763 bool muted_state = false; | 758 bool muted_state = false; |
764 EXPECT_CALL(*mock_source(), DoSetMutedState(_)) | 759 EXPECT_CALL(*mock_source(), DoSetMutedState(_)) |
765 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure))); | 760 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure))); |
766 run_loop.Run(); | 761 run_loop.Run(); |
767 EXPECT_EQ(muted_state, true); | 762 EXPECT_EQ(muted_state, true); |
768 | 763 |
769 EXPECT_EQ(track.source().getReadyState(), | 764 EXPECT_EQ(track.source().getReadyState(), |
770 blink::WebMediaStreamSource::ReadyStateMuted); | 765 blink::WebMediaStreamSource::ReadyStateMuted); |
771 | 766 |
772 base::RunLoop run_loop2; | 767 base::RunLoop run_loop2; |
773 base::Closure quit_closure2 = run_loop2.QuitClosure(); | 768 base::Closure quit_closure2 = run_loop2.QuitClosure(); |
774 EXPECT_CALL(*mock_source(), DoSetMutedState(_)) | 769 EXPECT_CALL(*mock_source(), DoSetMutedState(_)) |
775 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure2))); | 770 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure2))); |
776 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); | 771 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); |
777 run_loop2.Run(); | 772 run_loop2.Run(); |
778 | 773 |
779 EXPECT_EQ(muted_state, false); | 774 EXPECT_EQ(muted_state, false); |
780 EXPECT_EQ(track.source().getReadyState(), | 775 EXPECT_EQ(track.source().getReadyState(), |
781 blink::WebMediaStreamSource::ReadyStateLive); | 776 blink::WebMediaStreamSource::ReadyStateLive); |
782 | 777 |
783 MediaStreamVideoSink::RemoveFromVideoTrack(&sink, track); | 778 sink.DisconnectFromTrack(); |
784 } | 779 } |
785 | 780 |
786 } // namespace content | 781 } // namespace content |
OLD | NEW |