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

Side by Side Diff: ppapi/tests/test_video_encoder.cc

Issue 1132833002: pepper: add software vp9 encoder support to PPB_VideoEncoder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Additional comments Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « ppapi/tests/test_video_encoder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, Create, 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);
22 } 25 }
23 26
24 std::string TestVideoEncoder::TestCreate() { 27 std::string TestVideoEncoder::TestAvailableCodecs() {
25 // Test that we get results for supported formats. We should at 28 // Test that we get results for supported formats. We should at
26 // least get the software supported formats. 29 // least get the software supported formats.
27 { 30 pp::VideoEncoder video_encoder(instance_);
28 pp::VideoEncoder video_encoder(instance_); 31 ASSERT_FALSE(video_encoder.is_null());
29 ASSERT_FALSE(video_encoder.is_null());
30 32
31 TestCompletionCallbackWithOutput<std::vector<PP_VideoProfileDescription> > 33 TestCompletionCallbackWithOutput<std::vector<PP_VideoProfileDescription> >
32 callback(instance_->pp_instance(), false); 34 callback(instance_->pp_instance(), false);
33 callback.WaitForResult( 35 callback.WaitForResult(
34 video_encoder.GetSupportedProfiles(callback.GetCallback())); 36 video_encoder.GetSupportedProfiles(callback.GetCallback()));
35 37
36 ASSERT_GE(callback.result(), 1U); 38 ASSERT_GE(callback.result(), 1U);
37 39
38 const std::vector<PP_VideoProfileDescription> video_profiles = 40 const std::vector<PP_VideoProfileDescription> video_profiles =
39 callback.output(); 41 callback.output();
40 ASSERT_GE(video_profiles.size(), 1U); 42 ASSERT_GE(video_profiles.size(), 1U);
41 43
42 bool found_vp8 = false; 44 bool found_vp8 = false, found_vp9 = false;
43 for (uint32_t i = 0; i < video_profiles.size(); ++i) { 45 for (uint32_t i = 0; i < video_profiles.size(); ++i) {
44 const PP_VideoProfileDescription& description = video_profiles[i]; 46 const PP_VideoProfileDescription& description = video_profiles[i];
45 if (description.profile == PP_VIDEOPROFILE_VP8_ANY && 47 if (description.hardware_accelerated == PP_FALSE) {
46 description.hardware_accelerated == PP_FALSE) { 48 ASSERT_GE(description.max_framerate_numerator /
47 ASSERT_GE(description.max_framerate_numerator / 49 description.max_framerate_denominator,
48 description.max_framerate_denominator, 50 30U);
49 30U); 51 if (description.profile == PP_VIDEOPROFILE_VP8_ANY)
50 found_vp8 = true; 52 found_vp8 = true;
51 } 53 else if (description.profile == PP_VIDEOPROFILE_VP9_ANY)
54 found_vp9 = true;
52 } 55 }
53 ASSERT_TRUE(found_vp8);
54 } 56 }
55 // Test that initializing the encoder with incorrect size fails. 57 ASSERT_TRUE(found_vp8);
56 { 58 ASSERT_TRUE(found_vp9);
57 pp::VideoEncoder video_encoder(instance_);
58 ASSERT_FALSE(video_encoder.is_null());
59 pp::Size video_size(0, 0);
60
61 TestCompletionCallback callback(instance_->pp_instance(), false);
62 callback.WaitForResult(
63 video_encoder.Initialize(PP_VIDEOFRAME_FORMAT_I420,
64 video_size,
65 PP_VIDEOPROFILE_VP8_ANY,
66 1000000,
67 PP_HARDWAREACCELERATION_WITHFALLBACK,
68 callback.GetCallback()));
69
70 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
71 }
72 // Test that initializing the encoder with software VP8 succeeds.
73 {
74 pp::VideoEncoder video_encoder(instance_);
75 ASSERT_FALSE(video_encoder.is_null());
76 pp::Size video_size(640, 480);
77
78 TestCompletionCallback callback(instance_->pp_instance(), false);
79 callback.WaitForResult(
80 video_encoder.Initialize(PP_VIDEOFRAME_FORMAT_I420,
81 video_size,
82 PP_VIDEOPROFILE_VP8_ANY,
83 1000000,
84 PP_HARDWAREACCELERATION_WITHFALLBACK,
85 callback.GetCallback()));
86
87 ASSERT_EQ(PP_OK, callback.result());
88
89 pp::Size coded_size;
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);
93
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());
99
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());
103 }
104 59
105 PASS(); 60 PASS();
106 } 61 }
62
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);
68
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()));
73
74 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
75
76 PASS();
77 }
78
79 std::string TestVideoEncoder::TestInitializeVP8() {
80 return TestInitializeCodec(PP_VIDEOPROFILE_VP8_ANY);
81 }
82
83 std::string TestVideoEncoder::TestInitializeVP9() {
84 return TestInitializeCodec(PP_VIDEOPROFILE_VP9_ANY);
85 }
86
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);
91
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()));
96
97 ASSERT_EQ(PP_OK, callback.result());
98
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);
103
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());
109
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());
113
114 PASS();
115 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_video_encoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698