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

Side by Side Diff: content/renderer/media/video_capture_message_filter_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 "base/memory/shared_memory.h" 5 #include "base/memory/shared_memory.h"
6 #include "content/common/media/video_capture_messages.h" 6 #include "content/common/media/video_capture_messages.h"
7 #include "content/renderer/media/video_capture_message_filter.h" 7 #include "content/renderer/media/video_capture_message_filter.h"
8 #include "ipc/ipc_test_sink.h" 8 #include "ipc/ipc_test_sink.h"
9 #include "media/base/video_capture_types.h" 9 #include "media/base/video_capture_types.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 using ::testing::_; 13 using ::testing::_;
14 using ::testing::AnyNumber; 14 using ::testing::AnyNumber;
15 using ::testing::DoAll;
16 using ::testing::Invoke;
15 using ::testing::Mock; 17 using ::testing::Mock;
16 using ::testing::Return; 18 using ::testing::Return;
17 using ::testing::SaveArg; 19 using ::testing::SaveArg;
18 using ::testing::StrictMock; 20 using ::testing::StrictMock;
21 using ::testing::WithArg;
19 22
20 namespace content { 23 namespace content {
21 namespace { 24 namespace {
22 25
23 class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate { 26 class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate {
24 public: 27 public:
25 MockVideoCaptureDelegate() : device_id_(0) {} 28 MockVideoCaptureDelegate() : device_id_(0) {}
26 29
27 // VideoCaptureMessageFilter::Delegate implementation. 30 // VideoCaptureMessageFilter::Delegate implementation.
28 MOCK_METHOD3(OnBufferCreated, void(base::SharedMemoryHandle handle, 31 MOCK_METHOD3(OnBufferCreated, void(base::SharedMemoryHandle handle,
29 int length, 32 int length,
30 int buffer_id)); 33 int buffer_id));
31 MOCK_METHOD1(OnBufferDestroyed, void(int buffer_id)); 34 MOCK_METHOD1(OnBufferDestroyed, void(int buffer_id));
32 MOCK_METHOD4(OnBufferReceived, 35 MOCK_METHOD5(OnBufferReceived,
33 void(int buffer_id, 36 void(int buffer_id,
34 const media::VideoCaptureFormat& format, 37 const gfx::Size& coded_size,
35 const gfx::Rect& visible_rect, 38 const gfx::Rect& visible_rect,
36 base::TimeTicks timestamp)); 39 base::TimeTicks timestamp,
37 MOCK_METHOD4(OnMailboxBufferReceived, 40 const base::DictionaryValue& metadata));
41 MOCK_METHOD5(OnMailboxBufferReceived,
38 void(int buffer_id, 42 void(int buffer_id,
39 const gpu::MailboxHolder& mailbox_holder, 43 const gpu::MailboxHolder& mailbox_holder,
40 const media::VideoCaptureFormat& format, 44 const gfx::Size& packed_frame_size,
41 base::TimeTicks timestamp)); 45 base::TimeTicks timestamp,
46 const base::DictionaryValue& metadata));
42 MOCK_METHOD1(OnStateChanged, void(VideoCaptureState state)); 47 MOCK_METHOD1(OnStateChanged, void(VideoCaptureState state));
43 MOCK_METHOD1(OnDeviceSupportedFormatsEnumerated, 48 MOCK_METHOD1(OnDeviceSupportedFormatsEnumerated,
44 void(const media::VideoCaptureFormats& formats)); 49 void(const media::VideoCaptureFormats& formats));
45 MOCK_METHOD1(OnDeviceFormatsInUseReceived, 50 MOCK_METHOD1(OnDeviceFormatsInUseReceived,
46 void(const media::VideoCaptureFormats& formats_in_use)); 51 void(const media::VideoCaptureFormats& formats_in_use));
47 52
48 virtual void OnDelegateAdded(int32 device_id) override { 53 virtual void OnDelegateAdded(int32 device_id) override {
49 ASSERT_TRUE(device_id != 0); 54 ASSERT_TRUE(device_id != 0);
50 ASSERT_TRUE(device_id_ == 0); 55 ASSERT_TRUE(device_id_ == 0);
51 device_id_ = device_id; 56 device_id_ = device_id;
52 } 57 }
53 58
54 int device_id() { return device_id_; } 59 int device_id() { return device_id_; }
55 60
56 private: 61 private:
57 int device_id_; 62 int device_id_;
58 }; 63 };
59 64
65 void ExpectMetadataContainsFooBarBaz(const base::DictionaryValue& metadata) {
66 std::string value;
67 if (metadata.GetString("foo", &value))
68 EXPECT_EQ(std::string("bar"), value);
69 else if (metadata.GetString("bar", &value))
70 EXPECT_EQ(std::string("baz"), value);
71 else
72 FAIL() << "Missing key 'foo' or key 'bar'.";
73 }
74
60 } // namespace 75 } // namespace
61 76
62 TEST(VideoCaptureMessageFilterTest, Basic) { 77 TEST(VideoCaptureMessageFilterTest, Basic) {
63 scoped_refptr<VideoCaptureMessageFilter> filter( 78 scoped_refptr<VideoCaptureMessageFilter> filter(
64 new VideoCaptureMessageFilter()); 79 new VideoCaptureMessageFilter());
65 80
66 IPC::TestSink channel; 81 IPC::TestSink channel;
67 filter->OnFilterAdded(&channel); 82 filter->OnFilterAdded(&channel);
68 MockVideoCaptureDelegate delegate; 83 MockVideoCaptureDelegate delegate;
69 filter->AddDelegate(&delegate); 84 filter->AddDelegate(&delegate);
(...skipping 12 matching lines...) Expand all
82 reinterpret_cast<base::SharedMemoryHandle>(10); 97 reinterpret_cast<base::SharedMemoryHandle>(10);
83 #else 98 #else
84 base::SharedMemoryHandle(10, true); 99 base::SharedMemoryHandle(10, true);
85 #endif 100 #endif
86 EXPECT_CALL(delegate, OnBufferCreated(handle, 100, 1)); 101 EXPECT_CALL(delegate, OnBufferCreated(handle, 100, 1));
87 filter->OnMessageReceived(VideoCaptureMsg_NewBuffer( 102 filter->OnMessageReceived(VideoCaptureMsg_NewBuffer(
88 delegate.device_id(), handle, 100, 1)); 103 delegate.device_id(), handle, 100, 1));
89 Mock::VerifyAndClearExpectations(&delegate); 104 Mock::VerifyAndClearExpectations(&delegate);
90 105
91 // VideoCaptureMsg_BufferReady 106 // VideoCaptureMsg_BufferReady
92 int buffer_id = 22; 107 VideoCaptureMsg_BufferReady_Params params;
93 base::TimeTicks timestamp = base::TimeTicks::FromInternalValue(1); 108 params.device_id = delegate.device_id();
109 params.buffer_id = 22;
110 params.coded_size = gfx::Size(234, 512);
111 params.visible_rect = gfx::Rect(100, 200, 300, 400);
112 params.timestamp = base::TimeTicks::FromInternalValue(1);
113 params.metadata.SetString("foo", "bar");
94 114
95 const media::VideoCaptureFormat shm_format( 115 EXPECT_CALL(delegate, OnBufferReceived(params.buffer_id,
96 gfx::Size(234, 512), 30, media::PIXEL_FORMAT_I420); 116 params.coded_size,
97 media::VideoCaptureFormat saved_format; 117 params.visible_rect,
98 EXPECT_CALL(delegate, OnBufferReceived(buffer_id, _, _, timestamp)) 118 params.timestamp,
99 .WillRepeatedly(SaveArg<1>(&saved_format)); 119 _))
100 filter->OnMessageReceived(VideoCaptureMsg_BufferReady( 120 .WillRepeatedly(WithArg<4>(Invoke(&ExpectMetadataContainsFooBarBaz)));
101 delegate.device_id(), buffer_id, shm_format, gfx::Rect(234, 512), 121 filter->OnMessageReceived(VideoCaptureMsg_BufferReady(params));
102 timestamp));
103 Mock::VerifyAndClearExpectations(&delegate); 122 Mock::VerifyAndClearExpectations(&delegate);
104 EXPECT_EQ(shm_format.frame_size, saved_format.frame_size);
105 EXPECT_EQ(shm_format.frame_rate, saved_format.frame_rate);
106 EXPECT_EQ(shm_format.pixel_format, saved_format.pixel_format);
107 123
108 // VideoCaptureMsg_MailboxBufferReady 124 // VideoCaptureMsg_MailboxBufferReady
109 buffer_id = 33; 125 VideoCaptureMsg_MailboxBufferReady_Params params_m;
110 timestamp = base::TimeTicks::FromInternalValue(2); 126 params_m.device_id = delegate.device_id();
111 127 params_m.buffer_id = 33;
112 const media::VideoCaptureFormat mailbox_format(
113 gfx::Size(234, 512), 30, media::PIXEL_FORMAT_TEXTURE);
114 gpu::Mailbox mailbox; 128 gpu::Mailbox mailbox;
115 const int8 mailbox_name[arraysize(mailbox.name)] = "TEST MAILBOX"; 129 const int8 mailbox_name[arraysize(mailbox.name)] = "TEST MAILBOX";
116 mailbox.SetName(mailbox_name); 130 mailbox.SetName(mailbox_name);
117 unsigned int syncpoint = 44; 131 params_m.mailbox_holder = gpu::MailboxHolder(mailbox, 0, 44);
132 params_m.packed_frame_size = gfx::Size(345, 256);
133 params_m.timestamp = base::TimeTicks::FromInternalValue(2);
134 params_m.metadata.SetString("bar", "baz");
135
118 gpu::MailboxHolder saved_mailbox_holder; 136 gpu::MailboxHolder saved_mailbox_holder;
119 EXPECT_CALL(delegate, OnMailboxBufferReceived(buffer_id, _, _, timestamp)) 137 EXPECT_CALL(delegate, OnMailboxBufferReceived(params_m.buffer_id,
120 .WillRepeatedly( 138 _,
121 DoAll(SaveArg<1>(&saved_mailbox_holder), SaveArg<2>(&saved_format))); 139 params_m.packed_frame_size,
122 gpu::MailboxHolder mailbox_holder(mailbox, 0, syncpoint); 140 params_m.timestamp,
123 filter->OnMessageReceived( 141 _))
124 VideoCaptureMsg_MailboxBufferReady(delegate.device_id(), 142 .WillRepeatedly(DoAll(
125 buffer_id, 143 SaveArg<1>(&saved_mailbox_holder),
126 mailbox_holder, 144 WithArg<4>(Invoke(&ExpectMetadataContainsFooBarBaz))));
127 mailbox_format, 145 filter->OnMessageReceived(VideoCaptureMsg_MailboxBufferReady(params_m));
128 timestamp));
129 Mock::VerifyAndClearExpectations(&delegate); 146 Mock::VerifyAndClearExpectations(&delegate);
130 EXPECT_EQ(mailbox_format.frame_size, saved_format.frame_size);
131 EXPECT_EQ(mailbox_format.frame_rate, saved_format.frame_rate);
132 EXPECT_EQ(mailbox_format.pixel_format, saved_format.pixel_format);
133 EXPECT_EQ(memcmp(mailbox.name, 147 EXPECT_EQ(memcmp(mailbox.name,
134 saved_mailbox_holder.mailbox.name, 148 saved_mailbox_holder.mailbox.name,
135 sizeof(mailbox.name)), 149 sizeof(mailbox.name)),
136 0); 150 0);
137 151
138 // VideoCaptureMsg_FreeBuffer 152 // VideoCaptureMsg_FreeBuffer
139 EXPECT_CALL(delegate, OnBufferDestroyed(buffer_id)); 153 EXPECT_CALL(delegate, OnBufferDestroyed(params_m.buffer_id));
140 filter->OnMessageReceived(VideoCaptureMsg_FreeBuffer( 154 filter->OnMessageReceived(VideoCaptureMsg_FreeBuffer(
141 delegate.device_id(), buffer_id)); 155 delegate.device_id(), params_m.buffer_id));
142 Mock::VerifyAndClearExpectations(&delegate); 156 Mock::VerifyAndClearExpectations(&delegate);
143 } 157 }
144 158
145 TEST(VideoCaptureMessageFilterTest, Delegates) { 159 TEST(VideoCaptureMessageFilterTest, Delegates) {
146 scoped_refptr<VideoCaptureMessageFilter> filter( 160 scoped_refptr<VideoCaptureMessageFilter> filter(
147 new VideoCaptureMessageFilter()); 161 new VideoCaptureMessageFilter());
148 162
149 IPC::TestSink channel; 163 IPC::TestSink channel;
150 filter->OnFilterAdded(&channel); 164 filter->OnFilterAdded(&channel);
151 165
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 MockVideoCaptureDelegate delegate; 221 MockVideoCaptureDelegate delegate;
208 filter->AddDelegate(&delegate); 222 filter->AddDelegate(&delegate);
209 ASSERT_EQ(1, delegate.device_id()); 223 ASSERT_EQ(1, delegate.device_id());
210 224
211 EXPECT_CALL(delegate, OnDeviceFormatsInUseReceived(_)); 225 EXPECT_CALL(delegate, OnDeviceFormatsInUseReceived(_));
212 media::VideoCaptureFormats formats_in_use; 226 media::VideoCaptureFormats formats_in_use;
213 filter->OnMessageReceived(VideoCaptureMsg_DeviceFormatsInUseReceived( 227 filter->OnMessageReceived(VideoCaptureMsg_DeviceFormatsInUseReceived(
214 delegate.device_id(), formats_in_use)); 228 delegate.device_id(), formats_in_use));
215 } 229 }
216 } // namespace content 230 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_message_filter.cc ('k') | content/renderer/media/video_source_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698