OLD | NEW |
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" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 233 |
234 // Ensure each frame is properly sized and allocated. Will trigger OOB reads | 234 // Ensure each frame is properly sized and allocated. Will trigger OOB reads |
235 // and writes as well as incorrect frame hashes otherwise. | 235 // and writes as well as incorrect frame hashes otherwise. |
236 TEST(VideoFrame, CheckFrameExtents) { | 236 TEST(VideoFrame, CheckFrameExtents) { |
237 // Each call consists of a VideoFrame::Format and the expected hash of all | 237 // Each call consists of a VideoFrame::Format and the expected hash of all |
238 // planes if filled with kFillByte (defined in ExpectFrameExtents). | 238 // planes if filled with kFillByte (defined in ExpectFrameExtents). |
239 ExpectFrameExtents(VideoFrame::YV12, "8e5d54cb23cd0edca111dd35ffb6ff05"); | 239 ExpectFrameExtents(VideoFrame::YV12, "8e5d54cb23cd0edca111dd35ffb6ff05"); |
240 ExpectFrameExtents(VideoFrame::YV16, "cce408a044b212db42a10dfec304b3ef"); | 240 ExpectFrameExtents(VideoFrame::YV16, "cce408a044b212db42a10dfec304b3ef"); |
241 } | 241 } |
242 | 242 |
243 static void TextureCallback(uint32* called_sync_point, | 243 static void TextureCallback(std::vector<uint32>* called_sync_point, |
244 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 244 const std::vector<uint32>& release_sync_points) { |
245 *called_sync_point = mailbox_holder->sync_point; | 245 called_sync_point->assign(release_sync_points.begin(), |
| 246 release_sync_points.end()); |
246 } | 247 } |
247 | 248 |
248 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is | 249 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
249 // destroyed with the original sync point. | 250 // destroyed with the default release sync points. |
250 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { | 251 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { |
251 uint32 sync_point = 7; | 252 std::vector<uint32> called_sync_points; |
252 uint32 called_sync_point = 0; | 253 called_sync_points.push_back(1); |
253 | 254 |
254 { | 255 { |
255 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | 256 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( |
256 make_scoped_ptr(new gpu::MailboxHolder(gpu::Mailbox(), 5, sync_point)), | 257 make_scoped_ptr( |
257 base::Bind(&TextureCallback, &called_sync_point), | 258 new gpu::MailboxHolder(gpu::Mailbox(), 5, 0 /* sync_point */)), |
258 gfx::Size(10, 10), // coded_size | 259 base::Bind(&TextureCallback, &called_sync_points), |
259 gfx::Rect(10, 10), // visible_rect | 260 gfx::Size(10, 10), // coded_size |
260 gfx::Size(10, 10), // natural_size | 261 gfx::Rect(10, 10), // visible_rect |
261 base::TimeDelta(), // timestamp | 262 gfx::Size(10, 10), // natural_size |
262 base::Callback<void(const SkBitmap&)>()); // read_pixels_cb | 263 base::TimeDelta(), // timestamp |
| 264 VideoFrame::ReadPixelsCB()); // read_pixels_cb |
263 | 265 |
264 EXPECT_EQ(0u, called_sync_point); | 266 EXPECT_EQ(1u, called_sync_points.size()); |
265 } | 267 } |
266 EXPECT_EQ(sync_point, called_sync_point); | 268 EXPECT_TRUE(called_sync_points.empty()); |
267 } | 269 } |
268 | 270 |
269 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is | 271 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
270 // destroyed with the new sync point, when the mailbox is accessed by a caller. | 272 // destroyed with the release sync points, which was updated by clients. |
| 273 // (i.e. the compositor, webgl). |
271 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { | 274 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { |
272 uint32 called_sync_point = 0; | 275 std::vector<uint32> called_sync_points; |
273 | 276 |
274 gpu::Mailbox mailbox; | 277 gpu::Mailbox mailbox; |
275 mailbox.name[0] = 50; | 278 mailbox.name[0] = 50; |
276 uint32 sync_point = 7; | 279 uint32 sync_point = 7; |
277 uint32 target = 9; | 280 uint32 target = 9; |
| 281 std::vector<uint32> release_sync_points; |
| 282 release_sync_points.push_back(1); |
| 283 release_sync_points.push_back(2); |
| 284 release_sync_points.push_back(3); |
278 | 285 |
279 { | 286 { |
280 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | 287 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( |
281 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), | 288 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), |
282 base::Bind(&TextureCallback, &called_sync_point), | 289 base::Bind(&TextureCallback, &called_sync_points), |
283 gfx::Size(10, 10), // coded_size | 290 gfx::Size(10, 10), // coded_size |
284 gfx::Rect(10, 10), // visible_rect | 291 gfx::Rect(10, 10), // visible_rect |
285 gfx::Size(10, 10), // natural_size | 292 gfx::Size(10, 10), // natural_size |
286 base::TimeDelta(), // timestamp | 293 base::TimeDelta(), // timestamp |
287 base::Callback<void(const SkBitmap&)>()); // read_pixels_cb | 294 VideoFrame::ReadPixelsCB()); // read_pixels_cb |
| 295 EXPECT_TRUE(called_sync_points.empty()); |
288 | 296 |
289 gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); | 297 const gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); |
290 | 298 |
291 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); | 299 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); |
292 EXPECT_EQ(target, mailbox_holder->texture_target); | 300 EXPECT_EQ(target, mailbox_holder->texture_target); |
293 EXPECT_EQ(sync_point, mailbox_holder->sync_point); | 301 EXPECT_EQ(sync_point, mailbox_holder->sync_point); |
294 | 302 |
295 // Finish using the mailbox_holder and drop our reference. | 303 frame->AppendReleaseSyncPoint(release_sync_points[0]); |
296 sync_point = 10; | 304 frame->AppendReleaseSyncPoint(release_sync_points[1]); |
297 mailbox_holder->sync_point = sync_point; | 305 frame->AppendReleaseSyncPoint(release_sync_points[2]); |
| 306 EXPECT_EQ(sync_point, mailbox_holder->sync_point); |
298 } | 307 } |
299 EXPECT_EQ(sync_point, called_sync_point); | 308 EXPECT_EQ(release_sync_points, called_sync_points); |
300 } | 309 } |
301 | 310 |
302 } // namespace media | 311 } // namespace media |
OLD | NEW |