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/mac/video_frame_mac.h" | 5 #include "media/base/mac/video_frame_mac.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "media/base/mac/corevideo_glue.h" | 13 #include "media/base/mac/corevideo_glue.h" |
| 14 #include "media/base/video_frame.h" | 14 #include "media/base/video_frame.h" |
| 15 | 15 |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace media { | 18 namespace media { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const int kWidth = 64; | 22 const int kWidth = 64; |
| 23 const int kHeight = 48; | 23 const int kHeight = 48; |
| 24 const int kVisibleRectOffset = 4; | |
| 24 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); | 25 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); |
| 25 | 26 |
| 26 struct FormatPair { | 27 struct FormatPair { |
| 27 VideoPixelFormat chrome; | 28 VideoPixelFormat chrome; |
| 28 OSType corevideo; | 29 OSType corevideo; |
| 29 }; | 30 }; |
| 30 | 31 |
| 31 void Increment(int* i) { | 32 void Increment(int* i) { |
| 32 ++(*i); | 33 ++(*i); |
| 33 } | 34 } |
| 34 | 35 |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 37 TEST(VideoFrameMac, CheckBasicAttributes) { | 38 TEST(VideoFrameMac, CheckBasicAttributes) { |
| 38 gfx::Size size(kWidth, kHeight); | 39 gfx::Size size(kWidth, kHeight); |
| 39 auto frame = VideoFrame::CreateFrame(PIXEL_FORMAT_I420, size, gfx::Rect(size), | 40 auto frame = VideoFrame::CreateFrame(PIXEL_FORMAT_I420, size, gfx::Rect(size), |
| 40 size, kTimestamp); | 41 size, kTimestamp); |
| 41 ASSERT_TRUE(frame.get()); | 42 ASSERT_TRUE(frame.get()); |
| 42 | 43 |
| 43 auto pb = WrapVideoFrameInCVPixelBuffer(*frame); | 44 auto pb = WrapVideoFrameInCVPixelBuffer(*frame); |
| 44 ASSERT_TRUE(pb.get()); | 45 ASSERT_TRUE(pb.get()); |
| 45 | 46 |
| 46 gfx::Size coded_size = frame->coded_size(); | 47 const gfx::Size coded_size = frame->coded_size(); |
| 47 VideoPixelFormat format = frame->format(); | 48 const VideoPixelFormat format = frame->format(); |
| 48 | 49 |
| 49 EXPECT_EQ(coded_size.width(), static_cast<int>(CVPixelBufferGetWidth(pb))); | 50 EXPECT_EQ(coded_size.width(), static_cast<int>(CVPixelBufferGetWidth(pb))); |
| 50 EXPECT_EQ(coded_size.height(), static_cast<int>(CVPixelBufferGetHeight(pb))); | 51 EXPECT_EQ(coded_size.height(), static_cast<int>(CVPixelBufferGetHeight(pb))); |
| 51 EXPECT_EQ(VideoFrame::NumPlanes(format), CVPixelBufferGetPlaneCount(pb)); | 52 EXPECT_EQ(VideoFrame::NumPlanes(format), CVPixelBufferGetPlaneCount(pb)); |
| 52 | 53 |
| 53 CVPixelBufferLockBaseAddress(pb, 0); | 54 CVPixelBufferLockBaseAddress(pb, 0); |
| 54 for (size_t i = 0; i < VideoFrame::NumPlanes(format); ++i) { | 55 for (size_t i = 0; i < VideoFrame::NumPlanes(format); ++i) { |
| 55 gfx::Size plane_size = VideoFrame::PlaneSize(format, i, coded_size); | 56 const gfx::Size plane_size = VideoFrame::PlaneSize(format, i, coded_size); |
| 56 EXPECT_EQ(plane_size.width(), | 57 EXPECT_EQ(plane_size.width(), |
| 57 static_cast<int>(CVPixelBufferGetWidthOfPlane(pb, i))); | 58 static_cast<int>(CVPixelBufferGetWidthOfPlane(pb, i))); |
| 58 EXPECT_EQ(plane_size.height(), | 59 EXPECT_EQ(plane_size.height(), |
| 59 static_cast<int>(CVPixelBufferGetHeightOfPlane(pb, i))); | 60 static_cast<int>(CVPixelBufferGetHeightOfPlane(pb, i))); |
| 60 EXPECT_EQ(frame->data(i), CVPixelBufferGetBaseAddressOfPlane(pb, i)); | 61 EXPECT_EQ(frame->data(i), CVPixelBufferGetBaseAddressOfPlane(pb, i)); |
| 61 } | 62 } |
| 62 CVPixelBufferUnlockBaseAddress(pb, 0); | 63 CVPixelBufferUnlockBaseAddress(pb, 0); |
| 63 } | 64 } |
| 64 | 65 |
| 65 TEST(VideoFrameMac, CheckFormats) { | 66 TEST(VideoFrameMac, CheckFormats) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 EXPECT_EQ(1, instances_destroyed); | 109 EXPECT_EQ(1, instances_destroyed); |
| 109 } | 110 } |
| 110 | 111 |
| 111 TEST(VideoFrameMac, CheckWrapperFrame) { | 112 TEST(VideoFrameMac, CheckWrapperFrame) { |
| 112 const FormatPair format_pairs[] = { | 113 const FormatPair format_pairs[] = { |
| 113 {PIXEL_FORMAT_I420, kCVPixelFormatType_420YpCbCr8Planar}, | 114 {PIXEL_FORMAT_I420, kCVPixelFormatType_420YpCbCr8Planar}, |
| 114 {PIXEL_FORMAT_NV12, | 115 {PIXEL_FORMAT_NV12, |
| 115 CoreVideoGlue::kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange}, | 116 CoreVideoGlue::kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange}, |
| 116 }; | 117 }; |
| 117 | 118 |
| 118 gfx::Size size(kWidth, kHeight); | 119 const gfx::Size size(kWidth, kHeight); |
| 119 for (const auto& format_pair : format_pairs) { | 120 for (const auto& format_pair : format_pairs) { |
| 120 base::ScopedCFTypeRef<CVPixelBufferRef> pb; | 121 base::ScopedCFTypeRef<CVPixelBufferRef> pb; |
| 121 CVPixelBufferCreate(nullptr, kWidth, kHeight, format_pair.corevideo, | 122 CVPixelBufferCreate(nullptr, kWidth, kHeight, format_pair.corevideo, |
| 122 nullptr, pb.InitializeInto()); | 123 nullptr, pb.InitializeInto()); |
| 123 ASSERT_TRUE(pb.get()); | 124 ASSERT_TRUE(pb.get()); |
| 124 | 125 |
| 125 auto frame = VideoFrame::WrapCVPixelBuffer(pb.get(), kTimestamp); | 126 auto frame = VideoFrame::WrapCVPixelBuffer(pb.get(), kTimestamp); |
| 126 ASSERT_TRUE(frame.get()); | 127 ASSERT_TRUE(frame.get()); |
| 127 EXPECT_EQ(pb.get(), frame->cv_pixel_buffer()); | 128 EXPECT_EQ(pb.get(), frame->cv_pixel_buffer()); |
| 128 EXPECT_EQ(format_pair.chrome, frame->format()); | 129 EXPECT_EQ(format_pair.chrome, frame->format()); |
| 129 | 130 |
| 130 frame = nullptr; | 131 frame = nullptr; |
| 131 EXPECT_EQ(1, CFGetRetainCount(pb.get())); | 132 EXPECT_EQ(1, CFGetRetainCount(pb.get())); |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 | 135 |
| 136 TEST(VideoFrameMac, CheckFrameWithVisibleRect) { | |
|
miu
2016/03/24 20:29:00
nit: Please rename to something more meaningful.
emircan
2016/03/25 07:43:22
Done.
| |
| 137 const gfx::Size size(kWidth, kHeight); | |
|
miu
2016/03/24 20:29:00
nit: Please name this coded_size for clarity.
emircan
2016/03/25 07:43:22
Done.
| |
| 138 const gfx::Rect visible_rect(kVisibleRectOffset, kVisibleRectOffset, | |
| 139 kWidth - 2 * kVisibleRectOffset, | |
| 140 kHeight - 2 * kVisibleRectOffset); | |
| 141 auto frame = VideoFrame::CreateFrame(PIXEL_FORMAT_I420, size, visible_rect, | |
| 142 size, kTimestamp); | |
| 143 ASSERT_TRUE(frame.get()); | |
| 144 auto pb = WrapVideoFrameInCVPixelBuffer(*frame); | |
| 145 ASSERT_TRUE(pb.get()); | |
| 146 EXPECT_EQ(kCVPixelFormatType_420YpCbCr8Planar, | |
| 147 CVPixelBufferGetPixelFormatType(pb)); | |
| 148 EXPECT_EQ(visible_rect.width(), static_cast<int>(CVPixelBufferGetWidth(pb))); | |
| 149 EXPECT_EQ(visible_rect.height(), | |
| 150 static_cast<int>(CVPixelBufferGetHeight(pb))); | |
| 151 | |
| 152 CVPixelBufferLockBaseAddress(pb, 0); | |
| 153 for (size_t i = 0; i < VideoFrame::NumPlanes(frame->format()); ++i) { | |
| 154 const gfx::Size plane_size = | |
| 155 VideoFrame::PlaneSize(frame->format(), i, visible_rect.size()); | |
| 156 EXPECT_EQ(plane_size.width(), | |
| 157 static_cast<int>(CVPixelBufferGetWidthOfPlane(pb, i))); | |
| 158 EXPECT_EQ(plane_size.height(), | |
| 159 static_cast<int>(CVPixelBufferGetHeightOfPlane(pb, i))); | |
| 160 EXPECT_EQ(frame->visible_data(i), | |
| 161 CVPixelBufferGetBaseAddressOfPlane(pb, i)); | |
| 162 } | |
|
miu
2016/03/24 20:29:00
Also, you should check the value returned by CVPix
miu
2016/03/24 20:29:00
Per earlier discussion, I think it would be good t
emircan
2016/03/25 07:43:22
Ok, that should equals stride as well.
emircan
2016/03/25 07:43:22
Done.
| |
| 163 CVPixelBufferUnlockBaseAddress(pb, 0); | |
| 164 } | |
| 165 | |
| 135 } // namespace media | 166 } // namespace media |
| OLD | NEW |