OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 this, | 56 this, |
57 &CaptureManagerTest::OnCapturerStateChange); | 57 &CaptureManagerTest::OnCapturerStateChange); |
58 } | 58 } |
59 void PopulateSupportedFormats() { | 59 void PopulateSupportedFormats() { |
60 std::vector<cricket::VideoFormat> formats; | 60 std::vector<cricket::VideoFormat> formats; |
61 for (int i = 0; i < ARRAY_SIZE(kCameraFormats); ++i) { | 61 for (int i = 0; i < ARRAY_SIZE(kCameraFormats); ++i) { |
62 formats.push_back(cricket::VideoFormat(kCameraFormats[i])); | 62 formats.push_back(cricket::VideoFormat(kCameraFormats[i])); |
63 } | 63 } |
64 video_capturer_.ResetSupportedFormats(formats); | 64 video_capturer_.ResetSupportedFormats(formats); |
65 } | 65 } |
66 int NumFramesProcessed() { return media_processor_.video_frame_count(); } | |
67 int NumFramesRendered() { return video_renderer_.num_rendered_frames(); } | 66 int NumFramesRendered() { return video_renderer_.num_rendered_frames(); } |
68 bool WasRenderedResolution(cricket::VideoFormat format) { | 67 bool WasRenderedResolution(cricket::VideoFormat format) { |
69 return format.width == video_renderer_.width() && | 68 return format.width == video_renderer_.width() && |
70 format.height == video_renderer_.height(); | 69 format.height == video_renderer_.height(); |
71 } | 70 } |
72 cricket::CaptureState capture_state() { return capture_state_; } | 71 cricket::CaptureState capture_state() { return capture_state_; } |
73 int callback_count() { return callback_count_; } | 72 int callback_count() { return callback_count_; } |
74 void OnCapturerStateChange(cricket::VideoCapturer* capturer, | 73 void OnCapturerStateChange(cricket::VideoCapturer* capturer, |
75 cricket::CaptureState capture_state) { | 74 cricket::CaptureState capture_state) { |
76 capture_state_ = capture_state; | 75 capture_state_ = capture_state; |
(...skipping 11 matching lines...) Expand all Loading... |
88 int callback_count_; | 87 int callback_count_; |
89 cricket::VideoFormat format_vga_; | 88 cricket::VideoFormat format_vga_; |
90 cricket::VideoFormat format_qvga_; | 89 cricket::VideoFormat format_qvga_; |
91 }; | 90 }; |
92 | 91 |
93 // Incorrect use cases. | 92 // Incorrect use cases. |
94 TEST_F(CaptureManagerTest, InvalidCallOrder) { | 93 TEST_F(CaptureManagerTest, InvalidCallOrder) { |
95 // Capturer must be registered before any of these calls. | 94 // Capturer must be registered before any of these calls. |
96 EXPECT_FALSE(capture_manager_.AddVideoRenderer(&video_capturer_, | 95 EXPECT_FALSE(capture_manager_.AddVideoRenderer(&video_capturer_, |
97 &video_renderer_)); | 96 &video_renderer_)); |
98 EXPECT_FALSE(capture_manager_.AddVideoProcessor(&video_capturer_, | |
99 &media_processor_)); | |
100 } | 97 } |
101 | 98 |
102 TEST_F(CaptureManagerTest, InvalidAddingRemoving) { | 99 TEST_F(CaptureManagerTest, InvalidAddingRemoving) { |
103 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, | 100 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, |
104 cricket::VideoFormat())); | 101 cricket::VideoFormat())); |
105 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | 102 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, |
106 format_vga_)); | 103 format_vga_)); |
107 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); | 104 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
108 EXPECT_EQ(1, callback_count()); | 105 EXPECT_EQ(1, callback_count()); |
109 EXPECT_FALSE(capture_manager_.AddVideoRenderer(&video_capturer_, NULL)); | 106 EXPECT_FALSE(capture_manager_.AddVideoRenderer(&video_capturer_, NULL)); |
110 EXPECT_FALSE(capture_manager_.RemoveVideoRenderer(&video_capturer_, | 107 EXPECT_FALSE(capture_manager_.RemoveVideoRenderer(&video_capturer_, |
111 &video_renderer_)); | 108 &video_renderer_)); |
112 EXPECT_FALSE(capture_manager_.AddVideoProcessor(&video_capturer_, | |
113 NULL)); | |
114 EXPECT_FALSE(capture_manager_.RemoveVideoProcessor(&video_capturer_, | |
115 &media_processor_)); | |
116 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); | 109 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); |
117 } | 110 } |
118 | 111 |
119 // Valid use cases | 112 // Valid use cases |
120 TEST_F(CaptureManagerTest, ProcessorTest) { | |
121 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | |
122 format_vga_)); | |
123 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); | |
124 EXPECT_EQ(1, callback_count()); | |
125 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, | |
126 &video_renderer_)); | |
127 EXPECT_TRUE(capture_manager_.AddVideoProcessor(&video_capturer_, | |
128 &media_processor_)); | |
129 EXPECT_TRUE(video_capturer_.CaptureFrame()); | |
130 EXPECT_EQ(1, NumFramesProcessed()); | |
131 EXPECT_EQ(1, NumFramesRendered()); | |
132 EXPECT_TRUE(capture_manager_.RemoveVideoProcessor(&video_capturer_, | |
133 &media_processor_)); | |
134 // Processor has been removed so no more frames should be processed. | |
135 EXPECT_TRUE(video_capturer_.CaptureFrame()); | |
136 EXPECT_EQ(1, NumFramesProcessed()); | |
137 EXPECT_EQ(2, NumFramesRendered()); | |
138 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); | |
139 EXPECT_EQ(2, callback_count()); | |
140 } | |
141 | |
142 TEST_F(CaptureManagerTest, KeepFirstResolutionHigh) { | 113 TEST_F(CaptureManagerTest, KeepFirstResolutionHigh) { |
143 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | 114 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, |
144 format_vga_)); | 115 format_vga_)); |
145 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); | 116 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
146 EXPECT_EQ(1, callback_count()); | 117 EXPECT_EQ(1, callback_count()); |
147 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, | 118 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, |
148 &video_renderer_)); | 119 &video_renderer_)); |
149 EXPECT_TRUE(video_capturer_.CaptureFrame()); | 120 EXPECT_TRUE(video_capturer_.CaptureFrame()); |
150 EXPECT_EQ(1, NumFramesRendered()); | 121 EXPECT_EQ(1, NumFramesRendered()); |
151 // Renderer should be fed frames with the resolution of format_vga_. | 122 // Renderer should be fed frames with the resolution of format_vga_. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // Now request restart with qvga. | 221 // Now request restart with qvga. |
251 EXPECT_TRUE(capture_manager_.RestartVideoCapture( | 222 EXPECT_TRUE(capture_manager_.RestartVideoCapture( |
252 &video_capturer_, format_vga_, format_qvga_, | 223 &video_capturer_, format_vga_, format_qvga_, |
253 cricket::CaptureManager::kRequestRestart)); | 224 cricket::CaptureManager::kRequestRestart)); |
254 EXPECT_TRUE(video_capturer_.CaptureFrame()); | 225 EXPECT_TRUE(video_capturer_.CaptureFrame()); |
255 EXPECT_EQ(2, NumFramesRendered()); | 226 EXPECT_EQ(2, NumFramesRendered()); |
256 EXPECT_TRUE(WasRenderedResolution(format_vga_)); | 227 EXPECT_TRUE(WasRenderedResolution(format_vga_)); |
257 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, | 228 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, |
258 format_qvga_)); | 229 format_qvga_)); |
259 } | 230 } |
OLD | NEW |