Updates to videoFrame:
1. Adding non-const members. 2. Updating copy interface. Review URL: https://webrtc-codereview.appspot.com/866005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2864 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
aee9120409
commit
60ac6a642a
@ -38,9 +38,9 @@ int I420VideoFrame::CreateEmptyFrame(int width, int height,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int I420VideoFrame::CreateFrame(int size_y, const uint8_t& buffer_y,
|
||||
int size_u, const uint8_t& buffer_u,
|
||||
int size_v, const uint8_t& buffer_v,
|
||||
int I420VideoFrame::CreateFrame(int size_y, const uint8_t* buffer_y,
|
||||
int size_u, const uint8_t* buffer_u,
|
||||
int size_v, const uint8_t* buffer_v,
|
||||
int width, int height,
|
||||
int stride_y, int stride_u, int stride_v) {
|
||||
if (size_y < 1 || size_u < 1 || size_v < 1)
|
||||
@ -56,9 +56,9 @@ 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.size(kYPlane), videoFrame.buffer(kYPlane),
|
||||
videoFrame.size(kUPlane), videoFrame.buffer(kUPlane),
|
||||
videoFrame.size(kVPlane), videoFrame.buffer(kVPlane),
|
||||
videoFrame.width_, videoFrame.height_,
|
||||
videoFrame.stride(kYPlane), videoFrame.stride(kUPlane),
|
||||
videoFrame.stride(kVPlane));
|
||||
@ -79,6 +79,13 @@ void I420VideoFrame::SwapFrame(I420VideoFrame* videoFrame) {
|
||||
std::swap(render_time_ms_, videoFrame->render_time_ms_);
|
||||
}
|
||||
|
||||
uint8_t* I420VideoFrame::buffer(PlaneType type) {
|
||||
Plane* plane_ptr = GetPlane(type);
|
||||
if (plane_ptr)
|
||||
return plane_ptr->buffer();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const uint8_t* I420VideoFrame::buffer(PlaneType type) const {
|
||||
const Plane* plane_ptr = GetPlane(type);
|
||||
if (plane_ptr)
|
||||
@ -141,5 +148,19 @@ const Plane* I420VideoFrame::GetPlane(PlaneType type) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Plane* I420VideoFrame::GetPlane(PlaneType type) {
|
||||
switch (type) {
|
||||
case kYPlane :
|
||||
return &y_plane_;
|
||||
case kUPlane :
|
||||
return &u_plane_;
|
||||
case kVPlane :
|
||||
return &v_plane_;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -87,9 +87,9 @@ TEST(TestI420VideoFrame, CopyFrame) {
|
||||
memset(buffer_y, 16, kSizeY);
|
||||
memset(buffer_u, 8, kSizeU);
|
||||
memset(buffer_v, 4, kSizeV);
|
||||
frame2.CreateFrame(kSizeY, *buffer_y,
|
||||
kSizeU, *buffer_u,
|
||||
kSizeV, *buffer_v,
|
||||
frame2.CreateFrame(kSizeY, buffer_y,
|
||||
kSizeU, buffer_u,
|
||||
kSizeV, buffer_v,
|
||||
width + 5, height + 5, stride_y + 5, stride_u, stride_v);
|
||||
// Frame of smaller dimensions - allocated sizes should not vary.
|
||||
EXPECT_EQ(0, frame1.CopyFrame(frame2));
|
||||
@ -119,9 +119,9 @@ TEST(TestI420VideoFrame, CopyBuffer) {
|
||||
memset(buffer_y, 16, kSizeY);
|
||||
memset(buffer_u, 8, kSizeUv);
|
||||
memset(buffer_v, 4, kSizeUv);
|
||||
frame2.CreateFrame(kSizeY, *buffer_y,
|
||||
kSizeUv, *buffer_u,
|
||||
kSizeUv, *buffer_v,
|
||||
frame2.CreateFrame(kSizeY, buffer_y,
|
||||
kSizeUv, buffer_u,
|
||||
kSizeUv, buffer_v,
|
||||
width, height, stride_y, stride_uv, stride_uv);
|
||||
// Copy memory (at least allocated size).
|
||||
EXPECT_EQ(memcmp(buffer_y, frame2.buffer(kYPlane), kSizeY), 0);
|
||||
@ -167,9 +167,9 @@ TEST(TestI420VideoFrame, FrameSwap) {
|
||||
memset(buffer_y1, 2, kSizeY1);
|
||||
memset(buffer_u1, 4, kSizeU1);
|
||||
memset(buffer_v1, 8, kSizeV1);
|
||||
frame1.CreateFrame(kSizeY1, *buffer_y1,
|
||||
kSizeU1, *buffer_u1,
|
||||
kSizeV1, *buffer_v1,
|
||||
frame1.CreateFrame(kSizeY1, buffer_y1,
|
||||
kSizeU1, buffer_u1,
|
||||
kSizeV1, buffer_v1,
|
||||
width1, height1, stride_y1, stride_u1, stride_v1);
|
||||
// Initialize frame2 values.
|
||||
EXPECT_EQ(0, frame2.CreateEmptyFrame(width2, height2,
|
||||
@ -183,9 +183,9 @@ TEST(TestI420VideoFrame, FrameSwap) {
|
||||
memset(buffer_y2, 0, kSizeY2);
|
||||
memset(buffer_u2, 1, kSizeU2);
|
||||
memset(buffer_v2, 2, kSizeV2);
|
||||
frame2.CreateFrame(kSizeY2, *buffer_y2,
|
||||
kSizeU2, *buffer_u2,
|
||||
kSizeV2, *buffer_v2,
|
||||
frame2.CreateFrame(kSizeY2, buffer_y2,
|
||||
kSizeU2, buffer_u2,
|
||||
kSizeV2, buffer_v2,
|
||||
width2, height2, stride_y2, stride_u2, stride_v2);
|
||||
// Copy frames for subsequent comparison.
|
||||
I420VideoFrame frame1_copy, frame2_copy;
|
||||
|
||||
@ -43,9 +43,9 @@ class I420VideoFrame {
|
||||
// CreateFrame: Sets the frame's members and buffers. If required size is
|
||||
// bigger than allocated one, new buffers of adequate size will be allocated.
|
||||
// Return value: 0 on success ,-1 on error.
|
||||
int CreateFrame(int size_y, const uint8_t& buffer_y,
|
||||
int size_u, const uint8_t& buffer_u,
|
||||
int size_v, const uint8_t& buffer_v,
|
||||
int CreateFrame(int size_y, const uint8_t* buffer_y,
|
||||
int size_u, const uint8_t* buffer_u,
|
||||
int size_v, const uint8_t* buffer_v,
|
||||
int width, int height,
|
||||
int stride_y, int stride_u, int stride_v);
|
||||
|
||||
@ -58,6 +58,8 @@ class I420VideoFrame {
|
||||
void SwapFrame(I420VideoFrame* videoFrame);
|
||||
|
||||
// Get pointer to buffer per plane.
|
||||
uint8_t* buffer(PlaneType type);
|
||||
// Overloading with const.
|
||||
const uint8_t* buffer(PlaneType type) const;
|
||||
|
||||
// Get allocated size per plane.
|
||||
@ -98,6 +100,8 @@ class I420VideoFrame {
|
||||
int stride_y, int stride_u, int stride_v);
|
||||
// Get the pointer to a specific plane.
|
||||
const Plane* GetPlane(PlaneType type) const;
|
||||
// Overloading with non-const.
|
||||
Plane* GetPlane(PlaneType type);
|
||||
|
||||
Plane y_plane_;
|
||||
Plane u_plane_;
|
||||
|
||||
@ -57,10 +57,10 @@ int Plane::Copy(const Plane& plane) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Plane::Copy(int size, int stride, const uint8_t& buffer) {
|
||||
int Plane::Copy(int size, int stride, const uint8_t* buffer) {
|
||||
if (MaybeResize(size) < 0)
|
||||
return -1;
|
||||
memcpy(buffer_.get(), &buffer, size);
|
||||
memcpy(buffer_.get(), buffer, size);
|
||||
plane_size_ = size;
|
||||
stride_ = stride;
|
||||
return 0;
|
||||
|
||||
@ -35,7 +35,7 @@ class Plane {
|
||||
// Copy buffer: If current size is smaller
|
||||
// than current size, then a buffer of sufficient size will be allocated.
|
||||
// Return value: 0 on success ,-1 on error.
|
||||
int Copy(int size, int stride, const uint8_t& buffer);
|
||||
int Copy(int size, int stride, const uint8_t* buffer);
|
||||
|
||||
// Swap plane data.
|
||||
void Swap(Plane& plane);
|
||||
@ -48,6 +48,8 @@ class Plane {
|
||||
|
||||
// Return data pointer.
|
||||
const uint8_t* buffer() const {return buffer_.get();}
|
||||
// Overloading with non-const.
|
||||
uint8_t* buffer() {return buffer_.get();}
|
||||
|
||||
private:
|
||||
// Resize when needed: If current allocated size is less than new_size, buffer
|
||||
|
||||
@ -56,7 +56,7 @@ TEST(TestPlane, PlaneCopy) {
|
||||
uint8_t buffer1[100];
|
||||
size1 = 80;
|
||||
memset(&buffer1, 0, size1);
|
||||
plane2.Copy(size1, stride1, *buffer1);
|
||||
plane2.Copy(size1, stride1, buffer1);
|
||||
EXPECT_GE(plane2.allocated_size(), size1);
|
||||
EXPECT_EQ(0, memcmp(buffer1, plane2.buffer(), size1));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user