!305 Resolve conflict files and replace marco function with standard function

Merge pull request !305 from zhujie/master
This commit is contained in:
openharmony_ci 2022-03-18 08:39:16 +00:00 committed by Gitee
commit b178e4da6b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 93 additions and 44 deletions

0
OAT.xml Executable file → Normal file
View File

0
README.md Executable file → Normal file
View File

0
README_zh.md Executable file → Normal file
View File

0
bundle.json Executable file → Normal file
View File

0
figures/en-us_image_0000001152315135.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

0
figures/zh-cn_image_0000001152315135.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

View File

@ -33,6 +33,7 @@ namespace AudioStandard {
AudioRendererCallbacks::~AudioRendererCallbacks() = default;
AudioCapturerCallbacks::~AudioCapturerCallbacks() = default;
const uint32_t CHECK_UTIL_SUCCESS = 0;
const uint64_t LATENCY_IN_MSEC = 50UL;
const uint32_t READ_TIMEOUT_IN_SEC = 5;
const uint32_t DOUBLE_VALUE = 2;
@ -43,31 +44,33 @@ const uint64_t MIN_BUF_DURATION_IN_USEC = 92880;
const string APP_DATA_BASE_PATH = "/data/accounts/account_0/appdata/";
const string APP_COOKIE_FILE_PATH = "/cache/cookie";
#define CHECK_AND_RETURN_IFINVALID(expr) \
do { \
if (!(expr)) { \
return AUDIO_CLIENT_ERR; \
} \
} while (false)
static int32_t CheckReturnIfinvalid(bool expr, const uint32_t retVal)
{
do {
if (!(expr)) {
return retVal;
}
} while (false);
return CHECK_UTIL_SUCCESS;
}
#define CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, error) \
do { \
if (!context || !paStream || !mainLoop \
|| !PA_CONTEXT_IS_GOOD(pa_context_get_state(context)) \
|| !PA_STREAM_IS_GOOD(pa_stream_get_state(paStream))) { \
return error; \
} \
} while (false)
static int32_t CheckPaStatusIfinvalid(pa_threaded_mainloop *mainLoop, pa_context *context,
pa_stream *paStream, const uint32_t retVal)
{
return CheckReturnIfinvalid(mainLoop && context &&
paStream && PA_CONTEXT_IS_GOOD(pa_context_get_state(context)) &&
PA_STREAM_IS_GOOD(pa_stream_get_state(paStream)), retVal);
}
#define CHECK_PA_STATUS_FOR_WRITE(mainLoop, context, paStream, pError, retVal) \
do { \
if (!context || !paStream || !mainLoop \
|| !PA_CONTEXT_IS_GOOD(pa_context_get_state(context)) \
|| !PA_STREAM_IS_GOOD(pa_stream_get_state(paStream))) { \
pError = pa_context_errno(context); \
return retVal; \
} \
} while (false)
static int32_t CheckPaStatusIfinvalid(pa_threaded_mainloop *mainLoop, pa_context *context,
pa_stream *paStream, const uint32_t retVal, int32_t &pError)
{
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, -1) < 0) {
pError = pa_context_errno(context);
return -1;
}
return retVal;
}
AudioStreamParams AudioServiceClient::ConvertFromPAAudioParams(pa_sample_spec paSampleSpec)
{
@ -232,7 +235,10 @@ int32_t AudioServiceClient::SetAudioRenderMode(AudioRenderMode renderMode)
return AUDIO_CLIENT_SUCCESS;
}
CHECK_AND_RETURN_IFINVALID(mainLoop && context && paStream);
if (CheckReturnIfinvalid(mainLoop && context && paStream, AUDIO_CLIENT_ERR) < 0) {
return AUDIO_CLIENT_ERR;
}
pa_threaded_mainloop_lock(mainLoop);
pa_buffer_attr bufferAttr;
bufferAttr.fragsize = static_cast<uint32_t>(-1);
@ -667,7 +673,10 @@ int32_t AudioServiceClient::ConnectStreamToPA()
{
int error, result;
CHECK_AND_RETURN_IFINVALID(mainLoop && context && paStream);
if (CheckReturnIfinvalid(mainLoop && context && paStream, AUDIO_CLIENT_ERR) < 0) {
return AUDIO_CLIENT_ERR;
}
pa_threaded_mainloop_lock(mainLoop);
pa_buffer_attr bufferAttr;
@ -724,7 +733,10 @@ int32_t AudioServiceClient::ConnectStreamToPA()
int32_t AudioServiceClient::InitializeAudioCache()
{
MEDIA_INFO_LOG("Initializing internal audio cache");
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckReturnIfinvalid(mainLoop && context && paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
const pa_buffer_attr *bufferAttr = pa_stream_get_buffer_attr(paStream);
if (bufferAttr == nullptr) {
@ -748,8 +760,9 @@ int32_t AudioServiceClient::InitializeAudioCache()
int32_t AudioServiceClient::CreateStream(AudioStreamParams audioParams, AudioStreamType audioType)
{
int error;
CHECK_AND_RETURN_IFINVALID(mainLoop && context);
if (CheckReturnIfinvalid(mainLoop && context, AUDIO_CLIENT_ERR) < 0) {
return AUDIO_CLIENT_ERR;
}
if (eAudioClientType == AUDIO_SERVICE_CLIENT_CONTROLLER) {
return AUDIO_CLIENT_INVALID_PARAMS_ERR;
@ -841,7 +854,10 @@ int32_t AudioServiceClient::StartStream()
{
int error;
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
pa_operation *operation = nullptr;
pa_threaded_mainloop_lock(mainLoop);
@ -912,7 +928,10 @@ int32_t AudioServiceClient::StopStream()
int32_t AudioServiceClient::CorkStream()
{
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
pa_operation *operation = nullptr;
pa_threaded_mainloop_lock(mainLoop);
@ -939,7 +958,11 @@ int32_t AudioServiceClient::CorkStream()
int32_t AudioServiceClient::FlushStream()
{
int error;
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
pa_operation *operation = nullptr;
lock_guard<mutex> lock(dataMutex);
@ -995,8 +1018,13 @@ int32_t AudioServiceClient::DrainStream()
MEDIA_ERR_LOG("Audio cache drain failed");
return AUDIO_CLIENT_ERR;
}
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
pa_operation *operation = nullptr;
pa_threaded_mainloop_lock(mainLoop);
@ -1112,7 +1140,10 @@ void AudioServiceClient::HandleRenderPositionCallbacks(size_t bytesWritten)
int32_t AudioServiceClient::DrainAudioCache()
{
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
pa_threaded_mainloop_lock(mainLoop);
int32_t error = 0;
@ -1176,8 +1207,10 @@ size_t AudioServiceClient::WriteStreamInCb(const StreamBuffer &stream, int32_t &
{
lock_guard<mutex> lock(dataMutex);
int error = 0;
CHECK_PA_STATUS_FOR_WRITE(mainLoop, context, paStream, pError, 0);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, 0, pError) < 0) {
return 0;
}
pa_threaded_mainloop_lock(mainLoop);
const uint8_t *buffer = stream.buffer;
@ -1198,8 +1231,9 @@ size_t AudioServiceClient::WriteStream(const StreamBuffer &stream, int32_t &pErr
pError = error;
return cachedLen;
}
CHECK_PA_STATUS_FOR_WRITE(mainLoop, context, paStream, pError, 0);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, 0, pError) < 0) {
return 0;
}
pa_threaded_mainloop_lock(mainLoop);
if (acache.buffer == nullptr) {
@ -1319,8 +1353,9 @@ int32_t AudioServiceClient::ReadStream(StreamBuffer &stream, bool isBlocking)
uint8_t *buffer = stream.buffer;
size_t length = stream.bufferLen;
size_t readSize = 0;
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
lock_guard<mutex> lock(dataMutex);
pa_threaded_mainloop_lock(mainLoop);
@ -1395,7 +1430,9 @@ int32_t AudioServiceClient::SetBufferSizeInMsec(int32_t bufferSizeInMsec)
int32_t AudioServiceClient::GetMinimumBufferSize(size_t &minBufferSize) const
{
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
const pa_buffer_attr *bufferAttr = pa_stream_get_buffer_attr(paStream);
@ -1421,7 +1458,10 @@ int32_t AudioServiceClient::GetMinimumBufferSize(size_t &minBufferSize) const
int32_t AudioServiceClient::GetMinimumFrameCount(uint32_t &frameCount) const
{
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
size_t minBufferSize = 0;
const pa_buffer_attr *bufferAttr = pa_stream_get_buffer_attr(paStream);
@ -1471,7 +1511,10 @@ uint8_t AudioServiceClient::GetSampleSize() const
int32_t AudioServiceClient::GetAudioStreamParams(AudioStreamParams& audioParams) const
{
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
const pa_sample_spec *paSampleSpec = pa_stream_get_sample_spec(paStream);
if (!paSampleSpec) {
@ -1490,7 +1533,10 @@ uint32_t AudioServiceClient::GetStreamVolume(uint32_t sessionID)
int32_t AudioServiceClient::GetCurrentTimeStamp(uint64_t &timeStamp) const
{
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
int32_t retVal = AUDIO_CLIENT_SUCCESS;
pa_threaded_mainloop_lock(mainLoop);
@ -1513,7 +1559,10 @@ int32_t AudioServiceClient::GetCurrentTimeStamp(uint64_t &timeStamp) const
int32_t AudioServiceClient::GetAudioLatency(uint64_t &latency) const
{
CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR);
if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) {
return AUDIO_CLIENT_PA_ERR;
}
pa_usec_t paLatency;
pa_usec_t cacheLatency;
int32_t retVal = AUDIO_CLIENT_SUCCESS;