Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1929)

Unified Diff: content/renderer/media/gpu/rtc_video_encoder_unittest.cc

Issue 2182183007: Handle scaling frames in RTCVideoEncoder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: posciak@ comments. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/gpu/rtc_video_encoder.cc ('k') | media/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/gpu/rtc_video_encoder_unittest.cc
diff --git a/content/renderer/media/gpu/rtc_video_encoder_unittest.cc b/content/renderer/media/gpu/rtc_video_encoder_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7531eb2aa6a80f8cef8981b30ebef4451294ee73
--- /dev/null
+++ b/content/renderer/media/gpu/rtc_video_encoder_unittest.cc
@@ -0,0 +1,180 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdint.h>
+
+#include "base/bind.h"
+#include "base/memory/ptr_util.h"
+#include "base/single_thread_task_runner.h"
+#include "base/synchronization/waitable_event.h"
+#include "base/threading/thread.h"
+#include "content/renderer/media/gpu/rtc_video_encoder.h"
+#include "media/renderers/mock_gpu_video_accelerator_factories.h"
+#include "media/video/mock_video_encode_accelerator.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/libyuv/include/libyuv/planar_functions.h"
+#include "third_party/webrtc/modules/video_coding/include/video_codec_interface.h"
+
+using ::testing::_;
+using ::testing::Invoke;
+using ::testing::Return;
+using ::testing::SaveArg;
+using ::testing::Values;
+using ::testing::WithArgs;
+
+namespace content {
+
+namespace {
+
+const int kInputFrameFillY = 12;
+const int kInputFrameFillU = 23;
+const int kInputFrameFillV = 34;
+const unsigned short kInputFrameHeight = 234;
+const unsigned short kInputFrameWidth = 345;
+const unsigned short kStartBitrate = 100;
+
+} // anonymous namespace
+
+class RTCVideoEncoderTest
+ : public ::testing::TestWithParam<webrtc::VideoCodecType> {
+ public:
+ RTCVideoEncoderTest()
+ : mock_gpu_factories_(
+ new media::MockGpuVideoAcceleratorFactories(nullptr)),
+ encoder_thread_("vea_thread"),
+ idle_waiter_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
+ base::WaitableEvent::InitialState::NOT_SIGNALED) {}
+
+ void SetUp() override {
+ DVLOG(3) << __FUNCTION__;
+ ASSERT_TRUE(encoder_thread_.Start());
+ mock_vea_ = new media::MockVideoEncodeAccelerator();
+
+ EXPECT_CALL(*mock_gpu_factories_.get(), GetTaskRunner())
+ .WillRepeatedly(Return(encoder_thread_.task_runner()));
+ EXPECT_CALL(*mock_gpu_factories_.get(), DoCreateVideoEncodeAccelerator())
+ .WillRepeatedly(Return(mock_vea_));
+ EXPECT_CALL(*mock_vea_, Initialize(_, _, _, _, _))
+ .WillOnce(Invoke(this, &RTCVideoEncoderTest::Initialize));
+ EXPECT_CALL(*mock_vea_, UseOutputBitstreamBuffer(_)).Times(3);
+ EXPECT_CALL(*mock_vea_, Destroy()).Times(1);
+ }
+
+ void TearDown() override {
+ DVLOG(3) << __FUNCTION__;
+ EXPECT_TRUE(encoder_thread_.IsRunning());
+ RunUntilIdle();
+ rtc_encoder_->Release();
+ RunUntilIdle();
+ encoder_thread_.Stop();
+ }
+
+ void RunUntilIdle() {
+ DVLOG(3) << __FUNCTION__;
+ encoder_thread_.task_runner()->PostTask(
+ FROM_HERE, base::Bind(&base::WaitableEvent::Signal,
+ base::Unretained(&idle_waiter_)));
+ idle_waiter_.Wait();
+ }
+
+ void CreateEncoder(webrtc::VideoCodecType codec_type) {
+ DVLOG(3) << __FUNCTION__;
+ rtc_encoder_ = base::WrapUnique(
+ new RTCVideoEncoder(codec_type, mock_gpu_factories_.get()));
+ }
+
+ // media::VideoEncodeAccelerator implementation.
+ bool Initialize(media::VideoPixelFormat input_format,
+ const gfx::Size& input_visible_size,
+ media::VideoCodecProfile output_profile,
+ uint32_t initial_bitrate,
+ media::VideoEncodeAccelerator::Client* client) {
+ DVLOG(3) << __FUNCTION__;
+ client->RequireBitstreamBuffers(0, input_visible_size,
+ input_visible_size.GetArea());
+ return true;
+ }
+
+ webrtc::VideoCodec GetDefaultCodec() {
+ webrtc::VideoCodec codec = {};
+ memset(&codec, 0, sizeof(codec));
+ codec.width = kInputFrameWidth;
+ codec.height = kInputFrameHeight;
+ codec.codecType = webrtc::kVideoCodecVP8;
+ codec.startBitrate = kStartBitrate;
+ return codec;
+ }
+
+ void FillFrameBuffer(rtc::scoped_refptr<webrtc::I420Buffer> frame) {
+ CHECK(libyuv::I420Rect(frame->MutableDataY(), frame->StrideY(),
+ frame->MutableDataU(), frame->StrideU(),
+ frame->MutableDataV(), frame->StrideV(), 0, 0,
+ frame->width(), frame->height(), kInputFrameFillY,
+ kInputFrameFillU, kInputFrameFillV) == 0);
+ }
+
+ void VerifyEncodedFrame(const scoped_refptr<media::VideoFrame>& frame,
+ bool force_keyframe) {
+ DVLOG(3) << __FUNCTION__;
+ EXPECT_EQ(kInputFrameWidth, frame->visible_rect().width());
+ EXPECT_EQ(kInputFrameHeight, frame->visible_rect().height());
+ EXPECT_EQ(kInputFrameFillY,
+ frame->visible_data(media::VideoFrame::kYPlane)[0]);
+ EXPECT_EQ(kInputFrameFillU,
+ frame->visible_data(media::VideoFrame::kUPlane)[0]);
+ EXPECT_EQ(kInputFrameFillV,
+ frame->visible_data(media::VideoFrame::kVPlane)[0]);
+ }
+
+ protected:
+ media::MockVideoEncodeAccelerator* mock_vea_;
+ std::unique_ptr<RTCVideoEncoder> rtc_encoder_;
+
+ private:
+ std::unique_ptr<media::MockGpuVideoAcceleratorFactories> mock_gpu_factories_;
+ base::Thread encoder_thread_;
+ base::WaitableEvent idle_waiter_;
+};
+
+TEST_P(RTCVideoEncoderTest, CreateAndInitSucceeds) {
+ const webrtc::VideoCodecType codec_type = GetParam();
+ CreateEncoder(codec_type);
+ webrtc::VideoCodec codec = GetDefaultCodec();
+ codec.codecType = codec_type;
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_encoder_->InitEncode(&codec, 1, 12345));
+}
+
+TEST_F(RTCVideoEncoderTest, EncodeScaledFrame) {
+ const webrtc::VideoCodecType codec_type = webrtc::kVideoCodecVP8;
+ CreateEncoder(codec_type);
+ webrtc::VideoCodec codec = GetDefaultCodec();
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_encoder_->InitEncode(&codec, 1, 12345));
+
+ EXPECT_CALL(*mock_vea_, Encode(_, _))
+ .Times(2)
+ .WillRepeatedly(Invoke(this, &RTCVideoEncoderTest::VerifyEncodedFrame));
+
+ const rtc::scoped_refptr<webrtc::I420Buffer> buffer =
+ webrtc::I420Buffer::Create(kInputFrameWidth, kInputFrameHeight);
+ FillFrameBuffer(buffer);
+ std::vector<webrtc::FrameType> frame_types;
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
+ rtc_encoder_->Encode(
+ webrtc::VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0),
+ nullptr, &frame_types));
+
+ const rtc::scoped_refptr<webrtc::I420Buffer> upscaled_buffer =
+ webrtc::I420Buffer::Create(2 * kInputFrameWidth, 2 * kInputFrameHeight);
+ FillFrameBuffer(upscaled_buffer);
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
+ rtc_encoder_->Encode(webrtc::VideoFrame(upscaled_buffer, 0, 0,
+ webrtc::kVideoRotation_0),
+ nullptr, &frame_types));
+}
+
+INSTANTIATE_TEST_CASE_P(CodecProfiles,
+ RTCVideoEncoderTest,
+ Values(webrtc::kVideoCodecVP8,
+ webrtc::kVideoCodecH264));
+} // namespace content
« no previous file with comments | « content/renderer/media/gpu/rtc_video_encoder.cc ('k') | media/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698