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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 *called_sync_point = release_sync_point; | 245 *called_sync_point = release_sync_point; |
246 } | 246 } |
247 | 247 |
248 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is | 248 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
249 // destroyed with the default release sync point. | 249 // destroyed with the default release sync point. |
250 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { | 250 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { |
251 uint32 called_sync_point = 1; | 251 uint32 called_sync_point = 1; |
252 | 252 |
253 { | 253 { |
254 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | 254 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( |
255 make_scoped_ptr( | 255 gpu::MailboxHolder(gpu::Mailbox(), 5, 0 /* sync_point */), |
256 new gpu::MailboxHolder(gpu::Mailbox(), 5, 0 /* sync_point */)), | |
257 base::Bind(&TextureCallback, &called_sync_point), | 256 base::Bind(&TextureCallback, &called_sync_point), |
258 gfx::Size(10, 10), // coded_size | 257 gfx::Size(10, 10), // coded_size |
259 gfx::Rect(10, 10), // visible_rect | 258 gfx::Rect(10, 10), // visible_rect |
260 gfx::Size(10, 10), // natural_size | 259 gfx::Size(10, 10), // natural_size |
261 base::TimeDelta(), // timestamp | 260 base::TimeDelta(), // timestamp |
262 false); // allow_overlay | 261 false); // allow_overlay |
| 262 EXPECT_EQ(VideoFrame::TEXTURE_RGBA, frame->texture_format()); |
263 } | 263 } |
264 // Nobody set a sync point to |frame|, so |frame| set |called_sync_point| to 0 | 264 // Nobody set a sync point to |frame|, so |frame| set |called_sync_point| to 0 |
265 // as default value. | 265 // as default value. |
266 EXPECT_EQ(0u, called_sync_point); | 266 EXPECT_EQ(0u, called_sync_point); |
267 } | 267 } |
268 | 268 |
269 namespace { | 269 namespace { |
270 | 270 |
271 class SyncPointClientImpl : public VideoFrame::SyncPointClient { | 271 class SyncPointClientImpl : public VideoFrame::SyncPointClient { |
272 public: | 272 public: |
273 explicit SyncPointClientImpl(uint32 sync_point) : sync_point_(sync_point) {} | 273 explicit SyncPointClientImpl(uint32 sync_point) : sync_point_(sync_point) {} |
274 ~SyncPointClientImpl() override {} | 274 ~SyncPointClientImpl() override {} |
275 uint32 InsertSyncPoint() override { return sync_point_; } | 275 uint32 InsertSyncPoint() override { return sync_point_; } |
276 void WaitSyncPoint(uint32 sync_point) override {} | 276 void WaitSyncPoint(uint32 sync_point) override {} |
277 | 277 |
278 private: | 278 private: |
279 uint32 sync_point_; | 279 uint32 sync_point_; |
280 }; | 280 }; |
281 | 281 |
282 } // namespace | 282 } // namespace |
283 | 283 |
284 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is | 284 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
285 // destroyed with the release sync point, which was updated by clients. | 285 // destroyed with the release sync point, which was updated by clients. |
286 // (i.e. the compositor, webgl). | 286 // (i.e. the compositor, webgl). |
287 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { | 287 TEST(VideoFrame, |
288 gpu::Mailbox mailbox; | 288 TexturesNoLongerNeededCallbackAfterTakingAndReleasingMailboxes) { |
289 mailbox.name[0] = 50; | 289 const int kPlanesNum = 3; |
| 290 gpu::Mailbox mailbox[kPlanesNum]; |
| 291 for (int i = 0; i < kPlanesNum; ++i) { |
| 292 mailbox[i].name[0] = 50 + 1; |
| 293 } |
| 294 |
290 uint32 sync_point = 7; | 295 uint32 sync_point = 7; |
291 uint32 target = 9; | 296 uint32 target = 9; |
292 uint32 release_sync_point = 111; | 297 uint32 release_sync_point = 111; |
293 uint32 called_sync_point = 0; | 298 uint32 called_sync_point = 0; |
| 299 { |
| 300 scoped_refptr<VideoFrame> frame = VideoFrame::WrapYUV420NativeTextures( |
| 301 gpu::MailboxHolder(mailbox[VideoFrame::kYPlane], target, sync_point), |
| 302 gpu::MailboxHolder(mailbox[VideoFrame::kUPlane], target, sync_point), |
| 303 gpu::MailboxHolder(mailbox[VideoFrame::kVPlane], target, sync_point), |
| 304 base::Bind(&TextureCallback, &called_sync_point), |
| 305 gfx::Size(10, 10), // coded_size |
| 306 gfx::Rect(10, 10), // visible_rect |
| 307 gfx::Size(10, 10), // natural_size |
| 308 base::TimeDelta(), // timestamp |
| 309 false); // allow_overlay |
294 | 310 |
295 { | 311 EXPECT_EQ(VideoFrame::TEXTURE_YUV_420, frame->texture_format()); |
296 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | 312 EXPECT_EQ(3u, VideoFrame::NumTextures(frame->texture_format())); |
297 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), | 313 for (size_t i = 0; i < VideoFrame::NumTextures(frame->texture_format()); |
298 base::Bind(&TextureCallback, &called_sync_point), | 314 ++i) { |
299 gfx::Size(10, 10), // coded_size | 315 const gpu::MailboxHolder& mailbox_holder = frame->mailbox_holder(i); |
300 gfx::Rect(10, 10), // visible_rect | 316 EXPECT_EQ(mailbox[i].name[0], mailbox_holder.mailbox.name[0]); |
301 gfx::Size(10, 10), // natural_size | 317 EXPECT_EQ(target, mailbox_holder.texture_target); |
302 base::TimeDelta(), // timestamp | 318 EXPECT_EQ(sync_point, mailbox_holder.sync_point); |
303 false); // allow_overlay | 319 } |
304 | |
305 const gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); | |
306 | |
307 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); | |
308 EXPECT_EQ(target, mailbox_holder->texture_target); | |
309 EXPECT_EQ(sync_point, mailbox_holder->sync_point); | |
310 | 320 |
311 SyncPointClientImpl client(release_sync_point); | 321 SyncPointClientImpl client(release_sync_point); |
312 frame->UpdateReleaseSyncPoint(&client); | 322 frame->UpdateReleaseSyncPoint(&client); |
313 EXPECT_EQ(sync_point, mailbox_holder->sync_point); | 323 EXPECT_EQ(sync_point, |
| 324 frame->mailbox_holder(VideoFrame::kYPlane).sync_point); |
314 } | 325 } |
315 EXPECT_EQ(release_sync_point, called_sync_point); | 326 EXPECT_EQ(release_sync_point, called_sync_point); |
316 } | 327 } |
317 | 328 |
318 TEST(VideoFrame, ZeroInitialized) { | 329 TEST(VideoFrame, ZeroInitialized) { |
319 const int kWidth = 64; | 330 const int kWidth = 64; |
320 const int kHeight = 48; | 331 const int kHeight = 48; |
321 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); | 332 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); |
322 | 333 |
323 gfx::Size size(kWidth, kHeight); | 334 gfx::Size size(kWidth, kHeight); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 412 |
402 for (int i = 0; i < VideoFrameMetadata::NUM_KEYS; ++i) { | 413 for (int i = 0; i < VideoFrameMetadata::NUM_KEYS; ++i) { |
403 const VideoFrameMetadata::Key key = static_cast<VideoFrameMetadata::Key>(i); | 414 const VideoFrameMetadata::Key key = static_cast<VideoFrameMetadata::Key>(i); |
404 int value = -1; | 415 int value = -1; |
405 EXPECT_TRUE(result.GetInteger(key, &value)); | 416 EXPECT_TRUE(result.GetInteger(key, &value)); |
406 EXPECT_EQ(i, value); | 417 EXPECT_EQ(i, value); |
407 } | 418 } |
408 } | 419 } |
409 | 420 |
410 } // namespace media | 421 } // namespace media |
OLD | NEW |