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

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

Issue 83793004: Implement IPCs and VideoCapture::Client interfaces for texture capture (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: e296ac98 Win32 bits. Created 6 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 | Annotate | Revision Log
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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 class MockVideoCaptureHost : public VideoCaptureHost { 108 class MockVideoCaptureHost : public VideoCaptureHost {
109 public: 109 public:
110 MockVideoCaptureHost(MediaStreamManager* manager) 110 MockVideoCaptureHost(MediaStreamManager* manager)
111 : VideoCaptureHost(manager), 111 : VideoCaptureHost(manager),
112 return_buffers_(false), 112 return_buffers_(false),
113 dump_video_(false) {} 113 dump_video_(false) {}
114 114
115 // A list of mock methods. 115 // A list of mock methods.
116 MOCK_METHOD4(OnNewBufferCreated, 116 MOCK_METHOD4(OnNewBufferCreated,
117 void(int device_id, base::SharedMemoryHandle handle, 117 void(int device_id,
118 int length, int buffer_id)); 118 base::SharedMemoryHandle handle,
119 int length,
120 int buffer_id));
119 MOCK_METHOD2(OnBufferFreed, 121 MOCK_METHOD2(OnBufferFreed,
120 void(int device_id, int buffer_id)); 122 void(int device_id, int buffer_id));
121 MOCK_METHOD4(OnBufferFilled, 123 MOCK_METHOD4(OnBufferFilled,
122 void(int device_id, 124 void(int device_id,
123 int buffer_id, 125 int buffer_id,
124 base::TimeTicks timestamp, 126 const media::VideoCaptureFormat& format,
125 const media::VideoCaptureFormat& format)); 127 base::TimeTicks timestamp));
128 MOCK_METHOD5(OnMailboxBufferFilled,
129 void(int device_id,
130 int buffer_id,
131 const gpu::MailboxHolder& mailbox_holder,
132 const media::VideoCaptureFormat& format,
133 base::TimeTicks timestamp));
126 MOCK_METHOD2(OnStateChanged, void(int device_id, VideoCaptureState state)); 134 MOCK_METHOD2(OnStateChanged, void(int device_id, VideoCaptureState state));
127 135
128 // Use class DumpVideo to write I420 video to file. 136 // Use class DumpVideo to write I420 video to file.
129 void SetDumpVideo(bool enable) { 137 void SetDumpVideo(bool enable) {
130 dump_video_ = enable; 138 dump_video_ = enable;
131 } 139 }
132 140
133 void SetReturnReceivedDibs(bool enable) { 141 void SetReturnReceivedDibs(bool enable) {
134 return_buffers_ = enable; 142 return_buffers_ = enable;
135 } 143 }
136 144
137 // Return Dibs we currently have received. 145 // Return Dibs we currently have received.
138 void ReturnReceivedDibs(int device_id) { 146 void ReturnReceivedDibs(int device_id) {
139 int handle = GetReceivedDib(); 147 int handle = GetReceivedDib();
140 while (handle) { 148 while (handle) {
141 this->OnReceiveEmptyBuffer(device_id, handle); 149 this->OnReceiveEmptyBuffer(device_id, handle, 0);
142 handle = GetReceivedDib(); 150 handle = GetReceivedDib();
143 } 151 }
144 } 152 }
145 153
146 int GetReceivedDib() { 154 int GetReceivedDib() {
147 if (filled_dib_.empty()) 155 if (filled_dib_.empty())
148 return 0; 156 return 0;
149 std::map<int, base::SharedMemory*>::iterator it = filled_dib_.begin(); 157 std::map<int, base::SharedMemory*>::iterator it = filled_dib_.begin();
150 int h = it->first; 158 int h = it->first;
151 delete it->second; 159 delete it->second;
(...skipping 14 matching lines...) Expand all
166 virtual bool Send(IPC::Message* message) OVERRIDE { 174 virtual bool Send(IPC::Message* message) OVERRIDE {
167 CHECK(message); 175 CHECK(message);
168 176
169 // In this method we dispatch the messages to the according handlers as if 177 // In this method we dispatch the messages to the according handlers as if
170 // we are the renderer. 178 // we are the renderer.
171 bool handled = true; 179 bool handled = true;
172 IPC_BEGIN_MESSAGE_MAP(MockVideoCaptureHost, *message) 180 IPC_BEGIN_MESSAGE_MAP(MockVideoCaptureHost, *message)
173 IPC_MESSAGE_HANDLER(VideoCaptureMsg_NewBuffer, OnNewBufferCreatedDispatch) 181 IPC_MESSAGE_HANDLER(VideoCaptureMsg_NewBuffer, OnNewBufferCreatedDispatch)
174 IPC_MESSAGE_HANDLER(VideoCaptureMsg_FreeBuffer, OnBufferFreedDispatch) 182 IPC_MESSAGE_HANDLER(VideoCaptureMsg_FreeBuffer, OnBufferFreedDispatch)
175 IPC_MESSAGE_HANDLER(VideoCaptureMsg_BufferReady, OnBufferFilledDispatch) 183 IPC_MESSAGE_HANDLER(VideoCaptureMsg_BufferReady, OnBufferFilledDispatch)
184 IPC_MESSAGE_HANDLER(VideoCaptureMsg_MailboxBufferReady,
185 OnMailboxBufferFilledDispatch)
176 IPC_MESSAGE_HANDLER(VideoCaptureMsg_StateChanged, OnStateChangedDispatch) 186 IPC_MESSAGE_HANDLER(VideoCaptureMsg_StateChanged, OnStateChangedDispatch)
177 IPC_MESSAGE_UNHANDLED(handled = false) 187 IPC_MESSAGE_UNHANDLED(handled = false)
178 IPC_END_MESSAGE_MAP() 188 IPC_END_MESSAGE_MAP()
179 EXPECT_TRUE(handled); 189 EXPECT_TRUE(handled);
180 190
181 delete message; 191 delete message;
182 return true; 192 return true;
183 } 193 }
184 194
185 // These handler methods do minimal things and delegate to the mock methods. 195 // These handler methods do minimal things and delegate to the mock methods.
(...skipping 12 matching lines...) Expand all
198 208
199 std::map<int, base::SharedMemory*>::iterator it = 209 std::map<int, base::SharedMemory*>::iterator it =
200 filled_dib_.find(buffer_id); 210 filled_dib_.find(buffer_id);
201 ASSERT_TRUE(it != filled_dib_.end()); 211 ASSERT_TRUE(it != filled_dib_.end());
202 delete it->second; 212 delete it->second;
203 filled_dib_.erase(it); 213 filled_dib_.erase(it);
204 } 214 }
205 215
206 void OnBufferFilledDispatch(int device_id, 216 void OnBufferFilledDispatch(int device_id,
207 int buffer_id, 217 int buffer_id,
208 base::TimeTicks timestamp, 218 const media::VideoCaptureFormat& frame_format,
209 const media::VideoCaptureFormat& frame_format) { 219 base::TimeTicks timestamp) {
210 base::SharedMemory* dib = filled_dib_[buffer_id]; 220 base::SharedMemory* dib = filled_dib_[buffer_id];
211 ASSERT_TRUE(dib != NULL); 221 ASSERT_TRUE(dib != NULL);
212 if (dump_video_) { 222 if (dump_video_) {
213 if (!format_.IsValid()) { 223 if (!format_.IsValid()) {
214 dumper_.StartDump(frame_format.frame_size.width(), 224 dumper_.StartDump(frame_format.frame_size.width(),
215 frame_format.frame_size.height()); 225 frame_format.frame_size.height());
216 format_ = frame_format; 226 format_ = frame_format;
217 } 227 }
218 ASSERT_EQ(format_.frame_size.width(), frame_format.frame_size.width()) 228 ASSERT_EQ(format_.frame_size.width(), frame_format.frame_size.width())
219 << "Dump format does not handle variable resolution."; 229 << "Dump format does not handle variable resolution.";
220 ASSERT_EQ(format_.frame_size.height(), frame_format.frame_size.height()) 230 ASSERT_EQ(format_.frame_size.height(), frame_format.frame_size.height())
221 << "Dump format does not handle variable resolution."; 231 << "Dump format does not handle variable resolution.";
222 dumper_.NewVideoFrame(dib->memory()); 232 dumper_.NewVideoFrame(dib->memory());
223 } 233 }
224 234
225 OnBufferFilled(device_id, buffer_id, timestamp, frame_format); 235 OnBufferFilled(device_id, buffer_id, frame_format, timestamp);
226 if (return_buffers_) { 236 if (return_buffers_) {
227 VideoCaptureHost::OnReceiveEmptyBuffer(device_id, buffer_id); 237 VideoCaptureHost::OnReceiveEmptyBuffer(device_id, buffer_id, 0);
228 } 238 }
229 } 239 }
230 240
241 void OnMailboxBufferFilledDispatch(int device_id,
242 int buffer_id,
243 const gpu::MailboxHolder& mailbox_holder,
244 const media::VideoCaptureFormat& format,
245 base::TimeTicks timestamp) {
246 OnMailboxBufferFilled(
247 device_id, buffer_id, mailbox_holder, format, timestamp);
248 if (return_buffers_) {
249 VideoCaptureHost::OnReceiveEmptyBuffer(
250 device_id, buffer_id, mailbox_holder.sync_point);
251 }
252 }
253
231 void OnStateChangedDispatch(int device_id, VideoCaptureState state) { 254 void OnStateChangedDispatch(int device_id, VideoCaptureState state) {
232 OnStateChanged(device_id, state); 255 OnStateChanged(device_id, state);
233 } 256 }
234 257
235 std::map<int, base::SharedMemory*> filled_dib_; 258 std::map<int, base::SharedMemory*> filled_dib_;
236 bool return_buffers_; 259 bool return_buffers_;
237 bool dump_video_; 260 bool dump_video_;
238 media::VideoCaptureFormat format_; 261 media::VideoCaptureFormat format_;
239 DumpVideo dumper_; 262 DumpVideo dumper_;
240 }; 263 };
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 #ifdef DUMP_VIDEO 526 #ifdef DUMP_VIDEO
504 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { 527 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) {
505 CaptureAndDumpVideo(640, 480, 30); 528 CaptureAndDumpVideo(640, 480, 30);
506 } 529 }
507 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { 530 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) {
508 CaptureAndDumpVideo(1280, 720, 30); 531 CaptureAndDumpVideo(1280, 720, 30);
509 } 532 }
510 #endif 533 #endif
511 534
512 } // namespace content 535 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698