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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 uint8* u_plane = frame->data(VideoFrame::kUPlane); | 193 uint8* u_plane = frame->data(VideoFrame::kUPlane); |
194 uint8* v_plane = frame->data(VideoFrame::kVPlane); | 194 uint8* v_plane = frame->data(VideoFrame::kVPlane); |
195 for (int y = 0; y < frame->coded_size().height() / 2; ++y) { | 195 for (int y = 0; y < frame->coded_size().height() / 2; ++y) { |
196 EXPECT_EQ(0, memcmp(kExpectedUVRow, u_plane, arraysize(kExpectedUVRow))); | 196 EXPECT_EQ(0, memcmp(kExpectedUVRow, u_plane, arraysize(kExpectedUVRow))); |
197 EXPECT_EQ(0, memcmp(kExpectedUVRow, v_plane, arraysize(kExpectedUVRow))); | 197 EXPECT_EQ(0, memcmp(kExpectedUVRow, v_plane, arraysize(kExpectedUVRow))); |
198 u_plane += frame->stride(VideoFrame::kUPlane); | 198 u_plane += frame->stride(VideoFrame::kUPlane); |
199 v_plane += frame->stride(VideoFrame::kVPlane); | 199 v_plane += frame->stride(VideoFrame::kVPlane); |
200 } | 200 } |
201 } | 201 } |
202 | 202 |
| 203 static void FrameNoLongerNeededCallback( |
| 204 const scoped_refptr<media::VideoFrame>& frame, |
| 205 bool* triggered) { |
| 206 *triggered = true; |
| 207 } |
| 208 |
| 209 TEST(VideoFrame, WrapVideoFrame) { |
| 210 const int kWidth = 4; |
| 211 const int kHeight = 4; |
| 212 scoped_refptr<media::VideoFrame> frame; |
| 213 bool no_longer_needed_triggered = false; |
| 214 { |
| 215 scoped_refptr<media::VideoFrame> wrapped_frame = |
| 216 VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight)); |
| 217 ASSERT_TRUE(wrapped_frame.get()); |
| 218 |
| 219 gfx::Rect visible_rect(1, 1, 1, 1); |
| 220 frame = media::VideoFrame::WrapVideoFrame( |
| 221 wrapped_frame, visible_rect, |
| 222 base::Bind(&FrameNoLongerNeededCallback, wrapped_frame, |
| 223 &no_longer_needed_triggered)); |
| 224 EXPECT_EQ(wrapped_frame->coded_size(), frame->coded_size()); |
| 225 EXPECT_EQ(wrapped_frame->data(media::VideoFrame::kYPlane), |
| 226 frame->data(media::VideoFrame::kYPlane)); |
| 227 EXPECT_NE(wrapped_frame->visible_rect(), frame->visible_rect()); |
| 228 EXPECT_EQ(visible_rect, frame->visible_rect()); |
| 229 } |
| 230 |
| 231 EXPECT_FALSE(no_longer_needed_triggered); |
| 232 frame = NULL; |
| 233 EXPECT_TRUE(no_longer_needed_triggered); |
| 234 } |
| 235 |
203 // Ensure each frame is properly sized and allocated. Will trigger OOB reads | 236 // Ensure each frame is properly sized and allocated. Will trigger OOB reads |
204 // and writes as well as incorrect frame hashes otherwise. | 237 // and writes as well as incorrect frame hashes otherwise. |
205 TEST(VideoFrame, CheckFrameExtents) { | 238 TEST(VideoFrame, CheckFrameExtents) { |
206 // Each call consists of a VideoFrame::Format, # of planes, bytes per pixel, | 239 // Each call consists of a VideoFrame::Format, # of planes, bytes per pixel, |
207 // and the expected hash of all planes if filled with kFillByte (defined in | 240 // and the expected hash of all planes if filled with kFillByte (defined in |
208 // ExpectFrameExtents). | 241 // ExpectFrameExtents). |
209 ExpectFrameExtents( | 242 ExpectFrameExtents( |
210 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); | 243 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); |
211 ExpectFrameExtents( | 244 ExpectFrameExtents( |
212 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); | 245 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 EXPECT_EQ(sync_point, mailbox_holder->sync_point); | 298 EXPECT_EQ(sync_point, mailbox_holder->sync_point); |
266 | 299 |
267 // Finish using the mailbox_holder and drop our reference. | 300 // Finish using the mailbox_holder and drop our reference. |
268 sync_point = 10; | 301 sync_point = 10; |
269 mailbox_holder->sync_point = sync_point; | 302 mailbox_holder->sync_point = sync_point; |
270 } | 303 } |
271 EXPECT_EQ(sync_point, called_sync_point); | 304 EXPECT_EQ(sync_point, called_sync_point); |
272 } | 305 } |
273 | 306 |
274 } // namespace media | 307 } // namespace media |
OLD | NEW |