Cleanup of webrtc::VideoFrame.
Delete EqualsFrame method, used only by tests. Delete one of the CreateFrame methods. Drop return value for CreateEmptyFrame, CreateFrame and CopyFrame. BUG=webrtc:5426 Review URL: https://codereview.webrtc.org/1679323002 Cr-Commit-Position: refs/heads/master@{#11783}
This commit is contained in:
parent
c63f79a0a5
commit
208019637b
@ -17,7 +17,7 @@
|
||||
'<(DEPTH)/testing/gtest.gyp:gtest',
|
||||
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers',
|
||||
'<(webrtc_root)/test/test.gyp:test_support_main',
|
||||
'<(webrtc_root)/test/test.gyp:fake_video_frames',
|
||||
'<(webrtc_root)/test/test.gyp:video_test_common',
|
||||
],
|
||||
'sources': [
|
||||
'i420_buffer_pool_unittest.cc',
|
||||
|
||||
@ -15,15 +15,11 @@
|
||||
#include "webrtc/base/bind.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
#include "webrtc/test/fake_texture_frame.h"
|
||||
#include "webrtc/test/frame_utils.h"
|
||||
#include "webrtc/video_frame.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
bool EqualPlane(const uint8_t* data1,
|
||||
const uint8_t* data2,
|
||||
int stride,
|
||||
int width,
|
||||
int height);
|
||||
int ExpectedSize(int plane_stride, int image_height, PlaneType type);
|
||||
|
||||
TEST(TestVideoFrame, InitialValues) {
|
||||
@ -41,7 +37,7 @@ TEST(TestVideoFrame, CopiesInitialFrameWithoutCrashing) {
|
||||
TEST(TestVideoFrame, WidthHeightValues) {
|
||||
VideoFrame frame;
|
||||
const int valid_value = 10;
|
||||
EXPECT_EQ(0, frame.CreateEmptyFrame(10, 10, 10, 14, 90));
|
||||
frame.CreateEmptyFrame(10, 10, 10, 14, 90);
|
||||
EXPECT_EQ(valid_value, frame.width());
|
||||
EXPECT_EQ(valid_value, frame.height());
|
||||
frame.set_timestamp(123u);
|
||||
@ -54,7 +50,7 @@ TEST(TestVideoFrame, WidthHeightValues) {
|
||||
|
||||
TEST(TestVideoFrame, SizeAllocation) {
|
||||
VideoFrame frame;
|
||||
EXPECT_EQ(0, frame. CreateEmptyFrame(10, 10, 12, 14, 220));
|
||||
frame. CreateEmptyFrame(10, 10, 12, 14, 220);
|
||||
int height = frame.height();
|
||||
int stride_y = frame.stride(kYPlane);
|
||||
int stride_u = frame.stride(kUPlane);
|
||||
@ -79,8 +75,8 @@ TEST(TestVideoFrame, CopyFrame) {
|
||||
int height = 15;
|
||||
// Copy frame.
|
||||
VideoFrame small_frame;
|
||||
EXPECT_EQ(0, small_frame.CreateEmptyFrame(width, height,
|
||||
stride_y, stride_u, stride_v));
|
||||
small_frame.CreateEmptyFrame(width, height,
|
||||
stride_y, stride_u, stride_v);
|
||||
small_frame.set_timestamp(timestamp);
|
||||
small_frame.set_ntp_time_ms(ntp_time_ms);
|
||||
small_frame.set_render_time_ms(render_time_ms);
|
||||
@ -95,23 +91,22 @@ TEST(TestVideoFrame, CopyFrame) {
|
||||
memset(buffer_u, 8, kSizeU);
|
||||
memset(buffer_v, 4, kSizeV);
|
||||
VideoFrame big_frame;
|
||||
EXPECT_EQ(0,
|
||||
big_frame.CreateFrame(buffer_y, buffer_u, buffer_v,
|
||||
width + 5, height + 5, stride_y + 5,
|
||||
stride_u, stride_v, kRotation));
|
||||
big_frame.CreateFrame(buffer_y, buffer_u, buffer_v,
|
||||
width + 5, height + 5, stride_y + 5,
|
||||
stride_u, stride_v, kRotation);
|
||||
// Frame of smaller dimensions.
|
||||
EXPECT_EQ(0, small_frame.CopyFrame(big_frame));
|
||||
EXPECT_TRUE(small_frame.EqualsFrame(big_frame));
|
||||
small_frame.CopyFrame(big_frame);
|
||||
EXPECT_TRUE(test::FramesEqual(small_frame, big_frame));
|
||||
EXPECT_EQ(kRotation, small_frame.rotation());
|
||||
|
||||
// Frame of larger dimensions.
|
||||
EXPECT_EQ(0, small_frame.CreateEmptyFrame(width, height,
|
||||
stride_y, stride_u, stride_v));
|
||||
small_frame.CreateEmptyFrame(width, height,
|
||||
stride_y, stride_u, stride_v);
|
||||
memset(small_frame.buffer(kYPlane), 1, small_frame.allocated_size(kYPlane));
|
||||
memset(small_frame.buffer(kUPlane), 2, small_frame.allocated_size(kUPlane));
|
||||
memset(small_frame.buffer(kVPlane), 3, small_frame.allocated_size(kVPlane));
|
||||
EXPECT_EQ(0, big_frame.CopyFrame(small_frame));
|
||||
EXPECT_TRUE(small_frame.EqualsFrame(big_frame));
|
||||
big_frame.CopyFrame(small_frame);
|
||||
EXPECT_TRUE(test::FramesEqual(small_frame, big_frame));
|
||||
}
|
||||
|
||||
TEST(TestVideoFrame, ShallowCopy) {
|
||||
@ -135,8 +130,8 @@ TEST(TestVideoFrame, ShallowCopy) {
|
||||
memset(buffer_u, 8, kSizeU);
|
||||
memset(buffer_v, 4, kSizeV);
|
||||
VideoFrame frame1;
|
||||
EXPECT_EQ(0, frame1.CreateFrame(buffer_y, buffer_u, buffer_v, width, height,
|
||||
stride_y, stride_u, stride_v, kRotation));
|
||||
frame1.CreateFrame(buffer_y, buffer_u, buffer_v, width, height,
|
||||
stride_y, stride_u, stride_v, kRotation);
|
||||
frame1.set_timestamp(timestamp);
|
||||
frame1.set_ntp_time_ms(ntp_time_ms);
|
||||
frame1.set_render_time_ms(render_time_ms);
|
||||
@ -172,7 +167,7 @@ TEST(TestVideoFrame, ShallowCopy) {
|
||||
|
||||
TEST(TestVideoFrame, Reset) {
|
||||
VideoFrame frame;
|
||||
ASSERT_EQ(frame.CreateEmptyFrame(5, 5, 5, 5, 5), 0);
|
||||
frame.CreateEmptyFrame(5, 5, 5, 5, 5);
|
||||
frame.set_ntp_time_ms(1);
|
||||
frame.set_timestamp(2);
|
||||
frame.set_render_time_ms(3);
|
||||
@ -193,8 +188,8 @@ TEST(TestVideoFrame, CopyBuffer) {
|
||||
int stride_uv = 10;
|
||||
const int kSizeY = 225;
|
||||
const int kSizeUv = 80;
|
||||
EXPECT_EQ(0, frame2.CreateEmptyFrame(width, height,
|
||||
stride_y, stride_uv, stride_uv));
|
||||
frame2.CreateEmptyFrame(width, height,
|
||||
stride_y, stride_uv, stride_uv);
|
||||
uint8_t buffer_y[kSizeY];
|
||||
uint8_t buffer_u[kSizeUv];
|
||||
uint8_t buffer_v[kSizeUv];
|
||||
@ -202,11 +197,15 @@ TEST(TestVideoFrame, CopyBuffer) {
|
||||
memset(buffer_u, 8, kSizeUv);
|
||||
memset(buffer_v, 4, kSizeUv);
|
||||
frame2.CreateFrame(buffer_y, buffer_u, buffer_v,
|
||||
width, height, stride_y, stride_uv, stride_uv);
|
||||
width, height, stride_y, stride_uv, stride_uv,
|
||||
kVideoRotation_0);
|
||||
// Expect exactly the same pixel data.
|
||||
EXPECT_TRUE(EqualPlane(buffer_y, frame2.buffer(kYPlane), stride_y, 15, 15));
|
||||
EXPECT_TRUE(EqualPlane(buffer_u, frame2.buffer(kUPlane), stride_uv, 8, 8));
|
||||
EXPECT_TRUE(EqualPlane(buffer_v, frame2.buffer(kVPlane), stride_uv, 8, 8));
|
||||
EXPECT_TRUE(
|
||||
test::EqualPlane(buffer_y, frame2.buffer(kYPlane), stride_y, 15, 15));
|
||||
EXPECT_TRUE(
|
||||
test::EqualPlane(buffer_u, frame2.buffer(kUPlane), stride_uv, 8, 8));
|
||||
EXPECT_TRUE(
|
||||
test::EqualPlane(buffer_v, frame2.buffer(kVPlane), stride_uv, 8, 8));
|
||||
|
||||
// Compare size.
|
||||
EXPECT_LE(kSizeY, frame2.allocated_size(kYPlane));
|
||||
|
||||
@ -56,10 +56,10 @@ class IncomingVideoStream : public VideoRenderCallback {
|
||||
uint32_t StreamId() const;
|
||||
uint32_t IncomingRate() const;
|
||||
|
||||
int32_t SetStartImage(const VideoFrame& video_frame);
|
||||
void SetStartImage(const VideoFrame& video_frame);
|
||||
|
||||
int32_t SetTimeoutImage(const VideoFrame& video_frame,
|
||||
const uint32_t timeout);
|
||||
void SetTimeoutImage(const VideoFrame& video_frame,
|
||||
const uint32_t timeout);
|
||||
|
||||
int32_t SetExpectedRenderDelay(int32_t delay_ms);
|
||||
|
||||
|
||||
@ -90,16 +90,16 @@ int32_t IncomingVideoStream::RenderFrame(const uint32_t stream_id,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t IncomingVideoStream::SetStartImage(const VideoFrame& video_frame) {
|
||||
void IncomingVideoStream::SetStartImage(const VideoFrame& video_frame) {
|
||||
rtc::CritScope csS(&thread_critsect_);
|
||||
return start_image_.CopyFrame(video_frame);
|
||||
start_image_.CopyFrame(video_frame);
|
||||
}
|
||||
|
||||
int32_t IncomingVideoStream::SetTimeoutImage(const VideoFrame& video_frame,
|
||||
const uint32_t timeout) {
|
||||
void IncomingVideoStream::SetTimeoutImage(const VideoFrame& video_frame,
|
||||
const uint32_t timeout) {
|
||||
rtc::CritScope csS(&thread_critsect_);
|
||||
timeout_time_ = timeout;
|
||||
return timeout_image_.CopyFrame(video_frame);
|
||||
timeout_image_.CopyFrame(video_frame);
|
||||
}
|
||||
|
||||
void IncomingVideoStream::SetRenderCallback(
|
||||
|
||||
@ -111,13 +111,14 @@ void TestLibYuv::SetUp() {
|
||||
|
||||
EXPECT_EQ(frame_length_,
|
||||
fread(orig_buffer_.get(), 1, frame_length_, source_file_));
|
||||
EXPECT_EQ(0, orig_frame_.CreateFrame(orig_buffer_.get(),
|
||||
orig_buffer_.get() + size_y_,
|
||||
orig_buffer_.get() +
|
||||
size_y_ + size_uv_,
|
||||
width_, height_,
|
||||
width_, (width_ + 1) / 2,
|
||||
(width_ + 1) / 2));
|
||||
orig_frame_.CreateFrame(orig_buffer_.get(),
|
||||
orig_buffer_.get() + size_y_,
|
||||
orig_buffer_.get() +
|
||||
size_y_ + size_uv_,
|
||||
width_, height_,
|
||||
width_, (width_ + 1) / 2,
|
||||
(width_ + 1) / 2,
|
||||
kVideoRotation_0);
|
||||
}
|
||||
|
||||
void TestLibYuv::TearDown() {
|
||||
@ -142,9 +143,9 @@ TEST_F(TestLibYuv, ConvertTest) {
|
||||
double psnr = 0.0;
|
||||
|
||||
VideoFrame res_i420_frame;
|
||||
EXPECT_EQ(0, res_i420_frame.CreateEmptyFrame(width_, height_, width_,
|
||||
res_i420_frame.CreateEmptyFrame(width_, height_, width_,
|
||||
(width_ + 1) / 2,
|
||||
(width_ + 1) / 2));
|
||||
(width_ + 1) / 2);
|
||||
printf("\nConvert #%d I420 <-> I420 \n", j);
|
||||
rtc::scoped_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]);
|
||||
EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0,
|
||||
@ -202,7 +203,8 @@ TEST_F(TestLibYuv, ConvertTest) {
|
||||
outYV120Buffer.get() + size_y_,
|
||||
outYV120Buffer.get() + size_y_ + size_uv_,
|
||||
width_, height_,
|
||||
width_, (width_ + 1) / 2, (width_ + 1) / 2);
|
||||
width_, (width_ + 1) / 2, (width_ + 1) / 2,
|
||||
kVideoRotation_0);
|
||||
EXPECT_EQ(0, ConvertFromYV12(yv12_frame, kI420, 0, res_i420_buffer.get()));
|
||||
if (fwrite(res_i420_buffer.get(), 1, frame_length_, output_file) !=
|
||||
frame_length_) {
|
||||
@ -281,8 +283,8 @@ TEST_F(TestLibYuv, ConvertAlignedFrame) {
|
||||
int stride_y = 0;
|
||||
int stride_uv = 0;
|
||||
Calc16ByteAlignedStride(width_, &stride_y, &stride_uv);
|
||||
EXPECT_EQ(0, res_i420_frame.CreateEmptyFrame(width_, height_,
|
||||
stride_y, stride_uv, stride_uv));
|
||||
res_i420_frame.CreateEmptyFrame(width_, height_,
|
||||
stride_y, stride_uv, stride_uv);
|
||||
rtc::scoped_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]);
|
||||
EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0,
|
||||
out_i420_buffer.get()));
|
||||
@ -306,18 +308,18 @@ TEST_F(TestLibYuv, RotateTest) {
|
||||
int stride_y;
|
||||
int stride_uv;
|
||||
Calc16ByteAlignedStride(rotated_width, &stride_y, &stride_uv);
|
||||
EXPECT_EQ(0, rotated_res_i420_frame.CreateEmptyFrame(rotated_width,
|
||||
rotated_height,
|
||||
stride_y,
|
||||
stride_uv,
|
||||
stride_uv));
|
||||
rotated_res_i420_frame.CreateEmptyFrame(rotated_width,
|
||||
rotated_height,
|
||||
stride_y,
|
||||
stride_uv,
|
||||
stride_uv);
|
||||
EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_,
|
||||
0, kVideoRotation_90, &rotated_res_i420_frame));
|
||||
EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_,
|
||||
0, kVideoRotation_270, &rotated_res_i420_frame));
|
||||
EXPECT_EQ(0, rotated_res_i420_frame.CreateEmptyFrame(width_, height_,
|
||||
width_, (width_ + 1) / 2,
|
||||
(width_ + 1) / 2));
|
||||
rotated_res_i420_frame.CreateEmptyFrame(width_, height_,
|
||||
width_, (width_ + 1) / 2,
|
||||
(width_ + 1) / 2);
|
||||
EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_,
|
||||
0, kVideoRotation_180, &rotated_res_i420_frame));
|
||||
}
|
||||
|
||||
@ -104,7 +104,8 @@ TEST_F(TestScaler, ScaleSendingBufferTooSmall) {
|
||||
orig_buffer.get() + size_y_,
|
||||
orig_buffer.get() + size_y_ + size_uv_,
|
||||
width_, height_,
|
||||
width_, half_width_, half_width_);
|
||||
width_, half_width_, half_width_,
|
||||
kVideoRotation_0);
|
||||
EXPECT_EQ(0, test_scaler_.Scale(test_frame_, &test_frame2));
|
||||
EXPECT_GT(width_ * height_, test_frame2.allocated_size(kYPlane));
|
||||
EXPECT_GT(size_uv_, test_frame2.allocated_size(kUPlane));
|
||||
@ -372,7 +373,8 @@ void TestScaler::ScaleSequence(ScaleMethod method,
|
||||
frame_buffer.get() + size_y + size_uv,
|
||||
src_width, src_height,
|
||||
src_width, (src_width + 1) / 2,
|
||||
(src_width + 1) / 2);
|
||||
(src_width + 1) / 2,
|
||||
kVideoRotation_0);
|
||||
|
||||
start_clock = TickTime::MillisecondTimestamp();
|
||||
EXPECT_EQ(0, test_scaler_.Scale(input_frame, &output_frame));
|
||||
|
||||
@ -23,20 +23,6 @@ namespace webrtc {
|
||||
// to optimized bitstream readers. See avcodec_decode_video2.
|
||||
const size_t EncodedImage::kBufferPaddingBytesH264 = 8;
|
||||
|
||||
bool EqualPlane(const uint8_t* data1,
|
||||
const uint8_t* data2,
|
||||
int stride,
|
||||
int width,
|
||||
int height) {
|
||||
for (int y = 0; y < height; ++y) {
|
||||
if (memcmp(data1, data2, width) != 0)
|
||||
return false;
|
||||
data1 += stride;
|
||||
data2 += stride;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int ExpectedSize(int plane_stride, int image_height, PlaneType type) {
|
||||
if (type == kYPlane)
|
||||
return plane_stride * image_height;
|
||||
@ -60,11 +46,11 @@ VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
|
||||
rotation_(rotation) {
|
||||
}
|
||||
|
||||
int VideoFrame::CreateEmptyFrame(int width,
|
||||
int height,
|
||||
int stride_y,
|
||||
int stride_u,
|
||||
int stride_v) {
|
||||
void VideoFrame::CreateEmptyFrame(int width,
|
||||
int height,
|
||||
int stride_y,
|
||||
int stride_u,
|
||||
int stride_v) {
|
||||
const int half_width = (width + 1) / 2;
|
||||
RTC_DCHECK_GT(width, 0);
|
||||
RTC_DCHECK_GT(height, 0);
|
||||
@ -84,36 +70,23 @@ int VideoFrame::CreateEmptyFrame(int width,
|
||||
width == video_frame_buffer_->width() &&
|
||||
height == video_frame_buffer_->height() && stride_y == stride(kYPlane) &&
|
||||
stride_u == stride(kUPlane) && stride_v == stride(kVPlane)) {
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Need to allocate new buffer.
|
||||
video_frame_buffer_ = new rtc::RefCountedObject<I420Buffer>(
|
||||
width, height, stride_y, stride_u, stride_v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VideoFrame::CreateFrame(const uint8_t* buffer_y,
|
||||
const uint8_t* buffer_u,
|
||||
const uint8_t* buffer_v,
|
||||
int width,
|
||||
int height,
|
||||
int stride_y,
|
||||
int stride_u,
|
||||
int stride_v) {
|
||||
return CreateFrame(buffer_y, buffer_u, buffer_v, width, height, stride_y,
|
||||
stride_u, stride_v, kVideoRotation_0);
|
||||
}
|
||||
|
||||
int VideoFrame::CreateFrame(const uint8_t* buffer_y,
|
||||
const uint8_t* buffer_u,
|
||||
const uint8_t* buffer_v,
|
||||
int width,
|
||||
int height,
|
||||
int stride_y,
|
||||
int stride_u,
|
||||
int stride_v,
|
||||
VideoRotation rotation) {
|
||||
void VideoFrame::CreateFrame(const uint8_t* buffer_y,
|
||||
const uint8_t* buffer_u,
|
||||
const uint8_t* buffer_v,
|
||||
int width,
|
||||
int height,
|
||||
int stride_y,
|
||||
int stride_u,
|
||||
int stride_v,
|
||||
VideoRotation rotation) {
|
||||
const int half_height = (height + 1) / 2;
|
||||
const int expected_size_y = height * stride_y;
|
||||
const int expected_size_u = half_height * stride_u;
|
||||
@ -123,24 +96,23 @@ int VideoFrame::CreateFrame(const uint8_t* buffer_y,
|
||||
memcpy(buffer(kUPlane), buffer_u, expected_size_u);
|
||||
memcpy(buffer(kVPlane), buffer_v, expected_size_v);
|
||||
rotation_ = rotation;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VideoFrame::CreateFrame(const uint8_t* buffer,
|
||||
int width,
|
||||
int height,
|
||||
VideoRotation rotation) {
|
||||
void VideoFrame::CreateFrame(const uint8_t* buffer,
|
||||
int width,
|
||||
int height,
|
||||
VideoRotation rotation) {
|
||||
const int stride_y = width;
|
||||
const int stride_uv = (width + 1) / 2;
|
||||
|
||||
const uint8_t* buffer_y = buffer;
|
||||
const uint8_t* buffer_u = buffer_y + stride_y * height;
|
||||
const uint8_t* buffer_v = buffer_u + stride_uv * ((height + 1) / 2);
|
||||
return CreateFrame(buffer_y, buffer_u, buffer_v, width, height, stride_y,
|
||||
stride_uv, stride_uv, rotation);
|
||||
CreateFrame(buffer_y, buffer_u, buffer_v, width, height, stride_y,
|
||||
stride_uv, stride_uv, rotation);
|
||||
}
|
||||
|
||||
int VideoFrame::CopyFrame(const VideoFrame& videoFrame) {
|
||||
void VideoFrame::CopyFrame(const VideoFrame& videoFrame) {
|
||||
if (videoFrame.IsZeroSize()) {
|
||||
video_frame_buffer_ = nullptr;
|
||||
} else if (videoFrame.native_handle()) {
|
||||
@ -149,14 +121,14 @@ int VideoFrame::CopyFrame(const VideoFrame& videoFrame) {
|
||||
CreateFrame(videoFrame.buffer(kYPlane), videoFrame.buffer(kUPlane),
|
||||
videoFrame.buffer(kVPlane), videoFrame.width(),
|
||||
videoFrame.height(), videoFrame.stride(kYPlane),
|
||||
videoFrame.stride(kUPlane), videoFrame.stride(kVPlane));
|
||||
videoFrame.stride(kUPlane), videoFrame.stride(kVPlane),
|
||||
kVideoRotation_0);
|
||||
}
|
||||
|
||||
timestamp_ = videoFrame.timestamp_;
|
||||
ntp_time_ms_ = videoFrame.ntp_time_ms_;
|
||||
render_time_ms_ = videoFrame.render_time_ms_;
|
||||
rotation_ = videoFrame.rotation_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void VideoFrame::ShallowCopy(const VideoFrame& videoFrame) {
|
||||
@ -226,26 +198,6 @@ VideoFrame VideoFrame::ConvertNativeToI420Frame() const {
|
||||
return frame;
|
||||
}
|
||||
|
||||
bool VideoFrame::EqualsFrame(const VideoFrame& frame) const {
|
||||
if (width() != frame.width() || height() != frame.height() ||
|
||||
stride(kYPlane) != frame.stride(kYPlane) ||
|
||||
stride(kUPlane) != frame.stride(kUPlane) ||
|
||||
stride(kVPlane) != frame.stride(kVPlane) ||
|
||||
timestamp() != frame.timestamp() ||
|
||||
ntp_time_ms() != frame.ntp_time_ms() ||
|
||||
render_time_ms() != frame.render_time_ms()) {
|
||||
return false;
|
||||
}
|
||||
const int half_width = (width() + 1) / 2;
|
||||
const int half_height = (height() + 1) / 2;
|
||||
return EqualPlane(buffer(kYPlane), frame.buffer(kYPlane),
|
||||
stride(kYPlane), width(), height()) &&
|
||||
EqualPlane(buffer(kUPlane), frame.buffer(kUPlane),
|
||||
stride(kUPlane), half_width, half_height) &&
|
||||
EqualPlane(buffer(kVPlane), frame.buffer(kVPlane),
|
||||
stride(kVPlane), half_width, half_height);
|
||||
}
|
||||
|
||||
size_t EncodedImage::GetBufferPaddingBytes(VideoCodecType codec_type) {
|
||||
switch (codec_type) {
|
||||
case kVideoCodecVP8:
|
||||
|
||||
@ -90,17 +90,14 @@ class FakeWebRtcVideoCaptureModule : public webrtc::VideoCaptureModule {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool SendFrame(int w, int h) {
|
||||
if (!running_) return false;
|
||||
void SendFrame(int w, int h) {
|
||||
if (!running_) return;
|
||||
webrtc::VideoFrame sample;
|
||||
// Setting stride based on width.
|
||||
if (sample.CreateEmptyFrame(w, h, w, (w + 1) / 2, (w + 1) / 2) < 0) {
|
||||
return false;
|
||||
}
|
||||
sample.CreateEmptyFrame(w, h, w, (w + 1) / 2, (w + 1) / 2);
|
||||
if (callback_) {
|
||||
callback_->OnIncomingCapturedFrame(id_, sample);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const webrtc::VideoCaptureCapability& cap() const {
|
||||
|
||||
@ -90,7 +90,7 @@ TEST_F(WebRtcVideoCapturerTest, TestCapture) {
|
||||
ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL);
|
||||
EXPECT_EQ(format, *capturer_->GetCaptureFormat());
|
||||
EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener_.last_capture_state(), 1000);
|
||||
EXPECT_TRUE(factory_->modules[0]->SendFrame(640, 480));
|
||||
factory_->modules[0]->SendFrame(640, 480);
|
||||
EXPECT_TRUE_WAIT(listener_.frame_count() > 0, 5000);
|
||||
EXPECT_EQ(capturer_->GetCaptureFormat()->fourcc, listener_.frame_fourcc());
|
||||
EXPECT_EQ(640, listener_.frame_width());
|
||||
@ -117,7 +117,7 @@ TEST_F(WebRtcVideoCapturerTest, TestCaptureVcm) {
|
||||
ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL);
|
||||
EXPECT_EQ(format, *capturer_->GetCaptureFormat());
|
||||
EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener_.last_capture_state(), 1000);
|
||||
EXPECT_TRUE(factory_->modules[0]->SendFrame(640, 480));
|
||||
factory_->modules[0]->SendFrame(640, 480);
|
||||
EXPECT_TRUE_WAIT(listener_.frame_count() > 0, 5000);
|
||||
EXPECT_EQ(capturer_->GetCaptureFormat()->fourcc, listener_.frame_fourcc());
|
||||
EXPECT_EQ(640, listener_.frame_width());
|
||||
|
||||
@ -160,7 +160,7 @@
|
||||
'<(webrtc_root)/modules/video_coding/codecs/vp8/vp8.gyp:webrtc_vp8',
|
||||
'<(webrtc_root)/modules/video_coding/codecs/vp9/vp9.gyp:webrtc_vp9',
|
||||
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers',
|
||||
'<(webrtc_root)/test/test.gyp:fake_video_frames',
|
||||
'<(webrtc_root)/test/test.gyp:video_test_common',
|
||||
'<(webrtc_root)/test/test.gyp:rtp_test_utils',
|
||||
'<(webrtc_root)/test/test.gyp:test_support_main',
|
||||
'<(webrtc_root)/test/webrtc_test_common.gyp:webrtc_test_common',
|
||||
|
||||
@ -278,16 +278,10 @@ int32_t VideoCaptureImpl::IncomingFrame(
|
||||
// Setting absolute height (in case it was negative).
|
||||
// In Windows, the image starts bottom left, instead of top left.
|
||||
// Setting a negative source height, inverts the image (within LibYuv).
|
||||
int ret = _captureFrame.CreateEmptyFrame(target_width,
|
||||
abs(target_height),
|
||||
stride_y,
|
||||
stride_uv, stride_uv);
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG(LS_ERROR) << "Failed to create empty frame, this should only "
|
||||
"happen due to bad parameters.";
|
||||
return -1;
|
||||
}
|
||||
_captureFrame.CreateEmptyFrame(target_width,
|
||||
abs(target_height),
|
||||
stride_y,
|
||||
stride_uv, stride_uv);
|
||||
const int conversionResult = ConvertToI420(
|
||||
commonVideoType, videoFrame, 0, 0, // No cropping
|
||||
width, height, videoFrameLength,
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include "webrtc/modules/video_processing/include/video_processing.h"
|
||||
#include "webrtc/modules/video_processing/test/video_processing_unittest.h"
|
||||
#include "webrtc/modules/video_processing/video_denoiser.h"
|
||||
#include "webrtc/test/frame_utils.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -148,7 +149,7 @@ TEST_F(VideoProcessingTest, Denoiser) {
|
||||
denoiser_sse_neon.DenoiseFrame(video_frame_, &denoised_frame_sse_neon);
|
||||
|
||||
// Denoising results should be the same for C and SSE/NEON denoiser.
|
||||
ASSERT_EQ(true, denoised_frame_c.EqualsFrame(denoised_frame_sse_neon));
|
||||
ASSERT_TRUE(test::FramesEqual(denoised_frame_c, denoised_frame_sse_neon));
|
||||
}
|
||||
ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
|
||||
}
|
||||
|
||||
@ -69,8 +69,8 @@ void VideoProcessingTest::SetUp() {
|
||||
vp_ = VideoProcessing::Create();
|
||||
ASSERT_TRUE(vp_ != NULL);
|
||||
|
||||
ASSERT_EQ(0, video_frame_.CreateEmptyFrame(width_, height_, width_,
|
||||
half_width_, half_width_));
|
||||
video_frame_.CreateEmptyFrame(width_, height_, width_,
|
||||
half_width_, half_width_);
|
||||
// Clear video frame so DrMemory/Valgrind will allow reads of the buffer.
|
||||
memset(video_frame_.buffer(kYPlane), 0, video_frame_.allocated_size(kYPlane));
|
||||
memset(video_frame_.buffer(kUPlane), 0, video_frame_.allocated_size(kUPlane));
|
||||
@ -142,7 +142,7 @@ TEST_F(VideoProcessingTest, IdenticalResultsAfterReset) {
|
||||
0, kVideoRotation_0, &video_frame_));
|
||||
vp_->GetFrameStats(video_frame_, &stats);
|
||||
EXPECT_GT(stats.num_pixels, 0u);
|
||||
ASSERT_EQ(0, video_frame2.CopyFrame(video_frame_));
|
||||
video_frame2.CopyFrame(video_frame_);
|
||||
ASSERT_EQ(0, vp_->Deflickering(&video_frame_, &stats));
|
||||
|
||||
// Retrieve frame stats again in case Deflickering() has zeroed them.
|
||||
|
||||
@ -70,7 +70,7 @@ void VideoDenoiser::DenoiseFrame(const VideoFrame& frame,
|
||||
height_ = frame.height();
|
||||
denoised_frame->CreateFrame(frame.buffer(kYPlane), frame.buffer(kUPlane),
|
||||
frame.buffer(kVPlane), width_, height_,
|
||||
stride_y, stride_u, stride_v);
|
||||
stride_y, stride_u, stride_v, kVideoRotation_0);
|
||||
// Setting time parameters to the output frame.
|
||||
denoised_frame->set_timestamp(frame.timestamp());
|
||||
denoised_frame->set_render_time_ms(frame.render_time_ms());
|
||||
|
||||
@ -568,7 +568,8 @@ int32_t ModuleVideoRenderImpl::SetStartImage(const uint32_t streamId,
|
||||
return -1;
|
||||
}
|
||||
assert (item->second != NULL);
|
||||
return item->second->SetStartImage(videoFrame);
|
||||
item->second->SetStartImage(videoFrame);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -594,7 +595,8 @@ int32_t ModuleVideoRenderImpl::SetTimeoutImage(const uint32_t streamId,
|
||||
return -1;
|
||||
}
|
||||
assert(item->second != NULL);
|
||||
return item->second->SetTimeoutImage(videoFrame, timeout);
|
||||
item->second->SetTimeoutImage(videoFrame, timeout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -791,7 +791,8 @@ int32_t ModuleVideoRenderImpl::SetStartImage(const uint32_t streamId,
|
||||
return -1;
|
||||
}
|
||||
assert (item->second != NULL);
|
||||
return item->second->SetStartImage(videoFrame);
|
||||
item->second->SetStartImage(videoFrame);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -817,7 +818,8 @@ int32_t ModuleVideoRenderImpl::SetTimeoutImage(const uint32_t streamId,
|
||||
return -1;
|
||||
}
|
||||
assert(item->second != NULL);
|
||||
return item->second->SetTimeoutImage(videoFrame, timeout);
|
||||
item->second->SetTimeoutImage(videoFrame, timeout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -217,7 +217,8 @@ class ScrollingImageFrameGenerator : public FrameGenerator {
|
||||
kTargetWidth, kTargetHeight,
|
||||
current_source_frame_->stride(PlaneType::kYPlane),
|
||||
current_source_frame_->stride(PlaneType::kUPlane),
|
||||
current_source_frame_->stride(PlaneType::kVPlane));
|
||||
current_source_frame_->stride(PlaneType::kVPlane),
|
||||
kVideoRotation_0);
|
||||
}
|
||||
|
||||
Clock* const clock_;
|
||||
|
||||
51
webrtc/test/frame_utils.cc
Normal file
51
webrtc/test/frame_utils.cc
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/test/frame_utils.h"
|
||||
#include "webrtc/video_frame.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
bool EqualPlane(const uint8_t* data1,
|
||||
const uint8_t* data2,
|
||||
int stride,
|
||||
int width,
|
||||
int height) {
|
||||
for (int y = 0; y < height; ++y) {
|
||||
if (memcmp(data1, data2, width) != 0)
|
||||
return false;
|
||||
data1 += stride;
|
||||
data2 += stride;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool FramesEqual(const webrtc::VideoFrame& f1, const webrtc::VideoFrame& f2) {
|
||||
if (f1.width() != f2.width() || f1.height() != f2.height() ||
|
||||
f1.stride(webrtc::kYPlane) != f2.stride(webrtc::kYPlane) ||
|
||||
f1.stride(webrtc::kUPlane) != f2.stride(webrtc::kUPlane) ||
|
||||
f1.stride(webrtc::kVPlane) != f2.stride(webrtc::kVPlane) ||
|
||||
f1.timestamp() != f2.timestamp() ||
|
||||
f1.ntp_time_ms() != f2.ntp_time_ms() ||
|
||||
f1.render_time_ms() != f2.render_time_ms()) {
|
||||
return false;
|
||||
}
|
||||
const int half_width = (f1.width() + 1) / 2;
|
||||
const int half_height = (f1.height() + 1) / 2;
|
||||
return EqualPlane(f1.buffer(webrtc::kYPlane), f2.buffer(webrtc::kYPlane),
|
||||
f1.stride(webrtc::kYPlane), f1.width(), f1.height()) &&
|
||||
EqualPlane(f1.buffer(webrtc::kUPlane), f2.buffer(webrtc::kUPlane),
|
||||
f1.stride(webrtc::kUPlane), half_width, half_height) &&
|
||||
EqualPlane(f1.buffer(webrtc::kVPlane), f2.buffer(webrtc::kVPlane),
|
||||
f1.stride(webrtc::kVPlane), half_width, half_height);
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
30
webrtc/test/frame_utils.h
Normal file
30
webrtc/test/frame_utils.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef WEBRTC_TEST_FRAME_UTILS_H_
|
||||
#define WEBRTC_TEST_FRAME_UTILS_H_
|
||||
|
||||
#include "webrtc/base/basictypes.h"
|
||||
|
||||
namespace webrtc {
|
||||
class VideoFrame;
|
||||
namespace test {
|
||||
|
||||
bool EqualPlane(const uint8_t* data1,
|
||||
const uint8_t* data2,
|
||||
int stride,
|
||||
int width,
|
||||
int height);
|
||||
|
||||
bool FramesEqual(const webrtc::VideoFrame& f1, const webrtc::VideoFrame& f2);
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_TEST_FRAME_UTILS_H_
|
||||
@ -62,13 +62,15 @@
|
||||
], # conditions.
|
||||
},
|
||||
{
|
||||
'target_name': 'fake_video_frames',
|
||||
'target_name': 'video_test_common',
|
||||
'type': 'static_library',
|
||||
'sources': [
|
||||
'fake_texture_frame.cc',
|
||||
'fake_texture_frame.h',
|
||||
'frame_generator.cc',
|
||||
'frame_generator.h',
|
||||
'frame_utils.cc',
|
||||
'frame_utils.h',
|
||||
],
|
||||
'dependencies': [
|
||||
'<(webrtc_root)/common_video/common_video.gyp:common_video',
|
||||
|
||||
@ -69,7 +69,7 @@
|
||||
'<(webrtc_root)/common.gyp:webrtc_common',
|
||||
'<(webrtc_root)/modules/modules.gyp:media_file',
|
||||
'<(webrtc_root)/modules/modules.gyp:video_render',
|
||||
'<(webrtc_root)/test/test.gyp:fake_video_frames',
|
||||
'<(webrtc_root)/test/test.gyp:video_test_common',
|
||||
'<(webrtc_root)/test/test.gyp:test_support',
|
||||
'<(webrtc_root)/test/test.gyp:rtp_test_utils',
|
||||
'<(webrtc_root)/webrtc.gyp:webrtc',
|
||||
@ -134,7 +134,7 @@
|
||||
'dependencies': [
|
||||
'<(DEPTH)/testing/gtest.gyp:gtest',
|
||||
'<(webrtc_root)/modules/modules.gyp:media_file',
|
||||
'<(webrtc_root)/test/test.gyp:fake_video_frames',
|
||||
'<(webrtc_root)/test/test.gyp:video_test_common',
|
||||
'<(webrtc_root)/test/test.gyp:test_support',
|
||||
],
|
||||
'direct_dependent_settings': {
|
||||
|
||||
@ -290,7 +290,7 @@ VideoFrame* CreateVideoFrame(uint8_t data) {
|
||||
uint8_t buffer[kSizeY];
|
||||
memset(buffer, data, kSizeY);
|
||||
frame->CreateFrame(buffer, buffer, buffer, width, height, width, width / 2,
|
||||
width / 2);
|
||||
width / 2, kVideoRotation_0);
|
||||
frame->set_render_time_ms(data);
|
||||
return frame;
|
||||
}
|
||||
|
||||
@ -1298,7 +1298,7 @@ VideoFrame CreateVideoFrame(int width, int height, uint8_t data) {
|
||||
memset(buffer.get(), data, kSizeY);
|
||||
VideoFrame frame;
|
||||
frame.CreateFrame(buffer.get(), buffer.get(), buffer.get(), width, height,
|
||||
width, width / 2, width / 2);
|
||||
width, width / 2, width / 2, kVideoRotation_0);
|
||||
frame.set_timestamp(data);
|
||||
frame.set_render_time_ms(data);
|
||||
return frame;
|
||||
|
||||
@ -27,56 +27,39 @@ class VideoFrame {
|
||||
int64_t render_time_ms,
|
||||
VideoRotation rotation);
|
||||
|
||||
// TODO(pbos): Make all create/copy functions void, they should not be able to
|
||||
// fail (which should be RTC_DCHECK/CHECKed instead).
|
||||
|
||||
// CreateEmptyFrame: Sets frame dimensions and allocates buffers based
|
||||
// on set dimensions - height and plane stride.
|
||||
// If required size is bigger than the allocated one, new buffers of adequate
|
||||
// size will be allocated.
|
||||
// Return value: 0 on success, -1 on error.
|
||||
int CreateEmptyFrame(int width,
|
||||
int height,
|
||||
int stride_y,
|
||||
int stride_u,
|
||||
int stride_v);
|
||||
void CreateEmptyFrame(int width,
|
||||
int height,
|
||||
int stride_y,
|
||||
int stride_u,
|
||||
int stride_v);
|
||||
|
||||
// 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(const uint8_t* buffer_y,
|
||||
const uint8_t* buffer_u,
|
||||
const uint8_t* buffer_v,
|
||||
int width,
|
||||
int height,
|
||||
int stride_y,
|
||||
int stride_u,
|
||||
int stride_v);
|
||||
|
||||
// TODO(guoweis): remove the previous CreateFrame when chromium has this code.
|
||||
int CreateFrame(const uint8_t* buffer_y,
|
||||
const uint8_t* buffer_u,
|
||||
const uint8_t* buffer_v,
|
||||
int width,
|
||||
int height,
|
||||
int stride_y,
|
||||
int stride_u,
|
||||
int stride_v,
|
||||
VideoRotation rotation);
|
||||
void CreateFrame(const uint8_t* buffer_y,
|
||||
const uint8_t* buffer_u,
|
||||
const uint8_t* buffer_v,
|
||||
int width,
|
||||
int height,
|
||||
int stride_y,
|
||||
int stride_u,
|
||||
int stride_v,
|
||||
VideoRotation rotation);
|
||||
|
||||
// CreateFrame: Sets the frame's members and buffers. If required size is
|
||||
// bigger than allocated one, new buffers of adequate size will be allocated.
|
||||
// |buffer| must be a packed I420 buffer.
|
||||
// Return value: 0 on success, -1 on error.
|
||||
int CreateFrame(const uint8_t* buffer,
|
||||
void CreateFrame(const uint8_t* buffer,
|
||||
int width,
|
||||
int height,
|
||||
VideoRotation rotation);
|
||||
|
||||
// Deep copy frame: 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 CopyFrame(const VideoFrame& videoFrame);
|
||||
void CopyFrame(const VideoFrame& videoFrame);
|
||||
|
||||
// Creates a shallow copy of |videoFrame|, i.e, the this object will retain a
|
||||
// reference to the video buffer also retained by |videoFrame|.
|
||||
@ -158,8 +141,6 @@ class VideoFrame {
|
||||
// called on a non-native-handle frame.
|
||||
VideoFrame ConvertNativeToI420Frame() const;
|
||||
|
||||
bool EqualsFrame(const VideoFrame& frame) const;
|
||||
|
||||
private:
|
||||
// An opaque reference counted handle that stores the pixel data.
|
||||
rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user