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

Side by Side Diff: webrtc/modules/audio_device/android/audio_manager_unittest.cc

Issue 2019223004: Moves ownership of OpenSL engine object to Android audio manager (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Feedback from magjed@ Created 4 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory> 11 #include <memory>
12 #include <SLES/OpenSLES_Android.h>
12 13
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webrtc/base/arraysize.h"
14 #include "webrtc/base/format_macros.h" 16 #include "webrtc/base/format_macros.h"
15 #include "webrtc/modules/audio_device/android/build_info.h" 17 #include "webrtc/modules/audio_device/android/build_info.h"
16 #include "webrtc/modules/audio_device/android/audio_manager.h" 18 #include "webrtc/modules/audio_device/android/audio_manager.h"
17 #include "webrtc/modules/audio_device/android/ensure_initialized.h" 19 #include "webrtc/modules/audio_device/android/ensure_initialized.h"
18 20
19 #define PRINT(...) fprintf(stderr, __VA_ARGS__); 21 #define PRINT(...) fprintf(stderr, __VA_ARGS__);
20 22
21 namespace webrtc { 23 namespace webrtc {
22 24
23 static const char kTag[] = " "; 25 static const char kTag[] = " ";
(...skipping 13 matching lines...) Expand all
37 AudioManager* audio_manager() const { return audio_manager_.get(); } 39 AudioManager* audio_manager() const { return audio_manager_.get(); }
38 40
39 // A valid audio layer must always be set before calling Init(), hence we 41 // A valid audio layer must always be set before calling Init(), hence we
40 // might as well make it a part of the test fixture. 42 // might as well make it a part of the test fixture.
41 void SetActiveAudioLayer() { 43 void SetActiveAudioLayer() {
42 EXPECT_EQ(0, audio_manager()->GetDelayEstimateInMilliseconds()); 44 EXPECT_EQ(0, audio_manager()->GetDelayEstimateInMilliseconds());
43 audio_manager()->SetActiveAudioLayer(AudioDeviceModule::kAndroidJavaAudio); 45 audio_manager()->SetActiveAudioLayer(AudioDeviceModule::kAndroidJavaAudio);
44 EXPECT_NE(0, audio_manager()->GetDelayEstimateInMilliseconds()); 46 EXPECT_NE(0, audio_manager()->GetDelayEstimateInMilliseconds());
45 } 47 }
46 48
49 // One way to ensure that the engine object is valid is to create an
50 // SL Engine interface since it exposes creation methods of all the OpenSL ES
51 // object types and it is only supported on the engine object. This method
52 // also verifies that the engine interface supports at least one interface.
53 // Note that, the test below is not a full test of the SLEngineItf object
54 // but only a simple sanity test to check that the global engine object is OK.
55 void ValidateSLEngine(SLObjectItf engine_object) {
56 EXPECT_NE(nullptr, engine_object);
57 // Get the SL Engine interface which is exposed by the engine object.
58 SLEngineItf engine;
59 SLresult result =
60 (*engine_object)->GetInterface(engine_object, SL_IID_ENGINE, &engine);
61 EXPECT_EQ(result, SL_RESULT_SUCCESS) << "GetInterface() on engine failed";
62 // Ensure that the SL Engine interface exposes at least one interface.
63 SLuint32 object_id = SL_OBJECTID_ENGINE;
64 SLuint32 num_supported_interfaces = 0;
65 result = (*engine)->QueryNumSupportedInterfaces(engine, object_id,
66 &num_supported_interfaces);
67 EXPECT_EQ(result, SL_RESULT_SUCCESS)
68 << "QueryNumSupportedInterfaces() failed";
69 EXPECT_GE(num_supported_interfaces, 1u);
70 }
71
47 std::unique_ptr<AudioManager> audio_manager_; 72 std::unique_ptr<AudioManager> audio_manager_;
48 AudioParameters playout_parameters_; 73 AudioParameters playout_parameters_;
49 AudioParameters record_parameters_; 74 AudioParameters record_parameters_;
50 }; 75 };
51 76
52 TEST_F(AudioManagerTest, ConstructDestruct) { 77 TEST_F(AudioManagerTest, ConstructDestruct) {
53 } 78 }
54 79
80 // It should not be possible to create an OpenSL engine object if Java based
81 // audio is requested in both directions.
82 TEST_F(AudioManagerTest, GetOpenSLEngineShouldFailForJavaAudioLayer) {
83 audio_manager()->SetActiveAudioLayer(AudioDeviceModule::kAndroidJavaAudio);
84 SLObjectItf engine_object = audio_manager()->GetOpenSLEngine();
85 EXPECT_EQ(nullptr, engine_object);
86 }
87
88 // It should be possible to create an OpenSL engine object if OpenSL ES based
89 // audio is requested in any direction.
90 TEST_F(AudioManagerTest, GetOpenSLEngineShouldSucceedForOpenSLESAudioLayer) {
91 // List of supported audio layers that uses OpenSL ES audio.
92 const AudioDeviceModule::AudioLayer opensles_audio[] = {
93 AudioDeviceModule::kAndroidOpenSLESAudio,
94 AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio};
95 // Verify that the global (singleton) OpenSL Engine can be acquired for all
96 // audio layes that uses OpenSL ES. Note that the engine is only created once.
97 for (const AudioDeviceModule::AudioLayer audio_layer : opensles_audio) {
98 audio_manager()->SetActiveAudioLayer(audio_layer);
99 SLObjectItf engine_object = audio_manager()->GetOpenSLEngine();
100 EXPECT_NE(nullptr, engine_object);
101 // Perform a simple sanity check of the created engine object.
102 ValidateSLEngine(engine_object);
103 }
104 }
105
55 TEST_F(AudioManagerTest, InitClose) { 106 TEST_F(AudioManagerTest, InitClose) {
56 EXPECT_TRUE(audio_manager()->Init()); 107 EXPECT_TRUE(audio_manager()->Init());
57 EXPECT_TRUE(audio_manager()->Close()); 108 EXPECT_TRUE(audio_manager()->Close());
58 } 109 }
59 110
60 TEST_F(AudioManagerTest, IsAcousticEchoCancelerSupported) { 111 TEST_F(AudioManagerTest, IsAcousticEchoCancelerSupported) {
61 PRINT("%sAcoustic Echo Canceler support: %s\n", kTag, 112 PRINT("%sAcoustic Echo Canceler support: %s\n", kTag,
62 audio_manager()->IsAcousticEchoCancelerSupported() ? "Yes" : "No"); 113 audio_manager()->IsAcousticEchoCancelerSupported() ? "Yes" : "No");
63 } 114 }
64 115
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 params.frames_per_10ms_buffer()); 202 params.frames_per_10ms_buffer());
152 EXPECT_EQ(kBytesPerFrame, params.GetBytesPerFrame()); 203 EXPECT_EQ(kBytesPerFrame, params.GetBytesPerFrame());
153 EXPECT_EQ(kBytesPerFrame * kFramesPerBuffer, params.GetBytesPerBuffer()); 204 EXPECT_EQ(kBytesPerFrame * kFramesPerBuffer, params.GetBytesPerBuffer());
154 EXPECT_EQ(kBytesPerFrame * kFramesPer10msBuffer, 205 EXPECT_EQ(kBytesPerFrame * kFramesPer10msBuffer,
155 params.GetBytesPer10msBuffer()); 206 params.GetBytesPer10msBuffer());
156 EXPECT_EQ(kBufferSizeInMs, params.GetBufferSizeInMilliseconds()); 207 EXPECT_EQ(kBufferSizeInMs, params.GetBufferSizeInMilliseconds());
157 } 208 }
158 209
159 } // namespace webrtc 210 } // namespace webrtc
160 211
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/android/audio_manager.cc ('k') | webrtc/modules/audio_device/android/opensles_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698