Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 | 222 |
| 223 static void FrameNoLongerNeededCallback( | 223 static void FrameNoLongerNeededCallback( |
| 224 const scoped_refptr<media::VideoFrame>& frame, | 224 const scoped_refptr<media::VideoFrame>& frame, |
| 225 bool* triggered) { | 225 bool* triggered) { |
| 226 *triggered = true; | 226 *triggered = true; |
| 227 } | 227 } |
| 228 | 228 |
| 229 TEST(VideoFrame, WrapVideoFrame) { | 229 TEST(VideoFrame, WrapVideoFrame) { |
| 230 const int kWidth = 4; | 230 const int kWidth = 4; |
| 231 const int kHeight = 4; | 231 const int kHeight = 4; |
| 232 const base::TimeDelta kFrameDuration = base::TimeDelta::FromMicroseconds(42); | |
| 233 | |
| 232 scoped_refptr<media::VideoFrame> frame; | 234 scoped_refptr<media::VideoFrame> frame; |
| 233 bool done_callback_was_run = false; | 235 bool done_callback_was_run = false; |
| 234 { | 236 { |
| 235 scoped_refptr<media::VideoFrame> wrapped_frame = | 237 scoped_refptr<media::VideoFrame> wrapped_frame = |
| 236 VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight)); | 238 VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight)); |
| 237 ASSERT_TRUE(wrapped_frame.get()); | 239 ASSERT_TRUE(wrapped_frame.get()); |
| 238 | 240 |
| 239 gfx::Rect visible_rect(1, 1, 1, 1); | 241 gfx::Rect visible_rect(1, 1, 1, 1); |
| 240 gfx::Size natural_size = visible_rect.size(); | 242 gfx::Size natural_size = visible_rect.size(); |
| 241 frame = media::VideoFrame::WrapVideoFrame( | 243 wrapped_frame->metadata()->SetTimeDelta( |
| 242 wrapped_frame, visible_rect, natural_size); | 244 media::VideoFrameMetadata::FRAME_DURATION, kFrameDuration); |
| 243 frame->AddDestructionObserver( | 245 frame = media::VideoFrame::WrapVideoFrame(wrapped_frame, visible_rect, |
| 244 base::Bind(&FrameNoLongerNeededCallback, wrapped_frame, | 246 natural_size); |
| 245 &done_callback_was_run)); | 247 frame->AddDestructionObserver(base::Bind( |
| 248 &FrameNoLongerNeededCallback, wrapped_frame, &done_callback_was_run)); | |
| 249 | |
| 246 EXPECT_EQ(wrapped_frame->coded_size(), frame->coded_size()); | 250 EXPECT_EQ(wrapped_frame->coded_size(), frame->coded_size()); |
| 247 EXPECT_EQ(wrapped_frame->data(media::VideoFrame::kYPlane), | 251 EXPECT_EQ(wrapped_frame->data(media::VideoFrame::kYPlane), |
| 248 frame->data(media::VideoFrame::kYPlane)); | 252 frame->data(media::VideoFrame::kYPlane)); |
| 249 EXPECT_NE(wrapped_frame->visible_rect(), frame->visible_rect()); | 253 EXPECT_NE(wrapped_frame->visible_rect(), frame->visible_rect()); |
| 250 EXPECT_EQ(visible_rect, frame->visible_rect()); | 254 EXPECT_EQ(visible_rect, frame->visible_rect()); |
| 251 EXPECT_NE(wrapped_frame->natural_size(), frame->natural_size()); | 255 EXPECT_NE(wrapped_frame->natural_size(), frame->natural_size()); |
| 252 EXPECT_EQ(natural_size, frame->natural_size()); | 256 EXPECT_EQ(natural_size, frame->natural_size()); |
| 257 | |
| 258 // Verify metada was copied to the wrapped frame | |
|
watk
2016/03/02 21:25:16
s/metada/metadata
Full stop.
tguilbert
2016/03/03 21:42:04
Done.
| |
| 259 base::TimeDelta frame_duration; | |
| 260 bool frame_has_duration = frame->metadata()->GetTimeDelta( | |
| 261 media::VideoFrameMetadata::FRAME_DURATION, &frame_duration); | |
| 262 | |
| 263 EXPECT_TRUE(frame_has_duration); | |
| 264 if (frame_has_duration) { | |
|
watk
2016/03/02 21:25:16
No need to handle !frame_has_duration because that
tguilbert
2016/03/03 21:42:04
Good to know, thank you for the tip.
| |
| 265 EXPECT_EQ(frame_duration, kFrameDuration); | |
| 266 | |
| 267 // Verify the metadata copy was a deep copy | |
|
watk
2016/03/02 21:25:16
Full stop.
tguilbert
2016/03/03 21:42:04
Done.
| |
| 268 wrapped_frame->metadata()->Clear(); | |
| 269 EXPECT_NE( | |
| 270 wrapped_frame->metadata()->HasKey( | |
| 271 media::VideoFrameMetadata::FRAME_DURATION), | |
| 272 frame->metadata()->HasKey(media::VideoFrameMetadata::FRAME_DURATION)); | |
| 273 } | |
| 253 } | 274 } |
| 254 | 275 |
| 255 EXPECT_FALSE(done_callback_was_run); | 276 EXPECT_FALSE(done_callback_was_run); |
| 256 frame = NULL; | 277 frame = NULL; |
| 257 EXPECT_TRUE(done_callback_was_run); | 278 EXPECT_TRUE(done_callback_was_run); |
| 258 } | 279 } |
| 259 | 280 |
| 260 // Ensure each frame is properly sized and allocated. Will trigger OOB reads | 281 // Ensure each frame is properly sized and allocated. Will trigger OOB reads |
| 261 // and writes as well as incorrect frame hashes otherwise. | 282 // and writes as well as incorrect frame hashes otherwise. |
| 262 TEST(VideoFrame, CheckFrameExtents) { | 283 TEST(VideoFrame, CheckFrameExtents) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 | 510 |
| 490 for (int i = 0; i < VideoFrameMetadata::NUM_KEYS; ++i) { | 511 for (int i = 0; i < VideoFrameMetadata::NUM_KEYS; ++i) { |
| 491 const VideoFrameMetadata::Key key = static_cast<VideoFrameMetadata::Key>(i); | 512 const VideoFrameMetadata::Key key = static_cast<VideoFrameMetadata::Key>(i); |
| 492 int value = -1; | 513 int value = -1; |
| 493 EXPECT_TRUE(result.GetInteger(key, &value)); | 514 EXPECT_TRUE(result.GetInteger(key, &value)); |
| 494 EXPECT_EQ(i, value); | 515 EXPECT_EQ(i, value); |
| 495 } | 516 } |
| 496 } | 517 } |
| 497 | 518 |
| 498 } // namespace media | 519 } // namespace media |
| OLD | NEW |