Chromium Code Reviews| Index: webrtc/modules/audio_device/android/audio_manager_unittest.cc |
| diff --git a/webrtc/modules/audio_device/android/audio_manager_unittest.cc b/webrtc/modules/audio_device/android/audio_manager_unittest.cc |
| index 3abfc5a8ceefc122414d538e03279c203c10efb3..960f9d18156d7f3d4596ba47f3e17db794da7ff2 100644 |
| --- a/webrtc/modules/audio_device/android/audio_manager_unittest.cc |
| +++ b/webrtc/modules/audio_device/android/audio_manager_unittest.cc |
| @@ -9,8 +9,10 @@ |
| */ |
| #include <memory> |
| +#include <SLES/OpenSLES_Android.h> |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "webrtc/base/arraysize.h" |
| #include "webrtc/base/format_macros.h" |
| #include "webrtc/modules/audio_device/android/build_info.h" |
| #include "webrtc/modules/audio_device/android/audio_manager.h" |
| @@ -44,6 +46,29 @@ class AudioManagerTest : public ::testing::Test { |
| EXPECT_NE(0, audio_manager()->GetDelayEstimateInMilliseconds()); |
| } |
| + // One way to ensure that the engine object is valid is to create an |
| + // SL Engine interface since it exposes creation methods of all the OpenSL ES |
| + // object types and it is only supported on the engine object. This method |
| + // also verifies that the engine interface supports at least one interface. |
| + // Note that, the test below is not a full test of the SLEngineItf object |
| + // but only a simple sanity test to check that the global engine object is OK. |
| + bool SLEngineIsValid(SLObjectItf engine_object) { |
|
magjed_webrtc
2016/05/31 11:24:07
If you return a bool, you will not know why SLEngi
henrika_webrtc
2016/05/31 12:04:03
Thanks. Used the second approach ;-)
|
| + if (engine_object == nullptr) |
| + return false; |
| + // Get the SL Engine interface which is exposed by the engine object. |
| + SLEngineItf engine; |
| + SLresult result = |
| + (*engine_object)->GetInterface(engine_object, SL_IID_ENGINE, &engine); |
| + if (result != SL_RESULT_SUCCESS) |
| + return false; |
| + // Ensure that the SL Engine interface exposes at least one interface. |
| + SLuint32 object_id = SL_OBJECTID_ENGINE; |
| + SLuint32 num_supported_interfaces = 0; |
| + result = (*engine)->QueryNumSupportedInterfaces(engine, object_id, |
| + &num_supported_interfaces); |
| + return (result == SL_RESULT_SUCCESS && num_supported_interfaces >= 1); |
| + } |
| + |
| std::unique_ptr<AudioManager> audio_manager_; |
| AudioParameters playout_parameters_; |
| AudioParameters record_parameters_; |
| @@ -52,6 +77,32 @@ class AudioManagerTest : public ::testing::Test { |
| TEST_F(AudioManagerTest, ConstructDestruct) { |
| } |
| +// It should not be possible to create an OpenSL engine object if Java based |
| +// audio is requested in both directions. |
| +TEST_F(AudioManagerTest, GetOpenSLEngineShouldFailForJavaAudioLayer) { |
| + audio_manager()->SetActiveAudioLayer(AudioDeviceModule::kAndroidJavaAudio); |
| + SLObjectItf engine_object = audio_manager()->GetOpenSLEngine(); |
| + EXPECT_EQ(nullptr, engine_object); |
| +} |
| + |
| +// It should be possible to create an OpenSL engine object if OpenSL ES based |
| +// audio is requested in any direction. |
| +TEST_F(AudioManagerTest, GetOpenSLEngineShouldSucceedForOpenSLESAudioLayer) { |
| + // List of supported audio layers that uses OpenSL ES audio. |
| + const AudioDeviceModule::AudioLayer opensles_audio[] = { |
| + AudioDeviceModule::kAndroidOpenSLESAudio, |
| + AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio}; |
| + // Verify that the global (singleton) OpenSL Engine can be acquired for all |
| + // audio layes that uses OpenSL ES. Note that the engine is only created once. |
| + for (size_t i = 0; i < arraysize(opensles_audio); ++i) { |
|
magjed_webrtc
2016/05/31 11:24:07
nit: Use for-each loop instead, i.e.
for (const Au
henrika_webrtc
2016/05/31 12:04:03
Thanks, done ;-)
|
| + audio_manager()->SetActiveAudioLayer(opensles_audio[i]); |
| + SLObjectItf engine_object = audio_manager()->GetOpenSLEngine(); |
| + EXPECT_NE(nullptr, engine_object); |
| + // Perform a simple sanity check of the created engine object. |
| + EXPECT_TRUE(SLEngineIsValid(engine_object)); |
| + } |
| +} |
| + |
| TEST_F(AudioManagerTest, InitClose) { |
| EXPECT_TRUE(audio_manager()->Init()); |
| EXPECT_TRUE(audio_manager()->Close()); |