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

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

Issue 1439533004: Remove dead code paths around PIXEL_STORAGE_TEXTURE in capture pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mcasas's second round comments REBASE Created 5 years, 1 month 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
OLDNEW
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 #include "base/memory/shared_memory.h" 5 #include "base/memory/shared_memory.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "content/child/child_process.h" 7 #include "content/child/child_process.h"
8 #include "content/common/media/video_capture_messages.h" 8 #include "content/common/media/video_capture_messages.h"
9 #include "content/renderer/media/video_capture_impl.h" 9 #include "content/renderer/media/video_capture_impl.h"
10 #include "media/base/bind_to_current_loop.h" 10 #include "media/base/bind_to_current_loop.h"
(...skipping 15 matching lines...) Expand all
26 // Filter implementation. 26 // Filter implementation.
27 MOCK_METHOD1(Send, bool(IPC::Message* message)); 27 MOCK_METHOD1(Send, bool(IPC::Message* message));
28 28
29 protected: 29 protected:
30 virtual ~MockVideoCaptureMessageFilter() {} 30 virtual ~MockVideoCaptureMessageFilter() {}
31 31
32 private: 32 private:
33 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter); 33 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter);
34 }; 34 };
35 35
36 struct BufferReceivedTestArg { 36 class VideoCaptureImplTest : public ::testing::Test {
37 BufferReceivedTestArg(media::VideoPixelFormat pixel_format,
38 const gpu::MailboxHolder& holder)
39 : pixel_format(pixel_format), mailbox_holder(holder) {}
40
41 BufferReceivedTestArg(media::VideoPixelFormat pixel_format)
42 : pixel_format(pixel_format) {}
43
44 media::VideoPixelFormat pixel_format;
45 gpu::MailboxHolder mailbox_holder;
46 };
47
48 static const BufferReceivedTestArg kBufferFormats[] = {
49 BufferReceivedTestArg(media::PIXEL_FORMAT_I420),
50 BufferReceivedTestArg(
51 media::PIXEL_FORMAT_ARGB,
52 gpu::MailboxHolder(gpu::Mailbox::Generate(), gpu::SyncToken(), 0))};
53
54 class VideoCaptureImplTest
55 : public ::testing::TestWithParam<BufferReceivedTestArg> {
56 public: 37 public:
57 class MockVideoCaptureImpl : public VideoCaptureImpl { 38 class MockVideoCaptureImpl : public VideoCaptureImpl {
58 public: 39 public:
59 MockVideoCaptureImpl(const media::VideoCaptureSessionId id, 40 MockVideoCaptureImpl(const media::VideoCaptureSessionId id,
60 VideoCaptureMessageFilter* filter) 41 VideoCaptureMessageFilter* filter)
61 : VideoCaptureImpl(id, filter), received_buffer_count_(0) {} 42 : VideoCaptureImpl(id, filter), received_buffer_count_(0) {}
62 ~MockVideoCaptureImpl() override {} 43 ~MockVideoCaptureImpl() override {}
63 44
64 // Override Send() to mimic device to send events. 45 // Override Send() to mimic device to send events.
65 void Send(IPC::Message* message) override { 46 void Send(IPC::Message* message) override {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 void StopCapture(int client_id) { 157 void StopCapture(int client_id) {
177 video_capture_impl_->StopCapture(client_id); 158 video_capture_impl_->StopCapture(client_id);
178 } 159 }
179 160
180 void NewBuffer(int buffer_id, const base::SharedMemory& shm) { 161 void NewBuffer(int buffer_id, const base::SharedMemory& shm) {
181 video_capture_impl_->OnBufferCreated( 162 video_capture_impl_->OnBufferCreated(
182 base::SharedMemory::DuplicateHandle(shm.handle()), 163 base::SharedMemory::DuplicateHandle(shm.handle()),
183 shm.mapped_size(), buffer_id); 164 shm.mapped_size(), buffer_id);
184 } 165 }
185 166
186 void BufferReceived(int buffer_id, const gfx::Size& size, 167 void BufferReceived(int buffer_id, const gfx::Size& size) {
187 media::VideoPixelFormat pixel_format,
188 const gpu::MailboxHolder& mailbox_holder) {
189 const media::VideoFrame::StorageType storage_type =
190 pixel_format != media::PIXEL_FORMAT_ARGB
191 ? media::VideoFrame::STORAGE_UNOWNED_MEMORY
192 : media::VideoFrame::STORAGE_OPAQUE;
193 video_capture_impl_->OnBufferReceived( 168 video_capture_impl_->OnBufferReceived(
194 buffer_id, base::TimeTicks::Now(), base::DictionaryValue(), 169 buffer_id, base::TimeTicks::Now(), base::DictionaryValue(),
195 pixel_format, storage_type, size, gfx::Rect(size), mailbox_holder); 170 media::PIXEL_FORMAT_I420, media::VideoFrame::STORAGE_SHMEM, size,
171 gfx::Rect(size));
196 } 172 }
197 173
198 void BufferDestroyed(int buffer_id) { 174 void BufferDestroyed(int buffer_id) {
199 video_capture_impl_->OnBufferDestroyed(buffer_id); 175 video_capture_impl_->OnBufferDestroyed(buffer_id);
200 } 176 }
201 177
202 void DeInit() { 178 void DeInit() {
203 video_capture_impl_->DeInit(); 179 video_capture_impl_->DeInit();
204 } 180 }
205 181
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // Check that a request to GetDeviceFormatsInUse() ends up eventually in the 278 // Check that a request to GetDeviceFormatsInUse() ends up eventually in the
303 // provided callback. 279 // provided callback.
304 TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) { 280 TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) {
305 EXPECT_CALL(*this, OnDeviceFormatsInUse(_)); 281 EXPECT_CALL(*this, OnDeviceFormatsInUse(_));
306 282
307 Init(); 283 Init();
308 GetDeviceFormatsInUse(); 284 GetDeviceFormatsInUse();
309 DeInit(); 285 DeInit();
310 } 286 }
311 287
312 TEST_P(VideoCaptureImplTest, BufferReceivedWithFormat) { 288 TEST_F(VideoCaptureImplTest, BufferReceived) {
313 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(1); 289 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(1);
314 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(1); 290 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(1);
315 EXPECT_CALL(*this, OnFrameReady(_, _)).Times(1); 291 EXPECT_CALL(*this, OnFrameReady(_, _)).Times(1);
316 292
317 const BufferReceivedTestArg& buffer_arg = GetParam();
318 const gfx::Size size(1280, 720); 293 const gfx::Size size(1280, 720);
319 294
320 // Create a fake shared memory for buffer. 295 // Create a fake shared memory for buffer.
321 base::SharedMemory shm; 296 base::SharedMemory shm;
322 const size_t frame_size = media::VideoFrame::AllocationSize( 297 const size_t frame_size = media::VideoFrame::AllocationSize(
323 buffer_arg.pixel_format, size); 298 media::PIXEL_FORMAT_I420, size);
324 ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size)); 299 ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size));
325 300
326 media::VideoCaptureParams params; 301 media::VideoCaptureParams params;
327 params.requested_format = media::VideoCaptureFormat( 302 params.requested_format = media::VideoCaptureFormat(
328 size, 30, buffer_arg.pixel_format); 303 size, 30, media::PIXEL_FORMAT_I420);
329 304
330 Init(); 305 Init();
331 StartCapture(0, params); 306 StartCapture(0, params);
332 NewBuffer(0, shm); 307 NewBuffer(0, shm);
333 BufferReceived(0, size, buffer_arg.pixel_format, buffer_arg.mailbox_holder); 308 BufferReceived(0, size);
334 StopCapture(0); 309 StopCapture(0);
335 BufferDestroyed(0); 310 BufferDestroyed(0);
336 DeInit(); 311 DeInit();
337 } 312 }
338 313
339 INSTANTIATE_TEST_CASE_P(I420AndARGB,
340 VideoCaptureImplTest,
341 testing::ValuesIn(kBufferFormats));
342
343 TEST_F(VideoCaptureImplTest, BufferReceivedAfterStop) { 314 TEST_F(VideoCaptureImplTest, BufferReceivedAfterStop) {
344 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(1); 315 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(1);
345 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(1); 316 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(1);
346 EXPECT_CALL(*this, OnFrameReady(_, _)).Times(0); 317 EXPECT_CALL(*this, OnFrameReady(_, _)).Times(0);
347 318
348 // Create a fake shared memory for buffer. 319 // Create a fake shared memory for buffer.
349 base::SharedMemory shm; 320 base::SharedMemory shm;
350 const size_t i420_frame_size = media::VideoFrame::AllocationSize( 321 const size_t i420_frame_size = media::VideoFrame::AllocationSize(
351 media::PIXEL_FORMAT_I420, params_large_.requested_format.frame_size); 322 media::PIXEL_FORMAT_I420, params_large_.requested_format.frame_size);
352 ASSERT_TRUE(shm.CreateAndMapAnonymous(i420_frame_size)); 323 ASSERT_TRUE(shm.CreateAndMapAnonymous(i420_frame_size));
353 324
354 Init(); 325 Init();
355 StartCapture(0, params_large_); 326 StartCapture(0, params_large_);
356 NewBuffer(0, shm); 327 NewBuffer(0, shm);
357 StopCapture(0); 328 StopCapture(0);
358 BufferReceived(0, params_large_.requested_format.frame_size, 329 BufferReceived(0, params_large_.requested_format.frame_size);
359 media::PIXEL_FORMAT_I420, gpu::MailboxHolder());
360 BufferDestroyed(0); 330 BufferDestroyed(0);
361 DeInit(); 331 DeInit();
362 332
363 EXPECT_EQ(this->video_capture_impl_->received_buffer_count(), 1); 333 EXPECT_EQ(this->video_capture_impl_->received_buffer_count(), 1);
364 } 334 }
365 335
366 TEST_F(VideoCaptureImplTest, AlreadyStarted) { 336 TEST_F(VideoCaptureImplTest, AlreadyStarted) {
367 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); 337 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2);
368 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); 338 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2);
369 339
(...skipping 29 matching lines...) Expand all
399 StartCapture(0, params_small_); 369 StartCapture(0, params_small_);
400 370
401 // Receive state change message from browser. 371 // Receive state change message from browser.
402 video_capture_impl_->ReceiveStateChangeMessage(VIDEO_CAPTURE_STATE_ERROR); 372 video_capture_impl_->ReceiveStateChangeMessage(VIDEO_CAPTURE_STATE_ERROR);
403 373
404 StopCapture(0); 374 StopCapture(0);
405 DeInit(); 375 DeInit();
406 } 376 }
407 377
408 } // namespace content 378 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.cc ('k') | content/renderer/media/video_capture_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698