Chromium Code Reviews| OLD | NEW |
|---|---|
| (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); | |
|
bbudge
2015/11/18 17:57:57
test TestInitializeOpusStereo
llandwerlin-old
2015/11/18 18:05:27
Done.
| |
| 25 } | |
| 26 | |
| 27 std::string TestAudioEncoder::TestAvailableCodecs() { | |
| 28 // Test that we get results for supported formats. We should at | |
| 29 // least get the software supported formats. | |
| 30 pp::AudioEncoder audio_encoder(instance_); | |
| 31 ASSERT_FALSE(audio_encoder.is_null()); | |
| 32 | |
| 33 TestCompletionCallbackWithOutput<std::vector<PP_AudioProfileDescription>> | |
| 34 callback(instance_->pp_instance(), false); | |
| 35 callback.WaitForResult( | |
| 36 audio_encoder.GetSupportedProfiles(callback.GetCallback())); | |
| 37 ASSERT_GE(callback.result(), 1U); | |
| 38 | |
| 39 const std::vector<PP_AudioProfileDescription> audio_profiles = | |
| 40 callback.output(); | |
| 41 ASSERT_GE(audio_profiles.size(), 1U); | |
| 42 | |
| 43 bool found_opus_48hz = false; | |
| 44 for (uint32_t i = 0; i < audio_profiles.size(); ++i) { | |
| 45 const PP_AudioProfileDescription& description = audio_profiles[i]; | |
| 46 if (description.profile == PP_AUDIOPROFILE_OPUS && | |
| 47 description.sample_rate == PP_AUDIOBUFFER_SAMPLERATE_48000 && | |
| 48 description.max_channels >= 2) | |
| 49 found_opus_48hz = true; | |
| 50 } | |
| 51 ASSERT_TRUE(found_opus_48hz); | |
| 52 | |
| 53 PASS(); | |
| 54 } | |
| 55 | |
| 56 std::string TestAudioEncoder::TestIncorrectParametersFails() { | |
| 57 // Test that initializing the encoder with incorrect size fails. | |
| 58 pp::AudioEncoder audio_encoder(instance_); | |
| 59 ASSERT_FALSE(audio_encoder.is_null()); | |
| 60 | |
| 61 // Invalid number of channels. | |
| 62 TestCompletionCallback callback(instance_->pp_instance(), false); | |
| 63 callback.WaitForResult(audio_encoder.Initialize( | |
| 64 42, static_cast<PP_AudioBuffer_SampleRate>(48000), | |
|
bbudge
2015/11/18 17:57:57
PP_AUDIOBUFFER_SAMPLERATE_48000
llandwerlin-old
2015/11/18 18:05:26
Done.
| |
| 65 static_cast<PP_AudioBuffer_SampleSize>(2), PP_AUDIOPROFILE_OPUS, 10000, | |
| 66 PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback())); | |
| 67 ASSERT_EQ(PP_ERROR_NOTSUPPORTED, callback.result()); | |
| 68 | |
| 69 // Invalid sampling rate. | |
| 70 callback.WaitForResult(audio_encoder.Initialize( | |
| 71 2, static_cast<PP_AudioBuffer_SampleRate>(123456), | |
| 72 static_cast<PP_AudioBuffer_SampleSize>(2), PP_AUDIOPROFILE_OPUS, 10000, | |
|
bbudge
2015/11/18 17:57:57
PP_AUDIOBUFFER_SAMPLESIZE_16_BITS
llandwerlin-old
2015/11/18 18:05:26
Done.
| |
| 73 PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback())); | |
| 74 ASSERT_EQ(PP_ERROR_NOTSUPPORTED, callback.result()); | |
| 75 | |
| 76 // Invalid sample size. | |
| 77 callback.WaitForResult(audio_encoder.Initialize( | |
| 78 2, static_cast<PP_AudioBuffer_SampleRate>(48000), | |
| 79 static_cast<PP_AudioBuffer_SampleSize>(72), PP_AUDIOPROFILE_OPUS, 10000, | |
| 80 PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback())); | |
| 81 ASSERT_EQ(PP_ERROR_NOTSUPPORTED, callback.result()); | |
| 82 | |
| 83 PASS(); | |
| 84 } | |
| 85 | |
| 86 std::string TestAudioEncoder::TestInitializeTwiceFails() { | |
| 87 // Test that initializing the encoder with incorrect size fails. | |
| 88 pp::AudioEncoder audio_encoder(instance_); | |
| 89 ASSERT_FALSE(audio_encoder.is_null()); | |
| 90 | |
| 91 TestCompletionCallback callback(instance_->pp_instance(), false); | |
| 92 callback.WaitForResult(audio_encoder.Initialize( | |
| 93 2, PP_AUDIOBUFFER_SAMPLERATE_48000, PP_AUDIOBUFFER_SAMPLESIZE_16_BITS, | |
| 94 PP_AUDIOPROFILE_OPUS, 10000, PP_HARDWAREACCELERATION_WITHFALLBACK, | |
| 95 callback.GetCallback())); | |
| 96 ASSERT_EQ(PP_OK, callback.result()); | |
| 97 | |
| 98 callback.WaitForResult(audio_encoder.Initialize( | |
| 99 2, PP_AUDIOBUFFER_SAMPLERATE_48000, PP_AUDIOBUFFER_SAMPLESIZE_16_BITS, | |
| 100 PP_AUDIOPROFILE_OPUS, 10000, PP_HARDWAREACCELERATION_WITHFALLBACK, | |
| 101 callback.GetCallback())); | |
| 102 ASSERT_EQ(PP_ERROR_FAILED, callback.result()); | |
| 103 | |
| 104 PASS(); | |
| 105 } | |
| 106 | |
| 107 std::string TestAudioEncoder::TestInitializeOpusMono() { | |
| 108 return TestInitializeCodec(1, PP_AUDIOBUFFER_SAMPLERATE_48000, | |
| 109 PP_AUDIOBUFFER_SAMPLESIZE_16_BITS, | |
| 110 PP_AUDIOPROFILE_OPUS); | |
| 111 } | |
| 112 | |
| 113 std::string TestAudioEncoder::TestInitializeOpusStereo() { | |
| 114 return TestInitializeCodec(2, PP_AUDIOBUFFER_SAMPLERATE_48000, | |
| 115 PP_AUDIOBUFFER_SAMPLESIZE_16_BITS, | |
| 116 PP_AUDIOPROFILE_OPUS); | |
| 117 } | |
| 118 | |
| 119 std::string TestAudioEncoder::TestInitializeCodec( | |
| 120 uint32_t channels, | |
| 121 PP_AudioBuffer_SampleRate input_sample_rate, | |
| 122 PP_AudioBuffer_SampleSize input_sample_size, | |
| 123 PP_AudioProfile output_profile) { | |
| 124 pp::AudioEncoder audio_encoder(instance_); | |
| 125 ASSERT_FALSE(audio_encoder.is_null()); | |
| 126 pp::Size audio_size(640, 480); | |
| 127 | |
| 128 TestCompletionCallback callback(instance_->pp_instance(), false); | |
| 129 callback.WaitForResult(audio_encoder.Initialize( | |
| 130 channels, input_sample_rate, input_sample_size, output_profile, 10000, | |
| 131 PP_HARDWAREACCELERATION_WITHFALLBACK, callback.GetCallback())); | |
| 132 ASSERT_EQ(PP_OK, callback.result()); | |
| 133 | |
| 134 ASSERT_GE(audio_encoder.GetNumberOfSamples(), 2U); | |
| 135 | |
| 136 TestCompletionCallbackWithOutput<pp::AudioBuffer> get_buffer( | |
| 137 instance_->pp_instance(), false); | |
| 138 get_buffer.WaitForResult(audio_encoder.GetBuffer(get_buffer.GetCallback())); | |
| 139 ASSERT_EQ(PP_OK, get_buffer.result()); | |
| 140 | |
| 141 PASS(); | |
| 142 } | |
| OLD | NEW |