1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License. 5f6603c60Sopenharmony_ci * You may obtain a copy of the License at 6f6603c60Sopenharmony_ci * 7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f6603c60Sopenharmony_ci * 9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and 13f6603c60Sopenharmony_ci * limitations under the License. 14f6603c60Sopenharmony_ci */ 15f6603c60Sopenharmony_ci 16f6603c60Sopenharmony_ci#include "audio_log.h" 17f6603c60Sopenharmony_ci#include "audio_info.h" 18f6603c60Sopenharmony_ci#include <OpenSLES.h> 19f6603c60Sopenharmony_ci#include <OpenSLES_OpenHarmony.h> 20f6603c60Sopenharmony_ci#include <string> 21f6603c60Sopenharmony_ci#include "gtest/gtest.h" 22f6603c60Sopenharmony_ci 23f6603c60Sopenharmony_ciusing namespace std; 24f6603c60Sopenharmony_ciusing namespace testing::ext; 25f6603c60Sopenharmony_cinamespace { 26f6603c60Sopenharmony_ciclass ActsOpenslesPlayerNdkTest : public testing::Test { 27f6603c60Sopenharmony_cipublic: 28f6603c60Sopenharmony_ci static void SetUpTestCase(); 29f6603c60Sopenharmony_ci static void TearDownTestCase(); 30f6603c60Sopenharmony_ci void SetUp() override; 31f6603c60Sopenharmony_ci void TearDown() override; 32f6603c60Sopenharmony_ci}; 33f6603c60Sopenharmony_ci 34f6603c60Sopenharmony_cistruct WAV_HEADER { 35f6603c60Sopenharmony_ci /* RIFF Chunk Descriptor */ 36f6603c60Sopenharmony_ci uint8_t RIFF[4] = {'R', 'I', 'F', 'F'}; // RIFF Header Magic header 37f6603c60Sopenharmony_ci uint32_t ChunkSize = 0; // RIFF Chunk Size 38f6603c60Sopenharmony_ci uint8_t WAVE[4] = {'W', 'A', 'V', 'E'}; // WAVE Header 39f6603c60Sopenharmony_ci /* "fmt" sub-chunk */ 40f6603c60Sopenharmony_ci uint8_t fmt[4] = {'f', 'm', 't', ' '}; // FMT header 41f6603c60Sopenharmony_ci uint32_t Subchunk1Size = 16; // Size of the fmt chunk 42f6603c60Sopenharmony_ci uint16_t AudioFormat = 1; // Audio format 1=PCM 43f6603c60Sopenharmony_ci uint16_t NumOfChan = 2; // Number of channels 1=Mono 2=Stereo 44f6603c60Sopenharmony_ci uint32_t SamplesPerSec = 44100; // Sampling Frequency in Hz 45f6603c60Sopenharmony_ci uint32_t bytesPerSec = 176400; // bytes per second 46f6603c60Sopenharmony_ci uint16_t blockAlign = 2; // 2=16-bit mono, 4=16-bit stereo 47f6603c60Sopenharmony_ci uint16_t bitsPerSample = 16; // Number of bits per sample 48f6603c60Sopenharmony_ci /* "data" sub-chunk */ 49f6603c60Sopenharmony_ci uint8_t Subchunk2ID[4] = {'d', 'a', 't', 'a'}; // "data" string 50f6603c60Sopenharmony_ci uint32_t Subchunk2Size = 0; // Sampled data length 51f6603c60Sopenharmony_ci}; 52f6603c60Sopenharmony_ci 53f6603c60Sopenharmony_ciusing wav_hdr = struct WAV_HEADER; 54f6603c60Sopenharmony_ci 55f6603c60Sopenharmony_civoid ActsOpenslesPlayerNdkTest::SetUpTestCase() {} 56f6603c60Sopenharmony_civoid ActsOpenslesPlayerNdkTest::TearDownTestCase() {} 57f6603c60Sopenharmony_civoid ActsOpenslesPlayerNdkTest::SetUp() {} 58f6603c60Sopenharmony_civoid ActsOpenslesPlayerNdkTest::TearDown() {} 59f6603c60Sopenharmony_ci 60f6603c60Sopenharmony_cistatic void BuqqerQueueCallback(SLOHBufferQueueItf sBufferQueueItf, void *pContext, SLuint32 size); 61f6603c60Sopenharmony_ci 62f6603c60Sopenharmony_cistatic SLuint32 PlayerStart(SLPlayItf sPlayItf, SLOHBufferQueueItf sBufferQueueItf, FILE *wavFile); 63f6603c60Sopenharmony_ci 64f6603c60Sopenharmony_cistatic SLuint32 PlayerStop(SLPlayItf sPlayItf, SLOHBufferQueueItf sBufferQueueItf); 65f6603c60Sopenharmony_ci 66f6603c60Sopenharmony_cistatic SLresult OpenSlTest(); 67f6603c60Sopenharmony_ci 68f6603c60Sopenharmony_cistatic SLresult OpenSlTestConcurrent(); 69f6603c60Sopenharmony_ci 70f6603c60Sopenharmony_ciconst SLuint32 number = 3; 71f6603c60Sopenharmony_ciconst char* READPATH1 = "/data/audio/S16LE_2_44100.pcm"; 72f6603c60Sopenharmony_ciconst char* READPATH2 = "/data/audio/S16LE_2_64000.pcm"; 73f6603c60Sopenharmony_ciFILE *wavFile_ = nullptr; 74f6603c60Sopenharmony_ciFILE *wavFile1_ = nullptr; 75f6603c60Sopenharmony_ciFILE *wavFile2_ = nullptr; 76f6603c60Sopenharmony_ciwav_hdr wavHeader_; 77f6603c60Sopenharmony_ciwav_hdr wavHeader1_; 78f6603c60Sopenharmony_ciwav_hdr wavHeader2_; 79f6603c60Sopenharmony_ciSLObjectItf engineObject = nullptr; 80f6603c60Sopenharmony_ciSLObjectItf outputMixObject = nullptr; 81f6603c60Sopenharmony_ciSLPlayItf playItf; 82f6603c60Sopenharmony_ciSLPlayItf playItf1; 83f6603c60Sopenharmony_ciSLPlayItf playItf2; 84f6603c60Sopenharmony_ciSLVolumeItf volumeItf1; 85f6603c60Sopenharmony_ciSLVolumeItf volumeItf2; 86f6603c60Sopenharmony_ciSLOHBufferQueueItf bufferQueueItf; 87f6603c60Sopenharmony_ciSLOHBufferQueueItf bufferQueueItf1; 88f6603c60Sopenharmony_ciSLOHBufferQueueItf bufferQueueItf2; 89f6603c60Sopenharmony_ciSLObjectItf pcmPlayerObject = nullptr; 90f6603c60Sopenharmony_ciSLObjectItf pcmPlayerObject1 = nullptr; 91f6603c60Sopenharmony_ciSLObjectItf pcmPlayerObject2 = nullptr; 92f6603c60Sopenharmony_ci 93f6603c60Sopenharmony_cistatic SLresult OpenSlTest() 94f6603c60Sopenharmony_ci{ 95f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest enter"); 96f6603c60Sopenharmony_ci engineObject = nullptr; 97f6603c60Sopenharmony_ci SLEngineItf engineEngine = nullptr; 98f6603c60Sopenharmony_ci SLresult result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr); 99f6603c60Sopenharmony_ci // get engine object 100f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 101f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest slCreateEngine result: %{public}lu", result); 102f6603c60Sopenharmony_ci return result; 103f6603c60Sopenharmony_ci } 104f6603c60Sopenharmony_ci result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); 105f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 106f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest Realize result: %{public}lu", result); 107f6603c60Sopenharmony_ci return result; 108f6603c60Sopenharmony_ci } 109f6603c60Sopenharmony_ci // get engineEngine object 110f6603c60Sopenharmony_ci result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); 111f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 112f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest get engineEngine result: %{public}lu", result); 113f6603c60Sopenharmony_ci return result; 114f6603c60Sopenharmony_ci } 115f6603c60Sopenharmony_ci outputMixObject = nullptr; 116f6603c60Sopenharmony_ci result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, nullptr, nullptr); 117f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 118f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest CreateOutputMix result: %{public}lu", result); 119f6603c60Sopenharmony_ci return result; 120f6603c60Sopenharmony_ci } 121f6603c60Sopenharmony_ci result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); 122f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 123f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest outPut Realize result: %{public}lu", result); 124f6603c60Sopenharmony_ci return result; 125f6603c60Sopenharmony_ci } 126f6603c60Sopenharmony_ci 127f6603c60Sopenharmony_ci SLDataLocator_OutputMix slOutputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject}; 128f6603c60Sopenharmony_ci SLDataSink slSink = {&slOutputMix, nullptr}; 129f6603c60Sopenharmony_ci SLDataLocator_BufferQueue slBufferQueue = { 130f6603c60Sopenharmony_ci SL_DATALOCATOR_BUFFERQUEUE, 131f6603c60Sopenharmony_ci 0 132f6603c60Sopenharmony_ci }; 133f6603c60Sopenharmony_ci SLDataFormat_PCM pcmFormat = { 134f6603c60Sopenharmony_ci SL_DATAFORMAT_PCM, 135f6603c60Sopenharmony_ci wavHeader_.NumOfChan, 136f6603c60Sopenharmony_ci wavHeader_.SamplesPerSec * 1000, 137f6603c60Sopenharmony_ci wavHeader_.bitsPerSample, 138f6603c60Sopenharmony_ci 0, 139f6603c60Sopenharmony_ci 0, 140f6603c60Sopenharmony_ci 0 141f6603c60Sopenharmony_ci }; 142f6603c60Sopenharmony_ci SLDataSource slSource = {&slBufferQueue, &pcmFormat}; 143f6603c60Sopenharmony_ci 144f6603c60Sopenharmony_ci result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject, 145f6603c60Sopenharmony_ci &slSource, &slSink, number, nullptr, nullptr); 146f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 147f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest CreateAudioPlayer result: %{public}lu", result); 148f6603c60Sopenharmony_ci return result; 149f6603c60Sopenharmony_ci } 150f6603c60Sopenharmony_ci result = (*pcmPlayerObject)->Realize(pcmPlayerObject, SL_BOOLEAN_FALSE); 151f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 152f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest CreateAudioPlayer Realize result: %{public}lu", result); 153f6603c60Sopenharmony_ci return result; 154f6603c60Sopenharmony_ci } 155f6603c60Sopenharmony_ci // get bufferQueueItf object 156f6603c60Sopenharmony_ci result = (*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_PLAY, &playItf); 157f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 158f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest get playItf result: %{public}lu", result); 159f6603c60Sopenharmony_ci return result; 160f6603c60Sopenharmony_ci } 161f6603c60Sopenharmony_ci SLVolumeItf volumeItf; 162f6603c60Sopenharmony_ci result = (*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_VOLUME, &volumeItf); 163f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 164f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest get volumeItf result: %{public}lu", result); 165f6603c60Sopenharmony_ci return result; 166f6603c60Sopenharmony_ci } 167f6603c60Sopenharmony_ci SLmillibel pLevel = 0; 168f6603c60Sopenharmony_ci result = (*volumeItf)->GetVolumeLevel(volumeItf, &pLevel); 169f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 170f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest GetVolumeLevel result: %{public}lu", result); 171f6603c60Sopenharmony_ci return result; 172f6603c60Sopenharmony_ci } 173f6603c60Sopenharmony_ci result = (*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf); 174f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 175f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest get bufferQueueItf result: %{public}lu", result); 176f6603c60Sopenharmony_ci return result; 177f6603c60Sopenharmony_ci } 178f6603c60Sopenharmony_ci result = (*bufferQueueItf)->RegisterCallback(bufferQueueItf, BuqqerQueueCallback, wavFile_); 179f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 180f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest RegisterCallback result: %{public}lu", result); 181f6603c60Sopenharmony_ci return result; 182f6603c60Sopenharmony_ci } 183f6603c60Sopenharmony_ci result = PlayerStart(playItf, bufferQueueItf, wavFile_); 184f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 185f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest PlayerStart result: %{public}lu", result); 186f6603c60Sopenharmony_ci return result; 187f6603c60Sopenharmony_ci } 188f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTest return result: %{public}lu", result); 189f6603c60Sopenharmony_ci return result; 190f6603c60Sopenharmony_ci} 191f6603c60Sopenharmony_ci 192f6603c60Sopenharmony_cistatic SLresult OpenSlTestConcurrent() 193f6603c60Sopenharmony_ci{ 194f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent start"); 195f6603c60Sopenharmony_ci engineObject = nullptr; 196f6603c60Sopenharmony_ci SLEngineItf engineEngine = nullptr; 197f6603c60Sopenharmony_ci SLresult result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr); 198f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 199f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent slCreateEngine result: %{public}lu", result); 200f6603c60Sopenharmony_ci return result; 201f6603c60Sopenharmony_ci } 202f6603c60Sopenharmony_ci result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); 203f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 204f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent Realize result: %{public}lu", result); 205f6603c60Sopenharmony_ci return result; 206f6603c60Sopenharmony_ci } 207f6603c60Sopenharmony_ci 208f6603c60Sopenharmony_ci result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); 209f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 210f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent get engineEngine result: %{public}lu", result); 211f6603c60Sopenharmony_ci return result; 212f6603c60Sopenharmony_ci } 213f6603c60Sopenharmony_ci 214f6603c60Sopenharmony_ci outputMixObject = nullptr; 215f6603c60Sopenharmony_ci result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, nullptr, nullptr); 216f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 217f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent CreateOutputMix result: %{public}lu", result); 218f6603c60Sopenharmony_ci return result; 219f6603c60Sopenharmony_ci } 220f6603c60Sopenharmony_ci result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); 221f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 222f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent outPut Realize result: %{public}lu", result); 223f6603c60Sopenharmony_ci return result; 224f6603c60Sopenharmony_ci } 225f6603c60Sopenharmony_ci SLuint32 state; 226f6603c60Sopenharmony_ci result = (*outputMixObject)->GetState(outputMixObject, &state); 227f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 228f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent outPut GetState result: %{public}lu", result); 229f6603c60Sopenharmony_ci return result; 230f6603c60Sopenharmony_ci } 231f6603c60Sopenharmony_ci 232f6603c60Sopenharmony_ci SLDataLocator_OutputMix slOutputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject}; 233f6603c60Sopenharmony_ci SLDataSink slSink = {&slOutputMix, nullptr}; 234f6603c60Sopenharmony_ci SLDataLocator_BufferQueue slBufferQueue = { 235f6603c60Sopenharmony_ci SL_DATALOCATOR_BUFFERQUEUE, 236f6603c60Sopenharmony_ci 0 237f6603c60Sopenharmony_ci }; 238f6603c60Sopenharmony_ci SLDataFormat_PCM pcmFormat1 = { 239f6603c60Sopenharmony_ci SL_DATAFORMAT_PCM, 240f6603c60Sopenharmony_ci wavHeader1_.NumOfChan, 241f6603c60Sopenharmony_ci wavHeader1_.SamplesPerSec * 1000, 242f6603c60Sopenharmony_ci wavHeader1_.bitsPerSample, 243f6603c60Sopenharmony_ci 0, 244f6603c60Sopenharmony_ci 0, 245f6603c60Sopenharmony_ci 0 246f6603c60Sopenharmony_ci }; 247f6603c60Sopenharmony_ci SLDataFormat_PCM pcmFormat2 = { 248f6603c60Sopenharmony_ci SL_DATAFORMAT_PCM, 249f6603c60Sopenharmony_ci wavHeader2_.NumOfChan, 250f6603c60Sopenharmony_ci wavHeader2_.SamplesPerSec * 1000, 251f6603c60Sopenharmony_ci wavHeader2_.bitsPerSample, 252f6603c60Sopenharmony_ci 0, 253f6603c60Sopenharmony_ci 0, 254f6603c60Sopenharmony_ci 0 255f6603c60Sopenharmony_ci }; 256f6603c60Sopenharmony_ci SLDataSource slSource1 = {&slBufferQueue, &pcmFormat1}; 257f6603c60Sopenharmony_ci SLDataSource slSource2 = {&slBufferQueue, &pcmFormat2}; 258f6603c60Sopenharmony_ci 259f6603c60Sopenharmony_ci result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject1, &slSource1, 260f6603c60Sopenharmony_ci &slSink, number, nullptr, nullptr); 261f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 262f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent CreateAudioPlayer pcmPlayerObject1 Realize result: %{public}lu", result); 263f6603c60Sopenharmony_ci return result; 264f6603c60Sopenharmony_ci } 265f6603c60Sopenharmony_ci result = (*pcmPlayerObject1)->Realize(pcmPlayerObject1, SL_BOOLEAN_FALSE); 266f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 267f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent outPut Realize pcmPlayerObject1 result: %{public}lu", result); 268f6603c60Sopenharmony_ci return result; 269f6603c60Sopenharmony_ci } 270f6603c60Sopenharmony_ci 271f6603c60Sopenharmony_ci result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject2, &slSource2, &slSink, 272f6603c60Sopenharmony_ci number, nullptr, nullptr); 273f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 274f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent CreateAudioPlayer pcmPlayerObject2 result: %{public}lu", result); 275f6603c60Sopenharmony_ci return result; 276f6603c60Sopenharmony_ci } 277f6603c60Sopenharmony_ci result = (*pcmPlayerObject2)->Realize(pcmPlayerObject2, SL_BOOLEAN_FALSE); 278f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 279f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent Realize pcmPlayerObject2 result: %{public}lu", result); 280f6603c60Sopenharmony_ci return result; 281f6603c60Sopenharmony_ci } 282f6603c60Sopenharmony_ci 283f6603c60Sopenharmony_ci result = (*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_PLAY, &playItf1); 284f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 285f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent playItf1 result: %{public}lu", result); 286f6603c60Sopenharmony_ci return result; 287f6603c60Sopenharmony_ci } 288f6603c60Sopenharmony_ci result = (*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_PLAY, &playItf2); 289f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 290f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent playItf2 result: %{public}lu", result); 291f6603c60Sopenharmony_ci return result; 292f6603c60Sopenharmony_ci } 293f6603c60Sopenharmony_ci result = (*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_VOLUME, &volumeItf1); 294f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 295f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent volumeItf1 result: %{public}lu", result); 296f6603c60Sopenharmony_ci return result; 297f6603c60Sopenharmony_ci } 298f6603c60Sopenharmony_ci 299f6603c60Sopenharmony_ci SLmillibel level1 = 0; 300f6603c60Sopenharmony_ci (*volumeItf1)->GetMaxVolumeLevel(volumeItf1, &level1); 301f6603c60Sopenharmony_ci SLmillibel temp = 2; // SetVolumeLevel level1 302f6603c60Sopenharmony_ci level1 = (SLmillibel) (level1 / temp); 303f6603c60Sopenharmony_ci (*volumeItf1)->SetVolumeLevel(volumeItf1, level1); 304f6603c60Sopenharmony_ci (*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_VOLUME, &volumeItf2); 305f6603c60Sopenharmony_ci SLmillibel level2 = 0; 306f6603c60Sopenharmony_ci (*volumeItf2)->GetMaxVolumeLevel(volumeItf2, &level2); 307f6603c60Sopenharmony_ci temp = 15; // SetVolumeLevel level2 308f6603c60Sopenharmony_ci level2 = (SLmillibel) (level2 / temp); 309f6603c60Sopenharmony_ci (*volumeItf2)->SetVolumeLevel(volumeItf2, level2); 310f6603c60Sopenharmony_ci 311f6603c60Sopenharmony_ci result = (*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf1); 312f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 313f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent bufferQueueItf1 result: %{public}lu", result); 314f6603c60Sopenharmony_ci return result; 315f6603c60Sopenharmony_ci } 316f6603c60Sopenharmony_ci result = (*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf2); 317f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 318f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent bufferQueueItf2 result: %{public}lu", result); 319f6603c60Sopenharmony_ci return result; 320f6603c60Sopenharmony_ci } 321f6603c60Sopenharmony_ci result = (*bufferQueueItf1)->RegisterCallback(bufferQueueItf1, BuqqerQueueCallback, wavFile1_); 322f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 323f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent RegisterCallback1 result: %{public}lu", result); 324f6603c60Sopenharmony_ci return result; 325f6603c60Sopenharmony_ci } 326f6603c60Sopenharmony_ci result = (*bufferQueueItf2)->RegisterCallback(bufferQueueItf2, BuqqerQueueCallback, wavFile2_); 327f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 328f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent RegisterCallback2 result: %{public}lu", result); 329f6603c60Sopenharmony_ci return result; 330f6603c60Sopenharmony_ci } 331f6603c60Sopenharmony_ci result = PlayerStart(playItf1, bufferQueueItf1, wavFile1_); 332f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 333f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent playItf1 PlayerStart result: %{public}lu", result); 334f6603c60Sopenharmony_ci return result; 335f6603c60Sopenharmony_ci } 336f6603c60Sopenharmony_ci result = PlayerStart(playItf2, bufferQueueItf2, wavFile2_); 337f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 338f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent playItf2 PlayerStart result: %{public}lu", result); 339f6603c60Sopenharmony_ci return result; 340f6603c60Sopenharmony_ci } 341f6603c60Sopenharmony_ci AUDIO_INFO_LOG("OpenSlTestConcurrent return result: %{public}lu", result); 342f6603c60Sopenharmony_ci return result; 343f6603c60Sopenharmony_ci} 344f6603c60Sopenharmony_ci 345f6603c60Sopenharmony_cistatic void BuqqerQueueCallback(SLOHBufferQueueItf sBufferQueueItf, void *pContext, SLuint32 size) 346f6603c60Sopenharmony_ci{ 347f6603c60Sopenharmony_ci FILE *wavFile = (FILE *)pContext; 348f6603c60Sopenharmony_ci if (!feof(wavFile)) { 349f6603c60Sopenharmony_ci SLuint8 *buffer = nullptr; 350f6603c60Sopenharmony_ci SLuint32 pSize = 0; 351f6603c60Sopenharmony_ci SLresult result = (*bufferQueueItf)->GetBuffer(sBufferQueueItf, &buffer, &pSize); 352f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 353f6603c60Sopenharmony_ci AUDIO_INFO_LOG("BuqqerQueueCallback GetBuffer result: %{public}lu", result); 354f6603c60Sopenharmony_ci return ; 355f6603c60Sopenharmony_ci } 356f6603c60Sopenharmony_ci fread(buffer, 1, size, wavFile); 357f6603c60Sopenharmony_ci result = (*bufferQueueItf)->Enqueue(sBufferQueueItf, buffer, size); 358f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 359f6603c60Sopenharmony_ci AUDIO_INFO_LOG("BuqqerQueueCallback Enqueue result: %{public}lu", result); 360f6603c60Sopenharmony_ci return ; 361f6603c60Sopenharmony_ci } 362f6603c60Sopenharmony_ci } 363f6603c60Sopenharmony_ci return ; 364f6603c60Sopenharmony_ci} 365f6603c60Sopenharmony_ci 366f6603c60Sopenharmony_cistatic SLresult PlayerStart(SLPlayItf sPlayItf, SLOHBufferQueueItf sBufferQueueItf, FILE *wavFile) 367f6603c60Sopenharmony_ci{ 368f6603c60Sopenharmony_ci AUDIO_INFO_LOG("PlayerStart enter"); 369f6603c60Sopenharmony_ci SLresult result = (*playItf)->SetPlayState(sPlayItf, SL_PLAYSTATE_PLAYING); 370f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 371f6603c60Sopenharmony_ci AUDIO_INFO_LOG("PlayerStart SetPlayState result: %{public}lu", result); 372f6603c60Sopenharmony_ci return result; 373f6603c60Sopenharmony_ci } 374f6603c60Sopenharmony_ci SLuint32 state = SL_PLAYSTATE_PLAYING; 375f6603c60Sopenharmony_ci result = (*playItf)->GetPlayState(sPlayItf, &state); 376f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 377f6603c60Sopenharmony_ci AUDIO_INFO_LOG("PlayerStart GetPlayState result: %{public}lu", result); 378f6603c60Sopenharmony_ci return result; 379f6603c60Sopenharmony_ci } 380f6603c60Sopenharmony_ci if (!feof(wavFile)) { 381f6603c60Sopenharmony_ci SLuint8* buffer = nullptr; 382f6603c60Sopenharmony_ci SLuint32 pSize = 0; 383f6603c60Sopenharmony_ci result = (*bufferQueueItf)->GetBuffer(sBufferQueueItf, &buffer, &pSize); 384f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 385f6603c60Sopenharmony_ci AUDIO_INFO_LOG("PlayerStart GetBuffer result: %{public}lu", result); 386f6603c60Sopenharmony_ci return result; 387f6603c60Sopenharmony_ci } 388f6603c60Sopenharmony_ci fread(buffer, 1, pSize, wavFile); 389f6603c60Sopenharmony_ci result = (*bufferQueueItf)->Enqueue(sBufferQueueItf, buffer, pSize); 390f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 391f6603c60Sopenharmony_ci AUDIO_INFO_LOG("PlayerStart Enqueue result: %{public}lu", result); 392f6603c60Sopenharmony_ci return result; 393f6603c60Sopenharmony_ci } 394f6603c60Sopenharmony_ci } 395f6603c60Sopenharmony_ci AUDIO_INFO_LOG("PlayerStart return result: %{public}lu", result); 396f6603c60Sopenharmony_ci return result; 397f6603c60Sopenharmony_ci} 398f6603c60Sopenharmony_ci 399f6603c60Sopenharmony_cistatic SLresult PlayerStop(SLPlayItf sPlayItf, SLOHBufferQueueItf sBufferQueueItf) 400f6603c60Sopenharmony_ci{ 401f6603c60Sopenharmony_ci AUDIO_INFO_LOG("PlayerStop enetr"); 402f6603c60Sopenharmony_ci 403f6603c60Sopenharmony_ci SLresult result = (*playItf)->SetPlayState(sPlayItf, SL_PLAYSTATE_STOPPED); 404f6603c60Sopenharmony_ci if (SL_RESULT_SUCCESS != result) { 405f6603c60Sopenharmony_ci AUDIO_INFO_LOG("PlayerStop SetPlayState result: %{public}lu", result); 406f6603c60Sopenharmony_ci return result; 407f6603c60Sopenharmony_ci } 408f6603c60Sopenharmony_ci AUDIO_INFO_LOG("PlayerStop return result: %{public}lu", result); 409f6603c60Sopenharmony_ci return result; 410f6603c60Sopenharmony_ci} 411f6603c60Sopenharmony_ci} 412f6603c60Sopenharmony_ci 413f6603c60Sopenharmony_ci/** 414f6603c60Sopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_OPENSELES_PALYER_FUNCTION_0100 415f6603c60Sopenharmony_ci * @tc.name : Pcm gemischte Wiedergabe 416f6603c60Sopenharmony_ci * @tc.desc : Basic function test 417f6603c60Sopenharmony_ci */ 418f6603c60Sopenharmony_ciHWTEST_F(ActsOpenslesPlayerNdkTest, SUB_MULTIMEDIA_AUDIO_OPENSELES_PALYER_FUNCTION_0100, TestSize.Level1) 419f6603c60Sopenharmony_ci{ 420f6603c60Sopenharmony_ci size_t headerSize = sizeof(wav_hdr); 421f6603c60Sopenharmony_ci char path[PATH_MAX + 1] = {0x00}; 422f6603c60Sopenharmony_ci if ((strlen(READPATH1) > PATH_MAX) || (realpath(READPATH1, path) == nullptr)) { 423f6603c60Sopenharmony_ci AUDIO_ERR_LOG("Invalid path"); 424f6603c60Sopenharmony_ci return ; 425f6603c60Sopenharmony_ci } 426f6603c60Sopenharmony_ci wavFile1_ = fopen(path, "rb"); 427f6603c60Sopenharmony_ci if (wavFile1_ == nullptr) { 428f6603c60Sopenharmony_ci AUDIO_INFO_LOG("AudioRendererTest: Unable to open wave file"); 429f6603c60Sopenharmony_ci return ; 430f6603c60Sopenharmony_ci } 431f6603c60Sopenharmony_ci fread(&wavHeader1_, 1, headerSize, wavFile1_); 432f6603c60Sopenharmony_ci 433f6603c60Sopenharmony_ci headerSize = sizeof(wav_hdr); 434f6603c60Sopenharmony_ci if ((strlen(READPATH2) > PATH_MAX) || (realpath(READPATH2, path) == nullptr)) { 435f6603c60Sopenharmony_ci AUDIO_ERR_LOG("Invalid path"); 436f6603c60Sopenharmony_ci return ; 437f6603c60Sopenharmony_ci } 438f6603c60Sopenharmony_ci wavFile2_ = fopen(path, "rb"); 439f6603c60Sopenharmony_ci if (wavFile2_ == nullptr) { 440f6603c60Sopenharmony_ci AUDIO_INFO_LOG("AudioRendererTest: Unable to open wave file"); 441f6603c60Sopenharmony_ci return ; 442f6603c60Sopenharmony_ci } 443f6603c60Sopenharmony_ci fread(&wavHeader2_, 1, headerSize, wavFile2_); 444f6603c60Sopenharmony_ci SLresult result = OpenSlTestConcurrent(); 445f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 446f6603c60Sopenharmony_ci while (!feof(wavFile1_) || !feof(wavFile2_)) { 447f6603c60Sopenharmony_ci sleep(1); 448f6603c60Sopenharmony_ci } 449f6603c60Sopenharmony_ci result = PlayerStop(playItf1, bufferQueueItf1); 450f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 451f6603c60Sopenharmony_ci 452f6603c60Sopenharmony_ci result = PlayerStop(playItf2, bufferQueueItf2); 453f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 454f6603c60Sopenharmony_ci (*pcmPlayerObject1)->Destroy(pcmPlayerObject1); 455f6603c60Sopenharmony_ci (*pcmPlayerObject2)->Destroy(pcmPlayerObject2); 456f6603c60Sopenharmony_ci (*engineObject)->Destroy(engineObject); 457f6603c60Sopenharmony_ci (*outputMixObject)->Destroy(outputMixObject); 458f6603c60Sopenharmony_ci} 459f6603c60Sopenharmony_ci 460f6603c60Sopenharmony_ci/** 461f6603c60Sopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_OPENSELES_PALYER_FUNCTION_0200 462f6603c60Sopenharmony_ci * @tc.name : Pcm spielt weiter 463f6603c60Sopenharmony_ci * @tc.desc : Basic function test 464f6603c60Sopenharmony_ci */ 465f6603c60Sopenharmony_ciHWTEST_F(ActsOpenslesPlayerNdkTest, SUB_MULTIMEDIA_AUDIO_OPENSELES_PALYER_FUNCTION_0200, TestSize.Level1) 466f6603c60Sopenharmony_ci{ 467f6603c60Sopenharmony_ci size_t headerSize = sizeof(wav_hdr); 468f6603c60Sopenharmony_ci char path[PATH_MAX + 1] = {0x00}; 469f6603c60Sopenharmony_ci if ((strlen(READPATH1) > PATH_MAX) || (realpath(READPATH1, path) == nullptr)) { 470f6603c60Sopenharmony_ci AUDIO_ERR_LOG("Invalid path"); 471f6603c60Sopenharmony_ci return ; 472f6603c60Sopenharmony_ci } 473f6603c60Sopenharmony_ci wavFile_ = fopen(path, "rb"); 474f6603c60Sopenharmony_ci if (wavFile_ == nullptr) { 475f6603c60Sopenharmony_ci AUDIO_INFO_LOG("AudioRendererTest: Unable to open wave file"); 476f6603c60Sopenharmony_ci return ; 477f6603c60Sopenharmony_ci } 478f6603c60Sopenharmony_ci fread(&wavHeader_, 1, headerSize, wavFile_); 479f6603c60Sopenharmony_ci 480f6603c60Sopenharmony_ci SLresult result = OpenSlTest(); 481f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 482f6603c60Sopenharmony_ci 483f6603c60Sopenharmony_ci while (!feof(wavFile_)) { 484f6603c60Sopenharmony_ci sleep(1); 485f6603c60Sopenharmony_ci } 486f6603c60Sopenharmony_ci result = PlayerStop(playItf, bufferQueueItf); 487f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 488f6603c60Sopenharmony_ci (*pcmPlayerObject)->Destroy(pcmPlayerObject); 489f6603c60Sopenharmony_ci 490f6603c60Sopenharmony_ci char path2[PATH_MAX + 1] = {0x00}; 491f6603c60Sopenharmony_ci if ((strlen(READPATH2) > PATH_MAX) || (realpath(READPATH2, path2) == nullptr)) { 492f6603c60Sopenharmony_ci AUDIO_ERR_LOG("Invalid path"); 493f6603c60Sopenharmony_ci return ; 494f6603c60Sopenharmony_ci } 495f6603c60Sopenharmony_ci wavFile_ = fopen(path2, "rb"); 496f6603c60Sopenharmony_ci if (wavFile_ == nullptr) { 497f6603c60Sopenharmony_ci AUDIO_INFO_LOG("AudioRendererTest: Unable to open wave file"); 498f6603c60Sopenharmony_ci return ; 499f6603c60Sopenharmony_ci } 500f6603c60Sopenharmony_ci fread(&wavHeader_, 1, headerSize, wavFile_); 501f6603c60Sopenharmony_ci 502f6603c60Sopenharmony_ci result = OpenSlTest(); 503f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 504f6603c60Sopenharmony_ci 505f6603c60Sopenharmony_ci while (!feof(wavFile_)) { 506f6603c60Sopenharmony_ci sleep(1); 507f6603c60Sopenharmony_ci } 508f6603c60Sopenharmony_ci result = PlayerStop(playItf, bufferQueueItf); 509f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 510f6603c60Sopenharmony_ci (*pcmPlayerObject)->Destroy(pcmPlayerObject); 511f6603c60Sopenharmony_ci} 512f6603c60Sopenharmony_ci 513f6603c60Sopenharmony_ci/** 514f6603c60Sopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_OPENSELES_ENGINEITF_INVALID_0100 515f6603c60Sopenharmony_ci * @tc.name : engine itf invalid 516f6603c60Sopenharmony_ci * @tc.desc : Basic function test 517f6603c60Sopenharmony_ci */ 518f6603c60Sopenharmony_ciHWTEST_F(ActsOpenslesPlayerNdkTest, SUB_MULTIMEDIA_AUDIO_OPENSELES_ENGINEITF_INVALID_0100, TestSize.Level1) 519f6603c60Sopenharmony_ci{ 520f6603c60Sopenharmony_ci SLEngineItf engineEngine = nullptr; 521f6603c60Sopenharmony_ci engineObject = nullptr; 522f6603c60Sopenharmony_ci SLresult result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr); 523f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 524f6603c60Sopenharmony_ci 525f6603c60Sopenharmony_ci result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); 526f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 527f6603c60Sopenharmony_ci 528f6603c60Sopenharmony_ci SLresult result1 = (*engineEngine)->CreateLEDDevice(engineEngine, nullptr, 0, 0, nullptr, nullptr); 529f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result1); 530f6603c60Sopenharmony_ci 531f6603c60Sopenharmony_ci SLresult result2 = (*engineEngine)->CreateVibraDevice(engineEngine, nullptr, 0, 0, nullptr, nullptr); 532f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result2); 533f6603c60Sopenharmony_ci 534f6603c60Sopenharmony_ci SLresult result4 = (*engineEngine)->CreateListener(engineEngine, nullptr, 0, nullptr, nullptr); 535f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result4); 536f6603c60Sopenharmony_ci 537f6603c60Sopenharmony_ci SLresult result5 = (*engineEngine)->Create3DGroup(engineEngine, nullptr, 0, nullptr, nullptr); 538f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result5); 539f6603c60Sopenharmony_ci 540f6603c60Sopenharmony_ci SLresult result6 = (*engineEngine)->CreateMetadataExtractor(engineEngine, nullptr, nullptr, 0, nullptr, nullptr); 541f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result6); 542f6603c60Sopenharmony_ci 543f6603c60Sopenharmony_ci SLresult result7 = (*engineEngine)->CreateExtensionObject(engineEngine, nullptr, nullptr, 0, 544f6603c60Sopenharmony_ci 0, nullptr, nullptr); 545f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result7); 546f6603c60Sopenharmony_ci 547f6603c60Sopenharmony_ci SLresult result8 = (*engineEngine)->QueryNumSupportedInterfaces(engineEngine, 0, nullptr); 548f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result8); 549f6603c60Sopenharmony_ci 550f6603c60Sopenharmony_ci SLresult result9 = (*engineEngine)->QuerySupportedInterfaces(engineEngine, 0, 0, nullptr); 551f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result9); 552f6603c60Sopenharmony_ci 553f6603c60Sopenharmony_ci SLresult result10 = (*engineEngine)->QueryNumSupportedExtensions(engineEngine, nullptr); 554f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result10); 555f6603c60Sopenharmony_ci 556f6603c60Sopenharmony_ci SLresult result11 = (*engineEngine)->QuerySupportedExtension(engineEngine, 0, nullptr, nullptr); 557f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result11); 558f6603c60Sopenharmony_ci 559f6603c60Sopenharmony_ci SLresult result12 = (*engineEngine)->IsExtensionSupported(engineEngine, nullptr, nullptr); 560f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result12); 561f6603c60Sopenharmony_ci} 562f6603c60Sopenharmony_ci 563f6603c60Sopenharmony_ci/** 564f6603c60Sopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_OPENSELES_ENGINEITF_INVALID_0200 565f6603c60Sopenharmony_ci * @tc.name : engine itf invalid 566f6603c60Sopenharmony_ci * @tc.desc : Basic function test 567f6603c60Sopenharmony_ci */ 568f6603c60Sopenharmony_ciHWTEST_F(ActsOpenslesPlayerNdkTest, SUB_MULTIMEDIA_AUDIO_OPENSELES_ENGINEITF_INVALID_0200, TestSize.Level1) 569f6603c60Sopenharmony_ci{ 570f6603c60Sopenharmony_ci SLObjectItf engineObject_; 571f6603c60Sopenharmony_ci SLresult result = slCreateEngine(&engineObject_, 0, nullptr, 0, nullptr, nullptr); 572f6603c60Sopenharmony_ci EXPECT_TRUE(result == SL_RESULT_SUCCESS); 573f6603c60Sopenharmony_ci 574f6603c60Sopenharmony_ci SLresult result1 = (*engineObject_)->RegisterCallback(engineObject_, nullptr, nullptr); 575f6603c60Sopenharmony_ci EXPECT_TRUE(result1 == SL_RESULT_FEATURE_UNSUPPORTED); 576f6603c60Sopenharmony_ci 577f6603c60Sopenharmony_ci (*engineObject_)->AbortAsyncOperation(engineObject_); 578f6603c60Sopenharmony_ci 579f6603c60Sopenharmony_ci SLresult result2 = (*engineObject_)->SetPriority(engineObject_, 0, SL_BOOLEAN_FALSE); 580f6603c60Sopenharmony_ci EXPECT_TRUE(result2 == SL_RESULT_FEATURE_UNSUPPORTED); 581f6603c60Sopenharmony_ci 582f6603c60Sopenharmony_ci SLresult result3 = (*engineObject_)->GetPriority(engineObject_, nullptr, nullptr); 583f6603c60Sopenharmony_ci EXPECT_TRUE(result3 == SL_RESULT_FEATURE_UNSUPPORTED); 584f6603c60Sopenharmony_ci 585f6603c60Sopenharmony_ci SLresult result4 = (*engineObject_)->SetLossOfControlInterfaces(engineObject_, 0, nullptr, false); 586f6603c60Sopenharmony_ci EXPECT_TRUE(result4 == SL_RESULT_FEATURE_UNSUPPORTED); 587f6603c60Sopenharmony_ci} 588f6603c60Sopenharmony_ci 589f6603c60Sopenharmony_ci/** 590f6603c60Sopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_OPENSELES_ENGINEITF_INVALID_0300 591f6603c60Sopenharmony_ci * @tc.name : engine itf invalid 592f6603c60Sopenharmony_ci * @tc.desc : Basic function test 593f6603c60Sopenharmony_ci */ 594f6603c60Sopenharmony_ciHWTEST_F(ActsOpenslesPlayerNdkTest, SUB_MULTIMEDIA_AUDIO_OPENSELES_ENGINEITF_INVALID_0300, TestSize.Level1) 595f6603c60Sopenharmony_ci{ 596f6603c60Sopenharmony_ci // get engineObject 597f6603c60Sopenharmony_ci engineObject = nullptr; 598f6603c60Sopenharmony_ci SLresult result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr); 599f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 600f6603c60Sopenharmony_ci 601f6603c60Sopenharmony_ci // get engineEngine 602f6603c60Sopenharmony_ci SLEngineItf engineEngine = nullptr; 603f6603c60Sopenharmony_ci result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); 604f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 605f6603c60Sopenharmony_ci 606f6603c60Sopenharmony_ci // get pcmPlayerObject 607f6603c60Sopenharmony_ci pcmPlayerObject = nullptr; 608f6603c60Sopenharmony_ci SLDataLocator_OutputMix slOutputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject}; 609f6603c60Sopenharmony_ci SLDataSink slSink = {&slOutputMix, nullptr}; 610f6603c60Sopenharmony_ci SLDataLocator_BufferQueue slBufferQueue = { 611f6603c60Sopenharmony_ci SL_DATALOCATOR_BUFFERQUEUE, 612f6603c60Sopenharmony_ci 0}; 613f6603c60Sopenharmony_ci SLDataFormat_PCM pcmFormat = { 614f6603c60Sopenharmony_ci SL_DATAFORMAT_PCM, 615f6603c60Sopenharmony_ci wavHeader_.NumOfChan, 616f6603c60Sopenharmony_ci wavHeader_.SamplesPerSec * 1000, 617f6603c60Sopenharmony_ci wavHeader_.bitsPerSample, 618f6603c60Sopenharmony_ci 0, 619f6603c60Sopenharmony_ci 0, 620f6603c60Sopenharmony_ci 0}; 621f6603c60Sopenharmony_ci SLDataSource slSource = {&slBufferQueue, &pcmFormat}; 622f6603c60Sopenharmony_ci result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject, &slSource, &slSink, 623f6603c60Sopenharmony_ci number, nullptr, nullptr); 624f6603c60Sopenharmony_ci EXPECT_TRUE(result == SL_RESULT_SUCCESS); 625f6603c60Sopenharmony_ci 626f6603c60Sopenharmony_ci // get playItf 627f6603c60Sopenharmony_ci playItf = nullptr; 628f6603c60Sopenharmony_ci result = (*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_PLAY, &playItf); 629f6603c60Sopenharmony_ci EXPECT_TRUE(result == SL_RESULT_SUCCESS); 630f6603c60Sopenharmony_ci 631f6603c60Sopenharmony_ci SLresult result1 = (*playItf)->GetDuration(playItf, nullptr); 632f6603c60Sopenharmony_ci EXPECT_TRUE(result1 == SL_RESULT_FEATURE_UNSUPPORTED); 633f6603c60Sopenharmony_ci 634f6603c60Sopenharmony_ci SLresult result2 = (*playItf)->GetPositionUpdatePeriod(playItf, nullptr); 635f6603c60Sopenharmony_ci EXPECT_TRUE(result2 == SL_RESULT_FEATURE_UNSUPPORTED); 636f6603c60Sopenharmony_ci 637f6603c60Sopenharmony_ci SLresult result3 = (*playItf)->RegisterCallback(playItf, nullptr, nullptr); 638f6603c60Sopenharmony_ci EXPECT_TRUE(result3 == SL_RESULT_FEATURE_UNSUPPORTED); 639f6603c60Sopenharmony_ci 640f6603c60Sopenharmony_ci SLresult result4 = (*playItf)->SetCallbackEventsMask(playItf, 0); 641f6603c60Sopenharmony_ci EXPECT_TRUE(result4 == SL_RESULT_FEATURE_UNSUPPORTED); 642f6603c60Sopenharmony_ci 643f6603c60Sopenharmony_ci SLresult result5 = (*playItf)->GetCallbackEventsMask(playItf, 0); 644f6603c60Sopenharmony_ci EXPECT_TRUE(result5 == SL_RESULT_FEATURE_UNSUPPORTED); 645f6603c60Sopenharmony_ci 646f6603c60Sopenharmony_ci SLresult result6 = (*playItf)->SetMarkerPosition(playItf, 0); 647f6603c60Sopenharmony_ci EXPECT_TRUE(result6 == SL_RESULT_FEATURE_UNSUPPORTED); 648f6603c60Sopenharmony_ci 649f6603c60Sopenharmony_ci SLresult result7 = (*playItf)->GetMarkerPosition(playItf, nullptr); 650f6603c60Sopenharmony_ci EXPECT_TRUE(result7 == SL_RESULT_FEATURE_UNSUPPORTED); 651f6603c60Sopenharmony_ci 652f6603c60Sopenharmony_ci SLresult result8 = (*playItf)->SetPositionUpdatePeriod(playItf, 0); 653f6603c60Sopenharmony_ci EXPECT_TRUE(result8 == SL_RESULT_FEATURE_UNSUPPORTED); 654f6603c60Sopenharmony_ci 655f6603c60Sopenharmony_ci SLresult result9 = (*playItf)->ClearMarkerPosition(playItf); 656f6603c60Sopenharmony_ci EXPECT_TRUE(result9 == SL_RESULT_FEATURE_UNSUPPORTED); 657f6603c60Sopenharmony_ci 658f6603c60Sopenharmony_ci SLresult result10 = (*playItf)->GetPosition(playItf, nullptr); 659f6603c60Sopenharmony_ci EXPECT_TRUE(result10 == SL_RESULT_FEATURE_UNSUPPORTED); 660f6603c60Sopenharmony_ci} 661f6603c60Sopenharmony_ci 662f6603c60Sopenharmony_ci/** 663f6603c60Sopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_OPENSELES_ENGINEITF_INVALID_0400 664f6603c60Sopenharmony_ci * @tc.name : engine itf invalid 665f6603c60Sopenharmony_ci * @tc.desc : Basic function test 666f6603c60Sopenharmony_ci */ 667f6603c60Sopenharmony_ciHWTEST_F(ActsOpenslesPlayerNdkTest, SUB_MULTIMEDIA_AUDIO_OPENSELES_ENGINEITF_INVALID_0400, TestSize.Level1) 668f6603c60Sopenharmony_ci{ 669f6603c60Sopenharmony_ci // get engineObject 670f6603c60Sopenharmony_ci engineObject = nullptr; 671f6603c60Sopenharmony_ci SLresult result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr); 672f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 673f6603c60Sopenharmony_ci 674f6603c60Sopenharmony_ci // get engineEngine 675f6603c60Sopenharmony_ci SLEngineItf engineEngine = nullptr; 676f6603c60Sopenharmony_ci result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); 677f6603c60Sopenharmony_ci ASSERT_EQ(SL_RESULT_SUCCESS, result); 678f6603c60Sopenharmony_ci 679f6603c60Sopenharmony_ci // get pcmPlayerObject 680f6603c60Sopenharmony_ci pcmPlayerObject = nullptr; 681f6603c60Sopenharmony_ci SLDataLocator_OutputMix slOutputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject}; 682f6603c60Sopenharmony_ci SLDataSink slSink = {&slOutputMix, nullptr}; 683f6603c60Sopenharmony_ci SLDataLocator_BufferQueue slBufferQueue = { 684f6603c60Sopenharmony_ci SL_DATALOCATOR_BUFFERQUEUE, 685f6603c60Sopenharmony_ci 0}; 686f6603c60Sopenharmony_ci SLDataFormat_PCM pcmFormat = { 687f6603c60Sopenharmony_ci SL_DATAFORMAT_PCM, 688f6603c60Sopenharmony_ci wavHeader_.NumOfChan, 689f6603c60Sopenharmony_ci wavHeader_.SamplesPerSec * 1000, 690f6603c60Sopenharmony_ci wavHeader_.bitsPerSample, 691f6603c60Sopenharmony_ci 0, 692f6603c60Sopenharmony_ci 0, 693f6603c60Sopenharmony_ci 0}; 694f6603c60Sopenharmony_ci SLDataSource slSource = {&slBufferQueue, &pcmFormat}; 695f6603c60Sopenharmony_ci result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject, &slSource, 696f6603c60Sopenharmony_ci &slSink, number, nullptr, nullptr); 697f6603c60Sopenharmony_ci EXPECT_TRUE(result == SL_RESULT_SUCCESS); 698f6603c60Sopenharmony_ci 699f6603c60Sopenharmony_ci // get volumeItf 700f6603c60Sopenharmony_ci SLVolumeItf volumeItf = nullptr; 701f6603c60Sopenharmony_ci result = (*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_VOLUME, &volumeItf); 702f6603c60Sopenharmony_ci EXPECT_TRUE(result == SL_RESULT_SUCCESS); 703f6603c60Sopenharmony_ci 704f6603c60Sopenharmony_ci SLresult result1 = (*volumeItf)->SetMute(volumeItf, SL_BOOLEAN_FALSE); 705f6603c60Sopenharmony_ci EXPECT_TRUE(result1 == SL_RESULT_FEATURE_UNSUPPORTED); 706f6603c60Sopenharmony_ci 707f6603c60Sopenharmony_ci SLresult result2 = (*volumeItf)->GetMute(volumeItf, nullptr); 708f6603c60Sopenharmony_ci EXPECT_TRUE(result2 == SL_RESULT_FEATURE_UNSUPPORTED); 709f6603c60Sopenharmony_ci 710f6603c60Sopenharmony_ci SLresult result3 = (*volumeItf)->EnableStereoPosition(volumeItf, SL_BOOLEAN_FALSE); 711f6603c60Sopenharmony_ci EXPECT_TRUE(result3 == SL_RESULT_FEATURE_UNSUPPORTED); 712f6603c60Sopenharmony_ci 713f6603c60Sopenharmony_ci SLresult result4 = (*volumeItf)->IsEnabledStereoPosition(volumeItf, nullptr); 714f6603c60Sopenharmony_ci EXPECT_TRUE(result4 == SL_RESULT_FEATURE_UNSUPPORTED); 715f6603c60Sopenharmony_ci 716f6603c60Sopenharmony_ci SLresult result5 = (*volumeItf)->SetStereoPosition(volumeItf, 0); 717f6603c60Sopenharmony_ci EXPECT_TRUE(result5 == SL_RESULT_FEATURE_UNSUPPORTED); 718f6603c60Sopenharmony_ci 719f6603c60Sopenharmony_ci SLresult result6 = (*volumeItf)->GetStereoPosition(volumeItf, nullptr); 720f6603c60Sopenharmony_ci EXPECT_TRUE(result6 == SL_RESULT_FEATURE_UNSUPPORTED); 721f6603c60Sopenharmony_ci}