I420VideoFrame: Adding: 1. IsEmpty 2. ResetSize

Review URL: https://webrtc-codereview.appspot.com/857011

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2924 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mikhal@webrtc.org 2012-10-15 16:12:09 +00:00
parent 89752611a1
commit dfc6b576a7
5 changed files with 81 additions and 21 deletions

View File

@ -56,9 +56,12 @@ int I420VideoFrame::CreateFrame(int size_y, const uint8_t* buffer_y,
}
int I420VideoFrame::CopyFrame(const I420VideoFrame& videoFrame) {
int ret = CreateFrame(videoFrame.size(kYPlane), videoFrame.buffer(kYPlane),
videoFrame.size(kUPlane), videoFrame.buffer(kUPlane),
videoFrame.size(kVPlane), videoFrame.buffer(kVPlane),
int ret = CreateFrame(videoFrame.allocated_size(kYPlane),
videoFrame.buffer(kYPlane),
videoFrame.allocated_size(kUPlane),
videoFrame.buffer(kUPlane),
videoFrame.allocated_size(kVPlane),
videoFrame.buffer(kVPlane),
videoFrame.width_, videoFrame.height_,
videoFrame.stride(kYPlane), videoFrame.stride(kUPlane),
videoFrame.stride(kVPlane));
@ -93,7 +96,7 @@ const uint8_t* I420VideoFrame::buffer(PlaneType type) const {
return NULL;
}
int I420VideoFrame::size(PlaneType type) const {
int I420VideoFrame::allocated_size(PlaneType type) const {
const Plane* plane_ptr = GetPlane(type);
if (plane_ptr)
return plane_ptr->allocated_size();
@ -125,6 +128,17 @@ int I420VideoFrame::set_height(int height) {
return 0;
}
bool I420VideoFrame::IsZeroSize() {
return (y_plane_.IsZeroSize() && u_plane_.IsZeroSize() &&
v_plane_.IsZeroSize());
}
void I420VideoFrame::ResetSize() {
y_plane_.ResetSize();
u_plane_.ResetSize();
v_plane_.ResetSize();
}
int I420VideoFrame::CheckDimensions(int width, int height,
int stride_y, int stride_u, int stride_v) {
int half_width = (width + 1) / 2;

View File

@ -26,12 +26,14 @@ int ExpectedSize(int plane_stride, int image_height, PlaneType type);
TEST(TestI420VideoFrame, InitialValues) {
I420VideoFrame frame;
// Invalid arguments - one call for each variable.
EXPECT_TRUE(frame.IsZeroSize());
EXPECT_EQ(-1, frame.CreateEmptyFrame(0, 10, 10, 14, 14));
EXPECT_EQ(-1, frame.CreateEmptyFrame(10, -1, 10, 90, 14));
EXPECT_EQ(-1, frame.CreateEmptyFrame(10, 10, 0, 14, 18));
EXPECT_EQ(-1, frame.CreateEmptyFrame(10, 10, 10, -2, 13));
EXPECT_EQ(-1, frame.CreateEmptyFrame(10, 10, 10, 14, 0));
EXPECT_EQ(0, frame.CreateEmptyFrame(10, 10, 10, 14, 90));
EXPECT_FALSE(frame.IsZeroSize());
}
TEST(TestI420VideoFrame, WidthHeightValues) {
@ -59,9 +61,20 @@ TEST(TestI420VideoFrame, SizeAllocation) {
int stride_u = frame.stride(kUPlane);
int stride_v = frame.stride(kVPlane);
// Verify that allocated size was computed correctly.
EXPECT_EQ(ExpectedSize(stride_y, height, kYPlane), frame.size(kYPlane));
EXPECT_EQ(ExpectedSize(stride_u, height, kUPlane), frame.size(kUPlane));
EXPECT_EQ(ExpectedSize(stride_v, height, kVPlane), frame.size(kVPlane));
EXPECT_EQ(ExpectedSize(stride_y, height, kYPlane),
frame.allocated_size(kYPlane));
EXPECT_EQ(ExpectedSize(stride_u, height, kUPlane),
frame.allocated_size(kUPlane));
EXPECT_EQ(ExpectedSize(stride_v, height, kVPlane),
frame.allocated_size(kVPlane));
}
TEST(TestI420VideoFrame, ResetSize) {
I420VideoFrame frame;
EXPECT_EQ(0, frame. CreateEmptyFrame(10, 10, 12, 14, 220));
EXPECT_FALSE(frame.IsZeroSize());
frame.ResetSize();
EXPECT_TRUE(frame.IsZeroSize());
}
TEST(TestI420VideoFrame, CopyFrame) {
@ -94,9 +107,9 @@ TEST(TestI420VideoFrame, CopyFrame) {
// Frame of smaller dimensions - allocated sizes should not vary.
EXPECT_EQ(0, frame1.CopyFrame(frame2));
EXPECT_TRUE(EqualFramesExceptSize(frame1, frame2));
EXPECT_EQ(kSizeY, frame1.size(kYPlane));
EXPECT_EQ(kSizeU, frame1.size(kUPlane));
EXPECT_EQ(kSizeV, frame1.size(kVPlane));
EXPECT_EQ(kSizeY, frame1.allocated_size(kYPlane));
EXPECT_EQ(kSizeU, frame1.allocated_size(kUPlane));
EXPECT_EQ(kSizeV, frame1.allocated_size(kVPlane));
// Verify copy of all parameters.
// Frame of larger dimensions - update allocated sizes.
EXPECT_EQ(0, frame2.CopyFrame(frame1));
@ -128,9 +141,9 @@ TEST(TestI420VideoFrame, CopyBuffer) {
EXPECT_EQ(memcmp(buffer_u, frame2.buffer(kUPlane), kSizeUv), 0);
EXPECT_EQ(memcmp(buffer_v, frame2.buffer(kVPlane), kSizeUv), 0);
// Comapre size.
EXPECT_LE(kSizeY, frame2.size(kYPlane));
EXPECT_LE(kSizeUv, frame2.size(kUPlane));
EXPECT_LE(kSizeUv, frame2.size(kVPlane));
EXPECT_LE(kSizeY, frame2.allocated_size(kYPlane));
EXPECT_LE(kSizeUv, frame2.allocated_size(kUPlane));
EXPECT_LE(kSizeUv, frame2.allocated_size(kVPlane));
}
TEST(TestI420VideoFrame, FrameSwap) {
@ -204,9 +217,9 @@ bool EqualFrames(const I420VideoFrame& frame1,
return false;
// Compare allocated memory size.
bool ret = true;
ret |= (frame1.size(kYPlane) == frame2.size(kYPlane));
ret |= (frame1.size(kUPlane) == frame2.size(kUPlane));
ret |= (frame1.size(kVPlane) == frame2.size(kVPlane));
ret |= (frame1.allocated_size(kYPlane) == frame2.allocated_size(kYPlane));
ret |= (frame1.allocated_size(kUPlane) == frame2.allocated_size(kUPlane));
ret |= (frame1.allocated_size(kVPlane) == frame2.allocated_size(kVPlane));
return ret;
}
@ -223,9 +236,12 @@ bool EqualFramesExceptSize(const I420VideoFrame& frame1,
if (!ret)
return false;
// Memory should be the equal for the minimum of the two sizes.
int size_y = std::min(frame1.size(kYPlane), frame2.size(kYPlane));
int size_u = std::min(frame1.size(kUPlane), frame2.size(kUPlane));
int size_v = std::min(frame1.size(kVPlane), frame2.size(kVPlane));
int size_y = std::min(frame1.allocated_size(kYPlane),
frame2.allocated_size(kYPlane));
int size_u = std::min(frame1.allocated_size(kUPlane),
frame2.allocated_size(kUPlane));
int size_v = std::min(frame1.allocated_size(kVPlane),
frame2.allocated_size(kVPlane));
int ret_val = 0;
ret_val += memcmp(frame1.buffer(kYPlane), frame2.buffer(kYPlane), size_y);
ret_val += memcmp(frame1.buffer(kUPlane), frame2.buffer(kUPlane), size_u);

View File

@ -63,7 +63,7 @@ class I420VideoFrame {
const uint8_t* buffer(PlaneType type) const;
// Get allocated size per plane.
int size(PlaneType type) const;
int allocated_size(PlaneType type) const;
// Get allocated stride per plane.
int stride(PlaneType type) const;
@ -93,6 +93,13 @@ class I420VideoFrame {
// Get render time in miliseconds.
int64_t render_time_ms() const {return render_time_ms_;}
// Return true if underlying plane buffers are of zero size, false if not.
bool IsZeroSize();
// Reset underlying plane buffers sizes to 0. This function doesn't
// clear memory.
void ResetSize();
private:
// Verifies legality of parameters.
// Return value: 0 on success ,-1 on error.

View File

@ -43,6 +43,12 @@ class Plane {
// Get allocated size.
int allocated_size() const {return allocated_size_;}
// Set actual size.
void ResetSize() {plane_size_ = 0;};
// Return true is plane size is zero, false if not.
bool IsZeroSize() {return plane_size_ == 0;};
// Get stride value.
int stride() const {return stride_;}

View File

@ -17,11 +17,12 @@
namespace webrtc {
TEST(TestPlane, CreateEmptyPlaneialValues) {
TEST(TestPlane, CreateEmptyPlaneValues) {
Plane plane;
int size, stride;
EXPECT_EQ(0, plane.allocated_size());
EXPECT_EQ(0, plane.stride());
EXPECT_TRUE(plane.IsZeroSize());
size = 0;
stride = 20;
EXPECT_EQ(-1, plane.CreateEmptyPlane(size, stride, 1));
@ -33,6 +34,22 @@ TEST(TestPlane, CreateEmptyPlaneialValues) {
EXPECT_EQ(0, plane.CreateEmptyPlane(size, stride, size));
EXPECT_EQ(size, plane.allocated_size());
EXPECT_EQ(stride, plane.stride());
EXPECT_FALSE(plane.IsZeroSize());
}
TEST(TestPlane, ResetSize) {
Plane plane;
EXPECT_TRUE(plane.IsZeroSize());
int allocated_size, plane_size, stride;
EXPECT_EQ(0, plane.allocated_size());
allocated_size = 30;
plane_size = 20;
stride = 10;
EXPECT_EQ(0, plane.CreateEmptyPlane(allocated_size, stride, plane_size));
EXPECT_EQ(allocated_size, plane.allocated_size());
EXPECT_FALSE(plane.IsZeroSize());
plane.ResetSize();
EXPECT_TRUE(plane.IsZeroSize());
}
TEST(TestPlane, PlaneCopy) {