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

Side by Side Diff: content/browser/renderer_host/media/video_capture_host_unittest.cc

Issue 955253002: Add metadata to media::VideoFrame and plumb it through IPC/MediaStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tommi's nits addressed Created 5 years, 9 months 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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // Define to enable test where video is dumped to file. 57 // Define to enable test where video is dumped to file.
58 // #define DUMP_VIDEO 58 // #define DUMP_VIDEO
59 59
60 // Define to use a real video capture device. 60 // Define to use a real video capture device.
61 // #define TEST_REAL_CAPTURE_DEVICE 61 // #define TEST_REAL_CAPTURE_DEVICE
62 62
63 // Simple class used for dumping video to a file. This can be used for 63 // Simple class used for dumping video to a file. This can be used for
64 // verifying the output. 64 // verifying the output.
65 class DumpVideo { 65 class DumpVideo {
66 public: 66 public:
67 DumpVideo() : expected_size_(0) {} 67 DumpVideo() {}
68 void StartDump(int width, int height) { 68 const gfx::Size& coded_size() const { return coded_size_; }
69 void StartDump(const gfx::Size& coded_size) {
69 base::FilePath file_name = base::FilePath(base::StringPrintf( 70 base::FilePath file_name = base::FilePath(base::StringPrintf(
70 FILE_PATH_LITERAL("dump_w%d_h%d.yuv"), width, height)); 71 FILE_PATH_LITERAL("dump_w%d_h%d.yuv"),
72 coded_size.width(),
73 coded_size.height()));
71 file_.reset(base::OpenFile(file_name, "wb")); 74 file_.reset(base::OpenFile(file_name, "wb"));
72 expected_size_ = media::VideoFrame::AllocationSize( 75 coded_size_ = coded_size;
73 media::VideoFrame::I420, gfx::Size(width, height));
74 } 76 }
75 void NewVideoFrame(const void* buffer) { 77 void NewVideoFrame(const void* buffer) {
76 if (file_.get() != NULL) { 78 if (file_.get() != NULL) {
77 ASSERT_EQ(1U, fwrite(buffer, expected_size_, 1, file_.get())); 79 const int size = media::VideoFrame::AllocationSize(
80 media::VideoFrame::I420, coded_size_);
81 ASSERT_EQ(1U, fwrite(buffer, size, 1, file_.get()));
78 } 82 }
79 } 83 }
80 84
81 private: 85 private:
82 base::ScopedFILE file_; 86 base::ScopedFILE file_;
83 int expected_size_; 87 gfx::Size coded_size_;
84 }; 88 };
85 89
86 class MockMediaStreamRequester : public MediaStreamRequester { 90 class MockMediaStreamRequester : public MediaStreamRequester {
87 public: 91 public:
88 MockMediaStreamRequester() {} 92 MockMediaStreamRequester() {}
89 virtual ~MockMediaStreamRequester() {} 93 virtual ~MockMediaStreamRequester() {}
90 94
91 // MediaStreamRequester implementation. 95 // MediaStreamRequester implementation.
92 MOCK_METHOD5(StreamGenerated, 96 MOCK_METHOD5(StreamGenerated,
93 void(int render_frame_id, 97 void(int render_frame_id,
(...skipping 29 matching lines...) Expand all
123 dump_video_(false) {} 127 dump_video_(false) {}
124 128
125 // A list of mock methods. 129 // A list of mock methods.
126 MOCK_METHOD4(OnNewBufferCreated, 130 MOCK_METHOD4(OnNewBufferCreated,
127 void(int device_id, 131 void(int device_id,
128 base::SharedMemoryHandle handle, 132 base::SharedMemoryHandle handle,
129 int length, 133 int length,
130 int buffer_id)); 134 int buffer_id));
131 MOCK_METHOD2(OnBufferFreed, 135 MOCK_METHOD2(OnBufferFreed,
132 void(int device_id, int buffer_id)); 136 void(int device_id, int buffer_id));
133 MOCK_METHOD5(OnBufferFilled, 137 MOCK_METHOD6(OnBufferFilled,
134 void(int device_id, 138 void(int device_id,
135 int buffer_id, 139 int buffer_id,
136 const media::VideoCaptureFormat& format, 140 const gfx::Size& coded_size,
137 const gfx::Rect& visible_rect, 141 const gfx::Rect& visible_rect,
138 base::TimeTicks timestamp)); 142 base::TimeTicks timestamp,
139 MOCK_METHOD5(OnMailboxBufferFilled, 143 const base::DictionaryValue& metadata));
144 MOCK_METHOD6(OnMailboxBufferFilled,
140 void(int device_id, 145 void(int device_id,
141 int buffer_id, 146 int buffer_id,
142 const gpu::MailboxHolder& mailbox_holder, 147 const gpu::MailboxHolder& mailbox_holder,
143 const media::VideoCaptureFormat& format, 148 const gfx::Size& packed_frame_size,
144 base::TimeTicks timestamp)); 149 base::TimeTicks timestamp,
150 const base::DictionaryValue& metadata));
145 MOCK_METHOD2(OnStateChanged, void(int device_id, VideoCaptureState state)); 151 MOCK_METHOD2(OnStateChanged, void(int device_id, VideoCaptureState state));
146 152
147 // Use class DumpVideo to write I420 video to file. 153 // Use class DumpVideo to write I420 video to file.
148 void SetDumpVideo(bool enable) { 154 void SetDumpVideo(bool enable) {
149 dump_video_ = enable; 155 dump_video_ = enable;
150 } 156 }
151 157
152 void SetReturnReceivedDibs(bool enable) { 158 void SetReturnReceivedDibs(bool enable) {
153 return_buffers_ = enable; 159 return_buffers_ = enable;
154 } 160 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 void OnBufferFreedDispatch(int device_id, int buffer_id) { 223 void OnBufferFreedDispatch(int device_id, int buffer_id) {
218 OnBufferFreed(device_id, buffer_id); 224 OnBufferFreed(device_id, buffer_id);
219 225
220 std::map<int, base::SharedMemory*>::iterator it = 226 std::map<int, base::SharedMemory*>::iterator it =
221 filled_dib_.find(buffer_id); 227 filled_dib_.find(buffer_id);
222 ASSERT_TRUE(it != filled_dib_.end()); 228 ASSERT_TRUE(it != filled_dib_.end());
223 delete it->second; 229 delete it->second;
224 filled_dib_.erase(it); 230 filled_dib_.erase(it);
225 } 231 }
226 232
227 void OnBufferFilledDispatch(int device_id, 233 void OnBufferFilledDispatch(
228 int buffer_id, 234 const VideoCaptureMsg_BufferReady_Params& params) {
229 const media::VideoCaptureFormat& frame_format, 235 base::SharedMemory* dib = filled_dib_[params.buffer_id];
230 const gfx::Rect& visible_rect,
231 base::TimeTicks timestamp) {
232 base::SharedMemory* dib = filled_dib_[buffer_id];
233 ASSERT_TRUE(dib != NULL); 236 ASSERT_TRUE(dib != NULL);
234 if (dump_video_) { 237 if (dump_video_) {
235 if (!format_.IsValid()) { 238 if (dumper_.coded_size().IsEmpty())
236 dumper_.StartDump(frame_format.frame_size.width(), 239 dumper_.StartDump(params.coded_size);
237 frame_format.frame_size.height()); 240 ASSERT_TRUE(dumper_.coded_size() == params.coded_size)
238 format_ = frame_format;
239 }
240 ASSERT_EQ(format_.frame_size.width(), frame_format.frame_size.width())
241 << "Dump format does not handle variable resolution.";
242 ASSERT_EQ(format_.frame_size.height(), frame_format.frame_size.height())
243 << "Dump format does not handle variable resolution."; 241 << "Dump format does not handle variable resolution.";
244 dumper_.NewVideoFrame(dib->memory()); 242 dumper_.NewVideoFrame(dib->memory());
245 } 243 }
246 244
247 OnBufferFilled(device_id, buffer_id, frame_format, visible_rect, timestamp); 245 OnBufferFilled(params.device_id, params.buffer_id, params.coded_size,
246 params.visible_rect, params.timestamp, params.metadata);
248 if (return_buffers_) { 247 if (return_buffers_) {
249 VideoCaptureHost::OnReceiveEmptyBuffer(device_id, buffer_id, 0); 248 VideoCaptureHost::OnReceiveEmptyBuffer(
249 params.device_id, params.buffer_id, 0);
250 } 250 }
251 } 251 }
252 252
253 void OnMailboxBufferFilledDispatch(int device_id, 253 void OnMailboxBufferFilledDispatch(
254 int buffer_id, 254 const VideoCaptureMsg_MailboxBufferReady_Params& params) {
255 const gpu::MailboxHolder& mailbox_holder, 255 OnMailboxBufferFilled(params.device_id, params.buffer_id,
256 const media::VideoCaptureFormat& format, 256 params.mailbox_holder, params.packed_frame_size,
257 base::TimeTicks timestamp) { 257 params.timestamp, params.metadata);
258 OnMailboxBufferFilled(
259 device_id, buffer_id, mailbox_holder, format, timestamp);
260 if (return_buffers_) { 258 if (return_buffers_) {
261 VideoCaptureHost::OnReceiveEmptyBuffer(device_id, buffer_id, 0); 259 VideoCaptureHost::OnReceiveEmptyBuffer(
260 params.device_id, params.buffer_id, 0);
262 } 261 }
263 } 262 }
264 263
265 void OnStateChangedDispatch(int device_id, VideoCaptureState state) { 264 void OnStateChangedDispatch(int device_id, VideoCaptureState state) {
266 OnStateChanged(device_id, state); 265 OnStateChanged(device_id, state);
267 } 266 }
268 267
269 std::map<int, base::SharedMemory*> filled_dib_; 268 std::map<int, base::SharedMemory*> filled_dib_;
270 bool return_buffers_; 269 bool return_buffers_;
271 bool dump_video_; 270 bool dump_video_;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 opened_session_id_ = kInvalidMediaCaptureSessionId; 399 opened_session_id_ = kInvalidMediaCaptureSessionId;
401 } 400 }
402 401
403 protected: 402 protected:
404 void StartCapture() { 403 void StartCapture() {
405 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) 404 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _))
406 .Times(AnyNumber()) 405 .Times(AnyNumber())
407 .WillRepeatedly(Return()); 406 .WillRepeatedly(Return());
408 407
409 base::RunLoop run_loop; 408 base::RunLoop run_loop;
410 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _, _)) 409 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _, _, _))
411 .Times(AnyNumber()) 410 .Times(AnyNumber())
412 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); 411 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure()));
413 412
414 media::VideoCaptureParams params; 413 media::VideoCaptureParams params;
415 params.requested_format = media::VideoCaptureFormat( 414 params.requested_format = media::VideoCaptureFormat(
416 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420); 415 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420);
417 host_->OnStartCapture(kDeviceId, opened_session_id_, params); 416 host_->OnStartCapture(kDeviceId, opened_session_id_, params);
418 run_loop.Run(); 417 run_loop.Run();
419 } 418 }
420 419
(...skipping 13 matching lines...) Expand all
434 WaitForVideoDeviceThread(); 433 WaitForVideoDeviceThread();
435 } 434 }
436 435
437 #ifdef DUMP_VIDEO 436 #ifdef DUMP_VIDEO
438 void CaptureAndDumpVideo(int width, int height, int frame_rate) { 437 void CaptureAndDumpVideo(int width, int height, int frame_rate) {
439 InSequence s; 438 InSequence s;
440 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) 439 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _))
441 .Times(AnyNumber()).WillRepeatedly(Return()); 440 .Times(AnyNumber()).WillRepeatedly(Return());
442 441
443 base::RunLoop run_loop; 442 base::RunLoop run_loop;
444 EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _, _, _)) 443 EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _, _, _, _))
445 .Times(AnyNumber()) 444 .Times(AnyNumber())
446 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); 445 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure()));
447 446
448 media::VideoCaptureParams params; 447 media::VideoCaptureParams params;
449 params.requested_format = 448 params.requested_format =
450 media::VideoCaptureFormat(gfx::Size(width, height), frame_rate); 449 media::VideoCaptureFormat(gfx::Size(width, height), frame_rate);
451 host_->SetDumpVideo(true); 450 host_->SetDumpVideo(true);
452 host_->OnStartCapture(kDeviceId, opened_session_id_, params); 451 host_->OnStartCapture(kDeviceId, opened_session_id_, params);
453 run_loop.Run(); 452 run_loop.Run();
454 } 453 }
(...skipping 11 matching lines...) Expand all
466 465
467 run_loop.Run(); 466 run_loop.Run();
468 467
469 host_->SetReturnReceivedDibs(false); 468 host_->SetReturnReceivedDibs(false);
470 // Expect the VideoCaptureDevice has been stopped 469 // Expect the VideoCaptureDevice has been stopped
471 EXPECT_EQ(0u, host_->entries_.size()); 470 EXPECT_EQ(0u, host_->entries_.size());
472 } 471 }
473 472
474 void NotifyPacketReady() { 473 void NotifyPacketReady() {
475 base::RunLoop run_loop; 474 base::RunLoop run_loop;
476 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _, _)) 475 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _, _, _))
477 .Times(AnyNumber()) 476 .Times(AnyNumber())
478 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())) 477 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure()))
479 .RetiresOnSaturation(); 478 .RetiresOnSaturation();
480 run_loop.Run(); 479 run_loop.Run();
481 } 480 }
482 481
483 void ReturnReceivedPackets() { 482 void ReturnReceivedPackets() {
484 host_->ReturnReceivedDibs(kDeviceId); 483 host_->ReturnReceivedDibs(kDeviceId);
485 } 484 }
486 485
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 #ifdef DUMP_VIDEO 560 #ifdef DUMP_VIDEO
562 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { 561 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) {
563 CaptureAndDumpVideo(640, 480, 30); 562 CaptureAndDumpVideo(640, 480, 30);
564 } 563 }
565 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { 564 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) {
566 CaptureAndDumpVideo(1280, 720, 30); 565 CaptureAndDumpVideo(1280, 720, 30);
567 } 566 }
568 #endif 567 #endif
569 568
570 } // namespace content 569 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698