| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Unit test for VideoCaptureController. | 5 // Unit test for VideoCaptureController. |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/media/video_capture_controller.h" | 7 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 8 | 8 |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 : public media::VideoFrameConsumerFeedbackObserver { | 108 : public media::VideoFrameConsumerFeedbackObserver { |
| 109 public: | 109 public: |
| 110 MOCK_METHOD2(OnUtilizationReport, | 110 MOCK_METHOD2(OnUtilizationReport, |
| 111 void(int frame_feedback_id, double utilization)); | 111 void(int frame_feedback_id, double utilization)); |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 class MockFrameBufferPool : public media::FrameBufferPool { | 114 class MockFrameBufferPool : public media::FrameBufferPool { |
| 115 public: | 115 public: |
| 116 MOCK_METHOD1(SetBufferHold, void(int buffer_id)); | 116 MOCK_METHOD1(SetBufferHold, void(int buffer_id)); |
| 117 MOCK_METHOD1(ReleaseBufferHold, void(int buffer_id)); | 117 MOCK_METHOD1(ReleaseBufferHold, void(int buffer_id)); |
| 118 MOCK_METHOD1(GetHandleForTransit, | |
| 119 mojo::ScopedSharedBufferHandle(int buffer_id)); | |
| 120 }; | 118 }; |
| 121 | 119 |
| 122 // Test class. | 120 // Test class. |
| 123 class VideoCaptureControllerTest | 121 class VideoCaptureControllerTest |
| 124 : public testing::Test, | 122 : public testing::Test, |
| 125 public testing::WithParamInterface<media::VideoPixelFormat> { | 123 public testing::WithParamInterface<media::VideoPixelFormat> { |
| 126 public: | 124 public: |
| 127 VideoCaptureControllerTest() {} | 125 VideoCaptureControllerTest() {} |
| 128 ~VideoCaptureControllerTest() override {} | 126 ~VideoCaptureControllerTest() override {} |
| 129 | 127 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 145 base::Bind(&media::VideoFrameReceiver::OnIncomingCapturedVideoFrame, | 143 base::Bind(&media::VideoFrameReceiver::OnIncomingCapturedVideoFrame, |
| 146 controller_->GetWeakPtrForIOThread())))); | 144 controller_->GetWeakPtrForIOThread())))); |
| 147 auto frame_receiver_observer = base::MakeUnique<MockFrameBufferPool>(); | 145 auto frame_receiver_observer = base::MakeUnique<MockFrameBufferPool>(); |
| 148 mock_frame_receiver_observer_ = frame_receiver_observer.get(); | 146 mock_frame_receiver_observer_ = frame_receiver_observer.get(); |
| 149 controller_->SetFrameBufferPool(std::move(frame_receiver_observer)); | 147 controller_->SetFrameBufferPool(std::move(frame_receiver_observer)); |
| 150 auto consumer_feedback_observer = | 148 auto consumer_feedback_observer = |
| 151 base::MakeUnique<MockConsumerFeedbackObserver>(); | 149 base::MakeUnique<MockConsumerFeedbackObserver>(); |
| 152 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); | 150 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); |
| 153 controller_->SetConsumerFeedbackObserver( | 151 controller_->SetConsumerFeedbackObserver( |
| 154 std::move(consumer_feedback_observer)); | 152 std::move(consumer_feedback_observer)); |
| 155 client_a_.reset(new MockVideoCaptureControllerEventHandler( | 153 client_a_.reset( |
| 156 controller_.get())); | 154 new MockVideoCaptureControllerEventHandler(controller_.get())); |
| 157 client_b_.reset(new MockVideoCaptureControllerEventHandler( | 155 client_b_.reset( |
| 158 controller_.get())); | 156 new MockVideoCaptureControllerEventHandler(controller_.get())); |
| 159 } | 157 } |
| 160 | 158 |
| 161 void TearDown() override { base::RunLoop().RunUntilIdle(); } | 159 void TearDown() override { base::RunLoop().RunUntilIdle(); } |
| 162 | 160 |
| 163 TestBrowserThreadBundle bundle_; | 161 TestBrowserThreadBundle bundle_; |
| 164 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; | 162 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; |
| 165 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; | 163 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; |
| 166 std::unique_ptr<VideoCaptureController> controller_; | 164 std::unique_ptr<VideoCaptureController> controller_; |
| 167 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; | 165 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; |
| 168 MockFrameBufferPool* mock_frame_receiver_observer_; | 166 MockFrameBufferPool* mock_frame_receiver_observer_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 190 // Intentionally use the same route ID for two of the clients: the device_ids | 188 // Intentionally use the same route ID for two of the clients: the device_ids |
| 191 // are a per-VideoCaptureHost namespace, and can overlap across hosts. | 189 // are a per-VideoCaptureHost namespace, and can overlap across hosts. |
| 192 const VideoCaptureControllerID client_a_route_1(44); | 190 const VideoCaptureControllerID client_a_route_1(44); |
| 193 const VideoCaptureControllerID client_a_route_2(30); | 191 const VideoCaptureControllerID client_a_route_2(30); |
| 194 const VideoCaptureControllerID client_b_route_1(30); | 192 const VideoCaptureControllerID client_b_route_1(30); |
| 195 const VideoCaptureControllerID client_b_route_2(1); | 193 const VideoCaptureControllerID client_b_route_2(1); |
| 196 | 194 |
| 197 // Clients in controller: [] | 195 // Clients in controller: [] |
| 198 ASSERT_EQ(0, controller_->GetClientCount()) | 196 ASSERT_EQ(0, controller_->GetClientCount()) |
| 199 << "Client count should initially be zero."; | 197 << "Client count should initially be zero."; |
| 200 controller_->AddClient(client_a_route_1, | 198 controller_->AddClient(client_a_route_1, client_a_.get(), 100, session_100); |
| 201 client_a_.get(), | |
| 202 100, | |
| 203 session_100); | |
| 204 // Clients in controller: [A/1] | 199 // Clients in controller: [A/1] |
| 205 ASSERT_EQ(1, controller_->GetClientCount()) | 200 ASSERT_EQ(1, controller_->GetClientCount()) |
| 206 << "Adding client A/1 should bump client count."; | 201 << "Adding client A/1 should bump client count."; |
| 207 controller_->AddClient(client_a_route_2, | 202 controller_->AddClient(client_a_route_2, client_a_.get(), 200, session_200); |
| 208 client_a_.get(), | |
| 209 200, | |
| 210 session_200); | |
| 211 // Clients in controller: [A/1, A/2] | 203 // Clients in controller: [A/1, A/2] |
| 212 ASSERT_EQ(2, controller_->GetClientCount()) | 204 ASSERT_EQ(2, controller_->GetClientCount()) |
| 213 << "Adding client A/2 should bump client count."; | 205 << "Adding client A/2 should bump client count."; |
| 214 controller_->AddClient(client_b_route_1, | 206 controller_->AddClient(client_b_route_1, client_b_.get(), 300, session_300); |
| 215 client_b_.get(), | |
| 216 300, | |
| 217 session_300); | |
| 218 // Clients in controller: [A/1, A/2, B/1] | 207 // Clients in controller: [A/1, A/2, B/1] |
| 219 ASSERT_EQ(3, controller_->GetClientCount()) | 208 ASSERT_EQ(3, controller_->GetClientCount()) |
| 220 << "Adding client B/1 should bump client count."; | 209 << "Adding client B/1 should bump client count."; |
| 221 ASSERT_EQ(200, | 210 ASSERT_EQ(200, controller_->RemoveClient(client_a_route_2, client_a_.get())) |
| 222 controller_->RemoveClient(client_a_route_2, client_a_.get())) | |
| 223 << "Removing client A/1 should return its session_id."; | 211 << "Removing client A/1 should return its session_id."; |
| 224 // Clients in controller: [A/1, B/1] | 212 // Clients in controller: [A/1, B/1] |
| 225 ASSERT_EQ(2, controller_->GetClientCount()); | 213 ASSERT_EQ(2, controller_->GetClientCount()); |
| 226 ASSERT_EQ(static_cast<int>(kInvalidMediaCaptureSessionId), | 214 ASSERT_EQ(static_cast<int>(kInvalidMediaCaptureSessionId), |
| 227 controller_->RemoveClient(client_a_route_2, client_a_.get())) | 215 controller_->RemoveClient(client_a_route_2, client_a_.get())) |
| 228 << "Removing a nonexistant client should fail."; | 216 << "Removing a nonexistant client should fail."; |
| 229 // Clients in controller: [A/1, B/1] | 217 // Clients in controller: [A/1, B/1] |
| 230 ASSERT_EQ(2, controller_->GetClientCount()); | 218 ASSERT_EQ(2, controller_->GetClientCount()); |
| 231 ASSERT_EQ(300, | 219 ASSERT_EQ(300, controller_->RemoveClient(client_b_route_1, client_b_.get())) |
| 232 controller_->RemoveClient(client_b_route_1, client_b_.get())) | |
| 233 << "Removing client B/1 should return its session_id."; | 220 << "Removing client B/1 should return its session_id."; |
| 234 // Clients in controller: [A/1] | 221 // Clients in controller: [A/1] |
| 235 ASSERT_EQ(1, controller_->GetClientCount()); | 222 ASSERT_EQ(1, controller_->GetClientCount()); |
| 236 controller_->AddClient(client_b_route_2, | 223 controller_->AddClient(client_b_route_2, client_b_.get(), 400, session_400); |
| 237 client_b_.get(), | |
| 238 400, | |
| 239 session_400); | |
| 240 // Clients in controller: [A/1, B/2] | 224 // Clients in controller: [A/1, B/2] |
| 241 | 225 |
| 242 EXPECT_CALL(*client_a_, DoEnded(client_a_route_1)).Times(1); | 226 EXPECT_CALL(*client_a_, DoEnded(client_a_route_1)).Times(1); |
| 243 controller_->StopSession(100); // Session 100 == client A/1 | 227 controller_->StopSession(100); // Session 100 == client A/1 |
| 244 Mock::VerifyAndClearExpectations(client_a_.get()); | 228 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 245 ASSERT_EQ(2, controller_->GetClientCount()) | 229 ASSERT_EQ(2, controller_->GetClientCount()) |
| 246 << "Client should be closed but still exist after StopSession."; | 230 << "Client should be closed but still exist after StopSession."; |
| 247 // Clients in controller: [A/1 (closed, removal pending), B/2] | 231 // Clients in controller: [A/1 (closed, removal pending), B/2] |
| 248 base::RunLoop().RunUntilIdle(); | 232 base::RunLoop().RunUntilIdle(); |
| 249 // Clients in controller: [B/2] | 233 // Clients in controller: [B/2] |
| 250 ASSERT_EQ(1, controller_->GetClientCount()) | 234 ASSERT_EQ(1, controller_->GetClientCount()) |
| 251 << "Client A/1 should be deleted by now."; | 235 << "Client A/1 should be deleted by now."; |
| 252 controller_->StopSession(200); // Session 200 does not exist anymore | 236 controller_->StopSession(200); // Session 200 does not exist anymore |
| 253 // Clients in controller: [B/2] | 237 // Clients in controller: [B/2] |
| 254 ASSERT_EQ(1, controller_->GetClientCount()) | 238 ASSERT_EQ(1, controller_->GetClientCount()) |
| 255 << "Stopping non-existant session 200 should be a no-op."; | 239 << "Stopping non-existant session 200 should be a no-op."; |
| 256 controller_->StopSession(256); // Session 256 never existed. | 240 controller_->StopSession(256); // Session 256 never existed. |
| 257 // Clients in controller: [B/2] | 241 // Clients in controller: [B/2] |
| 258 ASSERT_EQ(1, controller_->GetClientCount()) | 242 ASSERT_EQ(1, controller_->GetClientCount()) |
| 259 << "Stopping non-existant session 256 should be a no-op."; | 243 << "Stopping non-existant session 256 should be a no-op."; |
| 260 ASSERT_EQ(static_cast<int>(kInvalidMediaCaptureSessionId), | 244 ASSERT_EQ(static_cast<int>(kInvalidMediaCaptureSessionId), |
| 261 controller_->RemoveClient(client_a_route_1, client_a_.get())) | 245 controller_->RemoveClient(client_a_route_1, client_a_.get())) |
| 262 << "Removing already-removed client A/1 should fail."; | 246 << "Removing already-removed client A/1 should fail."; |
| 263 // Clients in controller: [B/2] | 247 // Clients in controller: [B/2] |
| 264 ASSERT_EQ(1, controller_->GetClientCount()) | 248 ASSERT_EQ(1, controller_->GetClientCount()) |
| 265 << "Removing non-existant session 200 should be a no-op."; | 249 << "Removing non-existant session 200 should be a no-op."; |
| 266 ASSERT_EQ(400, | 250 ASSERT_EQ(400, controller_->RemoveClient(client_b_route_2, client_b_.get())) |
| 267 controller_->RemoveClient(client_b_route_2, client_b_.get())) | |
| 268 << "Removing client B/2 should return its session_id."; | 251 << "Removing client B/2 should return its session_id."; |
| 269 // Clients in controller: [] | 252 // Clients in controller: [] |
| 270 ASSERT_EQ(0, controller_->GetClientCount()) | 253 ASSERT_EQ(0, controller_->GetClientCount()) |
| 271 << "Client count should return to zero after all clients are gone."; | 254 << "Client count should return to zero after all clients are gone."; |
| 272 } | 255 } |
| 273 | 256 |
| 274 // This test will connect and disconnect several clients while simulating an | 257 // This test will connect and disconnect several clients while simulating an |
| 275 // active capture device being started and generating frames. It runs on one | 258 // active capture device being started and generating frames. It runs on one |
| 276 // thread and is intended to behave deterministically. | 259 // thread and is intended to behave deterministically. |
| 277 TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) { | 260 TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 289 | 272 |
| 290 media::VideoCaptureParams session_1 = session_100; | 273 media::VideoCaptureParams session_1 = session_100; |
| 291 | 274 |
| 292 media::VideoCaptureFormat device_format(gfx::Size(444, 200), 25, format); | 275 media::VideoCaptureFormat device_format(gfx::Size(444, 200), 25, format); |
| 293 | 276 |
| 294 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1); | 277 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1); |
| 295 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2); | 278 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2); |
| 296 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); | 279 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); |
| 297 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); | 280 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); |
| 298 | 281 |
| 299 controller_->AddClient(client_a_route_1, | 282 controller_->AddClient(client_a_route_1, client_a_.get(), 100, session_100); |
| 300 client_a_.get(), | 283 controller_->AddClient(client_b_route_1, client_b_.get(), 300, session_300); |
| 301 100, | 284 controller_->AddClient(client_a_route_2, client_a_.get(), 200, session_200); |
| 302 session_100); | |
| 303 controller_->AddClient(client_b_route_1, | |
| 304 client_b_.get(), | |
| 305 300, | |
| 306 session_300); | |
| 307 controller_->AddClient(client_a_route_2, | |
| 308 client_a_.get(), | |
| 309 200, | |
| 310 session_200); | |
| 311 ASSERT_EQ(3, controller_->GetClientCount()); | 285 ASSERT_EQ(3, controller_->GetClientCount()); |
| 312 | 286 |
| 313 // Now, simulate an incoming captured buffer from the capture device. As a | 287 // Now, simulate an incoming captured buffer from the capture device. As a |
| 314 // side effect this will cause the first buffer to be shared with clients. | 288 // side effect this will cause the first buffer to be shared with clients. |
| 315 uint8_t buffer_no = 1; | 289 uint8_t buffer_no = 1; |
| 316 const int arbitrary_frame_feedback_id = 101; | 290 const int arbitrary_frame_feedback_id = 101; |
| 317 ASSERT_EQ(0.0, device_client_->GetBufferPoolUtilization()); | 291 ASSERT_EQ(0.0, device_client_->GetBufferPoolUtilization()); |
| 318 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 292 media::VideoCaptureDevice::Client::Buffer buffer = |
| 319 device_client_->ReserveOutputBuffer(device_format.frame_size, | 293 device_client_->ReserveOutputBuffer( |
| 320 device_format.pixel_format, | 294 device_format.frame_size, device_format.pixel_format, |
| 321 device_format.pixel_storage, | 295 device_format.pixel_storage, arbitrary_frame_feedback_id); |
| 322 arbitrary_frame_feedback_id)); | 296 ASSERT_TRUE(buffer.is_valid()); |
| 323 ASSERT_TRUE(buffer.get()); | 297 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess(); |
| 324 ASSERT_EQ(1.0 / kPoolSize, device_client_->GetBufferPoolUtilization()); | 298 ASSERT_EQ(1.0 / kPoolSize, device_client_->GetBufferPoolUtilization()); |
| 325 memset(buffer->data(), buffer_no++, buffer->mapped_size()); | 299 memset(buffer_access->data(), buffer_no++, buffer_access->mapped_size()); |
| 326 { | 300 { |
| 327 InSequence s; | 301 InSequence s; |
| 328 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 302 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
| 329 EXPECT_CALL(*client_a_, | 303 EXPECT_CALL(*client_a_, |
| 330 DoBufferReady(client_a_route_1, device_format.frame_size)) | 304 DoBufferReady(client_a_route_1, device_format.frame_size)) |
| 331 .Times(1); | 305 .Times(1); |
| 332 } | 306 } |
| 333 { | 307 { |
| 334 InSequence s; | 308 InSequence s; |
| 335 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 309 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
| 336 EXPECT_CALL(*client_b_, | 310 EXPECT_CALL(*client_b_, |
| 337 DoBufferReady(client_b_route_1, device_format.frame_size)) | 311 DoBufferReady(client_b_route_1, device_format.frame_size)) |
| 338 .Times(1); | 312 .Times(1); |
| 339 } | 313 } |
| 340 { | 314 { |
| 341 InSequence s; | 315 InSequence s; |
| 342 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 316 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
| 343 EXPECT_CALL(*client_a_, | 317 EXPECT_CALL(*client_a_, |
| 344 DoBufferReady(client_a_route_2, device_format.frame_size)) | 318 DoBufferReady(client_a_route_2, device_format.frame_size)) |
| 345 .Times(1); | 319 .Times(1); |
| 346 } | 320 } |
| 347 client_a_->resource_utilization_ = 0.5; | 321 client_a_->resource_utilization_ = 0.5; |
| 348 client_b_->resource_utilization_ = -1.0; | 322 client_b_->resource_utilization_ = -1.0; |
| 349 { | 323 { |
| 350 InSequence s; | 324 InSequence s; |
| 351 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer->id())) | 325 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer.id())) |
| 352 .Times(1); | 326 .Times(1); |
| 353 // Expect VideoCaptureController to call the load observer with a | 327 // Expect VideoCaptureController to call the load observer with a |
| 354 // resource utilization of 0.5 (the largest of all reported values). | 328 // resource utilization of 0.5 (the largest of all reported values). |
| 355 EXPECT_CALL(*mock_consumer_feedback_observer_, | 329 EXPECT_CALL(*mock_consumer_feedback_observer_, |
| 356 OnUtilizationReport(arbitrary_frame_feedback_id, 0.5)) | 330 OnUtilizationReport(arbitrary_frame_feedback_id, 0.5)) |
| 357 .Times(1); | 331 .Times(1); |
| 358 EXPECT_CALL(*mock_frame_receiver_observer_, ReleaseBufferHold(buffer->id())) | 332 EXPECT_CALL(*mock_frame_receiver_observer_, ReleaseBufferHold(buffer.id())) |
| 359 .Times(1); | 333 .Times(1); |
| 360 } | 334 } |
| 361 | 335 |
| 362 device_client_->OnIncomingCapturedBuffer(std::move(buffer), | 336 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, |
| 363 device_format, | 337 arbitrary_reference_time_, |
| 364 arbitrary_reference_time_, | 338 arbitrary_timestamp_); |
| 365 arbitrary_timestamp_); | |
| 366 | 339 |
| 367 base::RunLoop().RunUntilIdle(); | 340 base::RunLoop().RunUntilIdle(); |
| 368 Mock::VerifyAndClearExpectations(client_a_.get()); | 341 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 369 Mock::VerifyAndClearExpectations(client_b_.get()); | 342 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 370 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); | 343 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); |
| 371 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); | 344 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); |
| 372 | 345 |
| 373 // Second buffer which ought to use the same shared memory buffer. In this | 346 // Second buffer which ought to use the same shared memory buffer. In this |
| 374 // case pretend that the Buffer pointer is held by the device for a long | 347 // case pretend that the Buffer pointer is held by the device for a long |
| 375 // delay. This shouldn't affect anything. | 348 // delay. This shouldn't affect anything. |
| 376 const int arbitrary_frame_feedback_id_2 = 102; | 349 const int arbitrary_frame_feedback_id_2 = 102; |
| 377 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = | 350 media::VideoCaptureDevice::Client::Buffer buffer2 = |
| 378 device_client_->ReserveOutputBuffer(device_format.frame_size, | 351 device_client_->ReserveOutputBuffer( |
| 379 device_format.pixel_format, | 352 device_format.frame_size, device_format.pixel_format, |
| 380 device_format.pixel_storage, | 353 device_format.pixel_storage, arbitrary_frame_feedback_id_2); |
| 381 arbitrary_frame_feedback_id_2); | 354 ASSERT_TRUE(buffer2.is_valid()); |
| 382 ASSERT_TRUE(buffer2.get()); | 355 auto buffer2_access = |
| 383 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); | 356 buffer2.handle_provider()->GetHandleForInProcessAccess(); |
| 357 memset(buffer2_access->data(), buffer_no++, buffer2_access->mapped_size()); |
| 384 client_a_->resource_utilization_ = 0.5; | 358 client_a_->resource_utilization_ = 0.5; |
| 385 client_b_->resource_utilization_ = 3.14; | 359 client_b_->resource_utilization_ = 3.14; |
| 386 // Expect VideoCaptureController to call the load observer with a | 360 // Expect VideoCaptureController to call the load observer with a |
| 387 // resource utilization of 3.14 (the largest of all reported values). | 361 // resource utilization of 3.14 (the largest of all reported values). |
| 388 { | 362 { |
| 389 InSequence s; | 363 InSequence s; |
| 390 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer2->id())) | 364 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer2.id())) |
| 391 .Times(1); | 365 .Times(1); |
| 392 // Expect VideoCaptureController to call the load observer with a | 366 // Expect VideoCaptureController to call the load observer with a |
| 393 // resource utilization of 3.14 (the largest of all reported values). | 367 // resource utilization of 3.14 (the largest of all reported values). |
| 394 EXPECT_CALL(*mock_consumer_feedback_observer_, | 368 EXPECT_CALL(*mock_consumer_feedback_observer_, |
| 395 OnUtilizationReport(arbitrary_frame_feedback_id_2, 3.14)) | 369 OnUtilizationReport(arbitrary_frame_feedback_id_2, 3.14)) |
| 396 .Times(1); | 370 .Times(1); |
| 397 EXPECT_CALL(*mock_frame_receiver_observer_, | 371 EXPECT_CALL(*mock_frame_receiver_observer_, ReleaseBufferHold(buffer2.id())) |
| 398 ReleaseBufferHold(buffer2->id())) | |
| 399 .Times(1); | 372 .Times(1); |
| 400 } | 373 } |
| 401 | 374 |
| 402 device_client_->OnIncomingCapturedBuffer(std::move(buffer2), | 375 device_client_->OnIncomingCapturedBuffer(std::move(buffer2), device_format, |
| 403 device_format, | 376 arbitrary_reference_time_, |
| 404 arbitrary_reference_time_, | 377 arbitrary_timestamp_); |
| 405 arbitrary_timestamp_); | |
| 406 | 378 |
| 407 // The buffer should be delivered to the clients in any order. | 379 // The buffer should be delivered to the clients in any order. |
| 408 { | 380 { |
| 409 InSequence s; | 381 InSequence s; |
| 410 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 382 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
| 411 EXPECT_CALL(*client_a_, | 383 EXPECT_CALL(*client_a_, |
| 412 DoBufferReady(client_a_route_1, device_format.frame_size)) | 384 DoBufferReady(client_a_route_1, device_format.frame_size)) |
| 413 .Times(1); | 385 .Times(1); |
| 414 } | 386 } |
| 415 { | 387 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 426 DoBufferReady(client_a_route_2, device_format.frame_size)) | 398 DoBufferReady(client_a_route_2, device_format.frame_size)) |
| 427 .Times(1); | 399 .Times(1); |
| 428 } | 400 } |
| 429 base::RunLoop().RunUntilIdle(); | 401 base::RunLoop().RunUntilIdle(); |
| 430 Mock::VerifyAndClearExpectations(client_a_.get()); | 402 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 431 Mock::VerifyAndClearExpectations(client_b_.get()); | 403 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 432 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); | 404 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); |
| 433 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); | 405 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); |
| 434 | 406 |
| 435 // Add a fourth client now that some buffers have come through. | 407 // Add a fourth client now that some buffers have come through. |
| 436 controller_->AddClient(client_b_route_2, | 408 controller_->AddClient(client_b_route_2, client_b_.get(), 1, session_1); |
| 437 client_b_.get(), | |
| 438 1, | |
| 439 session_1); | |
| 440 Mock::VerifyAndClearExpectations(client_b_.get()); | 409 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 441 | 410 |
| 442 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 411 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
| 443 for (int i = 0; i < kPoolSize; i++) { | 412 for (int i = 0; i < kPoolSize; i++) { |
| 444 const int arbitrary_frame_feedback_id = 200 + i; | 413 const int arbitrary_frame_feedback_id = 200 + i; |
| 445 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 414 media::VideoCaptureDevice::Client::Buffer buffer = |
| 446 device_client_->ReserveOutputBuffer(device_format.frame_size, | 415 device_client_->ReserveOutputBuffer( |
| 447 device_format.pixel_format, | 416 device_format.frame_size, device_format.pixel_format, |
| 448 device_format.pixel_storage, | 417 device_format.pixel_storage, arbitrary_frame_feedback_id); |
| 449 arbitrary_frame_feedback_id); | 418 ASSERT_TRUE(buffer.is_valid()); |
| 450 ASSERT_TRUE(buffer.get()); | 419 auto buffer_access = |
| 451 memset(buffer->data(), buffer_no++, buffer->mapped_size()); | 420 buffer.handle_provider()->GetHandleForInProcessAccess(); |
| 452 device_client_->OnIncomingCapturedBuffer(std::move(buffer), | 421 memset(buffer_access->data(), buffer_no++, buffer_access->mapped_size()); |
| 453 device_format, | 422 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, |
| 454 arbitrary_reference_time_, | 423 arbitrary_reference_time_, |
| 455 arbitrary_timestamp_); | 424 arbitrary_timestamp_); |
| 456 } | 425 } |
| 457 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 426 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
| 458 ASSERT_FALSE(device_client_ | 427 ASSERT_FALSE(device_client_ |
| 459 ->ReserveOutputBuffer(device_format.frame_size, | 428 ->ReserveOutputBuffer( |
| 460 device_format.pixel_format, | 429 device_format.frame_size, device_format.pixel_format, |
| 461 device_format.pixel_storage, | 430 device_format.pixel_storage, arbitrary_frame_feedback_id) |
| 462 arbitrary_frame_feedback_id) | 431 .is_valid()); |
| 463 .get()); | |
| 464 | 432 |
| 465 // The new client needs to be notified of the creation of |kPoolSize| buffers; | 433 // The new client needs to be notified of the creation of |kPoolSize| buffers; |
| 466 // the old clients only |kPoolSize - 2|. | 434 // the old clients only |kPoolSize - 2|. |
| 467 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 435 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
| 468 EXPECT_CALL(*client_b_, | 436 EXPECT_CALL(*client_b_, |
| 469 DoBufferReady(client_b_route_2, device_format.frame_size)) | 437 DoBufferReady(client_b_route_2, device_format.frame_size)) |
| 470 .Times(kPoolSize); | 438 .Times(kPoolSize); |
| 471 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) | 439 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) |
| 472 .Times(kPoolSize - 2); | 440 .Times(kPoolSize - 2); |
| 473 EXPECT_CALL(*client_a_, | 441 EXPECT_CALL(*client_a_, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 487 Mock::VerifyAndClearExpectations(client_a_.get()); | 455 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 488 Mock::VerifyAndClearExpectations(client_b_.get()); | 456 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 489 | 457 |
| 490 // Now test the interaction of client shutdown and buffer delivery. | 458 // Now test the interaction of client shutdown and buffer delivery. |
| 491 // Kill A1 via renderer disconnect (synchronous). | 459 // Kill A1 via renderer disconnect (synchronous). |
| 492 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 460 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
| 493 // Kill B1 via session close (posts a task to disconnect). | 461 // Kill B1 via session close (posts a task to disconnect). |
| 494 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 462 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
| 495 controller_->StopSession(300); | 463 controller_->StopSession(300); |
| 496 // Queue up another buffer. | 464 // Queue up another buffer. |
| 497 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = | 465 media::VideoCaptureDevice::Client::Buffer buffer3 = |
| 498 device_client_->ReserveOutputBuffer(device_format.frame_size, | 466 device_client_->ReserveOutputBuffer( |
| 499 device_format.pixel_format, | 467 device_format.frame_size, device_format.pixel_format, |
| 500 device_format.pixel_storage, | 468 device_format.pixel_storage, arbitrary_frame_feedback_id); |
| 501 arbitrary_frame_feedback_id); | 469 ASSERT_TRUE(buffer3.is_valid()); |
| 502 ASSERT_TRUE(buffer3.get()); | 470 auto buffer3_access = |
| 503 memset(buffer3->data(), buffer_no++, buffer3->mapped_size()); | 471 buffer3.handle_provider()->GetHandleForInProcessAccess(); |
| 504 device_client_->OnIncomingCapturedBuffer(std::move(buffer3), | 472 memset(buffer3_access->data(), buffer_no++, buffer3_access->mapped_size()); |
| 505 device_format, | 473 device_client_->OnIncomingCapturedBuffer(std::move(buffer3), device_format, |
| 506 arbitrary_reference_time_, | 474 arbitrary_reference_time_, |
| 507 arbitrary_timestamp_); | 475 arbitrary_timestamp_); |
| 508 | 476 |
| 509 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = | 477 media::VideoCaptureDevice::Client::Buffer buffer4 = |
| 510 device_client_->ReserveOutputBuffer(device_format.frame_size, | 478 device_client_->ReserveOutputBuffer( |
| 511 device_format.pixel_format, | 479 device_format.frame_size, device_format.pixel_format, |
| 512 device_format.pixel_storage, | 480 device_format.pixel_storage, arbitrary_frame_feedback_id); |
| 513 arbitrary_frame_feedback_id); | |
| 514 { | 481 { |
| 515 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 482 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
| 516 // be sent either of these two buffers). | 483 // be sent either of these two buffers). |
| 517 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 484 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
| 518 controller_->StopSession(200); | 485 controller_->StopSession(200); |
| 519 } | 486 } |
| 520 ASSERT_TRUE(buffer4.get()); | 487 ASSERT_TRUE(buffer4.is_valid()); |
| 521 memset(buffer4->data(), buffer_no++, buffer4->mapped_size()); | 488 auto buffer4_access = |
| 522 device_client_->OnIncomingCapturedBuffer(std::move(buffer4), | 489 buffer4.handle_provider()->GetHandleForInProcessAccess(); |
| 523 device_format, | 490 memset(buffer4_access->data(), buffer_no++, buffer4_access->mapped_size()); |
| 524 arbitrary_reference_time_, | 491 device_client_->OnIncomingCapturedBuffer(std::move(buffer4), device_format, |
| 525 arbitrary_timestamp_); | 492 arbitrary_reference_time_, |
| 493 arbitrary_timestamp_); |
| 526 // B2 is the only client left, and is the only one that should | 494 // B2 is the only client left, and is the only one that should |
| 527 // get the buffer. | 495 // get the buffer. |
| 528 EXPECT_CALL(*client_b_, | 496 EXPECT_CALL(*client_b_, |
| 529 DoBufferReady(client_b_route_2, device_format.frame_size)) | 497 DoBufferReady(client_b_route_2, device_format.frame_size)) |
| 530 .Times(2); | 498 .Times(2); |
| 531 base::RunLoop().RunUntilIdle(); | 499 base::RunLoop().RunUntilIdle(); |
| 532 Mock::VerifyAndClearExpectations(client_a_.get()); | 500 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 533 Mock::VerifyAndClearExpectations(client_b_.get()); | 501 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 534 } | 502 } |
| 535 | 503 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 561 // Second client connects after the error state. It also should get told of | 529 // Second client connects after the error state. It also should get told of |
| 562 // the error. | 530 // the error. |
| 563 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 531 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 564 controller_->AddClient(route_id, client_b_.get(), 200, session_200); | 532 controller_->AddClient(route_id, client_b_.get(), 200, session_200); |
| 565 base::RunLoop().RunUntilIdle(); | 533 base::RunLoop().RunUntilIdle(); |
| 566 Mock::VerifyAndClearExpectations(client_b_.get()); | 534 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 567 | 535 |
| 568 media::VideoCaptureFormat device_format( | 536 media::VideoCaptureFormat device_format( |
| 569 capture_resolution, arbitrary_frame_rate_, media::PIXEL_FORMAT_I420, | 537 capture_resolution, arbitrary_frame_rate_, media::PIXEL_FORMAT_I420, |
| 570 media::PIXEL_STORAGE_CPU); | 538 media::PIXEL_STORAGE_CPU); |
| 571 const int arbitrary_frame_feedback_id = 101; | 539 const int arbitrary_frame_feedback_id = 101; |
| 572 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 540 media::VideoCaptureDevice::Client::Buffer buffer = |
| 573 device_client_->ReserveOutputBuffer(device_format.frame_size, | 541 device_client_->ReserveOutputBuffer( |
| 574 device_format.pixel_format, | 542 device_format.frame_size, device_format.pixel_format, |
| 575 device_format.pixel_storage, | 543 device_format.pixel_storage, arbitrary_frame_feedback_id); |
| 576 arbitrary_frame_feedback_id)); | 544 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, |
| 577 device_client_->OnIncomingCapturedBuffer(std::move(buffer), | 545 arbitrary_reference_time_, |
| 578 device_format, | 546 arbitrary_timestamp_); |
| 579 arbitrary_reference_time_, | |
| 580 arbitrary_timestamp_); | |
| 581 | 547 |
| 582 base::RunLoop().RunUntilIdle(); | 548 base::RunLoop().RunUntilIdle(); |
| 583 } | 549 } |
| 584 | 550 |
| 585 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 551 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| 586 // behavior of various operations after the error state has been signalled. | 552 // behavior of various operations after the error state has been signalled. |
| 587 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { | 553 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { |
| 588 media::VideoCaptureParams session_100; | 554 media::VideoCaptureParams session_100; |
| 589 session_100.requested_format = media::VideoCaptureFormat( | 555 session_100.requested_format = media::VideoCaptureFormat( |
| 590 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 556 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 591 | 557 |
| 592 media::VideoCaptureParams session_200 = session_100; | 558 media::VideoCaptureParams session_200 = session_100; |
| 593 | 559 |
| 594 const VideoCaptureControllerID route_id(0x99); | 560 const VideoCaptureControllerID route_id(0x99); |
| 595 | 561 |
| 596 // Start with one client. | 562 // Start with one client. |
| 597 controller_->AddClient(route_id, client_a_.get(), 100, session_100); | 563 controller_->AddClient(route_id, client_a_.get(), 100, session_100); |
| 598 | 564 |
| 599 // Start the device. Then, before the first buffer, signal an error and | 565 // Start the device. Then, before the first buffer, signal an error and |
| 600 // deliver the buffer. The error should be propagated to clients; the buffer | 566 // deliver the buffer. The error should be propagated to clients; the buffer |
| 601 // should not be. | 567 // should not be. |
| 602 base::RunLoop().RunUntilIdle(); | 568 base::RunLoop().RunUntilIdle(); |
| 603 Mock::VerifyAndClearExpectations(client_a_.get()); | 569 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 604 | 570 |
| 605 media::VideoCaptureFormat device_format( | 571 media::VideoCaptureFormat device_format( |
| 606 gfx::Size(10, 10), arbitrary_frame_rate_, media::PIXEL_FORMAT_I420); | 572 gfx::Size(10, 10), arbitrary_frame_rate_, media::PIXEL_FORMAT_I420); |
| 607 const int arbitrary_frame_feedback_id = 101; | 573 const int arbitrary_frame_feedback_id = 101; |
| 608 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 574 media::VideoCaptureDevice::Client::Buffer buffer = |
| 609 device_client_->ReserveOutputBuffer(device_format.frame_size, | 575 device_client_->ReserveOutputBuffer( |
| 610 device_format.pixel_format, | 576 device_format.frame_size, device_format.pixel_format, |
| 611 device_format.pixel_storage, | 577 device_format.pixel_storage, arbitrary_frame_feedback_id); |
| 612 arbitrary_frame_feedback_id)); | 578 ASSERT_TRUE(buffer.is_valid()); |
| 613 ASSERT_TRUE(buffer.get()); | |
| 614 | 579 |
| 615 device_client_->OnError(FROM_HERE, "Test Error"); | 580 device_client_->OnError(FROM_HERE, "Test Error"); |
| 616 device_client_->OnIncomingCapturedBuffer(std::move(buffer), | 581 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, |
| 617 device_format, | 582 arbitrary_reference_time_, |
| 618 arbitrary_reference_time_, | 583 arbitrary_timestamp_); |
| 619 arbitrary_timestamp_); | |
| 620 | 584 |
| 621 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 585 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
| 622 base::RunLoop().RunUntilIdle(); | 586 base::RunLoop().RunUntilIdle(); |
| 623 Mock::VerifyAndClearExpectations(client_a_.get()); | 587 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 624 | 588 |
| 625 // Second client connects after the error state. It also should get told of | 589 // Second client connects after the error state. It also should get told of |
| 626 // the error. | 590 // the error. |
| 627 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 591 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 628 controller_->AddClient(route_id, client_b_.get(), 200, session_200); | 592 controller_->AddClient(route_id, client_b_.get(), 200, session_200); |
| 629 Mock::VerifyAndClearExpectations(client_b_.get()); | 593 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 630 } | 594 } |
| 631 | 595 |
| 632 } // namespace content | 596 } // namespace content |
| OLD | NEW |