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
, Create
, filter
);
24 std::string
TestVideoEncoder::TestCreate() {
25 // Test that we get results for supported formats. We should at
26 // least get the software supported formats.
28 pp::VideoEncoder
video_encoder(instance_
);
29 ASSERT_FALSE(video_encoder
.is_null());
31 TestCompletionCallbackWithOutput
<std::vector
<PP_VideoProfileDescription
> >
32 callback(instance_
->pp_instance(), false);
33 callback
.WaitForResult(
34 video_encoder
.GetSupportedProfiles(callback
.GetCallback()));
36 ASSERT_GE(callback
.result(), 1U);
38 const std::vector
<PP_VideoProfileDescription
> video_profiles
=
40 ASSERT_GE(video_profiles
.size(), 1U);
42 bool found_vp8
= false;
43 for (uint32_t i
= 0; i
< video_profiles
.size(); ++i
) {
44 const PP_VideoProfileDescription
& description
= video_profiles
[i
];
45 if (description
.profile
== PP_VIDEOPROFILE_VP8_ANY
&&
46 description
.hardware_accelerated
== PP_FALSE
) {
47 ASSERT_GE(description
.max_framerate_numerator
/
48 description
.max_framerate_denominator
,
53 ASSERT_TRUE(found_vp8
);
55 // Test that initializing the encoder with incorrect size fails.
57 pp::VideoEncoder
video_encoder(instance_
);
58 ASSERT_FALSE(video_encoder
.is_null());
59 pp::Size
video_size(0, 0);
61 TestCompletionCallback
callback(instance_
->pp_instance(), false);
62 callback
.WaitForResult(
63 video_encoder
.Initialize(PP_VIDEOFRAME_FORMAT_I420
,
65 PP_VIDEOPROFILE_VP8_ANY
,
67 PP_HARDWAREACCELERATION_WITHFALLBACK
,
68 callback
.GetCallback()));
70 ASSERT_EQ(PP_ERROR_BADARGUMENT
, callback
.result());
72 // Test that initializing the encoder with software VP8 succeeds.
74 pp::VideoEncoder
video_encoder(instance_
);
75 ASSERT_FALSE(video_encoder
.is_null());
76 pp::Size
video_size(640, 480);
78 TestCompletionCallback
callback(instance_
->pp_instance(), false);
79 callback
.WaitForResult(
80 video_encoder
.Initialize(PP_VIDEOFRAME_FORMAT_I420
,
82 PP_VIDEOPROFILE_VP8_ANY
,
84 PP_HARDWAREACCELERATION_WITHFALLBACK
,
85 callback
.GetCallback()));
87 ASSERT_EQ(PP_OK
, callback
.result());
90 ASSERT_EQ(PP_OK
, video_encoder
.GetFrameCodedSize(&coded_size
));
91 ASSERT_GE(coded_size
.GetArea(), video_size
.GetArea());
92 ASSERT_GE(video_encoder
.GetFramesRequired(), 1);
94 TestCompletionCallbackWithOutput
<pp::VideoFrame
> get_video_frame(
95 instance_
->pp_instance(), false);
96 get_video_frame
.WaitForResult(
97 video_encoder
.GetVideoFrame(get_video_frame
.GetCallback()));
98 ASSERT_EQ(PP_OK
, get_video_frame
.result());
100 pp::Size video_frame_size
;
101 ASSERT_TRUE(get_video_frame
.output().GetSize(&video_frame_size
));
102 ASSERT_EQ(coded_size
.GetArea(), video_frame_size
.GetArea());