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(std::vector<uint32>* called_sync_point, | 243 static void TextureCallback(uint32* called_sync_point, |
244 const std::vector<uint32>& release_sync_points) { | 244 uint32 release_sync_point) { |
245 called_sync_point->assign(release_sync_points.begin(), | 245 *called_sync_point = release_sync_point; |
246 release_sync_points.end()); | |
247 } | 246 } |
248 | 247 |
249 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is | 248 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
250 // destroyed with the default release sync points. | 249 // destroyed with the default release sync point. |
251 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { | 250 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { |
252 std::vector<uint32> called_sync_points; | 251 uint32 called_sync_point = 1; |
253 called_sync_points.push_back(1); | |
254 | 252 |
255 { | 253 { |
256 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | 254 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( |
257 make_scoped_ptr( | 255 make_scoped_ptr( |
258 new gpu::MailboxHolder(gpu::Mailbox(), 5, 0 /* sync_point */)), | 256 new gpu::MailboxHolder(gpu::Mailbox(), 5, 0 /* sync_point */)), |
259 base::Bind(&TextureCallback, &called_sync_points), | 257 base::Bind(&TextureCallback, &called_sync_point), |
| 258 gfx::Size(10, 10), // coded_size |
| 259 gfx::Rect(10, 10), // visible_rect |
| 260 gfx::Size(10, 10), // natural_size |
| 261 base::TimeDelta(), // timestamp |
| 262 VideoFrame::ReadPixelsCB()); // read_pixels_cb |
| 263 } |
| 264 // Nobody set a sync point to |frame|, so |frame| set |called_sync_point| to 0 |
| 265 // as default value. |
| 266 EXPECT_EQ(0u, called_sync_point); |
| 267 } |
| 268 |
| 269 namespace { |
| 270 |
| 271 class SyncPointClientImpl : public VideoFrame::SyncPointClient { |
| 272 public: |
| 273 explicit SyncPointClientImpl(uint32 sync_point) : sync_point_(sync_point) {} |
| 274 virtual ~SyncPointClientImpl() {} |
| 275 virtual uint32 InsertSyncPoint() OVERRIDE { return sync_point_; } |
| 276 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE {} |
| 277 |
| 278 private: |
| 279 uint32 sync_point_; |
| 280 }; |
| 281 |
| 282 } // namespace |
| 283 |
| 284 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
| 285 // destroyed with the release sync point, which was updated by clients. |
| 286 // (i.e. the compositor, webgl). |
| 287 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { |
| 288 gpu::Mailbox mailbox; |
| 289 mailbox.name[0] = 50; |
| 290 uint32 sync_point = 7; |
| 291 uint32 target = 9; |
| 292 uint32 release_sync_point = 111; |
| 293 uint32 called_sync_point = 0; |
| 294 |
| 295 { |
| 296 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( |
| 297 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), |
| 298 base::Bind(&TextureCallback, &called_sync_point), |
260 gfx::Size(10, 10), // coded_size | 299 gfx::Size(10, 10), // coded_size |
261 gfx::Rect(10, 10), // visible_rect | 300 gfx::Rect(10, 10), // visible_rect |
262 gfx::Size(10, 10), // natural_size | 301 gfx::Size(10, 10), // natural_size |
263 base::TimeDelta(), // timestamp | 302 base::TimeDelta(), // timestamp |
264 VideoFrame::ReadPixelsCB()); // read_pixels_cb | 303 VideoFrame::ReadPixelsCB()); // read_pixels_cb |
265 | 304 |
266 EXPECT_EQ(1u, called_sync_points.size()); | |
267 } | |
268 EXPECT_TRUE(called_sync_points.empty()); | |
269 } | |
270 | |
271 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is | |
272 // destroyed with the release sync points, which was updated by clients. | |
273 // (i.e. the compositor, webgl). | |
274 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { | |
275 std::vector<uint32> called_sync_points; | |
276 | |
277 gpu::Mailbox mailbox; | |
278 mailbox.name[0] = 50; | |
279 uint32 sync_point = 7; | |
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); | |
285 | |
286 { | |
287 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | |
288 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), | |
289 base::Bind(&TextureCallback, &called_sync_points), | |
290 gfx::Size(10, 10), // coded_size | |
291 gfx::Rect(10, 10), // visible_rect | |
292 gfx::Size(10, 10), // natural_size | |
293 base::TimeDelta(), // timestamp | |
294 VideoFrame::ReadPixelsCB()); // read_pixels_cb | |
295 EXPECT_TRUE(called_sync_points.empty()); | |
296 | |
297 const gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); | 305 const gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); |
298 | 306 |
299 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); | 307 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); |
300 EXPECT_EQ(target, mailbox_holder->texture_target); | 308 EXPECT_EQ(target, mailbox_holder->texture_target); |
301 EXPECT_EQ(sync_point, mailbox_holder->sync_point); | 309 EXPECT_EQ(sync_point, mailbox_holder->sync_point); |
302 | 310 |
303 frame->AppendReleaseSyncPoint(release_sync_points[0]); | 311 SyncPointClientImpl client(release_sync_point); |
304 frame->AppendReleaseSyncPoint(release_sync_points[1]); | 312 frame->UpdateReleaseSyncPoint(&client); |
305 frame->AppendReleaseSyncPoint(release_sync_points[2]); | |
306 EXPECT_EQ(sync_point, mailbox_holder->sync_point); | 313 EXPECT_EQ(sync_point, mailbox_holder->sync_point); |
307 } | 314 } |
308 EXPECT_EQ(release_sync_points, called_sync_points); | 315 EXPECT_EQ(release_sync_point, called_sync_point); |
309 } | 316 } |
310 | 317 |
311 TEST(VideoFrame, ZeroInitialized) { | 318 TEST(VideoFrame, ZeroInitialized) { |
312 const int kWidth = 64; | 319 const int kWidth = 64; |
313 const int kHeight = 48; | 320 const int kHeight = 48; |
314 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); | 321 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); |
315 | 322 |
316 gfx::Size size(kWidth, kHeight); | 323 gfx::Size size(kWidth, kHeight); |
317 scoped_refptr<media::VideoFrame> frame = VideoFrame::CreateFrame( | 324 scoped_refptr<media::VideoFrame> frame = VideoFrame::CreateFrame( |
318 media::VideoFrame::YV12, size, gfx::Rect(size), size, kTimestamp); | 325 media::VideoFrame::YV12, size, gfx::Rect(size), size, kTimestamp); |
319 | 326 |
320 for (size_t i = 0; i < VideoFrame::NumPlanes(frame->format()); ++i) | 327 for (size_t i = 0; i < VideoFrame::NumPlanes(frame->format()); ++i) |
321 EXPECT_EQ(0, frame->data(i)[0]); | 328 EXPECT_EQ(0, frame->data(i)[0]); |
322 } | 329 } |
323 | 330 |
324 } // namespace media | 331 } // namespace media |
OLD | NEW |