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.
27 pp::VideoEncoder
video_encoder(instance_
);
28 ASSERT_FALSE(video_encoder
.is_null());
30 TestCompletionCallbackWithOutput
<std::vector
<PP_VideoProfileDescription
> >
31 callback(instance_
->pp_instance(), false);
32 callback
.WaitForResult(
33 video_encoder
.GetSupportedProfiles(callback
.GetCallback()));
35 ASSERT_EQ(PP_OK
, callback
.result());
37 const std::vector
<PP_VideoProfileDescription
> video_profiles
=
39 ASSERT_GE(video_profiles
.size(), 1U);
41 bool found_vp8
= false;
42 for (uint32_t i
= 0; i
< video_profiles
.size(); ++i
) {
43 const PP_VideoProfileDescription
& description
= video_profiles
[i
];
44 if (description
.profile
== PP_VIDEOPROFILE_VP8_ANY
)
47 ASSERT_TRUE(found_vp8
);
49 // Test that initializing the encoder with incorrect size fails.
51 pp::VideoEncoder
video_encoder(instance_
);
52 ASSERT_FALSE(video_encoder
.is_null());
53 pp::Size
video_size(0, 0);
55 TestCompletionCallback
callback(instance_
->pp_instance(), false);
56 callback
.WaitForResult(
57 video_encoder
.Initialize(PP_VIDEOFRAME_FORMAT_I420
,
59 PP_VIDEOPROFILE_VP8_ANY
,
61 PP_HARDWAREACCELERATION_WITHFALLBACK
,
62 callback
.GetCallback()));
64 ASSERT_EQ(PP_ERROR_BADARGUMENT
, callback
.result());
66 // Test that initializing the encoder with software VP8 succeeds.
68 pp::VideoEncoder
video_encoder(instance_
);
69 ASSERT_FALSE(video_encoder
.is_null());
70 pp::Size
video_size(640, 480);
72 TestCompletionCallback
callback(instance_
->pp_instance(), false);
73 callback
.WaitForResult(
74 video_encoder
.Initialize(PP_VIDEOFRAME_FORMAT_I420
,
76 PP_VIDEOPROFILE_VP8_ANY
,
78 PP_HARDWAREACCELERATION_WITHFALLBACK
,
79 callback
.GetCallback()));
81 ASSERT_EQ(PP_OK
, callback
.result());
84 ASSERT_EQ(PP_OK
, video_encoder
.GetFrameCodedSize(&coded_size
));
85 ASSERT_GE(coded_size
.GetArea(), video_size
.GetArea());
86 ASSERT_GE(video_encoder
.GetFramesRequired(), 1);
88 TestCompletionCallbackWithOutput
<pp::VideoFrame
> get_video_frame(
89 instance_
->pp_instance(), false);
90 get_video_frame
.WaitForResult(
91 video_encoder
.GetVideoFrame(get_video_frame
.GetCallback()));
92 ASSERT_EQ(PP_OK
, get_video_frame
.result());
94 pp::Size video_frame_size
;
95 ASSERT_TRUE(get_video_frame
.output().GetSize(&video_frame_size
));
96 ASSERT_EQ(coded_size
.GetArea(), video_frame_size
.GetArea());