diff --git a/BUILD.gn b/BUILD.gn index 1856b6f3..4ab304bc 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 diff --git a/OAT.xml b/OAT.xml index 3b2e306e..ea613f02 100644 --- a/OAT.xml +++ b/OAT.xml @@ -1,5 +1,5 @@ - diff --git a/services/src/audio_policy/server/etc/audio_policy_config.xml b/services/src/audio_policy/server/etc/audio_policy_config.xml index 33272a66..260af97e 100644 --- a/services/src/audio_policy/server/etc/audio_policy_config.xml +++ b/services/src/audio_policy/server/etc/audio_policy_config.xml @@ -1,5 +1,5 @@ -stop to work + // Player doesn't support play in stopped state. Hence reinitialise player for making start<-->stop to work if (ringtoneState_ == STATE_STOPPED) { (void)PrepareRingtonePlayer(true); } else { diff --git a/services/src/audio_service/client/audio_service_client.cpp b/services/src/audio_service/client/audio_service_client.cpp index 4628ca87..8dcf2f78 100644 --- a/services/src/audio_service/client/audio_service_client.cpp +++ b/services/src/audio_service/client/audio_service_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -144,6 +144,10 @@ static size_t AlignToAudioFrameSize(size_t l, const pa_sample_spec &ss) void AudioServiceClient::PAStreamStartSuccessCb(pa_stream *stream, int32_t success, void *userdata) { + if (userdata == nullptr) { + MEDIA_ERR_LOG(" Error: userData is null!"); + return; + } AudioServiceClient *asClient = static_cast(userdata); pa_threaded_mainloop *mainLoop = static_cast(asClient->mainLoop); @@ -366,7 +370,7 @@ AudioServiceClient::AudioServiceClient() mVolumeFactor = 1.0f; mStreamType = STREAM_MUSIC; - mAudioSystemMgr = NULL; + mAudioSystemMgr = nullptr; streamIndex = 0; volumeChannels = STEREO; @@ -386,16 +390,16 @@ AudioServiceClient::AudioServiceClient() mFramePeriodWritten = 0; mTotalBytesRead = 0; mFramePeriodRead = 0; - mRenderPositionCb = NULL; - mRenderPeriodPositionCb = NULL; + mRenderPositionCb = nullptr; + mRenderPeriodPositionCb = nullptr; - mAudioRendererCallbacks = NULL; - mAudioCapturerCallbacks = NULL; - internalReadBuffer = NULL; - mainLoop = NULL; - paStream = NULL; - context = NULL; - api = NULL; + mAudioRendererCallbacks = nullptr; + mAudioCapturerCallbacks = nullptr; + internalReadBuffer = nullptr; + mainLoop = nullptr; + paStream = nullptr; + context = nullptr; + api = nullptr; internalRdBufIndex = 0; internalRdBufLen = 0; @@ -408,7 +412,7 @@ AudioServiceClient::AudioServiceClient() acache.writeIndex = 0; acache.isFull = false; acache.totalCacheSize = 0; - acache.buffer = NULL; + acache.buffer = nullptr; PAStreamCorkSuccessCb = PAStreamStopSuccessCb; } @@ -420,11 +424,11 @@ void AudioServiceClient::ResetPAAudioClient() pa_threaded_mainloop_stop(mainLoop); if (paStream) { - pa_stream_set_state_callback(paStream, NULL, NULL); - pa_stream_set_write_callback(paStream, NULL, NULL); - pa_stream_set_read_callback(paStream, NULL, NULL); - pa_stream_set_latency_update_callback(paStream, NULL, NULL); - pa_stream_set_underflow_callback(paStream, NULL, NULL); + pa_stream_set_state_callback(paStream, nullptr, nullptr); + pa_stream_set_write_callback(paStream, nullptr, nullptr); + pa_stream_set_read_callback(paStream, nullptr, nullptr); + pa_stream_set_latency_update_callback(paStream, nullptr, nullptr); + pa_stream_set_underflow_callback(paStream, nullptr, nullptr); if (isStreamConnected == true) pa_stream_disconnect(paStream); @@ -432,7 +436,7 @@ void AudioServiceClient::ResetPAAudioClient() } if (context) { - pa_context_set_state_callback(context, NULL, NULL); + pa_context_set_state_callback(context, nullptr, nullptr); if (isContextConnected == true) pa_context_disconnect(context); pa_context_unref(context); @@ -468,26 +472,26 @@ void AudioServiceClient::ResetPAAudioClient() sourceOutputs.clear(); clientInfo.clear(); - mAudioRendererCallbacks = NULL; - mAudioCapturerCallbacks = NULL; - internalReadBuffer = NULL; + mAudioRendererCallbacks = nullptr; + mAudioCapturerCallbacks = nullptr; + internalReadBuffer = nullptr; - mainLoop = NULL; - paStream = NULL; - context = NULL; - api = NULL; + mainLoop = nullptr; + paStream = nullptr; + context = nullptr; + api = nullptr; internalRdBufIndex = 0; internalRdBufLen = 0; underFlowCount = 0; - acache.buffer = NULL; + acache.buffer = nullptr; acache.readIndex = 0; acache.writeIndex = 0; acache.isFull = false; acache.totalCacheSize = 0; - PAStreamCorkSuccessCb = NULL; + PAStreamCorkSuccessCb = nullptr; } AudioServiceClient::~AudioServiceClient() @@ -506,13 +510,13 @@ static std::string GetClientBundle(int uid) sptr object = samgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); if (object == nullptr) { - MEDIA_DEBUG_LOG("object is NULL."); + MEDIA_DEBUG_LOG("object is nullptr."); return bundleName; } sptr bms = iface_cast(object); if (bms == nullptr) { - MEDIA_DEBUG_LOG("bundle manager service is NULL."); + MEDIA_DEBUG_LOG("bundle manager service is nullptr."); return bundleName; } @@ -540,17 +544,17 @@ int32_t AudioServiceClient::Initialize(ASClientType eClientType) mAudioSystemMgr = AudioSystemManager::GetInstance(); mainLoop = pa_threaded_mainloop_new(); - if (mainLoop == NULL) + if (mainLoop == nullptr) return AUDIO_CLIENT_INIT_ERR; api = pa_threaded_mainloop_get_api(mainLoop); - if (api == NULL) { + if (api == nullptr) { ResetPAAudioClient(); return AUDIO_CLIENT_INIT_ERR; } context = pa_context_new(api, "AudioServiceClient"); - if (context == NULL) { + if (context == nullptr) { ResetPAAudioClient(); return AUDIO_CLIENT_INIT_ERR; } @@ -578,7 +582,7 @@ int32_t AudioServiceClient::Initialize(ASClientType eClientType) pa_context_load_cookie_from_file(context, appCookiePath.c_str()); } - if (pa_context_connect(context, NULL, PA_CONTEXT_NOFAIL, NULL) < 0) { + if (pa_context_connect(context, nullptr, PA_CONTEXT_NOFAIL, nullptr) < 0) { error = pa_context_errno(context); MEDIA_ERR_LOG("context connect error: %{public}s", pa_strerror(error)); ResetPAAudioClient(); @@ -684,14 +688,14 @@ int32_t AudioServiceClient::ConnectStreamToPA() bufferAttr.minreq = pa_usec_to_bytes(LATENCY_IN_MSEC * PA_USEC_PER_MSEC, &sampleSpec); if (eAudioClientType == AUDIO_SERVICE_CLIENT_PLAYBACK) - result = pa_stream_connect_playback(paStream, NULL, &bufferAttr, + result = pa_stream_connect_playback(paStream, nullptr, &bufferAttr, (pa_stream_flags_t)(PA_STREAM_ADJUST_LATENCY | PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_START_CORKED | PA_STREAM_AUTO_TIMING_UPDATE - | PA_STREAM_VARIABLE_RATE), NULL, NULL); + | PA_STREAM_VARIABLE_RATE), nullptr, nullptr); else - result = pa_stream_connect_record(paStream, NULL, NULL, + result = pa_stream_connect_record(paStream, nullptr, nullptr, (pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_START_CORKED @@ -735,13 +739,13 @@ int32_t AudioServiceClient::InitializeAudioCache() } const pa_buffer_attr *bufferAttr = pa_stream_get_buffer_attr(paStream); - if (bufferAttr == NULL) { + if (bufferAttr == nullptr) { MEDIA_ERR_LOG("pa stream get buffer attribute returned null"); return AUDIO_CLIENT_INIT_ERR; } acache.buffer = make_unique(bufferAttr->minreq); - if (acache.buffer == NULL) { + if (acache.buffer == nullptr) { MEDIA_ERR_LOG("Allocate memory for buffer failed"); return AUDIO_CLIENT_INIT_ERR; } @@ -769,13 +773,13 @@ int32_t AudioServiceClient::CreateStream(AudioStreamParams audioParams, AudioStr const std::string streamName = GetStreamName(audioType); auto timenow = chrono::system_clock::to_time_t(chrono::system_clock::now()); - const std::string StreamStartTime = ctime(&timenow); + const std::string streamStartTime = ctime(&timenow); sampleSpec = ConvertToPAAudioParams(audioParams); mFrameSize = pa_frame_size(&sampleSpec); pa_proplist *propList = pa_proplist_new(); - if (propList == NULL) { + if (propList == nullptr) { MEDIA_ERR_LOG("pa_proplist_new failed"); ResetPAAudioClient(); return AUDIO_CLIENT_CREATE_STREAM_ERR; @@ -784,9 +788,9 @@ int32_t AudioServiceClient::CreateStream(AudioStreamParams audioParams, AudioStr pa_proplist_sets(propList, "stream.type", streamName.c_str()); pa_proplist_sets(propList, "stream.volumeFactor", std::to_string(mVolumeFactor).c_str()); pa_proplist_sets(propList, "stream.sessionID", std::to_string(pa_context_get_index(context)).c_str()); - pa_proplist_sets(propList, "stream.startTime", StreamStartTime.c_str()); + pa_proplist_sets(propList, "stream.startTime", streamStartTime.c_str()); - if (!(paStream = pa_stream_new_with_proplist(context, streamName.c_str(), &sampleSpec, NULL, propList))) { + if (!(paStream = pa_stream_new_with_proplist(context, streamName.c_str(), &sampleSpec, nullptr, propList))) { error = pa_context_errno(context); pa_proplist_free(propList); pa_threaded_mainloop_unlock(mainLoop); @@ -833,7 +837,7 @@ int32_t AudioServiceClient::CreateStream(AudioStreamParams audioParams, AudioStr return AUDIO_CLIENT_SUCCESS; } -int32_t AudioServiceClient::GetSessionID(uint32_t &sessionID) +int32_t AudioServiceClient::GetSessionID(uint32_t &sessionID) const { MEDIA_DEBUG_LOG("AudioServiceClient: GetSessionID"); uint32_t client_index = pa_context_get_index(context); @@ -849,11 +853,12 @@ int32_t AudioServiceClient::GetSessionID(uint32_t &sessionID) int32_t AudioServiceClient::StartStream() { int error; + if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) { return AUDIO_CLIENT_PA_ERR; } - - pa_operation *operation = NULL; + + pa_operation *operation = nullptr; pa_threaded_mainloop_lock(mainLoop); @@ -927,7 +932,7 @@ int32_t AudioServiceClient::CorkStream() return AUDIO_CLIENT_PA_ERR; } - pa_operation *operation = NULL; + pa_operation *operation = nullptr; pa_threaded_mainloop_lock(mainLoop); pa_stream_state_t state = pa_stream_get_state(paStream); @@ -953,11 +958,12 @@ int32_t AudioServiceClient::CorkStream() int32_t AudioServiceClient::FlushStream() { int error; + if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) { return AUDIO_CLIENT_PA_ERR; } - pa_operation *operation = NULL; + pa_operation *operation = nullptr; lock_guard lock(dataMutex); pa_threaded_mainloop_lock(mainLoop); @@ -972,7 +978,7 @@ int32_t AudioServiceClient::FlushStream() streamFlushStatus = 0; operation = pa_stream_flush(paStream, PAStreamFlushSuccessCb, (void *)this); - if (operation == NULL) { + if (operation == nullptr) { MEDIA_ERR_LOG("Stream Flush Operation Failed"); pa_threaded_mainloop_unlock(mainLoop); return AUDIO_CLIENT_ERR; @@ -1016,7 +1022,10 @@ int32_t AudioServiceClient::DrainStream() return AUDIO_CLIENT_PA_ERR; } - pa_operation *operation = NULL; + if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) { + return AUDIO_CLIENT_PA_ERR; + } + pa_operation *operation = nullptr; pa_threaded_mainloop_lock(mainLoop); @@ -1075,7 +1084,7 @@ int32_t AudioServiceClient::PaWriteStream(const uint8_t *buffer, size_t &length) break; } - error = pa_stream_write(paStream, (void *)buffer, writableSize, NULL, 0LL, + error = pa_stream_write(paStream, (void *)buffer, writableSize, nullptr, 0LL, PA_SEEK_RELATIVE); if (error < 0) { MEDIA_ERR_LOG("Write stream failed"); @@ -1097,6 +1106,11 @@ int32_t AudioServiceClient::PaWriteStream(const uint8_t *buffer, size_t &length) void AudioServiceClient::HandleRenderPositionCallbacks(size_t bytesWritten) { mTotalBytesWritten += bytesWritten; + if (mFrameSize == 0) { + MEDIA_ERR_LOG("HandleRenderPositionCallbacks: capturePeriodPositionCb not set"); + return; + } + uint64_t writtenFrameNumber = mTotalBytesWritten / mFrameSize; MEDIA_DEBUG_LOG("frame size: %{public}d", mFrameSize); if (!mMarkReached && mRenderPositionCb) { @@ -1133,7 +1147,7 @@ int32_t AudioServiceClient::DrainAudioCache() pa_threaded_mainloop_lock(mainLoop); int32_t error = 0; - if (acache.buffer == NULL) { + if (acache.buffer == nullptr) { MEDIA_ERR_LOG("Drain cache failed"); return AUDIO_CLIENT_ERR; } @@ -1152,7 +1166,7 @@ int32_t AudioServiceClient::DrainAudioCache() size_t AudioServiceClient::WriteToAudioCache(const StreamBuffer &stream) { - if (stream.buffer == NULL) { + if (stream.buffer == nullptr) { return 0; } @@ -1222,7 +1236,7 @@ size_t AudioServiceClient::WriteStream(const StreamBuffer &stream, int32_t &pErr } pa_threaded_mainloop_lock(mainLoop); - if (acache.buffer == NULL) { + if (acache.buffer == nullptr) { MEDIA_ERR_LOG("Buffer is null"); pError = AUDIO_CLIENT_WRITE_STREAM_ERR; return cachedLen; @@ -1279,7 +1293,7 @@ int32_t AudioServiceClient::UpdateReadBuffer(uint8_t *buffer, size_t &length, si if (!internalRdBufLen) { int retVal = pa_stream_drop(paStream); - internalReadBuffer = NULL; + internalReadBuffer = nullptr; internalRdBufLen = 0; internalRdBufIndex = 0; if (retVal < 0) { @@ -1302,6 +1316,11 @@ void AudioServiceClient::OnTimeOut() void AudioServiceClient::HandleCapturePositionCallbacks(size_t bytesRead) { mTotalBytesRead += bytesRead; + if (mFrameSize == 0) { + MEDIA_ERR_LOG("HandleCapturePositionCallbacks: capturePeriodPositionCb not set"); + return; + } + uint64_t readFrameNumber = mTotalBytesRead / mFrameSize; MEDIA_DEBUG_LOG("frame size: %{public}d", mFrameSize); if (!mMarkReached && mCapturePositionCb) { @@ -1409,7 +1428,7 @@ int32_t AudioServiceClient::SetBufferSizeInMsec(int32_t bufferSizeInMsec) return AUDIO_CLIENT_SUCCESS; } -int32_t AudioServiceClient::GetMinimumBufferSize(size_t &minBufferSize) +int32_t AudioServiceClient::GetMinimumBufferSize(size_t &minBufferSize) const { if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) { return AUDIO_CLIENT_PA_ERR; @@ -1417,8 +1436,8 @@ int32_t AudioServiceClient::GetMinimumBufferSize(size_t &minBufferSize) const pa_buffer_attr *bufferAttr = pa_stream_get_buffer_attr(paStream); - if (bufferAttr == NULL) { - MEDIA_ERR_LOG("pa_stream_get_buffer_attr returned NULL"); + if (bufferAttr == nullptr) { + MEDIA_ERR_LOG("pa_stream_get_buffer_attr returned nullptr"); return AUDIO_CLIENT_ERR; } @@ -1437,7 +1456,7 @@ int32_t AudioServiceClient::GetMinimumBufferSize(size_t &minBufferSize) return AUDIO_CLIENT_SUCCESS; } -int32_t AudioServiceClient::GetMinimumFrameCount(uint32_t &frameCount) +int32_t AudioServiceClient::GetMinimumFrameCount(uint32_t &frameCount) const { if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) { return AUDIO_CLIENT_PA_ERR; @@ -1447,8 +1466,8 @@ int32_t AudioServiceClient::GetMinimumFrameCount(uint32_t &frameCount) const pa_buffer_attr *bufferAttr = pa_stream_get_buffer_attr(paStream); - if (bufferAttr == NULL) { - MEDIA_ERR_LOG("pa_stream_get_buffer_attr returned NULL"); + if (bufferAttr == nullptr) { + MEDIA_ERR_LOG("pa_stream_get_buffer_attr returned nullptr"); return AUDIO_CLIENT_ERR; } @@ -1475,22 +1494,22 @@ int32_t AudioServiceClient::GetMinimumFrameCount(uint32_t &frameCount) return AUDIO_CLIENT_SUCCESS; } -uint32_t AudioServiceClient::GetSamplingRate() +uint32_t AudioServiceClient::GetSamplingRate() const { return DEFAULT_SAMPLING_RATE; } -uint8_t AudioServiceClient::GetChannelCount() +uint8_t AudioServiceClient::GetChannelCount() const { return DEFAULT_CHANNEL_COUNT; } -uint8_t AudioServiceClient::GetSampleSize() +uint8_t AudioServiceClient::GetSampleSize() const { return DEFAULT_SAMPLE_SIZE; } -int32_t AudioServiceClient::GetAudioStreamParams(AudioStreamParams& audioParams) +int32_t AudioServiceClient::GetAudioStreamParams(AudioStreamParams& audioParams) const { if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) { return AUDIO_CLIENT_PA_ERR; @@ -1512,7 +1531,7 @@ uint32_t AudioServiceClient::GetStreamVolume(uint32_t sessionID) return DEFAULT_STREAM_VOLUME; } -int32_t AudioServiceClient::GetCurrentTimeStamp(uint64_t &timeStamp) +int32_t AudioServiceClient::GetCurrentTimeStamp(uint64_t &timeStamp) const { if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) { return AUDIO_CLIENT_PA_ERR; @@ -1522,7 +1541,7 @@ int32_t AudioServiceClient::GetCurrentTimeStamp(uint64_t &timeStamp) pa_threaded_mainloop_lock(mainLoop); const pa_timing_info *info = pa_stream_get_timing_info(paStream); - if (!info) { + if (info == nullptr) { retVal = AUDIO_CLIENT_ERR; } else { if (eAudioClientType == AUDIO_SERVICE_CLIENT_PLAYBACK) { @@ -1538,7 +1557,7 @@ int32_t AudioServiceClient::GetCurrentTimeStamp(uint64_t &timeStamp) return retVal; } -int32_t AudioServiceClient::GetAudioLatency(uint64_t &latency) +int32_t AudioServiceClient::GetAudioLatency(uint64_t &latency) const { if (CheckPaStatusIfinvalid(mainLoop, context, paStream, AUDIO_CLIENT_PA_ERR) < 0) { return AUDIO_CLIENT_PA_ERR; @@ -1621,7 +1640,12 @@ void AudioServiceClient::SetRendererPeriodPositionCallback(int64_t periodPositio { MEDIA_INFO_LOG("Registering render period position callback"); mFramePeriodNumber = periodPosition; - mFramePeriodWritten = (mTotalBytesWritten / mFrameSize) % mFramePeriodNumber; + if ((mFrameSize != 0) && (mFramePeriodNumber != 0)) { + mFramePeriodWritten = (mTotalBytesWritten / mFrameSize) % mFramePeriodNumber; + } else { + MEDIA_ERR_LOG("AudioServiceClient::SetRendererPeriodPositionCallback failed"); + return; + } mRenderPeriodPositionCb = callback; } @@ -1655,7 +1679,12 @@ void AudioServiceClient::SetCapturerPeriodPositionCallback(int64_t periodPositio { MEDIA_INFO_LOG("Registering period position callback"); mFramePeriodNumber = periodPosition; - mFramePeriodRead = (mTotalBytesRead / mFrameSize) % mFramePeriodNumber; + if ((mFrameSize != 0) && (mFramePeriodNumber) != 0) { + mFramePeriodRead = (mTotalBytesRead / mFrameSize) % mFramePeriodNumber; + } else { + MEDIA_INFO_LOG("AudioServiceClient::SetCapturerPeriodPositionCallback failed"); + return; + } mCapturePeriodPositionCb = callback; } @@ -1671,7 +1700,7 @@ int32_t AudioServiceClient::SetStreamType(AudioStreamType audioStreamType) { MEDIA_INFO_LOG("SetStreamType: %{public}d", audioStreamType); - if (context == NULL) { + if (context == nullptr) { MEDIA_ERR_LOG("context is null"); return AUDIO_CLIENT_ERR; } @@ -1682,7 +1711,7 @@ int32_t AudioServiceClient::SetStreamType(AudioStreamType audioStreamType) const std::string streamName = GetStreamName(audioStreamType); pa_proplist *propList = pa_proplist_new(); - if (propList == NULL) { + if (propList == nullptr) { MEDIA_ERR_LOG("pa_proplist_new failed"); pa_threaded_mainloop_unlock(mainLoop); return AUDIO_CLIENT_ERR; @@ -1690,7 +1719,8 @@ int32_t AudioServiceClient::SetStreamType(AudioStreamType audioStreamType) pa_proplist_sets(propList, "stream.type", streamName.c_str()); pa_proplist_sets(propList, "media.name", streamName.c_str()); - pa_operation *updatePropOperation = pa_stream_proplist_update(paStream, PA_UPDATE_REPLACE, propList, NULL, NULL); + pa_operation *updatePropOperation = pa_stream_proplist_update(paStream, PA_UPDATE_REPLACE, propList, + nullptr, nullptr); pa_proplist_free(propList); pa_operation_unref(updatePropOperation); @@ -1704,7 +1734,7 @@ int32_t AudioServiceClient::SetStreamVolume(float volume) lock_guard lock(ctrlMutex); MEDIA_INFO_LOG("SetVolume volume: %{public}f", volume); - if (context == NULL) { + if (context == nullptr) { MEDIA_ERR_LOG("context is null"); return AUDIO_CLIENT_ERR; } @@ -1719,18 +1749,19 @@ int32_t AudioServiceClient::SetStreamVolume(float volume) mVolumeFactor = volume; pa_proplist *propList = pa_proplist_new(); - if (propList == NULL) { + if (propList == nullptr) { MEDIA_ERR_LOG("pa_proplist_new failed"); pa_threaded_mainloop_unlock(mainLoop); return AUDIO_CLIENT_ERR; } pa_proplist_sets(propList, "stream.volumeFactor", std::to_string(mVolumeFactor).c_str()); - pa_operation *updatePropOperation = pa_stream_proplist_update(paStream, PA_UPDATE_REPLACE, propList, NULL, NULL); + pa_operation *updatePropOperation = pa_stream_proplist_update(paStream, PA_UPDATE_REPLACE, propList, + nullptr, nullptr); pa_proplist_free(propList); pa_operation_unref(updatePropOperation); - if (mAudioSystemMgr == NULL) { + if (mAudioSystemMgr == nullptr) { MEDIA_ERR_LOG("System manager instance is null"); pa_threaded_mainloop_unlock(mainLoop); return AUDIO_CLIENT_ERR; @@ -1740,7 +1771,7 @@ int32_t AudioServiceClient::SetStreamVolume(float volume) uint32_t idx = pa_stream_get_index(paStream); pa_operation *operation = pa_context_get_sink_input_info(context, idx, AudioServiceClient::GetSinkInputInfoCb, reinterpret_cast(this)); - if (operation == NULL) { + if (operation == nullptr) { MEDIA_ERR_LOG("pa_context_get_sink_input_info_list returned null"); pa_threaded_mainloop_unlock(mainLoop); return AUDIO_CLIENT_ERR; @@ -1763,13 +1794,14 @@ float AudioServiceClient::GetStreamVolume() return mVolumeFactor; } -void AudioServiceClient::GetSinkInputInfoCb(pa_context *c, const pa_sink_input_info *i, int eol, void *userdata) +void AudioServiceClient::GetSinkInputInfoCb(pa_context *context, const pa_sink_input_info *info, int eol, + void *userdata) { MEDIA_INFO_LOG("GetSinkInputInfoVolumeCb in"); AudioServiceClient *thiz = reinterpret_cast(userdata); if (eol < 0) { - MEDIA_ERR_LOG("Failed to get sink input information: %{public}s", pa_strerror(pa_context_errno(c))); + MEDIA_ERR_LOG("Failed to get sink input information: %{public}s", pa_strerror(pa_context_errno(context))); return; } @@ -1778,14 +1810,14 @@ void AudioServiceClient::GetSinkInputInfoCb(pa_context *c, const pa_sink_input_i return; } - if (i->proplist == NULL) { - MEDIA_ERR_LOG("Invalid prop list for sink input (%{public}d).", i->index); + if (info->proplist == nullptr) { + MEDIA_ERR_LOG("Invalid prop list for sink input (%{public}d).", info->index); return; } - thiz->cvolume = i->volume; - thiz->streamIndex = i->index; - thiz->volumeChannels = i->channel_map.channels; + thiz->cvolume = info->volume; + thiz->streamIndex = info->index; + thiz->volumeChannels = info->channel_map.channels; thiz->streamInfoUpdated = true; SetPaVolume(*thiz); @@ -1808,7 +1840,7 @@ void AudioServiceClient::SetPaVolume(const AudioServiceClient &client) uint32_t volume = pa_sw_volume_from_linear(vol); pa_cvolume_set(&cv, client.volumeChannels, volume); - pa_operation_unref(pa_context_set_sink_input_volume(client.context, client.streamIndex, &cv, NULL, NULL)); + pa_operation_unref(pa_context_set_sink_input_volume(client.context, client.streamIndex, &cv, nullptr, nullptr)); MEDIA_INFO_LOG("Applied volume : %{public}f, pa volume: %{public}d", vol, volume); } @@ -1836,7 +1868,7 @@ int32_t AudioServiceClient::SetStreamRenderRate(AudioRendererRate audioRendererR } pa_threaded_mainloop_lock(mainLoop); - pa_operation *operation = pa_stream_update_sample_rate(paStream, rate, NULL, NULL); + pa_operation *operation = pa_stream_update_sample_rate(paStream, rate, nullptr, nullptr); pa_operation_unref(operation); pa_threaded_mainloop_unlock(mainLoop); diff --git a/services/src/audio_service/client/audio_session.cpp b/services/src/audio_service/client/audio_session.cpp index abc4fa75..055b7d24 100644 --- a/services/src/audio_service/client/audio_session.cpp +++ b/services/src/audio_service/client/audio_session.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/services/src/audio_service/client/audio_stream.cpp b/services/src/audio_service/client/audio_stream.cpp index 1423b9a5..18574049 100644 --- a/services/src/audio_service/client/audio_stream.cpp +++ b/services/src/audio_service/client/audio_stream.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -34,6 +34,51 @@ 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; +const map, AudioStreamType> AudioStream::streamTypeMap_ = AudioStream::CreateStreamMap(); + +map, AudioStreamType> AudioStream::CreateStreamMap() +{ + map, AudioStreamType> streamMap; + + streamMap[make_pair(CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_UNKNOWN, STREAM_USAGE_MEDIA)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_UNKNOWN, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_UNKNOWN, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_UNKNOWN, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_MUSIC; + + streamMap[make_pair(CONTENT_TYPE_SPEECH, STREAM_USAGE_UNKNOWN)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_SPEECH, STREAM_USAGE_MEDIA)] = STREAM_VOICE_ASSISTANT; + streamMap[make_pair(CONTENT_TYPE_SPEECH, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_VOICE_CALL; + streamMap[make_pair(CONTENT_TYPE_SPEECH, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_VOICE_ASSISTANT; + streamMap[make_pair(CONTENT_TYPE_SPEECH, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_MUSIC; + + streamMap[make_pair(CONTENT_TYPE_MUSIC, STREAM_USAGE_UNKNOWN)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_MUSIC, STREAM_USAGE_MEDIA)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_MUSIC, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_MUSIC, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_VOICE_ASSISTANT; + streamMap[make_pair(CONTENT_TYPE_MUSIC, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_RING; + + streamMap[make_pair(CONTENT_TYPE_MOVIE, STREAM_USAGE_UNKNOWN)] = STREAM_MEDIA; + streamMap[make_pair(CONTENT_TYPE_MOVIE, STREAM_USAGE_MEDIA)] = STREAM_MEDIA; + streamMap[make_pair(CONTENT_TYPE_MOVIE, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_MOVIE, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_MOVIE, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_MUSIC; + + streamMap[make_pair(CONTENT_TYPE_SONIFICATION, STREAM_USAGE_UNKNOWN)] = STREAM_NOTIFICATION; + streamMap[make_pair(CONTENT_TYPE_SONIFICATION, STREAM_USAGE_MEDIA)] = STREAM_NOTIFICATION; + streamMap[make_pair(CONTENT_TYPE_SONIFICATION, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_SONIFICATION, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_SONIFICATION, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_MUSIC; + + streamMap[make_pair(CONTENT_TYPE_RINGTONE, STREAM_USAGE_UNKNOWN)] = STREAM_RING; + streamMap[make_pair(CONTENT_TYPE_RINGTONE, STREAM_USAGE_MEDIA)] = STREAM_RING; + streamMap[make_pair(CONTENT_TYPE_RINGTONE, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_RINGTONE, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_MUSIC; + streamMap[make_pair(CONTENT_TYPE_RINGTONE, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_RING; + + return streamMap; +} + AudioStream::AudioStream(AudioStreamType eStreamType, AudioMode eMode) : eStreamType_(eStreamType), eMode_(eMode), state_(NEW), @@ -63,7 +108,7 @@ State AudioStream::GetState() return state_; } -int32_t AudioStream::GetAudioSessionID(uint32_t &sessionID) +int32_t AudioStream::GetAudioSessionID(uint32_t &sessionID) const { if ((state_ == RELEASED) || (state_ == NEW)) { return ERR_ILLEGAL_STATE; @@ -76,7 +121,7 @@ int32_t AudioStream::GetAudioSessionID(uint32_t &sessionID) return SUCCESS; } -bool AudioStream::GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base) +bool AudioStream::GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base) const { uint64_t paTimeStamp = 0; if (GetCurrentTimeStamp(paTimeStamp) == SUCCESS) { @@ -94,7 +139,7 @@ bool AudioStream::GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase ba return false; } -int32_t AudioStream::GetBufferSize(size_t &bufferSize) +int32_t AudioStream::GetBufferSize(size_t &bufferSize) const { MEDIA_INFO_LOG("AudioStream: Get Buffer size"); if (GetMinimumBufferSize(bufferSize) != 0) { @@ -104,7 +149,7 @@ int32_t AudioStream::GetBufferSize(size_t &bufferSize) return SUCCESS; } -int32_t AudioStream::GetFrameCount(uint32_t &frameCount) +int32_t AudioStream::GetFrameCount(uint32_t &frameCount) const { MEDIA_INFO_LOG("AudioStream: Get frame count"); if (GetMinimumFrameCount(frameCount) != 0) { @@ -114,7 +159,7 @@ int32_t AudioStream::GetFrameCount(uint32_t &frameCount) return SUCCESS; } -int32_t AudioStream::GetLatency(uint64_t &latency) +int32_t AudioStream::GetLatency(uint64_t &latency) const { if (GetAudioLatency(latency) != SUCCESS) { return ERR_OPERATION_FAILED; @@ -123,22 +168,22 @@ int32_t AudioStream::GetLatency(uint64_t &latency) } } -vector AudioStream::GetSupportedFormats() +vector AudioStream::GetSupportedFormats() const { return AUDIO_SUPPORTED_FORMATS; } -vector AudioStream::GetSupportedChannels() +vector AudioStream::GetSupportedChannels() const { return AUDIO_SUPPORTED_CHANNELS; } -vector AudioStream::GetSupportedEncodingTypes() +vector AudioStream::GetSupportedEncodingTypes() const { return AUDIO_SUPPORTED_ENCODING_TYPES; } -vector AudioStream::GetSupportedSamplingRates() +vector AudioStream::GetSupportedSamplingRates() const { return AUDIO_SUPPORTED_SAMPLING_RATES; } @@ -326,11 +371,6 @@ size_t AudioStream::Write(uint8_t *buffer, size_t buffer_size) MEDIA_ERR_LOG("WriteStream fail,writeError:%{public}d", writeError); return ERR_WRITE_FAILED; } - if (bytesWritten < 0) { - MEDIA_ERR_LOG("WriteStream fail,bytesWritten:%{public}zu", bytesWritten); - return ERR_INVALID_WRITE; - } - return bytesWritten; } @@ -453,7 +493,12 @@ bool AudioStream::ReleaseAudioStream() AudioStreamType AudioStream::GetStreamType(ContentType contentType, StreamUsage streamUsage) { - AudioStreamType streamType = streamTypeMap_[contentType][streamUsage]; + AudioStreamType streamType = STREAM_MUSIC; + auto pos = streamTypeMap_.find(make_pair(contentType, streamUsage)); + if (pos != streamTypeMap_.end()) { + streamType = pos->second; + } + if (streamType == STREAM_MEDIA) { streamType = STREAM_MUSIC; } diff --git a/services/src/audio_service/client/audio_system_manager.cpp b/services/src/audio_service/client/audio_system_manager.cpp index 0d90aa2e..72095d97 100644 --- a/services/src/audio_service/client/audio_system_manager.cpp +++ b/services/src/audio_service/client/audio_system_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -150,7 +150,7 @@ const std::string AudioSystemManager::GetAudioParameter(const std::string key) c return g_sProxy->GetAudioParameter(key); } -void AudioSystemManager::SetAudioParameter(const std::string key, const std::string value) const +void AudioSystemManager::SetAudioParameter(const std::string &key, const std::string &value) const { g_sProxy->SetAudioParameter(key, value); } @@ -341,8 +341,8 @@ int32_t AudioSystemManager::UnregisterVolumeKeyEventCallback(const int32_t clien return ret; } -// Below stub implemention is added to handle compilation error in call manager -// Once call manager adapt to new interrupt implementation, this will be rmeoved +// Below stub implementation is added to handle compilation error in call manager +// Once call manager adapt to new interrupt implementation, this will be removed int32_t AudioSystemManager::SetAudioManagerCallback(const AudioSystemManager::AudioVolumeType streamType, const std::shared_ptr &callback) { diff --git a/services/src/audio_service/server/audio_manager_stub.cpp b/services/src/audio_service/server/audio_manager_stub.cpp index 3d9790c1..1813cc60 100644 --- a/services/src/audio_service/server/audio_manager_stub.cpp +++ b/services/src/audio_service/server/audio_manager_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/services/src/audio_service/server/audio_server.cpp b/services/src/audio_service/server/audio_server.cpp index efdfbc1a..83bc8486 100644 --- a/services/src/audio_service/server/audio_server.cpp +++ b/services/src/audio_service/server/audio_server.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -86,13 +86,13 @@ void AudioServer::OnStop() MEDIA_DEBUG_LOG("AudioService OnStop"); } -void AudioServer::SetAudioParameter(const std::string key, const std::string value) +void AudioServer::SetAudioParameter(const std::string &key, const std::string &value) { MEDIA_DEBUG_LOG("server: set audio parameter"); AudioServer::audioParameters[key] = value; } -const std::string AudioServer::GetAudioParameter(const std::string key) +const std::string AudioServer::GetAudioParameter(const std::string &key) { MEDIA_DEBUG_LOG("server: get audio parameter"); @@ -141,7 +141,7 @@ int32_t AudioServer::SetMicrophoneMute(bool isMute) { AudioCapturerSource *audioCapturerSourceInstance = AudioCapturerSource::GetInstance(); - if (audioCapturerSourceInstance->capturerInited_ == false) { + if (!audioCapturerSourceInstance->capturerInited_) { MEDIA_INFO_LOG("Capturer is not initialized. Set the flag mute state flag"); AudioCapturerSource::micMuteState_ = isMute; return 0; @@ -155,7 +155,7 @@ bool AudioServer::IsMicrophoneMute() AudioCapturerSource *audioCapturerSourceInstance = AudioCapturerSource::GetInstance(); bool isMute = false; - if (audioCapturerSourceInstance->capturerInited_ == false) { + if (!audioCapturerSourceInstance->capturerInited_) { MEDIA_INFO_LOG("Capturer is not initialized. Get the mic mute state flag value!"); return AudioCapturerSource::micMuteState_; } @@ -172,13 +172,13 @@ int32_t AudioServer::SetAudioScene(AudioScene audioScene) AudioCapturerSource *audioCapturerSourceInstance = AudioCapturerSource::GetInstance(); AudioRendererSink *audioRendererSinkInstance = AudioRendererSink::GetInstance(); - if (audioCapturerSourceInstance->capturerInited_ == false) { + if (!audioCapturerSourceInstance->capturerInited_) { MEDIA_WARNING_LOG("Capturer is not initialized."); } else { audioCapturerSourceInstance->SetAudioScene(audioScene); } - if (audioRendererSinkInstance->rendererInited_ == false) { + if (!audioRendererSinkInstance->rendererInited_) { MEDIA_WARNING_LOG("Renderer is not initialized."); } else { audioRendererSinkInstance->SetAudioScene(audioScene); diff --git a/services/test/audio_capturer_test.cpp b/services/test/audio_capturer_test.cpp index a20b8349..15fdd497 100644 --- a/services/test/audio_capturer_test.cpp +++ b/services/test/audio_capturer_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/services/test/audio_interrupt_test.cpp b/services/test/audio_interrupt_test.cpp index a7d7018a..38b8563e 100644 --- a/services/test/audio_interrupt_test.cpp +++ b/services/test/audio_interrupt_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/services/test/audio_interrupt_test.h b/services/test/audio_interrupt_test.h index b8471eb6..ac1f5d9d 100644 --- a/services/test/audio_interrupt_test.h +++ b/services/test/audio_interrupt_test.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/services/test/audio_opensles_test.cpp b/services/test/audio_opensles_test.cpp index 74df709e..66e240f8 100644 --- a/services/test/audio_opensles_test.cpp +++ b/services/test/audio_opensles_test.cpp @@ -1,301 +1,301 @@ -/* - * 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 -#include -#include -#include "media_log.h" -#include -#include "pcm2wav.h" -#include - -using namespace std; - -static void BuqqerQueueCallback (SLOHBufferQueueItf bufferQueueItf, void *pContext, SLuint32 size); - -static void PlayerStart (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf, FILE *wavFile); - -static void PlayerStop (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf); - -static void OpenSlTest(); - -static void OpenSlTestConcurrent(); - -FILE *wavFile_ = nullptr; -FILE *wavFile1_ = nullptr; -FILE *wavFile2_ = nullptr; -wav_hdr wavHeader_; -wav_hdr wavHeader1_; -wav_hdr wavHeader2_; -SLObjectItf engineObject = nullptr; -SLObjectItf outputMixObject = nullptr; -SLPlayItf playItf; -SLPlayItf playItf1; -SLPlayItf playItf2; -SLVolumeItf volumeItf1; -SLVolumeItf volumeItf2; -SLOHBufferQueueItf bufferQueueItf; -SLOHBufferQueueItf bufferQueueItf1; -SLOHBufferQueueItf bufferQueueItf2; -SLObjectItf pcmPlayerObject = nullptr; -SLObjectItf pcmPlayerObject1 = nullptr; -SLObjectItf pcmPlayerObject2 = nullptr; - -int main(int argc, char *argv[]) -{ - if (argc == 4) { - size_t headerSize = sizeof(wav_hdr); - char *inputPath = argv[1]; - char path[PATH_MAX + 1] = {0x00}; - if ((strlen(inputPath) > PATH_MAX) || (realpath(inputPath, path) == nullptr)) { - MEDIA_ERR_LOG("Invalid path"); - return -1; - } - wavFile1_ = fopen(path, "rb"); - if (wavFile1_ == nullptr) { - MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file"); - return -1; - } - fread(&wavHeader1_, 1, headerSize, wavFile1_); - - headerSize = sizeof(wav_hdr); - inputPath = argv[2]; - if ((strlen(inputPath) > PATH_MAX) || (realpath(inputPath, path) == nullptr)) { - MEDIA_ERR_LOG("Invalid path"); - return -1; - } - wavFile2_ = fopen(path, "rb"); - if (wavFile2_ == nullptr) { - MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file"); - return -1; - } - fread(&wavHeader2_, 1, headerSize, wavFile2_); - - OpenSlTestConcurrent(); - - while (!feof(wavFile1_) || !feof(wavFile2_)) { - sleep(1); - } - - PlayerStop(playItf1, bufferQueueItf1); - PlayerStop(playItf2, bufferQueueItf2); - (*pcmPlayerObject1)->Destroy(pcmPlayerObject1); - (*pcmPlayerObject2)->Destroy(pcmPlayerObject2); - (*engineObject)->Destroy(engineObject); - (*outputMixObject)->Destroy(outputMixObject); - return 0; - } else { - if (argc < 2) { - return -1; - } - size_t headerSize = sizeof(wav_hdr); - char *inputPath = argv[1]; - char path[PATH_MAX + 1] = {0x00}; - if ((strlen(inputPath) > PATH_MAX) || (realpath(inputPath, path) == nullptr)) { - MEDIA_ERR_LOG("Invalid path"); - return -1; - } - wavFile_ = fopen(path, "rb"); - if (wavFile_ == nullptr) { - MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file"); - return -1; - } - fread(&wavHeader_, 1, headerSize, wavFile_); - - OpenSlTest(); - - while (!feof(wavFile_)) { - sleep(1); - } - PlayerStop(playItf, bufferQueueItf); - (*pcmPlayerObject)->Destroy(pcmPlayerObject); - - if (argc < 3) { - return 0; - } - char *inputPath2 = argv[2]; - char path2[PATH_MAX + 1] = {0x00}; - if ((strlen(inputPath2) > PATH_MAX) || (realpath(inputPath2, path2) == nullptr)) { - MEDIA_ERR_LOG("Invalid path"); - return -1; - } - wavFile_ = fopen(path2, "rb"); - if (wavFile_ == nullptr) { - MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file"); - return -1; - } - fread(&wavHeader_, 1, headerSize, wavFile_); - - OpenSlTest(); - - while (!feof(wavFile_)) { - sleep(1); - } - PlayerStop(playItf, bufferQueueItf); - (*pcmPlayerObject)->Destroy(pcmPlayerObject); - return 0; - } -} - -static void OpenSlTest() -{ - MEDIA_INFO_LOG("OpenSlTest"); - engineObject = nullptr; - SLEngineItf engineEngine = nullptr; - SLresult result; - result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr); - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - - outputMixObject = nullptr; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, nullptr, nullptr); - (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); - - SLDataLocator_OutputMix slOutputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject}; - SLDataSink slSink = {&slOutputMix, nullptr}; - SLDataLocator_BufferQueue slBufferQueue = { - SL_DATALOCATOR_BUFFERQUEUE, - 0 - }; - SLDataFormat_PCM pcmFormat = { - SL_DATAFORMAT_PCM, - wavHeader_.NumOfChan, - wavHeader_.SamplesPerSec * 1000, - wavHeader_.bitsPerSample, - 0, - 0, - 0 - }; - SLDataSource slSource = {&slBufferQueue, &pcmFormat}; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject, &slSource, &slSink, 3, nullptr, nullptr); - (*pcmPlayerObject)->Realize(pcmPlayerObject, SL_BOOLEAN_FALSE); - - (*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_PLAY, &playItf); - SLVolumeItf volumeItf; - (*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_VOLUME, &volumeItf); - SLmillibel pLevel = 0; - (*volumeItf)->GetVolumeLevel(volumeItf, &pLevel); - (*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf); - (*bufferQueueItf)->RegisterCallback(bufferQueueItf, BuqqerQueueCallback, wavFile_); - - PlayerStart(playItf, bufferQueueItf, wavFile_); -} - -static void OpenSlTestConcurrent() -{ - MEDIA_INFO_LOG("OpenSlTestConcurrent"); - engineObject = nullptr; - SLEngineItf engineEngine = nullptr; - SLresult result; - - result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr); - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - - outputMixObject = nullptr; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, nullptr, nullptr); - (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); - - SLDataLocator_OutputMix slOutputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject}; - SLDataSink slSink = {&slOutputMix, nullptr}; - SLDataLocator_BufferQueue slBufferQueue = { - SL_DATALOCATOR_BUFFERQUEUE, - 0 - }; - SLDataFormat_PCM pcmFormat1 = { - SL_DATAFORMAT_PCM, - wavHeader1_.NumOfChan, - wavHeader1_.SamplesPerSec * 1000, - wavHeader1_.bitsPerSample, - 0, - 0, - 0 - }; - SLDataFormat_PCM pcmFormat2 = { - SL_DATAFORMAT_PCM, - wavHeader2_.NumOfChan, - wavHeader2_.SamplesPerSec * 1000, - wavHeader2_.bitsPerSample, - 0, - 0, - 0 - }; - SLDataSource slSource1 = {&slBufferQueue, &pcmFormat1}; - SLDataSource slSource2 = {&slBufferQueue, &pcmFormat2}; - - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject1, &slSource1, &slSink, 3, nullptr, nullptr); - (*pcmPlayerObject1)->Realize(pcmPlayerObject1, SL_BOOLEAN_FALSE); - - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject2, &slSource2, &slSink, 3, nullptr, nullptr); - (*pcmPlayerObject2)->Realize(pcmPlayerObject2, SL_BOOLEAN_FALSE); - - (*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_PLAY, &playItf1); - (*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_PLAY, &playItf2); - (*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_VOLUME, &volumeItf1); - - SLmillibel level1 = 0; - (*volumeItf1)->GetMaxVolumeLevel(volumeItf1, &level1); - SLmillibel temp = 2; - level1 = (SLmillibel) (level1 / temp); - (*volumeItf1)->SetVolumeLevel(volumeItf1, level1); - (*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_VOLUME, &volumeItf2); - SLmillibel level2 = 0; - (*volumeItf2)->GetMaxVolumeLevel(volumeItf2, &level2); - temp = 15; - level2 = (SLmillibel) (level2 / temp); - (*volumeItf2)->SetVolumeLevel(volumeItf2, level2); - - (*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf1); - (*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf2); - (*bufferQueueItf1)->RegisterCallback(bufferQueueItf1, BuqqerQueueCallback, wavFile1_); - (*bufferQueueItf2)->RegisterCallback(bufferQueueItf2, BuqqerQueueCallback, wavFile2_); - PlayerStart(playItf1, bufferQueueItf1, wavFile1_); - PlayerStart(playItf2, bufferQueueItf2, wavFile2_); -} - -static void BuqqerQueueCallback (SLOHBufferQueueItf bufferQueueItf, void *pContext, SLuint32 size) -{ - FILE *wavFile = (FILE *)pContext; - if (!feof(wavFile)) { - SLuint8 *buffer = nullptr; - SLuint32 pSize = 0; - (*bufferQueueItf)->GetBuffer(bufferQueueItf, &buffer, pSize); - fread(buffer, 1, size, wavFile); - (*bufferQueueItf)->Enqueue(bufferQueueItf, buffer, size); - } - return; -} - -static void PlayerStart (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf, FILE *wavFile) -{ - MEDIA_INFO_LOG("PlayerStart"); - (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING); - if (!feof(wavFile)) { - SLuint8* buffer = nullptr; - SLuint32 pSize = 0; - (*bufferQueueItf)->GetBuffer(bufferQueueItf, &buffer, pSize); - fread(buffer, 1, pSize, wavFile); - (*bufferQueueItf)->Enqueue(bufferQueueItf, buffer, pSize); - } - return; -} - -static void PlayerStop (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf) -{ - MEDIA_INFO_LOG("PlayerStop"); - (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - return; -} - +/* + * 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 +#include +#include +#include "media_log.h" +#include +#include "pcm2wav.h" +#include + +using namespace std; + +static void BuqqerQueueCallback (SLOHBufferQueueItf bufferQueueItf, void *pContext, SLuint32 size); + +static void PlayerStart (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf, FILE *wavFile); + +static void PlayerStop (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf); + +static void OpenSlTest(); + +static void OpenSlTestConcurrent(); + +FILE *wavFile_ = nullptr; +FILE *wavFile1_ = nullptr; +FILE *wavFile2_ = nullptr; +wav_hdr wavHeader_; +wav_hdr wavHeader1_; +wav_hdr wavHeader2_; +SLObjectItf engineObject = nullptr; +SLObjectItf outputMixObject = nullptr; +SLPlayItf playItf; +SLPlayItf playItf1; +SLPlayItf playItf2; +SLVolumeItf volumeItf1; +SLVolumeItf volumeItf2; +SLOHBufferQueueItf bufferQueueItf; +SLOHBufferQueueItf bufferQueueItf1; +SLOHBufferQueueItf bufferQueueItf2; +SLObjectItf pcmPlayerObject = nullptr; +SLObjectItf pcmPlayerObject1 = nullptr; +SLObjectItf pcmPlayerObject2 = nullptr; + +int main(int argc, char *argv[]) +{ + if (argc == 4) { + size_t headerSize = sizeof(wav_hdr); + char *inputPath = argv[1]; + char path[PATH_MAX + 1] = {0x00}; + if ((strlen(inputPath) > PATH_MAX) || (realpath(inputPath, path) == nullptr)) { + MEDIA_ERR_LOG("Invalid path"); + return -1; + } + wavFile1_ = fopen(path, "rb"); + if (wavFile1_ == nullptr) { + MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file"); + return -1; + } + fread(&wavHeader1_, 1, headerSize, wavFile1_); + + headerSize = sizeof(wav_hdr); + inputPath = argv[2]; + if ((strlen(inputPath) > PATH_MAX) || (realpath(inputPath, path) == nullptr)) { + MEDIA_ERR_LOG("Invalid path"); + return -1; + } + wavFile2_ = fopen(path, "rb"); + if (wavFile2_ == nullptr) { + MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file"); + return -1; + } + fread(&wavHeader2_, 1, headerSize, wavFile2_); + + OpenSlTestConcurrent(); + + while (!feof(wavFile1_) || !feof(wavFile2_)) { + sleep(1); + } + + PlayerStop(playItf1, bufferQueueItf1); + PlayerStop(playItf2, bufferQueueItf2); + (*pcmPlayerObject1)->Destroy(pcmPlayerObject1); + (*pcmPlayerObject2)->Destroy(pcmPlayerObject2); + (*engineObject)->Destroy(engineObject); + (*outputMixObject)->Destroy(outputMixObject); + return 0; + } else { + if (argc < 2) { + return -1; + } + size_t headerSize = sizeof(wav_hdr); + char *inputPath = argv[1]; + char path[PATH_MAX + 1] = {0x00}; + if ((strlen(inputPath) > PATH_MAX) || (realpath(inputPath, path) == nullptr)) { + MEDIA_ERR_LOG("Invalid path"); + return -1; + } + wavFile_ = fopen(path, "rb"); + if (wavFile_ == nullptr) { + MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file"); + return -1; + } + fread(&wavHeader_, 1, headerSize, wavFile_); + + OpenSlTest(); + + while (!feof(wavFile_)) { + sleep(1); + } + PlayerStop(playItf, bufferQueueItf); + (*pcmPlayerObject)->Destroy(pcmPlayerObject); + + if (argc < 3) { + return 0; + } + char *inputPath2 = argv[2]; + char path2[PATH_MAX + 1] = {0x00}; + if ((strlen(inputPath2) > PATH_MAX) || (realpath(inputPath2, path2) == nullptr)) { + MEDIA_ERR_LOG("Invalid path"); + return -1; + } + wavFile_ = fopen(path2, "rb"); + if (wavFile_ == nullptr) { + MEDIA_INFO_LOG("AudioRendererTest: Unable to open wave file"); + return -1; + } + fread(&wavHeader_, 1, headerSize, wavFile_); + + OpenSlTest(); + + while (!feof(wavFile_)) { + sleep(1); + } + PlayerStop(playItf, bufferQueueItf); + (*pcmPlayerObject)->Destroy(pcmPlayerObject); + return 0; + } +} + +static void OpenSlTest() +{ + MEDIA_INFO_LOG("OpenSlTest"); + engineObject = nullptr; + SLEngineItf engineEngine = nullptr; + SLresult result; + result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr); + result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); + result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); + + outputMixObject = nullptr; + result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, nullptr, nullptr); + (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); + + SLDataLocator_OutputMix slOutputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject}; + SLDataSink slSink = {&slOutputMix, nullptr}; + SLDataLocator_BufferQueue slBufferQueue = { + SL_DATALOCATOR_BUFFERQUEUE, + 0 + }; + SLDataFormat_PCM pcmFormat = { + SL_DATAFORMAT_PCM, + wavHeader_.NumOfChan, + wavHeader_.SamplesPerSec * 1000, + wavHeader_.bitsPerSample, + 0, + 0, + 0 + }; + SLDataSource slSource = {&slBufferQueue, &pcmFormat}; + result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject, &slSource, &slSink, 3, nullptr, nullptr); + (*pcmPlayerObject)->Realize(pcmPlayerObject, SL_BOOLEAN_FALSE); + + (*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_PLAY, &playItf); + SLVolumeItf volumeItf; + (*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_VOLUME, &volumeItf); + SLmillibel pLevel = 0; + (*volumeItf)->GetVolumeLevel(volumeItf, &pLevel); + (*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf); + (*bufferQueueItf)->RegisterCallback(bufferQueueItf, BuqqerQueueCallback, wavFile_); + + PlayerStart(playItf, bufferQueueItf, wavFile_); +} + +static void OpenSlTestConcurrent() +{ + MEDIA_INFO_LOG("OpenSlTestConcurrent"); + engineObject = nullptr; + SLEngineItf engineEngine = nullptr; + SLresult result; + + result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr); + result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); + result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); + + outputMixObject = nullptr; + result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, nullptr, nullptr); + (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); + + SLDataLocator_OutputMix slOutputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject}; + SLDataSink slSink = {&slOutputMix, nullptr}; + SLDataLocator_BufferQueue slBufferQueue = { + SL_DATALOCATOR_BUFFERQUEUE, + 0 + }; + SLDataFormat_PCM pcmFormat1 = { + SL_DATAFORMAT_PCM, + wavHeader1_.NumOfChan, + wavHeader1_.SamplesPerSec * 1000, + wavHeader1_.bitsPerSample, + 0, + 0, + 0 + }; + SLDataFormat_PCM pcmFormat2 = { + SL_DATAFORMAT_PCM, + wavHeader2_.NumOfChan, + wavHeader2_.SamplesPerSec * 1000, + wavHeader2_.bitsPerSample, + 0, + 0, + 0 + }; + SLDataSource slSource1 = {&slBufferQueue, &pcmFormat1}; + SLDataSource slSource2 = {&slBufferQueue, &pcmFormat2}; + + result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject1, &slSource1, &slSink, 3, nullptr, nullptr); + (*pcmPlayerObject1)->Realize(pcmPlayerObject1, SL_BOOLEAN_FALSE); + + result = (*engineEngine)->CreateAudioPlayer(engineEngine, &pcmPlayerObject2, &slSource2, &slSink, 3, nullptr, nullptr); + (*pcmPlayerObject2)->Realize(pcmPlayerObject2, SL_BOOLEAN_FALSE); + + (*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_PLAY, &playItf1); + (*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_PLAY, &playItf2); + (*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_VOLUME, &volumeItf1); + + SLmillibel level1 = 0; + (*volumeItf1)->GetMaxVolumeLevel(volumeItf1, &level1); + SLmillibel temp = 2; + level1 = (SLmillibel) (level1 / temp); + (*volumeItf1)->SetVolumeLevel(volumeItf1, level1); + (*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_VOLUME, &volumeItf2); + SLmillibel level2 = 0; + (*volumeItf2)->GetMaxVolumeLevel(volumeItf2, &level2); + temp = 15; + level2 = (SLmillibel) (level2 / temp); + (*volumeItf2)->SetVolumeLevel(volumeItf2, level2); + + (*pcmPlayerObject1)->GetInterface(pcmPlayerObject1, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf1); + (*pcmPlayerObject2)->GetInterface(pcmPlayerObject2, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf2); + (*bufferQueueItf1)->RegisterCallback(bufferQueueItf1, BuqqerQueueCallback, wavFile1_); + (*bufferQueueItf2)->RegisterCallback(bufferQueueItf2, BuqqerQueueCallback, wavFile2_); + PlayerStart(playItf1, bufferQueueItf1, wavFile1_); + PlayerStart(playItf2, bufferQueueItf2, wavFile2_); +} + +static void BuqqerQueueCallback (SLOHBufferQueueItf bufferQueueItf, void *pContext, SLuint32 size) +{ + FILE *wavFile = (FILE *)pContext; + if (!feof(wavFile)) { + SLuint8 *buffer = nullptr; + SLuint32 pSize = 0; + (*bufferQueueItf)->GetBuffer(bufferQueueItf, &buffer, pSize); + fread(buffer, 1, size, wavFile); + (*bufferQueueItf)->Enqueue(bufferQueueItf, buffer, size); + } + return; +} + +static void PlayerStart (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf, FILE *wavFile) +{ + MEDIA_INFO_LOG("PlayerStart"); + (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING); + if (!feof(wavFile)) { + SLuint8* buffer = nullptr; + SLuint32 pSize = 0; + (*bufferQueueItf)->GetBuffer(bufferQueueItf, &buffer, pSize); + fread(buffer, 1, pSize, wavFile); + (*bufferQueueItf)->Enqueue(bufferQueueItf, buffer, pSize); + } + return; +} + +static void PlayerStop (SLPlayItf playItf, SLOHBufferQueueItf bufferQueueItf) +{ + MEDIA_INFO_LOG("PlayerStop"); + (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); + return; +} + diff --git a/services/test/audio_policy_test.cpp b/services/test/audio_policy_test.cpp index c7b1c00c..6e38a7db 100644 --- a/services/test/audio_policy_test.cpp +++ b/services/test/audio_policy_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -61,6 +61,8 @@ static void PrintUsage(void) cout << "-u\n\t Checks if the Microphone is muted " << endl << endl; cout << "-R\n\tSets RingerMode" << endl << endl; cout << "-r\n\tGets RingerMode status" << endl << endl; + cout << "-C\n\tSets AudioScene" << endl << endl; + cout << "-c\n\tGets AudioScene status" << endl << endl; cout << "-s\n\tGet Stream Status" << endl << endl; cout << "AUTHOR" << endl << endl; cout << "\tWritten by Sajeesh Sidharthan and Anurup M" << endl << endl; @@ -163,6 +165,19 @@ static void HandleRingerMode(char option) } } +static void HandleAudioScene(char option) +{ + AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance(); + if (option == 'c') { + int scene = static_cast(audioSystemMgr->GetAudioScene()); + cout << "Get Audio Scene : " << scene << endl; + } else { + int scene = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE); + cout << "Set Audio Scene : " << scene << endl; + audioSystemMgr->SetAudioScene(static_cast(scene)); + } +} + static void NoValueError() { char option[AudioPolicyTest::OPT_SHORT_LEN]; @@ -199,7 +214,7 @@ int main(int argc, char* argv[]) } int streamType = static_cast(AudioSystemManager::AudioVolumeType::STREAM_MUSIC); - while ((opt = getopt(argc, argv, ":V:U:S:D:M:R:d:s:vmru")) != -1) { + while ((opt = getopt(argc, argv, ":V:U:S:D:M:R:C:d:s:vmruc")) != -1) { switch (opt) { case 'V': case 'v': @@ -229,6 +244,10 @@ int main(int argc, char* argv[]) case 'r': HandleRingerMode(opt); break; + case 'C': + case 'c': + HandleAudioScene(opt); + break; case ':': NoValueError(); break; diff --git a/services/test/audio_render_mode_callback_test.cpp b/services/test/audio_render_mode_callback_test.cpp index 18bb4b33..5e4a3bb9 100644 --- a/services/test/audio_render_mode_callback_test.cpp +++ b/services/test/audio_render_mode_callback_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/services/test/audio_renderer_test.cpp b/services/test/audio_renderer_test.cpp index 75722578..3958e29e 100644 --- a/services/test/audio_renderer_test.cpp +++ b/services/test/audio_renderer_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -286,6 +286,7 @@ public: if (audioRenderer == nullptr) { MEDIA_ERR_LOG("AudioRendererTest: Create failed"); + fclose(wavFile); return false; } @@ -294,6 +295,7 @@ public: ret = audioRenderer->SetRendererCallback(cb1); if (ret) { MEDIA_ERR_LOG("AudioRendererTest: SetRendererCallback failed %{public}d", ret); + fclose(wavFile); return false; } diff --git a/services/test/audio_voip_test.cpp b/services/test/audio_voip_test.cpp index 9bc9507c..6621fb4a 100644 --- a/services/test/audio_voip_test.cpp +++ b/services/test/audio_voip_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -278,11 +278,23 @@ int main(int argc, char *argv[]) MEDIA_INFO_LOG("AudioVoIPTest: capturer test path = %{public}s", argv[AudioTestConstants::ARGS_INDEX_CAPTURER_TEST_PATH]); - AudioVoIPTest *renderTestObj = new AudioVoIPTest(); + AudioVoIPTest *renderTestObj = new(std::nothrow) AudioVoIPTest(); + if (!renderTestObj) { + MEDIA_ERR_LOG("AudioVoIPTest: create renderer object failed"); + return 0; + } + + AudioVoIPTest *captureTestObj = new(std::nothrow) AudioVoIPTest(); + if (!captureTestObj) { + MEDIA_ERR_LOG("AudioVoIPTest: create capturer object failed"); + delete renderTestObj; + renderTestObj = nullptr; + return 0; + } + std::thread renderThread(&AudioVoIPTest::TestPlayback, renderTestObj, argv[AudioTestConstants::ARGS_INDEX_RENDERER_TEST_PATH]); - AudioVoIPTest *captureTestObj = new AudioVoIPTest(); std::thread captureThread(&AudioVoIPTest::TestRecording, captureTestObj, argv[AudioTestConstants::ARGS_INDEX_CAPTURER_TEST_PATH]); @@ -290,7 +302,9 @@ int main(int argc, char *argv[]) captureThread.join(); delete renderTestObj; + renderTestObj = nullptr; delete captureTestObj; + captureTestObj = nullptr; return 0; } diff --git a/services/test/interrupt_multi_renderer_test.cpp b/services/test/interrupt_multi_renderer_test.cpp index 2f6d974d..9df589d2 100644 --- a/services/test/interrupt_multi_renderer_test.cpp +++ b/services/test/interrupt_multi_renderer_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/services/test/interrupt_multi_renderer_test.h b/services/test/interrupt_multi_renderer_test.h index 2fc42b95..79dbbda4 100644 --- a/services/test/interrupt_multi_renderer_test.h +++ b/services/test/interrupt_multi_renderer_test.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/services/test/pcm2wav.h b/services/test/pcm2wav.h index 55aec245..988c5aa4 100644 --- a/services/test/pcm2wav.h +++ b/services/test/pcm2wav.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/services/test/playback_test.cpp b/services/test/playback_test.cpp index 26dfb356..80048fba 100644 --- a/services/test/playback_test.cpp +++ b/services/test/playback_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -74,7 +74,7 @@ static int32_t InitPlayback(std::unique_ptr &client, AudioSt int32_t StartPlayback(std::unique_ptr &client, FILE *wavFile) { uint8_t* buffer = nullptr; - int32_t n = 2; + size_t n = 2; size_t bytesToWrite = 0; size_t bytesWritten = 0; size_t minBytes = 4; diff --git a/services/test/record_test.cpp b/services/test/record_test.cpp index fdaa8679..d75b4290 100644 --- a/services/test/record_test.cpp +++ b/services/test/record_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/test/BUILD.gn b/test/BUILD.gn index effa1e88..3fee7fea 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 diff --git a/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h b/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h index c51995bb..a7ab2a18 100644 --- a/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h +++ b/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp b/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp index f5e0343d..af2722e5 100644 --- a/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp +++ b/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/test/moduletest/audiopolicy/BUILD.gn b/test/moduletest/audiopolicy/BUILD.gn index 3f67288c..7b05ebf8 100644 --- a/test/moduletest/audiopolicy/BUILD.gn +++ b/test/moduletest/audiopolicy/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 diff --git a/test/resource/audio_renderer/ohos_test.xml b/test/resource/audio_renderer/ohos_test.xml index 2240cfe5..9b3d5300 100644 --- a/test/resource/audio_renderer/ohos_test.xml +++ b/test/resource/audio_renderer/ohos_test.xml @@ -1,5 +1,5 @@ -