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

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: virtualandroid 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
« no previous file with comments | « media/base/video_frame.cc ('k') | media/filters/gpu_video_decoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 new VideoFrame::MailboxHolder(
227 gpu::Mailbox(),
228 sync_point,
229 base::Bind(&TextureCallback, &called_sync_point)),
230 5, // texture_target
231 gfx::Size(10, 10), // coded_size
232 gfx::Rect(10, 10), // visible_rect
233 gfx::Size(10, 10), // natural_size
234 base::TimeDelta(), // timestamp
235 base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
236 base::Closure()); // no_longer_needed_cb
237
238 EXPECT_EQ(0u, called_sync_point);
239 }
240 EXPECT_EQ(sync_point, called_sync_point);
241 }
242
243 // Verify the TextureNoLongerNeededCallback is called when VideoFrame is
244 // destroyed with the new sync point, when the mailbox is taken by a caller.
245 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) {
246 uint32 called_sync_point = 0;
247
248 gpu::Mailbox mailbox;
249 mailbox.name[0] = 50;
250 uint32 sync_point = 7;
251 uint32 target = 9;
252
253 {
254 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
255 new VideoFrame::MailboxHolder(
256 mailbox,
257 sync_point,
258 base::Bind(&TextureCallback, &called_sync_point)),
259 target,
260 gfx::Size(10, 10), // coded_size
261 gfx::Rect(10, 10), // visible_rect
262 gfx::Size(10, 10), // natural_size
263 base::TimeDelta(), // timestamp
264 base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
265 base::Closure()); // no_longer_needed_cb
266
267 {
268 scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder =
269 frame->texture_mailbox();
270
271 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
272 EXPECT_EQ(sync_point, mailbox_holder->sync_point());
273 EXPECT_EQ(target, frame->texture_target());
274
275 // Misuse the callback.
276 sync_point = 12;
277 mailbox_holder->Return(sync_point);
278 EXPECT_EQ(0u, called_sync_point);
279
280 // Finish using the mailbox_holder and drop our reference.
281 sync_point = 10;
282 mailbox_holder->Return(sync_point);
283 }
284 EXPECT_EQ(0u, called_sync_point);
285 }
286 EXPECT_EQ(sync_point, called_sync_point);
287 }
288
289 // If a caller has taken ownership of the texture mailbox, it should
290 // not be released when the VideoFrame is destroyed, but should when
291 // the TextureNoLongerNeededCallback is called.
292 TEST(VideoFrame,
293 TextureNoLongerNeededCallbackAfterTakingMailboxWithDestroyedFrame) {
294 uint32 called_sync_point = 0;
295
296 gpu::Mailbox mailbox;
297 mailbox.name[0] = 50;
298 uint32 sync_point = 7;
299 uint32 target = 9;
300
301 {
302 scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder;
303
304 {
305 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
306 new VideoFrame::MailboxHolder(
307 mailbox,
308 sync_point,
309 base::Bind(&TextureCallback, &called_sync_point)),
310 target,
311 gfx::Size(10, 10), // coded_size
312 gfx::Rect(10, 10), // visible_rect
313 gfx::Size(10, 10), // natural_size
314 base::TimeDelta(), // timestamp
315 base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
316 base::Closure()); // no_longer_needed_cb
317
318 mailbox_holder = frame->texture_mailbox();
319
320 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
321 EXPECT_EQ(sync_point, mailbox_holder->sync_point());
322 EXPECT_EQ(target, frame->texture_target());
323
324 // Keep a ref on the mailbox_holder after the VideoFrame is dropped.
325 }
326 EXPECT_EQ(0u, called_sync_point);
327
328 // Misuse the callback.
329 sync_point = 12;
330 mailbox_holder->Return(sync_point);
331 EXPECT_EQ(0u, called_sync_point);
332
333 // Finish using the mailbox_holder and drop our ref.
334 sync_point = 10;
335 mailbox_holder->Return(sync_point);
336 }
337 EXPECT_EQ(sync_point, called_sync_point);
338 }
339
340 // If a caller has taken ownership of the texture mailbox, but does
341 // not call the callback, it should still happen with the original
342 // sync point.
343 TEST(VideoFrame,
344 TextureNoLongerNeededCallbackWhenNotCallingAndFrameDestroyed) {
345 uint32 called_sync_point = 0;
346
347 gpu::Mailbox mailbox;
348 mailbox.name[0] = 50;
349 uint32 sync_point = 7;
350 uint32 target = 9;
351
352 {
353 scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder;
354
355 {
356 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
357 new VideoFrame::MailboxHolder(
358 mailbox,
359 sync_point,
360 base::Bind(&TextureCallback, &called_sync_point)),
361 target,
362 gfx::Size(10, 10), // coded_size
363 gfx::Rect(10, 10), // visible_rect
364 gfx::Size(10, 10), // natural_size
365 base::TimeDelta(), // timestamp
366 base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
367 base::Closure()); // no_longer_needed_cb
368
369 mailbox_holder = frame->texture_mailbox();
370
371 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
372 EXPECT_EQ(sync_point, mailbox_holder->sync_point());
373 EXPECT_EQ(target, frame->texture_target());
374
375 // Destroy the video frame.
376 }
377 EXPECT_EQ(0u, called_sync_point);
378
379 // Drop the reference on the mailbox without using it at all.
380 }
381 EXPECT_EQ(sync_point, called_sync_point);
382 }
383
384 // If a caller has taken ownership of the texture mailbox, but does
385 // not call the callback, it should still happen with the original
386 // sync point.
387 TEST(VideoFrame,
388 TextureNoLongerNeededCallbackAfterTakingMailboxAndNotCalling) {
389 uint32 called_sync_point = 0;
390
391 gpu::Mailbox mailbox;
392 mailbox.name[0] = 50;
393 uint32 sync_point = 7;
394 uint32 target = 9;
395
396 {
397 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
398 new VideoFrame::MailboxHolder(
399 mailbox,
400 sync_point,
401 base::Bind(&TextureCallback, &called_sync_point)),
402 target,
403 gfx::Size(10, 10), // coded_size
404 gfx::Rect(10, 10), // visible_rect
405 gfx::Size(10, 10), // natural_size
406 base::TimeDelta(), // timestamp
407 base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
408 base::Closure()); // no_longer_needed_cb
409
410 scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder =
411 frame->texture_mailbox();
412
413 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
414 EXPECT_EQ(sync_point, mailbox_holder->sync_point());
415 EXPECT_EQ(target, frame->texture_target());
416
417 EXPECT_EQ(0u, called_sync_point);
418
419 // Don't use the mailbox at all and drop our ref on it.
420 }
421 // The VideoFrame is destroyed, it should call the callback.
422 EXPECT_EQ(sync_point, called_sync_point);
423 }
424
212 } // namespace media 425 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.cc ('k') | media/filters/gpu_video_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698