mirror of
https://gitee.com/openharmony/multimedia_audio_standard
synced 2024-12-04 02:42:55 +00:00
add opensl es recording module.
Signed-off-by: yangshuai0222 <yangshuai67@huawei.com>
This commit is contained in:
parent
c12e7dfb4a
commit
76dbddc190
@ -58,7 +58,8 @@
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/audiorenderer:renderer_sink_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"
|
||||
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/opensles:audio_opensles_test",
|
||||
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/opensles:audio_opensles_capture_test"
|
||||
],
|
||||
"inner_kits": [
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ public:
|
||||
int32_t Read(uint8_t &buffer, size_t userSize, bool isBlockingRead) const override;
|
||||
CapturerState GetStatus() const override;
|
||||
bool GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base) const override;
|
||||
bool Pause() const override;
|
||||
bool Stop() const override;
|
||||
bool Flush() const override;
|
||||
bool Release() const override;
|
||||
@ -44,6 +45,13 @@ public:
|
||||
const std::shared_ptr<CapturerPeriodPositionCallback> &callback) override;
|
||||
void UnsetCapturerPeriodPositionCallback() override;
|
||||
int32_t SetBufferDuration(uint64_t bufferDuration) const override;
|
||||
int32_t SetCaptureMode(AudioCaptureMode renderMode)const override;
|
||||
AudioCaptureMode GetCaptureMode()const override;
|
||||
int32_t SetCapturerReadCallback(const std::shared_ptr<AudioCapturerReadCallback> &callback) override;
|
||||
int32_t GetBufferDesc(BufferDesc &bufDesc)const override;
|
||||
int32_t Enqueue(const BufferDesc &bufDesc)const override;
|
||||
int32_t Clear()const override;
|
||||
int32_t GetBufQueueState(BufferQueueState &bufState)const override;
|
||||
void SetApplicationCachePath(const std::string cachePath) override;
|
||||
|
||||
std::shared_ptr<AudioStream> audioStream_;
|
||||
|
@ -217,6 +217,11 @@ bool AudioCapturerPrivate::GetAudioTime(Timestamp ×tamp, Timestamp::Timesta
|
||||
return audioStream_->GetAudioTime(timestamp, base);
|
||||
}
|
||||
|
||||
bool AudioCapturerPrivate::Pause() const
|
||||
{
|
||||
return audioStream_->PauseAudioStream();
|
||||
}
|
||||
|
||||
bool AudioCapturerPrivate::Stop() const
|
||||
{
|
||||
return audioStream_->StopAudioStream();
|
||||
@ -286,5 +291,40 @@ std::vector<AudioSamplingRate> AudioCapturer::GetSupportedSamplingRates()
|
||||
{
|
||||
return AUDIO_SUPPORTED_SAMPLING_RATES;
|
||||
}
|
||||
|
||||
int32_t AudioCapturerPrivate::SetCaptureMode(AudioCaptureMode captureMode) const
|
||||
{
|
||||
return audioStream_->SetCaptureMode(captureMode);
|
||||
}
|
||||
|
||||
AudioCaptureMode AudioCapturerPrivate::GetCaptureMode() const
|
||||
{
|
||||
return audioStream_->GetCaptureMode();
|
||||
}
|
||||
|
||||
int32_t AudioCapturerPrivate::SetCapturerReadCallback(const std::shared_ptr<AudioCapturerReadCallback> &callback)
|
||||
{
|
||||
return audioStream_->SetCapturerReadCallback(callback);
|
||||
}
|
||||
|
||||
int32_t AudioCapturerPrivate::GetBufferDesc(BufferDesc &bufDesc) const
|
||||
{
|
||||
return audioStream_->GetBufferDesc(bufDesc);
|
||||
}
|
||||
|
||||
int32_t AudioCapturerPrivate::Enqueue(const BufferDesc &bufDesc) const
|
||||
{
|
||||
return audioStream_->Enqueue(bufDesc);
|
||||
}
|
||||
|
||||
int32_t AudioCapturerPrivate::Clear() const
|
||||
{
|
||||
return audioStream_->Clear();
|
||||
}
|
||||
|
||||
int32_t AudioCapturerPrivate::GetBufQueueState(BufferQueueState &bufState) const
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
||||
|
@ -52,6 +52,9 @@ public:
|
||||
int32_t SetRenderMode(AudioRenderMode renderMode);
|
||||
AudioRenderMode GetRenderMode();
|
||||
int32_t SetRendererWriteCallback(const std::shared_ptr<AudioRendererWriteCallback> &callback);
|
||||
int32_t SetCaptureMode(AudioCaptureMode captureMode);
|
||||
AudioCaptureMode GetCaptureMode();
|
||||
int32_t SetCapturerReadCallback(const std::shared_ptr<AudioCapturerReadCallback> &callback);
|
||||
int32_t GetBufferDesc(BufferDesc &bufDesc);
|
||||
int32_t Enqueue(const BufferDesc &bufDesc);
|
||||
int32_t Clear();
|
||||
@ -84,12 +87,16 @@ private:
|
||||
uint64_t resetTimestamp_;
|
||||
struct timespec baseTimestamp_;
|
||||
AudioRenderMode renderMode_;
|
||||
AudioCaptureMode captureMode_;
|
||||
std::queue<BufferDesc> freeBufferQ_;
|
||||
std::queue<BufferDesc> filledBufferQ_;
|
||||
std::array<std::unique_ptr<uint8_t[]>, MAX_NUM_BUFFERS> bufferPool_ = {};
|
||||
std::unique_ptr<std::thread> writeThread_ = nullptr;
|
||||
std::unique_ptr<std::thread> readThread_ = nullptr;
|
||||
bool isReadyToWrite_;
|
||||
bool isReadyToRead_;
|
||||
void WriteBuffers();
|
||||
void ReadBuffers();
|
||||
|
||||
static const std::map<std::pair<ContentType, StreamUsage>, AudioStreamType> streamTypeMap_;
|
||||
static std::map<std::pair<ContentType, StreamUsage>, AudioStreamType> CreateStreamMap();
|
||||
|
@ -16,10 +16,12 @@ import("//build/ohos.gni")
|
||||
pulseaudio_dir = "//third_party/pulseaudio"
|
||||
opensles_dir = "//third_party/openSLES"
|
||||
|
||||
config("audio_renderer_config") {
|
||||
config("audio_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/audiocapturer/include",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/audiocapturer/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",
|
||||
@ -43,21 +45,25 @@ ohos_shared_library("opensles") {
|
||||
"$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/andiocapturer/include/",
|
||||
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/andiomanager/include/",
|
||||
]
|
||||
|
||||
configs = [ ":audio_renderer_config" ]
|
||||
configs = [ ":audio_config" ]
|
||||
|
||||
sources = [
|
||||
"$opensles_dir/api/1.0.1/OpenSLES_IID.c",
|
||||
"$opensles_dir/api/1.0.1/OpenSLES_OpenHarmony_IID.cpp",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/adapter/audiocapturer_adapter.cpp",
|
||||
"//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/adapter/readorwritecallback_adapter.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/openharmony_buffer_queue_itf.cpp",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/itf/play_itf.cpp",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/itf/record_itf.cpp",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/itf/volume_itf.cpp",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/obj/audiocapturer_obj.cpp",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/obj/audioplayer_obj.cpp",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/obj/engine_obj.cpp",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/opensles/src/obj/output_mix_obj.cpp",
|
||||
@ -69,6 +75,7 @@ ohos_shared_library("opensles") {
|
||||
|
||||
deps = [
|
||||
"//foundation/multimedia/audio_standard:libsl",
|
||||
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiocapturer:audio_capturer",
|
||||
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiomanager:audio_client",
|
||||
"//foundation/multimedia/audio_standard/interfaces/inner_api/native/audiorenderer:audio_renderer",
|
||||
]
|
||||
|
58
frameworks/native/opensles/include/audiocapturer_adapter.h
Normal file
58
frameworks/native/opensles/include/audiocapturer_adapter.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef AUDIOCAPTURER_ADAPTER_H
|
||||
#define AUDIOCAPTURER_ADAPTER_H
|
||||
|
||||
#include <OpenSLES.h>
|
||||
#include <OpenSLES_Platform.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <audio_capturer.h>
|
||||
#include <audio_system_manager.h>
|
||||
#include <readorwritecallback_adapter.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AudioStandard {
|
||||
class AudioCapturerAdapter {
|
||||
public:
|
||||
static AudioCapturerAdapter* GetInstance();
|
||||
AudioCapturer *GetAudioCapturerById(SLuint32 id);
|
||||
void EraseAudioCapturerById(SLuint32 id);
|
||||
SLresult CreateAudioCapturerAdapter
|
||||
(SLuint32 id, SLDataSource *dataSource, SLDataSink *dataSink, AudioStreamType streamType);
|
||||
SLresult SetCaptureStateAdapter(SLuint32 id, SLuint32 state);
|
||||
SLresult GetCaptureStateAdapter(SLuint32 id, SLuint32 *state);
|
||||
SLresult EnqueueAdapter(SLuint32 id, const void *buffer, SLuint32 size);
|
||||
SLresult ClearAdapter(SLuint32 id);
|
||||
SLresult GetStateAdapter(SLuint32 id, SLOHBufferQueueState *state);
|
||||
SLresult GetBufferAdapter(SLuint32 id, SLuint8 **buffer, SLuint32 &size);
|
||||
SLresult RegisterCallbackAdapter(SLOHBufferQueueItf itf, SlOHBufferQueueCallback callback, void *pContext);
|
||||
|
||||
private:
|
||||
AudioCapturerAdapter();
|
||||
~AudioCapturerAdapter();
|
||||
std::map<SLuint32, AudioCapturer*> captureMap_;
|
||||
std::shared_ptr<ReadOrWriteCallbackAdapter> callbackPtr_;
|
||||
std::map<SLuint32, std::shared_ptr<ReadOrWriteCallbackAdapter>> callbackMap_;
|
||||
|
||||
void ConvertPcmFormat(SLDataFormat_PCM *slFormat, AudioCapturerParams *capturerParams);
|
||||
AudioSampleFormat SlToOhosSampelFormat(SLDataFormat_PCM *pcmFormat);
|
||||
AudioSamplingRate SlToOhosSamplingRate(SLDataFormat_PCM *pcmFormat);
|
||||
AudioChannel SlToOhosChannel(SLDataFormat_PCM *pcmFormat);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -22,7 +22,7 @@
|
||||
#include <map>
|
||||
#include <audio_renderer.h>
|
||||
#include <audio_system_manager.h>
|
||||
#include <writecallback_adapter.h>
|
||||
#include <readorwritecallback_adapter.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AudioStandard {
|
||||
@ -49,8 +49,8 @@ private:
|
||||
~AudioPlayerAdapter();
|
||||
const float MAGNIFICATION = 2000;
|
||||
std::map<SLuint32, AudioRenderer*> renderMap_;
|
||||
std::shared_ptr<WriteCallbackAdapter> callbackPtr_;
|
||||
std::map<SLuint32, std::shared_ptr<WriteCallbackAdapter>> callbackMap_;
|
||||
std::shared_ptr<ReadOrWriteCallbackAdapter> callbackPtr_;
|
||||
std::map<SLuint32, std::shared_ptr<ReadOrWriteCallbackAdapter>> callbackMap_;
|
||||
|
||||
void ConvertPcmFormat(SLDataFormat_PCM *slFormat, AudioRendererParams *rendererParams);
|
||||
AudioSampleFormat SlToOhosSampelFormat(SLDataFormat_PCM *pcmFormat);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <OpenSLES_OpenHarmony.h>
|
||||
#include <OpenSLES_Platform.h>
|
||||
#include <audioplayer_adapter.h>
|
||||
#include<audiocapturer_adapter.h>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <stddef.h>
|
||||
@ -49,9 +50,16 @@ struct IPlay {
|
||||
SLuint8 mId;
|
||||
};
|
||||
|
||||
struct IRecord {
|
||||
const struct SLRecordItf_ *mItf;
|
||||
SLuint32 mState;
|
||||
SLuint8 mId;
|
||||
};
|
||||
|
||||
struct IOHBufferQueue {
|
||||
const struct SLOHBufferQueueItf_ *mItf;
|
||||
SLuint32 mState;
|
||||
SLInterfaceID mIid;
|
||||
SLuint8 mId;
|
||||
};
|
||||
|
||||
@ -75,6 +83,13 @@ struct CAudioPlayer {
|
||||
SLuint32 mId;
|
||||
};
|
||||
|
||||
struct CAudioRecorder {
|
||||
IObject mObject;
|
||||
IRecord mRecord;
|
||||
IOHBufferQueue mBufferQueue;
|
||||
SLuint32 mId;
|
||||
};
|
||||
|
||||
struct COutputMix {
|
||||
IObject mObject;
|
||||
};
|
||||
@ -88,13 +103,15 @@ extern ClassTable EngineTab;
|
||||
|
||||
extern ClassTable AudioPlayerTab;
|
||||
|
||||
extern ClassTable AudioRecorderTab;
|
||||
|
||||
extern ClassTable OutputMixTab;
|
||||
|
||||
ClassTable *ObjectIdToClass(SLuint32 objectId);
|
||||
|
||||
IObject *Construct(const ClassTable *classTable, SLEngineItf itf);
|
||||
|
||||
void IOHBufferQueueInit(void *self, SLuint32 id);
|
||||
void IOHBufferQueueInit(void *self, const SLInterfaceID iid, SLuint32 id);
|
||||
|
||||
void IEngineInit(void *self);
|
||||
|
||||
@ -104,9 +121,13 @@ void IPlayInit(void *self, SLuint32 id);
|
||||
|
||||
void IVolumeInit(void *self, SLuint32 id);
|
||||
|
||||
void IRecordInit(void *self, SLuint32 id);
|
||||
|
||||
SLresult EngineDestory(void* self);
|
||||
|
||||
SLresult AudioPlayerDestroy(void* self);
|
||||
|
||||
SLresult OutputMixDestroy(void* self);
|
||||
|
||||
SLresult AudioRecorderDestroy(void *self);
|
||||
#endif
|
||||
|
@ -1,40 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef READORWRITECALLBACK_ADAPTER_H
|
||||
#define READORWRITECALLBACK_ADAPTER_H
|
||||
|
||||
#include <OpenSLES.h>
|
||||
#include <OpenSLES_Platform.h>
|
||||
#include <iostream>
|
||||
#include <audio_renderer.h>
|
||||
#include <audio_capturer.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AudioStandard {
|
||||
class ReadOrWriteCallbackAdapter : public AudioRendererWriteCallback, public AudioCapturerReadCallback {
|
||||
public:
|
||||
ReadOrWriteCallbackAdapter (SlOHBufferQueueCallback callback, SLOHBufferQueueItf itf, void *pContext);
|
||||
~ReadOrWriteCallbackAdapter();
|
||||
void OnWriteData(size_t length) override;
|
||||
void OnReadData(size_t length) override;
|
||||
|
||||
private:
|
||||
SlOHBufferQueueCallback callback_;
|
||||
SLOHBufferQueueItf itf_;
|
||||
void *context_;
|
||||
};
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
||||
#endif // READORWRITECALLBACK_ADAPTER_H
|
267
frameworks/native/opensles/src/adapter/audiocapturer_adapter.cpp
Normal file
267
frameworks/native/opensles/src/adapter/audiocapturer_adapter.cpp
Normal file
@ -0,0 +1,267 @@
|
||||
/*
|
||||
* 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 {
|
||||
AudioCapturerAdapter::AudioCapturerAdapter() { }
|
||||
|
||||
AudioCapturerAdapter::~AudioCapturerAdapter() { }
|
||||
|
||||
AudioCapturerAdapter* AudioCapturerAdapter::GetInstance()
|
||||
{
|
||||
static AudioCapturerAdapter audioCapturerAdapter_;
|
||||
return &audioCapturerAdapter_;
|
||||
}
|
||||
|
||||
AudioCapturer *AudioCapturerAdapter::GetAudioCapturerById(SLuint32 id)
|
||||
{
|
||||
AUDIO_INFO_LOG("AudioCapturerAdapter::GetAudioCapturerById: %{public}lu", id);
|
||||
return captureMap_.find(id)->second;
|
||||
}
|
||||
|
||||
void AudioCapturerAdapter::EraseAudioCapturerById(SLuint32 id)
|
||||
{
|
||||
AUDIO_INFO_LOG("AudioCapturerAdapter::EraseAudioCapturerById: %{public}lu", id);
|
||||
captureMap_.erase(id);
|
||||
callbackMap_.erase(id);
|
||||
}
|
||||
|
||||
SLresult AudioCapturerAdapter::CreateAudioCapturerAdapter(SLuint32 id, SLDataSource *dataSource,
|
||||
SLDataSink *dataSink, AudioStreamType streamType)
|
||||
{
|
||||
AUDIO_INFO_LOG("AudioCapturerAdapter::CreateAudioCapturerAdapter .");
|
||||
SLDataFormat_PCM *pcmFormat = (SLDataFormat_PCM *)dataSink->pFormat;
|
||||
AudioCapturerParams capturerParams;
|
||||
ConvertPcmFormat(pcmFormat, &capturerParams);
|
||||
streamType = AudioStreamType::STREAM_MUSIC;
|
||||
unique_ptr<AudioCapturer> capturerHolder = AudioCapturer::Create(streamType);
|
||||
capturerHolder->SetParams(capturerParams);
|
||||
AudioCapturer *capturer = capturerHolder.release();
|
||||
AUDIO_INFO_LOG("AudioCapturerAdapter::CreateAudioCapturerAdapter ID: %{public}lu", id);
|
||||
capturer->SetCaptureMode(CAPTURE_MODE_CALLBACK);
|
||||
captureMap_.insert(make_pair(id, capturer));
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
SLresult AudioCapturerAdapter::SetCaptureStateAdapter(SLuint32 id, SLuint32 state)
|
||||
{
|
||||
AudioCapturer *audioCapturer = GetAudioCapturerById(id);
|
||||
SLresult slResult = SL_RESULT_SUCCESS;
|
||||
bool reseult = false;
|
||||
switch (state) {
|
||||
case SL_RECORDSTATE_RECORDING:
|
||||
reseult = audioCapturer->Start();
|
||||
break;
|
||||
case SL_RECORDSTATE_PAUSED:
|
||||
reseult = audioCapturer->Pause();
|
||||
break;
|
||||
case SL_RECORDSTATE_STOPPED: {
|
||||
reseult = audioCapturer->Clear();
|
||||
reseult = reseult && audioCapturer->Stop();
|
||||
reseult = reseult && audioCapturer->Release();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
AUDIO_ERR_LOG("AudioPlayerAdapter::play state not supported ");
|
||||
break;
|
||||
}
|
||||
slResult = reseult ? SL_RESULT_SUCCESS : SL_RESULT_RESOURCE_ERROR;
|
||||
return slResult;
|
||||
}
|
||||
|
||||
SLresult AudioCapturerAdapter::GetCaptureStateAdapter(SLuint32 id, SLuint32 *state)
|
||||
{
|
||||
AudioCapturer *audioCapturer = GetAudioCapturerById(id);
|
||||
CapturerState capturerState = audioCapturer->GetStatus();
|
||||
switch (capturerState) {
|
||||
case CAPTURER_RUNNING:
|
||||
*state = SL_RECORDSTATE_RECORDING;
|
||||
break;
|
||||
case CAPTURER_PAUSED:
|
||||
*state = SL_RECORDSTATE_PAUSED;
|
||||
break;
|
||||
case CAPTURER_STOPPED:
|
||||
*state = SL_RECORDSTATE_STOPPED;
|
||||
break;
|
||||
default:
|
||||
*state = -1;
|
||||
break;
|
||||
}
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
SLresult AudioCapturerAdapter::EnqueueAdapter(SLuint32 id, const void *buffer, SLuint32 size)
|
||||
{
|
||||
AudioCapturer *audioCapturer = GetAudioCapturerById(id);
|
||||
BufferDesc bufDesc = {};
|
||||
bufDesc.buffer = (uint8_t*) buffer;
|
||||
bufDesc.bufLength = size;
|
||||
AUDIO_INFO_LOG("AudioCapturerAdapter::EnqueueAdapter bufferlength: %{public}zu", bufDesc.bufLength);
|
||||
audioCapturer->Enqueue(bufDesc);
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
SLresult AudioCapturerAdapter::ClearAdapter(SLuint32 id)
|
||||
{
|
||||
AudioCapturer *audioCapturer = GetAudioCapturerById(id);
|
||||
audioCapturer->Clear();
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
SLresult AudioCapturerAdapter::GetStateAdapter(SLuint32 id, SLOHBufferQueueState *state)
|
||||
{
|
||||
AudioCapturer *audioCapturer = GetAudioCapturerById(id);
|
||||
BufferQueueState queueState = {0, 0};
|
||||
audioCapturer->GetBufQueueState(queueState);
|
||||
state->count = queueState.numBuffers;
|
||||
state->index = queueState.currentIndex;
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
SLresult AudioCapturerAdapter::GetBufferAdapter(SLuint32 id, SLuint8 **buffer, SLuint32 &size)
|
||||
{
|
||||
AudioCapturer *audioCapturer = GetAudioCapturerById(id);
|
||||
BufferDesc bufferDesc = {};
|
||||
audioCapturer->GetBufferDesc(bufferDesc);
|
||||
*buffer = bufferDesc.buffer;
|
||||
size = bufferDesc.bufLength;
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
SLresult AudioCapturerAdapter::RegisterCallbackAdapter(SLOHBufferQueueItf itf,
|
||||
SlOHBufferQueueCallback callback, void *pContext)
|
||||
{
|
||||
IOHBufferQueue *thiz = (IOHBufferQueue *)itf;
|
||||
AudioCapturer *audioCapturer = GetAudioCapturerById(thiz->mId);
|
||||
callbackPtr_ = make_shared<ReadOrWriteCallbackAdapter>(callback, itf, pContext);
|
||||
audioCapturer->SetCapturerReadCallback(static_pointer_cast<AudioCapturerReadCallback>(callbackPtr_));
|
||||
callbackMap_.insert(make_pair(thiz->mId, callbackPtr_));
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void AudioCapturerAdapter::ConvertPcmFormat(SLDataFormat_PCM *slFormat, AudioCapturerParams *capturerParams)
|
||||
{
|
||||
AudioSampleFormat sampleFormat = SlToOhosSampelFormat(slFormat);
|
||||
AudioSamplingRate sampleRate = SlToOhosSamplingRate(slFormat);
|
||||
AudioChannel channelCount = SlToOhosChannel(slFormat);
|
||||
capturerParams->audioSampleFormat = sampleFormat;
|
||||
capturerParams->samplingRate = sampleRate;
|
||||
capturerParams->audioChannel = channelCount;
|
||||
capturerParams->audioEncoding = ENCODING_PCM;
|
||||
}
|
||||
|
||||
AudioSampleFormat AudioCapturerAdapter::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 AudioCapturerAdapter::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: {
|
||||
AUDIO_ERR_LOG("AudioCapturerAdapter::SlToOhosSamplingRate mismatch, use default.");
|
||||
sampleRate = SAMPLE_RATE_44100;
|
||||
}
|
||||
}
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
AudioChannel AudioCapturerAdapter::SlToOhosChannel(SLDataFormat_PCM *pcmFormat)
|
||||
{
|
||||
AudioChannel channelCount;
|
||||
switch (pcmFormat->numChannels) {
|
||||
case MONO:
|
||||
channelCount = MONO;
|
||||
break;
|
||||
case STEREO:
|
||||
channelCount = STEREO;
|
||||
break;
|
||||
default:
|
||||
channelCount = MONO;
|
||||
AUDIO_ERR_LOG("AudioPlayerAdapter::channel count not supported ");
|
||||
}
|
||||
return channelCount;
|
||||
}
|
||||
}
|
||||
}
|
@ -75,8 +75,8 @@ SLresult AudioPlayerAdapter::SetPlayStateAdapter(SLuint32 id, SLuint32 state)
|
||||
break;
|
||||
case SL_PLAYSTATE_STOPPED: {
|
||||
reseult = pRender->Clear();
|
||||
reseult = reseult & pRender->Stop();
|
||||
reseult = reseult & pRender->Release();
|
||||
reseult = reseult && pRender->Stop();
|
||||
reseult = reseult && pRender->Release();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -155,7 +155,7 @@ SLresult AudioPlayerAdapter::GetStateAdapter(SLuint32 id, SLOHBufferQueueState *
|
||||
BufferQueueState queueState = {0, 0};
|
||||
audioRenderer->GetBufQueueState(queueState);
|
||||
state->count = queueState.numBuffers;
|
||||
state->playIndex = queueState.currentIndex;
|
||||
state->index = queueState.currentIndex;
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ SLresult AudioPlayerAdapter::RegisterCallbackAdapter
|
||||
{
|
||||
IOHBufferQueue *thiz = (IOHBufferQueue *)itf;
|
||||
AudioRenderer *audioRenderer = GetAudioRenderById(thiz->mId);
|
||||
callbackPtr_ = make_shared<WriteCallbackAdapter>(callback, itf, pContext);
|
||||
callbackPtr_ = make_shared<ReadOrWriteCallbackAdapter>(callback, itf, pContext);
|
||||
audioRenderer->SetRendererWriteCallback(static_pointer_cast<AudioRendererWriteCallback>(callbackPtr_));
|
||||
callbackMap_.insert(make_pair(thiz->mId, callbackPtr_));
|
||||
return SL_RESULT_SUCCESS;
|
||||
|
@ -1,36 +1,41 @@
|
||||
/*
|
||||
* 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
|
||||
/*
|
||||
* 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 {
|
||||
ReadOrWriteCallbackAdapter::ReadOrWriteCallbackAdapter
|
||||
(SlOHBufferQueueCallback callback, SLOHBufferQueueItf itf, void *context)
|
||||
{
|
||||
callback_ = callback;
|
||||
itf_ = itf;
|
||||
context_ = context;
|
||||
}
|
||||
|
||||
ReadOrWriteCallbackAdapter::~ReadOrWriteCallbackAdapter() { }
|
||||
|
||||
void ReadOrWriteCallbackAdapter::OnWriteData(size_t length)
|
||||
{
|
||||
callback_(itf_, context_, length);
|
||||
return;
|
||||
}
|
||||
|
||||
void ReadOrWriteCallbackAdapter::OnReadData(size_t length)
|
||||
{
|
||||
callback_(itf_, context_, length);
|
||||
}
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
@ -17,7 +17,8 @@
|
||||
|
||||
using namespace OHOS::AudioStandard;
|
||||
|
||||
static SLuint32 audioplayerId = 0;
|
||||
static SLuint32 audioPlayerId = 0;
|
||||
static SLuint32 audioRecorderId = 0;
|
||||
|
||||
static SLresult CreateLEDDevice(
|
||||
SLEngineItf self, SLObjectItf *pDevice, SLuint32 deviceID, SLuint32 numInterfaces,
|
||||
@ -45,23 +46,38 @@ static SLresult CreateAudioPlayer(
|
||||
if (thiz == nullptr) {
|
||||
return SL_RESULT_PARAMETER_INVALID;
|
||||
}
|
||||
thiz->mId = audioplayerId;
|
||||
thiz->mId = audioPlayerId;
|
||||
IObjectInit(&thiz->mObject);
|
||||
IPlayInit(&thiz->mPlay, audioplayerId);
|
||||
IVolumeInit(&thiz->mVolume, audioplayerId);
|
||||
IOHBufferQueueInit(&thiz->mBufferQueue, audioplayerId);
|
||||
IPlayInit(&thiz->mPlay, audioPlayerId);
|
||||
IVolumeInit(&thiz->mVolume, audioPlayerId);
|
||||
IOHBufferQueueInit(&thiz->mBufferQueue, SL_IID_PLAY, audioPlayerId);
|
||||
*pPlayer = &thiz->mObject.mItf;
|
||||
AudioPlayerAdapter::GetInstance()->
|
||||
CreateAudioPlayerAdapter(audioplayerId, pAudioSrc, pAudioSnk, OHOS::AudioStandard::STREAM_MUSIC);
|
||||
audioplayerId++;
|
||||
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;
|
||||
if (pRecorder == nullptr) {
|
||||
return SL_RESULT_PARAMETER_INVALID;
|
||||
}
|
||||
ClassTable *audioRecorderClass = ObjectIdToClass(SL_OBJECTID_AUDIORECORDER);
|
||||
CAudioRecorder *thiz = (CAudioRecorder *) Construct(audioRecorderClass, self);
|
||||
thiz->mId = audioRecorderId;
|
||||
IObjectInit(&thiz->mObject);
|
||||
IRecordInit(&thiz->mRecord, audioRecorderId);
|
||||
IOHBufferQueueInit(&thiz->mBufferQueue, SL_IID_RECORD, audioRecorderId);
|
||||
*pRecorder = &thiz->mObject.mItf;
|
||||
AudioCapturerAdapter::GetInstance()->
|
||||
CreateAudioCapturerAdapter(audioRecorderId, pAudioSrc, pAudioSnk, OHOS::AudioStandard::STREAM_MUSIC);
|
||||
audioRecorderId++;
|
||||
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static SLresult CreateMidiPlayer(
|
||||
|
@ -60,8 +60,20 @@ static SLresult GetInterface(SLObjectItf self, const SLInterfaceID iid, void *in
|
||||
*(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);
|
||||
IObject *iObject = (IObject *)self;
|
||||
if (iObject->mClass->mObjectId == SL_OBJECTID_AUDIOPLAYER) {
|
||||
CAudioPlayer *cAudioPlayer = (CAudioPlayer *)iObject;
|
||||
*(void **)interface = (void *)&(cAudioPlayer->mBufferQueue.mItf);
|
||||
} else if (iObject->mClass->mObjectId == SL_OBJECTID_AUDIORECORDER) {
|
||||
CAudioRecorder *cAudioRecorder = (CAudioRecorder *)iObject;
|
||||
*(void **)interface = (void *)&(cAudioRecorder->mBufferQueue.mItf);
|
||||
} else {
|
||||
return SL_RESULT_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
return SL_RESULT_SUCCESS;
|
||||
} else if (iid == SL_IID_RECORD) {
|
||||
CAudioRecorder *cAudioRecorder = (CAudioRecorder *)self;
|
||||
*(void **)interface = (void *)&(cAudioRecorder->mRecord.mItf);
|
||||
return SL_RESULT_SUCCESS;
|
||||
} else {
|
||||
AUDIO_ERR_LOG("GetInterface: SLInterfaceID not supported");
|
||||
@ -112,6 +124,9 @@ void Destroy(SLObjectItf self)
|
||||
case SL_OBJECTID_OUTPUTMIX:
|
||||
OutputMixDestroy((void *)self);
|
||||
break;
|
||||
case SL_OBJECTID_AUDIORECORDER:
|
||||
AudioRecorderDestroy((void *)self);
|
||||
break;
|
||||
default:
|
||||
AUDIO_ERR_LOG("objectId not supported");
|
||||
break;
|
||||
|
@ -23,7 +23,12 @@ SLresult Enqueue(SLOHBufferQueueItf self, const void *buffer, SLuint32 size)
|
||||
return SL_RESULT_PARAMETER_INVALID;
|
||||
}
|
||||
IOHBufferQueue *thiz = (IOHBufferQueue *)self;
|
||||
AudioPlayerAdapter::GetInstance()->EnqueueAdapter(thiz->mId, buffer, size);
|
||||
if (thiz->mIid == SL_IID_PLAY) {
|
||||
AudioPlayerAdapter::GetInstance()->EnqueueAdapter(thiz->mId, buffer, size);
|
||||
} else if (thiz->mIid == SL_IID_RECORD) {
|
||||
AudioCapturerAdapter::GetInstance()->EnqueueAdapter(thiz->mId, buffer, size);
|
||||
}
|
||||
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -33,7 +38,12 @@ SLresult Clear(SLOHBufferQueueItf self)
|
||||
return SL_RESULT_PARAMETER_INVALID;
|
||||
}
|
||||
IOHBufferQueue *thiz = (IOHBufferQueue *)self;
|
||||
AudioPlayerAdapter::GetInstance()->ClearAdapter(thiz->mId);
|
||||
if (thiz->mIid == SL_IID_PLAY) {
|
||||
AudioPlayerAdapter::GetInstance()->ClearAdapter(thiz->mId);
|
||||
} else if (thiz->mIid == SL_IID_RECORD) {
|
||||
AudioCapturerAdapter::GetInstance()->ClearAdapter(thiz->mId);
|
||||
}
|
||||
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -43,7 +53,12 @@ SLresult GetState(SLOHBufferQueueItf self, SLOHBufferQueueState *state)
|
||||
return SL_RESULT_PARAMETER_INVALID;
|
||||
}
|
||||
IOHBufferQueue *thiz = (IOHBufferQueue *)self;
|
||||
AudioPlayerAdapter::GetInstance()->GetStateAdapter(thiz->mId, state);
|
||||
if (thiz->mIid == SL_IID_PLAY) {
|
||||
AudioPlayerAdapter::GetInstance()->GetStateAdapter(thiz->mId, state);
|
||||
} else if (thiz->mIid == SL_IID_RECORD) {
|
||||
AudioCapturerAdapter::GetInstance()->GetStateAdapter(thiz->mId, state);
|
||||
}
|
||||
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -53,17 +68,25 @@ SLresult GetBuffer(SLOHBufferQueueItf self, SLuint8 **buffer, SLuint32 &size)
|
||||
return SL_RESULT_PARAMETER_INVALID;
|
||||
}
|
||||
IOHBufferQueue *thiz = (IOHBufferQueue *)self;
|
||||
AudioPlayerAdapter::GetInstance()->GetBufferAdapter(thiz->mId, buffer, size);
|
||||
if (thiz->mIid == SL_IID_PLAY) {
|
||||
AudioPlayerAdapter::GetInstance()->GetBufferAdapter(thiz->mId, buffer, size);
|
||||
} else if (thiz->mIid == SL_IID_RECORD) {
|
||||
AudioCapturerAdapter::GetInstance()->GetBufferAdapter(thiz->mId, buffer, size);
|
||||
}
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
SLresult RegisterCallback(SLOHBufferQueueItf self,
|
||||
SlOHBufferQueueCallback callback, void *pContext)
|
||||
SLresult RegisterCallback(SLOHBufferQueueItf self, SlOHBufferQueueCallback callback, void *pContext)
|
||||
{
|
||||
if (self == nullptr || callback == nullptr) {
|
||||
return SL_RESULT_PARAMETER_INVALID;
|
||||
}
|
||||
AudioPlayerAdapter::GetInstance()->RegisterCallbackAdapter(self, callback, pContext);
|
||||
IOHBufferQueue *thiz = (IOHBufferQueue *)self;
|
||||
if (thiz->mIid == SL_IID_PLAY) {
|
||||
AudioPlayerAdapter::GetInstance()->RegisterCallbackAdapter(self, callback, pContext);
|
||||
} else if (thiz->mIid == SL_IID_RECORD) {
|
||||
AudioCapturerAdapter::GetInstance()->RegisterCallbackAdapter(self, callback, pContext);
|
||||
}
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -75,10 +98,15 @@ static const struct SLOHBufferQueueItf_ IOHBufferQueueItf = {
|
||||
RegisterCallback
|
||||
};
|
||||
|
||||
void IOHBufferQueueInit(void *self, SLuint32 id)
|
||||
void IOHBufferQueueInit(void *self, const SLInterfaceID iid, SLuint32 id)
|
||||
{
|
||||
IOHBufferQueue *thiz = (IOHBufferQueue *) self;
|
||||
thiz->mItf = &IOHBufferQueueItf;
|
||||
thiz->mIid = iid;
|
||||
thiz->mId = id;
|
||||
thiz->mState = SL_PLAYSTATE_STOPPED;
|
||||
if (thiz->mIid == SL_IID_PLAY) {
|
||||
thiz->mState = SL_PLAYSTATE_STOPPED;
|
||||
} else if (thiz->mIid == SL_IID_RECORD) {
|
||||
thiz->mState = SL_RECORDSTATE_STOPPED;
|
||||
}
|
||||
}
|
||||
|
111
frameworks/native/opensles/src/itf/record_itf.cpp
Normal file
111
frameworks/native/opensles/src/itf/record_itf.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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 SetRecordState(SLRecordItf self, SLuint32 state)
|
||||
{
|
||||
if (self == nullptr) {
|
||||
return SL_RESULT_PARAMETER_INVALID;
|
||||
}
|
||||
IRecord *thiz = (IRecord *)self;
|
||||
AudioCapturerAdapter::GetInstance()->SetCaptureStateAdapter(thiz->mId, state);
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static SLresult GetRecordState(SLRecordItf self, SLuint32 *pState)
|
||||
{
|
||||
if (self == nullptr) {
|
||||
return SL_RESULT_PARAMETER_INVALID;
|
||||
}
|
||||
IRecord *thiz = (IRecord *)self;
|
||||
AudioCapturerAdapter::GetInstance()->GetCaptureStateAdapter(thiz->mId, pState);
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static SLresult SetDurationLimit(SLRecordItf self, SLmillisecond msec)
|
||||
{
|
||||
return SL_RESULT_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static SLresult GetPosition(SLRecordItf self, SLmillisecond *pMsec)
|
||||
{
|
||||
return SL_RESULT_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static SLresult RegisterCallback(SLRecordItf self, slRecordCallback callback, void *pContext)
|
||||
{
|
||||
return SL_RESULT_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static SLresult SetCallbackEventsMask(SLRecordItf self, SLuint32 eventFlags)
|
||||
{
|
||||
return SL_RESULT_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static SLresult GetCallbackEventsMask(SLRecordItf self, SLuint32 *pEventFlags)
|
||||
{
|
||||
return SL_RESULT_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static SLresult SetMarkerPosition(SLRecordItf self, SLmillisecond mSec)
|
||||
{
|
||||
return SL_RESULT_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static SLresult ClearMarkerPosition(SLRecordItf self)
|
||||
{
|
||||
return SL_RESULT_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static SLresult GetMarkerPosition(SLRecordItf self, SLmillisecond *pMsec)
|
||||
{
|
||||
return SL_RESULT_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static SLresult SetPositionUpdatePeriod(SLRecordItf self, SLmillisecond mSec)
|
||||
{
|
||||
return SL_RESULT_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static SLresult GetPositionUpdatePeriod(SLRecordItf self, SLmillisecond *pMsec)
|
||||
{
|
||||
return SL_RESULT_FEATURE_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static const struct SLRecordItf_ RecordItf = {
|
||||
SetRecordState,
|
||||
GetRecordState,
|
||||
SetDurationLimit,
|
||||
GetPosition,
|
||||
RegisterCallback,
|
||||
SetCallbackEventsMask,
|
||||
GetCallbackEventsMask,
|
||||
SetMarkerPosition,
|
||||
ClearMarkerPosition,
|
||||
GetMarkerPosition,
|
||||
SetPositionUpdatePeriod,
|
||||
GetPositionUpdatePeriod
|
||||
};
|
||||
|
||||
void IRecordInit(void *self, SLuint32 id)
|
||||
{
|
||||
IRecord *thiz = (IRecord *)self;
|
||||
thiz->mItf = &RecordItf;
|
||||
thiz->mState = SL_RECORDSTATE_STOPPED;
|
||||
thiz->mId = id;
|
||||
}
|
28
frameworks/native/opensles/src/obj/audiocapturer_obj.cpp
Normal file
28
frameworks/native/opensles/src/obj/audiocapturer_obj.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 AudioRecorderDestroy(void *self)
|
||||
{
|
||||
if (self == nullptr) {
|
||||
return SL_RESULT_PARAMETER_INVALID;
|
||||
}
|
||||
CAudioRecorder *cAudioRecorder = (CAudioRecorder *)self;
|
||||
AudioCapturerAdapter::GetInstance()->EraseAudioCapturerById(cAudioRecorder->mId);
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
@ -40,6 +40,8 @@ ClassTable *ObjectIdToClass(SLuint32 objectId)
|
||||
classTable = (ClassTable *) &EngineTab;
|
||||
} else if (objectId == SL_OBJECTID_AUDIOPLAYER) {
|
||||
classTable = (ClassTable *) &AudioPlayerTab;
|
||||
} else if (objectId == SL_OBJECTID_AUDIORECORDER) {
|
||||
classTable = (ClassTable *) &AudioRecorderTab;
|
||||
} else if (objectId == SL_OBJECTID_OUTPUTMIX) {
|
||||
classTable = (ClassTable *) &OutputMixTab;
|
||||
}
|
||||
|
@ -29,3 +29,8 @@ ClassTable OutputMixTab = {
|
||||
SL_OBJECTID_OUTPUTMIX,
|
||||
sizeof(CAudioPlayer),
|
||||
};
|
||||
|
||||
ClassTable AudioRecorderTab = {
|
||||
SL_OBJECTID_AUDIORECORDER,
|
||||
sizeof(CAudioRecorder),
|
||||
};
|
@ -56,7 +56,9 @@ enum CapturerState {
|
||||
/** Capturer Stopped state */
|
||||
CAPTURER_STOPPED,
|
||||
/** Capturer Released state */
|
||||
CAPTURER_RELEASED
|
||||
CAPTURER_RELEASED,
|
||||
/** Capturer Paused state */
|
||||
CAPTURER_PAUSED
|
||||
};
|
||||
|
||||
class AudioCapturerCallback {
|
||||
@ -95,6 +97,18 @@ public:
|
||||
virtual void OnPeriodReached(const int64_t &frameNumber) = 0;
|
||||
};
|
||||
|
||||
class AudioCapturerReadCallback {
|
||||
public:
|
||||
virtual ~AudioCapturerReadCallback() = default;
|
||||
|
||||
/**
|
||||
* Called when buffer to be enqueued.
|
||||
*
|
||||
* @param length Indicates requested buffer length.
|
||||
*/
|
||||
virtual void OnReadData(size_t length) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Provides functions for applications to implement audio capturing.
|
||||
*/
|
||||
@ -219,6 +233,8 @@ public:
|
||||
*/
|
||||
virtual bool GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base) const = 0;
|
||||
|
||||
virtual bool Pause() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Stops audio capturing.
|
||||
*
|
||||
@ -334,6 +350,72 @@ public:
|
||||
*/
|
||||
static std::vector<AudioSamplingRate> GetSupportedSamplingRates();
|
||||
|
||||
/**
|
||||
* @brief Sets the capture mode. By default the mode is CAPTURE_MODE_NORMAL.
|
||||
* This API is needs to be used only if CAPTURE_MODE_CALLBACK is required.
|
||||
*
|
||||
* * @param captureMode The mode of capture.
|
||||
* @return Returns {@link SUCCESS} if capture mode is successfully set; returns an error code
|
||||
* defined in {@link audio_errors.h} otherwise.
|
||||
*/
|
||||
virtual int32_t SetCaptureMode(AudioCaptureMode captureMode) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Obtains the capture mode.
|
||||
*
|
||||
* @return Returns current capture mode.
|
||||
*/
|
||||
virtual AudioCaptureMode GetCaptureMode() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Registers the capturer read callback listener.
|
||||
* This API should only be used if CAPTURE_MODE_CALLBACK is needed.
|
||||
*
|
||||
* @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
|
||||
* defined in {@link audio_errors.h} otherwise.
|
||||
*/
|
||||
virtual int32_t SetCapturerReadCallback(const std::shared_ptr<AudioCapturerReadCallback> &callback) = 0;
|
||||
|
||||
/**
|
||||
* @brief Gets the BufferDesc to read the data.
|
||||
* This API should only be used if CAPTURE_MODE_CALLBACK is needed.
|
||||
*
|
||||
* @param bufDesc Indicates the buffer descriptor from which data will be read.
|
||||
* refer BufferQueueState in audio_info.h.
|
||||
* @return Returns {@link SUCCESS} if bufDesc is successfully obtained; returns an error code
|
||||
* defined in {@link audio_errors.h} otherwise.
|
||||
*/
|
||||
virtual int32_t GetBufferDesc(BufferDesc &bufDesc) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Enqueues used buffer to the bufferQueue for recording new data.
|
||||
* This API should only be used if CAPTURE_MODE_CALLBACK is needed.
|
||||
*
|
||||
* @return Returns {@link SUCCESS} if bufDesc is successfully enqueued; returns an error code
|
||||
* defined in {@link audio_errors.h} otherwise.
|
||||
*/
|
||||
virtual int32_t Enqueue(const BufferDesc &bufDesc) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Clears the bufferQueue.
|
||||
* This API should only be used if CAPTURE_MODE_CALLBACK is needed.
|
||||
*
|
||||
* @return Returns {@link SUCCESS} if successful; returns an error code
|
||||
* defined in {@link audio_errors.h} otherwise.
|
||||
*/
|
||||
virtual int32_t Clear() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Obtains the current state of bufferQueue.
|
||||
* This API should only be used if CAPTURE_MODE_CALLBACK is needed.
|
||||
*
|
||||
* @param bufDesc Indicates the bufState reference in which state will be obtained.
|
||||
* refer BufferQueueState in audio_info.h.
|
||||
* @return Returns {@link SUCCESS} if bufState is successfully obtained; returns an error code
|
||||
* defined in {@link audio_errors.h} otherwise.
|
||||
*/
|
||||
virtual int32_t GetBufQueueState(BufferQueueState &bufState) const = 0;
|
||||
|
||||
virtual ~AudioCapturer();
|
||||
};
|
||||
} // namespace AudioStandard
|
||||
|
@ -498,6 +498,11 @@ enum AudioRenderMode {
|
||||
RENDER_MODE_CALLBACK
|
||||
};
|
||||
|
||||
enum AudioCaptureMode {
|
||||
CAPTURE_MODE_NORMAL,
|
||||
CAPTURE_MODE_CALLBACK
|
||||
};
|
||||
|
||||
typedef uint32_t AudioIOHandle;
|
||||
|
||||
static inline bool FLOAT_COMPARE_EQ(const float& x, const float& y)
|
||||
|
@ -16,10 +16,12 @@ import("//build/ohos.gni")
|
||||
pulseaudio_dir = "//third_party/pulseaudio"
|
||||
opensles_dir = "//third_party/openSLES"
|
||||
|
||||
config("audio_renderer_config") {
|
||||
config("audio_operation_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/audiocapturer/include",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/audiocapturer/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",
|
||||
@ -52,7 +54,28 @@ ohos_executable("audio_opensles_test") {
|
||||
|
||||
configs = [
|
||||
":audio_opensles_config",
|
||||
":audio_renderer_config",
|
||||
":audio_operation_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/multimedia/audio_standard:libsl",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/opensles:opensles",
|
||||
]
|
||||
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
|
||||
part_name = "multimedia_audio_standard"
|
||||
subsystem_name = "multimedia"
|
||||
}
|
||||
|
||||
ohos_executable("audio_opensles_capture_test") {
|
||||
install_enable = false
|
||||
|
||||
sources = [ "//foundation/multimedia/audio_standard/services/test/audio_opensles_capture_test.cpp" ]
|
||||
|
||||
configs = [
|
||||
":audio_opensles_config",
|
||||
":audio_operation_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
|
@ -478,7 +478,9 @@ public:
|
||||
* defined in {@link audio_errors.h} otherwise.
|
||||
*/
|
||||
int32_t SaveWriteCallback(const std::weak_ptr<AudioRendererWriteCallback> &callback);
|
||||
|
||||
int32_t SetAudioCaptureMode(AudioCaptureMode captureMode);
|
||||
int32_t SaveReadCallback(const std::weak_ptr<AudioCapturerReadCallback> &callback);
|
||||
AudioCaptureMode GetAudioCaptureMode();
|
||||
/**
|
||||
* @brief Set the applicationcache path to access the application resources
|
||||
*
|
||||
@ -526,6 +528,8 @@ private:
|
||||
AudioRendererRate renderRate;
|
||||
AudioRenderMode renderMode_;
|
||||
std::weak_ptr<AudioRendererWriteCallback> writeCallback_;
|
||||
AudioCaptureMode captureMode_;
|
||||
std::weak_ptr<AudioCapturerReadCallback> readCallback_;
|
||||
|
||||
uint32_t mFrameSize = 0;
|
||||
bool mMarkReached = false;
|
||||
|
@ -225,12 +225,6 @@ void AudioServiceClient::PAStreamFlushSuccessCb(pa_stream *stream, int32_t succe
|
||||
pa_threaded_mainloop_signal(mainLoop, 0);
|
||||
}
|
||||
|
||||
void AudioServiceClient::PAStreamReadCb(pa_stream *stream, size_t length, void *userdata)
|
||||
{
|
||||
pa_threaded_mainloop *mainLoop = (pa_threaded_mainloop *)userdata;
|
||||
pa_threaded_mainloop_signal(mainLoop, 0);
|
||||
}
|
||||
|
||||
void AudioServiceClient::PAStreamSetBufAttrSuccessCb(pa_stream *stream, int32_t success, void *userdata)
|
||||
{
|
||||
if (!userdata) {
|
||||
@ -287,6 +281,19 @@ AudioRenderMode AudioServiceClient::GetAudioRenderMode()
|
||||
return renderMode_;
|
||||
}
|
||||
|
||||
int32_t AudioServiceClient::SetAudioCaptureMode(AudioCaptureMode captureMode)
|
||||
{
|
||||
AUDIO_DEBUG_LOG("AudioServiceClient::SetAudioCaptureMode.");
|
||||
captureMode_ = captureMode;
|
||||
|
||||
return AUDIO_CLIENT_SUCCESS;
|
||||
}
|
||||
|
||||
AudioCaptureMode AudioServiceClient::GetAudioCaptureMode()
|
||||
{
|
||||
return captureMode_;
|
||||
}
|
||||
|
||||
int32_t AudioServiceClient::SaveWriteCallback(const std::weak_ptr<AudioRendererWriteCallback> &callback)
|
||||
{
|
||||
if (callback.lock() == nullptr) {
|
||||
@ -298,6 +305,17 @@ int32_t AudioServiceClient::SaveWriteCallback(const std::weak_ptr<AudioRendererW
|
||||
return AUDIO_CLIENT_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t AudioServiceClient::SaveReadCallback(const std::weak_ptr<AudioCapturerReadCallback> &callback)
|
||||
{
|
||||
if (callback.lock() == nullptr) {
|
||||
AUDIO_ERR_LOG("AudioServiceClient::SaveReadCallback callback == nullptr");
|
||||
return AUDIO_CLIENT_INIT_ERR;
|
||||
}
|
||||
readCallback_ = callback;
|
||||
|
||||
return AUDIO_CLIENT_SUCCESS;
|
||||
}
|
||||
|
||||
void AudioServiceClient::PAStreamWriteCb(pa_stream *stream, size_t length, void *userdata)
|
||||
{
|
||||
AUDIO_INFO_LOG("AudioServiceClient::Inside PA write callback");
|
||||
@ -326,6 +344,33 @@ void AudioServiceClient::PAStreamWriteCb(pa_stream *stream, size_t length, void
|
||||
}
|
||||
}
|
||||
|
||||
void AudioServiceClient::PAStreamReadCb(pa_stream *stream, size_t length, void *userdata)
|
||||
{
|
||||
AUDIO_INFO_LOG("AudioServiceClient::PAStreamReadCb Inside PA read callback");
|
||||
if (!userdata) {
|
||||
AUDIO_ERR_LOG("AudioServiceClient::PAStreamReadCb: userdata is null");
|
||||
return;
|
||||
}
|
||||
auto asClient = static_cast<AudioServiceClient *>(userdata);
|
||||
auto mainLoop = static_cast<pa_threaded_mainloop *>(asClient->mainLoop);
|
||||
pa_threaded_mainloop_signal(mainLoop, 0);
|
||||
|
||||
if (asClient->captureMode_ != CAPTURE_MODE_CALLBACK) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<AudioCapturerReadCallback> cb = asClient->readCallback_.lock();
|
||||
if (cb != nullptr) {
|
||||
size_t requestSize;
|
||||
asClient->GetMinimumBufferSize(requestSize);
|
||||
AUDIO_INFO_LOG("AudioServiceClient::PAStreamReadCb: cb != nullptr firing OnReadData");
|
||||
AUDIO_INFO_LOG("AudioServiceClient::OnReadData requestSize : %{public}zu", requestSize);
|
||||
cb->OnReadData(requestSize);
|
||||
} else {
|
||||
AUDIO_ERR_LOG("AudioServiceClient::PAStreamReadCb: cb == nullptr not firing OnReadData");
|
||||
}
|
||||
}
|
||||
|
||||
void AudioServiceClient::PAStreamUnderFlowCb(pa_stream *stream, void *userdata)
|
||||
{
|
||||
if (!userdata) {
|
||||
@ -417,6 +462,8 @@ AudioServiceClient::AudioServiceClient()
|
||||
renderRate = RENDER_RATE_NORMAL;
|
||||
renderMode_ = RENDER_MODE_NORMAL;
|
||||
|
||||
captureMode_ = CAPTURE_MODE_NORMAL;
|
||||
|
||||
eAudioClientType = AUDIO_SERVICE_CLIENT_PLAYBACK;
|
||||
|
||||
mFrameSize = 0;
|
||||
@ -838,7 +885,7 @@ int32_t AudioServiceClient::CreateStream(AudioStreamParams audioParams, AudioStr
|
||||
pa_proplist_free(propList);
|
||||
pa_stream_set_state_callback(paStream, PAStreamStateCb, (void *)this);
|
||||
pa_stream_set_write_callback(paStream, PAStreamWriteCb, (void *)this);
|
||||
pa_stream_set_read_callback(paStream, PAStreamReadCb, mainLoop);
|
||||
pa_stream_set_read_callback(paStream, PAStreamReadCb, (void *)this);
|
||||
pa_stream_set_latency_update_callback(paStream, PAStreamLatencyUpdateCb, mainLoop);
|
||||
pa_stream_set_underflow_callback(paStream, PAStreamUnderFlowCb, (void *)this);
|
||||
|
||||
|
@ -33,6 +33,7 @@ const unsigned long long TIME_CONVERSION_NS_S = 1000000000ULL; /* ns to s */
|
||||
constexpr int32_t WRITE_RETRY_DELAY_IN_US = 500;
|
||||
constexpr int32_t READ_WRITE_WAIT_TIME_IN_US = 500;
|
||||
constexpr int32_t CB_WRITE_BUFFERS_WAIT_IN_US = 500;
|
||||
constexpr int32_t CB_READ_BUFFERS_WAIT_IN_US = 500;
|
||||
|
||||
const map<pair<ContentType, StreamUsage>, AudioStreamType> AudioStream::streamTypeMap_ = AudioStream::CreateStreamMap();
|
||||
|
||||
@ -87,7 +88,9 @@ AudioStream::AudioStream(AudioStreamType eStreamType, AudioMode eMode) : eStream
|
||||
resetTime_(false),
|
||||
resetTimestamp_(0),
|
||||
renderMode_(RENDER_MODE_NORMAL),
|
||||
captureMode_(CAPTURE_MODE_NORMAL),
|
||||
isReadyToWrite_(false),
|
||||
isReadyToRead_(false),
|
||||
isFirstRead_(false)
|
||||
{
|
||||
AUDIO_DEBUG_LOG("AudioStream ctor");
|
||||
@ -96,10 +99,16 @@ AudioStream::AudioStream(AudioStreamType eStreamType, AudioMode eMode) : eStream
|
||||
AudioStream::~AudioStream()
|
||||
{
|
||||
isReadyToWrite_ = false;
|
||||
isReadyToRead_ = false;
|
||||
|
||||
if (writeThread_ && writeThread_->joinable()) {
|
||||
writeThread_->join();
|
||||
}
|
||||
|
||||
if (readThread_ && readThread_->joinable()) {
|
||||
readThread_->join();
|
||||
}
|
||||
|
||||
if (state_ != RELEASED && state_ != NEW) {
|
||||
ReleaseAudioStream();
|
||||
}
|
||||
@ -313,6 +322,9 @@ bool AudioStream::StartAudioStream()
|
||||
if (renderMode_ == RENDER_MODE_CALLBACK) {
|
||||
isReadyToWrite_ = true;
|
||||
writeThread_ = std::make_unique<std::thread>(&AudioStream::WriteBuffers, this);
|
||||
} else if (captureMode_ == CAPTURE_MODE_CALLBACK) {
|
||||
isReadyToRead_ = true;
|
||||
readThread_ = std::make_unique<std::thread>(&AudioStream::ReadBuffers, this);
|
||||
}
|
||||
|
||||
isFirstRead_ = true;
|
||||
@ -393,6 +405,12 @@ bool AudioStream::PauseAudioStream()
|
||||
}
|
||||
State oldState = state_;
|
||||
state_ = PAUSED; // Set it before stopping as Read/Write and Stop can be called from different threads
|
||||
if (captureMode_ == CAPTURE_MODE_CALLBACK) {
|
||||
isReadyToRead_ = false;
|
||||
if (readThread_ && readThread_->joinable()) {
|
||||
readThread_->join();
|
||||
}
|
||||
}
|
||||
while (isReadInProgress_ || isWriteInProgress_) {
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(READ_WRITE_WAIT_TIME_IN_US));
|
||||
}
|
||||
@ -429,6 +447,12 @@ bool AudioStream::StopAudioStream()
|
||||
}
|
||||
State oldState = state_;
|
||||
state_ = STOPPED; // Set it before stopping as Read/Write and Stop can be called from different threads
|
||||
if (captureMode_ == CAPTURE_MODE_CALLBACK) {
|
||||
isReadyToRead_ = false;
|
||||
if (readThread_ && readThread_->joinable()) {
|
||||
readThread_->join();
|
||||
}
|
||||
}
|
||||
while (isReadInProgress_ || isWriteInProgress_) {
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(READ_WRITE_WAIT_TIME_IN_US));
|
||||
}
|
||||
@ -588,6 +612,40 @@ AudioRenderMode AudioStream::GetRenderMode()
|
||||
return GetAudioRenderMode();
|
||||
}
|
||||
|
||||
int32_t AudioStream::SetCaptureMode(AudioCaptureMode captureMode)
|
||||
{
|
||||
int32_t ret = SetAudioCaptureMode(captureMode);
|
||||
if (ret) {
|
||||
AUDIO_ERR_LOG("AudioStream::SetCaptureMode: captureMode: %{public}d failed", captureMode);
|
||||
return ERR_OPERATION_FAILED;
|
||||
}
|
||||
captureMode_ = captureMode;
|
||||
|
||||
for (int32_t i = 0; i < MAX_NUM_BUFFERS; ++i) {
|
||||
size_t length;
|
||||
GetMinimumBufferSize(length);
|
||||
AUDIO_INFO_LOG("AudioStream::SetCaptureMode: length %{public}zu", length);
|
||||
|
||||
bufferPool_[i] = std::make_unique<uint8_t[]>(length);
|
||||
if (bufferPool_[i] == nullptr) {
|
||||
AUDIO_INFO_LOG("AudioStream::SetCaptureMode bufferPool_[i]==nullptr. Allocate memory failed.");
|
||||
return ERR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
BufferDesc bufDesc {};
|
||||
bufDesc.buffer = bufferPool_[i].get();
|
||||
bufDesc.bufLength = length;
|
||||
freeBufferQ_.emplace(bufDesc);
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
AudioCaptureMode AudioStream::GetCaptureMode()
|
||||
{
|
||||
return GetAudioCaptureMode();
|
||||
}
|
||||
|
||||
int32_t AudioStream::SetRendererWriteCallback(const std::shared_ptr<AudioRendererWriteCallback> &callback)
|
||||
{
|
||||
if (renderMode_ != RENDER_MODE_CALLBACK) {
|
||||
@ -604,37 +662,64 @@ int32_t AudioStream::SetRendererWriteCallback(const std::shared_ptr<AudioRendere
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t AudioStream::SetCapturerReadCallback(const std::shared_ptr<AudioCapturerReadCallback> &callback)
|
||||
{
|
||||
if (captureMode_ != CAPTURE_MODE_CALLBACK) {
|
||||
AUDIO_ERR_LOG("AudioStream::SetCapturerReadCallback not supported. Capture mode is not callback.");
|
||||
return ERR_INCORRECT_MODE;
|
||||
}
|
||||
|
||||
int32_t ret = SaveReadCallback(callback);
|
||||
if (ret) {
|
||||
AUDIO_ERR_LOG("AudioStream::SetCapturerReadCallback: failed.");
|
||||
return ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t AudioStream::GetBufferDesc(BufferDesc &bufDesc)
|
||||
{
|
||||
if (renderMode_ != RENDER_MODE_CALLBACK) {
|
||||
AUDIO_ERR_LOG("AudioStream::GetBufferDesc not supported. Render mode is not callback.");
|
||||
if ((renderMode_ != RENDER_MODE_CALLBACK) && (captureMode_ != CAPTURE_MODE_CALLBACK)) {
|
||||
AUDIO_ERR_LOG("AudioStream::GetBufferDesc not supported. Render or Capture mode is not callback.");
|
||||
return ERR_INCORRECT_MODE;
|
||||
}
|
||||
|
||||
AUDIO_INFO_LOG("AudioStream::freeBufferQ_ count %{public}zu", freeBufferQ_.size());
|
||||
AUDIO_INFO_LOG("AudioStream::filledBufferQ_ count %{public}zu", filledBufferQ_.size());
|
||||
|
||||
if (!freeBufferQ_.empty()) {
|
||||
bufDesc.buffer = freeBufferQ_.front().buffer;
|
||||
bufDesc.bufLength = freeBufferQ_.front().bufLength;
|
||||
freeBufferQ_.pop();
|
||||
} else {
|
||||
bufDesc.buffer = nullptr;
|
||||
if (renderMode_ == RENDER_MODE_CALLBACK) {
|
||||
if (!freeBufferQ_.empty()) {
|
||||
bufDesc.buffer = freeBufferQ_.front().buffer;
|
||||
bufDesc.bufLength = freeBufferQ_.front().bufLength;
|
||||
freeBufferQ_.pop();
|
||||
} else {
|
||||
bufDesc.buffer = nullptr;
|
||||
AUDIO_INFO_LOG("AudioStream::GetBufferDesc freeBufferQ_.empty()");
|
||||
return ERR_OPERATION_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (bufDesc.buffer == nullptr) {
|
||||
AUDIO_INFO_LOG("AudioStream::GetBufferDesc freeBufferQ_.empty()");
|
||||
return ERR_OPERATION_FAILED;
|
||||
if (captureMode_ == CAPTURE_MODE_CALLBACK) {
|
||||
if (!filledBufferQ_.empty()) {
|
||||
bufDesc.buffer = filledBufferQ_.front().buffer;
|
||||
bufDesc.bufLength = filledBufferQ_.front().bufLength;
|
||||
bufDesc.dataLength = filledBufferQ_.front().dataLength;
|
||||
filledBufferQ_.pop();
|
||||
} else {
|
||||
bufDesc.buffer = nullptr;
|
||||
AUDIO_INFO_LOG("AudioStream::GetBufferDesc filledBufferQ_.empty()");
|
||||
return ERR_OPERATION_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t AudioStream::Enqueue(const BufferDesc &bufDesc)
|
||||
{
|
||||
AUDIO_INFO_LOG("AudioStream::Enqueue");
|
||||
if (renderMode_ != RENDER_MODE_CALLBACK) {
|
||||
AUDIO_ERR_LOG("AudioStream::Enqueue not supported. Render mode is not callback.");
|
||||
if ((renderMode_ != RENDER_MODE_CALLBACK) && (captureMode_ != CAPTURE_MODE_CALLBACK)) {
|
||||
AUDIO_ERR_LOG("AudioStream::Enqueue not supported. Render or capture mode is not callback.");
|
||||
return ERR_INCORRECT_MODE;
|
||||
}
|
||||
|
||||
@ -642,15 +727,24 @@ int32_t AudioStream::Enqueue(const BufferDesc &bufDesc)
|
||||
AUDIO_ERR_LOG("AudioStream::Enqueue: failed. bufDesc.buffer == nullptr.");
|
||||
return ERR_INVALID_PARAM;
|
||||
}
|
||||
filledBufferQ_.emplace(bufDesc);
|
||||
|
||||
if (renderMode_ == RENDER_MODE_CALLBACK) {
|
||||
AUDIO_INFO_LOG("AudioStream::Enqueue: filledBuffer length: %{public}zu.", bufDesc.bufLength);
|
||||
filledBufferQ_.emplace(bufDesc);
|
||||
}
|
||||
|
||||
if (captureMode_ == CAPTURE_MODE_CALLBACK) {
|
||||
AUDIO_INFO_LOG("AudioStream::Enqueue: freeBuffer length: %{public}zu.", bufDesc.bufLength);
|
||||
freeBufferQ_.emplace(bufDesc);
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t AudioStream::Clear()
|
||||
{
|
||||
if (renderMode_ != RENDER_MODE_CALLBACK) {
|
||||
AUDIO_ERR_LOG("AudioStream::Clear not supported. Render mode is not callback.");
|
||||
if ((renderMode_ != RENDER_MODE_CALLBACK) && (captureMode_ != CAPTURE_MODE_CALLBACK)) {
|
||||
AUDIO_ERR_LOG("AudioStream::Clear not supported. Render or capture mode is not callback.");
|
||||
return ERR_INCORRECT_MODE;
|
||||
}
|
||||
|
||||
@ -680,20 +774,60 @@ void AudioStream::WriteBuffers()
|
||||
stream.buffer = filledBufferQ_.front().buffer;
|
||||
stream.bufferLen = filledBufferQ_.front().dataLength;
|
||||
AUDIO_DEBUG_LOG("AudioStream::WriteBuffers stream.bufferLen:%{public}d", stream.bufferLen);
|
||||
freeBufferQ_.emplace(filledBufferQ_.front());
|
||||
filledBufferQ_.pop();
|
||||
if (stream.buffer == nullptr) {
|
||||
continue;
|
||||
AUDIO_ERR_LOG("AudioStream::WriteBuffers stream.buffer == nullptr return");
|
||||
return;
|
||||
}
|
||||
bytesWritten = WriteStreamInCb(stream, writeError);
|
||||
if (writeError != 0) {
|
||||
AUDIO_ERR_LOG("AudioStream::WriteStreamInCb fail, writeError:%{public}d", writeError);
|
||||
} else {
|
||||
AUDIO_INFO_LOG("AudioStream::WriteBuffers WriteStream, bytesWritten:%{public}zu", bytesWritten);
|
||||
freeBufferQ_.emplace(filledBufferQ_.front());
|
||||
filledBufferQ_.pop();
|
||||
}
|
||||
AUDIO_INFO_LOG("AudioStream::WriteBuffers WriteStream, bytesWritten:%{public}zu", bytesWritten);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(CB_WRITE_BUFFERS_WAIT_IN_US));
|
||||
}
|
||||
AUDIO_INFO_LOG("AudioStream::WriteBuffers thread end");
|
||||
}
|
||||
|
||||
void AudioStream::ReadBuffers()
|
||||
{
|
||||
AUDIO_INFO_LOG("AudioStream::ReadBuffers thread start");
|
||||
StreamBuffer stream;
|
||||
int32_t readLen;
|
||||
bool isBlockingRead = true;
|
||||
|
||||
while (isReadyToRead_) {
|
||||
while (!freeBufferQ_.empty()) {
|
||||
if (state_ != RUNNING) {
|
||||
AUDIO_ERR_LOG("AudioStream::ReadBuffers Read: Illegal state:%{public}u", state_);
|
||||
isReadyToRead_ = false;
|
||||
return;
|
||||
}
|
||||
AUDIO_DEBUG_LOG("AudioStream::ReadBuffers !freeBufferQ_.empty()");
|
||||
stream.buffer = freeBufferQ_.front().buffer;
|
||||
stream.bufferLen = freeBufferQ_.front().bufLength;
|
||||
AUDIO_DEBUG_LOG("AudioStream::ReadBuffers requested stream.bufferLen:%{public}d", stream.bufferLen);
|
||||
if (stream.buffer == nullptr) {
|
||||
AUDIO_ERR_LOG("AudioStream::ReadBuffers stream.buffer == nullptr return");
|
||||
return;
|
||||
}
|
||||
readLen = ReadStream(stream, isBlockingRead);
|
||||
if (readLen < 0) {
|
||||
AUDIO_ERR_LOG("AudioStream::ReadBuffers ReadStream fail, ret: %{public}d", readLen);
|
||||
} else {
|
||||
AUDIO_INFO_LOG("AudioStream::ReadBuffers ReadStream, bytesRead:%{public}d", readLen);
|
||||
freeBufferQ_.front().dataLength = readLen;
|
||||
filledBufferQ_.emplace(freeBufferQ_.front());
|
||||
freeBufferQ_.pop();
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(CB_READ_BUFFERS_WAIT_IN_US));
|
||||
}
|
||||
|
||||
AUDIO_INFO_LOG("AudioStream::ReadBuffers thread end");
|
||||
}
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
||||
|
168
services/test/audio_opensles_capture_test.cpp
Normal file
168
services/test/audio_opensles_capture_test.cpp
Normal file
@ -0,0 +1,168 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <unistd.h>
|
||||
#include <OpenSLES.h>
|
||||
#include <OpenSLES_OpenHarmony.h>
|
||||
#include <OpenSLES_Platform.h>
|
||||
#include "audio_info.h"
|
||||
#include "audio_log.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static void BuqqerQueueCallback (SLOHBufferQueueItf bufferQueueItf, void *pContext, SLuint32 size);
|
||||
|
||||
static void CaptureStart(SLRecordItf recordItf, SLOHBufferQueueItf bufferQueueItf, FILE *wavFile);
|
||||
|
||||
static void CaptureStop(SLRecordItf recordItf, SLOHBufferQueueItf bufferQueueItf);
|
||||
|
||||
static void OpenSLCaptureTest();
|
||||
|
||||
const int PARAMETERS = 2;
|
||||
FILE *wavFile_ = nullptr;
|
||||
SLObjectItf engineObject = nullptr;
|
||||
SLRecordItf recordItf;
|
||||
SLOHBufferQueueItf bufferQueueItf;
|
||||
SLObjectItf pcmCapturerObject = nullptr;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
AUDIO_INFO_LOG("opensl es capture test in");
|
||||
if (argc != PARAMETERS) {
|
||||
AUDIO_ERR_LOG("Incorrect number of parameters.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
string filePath = argv[1];
|
||||
wavFile_ = fopen(filePath.c_str(), "wb");
|
||||
if (wavFile_ == nullptr) {
|
||||
AUDIO_INFO_LOG("OpenSLES record: Unable to open file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
OpenSLCaptureTest();
|
||||
while (wavFile_ != nullptr) {
|
||||
sleep(1);
|
||||
}
|
||||
fflush(wavFile_);
|
||||
CaptureStop(recordItf, bufferQueueItf);
|
||||
(*pcmCapturerObject)->Destroy(pcmCapturerObject);
|
||||
fclose(wavFile_);
|
||||
wavFile_ = nullptr;
|
||||
}
|
||||
|
||||
static void OpenSLCaptureTest()
|
||||
{
|
||||
AUDIO_ERR_LOG("OpenSLCaptureTest");
|
||||
engineObject = nullptr;
|
||||
SLEngineItf engineItf = nullptr;
|
||||
|
||||
SLresult result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr);
|
||||
result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
|
||||
result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineItf);
|
||||
|
||||
SLDataLocator_IODevice io_device = {
|
||||
SL_DATALOCATOR_IODEVICE,
|
||||
SL_IODEVICE_AUDIOINPUT,
|
||||
SL_DEFAULTDEVICEID_AUDIOINPUT,
|
||||
NULL
|
||||
};
|
||||
|
||||
SLDataSource audioSource = {
|
||||
&io_device,
|
||||
NULL
|
||||
};
|
||||
|
||||
SLDataLocator_BufferQueue buffer_queue = {
|
||||
SL_DATALOCATOR_BUFFERQUEUE,
|
||||
3
|
||||
};
|
||||
|
||||
SLDataFormat_PCM format_pcm = {
|
||||
SL_DATAFORMAT_PCM,
|
||||
OHOS::AudioStandard::AudioChannel::MONO,
|
||||
OHOS::AudioStandard::AudioSamplingRate::SAMPLE_RATE_44100,
|
||||
OHOS::AudioStandard::AudioSampleFormat::SAMPLE_S16LE,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
SLDataSink audioSink = {
|
||||
&buffer_queue,
|
||||
&format_pcm
|
||||
};
|
||||
|
||||
result = (*engineItf)->CreateAudioRecorder(engineItf, &pcmCapturerObject,
|
||||
&audioSource, &audioSink, 0, nullptr, nullptr);
|
||||
(*pcmCapturerObject)->Realize(pcmCapturerObject, SL_BOOLEAN_FALSE);
|
||||
|
||||
(*pcmCapturerObject)->GetInterface(pcmCapturerObject, SL_IID_RECORD, &recordItf);
|
||||
(*pcmCapturerObject)->GetInterface(pcmCapturerObject, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf);
|
||||
(*bufferQueueItf)->RegisterCallback(bufferQueueItf, BuqqerQueueCallback, wavFile_);
|
||||
|
||||
CaptureStart(recordItf, bufferQueueItf, wavFile_);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void BuqqerQueueCallback(SLOHBufferQueueItf bufferQueueItf, void *pContext, SLuint32 size)
|
||||
{
|
||||
AUDIO_INFO_LOG("BuqqerQueueCallback");
|
||||
FILE *wavFile = (FILE *)pContext;
|
||||
if (wavFile != nullptr) {
|
||||
SLuint8 *buffer = nullptr;
|
||||
SLuint32 pSize = 0;
|
||||
(*bufferQueueItf)->GetBuffer(bufferQueueItf, &buffer, pSize);
|
||||
if (buffer != nullptr) {
|
||||
AUDIO_INFO_LOG("BuqqerQueueCallback, length, pSize:%{public}lu, size: %{public}lu.",
|
||||
pSize, size);
|
||||
fwrite(buffer, 1, pSize, wavFile);
|
||||
(*bufferQueueItf)->Enqueue(bufferQueueItf, buffer, size);
|
||||
} else {
|
||||
AUDIO_INFO_LOG("BuqqerQueueCallback, buffer is null or pSize: %{public}lu, size: %{public}lu.",
|
||||
pSize, size);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void CaptureStart(SLRecordItf recordItf, SLOHBufferQueueItf bufferQueueItf, FILE *wavFile)
|
||||
{
|
||||
AUDIO_INFO_LOG("CaptureStart");
|
||||
(*recordItf)->SetRecordState(recordItf, SL_RECORDSTATE_RECORDING);
|
||||
if (wavFile != nullptr) {
|
||||
SLuint8* buffer = nullptr;
|
||||
SLuint32 pSize = 0;
|
||||
(*bufferQueueItf)->GetBuffer(bufferQueueItf, &buffer, pSize);
|
||||
if (buffer != nullptr) {
|
||||
AUDIO_INFO_LOG("CaptureStart, enqueue buffer length: %{public}lu.", pSize);
|
||||
fwrite(buffer, 1, pSize, wavFile);
|
||||
(*bufferQueueItf)->Enqueue(bufferQueueItf, buffer, pSize);
|
||||
} else {
|
||||
AUDIO_INFO_LOG("BuqqerQueueCallback, buffer is null or pSize: %{public}lu.", pSize);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void CaptureStop(SLRecordItf recordItf, SLOHBufferQueueItf bufferQueueItf)
|
||||
{
|
||||
AUDIO_INFO_LOG("CaptureStop");
|
||||
(*recordItf)->SetRecordState(recordItf, SL_RECORDSTATE_STOPPED);
|
||||
return;
|
||||
}
|
@ -17,6 +17,7 @@ group("audio_unit_test") {
|
||||
deps = [
|
||||
"unittest/capturer_test:audio_capturer_unit_test",
|
||||
"unittest/manager_test:audio_manager_unit_test",
|
||||
"unittest/opensles_capture_test:audio_opensles_capture_unit_test",
|
||||
"unittest/opensles_test:audio_opensles_unit_test",
|
||||
"unittest/renderer_test:audio_renderer_unit_test",
|
||||
"unittest/volume_change_test:audio_volume_change_unit_test",
|
||||
|
66
test/unittest/opensles_capture_test/BUILD.gn
Normal file
66
test/unittest/opensles_capture_test/BUILD.gn
Normal file
@ -0,0 +1,66 @@
|
||||
# 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_capture_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/audiocapturer/include",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/audiocapturer/include",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/audiopolicy/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/audio_service/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_capture_unit_test") {
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [ "./include" ]
|
||||
|
||||
configs = [
|
||||
":audio_opensles_config",
|
||||
":audio_capture_config",
|
||||
]
|
||||
|
||||
sources = [ "src/audio_opensles_capture_unit_test.cpp" ]
|
||||
|
||||
deps = [ "//foundation/multimedia/audio_standard/frameworks/native/opensles:opensles" ]
|
||||
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef AUDIO_OPENESLES_CAPTURE_UNIT_TEST_H
|
||||
#define AUDIO_OPENESLES_CAPTURE_UNIT_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "common.h"
|
||||
#include "audio_errors.h"
|
||||
#include "audio_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AudioStandard {
|
||||
class AudioOpenslesCaptureUnitTest : 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_CAPTURE_UNIT_TEST_H
|
@ -0,0 +1,322 @@
|
||||
/*
|
||||
* 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 "audio_opensles_capture_unit_test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AudioStandard {
|
||||
namespace {
|
||||
const char *AUDIORENDER_TEST_FILE_PATH = "/data/test_capture.pcm";
|
||||
FILE *wavFile_;
|
||||
SLObjectItf engineObject_;
|
||||
SLRecordItf captureItf_;
|
||||
SLOHBufferQueueItf bufferQueueItf_;
|
||||
SLObjectItf pcmCapturerObject_;
|
||||
SLEngineItf engineEngine_;
|
||||
} // namespace
|
||||
|
||||
static void BuqqerQueueCallback(SLOHBufferQueueItf bufferQueueItf, void *pContext, SLuint32 size)
|
||||
{
|
||||
FILE *wavFile = (FILE *)pContext;
|
||||
if (wavFile != nullptr) {
|
||||
SLuint8 *buffer = nullptr;
|
||||
SLuint32 pSize = 0;
|
||||
(*bufferQueueItf)->GetBuffer(bufferQueueItf, &buffer, pSize);
|
||||
if (buffer != nullptr) {
|
||||
fwrite(buffer, 1, pSize, wavFile);
|
||||
(*bufferQueueItf)->Enqueue(bufferQueueItf, buffer, size);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void AudioOpenslesCaptureUnitTest::SetUpTestCase(void) { }
|
||||
|
||||
void AudioOpenslesCaptureUnitTest::TearDownTestCase(void) { }
|
||||
|
||||
void AudioOpenslesCaptureUnitTest::SetUp(void) { }
|
||||
|
||||
void AudioOpenslesCaptureUnitTest::TearDown(void) { }
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_CreateEngine_001, TestSize.Level0)
|
||||
{
|
||||
SLresult result = slCreateEngine(&engineObject_, 0, nullptr, 0, nullptr, nullptr);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_CreateEngine_002, TestSize.Level0)
|
||||
{
|
||||
SLresult result = (*engineObject_)->Realize(engineObject_, SL_BOOLEAN_FALSE);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_CreateEngine_003, TestSize.Level0)
|
||||
{
|
||||
SLresult result = (*engineObject_)->GetInterface(engineObject_, SL_IID_ENGINE, &engineEngine_);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_CreateAudioRecorder_001, TestSize.Level0)
|
||||
{
|
||||
wavFile_ = fopen(AUDIORENDER_TEST_FILE_PATH, "wb");
|
||||
if (wavFile_ == nullptr) {
|
||||
AUDIO_INFO_LOG("AudioCaptureTest: Unable to open record file.");
|
||||
}
|
||||
|
||||
SLDataLocator_IODevice io_device = {
|
||||
SL_DATALOCATOR_IODEVICE,
|
||||
SL_IODEVICE_AUDIOINPUT,
|
||||
SL_DEFAULTDEVICEID_AUDIOINPUT,
|
||||
NULL
|
||||
};
|
||||
|
||||
SLDataSource audioSource = {
|
||||
&io_device,
|
||||
NULL
|
||||
};
|
||||
|
||||
SLDataLocator_BufferQueue buffer_queue = {
|
||||
SL_DATALOCATOR_BUFFERQUEUE,
|
||||
3
|
||||
};
|
||||
|
||||
SLDataFormat_PCM format_pcm = {
|
||||
SL_DATAFORMAT_PCM,
|
||||
OHOS::AudioStandard::AudioChannel::MONO,
|
||||
OHOS::AudioStandard::AudioSamplingRate::SAMPLE_RATE_44100,
|
||||
OHOS::AudioStandard::AudioSampleFormat::SAMPLE_S16LE,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
SLDataSink audioSink = {
|
||||
&buffer_queue,
|
||||
&format_pcm
|
||||
};
|
||||
|
||||
SLresult result = (*engineEngine_)->CreateAudioRecorder(engineEngine_, &pcmCapturerObject_, &audioSource,
|
||||
&audioSink, 0, nullptr, nullptr);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_CreateAudioRecorder_002, TestSize.Level0)
|
||||
{
|
||||
SLresult result = (*pcmCapturerObject_)->Realize(pcmCapturerObject_, SL_BOOLEAN_FALSE);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_CreateAudioRecorder_003, TestSize.Level0)
|
||||
{
|
||||
SLresult result = (*pcmCapturerObject_)->GetInterface(pcmCapturerObject_, SL_IID_RECORD, &captureItf_);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_GetBufferQueue_001, TestSize.Level0)
|
||||
{
|
||||
SLresult result = (*pcmCapturerObject_)->GetInterface(pcmCapturerObject_, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf_);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_RegisterCallback_001, TestSize.Level0)
|
||||
{
|
||||
SLresult result = (*bufferQueueItf_)->RegisterCallback(bufferQueueItf_, BuqqerQueueCallback, wavFile_);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_SetRecordState_001, TestSize.Level0)
|
||||
{
|
||||
SLresult result = (*captureItf_)->SetRecordState(captureItf_, SL_RECORDSTATE_RECORDING);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_001, TestSize.Level0)
|
||||
{
|
||||
if (wavFile_ != nullptr) {
|
||||
SLuint8* buffer = nullptr;
|
||||
SLuint32 size = 0;
|
||||
SLresult result = (*bufferQueueItf_)->GetBuffer(bufferQueueItf_, &buffer, size);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
if (buffer != nullptr) {
|
||||
fwrite(buffer, 1, size, wavFile_);
|
||||
result = (*bufferQueueItf_)->Enqueue(bufferQueueItf_, buffer, size);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_SetRecordState_002, TestSize.Level0)
|
||||
{
|
||||
SLresult result = (*captureItf_)->SetRecordState(captureItf_, SL_RECORDSTATE_PAUSED);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_SetRecordState_003, TestSize.Level0)
|
||||
{
|
||||
SLresult result = (*captureItf_)->SetRecordState(captureItf_, SL_RECORDSTATE_STOPPED);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_GetRecordState_001, TestSize.Level0)
|
||||
{
|
||||
SLuint32 state;
|
||||
SLresult result = (*captureItf_)->GetRecordState(captureItf_, &state);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_Destroy_001, TestSize.Level0)
|
||||
{
|
||||
(*pcmCapturerObject_)->Destroy(pcmCapturerObject_);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Audio_Opensles_Capture_Destroy_002, TestSize.Level0)
|
||||
{
|
||||
(*engineObject_)->Destroy(engineObject_);
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Prf_Audio_Opensles_Capture_CreateEngine_001, TestSize.Level0)
|
||||
{
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
clock_gettime(CLOCK_REALTIME, &tv1);
|
||||
slCreateEngine(&engineObject_, 0, nullptr, 0, nullptr, nullptr);
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Prf_Audio_Opensles_Capture_DestoryEngine_001, TestSize.Level0)
|
||||
{
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
engineObject_ = {};
|
||||
slCreateEngine(&engineObject_, 0, nullptr, 0, nullptr, nullptr);
|
||||
clock_gettime(CLOCK_REALTIME, &tv1);
|
||||
(*engineObject_)->Destroy(engineObject_);
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Prf_Audio_Opensles_Capture_Realize_001, TestSize.Level0)
|
||||
{
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
engineObject_ = {};
|
||||
slCreateEngine(&engineObject_, 0, nullptr, 0, nullptr, nullptr);
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
clock_gettime(CLOCK_REALTIME, &tv1);
|
||||
(*engineObject_)->Realize(engineObject_, SL_BOOLEAN_FALSE);
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Prf_Audio_Opensles_Capture_GetInterface_001, TestSize.Level0)
|
||||
{
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
clock_gettime(CLOCK_REALTIME, &tv1);
|
||||
(*engineObject_)->GetInterface(engineObject_, SL_IID_ENGINE, &engineEngine_);
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesCaptureUnitTest, Prf_Audio_Opensles_CreateAudioRecorder_001, TestSize.Level0)
|
||||
{
|
||||
wavFile_ = fopen(AUDIORENDER_TEST_FILE_PATH, "wb");
|
||||
if (wavFile_ == nullptr) {
|
||||
AUDIO_INFO_LOG("AudioCaptureTest: Unable to open record file.");
|
||||
}
|
||||
|
||||
SLDataLocator_IODevice io_device = {
|
||||
SL_DATALOCATOR_IODEVICE,
|
||||
SL_IODEVICE_AUDIOINPUT,
|
||||
SL_DEFAULTDEVICEID_AUDIOINPUT,
|
||||
NULL
|
||||
};
|
||||
|
||||
SLDataSource audioSource = {
|
||||
&io_device,
|
||||
NULL
|
||||
};
|
||||
|
||||
SLDataLocator_BufferQueue buffer_queue = {
|
||||
SL_DATALOCATOR_BUFFERQUEUE,
|
||||
3
|
||||
};
|
||||
|
||||
SLDataFormat_PCM format_pcm = {
|
||||
SL_DATAFORMAT_PCM,
|
||||
OHOS::AudioStandard::AudioChannel::MONO,
|
||||
OHOS::AudioStandard::AudioSamplingRate::SAMPLE_RATE_44100,
|
||||
OHOS::AudioStandard::AudioSampleFormat::SAMPLE_S16LE,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
SLDataSink audioSink = {
|
||||
&buffer_queue,
|
||||
&format_pcm
|
||||
};
|
||||
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
clock_gettime(CLOCK_REALTIME, &tv1);
|
||||
(*engineEngine_)->CreateAudioRecorder(engineEngine_, &pcmCapturerObject_, &audioSource,
|
||||
&audioSink, 0, nullptr, nullptr);
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
@ -21,6 +21,9 @@ 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/audiocapturer/include",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/audiocapturer/include",
|
||||
"//foundation/multimedia/audio_standard/frameworks/native/audiopolicy/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",
|
||||
|
@ -159,7 +159,7 @@ HWTEST(AudioOpenslesUnitTest, Audio_Opensles_SetVoume_002, TestSize.Level0)
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_CetBufferQueue_001, TestSize.Level0)
|
||||
HWTEST(AudioOpenslesUnitTest, Audio_Opensles_GetBufferQueue_001, TestSize.Level0)
|
||||
{
|
||||
SLresult result = (*pcmPlayerObject_)->GetInterface(pcmPlayerObject_, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf_);
|
||||
EXPECT_TRUE(result == SL_RESULT_SUCCESS);
|
||||
@ -232,7 +232,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_CreateEngine_001, TestSize.Leve
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
clock_gettime(CLOCK_REALTIME, &tv1);
|
||||
@ -240,7 +240,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_CreateEngine_001, TestSize.Leve
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000;
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
@ -249,7 +249,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_DestoryEngine_001, TestSize.Lev
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
engineObject_ = {};
|
||||
@ -259,7 +259,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_DestoryEngine_001, TestSize.Lev
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000;
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_Realize_001, TestSize.Level0)
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
engineObject_ = {};
|
||||
slCreateEngine(&engineObject_, 0, nullptr, 0, nullptr, nullptr);
|
||||
@ -278,7 +278,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_Realize_001, TestSize.Level0)
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000;
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
@ -287,7 +287,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_GetInterface_001, TestSize.Leve
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
clock_gettime(CLOCK_REALTIME, &tv1);
|
||||
@ -295,7 +295,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_GetInterface_001, TestSize.Leve
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000;
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
@ -304,7 +304,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_CreateOutputMix_001, TestSize.L
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
clock_gettime(CLOCK_REALTIME, &tv1);
|
||||
@ -312,7 +312,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_CreateOutputMix_001, TestSize.L
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000;
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_CreateAudioPlayer_001, TestSize
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
clock_gettime(CLOCK_REALTIME, &tv1);
|
||||
@ -351,7 +351,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_CreateAudioPlayer_001, TestSize
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 10000000;
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
@ -360,7 +360,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_GetVolumeLevel_001, TestSize.Le
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
SLmillibel level = 0;
|
||||
(*pcmPlayerObject_)->GetInterface(pcmPlayerObject_, SL_IID_VOLUME, &volumeItf_);
|
||||
@ -370,7 +370,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_GetVolumeLevel_001, TestSize.Le
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 10000000;
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
@ -379,7 +379,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_GetMaxVolumeLevel_001, TestSize
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
SLmillibel level = 0;
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
@ -388,7 +388,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_GetMaxVolumeLevel_001, TestSize
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000;
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
|
||||
@ -397,7 +397,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_SetVolumeLevel_001, TestSize.Le
|
||||
struct timespec tv1 = {0};
|
||||
struct timespec tv2 = {0};
|
||||
int64_t performanceTestTimes = 10;
|
||||
int64_t usecTimes = 1000000;
|
||||
int64_t usecTimes = 1000000000;
|
||||
int64_t totalTime = 0;
|
||||
SLmillibel level = 0;
|
||||
for (int32_t i = 0; i < performanceTestTimes; i++) {
|
||||
@ -406,7 +406,7 @@ HWTEST(AudioOpenslesUnitTest, Prf_Audio_Opensles_SetVolumeLevel_001, TestSize.Le
|
||||
clock_gettime(CLOCK_REALTIME, &tv2);
|
||||
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
|
||||
}
|
||||
int64_t expectTime = 1000000;
|
||||
int64_t expectTime = 1000000000;
|
||||
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
|
||||
}
|
||||
} // namespace AudioStandard
|
||||
|
Loading…
Reference in New Issue
Block a user