| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 13 #include "media/base/buffers.h" | 14 #include "media/base/buffers.h" |
| 14 #include "media/base/yuv_convert.h" | 15 #include "media/base/yuv_convert.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace media { | 18 namespace media { |
| 18 | 19 |
| 19 using base::MD5DigestToBase16; | 20 using base::MD5DigestToBase16; |
| 20 | 21 |
| 21 // Helper function that initializes a YV12 frame with white and black scan | 22 // Helper function that initializes a YV12 frame with white and black scan |
| 22 // lines based on the |white_to_black| parameter. If 0, then the entire | 23 // lines based on the |white_to_black| parameter. If 0, then the entire |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 TEST(VideoFrame, CheckFrameExtents) { | 205 TEST(VideoFrame, CheckFrameExtents) { |
| 205 // Each call consists of a VideoFrame::Format, # of planes, bytes per pixel, | 206 // Each call consists of a VideoFrame::Format, # of planes, bytes per pixel, |
| 206 // and the expected hash of all planes if filled with kFillByte (defined in | 207 // and the expected hash of all planes if filled with kFillByte (defined in |
| 207 // ExpectFrameExtents). | 208 // ExpectFrameExtents). |
| 208 ExpectFrameExtents( | 209 ExpectFrameExtents( |
| 209 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); | 210 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); |
| 210 ExpectFrameExtents( | 211 ExpectFrameExtents( |
| 211 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); | 212 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); |
| 212 } | 213 } |
| 213 | 214 |
| 214 static void TextureCallback(uint32* called_sync_point, uint32 sync_point) { | 215 static void TextureCallback(uint32* called_sync_point, |
| 215 *called_sync_point = sync_point; | 216 const gpu::MailboxHolder* mailbox_holder) { |
| 217 *called_sync_point = mailbox_holder->sync_point; |
| 216 } | 218 } |
| 217 | 219 |
| 218 // Verify the TextureNoLongerNeededCallback is called when VideoFrame is | 220 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
| 219 // destroyed with the original sync point. | 221 // destroyed with the original sync point. |
| 220 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { | 222 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { |
| 221 uint32 sync_point = 7; | 223 uint32 sync_point = 7; |
| 222 uint32 called_sync_point = 0; | 224 uint32 called_sync_point = 0; |
| 223 | 225 |
| 224 { | 226 { |
| 225 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | 227 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( |
| 226 make_scoped_ptr(new VideoFrame::MailboxHolder( | 228 make_scoped_ptr(new gpu::MailboxHolder(gpu::Mailbox(), 5, sync_point)), |
| 227 gpu::Mailbox(), | 229 base::Bind(&TextureCallback, &called_sync_point), |
| 228 sync_point, | 230 gfx::Size(10, 10), // coded_size |
| 229 base::Bind(&TextureCallback, &called_sync_point))), | 231 gfx::Rect(10, 10), // visible_rect |
| 230 5, // texture_target | 232 gfx::Size(10, 10), // natural_size |
| 231 gfx::Size(10, 10), // coded_size | 233 base::TimeDelta(), // timestamp |
| 232 gfx::Rect(10, 10), // visible_rect | 234 base::Callback<void(const SkBitmap&)>()); // read_pixels_cb |
| 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 | 235 |
| 238 EXPECT_EQ(0u, called_sync_point); | 236 EXPECT_EQ(0u, called_sync_point); |
| 239 } | 237 } |
| 240 EXPECT_EQ(sync_point, called_sync_point); | 238 EXPECT_EQ(sync_point, called_sync_point); |
| 241 } | 239 } |
| 242 | 240 |
| 243 // Verify the TextureNoLongerNeededCallback is called when VideoFrame is | 241 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
| 244 // destroyed with the new sync point, when the mailbox is accessed by a caller. | 242 // destroyed with the new sync point, when the mailbox is accessed by a caller. |
| 245 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { | 243 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { |
| 246 uint32 called_sync_point = 0; | 244 uint32 called_sync_point = 0; |
| 247 | 245 |
| 248 gpu::Mailbox mailbox; | 246 gpu::Mailbox mailbox; |
| 249 mailbox.name[0] = 50; | 247 mailbox.name[0] = 50; |
| 250 uint32 sync_point = 7; | 248 uint32 sync_point = 7; |
| 251 uint32 target = 9; | 249 uint32 target = 9; |
| 252 | 250 |
| 253 { | 251 { |
| 254 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | 252 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( |
| 255 make_scoped_ptr(new VideoFrame::MailboxHolder( | 253 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), |
| 256 mailbox, | 254 base::Bind(&TextureCallback, &called_sync_point), |
| 257 sync_point, | 255 gfx::Size(10, 10), // coded_size |
| 258 base::Bind(&TextureCallback, &called_sync_point))), | 256 gfx::Rect(10, 10), // visible_rect |
| 259 target, | 257 gfx::Size(10, 10), // natural_size |
| 260 gfx::Size(10, 10), // coded_size | 258 base::TimeDelta(), // timestamp |
| 261 gfx::Rect(10, 10), // visible_rect | 259 base::Callback<void(const SkBitmap&)>()); // read_pixels_cb |
| 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 | 260 |
| 267 VideoFrame::MailboxHolder* mailbox_holder = frame->texture_mailbox(); | 261 gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); |
| 268 | 262 |
| 269 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]); | 263 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); |
| 270 EXPECT_EQ(sync_point, mailbox_holder->sync_point()); | 264 EXPECT_EQ(target, mailbox_holder->texture_target); |
| 271 EXPECT_EQ(target, frame->texture_target()); | 265 EXPECT_EQ(sync_point, mailbox_holder->sync_point); |
| 272 | 266 |
| 273 // Finish using the mailbox_holder and drop our reference. | 267 // Finish using the mailbox_holder and drop our reference. |
| 274 sync_point = 10; | 268 sync_point = 10; |
| 275 mailbox_holder->Resync(sync_point); | 269 mailbox_holder->sync_point = sync_point; |
| 276 } | 270 } |
| 277 EXPECT_EQ(sync_point, called_sync_point); | 271 EXPECT_EQ(sync_point, called_sync_point); |
| 278 } | 272 } |
| 279 | 273 |
| 280 } // namespace media | 274 } // namespace media |
| OLD | NEW |