Signed-off-by: yangshuai<yangshuai67@huawei.com>
This commit is contained in:
yangshuai0222 2022-02-18 16:09:43 +08:00
parent 4230524f55
commit 64ba51cff4
27 changed files with 2052 additions and 1 deletions

View File

@ -21,3 +21,9 @@ group("audio_packages") {
"services:audio_service",
]
}
group("libsl") {
public_deps = [
"//third_party/openSLES:libSLES",
]
}

View File

@ -0,0 +1,86 @@
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
pulseaudio_dir = "//third_party/pulseaudio"
opensles_dir = "//third_party/openSLES"
config("audio_renderer_config") {
include_dirs = [
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiorenderer/include",
"//foundation/multimedia/audio_standard/frameworks/native/audiorenderer/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiocommon/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiostream/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiosession/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiomanager/include",
"//foundation/multimedia/audio_standard/services/include",
"//foundation/multimedia/audio_standard/services/include/client",
"//foundation/multimedia/audio_standard/services/test",
"//utils/native/base/include",
"$pulseaudio_dir/src",
"$pulseaudio_dir/confgure/src",
]
cflags = [
"-Wall",
"-Werror",
]
}
ohos_shared_library("opensles") {
include_dirs = [
"$opensles_dir/api/1.0.1",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/andiorenderer/include/",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/andiomanager/include/",
]
configs = [
":audio_renderer_config",
]
sources = [
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/adapter/audioplayer_adapter.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/adapter/writecallback_adapter.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/itf/openharmony_buffer_queue_itf.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/itf/engine_itf.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/itf/object_itf.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/itf/play_itf.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/itf/volume_itf.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/obj/engine_obj.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/obj/audioplayer_obj.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/obj/output_mix_obj.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/util/OpenSLES_OpenHarmony_IID.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/util/builder.cpp",
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/util/table_struct.cpp",
"$opensles_dir/api/1.0.1/OpenSLES_IID.c",
]
cflags = [
"-Werror",
]
deps = [
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiorenderer:audio_renderer",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiomanager:audio_client",
"//foundation/multimedia/audio_standard:libsl"
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
output_name = "OpenSLES"
output_extension = "so"
subsystem_name = "multimedia"
part_name = "multimedia_audio_standard"
}

View File

@ -0,0 +1,50 @@
#include<OpenSLES.h>
#include<OpenSLES_Platform.h>
/*---------------------------------------------------------------------------*/
/* OH Buffer Queue Interface */
/*---------------------------------------------------------------------------*/
extern const SLInterfaceID SL_IID_OH_BUFFERQUEUE;
struct SLOHBufferQueueItf_;
typedef const struct SLOHBufferQueueItf_ * const * SLOHBufferQueueItf;
typedef void (SLAPIENTRY *SlOHBufferQueueCallback)(
SLOHBufferQueueItf caller,
void *pContext,
SLuint32 size
);
/** OH Buffer queue state **/
typedef struct SLOHBufferQueueState_ {
SLuint32 count;
SLuint32 playIndex;
} SLOHBufferQueueState;
struct SLOHBufferQueueItf_ {
SLresult (*Enqueue) (
SLOHBufferQueueItf self,
const void *pBuffer,
SLuint32 size
);
SLresult (*Clear) (
SLOHBufferQueueItf self
);
SLresult (*GetState) (
SLOHBufferQueueItf self,
SLOHBufferQueueState *pState
);
SLresult (*GetBuffer) (
SLOHBufferQueueItf self,
SLuint8** pBuffer,
SLuint32& pSize
);
SLresult (*RegisterCallback) (
SLOHBufferQueueItf self,
SlOHBufferQueueCallback callback,
void* pContext
);
};

View File

@ -0,0 +1,46 @@
#ifndef AUDIOPLAYER_ADAPTER_H
#define AUDIOPLAYER_ADAPTER_H
#include <OpenSLES.h>
#include <OpenSLES_Platform.h>
#include <iostream>
#include <map>
#include <audio_renderer.h>
#include <audio_system_manager.h>
#include <writecallback_adapter.h>
namespace OHOS {
namespace AudioStandard {
class AudioPlayerAdapter {
public:
static AudioPlayerAdapter* GetInstance();
AudioRenderer *GetAudioRenderById(SLuint32 id);
void EraseAudioRenderById(SLuint32 id);
SLresult CreateAudioPlayerAdapter(SLuint32 id, SLDataSource *dataSource, SLDataSink *dataSink, AudioStreamType streamType);
SLresult SetPlayStateAdapter(SLuint32 id, SLuint32 state);
SLresult GetPlayStateAdapter(SLuint32 id, SLuint32 *state);
SLresult SetVolumeLevelAdapter(SLuint32 id, SLmillibel level);
SLresult GetVolumeLevelAdapter(SLuint32 id, SLmillibel *level);
SLresult GetMaxVolumeLevelAdapter(SLuint32 id, SLmillibel *level);
SLresult EnqueueAdapter(SLuint32 id, const void *pBuffer, SLuint32 size);
SLresult ClearAdapter(SLuint32 id);
SLresult GetStateAdapter(SLuint32 id, SLOHBufferQueueState *pState);
SLresult GetBufferAdapter(SLuint32 id, SLuint8 **pBuffer, SLuint32 &pSize);
SLresult RegisterCallbackAdapter(SLOHBufferQueueItf itf, SlOHBufferQueueCallback callback, void *pContext);
private:
AudioPlayerAdapter();
~AudioPlayerAdapter();
std::map<SLuint32, AudioRenderer*> renderMap_;
std::shared_ptr<WriteCallbackAdapter> callbackPtr_;
std::map<SLuint32, std::shared_ptr<WriteCallbackAdapter>> callbackMap_;
void ConvertPcmFormat(SLDataFormat_PCM *slFormat, AudioRendererParams *rendererParams);
AudioSampleFormat SlToOhosSampelFormat(SLDataFormat_PCM *pcmFormat);
AudioSamplingRate SlToOhosSamplingRate(SLDataFormat_PCM *pcmFormat);
AudioChannel SlToOhosChannel(SLDataFormat_PCM *pcmFormat);
};
} // namespace AudioStandard
} // namespace OHOS
#endif // AUDIO_RENDERER_SINK_H

View File

@ -0,0 +1,14 @@
#ifndef BUILDER_H
#define BUILDER_H
#include <common.h>
struct ClassTable;
struct IObject;
ClassTable *ObjectIdToClass(SLuint32 objectId);
IObject *Construct(const ClassTable *classTable, SLEngineItf itf);
#endif

View File

@ -0,0 +1,84 @@
#ifndef COMMON_H
#define COMMON_H
#include <OpenSLES.h>
#include <OpenSLES_OpenHarmony.h>
#include <OpenSLES_Platform.h>
#include <audioplayer_adapter.h>
#include <builder.h>
#include <table_struct.h>
#include <iostream>
#include <cstdlib>
#include <stddef.h>
#include "media_log.h"
struct CEngine;
struct ClassTable;
/** itf struct **/
struct IObject {
const struct SLObjectItf_ *mItf;
CEngine *mEngine;
const ClassTable *mClass;
SLuint8 mState;
};
struct IEngine {
const struct SLEngineItf_ *mItf;
IObject *mThis;
};
struct IPlay {
const struct SLPlayItf_ *mItf;
SLuint32 mState;
SLuint8 mId;
};
struct IOHBufferQueue {
const struct SLOHBufferQueueItf_ *mItf;
SLuint32 mState;
SLuint8 mId;
};
struct IVolume {
const struct SLVolumeItf_ *mItf;
SLuint8 mId;
};
/** class struct **/
struct CEngine {
IObject mObject;
IEngine mEngine;
};
struct CAudioPlayer {
IObject mObject;
IPlay mPlay;
IVolume mVolume;
IOHBufferQueue mBufferQueue;
SLuint32 mId;
};
struct COutputMix {
IObject mObject;
};
void IOHBufferQueueInit(void *self, SLuint32 id);
void IEngineInit(void *self);
void IObjectInit(void *self);
void IPlayInit(void *self, SLuint32 id);
void IVolumeInit(void *self, SLuint32 id);
SLresult EngineDestory(void* self);
SLresult AudioPlayerDestroy(void* self);
SLresult OutputMixDestroy(void* self);
#endif

View File

@ -0,0 +1,17 @@
#ifndef TABLE_STRUCT_H
#define TABLE_STRUCT_H
#include <common.h>
struct ClassTable {
SLuint32 mObjectId;
size_t mSize;
};
extern ClassTable EngineTab;
extern ClassTable AudioPlayerTab;
extern ClassTable OutputMixTab;
#endif

View File

@ -0,0 +1,26 @@
#ifndef WRITECALLBACK_ADAPTER_H
#define WRITECALLBACK_ADAPTER_H
#include <OpenSLES.h>
#include <OpenSLES_Platform.h>
#include <iostream>
#include <audio_renderer.h>
namespace OHOS {
namespace AudioStandard {
class WriteCallbackAdapter : public AudioRendererWriteCallback {
public:
WriteCallbackAdapter (SlOHBufferQueueCallback callback, SLOHBufferQueueItf itf, void *pContext);
~WriteCallbackAdapter();
void OnWriteData(size_t length) override;
private:
SlOHBufferQueueCallback callback_;
SLOHBufferQueueItf itf_;
void *context_;
};
} // namespace AudioStandard
} // namespace OHOS
#endif // AUDIO_RENDERER_SINK_H

View File

@ -0,0 +1,293 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <common.h>
using namespace std;
using namespace OHOS;
using namespace OHOS::AudioStandard;
namespace OHOS {
namespace AudioStandard {
AudioPlayerAdapter::AudioPlayerAdapter() { }
AudioPlayerAdapter::~AudioPlayerAdapter() { }
AudioPlayerAdapter* AudioPlayerAdapter::GetInstance()
{
static AudioPlayerAdapter audioPlayerAdapter_;
return &audioPlayerAdapter_;
}
AudioRenderer* AudioPlayerAdapter::GetAudioRenderById(SLuint32 id)
{
MEDIA_INFO_LOG("GetAudioRenderById: %{public}lu", id);
return renderMap_.find(id)->second;
}
void AudioPlayerAdapter::EraseAudioRenderById(SLuint32 id)
{
MEDIA_INFO_LOG("EraseAudioRenderById: %{public}lu", id);
renderMap_.erase(id);
callbackMap_.erase(id);
return;
}
SLresult AudioPlayerAdapter::CreateAudioPlayerAdapter(SLuint32 id, SLDataSource *dataSource, SLDataSink *dataSink, AudioStreamType streamType)
{
SLDataFormat_PCM *pcmFormat = (SLDataFormat_PCM *)dataSource->pFormat;
AudioRendererParams rendererParams;
ConvertPcmFormat(pcmFormat, &rendererParams);
streamType = AudioStreamType::STREAM_MUSIC;
unique_ptr<AudioRenderer> rendererHolder = AudioRenderer::Create(streamType);
rendererHolder->SetParams(rendererParams);
AudioRenderer *renderer = rendererHolder.release();
MEDIA_INFO_LOG("CreateAudioPlayer ID: %{public}lu", id);
renderer->SetRenderMode(RENDER_MODE_CALLBACK);
renderMap_.insert(make_pair(id, renderer));
return SL_RESULT_SUCCESS;
}
SLresult AudioPlayerAdapter::SetPlayStateAdapter(SLuint32 id, SLuint32 state)
{
AudioRenderer* pRender = GetAudioRenderById(id);
SLresult slResult = SL_RESULT_SUCCESS;
bool reseult = false;
switch (state) {
case SL_PLAYSTATE_PLAYING:
reseult = pRender->Start();
break;
case SL_PLAYSTATE_PAUSED:
reseult = pRender->Pause();
break;
case SL_PLAYSTATE_STOPPED: {
reseult = pRender->Clear();
reseult = reseult & pRender->Stop();
reseult = reseult & pRender->Release();
break;
}
default:
MEDIA_ERR_LOG("play state not supported ");
break;
}
return slResult;
}
SLresult AudioPlayerAdapter::GetPlayStateAdapter(SLuint32 id, SLuint32 *state)
{
AudioRenderer* pRender = GetAudioRenderById(id);
RendererState rendererState = pRender->GetStatus();
switch (rendererState) {
case RENDERER_RUNNING:
*state = SL_PLAYSTATE_PLAYING;
break;
case RENDERER_PAUSED:
*state = SL_PLAYSTATE_PAUSED;
break;
case RENDERER_STOPPED:
*state = SL_PLAYSTATE_STOPPED;
break;
default:
*state = -1;
break;
}
return SL_RESULT_SUCCESS;
}
SLresult AudioPlayerAdapter::SetVolumeLevelAdapter(SLuint32 id, SLmillibel level)
{
AudioRenderer *audioRenderer = GetAudioRenderById(id);
float volume = pow(10, level / 2000.0);
std::cout << "setVolume level: " << level << std::endl;
audioRenderer->SetVolume(volume / 15.0);
std::cout << "setVolume volume: " << volume << std::endl;
return SL_RESULT_SUCCESS;
}
SLresult AudioPlayerAdapter::GetVolumeLevelAdapter(SLuint32 id, SLmillibel *level)
{
AudioRenderer *audioRenderer = GetAudioRenderById(id);
float volume = audioRenderer->GetVolume();
*level = (SLmillibel) (2000 * log10(volume));
std::cout << "getVolume *level*: " << pow(10, volume / 2000.0) << std::endl;
return SL_RESULT_SUCCESS;
}
SLresult AudioPlayerAdapter::GetMaxVolumeLevelAdapter(SLuint32 id, SLmillibel *level)
{
float volume = AudioSystemManager::GetInstance()->GetMaxVolume(AudioSystemManager::STREAM_MUSIC);
*level = (SLmillibel) (2000 * log10(volume));
std::cout << "getMaxVolume volume: " << volume << std::endl;
std::cout << "getMaxVolume level*: " << *level << std::endl;
return SL_RESULT_SUCCESS;
}
SLresult AudioPlayerAdapter::EnqueueAdapter(SLuint32 id, const void *pBuffer, SLuint32 size)
{
AudioRenderer *audioRenderer = GetAudioRenderById(id);
BufferDesc bufDesc = {};
bufDesc.buffer = (uint8_t*) pBuffer;
bufDesc.length = size;
audioRenderer->Enqueue(bufDesc);
return SL_RESULT_SUCCESS;
}
SLresult AudioPlayerAdapter::ClearAdapter(SLuint32 id)
{
AudioRenderer *audioRenderer = GetAudioRenderById(id);
audioRenderer->Clear();
return SL_RESULT_SUCCESS;
}
SLresult AudioPlayerAdapter::GetStateAdapter(SLuint32 id, SLOHBufferQueueState *pState)
{
AudioRenderer *audioRenderer = GetAudioRenderById(id);
BufferQueueState state = {0, 0};
audioRenderer->GetBufQueueState(state);
pState->count = state.numBuffers;
pState->playIndex = state.currentIndex;
return SL_RESULT_SUCCESS;
}
SLresult AudioPlayerAdapter::GetBufferAdapter(SLuint32 id, SLuint8 **pBuffer, SLuint32 &pSize)
{
AudioRenderer *audioRenderer = GetAudioRenderById(id);
BufferDesc bufferDesc = {};
audioRenderer->GetBufferDesc(bufferDesc);
*pBuffer = bufferDesc.buffer;
pSize = bufferDesc.length;
return SL_RESULT_SUCCESS;
}
SLresult AudioPlayerAdapter::RegisterCallbackAdapter(SLOHBufferQueueItf itf, SlOHBufferQueueCallback callback, void *pContext)
{
IOHBufferQueue *thiz = (IOHBufferQueue *)itf;
AudioRenderer *audioRenderer = GetAudioRenderById(thiz->mId);
callbackPtr_ = make_shared<WriteCallbackAdapter>(callback, itf, pContext);
audioRenderer->SetRendererWriteCallback(static_pointer_cast<AudioRendererWriteCallback>(callbackPtr_));
callbackMap_.insert(make_pair(thiz->mId, callbackPtr_));
return SL_RESULT_SUCCESS;
}
void AudioPlayerAdapter::ConvertPcmFormat(SLDataFormat_PCM *slFormat, AudioRendererParams *rendererParams)
{
AudioSampleFormat sampleFormat = SlToOhosSampelFormat(slFormat);
AudioSamplingRate sampleRate = SlToOhosSamplingRate(slFormat);
AudioChannel channelCount = SlToOhosChannel(slFormat);
rendererParams->sampleFormat = sampleFormat;
rendererParams->sampleRate = sampleRate;
rendererParams->channelCount = channelCount;
rendererParams->encodingType = ENCODING_PCM;
}
AudioSampleFormat AudioPlayerAdapter::SlToOhosSampelFormat(SLDataFormat_PCM *pcmFormat)
{
AudioSampleFormat sampleFormat;
switch (pcmFormat->bitsPerSample) {
case SL_PCMSAMPLEFORMAT_FIXED_8:
sampleFormat = SAMPLE_U8;
break;
case SL_PCMSAMPLEFORMAT_FIXED_16:
sampleFormat = SAMPLE_S16LE;
break;
case SL_PCMSAMPLEFORMAT_FIXED_20:
sampleFormat = INVALID_WIDTH;
break;
case SL_PCMSAMPLEFORMAT_FIXED_24:
sampleFormat = SAMPLE_S24LE;
break;
case SL_PCMSAMPLEFORMAT_FIXED_28:
sampleFormat = INVALID_WIDTH;
break;
case SL_PCMSAMPLEFORMAT_FIXED_32:
sampleFormat = SAMPLE_S32LE;
break;
default:
sampleFormat = INVALID_WIDTH;
}
return sampleFormat;;
}
AudioSamplingRate AudioPlayerAdapter::SlToOhosSamplingRate(SLDataFormat_PCM *pcmFormat)
{
AudioSamplingRate sampleRate;
switch (pcmFormat->samplesPerSec)
{
case SL_SAMPLINGRATE_8:
sampleRate = SAMPLE_RATE_8000;
break;
case SL_SAMPLINGRATE_11_025:
sampleRate = SAMPLE_RATE_11025;
break;
case SL_SAMPLINGRATE_12:
sampleRate = SAMPLE_RATE_12000;
break;
case SL_SAMPLINGRATE_16:
sampleRate = SAMPLE_RATE_16000;
break;
case SL_SAMPLINGRATE_22_05:
sampleRate = SAMPLE_RATE_22050;
break;
case SL_SAMPLINGRATE_24:
sampleRate = SAMPLE_RATE_24000;
break;
case SL_SAMPLINGRATE_32:
sampleRate = SAMPLE_RATE_32000;
break;
case SL_SAMPLINGRATE_44_1:
sampleRate = SAMPLE_RATE_44100;
break;
case SL_SAMPLINGRATE_48:
sampleRate = SAMPLE_RATE_48000;
break;
case SL_SAMPLINGRATE_64:
sampleRate = SAMPLE_RATE_64000;
break;
case SL_SAMPLINGRATE_88_2:
sampleRate = SAMPLE_RATE_44100;
break;
case SL_SAMPLINGRATE_96:
sampleRate = SAMPLE_RATE_96000;
break;
case SL_SAMPLINGRATE_192:
sampleRate = SAMPLE_RATE_44100;
break;
default:
sampleRate = SAMPLE_RATE_44100;
}
return sampleRate;
}
AudioChannel AudioPlayerAdapter::SlToOhosChannel(SLDataFormat_PCM *pcmFormat)
{
AudioChannel channelCount;
std::cout << "numChannels: " << pcmFormat->numChannels << std::endl;
switch (pcmFormat->numChannels)
{
case 1:
channelCount = MONO;
break;
case 2:
channelCount = STEREO;
break;
default:
channelCount = MONO;
break;
}
return channelCount;
}
} // namespace AudioStandard
} // namespace OHOS

View File

@ -0,0 +1,35 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <common.h>
namespace OHOS {
namespace AudioStandard {
WriteCallbackAdapter::WriteCallbackAdapter (SlOHBufferQueueCallback callback, SLOHBufferQueueItf itf, void *context)
{
callback_ = callback;
itf_ = itf;
context_ = context;
}
WriteCallbackAdapter::~WriteCallbackAdapter () { }
void WriteCallbackAdapter::OnWriteData (size_t length)
{
callback_(itf_, context_, length);
return;
}
} // namespace AudioStandard
} // namespace OHOS

View File

@ -0,0 +1,167 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <common.h>
using namespace OHOS::AudioStandard;
static SLuint32 audioplayerId = 0;
static SLresult CreateLEDDevice(SLEngineItf self, SLObjectItf *pDevice, SLuint32 deviceID,
SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult CreateVibraDevice(SLEngineItf self, SLObjectItf *pDevice, SLuint32 deviceID,
SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult CreateAudioPlayer(SLEngineItf self, SLObjectItf *pPlayer,
SLDataSource *pAudioSrc, SLDataSink *pAudioSnk, SLuint32 numInterfaces,
const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
{
ClassTable *audioPlayerClass = ObjectIdToClass(SL_OBJECTID_AUDIOPLAYER);
CAudioPlayer *thiz = (CAudioPlayer *) Construct(audioPlayerClass, self);
thiz->mId = audioplayerId;
IObjectInit(&thiz->mObject);
IPlayInit(&thiz->mPlay, audioplayerId);
IVolumeInit(&thiz->mVolume, audioplayerId);
IOHBufferQueueInit(&thiz->mBufferQueue, audioplayerId);
*pPlayer = &thiz->mObject.mItf;
AudioPlayerAdapter::GetInstance()->CreateAudioPlayerAdapter(audioplayerId, pAudioSrc, pAudioSnk, OHOS::AudioStandard::STREAM_MUSIC);
audioplayerId++;
return SL_RESULT_SUCCESS;
}
static SLresult CreateAudioRecorder(SLEngineItf self, SLObjectItf *pRecorder,
SLDataSource *pAudioSrc, SLDataSink *pAudioSnk, SLuint32 numInterfaces,
const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult CreateMidiPlayer(SLEngineItf self, SLObjectItf *pPlayer,
SLDataSource *pMIDISrc, SLDataSource *pBankSrc, SLDataSink *pAudioOutput,
SLDataSink *pVibra, SLDataSink *pLEDArray, SLuint32 numInterfaces,
const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult CreateListener(SLEngineItf self, SLObjectItf *pListener,
SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult Create3DGroup(SLEngineItf self, SLObjectItf *pGroup, SLuint32 numInterfaces,
const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult CreateOutputMix(SLEngineItf self, SLObjectItf *pMix, SLuint32 numInterfaces,
const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
{
ClassTable *outputMixClass = ObjectIdToClass(SL_OBJECTID_OUTPUTMIX);
COutputMix *thiz = (COutputMix *) Construct(outputMixClass, self);
IObjectInit(&thiz->mObject);
*pMix = &thiz->mObject.mItf;
return SL_RESULT_SUCCESS;
}
static SLresult CreateMetadataExtractor(SLEngineItf self, SLObjectItf *pMetadataExtractor,
SLDataSource *pDataSource, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds,
const SLboolean *pInterfaceRequired)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult CreateExtensionObject(SLEngineItf self, SLObjectItf *pObject,
void *pParameters, SLuint32 objectID, SLuint32 numInterfaces,
const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult QueryNumSupportedInterfaces(SLEngineItf self,
SLuint32 objectID, SLuint32 *pNumSupportedInterfaces)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult QuerySupportedInterfaces(SLEngineItf self,
SLuint32 objectID, SLuint32 index, SLInterfaceID *pInterfaceId)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
};
static SLresult QueryNumSupportedExtensions(SLEngineItf self, SLuint32 *pNumExtensions)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult QuerySupportedExtension(SLEngineItf self,
SLuint32 index, SLchar *pExtensionName, SLint16 *pNameLength)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult IsExtensionSupported(SLEngineItf self,
const SLchar *pExtensionName, SLboolean *pSupported)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static const struct SLEngineItf_ EngineItf = {
CreateLEDDevice,
CreateVibraDevice,
CreateAudioPlayer,
CreateAudioRecorder,
CreateMidiPlayer,
CreateListener,
Create3DGroup,
CreateOutputMix,
CreateMetadataExtractor,
CreateExtensionObject,
QueryNumSupportedInterfaces,
QuerySupportedInterfaces,
QueryNumSupportedExtensions,
QuerySupportedExtension,
IsExtensionSupported
};
void IEngineInit(void *self)
{
IEngine *thiz = (IEngine *) self;
thiz->mItf = &EngineItf;
}

View File

@ -0,0 +1,149 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <common.h>
using namespace OHOS::AudioStandard;
static SLresult Realize(SLObjectItf self, SLboolean async)
{
return SL_RESULT_SUCCESS;
}
static SLresult Resume(SLObjectItf self, SLboolean async)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult GetState(SLObjectItf self, SLuint32 *state) {
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult GetInterface(SLObjectItf self, const SLInterfaceID iid, void *interface)
{
/*
switch (iid) {
case SL_IID_ENGINE: {
CEngine *cEngine = (CEngine *)self;
*(void **)interface = (void *)&(cEngine->mEngine.mItf);
return SL_RESULT_SUCCESS;
}
case SL_IID_PLAY: {
CAudioPlayer *cAudioPlayer = (CAudioPlayer *)self;
*(void **)interface = (void *)&(cAudioPlayer->mPlay.mItf);
return SL_RESULT_SUCCESS;
}
case SL_IID_VOLUME: {
CAudioPlayer *cAudioPlayer = (CAudioPlayer *)self;
*(void **)interface = (void *)&(cAudioPlayer->mVolume.mItf);
return SL_RESULT_SUCCESS;
}
case SL_IID_OH_BUFFERQUEUE: {
CAudioPlayer *cAudioPlayer = (CAudioPlayer *)self;
*(void **)interface = (void *)&(cAudioPlayer->mBufferQueue.mItf);
return SL_RESULT_SUCCESS;
}
default:
return SL_RESULT_FEATURE_UNSUPPORTED;
}
*/
if (iid == SL_IID_ENGINE) {
CEngine *cEngine = (CEngine *)self;
*(void **)interface = (void *)&(cEngine->mEngine.mItf);
return SL_RESULT_SUCCESS;
} else if (iid == SL_IID_PLAY) {
CAudioPlayer *cAudioPlayer = (CAudioPlayer *)self;
*(void **)interface = (void *)&(cAudioPlayer->mPlay.mItf);
return SL_RESULT_SUCCESS;
} else if (iid == SL_IID_VOLUME) {
CAudioPlayer *cAudioPlayer = (CAudioPlayer *)self;
*(void **)interface = (void *)&(cAudioPlayer->mVolume.mItf);
return SL_RESULT_SUCCESS;
} else if (iid == SL_IID_OH_BUFFERQUEUE) {
CAudioPlayer *cAudioPlayer = (CAudioPlayer *)self;
*(void **)interface = (void *)&(cAudioPlayer->mBufferQueue.mItf);
return SL_RESULT_SUCCESS;
} else {
return SL_RESULT_FEATURE_UNSUPPORTED;
}
}
static SLresult RegisterCallback(SLObjectItf self, slObjectCallback callback, void *pContext)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static void AbortAsyncOperation(SLObjectItf self)
{
return;
}
static SLresult SetPriority(SLObjectItf self, SLint32 priority, SLboolean preemptable)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult GetPriority(SLObjectItf self, SLint32 *pPriority, SLboolean *pPreemptable)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult SetLossOfControlInterfaces(SLObjectItf self,
SLint16 numInterfaces, SLInterfaceID *pInterfaceIDs, SLboolean enabled)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
void Destroy(SLObjectItf self) {
IObject *iObject = (IObject *)self;
SLuint32 objectId = iObject->mClass->mObjectId;
switch (objectId) {
case SL_OBJECTID_AUDIOPLAYER: {
AudioPlayerDestroy((void *)self);
break;
}
case SL_OBJECTID_ENGINE: {
EngineDestory((void *)self);
break;
}
case SL_OBJECTID_OUTPUTMIX: {
OutputMixDestroy((void *)self);
break;
}
default:
MEDIA_ERR_LOG("not supported");
break;
}
return;
}
static const struct SLObjectItf_ ObjectItf = {
Realize,
Resume,
GetState,
GetInterface,
RegisterCallback,
AbortAsyncOperation,
Destroy,
SetPriority,
GetPriority,
SetLossOfControlInterfaces
};
void IObjectInit(void *self)
{
IObject *thiz = (IObject *) self;
thiz->mItf = &ObjectItf;
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <common.h>
using namespace OHOS::AudioStandard;
SLresult Enqueue(SLOHBufferQueueItf self, const void *pBuffer, SLuint32 size)
{
IOHBufferQueue *thiz = (IOHBufferQueue *)self;
AudioPlayerAdapter::GetInstance()->EnqueueAdapter(thiz->mId, pBuffer, size);
return SL_RESULT_SUCCESS;
}
SLresult Clear(SLOHBufferQueueItf self)
{
IOHBufferQueue *thiz = (IOHBufferQueue *)self;
AudioPlayerAdapter::GetInstance()->ClearAdapter(thiz->mId);
return SL_RESULT_SUCCESS;
}
SLresult GetState(SLOHBufferQueueItf self, SLOHBufferQueueState *pState)
{
IOHBufferQueue *thiz = (IOHBufferQueue *)self;
AudioPlayerAdapter::GetInstance()->GetStateAdapter(thiz->mId, pState);
return SL_RESULT_SUCCESS;
}
SLresult GetBuffer(SLOHBufferQueueItf self, SLuint8 **pBuffer, SLuint32 &pSize)
{
IOHBufferQueue *thiz = (IOHBufferQueue *)self;
AudioPlayerAdapter::GetInstance()->GetBufferAdapter(thiz->mId, pBuffer, pSize);
return SL_RESULT_SUCCESS;
}
SLresult RegisterCallback(SLOHBufferQueueItf self,
SlOHBufferQueueCallback callback, void *pContext)
{
AudioPlayerAdapter::GetInstance()->RegisterCallbackAdapter(self, callback, pContext);
return SL_RESULT_SUCCESS;
}
static const struct SLOHBufferQueueItf_ IOHBufferQueueItf = {
Enqueue,
Clear,
GetState,
GetBuffer,
RegisterCallback
};
void IOHBufferQueueInit(void *self, SLuint32 id)
{
IOHBufferQueue *thiz = (IOHBufferQueue *) self;
thiz->mItf = &IOHBufferQueueItf;
thiz->mId = id;
thiz->mState = SL_PLAYSTATE_STOPPED;
}

View File

@ -0,0 +1,107 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Play implementation */
#include <common.h>
using namespace OHOS::AudioStandard;
static SLresult SetPlayState(SLPlayItf self, SLuint32 state)
{
IPlay *thiz = (IPlay *)self;
AudioPlayerAdapter::GetInstance()->SetPlayStateAdapter(thiz->mId, state);
return SL_RESULT_SUCCESS;
}
static SLresult GetPlayState(SLPlayItf self, SLuint32 *pState)
{
IPlay *thiz = (IPlay *)self;
AudioPlayerAdapter::GetInstance()->GetPlayStateAdapter(thiz->mId, pState);
return SL_RESULT_SUCCESS;
}
static SLresult GetDuration(SLPlayItf self, SLmillisecond *pMsec)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult GetPosition(SLPlayItf self, SLmillisecond *pMsec)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult RegisterCallback(SLPlayItf self, slPlayCallback callback, void *pContext)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult SetCallbackEventsMask(SLPlayItf self, SLuint32 eventFlags)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult GetCallbackEventsMask(SLPlayItf self, SLuint32 *pEventFlags)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult SetMarkerPosition(SLPlayItf self, SLmillisecond mSec)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult ClearMarkerPosition(SLPlayItf self)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult GetMarkerPosition(SLPlayItf self, SLmillisecond *pMsec)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult SetPositionUpdatePeriod(SLPlayItf self, SLmillisecond mSec)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult GetPositionUpdatePeriod(SLPlayItf self, SLmillisecond *pMsec)
{
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static const struct SLPlayItf_ PlayItf = {
SetPlayState,
GetPlayState,
GetDuration,
GetPosition,
RegisterCallback,
SetCallbackEventsMask,
GetCallbackEventsMask,
SetMarkerPosition,
ClearMarkerPosition,
GetMarkerPosition,
SetPositionUpdatePeriod,
GetPositionUpdatePeriod
};
void IPlayInit(void *self, SLuint32 id)
{
IPlay *thiz = (IPlay *)self;
thiz->mItf = &PlayItf;
thiz->mState = SL_PLAYSTATE_STOPPED;
thiz->mId = id;
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <common.h>
using namespace OHOS::AudioStandard;
static SLresult SetVolumeLevel(SLVolumeItf self, SLmillibel level) {
IVolume *thiz = (IVolume *)self;
AudioPlayerAdapter::GetInstance()->SetVolumeLevelAdapter(thiz->mId, level);
return SL_RESULT_SUCCESS;
}
static SLresult GetVolumeLevel(SLVolumeItf self, SLmillibel *pLevel) {
IVolume *thiz = (IVolume *)self;
AudioPlayerAdapter::GetInstance()->GetVolumeLevelAdapter(thiz->mId, pLevel);
return SL_RESULT_SUCCESS;
}
static SLresult GetMaxVolumeLevel(SLVolumeItf self, SLmillibel *pMaxLevel) {
IVolume *thiz = (IVolume *)self;
AudioPlayerAdapter::GetInstance()->GetMaxVolumeLevelAdapter(thiz->mId, pMaxLevel);
return SL_RESULT_SUCCESS;
}
static SLresult SetMute(SLVolumeItf self, SLboolean state) {
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult GetMute(SLVolumeItf self, SLboolean *pState) {
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult EnableStereoPosition(SLVolumeItf self, SLboolean enable) {
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult IsEnabledStereoPosition(SLVolumeItf self, SLboolean *pEnable) {
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult SetStereoPosition(SLVolumeItf self, SLpermille stereoPosition) {
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static SLresult GetStereoPosition(SLVolumeItf self, SLpermille *pStereoPosition) {
return SL_RESULT_FEATURE_UNSUPPORTED;
}
static const struct SLVolumeItf_ VolumeItf = {
SetVolumeLevel,
GetVolumeLevel,
GetMaxVolumeLevel,
SetMute,
GetMute,
EnableStereoPosition,
IsEnabledStereoPosition,
SetStereoPosition,
GetStereoPosition
};
void IVolumeInit(void *self, SLuint32 id)
{
IVolume *thiz = (IVolume *) self;
thiz->mItf = &VolumeItf;
thiz->mId = id;
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include<common.h>
using namespace OHOS::AudioStandard;
SLresult AudioPlayerDestroy(void *self)
{
CAudioPlayer *cAudioPlayer = (CAudioPlayer *)self;
AudioPlayerAdapter::GetInstance()->EraseAudioRenderById(cAudioPlayer->mId);
return SL_RESULT_SUCCESS;
}

View File

@ -0,0 +1,22 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include<common.h>
SLresult EngineDestory(void* self)
{
free(self);
return SL_RESULT_SUCCESS;
}

View File

@ -0,0 +1,22 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include<common.h>
SLresult OutputMixDestroy(void *self)
{
free(self);
return SL_RESULT_SUCCESS;
}

View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <OpenSLES_OpenHarmony.h>
/*****************************************************************************/
/* Interface IDs */
/*****************************************************************************/
static const struct SLInterfaceID_ SL_IID_OH_BUFFERQUEUE_ = { 0x2bc99cc0, 0xddd4, 0x11db, 0x8d99, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
const SLInterfaceID SL_IID_OH_BUFFERQUEUE = &SL_IID_OH_BUFFERQUEUE_;

View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <common.h>
SLresult SLAPIENTRY slCreateEngine(SLObjectItf *pEngine, SLuint32 numOptions,
const SLEngineOption *pEngineOptions, SLuint32 numInterfaces,
const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
{
ClassTable *engineClass = ObjectIdToClass(SL_OBJECTID_ENGINE);
CEngine *thiz = (CEngine *) Construct(engineClass, nullptr);
IObjectInit(&thiz->mObject);
IEngineInit(&thiz->mEngine);
*pEngine = &thiz->mObject.mItf;
return SL_RESULT_SUCCESS;
}
ClassTable *ObjectIdToClass(SLuint32 objectId) {
ClassTable *classTable = nullptr;
if (objectId == SL_OBJECTID_ENGINE) {
classTable = (ClassTable *) &EngineTab;
} else if (objectId == SL_OBJECTID_AUDIOPLAYER) {
classTable = (ClassTable *) &AudioPlayerTab;
} else if (objectId == SL_OBJECTID_OUTPUTMIX) {
classTable = (ClassTable *) &OutputMixTab;
}
return classTable;
}
IObject *Construct(const ClassTable *classTable, SLEngineItf engine) {
IObject *thiz = (IObject *) calloc(1, classTable->mSize);
if (thiz != nullptr) {
IEngine *thisEngine = (IEngine *) engine;
if (thisEngine != nullptr) {
thiz->mEngine = (CEngine *) thisEngine->mThis;
} else {
thiz->mEngine = (CEngine *) thiz;
}
thiz->mClass = classTable;
}
return thiz;
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <common.h>
ClassTable EngineTab = {
SL_OBJECTID_ENGINE,
sizeof(CEngine),
};
ClassTable AudioPlayerTab = {
SL_OBJECTID_AUDIOPLAYER,
sizeof(CAudioPlayer),
};
ClassTable OutputMixTab = {
SL_OBJECTID_OUTPUTMIX,
sizeof(CAudioPlayer),
};

View File

@ -0,0 +1,54 @@
import("//build/ohos.gni")
pulseaudio_dir = "//third_party/pulseaudio"
opensles_dir = "//third_party/openSLES"
config("audio_renderer_config") {
include_dirs = [
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiorenderer/include",
"//foundation/multimedia/audio_standard/frameworks/native/audiorenderer/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiocommon/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiostream/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiosession/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiomanager/include",
"//foundation/multimedia/audio_standard/services/include",
"//foundation/multimedia/audio_standard/services/include/client",
"//foundation/multimedia/audio_standard/services/test",
"//utils/native/base/include",
"$pulseaudio_dir/src",
"$pulseaudio_dir/confgure/src",
]
cflags = [
"-Wall",
"-Werror",
]
}
config("audio_opensles_config") {
include_dirs = [
"//foundation/multimedia/audio_standard/frameworks/native/opensles/include",
"$opensles_dir/api/1.0.1",
]
}
ohos_executable("audio_opensles_test") {
install_enable = true
sources = [ "//foundation/multimedia/audio_standard/services/test/audio_opensles_test.cpp" ]
configs = [
":audio_opensles_config",
":audio_renderer_config"
]
deps = [
"//foundation/multimedia/audio_standard/frameworks/native/opensles:opensles",
"//foundation/multimedia/audio_standard:libsl"
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
part_name = "multimedia_audio_standard"
subsystem_name = "multimedia"
}

View File

@ -24,7 +24,9 @@
"//foundation/multimedia/audio_standard/frameworks/native/audiopolicy:audio_policy_test",
"//foundation/multimedia/audio_standard/frameworks/native/audiocapturer:audio_capturer_source",
"//foundation/multimedia/audio_standard/frameworks/native/audiorenderer:audio_renderer_sink",
"//foundation/multimedia/audio_standard/frameworks/native/audioadapter:pulse_audio_service_adapter"
"//foundation/multimedia/audio_standard/frameworks/native/audioadapter:pulse_audio_service_adapter",
"//foundation/multimedia/audio_standard/frameworks/native/opensles:opensles",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/opensles:audio_opensles_test"
],
"inner_kits": [
{

View File

@ -0,0 +1,344 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <OpenSLES.h>
#include <OpenSLES_OpenHarmony.h>
#include <OpenSLES_Platform.h>
#include "media_log.h"
#include <iostream>
#include "pcm2wav.h"
#include <thread>
#include <unistd.h>
using namespace std;
static void BuqqerQueueCallback (SLOHBufferQueueItf bufferQueueItf, void *pContext, SLuint32 size);
static void PlayerStart (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf, FILE *wavFile);
static void PlayerStop (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf);
static void OpenSlTest();
static void OpenSlTestAll();
FILE *wavFile_ = nullptr;
FILE *wavFile1_ = nullptr;
FILE *wavFile2_ = nullptr;
wav_hdr wavHeader_;
wav_hdr wavHeader1_;
wav_hdr wavHeader2_;
SLObjectItf engineObject = nullptr;
SLObjectItf outputMixObject = nullptr;
SLPlayItf playItf;
SLPlayItf playItf1;
SLPlayItf playItf2;
SLVolumeItf volumeItf1;
SLVolumeItf volumeItf2;
SLOHBufferQueueItf bufferQueueItf;
SLOHBufferQueueItf bufferQueueItf1;
SLOHBufferQueueItf bufferQueueItf2;
SLObjectItf pcmPlayerObject = nullptr;
SLObjectItf pcmPlayerObject1 = nullptr;
SLObjectItf pcmPlayerObject2 = nullptr;
int main(int argc, char *argv[])
{
if (argc == 4) {
size_t headerSize = sizeof(wav_hdr);
char *inputPath = argv[1];
char path[PATH_MAX + 1] = {0x00};
if ((strlen(inputPath) > PATH_MAX) || (realpath(inputPath, path) == nullptr)) {
MEDIA_ERR_LOG("Invalid path");
return -1;
}
wavFile1_ = fopen(path, "rb");
if (wavFile1_ == nullptr) {
MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file");
return -1;
}
fread(&wavHeader1_, 1, headerSize, wavFile1_);
headerSize = sizeof(wav_hdr);
inputPath = argv[2];
if ((strlen(inputPath) > PATH_MAX) || (realpath(inputPath, path) == nullptr)) {
MEDIA_ERR_LOG("Invalid path");
return -1;
}
wavFile2_ = fopen(path, "rb");
if (wavFile2_ == nullptr) {
MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file");
return -1;
}
fread(&wavHeader2_, 1, headerSize, wavFile2_);
OpenSlTestAll();
while (!feof(wavFile1_) || !feof(wavFile2_)) {
sleep(1);
}
PlayerStop(playItf1, bufferQueueItf1);
PlayerStop(playItf2, bufferQueueItf2);
(*pcmPlayerObject1)->Destroy(pcmPlayerObject1);
(*pcmPlayerObject2)->Destroy(pcmPlayerObject2);
(*engineObject)->Destroy(engineObject);
(*outputMixObject)->Destroy(outputMixObject);
return 0;
} else if (argc == 3) {
}
if (argc < 2) {
return -1;
}
size_t headerSize = sizeof(wav_hdr);
char *inputPath = argv[1];
char path[PATH_MAX + 1] = {0x00};
if ((strlen(inputPath) > PATH_MAX) || (realpath(inputPath, path) == nullptr)) {
MEDIA_ERR_LOG("Invalid path");
return -1;
}
wavFile_ = fopen(path, "rb");
if (wavFile_ == nullptr) {
MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file");
return -1;
}
fread(&wavHeader_, 1, headerSize, wavFile_);
OpenSlTest();
while (!feof(wavFile_)) {
sleep(1);
}
PlayerStop(playItf, bufferQueueItf);
(*pcmPlayerObject)->Destroy(pcmPlayerObject);
if (argc < 3) {
return -1;
}
char *inputPath2 = argv[2];
char path2[PATH_MAX + 1] = {0x00};
if ((strlen(inputPath2) > PATH_MAX) || (realpath(inputPath2, path2) == nullptr)) {
MEDIA_ERR_LOG("Invalid path");
return -1;
}
wavFile_ = fopen(path2, "rb");
if (wavFile_ == nullptr) {
MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file");
return -1;
}
fread(&wavHeader_, 1, headerSize, wavFile_);
OpenSlTest();
while (!feof(wavFile_)) {
sleep(1);
}
PlayerStop(playItf, bufferQueueItf);
(*pcmPlayerObject)->Destroy(pcmPlayerObject);
return 0;
}
static void OpenSlTest()
{
engineObject = nullptr;
SLEngineItf engineEngine = nullptr;
SLresult result;
result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr);
result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
MEDIA_INFO_LOG("get engine itf");
result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine);
MEDIA_INFO_LOG("create outputmix");
if (*engineEngine == nullptr) {
MEDIA_INFO_LOG("engineEngine is null");
}
outputMixObject = nullptr;
result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, nullptr, nullptr);
(*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);
SLDataLocator_OutputMix slOutputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
SLDataSink slSink = {&slOutputMix, nullptr};
SLDataLocator_BufferQueue slBufferQueue = {
SL_DATALOCATOR_BUFFERQUEUE,
0
};
SLDataFormat_PCM pcmFormat = {
SL_DATAFORMAT_PCM,
wavHeader_.NumOfChan,
wavHeader_.SamplesPerSec * 1000,
wavHeader_.bitsPerSample,
0,
0,
0
};
SLDataSource slSource = {&slBufferQueue, &pcmFormat};
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject, &slSource, &slSink, 3, nullptr, nullptr);
(*pcmPlayerObject)->Realize(pcmPlayerObject, SL_BOOLEAN_FALSE);
(*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_PLAY, &playItf);
SLVolumeItf volumeItf;
(*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_VOLUME, &volumeItf);
SLmillibel pLevel = 0;
(*volumeItf)->GetVolumeLevel(volumeItf, &pLevel);
(*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf);
(*bufferQueueItf)->RegisterCallback(bufferQueueItf, BuqqerQueueCallback, wavFile_);
PlayerStart(playItf, bufferQueueItf, wavFile_);
}
static void OpenSlTestAll()
{
engineObject = nullptr;
SLEngineItf engineEngine = nullptr;
SLresult result;
result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr);
result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine);
if (*engineEngine == nullptr) {
MEDIA_INFO_LOG("engineEngine is null");
}
outputMixObject = nullptr;
result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, nullptr, nullptr);
(*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);
MEDIA_INFO_LOG("config audio sink");
SLDataLocator_OutputMix slOutputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
SLDataSink slSink = {&slOutputMix, nullptr};
SLDataLocator_BufferQueue slBufferQueue = {
SL_DATALOCATOR_BUFFERQUEUE,
0
};
SLDataFormat_PCM pcmFormat1 = {
SL_DATAFORMAT_PCM,
wavHeader1_.NumOfChan,
wavHeader1_.SamplesPerSec * 1000,
wavHeader1_.bitsPerSample,
0,
0,
0
};
SLDataFormat_PCM pcmFormat2 = {
SL_DATAFORMAT_PCM,
wavHeader2_.NumOfChan,
wavHeader2_.SamplesPerSec * 1000,
wavHeader2_.bitsPerSample,
0,
0,
0
};
SLDataSource slSource1 = {&slBufferQueue, &pcmFormat1};
SLDataSource slSource2 = {&slBufferQueue, &pcmFormat2};
MEDIA_INFO_LOG("create audioplayer1");
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject1, &slSource1, &slSink, 3, nullptr, nullptr);
(*pcmPlayerObject1)->Realize(pcmPlayerObject1, SL_BOOLEAN_FALSE);
MEDIA_INFO_LOG("create audioplayer2");
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject2, &slSource2, &slSink, 3, nullptr, nullptr);
(*pcmPlayerObject2)->Realize(pcmPlayerObject2, SL_BOOLEAN_FALSE);
MEDIA_INFO_LOG("get play itf1");
(*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_PLAY, &playItf1);
MEDIA_INFO_LOG("get play itf2");
(*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_PLAY, &playItf2);
MEDIA_INFO_LOG("get volume itf1");
(*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_VOLUME, &volumeItf1);
SLmillibel level1 = 0;
(*volumeItf1)->GetMaxVolumeLevel(volumeItf1, &level1);
SLmillibel temp = 2;
level1 = (SLmillibel) (level1 / temp);
(*volumeItf1)->SetVolumeLevel(volumeItf1, level1);
MEDIA_INFO_LOG("get volume itf2");
(*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_VOLUME, &volumeItf2);
SLmillibel level2 = 0;
(*volumeItf2)->GetMaxVolumeLevel(volumeItf2, &level2);
temp = 15;
level2 = (SLmillibel) (level2 / temp);
(*volumeItf2)->SetVolumeLevel(volumeItf2, level2);
MEDIA_INFO_LOG("get bufferqueue itf1");
(*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf1);
MEDIA_INFO_LOG("get bufferqueue itf2");
(*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf2);
MEDIA_INFO_LOG("register callback");
(*bufferQueueItf1)->RegisterCallback(bufferQueueItf1, BuqqerQueueCallback, wavFile1_);
(*bufferQueueItf2)->RegisterCallback(bufferQueueItf2, BuqqerQueueCallback, wavFile2_);
PlayerStart(playItf1, bufferQueueItf1, wavFile1_);
PlayerStart(playItf2, bufferQueueItf2, wavFile2_);
}
static void BuqqerQueueCallback (SLOHBufferQueueItf bufferQueueItf, void *pContext, SLuint32 size)
{
FILE *wavFile = (FILE *)pContext;
if (!feof(wavFile)) {
SLuint8 *buffer = nullptr;
SLuint32 pSize = 0;
(*bufferQueueItf)->GetBuffer(bufferQueueItf, &buffer, pSize);
fread(buffer, 1, size, wavFile);
(*bufferQueueItf)->Enqueue(bufferQueueItf, buffer, size);
}
return;
}
static void PlayerStart (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf, FILE *wavFile)
{
(*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING);
MEDIA_INFO_LOG("PlayerStart");
if (!feof(wavFile)) {
SLuint8* buffer = nullptr;
SLuint32 pSize = 0;
(*bufferQueueItf)->GetBuffer(bufferQueueItf, &buffer, pSize);
fread(buffer, 1, pSize, wavFile);
(*bufferQueueItf)->Enqueue(bufferQueueItf, buffer, pSize);
}
return;
}
static void PlayerStop (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf)
{
(*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED);
MEDIA_INFO_LOG("PlayerStop");
return;
}

View File

@ -0,0 +1,67 @@
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
module_output_path = "audio_standard/audio_opensles"
pulseaudio_dir = "//third_party/pulseaudio"
opensles_dir = "//third_party/openSLES"
config("audio_renderer_config") {
include_dirs = [
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiorenderer/include",
"//foundation/multimedia/audio_standard/frameworks/native/audiorenderer/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiocommon/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiostream/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiosession/include",
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiomanager/include",
"//foundation/multimedia/audio_standard/services/include",
"//foundation/multimedia/audio_standard/services/include/client",
"//foundation/multimedia/audio_standard/services/test",
"//utils/native/base/include",
"$pulseaudio_dir/src",
"$pulseaudio_dir/confgure/src",
]
cflags = [
"-Wall",
"-Werror",
]
}
config("audio_opensles_config") {
include_dirs = [
"//foundation/multimedia/audio_standard/frameworks/native/opensles/include",
"$opensles_dir/api/1.0.1",
]
}
ohos_unittest("audio_opensles_unit_test") {
module_out_path = module_output_path
include_dirs = [
"./include",
]
configs = [
":audio_opensles_config",
":audio_renderer_config"
]
sources = [ "src/audio_opensles_unit_test.cpp" ]
deps = [ "//foundation/multimedia/audio_standard/frameworks/native/opensles:opensles" ]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
resource_config_file = "//foundation/multimedia/audio_standard/test/resource/audio_renderer/ohos_test.xml"
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef AUDIO_OPENESLES_UNIT_TEST_H
#define AUDIO_OPENESLES_UNIT_TEST_H
#include "gtest/gtest.h"
#include "common.h"
#include "audio_errors.h"
#include "audio_info.h"
#include "pcm2wav.h"
namespace OHOS {
namespace AudioStandard {
class AudioOpenslesUnitTest : public testing::Test {
public:
// SetUpTestCase: Called before all test cases
static void SetUpTestCase(void);
// TearDownTestCase: Called after all test case
static void TearDownTestCase(void);
// SetUp: Called before each test cases
void SetUp(void);
// TearDown: Called after each test cases
void TearDown(void);
};
} // namespace AudioStandard
} // namespace OHOS
#endif // AUDIO_OPENESLES_UNIT_TEST_H

View File

@ -0,0 +1,138 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "audio_opensles_unit_test.h"
using namespace std;
using namespace testing::ext;
namespace OHOS {
namespace AudioStandard {
namespace {
const char * AUDIORENDER_TEST_FILE_PATH = "/data/test_44100_2.wav";
FILE *wavFile_;
wav_hdr wavHeader_;
SLObjectItf engineObject_;
SLObjectItf outputMixObject_;
SLPlayItf playItf_;
SLVolumeItf volumeItf_;
SLOHBufferQueueItf bufferQueueItf_;
SLObjectItf pcmPlayerObject_;
SLEngineItf engineEngine_;
} // namespace
void AudioOpenslesUnitTest::SetUpTestCase(void)
{
}
void AudioOpenslesUnitTest::TearDownTestCase(void)
{
}
void AudioOpenslesUnitTest::SetUp(void)
{
wavFile_ = fopen(AUDIORENDER_TEST_FILE_PATH, "rb");
if (wavFile_ == nullptr) {
MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file");
}
size_t headerSize = sizeof(wav_hdr);
fread(&wavHeader_, 1, headerSize, wavFile_);
}
void AudioOpenslesUnitTest::TearDown(void)
{
}
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_CreateEngine_001, TestSize.Level0)
{
SLresult result = slCreateEngine(&engineObject_, 0, nullptr, 0, nullptr, nullptr);
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
}
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_CreateEngine_002, TestSize.Level0)
{
SLresult result = (*engineObject_)->Realize(engineObject_, SL_BOOLEAN_FALSE);
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
}
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_CreateEngine_003, TestSize.Level0)
{
SLresult result = (*engineObject_)->GetInterface(engineObject_, SL_IID_ENGINE, &engineEngine_);
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
}
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_CreateOutputMix_001, TestSize.Level0)
{
SLresult result = (*engineEngine_)->CreateOutputMix(engineEngine_, &outputMixObject_, 0, nullptr, nullptr);
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
}
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_CreateOutputMix_002, TestSize.Level0)
{
SLresult result = (*outputMixObject_)->Realize(outputMixObject_, SL_BOOLEAN_FALSE);;
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
}
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_CreateAudioPlayer_001, TestSize.Level0)
{
SLDataLocator_OutputMix slOutputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject_};
SLDataSink slSink = {&slOutputMix, nullptr};
SLDataLocator_BufferQueue slBufferQueue = {
SL_DATALOCATOR_BUFFERQUEUE,
0
};
SLDataFormat_PCM pcmFormat = {
SL_DATAFORMAT_PCM,
wavHeader_.NumOfChan,
wavHeader_.SamplesPerSec * 1000,
wavHeader_.bitsPerSample,
0,
0,
0
};
SLDataSource slSource = {&slBufferQueue, &pcmFormat};
SLresult result = (*engineEngine_)->CreateAudioPlayer(engineEngine_, &pcmPlayerObject_, &slSource, &slSink, 0, nullptr, nullptr);
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
}
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_CreateAudioPlayer_002, TestSize.Level0)
{
SLresult result = (*pcmPlayerObject_)->Realize(pcmPlayerObject_, SL_BOOLEAN_FALSE);
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
}
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_CreateAudioPlayer_003, TestSize.Level0)
{
SLresult result = (*pcmPlayerObject_)->GetInterface(pcmPlayerObject_, SL_IID_PLAY, &playItf_);
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
}
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_GetVoumeItf_001, TestSize.Level0)
{
SLresult result = (*pcmPlayerObject_)->GetInterface(pcmPlayerObject_, SL_IID_VOLUME, &volumeItf_);
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
}
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_CetBufferQueue_001, TestSize.Level0)
{
SLresult result = (*pcmPlayerObject_)->GetInterface(pcmPlayerObject_, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf_);
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
}
} // namespace AudioStandard
} // namespace OHOS