| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 cricket::CaptureManager capture_manager_; | 83 cricket::CaptureManager capture_manager_; |
| 84 | 84 |
| 85 cricket::CaptureState capture_state_; | 85 cricket::CaptureState capture_state_; |
| 86 int callback_count_; | 86 int callback_count_; |
| 87 cricket::VideoFormat format_vga_; | 87 cricket::VideoFormat format_vga_; |
| 88 cricket::VideoFormat format_qvga_; | 88 cricket::VideoFormat format_qvga_; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 // Incorrect use cases. | 91 // Incorrect use cases. |
| 92 TEST_F(CaptureManagerTest, InvalidCallOrder) { | |
| 93 // Capturer must be registered before any of these calls. | |
| 94 EXPECT_FALSE(capture_manager_.AddVideoRenderer(&video_capturer_, | |
| 95 &video_renderer_)); | |
| 96 } | |
| 97 | |
| 98 TEST_F(CaptureManagerTest, InvalidAddingRemoving) { | 92 TEST_F(CaptureManagerTest, InvalidAddingRemoving) { |
| 99 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, | 93 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, |
| 100 cricket::VideoFormat())); | 94 cricket::VideoFormat())); |
| 101 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | 95 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, |
| 102 format_vga_)); | 96 format_vga_)); |
| 103 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); | 97 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
| 104 EXPECT_EQ(1, callback_count()); | 98 EXPECT_EQ(1, callback_count()); |
| 105 EXPECT_FALSE(capture_manager_.AddVideoRenderer(&video_capturer_, NULL)); | 99 // NULL argument currently allowed, and does nothing. |
| 100 capture_manager_.AddVideoSink(&video_capturer_, NULL); |
| 106 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); | 101 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); |
| 107 } | 102 } |
| 108 | 103 |
| 109 // Valid use cases | 104 // Valid use cases |
| 110 TEST_F(CaptureManagerTest, KeepFirstResolutionHigh) { | 105 TEST_F(CaptureManagerTest, KeepFirstResolutionHigh) { |
| 111 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | 106 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, |
| 112 format_vga_)); | 107 format_vga_)); |
| 113 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); | 108 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
| 114 EXPECT_EQ(1, callback_count()); | 109 EXPECT_EQ(1, callback_count()); |
| 115 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, | 110 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_); |
| 116 &video_renderer_)); | |
| 117 EXPECT_TRUE(video_capturer_.CaptureFrame()); | 111 EXPECT_TRUE(video_capturer_.CaptureFrame()); |
| 118 EXPECT_EQ(1, NumFramesRendered()); | 112 EXPECT_EQ(1, NumFramesRendered()); |
| 119 // Renderer should be fed frames with the resolution of format_vga_. | 113 // Renderer should be fed frames with the resolution of format_vga_. |
| 120 EXPECT_TRUE(WasRenderedResolution(format_vga_)); | 114 EXPECT_TRUE(WasRenderedResolution(format_vga_)); |
| 121 | 115 |
| 122 // Start again with one more format. | 116 // Start again with one more format. |
| 123 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | 117 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, |
| 124 format_qvga_)); | 118 format_qvga_)); |
| 125 // Existing renderers should be fed frames with the resolution of format_vga_. | 119 // Existing renderers should be fed frames with the resolution of format_vga_. |
| 126 EXPECT_TRUE(video_capturer_.CaptureFrame()); | 120 EXPECT_TRUE(video_capturer_.CaptureFrame()); |
| 127 EXPECT_TRUE(WasRenderedResolution(format_vga_)); | 121 EXPECT_TRUE(WasRenderedResolution(format_vga_)); |
| 128 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); | 122 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); |
| 129 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, | 123 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, |
| 130 format_qvga_)); | 124 format_qvga_)); |
| 131 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, | 125 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, |
| 132 format_vga_)); | 126 format_vga_)); |
| 133 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, | 127 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, |
| 134 format_qvga_)); | 128 format_qvga_)); |
| 135 } | 129 } |
| 136 | 130 |
| 137 // Should pick the lowest resolution as the highest resolution is not chosen | 131 // Should pick the lowest resolution as the highest resolution is not chosen |
| 138 // until after capturing has started. This ensures that no particular resolution | 132 // until after capturing has started. This ensures that no particular resolution |
| 139 // is favored over others. | 133 // is favored over others. |
| 140 TEST_F(CaptureManagerTest, KeepFirstResolutionLow) { | 134 TEST_F(CaptureManagerTest, KeepFirstResolutionLow) { |
| 141 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | 135 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, |
| 142 format_qvga_)); | 136 format_qvga_)); |
| 143 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | 137 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, |
| 144 format_vga_)); | 138 format_vga_)); |
| 145 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, | 139 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_); |
| 146 &video_renderer_)); | |
| 147 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); | 140 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); |
| 148 EXPECT_TRUE(video_capturer_.CaptureFrame()); | 141 EXPECT_TRUE(video_capturer_.CaptureFrame()); |
| 149 EXPECT_EQ(1, NumFramesRendered()); | 142 EXPECT_EQ(1, NumFramesRendered()); |
| 150 EXPECT_TRUE(WasRenderedResolution(format_qvga_)); | 143 EXPECT_TRUE(WasRenderedResolution(format_qvga_)); |
| 151 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, | 144 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, |
| 152 format_qvga_)); | 145 format_qvga_)); |
| 153 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, | 146 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, |
| 154 format_vga_)); | 147 format_vga_)); |
| 155 } | 148 } |
| 156 | 149 |
| 157 // Ensure that the reference counting is working when multiple start and | 150 // Ensure that the reference counting is working when multiple start and |
| 158 // multiple stop calls are made. | 151 // multiple stop calls are made. |
| 159 TEST_F(CaptureManagerTest, MultipleStartStops) { | 152 TEST_F(CaptureManagerTest, MultipleStartStops) { |
| 160 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | 153 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, |
| 161 format_vga_)); | 154 format_vga_)); |
| 162 // Add video capturer but with different format. | 155 // Add video capturer but with different format. |
| 163 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | 156 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, |
| 164 format_qvga_)); | 157 format_qvga_)); |
| 165 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); | 158 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
| 166 EXPECT_EQ(1, callback_count()); | 159 EXPECT_EQ(1, callback_count()); |
| 167 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, | 160 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_); |
| 168 &video_renderer_)); | |
| 169 // Ensure that a frame can be captured when two start calls have been made. | 161 // Ensure that a frame can be captured when two start calls have been made. |
| 170 EXPECT_TRUE(video_capturer_.CaptureFrame()); | 162 EXPECT_TRUE(video_capturer_.CaptureFrame()); |
| 171 EXPECT_EQ(1, NumFramesRendered()); | 163 EXPECT_EQ(1, NumFramesRendered()); |
| 172 | 164 |
| 173 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); | 165 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); |
| 174 // Video should still render since there has been two start calls but only | 166 // Video should still render since there has been two start calls but only |
| 175 // one stop call. | 167 // one stop call. |
| 176 EXPECT_TRUE(video_capturer_.CaptureFrame()); | 168 EXPECT_TRUE(video_capturer_.CaptureFrame()); |
| 177 EXPECT_EQ(2, NumFramesRendered()); | 169 EXPECT_EQ(2, NumFramesRendered()); |
| 178 | 170 |
| 179 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, | 171 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, |
| 180 format_qvga_)); | 172 format_qvga_)); |
| 181 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait); | 173 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait); |
| 182 EXPECT_EQ(2, callback_count()); | 174 EXPECT_EQ(2, callback_count()); |
| 183 // Last stop call should fail as it is one more than the number of start | 175 // Last stop call should fail as it is one more than the number of start |
| 184 // calls. | 176 // calls. |
| 185 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, | 177 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, |
| 186 format_vga_)); | 178 format_vga_)); |
| 187 } | 179 } |
| 188 | 180 |
| 189 TEST_F(CaptureManagerTest, TestForceRestart) { | 181 TEST_F(CaptureManagerTest, TestForceRestart) { |
| 190 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | 182 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, |
| 191 format_qvga_)); | 183 format_qvga_)); |
| 192 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, | 184 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_); |
| 193 &video_renderer_)); | |
| 194 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); | 185 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); |
| 195 EXPECT_TRUE(video_capturer_.CaptureFrame()); | 186 EXPECT_TRUE(video_capturer_.CaptureFrame()); |
| 196 EXPECT_EQ(1, NumFramesRendered()); | 187 EXPECT_EQ(1, NumFramesRendered()); |
| 197 EXPECT_TRUE(WasRenderedResolution(format_qvga_)); | 188 EXPECT_TRUE(WasRenderedResolution(format_qvga_)); |
| 198 // Now restart with vga. | 189 // Now restart with vga. |
| 199 EXPECT_TRUE(capture_manager_.RestartVideoCapture( | 190 EXPECT_TRUE(capture_manager_.RestartVideoCapture( |
| 200 &video_capturer_, format_qvga_, format_vga_, | 191 &video_capturer_, format_qvga_, format_vga_, |
| 201 cricket::CaptureManager::kForceRestart)); | 192 cricket::CaptureManager::kForceRestart)); |
| 202 EXPECT_TRUE(video_capturer_.CaptureFrame()); | 193 EXPECT_TRUE(video_capturer_.CaptureFrame()); |
| 203 EXPECT_EQ(2, NumFramesRendered()); | 194 EXPECT_EQ(2, NumFramesRendered()); |
| 204 EXPECT_TRUE(WasRenderedResolution(format_vga_)); | 195 EXPECT_TRUE(WasRenderedResolution(format_vga_)); |
| 205 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, | 196 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, |
| 206 format_vga_)); | 197 format_vga_)); |
| 207 } | 198 } |
| 208 | 199 |
| 209 TEST_F(CaptureManagerTest, TestRequestRestart) { | 200 TEST_F(CaptureManagerTest, TestRequestRestart) { |
| 210 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, | 201 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, |
| 211 format_vga_)); | 202 format_vga_)); |
| 212 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, | 203 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_); |
| 213 &video_renderer_)); | |
| 214 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); | 204 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); |
| 215 EXPECT_TRUE(video_capturer_.CaptureFrame()); | 205 EXPECT_TRUE(video_capturer_.CaptureFrame()); |
| 216 EXPECT_EQ(1, NumFramesRendered()); | 206 EXPECT_EQ(1, NumFramesRendered()); |
| 217 EXPECT_TRUE(WasRenderedResolution(format_vga_)); | 207 EXPECT_TRUE(WasRenderedResolution(format_vga_)); |
| 218 // Now request restart with qvga. | 208 // Now request restart with qvga. |
| 219 EXPECT_TRUE(capture_manager_.RestartVideoCapture( | 209 EXPECT_TRUE(capture_manager_.RestartVideoCapture( |
| 220 &video_capturer_, format_vga_, format_qvga_, | 210 &video_capturer_, format_vga_, format_qvga_, |
| 221 cricket::CaptureManager::kRequestRestart)); | 211 cricket::CaptureManager::kRequestRestart)); |
| 222 EXPECT_TRUE(video_capturer_.CaptureFrame()); | 212 EXPECT_TRUE(video_capturer_.CaptureFrame()); |
| 223 EXPECT_EQ(2, NumFramesRendered()); | 213 EXPECT_EQ(2, NumFramesRendered()); |
| 224 EXPECT_TRUE(WasRenderedResolution(format_vga_)); | 214 EXPECT_TRUE(WasRenderedResolution(format_vga_)); |
| 225 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, | 215 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, |
| 226 format_qvga_)); | 216 format_qvga_)); |
| 227 } | 217 } |
| OLD | NEW |