| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/buffers.h" | 5 #include "media/base/buffers.h" |
| 6 #include "media/base/mock_media_filters.h" | 6 #include "media/base/mock_filters.h" |
| 7 #include "media/base/video_frame_impl.h" | 7 #include "media/base/video_frame_impl.h" |
| 8 #include "media/base/yuv_convert.h" | 8 #include "media/base/yuv_convert.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 using media::VideoFrameImpl; | 11 namespace media { |
| 12 using media::VideoSurface; | |
| 13 | 12 |
| 14 namespace { | 13 // Helper function that initializes a YV12 frame with white and black scan |
| 14 // lines based on the |white_to_black| parameter. If 0, then the entire |
| 15 // frame will be black, if 1 then the entire frame will be white. |
| 16 void InitializeYV12Frame(VideoFrame* frame, double white_to_black) { |
| 17 VideoSurface surface; |
| 18 if (!frame->Lock(&surface)) { |
| 19 ADD_FAILURE(); |
| 20 return; |
| 21 } |
| 22 EXPECT_EQ(surface.format, VideoSurface::YV12); |
| 23 size_t first_black_row = static_cast<size_t>(surface.height * white_to_black); |
| 24 uint8* y_plane = surface.data[VideoSurface::kYPlane]; |
| 25 for (size_t row = 0; row < surface.height; ++row) { |
| 26 int color = (row < first_black_row) ? 0xFF : 0x00; |
| 27 memset(y_plane, color, surface.width); |
| 28 y_plane += surface.strides[VideoSurface::kYPlane]; |
| 29 } |
| 30 uint8* u_plane = surface.data[VideoSurface::kUPlane]; |
| 31 uint8* v_plane = surface.data[VideoSurface::kVPlane]; |
| 32 for (size_t row = 0; row < surface.height; row += 2) { |
| 33 memset(u_plane, 0x80, surface.width / 2); |
| 34 memset(v_plane, 0x80, surface.width / 2); |
| 35 u_plane += surface.strides[VideoSurface::kUPlane]; |
| 36 v_plane += surface.strides[VideoSurface::kVPlane]; |
| 37 } |
| 38 frame->Unlock(); |
| 39 } |
| 15 | 40 |
| 16 // Given a |yv12_frame| this method converts the YV12 frame to RGBA and | 41 // Given a |yv12_frame| this method converts the YV12 frame to RGBA and |
| 17 // makes sure that all the pixels of the RBG frame equal |expect_rgb_color|. | 42 // makes sure that all the pixels of the RBG frame equal |expect_rgb_color|. |
| 18 void ExpectFrameColor(media::VideoFrame* yv12_frame, uint32 expect_rgb_color) { | 43 void ExpectFrameColor(media::VideoFrame* yv12_frame, uint32 expect_rgb_color) { |
| 19 // On linux and mac builds if you directly compare using EXPECT_EQ and use | 44 // On linux and mac builds if you directly compare using EXPECT_EQ and use |
| 20 // the VideoSurface::kNumxxxPlanes constants, it generates an error when | 45 // the VideoSurface::kNumxxxPlanes constants, it generates an error when |
| 21 // linking. These are declared so that we can compare against locals. | 46 // linking. These are declared so that we can compare against locals. |
| 22 const size_t expect_yuv_planes = VideoSurface::kNumYUVPlanes; | 47 const size_t expect_yuv_planes = VideoSurface::kNumYUVPlanes; |
| 23 const size_t expect_rgb_planes = VideoSurface::kNumRGBPlanes; | 48 const size_t expect_rgb_planes = VideoSurface::kNumRGBPlanes; |
| 24 | 49 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 rgb_surface.data[VideoSurface::kRGBPlane] + | 83 rgb_surface.data[VideoSurface::kRGBPlane] + |
| 59 (rgb_surface.strides[VideoSurface::kRGBPlane] * row)); | 84 (rgb_surface.strides[VideoSurface::kRGBPlane] * row)); |
| 60 for (size_t col = 0; col < rgb_surface.width; ++col) { | 85 for (size_t col = 0; col < rgb_surface.width; ++col) { |
| 61 EXPECT_EQ(rgb_row_data[col], expect_rgb_color); | 86 EXPECT_EQ(rgb_row_data[col], expect_rgb_color); |
| 62 } | 87 } |
| 63 } | 88 } |
| 64 rgb_frame->Unlock(); | 89 rgb_frame->Unlock(); |
| 65 yv12_frame->Unlock(); | 90 yv12_frame->Unlock(); |
| 66 } | 91 } |
| 67 | 92 |
| 68 } // namespace | 93 TEST(VideoFrameImpl, CreateFrame) { |
| 69 | |
| 70 | |
| 71 TEST(VideoFrameImpl, Basic) { | |
| 72 const size_t kWidth = 64; | 94 const size_t kWidth = 64; |
| 73 const size_t kHeight = 48; | 95 const size_t kHeight = 48; |
| 74 const base::TimeDelta kTimestampA = base::TimeDelta::FromMicroseconds(1337); | 96 const base::TimeDelta kTimestampA = base::TimeDelta::FromMicroseconds(1337); |
| 75 const base::TimeDelta kDurationA = base::TimeDelta::FromMicroseconds(1667); | 97 const base::TimeDelta kDurationA = base::TimeDelta::FromMicroseconds(1667); |
| 76 const base::TimeDelta kTimestampB = base::TimeDelta::FromMicroseconds(1234); | 98 const base::TimeDelta kTimestampB = base::TimeDelta::FromMicroseconds(1234); |
| 77 const base::TimeDelta kDurationB = base::TimeDelta::FromMicroseconds(5678); | 99 const base::TimeDelta kDurationB = base::TimeDelta::FromMicroseconds(5678); |
| 78 | 100 |
| 79 // Create a YV12 Video Frame. | 101 // Create a YV12 Video Frame. |
| 80 scoped_refptr<media::VideoFrame> frame; | 102 scoped_refptr<media::VideoFrame> frame; |
| 81 media::VideoFrameImpl::CreateFrame(media::VideoSurface::YV12, kWidth, kHeight, | 103 VideoFrameImpl::CreateFrame(media::VideoSurface::YV12, kWidth, kHeight, |
| 82 kTimestampA, kDurationA, &frame); | 104 kTimestampA, kDurationA, &frame); |
| 83 ASSERT_TRUE(frame); | 105 ASSERT_TRUE(frame); |
| 84 | 106 |
| 85 // Test StreamSample implementation. | 107 // Test StreamSample implementation. |
| 86 EXPECT_TRUE(kTimestampA == frame->GetTimestamp()); | 108 EXPECT_TRUE(kTimestampA == frame->GetTimestamp()); |
| 87 EXPECT_TRUE(kDurationA == frame->GetDuration()); | 109 EXPECT_TRUE(kDurationA == frame->GetDuration()); |
| 88 EXPECT_FALSE(frame->IsEndOfStream()); | 110 EXPECT_FALSE(frame->IsEndOfStream()); |
| 89 EXPECT_FALSE(frame->IsDiscontinuous()); | 111 EXPECT_FALSE(frame->IsDiscontinuous()); |
| 90 frame->SetTimestamp(kTimestampB); | 112 frame->SetTimestamp(kTimestampB); |
| 91 frame->SetDuration(kDurationB); | 113 frame->SetDuration(kDurationB); |
| 92 EXPECT_TRUE(kTimestampB == frame->GetTimestamp()); | 114 EXPECT_TRUE(kTimestampB == frame->GetTimestamp()); |
| 93 EXPECT_TRUE(kDurationB == frame->GetDuration()); | 115 EXPECT_TRUE(kDurationB == frame->GetDuration()); |
| 94 EXPECT_FALSE(frame->IsEndOfStream()); | 116 EXPECT_FALSE(frame->IsEndOfStream()); |
| 95 frame->SetDiscontinuous(true); | 117 frame->SetDiscontinuous(true); |
| 96 EXPECT_TRUE(frame->IsDiscontinuous()); | 118 EXPECT_TRUE(frame->IsDiscontinuous()); |
| 97 frame->SetDiscontinuous(false); | 119 frame->SetDiscontinuous(false); |
| 98 EXPECT_FALSE(frame->IsDiscontinuous()); | 120 EXPECT_FALSE(frame->IsDiscontinuous()); |
| 99 | 121 |
| 100 // Test VideoFrame implementation. | 122 // Test VideoFrame implementation. |
| 101 media::old_mocks::MockVideoDecoder::InitializeYV12Frame(frame, 0.0f); | 123 InitializeYV12Frame(frame, 0.0f); |
| 102 ExpectFrameColor(frame, 0xFF000000); | 124 ExpectFrameColor(frame, 0xFF000000); |
| 103 media::old_mocks::MockVideoDecoder::InitializeYV12Frame(frame, 1.0f); | 125 InitializeYV12Frame(frame, 1.0f); |
| 104 ExpectFrameColor(frame, 0xFFFFFFFF); | 126 ExpectFrameColor(frame, 0xFFFFFFFF); |
| 105 | 127 |
| 106 // Test an empty frame. | 128 // Test an empty frame. |
| 107 media::VideoFrameImpl::CreateEmptyFrame(&frame); | 129 VideoFrameImpl::CreateEmptyFrame(&frame); |
| 108 EXPECT_TRUE(frame->IsEndOfStream()); | 130 EXPECT_TRUE(frame->IsEndOfStream()); |
| 109 } | 131 } |
| 132 |
| 133 } // namespace media |
| OLD | NEW |