Add dataLength to BufferDesc and gtest cases

Signed-off-by: Vaidegi B <vaidegi.b1@huawei.com>
This commit is contained in:
Vaidegi B 2022-02-23 12:12:21 +05:30
parent a9372e5e53
commit ff40a50a72
7 changed files with 587 additions and 25 deletions

View File

@ -137,7 +137,7 @@ SLresult AudioPlayerAdapter::EnqueueAdapter(SLuint32 id, const void *buffer, SLu
AudioRenderer *audioRenderer = GetAudioRenderById(id);
BufferDesc bufDesc = {};
bufDesc.buffer = (uint8_t*) buffer;
bufDesc.length = size;
bufDesc.dataLength = size;
audioRenderer->Enqueue(bufDesc);
return SL_RESULT_SUCCESS;
}
@ -165,7 +165,7 @@ SLresult AudioPlayerAdapter::GetBufferAdapter(SLuint32 id, SLuint8 **buffer, SLu
BufferDesc bufferDesc = {};
audioRenderer->GetBufferDesc(bufferDesc);
*buffer = bufferDesc.buffer;
size = bufferDesc.length;
size = bufferDesc.bufLength;
return SL_RESULT_SUCCESS;
}

View File

@ -115,6 +115,9 @@ const int32_t ERR_INVALID_INDEX = BASE_AUDIO_ERR_OFFSET - 17;
/** focus request denied */
const int32_t ERR_FOCUS_DENIED = BASE_AUDIO_ERR_OFFSET - 18;
/** incorrect render/capture mode */
const int32_t ERR_INCORRECT_MODE = BASE_AUDIO_ERR_OFFSET - 19;
/** Unknown error */
const int32_t ERR_UNKNOWN = BASE_AUDIO_ERR_OFFSET - 200;
} // namespace AudioStandard

View File

