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:
parent
89752611a1
commit
dfc6b576a7
@ -56,9 +56,12 @@ int I420VideoFrame::CreateFrame(int size_y, const uint8_t* buffer_y,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int I420VideoFrame::CopyFrame(const I420VideoFrame& videoFrame) {
|
int I420VideoFrame::CopyFrame(const I420VideoFrame& videoFrame) {
|
||||||
int ret = CreateFrame(videoFrame.size(kYPlane), videoFrame.buffer(kYPlane),
|
int ret = CreateFrame(videoFrame.allocated_size(kYPlane),
|
||||||
videoFrame.size(kUPlane), videoFrame.buffer(kUPlane),
|
videoFrame.buffer(kYPlane),
|
||||||
videoFrame.size(kVPlane), videoFrame.buffer(kVPlane),
|
videoFrame.allocated_size(kUPlane),
|
||||||
|
videoFrame.buffer(kUPlane),
|
||||||
|
videoFrame.allocated_size(kVPlane),
|
||||||
|
videoFrame.buffer(kVPlane),
|
||||||
videoFrame.width_, videoFrame.height_,
|
videoFrame.width_, videoFrame.height_,
|
||||||
videoFrame.stride(kYPlane), videoFrame.stride(kUPlane),
|
videoFrame.stride(kYPlane), videoFrame.stride(kUPlane),
|
||||||
videoFrame.stride(kVPlane));
|
videoFrame.stride(kVPlane));
|
||||||
@ -93,7 +96,7 @@ const uint8_t* I420VideoFrame::buffer(PlaneType type) const {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int I420VideoFrame::size(PlaneType type) const {
|
int I420VideoFrame::allocated_size(PlaneType type) const {
|
||||||
const Plane* plane_ptr = GetPlane(type);
|
const Plane* plane_ptr = GetPlane(type);
|
||||||
if (plane_ptr)
|
if (plane_ptr)
|
||||||
return plane_ptr->allocated_size();
|
return plane_ptr->allocated_size();
|
||||||
@ -125,6 +128,17 @@ int I420VideoFrame::set_height(int height) {
|
|||||||
return 0;
|
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 I420VideoFrame::CheckDimensions(int width, int height,
|
||||||
int stride_y, int stride_u, int stride_v) {
|
int stride_y, int stride_u, int stride_v) {
|
||||||
int half_width = (width + 1) / 2;
|
int half_width = (width + 1) / 2;
|
||||||
|
@ -26,12 +26,14 @@ int ExpectedSize(int plane_stride, int image_height, PlaneType type);
|
|||||||
TEST(TestI420VideoFrame, InitialValues) {
|
TEST(TestI420VideoFrame, InitialValues) {
|
||||||
I420VideoFrame frame;
|
I420VideoFrame frame;
|
||||||
// Invalid arguments - one call for each variable.
|
// 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(0, 10, 10, 14, 14));
|
||||||
EXPECT_EQ(-1, frame.CreateEmptyFrame(10, -1, 10, 90, 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, 0, 14, 18));
|
||||||
EXPECT_EQ(-1, frame.CreateEmptyFrame(10, 10, 10, -2, 13));
|
EXPECT_EQ(-1, frame.CreateEmptyFrame(10, 10, 10, -2, 13));
|
||||||
EXPECT_EQ(-1, frame.CreateEmptyFrame(10, 10, 10, 14, 0));
|
EXPECT_EQ(-1, frame.CreateEmptyFrame(10, 10, 10, 14, 0));
|
||||||
EXPECT_EQ(0, frame.CreateEmptyFrame(10, 10, 10, 14, 90));
|
EXPECT_EQ(0, frame.CreateEmptyFrame(10, 10, 10, 14, 90));
|
||||||
|
EXPECT_FALSE(frame.IsZeroSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TestI420VideoFrame, WidthHeightValues) {
|
TEST(TestI420VideoFrame, WidthHeightValues) {
|
||||||
@ -59,9 +61,20 @@ TEST(TestI420VideoFrame, SizeAllocation) {
|
|||||||
int stride_u = frame.stride(kUPlane);
|
int stride_u = frame.stride(kUPlane);
|
||||||
int stride_v = frame.stride(kVPlane);
|
int stride_v = frame.stride(kVPlane);
|
||||||
// Verify that allocated size was computed correctly.
|
// Verify that allocated size was computed correctly.
|
||||||
EXPECT_EQ(ExpectedSize(stride_y, height, kYPlane), frame.size(kYPlane));
|
EXPECT_EQ(ExpectedSize(stride_y, height, kYPlane),
|
||||||
EXPECT_EQ(ExpectedSize(stride_u, height, kUPlane), frame.size(kUPlane));
|
frame.allocated_size(kYPlane));
|
||||||
EXPECT_EQ(ExpectedSize(stride_v, height, kVPlane), frame.size(kVPlane));
|
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) {
|
TEST(TestI420VideoFrame, CopyFrame) {
|
||||||
@ -94,9 +107,9 @@ TEST(TestI420VideoFrame, CopyFrame) {
|
|||||||
// Frame of smaller dimensions - allocated sizes should not vary.
|
// Frame of smaller dimensions - allocated sizes should not vary.
|
||||||
EXPECT_EQ(0, frame1.CopyFrame(frame2));
|
EXPECT_EQ(0, frame1.CopyFrame(frame2));
|
||||||
EXPECT_TRUE(EqualFramesExceptSize(frame1, frame2));
|
EXPECT_TRUE(EqualFramesExceptSize(frame1, frame2));
|
||||||
EXPECT_EQ(kSizeY, frame1.size(kYPlane));
|
EXPECT_EQ(kSizeY, frame1.allocated_size(kYPlane));
|
||||||
EXPECT_EQ(kSizeU, frame1.size(kUPlane));
|
EXPECT_EQ(kSizeU, frame1.allocated_size(kUPlane));
|
||||||
EXPECT_EQ(kSizeV, frame1.size(kVPlane));
|
EXPECT_EQ(kSizeV, frame1.allocated_size(kVPlane));
|
||||||
// Verify copy of all parameters.
|
// Verify copy of all parameters.
|
||||||
// Frame of larger dimensions - update allocated sizes.
|
// Frame of larger dimensions - update allocated sizes.
|
||||||
EXPECT_EQ(0, frame2.CopyFrame(frame1));
|
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_u, frame2.buffer(kUPlane), kSizeUv), 0);
|
||||||
EXPECT_EQ(memcmp(buffer_v, frame2.buffer(kVPlane), kSizeUv), 0);
|
EXPECT_EQ(memcmp(buffer_v, frame2.buffer(kVPlane), kSizeUv), 0);
|
||||||
// Comapre size.
|
// Comapre size.
|
||||||
EXPECT_LE(kSizeY, frame2.size(kYPlane));
|
EXPECT_LE(kSizeY, frame2.allocated_size(kYPlane));
|
||||||
EXPECT_LE(kSizeUv, frame2.size(kUPlane));
|
EXPECT_LE(kSizeUv, frame2.allocated_size(kUPlane));
|
||||||
EXPECT_LE(kSizeUv, frame2.size(kVPlane));
|
EXPECT_LE(kSizeUv, frame2.allocated_size(kVPlane));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TestI420VideoFrame, FrameSwap) {
|
TEST(TestI420VideoFrame, FrameSwap) {
|
||||||
@ -204,9 +217,9 @@ bool EqualFrames(const I420VideoFrame& frame1,
|
|||||||
return false;
|
return false;
|
||||||
// Compare allocated memory size.
|
// Compare allocated memory size.
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
ret |= (frame1.size(kYPlane) == frame2.size(kYPlane));
|
ret |= (frame1.allocated_size(kYPlane) == frame2.allocated_size(kYPlane));
|
||||||
ret |= (frame1.size(kUPlane) == frame2.size(kUPlane));
|
ret |= (frame1.allocated_size(kUPlane) == frame2.allocated_size(kUPlane));
|
||||||
ret |= (frame1.size(kVPlane) == frame2.size(kVPlane));
|
ret |= (frame1.allocated_size(kVPlane) == frame2.allocated_size(kVPlane));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,9 +236,12 @@ bool EqualFramesExceptSize(const I420VideoFrame& frame1,
|
|||||||
if (!ret)
|
if (!ret)
|
||||||
return false;
|
return false;
|
||||||
// Memory should be the equal for the minimum of the two sizes.
|
// 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_y = std::min(frame1.allocated_size(kYPlane),
|
||||||
int size_u = std::min(frame1.size(kUPlane), frame2.size(kUPlane));
|
frame2.allocated_size(kYPlane));
|
||||||
int size_v = std::min(frame1.size(kVPlane), frame2.size(kVPlane));
|
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;
|
int ret_val = 0;
|
||||||
ret_val += memcmp(frame1.buffer(kYPlane), frame2.buffer(kYPlane), size_y);
|
ret_val += memcmp(frame1.buffer(kYPlane), frame2.buffer(kYPlane), size_y);
|
||||||
ret_val += memcmp(frame1.buffer(kUPlane), frame2.buffer(kUPlane), size_u);
|
ret_val += memcmp(frame1.buffer(kUPlane), frame2.buffer(kUPlane), size_u);
|
||||||
|
@ -63,7 +63,7 @@ class I420VideoFrame {
|
|||||||
const uint8_t* buffer(PlaneType type) const;
|
const uint8_t* buffer(PlaneType type) const;
|
||||||
|
|
||||||
// Get allocated size per plane.
|
// Get allocated size per plane.
|
||||||
int size(PlaneType type) const;
|
int allocated_size(PlaneType type) const;
|
||||||
|
|
||||||
// Get allocated stride per plane.
|
// Get allocated stride per plane.
|
||||||
int stride(PlaneType type) const;
|
int stride(PlaneType type) const;
|
||||||
@ -93,6 +93,13 @@ class I420VideoFrame {
|
|||||||
// Get render time in miliseconds.
|
// Get render time in miliseconds.
|
||||||
int64_t render_time_ms() const {return render_time_ms_;}
|
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:
|
private:
|
||||||
// Verifies legality of parameters.
|
// Verifies legality of parameters.
|
||||||
// Return value: 0 on success ,-1 on error.
|
// Return value: 0 on success ,-1 on error.
|
||||||
|
@ -43,6 +43,12 @@ class Plane {
|
|||||||
// Get allocated size.
|
// Get allocated size.
|
||||||
int allocated_size() const {return 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.
|
// Get stride value.
|
||||||
int stride() const {return stride_;}
|
int stride() const {return stride_;}
|
||||||
|
|
||||||
|
@ -17,11 +17,12 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
TEST(TestPlane, CreateEmptyPlaneialValues) {
|
TEST(TestPlane, CreateEmptyPlaneValues) {
|
||||||
Plane plane;
|
Plane plane;
|
||||||
int size, stride;
|
int size, stride;
|
||||||
EXPECT_EQ(0, plane.allocated_size());
|
EXPECT_EQ(0, plane.allocated_size());
|
||||||
EXPECT_EQ(0, plane.stride());
|
EXPECT_EQ(0, plane.stride());
|
||||||
|
EXPECT_TRUE(plane.IsZeroSize());
|
||||||
size = 0;
|
size = 0;
|
||||||
stride = 20;
|
stride = 20;
|
||||||
EXPECT_EQ(-1, plane.CreateEmptyPlane(size, stride, 1));
|
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(0, plane.CreateEmptyPlane(size, stride, size));
|
||||||
EXPECT_EQ(size, plane.allocated_size());
|
EXPECT_EQ(size, plane.allocated_size());
|
||||||
EXPECT_EQ(stride, plane.stride());
|
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) {
|
TEST(TestPlane, PlaneCopy) {
|
||||||
|
Loading…
Reference in New Issue
Block a user