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

Unified Diff: services/video_capture/test/fake_device_unittest.cc

Issue 2818513003: [Mojo Video Capture] Adapt video_capture service to refactored video capture stack (Closed)
Patch Set: Fix compile errors Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: services/video_capture/test/fake_device_unittest.cc
diff --git a/services/video_capture/test/fake_device_unittest.cc b/services/video_capture/test/fake_device_unittest.cc
index 6550909bc9425d510c498911b25ba63e8fdbbb81..ee2d651830e5a4b8c954e65b7062267e970b594c 100644
--- a/services/video_capture/test/fake_device_unittest.cc
+++ b/services/video_capture/test/fake_device_unittest.cc
@@ -12,6 +12,7 @@
#include "services/video_capture/test/mock_receiver.h"
using testing::_;
+using testing::AtLeast;
using testing::Invoke;
using testing::InvokeWithoutArgs;
@@ -20,7 +21,7 @@ namespace {
struct FrameInfo {
gfx::Size size;
media::VideoPixelFormat pixel_format;
- media::VideoFrame::StorageType storage_type;
+ media::VideoPixelStorage storage_type;
base::TimeDelta timestamp;
};
@@ -32,23 +33,23 @@ namespace video_capture {
// TODO(rockot/chfremer): Consider just renaming the type.
using FakeVideoCaptureDeviceTest = FakeDeviceTest;
-TEST_F(FakeVideoCaptureDeviceTest, DISABLED_FrameCallbacksArrive) {
+TEST_F(FakeVideoCaptureDeviceTest, FrameCallbacksArrive) {
base::RunLoop wait_loop;
- // These two constants must be static as a workaround
+ // Constants must be static as a workaround
// for a MSVC++ bug about lambda captures, see the discussion at
// https://social.msdn.microsoft.com/Forums/SqlServer/4abf18bd-4ae4-4c72-ba3e-3b13e7909d5f
static const int kNumFramesToWaitFor = 3;
int num_frames_arrived = 0;
mojom::ReceiverPtr receiver_proxy;
MockReceiver receiver(mojo::MakeRequest(&receiver_proxy));
- EXPECT_CALL(receiver, OnIncomingCapturedVideoFramePtr(_))
- .WillRepeatedly(InvokeWithoutArgs(
- [&wait_loop, &num_frames_arrived]() {
- num_frames_arrived += 1;
- if (num_frames_arrived >= kNumFramesToWaitFor) {
- wait_loop.Quit();
- }
- }));
+ EXPECT_CALL(receiver, DoOnNewBufferHandle(_, _)).Times(AtLeast(1));
+ EXPECT_CALL(receiver, DoOnFrameReadyInBuffer(_, _, _, _))
+ .WillRepeatedly(InvokeWithoutArgs([&wait_loop, &num_frames_arrived]() {
+ num_frames_arrived += 1;
+ if (num_frames_arrived >= kNumFramesToWaitFor) {
+ wait_loop.Quit();
+ }
+ }));
fake_device_proxy_->Start(requestable_settings_, std::move(receiver_proxy));
wait_loop.Run();
@@ -56,29 +57,31 @@ TEST_F(FakeVideoCaptureDeviceTest, DISABLED_FrameCallbacksArrive) {
// Tests that frames received from a fake capture device match the requested
// format and have increasing timestamps.
-TEST_F(FakeVideoCaptureDeviceTest,
- DISABLED_ReceiveFramesFromFakeCaptureDevice) {
+TEST_F(FakeVideoCaptureDeviceTest, ReceiveFramesFromFakeCaptureDevice) {
base::RunLoop wait_loop;
mojom::ReceiverPtr receiver_proxy;
- // These two constants must be static as a workaround
+ // Constants must be static as a workaround
// for a MSVC++ bug about lambda captures, see the discussion at
// https://social.msdn.microsoft.com/Forums/SqlServer/4abf18bd-4ae4-4c72-ba3e-3b13e7909d5f
static const int num_frames_to_receive = 2;
FrameInfo received_frame_infos[num_frames_to_receive];
int received_frame_count = 0;
MockReceiver receiver(mojo::MakeRequest(&receiver_proxy));
- EXPECT_CALL(receiver, OnIncomingCapturedVideoFramePtr(_))
- .WillRepeatedly(Invoke(
- [&received_frame_infos, &received_frame_count, &wait_loop]
- (const media::mojom::VideoFramePtr* frame) {
+ EXPECT_CALL(receiver, DoOnNewBufferHandle(_, _)).Times(AtLeast(1));
+ EXPECT_CALL(receiver, DoOnFrameReadyInBuffer(_, _, _, _))
+ .WillRepeatedly(
+ Invoke([&received_frame_infos, &received_frame_count, &wait_loop](
+ int32_t buffer_id, int32_t frame_feedback_id,
+ mojom::ScopedAccessPermissionPtr* access_permission,
+ media::mojom::VideoFrameInfoPtr* frame_info) {
if (received_frame_count >= num_frames_to_receive)
return;
- auto video_frame = frame->To<scoped_refptr<media::VideoFrame>>();
- auto& frame_info = received_frame_infos[received_frame_count];
- frame_info.pixel_format = video_frame->format();
- frame_info.storage_type = video_frame->storage_type();
- frame_info.size = video_frame->natural_size();
- frame_info.timestamp = video_frame->timestamp();
+ auto& received_frame_info =
+ received_frame_infos[received_frame_count];
+ received_frame_info.pixel_format = (*frame_info)->pixel_format;
+ received_frame_info.storage_type = (*frame_info)->storage_type;
+ received_frame_info.size = (*frame_info)->coded_size;
+ received_frame_info.timestamp = (*frame_info)->timestamp;
received_frame_count += 1;
if (received_frame_count == num_frames_to_receive)
wait_loop.Quit();
@@ -93,9 +96,10 @@ TEST_F(FakeVideoCaptureDeviceTest,
auto& frame_info = received_frame_infos[i];
// Service is expected to always output I420
EXPECT_EQ(media::PIXEL_FORMAT_I420, frame_info.pixel_format);
- // Service is expected to always use STORAGE_MOJO_SHARED_BUFFER
- EXPECT_EQ(media::VideoFrame::STORAGE_MOJO_SHARED_BUFFER,
- frame_info.storage_type);
+ // Service is expected to always use PIXEL_STORAGE_CPU
+ EXPECT_EQ(media::PIXEL_STORAGE_CPU, frame_info.storage_type);
+ EXPECT_EQ(requestable_settings_.requested_format.frame_size,
+ frame_info.size);
// Timestamps are expected to increase
if (i > 0)
EXPECT_GT(frame_info.timestamp, previous_timestamp);
@@ -103,4 +107,35 @@ TEST_F(FakeVideoCaptureDeviceTest,
}
}
+// Tests that buffers get reused when receiving more frames than the maximum
+// number of buffers in the pool.
+TEST_F(FakeVideoCaptureDeviceTest, BuffersGetReused) {
+ base::RunLoop wait_loop;
+ const int kMaxBufferPoolBuffers =
+ DeviceMediaToMojoAdapter::max_buffer_pool_buffer_count();
+ // Constants must be static as a workaround
+ // for a MSVC++ bug about lambda captures, see the discussion at
+ // https://social.msdn.microsoft.com/Forums/SqlServer/4abf18bd-4ae4-4c72-ba3e-3b13e7909d5f
+ static const int kNumFramesToWaitFor = kMaxBufferPoolBuffers + 3;
+ int num_buffers_created = 0;
+ int num_frames_arrived = 0;
+ mojom::ReceiverPtr receiver_proxy;
+ MockReceiver receiver(mojo::MakeRequest(&receiver_proxy));
+ EXPECT_CALL(receiver, DoOnNewBufferHandle(_, _))
+ .WillRepeatedly(InvokeWithoutArgs(
+ [&num_buffers_created]() { num_buffers_created++; }));
+ EXPECT_CALL(receiver, DoOnFrameReadyInBuffer(_, _, _, _))
+ .WillRepeatedly(InvokeWithoutArgs([&wait_loop, &num_frames_arrived]() {
+ if (++num_frames_arrived >= kNumFramesToWaitFor) {
+ wait_loop.Quit();
+ }
+ }));
+
+ fake_device_proxy_->Start(requestable_settings_, std::move(receiver_proxy));
+ wait_loop.Run();
+
+ ASSERT_LT(num_buffers_created, num_frames_arrived);
+ ASSERT_LE(num_buffers_created, kMaxBufferPoolBuffers);
+}
+
} // namespace video_capture
« no previous file with comments | « services/video_capture/test/fake_device_descriptor_unittest.cc ('k') | services/video_capture/test/mock_device_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698