Elim cr-checkbox
[chromium-blink-merge.git] / ppapi / tests / test_video_encoder.cc
blob4b2abf2a7764915f3bfaddae6e8ebb5237e9cd5f
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/tests/test_video_encoder.h"
7 #include "ppapi/c/pp_codecs.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/video_encoder.h"
10 #include "ppapi/tests/testing_instance.h"
12 REGISTER_TEST_CASE(VideoEncoder);
14 bool TestVideoEncoder::Init() {
15 video_encoder_interface_ = static_cast<const PPB_VideoEncoder_0_1*>(
16 pp::Module::Get()->GetBrowserInterface(PPB_VIDEOENCODER_INTERFACE_0_1));
17 return video_encoder_interface_ && CheckTestingInterface();
20 void TestVideoEncoder::RunTests(const std::string& filter) {
21 RUN_CALLBACK_TEST(TestVideoEncoder, AvailableCodecs, filter);
22 RUN_CALLBACK_TEST(TestVideoEncoder, IncorrectSizeFails, filter);
23 RUN_CALLBACK_TEST(TestVideoEncoder, InitializeVP8, filter);
24 RUN_CALLBACK_TEST(TestVideoEncoder, InitializeVP9, filter);
27 std::string TestVideoEncoder::TestAvailableCodecs() {
28 // Test that we get results for supported formats. We should at
29 // least get the software supported formats.
30 pp::VideoEncoder video_encoder(instance_);
31 ASSERT_FALSE(video_encoder.is_null());
33 TestCompletionCallbackWithOutput<std::vector<PP_VideoProfileDescription> >
34 callback(instance_->pp_instance(), false);
35 callback.WaitForResult(
36 video_encoder.GetSupportedProfiles(callback.GetCallback()));
38 ASSERT_GE(callback.result(), 1U);
40 const std::vector<PP_VideoProfileDescription> video_profiles =
41 callback.output();
42 ASSERT_GE(video_profiles.size(), 1U);
44 bool found_vp8 = false, found_vp9 = false;
45 for (uint32_t i = 0; i < video_profiles.size(); ++i) {
46 const PP_VideoProfileDescription& description = video_profiles[i];
47 if (description.hardware_accelerated == PP_FALSE) {
48 ASSERT_GE(description.max_framerate_numerator /
49 description.max_framerate_denominator,
50 30U);
51 if (description.profile == PP_VIDEOPROFILE_VP8_ANY)
52 found_vp8 = true;
53 else if (description.profile == PP_VIDEOPROFILE_VP9_ANY)
54 found_vp9 = true;
57 ASSERT_TRUE(found_vp8);
58 ASSERT_TRUE(found_vp9);
60 PASS();
63 std::string TestVideoEncoder::TestIncorrectSizeFails() {
64 // Test that initializing the encoder with incorrect size fails.
65 pp::VideoEncoder video_encoder(instance_);
66 ASSERT_FALSE(video_encoder.is_null());
67 pp::Size video_size(0, 0);
69 TestCompletionCallback callback(instance_->pp_instance(), false);
70 callback.WaitForResult(video_encoder.Initialize(
71 PP_VIDEOFRAME_FORMAT_I420, video_size, PP_VIDEOPROFILE_VP8_ANY, 1000000,
72 PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback()));
74 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
76 PASS();
79 std::string TestVideoEncoder::TestInitializeVP8() {
80 return TestInitializeCodec(PP_VIDEOPROFILE_VP8_ANY);
83 std::string TestVideoEncoder::TestInitializeVP9() {
84 return TestInitializeCodec(PP_VIDEOPROFILE_VP9_ANY);
87 std::string TestVideoEncoder::TestInitializeCodec(PP_VideoProfile profile) {
88 pp::VideoEncoder video_encoder(instance_);
89 ASSERT_FALSE(video_encoder.is_null());
90 pp::Size video_size(640, 480);
92 TestCompletionCallback callback(instance_->pp_instance(), false);
93 callback.WaitForResult(video_encoder.Initialize(
94 PP_VIDEOFRAME_FORMAT_I420, video_size, profile, 1000000,
95 PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback()));
97 ASSERT_EQ(PP_OK, callback.result());
99 pp::Size coded_size;
100 ASSERT_EQ(PP_OK, video_encoder.GetFrameCodedSize(&coded_size));
101 ASSERT_GE(coded_size.GetArea(), video_size.GetArea());
102 ASSERT_GE(video_encoder.GetFramesRequired(), 1);
104 TestCompletionCallbackWithOutput<pp::VideoFrame> get_video_frame(
105 instance_->pp_instance(), false);
106 get_video_frame.WaitForResult(
107 video_encoder.GetVideoFrame(get_video_frame.GetCallback()));
108 ASSERT_EQ(PP_OK, get_video_frame.result());
110 pp::Size video_frame_size;
111 ASSERT_TRUE(get_video_frame.output().GetSize(&video_frame_size));
112 ASSERT_EQ(coded_size.GetArea(), video_frame_size.GetArea());
114 PASS();