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

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

Issue 1348563003: ppapi: implement PPB_AudioEncoder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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_audio_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
(Empty)
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.
4
5 #include "ppapi/tests/test_audio_encoder.h"
6
7 #include "ppapi/c/pp_codecs.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/audio_encoder.h"
10 #include "ppapi/tests/testing_instance.h"
11
12 REGISTER_TEST_CASE(AudioEncoder);
13
14 bool TestAudioEncoder::Init() {
15 audio_encoder_interface_ = static_cast<const PPB_AudioEncoder_0_1*>(
16 pp::Module::Get()->GetBrowserInterface(PPB_AUDIOENCODER_INTERFACE_0_1));
17 return audio_encoder_interface_ && CheckTestingInterface();
18 }
19
20 void TestAudioEncoder::RunTests(const std::string& filter) {
21 RUN_CALLBACK_TEST(TestAudioEncoder, AvailableCodecs, filter);
22 RUN_CALLBACK_TEST(TestAudioEncoder, IncorrectParametersFails, filter);
23 RUN_CALLBACK_TEST(TestAudioEncoder, InitializeTwiceFails, filter);
24 RUN_CALLBACK_TEST(TestAudioEncoder, InitializeOpusMono, filter);
25 RUN_CALLBACK_TEST(TestAudioEncoder, InitializeOpusStereo, filter);
26 }
27
28 std::string TestAudioEncoder::TestAvailableCodecs() {
29 // Test that we get results for supported formats. We should at
30 // least get the software supported formats.
31 pp::AudioEncoder audio_encoder(instance_);
32 ASSERT_FALSE(audio_encoder.is_null());
33
34 TestCompletionCallbackWithOutput<std::vector<PP_AudioProfileDescription>>
Adrian Kuegel 2015/11/19 15:54:30 The two closing '>' break the GN build. Please fix
35 callback(instance_->pp_instance(), false);
36 callback.WaitForResult(
37 audio_encoder.GetSupportedProfiles(callback.GetCallback()));
38 ASSERT_GE(callback.result(), 1U);
39
40 const std::vector<PP_AudioProfileDescription> audio_profiles =
41 callback.output();
42 ASSERT_GE(audio_profiles.size(), 1U);
43
44 bool found_opus_48hz = false;
45 for (uint32_t i = 0; i < audio_profiles.size(); ++i) {
46 const PP_AudioProfileDescription& description = audio_profiles[i];
47 if (description.profile == PP_AUDIOPROFILE_OPUS &&
48 description.sample_rate == PP_AUDIOBUFFER_SAMPLERATE_48000 &&
49 description.max_channels >= 2)
50 found_opus_48hz = true;
51 }
52 ASSERT_TRUE(found_opus_48hz);
53
54 PASS();
55 }
56
57 std::string TestAudioEncoder::TestIncorrectParametersFails() {
58 // Test that initializing the encoder with incorrect size fails.
59 pp::AudioEncoder audio_encoder(instance_);
60 ASSERT_FALSE(audio_encoder.is_null());
61
62 // Invalid number of channels.
63 TestCompletionCallback callback(instance_->pp_instance(), false);
64 callback.WaitForResult(audio_encoder.Initialize(
65 42, PP_AUDIOBUFFER_SAMPLERATE_48000, PP_AUDIOBUFFER_SAMPLESIZE_16_BITS,
66 PP_AUDIOPROFILE_OPUS, 10000, PP_HARDWAREACCELERATION_WITHFALLBACK,
67 callback.GetCallback()));
68 ASSERT_EQ(PP_ERROR_NOTSUPPORTED, callback.result());
69
70 // Invalid sampling rate.
71 callback.WaitForResult(audio_encoder.Initialize(
72 2, static_cast<PP_AudioBuffer_SampleRate>(123456),
73 PP_AUDIOBUFFER_SAMPLESIZE_16_BITS, PP_AUDIOPROFILE_OPUS, 10000,
74 PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback()));
75 ASSERT_EQ(PP_ERROR_NOTSUPPORTED, callback.result());
76
77 // Invalid sample size.
78 callback.WaitForResult(audio_encoder.Initialize(
79 2, static_cast<PP_AudioBuffer_SampleRate>(48000),
80 static_cast<PP_AudioBuffer_SampleSize>(72), PP_AUDIOPROFILE_OPUS, 10000,
81 PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback()));
82 ASSERT_EQ(PP_ERROR_NOTSUPPORTED, callback.result());
83
84 PASS();
85 }
86
87 std::string TestAudioEncoder::TestInitializeTwiceFails() {
88 // Test that initializing the encoder with incorrect size fails.
89 pp::AudioEncoder audio_encoder(instance_);
90 ASSERT_FALSE(audio_encoder.is_null());
91
92 TestCompletionCallback callback(instance_->pp_instance(), false);
93 callback.WaitForResult(audio_encoder.Initialize(
94 2, PP_AUDIOBUFFER_SAMPLERATE_48000, PP_AUDIOBUFFER_SAMPLESIZE_16_BITS,
95 PP_AUDIOPROFILE_OPUS, 10000, PP_HARDWAREACCELERATION_WITHFALLBACK,
96 callback.GetCallback()));
97 ASSERT_EQ(PP_OK, callback.result());
98
99 callback.WaitForResult(audio_encoder.Initialize(
100 2, PP_AUDIOBUFFER_SAMPLERATE_48000, PP_AUDIOBUFFER_SAMPLESIZE_16_BITS,
101 PP_AUDIOPROFILE_OPUS, 10000, PP_HARDWAREACCELERATION_WITHFALLBACK,
102 callback.GetCallback()));
103 ASSERT_EQ(PP_ERROR_FAILED, callback.result());
104
105 PASS();
106 }
107
108 std::string TestAudioEncoder::TestInitializeOpusMono() {
109 return TestInitializeCodec(1, PP_AUDIOBUFFER_SAMPLERATE_48000,
110 PP_AUDIOBUFFER_SAMPLESIZE_16_BITS,
111 PP_AUDIOPROFILE_OPUS);
112 }
113
114 std::string TestAudioEncoder::TestInitializeOpusStereo() {
115 return TestInitializeCodec(2, PP_AUDIOBUFFER_SAMPLERATE_48000,
116 PP_AUDIOBUFFER_SAMPLESIZE_16_BITS,
117 PP_AUDIOPROFILE_OPUS);
118 }
119
120 std::string TestAudioEncoder::TestInitializeCodec(
121 uint32_t channels,
122 PP_AudioBuffer_SampleRate input_sample_rate,
123 PP_AudioBuffer_SampleSize input_sample_size,
124 PP_AudioProfile output_profile) {
125 pp::AudioEncoder audio_encoder(instance_);
126 ASSERT_FALSE(audio_encoder.is_null());
127 pp::Size audio_size(640, 480);
128
129 TestCompletionCallback callback(instance_->pp_instance(), false);
130 callback.WaitForResult(audio_encoder.Initialize(
131 channels, input_sample_rate, input_sample_size, output_profile, 10000,
132 PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback()));
133 ASSERT_EQ(PP_OK, callback.result());
134
135 ASSERT_GE(audio_encoder.GetNumberOfSamples(), 2U);
136
137 TestCompletionCallbackWithOutput<pp::AudioBuffer> get_buffer(
138 instance_->pp_instance(), false);
139 get_buffer.WaitForResult(audio_encoder.GetBuffer(get_buffer.GetCallback()));
140 ASSERT_EQ(PP_OK, get_buffer.result());
141
142 PASS();
143 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_audio_encoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698