Initial cleanup of cricket::VideoFrame.
Deleted GetRotation (old alias for GetVideoRotation). Deleted CopyToBuffer. Deleted Sizeof. Deleted Write. Demote CopyToPlanes to protected status. BUG=webrtc:5426 Committed: https://crrev.com/4d575b0d4276422bdf7b595d92c57c4f0f8ce0e9 Cr-Commit-Position: refs/heads/master@{#11564} Review URL: https://codereview.webrtc.org/1688643003 Cr-Commit-Position: refs/heads/master@{#11594}
This commit is contained in:
parent
65c7f67f09
commit
d73c99cf22
@ -79,12 +79,11 @@ class FakeVideoCapturer : public cricket::VideoCapturer {
|
||||
return false;
|
||||
}
|
||||
// Currently, |fourcc| is always I420 or ARGB.
|
||||
// TODO(fbarchard): Extend SizeOf to take fourcc.
|
||||
uint32_t size = 0u;
|
||||
if (fourcc == cricket::FOURCC_ARGB) {
|
||||
size = width * 4 * height;
|
||||
} else if (fourcc == cricket::FOURCC_I420) {
|
||||
size = static_cast<uint32_t>(cricket::VideoFrame::SizeOf(width, height));
|
||||
size = width * height + 2 * ((width + 1) / 2) * ((height + 1) / 2);
|
||||
} else {
|
||||
return false; // Unsupported FOURCC.
|
||||
}
|
||||
|
||||
@ -52,9 +52,9 @@ class VideoCapturerTest
|
||||
void OnVideoFrame(cricket::VideoCapturer*, const cricket::VideoFrame* frame) {
|
||||
++video_frames_received_;
|
||||
if (expects_rotation_applied_) {
|
||||
EXPECT_EQ(webrtc::kVideoRotation_0, frame->GetRotation());
|
||||
EXPECT_EQ(webrtc::kVideoRotation_0, frame->GetVideoRotation());
|
||||
} else {
|
||||
EXPECT_EQ(capturer_.GetRotation(), frame->GetRotation());
|
||||
EXPECT_EQ(capturer_.GetRotation(), frame->GetVideoRotation());
|
||||
}
|
||||
renderer_.RenderFrame(frame);
|
||||
}
|
||||
|
||||
@ -25,58 +25,6 @@ namespace cricket {
|
||||
// Round to 2 pixels because Chroma channels are half size.
|
||||
#define ROUNDTO2(v) (v & ~1)
|
||||
|
||||
rtc::StreamResult VideoFrame::Write(rtc::StreamInterface* stream,
|
||||
int* error) const {
|
||||
rtc::StreamResult result = rtc::SR_SUCCESS;
|
||||
const uint8_t* src_y = GetYPlane();
|
||||
const uint8_t* src_u = GetUPlane();
|
||||
const uint8_t* src_v = GetVPlane();
|
||||
if (!src_y || !src_u || !src_v) {
|
||||
return result; // Nothing to write.
|
||||
}
|
||||
const int32_t y_pitch = GetYPitch();
|
||||
const int32_t u_pitch = GetUPitch();
|
||||
const int32_t v_pitch = GetVPitch();
|
||||
const size_t width = GetWidth();
|
||||
const size_t height = GetHeight();
|
||||
const size_t half_width = (width + 1) >> 1;
|
||||
const size_t half_height = (height + 1) >> 1;
|
||||
// Write Y.
|
||||
for (size_t row = 0; row < height; ++row) {
|
||||
result = stream->Write(src_y + row * y_pitch, width, NULL, error);
|
||||
if (result != rtc::SR_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// Write U.
|
||||
for (size_t row = 0; row < half_height; ++row) {
|
||||
result = stream->Write(src_u + row * u_pitch, half_width, NULL, error);
|
||||
if (result != rtc::SR_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// Write V.
|
||||
for (size_t row = 0; row < half_height; ++row) {
|
||||
result = stream->Write(src_v + row * v_pitch, half_width, NULL, error);
|
||||
if (result != rtc::SR_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t VideoFrame::CopyToBuffer(uint8_t* buffer, size_t size) const {
|
||||
const size_t y_size = GetHeight() * GetYPitch();
|
||||
const size_t u_size = GetUPitch() * GetChromaHeight();
|
||||
const size_t v_size = GetVPitch() * GetChromaHeight();
|
||||
const size_t needed = y_size + u_size + v_size;
|
||||
if (size < needed)
|
||||
return needed;
|
||||
CopyToPlanes(buffer, buffer + y_size, buffer + y_size + u_size,
|
||||
GetYPitch(), GetUPitch(), GetVPitch());
|
||||
return needed;
|
||||
}
|
||||
|
||||
bool VideoFrame::CopyToPlanes(uint8_t* dst_y,
|
||||
uint8_t* dst_u,
|
||||
uint8_t* dst_v,
|
||||
|
||||
@ -77,12 +77,7 @@ class VideoFrame {
|
||||
virtual void SetTimeStamp(int64_t time_stamp) = 0;
|
||||
|
||||
// Indicates the rotation angle in degrees.
|
||||
// TODO(guoweis): Remove this function, rename GetVideoRotation and remove the
|
||||
// skeleton implementation of GetRotation once chrome is updated.
|
||||
virtual int GetRotation() const { return GetVideoRotation(); }
|
||||
virtual webrtc::VideoRotation GetVideoRotation() const {
|
||||
return webrtc::kVideoRotation_0;
|
||||
}
|
||||
virtual webrtc::VideoRotation GetVideoRotation() const = 0;
|
||||
|
||||
// Make a shallow copy of the frame. The frame buffer itself is not copied.
|
||||
// Both the current and new VideoFrame will share a single reference-counted
|
||||
@ -99,23 +94,6 @@ class VideoFrame {
|
||||
// buffer if it is currently shared by other objects.
|
||||
virtual bool MakeExclusive() = 0;
|
||||
|
||||
// Writes the frame into the given frame buffer, provided that it is of
|
||||
// sufficient size. Returns the frame's actual size, regardless of whether
|
||||
// it was written or not (like snprintf). If there is insufficient space,
|
||||
// nothing is written.
|
||||
virtual size_t CopyToBuffer(uint8_t* buffer, size_t size) const;
|
||||
|
||||
// Writes the frame into the given planes, stretched to the given width and
|
||||
// height. The parameter "interpolate" controls whether to interpolate or just
|
||||
// take the nearest-point. The parameter "crop" controls whether to crop this
|
||||
// frame to the aspect ratio of the given dimensions before stretching.
|
||||
virtual bool CopyToPlanes(uint8_t* dst_y,
|
||||
uint8_t* dst_u,
|
||||
uint8_t* dst_v,
|
||||
int32_t dst_pitch_y,
|
||||
int32_t dst_pitch_u,
|
||||
int32_t dst_pitch_v) const;
|
||||
|
||||
// Writes the frame into the target VideoFrame.
|
||||
virtual void CopyToFrame(VideoFrame* target) const;
|
||||
|
||||
@ -123,13 +101,6 @@ class VideoFrame {
|
||||
// ownership of the returned frame is held by this frame.
|
||||
virtual const VideoFrame* GetCopyWithRotationApplied() const = 0;
|
||||
|
||||
// Writes the frame into the given stream and returns the StreamResult.
|
||||
// See webrtc/base/stream.h for a description of StreamResult and error.
|
||||
// Error may be NULL. If a non-success value is returned from
|
||||
// StreamInterface::Write(), we immediately return with that value.
|
||||
virtual rtc::StreamResult Write(rtc::StreamInterface* stream,
|
||||
int* error) const;
|
||||
|
||||
// Converts the I420 data to RGB of a certain type such as ARGB and ABGR.
|
||||
// Returns the frame's actual size, regardless of whether it was written or
|
||||
// not (like snprintf). Parameters size and stride_rgb are in units of bytes.
|
||||
@ -178,12 +149,18 @@ class VideoFrame {
|
||||
const uint8_t* sample,
|
||||
size_t sample_size);
|
||||
|
||||
// Size of an I420 image of given dimensions when stored as a frame buffer.
|
||||
static size_t SizeOf(size_t w, size_t h) {
|
||||
return w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Writes the frame into the given planes, stretched to the given width and
|
||||
// height. The parameter "interpolate" controls whether to interpolate or just
|
||||
// take the nearest-point. The parameter "crop" controls whether to crop this
|
||||
// frame to the aspect ratio of the given dimensions before stretching.
|
||||
virtual bool CopyToPlanes(uint8_t* dst_y,
|
||||
uint8_t* dst_u,
|
||||
uint8_t* dst_v,
|
||||
int32_t dst_pitch_y,
|
||||
int32_t dst_pitch_u,
|
||||
int32_t dst_pitch_v) const;
|
||||
|
||||
// Creates an empty frame.
|
||||
virtual VideoFrame *CreateEmptyFrame(int w, int h,
|
||||
int64_t time_stamp) const = 0;
|
||||
|
||||
@ -163,19 +163,6 @@ class VideoFrameTest : public testing::Test {
|
||||
return ms.release();
|
||||
}
|
||||
|
||||
// Write an I420 frame out to disk.
|
||||
bool DumpFrame(const std::string& prefix,
|
||||
const cricket::VideoFrame& frame) {
|
||||
char filename[256];
|
||||
rtc::sprintfn(filename, sizeof(filename), "%s.%dx%d_P420.yuv",
|
||||
prefix.c_str(), frame.GetWidth(), frame.GetHeight());
|
||||
size_t out_size = cricket::VideoFrame::SizeOf(frame.GetWidth(),
|
||||
frame.GetHeight());
|
||||
rtc::scoped_ptr<uint8_t[]> out(new uint8_t[out_size]);
|
||||
frame.CopyToBuffer(out.get(), out_size);
|
||||
return DumpSample(filename, out.get(), out_size);
|
||||
}
|
||||
|
||||
bool DumpSample(const std::string& filename, const void* buffer, int size) {
|
||||
rtc::Pathname path(filename);
|
||||
rtc::scoped_ptr<rtc::FileStream> fs(
|
||||
@ -1831,21 +1818,6 @@ class VideoFrameTest : public testing::Test {
|
||||
EXPECT_NE(target->GetVPlane(), source->GetVPlane());
|
||||
}
|
||||
|
||||
void CopyToBuffer() {
|
||||
T frame;
|
||||
rtc::scoped_ptr<rtc::MemoryStream> ms(
|
||||
LoadSample(kImageFilename));
|
||||
ASSERT_TRUE(ms.get() != NULL);
|
||||
ASSERT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight,
|
||||
&frame));
|
||||
size_t out_size = kWidth * kHeight * 3 / 2;
|
||||
rtc::scoped_ptr<uint8_t[]> out(new uint8_t[out_size]);
|
||||
for (int i = 0; i < repeat_; ++i) {
|
||||
EXPECT_EQ(out_size, frame.CopyToBuffer(out.get(), out_size));
|
||||
}
|
||||
EXPECT_EQ(0, memcmp(out.get(), ms->GetBuffer(), out_size));
|
||||
}
|
||||
|
||||
void CopyToFrame() {
|
||||
T source;
|
||||
rtc::scoped_ptr<rtc::MemoryStream> ms(
|
||||
@ -1865,44 +1837,6 @@ class VideoFrameTest : public testing::Test {
|
||||
EXPECT_TRUE(IsEqual(source, target, 0));
|
||||
}
|
||||
|
||||
void Write() {
|
||||
T frame;
|
||||
rtc::scoped_ptr<rtc::MemoryStream> ms(
|
||||
LoadSample(kImageFilename));
|
||||
ASSERT_TRUE(ms.get() != NULL);
|
||||
rtc::MemoryStream ms2;
|
||||
size_t size;
|
||||
ASSERT_TRUE(ms->GetSize(&size));
|
||||
ASSERT_TRUE(ms2.ReserveSize(size));
|
||||
ASSERT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight,
|
||||
&frame));
|
||||
for (int i = 0; i < repeat_; ++i) {
|
||||
ms2.SetPosition(0u); // Useful when repeat_ > 1.
|
||||
int error;
|
||||
EXPECT_EQ(rtc::SR_SUCCESS, frame.Write(&ms2, &error));
|
||||
}
|
||||
size_t out_size = cricket::VideoFrame::SizeOf(kWidth, kHeight);
|
||||
EXPECT_EQ(0, memcmp(ms2.GetBuffer(), ms->GetBuffer(), out_size));
|
||||
}
|
||||
|
||||
void CopyToBuffer1Pixel() {
|
||||
size_t out_size = 3;
|
||||
rtc::scoped_ptr<uint8_t[]> out(new uint8_t[out_size + 1]);
|
||||
memset(out.get(), 0xfb, out_size + 1); // Fill buffer
|
||||
uint8_t pixel[3] = {1, 2, 3};
|
||||
T frame;
|
||||
EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel,
|
||||
sizeof(pixel), 0,
|
||||
webrtc::kVideoRotation_0));
|
||||
for (int i = 0; i < repeat_; ++i) {
|
||||
EXPECT_EQ(out_size, frame.CopyToBuffer(out.get(), out_size));
|
||||
}
|
||||
EXPECT_EQ(1, out.get()[0]); // Check Y. Should be 1.
|
||||
EXPECT_EQ(2, out.get()[1]); // Check U. Should be 2.
|
||||
EXPECT_EQ(3, out.get()[2]); // Check V. Should be 3.
|
||||
EXPECT_EQ(0xfb, out.get()[3]); // Check sentinel is still intact.
|
||||
}
|
||||
|
||||
void StretchToFrame() {
|
||||
// Create the source frame as a black frame.
|
||||
T source;
|
||||
|
||||
@ -473,8 +473,8 @@ TEST_F(WebRtcVideoEngine2Test,
|
||||
frame.width = 1280;
|
||||
frame.height = 720;
|
||||
frame.fourcc = cricket::FOURCC_I420;
|
||||
frame.data_size = static_cast<uint32_t>(
|
||||
cricket::VideoFrame::SizeOf(frame.width, frame.height));
|
||||
frame.data_size = frame.width * frame.height +
|
||||
2 * ((frame.width + 1) / 2) * ((frame.height + 1) / 2);
|
||||
rtc::scoped_ptr<char[]> data(new char[frame.data_size]);
|
||||
frame.data = data.get();
|
||||
memset(frame.data, 1, frame.data_size);
|
||||
|
||||
@ -66,9 +66,9 @@ class WebRtcVideoFrameTest : public VideoFrameTest<cricket::WebRtcVideoFrame> {
|
||||
// Verify the new frame.
|
||||
EXPECT_EQ(5678, frame.GetTimeStamp());
|
||||
if (apply_rotation)
|
||||
EXPECT_EQ(webrtc::kVideoRotation_0, frame.GetRotation());
|
||||
EXPECT_EQ(webrtc::kVideoRotation_0, frame.GetVideoRotation());
|
||||
else
|
||||
EXPECT_EQ(frame_rotation, frame.GetRotation());
|
||||
EXPECT_EQ(frame_rotation, frame.GetVideoRotation());
|
||||
// If |apply_rotation| and the frame rotation is 90 or 270, width and
|
||||
// height are flipped.
|
||||
if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90
|
||||
@ -233,10 +233,7 @@ TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBuffer)
|
||||
TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferStride)
|
||||
TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferInverted)
|
||||
// TEST_WEBRTCVIDEOFRAME(ConvertToI422Buffer)
|
||||
TEST_WEBRTCVIDEOFRAME(CopyToBuffer)
|
||||
TEST_WEBRTCVIDEOFRAME(CopyToFrame)
|
||||
TEST_WEBRTCVIDEOFRAME(Write)
|
||||
TEST_WEBRTCVIDEOFRAME(CopyToBuffer1Pixel)
|
||||
// TEST_WEBRTCVIDEOFRAME(ConstructARGBBlackWhitePixel)
|
||||
|
||||
TEST_WEBRTCVIDEOFRAME(StretchToFrame)
|
||||
|
||||
@ -46,11 +46,11 @@ class WebRtcVideoFrameFactoryTest
|
||||
int src_height,
|
||||
bool apply_rotation) {
|
||||
if (!apply_rotation) {
|
||||
EXPECT_EQ(dest_frame->GetRotation(), src_rotation);
|
||||
EXPECT_EQ(dest_frame->GetVideoRotation(), src_rotation);
|
||||
EXPECT_EQ(dest_frame->GetWidth(), src_width);
|
||||
EXPECT_EQ(dest_frame->GetHeight(), src_height);
|
||||
} else {
|
||||
EXPECT_EQ(dest_frame->GetRotation(), webrtc::kVideoRotation_0);
|
||||
EXPECT_EQ(dest_frame->GetVideoRotation(), webrtc::kVideoRotation_0);
|
||||
if (src_rotation == webrtc::kVideoRotation_90 ||
|
||||
src_rotation == webrtc::kVideoRotation_270) {
|
||||
EXPECT_EQ(dest_frame->GetWidth(), src_height);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user