@ -479,7 +479,8 @@ const std::vector<AudioSamplingRate> AUDIO_SUPPORTED_SAMPLING_RATES {
struct BufferDesc {
uint8_t* buffer;
size_t length;
size_t bufLength;
size_t dataLength;
};
struct BufferQueueState {

View File

@ -300,7 +300,7 @@ size_t AudioStream::Write(uint8_t *buffer, size_t buffer_size)
{
if (renderMode_ == RENDER_MODE_CALLBACK) {
MEDIA_ERR_LOG("AudioStream::Write not supported. RenderMode is callback");
return ERR_INVALID_OPERATION;
return ERR_INCORRECT_MODE;
}
if ((buffer == nullptr) || (buffer_size <= 0)) {
@ -508,17 +508,19 @@ int32_t AudioStream::SetRenderMode(AudioRenderMode renderMode)
renderMode_ = renderMode;
for (int32_t i = 0; i < MAX_NUM_BUFFERS; ++i) {
BufferDesc bufDesc {};
GetMinimumBufferSize(bufDesc.length);
MEDIA_INFO_LOG("AudioServiceClient:: GetMinimumBufferSize: %{public}zu", bufDesc.length);
size_t length;
GetMinimumBufferSize(length);
MEDIA_INFO_LOG("AudioServiceClient:: GetMinimumBufferSize: %{public}zu", length);
bufferPool_[i] = std::make_unique<uint8_t[]>(bufDesc.length);
bufferPool_[i] = std::make_unique<uint8_t[]>(length);
if (bufferPool_[i] == nullptr) {
MEDIA_INFO_LOG("AudioServiceClient::GetBufferDescriptor bufferPool_[i]==nullptr. Allocate memory failed.");
return ERR_OPERATION_FAILED;
}
BufferDesc bufDesc {};
bufDesc.buffer = bufferPool_[i].get();
bufDesc.bufLength = length;
freeBufferQ_.emplace(bufDesc);
}
@ -534,7 +536,7 @@ int32_t AudioStream::SetRendererWriteCallback(const std::shared_ptr<AudioRendere
{
if (renderMode_ != RENDER_MODE_CALLBACK) {
MEDIA_ERR_LOG("AudioStream::SetRendererWriteCallback not supported. Render mode is not callback.");
return ERR_NOT_SUPPORTED;
return ERR_INCORRECT_MODE;
}
int32_t ret = SaveWriteCallback(callback);
@ -550,7 +552,7 @@ int32_t AudioStream::GetBufferDesc(BufferDesc &bufDesc)
{
if (renderMode_ != RENDER_MODE_CALLBACK) {
MEDIA_ERR_LOG("AudioStream::GetBufferDesc not supported. Render mode is not callback.");
return ERR_NOT_SUPPORTED;
return ERR_INCORRECT_MODE;
}
MEDIA_INFO_LOG("AudioStream::freeBufferQ_ count %{public}zu", freeBufferQ_.size());
@ -558,7 +560,7 @@ int32_t AudioStream::GetBufferDesc(BufferDesc &bufDesc)
if (!freeBufferQ_.empty()) {
bufDesc.buffer = freeBufferQ_.front().buffer;
bufDesc.length = freeBufferQ_.front().length;
bufDesc.bufLength = freeBufferQ_.front().bufLength;
freeBufferQ_.pop();
} else {
bufDesc.buffer = nullptr;
@ -577,13 +579,7 @@ int32_t AudioStream::Enqueue(const BufferDesc &bufDesc)
MEDIA_INFO_LOG("AudioStream::Enqueue");
if (renderMode_ != RENDER_MODE_CALLBACK) {
MEDIA_ERR_LOG("AudioStream::Enqueue not supported. Render mode is not callback.");
return ERR_NOT_SUPPORTED;
}
if (state_ != RUNNING) {
MEDIA_ERR_LOG("AudioStream::Enqueue: failed. Illegal state:%{public}u", state_);
isReadyToWrite_ = false;
return ERR_ILLEGAL_STATE;
return ERR_INCORRECT_MODE;
}
if (bufDesc.buffer == nullptr) {
@ -599,7 +595,7 @@ int32_t AudioStream::Clear()
{
if (renderMode_ != RENDER_MODE_CALLBACK) {
MEDIA_ERR_LOG("AudioStream::Clear not supported. Render mode is not callback.");
return ERR_NOT_SUPPORTED;
return ERR_INCORRECT_MODE;
}
while (!filledBufferQ_.empty()) {
@ -626,7 +622,7 @@ void AudioStream::WriteBuffers()
}
MEDIA_DEBUG_LOG("AudioStream::WriteBuffers !filledBufferQ_.empty()");
stream.buffer = filledBufferQ_.front().buffer;
stream.bufferLen = filledBufferQ_.front().length;
stream.bufferLen = filledBufferQ_.front().dataLength;
MEDIA_DEBUG_LOG("AudioStream::WriteBuffers stream.bufferLen:%{public}d", stream.bufferLen);
freeBufferQ_.emplace(filledBufferQ_.front());
filledBufferQ_.pop();

View File

@ -123,13 +123,22 @@ private:
MEDIA_INFO_LOG("RenderCallbackTest: EnqueueBuffer thread");
while (!feof(wavFile_)) {
if (isEnqueue_) {
size_t bufLen = reqBufLen_;
// Requested length received in callback
size_t reqLen = reqBufLen_;
bufDesc_.buffer = nullptr;
audioRenderer_->GetBufferDesc(bufDesc_);
if (bufDesc_.buffer == nullptr) {
continue;
}
fread(bufDesc_.buffer, 1, bufLen, wavFile_);
// requested len in callback will never be greater than allocated buf length
// This is just a fail-safe
if (reqLen > bufDesc_.bufLength) {
bufDesc_.dataLength = bufDesc_.bufLength;
} else {
bufDesc_.dataLength = reqLen;
}
fread(bufDesc_.buffer, 1, bufDesc_.dataLength, wavFile_);
audioRenderer_->Enqueue(bufDesc_);
isEnqueue_ = false;
}

View File

@ -36,6 +36,11 @@ public:
void OnPeriodReached(const int64_t &frameNumber) override {}
};
class AudioRenderModeCallbackTest : public AudioRendererWriteCallback {
public:
void OnWriteData(size_t length) override;
};
class AudioRendererUnitTest : public testing::Test {
public:
// SetUpTestCase: Called before all test cases

View File

@ -42,6 +42,8 @@ namespace {
constexpr uint64_t BUFFER_DURATION_TEN = 10;
constexpr uint64_t BUFFER_DURATION_FIFTEEN = 15;
constexpr uint64_t BUFFER_DURATION_TWENTY = 20;
static size_t g_reqBufLen = 0;
} // namespace
void AudioRendererUnitTest::SetUpTestCase(void) {}
@ -49,6 +51,11 @@ void AudioRendererUnitTest::TearDownTestCase(void) {}
void AudioRendererUnitTest::SetUp(void) {}
void AudioRendererUnitTest::TearDown(void) {}
void AudioRenderModeCallbackTest::OnWriteData(size_t length)
{
g_reqBufLen = length;
}
int32_t AudioRendererUnitTest::InitializeRenderer(unique_ptr<AudioRenderer> &audioRenderer)
{
AudioRendererParams rendererParams;
@ -1690,6 +1697,47 @@ HWTEST(AudioRendererUnitTest, Audio_Renderer_Write_008, TestSize.Level1)
fclose(wavFile);
}
/**
* @tc.name : Test Write API via illegl render mode, RENDER_MODE_CALLBACK.
* @tc.number: Audio_Renderer_Write_009
* @tc.desc : Test Write interface. Returns error code, if the render mode is RENDER_MODE_CALLBACK.
* : In RENDER_MODE_CALLBACK Write API call not supported. By default render mode is RENDER_MODE_NORMAL.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_Write_009, TestSize.Level1)
{
int32_t ret = -1;
FILE *wavFile = fopen(AUDIORENDER_TEST_FILE_PATH.c_str(), "rb");
ASSERT_NE(nullptr, wavFile);
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
EXPECT_EQ(SUCCESS, ret);
size_t bufferLen;
ret = audioRenderer->GetBufferSize(bufferLen);
EXPECT_EQ(SUCCESS, ret);
uint8_t *buffer = (uint8_t *) malloc(bufferLen);
ASSERT_NE(nullptr, buffer);
bool isStarted = audioRenderer->Start();
EXPECT_EQ(true, isStarted);
size_t bytesToWrite = fread(buffer, 1, bufferLen, wavFile);
int32_t bytesWritten = audioRenderer->Write(buffer, bytesToWrite);
EXPECT_EQ(ERR_INCORRECT_MODE, bytesWritten);
audioRenderer->Release();
free(buffer);
fclose(wavFile);
}
/**
* @tc.name : Test GetAudioTime API via legal input.
* @tc.number: Audio_Renderer_GetAudioTime_001
@ -3087,7 +3135,7 @@ HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererCallback_002, TestSize.L
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
shared_ptr<AudioRendererCallbackTest> audioRendererCB = std::make_shared<AudioRendererCallbackTest>();
shared_ptr<AudioRendererCallbackTest> audioRendererCB = make_shared<AudioRendererCallbackTest>();
ret = audioRenderer->SetRendererCallback(audioRendererCB);
EXPECT_EQ(SUCCESS, ret);
}
@ -3119,7 +3167,7 @@ HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererCallback_003, TestSize.L
RendererState state = audioRenderer->GetStatus();
EXPECT_EQ(RENDERER_RELEASED, state);
shared_ptr<AudioRendererCallbackTest> audioRendererCB = std::make_shared<AudioRendererCallbackTest>();
shared_ptr<AudioRendererCallbackTest> audioRendererCB = make_shared<AudioRendererCallbackTest>();
ret = audioRenderer->SetRendererCallback(audioRendererCB);
EXPECT_NE(SUCCESS, ret);
EXPECT_EQ(ERR_ILLEGAL_STATE, ret);
@ -3149,11 +3197,511 @@ HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererCallback_004, TestSize.L
RendererState state = audioRenderer->GetStatus();
EXPECT_EQ(RENDERER_PREPARED, state);
shared_ptr<AudioRendererCallbackTest> audioRendererCB = std::make_shared<AudioRendererCallbackTest>();
shared_ptr<AudioRendererCallbackTest> audioRendererCB = make_shared<AudioRendererCallbackTest>();
ret = audioRenderer->SetRendererCallback(audioRendererCB);
EXPECT_EQ(SUCCESS, ret);
}
/**
* @tc.name : Test SetRenderMode via legal input, RENDER_MODE_CALLBACK
* @tc.number: Audio_Renderer_SetRenderMode_001
* @tc.desc : Test SetRenderMode interface. Returns SUCCESS, if the render mode is successfully set.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRenderMode_001, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
EXPECT_EQ(SUCCESS, ret);
audioRenderer->Release();
}
/**
* @tc.name : Test SetRenderMode via legal input, RENDER_MODE_NORMAL
* @tc.number: Audio_Renderer_SetRenderMode_002
* @tc.desc : Test SetRenderMode interface. Returns SUCCESS, if the render mode is successfully set.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRenderMode_002, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_NORMAL);
EXPECT_EQ(SUCCESS, ret);
audioRenderer->Release();
}
/**
* @tc.name : Test GetRenderMode with, RENDER_MODE_CALLBACK
* @tc.number: Audio_Renderer_GetRenderMode_001
* @tc.desc : Test GetRenderMode interface. Returns the current render mode.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_GetRenderMode_001, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
EXPECT_EQ(SUCCESS, ret);
AudioRenderMode renderMode = audioRenderer->GetRenderMode();
EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
audioRenderer->Release();
}
/**
* @tc.name : Test GetRenderMode with, RENDER_MODE_NORMAL
* @tc.number: Audio_Renderer_GetRenderMode_002
* @tc.desc : Test GetRenderMode interface. Returns the current render mode.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_GetRenderMode_002, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_NORMAL);
EXPECT_EQ(SUCCESS, ret);
AudioRenderMode renderMode = audioRenderer->GetRenderMode();
EXPECT_EQ(RENDER_MODE_NORMAL, renderMode);
audioRenderer->Release();
}
/**
* @tc.name : Test GetRenderMode with, default renderMode
* @tc.number: Audio_Renderer_GetRenderMode_003
* @tc.desc : Test GetRenderMode interface. Returns the default render mode RENDER_MODE_NORMAL.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_GetRenderMode_003, TestSize.Level1)
{
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
AudioRenderMode renderMode = audioRenderer->GetRenderMode();
EXPECT_EQ(RENDER_MODE_NORMAL, renderMode);
audioRenderer->Release();
}
/**
* @tc.name : Test SetRendererWriteCallback via legal render mode, RENDER_MODE_CALLBACK
* @tc.number: Audio_Renderer_SetRendererWriteCallback_001
* @tc.desc : Test SetRendererWriteCallback interface. Returns SUCCESS, if the callback is successfully set.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererWriteCallback_001, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
EXPECT_EQ(SUCCESS, ret);
AudioRenderMode renderMode = audioRenderer->GetRenderMode();
EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
ret = audioRenderer->SetRendererWriteCallback(cb);
EXPECT_EQ(SUCCESS, ret);
audioRenderer->Release();
}
/**
* @tc.name : Test SetRendererWriteCallback via illegal render mode, RENDER_MODE_NORMAL
* @tc.number: Audio_Renderer_SetRendererWriteCallback_002
* @tc.desc : Test SetRendererWriteCallback interface. Returns error code, if the render mode is not callback.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererWriteCallback_002, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_NORMAL);
EXPECT_EQ(SUCCESS, ret);
AudioRenderMode renderMode = audioRenderer->GetRenderMode();
EXPECT_EQ(RENDER_MODE_NORMAL, renderMode);
shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
ret = audioRenderer->SetRendererWriteCallback(cb);
EXPECT_EQ(ERR_INCORRECT_MODE, ret);
audioRenderer->Release();
}
/**
* @tc.name : Test SetRendererWriteCallback via illegal render mode, default render mode RENDER_MODE_NORMAL
* @tc.number: Audio_Renderer_SetRendererWriteCallback_003
* @tc.desc : Test SetRendererWriteCallback interface. Returns error code, if the render mode is not callback.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererWriteCallback_003, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
ret = audioRenderer->SetRendererWriteCallback(cb);
EXPECT_EQ(ERR_INCORRECT_MODE, ret);
audioRenderer->Release();
}
/**
* @tc.name : Test SetRendererWriteCallback via illegal input, nullptr
* @tc.number: Audio_Renderer_SetRendererWriteCallback_004
* @tc.desc : Test SetRendererWriteCallback interface. Returns error code, if the callback reference is nullptr.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_SetRendererWriteCallback_004, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
EXPECT_EQ(SUCCESS, ret);
AudioRenderMode renderMode = audioRenderer->GetRenderMode();
EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
ret = audioRenderer->SetRendererWriteCallback(nullptr);
EXPECT_EQ(ERR_INVALID_PARAM, ret);
audioRenderer->Release();
}
/**
* @tc.name : Test GetBufferDesc via legal render mode, RENDER_MODE_CALLBACK
* @tc.number: Audio_Renderer_GetBufferDesc_001
* @tc.desc : Test GetBufferDesc interface. Returns SUCCESS, if BufferDesc obtained successfully.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_GetBufferDesc_001, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
EXPECT_EQ(SUCCESS, ret);
AudioRenderMode renderMode = audioRenderer->GetRenderMode();
EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
ret = audioRenderer->SetRendererWriteCallback(cb);
EXPECT_EQ(SUCCESS, ret);
BufferDesc bufDesc {};
bufDesc.buffer = nullptr;
bufDesc.dataLength = g_reqBufLen;
ret = audioRenderer->GetBufferDesc(bufDesc);
EXPECT_EQ(SUCCESS, ret);
EXPECT_NE(nullptr, bufDesc.buffer);
audioRenderer->Release();
}
/**
* @tc.name : Test GetBufferDesc via illegal render mode, RENDER_MODE_NORMAL
* @tc.number: Audio_Renderer_GetBufferDesc_002
* @tc.desc : Test GetBufferDesc interface. Returns errorcode, if render mode is not callback.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_GetBufferDesc_002, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
ret = audioRenderer->SetRendererWriteCallback(cb);
EXPECT_EQ(ERR_INCORRECT_MODE, ret);
BufferDesc bufDesc {};
bufDesc.buffer = nullptr;
bufDesc.dataLength = g_reqBufLen;
ret = audioRenderer->GetBufferDesc(bufDesc);
EXPECT_EQ(ERR_INCORRECT_MODE, ret);
EXPECT_EQ(nullptr, bufDesc.buffer);
audioRenderer->Release();
}
/**
* @tc.name : Test Enqueue via legal render mode, RENDER_MODE_CALLBACK
* @tc.number: Audio_Renderer_Enqueue_001
* @tc.desc : Test Enqueue interface. Returns SUCCESS , if the buff desc enqueued successfully.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_Enqueue_001, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
EXPECT_EQ(SUCCESS, ret);
AudioRenderMode renderMode = audioRenderer->GetRenderMode();
EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
ret = audioRenderer->SetRendererWriteCallback(cb);
EXPECT_EQ(SUCCESS, ret);
bool isStarted = audioRenderer->Start();
EXPECT_EQ(true, isStarted);
BufferDesc bufDesc {};
bufDesc.buffer = nullptr;
bufDesc.dataLength = g_reqBufLen;
ret = audioRenderer->GetBufferDesc(bufDesc);
EXPECT_EQ(SUCCESS, ret);
EXPECT_NE(nullptr, bufDesc.buffer);
ret = audioRenderer->Enqueue(bufDesc);
EXPECT_EQ(SUCCESS, ret);
audioRenderer->Stop();
audioRenderer->Release();
}
/**
* @tc.name : Test Enqueue via illegal render mode, RENDER_MODE_NORMAL
* @tc.number: Audio_Renderer_Enqueue_002
* @tc.desc : Test Enqueue interface. Returns error code, if the render mode is not callback.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_Enqueue_002, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
ret = audioRenderer->SetRendererWriteCallback(cb);
EXPECT_EQ(ERR_INCORRECT_MODE, ret);
bool isStarted = audioRenderer->Start();
EXPECT_EQ(true, isStarted);
BufferDesc bufDesc {};
bufDesc.buffer = nullptr;
bufDesc.dataLength = g_reqBufLen;
ret = audioRenderer->GetBufferDesc(bufDesc);
EXPECT_EQ(ERR_INCORRECT_MODE, ret);
ret = audioRenderer->Enqueue(bufDesc);
EXPECT_EQ(ERR_INCORRECT_MODE, ret);
audioRenderer->Stop();
audioRenderer->Release();
}
/**
* @tc.name : Test Enqueue via illegal state, state is not RUNNING
* @tc.number: Audio_Renderer_Enqueue_003
* @tc.desc : Test Enqueue interface. Returns error code, if state is not RUNNING
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_Enqueue_003, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
EXPECT_EQ(SUCCESS, ret);
AudioRenderMode renderMode = audioRenderer->GetRenderMode();
EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
ret = audioRenderer->SetRendererWriteCallback(cb);
EXPECT_EQ(SUCCESS, ret);
BufferDesc bufDesc {};
bufDesc.buffer = nullptr;
bufDesc.dataLength = g_reqBufLen;
ret = audioRenderer->GetBufferDesc(bufDesc);
EXPECT_EQ(SUCCESS, ret);
EXPECT_NE(nullptr, bufDesc.buffer);
ret = audioRenderer->Enqueue(bufDesc);
EXPECT_EQ(ERR_ILLEGAL_STATE, ret);
audioRenderer->Release();
}
/**
* @tc.name : Test Enqueue via illegal input, buffer nullptr
* @tc.number: Audio_Renderer_Enqueue_004
* @tc.desc : Test Enqueue interface. Returns error code, if the buffer nullptr
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_Enqueue_004, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
EXPECT_EQ(SUCCESS, ret);
AudioRenderMode renderMode = audioRenderer->GetRenderMode();
EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
ret = audioRenderer->SetRendererWriteCallback(cb);
EXPECT_EQ(SUCCESS, ret);
bool isStarted = audioRenderer->Start();
EXPECT_EQ(true, isStarted);
BufferDesc bufDesc {};
bufDesc.buffer = nullptr;
bufDesc.dataLength = g_reqBufLen;
ret = audioRenderer->Enqueue(bufDesc);
EXPECT_EQ(ERR_INVALID_PARAM, ret);
audioRenderer->Stop();
audioRenderer->Release();
}
/**
* @tc.name : Test Clear via legal render mode, RENDER_MODE_CALLBACK
* @tc.number: Audio_Renderer_Clear_001
* @tc.desc : Test Clear interface. Returns SUCCESS , if the buff queue cleared successfully.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_Clear_001, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
ret = audioRenderer->SetRenderMode(RENDER_MODE_CALLBACK);
EXPECT_EQ(SUCCESS, ret);
AudioRenderMode renderMode = audioRenderer->GetRenderMode();
EXPECT_EQ(RENDER_MODE_CALLBACK, renderMode);
shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
ret = audioRenderer->SetRendererWriteCallback(cb);
EXPECT_EQ(SUCCESS, ret);
bool isStarted = audioRenderer->Start();
EXPECT_EQ(true, isStarted);
BufferDesc bufDesc {};
bufDesc.buffer = nullptr;
bufDesc.dataLength = g_reqBufLen;
ret = audioRenderer->GetBufferDesc(bufDesc);
EXPECT_EQ(SUCCESS, ret);
EXPECT_NE(nullptr, bufDesc.buffer);
ret = audioRenderer->Enqueue(bufDesc);
EXPECT_EQ(SUCCESS, ret);
ret = audioRenderer->Clear();
EXPECT_EQ(SUCCESS, ret);
audioRenderer->Stop();
audioRenderer->Release();
}
/**
* @tc.name : Test Clear via illegal render mode, RENDER_MODE_NORMAL
* @tc.number: Audio_Renderer_Clear_002
* @tc.desc : Test Clear interface. Returns error code, if the render mode is not callback.
*/
HWTEST(AudioRendererUnitTest, Audio_Renderer_Clear_002, TestSize.Level1)
{
int32_t ret = -1;
AudioRendererOptions rendererOptions;
AudioRendererUnitTest::InitializeRendererOptions(rendererOptions);
unique_ptr<AudioRenderer> audioRenderer = AudioRenderer::Create(rendererOptions);
ASSERT_NE(nullptr, audioRenderer);
shared_ptr<AudioRendererWriteCallback> cb = make_shared<AudioRenderModeCallbackTest>();
ret = audioRenderer->SetRendererWriteCallback(cb);
EXPECT_EQ(ERR_INCORRECT_MODE, ret);
bool isStarted = audioRenderer->Start();
EXPECT_EQ(true, isStarted);
BufferDesc bufDesc {};
bufDesc.buffer = nullptr;
bufDesc.dataLength = g_reqBufLen;
ret = audioRenderer->GetBufferDesc(bufDesc);
EXPECT_EQ(ERR_INCORRECT_MODE, ret);
ret = audioRenderer->Enqueue(bufDesc);
EXPECT_EQ(ERR_INCORRECT_MODE, ret);
ret = audioRenderer->Clear();
EXPECT_EQ(ERR_INCORRECT_MODE, ret);
audioRenderer->Stop();
audioRenderer->Release();
}
/**
* @tc.name : Test GetRendererInfo API after calling create
* @tc.number: Audio_Renderer_GetRendererInfo_001