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

Side by Side Diff: media/base/video_frame_unittest.cc

Issue 14199002: Send hardware video frames with mailboxes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: video-mailbox: merge create/gen/produce Created 7 years, 6 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 "media/base/video_frame.h" 5 #include "media/base/video_frame.h"
6 6
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
7 #include "base/format_macros.h" 9 #include "base/format_macros.h"
8 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
10 #include "media/base/buffers.h" 12 #include "media/base/buffers.h"
11 #include "media/base/yuv_convert.h" 13 #include "media/base/yuv_convert.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 15
14 namespace media { 16 namespace media {
15 17
16 using base::MD5DigestToBase16; 18 using base::MD5DigestToBase16;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // and the expected hash of all planes if filled with kFillByte (defined in 204 // and the expected hash of all planes if filled with kFillByte (defined in
203 // ExpectFrameExtents). 205 // ExpectFrameExtents).
204 ExpectFrameExtents( 206 ExpectFrameExtents(
205 VideoFrame::RGB32, 1, 4, "de6d3d567e282f6a38d478f04fc81fb0"); 207 VideoFrame::RGB32, 1, 4, "de6d3d567e282f6a38d478f04fc81fb0");
206 ExpectFrameExtents( 208 ExpectFrameExtents(
207 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); 209 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1");
208 ExpectFrameExtents( 210 ExpectFrameExtents(
209 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); 211 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461");
210 } 212 }
211 213
214 static void TextureCallback(uint32* called_sync_point, uint32 sync_point) {
215 *called_sync_point = sync_point;
216 }
217
218 // Verify the TextureNoLongerNeededCallback is called when VideoFrame is
219 // destroyed with the original sync point.
220 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) {
221 uint32 sync_point = 7;
222 uint32 called_sync_point = 0;
223
224 {
225 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
226 gpu::Mailbox(),
227 sync_point,
228 5, // texture_target
229 gfx::Size(10, 10), // coded_size
230 gfx::Rect(10, 10), // visible_rect
231 gfx::Size(10, 10), // natural_size
232 base::TimeDelta(), // timestamp
233 base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
234 base::Bind(&TextureCallback, &called_sync_point),
235 base::Closure()); // no_longer_needed_cb
236
237 EXPECT_EQ(0u, called_sync_point);
238 }
239 EXPECT_EQ(sync_point, called_sync_point);
240 }
241
242 // Verify the TextureNoLongerNeededCallback is called when VideoFrame is
243 // destroyed with the new sync point, when the mailbox is taken by a caller.
244 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) {
245 uint32 called_sync_point = 0;
246
247 gpu::Mailbox mailbox;
248 mailbox.name[0] = 50;
249 uint32 sync_point = 7;
250 uint32 target = 9;
251
252 {
253 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
254 mailbox,
255 sync_point,
256 target,
257 gfx::Size(10, 10), // coded_size
258 gfx::Rect(10, 10), // visible_rect
259 gfx::Size(10, 10), // natural_size
260 base::TimeDelta(), // timestamp
261 base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
262 base::Bind(&TextureCallback, &called_sync_point),
263 base::Closure()); // no_longer_needed_cb
264
265 {
266 scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder =
267 frame->texture_mailbox();
268
269 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
270 EXPECT_EQ(sync_point, mailbox_holder->sync_point());
271 EXPECT_EQ(target, frame->texture_target());
272
273 // Misuse the callback.
274 sync_point = 12;
275 mailbox_holder->Return(sync_point);
276 EXPECT_EQ(0u, called_sync_point);
277
278 // Finish using the mailbox_holder and drop our reference.
279 sync_point = 10;
280 mailbox_holder->Return(sync_point);
281 }
282 EXPECT_EQ(0u, called_sync_point);
283 }
284 EXPECT_EQ(sync_point, called_sync_point);
285 }
286
287 // If a caller has taken ownership of the texture mailbox, it should
288 // not be released when the VideoFrame is destroyed, but should when
289 // the TextureNoLongerNeededCallback is called.
290 TEST(VideoFrame,
291 TextureNoLongerNeededCallbackAfterTakingMailboxWithDestroyedFrame) {
292 uint32 called_sync_point = 0;
293
294 gpu::Mailbox mailbox;
295 mailbox.name[0] = 50;
296 uint32 sync_point = 7;
297 uint32 target = 9;
298
299 {
300 scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder;
301
302 {
303 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
304 mailbox,
305 sync_point,
306 target,
307 gfx::Size(10, 10), // coded_size
308 gfx::Rect(10, 10), // visible_rect
309 gfx::Size(10, 10), // natural_size
310 base::TimeDelta(), // timestamp
311 base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
312 base::Bind(&TextureCallback, &called_sync_point),
313 base::Closure()); // no_longer_needed_cb
314
315 mailbox_holder = frame->texture_mailbox();
316
317 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
318 EXPECT_EQ(sync_point, mailbox_holder->sync_point());
319 EXPECT_EQ(target, frame->texture_target());
320
321 // Keep a ref on the mailbox_holder after the VideoFrame is dropped.
322 }
323 EXPECT_EQ(0u, called_sync_point);
324
325 // Misuse the callback.
326 sync_point = 12;
327 mailbox_holder->Return(sync_point);
328 EXPECT_EQ(0u, called_sync_point);
329
330 // Finish using the mailbox_holder and drop our ref.
331 sync_point = 10;
332 mailbox_holder->Return(sync_point);
333 }
334 EXPECT_EQ(sync_point, called_sync_point);
335 }
336
337 // If a caller has taken ownership of the texture mailbox, but does
338 // not call the callback, it should still happen with the original
339 // sync point.
340 TEST(VideoFrame,
341 TextureNoLongerNeededCallbackWhenNotCallingAndFrameDestroyed) {
342 uint32 called_sync_point = 0;
343
344 gpu::Mailbox mailbox;
345 mailbox.name[0] = 50;
346 uint32 sync_point = 7;
347 uint32 target = 9;
348
349 {
350 scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder;
351
352 {
353 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
354 mailbox,
355 sync_point,
356 target,
357 gfx::Size(10, 10), // coded_size
358 gfx::Rect(10, 10), // visible_rect
359 gfx::Size(10, 10), // natural_size
360 base::TimeDelta(), // timestamp
361 base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
362 base::Bind(&TextureCallback, &called_sync_point),
363 base::Closure()); // no_longer_needed_cb
364
365 mailbox_holder = frame->texture_mailbox();
366
367 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
368 EXPECT_EQ(sync_point, mailbox_holder->sync_point());
369 EXPECT_EQ(target, frame->texture_target());
370
371 // Destroy the video frame.
372 }
373 EXPECT_EQ(0u, called_sync_point);
374
375 // Drop the reference on the mailbox without using it at all.
376 }
377 EXPECT_EQ(sync_point, called_sync_point);
378 }
379
380 // If a caller has taken ownership of the texture mailbox, but does
381 // not call the callback, it should still happen with the original
382 // sync point.
383 TEST(VideoFrame,
384 TextureNoLongerNeededCallbackAfterTakingMailboxAndNotCalling) {
385 uint32 called_sync_point = 0;
386
387 gpu::Mailbox mailbox;
388 mailbox.name[0] = 50;
389 uint32 sync_point = 7;
390 uint32 target = 9;
391
392 {
393 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
394 mailbox,
395 sync_point,
396 target,
397 gfx::Size(10, 10), // coded_size
398 gfx::Rect(10, 10), // visible_rect
399 gfx::Size(10, 10), // natural_size
400 base::TimeDelta(), // timestamp
401 base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
402 base::Bind(&TextureCallback, &called_sync_point),
403 base::Closure()); // no_longer_needed_cb
404
405 scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder =
406 frame->texture_mailbox();
407
408 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
409 EXPECT_EQ(sync_point, mailbox_holder->sync_point());
410 EXPECT_EQ(target, frame->texture_target());
411
412 EXPECT_EQ(0u, called_sync_point);
413
414 // Don't use the mailbox at all and drop our ref on it.
415 }
416 // The VideoFrame is destroyed, it should call the callback.
417 EXPECT_EQ(sync_point, called_sync_point);
418 }
419
212 } // namespace media 420 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698