OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/tests/test_video_encoder.h" | 5 #include "ppapi/tests/test_video_encoder.h" |
6 | 6 |
7 #include "ppapi/c/pp_codecs.h" | 7 #include "ppapi/c/pp_codecs.h" |
8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
9 #include "ppapi/cpp/video_encoder.h" | 9 #include "ppapi/cpp/video_encoder.h" |
10 #include "ppapi/tests/testing_instance.h" | 10 #include "ppapi/tests/testing_instance.h" |
11 | 11 |
12 REGISTER_TEST_CASE(VideoEncoder); | 12 REGISTER_TEST_CASE(VideoEncoder); |
13 | 13 |
14 bool TestVideoEncoder::Init() { | 14 bool TestVideoEncoder::Init() { |
15 video_encoder_interface_ = static_cast<const PPB_VideoEncoder_0_1*>( | 15 video_encoder_interface_ = static_cast<const PPB_VideoEncoder_0_1*>( |
16 pp::Module::Get()->GetBrowserInterface(PPB_VIDEOENCODER_INTERFACE_0_1)); | 16 pp::Module::Get()->GetBrowserInterface(PPB_VIDEOENCODER_INTERFACE_0_1)); |
17 return video_encoder_interface_ && CheckTestingInterface(); | 17 return video_encoder_interface_ && CheckTestingInterface(); |
18 } | 18 } |
19 | 19 |
20 void TestVideoEncoder::RunTests(const std::string& filter) { | 20 void TestVideoEncoder::RunTests(const std::string& filter) { |
21 RUN_CALLBACK_TEST(TestVideoEncoder, AvailableCodecs, filter); | 21 RUN_CALLBACK_TEST(TestVideoEncoder, AvailableCodecs, filter); |
22 RUN_CALLBACK_TEST(TestVideoEncoder, IncorrectSizeFails, filter); | 22 RUN_CALLBACK_TEST(TestVideoEncoder, IncorrectSizeFails, filter); |
23 RUN_CALLBACK_TEST(TestVideoEncoder, InitializeVP8, filter); | 23 RUN_CALLBACK_TEST(TestVideoEncoder, InitializeVP8, filter); |
24 RUN_CALLBACK_TEST(TestVideoEncoder, InitializeVP9, filter); | 24 RUN_CALLBACK_TEST(TestVideoEncoder, InitializeVP9_Profile0, filter); |
25 RUN_CALLBACK_TEST(TestVideoEncoder, InitializeVP9_Profile1, filter); | |
26 RUN_CALLBACK_TEST(TestVideoEncoder, InitializeVP9_Profile2, filter); | |
27 RUN_CALLBACK_TEST(TestVideoEncoder, InitializeVP9_Profile3, filter); | |
25 } | 28 } |
26 | 29 |
27 std::string TestVideoEncoder::TestAvailableCodecs() { | 30 std::string TestVideoEncoder::TestAvailableCodecs() { |
ddorwin
2016/03/25 22:51:22
Should this test have ifdef'd tests for H.264? (No
servolk
2016/03/25 23:52:01
The only H.264 encoder that I could find in Chrome
ddorwin
2016/03/26 00:45:08
Thanks for checking.
| |
28 // Test that we get results for supported formats. We should at | 31 // Test that we get results for supported formats. We should at |
29 // least get the software supported formats. | 32 // least get the software supported formats. |
30 pp::VideoEncoder video_encoder(instance_); | 33 pp::VideoEncoder video_encoder(instance_); |
31 ASSERT_FALSE(video_encoder.is_null()); | 34 ASSERT_FALSE(video_encoder.is_null()); |
32 | 35 |
33 TestCompletionCallbackWithOutput<std::vector<PP_VideoProfileDescription> > | 36 TestCompletionCallbackWithOutput<std::vector<PP_VideoProfileDescription> > |
34 callback(instance_->pp_instance(), false); | 37 callback(instance_->pp_instance(), false); |
35 callback.WaitForResult( | 38 callback.WaitForResult( |
36 video_encoder.GetSupportedProfiles(callback.GetCallback())); | 39 video_encoder.GetSupportedProfiles(callback.GetCallback())); |
37 | 40 |
38 ASSERT_GE(callback.result(), 1U); | 41 ASSERT_GE(callback.result(), 1U); |
39 | 42 |
40 const std::vector<PP_VideoProfileDescription> video_profiles = | 43 const std::vector<PP_VideoProfileDescription> video_profiles = |
41 callback.output(); | 44 callback.output(); |
42 ASSERT_GE(video_profiles.size(), 1U); | 45 ASSERT_GE(video_profiles.size(), 1U); |
43 | 46 |
44 bool found_vp8 = false, found_vp9 = false; | 47 bool found_vp8 = false; |
48 uint8_t found_vp9_profiles = 0; | |
45 for (uint32_t i = 0; i < video_profiles.size(); ++i) { | 49 for (uint32_t i = 0; i < video_profiles.size(); ++i) { |
46 const PP_VideoProfileDescription& description = video_profiles[i]; | 50 const PP_VideoProfileDescription& description = video_profiles[i]; |
47 if (description.hardware_accelerated == PP_FALSE) { | 51 if (description.hardware_accelerated == PP_FALSE) { |
48 ASSERT_GE(description.max_framerate_numerator / | 52 ASSERT_GE(description.max_framerate_numerator / |
49 description.max_framerate_denominator, | 53 description.max_framerate_denominator, |
50 30U); | 54 30U); |
51 if (description.profile == PP_VIDEOPROFILE_VP8_ANY) | 55 if (description.profile == PP_VIDEOPROFILE_VP8_ANY) |
52 found_vp8 = true; | 56 found_vp8 = true; |
53 else if (description.profile == PP_VIDEOPROFILE_VP9_ANY) | 57 else if (description.profile == PP_VIDEOPROFILE_VP9_PROFILE0) |
54 found_vp9 = true; | 58 found_vp9_profiles |= 1; |
59 else if (description.profile == PP_VIDEOPROFILE_VP9_PROFILE1) | |
60 found_vp9_profiles |= (1 << 1); | |
61 else if (description.profile == PP_VIDEOPROFILE_VP9_PROFILE2) | |
62 found_vp9_profiles |= (1 << 2); | |
63 else if (description.profile == PP_VIDEOPROFILE_VP9_PROFILE3) | |
64 found_vp9_profiles |= (1 << 3); | |
55 } | 65 } |
56 } | 66 } |
57 ASSERT_TRUE(found_vp8); | 67 ASSERT_TRUE(found_vp8); |
58 ASSERT_TRUE(found_vp9); | 68 ASSERT_EQ(0xf, found_vp9_profiles); |
59 | 69 |
60 PASS(); | 70 PASS(); |
61 } | 71 } |
62 | 72 |
63 std::string TestVideoEncoder::TestIncorrectSizeFails() { | 73 std::string TestVideoEncoder::TestIncorrectSizeFails() { |
64 // Test that initializing the encoder with incorrect size fails. | 74 // Test that initializing the encoder with incorrect size fails. |
65 pp::VideoEncoder video_encoder(instance_); | 75 pp::VideoEncoder video_encoder(instance_); |
66 ASSERT_FALSE(video_encoder.is_null()); | 76 ASSERT_FALSE(video_encoder.is_null()); |
67 pp::Size video_size(0, 0); | 77 pp::Size video_size(0, 0); |
68 | 78 |
69 TestCompletionCallback callback(instance_->pp_instance(), false); | 79 TestCompletionCallback callback(instance_->pp_instance(), false); |
70 callback.WaitForResult(video_encoder.Initialize( | 80 callback.WaitForResult(video_encoder.Initialize( |
71 PP_VIDEOFRAME_FORMAT_I420, video_size, PP_VIDEOPROFILE_VP8_ANY, 1000000, | 81 PP_VIDEOFRAME_FORMAT_I420, video_size, PP_VIDEOPROFILE_VP8_ANY, 1000000, |
72 PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback())); | 82 PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback())); |
73 | 83 |
74 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result()); | 84 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result()); |
75 | 85 |
76 PASS(); | 86 PASS(); |
77 } | 87 } |
78 | 88 |
79 std::string TestVideoEncoder::TestInitializeVP8() { | 89 std::string TestVideoEncoder::TestInitializeVP8() { |
80 return TestInitializeCodec(PP_VIDEOPROFILE_VP8_ANY); | 90 return TestInitializeCodec(PP_VIDEOPROFILE_VP8_ANY); |
81 } | 91 } |
82 | 92 |
83 std::string TestVideoEncoder::TestInitializeVP9() { | 93 std::string TestVideoEncoder::TestInitializeVP9_Profile0() { |
84 return TestInitializeCodec(PP_VIDEOPROFILE_VP9_ANY); | 94 return TestInitializeCodec(PP_VIDEOPROFILE_VP9_PROFILE0); |
95 } | |
96 | |
97 std::string TestVideoEncoder::TestInitializeVP9_Profile1() { | |
98 return TestInitializeCodec(PP_VIDEOPROFILE_VP9_PROFILE1); | |
99 } | |
100 | |
101 std::string TestVideoEncoder::TestInitializeVP9_Profile2() { | |
102 return TestInitializeCodec(PP_VIDEOPROFILE_VP9_PROFILE2); | |
103 } | |
104 | |
105 std::string TestVideoEncoder::TestInitializeVP9_Profile3() { | |
106 return TestInitializeCodec(PP_VIDEOPROFILE_VP9_PROFILE2); | |
ddorwin
2016/03/25 22:51:22
s/2/3/
servolk
2016/03/25 23:52:01
Done.
| |
85 } | 107 } |
86 | 108 |
87 std::string TestVideoEncoder::TestInitializeCodec(PP_VideoProfile profile) { | 109 std::string TestVideoEncoder::TestInitializeCodec(PP_VideoProfile profile) { |
88 pp::VideoEncoder video_encoder(instance_); | 110 pp::VideoEncoder video_encoder(instance_); |
89 ASSERT_FALSE(video_encoder.is_null()); | 111 ASSERT_FALSE(video_encoder.is_null()); |
90 pp::Size video_size(640, 480); | 112 pp::Size video_size(640, 480); |
91 | 113 |
92 TestCompletionCallback callback(instance_->pp_instance(), false); | 114 TestCompletionCallback callback(instance_->pp_instance(), false); |
93 callback.WaitForResult(video_encoder.Initialize( | 115 callback.WaitForResult(video_encoder.Initialize( |
94 PP_VIDEOFRAME_FORMAT_I420, video_size, profile, 1000000, | 116 PP_VIDEOFRAME_FORMAT_I420, video_size, profile, 1000000, |
(...skipping 11 matching lines...) Expand all Loading... | |
106 get_video_frame.WaitForResult( | 128 get_video_frame.WaitForResult( |
107 video_encoder.GetVideoFrame(get_video_frame.GetCallback())); | 129 video_encoder.GetVideoFrame(get_video_frame.GetCallback())); |
108 ASSERT_EQ(PP_OK, get_video_frame.result()); | 130 ASSERT_EQ(PP_OK, get_video_frame.result()); |
109 | 131 |
110 pp::Size video_frame_size; | 132 pp::Size video_frame_size; |
111 ASSERT_TRUE(get_video_frame.output().GetSize(&video_frame_size)); | 133 ASSERT_TRUE(get_video_frame.output().GetSize(&video_frame_size)); |
112 ASSERT_EQ(coded_size.GetArea(), video_frame_size.GetArea()); | 134 ASSERT_EQ(coded_size.GetArea(), video_frame_size.GetArea()); |
113 | 135 |
114 PASS(); | 136 PASS(); |
115 } | 137 } |
OLD | NEW |