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

Unified Diff: content/renderer/media/video_capture_impl_unittest.cc

Issue 1314483003: Improve VideoCaptureImpl unittest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/video_capture_impl_unittest.cc
diff --git a/content/renderer/media/video_capture_impl_unittest.cc b/content/renderer/media/video_capture_impl_unittest.cc
index 3860080eb49afaf388d0fdba44ebf60e4d70cd4c..d86b5773a88ab18927c49cddf0d15ab11774eb9c 100644
--- a/content/renderer/media/video_capture_impl_unittest.cc
+++ b/content/renderer/media/video_capture_impl_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop.h"
#include "content/child/child_process.h"
#include "content/common/media/video_capture_messages.h"
@@ -34,13 +35,34 @@ class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter {
DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter);
};
-class VideoCaptureImplTest : public ::testing::Test {
+struct BufferReceivedTestArg {
+ BufferReceivedTestArg(media::VideoPixelFormat pixel_format,
+ media::VideoCapturePixelFormat capture_pixel_format,
+ const gpu::MailboxHolder& mailbox_holder)
+ : pixel_format(pixel_format), capture_pixel_format(capture_pixel_format),
+ mailbox_holder(mailbox_holder) {}
+
+ media::VideoPixelFormat pixel_format;
+ media::VideoCapturePixelFormat capture_pixel_format;
+ const gpu::MailboxHolder mailbox_holder;
+};
+
+static const BufferReceivedTestArg kBufferFormats[] = {
+ BufferReceivedTestArg(media::PIXEL_FORMAT_I420,
+ media::VIDEO_CAPTURE_PIXEL_FORMAT_I420,
mcasas 2015/09/02 16:51:26 Heh incidentally there has been another CL unifyin
+ gpu::MailboxHolder()),
+ BufferReceivedTestArg(media::PIXEL_FORMAT_ARGB,
+ media::VIDEO_CAPTURE_PIXEL_FORMAT_ARGB,
+ gpu::MailboxHolder(gpu::Mailbox::Generate(), 0, 0))};
+
+class VideoCaptureImplTest :
+ public ::testing::TestWithParam<BufferReceivedTestArg> {
public:
class MockVideoCaptureImpl : public VideoCaptureImpl {
public:
MockVideoCaptureImpl(const media::VideoCaptureSessionId id,
VideoCaptureMessageFilter* filter)
- : VideoCaptureImpl(id, filter) {
+ : VideoCaptureImpl(id, filter), received_buffer_count_(0) {
}
~MockVideoCaptureImpl() override {}
@@ -72,7 +94,6 @@ class VideoCaptureImplTest : public ::testing::Test {
const media::VideoCaptureParams& params) {
// Do not call OnStateChanged(VIDEO_CAPTURE_STATE_STARTED) here, as this
// does not accurately reflect the behavior of the VideoCaptureHost.
- capture_params_ = params;
}
void DevicePauseCapture(int device_id) {}
@@ -84,7 +105,9 @@ class VideoCaptureImplTest : public ::testing::Test {
void DeviceReceiveEmptyBuffer(int device_id,
int buffer_id,
uint32 sync_point,
- double consumer_resource_utilization) {}
+ double consumer_resource_utilization) {
+ received_buffer_count_++;
+ }
void DeviceGetSupportedFormats(int device_id,
media::VideoCaptureSessionId session_id) {
@@ -102,12 +125,10 @@ class VideoCaptureImplTest : public ::testing::Test {
OnStateChanged(state);
}
- const media::VideoCaptureParams& capture_params() const {
- return capture_params_;
- }
+ int received_buffer_count() const { return received_buffer_count_; }
private:
- media::VideoCaptureParams capture_params_;
+ int received_buffer_count_;
};
VideoCaptureImplTest() {
@@ -154,6 +175,25 @@ class VideoCaptureImplTest : public ::testing::Test {
void StopCapture() { video_capture_impl_->StopCapture(); }
+ void NewBuffer(int buffer_id, const base::SharedMemory& shm) {
+ video_capture_impl_->OnBufferCreated(
+ base::SharedMemory::DuplicateHandle(shm.handle()),
+ shm.mapped_size(), buffer_id);
+ }
+
+ void BufferReceived(int buffer_id, const gfx::Size& size,
+ media::VideoPixelFormat pixel_format,
+ const gpu::MailboxHolder& mailbox_holder) {
+ video_capture_impl_->OnBufferReceived(
+ buffer_id, base::TimeTicks::Now(), base::DictionaryValue(),
+ pixel_format, media::VideoFrame::STORAGE_SHMEM, size,
+ gfx::Rect(size), mailbox_holder);
+ }
+
+ void BufferDestroyed(int buffer_id) {
+ video_capture_impl_->OnBufferDestroyed(buffer_id);
+ }
+
void DeInit() {
video_capture_impl_->DeInit();
}
@@ -228,6 +268,60 @@ TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) {
DeInit();
}
+TEST_P(VideoCaptureImplTest, BufferReceivedWithFormat) {
+ EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(1);
+ EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(1);
+ EXPECT_CALL(*this, OnFrameReady(_, _)).Times(1);
+
+ const BufferReceivedTestArg& buffer_arg = GetParam();
+ const gfx::Size size(1280, 720);
+
+ // Create a fake shared memory for buffer.
+ base::SharedMemory shm;
+ const size_t frame_size = media::VideoFrame::AllocationSize(
+ buffer_arg.pixel_format, size);
+ ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size));
+
+ media::VideoCaptureParams params;
+ params.requested_format = media::VideoCaptureFormat(
+ size, 30, buffer_arg.capture_pixel_format);
+
+ Init();
+ StartCapture(params);
+ NewBuffer(0, shm);
+ BufferReceived(0, size, buffer_arg.pixel_format, buffer_arg.mailbox_holder);
+ StopCapture();
+ BufferDestroyed(0);
+ DeInit();
+}
+
+INSTANTIATE_TEST_CASE_P(I420AndARGB,
+ VideoCaptureImplTest,
+ testing::ValuesIn(kBufferFormats));
+
+TEST_F(VideoCaptureImplTest, BufferReceivedAfterStop) {
+ EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(1);
+ EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(1);
+ EXPECT_CALL(*this, OnFrameReady(_, _)).Times(0);
+
+ // Create a fake shared memory for buffer.
+ base::SharedMemory shm;
+ const size_t i420_frame_size = media::VideoFrame::AllocationSize(
+ media::PIXEL_FORMAT_I420, params_large_.requested_format.frame_size);
+ ASSERT_TRUE(shm.CreateAndMapAnonymous(i420_frame_size));
+
+ Init();
+ StartCapture(params_large_);
+ NewBuffer(0, shm);
+ StopCapture();
+ BufferReceived(0, params_large_.requested_format.frame_size,
+ media::PIXEL_FORMAT_I420, gpu::MailboxHolder());
+ BufferDestroyed(0);
+ DeInit();
+
+ EXPECT_EQ(this->video_capture_impl_->received_buffer_count(), 1);
+}
+
TEST_F(VideoCaptureImplTest, EndedBeforeStop) {
EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED));
EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698