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

Unified Diff: media/gpu/video_encode_accelerator_unittest.cc

Issue 2858193002: Refactor: Extract gpu_video_encode_accelerator_factory. (Closed)
Patch Set: Try Again. Fix compiling errors on Windows. Created 3 years, 7 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 | « media/gpu/ipc/service/gpu_video_encode_accelerator.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/gpu/video_encode_accelerator_unittest.cc
diff --git a/media/gpu/video_encode_accelerator_unittest.cc b/media/gpu/video_encode_accelerator_unittest.cc
index aa6566314292a155fbaec0249af6445a7e2fab8c..6b76c8da7d459168da5e4c167cc2797eb3f60288 100644
--- a/media/gpu/video_encode_accelerator_unittest.cc
+++ b/media/gpu/video_encode_accelerator_unittest.cc
@@ -48,28 +48,16 @@
#include "media/filters/ffmpeg_video_decoder.h"
#include "media/filters/h264_parser.h"
#include "media/filters/ivf_parser.h"
+#include "media/gpu/gpu_video_encode_accelerator_factory.h"
#include "media/gpu/video_accelerator_unittest_helpers.h"
#include "media/video/fake_video_encode_accelerator.h"
#include "media/video/video_encode_accelerator.h"
#include "testing/gtest/include/gtest/gtest.h"
-#if defined(OS_CHROMEOS)
-#if defined(USE_V4L2_CODEC)
-#include "base/threading/thread_task_runner_handle.h"
-#include "media/gpu/v4l2_video_encode_accelerator.h"
-#endif
-#if defined(ARCH_CPU_X86_FAMILY)
-#include "media/gpu/vaapi_video_encode_accelerator.h"
+#if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
#include "media/gpu/vaapi_wrapper.h"
-// Status has been defined as int in Xlib.h.
-#undef Status
-#endif // defined(ARCH_CPU_X86_FAMILY)
-#elif defined(OS_MACOSX)
-#include "media/gpu/vt_video_encode_accelerator_mac.h"
#elif defined(OS_WIN)
#include "media/gpu/media_foundation_video_encode_accelerator_win.h"
-#else
-#error The VideoEncodeAcceleratorUnittest is not supported on this platform.
#endif
namespace media {
@@ -442,51 +430,6 @@ static void ParseAndReadTestStreamData(const base::FilePath::StringType& data,
}
}
-static std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA() {
- std::unique_ptr<VideoEncodeAccelerator> encoder;
- if (g_fake_encoder) {
- encoder.reset(new FakeVideoEncodeAccelerator(
- scoped_refptr<base::SingleThreadTaskRunner>(
- base::ThreadTaskRunnerHandle::Get())));
- }
- return encoder;
-}
-
-static std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA() {
- std::unique_ptr<VideoEncodeAccelerator> encoder;
-#if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
- scoped_refptr<V4L2Device> device = V4L2Device::Create();
- if (device)
- encoder.reset(new V4L2VideoEncodeAccelerator(device));
-#endif
- return encoder;
-}
-
-static std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA() {
- std::unique_ptr<VideoEncodeAccelerator> encoder;
-#if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
- encoder.reset(new VaapiVideoEncodeAccelerator());
-#endif
- return encoder;
-}
-
-static std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA() {
- std::unique_ptr<VideoEncodeAccelerator> encoder;
-#if defined(OS_MACOSX)
- encoder.reset(new VTVideoEncodeAccelerator());
-#endif
- return encoder;
-}
-
-static std::unique_ptr<VideoEncodeAccelerator> CreateMFVEA() {
- std::unique_ptr<VideoEncodeAccelerator> encoder;
-#if defined(OS_WIN)
- MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization();
- encoder.reset(new MediaFoundationVideoEncodeAccelerator());
-#endif
- return encoder;
-}
-
// Basic test environment shared across multiple test cases. We only need to
// setup it once for all test cases.
// It helps
@@ -1227,6 +1170,30 @@ VEAClient::VEAClient(TestStream* test_stream,
thread_checker_.DetachFromThread();
}
+// Helper function to create VEA.
+static std::unique_ptr<VideoEncodeAccelerator> CreateVideoEncodeAccelerator(
+ VideoPixelFormat input_format,
+ const gfx::Size& input_visible_size,
+ VideoCodecProfile output_profile,
+ uint32_t initial_bitrate,
+ VideoEncodeAccelerator::Client* client,
+ const gpu::GpuPreferences& gpu_preferences) {
+ if (g_fake_encoder) {
+ std::unique_ptr<VideoEncodeAccelerator> encoder(
+ new FakeVideoEncodeAccelerator(
+ scoped_refptr<base::SingleThreadTaskRunner>(
+ base::ThreadTaskRunnerHandle::Get())));
+ if (encoder->Initialize(input_format, input_visible_size, output_profile,
+ initial_bitrate, client))
+ return encoder;
+ return nullptr;
+ } else {
+ return GpuVideoEncodeAcceleratorFactory::CreateVEA(
+ input_format, input_visible_size, output_profile, initial_bitrate,
+ client, gpu_preferences);
+ }
+}
+
void VEAClient::CreateEncoder() {
DCHECK(thread_checker_.CalledOnValidThread());
LOG_ASSERT(!has_encoder());
@@ -1234,31 +1201,22 @@ void VEAClient::CreateEncoder() {
vea_client_task_runner_ = base::ThreadTaskRunnerHandle::Get();
encode_task_runner_ = vea_client_task_runner_;
- std::unique_ptr<VideoEncodeAccelerator> encoders[] = {
- CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(),
- CreateMFVEA()};
-
DVLOG(1) << "Profile: " << test_stream_->requested_profile
<< ", initial bitrate: " << requested_bitrate_;
- for (size_t i = 0; i < arraysize(encoders); ++i) {
- if (!encoders[i])
- continue;
- encoder_ = std::move(encoders[i]);
- if (encoder_->Initialize(kInputFormat, test_stream_->visible_size,
- test_stream_->requested_profile,
- requested_bitrate_, this)) {
- encoder_weak_factory_.reset(
- new base::WeakPtrFactory<VideoEncodeAccelerator>(encoder_.get()));
- TryToSetupEncodeOnSeparateThread();
- SetStreamParameters(requested_bitrate_, requested_framerate_);
- SetState(CS_INITIALIZED);
- return;
- }
+ encoder_ = CreateVideoEncodeAccelerator(
+ kInputFormat, test_stream_->visible_size, test_stream_->requested_profile,
+ requested_bitrate_, this, gpu::GpuPreferences());
+ if (!encoder_) {
+ LOG(ERROR) << "Failed creating a VideoEncodeAccelerator.";
+ SetState(CS_ERROR);
+ return;
}
- encoder_.reset();
- LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed";
- SetState(CS_ERROR);
+ encoder_weak_factory_.reset(
+ new base::WeakPtrFactory<VideoEncodeAccelerator>(encoder_.get()));
+ TryToSetupEncodeOnSeparateThread();
+ SetStreamParameters(requested_bitrate_, requested_framerate_);
+ SetState(CS_INITIALIZED);
}
void VEAClient::DecodeCompleted() {
@@ -1857,26 +1815,17 @@ void SimpleVEAClientBase::CreateEncoder() {
LOG_ASSERT(!has_encoder());
LOG_ASSERT(g_env->test_streams_.size());
- std::unique_ptr<VideoEncodeAccelerator> encoders[] = {
- CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(),
- CreateMFVEA()};
-
gfx::Size visible_size(width_, height_);
- for (auto& encoder : encoders) {
- if (!encoder)
- continue;
- encoder_ = std::move(encoder);
- if (encoder_->Initialize(kInputFormat, visible_size,
- g_env->test_streams_[0]->requested_profile,
- bitrate_, this)) {
- encoder_->RequestEncodingParametersChange(bitrate_, fps_);
- SetState(CS_INITIALIZED);
- return;
- }
+ encoder_ = CreateVideoEncodeAccelerator(
+ kInputFormat, visible_size, g_env->test_streams_[0]->requested_profile,
+ bitrate_, this, gpu::GpuPreferences());
+ if (!encoder_) {
+ LOG(ERROR) << "Failed creating a VideoEncodeAccelerator.";
+ SetState(CS_ERROR);
+ return;
}
- encoder_.reset();
- LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed";
- SetState(CS_ERROR);
+ encoder_->RequestEncodingParametersChange(bitrate_, fps_);
+ SetState(CS_INITIALIZED);
}
void SimpleVEAClientBase::DestroyEncoder() {
@@ -2375,6 +2324,8 @@ int main(int argc, char** argv) {
#if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
media::VaapiWrapper::PreSandboxInitialization();
+#elif defined(OS_WIN)
+ media::MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization();
#endif
media::g_env =
« no previous file with comments | « media/gpu/ipc/service/gpu_video_encode_accelerator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698