diff --git a/audiohandler/BUILD.gn b/audiohandler/BUILD.gn index e93e12408c201ac89e0a0af192a72f438fb5a314..a31af79f116f8f300d092684c6bde219c6360d8e 100644 --- a/audiohandler/BUILD.gn +++ b/audiohandler/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../distributedaudio.gni") ohos_shared_library("distributed_audio_handler") { include_dirs = [ @@ -38,14 +37,14 @@ ohos_shared_library("distributed_audio_handler") { sources = [ "src/daudio_handler.cpp" ] deps = [ - "${services_path}/common:distributed_audio_utils", "${mediastandard_path}/interfaces/inner_api/native:media_client", + "${services_path}/common:distributed_audio_utils", ] external_deps = [ "c_utils:utils", - "multimedia_audio_framework:audio_client", "multimedia_audio_framework:audio_capturer", + "multimedia_audio_framework:audio_client", ] defines = [ diff --git a/audiohandler/test/unittest/BUILD.gn b/audiohandler/test/unittest/BUILD.gn index c712c096df71cf6af6aec4e2a44a953bed43df9c..3e17b3bed5f5364baa1d9fad5180f37bb94e53eb 100644 --- a/audiohandler/test/unittest/BUILD.gn +++ b/audiohandler/test/unittest/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../distributedaudio.gni") module_out_path = "distributed_audio/audio_handler_test" diff --git a/bundle.json b/bundle.json index 4667befe6e3a60aaa5e2153bd9e0355b1a62c9d2..bcd6ba69be3b2aa801e0b1bfb9e368b9d1bc7bba 100755 --- a/bundle.json +++ b/bundle.json @@ -1,7 +1,7 @@ { "name":"@ohos/distributed_audio", "description":"distributed audio", - "version":"3.1", + "version":"4.0", "author":{}, "repository":"https://gitee.com/openharmony/distributed_audio", "license":"Apache License 2.0", @@ -21,8 +21,8 @@ "adapted_system_type":[ "standard" ], - "rom":"2000k", - "ram":"6M", + "rom":"2000KB", + "ram":"6MB", "hisysevent_config": [ "//foundation/distributedhardware/distributed_audio/hisysevent.yaml" ], @@ -65,8 +65,7 @@ "//foundation/distributedhardware/distributed_audio/services/audiotransport/audiochannel/audiodatachannel:distributed_audio_data_channel", "//foundation/distributedhardware/distributed_audio/services/audiotransport/audiotransportstatus:distributed_audio_transport_status", "//foundation/distributedhardware/distributed_audio/services/audiotransport/decodetransport:distributed_audio_decode_transport", - "//foundation/distributedhardware/distributed_audio/services/audiotransport/encodetransport:distributed_audio_encode_transport", - "//foundation/distributedhardware/distributed_audio/services/audioprocessor/effectcomponent:daudio_effect_component" + "//foundation/distributedhardware/distributed_audio/services/audiotransport/encodetransport:distributed_audio_encode_transport" ], "inner_kits":[ { @@ -88,6 +87,17 @@ "idaudio_source.h" ] } + }, + { + "type": "so", + "name": "//foundation/distributedhardware/distributed_audio/services/common:distributed_audio_utils", + "header": { + "header_base": "//foundation/distributedhardware/distributed_audio/services/common/", + "header_files": [ + "audiodata/include/audio_data.h", + "audioparam/audio_param.h" + ] + } } ], "test":[ diff --git a/common/dfx_utils/test/unittest/BUILD.gn b/common/dfx_utils/test/unittest/BUILD.gn index d15e775bb2612177389180a7f5184b415cbf13c5..04c9a8e1ded0c27b25f8790f78a9363b42b3c02b 100644 --- a/common/dfx_utils/test/unittest/BUILD.gn +++ b/common/dfx_utils/test/unittest/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") module_out_path = "distributed_audio/common/dfx_utils_test" @@ -76,9 +75,8 @@ config("module_private_config") { ohos_unittest("DAudioDfxTest") { module_out_path = module_out_path - sources = [ - "${common_path}/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp", - ] + sources = + [ "${common_path}/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp" ] configs = [ ":module_private_config" ] diff --git a/common/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp b/common/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp index 391b8deb419b703cbc7f8b2b0a9f8bfe00700ba5..73f6da8a61be9fb7e4330f761645160496d5fa4e 100644 --- a/common/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp +++ b/common/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp @@ -43,9 +43,6 @@ void DAudioHidumperTest::TearDown() HWTEST_F(DAudioHidumperTest, Dump_001, TestSize.Level1) { std::string result; - int32_t taskId = 1; - DaudioStartAsyncTrace(result, taskId); - DaudioFinishAsyncTrace(result, taskId); std::vector args; EXPECT_EQ(true, hidumper_->Dump(args, result)); args = { "-h"}; diff --git a/common/include/daudio_constants.h b/common/include/daudio_constants.h index 8f42b230cd709f49f49982a44574db623d18087b..ed2b9bb600d086110d3c3583614e7ee0cfe1c5ec 100644 --- a/common/include/daudio_constants.h +++ b/common/include/daudio_constants.h @@ -63,6 +63,10 @@ constexpr uint32_t DAUDIO_MAX_TASKQUEUE_LEN = 100; constexpr uint32_t DAUDIO_MAX_RECV_DATA_LEN = 104857600; constexpr uint32_t DAUDIO_MAX_JSON_LEN = 1024; +static constexpr int64_t AUDIO_OFFSET_FRAME_NUM = 10; +static constexpr int64_t LOW_LATENCY_INTERVAL_NS = 5000000; +static constexpr int64_t LOW_LATENCY_CLIENT_INTERVAL_NS = 20000000; + const std::string DAUDIO_LOG_TITLE_TAG = "DAUDIO"; const std::string DAUDIO_PREFIX = "DISTRIBUTED_AUDIO"; const std::string AUDIO_PREFIX = "AUDIO"; @@ -97,6 +101,7 @@ constexpr const char *KEY_RESULT = "result"; constexpr const char *KEY_EVENT_TYPE = "eventType"; constexpr const char *KEY_AUDIO_PARAM = "audioParam"; constexpr const char *KEY_ATTRS = "attrs"; +constexpr const char *KEY_RANDOM_TASK_CODE = "randomTaskCode"; constexpr const char *KEY_SAMPLING_RATE = "samplingRate"; constexpr const char *KEY_CHANNELS = "channels"; diff --git a/common/include/daudio_util.h b/common/include/daudio_util.h index f43deb0fd6211058b26e72146fc9ae9be8cfc63e..77f1a6f149b6131126398bfb07be4059b975e715 100644 --- a/common/include/daudio_util.h +++ b/common/include/daudio_util.h @@ -42,6 +42,10 @@ bool IsAudioParam(const json &jsonObj, const std::string &key); int32_t CalculateSampleNum(uint32_t sampleRate, uint32_t timems); int64_t GetCurNano(); int32_t AbsoluteSleep(int64_t nanoTime); +int64_t CalculateOffset(const int64_t frameIndex, const int64_t framePeriodNs, const int64_t startTime); +int64_t UpdateTimeOffset(const int64_t frameIndex, const int64_t framePeriodNs, int64_t &startTime); +void GetCurrentTime(int64_t &tvSec, int64_t &tvNSec); +bool CheckIsNum(const std::string &jsonString); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DAUDIO_UTIL_H diff --git a/common/src/daudio_util.cpp b/common/src/daudio_util.cpp index 167d0363f456639c92200549202c5f2d8a0f57f9..a1dbaa498ff5ca591492b7daaca67a9f5a2b7d2d 100644 --- a/common/src/daudio_util.cpp +++ b/common/src/daudio_util.cpp @@ -40,6 +40,7 @@ constexpr int32_t WORD_WIDTH_4 = 4; constexpr size_t INT32_SHORT_ID_LENGTH = 20; constexpr size_t INT32_MIN_ID_LENGTH = 3; constexpr size_t INT32_PLAINTEXT_LENGTH = 4; +constexpr uint8_t MAX_KEY_DH_ID_LEN = 20; std::map typeCheckMap = { std::map::value_type(KEY_TYPE, &DistributedHardware::IsInt32), @@ -50,6 +51,7 @@ std::map typeCheckMap = { std::map::value_type(KEY_EVENT_TYPE, &DistributedHardware::IsInt32), std::map::value_type(KEY_AUDIO_PARAM, &DistributedHardware::IsAudioParam), std::map::value_type(KEY_ATTRS, &DistributedHardware::IsString), + std::map::value_type(KEY_RANDOM_TASK_CODE, &DistributedHardware::IsString), std::map::value_type(KEY_SAMPLING_RATE, &DistributedHardware::IsInt32), std::map::value_type(KEY_CHANNELS, &DistributedHardware::IsInt32), std::map::value_type(KEY_FORMAT, &DistributedHardware::IsInt32), @@ -128,6 +130,16 @@ int32_t GetDevTypeByDHId(int32_t dhId) return AUDIO_DEVICE_TYPE_UNKNOWN; } +void GetCurrentTime(int64_t &tvSec, int64_t &tvNSec) +{ + struct timespec time; + if (clock_gettime(CLOCK_MONOTONIC, &time) < 0) { + DHLOGE("Get current time failed"); + } + tvSec = time.tv_sec; + tvNSec = time.tv_nsec; +} + int64_t GetNowTimeUs() { std::chrono::microseconds nowUs = @@ -216,7 +228,7 @@ bool IsAudioParam(const json &jsonObj, const std::string &key) int32_t CalculateSampleNum(uint32_t sampleRate, uint32_t timems) { - return sampleRate * timems / AUDIO_MS_PER_SECOND; + return (sampleRate * timems) / AUDIO_MS_PER_SECOND; } int64_t GetCurNano() @@ -249,8 +261,39 @@ int32_t AbsoluteSleep(int64_t nanoTime) if (ret != 0) { DHLOGE("AbsoluteSleep may failed, ret is : %d", ret); } - return ret; } + +int64_t CalculateOffset(const int64_t frameIndex, const int64_t framePeriodNs, const int64_t startTime) +{ + int64_t totalOffset = GetCurNano() - startTime; + return totalOffset - frameIndex * framePeriodNs; +} + +int64_t UpdateTimeOffset(const int64_t frameIndex, const int64_t framePeriodNs, int64_t &startTime) +{ + int64_t timeOffset = 0; + if (frameIndex == 0) { + startTime = GetCurNano(); + } else if (frameIndex % AUDIO_OFFSET_FRAME_NUM == 0) { + timeOffset = CalculateOffset(frameIndex, framePeriodNs, startTime); + } + return timeOffset; +} + +bool CheckIsNum(const std::string &jsonString) +{ + if (jsonString.empty() || jsonString.size() > MAX_KEY_DH_ID_LEN) { + DHLOGE("Json string size %d, is zero or too long.", jsonString.size()); + return false; + } + for (char const &c : jsonString) { + if (!std::isdigit(c)) { + DHLOGE("Json string is not number."); + return false; + } + } + return true; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/common/test_utils/BUILD.gn b/common/test_utils/BUILD.gn deleted file mode 100644 index a9ea98a6859f4b648609a0c03e97f52d4c0799da..0000000000000000000000000000000000000000 --- a/common/test_utils/BUILD.gn +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//foundation/distributedhardware/distributed_audio/distributedaudio.gni") -import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import("//drivers/peripheral/adapter/base/hidl_adapter.gni") - -ohos_executable("daudio_test_bin") { - include_dirs = [ - "//foundation/multimedia/audio_framework/interfaces/inner_api/native/audiocommon/include", - "//foundation/multimedia/audio_framework/frameworks/native/common/include", - "//foundation/multinedia/audio_framework/interfaces/inner_api/native/audiocapturer/include", - "${common_path}/include", - "//drivers/peripheral/audio/interfaces/include", - ] - - sources = [ - "audio_buffer.cpp", - "daudio_test_utils.cpp", - "local_audio.cpp", - "cycle_test.cpp", - "hdf_audio.cpp", - "audio_base.cpp" - ] - - deps = [ - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "hdf_core:libhdf_utils", - "hiviewdfx_hilog_native:libhilog", - "multimedia_audio_framework:audio_client", - "multimedia_audio_framework:audio_capturer", - "multimedia_audio_framework:audio_renderer", - ] - - subsystem_name = "distributedhardware" - part_name = "distributed_audio" -} \ No newline at end of file diff --git a/common/test_utils/aec_test.cpp b/common/test_utils/aec_test.cpp deleted file mode 100644 index 12aa736a20ecb3f425ad23c1800d1e0b5cebc14c..0000000000000000000000000000000000000000 --- a/common/test_utils/aec_test.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2023 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 "aec_test.h" - -#include -#include "daudio_errorcode.h" - -using namespace std; - -namespace OHOS { -namespace DistributedHardware { -int32_t AecTest::Init() -{ - cout << "Input file path: "; - string path; - cin >> path; - cout << endl; - - size_t pos = path.find(".pcm"); - if (pos != string::npos) { - if (render_.ReadPcmFile(path, info_) != DH_SUCCESS) { - return ERR_DH_AUDIO_FAILED; - } - } else { - cout << "File path is wrong." << endl; - return ERR_DH_AUDIO_FAILED; - } - - render_.Init(info_); - capture_.Init(info_); - return DH_SUCCESS; -} - -int32_t AecTest::Process() -{ - capture_.StartCaptureFrame(render_.GetPeriod()); - render_.StartRenderFrame(); - capture_.StopCaptureFrame(); - return DH_SUCCESS; -} - -void AecTest::Release() -{ - render_.Release(); - capture_.Release(); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/common/test_utils/audio_base.cpp b/common/test_utils/audio_base.cpp deleted file mode 100644 index ec8268096522913d2173a3f88376704f3b57151a..0000000000000000000000000000000000000000 --- a/common/test_utils/audio_base.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "audio_base.h" - -#include -#include -#include "audio_info.h" -#include "audio_buffer.h" -#include "daudio_errorcode.h" - -constexpr int32_t OFFSET_1 = 256; -constexpr int32_t OFFSET_2 = 65536; -constexpr int32_t OFFSET_3 = 16777216; -constexpr int32_t INT8_SIZE = 1; -constexpr int32_t INT16_SIZE = 2; -constexpr int32_t INT32_SIZE = 4; - -using namespace std; - -namespace OHOS { -namespace DistributedHardware { -int32_t AudioObject::CmdReadInt() -{ - int32_t cmd = 0; - cin >> cmd; - cout << endl; - return cmd; -} - -int32_t AudioObject::ReadAudioInfo(AudioBufferInfo &info) -{ - constexpr int32_t cmd1 = 1; - constexpr int32_t cmd2 = 2; - cout << "Input sample rate: " << endl << "[1] 16000" << endl << "[2] 48000" << endl; - int32_t cmd = CmdReadInt(); - if (cmd == cmd1) { - info.sampleRate = (int32_t)OHOS::AudioStandard::AudioSamplingRate::SAMPLE_RATE_16000; - } else if (cmd == cmd2) { - info.sampleRate = (int32_t)OHOS::AudioStandard::AudioSamplingRate::SAMPLE_RATE_48000; - } else { - cout << "Sample rate not support." << endl; - return ERR_DH_AUDIO_FAILED; - } - - cout << "Input channel number: " << endl << "[1] 1Ch" << endl << "[2] 2Ch" << endl; - cmd = CmdReadInt(); - if (cmd == cmd1) { - info.channel = (int32_t)OHOS::AudioStandard::AudioChannel::MONO; - } else if (cmd == cmd2) { - info.channel = (int32_t)OHOS::AudioStandard::AudioChannel::STEREO; - } else { - cout << "Channel number not support." << endl; - return ERR_DH_AUDIO_FAILED; - } - info.format = (int32_t)OHOS::AudioStandard::AudioSampleFormat::SAMPLE_S16LE; - - cout << "======================================" << endl - << "information:" << endl - << "sample_rate: " << info.sampleRate << endl - << "channels: " << info.channel << endl - << "format: " << info.format << endl - << "======================================" << endl; - return DH_SUCCESS; -} - -int32_t AudioObject::ReadInt32(FILE *fd) -{ - char tmp[INT32_SIZE]; - fread(tmp, INT8_SIZE, INT32_SIZE, fd); - int32_t res = - (int32_t)tmp[0] + (int32_t)tmp[1] * OFFSET_1 + (int32_t)tmp[2] * OFFSET_2 + (int32_t)tmp[3] * OFFSET_3; - return res; -} - -int32_t AudioObject::ReadInt16(FILE *fd) -{ - char tmp[INT16_SIZE]; - fread(tmp, INT8_SIZE, INT16_SIZE, fd); - int32_t res = (int32_t)tmp[0] + (int32_t)tmp[1] * OFFSET_1; - return res; -} - -int32_t AudioObject::ReadWavFile(const std::string &path, AudioBufferInfo &info) -{ - FILE *fd = fopen(path.c_str(), "rb"); - if (fd == nullptr) { - cout << "File not exist." << endl; - return ERR_DH_AUDIO_FAILED; - } - - constexpr int32_t WAV_OFFSET_4 = 4; - constexpr int32_t WAV_OFFSET_22 = 22; - constexpr int32_t WAV_OFFSET_24 = 24; - constexpr int32_t WAV_OFFSET_44 = 44; - - rewind(fd); - fseek(fd, WAV_OFFSET_4, SEEK_SET); - info.size = ReadInt32(fd) - WAV_SIZE_OFFSET; - fseek(fd, WAV_OFFSET_22, SEEK_SET); - info.channel = ReadInt16(fd); - fseek(fd, WAV_OFFSET_24, SEEK_SET); - info.sampleRate = ReadInt32(fd); - info.format = (int32_t)OHOS::AudioStandard::AudioSampleFormat::SAMPLE_S16LE; - cout << "======================================" << endl - << path << " information:" << endl - << "channels: " << info.channel << endl - << "sample_rate: " << info.sampleRate << endl - << "length: " << info.size << endl - << "======================================" << endl; - - data_ = std::make_unique(info); - fseek(fd, WAV_OFFSET_44, SEEK_SET); - fread(data_->Data(), 1, info.size, fd); - fclose(fd); - - return DH_SUCCESS; -} - -int32_t AudioObject::ReadPcmFile(const std::string &path, AudioBufferInfo &info) -{ - FILE *fd = fopen(path.c_str(), "rb"); - if (fd == nullptr) { - cout << "File not exist." << endl; - return ERR_DH_AUDIO_FAILED; - } - fseek(fd, 0, SEEK_END); - info.size = ftell(fd); - rewind(fd); - - int32_t res = ReadAudioInfo(info); - if (res != DH_SUCCESS) { - fclose(fd); - return res; - } - data_ = std::make_unique(info); - fread(data_->Data(), 1, info.size, fd); - fclose(fd); - return DH_SUCCESS; -} - -int32_t AudioObject::SaveAudioData(const std::string &path) -{ - if (data_ == nullptr) { - return ERR_DH_AUDIO_NULLPTR; - } - int32_t res = data_->WirteBufferToFile(path); - cout << "[*]Save file in: " << path << endl; - if (res != DH_SUCCESS) { - cout << "Write audio file failed." << endl; - return ERR_DH_AUDIO_FAILED; - } - return DH_SUCCESS; -} - -int32_t GetEnvNoise(const std::shared_ptr &data) -{ - int32_t max = 0; - for (int32_t i = 0; i < data->GetInfo().size / (int32_t)sizeof(int16_t); i++) { - int16_t f = abs((reinterpret_castdata->Data())[i]); - if (f > max) { - max = f; - } - } - return max; -} - -bool IsFrameHigh(const int16_t *data, const int32_t size, int32_t threshhold) -{ - int32_t max = 0; - for (int32_t i = 0; i < size; i++) { - int16_t f = abs(data[i]); - if (f > max) { - max = f; - } - } - return (max >= threshhold ? true : false); -} - -int64_t GetNowTimeUs() -{ - std::chrono::microseconds nowUs = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); - return nowUs.count(); -} - -int64_t RecordBeepTime(const uint8_t *base, const AudioBufferInfo &info, bool &status) -{ - int32_t threshhold = 10000; - if (IsFrameHigh(reinterpret_castbase, info.sizePerFrame / sizeof(int16_t), threshhold) == true && - status == true) { - status = false; - return GetNowTimeUs(); - } else if (IsFrameHigh(reinterpret_castbase, info.sizePerFrame / sizeof(int16_t), threshhold) == false) { - status = true; - } - - return 0; -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/common/test_utils/audio_base.h b/common/test_utils/audio_base.h deleted file mode 100644 index 36f1477964fcccaa2b001361d5262475b25fbeb6..0000000000000000000000000000000000000000 --- a/common/test_utils/audio_base.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_AUDIO_BASE_H -#define OHOS_AUDIO_BASE_H - -#include -#include -#include - -#include "audio_buffer.h" - -namespace OHOS { -namespace DistributedHardware { - -constexpr int32_t FRAME_PER_SEC = 50; -constexpr int32_t BIT_FORMAT_16 = 2; -constexpr int32_t SECOND_ONE = 1; -constexpr int32_t MILLISECONDS_PER_SECOND = 1000; -constexpr int32_t MICROSECONDS_PER_MILLISECOND = 1000; -constexpr int32_t CAPTURE_TIME_MAX = 600; -constexpr int32_t WAV_SIZE_OFFSET = 36; - -class AudioObject { -public: - AudioObject() = default; - virtual ~AudioObject() = default; - virtual int32_t Init(const AudioBufferInfo &info) = 0; - virtual void Release() = 0; - virtual void RunThread() = 0; - virtual void Start() = 0; - virtual void Stop() = 0; - virtual int32_t CaptureFrame(const int32_t time) = 0; - int32_t ReadAudioInfo(AudioBufferInfo &info); - int32_t ReadWavFile(const std::string &path, AudioBufferInfo &info); - int32_t ReadPcmFile(const std::string &path, AudioBufferInfo &info); - int32_t SaveAudioData(const std::string &path); - std::shared_ptr GetData() const - { - return data_; - } - int32_t GetPeriod() const - { - return info_.period; - } - std::vector GetBeepTime() const - { - return beepTime_; - } - -protected: - AudioBufferInfo info_; - std::thread runThread_; - std::shared_ptr data_ = nullptr; - std::vector beepTime_; - -private: - int32_t CmdReadInt(); - int32_t ReadInt32(FILE *fd); - int32_t ReadInt16(FILE *fd); -}; - -int32_t GetEnvNoise(const std::shared_ptr &data); -bool IsFrameHigh(const int16_t *data, const int32_t size, int32_t threshhold); -int64_t RecordBeepTime(const uint8_t *base, const AudioBufferInfo &info, bool &status); -int64_t GetNowTimeUs(); -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_AUDIO_BASE_H \ No newline at end of file diff --git a/common/test_utils/audio_buffer.cpp b/common/test_utils/audio_buffer.cpp deleted file mode 100644 index c7367403dbdacbfd9241947b0522eb7128874e75..0000000000000000000000000000000000000000 --- a/common/test_utils/audio_buffer.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "audio_buffer.h" - -#include - -#include "daudio_errorcode.h" - -namespace OHOS { -namespace DistributedHardware { - -constexpr int32_t MAX_SIZE = 3840 * 50 * 6000; - -AudioBuffer::AudioBuffer(const int32_t size) -{ - if (size > 0 && size < MAX_SIZE) { - data_ = new (std::nothrow) uint8_t[size] {0}; - if (data_ != nullptr) { - param_.size = size; - param_.channel = 0; - param_.format = 0; - param_.sampleRate = 0; - } - } -} - -AudioBuffer::AudioBuffer(const AudioBufferInfo &info) -{ - if (info.size > 0 && info.size < MAX_SIZE) { - param_ = info; - data_ = new (std::nothrow) uint8_t[info.size] { 0 }; - } -} - -int32_t AudioBuffer::Size() const -{ - return param_.size; -} - -uint8_t *AudioBuffer::Data() const -{ - return data_; -} - -AudioBuffer::~AudioBuffer() -{ - if (data_ != nullptr) { - delete[] data_; - data_ = nullptr; - } - param_.size = 0; -} - -int32_t AudioBuffer::WirteBufferToFile(const std::string &path) -{ - if (data_ == nullptr || param_.size == 0) { - return ERR_DH_AUDIO_FAILED; - } - - FILE *fd = fopen(path.c_str(), "wb"); - if (fd == nullptr) { - std::cout << "Open file failed." << std::endl; - return ERR_DH_AUDIO_FAILED; - } - fwrite(data_, sizeof(uint8_t), param_.size, fd); - fclose(fd); - return DH_SUCCESS; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/common/test_utils/audio_buffer.h b/common/test_utils/audio_buffer.h deleted file mode 100644 index 2d901538f2f5caf1d28aa42487812aecdd2bf2a3..0000000000000000000000000000000000000000 --- a/common/test_utils/audio_buffer.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_AUDIO_DATA_H -#define OHOS_AUDIO_DATA_H - -#include - -namespace OHOS { -namespace DistributedHardware { -typedef struct { - int32_t sampleRate; - int32_t channel; - int32_t format; - int32_t size; - int32_t frames; - int32_t period; - int32_t sizePerFrame; - std::string filePath; -} AudioBufferInfo; - -class AudioBuffer { -public: - AudioBuffer() = default; - ~AudioBuffer(); - explicit AudioBuffer(const int32_t size); - explicit AudioBuffer(const AudioBufferInfo &info); - - int32_t Size() const; - uint8_t *Data() const; - AudioBufferInfo GetInfo() const - { - return param_; - } - - int32_t WirteBufferToFile(const std::string &path); - -private: - AudioBuffer(const AudioBuffer &) = delete; - AudioBuffer &operator = (const AudioBuffer &) = delete; - - AudioBufferInfo param_; - uint8_t *data_ = nullptr; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_AUDIO_DATA_H \ No newline at end of file diff --git a/common/test_utils/cycle_test.cpp b/common/test_utils/cycle_test.cpp deleted file mode 100644 index d0ec8ade582c46aac71c3be77d78060051901662..0000000000000000000000000000000000000000 --- a/common/test_utils/cycle_test.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2023 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 "cycle_test.h" - -#include - -#include "local_audio.h" -#include "hdf_audio.h" -#include "daudio_errorcode.h" - -using namespace std; - -namespace OHOS { -namespace DistributedHardware { -void CycleTest::GetMode() -{ - cout << "Input audio cycle test mode: " << endl - << "[1] Use Audio FrameWork play, Audio FrameWork capture." << endl - << "[2] Use Audio HDF play, Audio HDF capture." << endl; - int32_t mode; - cin >> mode; - cout << endl; - if (mode != MODE_LR_LC && mode != MODE_HR_HC) { - cout << "Mode is invalid." << endl; - return; - } - mode_ = static_cast(mode); - - cout << "Input speaker file path(/data/): "; - cin >> spkFile_; - cout << endl; - cout << "Input mic file path(/data/): "; - cin >> micFile_; - cout << endl; - - string dir = "/data/"; - spkFile_ = dir + spkFile_; - micFile_ = dir + micFile_; - return; -} - -int32_t CycleTest::Init() -{ - GetMode(); - switch (static_cast(mode_)) { - case MODE_INVALID: - render_ = make_unique(); - capture_ = make_unique(); - break; - case MODE_LR_LC: - render_ = make_unique(); - capture_ = make_unique(); - break; - case MODE_HR_HC: - render_ = make_unique(); - capture_ = make_unique(); - break; - default: - break; - } - - bool ready = false; - size_t pos = spkFile_.find(".pcm"); - if (pos != string::npos) { - if (render_->ReadPcmFile(spkFile_, info_) != DH_SUCCESS) { - return ERR_DH_AUDIO_FAILED; - } - ready = true; - } - pos = spkFile_.find(".wav"); - if (pos != string::npos) { - if (render_->ReadWavFile(spkFile_, info_) != DH_SUCCESS) { - return ERR_DH_AUDIO_FAILED; - } - ready = true; - } - if (ready != true) { - cout << "File path is wrong." << endl; - return ERR_DH_AUDIO_FAILED; - } - - render_->Init(info_); - capture_->Init(info_); - return DH_SUCCESS; -} - -int32_t CycleTest::Process() -{ - if (capture_ == nullptr || render_ == nullptr) { - return ERR_DH_AUDIO_NULLPTR; - } - capture_->CaptureFrame(render_->GetPeriod()); - capture_->Start(); - render_->Start(); - capture_->Stop(); - capture_->SaveAudioData(micFile_); - - auto start = render_->GetBeepTime(); - auto stop = capture_->GetBeepTime(); - if (start.size() != stop.size()) { - cout << "Record num is not equal(" << start.size() << " " << stop.size() << ")." << endl; - return ERR_DH_AUDIO_FAILED; - } - - for (size_t i = 0; i < start.size(); i++) { - cout << "Send: " << start[i] << " Received: " << stop[i] << endl; - cout << "Time is: " << stop[i] - start[i] << endl; - } - return DH_SUCCESS; -} - -void CycleTest::Release() -{ - if (capture_ != nullptr) { - capture_->Release(); - } - - if (render_ != nullptr) { - render_->Release(); - } -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/common/test_utils/cycle_test.h b/common/test_utils/cycle_test.h deleted file mode 100644 index 3d34c1ba14db61f604c6585722f45043eb1a4159..0000000000000000000000000000000000000000 --- a/common/test_utils/cycle_test.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_CYCLE_TEST_H -#define OHOS_CYCLE_TEST_H - -#include -#include "audio_base.h" -#include "audio_buffer.h" - -namespace OHOS { -namespace DistributedHardware { -typedef enum { - MODE_INVALID = 0, - MODE_LR_LC = 1, - MODE_HR_HC = 2, -} CYCLE_MODE; -class CycleTest { -public: - CycleTest() = default; - ~CycleTest() = default; - - int32_t Init(); - int32_t Process(); - void Release(); -private: - void GetMode(); - -private: - CYCLE_MODE mode_ = MODE_INVALID; - std::string spkFile_; - std::string micFile_; - std::unique_ptr render_; - std::unique_ptr capture_; - AudioBufferInfo info_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_CYCLE_TEST_H \ No newline at end of file diff --git a/common/test_utils/daudio_test_utils.cpp b/common/test_utils/daudio_test_utils.cpp deleted file mode 100644 index 52a4028501e14c86533277731a104dc627908e47..0000000000000000000000000000000000000000 --- a/common/test_utils/daudio_test_utils.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (c) 2023 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 "daudio_test_utils.h" - -#include -#include - -#include "audio_buffer.h" -#include "cycle_test.h" -#include "daudio_errorcode.h" -#include "local_audio.h" -#include "hdf_audio.h" - -using namespace std; - -const string CMD_QUIT = "quit"; -const string CMD_QUIT_EXT = "0"; -const string CMD_LOCAL_CAPTURE = "lmic"; -const string CMD_LOCAL_CAPTURE_EXT = "20"; -const string CMD_LOCAL_RENDER = "lspk"; -const string CMD_LOCAL_RENDER_EXT = "21"; -const string CMD_CYCLE_TEST = "cycle"; -const string CMD_CYCLE_TEST_EXT = "22"; -const string CMD_HDF_CAPTURE = "hmic"; -const string CMD_HDF_CAPTURE_EXT = "23"; -const string CMD_HDF_RENDER = "hspk"; -const string CMD_HDF_RENDER_EXT = "24"; -namespace OHOS { -namespace DistributedHardware { - -void DAudioTestUtils::DoAudioTest() -{ - bool running = true; - string cmd = ""; - while (running) { - cout << endl <<"Input test command: "; - cin >> cmd; - cout <> time_; - cout << endl; - capture.CaptureFrame(time_); - capture.Start(); - capture.Stop(); - capture.SaveAudioData("/data/mic.pcm"); - capture.Release(); -} - -void DAudioTestUtils::LocalRender() -{ - cout << "[LocalRender]" << endl; - AudioRenderObj render; - AudioBufferInfo info; - - cout << "Input file path: "; - cin >> path_; - cout << endl; - - size_t pos = path_.find(".wav"); - if (pos != string::npos) { - if (render.ReadWavFile(path_, info) != DH_SUCCESS) { - return; - } - } - pos = path_.find(".pcm"); - if (pos != string::npos) { - if (render.ReadPcmFile(path_, info) != DH_SUCCESS) { - return; - } - } - - int32_t res = render.Init(info); - if (res != DH_SUCCESS) { - return; - } - render.Start(); - render.Stop(); - render.Release(); -} - -void DAudioTestUtils::AudioCycleTest() -{ - cout << "[CycleTest]" << endl; - CycleTest test; - int32_t res = test.Init(); - if (res != DH_SUCCESS) { - return; - } - test.Process(); - test.Release(); -} - -void DAudioTestUtils::HDFCapture() -{ - cout << "[HDFCapture]" << endl; - HDFAudioCaptureObj capture; - AudioBufferInfo info; - int32_t res = capture.ReadAudioInfo(info); - if (res != DH_SUCCESS) { - return; - } - res = capture.Init(info); - if (res != DH_SUCCESS) { - return; - } - cout << "Input capture time(s): "; - cin >> time_; - cout << endl; - capture.CaptureFrame(time_); - capture.Start(); - capture.Stop(); - capture.SaveAudioData("/data/mic.pcm"); - capture.Release(); -} - -void DAudioTestUtils::HDFRender() -{ - cout << "[HDFRender]" << endl; - HDFAudioRenderObj render; - AudioBufferInfo info; - - cout << "Input file path: "; - cin >> path_; - cout << endl; - - size_t pos = path_.find(".wav"); - if (pos != string::npos) { - if (render.ReadWavFile(path_, info) != DH_SUCCESS) { - return; - } - } - pos = path_.find(".pcm"); - if (pos != string::npos) { - if (render.ReadPcmFile(path_, info) != DH_SUCCESS) { - return; - } - } - - int32_t res = render.Init(info); - if (res != DH_SUCCESS) { - return; - } - render.Start(); - render.Stop(); - render.Release(); -} -} // namespace DistributedHardware -} // namespace OHOS - -int32_t main() -{ - cout << "**********************************************************************************" << endl - << "Distributed Audio Test Demo Bin." << endl - << "**********************************************************************************" << endl; - OHOS::DistributedHardware::DAudioTestUtils testBin; - testBin.DoAudioTest(); - return 0; -} \ No newline at end of file diff --git a/common/test_utils/hdf_audio.cpp b/common/test_utils/hdf_audio.cpp deleted file mode 100644 index 0cab52869141c22b0ec711aa735c84c5003e7f19..0000000000000000000000000000000000000000 --- a/common/test_utils/hdf_audio.cpp +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Copyright (c) 2023 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 "hdf_audio.h" - -#include -#include -#include -#include -#include - -#include "audio_adapter.h" -#include "audio_manager.h" -#include "audio_types.h" -#include "daudio_errorcode.h" - -using namespace std; - -namespace OHOS { -namespace DistributedHardware { - -static struct AudioManager *g_audioManager; -static struct AudioAdapter *g_audioAdapter; -static struct AudioCapture *g_audioCapture; -static struct AudioRender *g_audioRender; -static bool g_micInUse = false; -static bool g_spkInUse = false; -static void *g_handle = nullptr; -static constexpr const char* RENDER_RUN_THREAD = "hdfSpkRunTh"; -static constexpr const char* CAPTURE_RUN_THREAD = "hdfMicRunTh"; - -static int32_t GetAudioManager() -{ - struct AudioManager *(*func)() = nullptr; - string audioMgrPath = "/system/lib64/libhdi_audio_client.z.so"; - g_handle = dlopen(audioMgrPath.c_str(), RTLD_LAZY); - if (g_handle == nullptr) { - cout << "Open " << audioMgrPath << " failed." <(dlsym(g_handle, "GetAudioManagerFuncs")); - if (func == nullptr) { - cout << "Dlsym GetAudioManagerFuncs failed." <GetAllAdapters(g_audioManager, &descs, &size); - if (size > adpMaxNum || size == 0 || descs == nullptr || ret != 0) { - cout << "Get audio adapters failed." << endl; - return ERR_DH_AUDIO_FAILED; - } - struct AudioAdapterDescriptor *primaryDesc = nullptr; - for (int32_t index = 0; index < size; index++) { - auto desc = &descs[index]; - if (desc == nullptr || desc->adapterName == nullptr) { - continue; - } - if (!strcmp(desc->adapterName, "primary")) { - primaryDesc = desc; - break; - } - } - if (primaryDesc == nullptr) { - cout << "Find primary adapter failed." << endl; - return ERR_DH_AUDIO_FAILED; - } - ret = g_audioManager->LoadAdapter(g_audioManager, primaryDesc, &g_audioAdapter); - if (ret != DH_SUCCESS || g_audioAdapter == nullptr) { - cout << "Load primary adapter failed." << endl; - return ERR_DH_AUDIO_FAILED; - } - return DH_SUCCESS; -} - -static void ReleaseHDFAudioDevice() -{ - if (g_micInUse != false && g_spkInUse != false) { - return; - } - if (g_audioManager != nullptr) { - g_audioManager->UnloadAdapter(g_audioManager, g_audioAdapter); - } - g_audioManager = nullptr; - g_audioAdapter = nullptr; - (void)dlclose(g_handle); -} - -static int32_t InitHDFAudioDevice() -{ - if (g_micInUse != false || g_spkInUse != false) { - return DH_SUCCESS; - } - - if (GetAudioManager() != DH_SUCCESS) { - ReleaseHDFAudioDevice(); - return ERR_DH_AUDIO_FAILED; - } - - if (GetAdapter() != DH_SUCCESS) { - ReleaseHDFAudioDevice(); - return ERR_DH_AUDIO_FAILED; - } - return DH_SUCCESS; -} - -HDFAudioCaptureObj::HDFAudioCaptureObj() -{ - int32_t period = 1024; - int32_t streamId = 1; - captureDesc_.pins = AudioPortPin::PIN_IN_MIC; - captureDesc_.desc = nullptr; - captureAttr_.format = AUDIO_FORMAT_TYPE_PCM_16_BIT; - captureAttr_.interleaved = true; - captureAttr_.streamId = streamId; - captureAttr_.type = AUDIO_IN_MEDIA; - captureAttr_.period = period; - captureAttr_.isBigEndian = false; - captureAttr_.isSignedData = true; - captureAttr_.stopThreshold = 0x7fffffff; -} - -int32_t HDFAudioCaptureObj::Init(const AudioBufferInfo &info) -{ - cout << "[1]Create hdf audio capture." << endl; - if (InitHDFAudioDevice() != DH_SUCCESS) { - return ERR_DH_AUDIO_FAILED; - } - - info_ = info; - captureAttr_.channelCount = info.channel; - captureAttr_.sampleRate = info.sampleRate; - int32_t ret = g_audioAdapter->CreateCapture(g_audioAdapter, &captureDesc_, &captureAttr_, &g_audioCapture); - if (ret != DH_SUCCESS || g_audioCapture == nullptr) { - cout << "[1]CreateCapture failed, ret: " << ret << endl; - return ERR_DH_AUDIO_FAILED; - } - g_micInUse = true; - cout << "[1]Create hdf audio capture success."<< endl; - return DH_SUCCESS; -} - -void HDFAudioCaptureObj::Release() -{ - cout << "[4]Release hdf audio capture." << endl; - while (runThread_.joinable()) { - runThread_.join(); - } - if (g_audioAdapter != nullptr) { - g_audioAdapter->DestroyCapture(g_audioAdapter, g_audioCapture); - } - g_micInUse = false; - ReleaseHDFAudioDevice(); - cout << "[4]Release hdf audio capture success." << endl; -} - -int32_t HDFAudioCaptureObj::CaptureFrame(const int32_t time) -{ - if (g_audioCapture == nullptr) { - return ERR_DH_AUDIO_NULLPTR; - } - info_.period = time; - if (info_.period <= 0 || info_.period >= CAPTURE_TIME_MAX) { - cout << "Capture time is invalid." << endl; - return ERR_DH_AUDIO_FAILED; - } - info_.size = info_.sampleRate * info_.channel * BIT_FORMAT_16 * info_.period; - info_.frames = FRAME_PER_SEC * info_.period; - info_.sizePerFrame = info_.sampleRate * info_.channel * BIT_FORMAT_16 / FRAME_PER_SEC; - data_ = make_unique(info_); - - return DH_SUCCESS; -} - -void HDFAudioCaptureObj::RunThread() -{ - if (g_audioCapture == nullptr || data_ == nullptr || data_->Data() == nullptr) { - cout << "Capture or data is null." << endl; - return; - } - - if (pthread_setname_np(pthread_self(), CAPTURE_RUN_THREAD) != DH_SUCCESS) { - cout << "Hdf capture run thread setname failed." << endl; - } - int32_t playIndex = 0; - uint64_t size = 0; - uint8_t *base = data_->Data(); - auto data = make_unique(info_.sizePerFrame); - while (playIndex < info_.frames) { - g_audioCapture->CaptureFrame(g_audioCapture, data->Data(), info_.sizePerFrame, &size); - if (memcpy_s(base, data_->Size(), data->Data(), data->Size()) != EOK) { - cout << "Copy buffer failed." << endl; - break; - } - base += info_.sizePerFrame; - playIndex++; - } - cout << "[*]Capture frame number is: " << info_.frames << endl; -} - -void HDFAudioCaptureObj::Start() -{ - cout << "[2]Start hdf capture thread." << endl; - if (g_audioCapture == nullptr) { - return; - } - g_audioCapture->control.Start((AudioHandle)g_audioCapture); - runThread_ = thread(&HDFAudioCaptureObj::RunThread, this); - while (!runThread_.joinable()) { - } - cout << "[2]Start hdf capture thread success." << endl; -} - -void HDFAudioCaptureObj::Stop() -{ - usleep(MILLISECONDS_PER_SECOND * MICROSECONDS_PER_MILLISECOND * (info_.period + SECOND_ONE)); - if (g_audioCapture != nullptr) { - g_audioCapture->control.Stop((AudioHandle)g_audioCapture); - } - cout << "[3]Stop hdf capture thread success." << endl; -} - -HDFAudioRenderObj::HDFAudioRenderObj() -{ - int32_t period = 1024; - int32_t streamId = 0; - renderDesc_.pins = AudioPortPin::PIN_OUT_SPEAKER; - renderDesc_.desc = nullptr; - renderAttr_.interleaved = true; - renderAttr_.streamId = streamId; - renderAttr_.type = AUDIO_IN_MEDIA; - renderAttr_.period = period; - renderAttr_.isBigEndian = false; - renderAttr_.isSignedData = true; - renderAttr_.stopThreshold = 0x7fffffff; - renderAttr_.silenceThreshold = 0; - renderAttr_.format = AUDIO_FORMAT_TYPE_PCM_32_BIT; -} - -int32_t HDFAudioRenderObj::Init(const AudioBufferInfo &info) -{ - cout << "[1]Create hdf audio render." << endl; - if (InitHDFAudioDevice() != DH_SUCCESS) { - return ERR_DH_AUDIO_FAILED; - } - - renderAttr_.sampleRate = info.sampleRate; - renderAttr_.channelCount = info.channel; - info_ = info; - info_.sizePerFrame = info_.sampleRate * info_.channel * BIT_FORMAT_16 / FRAME_PER_SEC; - info_.frames = info_.size / info_.sizePerFrame; - info_.period = info_.frames / FRAME_PER_SEC; - int32_t ret = g_audioAdapter->CreateRender(g_audioAdapter, &renderDesc_, &renderAttr_, &g_audioRender); - if (ret != DH_SUCCESS || g_audioRender == nullptr) { - std::cout<<"[1]CreateRender failed, ret: "<< ret << std::endl; - return ERR_DH_AUDIO_FAILED; - } - g_spkInUse = true; - cout << "[1]Create hdf audio render success." << endl; - return DH_SUCCESS; -} - -void HDFAudioRenderObj::Release() -{ - cout << "[4]Release hdf audio render." << endl; - while (runThread_.joinable()) { - runThread_.join(); - } - if (g_audioAdapter != nullptr) { - g_audioAdapter->DestroyRender(g_audioAdapter, g_audioRender); - } - g_spkInUse = false; - ReleaseHDFAudioDevice(); - cout << "[4]Release hdf audio render success." << endl; -} - -void HDFAudioRenderObj::RunThread() -{ - if (g_audioRender == nullptr || data_ == nullptr || data_->Data() == nullptr) { - return; - } - - if (pthread_setname_np(pthread_self(), RENDER_RUN_THREAD) != DH_SUCCESS) { - cout << "Hdf render run thread setname failed."<< endl; - } - int32_t playIndex = 0; - int32_t offset = 65535; - uint64_t size = 0; - int32_t dataSize = info_.sizePerFrame * sizeof(int32_t) / sizeof(int16_t); - uint8_t *base = data_->Data(); - auto data = std::make_unique(dataSize); - while (playIndex < info_.frames) { - for (int32_t i = 0; i < info_.sizePerFrame; i++) { - (reinterpret_cast(data->Data()))[i] = (reinterpret_cast(base))[i] * offset; - } - g_audioRender->RenderFrame(g_audioRender, data->Data(), dataSize, &size); - base += info_.sizePerFrame; - playIndex++; - } - cout << "[*]Render frame number is: " << info_.frames << endl; -} - -void HDFAudioRenderObj::Start() -{ - cout << "[2]Start hdf paly thread." << endl; - if (g_audioRender == nullptr) { - return; - } - g_audioRender->control.Start((AudioHandle)g_audioRender); - runThread_ = std::thread(&HDFAudioRenderObj::RunThread, this); - while (!runThread_.joinable()) { - } - cout << "[2]Start hdf play thread success." << endl; -} - -void HDFAudioRenderObj::Stop() -{ - usleep(MILLISECONDS_PER_SECOND * MICROSECONDS_PER_MILLISECOND * (info_.period + SECOND_ONE)); - if (g_audioRender != nullptr) { - g_audioRender->control.Stop((AudioHandle)g_audioRender); - } - cout << "[2]Stop hdf play thread success." << endl; -} - -int32_t HDFAudioRenderObj::CaptureFrame(const int32_t time) -{ - (void) time; - return DH_SUCCESS; -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/common/test_utils/hdf_audio.h b/common/test_utils/hdf_audio.h deleted file mode 100644 index 2625a30615821c0cd3084004c7532d940c289227..0000000000000000000000000000000000000000 --- a/common/test_utils/hdf_audio.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDF_AUDIO_H -#define OHOS_HDF_AUDIO_H - -#include - -#include "audio_types.h" -#include "audio_capturer.h" -#include "audio_renderer.h" -#include "audio_base.h" -#include "audio_buffer.h" - -namespace OHOS { -namespace DistributedHardware { -class HDFAudioCaptureObj : public AudioObject { -public: - HDFAudioCaptureObj(); - ~HDFAudioCaptureObj() override = default; - int32_t Init(const AudioBufferInfo &info) override; - void Release() override; - void RunThread() override; - void Start() override; - void Stop() override; - int32_t CaptureFrame(const int32_t time) override; -private: - - struct AudioDeviceDescriptor captureDesc_; - struct AudioSampleAttributes captureAttr_; -}; - -class HDFAudioRenderObj : public AudioObject { -public: - HDFAudioRenderObj(); - ~HDFAudioRenderObj() override = default; - int32_t Init(const AudioBufferInfo &info) override; - void Release() override; - void RunThread() override; - void Start() override; - void Stop() override; - int32_t CaptureFrame(const int32_t time) override;; -private: - - struct AudioDeviceDescriptor renderDesc_; - struct AudioSampleAttributes renderAttr_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_HDF_AUDIO_H \ No newline at end of file diff --git a/common/test_utils/local_audio.cpp b/common/test_utils/local_audio.cpp deleted file mode 100644 index 843a764d193d98fafd0e249d0a671138801cc54a..0000000000000000000000000000000000000000 --- a/common/test_utils/local_audio.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) 2023 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 "local_audio.h" - -#include - -#include -#include "daudio_errorcode.h" - -using namespace std; -namespace OHOS { -namespace DistributedHardware { -static constexpr const char* RENDER_RUN_THREAD = "localSpkRunTh"; -static constexpr const char* CAPTURE_RUN_THREAD = "localMicRunTh"; -AudioCaptureObj::AudioCaptureObj() -{ - opts_.capturerInfo.sourceType = OHOS::AudioStandard::SourceType::SOURCE_TYPE_MIC; - opts_.streamInfo.encoding = OHOS::AudioStandard::AudioEncodingType::ENCODING_PCM; - opts_.capturerInfo.capturerFlags = 0; -} - -int32_t AudioCaptureObj::Init(const AudioBufferInfo &info) -{ - cout << "[1]Create local audio capturer." << endl; - info_ = info; - opts_.streamInfo.samplingRate = (OHOS::AudioStandard::AudioSamplingRate)info.sampleRate; - opts_.streamInfo.channels = (OHOS::AudioStandard::AudioChannel)info.channel; - opts_.streamInfo.format = (OHOS::AudioStandard::AudioSampleFormat)info.format; - capturer_ = OHOS::AudioStandard::AudioCapturer::Create(opts_); - if (capturer_ == nullptr) { - cout << "[1]Create local audio capturer failed." << endl; - return ERR_DH_AUDIO_NULLPTR; - } - cout << "[1]Create local audio capturer success." << endl; - return DH_SUCCESS; -} - -void AudioCaptureObj::Release() -{ - cout << "[4]Release local audio capturer." << endl; - while (runThread_.joinable()) { - runThread_.join(); - } - if (capturer_ != nullptr) { - capturer_->Release(); - } - cout << "[4]Release local audio capturer success." << endl; -} - -int32_t AudioCaptureObj::CaptureFrame(const int32_t time) -{ - info_.period = time; - if (info_.period <= 0 || info_.period >= CAPTURE_TIME_MAX) { - cout << "Capture time is invalid." << endl; - return ERR_DH_AUDIO_FAILED; - } - info_.size = info_.sampleRate * info_.channel * BIT_FORMAT_16 * info_.period; - info_.frames = FRAME_PER_SEC * info_.period; - info_.sizePerFrame = info_.sampleRate * info_.channel * BIT_FORMAT_16 / FRAME_PER_SEC; - data_ = std::make_unique(info_); - return DH_SUCCESS; -} - -void AudioCaptureObj::Start() -{ - cout << "[2]Start local capture thread." << endl; - if (capturer_ == nullptr) { - return; - } - capturer_->Start(); - runThread_ = std::thread(&AudioCaptureObj::RunThread, this); - while (!runThread_.joinable()) { - } - cout << "[2]Start local capture thread success." << endl; -} - -void AudioCaptureObj::Stop() -{ - usleep(MILLISECONDS_PER_SECOND * MICROSECONDS_PER_MILLISECOND * (info_.period + SECOND_ONE)); - if (capturer_ != nullptr) { - capturer_->Stop(); - } - cout << "[3]Stop local capture thread success." << endl; -} - -void AudioCaptureObj::RunThread() -{ - if (capturer_ == nullptr || data_ == nullptr || data_->Data() == nullptr) { - return; - } - - if (pthread_setname_np(pthread_self(), CAPTURE_RUN_THREAD) != DH_SUCCESS) { - cout << "Local capture run thread setname failed."<< endl; - } - int32_t playIndex = 0; - uint8_t *base = data_->Data(); - auto data = std::make_unique(info_.sizePerFrame); - while (playIndex < info_.frames) { - int32_t readOffSet = 0; - while (readOffSet < info_.sizePerFrame) { - int32_t len = capturer_->Read(*(data->Data() + readOffSet), info_.sizePerFrame - readOffSet, true); - readOffSet += len; - } - if (memcpy_s(base, data_->Size(), data->Data(), data->Size()) != EOK) { - cout << "Copy buffer failed." << endl; - break; - } - base += info_.sizePerFrame; - playIndex++; - } - cout << "[*]Capture frame number is: " << info_.frames << endl; -} - -AudioRenderObj::AudioRenderObj() -{ - opts_.streamInfo.encoding = OHOS::AudioStandard::AudioEncodingType::ENCODING_PCM; - opts_.rendererInfo.contentType = OHOS::AudioStandard::ContentType::CONTENT_TYPE_MUSIC; - opts_.rendererInfo.streamUsage = OHOS::AudioStandard::StreamUsage::STREAM_USAGE_MEDIA; - opts_.rendererInfo.rendererFlags = 0; -} - -int32_t AudioRenderObj::Init(const AudioBufferInfo &info) -{ - cout << "[1]Create local audio render." << endl; - - info_ = info; - info_.sizePerFrame = info_.sampleRate * info_.channel * BIT_FORMAT_16 / FRAME_PER_SEC; - info_.frames = info_.size / info_.sizePerFrame; - info_.period = info_.frames / FRAME_PER_SEC; - - opts_.streamInfo.samplingRate = (OHOS::AudioStandard::AudioSamplingRate)info_.sampleRate; - opts_.streamInfo.channels = (OHOS::AudioStandard::AudioChannel)info_.channel; - opts_.streamInfo.format = (OHOS::AudioStandard::AudioSampleFormat)info_.format; - render_ = OHOS::AudioStandard::AudioRenderer::Create(opts_); - if (render_ == nullptr) { - cout << "[1]Create local audio render failed." << endl; - return ERR_DH_AUDIO_NULLPTR; - } - cout << "[1]Create local audio render success." << endl; - return DH_SUCCESS; -} - -void AudioRenderObj::Release() -{ - cout << "[4]Release local audio render." << endl; - while (runThread_.joinable()) { - runThread_.join(); - } - if (render_ != nullptr) { - render_->Release(); - } - cout << "[4]Release local audio render success." << endl; -} - -void AudioRenderObj::Start() -{ - cout << "[2]Start local play thread." << endl; - if (render_ == nullptr) { - return; - } - render_->Start(); - runThread_ = std::thread(&AudioRenderObj::RunThread, this); - while (!runThread_.joinable()) { - } - cout << "[2]Start local play thread success." << endl; -} - -void AudioRenderObj::Stop() -{ - usleep(MILLISECONDS_PER_SECOND * MICROSECONDS_PER_MILLISECOND * (info_.period + SECOND_ONE)); - if (render_ != nullptr) { - render_->Stop(); - } - cout << "[2]Stop local play thread success." << endl; -} - -void AudioRenderObj::RunThread() -{ - if (render_ == nullptr || data_ == nullptr || data_->Data() == nullptr) { - return; - } - - if (pthread_setname_np(pthread_self(), RENDER_RUN_THREAD) != DH_SUCCESS) { - cout << "Local render run thread setname failed."<< endl; - } - int32_t playIndex = 0; - uint8_t *base = data_->Data(); - auto data = std::make_unique(info_.sizePerFrame); - while (playIndex < info_.frames) { - if (memcpy_s(data->Data(), data->Size(), base, info_.sizePerFrame) != EOK) { - cout << "Copy buffer failed." << endl; - break; - } - int32_t writeOffSet = 0; - while (writeOffSet < info_.sizePerFrame) { - int32_t writeLen = render_->Write(data->Data() + writeOffSet, info_.sizePerFrame - writeOffSet); - writeOffSet += writeLen; - } - base += info_.sizePerFrame; - playIndex++; - } - cout << "[*]Render frame number is: " << info_.frames << endl; -} - -int32_t AudioRenderObj::CaptureFrame(const int32_t time) -{ - (void) time; - return DH_SUCCESS; -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/common/test_utils/local_audio.h b/common/test_utils/local_audio.h deleted file mode 100644 index 01c9234ff36feff9cf609c8856171f01500c7f42..0000000000000000000000000000000000000000 --- a/common/test_utils/local_audio.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_LOCAL_AUDIO_H -#define OHOS_LOCAL_AUDIO_H - -#include - -#include "audio_capturer.h" -#include "audio_renderer.h" -#include "audio_info.h" -#include "audio_base.h" - -namespace OHOS { -namespace DistributedHardware { -class AudioCaptureObj : public AudioObject { -public: - AudioCaptureObj(); - ~AudioCaptureObj() override = default; - int32_t Init(const AudioBufferInfo &info) override; - void Release() override; - void RunThread() override; - void Start() override; - void Stop() override; - int32_t CaptureFrame(const int32_t time) override; -private: - OHOS::AudioStandard::AudioCapturerOptions opts_; - std::unique_ptr capturer_ = nullptr; -}; - -class AudioRenderObj : public AudioObject { -public: - AudioRenderObj(); - ~AudioRenderObj() override = default; - int32_t Init(const AudioBufferInfo &info) override; - void Release() override; - void RunThread() override; - void Start() override; - void Stop() override; - int32_t CaptureFrame(const int32_t time) override; -private: - - OHOS::AudioStandard::AudioRendererOptions opts_; - std::unique_ptr render_ = nullptr; -}; - -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_LOCAL_AUDIO_H \ No newline at end of file diff --git a/hdf_interfaces/distributed_audio/audio/v1_0/BUILD.gn b/hdf_interfaces/distributed_audio/audio/v1_0/BUILD.gn index 86d8eff3c639233c9bd4d4c9313a2eeee5350ff5..05f1c7e2f3b5a8eaa00919fd932e900d43823213 100644 --- a/hdf_interfaces/distributed_audio/audio/v1_0/BUILD.gn +++ b/hdf_interfaces/distributed_audio/audio/v1_0/BUILD.gn @@ -15,12 +15,12 @@ import("//drivers/hdf_core/adapter/uhdf2/hdi.gni") hdi("daudio") { module_name = "daudio" sources = [ + "AudioTypes.idl", "IAudioAdapter.idl", + "IAudioCallback.idl", "IAudioCapture.idl", "IAudioManager.idl", "IAudioRender.idl", - "AudioTypes.idl", - "IAudioCallback.idl", ] language = "cpp" root = "ohos.hdi://foundation/distributedhardware/distributed_audio/hdf_interfaces/" diff --git a/hdf_interfaces/distributed_audio/audioext/v1_0/IDAudioCallback.idl b/hdf_interfaces/distributed_audio/audioext/v1_0/IDAudioCallback.idl index 6c2c6c1730a706f26c6f6f3096b2636b965a7ac6..b4f787c74dc56948a30b3986be291b3317fcfe76 100644 --- a/hdf_interfaces/distributed_audio/audioext/v1_0/IDAudioCallback.idl +++ b/hdf_interfaces/distributed_audio/audioext/v1_0/IDAudioCallback.idl @@ -24,6 +24,6 @@ import ohos.hdi.distributed_audio.audioext.v1_0.Types; NotifyEvent([in] String adpName, [in] int devId, [in] struct DAudioEvent event); WriteStreamData([in] String adpName, [in] int devId, [in] struct AudioData data); ReadStreamData([in] String adpName, [in] int devId, [out] struct AudioData data); - ReadMmapPosition([in] String adpName, [in] int devId, [out] unsigned long frames, [out] unsigned long timeStamp); + ReadMmapPosition([in] String adpName, [in] int devId, [out] unsigned long frames, [out] struct CurrentTime time); RefreshAshmemInfo([in] String adpName, [in] int devId, [in] FileDescriptor fd, [in] int ashmemLength, [in] int lengthPerTrans); } \ No newline at end of file diff --git a/hdf_interfaces/distributed_audio/audioext/v1_0/Types.idl b/hdf_interfaces/distributed_audio/audioext/v1_0/Types.idl index d31a47aea6a2476c2dddf54f5b22996e32f18ebd..35b5c1fb6b8f382d42205c50922046c8b7f77681 100644 --- a/hdf_interfaces/distributed_audio/audioext/v1_0/Types.idl +++ b/hdf_interfaces/distributed_audio/audioext/v1_0/Types.idl @@ -14,6 +14,10 @@ */ package ohos.hdi.distributed_audio.audioext.v1_0; +enum PortOperationMode { + NORMAL_MODE = 0, + MMAP_MODE = 1, +}; struct AudioParameter { unsigned int format; unsigned int channelCount; @@ -21,8 +25,8 @@ struct AudioParameter { unsigned int period; unsigned int frameSize; unsigned int streamUsage; - int renderFlags; - int capturerFlags; + enum PortOperationMode renderFlags; + enum PortOperationMode capturerFlags; String ext; }; struct AudioData { @@ -33,3 +37,7 @@ struct DAudioEvent { int type; String content; }; +struct CurrentTime { + long tvSec; + long tvNSec; +}; \ No newline at end of file diff --git a/hdf_interfaces/distributed_audio/bundle.json b/hdf_interfaces/distributed_audio/bundle.json index 9ee9786ec078f8de6fd575c9747fd6c962c2db85..0b2891a41bd527730bba4fe65ad61d956cb68e04 100644 --- a/hdf_interfaces/distributed_audio/bundle.json +++ b/hdf_interfaces/distributed_audio/bundle.json @@ -1,13 +1,15 @@ { - "name": "drivers_interface_distributed_audio", + "name": "@ohos/drivers_interface_distributed_audio", "description": "distributed audio device driver interface", - "version": "1.0", + "version": "4.0", "license": "Apache License 2.0", "component": { "name": "drivers_interface_distributed_audio", "subsystem": "distributedhardware", "syscap": [""], - "adapter_system_type": ["standard"], + "adapted_system_type":[ + "standard" + ], "rom": "675KB", "ram": "1024KB", "deps": { diff --git a/hdf_service/distributed_audio/bundle.json b/hdf_service/distributed_audio/bundle.json index 3104d33b62bf050e2b2ee7a85b5defd61b5375eb..605514fa696ca6fc6970fc02f1dd8e32acac0caf 100644 --- a/hdf_service/distributed_audio/bundle.json +++ b/hdf_service/distributed_audio/bundle.json @@ -1,13 +1,15 @@ { - "name": "drivers_peripheral_distributed_audio", + "name": "@ohos/drivers_peripheral_distributed_audio", "description": "distributed audo device driver", - "version": "3.1", + "version": "4.0", "license": "Apache License 2.0", "component": { "name": "drivers_peripheral_distributed_audio", "subsystem": "distributedhardware", "syscap": [ "" ], - "adapter_system_type": ["standard"], + "adapted_system_type":[ + "standard" + ], "rom": "1000KB", "ram": "8000KB", "deps": { diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/BUILD.gn index 638663e11ef31e0aa3af720e79cb05209fe5a91c..bb3479370f053c3a41784290b72b9d5fe13a8c7b 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") ohos_shared_library("libaudio_manager_daudio_primary_service_1.0") { include_dirs = [ @@ -28,11 +27,9 @@ ohos_shared_library("libaudio_manager_daudio_primary_service_1.0") { "./src/audio_adapter_interface_impl.cpp", "./src/audio_capture_interface_impl.cpp", "./src/audio_capture_interface_impl_base.cpp", - "./src/audio_capture_lowlatency_impl.cpp", "./src/audio_manager_interface_impl.cpp", "./src/audio_render_interface_impl.cpp", "./src/audio_render_interface_impl_base.cpp", - "./src/audio_render_lowlatency_impl.cpp", ] public_deps = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_adapter_interface_impl.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_adapter_interface_impl.h index 73c4df7a3a0acba52b122e2764af961228987c51..569bbbf55592c41971fdb638b711649ceca9e95a 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_adapter_interface_impl.h +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_adapter_interface_impl.h @@ -26,10 +26,8 @@ #include "audio_capture_interface_impl.h" #include "audio_capture_interface_impl_base.h" -#include "audio_capture_lowlatency_impl.h" #include "audio_render_interface_impl.h" #include "audio_render_interface_impl_base.h" -#include "audio_render_lowlatency_impl.h" namespace OHOS { namespace HDI { @@ -37,6 +35,7 @@ namespace DistributedAudio { namespace Audio { namespace V1_0 { using OHOS::HDI::DistributedAudio::Audioext::V1_0::DAudioEvent; +using OHOS::HDI::DistributedAudio::Audioext::V1_0::PortOperationMode; using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioParameter; using OHOS::HDI::DistributedAudio::Audioext::V1_0::IDAudioCallback; @@ -63,11 +62,6 @@ typedef enum { EVENT_IS_STREAM_MUTE = 4, } VolumeEventType; -typedef enum { - NORMAL_FLAG = 0, - MMAP_FLAG = 1, -} RenderCaptureFlag; - class AudioAdapterInterfaceImpl : public IAudioAdapter { public: explicit AudioAdapterInterfaceImpl(const AudioAdapterDescriptor &desc); @@ -156,8 +150,8 @@ private: uint32_t timeInterval_ = 5; // mmap param - int32_t renderFlags_ = NORMAL_FLAG; - int32_t capturerFlags_ = NORMAL_FLAG; + PortOperationMode renderFlags_ = Audioext::V1_0::NORMAL_MODE; + PortOperationMode capturerFlags_ = Audioext::V1_0::NORMAL_MODE; const std::string NOT_MUTE_STATUS = "0"; const std::string IS_MUTE_STATUS = "1"; diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl.h index cf2169367b527136d106437713546492589f3321..d60f8db4944c52026632fa78dd74a53bbaeb13ee 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl.h +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl.h @@ -80,14 +80,14 @@ public: int32_t TurnStandbyMode() override; int32_t AudioDevDump(int32_t range, int32_t fd) override; int32_t IsSupportsPauseAndResume(bool &supportPause, bool &supportResume) override; - int64_t CalculateOffset(int64_t count); private: + static constexpr int64_t AUDIO_OFFSET_FRAME_NUM = 10; std::string adapterName_; AudioDeviceDescriptor devDesc_; AudioSampleAttributes devAttrs_; uint32_t timeInterval_ = 5; - int32_t frameIdx_ = 0; + int64_t frameIndex_ = 0; int64_t framePeriodNs_ = 0; int64_t startTime_ = 0; diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_lowlatency_impl.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_lowlatency_impl.h deleted file mode 100644 index c6b2e00858251ec0f5db324575b6a47ba1b3a821..0000000000000000000000000000000000000000 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_lowlatency_impl.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_AUDIO_CAPTURE_LOWLATENCY_IMPL_H -#define OHOS_AUDIO_CAPTURE_LOWLATENCY_IMPL_H - -#include -#include -#include - -#include -#include -#include - -#include "ashmem.h" -#include "audio_capture_interface_impl.h" -#include "audio_capture_interface_impl_base.h" - -namespace OHOS { -namespace HDI { -namespace DistributedAudio { -namespace Audio { -namespace V1_0 { -using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioData; -using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioParameter; -using OHOS::HDI::DistributedAudio::Audioext::V1_0::DAudioEvent; -using OHOS::HDI::DistributedAudio::Audioext::V1_0::IDAudioCallback; -class AudioCaptureLowLatencyImpl : public AudioCaptureInterfaceImplBase { -public: - AudioCaptureLowLatencyImpl(const std::string &adpName, const AudioDeviceDescriptor &desc, - const AudioSampleAttributes &attrs, const sptr &callback); - ~AudioCaptureLowLatencyImpl() override; - - int32_t CaptureFrame(std::vector &frame, uint64_t requestBytes) override; - int32_t GetCapturePosition(uint64_t &frames, AudioTimeStamp &time) override; - int32_t CheckSceneCapability(const AudioSceneDescriptor &scene, bool &supported) override; - int32_t SelectScene(const AudioSceneDescriptor &scene) override; - int32_t SetMute(bool mute) override; - int32_t GetMute(bool &mute) override; - int32_t SetVolume(float volume) override; - int32_t GetVolume(float &volume) override; - int32_t GetGainThreshold(float &min, float &max) override; - int32_t GetGain(float &gain) override; - int32_t SetGain(float gain) override; - int32_t GetFrameSize(uint64_t &size) override; - int32_t GetFrameCount(uint64_t &count) override; - int32_t SetSampleAttributes(const AudioSampleAttributes &attrs) override; - int32_t GetSampleAttributes(AudioSampleAttributes &attrs) override; - int32_t GetCurrentChannelId(uint32_t &channelId) override; - int32_t SetExtraParams(const std::string &keyValueList) override; - int32_t GetExtraParams(std::string &keyValueList) override; - int32_t ReqMmapBuffer(int32_t reqSize, AudioMmapBufferDescriptor &desc) override; - int32_t GetMmapPosition(uint64_t &frames, AudioTimeStamp &time) override; - int32_t AddAudioEffect(uint64_t effectid) override; - int32_t RemoveAudioEffect(uint64_t effectid) override; - int32_t GetFrameBufferSize(uint64_t &bufferSize) override; - int32_t Start() override; - int32_t Stop() override; - int32_t Pause() override; - int32_t Resume() override; - int32_t Flush() override; - int32_t TurnStandbyMode() override; - int32_t AudioDevDump(int32_t range, int32_t fd) override; - int32_t IsSupportsPauseAndResume(bool &supportPause, bool &supportResume) override; - -private: - int32_t InitAshmem(int32_t ashmemLength); - void UnInitAshmem(); -private: - std::string adapterName_; - AudioDeviceDescriptor devDesc_; - AudioSampleAttributes devAttrs_; - uint32_t timeInterval_ = 5; - uint32_t minTimeInterval_ = 30; - uint32_t maxTimeInterval_ = 80; - - std::mutex captureMtx_; - AudioCaptureStatus captureStatus_ = CAPTURE_STATUS_CLOSE; - sptr audioExtCallback_ = nullptr; - OHOS::sptr ashmem_ = nullptr; - int32_t ashmemLength_; - int32_t lengthPerTrans_; - int32_t fd_; -}; -} // V1_0 -} // Audio -} // Distributedaudio -} // HDI -} // OHOS -#endif // OHOS_AUDIO_CAPTURE_LOWLATENCY_IMPL_H \ No newline at end of file diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl.h index b5b9a77f36934ab9a9d965670aaafc856d8711c1..ff602bd84b6f35f3dba93d4489184070f62a3468 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl.h +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl.h @@ -97,6 +97,8 @@ private: int32_t FadeInProcess(const uint32_t durationFrame, int8_t* frameData, const size_t frameLength); private: + static constexpr int64_t AUDIO_OFFSET_FRAME_NUM = 10; + std::string adapterName_; AudioDeviceDescriptor devDesc_; AudioSampleAttributes devAttrs_; @@ -110,6 +112,10 @@ private: sptr audioExtCallback_ = nullptr; sptr renderCallback_ = nullptr; bool firstOpenFlag = true; + + int64_t frameIndex_ = 0; + int64_t framePeriodNs_ = 0; + int64_t startTime_ = 0; }; } // V1_0 } // Audio diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_lowlatency_impl.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_lowlatency_impl.h deleted file mode 100644 index a198b1def0d58729943d36f97bd34063676401ee..0000000000000000000000000000000000000000 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_lowlatency_impl.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_AUDIO_RENDER_LOWLATENCY_IMPL_H -#define OHOS_AUDIO_RENDER_LOWLATENCY_IMPL_H - -#include -#include -#include - -#include "ashmem.h" -#include "audio_render_interface_impl.h" -#include "audio_render_interface_impl_base.h" - -#include -#include -#include - -namespace OHOS { -namespace HDI { -namespace DistributedAudio { -namespace Audio { -namespace V1_0 { -using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioData; -using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioParameter; -using OHOS::HDI::DistributedAudio::Audioext::V1_0::DAudioEvent; -using OHOS::HDI::DistributedAudio::Audioext::V1_0::IDAudioCallback; -class AudioRenderLowLatencyImpl : public AudioRenderInterfaceImplBase { -public: - AudioRenderLowLatencyImpl(const std::string &adpName, const AudioDeviceDescriptor &desc, - const AudioSampleAttributes &attrs, const sptr &callback); - ~AudioRenderLowLatencyImpl() override; - - int32_t GetLatency(uint32_t &ms) override; - int32_t RenderFrame(const std::vector &frame, uint64_t &replyBytes) override; - int32_t GetRenderPosition(uint64_t &frames, AudioTimeStamp &time) override; - int32_t SetRenderSpeed(float speed) override; - int32_t GetRenderSpeed(float &speed) override; - int32_t SetChannelMode(AudioChannelMode mode) override; - int32_t GetChannelMode(AudioChannelMode &mode) override; - int32_t RegCallback(const sptr &audioCallback, int8_t cookie) override; - int32_t DrainBuffer(AudioDrainNotifyType &type) override; - int32_t IsSupportsDrain(bool &support) override; - int32_t CheckSceneCapability(const AudioSceneDescriptor &scene, bool &supported) override; - int32_t SelectScene(const AudioSceneDescriptor &scene) override; - int32_t SetMute(bool mute) override; - int32_t GetMute(bool &mute) override; - int32_t SetVolume(float volume) override; - int32_t GetVolume(float &volume) override; - int32_t GetGainThreshold(float &min, float &max) override; - int32_t SetGain(float gain) override; - int32_t GetGain(float &gain) override; - int32_t GetFrameSize(uint64_t &size) override; - int32_t GetFrameCount(uint64_t &count) override; - int32_t SetSampleAttributes(const AudioSampleAttributes &attrs) override; - int32_t GetSampleAttributes(AudioSampleAttributes &attrs) override; - int32_t GetCurrentChannelId(uint32_t &channelId) override; - int32_t SetExtraParams(const std::string &keyValueList) override; - int32_t GetExtraParams(std::string &keyValueList) override; - int32_t ReqMmapBuffer(int32_t reqSize, AudioMmapBufferDescriptor &desc) override; - int32_t GetMmapPosition(uint64_t &frames, AudioTimeStamp &time) override; - int32_t AddAudioEffect(uint64_t effectid) override; - int32_t RemoveAudioEffect(uint64_t effectid) override; - int32_t GetFrameBufferSize(uint64_t &bufferSize) override; - int32_t Start() override; - int32_t Stop() override; - int32_t Pause() override; - int32_t Resume() override; - int32_t Flush() override; - int32_t TurnStandbyMode() override; - int32_t AudioDevDump(int32_t range, int32_t fd) override; - int32_t IsSupportsPauseAndResume(bool &supportPause, bool &supportResume) override; - -private: - float GetFadeRate(uint32_t currentIndex, const uint32_t durationIndex); - int32_t FadeInProcess(const uint32_t durationFrame, int8_t* frameData, const size_t frameLength); - int32_t InitAshmem(int32_t ashmemLength); - void UnInitAshmem(); - -private: - std::string adapterName_; - AudioDeviceDescriptor devDesc_; - AudioSampleAttributes devAttrs_; - - uint32_t timeInterval_ = 5; - uint32_t minTimeInterval_ = 30; - uint32_t maxTimeInterval_ = 80; - float renderSpeed_ = 0; - uint32_t currentFrame_ = 0; - std::mutex renderMtx_; - AudioChannelMode channelMode_ = AUDIO_CHANNEL_NORMAL; - AudioRenderStatus renderStatus_ = RENDER_STATUS_CLOSE; - sptr audioExtCallback_ = nullptr; - sptr renderCallback_ = nullptr; - OHOS::sptr ashmem_ = nullptr; - int32_t ashmemLength_ = 0; - int32_t lengthPerTrans_ = 0; - int fd_ = 0; -}; -} // V1_0 -} // Audio -} // Distributedaudio -} // HDI -} // OHOS -#endif // OHOS_AUDIO_RENDER_LOWLATENCY_IMPL_H diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_adapter_interface_impl.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_adapter_interface_impl.cpp index 20349c9a108884329d996a8cd9c157fadc2f079f..b993d2f85be96414b9e8f8fff10222354b9f61df 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_adapter_interface_impl.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_adapter_interface_impl.cpp @@ -84,13 +84,8 @@ int32_t AudioAdapterInterfaceImpl::CreateRender(const AudioDeviceDescriptor &des return HDF_FAILURE; } } - if (attrs.type == AUDIO_MMAP_NOIRQ) { - renderFlags_ = MMAP_FLAG; - audioRender_ = new AudioRenderLowLatencyImpl(adpDescriptor_.adapterName, desc, attrs, extSpkCallback_); - } else { - renderFlags_ = NORMAL_FLAG; - audioRender_ = new AudioRenderInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extSpkCallback_); - } + renderFlags_ = Audioext::V1_0::NORMAL_MODE; + audioRender_ = new AudioRenderInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extSpkCallback_); if (audioRender_ == nullptr) { DHLOGE("Create render failed."); return HDF_FAILURE; @@ -141,13 +136,8 @@ int32_t AudioAdapterInterfaceImpl::CreateCapture(const AudioDeviceDescriptor &de return HDF_FAILURE; } } - if (attrs.type == AUDIO_MMAP_NOIRQ) { - capturerFlags_ = MMAP_FLAG; - audioCapture_ = new AudioCaptureLowLatencyImpl(adpDescriptor_.adapterName, desc, attrs, extMicCallback_); - } else { - capturerFlags_ = NORMAL_FLAG; - audioCapture_ = new AudioCaptureInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extMicCallback_); - } + capturerFlags_ = Audioext::V1_0::NORMAL_MODE; + audioCapture_ = new AudioCaptureInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extMicCallback_); if (audioCapture_ == nullptr) { DHLOGE("Create capture failed."); return HDF_FAILURE; @@ -420,7 +410,7 @@ int32_t AudioAdapterInterfaceImpl::OpenRenderDevice(const AudioDeviceDescriptor renderParam_.sampleRate = attrs.sampleRate; renderParam_.streamUsage = attrs.type; renderParam_.frameSize = CalculateFrameSize(attrs.sampleRate, attrs.channelCount, attrs.format, - timeInterval_, renderFlags_ == MMAP_FLAG); + timeInterval_, renderFlags_ == Audioext::V1_0::MMAP_MODE); renderParam_.renderFlags = renderFlags_; int32_t ret = extSpkCallback_->SetParameters(adpDescriptor_.adapterName, desc.pins, renderParam_); @@ -483,7 +473,7 @@ int32_t AudioAdapterInterfaceImpl::OpenCaptureDevice(const AudioDeviceDescriptor captureParam_.sampleRate = attrs.sampleRate; captureParam_.streamUsage = attrs.type; captureParam_.frameSize = CalculateFrameSize(attrs.sampleRate, attrs.channelCount, - attrs.format, timeInterval_, capturerFlags_ == MMAP_FLAG); + attrs.format, timeInterval_, capturerFlags_ == Audioext::V1_0::MMAP_MODE); captureParam_.capturerFlags = capturerFlags_; int32_t ret = extMicCallback_->SetParameters(adpDescriptor_.adapterName, desc.pins, captureParam_); diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_capture_interface_impl.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_capture_interface_impl.cpp index 3b84eeaf432e24278124becec63d105437cac265..d6e80e8fd72f2b8487870806199598b4f260ff1b 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_capture_interface_impl.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_capture_interface_impl.cpp @@ -40,7 +40,8 @@ AudioCaptureInterfaceImpl::AudioCaptureInterfaceImpl(const std::string &adpName, devAttrs_(attrs), audioExtCallback_(callback) { devAttrs_.frameSize = CalculateFrameSize(attrs.sampleRate, attrs.channelCount, attrs.format, timeInterval_, false); - framePeriodNs_ = devAttrs_.frameSize * AUDIO_NS_PER_SECOND / (attrs.sampleRate * attrs.channelCount * attrs.format); + const int32_t sizePerSec = static_cast(attrs.sampleRate * attrs.channelCount) *attrs.format; + framePeriodNs_ = (static_cast(devAttrs_.frameSize) * AUDIO_NS_PER_SECOND) / sizePerSec; DHLOGD("Distributed audio capture constructed, period(%d),frameSize(%d), framePeriodNs_(%d).", attrs.period, devAttrs_.frameSize, framePeriodNs_); DHLOGD("Distributed audio capture constructed, id(%d).", desc.pins); @@ -59,30 +60,18 @@ int32_t AudioCaptureInterfaceImpl::GetCapturePosition(uint64_t &frames, AudioTim return HDF_SUCCESS; } -int64_t AudioCaptureInterfaceImpl::CalculateOffset(int64_t count) -{ - const int64_t gapTime = AUDIO_OFFSET_FRAME_NUM * framePeriodNs_; - int64_t totalOffset = GetCurNano() - startTime_; - return totalOffset - count * gapTime; -} - int32_t AudioCaptureInterfaceImpl::CaptureFrame(std::vector &frame, uint64_t requestBytes) { - DHLOGI("Capture frame[sampleRate: %d, channelCount: %d, format: %d, frameSize: %d].", devAttrs_.sampleRate, + DHLOGD("Capture frame[sampleRate: %d, channelCount: %d, format: %d, frameSize: %d].", devAttrs_.sampleRate, devAttrs_.channelCount, devAttrs_.format, devAttrs_.frameSize); - int64_t timeOffset = 0; - if (frameIdx_ == 0) { - startTime_ = GetCurNano(); - } else if (frameIdx_ % AUDIO_OFFSET_FRAME_NUM == 0) { - timeOffset = CalculateOffset(frameIdx_ / AUDIO_OFFSET_FRAME_NUM); - DHLOGI("Capture frameIdx_: %d, timeOffset: %d.", frameIdx_, timeOffset); - } + int64_t timeOffset = UpdateTimeOffset(frameIndex_, framePeriodNs_, startTime_); + DHLOGD("Capture framIndex: %lld, timeOffset: %lld.", frameIndex_, timeOffset); + std::lock_guard captureLck(captureMtx_); if (captureStatus_ != CAPTURE_STATUS_START) { DHLOGE("Capture status wrong, return false."); return HDF_FAILURE; } - if (audioExtCallback_ == nullptr) { DHLOGE("Callback is nullptr."); return HDF_FAILURE; @@ -101,9 +90,9 @@ int32_t AudioCaptureInterfaceImpl::CaptureFrame(std::vector &frame, uint DHLOGE("Copy capture frame failed, error code %d.", ret); return HDF_FAILURE; } - ++frameIdx_; - AbsoluteSleep(startTime_ + frameIdx_ * framePeriodNs_ - timeOffset); - DHLOGI("Capture audio frame success."); + ++frameIndex_; + AbsoluteSleep(startTime_ + frameIndex_ * framePeriodNs_ - timeOffset); + DHLOGD("Capture audio frame success."); return HDF_SUCCESS; } @@ -121,7 +110,7 @@ int32_t AudioCaptureInterfaceImpl::Start() } std::lock_guard captureLck(captureMtx_); captureStatus_ = CAPTURE_STATUS_START; - frameIdx_ = 0; + frameIndex_ = 0; startTime_ = 0; return HDF_SUCCESS; } diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_capture_lowlatency_impl.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_capture_lowlatency_impl.cpp deleted file mode 100644 index 773fc6c62f344f5f0e33280e525aabcc7ba1a305..0000000000000000000000000000000000000000 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_capture_lowlatency_impl.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "audio_capture_lowlatency_impl.h" - -#include -#include -#include -#include - -#include "daudio_constants.h" -#include "daudio_events.h" -#include "daudio_log.h" -#include "daudio_utils.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioCaptureLowLatencyImpl" - -using namespace OHOS::DistributedHardware; -namespace OHOS { -namespace HDI { -namespace DistributedAudio { -namespace Audio { -namespace V1_0 { -AudioCaptureLowLatencyImpl::AudioCaptureLowLatencyImpl(const std::string &adpName, const AudioDeviceDescriptor &desc, - const AudioSampleAttributes &attrs, const sptr &callback) - : AudioCaptureInterfaceImplBase(desc), adapterName_(adpName), devDesc_(desc), - devAttrs_(attrs), audioExtCallback_(callback) -{ - devAttrs_.frameSize = CalculateFrameSize(attrs.sampleRate, attrs.channelCount, attrs.format, timeInterval_, true); - DHLOGI("Distributed lowlatency capture constructed, id(%d). framesize(%d)", desc.pins, devAttrs_.frameSize); -} - -AudioCaptureLowLatencyImpl::~AudioCaptureLowLatencyImpl() -{ - UnInitAshmem(); - DHLOGD("Distributed lowlatency capture destructed, id(%d).", devDesc_.pins); -} - -int32_t AudioCaptureLowLatencyImpl::InitAshmem(int32_t ashmemLength) -{ - std::string memory_name = "Capture ShareMemory"; - if (ashmemLength < DAUDIO_MIN_ASHMEM_LEN || ashmemLength > DAUDIO_MAX_ASHMEM_LEN) { - DHLOGE("Init ashmem failed. length is illegal"); - return HDF_FAILURE; - } - ashmem_ = OHOS::Ashmem::CreateAshmem(memory_name.c_str(), ashmemLength); - if (ashmem_ == nullptr) { - DHLOGE("Create ashmem failed."); - return HDF_FAILURE; - } - if (!ashmem_->MapReadAndWriteAshmem()) { - DHLOGE("Mmap ashmem failed."); - return HDF_FAILURE; - } - fd_ = ashmem_->GetAshmemFd(); - DHLOGI("Init Ashmem success, fd: %d, length: %d", fd_, ashmemLength); - return HDF_SUCCESS; -} - -void AudioCaptureLowLatencyImpl::UnInitAshmem() -{ - if (ashmem_ != nullptr) { - ashmem_->UnmapAshmem(); - ashmem_->CloseAshmem(); - ashmem_ = nullptr; - DHLOGI("UnInitAshmem success."); - } -} - -int32_t AudioCaptureLowLatencyImpl::GetCapturePosition(uint64_t &frames, AudioTimeStamp &time) -{ - DHLOGI("Get capture position, not support yet."); - (void)frames; - (void)time; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::CaptureFrame(std::vector &frame, uint64_t requestBytes) -{ - DHLOGI("Render frame. not support in low-latency capture"); - (void)devAttrs_.sampleRate; - (void)devAttrs_.channelCount; - (void)devAttrs_.format; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::Start() -{ - DHLOGI("Start capture mmap."); - DAudioEvent event = { HDF_AUDIO_EVENT_MMAP_START_MIC, "" }; - if (audioExtCallback_ == nullptr) { - DHLOGE("Callback is nullptr."); - return HDF_FAILURE; - } - int32_t ret = audioExtCallback_->NotifyEvent(adapterName_, devDesc_.pins, event); - if (ret != HDF_SUCCESS) { - DHLOGE("Start capture mmap failed."); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::Stop() -{ - DHLOGI("Stop capture mmap."); - DAudioEvent event = { HDF_AUDIO_EVENT_MMAP_STOP_MIC, "" }; - int32_t ret = audioExtCallback_->NotifyEvent(adapterName_, devDesc_.pins, event); - if (ret != HDF_SUCCESS) { - DHLOGE("Stop capture mmap failed."); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::Pause() -{ - DHLOGI("Pause capture."); - std::lock_guard captureLck(captureMtx_); - captureStatus_ = CAPTURE_STATUS_PAUSE; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::Resume() -{ - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::Flush() -{ - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::TurnStandbyMode() -{ - DHLOGI("Turn stand by mode, not support yet."); - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::AudioDevDump(int32_t range, int32_t fd) -{ - DHLOGI("Dump audio info, not support yet."); - (void)range; - (void)fd; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::IsSupportsPauseAndResume(bool &supportPause, bool &supportResume) -{ - DHLOGI("Check whether pause and resume is supported, not support yet."); - (void)supportPause; - (void)supportResume; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::CheckSceneCapability(const AudioSceneDescriptor &scene, bool &supported) -{ - DHLOGI("Check scene capability."); - (void)scene; - supported = false; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::SelectScene(const AudioSceneDescriptor &scene) -{ - DHLOGI("Select audio scene, not support yet."); - (void)scene; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::SetMute(bool mute) -{ - DHLOGI("Set mute, not support yet."); - (void)mute; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::GetMute(bool &mute) -{ - DHLOGI("Get mute, not support yet."); - (void)mute; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::SetVolume(float volume) -{ - DHLOGI("Can not set vol not by this interface."); - (void)volume; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::GetVolume(float &volume) -{ - DHLOGI("Can not get vol not by this interface."); - (void)volume; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::GetGainThreshold(float &min, float &max) -{ - DHLOGI("Get gain threshold, not support yet."); - min = 0; - max = 0; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::SetGain(float gain) -{ - DHLOGI("Set gain, not support yet."); - (void)gain; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::GetGain(float &gain) -{ - DHLOGI("Get gain, not support yet."); - gain = 1.0; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::GetFrameSize(uint64_t &size) -{ - (void)size; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::GetFrameCount(uint64_t &count) -{ - (void)count; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::SetSampleAttributes(const AudioSampleAttributes &attrs) -{ - DHLOGI("Set sample attributes."); - devAttrs_ = attrs; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::GetSampleAttributes(AudioSampleAttributes &attrs) -{ - DHLOGI("Get sample attributes."); - attrs = devAttrs_; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::GetCurrentChannelId(uint32_t &channelId) -{ - DHLOGI("Get current channel id, not support yet."); - (void)channelId; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::SetExtraParams(const std::string &keyValueList) -{ - DHLOGI("Set extra parameters, not support yet."); - (void)keyValueList; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::GetExtraParams(std::string &keyValueList) -{ - DHLOGI("Get extra parameters, not support yet."); - (void)keyValueList; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::ReqMmapBuffer(int32_t reqSize, AudioMmapBufferDescriptor &desc) -{ - DHLOGI("Request mmap buffer."); - int32_t minSize = CalculateSampleNum(devAttrs_.sampleRate, minTimeInterval_); - int32_t maxSize = CalculateSampleNum(devAttrs_.sampleRate, maxTimeInterval_); - int32_t realSize = reqSize; - if (reqSize < minSize) { - realSize = minSize; - } else if (reqSize > maxSize) { - realSize = maxSize; - } - DHLOGI("ReqMmap buffer realsize : %d, minsize: %d, maxsize:%d.", realSize, minSize, maxSize); - desc.totalBufferFrames = realSize; - ashmemLength_ = realSize * devAttrs_.channelCount * devAttrs_.format; - DHLOGI("Init ashmem real sample size : %d, length: %d.", realSize, ashmemLength_); - int32_t ret = InitAshmem(ashmemLength_); - if (ret != HDF_SUCCESS) { - DHLOGE("Init ashmem error.."); - return HDF_FAILURE; - } - desc.memoryFd = fd_; - desc.transferFrameSize = static_cast(CalculateSampleNum(devAttrs_.sampleRate, timeInterval_)); - lengthPerTrans_ = desc.transferFrameSize * devAttrs_.channelCount * devAttrs_.format; - desc.isShareable = false; - ret = audioExtCallback_->RefreshAshmemInfo(adapterName_, devDesc_.pins, fd_, ashmemLength_, lengthPerTrans_); - if (ret != HDF_SUCCESS) { - DHLOGE("Refresh ashmem info failed."); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::GetMmapPosition(uint64_t &frames, AudioTimeStamp &time) -{ - DHLOGI("Get mmap position, not support yet."); - (void)frames; - (void)time; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::AddAudioEffect(uint64_t effectid) -{ - DHLOGI("Add audio effect, not support yet."); - (void)effectid; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::RemoveAudioEffect(uint64_t effectid) -{ - DHLOGI("Remove audio effect, not support yet."); - (void)effectid; - return HDF_SUCCESS; -} - -int32_t AudioCaptureLowLatencyImpl::GetFrameBufferSize(uint64_t &bufferSize) -{ - DHLOGI("Get frame buffer size, not support yet."); - (void)bufferSize; - return HDF_SUCCESS; -} -} // V1_0 -} // Audio -} // Distributedaudio -} // HDI -} // OHOS diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_render_interface_impl.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_render_interface_impl.cpp index 4ad915d76e4a7f061bf9155f29e47325fbeaa558..d0374f55ae8aaa4d72d8922bb517f20270d8ec75 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_render_interface_impl.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_render_interface_impl.cpp @@ -39,7 +39,10 @@ AudioRenderInterfaceImpl::AudioRenderInterfaceImpl(const std::string &adpName, c devAttrs_(attrs), audioExtCallback_(callback) { devAttrs_.frameSize = CalculateFrameSize(attrs.sampleRate, attrs.channelCount, attrs.format, timeInterval_, false); - DHLOGD("Distributed audio render constructed, id(%d).", desc.pins); + const int32_t sizePerSec = static_cast(attrs.sampleRate * attrs.channelCount) *attrs.format; + framePeriodNs_ = (static_cast(devAttrs_.frameSize) * AUDIO_NS_PER_SECOND) /sizePerSec; + DHLOGD("Distributed audio render constructed, period(%d), frameSize(%d), framePeriodNs_(%d).", + attrs.period, devAttrs_.frameSize, framePeriodNs_); } AudioRenderInterfaceImpl::~AudioRenderInterfaceImpl() @@ -89,6 +92,8 @@ int32_t AudioRenderInterfaceImpl::RenderFrame(const std::vector &frame, { DHLOGI("Render frame[sampleRate: %d, channelCount: %d, format: %d, frameSize: %d].", devAttrs_.sampleRate, devAttrs_.channelCount, devAttrs_.format, devAttrs_.frameSize); + int64_t timeOffset = UpdateTimeOffset(frameIndex_, framePeriodNs_, startTime_); + DHLOGD("Render frameIndex: %lld, timeOffset: %lld.", frameIndex_, timeOffset); std::lock_guard renderLck(renderMtx_); if (renderStatus_ != RENDER_STATUS_START) { @@ -109,7 +114,9 @@ int32_t AudioRenderInterfaceImpl::RenderFrame(const std::vector &frame, return HDF_FAILURE; } - DHLOGI("Render audio frame success."); + ++frameIndex_; + AbsoluteSleep(startTime_ + frameIndex_ * framePeriodNs_ - timeOffset); + DHLOGD("Render audio frame success."); return HDF_SUCCESS; } @@ -186,6 +193,8 @@ int32_t AudioRenderInterfaceImpl::Start() std::lock_guard renderLck(renderMtx_); renderStatus_ = RENDER_STATUS_START; currentFrame_ = CUR_FRAME_INIT_VALUE; + frameIndex_ = 0; + startTime_ = 0; return HDF_SUCCESS; } diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_render_lowlatency_impl.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_render_lowlatency_impl.cpp deleted file mode 100644 index 4412d9ff9d2b1388c8fb22aeba837097ebe412fb..0000000000000000000000000000000000000000 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_render_lowlatency_impl.cpp +++ /dev/null @@ -1,443 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "audio_render_lowlatency_impl.h" - -#include -#include -#include "sys/time.h" - -#include "daudio_constants.h" -#include "daudio_events.h" -#include "daudio_log.h" -#include "daudio_utils.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioRenderLowLatencyImpl" - -using namespace OHOS::DistributedHardware; -namespace OHOS { -namespace HDI { -namespace DistributedAudio { -namespace Audio { -namespace V1_0 { -AudioRenderLowLatencyImpl::AudioRenderLowLatencyImpl(const std::string &adpName, const AudioDeviceDescriptor &desc, - const AudioSampleAttributes &attrs, const sptr &callback) - : AudioRenderInterfaceImplBase(desc), adapterName_(adpName), devDesc_(desc), - devAttrs_(attrs), audioExtCallback_(callback) -{ - devAttrs_.frameSize = CalculateFrameSize(attrs.sampleRate, attrs.channelCount, attrs.format, timeInterval_, true); - DHLOGI("Distributed lowlatency render constructed, id(%d). framesize(%d)", desc.pins, devAttrs_.frameSize); -} - -AudioRenderLowLatencyImpl::~AudioRenderLowLatencyImpl() -{ - UnInitAshmem(); - DHLOGI("Distributed lowlatency render destructed, id(%d).", devDesc_.pins); -} - -int32_t AudioRenderLowLatencyImpl::InitAshmem(int32_t ashmemLength) -{ - std::string memory_name = "Render ShareMemory"; - if (ashmemLength < DAUDIO_MIN_ASHMEM_LEN || ashmemLength > DAUDIO_MAX_ASHMEM_LEN) { - DHLOGE("Init ashmem failed. length is illegal"); - return HDF_FAILURE; - } - ashmem_ = OHOS::Ashmem::CreateAshmem(memory_name.c_str(), ashmemLength); - if (ashmem_ == nullptr) { - DHLOGE("Create ashmem failed."); - return HDF_FAILURE; - } - bool ret = ashmem_->MapReadAndWriteAshmem(); - if (ret != true) { - DHLOGE("Mmap ashmem failed."); - return HDF_FAILURE; - } - fd_ = ashmem_->GetAshmemFd(); - DHLOGI("Init Ashmem success, fd: %d, length: %d", fd_, ashmemLength); - return HDF_SUCCESS; -} - -void AudioRenderLowLatencyImpl::UnInitAshmem() -{ - if (ashmem_ != nullptr) { - ashmem_->UnmapAshmem(); - ashmem_->CloseAshmem(); - ashmem_ = nullptr; - DHLOGI("UnInitAshmem success."); - } -} - -int32_t AudioRenderLowLatencyImpl::GetLatency(uint32_t &ms) -{ - DHLOGI("Get render device latency, not support yet."); - ms = 0; - return HDF_SUCCESS; -} - -float AudioRenderLowLatencyImpl::GetFadeRate(uint32_t currentIndex, const uint32_t durationIndex) -{ - if (currentIndex > durationIndex) { - return 1.0f; - } - - float fadeRate = static_cast(currentIndex) / durationIndex * DAUDIO_FADE_NORMALIZATION_FACTOR; - if (fadeRate < 1) { - return pow(fadeRate, DAUDIO_FADE_POWER_NUM) / DAUDIO_FADE_NORMALIZATION_FACTOR; - } - return -pow(fadeRate - DAUDIO_FADE_MAXIMUM_VALUE, DAUDIO_FADE_POWER_NUM) / - DAUDIO_FADE_NORMALIZATION_FACTOR + 1; -} - -int32_t AudioRenderLowLatencyImpl::FadeInProcess(const uint32_t durationFrame, - int8_t* frameData, const size_t frameLength) -{ - int16_t* frame = reinterpret_cast(frameData); - const size_t newFrameLength = frameLength / 2; - - for (size_t k = 0; k < newFrameLength; ++k) { - float rate = GetFadeRate(currentFrame_ * newFrameLength + k, durationFrame * newFrameLength); - frame[k] = currentFrame_ == durationFrame - 1 ? frame[k] : static_cast(rate * frame[k]); - } - DHLOGI("Fade-in frame[currentFrame: %d].", currentFrame_); - ++currentFrame_; - currentFrame_ = currentFrame_ >= durationFrame ? durationFrame - 1 : currentFrame_; - - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::RenderFrame(const std::vector &frame, uint64_t &replyBytes) -{ - DHLOGI("Render frame. not support in low-latency render"); - (void)devAttrs_.sampleRate; - (void)devAttrs_.channelCount; - (void)devAttrs_.format; - - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetRenderPosition(uint64_t &frames, AudioTimeStamp &time) -{ - DHLOGI("Get render position, not support yet."); - (void)frames; - (void)time; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::SetRenderSpeed(float speed) -{ - DHLOGI("Set render speed, control render speed is not support yet."); - renderSpeed_ = speed; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetRenderSpeed(float &speed) -{ - DHLOGI("Get render speed, control render speed is not support yet."); - speed = renderSpeed_; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::SetChannelMode(AudioChannelMode mode) -{ - DHLOGI("Set channel mode, control channel mode is not support yet."); - channelMode_ = mode; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetChannelMode(AudioChannelMode &mode) -{ - DHLOGI("Get channel mode, control channel mode is not support yet."); - mode = channelMode_; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::RegCallback(const sptr &audioCallback, int8_t cookie) -{ - DHLOGI("Register render callback."); - (void)cookie; - renderCallback_ = audioCallback; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::DrainBuffer(AudioDrainNotifyType &type) -{ - DHLOGI("Drain audio buffer, not support yet."); - (void)type; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::IsSupportsDrain(bool &support) -{ - DHLOGI("Check whether drain is supported, not support yet."); - (void)support; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::Start() -{ - DHLOGI("Start render mmap."); - DAudioEvent event = { HDF_AUDIO_EVENT_MMAP_START, "" }; - if (audioExtCallback_ == nullptr) { - DHLOGE("Callback is nullptr."); - return HDF_FAILURE; - } - int32_t ret = audioExtCallback_->NotifyEvent(adapterName_, devDesc_.pins, event); - if (ret != HDF_SUCCESS) { - DHLOGE("Start render mmap failed."); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::Stop() -{ - DHLOGI("Stop render mmap."); - DAudioEvent event = { HDF_AUDIO_EVENT_MMAP_STOP, "" }; - int32_t ret = audioExtCallback_->NotifyEvent(adapterName_, devDesc_.pins, event); - if (ret != HDF_SUCCESS) { - DHLOGE("Stop render mmap failed."); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::Pause() -{ - DHLOGI("Pause render."); - std::lock_guard renderLck(renderMtx_); - renderStatus_ = RENDER_STATUS_PAUSE; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::Resume() -{ - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::Flush() -{ - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::TurnStandbyMode() -{ - DHLOGI("Turn stand by mode, not support yet."); - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::AudioDevDump(int32_t range, int32_t fd) -{ - DHLOGI("Dump audio info, not support yet."); - (void)range; - (void)fd; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::IsSupportsPauseAndResume(bool &supportPause, bool &supportResume) -{ - DHLOGI("Check whether pause and resume is supported, not support yet."); - (void)supportPause; - (void)supportResume; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::CheckSceneCapability(const AudioSceneDescriptor &scene, bool &supported) -{ - DHLOGI("Check scene capability."); - (void)scene; - (void)supported; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::SelectScene(const AudioSceneDescriptor &scene) -{ - DHLOGI("Select audio scene, not support yet."); - (void)scene; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::SetMute(bool mute) -{ - DHLOGI("Set mute, not support yet."); - (void)mute; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetMute(bool &mute) -{ - DHLOGI("Get mute, not support yet."); - (void)mute; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::SetVolume(float volume) -{ - DHLOGI("Can not set vol not by this interface."); - (void)volume; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetVolume(float &volume) -{ - DHLOGI("Can not get vol not by this interface."); - (void)volume; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetGainThreshold(float &min, float &max) -{ - DHLOGI("Get gain threshold, not support yet."); - min = 0; - max = 0; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::SetGain(float gain) -{ - DHLOGI("Set gain, not support yet."); - (void)gain; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetGain(float &gain) -{ - DHLOGI("Get gain, not support yet."); - gain = 1.0; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetFrameSize(uint64_t &size) -{ - (void)size; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetFrameCount(uint64_t &count) -{ - (void)count; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::SetSampleAttributes(const AudioSampleAttributes &attrs) -{ - DHLOGI("Set sample attributes."); - devAttrs_ = attrs; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetSampleAttributes(AudioSampleAttributes &attrs) -{ - DHLOGI("Get sample attributes."); - attrs = devAttrs_; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetCurrentChannelId(uint32_t &channelId) -{ - DHLOGI("Get current channel id, not support yet."); - (void)channelId; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::SetExtraParams(const std::string &keyValueList) -{ - DHLOGI("Set extra parameters, not support yet."); - (void)keyValueList; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetExtraParams(std::string &keyValueList) -{ - DHLOGI("Get extra parameters, not support yet."); - (void)keyValueList; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::ReqMmapBuffer(int32_t reqSize, AudioMmapBufferDescriptor &desc) -{ - DHLOGI("Request mmap buffer."); - int32_t minSize = CalculateSampleNum(devAttrs_.sampleRate, minTimeInterval_); - int32_t maxSize = CalculateSampleNum(devAttrs_.sampleRate, maxTimeInterval_); - int32_t realSize = reqSize; - if (reqSize < minSize) { - realSize = minSize; - } else if (reqSize > maxSize) { - realSize = maxSize; - } - DHLOGI("ReqMmap buffer realsize : %d, minsize: %d, maxsize:%d.", realSize, minSize, maxSize); - desc.totalBufferFrames = realSize; - ashmemLength_ = static_cast(realSize * devAttrs_.channelCount * devAttrs_.format); - DHLOGI("Init ashmem real sample size : %d, length: %d.", realSize, ashmemLength_); - int32_t ret = InitAshmem(ashmemLength_); - if (ret != HDF_SUCCESS) { - DHLOGE("Init ashmem error.."); - return HDF_FAILURE; - } - desc.memoryFd = fd_; - desc.transferFrameSize = static_cast(CalculateSampleNum(devAttrs_.sampleRate, timeInterval_)); - lengthPerTrans_ = desc.transferFrameSize * devAttrs_.channelCount * devAttrs_.format; - desc.isShareable = false; - ret = audioExtCallback_->RefreshAshmemInfo(adapterName_, devDesc_.pins, fd_, ashmemLength_, lengthPerTrans_); - if (ret != HDF_SUCCESS) { - DHLOGE("Refresh ashmem info failed."); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetMmapPosition(uint64_t &frames, AudioTimeStamp &time) -{ - DHLOGI("Get mmap position."); - (void)time; - if (audioExtCallback_ == nullptr) { - DHLOGE("Callback is nullptr."); - return HDF_FAILURE; - } - uint64_t timeStamp; - int32_t ret = audioExtCallback_->ReadMmapPosition(adapterName_, devDesc_.pins, frames, timeStamp); - if (ret != HDF_SUCCESS) { - DHLOGE("Read mmap position failed."); - return HDF_FAILURE; - } - DHLOGI("Read mmap position. frames: %d, timeStamp: %d", frames, timeStamp); - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::AddAudioEffect(uint64_t effectid) -{ - DHLOGI("Add audio effect, not support yet."); - (void)effectid; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::RemoveAudioEffect(uint64_t effectid) -{ - DHLOGI("Remove audio effect, not support yet."); - (void)effectid; - return HDF_SUCCESS; -} - -int32_t AudioRenderLowLatencyImpl::GetFrameBufferSize(uint64_t &bufferSize) -{ - DHLOGI("Get frame buffer size, not support yet."); - (void)bufferSize; - return HDF_SUCCESS; -} -} // V1_0 -} // Audio -} // Distributedaudio -} // HDI -} // OHOS diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/captureframe_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/captureframe_fuzzer/BUILD.gn index a75fb098f1462aaee308eb1663572c10c67370f2..5c859b2f7179a403aeba4f0fcf608c762eab2643 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/captureframe_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/captureframe_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("CaptureFrameFuzzTest") { @@ -43,13 +42,9 @@ ohos_fuzztest("CaptureFrameFuzzTest") { "${common_path}/include", ] - deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - ] + deps = [ "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0" ] - external_deps = [ - "c_utils:utils", - ] + external_deps = [ "c_utils:utils" ] defines = [ "HI_LOG_ENABLE", @@ -63,4 +58,4 @@ group("fuzztest") { testonly = true deps = [ ":CaptureFrameFuzzTest" ] } -############################################################################### \ No newline at end of file +############################################################################### diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/BUILD.gn index 4eba3dcb99d1f2d85c348ec848d96d7092d86fdb..87945bf87c91d99a064dcc8b04e920208bcbb10f 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("CreateCaptureFuzzTest") { @@ -43,13 +42,9 @@ ohos_fuzztest("CreateCaptureFuzzTest") { "${common_path}/include", ] - deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - ] + deps = [ "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0" ] - external_deps = [ - "c_utils:utils", - ] + external_deps = [ "c_utils:utils" ] defines = [ "HI_LOG_ENABLE", @@ -63,4 +58,4 @@ group("fuzztest") { testonly = true deps = [ ":CreateCaptureFuzzTest" ] } -############################################################################### \ No newline at end of file +############################################################################### diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/BUILD.gn index 404b06ccbe42f1b5ca0ea5146b0f4a2a72d84bcd..e9631e98406e73540c63c72cfa7b930bed0b4013 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("CreateRenderFuzzTest") { @@ -43,13 +42,9 @@ ohos_fuzztest("CreateRenderFuzzTest") { "${common_path}/include", ] - deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - ] + deps = [ "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0" ] - external_deps = [ - "c_utils:utils", - ] + external_deps = [ "c_utils:utils" ] defines = [ "HI_LOG_ENABLE", @@ -63,4 +58,4 @@ group("fuzztest") { testonly = true deps = [ ":CreateRenderFuzzTest" ] } -############################################################################### \ No newline at end of file +############################################################################### diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/BUILD.gn index 4a19984ac22bf48e54cb195a0dbcf7863b490e29..77260e36cf7c0db132f6e38beaac90a574e50b9c 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("DestroyCaptureFuzzTest") { @@ -43,9 +42,7 @@ ohos_fuzztest("DestroyCaptureFuzzTest") { "${common_path}/include", ] - deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - ] + deps = [ "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0" ] defines = [ "HI_LOG_ENABLE", @@ -59,4 +56,4 @@ group("fuzztest") { testonly = true deps = [ ":DestroyCaptureFuzzTest" ] } -############################################################################### \ No newline at end of file +############################################################################### diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/BUILD.gn index cca452db3ae75f192d7fac2beff11318dca5463c..e5dc01a86fd99fdf5de4c9e14d0c7496fc5a31ca 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("DestroyRenderFuzzTest") { @@ -43,9 +42,7 @@ ohos_fuzztest("DestroyRenderFuzzTest") { "${common_path}/include", ] - deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - ] + deps = [ "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0" ] defines = [ "HI_LOG_ENABLE", @@ -59,4 +56,4 @@ group("fuzztest") { testonly = true deps = [ ":DestroyRenderFuzzTest" ] } -############################################################################### \ No newline at end of file +############################################################################### diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getalladapters_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getalladapters_fuzzer/BUILD.gn index 1db61773f50b82b9cc173f9b2a0ef7ca581bc2f0..fb62e07104ab9888546e8019a8991cba8d4442fc 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getalladapters_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getalladapters_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("GetAllAdaptersFuzzTest") { @@ -43,9 +42,7 @@ ohos_fuzztest("GetAllAdaptersFuzzTest") { "${common_path}/include", ] - deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - ] + deps = [ "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0" ] external_deps = [ "hdf_core:libhdf_host" ] defines = [ "HI_LOG_ENABLE", diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getextraparams_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getextraparams_fuzzer/BUILD.gn index ca59e37750bcb5063cce9a5b5e3da6793d6f7177..1bc568b760fb98400e568c6d512fc717b4e7251e 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getextraparams_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getextraparams_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("GetExtraParamsFuzzTest") { @@ -43,9 +42,7 @@ ohos_fuzztest("GetExtraParamsFuzzTest") { "${common_path}/include", ] - deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - ] + deps = [ "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0" ] defines = [ "HI_LOG_ENABLE", @@ -59,4 +56,4 @@ group("fuzztest") { testonly = true deps = [ ":GetExtraParamsFuzzTest" ] } -############################################################################### \ No newline at end of file +############################################################################### diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/loadadapter_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/loadadapter_fuzzer/BUILD.gn index b829dc5a5ebb8caf793c9603cdc9ce945da0454f..78c854ac2ee865ce467499fa4024e2aea047f6f7 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/loadadapter_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/loadadapter_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("LoadAdapterFuzzTest") { @@ -43,9 +42,7 @@ ohos_fuzztest("LoadAdapterFuzzTest") { "${common_path}/include", ] - deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - ] + deps = [ "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0" ] external_deps = [ "c_utils:utils", diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/renderframe_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/renderframe_fuzzer/BUILD.gn index efaba1b29792103885b707b8102420e52f6c7888..71e85638e576cb095671b8562dee62027f22d738 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/renderframe_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/renderframe_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("RenderFrameFuzzTest") { @@ -43,13 +42,9 @@ ohos_fuzztest("RenderFrameFuzzTest") { "${common_path}/include", ] - deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - ] + deps = [ "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0" ] - external_deps = [ - "c_utils:utils", - ] + external_deps = [ "c_utils:utils" ] defines = [ "HI_LOG_ENABLE", @@ -63,4 +58,4 @@ group("fuzztest") { testonly = true deps = [ ":RenderFrameFuzzTest" ] } -############################################################################### \ No newline at end of file +############################################################################### diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/setextraparams_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/setextraparams_fuzzer/BUILD.gn index ff13840f90a1833b7dafa4495837daf066c32772..b1b8675a8690e2e489a65a0088e1877febf58daa 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/setextraparams_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/setextraparams_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SetExtraParamsFuzzTest") { @@ -43,9 +42,7 @@ ohos_fuzztest("SetExtraParamsFuzzTest") { "${common_path}/include", ] - deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - ] + deps = [ "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0" ] defines = [ "HI_LOG_ENABLE", @@ -59,4 +56,4 @@ group("fuzztest") { testonly = true deps = [ ":SetExtraParamsFuzzTest" ] } -############################################################################### \ No newline at end of file +############################################################################### diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/unloadadapter_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/unloadadapter_fuzzer/BUILD.gn index f5a0971bbd8f75ef0790b0cfdb6d8ffca43d407c..bdaadad4449e3f874c25e00ee1a2bd27be11407e 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/unloadadapter_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/unloadadapter_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("UnloadAdapterFuzzTest") { @@ -43,9 +42,7 @@ ohos_fuzztest("UnloadAdapterFuzzTest") { "${common_path}/include", ] - deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - ] + deps = [ "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0" ] external_deps = [ "hdf_core:libhdf_host" ] defines = [ "HI_LOG_ENABLE", diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/BUILD.gn index 22fe15d14b34192aefe0573abaeca017b2fadda9..72d69d8c9794e8857d2e0e6911b4e473cc116279 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../distributedaudio.gni") group("hdi_service_audio_test") { testonly = true @@ -23,7 +22,5 @@ group("hdi_service_audio_test") { "${hdf_ser_aud_path}/test/unittest/audio_capture_interface:hdi_service_audio_capture_test", "${hdf_ser_aud_path}/test/unittest/audio_manager_interface:hdi_service_audio_manager_test", "${hdf_ser_aud_path}/test/unittest/audio_render_interface:hdi_service_audio_render_test", - "${hdf_ser_aud_path}/test/unittest/audio_render_lowlatency:hdi_service_audio_render_lowlatency_test", - "${hdf_ser_aud_path}/test/unittest/audio_capture_lowlatency:hdi_service_audio_capture_lowlatency_test", ] } diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/BUILD.gn index 9bf727a027efb64984760032ba2af158b785c327..ecf0139210f1364efe386c217d39e9a86c33ba10 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/test.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") module_out_path = "distributed_audio/hdf_service/hdi_service/audio" @@ -34,7 +33,7 @@ config("module_private_config") { ] } -## UnitTest hdi_service_audio_test +## UnitTest hdi_service_adapter_test ohos_unittest("HDIServiceAudioAdapterTest") { module_out_path = module_out_path @@ -48,9 +47,7 @@ ohos_unittest("HDIServiceAudioAdapterTest") { "//third_party/googletest:gtest_main", ] - external_deps = [ - "c_utils:utils", - ] + external_deps = [ "c_utils:utils" ] } group("hdi_service_audio_adapter_test") { diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/src/audio_adapter_interface_impl_test.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/src/audio_adapter_interface_impl_test.cpp index 9a1efa5766c696e03e879198d9b4f893b99d1929..c2c586a33c4e76e4404da95c4f7df715bd9dbf30 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/src/audio_adapter_interface_impl_test.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/src/audio_adapter_interface_impl_test.cpp @@ -51,6 +51,8 @@ HWTEST_F(AudioAdapterInterfaceImpTest, InitAllPorts_001, TestSize.Level1) { sptr speakerCallback = nullptr; AdapterTest_->SetSpeakerCallback(speakerCallback); + speakerCallback = new MockIDAudioCallback(); + AdapterTest_->SetSpeakerCallback(speakerCallback); sptr micCallback = nullptr; AdapterTest_->SetMicCallback(micCallback); diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_interface/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_interface/BUILD.gn index 60e6fdf00c71de5041d627f01649f97c864386ec..723de98054473a55873bfdfc945ea7e63ae49dcf 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_interface/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_interface/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/test.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") module_out_path = "distributed_audio/hdf_service/hdi_service/audio" @@ -47,9 +46,7 @@ ohos_unittest("HDIServiceCaptureTest") { "//third_party/googletest:gtest_main", ] - external_deps = [ - "c_utils:utils", - ] + external_deps = [ "c_utils:utils" ] } group("hdi_service_audio_capture_test") { diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_interface/src/audio_capture_interface_impl_test.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_interface/src/audio_capture_interface_impl_test.cpp index bb13246f3169f9befdfdfe961e4e53f83381fd45..d23237d34f5c37ea955eecaa4c9c5b9a173a444a 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_interface/src/audio_capture_interface_impl_test.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_interface/src/audio_capture_interface_impl_test.cpp @@ -113,7 +113,7 @@ HWTEST_F(AudioCaptureInterfaceImplTest, CaptureFrame_003, TestSize.Level1) */ HWTEST_F(AudioCaptureInterfaceImplTest, Start_001, TestSize.Level1) { - EXPECT_EQ(HDF_SUCCESS, audioCaptureInterfaceImpl_->Start()); + EXPECT_EQ(HDF_FAILURE, audioCaptureInterfaceImpl_->Start()); } /** @@ -124,7 +124,7 @@ HWTEST_F(AudioCaptureInterfaceImplTest, Start_001, TestSize.Level1) */ HWTEST_F(AudioCaptureInterfaceImplTest, Stop_001, TestSize.Level1) { - EXPECT_EQ(HDF_SUCCESS, audioCaptureInterfaceImpl_->Stop()); + EXPECT_EQ(HDF_FAILURE, audioCaptureInterfaceImpl_->Stop()); } /** diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_lowlatency/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_lowlatency/BUILD.gn deleted file mode 100644 index 1892b8d446c562fff634890e94b8f3568e6fe52e..0000000000000000000000000000000000000000 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_lowlatency/BUILD.gn +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/test.gni") -import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") - -module_out_path = "distributed_audio/hdf_service/hdi_service/audio" - -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "include", - "${hdf_ser_aud_path}/include", - "${hdf_ser_aud_path}/test/unittest/audio_test_utils", - "${hdf_service_path}/hdi_service/common/include", - "${hdf_service_path}/hdi_service/common/log/include", - "${hdf_service_path}/hdi_service/common/utils/include", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", - ] -} - -## UnitTest hdi_service_audio_v1_0_test -ohos_unittest("HDIServiceCaptureLowlatencyTest") { - module_out_path = module_out_path - - sources = [ "${hdf_ser_aud_path}/test/unittest/audio_capture_lowlatency/src/audio_capture_lowlatency_impl_test.cpp" ] - - configs = [ ":module_private_config" ] - - public_deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "c_utils:utils", - ] -} - -group("hdi_service_audio_capture_lowlatency_test") { - testonly = true - deps = [ ":HDIServiceCaptureLowlatencyTest" ] -} diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_lowlatency/include/audio_capture_lowlatency_impl_test.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_lowlatency/include/audio_capture_lowlatency_impl_test.h deleted file mode 100644 index e6a14c9fb2dbf85138214b7d74b1697f566714eb..0000000000000000000000000000000000000000 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_lowlatency/include/audio_capture_lowlatency_impl_test.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_AUDIO_CAPTURE_LOWLATENCY_IMPL_TEST_H -#define OHOS_AUDIO_CAPTURE_LOWLATENCY_IMPL_TEST_H - -#include - -#include -#include -#include - -#include "audio_test_utils.h" -#define private public -#include "audio_capture_lowlatency_impl.h" -#undef private - -namespace OHOS { -namespace HDI { -namespace DistributedAudio { -namespace Audio { -namespace V1_0 { -using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioData; -using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioParameter; -using OHOS::HDI::DistributedAudio::Audioext::V1_0::IDAudioCallback; - -class AudioCaptureLowlatencyImplTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - std::string adpName_; - AudioDeviceDescriptor desc_; - AudioSampleAttributes attrs_; - sptr callback_; - std::shared_ptr audioCapturelatencyImpl_ = nullptr; -}; -} // V1_0 -} // Audio -} // Distributedaudio -} // HDI -} // OHOS -#endif // OHOS_AUDIO_CAPTURE_LOWLATENCY_IMPL_TEST_H - diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_lowlatency/src/audio_capture_lowlatency_impl_test.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_lowlatency/src/audio_capture_lowlatency_impl_test.cpp deleted file mode 100644 index d14d2cb4236e06f96ee9b4ca2de6b41106774ac2..0000000000000000000000000000000000000000 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_capture_lowlatency/src/audio_capture_lowlatency_impl_test.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "audio_capture_lowlatency_impl_test.h" - -#include -#include -#include - -#include "ashmem.h" -#include "daudio_constants.h" -#include "daudio_log.h" - -using namespace testing::ext; - -namespace OHOS { -namespace HDI { -namespace DistributedAudio { -namespace Audio { -namespace V1_0 { -void AudioCaptureLowlatencyImplTest::SetUpTestCase(void) {} - -void AudioCaptureLowlatencyImplTest::TearDownTestCase(void) {} - -void AudioCaptureLowlatencyImplTest::SetUp(void) -{ - std::string adpName; - AudioDeviceDescriptor desc; - AudioSampleAttributes attrs; - sptr callback; - audioCapturelatencyImpl_ = std::make_shared(adpName, desc, attrs, callback); -} - -void AudioCaptureLowlatencyImplTest::TearDown(void) -{ - audioCapturelatencyImpl_ = nullptr; -} - -/** - * @tc.name: InitAshmem_001 - * @tc.desc: Verify the InitAshmem function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioCaptureLowlatencyImplTest, InitAshmem_001, TestSize.Level1) -{ - int32_t ashmemLength = 1024; - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->InitAshmem(ashmemLength)); - audioCapturelatencyImpl_->UnInitAshmem(); -} - -/** - * @tc.name: InitAshmem_002 - * @tc.desc: Verify the InitAshmem function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioCaptureLowlatencyImplTest, InitAshmem_002, TestSize.Level1) -{ - int32_t ashmemLength = -1; - EXPECT_EQ(HDF_FAILURE, audioCapturelatencyImpl_->InitAshmem(ashmemLength)); - audioCapturelatencyImpl_->UnInitAshmem(); -} - -/** - * @tc.name: Start_001 - * @tc.desc: Verify the Start function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioCaptureLowlatencyImplTest, Start_001, TestSize.Level1) -{ - uint64_t frames = 0; - AudioTimeStamp time; - std::vector frame; - uint64_t requestBytes = 1024; - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->GetCapturePosition(frames, time)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->CaptureFrame(frame, requestBytes)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->Pause()); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->Resume()); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->Flush()); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->TurnStandbyMode()); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->GetMmapPosition(frames, time)); - audioCapturelatencyImpl_->audioExtCallback_ = new MockIDAudioCallback(); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->Start()); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->Stop()); -} - -/** - * @tc.name: Start_002 - * @tc.desc: Verify the Start function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioCaptureLowlatencyImplTest, Start_002, TestSize.Level1) -{ - int32_t range = 1; - int32_t fd = 1; - bool supportPause = true; - bool supportResume = true; - AudioSceneDescriptor scene; - bool supported = true; - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->AudioDevDump(range, fd)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->IsSupportsPauseAndResume(supportPause, supportResume)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->CheckSceneCapability(scene, supported)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->SelectScene(scene)); - audioCapturelatencyImpl_->audioExtCallback_ = nullptr; - EXPECT_EQ(HDF_FAILURE, audioCapturelatencyImpl_->Start()); -} - -/** - * @tc.name: ReqMmapBuffer_001 - * @tc.desc: Verify the ReqMmapBuffer function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioCaptureLowlatencyImplTest, ReqMmapBuffer_001, TestSize.Level1) -{ - int32_t reqSize = 30; - AudioMmapBufferDescriptor desc; - EXPECT_EQ(HDF_FAILURE, audioCapturelatencyImpl_->ReqMmapBuffer(reqSize, desc)); - audioCapturelatencyImpl_->UnInitAshmem(); -} - -/** - * @tc.name: ReqMmapBuffer_002 - * @tc.desc: Verify the ReqMmapBuffer function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioCaptureLowlatencyImplTest, ReqMmapBuffer_002, TestSize.Level1) -{ - int32_t reqSize = 30; - AudioMmapBufferDescriptor desc; - struct AudioSampleAttributes captureAttr = { - .type = AUDIO_IN_MEDIA, - .interleaved = 0, - .format = AUDIO_FORMAT_TYPE_PCM_16_BIT, - .sampleRate = 48000, - .channelCount = 2, - .period = 1024, - .frameSize = 4, - .isBigEndian = false, - .isSignedData = true, - .startThreshold = 1024, - .stopThreshold = 0x7fffffff, - .silenceThreshold = 0, - .streamId = 1, - }; - audioCapturelatencyImpl_->devAttrs_ = captureAttr; - audioCapturelatencyImpl_->audioExtCallback_ = new MockIDAudioCallback(); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->ReqMmapBuffer(reqSize, desc)); - audioCapturelatencyImpl_->UnInitAshmem(); -} - -/** - * @tc.name: SetMute_001 - * @tc.desc: Verify the SetMute function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioCaptureLowlatencyImplTest, SetMute_001, TestSize.Level1) -{ - bool mute = true; - float volume = 0.0; - float min = 0.0; - float max = 10.0; - uint64_t size = 1024; - uint32_t channelId = 0; - std::string keyValueList = "keyValueList"; - AudioSampleAttributes attrs; - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->SetMute(mute)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->GetMute(mute)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->SetVolume(volume)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->GetGainThreshold(min, max)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->SetGain(volume)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->GetGain(volume)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->GetFrameSize(size)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->GetFrameCount(size)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->SetSampleAttributes(attrs)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->GetSampleAttributes(attrs)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->GetCurrentChannelId(channelId)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->SetExtraParams(keyValueList)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->GetExtraParams(keyValueList)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->AddAudioEffect(size)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->RemoveAudioEffect(size)); - EXPECT_EQ(HDF_SUCCESS, audioCapturelatencyImpl_->GetFrameBufferSize(size)); -} -} // V1_0 -} // Audio -} // Distributedaudio -} // HDI -} // OHOS \ No newline at end of file diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_manager_interface/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_manager_interface/BUILD.gn index 7cb001d222f8b798305a536be3b9fb575ca8d3c1..25415052388dcc803d72de0d721a91ce0e353a16 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_manager_interface/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_manager_interface/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/test.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") module_out_path = "distributed_audio/hdf_service/hdi_service/audio" diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_interface/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_interface/BUILD.gn index b1d7f8ca629a4e2b45f432686582fb35f7842997..f9dfad9d1bfb9b6e0359652319ee40fe2b15a7d8 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_interface/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_interface/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/test.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") module_out_path = "distributed_audio/hdf_service/hdi_service/audio" @@ -48,9 +47,7 @@ ohos_unittest("HDIServiceRenderTest") { "//third_party/googletest:gtest_main", ] - external_deps = [ - "c_utils:utils", - ] + external_deps = [ "c_utils:utils" ] } group("hdi_service_audio_render_test") { diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_lowlatency/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_lowlatency/BUILD.gn deleted file mode 100644 index d937a21d371103a8b9f6f481a17d83f92b82b93c..0000000000000000000000000000000000000000 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_lowlatency/BUILD.gn +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/test.gni") -import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") - -module_out_path = "distributed_audio/hdf_service/hdi_service/audio" - -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "include", - "${hdf_ser_aud_path}/include", - "${hdf_ser_aud_path}/test/unittest/audio_test_utils", - "${hdf_service_path}/hdi_service/common/include", - "${hdf_service_path}/hdi_service/common/log/include", - "${hdf_service_path}/hdi_service/common/utils/include", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", - ] -} - -## UnitTest hdi_service_audio_v1_0_test -ohos_unittest("HDIServiceRenderLowlatencyTest") { - module_out_path = module_out_path - - sources = [ "${hdf_ser_aud_path}/test/unittest/audio_render_lowlatency/src/audio_render_lowlatency_impl_test.cpp" ] - - configs = [ ":module_private_config" ] - - public_deps = [ - "${hdf_ser_aud_path}:libaudio_manager_daudio_primary_service_1.0", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "c_utils:utils", - ] -} - -group("hdi_service_audio_render_lowlatency_test") { - testonly = true - deps = [ ":HDIServiceRenderLowlatencyTest" ] -} diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_lowlatency/include/audio_render_lowlatency_impl_test.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_lowlatency/include/audio_render_lowlatency_impl_test.h deleted file mode 100644 index 2f018ddbcc31d0052d8378df53e90da41c163a73..0000000000000000000000000000000000000000 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_lowlatency/include/audio_render_lowlatency_impl_test.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_AUDIO_RENDER_LOWLATENCY_IMPL_TEST_H -#define OHOS_AUDIO_RENDER_LOWLATENCY_IMPL_TEST_H - -#include - -#include -#include -#include - -#include "audio_test_utils.h" -#define private public -#include "audio_render_lowlatency_impl.h" -#undef private - -namespace OHOS { -namespace HDI { -namespace DistributedAudio { -namespace Audio { -namespace V1_0 { -using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioData; -using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioParameter; -using OHOS::HDI::DistributedAudio::Audioext::V1_0::IDAudioCallback; - -class AudioRenderLowlatencyImplTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - std::string adpName_; - AudioDeviceDescriptor desc_; - AudioSampleAttributes attrs_; - sptr callback_; - std::shared_ptr audioRenderlatencyImpl_ = nullptr; -}; -} // V1_0 -} // Audio -} // Distributedaudio -} // HDI -} // OHOS -#endif // OHOS_AUDIO_RENDER_LOWLATENCY_IMPL_TEST_H - diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_lowlatency/src/audio_render_lowlatency_impl_test.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_lowlatency/src/audio_render_lowlatency_impl_test.cpp deleted file mode 100644 index 03e5e2308a368236704e1ea35deb902c1c1a1061..0000000000000000000000000000000000000000 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_render_lowlatency/src/audio_render_lowlatency_impl_test.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "audio_render_lowlatency_impl_test.h" - -#include -#include -#include - -#include "ashmem.h" -#include "daudio_constants.h" -#include "daudio_log.h" - -using namespace testing::ext; - -namespace OHOS { -namespace HDI { -namespace DistributedAudio { -namespace Audio { -namespace V1_0 { -void AudioRenderLowlatencyImplTest::SetUpTestCase(void) {} - -void AudioRenderLowlatencyImplTest::TearDownTestCase(void) {} - -void AudioRenderLowlatencyImplTest::SetUp(void) -{ - std::string adpName; - AudioDeviceDescriptor desc; - AudioSampleAttributes attrs; - sptr callback; - audioRenderlatencyImpl_ = std::make_shared(adpName, desc, attrs, callback); -} - -void AudioRenderLowlatencyImplTest::TearDown(void) -{ - audioRenderlatencyImpl_ = nullptr; -} - -/** - * @tc.name: InitAshmem_001 - * @tc.desc: Verify the InitAshmem function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioRenderLowlatencyImplTest, InitAshmem_001, TestSize.Level1) -{ - int fd = 1; - uint32_t ms = 0; - float speed = 0.0; - uint64_t replyBytes = 0; - int32_t ashmemLength = 1024; - const std::vector frame; - AudioTimeStamp time; - audioRenderlatencyImpl_->audioExtCallback_ = new MockIDAudioCallback(); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->InitAshmem(ashmemLength)); - audioRenderlatencyImpl_->UnInitAshmem(); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetRenderPosition(replyBytes, time)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->RenderFrame(frame, replyBytes)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetLatency(ms)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->SetRenderSpeed(speed)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetRenderSpeed(speed)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->SetVolume(speed)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetVolume(speed)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->AudioDevDump(ashmemLength, fd)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetMmapPosition(replyBytes, time)); -} - -/** - * @tc.name: InitAshmem_002 - * @tc.desc: Verify the InitAshmem function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioRenderLowlatencyImplTest, InitAshmem_002, TestSize.Level1) -{ - int8_t cookie = 0; - bool support = true; - int32_t ashmemLength = -1; - AudioDrainNotifyType type; - AudioSceneDescriptor scene; - sptr audioCallback = nullptr; - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->Pause()); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->Resume()); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->Flush()); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->TurnStandbyMode()); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->DrainBuffer(type)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->IsSupportsPauseAndResume(support, support)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->CheckSceneCapability(scene, support)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->SelectScene(scene)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->SetMute(support)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetMute(support)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->IsSupportsDrain(support)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->RegCallback(audioCallback, cookie)); - EXPECT_EQ(HDF_FAILURE, audioRenderlatencyImpl_->InitAshmem(ashmemLength)); - audioRenderlatencyImpl_->UnInitAshmem(); -} - -/** - * @tc.name: GetFadeRate_001 - * @tc.desc: Verify the GetFadeRate function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioRenderLowlatencyImplTest, GetFadeRate_001, TestSize.Level1) -{ - float min = 0.0; - float max = 10.0; - uint64_t size = 1024; - uint32_t currentIndex = 2; - const uint32_t durationIndex = 5; - AudioSampleAttributes attrs; - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetGainThreshold(min, max)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->SetGain(min)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetGain(min)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetFrameSize(size)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetFrameCount(size)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->SetSampleAttributes(attrs)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetSampleAttributes(attrs)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetCurrentChannelId(currentIndex)); - float fadeRate = audioRenderlatencyImpl_->GetFadeRate(currentIndex, durationIndex); - EXPECT_LE(0, fadeRate); - EXPECT_GE(0.5f, fadeRate); -} - -/** - * @tc.name: FadeInProcess_001 - * @tc.desc: Verify the FadeInProcess function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioRenderLowlatencyImplTest, FadeInProcess_001, TestSize.Level1) -{ - uint64_t effectid = 0; - std::string keyValueList = "keyValueList"; - const uint32_t durationFrame = 10; - const size_t frameLength = 4096; - int8_t* frameData = new int8_t[frameLength]; - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->SetExtraParams(keyValueList)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetExtraParams(keyValueList)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->AddAudioEffect(effectid)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->RemoveAudioEffect(effectid)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetFrameBufferSize(effectid)); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetVolumeInner()); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetMaxVolumeInner()); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->GetMinVolumeInner()); - audioRenderlatencyImpl_->SetVolumeInner(durationFrame); - audioRenderlatencyImpl_->SetVolumeRangeInner(durationFrame, durationFrame); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->FadeInProcess(durationFrame, frameData, frameLength)); -} - -/** - * @tc.name: Start_001 - * @tc.desc: Verify the Start function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioRenderLowlatencyImplTest, Start_001, TestSize.Level1) -{ - audioRenderlatencyImpl_->audioExtCallback_ = new MockIDAudioCallback(); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->Start()); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->Stop()); -} - -/** - * @tc.name: Start_002 - * @tc.desc: Verify the Start function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioRenderLowlatencyImplTest, Start_002, TestSize.Level1) -{ - audioRenderlatencyImpl_->audioExtCallback_ = nullptr; - EXPECT_EQ(HDF_FAILURE, audioRenderlatencyImpl_->Start()); -} - -/** - * @tc.name: ReqMmapBuffer_001 - * @tc.desc: Verify the Start function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioRenderLowlatencyImplTest, ReqMmapBuffer_001, TestSize.Level1) -{ - int32_t reqSize = 30; - AudioMmapBufferDescriptor desc; - EXPECT_EQ(HDF_FAILURE, audioRenderlatencyImpl_->ReqMmapBuffer(reqSize, desc)); - audioRenderlatencyImpl_->UnInitAshmem(); -} - -/** - * @tc.name: ReqMmapBuffer_002 - * @tc.desc: Verify the Start function. - * @tc.type: FUNC - * @tc.require: AR000HP6J4 - */ -HWTEST_F(AudioRenderLowlatencyImplTest, ReqMmapBuffer_002, TestSize.Level1) -{ - int32_t reqSize = 30; - AudioMmapBufferDescriptor desc; - struct AudioSampleAttributes renderAttr = { - .type = AUDIO_IN_MEDIA, - .interleaved = 0, - .format = AUDIO_FORMAT_TYPE_PCM_16_BIT, - .sampleRate = 48000, - .channelCount = 2, - .period = 1024, - .frameSize = 4, - .isBigEndian = false, - .isSignedData = true, - .startThreshold = 1024, - .stopThreshold = 0x7fffffff, - .silenceThreshold = 0, - .streamId = 1, - }; - audioRenderlatencyImpl_->devAttrs_ = renderAttr; - audioRenderlatencyImpl_->audioExtCallback_ = new MockIDAudioCallback(); - EXPECT_EQ(HDF_SUCCESS, audioRenderlatencyImpl_->ReqMmapBuffer(reqSize, desc)); - audioRenderlatencyImpl_->UnInitAshmem(); -} -} // V1_0 -} // Audio -} // Distributedaudio -} // HDI -} // OHOS \ No newline at end of file diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_test_utils/audio_test_utils.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_test_utils/audio_test_utils.h index 883035ee41019361629521597993e7a9ecef4797..bc57b7db4ad093b47b48c2df829f84cc46974f3d 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_test_utils/audio_test_utils.h +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_test_utils/audio_test_utils.h @@ -34,6 +34,7 @@ namespace V1_0 { using OHOS::HDI::DistributedAudio::Audioext::V1_0::DAudioEvent; using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioData; using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioParameter; +using OHOS::HDI::DistributedAudio::Audioext::V1_0::CurrentTime; using OHOS::HDI::DistributedAudio::Audioext::V1_0::IDAudioCallback; using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback; class MockIDAudioCallback : public IDAudioCallback { @@ -71,7 +72,8 @@ public: return DistributedHardware::DH_SUCCESS; } - int32_t ReadMmapPosition(const std::string &adpName, int32_t devId, uint64_t &frames, uint64_t &timeStamp) override + int32_t ReadMmapPosition(const std::string &adpName, int32_t devId, uint64_t &frames, + CurrentTime &time) override { return DistributedHardware::DH_SUCCESS; } @@ -514,7 +516,8 @@ public: return DistributedHardware::ERR_DH_AUDIO_HDF_FAIL; } - int32_t ReadMmapPosition(const std::string &adpName, int32_t devId, uint64_t &frames, uint64_t &timeStamp) override + int32_t ReadMmapPosition(const std::string &adpName, int32_t devId, uint64_t &frames, + CurrentTime &time) override { return DistributedHardware::DH_SUCCESS; } diff --git a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/BUILD.gn index 0685b3a54065a37d682cd39d38f45b8d95091917..a8c2b3b77e63095be1d10571fa76f05eec9604a3 100644 --- a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") ohos_shared_library("libdaudio_manager_daudio_ext_service_1.0") { include_dirs = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/notifyevent_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/notifyevent_fuzzer/BUILD.gn index 67788145f3391d0dd21e6b78bbb85f68641c9350..358427f377a0a5389edc98aaa23045819cc0a741 100644 --- a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/notifyevent_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/notifyevent_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("NotifyEventFuzzTest") { @@ -45,8 +44,8 @@ ohos_fuzztest("NotifyEventFuzzTest") { ] deps = [ - "${hdf_ser_aud_ext_path}:libdaudio_manager_daudio_ext_service_1.0", "${hdf_interfaces_path}/audioext/v1_0:libdaudioext_stub_1.0", + "${hdf_ser_aud_ext_path}:libdaudio_manager_daudio_ext_service_1.0", ] external_deps = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/registeraudiodevice_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/registeraudiodevice_fuzzer/BUILD.gn index 36c34cc7d5ff06de2bf81aca91cf72e25deb8ee1..d7b8c5ec12c1a387683de3e26eff0044b5ff576f 100644 --- a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/registeraudiodevice_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/registeraudiodevice_fuzzer/BUILD.gn @@ -14,13 +14,13 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("RegisterAudioDeviceFuzzTest") { module_out_path = "distributed_audio/registeraudiodevice_fuzzer" - fuzz_config_file = "${hdf_ser_aud_ext_path}/test/fuzztest/registeraudiodevice_fuzzer" + fuzz_config_file = + "${hdf_ser_aud_ext_path}/test/fuzztest/registeraudiodevice_fuzzer" cflags = [ "-g", @@ -45,8 +45,8 @@ ohos_fuzztest("RegisterAudioDeviceFuzzTest") { ] deps = [ - "${hdf_ser_aud_ext_path}:libdaudio_manager_daudio_ext_service_1.0", "${hdf_interfaces_path}/audioext/v1_0:libdaudioext_stub_1.0", + "${hdf_ser_aud_ext_path}:libdaudio_manager_daudio_ext_service_1.0", ] external_deps = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/unregisteraudiodevice_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/unregisteraudiodevice_fuzzer/BUILD.gn index 3a200ee54f62527ecffece476e695201620cb3d4..a8996453373a147f29f64c88e24d1f609d0c2c8c 100644 --- a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/unregisteraudiodevice_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/unregisteraudiodevice_fuzzer/BUILD.gn @@ -14,13 +14,13 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("UnRegisterAudioDeviceFuzzTest") { module_out_path = "distributed_audio/unregisteraudiodevice_fuzzer" - fuzz_config_file = "${hdf_ser_aud_ext_path}/test/fuzztest/unregisteraudiodevice_fuzzer" + fuzz_config_file = + "${hdf_ser_aud_ext_path}/test/fuzztest/unregisteraudiodevice_fuzzer" cflags = [ "-g", @@ -45,8 +45,8 @@ ohos_fuzztest("UnRegisterAudioDeviceFuzzTest") { ] deps = [ - "${hdf_ser_aud_ext_path}:libdaudio_manager_daudio_ext_service_1.0", "${hdf_interfaces_path}/audioext/v1_0:libdaudioext_stub_1.0", + "${hdf_ser_aud_ext_path}:libdaudio_manager_daudio_ext_service_1.0", ] external_deps = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/unittest/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/unittest/BUILD.gn index df54f14ef58b8ea57702f935d8fc0c9cd515f9ef..56e45be12425107bc001273820899c14a8c150f2 100644 --- a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/unittest/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/unittest/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/test.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../../distributedaudio.gni") module_out_path = "distributed_audio/hdf_service/hdi_service/audio_ext" diff --git a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/unittest/include/daudio_test_utils.h b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/unittest/include/daudio_test_utils.h index 3d1c30626deff62882992882e1645757741a78f7..e54fc355038c100f01d8063df9c9fc263f35b3a3 100644 --- a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/unittest/include/daudio_test_utils.h +++ b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/unittest/include/daudio_test_utils.h @@ -57,7 +57,8 @@ public: return 0; } - int32_t ReadMmapPosition(const std::string &adpName, int32_t devId, uint64_t &frames, uint64_t &timeStamp) override + int32_t ReadMmapPosition(const std::string &adpName, int32_t devId, uint64_t &frames, + CurrentTime &time) override { return 0; } diff --git a/hdf_service/distributed_audio/hdi_service/common/include/daudio_constants.h b/hdf_service/distributed_audio/hdi_service/common/include/daudio_constants.h index 9b58ba742ae05e1fc034e6d6d409833fdc3ba958..56ef2fb665220d022343983c07033282a4374139 100644 --- a/hdf_service/distributed_audio/hdi_service/common/include/daudio_constants.h +++ b/hdf_service/distributed_audio/hdi_service/common/include/daudio_constants.h @@ -66,13 +66,13 @@ constexpr uint32_t AUDIO_FORMAT_DEFAULT = 16; constexpr int32_t MILLISECOND_PER_SECOND = 1000; constexpr uint32_t DEFAULT_AUDIO_DATA_SIZE = 4096; -constexpr int32_t AUDIO_OFFSET_FRAME_NUM = 10; +constexpr int64_t AUDIO_OFFSET_FRAME_NUM = 10; constexpr uint32_t AUDIO_DEFAULT_MAX_VOLUME_LEVEL = 15; constexpr uint32_t AUDIO_DEFAULT_MIN_VOLUME_LEVEL = 0; -constexpr uint32_t DAUDIO_MAX_ASHMEM_LEN = 100000; -constexpr uint32_t DAUDIO_MIN_ASHMEM_LEN = 10; +constexpr int32_t DAUDIO_MAX_ASHMEM_LEN = 100000; +constexpr int32_t DAUDIO_MIN_ASHMEM_LEN = 10; } // DistributeHardware } // OHOS #endif // OHOS_DAUDIO_CONSTANTS_H diff --git a/hdf_service/distributed_audio/hdi_service/common/include/daudio_events.h b/hdf_service/distributed_audio/hdi_service/common/include/daudio_events.h index b8ef012143e536d084c9f68410ec07ed08906c0c..5c9dd4732147f82ff8842c6a6e744dc0bd1b7c8a 100644 --- a/hdf_service/distributed_audio/hdi_service/common/include/daudio_events.h +++ b/hdf_service/distributed_audio/hdi_service/common/include/daudio_events.h @@ -59,10 +59,6 @@ typedef enum AudioExtParamEvent { HDF_AUDIO_EVENT_RENDER_STATE_CHANGE = 11, HDF_AUDIO_EVNET_MUTE_SET = 12, HDF_AUDIO_EVENT_CHANGE_PLAY_STATUS = 13, - HDF_AUDIO_EVENT_MMAP_START = 14, - HDF_AUDIO_EVENT_MMAP_STOP = 15, - HDF_AUDIO_EVENT_MMAP_START_MIC = 16, - HDF_AUDIO_EVENT_MMAP_STOP_MIC = 17, HDF_AUDIO_EVENT_START = 18, HDF_AUDIO_EVENT_STOP = 19, } EXT_PARAM_EVENT; diff --git a/hdf_service/distributed_audio/hdi_service/common/utils/include/daudio_utils.h b/hdf_service/distributed_audio/hdi_service/common/utils/include/daudio_utils.h index 64da2408917afccf63b68c2a4e4351b414ba8831..538b913040e31c18f4a286cbd6479b66d735b4e7 100644 --- a/hdf_service/distributed_audio/hdi_service/common/utils/include/daudio_utils.h +++ b/hdf_service/distributed_audio/hdi_service/common/utils/include/daudio_utils.h @@ -45,6 +45,10 @@ int32_t CalculateSampleNum(uint32_t sampleRate, uint32_t timems); int64_t GetCurNano(); int32_t AbsoluteSleep(int64_t nanoTime); + +int64_t CalculateOffset(const int64_t frameindex, const int64_t framePeriodNs, const int64_t startTime); + +int64_t UpdateTimeOffset(const int64_t frameIndex, const int64_t framePeriodNs, int64_t &startTime); } // DistributedHardware } // OHOS #endif \ No newline at end of file diff --git a/hdf_service/distributed_audio/hdi_service/common/utils/src/daudio_utils.cpp b/hdf_service/distributed_audio/hdi_service/common/utils/src/daudio_utils.cpp index 8bee9c30d7eaf0e72cd7a65e8e549e3d2f59bce8..f9e58d4b7df5773152470f9ca3cf95d0222b6a23 100644 --- a/hdf_service/distributed_audio/hdi_service/common/utils/src/daudio_utils.cpp +++ b/hdf_service/distributed_audio/hdi_service/common/utils/src/daudio_utils.cpp @@ -108,12 +108,12 @@ int32_t GetDevTypeByDHId(int32_t dhId) uint32_t CalculateFrameSize(uint32_t sampleRate, uint32_t channelCount, int32_t format, uint32_t timeInterval, bool isMMAP) { - return isMMAP ? sampleRate * channelCount * format * timeInterval / AUDIO_MS_PER_SECOND : DEFAULT_AUDIO_DATA_SIZE; + return isMMAP ? (sampleRate * channelCount * format * timeInterval) / AUDIO_MS_PER_SECOND : DEFAULT_AUDIO_DATA_SIZE; } int32_t CalculateSampleNum(uint32_t sampleRate, uint32_t timems) { - return sampleRate * timems / AUDIO_MS_PER_SECOND; + return (sampleRate * timems) / AUDIO_MS_PER_SECOND; } int64_t GetCurNano() @@ -141,8 +141,24 @@ int32_t AbsoluteSleep(int64_t nanoTime) clockid_t clockId = CLOCK_MONOTONIC; ret = clock_nanosleep(clockId, TIMER_ABSTIME, &time, nullptr); - return ret; } + +int64_t CalculateOffset(const int64_t frameIndex, const int64_t framePeriodNs, const int64_t startTime) +{ + int64_t totalOffset = GetCurNano() - startTime; + return totalOffset - frameIndex * framePeriodNs; +} + +int64_t UpdateTimeOffset(const int64_t frameIndex, const int64_t framePeriodNs, int64_t &startTime) +{ + int64_t timeOffset = 0; + if (frameIndex == 0) { + startTime = GetCurNano(); + } else if (frameIndex % AUDIO_OFFSET_FRAME_NUM == 0) { + timeOffset = CalculateOffset(frameIndex, framePeriodNs, startTime); + } + return timeOffset; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/hdf_service/distributed_audio/interface/audio_ext/v1_0/i_daudio_hdf_callback.h b/hdf_service/distributed_audio/interface/audio_ext/v1_0/i_daudio_hdf_callback.h index aaf0016513247b8e72488566d2ba9950e6e6cc98..c5fb27a00b7593db46d339cebdd374af0ad4c7b8 100644 --- a/hdf_service/distributed_audio/interface/audio_ext/v1_0/i_daudio_hdf_callback.h +++ b/hdf_service/distributed_audio/interface/audio_ext/v1_0/i_daudio_hdf_callback.h @@ -30,7 +30,7 @@ public: virtual int32_t WriteStreamData(int32_t devId, int32_t dhId, struct AudioStreamData &data) = 0; virtual struct AudioStreamData* ReadStreamData(int32_t devId, int32_t dhId) = 0; virtual int32_t ReadMmapPosition(int32_t devId, int32_t dhId, - uint64_t &frames, uint64_t &timeStamp) = 0; + uint64_t &frames, struct CurrentTime &time) = 0; virtual int32_t RefreshAshmemInfo(int32_t devId, int32_t dhId, int32_t fd, int32_t ashmemLength, int32_t lengthPerTrans) = 0; } // namespace DistributedHardware diff --git a/hdf_service/distributed_audio/mfc_test/BUILD.gn b/hdf_service/distributed_audio/mfc_test/BUILD.gn index e89b2d1f244231a7983c439e273c19cd0ef3f840..f2732b6cc628b82671ba8942deb0179084f135be 100644 --- a/hdf_service/distributed_audio/mfc_test/BUILD.gn +++ b/hdf_service/distributed_audio/mfc_test/BUILD.gn @@ -23,9 +23,7 @@ ohos_executable("audio_test_distributed_fifo") { "//foundation/distributedhardware/distributed_audio/hdf_service/distributed_audio/hdi_service/common/include", ] - sources = [ - "distributedaudiotest.cpp", - ] + sources = [ "distributedaudiotest.cpp" ] deps = [ "$hdf_uhdf_path/utils:libhdf_utils", @@ -35,7 +33,7 @@ ohos_executable("audio_test_distributed_fifo") { external_deps = [ "c_utils:utils", "hiviewdfx_hilog_native:libhilog", -] + ] defines = [ "HI_LOG_ENABLE", @@ -47,4 +45,4 @@ ohos_executable("audio_test_distributed_fifo") { install_images = [ chipset_base_dir ] subsystem_name = "distributedhardware" part_name = "distributed_audio" -} \ No newline at end of file +} diff --git a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn index 8128726baf8d921d9593eb3703355d88b52bfec4..934cd42e71c857d6481d305242af7eee17d8fcf2 100755 --- a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") ohos_shared_library("distributed_audio_sink_sdk") { include_dirs = [ @@ -37,7 +36,7 @@ ohos_shared_library("distributed_audio_sink_sdk") { "src/daudio_sink_proxy.cpp", ] - deps = [ "${services_path}/common:distributed_audio_utils", ] + deps = [ "${services_path}/common:distributed_audio_utils" ] external_deps = [ "c_utils:utils", diff --git a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn index 86999a07a29717308969c346171cd904a04ca87c..2898b1eb7de7808293401f1b3efbe74c448962db 100755 --- a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") ohos_shared_library("distributed_audio_source_sdk") { include_dirs = [ @@ -39,7 +38,7 @@ ohos_shared_library("distributed_audio_source_sdk") { "src/daudio_source_proxy.cpp", ] - deps = [ "${services_path}/common:distributed_audio_utils", ] + deps = [ "${services_path}/common:distributed_audio_utils" ] external_deps = [ "c_utils:utils", diff --git a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback_stub.cpp b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback_stub.cpp index 149a1098d329bf45a3acc9e0d804e53248f5afb2..68f950c24112227dedde3902399cc3b9afa04c59 100644 --- a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback_stub.cpp +++ b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback_stub.cpp @@ -43,7 +43,7 @@ int32_t DAudioIpcCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &dat std::map::iterator iter = memberFuncMap_.find(code); if (iter == memberFuncMap_.end()) { DHLOGE("Invalid request code."); - return ERR_DH_AUDIO_SA_INVALID_REQUEST_CODE; + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } DAudioCallbackFunc &func = iter->second; return (this->*func)(data, reply, option); diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index f45625a73ed471e1ccc3bb0623624902f23fb526..8605ec77d16b725f78a9832f3160eb412011c45a 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -13,13 +13,26 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") group("fuzztest") { testonly = true deps = [ + "${hdf_ser_aud_ext_path}/test/fuzztest/notifyevent_fuzzer:fuzztest", + "${hdf_ser_aud_ext_path}/test/fuzztest/registeraudiodevice_fuzzer:fuzztest", + "${hdf_ser_aud_ext_path}/test/fuzztest/unregisteraudiodevice_fuzzer:fuzztest", + "${hdf_ser_aud_path}/test/fuzztest/captureframe_fuzzer:fuzztest", + "${hdf_ser_aud_path}/test/fuzztest/createcapture_fuzzer:fuzztest", + "${hdf_ser_aud_path}/test/fuzztest/createrender_fuzzer:fuzztest", + "${hdf_ser_aud_path}/test/fuzztest/destroycapture_fuzzer:fuzztest", + "${hdf_ser_aud_path}/test/fuzztest/destroyrender_fuzzer:fuzztest", + "${hdf_ser_aud_path}/test/fuzztest/getalladapters_fuzzer:fuzztest", + "${hdf_ser_aud_path}/test/fuzztest/getextraparams_fuzzer:fuzztest", + "${hdf_ser_aud_path}/test/fuzztest/loadadapter_fuzzer:fuzztest", + "${hdf_ser_aud_path}/test/fuzztest/renderframe_fuzzer:fuzztest", + "${hdf_ser_aud_path}/test/fuzztest/setextraparams_fuzzer:fuzztest", + "${hdf_ser_aud_path}/test/fuzztest/unloadadapter_fuzzer:fuzztest", "onremotesinksvrdied_fuzzer:fuzztest", "onremotesourcesvrdied_fuzzer:fuzztest", "sinkhandlerfinishstartsa_fuzzer:fuzztest", @@ -46,19 +59,5 @@ group("fuzztest") { "sourceproxyinitsource_fuzzer:fuzztest", "sourceproxyregisterdistributedhardware_fuzzer:fuzztest", "sourceproxyunregisterdistributedhardware_fuzzer:fuzztest", - "${hdf_ser_aud_ext_path}/test/fuzztest/notifyevent_fuzzer:fuzztest", - "${hdf_ser_aud_ext_path}/test/fuzztest/unregisteraudiodevice_fuzzer:fuzztest", - "${hdf_ser_aud_ext_path}/test/fuzztest/registeraudiodevice_fuzzer:fuzztest", - "${hdf_ser_aud_path}/test/fuzztest/captureframe_fuzzer:fuzztest", - "${hdf_ser_aud_path}/test/fuzztest/getalladapters_fuzzer:fuzztest", - "${hdf_ser_aud_path}/test/fuzztest/loadadapter_fuzzer:fuzztest", - "${hdf_ser_aud_path}/test/fuzztest/unloadadapter_fuzzer:fuzztest", - "${hdf_ser_aud_path}/test/fuzztest/renderframe_fuzzer:fuzztest", - "${hdf_ser_aud_path}/test/fuzztest/createrender_fuzzer:fuzztest", - "${hdf_ser_aud_path}/test/fuzztest/destroycapture_fuzzer:fuzztest", - "${hdf_ser_aud_path}/test/fuzztest/destroyrender_fuzzer:fuzztest", - "${hdf_ser_aud_path}/test/fuzztest/createcapture_fuzzer:fuzztest", - "${hdf_ser_aud_path}/test/fuzztest/setextraparams_fuzzer:fuzztest", - "${hdf_ser_aud_path}/test/fuzztest/getextraparams_fuzzer:fuzztest", ] } diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesinksvrdied_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesinksvrdied_fuzzer/BUILD.gn index 0af18d3d95fd24f9254d6a16ac4284555ab3f174..8cb74d667d43da1c32d35105d03fcc9d9fef4902 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesinksvrdied_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesinksvrdied_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("OnRemoteSinkSvrDiedFuzzTest") { @@ -47,9 +46,8 @@ ohos_fuzztest("OnRemoteSinkSvrDiedFuzzTest") { "${innerkits_path}/native_cpp/audio_sink/include", ] - deps = [ - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesourcesvrdied_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesourcesvrdied_fuzzer/BUILD.gn index 8e4379d7d29f4e4c15fa0d4ba7851387dd9acc4c..f55439c35e65c9e7e53f237dbb05903cfa4a7b4d 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesourcesvrdied_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesourcesvrdied_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("OnRemoteSourceSvrDiedFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerfinishstartsa_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerfinishstartsa_fuzzer/BUILD.gn index fc41aa42875e4b62682a2dcd39adc106800d356e..7607a317c13b67edbaada89bf1ee00d2d564f308 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerfinishstartsa_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerfinishstartsa_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkHandlerFinishStartSAFuzzTest") { @@ -46,9 +45,8 @@ ohos_fuzztest("SinkHandlerFinishStartSAFuzzTest") { "${innerkits_path}/native_cpp/audio_sink/include", ] - deps = [ - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn index b7ad6bfbaea99b75db5c05413f08fbd6aee74de2..236fd0b2151a2f9ca50b14b7f09cb64e265b83b9 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkHandlerInitSinkFuzzTest") { @@ -47,9 +46,8 @@ ohos_fuzztest("SinkHandlerInitSinkFuzzTest") { "${innerkits_path}/native_cpp/audio_sink/include", ] - deps = [ - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn index 69a28ce9636897144153c1560a3ef0323eb02c02..778453fb72ad5e7071ae87f3d7ce0220abde25cb 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkHandlerSubscribeLocalHardwareFuzzTest") { @@ -46,9 +45,8 @@ ohos_fuzztest("SinkHandlerSubscribeLocalHardwareFuzzTest") { "${innerkits_path}/native_cpp/audio_sink/include", ] - deps = [ - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn index 74ed9ffedac6648c443391d0def1206478b79523..c0a7115f76cacc217bba404523d4fca12566a0aa 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkHandlerUnsubscribeLocalHardwareFuzzTest") { @@ -46,9 +45,8 @@ ohos_fuzztest("SinkHandlerUnsubscribeLocalHardwareFuzzTest") { "${innerkits_path}/native_cpp/audio_sink/include", ] - deps = [ - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn index 999aa237ec6501fce6eadce2e53986827218c9fb..ba31a5da624248b356eb91afbb083b19a3ad0926 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkOnLoadSystemAbilityFailFuzzTest") { @@ -45,9 +44,8 @@ ohos_fuzztest("SinkOnLoadSystemAbilityFailFuzzTest") { "${innerkits_path}/native_cpp/audio_sink/include", ] - deps = [ - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn index 4e6e6f892d802630ed9ed442ec2cd2534e8fb20a..e96df5cd3d9e2129a9d5525c5c9e04f367bfefa1 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkOnLoadSystemAbilitySuccessFuzzTest") { @@ -45,9 +44,8 @@ ohos_fuzztest("SinkOnLoadSystemAbilitySuccessFuzzTest") { "${innerkits_path}/native_cpp/audio_sink/include", ] - deps = [ - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxydaudionotify_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxydaudionotify_fuzzer/BUILD.gn index ba5c0d9b7894b96a170374c580af1da8c4dca304..7e62e86230b6c4c776018e08a387399522feda74 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxydaudionotify_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxydaudionotify_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkProxyDAudioNotifyFuzzTest") { @@ -46,9 +45,8 @@ ohos_fuzztest("SinkProxyDAudioNotifyFuzzTest") { "${innerkits_path}/native_cpp/audio_sink/include", ] - deps = [ - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/BUILD.gn index 0fabb6ba4c73890364978dd66fbb0a3fb26195e2..193da854e2580c95ba1a8f8576e97b3010052eb8 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkProxyInitSinkFuzzTest") { @@ -46,9 +45,8 @@ ohos_fuzztest("SinkProxyInitSinkFuzzTest") { "${innerkits_path}/native_cpp/audio_sink/include", ] - deps = [ - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn index 04558eb176c1b92b94a9d90c30112d2a9c643cf8..fe592476752409f8b5e0a8e86b556f12a58fe4f9 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkProxySubscribeLocalHardwareFuzzTest") { @@ -45,9 +44,8 @@ ohos_fuzztest("SinkProxySubscribeLocalHardwareFuzzTest") { "${innerkits_path}/native_cpp/audio_sink/include", ] - deps = [ - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn index 70d513f6e7feb2c0f9f10ed81dc6f107da4ec24c..81adb7ef6b06afc7085ead9a297c2db559ac3762 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkProxyUnsubscribeLocalHardwareFuzzTest") { @@ -45,9 +44,8 @@ ohos_fuzztest("SinkProxyUnsubscribeLocalHardwareFuzzTest") { "${innerkits_path}/native_cpp/audio_sink/include", ] - deps = [ - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] defines = [ "HI_LOG_ENABLE", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/BUILD.gn index 7c952ac625541f2fb99d20258aeeee3d58d6e3fe..f62c86372c4b8ed440b8640adcb90e4196f743d9 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceHandlerConfigDistributedHardwareFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerfinishstartsa_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerfinishstartsa_fuzzer/BUILD.gn index 414a2d1b48dffb1073c8fad9f77d07b92a0f9b79..a17da76350de39ec584e0cc3f3bfabc9e637899f 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerfinishstartsa_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerfinishstartsa_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceHandlerFinishStartSAFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/BUILD.gn index 4012d0fc2310e88cccef2e1a881af89af8345414..af8191b9c8a81a48185585fa6e30c47e6f453118 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceHandlerInitSourceFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn index 416fdaece0071af07a7322d193eb5bdd174bd465..5673ecb6791c288b157e168c40981a207d4a00ef 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceHandlerRegisterDistributedHardwareFuzzTest") { @@ -38,7 +37,6 @@ ohos_fuzztest("SourceHandlerRegisterDistributedHardwareFuzzTest") { "${fwk_common_path}/log/include", "${fwk_common_path}/utils/include", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", - ] include_dirs += [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn index 0fed9bff6d0320e3c2c06cb230b23185f6deb115..c216334db505a5b03b27fcfc75aadf520429d770 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceHandlerUnregisterDistributedHardwareFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyregresult_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyregresult_fuzzer/BUILD.gn index b349dce2eadcc04a0170ea67d6202cb9cd122323..db63745959d76dc5b1a997af69b0a35041b5bd5e 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyregresult_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyregresult_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceIpcCallbackOnNotifyRegResultFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyunregresult_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyunregresult_fuzzer/BUILD.gn index 57e3aeb824912300b32bbe7fe541ccb551c878b2..2725c60b629a471fc281f24395ed7a04f9f7b034 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyunregresult_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyunregresult_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceIpcCallbackOnNotifyUnregResultFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/BUILD.gn index 5ffc4759c251c9d3c0f9f3f4b68469cac2180989..53531f6f0caff288ec830cbba8b1aa52c8994534 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceOnLoadSystemAbilityFailFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/BUILD.gn index 33149bb76a82710d8cb0079bac542b5e15511c18..1df137cf937dbdb036422d459373e4d86c91fdd0 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceOnLoadSystemAbilitySuccessFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyconfigdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyconfigdistributedhardware_fuzzer/BUILD.gn index 2993f4c9c6c124908df57f43a96272477d072c83..06d00bc531e01273740ef560f03558c3973f0e40 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyconfigdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyconfigdistributedhardware_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceProxyConfigDistributedHardwareFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydaudionotify_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydaudionotify_fuzzer/BUILD.gn index f796b25a507a322453c45a5e92c37ef8086f89d8..d605aa8eabb1ce6f497cd8d4f89ffc477c88b29b 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydaudionotify_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydaudionotify_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceProxyDAudioNotifyFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/BUILD.gn index a77e390664bec4bb313e882dfd24cebef4a6ab09..e1ea532b21797e72466f9c31b4a2831e58e75f60 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceProxyInitSourceFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/BUILD.gn index 8f84f417f4966c8a3bfdf9e5f752034d4cd27f3e..2bbd43559fca08adfe11b19efb1cff7783b8b4e1 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceProxyRegisterDistributedHardwareFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/BUILD.gn index 403d4c0c056ee96a193b0c6c1ea6d1bb465b6475..a903e1bb3ddc99d0ab98a08f8197ab2b3c5fff1a 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/BUILD.gn @@ -14,8 +14,7 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceProxyUnregisterDistributedHardwareFuzzTest") { diff --git a/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn index e693f9dac1cf2775fefa5eb7367bca992163aa44..583e2b94397a68efc8b3777dad0b3c3f021db6d2 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn @@ -13,25 +13,24 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") group("unittest") { testonly = true deps = [ + "${distributedaudio_path}/audiohandler/test/unittest:audio_handler_test", + "${hdf_service_path}/hdi_service/audio/v1_0/test/unittest:hdi_service_audio_test", + "${hdf_service_path}/hdi_service/audio_ext/v1_0/test/unittest:hdi_service_audio_ext_test", "${interfaces_path}/inner_kits/native_cpp/test/unittest/audiosinktest:audio_sink_test", "${interfaces_path}/inner_kits/native_cpp/test/unittest/audiosourcetest:audio_source_test", - "${distributedaudio_path}/audiohandler/test/unittest:audio_handler_test", "${services_path}/audioclient/test/unittest:daudio_client_test", "${services_path}/audiocontrol/test/unittest:daudio_control_test", "${services_path}/audiohdiproxy/test/unittest:daudio_hdi_proxy_test", + "${services_path}/audiomanager/test/unittest:daudio_manager_test", "${services_path}/audioprocessor/test/unittest:daudio_processor_test", "${services_path}/audiotransport/test/unittest:daudio_transport_test", - "${services_path}/audiomanager/test/unittest:daudio_manager_test", - "${services_path}/softbusadapter/test/unittest:audio_soft_bus_adapter_test", "${services_path}/common/taskProcessor/test/unittest:task_processor_test", "${services_path}/hdfaudioclient/test/unittest:audio_adapter_hdi_test", - "${hdf_service_path}/hdi_service/audio/v1_0/test/unittest:hdi_service_audio_test", - "${hdf_service_path}/hdi_service/audio_ext/v1_0/test/unittest:hdi_service_audio_ext_test", + "${services_path}/softbusadapter/test/unittest:audio_soft_bus_adapter_test", ] } diff --git a/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/BUILD.gn index 47c6adf262479a37db66ce5ef5b8641ca2605e90..38c3bf0857cb9314ee1edf1a25a16f56ce45097d 100755 --- a/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") module_out_path = "distributed_audio/interfaces/audio_sink_test" @@ -41,8 +40,8 @@ ohos_unittest("AudioSinkTest") { sources = [ "${interfaces_path}/inner_kits/native_cpp/test/unittest/audiosinktest/src/daudio_sink_handler_test.cpp", - "${interfaces_path}/inner_kits/native_cpp/test/unittest/audiosinktest/src/daudio_sink_proxy_test.cpp" - ] + "${interfaces_path}/inner_kits/native_cpp/test/unittest/audiosinktest/src/daudio_sink_proxy_test.cpp", + ] configs = [ ":module_private_config" ] diff --git a/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/BUILD.gn index 8d112f655e1257811ef5c570585ed33d5e1d9a1f..1eb00aa9ee144bad97f2b5ae401d63f02e4a1c9a 100755 --- a/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") module_out_path = "distributed_audio/interfaces/audio_source_test" diff --git a/common/test_utils/aec_test.h b/services/audioclient/interface/imic_client.h similarity index 65% rename from common/test_utils/aec_test.h rename to services/audioclient/interface/imic_client.h index 383327ef66ec8f1698330705acf21d103adbc4f8..91feb930227447349f7e4c0f0cb1dca8cda4d075 100644 --- a/common/test_utils/aec_test.h +++ b/services/audioclient/interface/imic_client.h @@ -13,26 +13,25 @@ * limitations under the License. */ -#ifndef OHOS_AEC_TEST_H -#define OHOS_AEC_TEST_H +#ifndef OHOS_IMIC_CLIENT_H +#define OHOS_IMIC_CLIENT_H -#include "local_audio.h" +#include + +#include "audio_param.h" namespace OHOS { namespace DistributedHardware { -class AecTest { +class IMicClient { public: - AecTest() = default; - ~AecTest() = default; + IMicClient() = default; + virtual ~IMicClient() = default; - int32_t Init(); - int32_t Process(); - void Release(); -private: - AudioRenderObj render_; - AudioCaptureObj capture_; - AudioBufferInfo info_; + virtual int32_t SetUp(const AudioParam ¶m) = 0; + virtual int32_t Release() = 0; + virtual int32_t StartCapture() = 0; + virtual int32_t StopCapture() = 0; }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_AEC_TEST_H \ No newline at end of file +#endif // OHOS_IMIC_CLIENT_H diff --git a/common/test_utils/daudio_test_utils.h b/services/audioclient/interface/ispk_client.h similarity index 56% rename from common/test_utils/daudio_test_utils.h rename to services/audioclient/interface/ispk_client.h index 15d71f6a7ee327d092fa25ced5da22954540e32d..a6c03854068859dd2ae679704e144a7fd17bfaf2 100644 --- a/common/test_utils/daudio_test_utils.h +++ b/services/audioclient/interface/ispk_client.h @@ -13,30 +13,28 @@ * limitations under the License. */ -#ifndef OHOS_DAUDIO_TEST_UTILS_H -#define OHOS_DAUDIO_TEST_UTILS_H +#ifndef OHOS_ISPK_CLIENT_H +#define OHOS_ISPK_CLIENT_H + +#include + +#include "audio_param.h" -#include namespace OHOS { namespace DistributedHardware { -class DAudioTestUtils { +class ISpkClient { public: - DAudioTestUtils() = default; - ~DAudioTestUtils() = default; - void DoAudioTest(); + ISpkClient() = default; + virtual ~ISpkClient() = default; -private: - void LocalCapture(); - void LocalRender(); - void AudioCycleTest(); - void HDFCapture(); - void HDFRender(); - -private: - int32_t time_ = 0; - std::string path_; + virtual int32_t SetUp(const AudioParam ¶m) = 0; + virtual int32_t Release() = 0; + virtual int32_t StartRender() = 0; + virtual int32_t StopRender() = 0; + virtual int32_t SetMute(const AudioEvent &event) = 0; + virtual int32_t SetAudioParameters(const AudioEvent &event) = 0; + virtual void PlayStatusChange(const std::string &args) = 0; }; } // namespace DistributedHardware } // namespace OHOS - -#endif // OHOS_DAUDIO_TEST_UTILS_H \ No newline at end of file +#endif // OHOS_ISPK_CLIENT_H \ No newline at end of file diff --git a/services/audioclient/micclient/include/dmic_client.h b/services/audioclient/micclient/include/dmic_client.h index 9263220ca533a5bd06b77639767fdd669ee6f1bf..0e1313090ac682ab053509c42465db58f4f17695 100644 --- a/services/audioclient/micclient/include/dmic_client.h +++ b/services/audioclient/micclient/include/dmic_client.h @@ -37,20 +37,23 @@ #include "iaudio_data_transport.h" #include "iaudio_datatrans_callback.h" #include "iaudio_event_callback.h" +#include "imic_client.h" namespace OHOS { namespace DistributedHardware { -class DMicClient : public IAudioDataTransCallback, public std::enable_shared_from_this { +class DMicClient : public IAudioDataTransCallback, + public IMicClient, + public std::enable_shared_from_this { public: DMicClient(const std::string &devId, const std::shared_ptr &callback) : devId_(devId), eventCallback_(callback) {}; ~DMicClient() override; int32_t OnStateChange(const AudioEventType type) override; int32_t OnDecodeTransDataDone(const std::shared_ptr &audioData) override; - int32_t SetUp(const AudioParam ¶m); - int32_t Release(); - int32_t StartCapture(); - int32_t StopCapture(); + int32_t SetUp(const AudioParam ¶m) override; + int32_t Release() override; + int32_t StartCapture() override; + int32_t StopCapture() override; private: void CaptureThreadRunning(); diff --git a/services/audioclient/spkclient/include/dspeaker_client.h b/services/audioclient/spkclient/include/dspeaker_client.h index c5453a1e35909655021014a4435a07a3541c8984..bce42c9480b19098c317a404eab5fba863fd568a 100644 --- a/services/audioclient/spkclient/include/dspeaker_client.h +++ b/services/audioclient/spkclient/include/dspeaker_client.h @@ -39,10 +39,12 @@ #include "iaudio_data_transport.h" #include "iaudio_datatrans_callback.h" #include "iaudio_event_callback.h" +#include "ispk_client.h" namespace OHOS { namespace DistributedHardware { class DSpeakerClient : public IAudioDataTransCallback, + public ISpkClient, public AudioStandard::VolumeKeyEventCallback, public AudioStandard::AudioRendererCallback, public std::enable_shared_from_this { @@ -57,23 +59,27 @@ public: int32_t OnDecodeTransDataDone(const std::shared_ptr &audioData) override; void OnVolumeKeyEvent(AudioStandard::VolumeEvent volumeEvent) override; void OnInterrupt(const AudioStandard::InterruptEvent &interruptEvent) override; - int32_t SetUp(const AudioParam ¶m); - int32_t Release(); - int32_t StartRender(); - int32_t StopRender(); - int32_t SetMute(const AudioEvent &event); - int32_t SetAudioParameters(const AudioEvent &event); - std::string GetVolumeLevel(); - void PlayStatusChange(const std::string &args); + int32_t SetUp(const AudioParam ¶m) override; + int32_t Release() override; + int32_t StartRender() override; + int32_t StopRender() override; + int32_t SetMute(const AudioEvent &event) override; + int32_t SetAudioParameters(const AudioEvent &event) override; + void PlayStatusChange(const std::string &args) override; private: + std::string GetVolumeLevel(); void PlayThreadRunning(); void Pause(); void ReStart(); + void FillJitterQueue(); + void FlushJitterQueue(); private: - constexpr static size_t DATA_QUEUE_MAX_SIZE = 5; + constexpr static size_t DATA_QUEUE_MAX_SIZE = 12; constexpr static size_t REQUEST_DATA_WAIT = 10; + constexpr static size_t DATA_QUEUE_SIZE = 8; + constexpr static size_t SLEEP_TIME = 5000; static constexpr const char* RENDERTHREAD = "renderThread"; std::string devId_; diff --git a/services/audioclient/spkclient/src/dspeaker_client.cpp b/services/audioclient/spkclient/src/dspeaker_client.cpp index 1fecd9aff16d798e65408468c62efb78df4b8bdc..a0b630648962d6ea1fe55fa880956d857be92ed2 100644 --- a/services/audioclient/spkclient/src/dspeaker_client.cpp +++ b/services/audioclient/spkclient/src/dspeaker_client.cpp @@ -153,6 +153,8 @@ int32_t DSpeakerClient::StopRender() "daudio renderer is nullptr."); return ERR_DH_AUDIO_CLIENT_RENDER_OR_TRANS_IS_NULL; } + + FlushJitterQueue(); isRenderReady_.store(false); if (renderDataThread_.joinable()) { renderDataThread_.join(); @@ -174,6 +176,8 @@ void DSpeakerClient::PlayThreadRunning() if (pthread_setname_np(pthread_self(), RENDERTHREAD) != DH_SUCCESS) { DHLOGE("Render data thread setname failed."); } + + FillJitterQueue(); while (audioRenderer_ != nullptr && isRenderReady_.load()) { std::shared_ptr audioData = nullptr; { @@ -183,10 +187,11 @@ void DSpeakerClient::PlayThreadRunning() if (dataQueue_.empty()) { continue; } - audioData = dataQueue_.front(); dataQueue_.pop(); + DHLOGD("Pop spk data, dataqueue size: %d.", dataQueue_.size()); } + int32_t writeOffSet = 0; while (writeOffSet < static_cast(audioData->Capacity())) { int32_t writeLen = audioRenderer_->Write(audioData->Data() + writeOffSet, @@ -201,6 +206,32 @@ void DSpeakerClient::PlayThreadRunning() } } +void DSpeakerClient::FillJitterQueue() +{ + while (true) { + { + std::lock_guard lock(dataQueueMtx_); + if (dataQueue_.size() >= DATA_QUEUE_SIZE) { + break; + } + } + usleep(SLEEP_TIME); + } +} + +void DSpeakerClient::FlushJitterQueue() +{ + while (true) { + { + std::lock_guard lock(dataQueueMtx_); + if (dataQueue_.empty()) { + break; + } + } + usleep(SLEEP_TIME); + } +} + int32_t DSpeakerClient::OnDecodeTransDataDone(const std::shared_ptr &audioData) { DHLOGI("Write stream buffer."); @@ -394,6 +425,7 @@ int32_t DSpeakerClient::SetMute(const AudioEvent &event) void DSpeakerClient::Pause() { DHLOGI("Pause and flush"); + FlushJitterQueue(); isRenderReady_.store(false); if (renderDataThread_.joinable()) { renderDataThread_.join(); diff --git a/services/audioclient/test/unittest/BUILD.gn b/services/audioclient/test/unittest/BUILD.gn index ffc0b7019c6f0253bb69b442c9f1b2f5f0dc9b7b..9f6d80d59a9b1f8db20bbd4799a0dae7b95c2fd2 100644 --- a/services/audioclient/test/unittest/BUILD.gn +++ b/services/audioclient/test/unittest/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") group("daudio_client_test") { testonly = true diff --git a/services/audioclient/test/unittest/micclient/BUILD.gn b/services/audioclient/test/unittest/micclient/BUILD.gn index 78f700d3a66197a0f9e64bb1b99855b97134f429..77246db6710fc4d723ac0974a8bcc6847e05945f 100644 --- a/services/audioclient/test/unittest/micclient/BUILD.gn +++ b/services/audioclient/test/unittest/micclient/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audioclient/mic_client_test" @@ -29,6 +28,7 @@ config("module_private_config") { ] include_dirs += [ + "${audio_client_path}/interface", "${audio_client_path}/micclient/include", "${audio_client_path}/test/unittest/micclient/include", "${audio_client_path}/test/unittest/audioclienttestutils/include", diff --git a/services/audioclient/test/unittest/micclient/src/dmic_client_test.cpp b/services/audioclient/test/unittest/micclient/src/dmic_client_test.cpp index e32369abad365889028e3183e7149018214eef82..410e4f0a95c094ae0bd7e02477cb54323ce52783 100644 --- a/services/audioclient/test/unittest/micclient/src/dmic_client_test.cpp +++ b/services/audioclient/test/unittest/micclient/src/dmic_client_test.cpp @@ -87,6 +87,7 @@ HWTEST_F(DMicClientTest, SetUp_001, TestSize.Level1) */ HWTEST_F(DMicClientTest, StartCapture001, TestSize.Level1) { + micClient_->CaptureThreadRunning(); EXPECT_NE(DH_SUCCESS, micClient_->StartCapture()); EXPECT_NE(DH_SUCCESS, micClient_->StopCapture()); } @@ -101,6 +102,8 @@ HWTEST_F(DMicClientTest, StopCapture001, TestSize.Level1) { std::shared_ptr audioData = nullptr; EXPECT_NE(DH_SUCCESS, micClient_->StopCapture()); + micClient_->clientStatus_ = STATUS_START; + EXPECT_NE(DH_SUCCESS, micClient_->StopCapture()); EXPECT_EQ(DH_SUCCESS, micClient_->OnDecodeTransDataDone(audioData)); } } // DistributedHardware diff --git a/services/audioclient/test/unittest/spkclient/BUILD.gn b/services/audioclient/test/unittest/spkclient/BUILD.gn index f54951ea054e4727b30e1ecdc65991829e3cae2f..118cd99b0487622efa8b658da99c9aaf2d584342 100644 --- a/services/audioclient/test/unittest/spkclient/BUILD.gn +++ b/services/audioclient/test/unittest/spkclient/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audioclient/spk_client_test" @@ -33,6 +32,7 @@ config("module_private_config") { ] include_dirs += [ + "${audio_client_path}/interface", "${audio_client_path}/spkclient/include", "${audio_client_path}/test/unittest/spkclient/include", "${audio_client_path}/test/unittest/audioclienttestutils/include", diff --git a/services/audioclient/test/unittest/spkclient/src/dspeaker_client_test.cpp b/services/audioclient/test/unittest/spkclient/src/dspeaker_client_test.cpp index 943e0e29f2a06918fc4f5f0b0f9fcfa4070871f2..9b71312ec89bc9dcaf074e56bed741f6cb559062 100644 --- a/services/audioclient/test/unittest/spkclient/src/dspeaker_client_test.cpp +++ b/services/audioclient/test/unittest/spkclient/src/dspeaker_client_test.cpp @@ -88,6 +88,9 @@ HWTEST_F(DSpeakerClientTest, StartRender001, TestSize.Level1) { EXPECT_NE(DH_SUCCESS, speakerClient_->StartRender()); EXPECT_NE(DH_SUCCESS, speakerClient_->StopRender()); + + speakerClient_->clientStatus_ = STATUS_START; + EXPECT_EQ(ERR_DH_AUDIO_SA_STATUS_ERR, speakerClient_->StopRender()); } /** @@ -104,7 +107,10 @@ HWTEST_F(DSpeakerClientTest, StopRender001, TestSize.Level1) speakerClient_->PlayStatusChange(args); speakerClient_->SetAudioParameters(event); speakerClient_->SetMute(event); - + for (size_t i =0; i<10; i++) { + std::shared_ptr data = std::make_shared(4096); + speakerClient_->dataQueue_.push(data); + } args = "restart"; speakerClient_->PlayStatusChange(args); @@ -127,12 +133,24 @@ HWTEST_F(DSpeakerClientTest, OnDecodeTransDataDone001, TestSize.Level1) { std::shared_ptr audioData = nullptr; EXPECT_EQ(ERR_DH_AUDIO_CLIENT_PARAM_IS_NULL, speakerClient_->OnDecodeTransDataDone(audioData)); - for (size_t i = 0; i < 6; i++) { + for (size_t i = 0; i < 10; i++) { std::shared_ptr data = std::make_shared(4096); speakerClient_->dataQueue_.push(data); } audioData = std::make_shared(4096); EXPECT_EQ(DH_SUCCESS, speakerClient_->OnDecodeTransDataDone(audioData)); } + +/** + * @tc.name: Release_001 + * @tc.desc: Verify the Release function. + * @tc.type: FUNC + * @tc.require: AR000H0E6G + */ +HWTEST_F(DSpeakerClientTest, Release001, TestSize.Level1) +{ + speakerClient_->Pause(); + EXPECT_EQ(ERR_DH_AUDIO_SA_STATUS_ERR, speakerClient_->Release()); +} } // DistributedHardware } // OHOS diff --git a/services/audiocontrol/test/unittest/BUILD.gn b/services/audiocontrol/test/unittest/BUILD.gn index c1f65be0d29fca8f4473f53935465df226470d51..b71dc28762cf8d80e452b719e5ecb27dcb073ab3 100644 --- a/services/audiocontrol/test/unittest/BUILD.gn +++ b/services/audiocontrol/test/unittest/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") group("daudio_control_test") { testonly = true diff --git a/services/audiocontrol/test/unittest/controlsink/BUILD.gn b/services/audiocontrol/test/unittest/controlsink/BUILD.gn index 4a521952727c37427865d80d2a64d7f3791f1d04..c4a29abbaad302bb431aecb8d8abbb15236ff1e7 100644 --- a/services/audiocontrol/test/unittest/controlsink/BUILD.gn +++ b/services/audiocontrol/test/unittest/controlsink/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audiocontrol/control_sink_test" diff --git a/services/audiocontrol/test/unittest/controlsource/BUILD.gn b/services/audiocontrol/test/unittest/controlsource/BUILD.gn index f9142d4d31adf3cef281e1657efa0c5f95a1d30f..ca355a23cfcc6e37c7fcacc21df174ab101a62fd 100644 --- a/services/audiocontrol/test/unittest/controlsource/BUILD.gn +++ b/services/audiocontrol/test/unittest/controlsource/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audiocontrol/control_source_test" @@ -55,9 +54,12 @@ ohos_unittest("ControlSourceTest") { "${services_path}/audiomanager/servicesource:distributed_audio_source", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", - "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", - "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", - "//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken", + ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", ] } diff --git a/services/audiohdiproxy/include/daudio_manager_callback.h b/services/audiohdiproxy/include/daudio_manager_callback.h index 7b7e0dbe176ca4f5b27988e37ac0d10f4020d877..4962b3dab82ba1f7c2d084d354113384016c6dfe 100644 --- a/services/audiohdiproxy/include/daudio_manager_callback.h +++ b/services/audiohdiproxy/include/daudio_manager_callback.h @@ -44,8 +44,8 @@ public: int32_t ReadStreamData(const std::string &adpName, int32_t devId, OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioData &data) override; - int32_t ReadMmapPosition(const std::string &adpName, int32_t devId, - uint64_t &frames, uint64_t &timeStamp) override; + int32_t ReadMmapPosition(const std::string &adpName, int32_t devId, uint64_t &frames, + OHOS::HDI::DistributedAudio::Audioext::V1_0::CurrentTime &time) override; int32_t RefreshAshmemInfo(const std::string &adpName, int32_t devId, int fd, int32_t ashmemLength, int32_t lengthPerTrans) override; diff --git a/services/audiohdiproxy/include/idaudio_hdi_callback.h b/services/audiohdiproxy/include/idaudio_hdi_callback.h index 804702ff14b2112a77222ec904023185912ab8c5..2c7a70f891dab1a431bfc769ca74caa162c13262 100644 --- a/services/audiohdiproxy/include/idaudio_hdi_callback.h +++ b/services/audiohdiproxy/include/idaudio_hdi_callback.h @@ -26,23 +26,17 @@ class IDAudioHdiCallback { public: virtual ~IDAudioHdiCallback() = default; - virtual int32_t OpenDevice(const std::string& devId, const int32_t dhId) = 0; + virtual int32_t OpenDevice(const std::string &devId, const int32_t dhId) = 0; - virtual int32_t CloseDevice(const std::string& devId, const int32_t dhId) = 0; + virtual int32_t CloseDevice(const std::string &devId, const int32_t dhId) = 0; - virtual int32_t SetParameters(const std::string& devId, const int32_t dhId, const AudioParamHDF& param) = 0; + virtual int32_t SetParameters(const std::string &devId, const int32_t dhId, const AudioParamHDF& param) = 0; - virtual int32_t NotifyEvent(const std::string& devId, const int32_t dhId, const AudioEvent& event) = 0; + virtual int32_t NotifyEvent(const std::string &devId, const int32_t dhId, const AudioEvent& event) = 0; - virtual int32_t WriteStreamData(const std::string& devId, const int32_t dhId, std::shared_ptr &data) = 0; + virtual int32_t WriteStreamData(const std::string &devId, const int32_t dhId, std::shared_ptr &data) = 0; - virtual int32_t ReadStreamData(const std::string& devId, const int32_t dhId, std::shared_ptr &data) = 0; - - virtual int32_t ReadMmapPosition(const std::string &devId, const int32_t dhId, - uint64_t &frames, uint64_t &timeStamp) = 0; - - virtual int32_t RefreshAshmemInfo(const std::string &devId, const int32_t dhId, - int32_t fd, int32_t ashmemLength, int32_t lengthPerTrans) = 0; + virtual int32_t ReadStreamData(const std::string &devId, const int32_t dhId, std::shared_ptr &data) = 0; }; } // DistributedHardware } // OHOS diff --git a/services/audiohdiproxy/src/daudio_manager_callback.cpp b/services/audiohdiproxy/src/daudio_manager_callback.cpp index 5764966a39fd7af140e0575b85ca566b0dc26a29..17860e1178968b54ba39c6829d46526dc2fff7ed 100644 --- a/services/audiohdiproxy/src/daudio_manager_callback.cpp +++ b/services/audiohdiproxy/src/daudio_manager_callback.cpp @@ -100,8 +100,8 @@ int32_t DAudioManagerCallback::GetAudioParamHDF(const AudioParameter& param, Aud paramHDF.frameSize = param.frameSize; paramHDF.period = param.period; paramHDF.ext = param.ext; - paramHDF.renderFlags = param.renderFlags; - paramHDF.capturerFlags = param.capturerFlags; + paramHDF.renderFlags = static_cast(param.renderFlags); + paramHDF.capturerFlags = static_cast(param.capturerFlags); DHLOGI("HDF Param: sample rate %d, channel %d, bit format %d, stream usage %d, frame size %zu, " + "period %zu, renderFlags %d, capturerFlags %d, ext {%s}.", paramHDF.sampleRate, paramHDF.channelMask, paramHDF.bitFormat, paramHDF.streamUsage, paramHDF.frameSize, paramHDF.period, paramHDF.renderFlags, @@ -150,18 +150,6 @@ int32_t DAudioManagerCallback::NotifyEvent(const std::string& adpName, int32_t d case AudioEventHDF::AUDIO_EVENT_CHANGE_PLAY_STATUS: newEvent.type = AudioEventType::CHANGE_PLAY_STATUS; break; - case AudioEventHDF::AUDIO_EVENT_MMAP_START: - newEvent.type = AudioEventType::MMAP_START; - break; - case AudioEventHDF::AUDIO_EVENT_MMAP_STOP: - newEvent.type = AudioEventType::MMAP_STOP; - break; - case AudioEventHDF::AUDIO_EVENT_MIC_MMAP_START: - newEvent.type = AudioEventType::MMAP_START_MIC; - break; - case AudioEventHDF::AUDIO_EVENT_MIC_MMAP_STOP: - newEvent.type = AudioEventType::MMAP_STOP_MIC; - break; case AudioEventHDF::AUDIO_EVENT_START: newEvent.type = AudioEventType::AUDIO_START; break; @@ -233,38 +221,23 @@ int32_t DAudioManagerCallback::ReadStreamData(const std::string &adpName, int32_ } int32_t DAudioManagerCallback::ReadMmapPosition(const std::string &adpName, int32_t devId, - uint64_t &frames, uint64_t &timeStamp) + uint64_t &frames, OHOS::HDI::DistributedAudio::Audioext::V1_0::CurrentTime &time) { - DHLOGI("Read mmap position."); - if (callback_ == nullptr) { - DHLOGE("Register hdi callback is nullptr."); - return HDF_FAILURE; - } - - int32_t ret = callback_->ReadMmapPosition(adpName, devId, frames, timeStamp); - if (ret != DH_SUCCESS) { - DHLOGE("Read mmap postion failed."); - return HDF_FAILURE; - } - DHLOGI("Read mmap position success."); + (void) adpName; + (void) devId; + (void) frames; + (void) time; return HDF_SUCCESS; } int32_t DAudioManagerCallback::RefreshAshmemInfo(const std::string &adpName, int32_t devId, int fd, int32_t ashmemLength, int32_t lengthPerTrans) { - DHLOGI("Refresh ashmem info."); - if (callback_ == nullptr) { - DHLOGE("Register hdi callback is nullptr."); - return HDF_FAILURE; - } - - int32_t ret = callback_->RefreshAshmemInfo(adpName, devId, fd, ashmemLength, lengthPerTrans); - if (ret != DH_SUCCESS) { - DHLOGE("RefreshAshmemInfo failed."); - return HDF_FAILURE; - } - DHLOGI("RefreshAshmemInfo success."); + (void) adpName; + (void) devId; + (void) fd; + (void) ashmemLength; + (void) lengthPerTrans; return HDF_SUCCESS; } } // DistributedHardware diff --git a/services/audiohdiproxy/test/unittest/BUILD.gn b/services/audiohdiproxy/test/unittest/BUILD.gn index 43fb1972a06c80b214af7988740d6327d4678e94..a9ba7026168ee44f12836651431c9c2ff93ca044 100644 --- a/services/audiohdiproxy/test/unittest/BUILD.gn +++ b/services/audiohdiproxy/test/unittest/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") group("daudio_hdi_proxy_test") { testonly = true diff --git a/services/audiohdiproxy/test/unittest/daudio_hdi_handler/BUILD.gn b/services/audiohdiproxy/test/unittest/daudio_hdi_handler/BUILD.gn index 176e65f600ba25e24b212f6107153ba8f513bccf..3843e266905ad4f942204ccaeac593226d10fe7d 100644 --- a/services/audiohdiproxy/test/unittest/daudio_hdi_handler/BUILD.gn +++ b/services/audiohdiproxy/test/unittest/daudio_hdi_handler/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audiohdiproxy/daudio_hdi_handler" @@ -50,9 +49,7 @@ ohos_unittest("DAudioHdiHandlerTest") { "//third_party/googletest:gtest_main", ] - external_deps = [ - "c_utils:utils", - ] + external_deps = [ "c_utils:utils" ] } group("daudio_hdi_handler_test") { diff --git a/services/audiohdiproxy/test/unittest/daudio_hdi_handler/include/audio_test_utils.h b/services/audiohdiproxy/test/unittest/daudio_hdi_handler/include/audio_test_utils.h index c804ed9c023edf5b7a5204827a52a34c9fb913d3..333761fcad96574e61465f3d77891d8521571f0d 100644 --- a/services/audiohdiproxy/test/unittest/daudio_hdi_handler/include/audio_test_utils.h +++ b/services/audiohdiproxy/test/unittest/daudio_hdi_handler/include/audio_test_utils.h @@ -84,18 +84,6 @@ public: { return DH_SUCCESS; } - - int32_t ReadMmapPosition(const std::string &devId, const int32_t dhId, - uint64_t &frames, uint64_t &timeStamp) override - { - return DH_SUCCESS; - } - - virtual int32_t RefreshAshmemInfo(const std::string &devId, const int32_t dhId, - int32_t fd, int32_t ashmemLength, int32_t lengthPerTrans) override - { - return DH_SUCCESS; - } }; } // DistributedHardware } // OHOS diff --git a/services/audiohdiproxy/test/unittest/daudio_manager_callback/BUILD.gn b/services/audiohdiproxy/test/unittest/daudio_manager_callback/BUILD.gn index ca683f5ad31851200c6d23e42c284e548811ba4b..d0f72d8224ca8fca12c1a0a05a2434faea8472dd 100644 --- a/services/audiohdiproxy/test/unittest/daudio_manager_callback/BUILD.gn +++ b/services/audiohdiproxy/test/unittest/daudio_manager_callback/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audiohdiproxy/daudio_manager_callback" @@ -55,9 +54,7 @@ ohos_unittest("DAudioManagerCallbackTest") { "//third_party/googletest:gtest_main", ] - external_deps = [ - "c_utils:utils", - ] + external_deps = [ "c_utils:utils" ] } group("daudio_manager_callback_test") { diff --git a/services/audiohdiproxy/test/unittest/daudio_manager_callback/include/audio_test_utils.h b/services/audiohdiproxy/test/unittest/daudio_manager_callback/include/audio_test_utils.h index 7134ef9bfe104f62510302d9c62d30823b3a6220..c772cbb7527f78217830db34a42b27bd23a0c401 100644 --- a/services/audiohdiproxy/test/unittest/daudio_manager_callback/include/audio_test_utils.h +++ b/services/audiohdiproxy/test/unittest/daudio_manager_callback/include/audio_test_utils.h @@ -57,18 +57,6 @@ public: data = std::make_shared(DEFAULT_AUDIO_DATA_SIZE); return DH_SUCCESS; } - - int32_t ReadMmapPosition(const std::string &devId, const int32_t dhId, - uint64_t &frames, uint64_t &timeStamp) override - { - return DH_SUCCESS; - } - - virtual int32_t RefreshAshmemInfo(const std::string &devId, const int32_t dhId, - int32_t fd, int32_t ashmemLength, int32_t lengthPerTrans) override - { - return DH_SUCCESS; - } }; } // DistributedHardware } // OHOS diff --git a/services/audiomanager/managersink/include/daudio_sink_dev.h b/services/audiomanager/managersink/include/daudio_sink_dev.h index b664d817b92c9627a6f33966f517b6f9ac4cfedb..282f2b37d312fa7ad76feb968a184cafea963fc7 100644 --- a/services/audiomanager/managersink/include/daudio_sink_dev.h +++ b/services/audiomanager/managersink/include/daudio_sink_dev.h @@ -26,6 +26,8 @@ #include "dmic_client.h" #include "dspeaker_client.h" #include "task_queue.h" +#include "imic_client.h" +#include "ispk_client.h" #include "iaudio_event_callback.h" using json = nlohmann::json; @@ -88,8 +90,8 @@ private: std::string spkDhId_; std::string micDhId_; std::shared_ptr taskQueue_ = nullptr; - std::shared_ptr speakerClient_ = nullptr; - std::shared_ptr micClient_ = nullptr; + std::shared_ptr speakerClient_ = nullptr; + std::shared_ptr micClient_ = nullptr; std::shared_ptr audioCtrlMgr_ = nullptr; using DAudioSinkDevFunc = int32_t (DAudioSinkDev::*)(const AudioEvent &audioEvent); diff --git a/services/audiomanager/managersink/src/daudio_sink_dev.cpp b/services/audiomanager/managersink/src/daudio_sink_dev.cpp index 44e91e57e188c782bb2816f076a66ec2011a5aae..294b550e804a395f27ba32bcd425c60ba4d2f032 100644 --- a/services/audiomanager/managersink/src/daudio_sink_dev.cpp +++ b/services/audiomanager/managersink/src/daudio_sink_dev.cpp @@ -15,6 +15,8 @@ #include "daudio_sink_dev.h" +#include + #include "daudio_constants.h" #include "daudio_errorcode.h" #include "daudio_log.h" @@ -388,8 +390,10 @@ int32_t DAudioSinkDev::TaskOpenDSpeaker(const std::string &args) return ret; } - if (audioParam.renderOpts.renderFlags == 1) { - DHLOGI("dsink dev low-latency mode"); + if (speakerClient_ == nullptr) { + if (audioParam.renderOpts.renderFlags == NORMAL_MODE) { + speakerClient_ = std::make_shared(devId_, shared_from_this()); + } } if (speakerClient_ == nullptr) { @@ -456,7 +460,9 @@ int32_t DAudioSinkDev::TaskOpenDMic(const std::string &args) do { if (micClient_ == nullptr) { - micClient_ = std::make_shared(devId_, shared_from_this()); + if (audioParam.captureOpts.capturerFlags == NORMAL_MODE) { + micClient_ = std::make_shared(devId_, shared_from_this()); + } } ret = micClient_->SetUp(audioParam); if (ret != DH_SUCCESS) { @@ -600,10 +606,15 @@ void DAudioSinkDev::OnTaskResult(int32_t resultCode, const std::string &result, void DAudioSinkDev::NotifySourceDev(const AudioEventType type, const std::string dhId, const int32_t result) { + std::random_device rd; + const uint32_t randomTaskCode = rd(); json jEvent; jEvent[KEY_DH_ID] = dhId; jEvent[KEY_RESULT] = result; jEvent[KEY_EVENT_TYPE] = type; + jEvent[KEY_RANDOM_TASK_CODE] = std::to_string(randomTaskCode); + + DHLOGI("notify source dev, random task code: %d", randomTaskCode); DAudioSinkManager::GetInstance().DAudioNotify(devId_, dhId, type, jEvent.dump()); } diff --git a/services/audiomanager/managersink/src/daudio_sink_manager.cpp b/services/audiomanager/managersink/src/daudio_sink_manager.cpp index 242acd8182873e3e881b92fb8a2f86821fc12475..1c50d32a326fdfa2402aaf08fc233db49e19e645 100644 --- a/services/audiomanager/managersink/src/daudio_sink_manager.cpp +++ b/services/audiomanager/managersink/src/daudio_sink_manager.cpp @@ -91,6 +91,17 @@ int32_t DAudioSinkManager::HandleDAudioNotify(const std::string &devId, const st const int32_t eventType, const std::string &eventContent) { DHLOGI("Receive audio event from devId: %s, event type: %d.", GetAnonyString(devId).c_str(), eventType); + + if (eventContent.length() > DAUDIO_MAX_JSON_LEN || eventContent.empty()) { + return ERR_DH_AUDIO_FAILED; + } + + json jParam = json::parse(eventContent, nullptr, false); + if (JsonParamCheck(jParam, { KEY_RANDOM_TASK_CODE }) && CheckIsNum((std::string)jParam[KEY_RANDOM_TASK_CODE])) { + int32_t randomCode = std::stoi((std::string)jParam[KEY_RANDOM_TASK_CODE]); + DHLOGI("Receive audio notify from source, random task code: %d", randomCode); + } + std::lock_guard lock(devMapMutex_); auto iter = audioDevMap_.find(devId); if (iter == audioDevMap_.end() && CreateAudioDevice(devId) != DH_SUCCESS) { diff --git a/services/audiomanager/managersource/include/daudio_source_dev.h b/services/audiomanager/managersource/include/daudio_source_dev.h index 4d3304f383f527a466b08f3517b78e128f27829d..d4258335c90a477faa4d001b9f4f0d6eaeb9254c 100644 --- a/services/audiomanager/managersource/include/daudio_source_dev.h +++ b/services/audiomanager/managersource/include/daudio_source_dev.h @@ -89,10 +89,6 @@ private: int32_t HandleFocusChange(const AudioEvent &event); int32_t HandleRenderStateChange(const AudioEvent &event); int32_t HandlePlayStatusChange(const AudioEvent &event); - int32_t HandleMmapStart(const AudioEvent &event); - int32_t HandleMmapStop(const AudioEvent &event); - int32_t HandleMicMmapStart(const AudioEvent &event); - int32_t HandleMicMmapStop(const AudioEvent &event); int32_t NotifySinkDev(const AudioEventType type, const json Param, const std::string dhId); int32_t NotifyHDF(const AudioEventType type, const std::string result); @@ -100,7 +96,6 @@ private: int32_t CloseCtrlTrans(const AudioEvent &event, bool isSpk); AudioEventType getEventTypeFromArgs(const std::string &args); void to_json(json &j, const AudioParam ¶m); - bool CheckIsNum(const std::string &jsonString); private: static constexpr uint8_t RPC_WAIT_SECONDS = 2; @@ -111,7 +106,6 @@ private: static constexpr uint8_t EVENT_NOTIFY_CLOSE_MIC = 0x08; static constexpr uint8_t EVENT_NOTIFY_OPEN_CTRL = 0x10; static constexpr uint8_t EVENT_NOTIFY_CLOSE_CTRL = 0x20; - static constexpr uint8_t MAX_KEY_DH_ID_LEN = 10; std::string devId_; std::shared_ptr mgrCallback_; diff --git a/services/audiomanager/managersource/include/dmic_dev.h b/services/audiomanager/managersource/include/dmic_dev.h index 516f1ad2aa35938de4faff5a4ee4941d78cd8a32..22c9ee0490ff20a34bd37c6207ea43c794b410e3 100644 --- a/services/audiomanager/managersource/include/dmic_dev.h +++ b/services/audiomanager/managersource/include/dmic_dev.h @@ -18,12 +18,10 @@ #include #include -#include #include "nlohmann/json.hpp" #include "audio_param.h" #include "audio_status.h" -#include "ashmem.h" #include "daudio_hdi_handler.h" #include "iaudio_datatrans_callback.h" #include "iaudio_data_transport.h" @@ -51,12 +49,6 @@ public: int32_t WriteStreamData(const std::string &devId, const int32_t dhId, std::shared_ptr &data) override; int32_t ReadStreamData(const std::string &devId, const int32_t dhId, std::shared_ptr &data) override; int32_t NotifyEvent(const std::string &devId, const int32_t dhId, const AudioEvent &event) override; - int32_t ReadMmapPosition(const std::string &devId, const int32_t dhId, - uint64_t &frames, uint64_t &timeStamp) override; - int32_t RefreshAshmemInfo(const std::string &devId, const int32_t dhId, - int32_t fd, int32_t ashmemLength, int32_t lengthPerTrans) override; - int32_t MmapStart(); - int32_t MmapStop(); int32_t SetUp(); int32_t Start(); @@ -72,21 +64,19 @@ public: private: int32_t EnableDevice(const int32_t dhId, const std::string &capability); int32_t DisableDevice(const int32_t dhId); - void EnqueueThread(); private: static constexpr uint8_t CHANNEL_WAIT_SECONDS = 5; static constexpr size_t DATA_QUEUE_MAX_SIZE = 10; static constexpr size_t DATA_QUEUE_HALF_SIZE = DATA_QUEUE_MAX_SIZE >> 1U; - static constexpr int64_t periodNanoSec_ = 5000000; - static constexpr int32_t CAPTURE_MMAP_FLAG = 1; + static constexpr size_t LOW_LATENCY_DATA_QUEUE_MAX_SIZE = 40; + static constexpr size_t LOW_LATENCY_DATA_QUEUE_HALF_SIZE = LOW_LATENCY_DATA_QUEUE_MAX_SIZE >> 1U; static constexpr const char* ENQUEUE_THREAD = "micEnqueueTh"; std::string devId_; std::weak_ptr audioEventCallback_; std::mutex dataQueueMtx_; std::mutex channelWaitMutex_; - std::mutex writeAshmemtMutex_; std::condition_variable channelWaitCond_; int32_t curPort_ = 0; std::atomic isTransReady_ = false; @@ -99,15 +89,6 @@ private: // Mic capture parameters AudioParamHDF paramHDF_; AudioParam param_; - - // Ashmem - sptr ashmem_ = nullptr; - std::atomic isEnqueueRunning_ = false; - int32_t writeIndex_ = -1; - int32_t ashmemLength_ = -1; - int32_t lengthPerTrans_ = -1; - std::thread enqueueDataThread_; - std::condition_variable dataQueueCond_; }; } // DistributedHardware } // OHOS diff --git a/services/audiomanager/managersource/include/dspeaker_dev.h b/services/audiomanager/managersource/include/dspeaker_dev.h index 75e447cdcbd69382e49ebf7288c94fcb74049b65..d5ced91bd4a25b5237659d9d1a1f5b060ae768a3 100644 --- a/services/audiomanager/managersource/include/dspeaker_dev.h +++ b/services/audiomanager/managersource/include/dspeaker_dev.h @@ -50,12 +50,6 @@ public: int32_t WriteStreamData(const std::string &devId, const int32_t dhId, std::shared_ptr &data) override; int32_t ReadStreamData(const std::string &devId, const int32_t dhId, std::shared_ptr &data) override; int32_t NotifyEvent(const std::string &devId, const int32_t dhId, const AudioEvent &event) override; - int32_t ReadMmapPosition(const std::string &devId, const int32_t dhId, - uint64_t &frames, uint64_t &timeStamp) override; - int32_t RefreshAshmemInfo(const std::string &devId, const int32_t dhId, - int32_t fd, int32_t ashmemLength, int32_t lengthPerTrans) override; - int32_t MmapStart(); - int32_t MmapStop(); int32_t OnStateChange(const AudioEventType type) override; int32_t OnDecodeTransDataDone(const std::shared_ptr &audioData) override; @@ -74,7 +68,6 @@ public: private: int32_t EnableDevice(const int32_t dhId, const std::string &capability); int32_t DisableDevice(const int32_t dhId); - void EnqueueThread(); private: static constexpr const char* ENQUEUE_THREAD = "spkEnqueueTh"; @@ -92,19 +85,6 @@ private: // Speaker render parameters AudioParamHDF paramHDF_; AudioParam param_; - - // mmap parameters - uint32_t timeInterval_ = 5; - uint32_t readStartDelayms_ = 2000; - int64_t periodNanoSec_ = 5000000; - sptr ashmem_ = nullptr; - int32_t ashmemLength_ = -1; - int32_t lengthPerTrans_ = -1; - std::atomic isEnqueueRunning_ = false; - uint64_t readNum_ = 0; - int32_t readIndex_ = 0; - uint64_t readTimeStamp_ = 0; - std::thread enqueueDataThread_; }; } // DistributedHardware } // OHOS diff --git a/services/audiomanager/managersource/src/daudio_source_dev.cpp b/services/audiomanager/managersource/src/daudio_source_dev.cpp index 319fd498d06a42039e1876604446c37fe4cc23e5..47397aa92fe6c9563543d451a84ebbed976bfcc0 100644 --- a/services/audiomanager/managersource/src/daudio_source_dev.cpp +++ b/services/audiomanager/managersource/src/daudio_source_dev.cpp @@ -15,6 +15,8 @@ #include "daudio_source_dev.h" +#include + #include "daudio_constants.h" #include "daudio_errorcode.h" #include "daudio_hitrace.h" @@ -52,10 +54,6 @@ DAudioSourceDev::DAudioSourceDev(const std::string &devId, const std::shared_ptr memberFuncMap_[AUDIO_FOCUS_CHANGE] = &DAudioSourceDev::HandleFocusChange; memberFuncMap_[AUDIO_RENDER_STATE_CHANGE] = &DAudioSourceDev::HandleRenderStateChange; memberFuncMap_[CHANGE_PLAY_STATUS] = &DAudioSourceDev::HandlePlayStatusChange; - memberFuncMap_[MMAP_START] = &DAudioSourceDev::HandleMmapStart; - memberFuncMap_[MMAP_STOP] = &DAudioSourceDev::HandleMmapStop; - memberFuncMap_[MMAP_START_MIC] = &DAudioSourceDev::HandleMicMmapStart; - memberFuncMap_[MMAP_STOP_MIC] = &DAudioSourceDev::HandleMicMmapStop; eventNotifyMap_[NOTIFY_OPEN_SPEAKER_RESULT] = EVENT_NOTIFY_OPEN_SPK; eventNotifyMap_[NOTIFY_CLOSE_SPEAKER_RESULT] = EVENT_NOTIFY_CLOSE_SPK; @@ -392,54 +390,6 @@ int32_t DAudioSourceDev::HandlePlayStatusChange(const AudioEvent &event) } } -int32_t DAudioSourceDev::HandleMmapStart(const AudioEvent &event) -{ - DHLOGI("Mmap start, content: %s.", event.content.c_str()); - if (speaker_ == nullptr) { - DHLOGE("Mmap start, speaker is nullptr."); - return ERR_DH_AUDIO_NULLPTR; - } - speaker_->MmapStart(); - return DH_SUCCESS; -} - -int32_t DAudioSourceDev::HandleMmapStop(const AudioEvent &event) -{ - DHLOGI("Mmap stop, content: %s.", event.content.c_str()); - if (speaker_ == nullptr) { - DHLOGE("Mmap stop, speaker is nullptr."); - return ERR_DH_AUDIO_NULLPTR; - } - speaker_->MmapStop(); - return DH_SUCCESS; -} - -int32_t DAudioSourceDev::HandleMicMmapStart(const AudioEvent &event) -{ - DHLOGI("Mmap start, content: %s.", event.content.c_str()); - if (mic_ == nullptr) { - DHLOGE("Mmap start, mic is nullptr."); - return ERR_DH_AUDIO_NULLPTR; - } - if (mic_->MmapStart() != DH_SUCCESS) { - return ERR_DH_AUDIO_FAILED; - } - return DH_SUCCESS; -} - -int32_t DAudioSourceDev::HandleMicMmapStop(const AudioEvent &event) -{ - DHLOGI("Mmap stop, content: %s.", event.content.c_str()); - if (mic_ == nullptr) { - DHLOGE("Mmap stop, mic is nullptr."); - return ERR_DH_AUDIO_NULLPTR; - } - if (mic_->MmapStop() != DH_SUCCESS) { - return ERR_DH_AUDIO_FAILED; - } - return DH_SUCCESS; -} - int32_t DAudioSourceDev::WaitForRPC(const AudioEventType type) { std::unique_lock lck(rpcWaitMutex_); @@ -867,10 +817,14 @@ void DAudioSourceDev::OnTaskResult(int32_t resultCode, const std::string &result int32_t DAudioSourceDev::NotifySinkDev(const AudioEventType type, const json Param, const std::string dhId) { + std::random_device rd; + const uint32_t randomTaskCode = rd(); constexpr uint32_t eventOffset = 4; json jParam = { { KEY_DH_ID, dhId }, { KEY_EVENT_TYPE, type }, - { KEY_AUDIO_PARAM, Param } }; + { KEY_AUDIO_PARAM, Param }, + { KEY_RANDOM_TASK_CODE, std::to_string(randomTaskCode) } }; + DHLOGI("Notify sin dev, random task code: %d", randomTaskCode); DAudioSourceManager::GetInstance().DAudioNotify(devId_, dhId, type, jParam.dump()); return WaitForRPC(static_cast(static_cast(type) + eventOffset)); } @@ -922,20 +876,5 @@ void DAudioSourceDev::to_json(json &j, const AudioParam ¶m) { KEY_SOURCE_TYPE, param.captureOpts.sourceType }, }; } - -bool DAudioSourceDev::CheckIsNum(const std::string &jsonString) -{ - if (jsonString.empty() || jsonString.size() > MAX_KEY_DH_ID_LEN) { - DHLOGE("Json string size %d, is zero or too long.", jsonString.size()); - return false; - } - for (char const &c : jsonString) { - if (!std::isdigit(c)) { - DHLOGE("Json string is not number."); - return false; - } - } - return true; -} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/audiomanager/managersource/src/daudio_source_manager.cpp b/services/audiomanager/managersource/src/daudio_source_manager.cpp index bd7f3d4d9467db4b02d5462dccb64c0094e8040f..45b8dc49f0c07479aa6e5cc004e02aec81702470 100644 --- a/services/audiomanager/managersource/src/daudio_source_manager.cpp +++ b/services/audiomanager/managersource/src/daudio_source_manager.cpp @@ -128,6 +128,15 @@ int32_t DAudioSourceManager::HandleDAudioNotify(const std::string &devId, const { DHLOGI("Handle distributed audio notify, devId: %s, dhId: %s, eventType: %d.", GetAnonyString(devId).c_str(), dhId.c_str(), eventType); + if (eventContent.length() > DAUDIO_MAX_JSON_LEN || eventContent.empty()) { + return ERR_DH_AUDIO_FAILED; + } + + json jParam = json::parse(eventContent, nullptr, false); + if (JsonParamCheck(jParam, { KEY_RANDOM_TASK_CODE }) && CheckIsNum((std::string)jParam[KEY_RANDOM_TASK_CODE])) { + int32_t randomCode = std::stoi((std::string)jParam[KEY_RANDOM_TASK_CODE]); + DHLOGI("Handle distributed audio notify from sink, random task code: %d", randomCode); + } std::lock_guard lock(devMapMtx_); auto dev = audioDevMap_.find(devId); if (dev == audioDevMap_.end()) { diff --git a/services/audiomanager/managersource/src/dmic_dev.cpp b/services/audiomanager/managersource/src/dmic_dev.cpp index 20d06880274dabe5cad73806345288a1798c88e7..93f46ba0ecc7dde1332a71713636925e95e4516c 100644 --- a/services/audiomanager/managersource/src/dmic_dev.cpp +++ b/services/audiomanager/managersource/src/dmic_dev.cpp @@ -161,77 +161,21 @@ int32_t DMicDev::NotifyEvent(const std::string &devId, const int32_t dhId, const DHLOGE("Event callback is null"); return ERR_DH_AUDIO_SA_EVENT_CALLBACK_NULL; } - if (event.type == AudioEventType::AUDIO_START) { - curStatus_ = AudioStatus::STATUS_START; - return DH_SUCCESS; - } - if (event.type == AudioEventType::AUDIO_STOP) { - curStatus_ = AudioStatus::STATUS_STOP; - return DH_SUCCESS; + switch (event.type) { + case AudioEventType::AUDIO_START: + curStatus_ = AudioStatus::STATUS_START; + break; + case AudioEventType::AUDIO_STOP: + curStatus_ = AudioStatus::STATUS_STOP; + break; + default: + break; } AudioEvent audioEvent(event.type, event.content); cbObj->NotifyEvent(audioEvent); return DH_SUCCESS; } -int32_t DMicDev::MmapStart() -{ - if (ashmem_ == nullptr || micTrans_ == nullptr) { - DHLOGE("Ashmem or trans is null."); - return ERR_DH_AUDIO_NULLPTR; - } - std::lock_guard lock(writeAshmemtMutex_); - isEnqueueRunning_.store(true); - enqueueDataThread_ = std::thread(&DMicDev::EnqueueThread, this); - if (pthread_setname_np(enqueueDataThread_.native_handle(), ENQUEUE_THREAD) != DH_SUCCESS) { - DHLOGE("Enqueue data thread setname failed."); - } - return DH_SUCCESS; -} - -void DMicDev::EnqueueThread() -{ - writeIndex_ = 0; - DHLOGI("lengthPerRead length: %d", lengthPerTrans_); - int64_t startTime = GetCurNano(); - uint64_t writeCount = 0; - while (isEnqueueRunning_.load()) { - std::shared_ptr audioData = nullptr; - { - std::lock_guard lock(dataQueueMtx_); - if (dataQueue_.empty()) { - DHLOGI("Data queue is empty."); - audioData = std::make_shared(param_.comParam.frameSize); - } else { - audioData = dataQueue_.front(); - dataQueue_.pop(); - } - } - bool writeRet = ashmem_->WriteToAshmem(audioData->Data(), audioData->Size(), writeIndex_); - if (writeRet) { - DHLOGI("Write to ashmem success! write index: %d, writeLength: %d", writeIndex_, lengthPerTrans_); - } else { - DHLOGE("Write daTa to ashmem failed."); - } - writeIndex_ += lengthPerTrans_; - if (writeIndex_ >= ashmemLength_) { - writeIndex_ = 0; - } - writeCount++; - AbsoluteSleep(startTime + writeCount * periodNanoSec_); - } -} - -int32_t DMicDev::MmapStop() -{ - std::lock_guard lock(writeAshmemtMutex_); - isEnqueueRunning_.store(false); - if (enqueueDataThread_.joinable()) { - enqueueDataThread_.join(); - } - return DH_SUCCESS; -} - int32_t DMicDev::SetUp() { DHLOGI("Set up mic device."); @@ -290,12 +234,6 @@ int32_t DMicDev::Stop() int32_t DMicDev::Release() { DHLOGI("Release mic device."); - if (ashmem_ != nullptr) { - ashmem_->UnmapAshmem(); - ashmem_->CloseAshmem(); - ashmem_ = nullptr; - DHLOGI("UnInitAshmem success."); - } if (micTrans_ == nullptr) { DHLOGE("Mic trans is null."); return DH_SUCCESS; @@ -339,40 +277,6 @@ int32_t DMicDev::ReadStreamData(const std::string &devId, const int32_t dhId, st return DH_SUCCESS; } -int32_t DMicDev::ReadMmapPosition(const std::string &devId, const int32_t dhId, uint64_t &frames, uint64_t &timeStamp) -{ - DHLOGI("Read mmap position."); - (void)devId; - (void)dhId; - (void)frames; - (void)timeStamp; - return DH_SUCCESS; -} - -int32_t DMicDev::RefreshAshmemInfo(const std::string &devId, const int32_t dhId, - int32_t fd, int32_t ashmemLength, int32_t lengthPerTrans) -{ - DHLOGI("RefreshAshmemInfo: fd: %d, ashmemLength: %d, lengthPerTrans: %d", fd, ashmemLength, lengthPerTrans); - if (param_.captureOpts.capturerFlags == CAPTURE_MMAP_FLAG) { - DHLOGI("Dmic dev low-latency mode"); - if (ashmem_ != nullptr) { - return DH_SUCCESS; - } - ashmem_ = new Ashmem(fd, ashmemLength); - ashmemLength_ = ashmemLength; - lengthPerTrans_ = lengthPerTrans; - DHLOGI("Create ashmem success. fd: %d, ashmem length: %d, lengthPerTrans: %d", - fd, ashmemLength_, lengthPerTrans_); - bool mapRet = ashmem_->MapReadAndWriteAshmem(); - if (!mapRet) { - DHLOGE("Mmap ashmem failed"); - return ERR_DH_AUDIO_NULLPTR; - } - } - return DH_SUCCESS; -} - - AudioParam DMicDev::GetAudioParam() const { return param_; @@ -421,7 +325,8 @@ int32_t DMicDev::OnDecodeTransDataDone(const std::shared_ptr &audioDa } std::lock_guard lock(dataQueueMtx_); size_t dataQueSize = curStatus_ != AudioStatus::STATUS_START ? - DATA_QUEUE_HALF_SIZE : DATA_QUEUE_MAX_SIZE; + (param_.captureOpts.capturerFlags == MMAP_MODE ? LOW_LATENCY_DATA_QUEUE_HALF_SIZE : DATA_QUEUE_HALF_SIZE) : + (param_.captureOpts.capturerFlags == MMAP_MODE ? LOW_LATENCY_DATA_QUEUE_MAX_SIZE : DATA_QUEUE_MAX_SIZE); while (dataQueue_.size() > dataQueSize) { DHLOGI("Data queue overflow. buf current size: %d", dataQueue_.size()); dataQueue_.pop(); diff --git a/services/audiomanager/managersource/src/dspeaker_dev.cpp b/services/audiomanager/managersource/src/dspeaker_dev.cpp index 849bbdf4694e7599b77181cf5411b24cf6080579..db9eb5dc63d0d9a96ba3fb1a8f366ace5c379918 100644 --- a/services/audiomanager/managersource/src/dspeaker_dev.cpp +++ b/services/audiomanager/managersource/src/dspeaker_dev.cpp @@ -168,68 +168,6 @@ int32_t DSpeakerDev::NotifyEvent(const std::string &devId, int32_t dhId, const A return DH_SUCCESS; } -int32_t DSpeakerDev::MmapStart() -{ - if (ashmem_ == nullptr || speakerTrans_ == nullptr) { - DHLOGE("Ashmem or trans is null."); - return ERR_DH_AUDIO_NULLPTR; - } - isEnqueueRunning_.store(true); - enqueueDataThread_ = std::thread(&DSpeakerDev::EnqueueThread, this); - if (pthread_setname_np(enqueueDataThread_.native_handle(), ENQUEUE_THREAD) != DH_SUCCESS) { - DHLOGE("Enqueue data thread setname failed."); - } - return DH_SUCCESS; -} - -void DSpeakerDev::EnqueueThread() -{ - readIndex_ = 0; - readNum_ = 0; - DHLOGI("lengthPerRead length: %d", lengthPerTrans_); - std::this_thread::sleep_for(std::chrono::microseconds(readStartDelayms_)); - int64_t startTime = GetCurNano(); - uint64_t readCount = 0; - while (isEnqueueRunning_.load()) { - auto readData = ashmem_->ReadFromAshmem(lengthPerTrans_, readIndex_); - DHLOGI("Read from ashmem success! read index: %d, readLength: %d", readIndex_, lengthPerTrans_); - std::shared_ptr audioData = std::make_shared(lengthPerTrans_); - if (readData != nullptr) { - const uint8_t *readAudioData = reinterpret_cast(readData); - int32_t ret = memcpy_s(audioData->Data(), audioData->Capacity(), readAudioData, param_.comParam.frameSize); - if (ret != EOK) { - DHLOGE("Copy audio data failed. errno: %d", ret); - } - } - - if (speakerTrans_ == nullptr) { - DHLOGE("Write stream data, speaker trans is null."); - return; - } - int32_t ret = speakerTrans_->FeedAudioData(audioData); - if (ret != DH_SUCCESS) { - DHLOGE("Write stream data failed, ret: %d.", ret); - } - readIndex_ += lengthPerTrans_; - if (readIndex_ >= ashmemLength_) { - readIndex_ = 0; - } - readNum_ += static_cast(CalculateSampleNum(param_.comParam.sampleRate, timeInterval_)); - readTimeStamp_ = 0; - readCount++; - AbsoluteSleep(startTime + readCount * periodNanoSec_); - } -} - -int32_t DSpeakerDev::MmapStop() -{ - isEnqueueRunning_.store(false); - if (enqueueDataThread_.joinable()) { - enqueueDataThread_.join(); - } - return DH_SUCCESS; -} - int32_t DSpeakerDev::SetUp() { DHLOGI("Set up speaker device."); @@ -291,12 +229,6 @@ int32_t DSpeakerDev::Stop() int32_t DSpeakerDev::Release() { DHLOGI("Release speaker device."); - if (ashmem_ != nullptr) { - ashmem_->UnmapAshmem(); - ashmem_->CloseAshmem(); - ashmem_ = nullptr; - DHLOGI("UnInitAshmem success."); - } if (speakerTrans_ == nullptr) { DHLOGE("Speaker trans is null."); return DH_SUCCESS; @@ -353,6 +285,7 @@ int32_t DSpeakerDev::ReadStreamData(const std::string &devId, const int32_t dhId (void)devId; (void)dhId; (void)data; + DHLOGI("Dspeaker dev not support read stream data."); return DH_SUCCESS; } @@ -371,37 +304,6 @@ int32_t DSpeakerDev::WriteStreamData(const std::string &devId, const int32_t dhI return DH_SUCCESS; } -int32_t DSpeakerDev::ReadMmapPosition(const std::string &devId, const int32_t dhId, - uint64_t &frames, uint64_t &timeStamp) -{ - DHLOGI("Read mmap position"); - frames = readNum_; - timeStamp = readTimeStamp_; - return DH_SUCCESS; -} - -int32_t DSpeakerDev::RefreshAshmemInfo(const std::string &devId, const int32_t dhId, - int32_t fd, int32_t ashmemLength, int32_t lengthPerTrans) -{ - DHLOGI("RefreshAshmemInfo: fd: %d, ashmemLength: %d, lengthPerTrans: %d", fd, ashmemLength, lengthPerTrans); - if (param_.renderOpts.renderFlags == 1) { - DHLOGI("Dspeaker dev low-latency mode"); - if (ashmem_ == nullptr) { - ashmem_ = new Ashmem(fd, ashmemLength); - ashmemLength_ = ashmemLength; - lengthPerTrans_ = lengthPerTrans; - DHLOGI("Create ashmem success. fd: %d, ashmem length: %d, lengthPerTrans: %d", - fd, ashmemLength_, lengthPerTrans_); - bool mapRet = ashmem_->MapReadAndWriteAshmem(); - if (!mapRet) { - DHLOGE("Mmap ashmem failed"); - return ERR_DH_AUDIO_NULLPTR; - } - } - } - return DH_SUCCESS; -} - AudioParam DSpeakerDev::GetAudioParam() const { return param_; diff --git a/services/audiomanager/servicesink/BUILD.gn b/services/audiomanager/servicesink/BUILD.gn index ace4763de96d69c496fc75c473c0fa89e10d9afa..bd822197d38cec95f634afff34ce636e02c6d4fa 100755 --- a/services/audiomanager/servicesink/BUILD.gn +++ b/services/audiomanager/servicesink/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../distributedaudio.gni") ohos_shared_library("distributed_audio_sink") { include_dirs = [ @@ -40,6 +39,7 @@ ohos_shared_library("distributed_audio_sink") { "${audio_client_path}/micclient/include", "${audio_client_path}/spkclient/include", "${audio_control_path}/controlsink/include", + "${audio_client_path}/interface", "${audio_processor_path}/encodeprocessor/include", "${audio_processor_path}/decodeprocessor/include", "${audio_processor_path}/interface", @@ -67,17 +67,17 @@ ohos_shared_library("distributed_audio_sink") { ] sources = [ - "src/daudio_sink_service.cpp", - "src/daudio_sink_stub.cpp", - "${audio_client_path}/spkclient/src/dspeaker_client.cpp", "${audio_client_path}/micclient/src/dmic_client.cpp", + "${audio_client_path}/spkclient/src/dspeaker_client.cpp", "${audio_control_path}/controlsink/src/daudio_sink_dev_ctrl_manager.cpp", "${innerkits_path}/native_cpp/audio_sink/src/daudio_sink_handler.cpp", - "${innerkits_path}/native_cpp/audio_sink/src/daudio_sink_proxy.cpp", "${innerkits_path}/native_cpp/audio_sink/src/daudio_sink_load_callback.cpp", + "${innerkits_path}/native_cpp/audio_sink/src/daudio_sink_proxy.cpp", "${innerkits_path}/native_cpp/audio_source/src/daudio_source_proxy.cpp", "${services_path}/audiomanager/managersink/src/daudio_sink_dev.cpp", "${services_path}/audiomanager/managersink/src/daudio_sink_manager.cpp", + "src/daudio_sink_service.cpp", + "src/daudio_sink_stub.cpp", ] deps = [ @@ -89,13 +89,16 @@ ohos_shared_library("distributed_audio_sink") { external_deps = [ "c_utils:utils", + "drivers_interface_audio:libaudio_proxy_1.0", + "hdf_core:libhdf_ipc_adapter", + "hdf_core:libhdi", "hitrace_native:hitrace_meter", "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "multimedia_audio_framework:audio_client", "multimedia_audio_framework:audio_capturer", + "multimedia_audio_framework:audio_client", "multimedia_audio_framework:audio_renderer", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] defines = [ diff --git a/services/audiomanager/servicesink/src/daudio_sink_stub.cpp b/services/audiomanager/servicesink/src/daudio_sink_stub.cpp index dcaa60beb527ecf1b9fdb2ae34ff6bc096c3a5ae..de02c128058fb2f2e16381c11499b81979f407fb 100644 --- a/services/audiomanager/servicesink/src/daudio_sink_stub.cpp +++ b/services/audiomanager/servicesink/src/daudio_sink_stub.cpp @@ -52,7 +52,7 @@ int32_t DAudioSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mess const auto &iter = memberFuncMap_.find(code); if (iter == memberFuncMap_.end()) { DHLOGE("Invalid request code."); - return ERR_DH_AUDIO_SA_INVALID_REQUEST_CODE; + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } DAudioSinkServiceFunc &func = iter->second; return (this->*func)(data, reply, option); diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index 87d5e197774bbbd0aea81c38c5a1c73e28db79b5..838ae15a47d10c345143fb454d381cde0de24b83 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../distributedaudio.gni") ohos_shared_library("distributed_audio_source") { include_dirs = [ @@ -66,9 +65,6 @@ ohos_shared_library("distributed_audio_source") { ] sources = [ - "src/daudio_ipc_callback_proxy.cpp", - "src/daudio_source_service.cpp", - "src/daudio_source_stub.cpp", "${audio_control_path}/controlsource/src/daudio_source_dev_ctrl_manager.cpp", "${audio_hdi_proxy_path}/src/daudio_hdf_operate.cpp", "${audio_hdi_proxy_path}/src/daudio_hdi_handler.cpp", @@ -81,6 +77,9 @@ ohos_shared_library("distributed_audio_source") { "${services_path}/audiomanager/managersource/src/daudio_source_mgr_callback.cpp", "${services_path}/audiomanager/managersource/src/dmic_dev.cpp", "${services_path}/audiomanager/managersource/src/dspeaker_dev.cpp", + "src/daudio_ipc_callback_proxy.cpp", + "src/daudio_source_service.cpp", + "src/daudio_source_stub.cpp", ] deps = [ @@ -89,8 +88,8 @@ ohos_shared_library("distributed_audio_source") { "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", "${distributedaudio_path}/audiohandler:distributed_audio_handler", "${hdf_interfaces_path}/audioext/v1_0:libdaudioext_proxy_1.0", - "${services_path}/hdfaudioclient:daudio_client", "${services_path}/common:distributed_audio_utils", + "${services_path}/hdfaudioclient:daudio_client", ] external_deps = [ diff --git a/services/audiomanager/servicesource/src/daudio_source_stub.cpp b/services/audiomanager/servicesource/src/daudio_source_stub.cpp index 1f1fdacfd53c6b9b7d224d2c0a1059770b82114c..ed68f4f976fac12d0da6365d49f16ae3d969eba8 100644 --- a/services/audiomanager/servicesource/src/daudio_source_stub.cpp +++ b/services/audiomanager/servicesource/src/daudio_source_stub.cpp @@ -48,7 +48,7 @@ int32_t DAudioSourceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me const auto &iter = memberFuncMap_.find(code); if (iter == memberFuncMap_.end()) { DHLOGE("Invalid request code."); - return ERR_DH_AUDIO_SA_INVALID_REQUEST_CODE; + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } DAudioSourceServiceFunc &func = iter->second; return (this->*func)(data, reply, option); diff --git a/services/audiomanager/test/unittest/BUILD.gn b/services/audiomanager/test/unittest/BUILD.gn index 71cc54a98a970542cff6f0b45f6139e11a7e8e5f..e9e5589c85afd17ab345609b747a44b7183be0e5 100644 --- a/services/audiomanager/test/unittest/BUILD.gn +++ b/services/audiomanager/test/unittest/BUILD.gn @@ -13,18 +13,17 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") group("daudio_manager_test") { testonly = true deps = [ - "${services_path}/audiomanager/test/unittest/managersink:manager_sink_test", - "${services_path}/audiomanager/test/unittest/source_device:daudio_source_dev_test", - "${services_path}/audiomanager/test/unittest/sourcemanager:daudio_source_mgr_test", "${common_path}/dfx_utils/test/unittest:DAudioDfxTest", + "${services_path}/audiomanager/test/unittest/managersink:manager_sink_test", "${services_path}/audiomanager/test/unittest/servicesink:DaudioSinkServiceTest", "${services_path}/audiomanager/test/unittest/servicesource:DaudioSourceServiceTest", + "${services_path}/audiomanager/test/unittest/source_device:daudio_source_dev_test", + "${services_path}/audiomanager/test/unittest/sourcemanager:daudio_source_mgr_test", "${services_path}/common/test/unittest/audiodata:audio_data_test", ] } diff --git a/services/audiomanager/test/unittest/managersink/BUILD.gn b/services/audiomanager/test/unittest/managersink/BUILD.gn index 334a0dcd6741f09ea75d64e1b8f5398d940dfc80..d34046af18112ca7acff9debca21fbb593847676 100644 --- a/services/audiomanager/test/unittest/managersink/BUILD.gn +++ b/services/audiomanager/test/unittest/managersink/BUILD.gn @@ -14,15 +14,14 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audiomanager/manager_sink_test" config("module_private_config") { visibility = [ ":*" ] - include_dirs = [ + include_dirs = [ "//third_party/json/include", "//foundation/multimedia/audio_framework/services/audio_service/client/include", "${audio_framework_path}/audiopolicy/include", @@ -36,6 +35,7 @@ config("module_private_config") { include_dirs += [ "${audio_client_path}/micclient/include", "${audio_client_path}/spkclient/include", + "${audio_client_path}/interface", "${audio_control_path}/controlsink/include", "${audio_processor_path}/decodeprocessor/include", "${audio_processor_path}/encodeprocessor/include", @@ -66,16 +66,29 @@ config("module_private_config") { ohos_unittest("DaudioSinkDevTest") { module_out_path = module_out_path - sources = [ - "${services_path}/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp", - ] + sources = [ "${services_path}/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp" ] configs = [ ":module_private_config" ] deps = [ + "${services_path}/audiomanager/servicesink:distributed_audio_sink", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", - "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + external_deps = [ + "c_utils:utils", + "drivers_interface_audio:libaudio_proxy_1.0", + "hdf_core:libhdf_ipc_adapter", + "hdf_core:libhdf_utils", + "hdf_core:libhdi", + "hitrace_native:hitrace_meter", + "ipc:ipc_core", + "multimedia_audio_framework:audio_capturer", + "multimedia_audio_framework:audio_client", + "multimedia_audio_framework:audio_renderer", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] } @@ -83,23 +96,36 @@ ohos_unittest("DaudioSinkDevTest") { ohos_unittest("DAudioSinkManagerTest") { module_out_path = module_out_path - sources = [ - "${services_path}/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp", - ] + sources = [ "${services_path}/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp" ] configs = [ ":module_private_config" ] deps = [ + "${services_path}/audiomanager/servicesink:distributed_audio_sink", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", - "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + external_deps = [ + "c_utils:utils", + "drivers_interface_audio:libaudio_proxy_1.0", + "hdf_core:libhdf_ipc_adapter", + "hdf_core:libhdf_utils", + "hdf_core:libhdi", + "hitrace_native:hitrace_meter", + "ipc:ipc_core", + "multimedia_audio_framework:audio_capturer", + "multimedia_audio_framework:audio_client", + "multimedia_audio_framework:audio_renderer", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] } group("manager_sink_test") { testonly = true deps = [ - ":DaudioSinkDevTest", ":DAudioSinkManagerTest", + ":DaudioSinkDevTest", ] } diff --git a/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp b/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp index 035d5965e1a7583823a148938716263d02f346a5..3c449e135d101c61e9fd50f86ab44e5827b899d4 100644 --- a/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp +++ b/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp @@ -38,6 +38,36 @@ void DAudioSinkDevTest::TearDown() sinkDev_ = nullptr; } +/** + * @tc.name: NotifyOpenCtrlChannel_001 + * @tc.desc: Verify the NotifyOpenCtrlChannel function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyOpenCtrlChannel_001, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + EXPECT_EQ(DH_SUCCESS, sinkDev_->NotifyOpenCtrlChannel(event)); + sinkDev_->NotifyEvent(event); +} + +/** + * @tc.name: NotifyCloseCtrlChannel_001 + * @tc.desc: Verify the NotifyCloseCtrlChannel function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyCloseCtrlChannel_001, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + EXPECT_EQ(DH_SUCCESS, sinkDev_->NotifyCloseCtrlChannel(event)); + sinkDev_->NotifyEvent(event); +} + /** * @tc.name: NotifyCtrlOpened_001 * @tc.desc: Verify the NotifyCtrlOpened function. @@ -51,6 +81,32 @@ HWTEST_F(DAudioSinkDevTest, NotifyCtrlOpened_001, TestSize.Level1) sinkDev_->NotifyEvent(event); } +/** + * @tc.name: NotifyCtrlClosed_001 + * @tc.desc: Verify the NotifyCtrlClosed function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyCtrlClosed_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyCtrlClosed(event)); +} + +/** + * @tc.name: NotifyCtrlClosed_002 + * @tc.desc: Verify the NotifyCtrlClosed function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyCtrlClosed_002, TestSize.Level1) +{ + AudioEvent event; + uint32_t maxSize = 10; + sinkDev_->taskQueue_ = std::make_shared(maxSize); + EXPECT_EQ(DH_SUCCESS, sinkDev_->NotifyCtrlClosed(event)); +} + /** * @tc.name: NotifySpeakerOpened_001 * @tc.desc: Verify the NotifySpeakerOpened function. @@ -63,6 +119,58 @@ HWTEST_F(DAudioSinkDevTest, NotifySpeakerOpened_001, TestSize.Level1) EXPECT_NE(DH_SUCCESS, sinkDev_->NotifySpeakerOpened(event)); } +/** + * @tc.name: NotifyOpenSpeaker_001 + * @tc.desc: Verify the NotifyOpenSpeaker function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyOpenSpeaker_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyOpenSpeaker(event)); +} + +/** + * @tc.name: NotifyOpenSpeaker_002 + * @tc.desc: Verify the NotifyOpenSpeaker function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyOpenSpeaker_002, TestSize.Level1) +{ + AudioEvent event; + uint32_t maxSize = 10; + sinkDev_->taskQueue_ = std::make_shared(maxSize); + EXPECT_EQ(DH_SUCCESS, sinkDev_->NotifyOpenSpeaker(event)); +} + +/** + * @tc.name: NotifyCloseSpeaker_001 + * @tc.desc: Verify the NotifyCloseSpeaker function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyCloseSpeaker_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyCloseSpeaker(event)); +} + +/** + * @tc.name: NotifyCloseSpeaker_002 + * @tc.desc: Verify the NotifyCloseSpeaker function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyCloseSpeaker_002, TestSize.Level1) +{ + AudioEvent event; + uint32_t maxSize = 10; + sinkDev_->taskQueue_ = std::make_shared(maxSize); + EXPECT_EQ(DH_SUCCESS, sinkDev_->NotifyCloseSpeaker(event)); +} + /** * @tc.name: NotifySpeakerOpened_002 * @tc.desc: Verify the NotifySpeakerOpened function. @@ -77,6 +185,48 @@ HWTEST_F(DAudioSinkDevTest, NotifySpeakerOpened_002, TestSize.Level1) EXPECT_NE(DH_SUCCESS, sinkDev_->NotifySpeakerOpened(event)); } +/** + * @tc.name: NotifySpeakerOpened_003 + * @tc.desc: Verify the NotifySpeakerOpened function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifySpeakerOpened_003, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + std::string devId = "devid"; + sinkDev_->speakerClient_ = std::make_shared(devId, sinkDev_); + EXPECT_NE(DH_SUCCESS, sinkDev_->NotifySpeakerOpened(event)); +} + +/** + * @tc.name: NotifySpeakerClosed_001 + * @tc.desc: Verify the NotifySpeakerClosed function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifySpeakerClosed_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifySpeakerClosed(event)); +} + +/** + * @tc.name: NotifySpeakerClosed_002 + * @tc.desc: Verify the NotifySpeakerClosed function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifySpeakerClosed_002, TestSize.Level1) +{ + AudioEvent event; + uint32_t maxSize = 10; + sinkDev_->taskQueue_ = std::make_shared(maxSize); + EXPECT_EQ(DH_SUCCESS, sinkDev_->NotifySpeakerClosed(event)); +} + /** * @tc.name: NotifyMicOpened_001 * @tc.desc: Verify the NotifyMicOpened function. @@ -89,6 +239,240 @@ HWTEST_F(DAudioSinkDevTest, NotifyMicOpened_001, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, sinkDev_->NotifyMicOpened(event)); } +/** + * @tc.name: NotifyMicClosed_001 + * @tc.desc: Verify the NotifyMicClosed function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyMicClosed_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyMicClosed(event)); +} + +/** + * @tc.name: NotifyMicClosed_002 + * @tc.desc: Verify the NotifyMicClosed function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyMicClosed_002, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + EXPECT_NE(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyMicClosed(event)); +} + +/** + * @tc.name: NotifyOpenMic_001 + * @tc.desc: Verify the NotifyOpenMic function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyOpenMic_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyOpenMic(event)); +} + +/** + * @tc.name: NotifyOpenMic_002 + * @tc.desc: Verify the NotifyOpenMic function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyOpenMic_002, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + EXPECT_NE(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyOpenMic(event)); +} + +/** + * @tc.name: NotifyCloseMic_001 + * @tc.desc: Verify the NotifyCloseMic function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyCloseMic_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyCloseMic(event)); +} + +/** + * @tc.name: NotifyCloseMic_002 + * @tc.desc: Verify the NotifyCloseMic function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyCloseMic_002, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + EXPECT_NE(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyCloseMic(event)); +} + +/** + * @tc.name: NotifySetParam_001 + * @tc.desc: Verify the NotifySetParam function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifySetParam_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifySetParam(event)); +} + +/** + * @tc.name: NotifySetParam_002 + * @tc.desc: Verify the NotifySetParam function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifySetParam_002, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + EXPECT_NE(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifySetParam(event)); +} + +/** + * @tc.name: NotifySetVolume_001 + * @tc.desc: Verify the NotifySetVolume function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifySetVolume_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifySetVolume(event)); +} + +/** + * @tc.name: NotifySetVolume_002 + * @tc.desc: Verify the NotifySetVolume function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifySetVolume_002, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + EXPECT_NE(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifySetVolume(event)); +} + +/** + * @tc.name: NotifySetMute_001 + * @tc.desc: Verify the NotifySetMute function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifySetMute_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifySetMute(event)); +} + +/** + * @tc.name: NotifySetMute_002 + * @tc.desc: Verify the NotifySetMute function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifySetMute_002, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + EXPECT_NE(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifySetMute(event)); +} + +/** + * @tc.name: NotifyVolumeChange_001 + * @tc.desc: Verify the NotifyVolumeChange function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyVolumeChange_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyVolumeChange(event)); +} + +/** + * @tc.name: NotifyVolumeChange_002 + * @tc.desc: Verify the NotifyVolumeChange function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyVolumeChange_002, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + EXPECT_NE(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyVolumeChange(event)); +} + +/** + * @tc.name: NotifyFocusChange_001 + * @tc.desc: Verify the NotifyFocusChange function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyFocusChange_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyFocusChange(event)); +} + +/** + * @tc.name: NotifyFocusChange_002 + * @tc.desc: Verify the NotifyFocusChange function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyFocusChange_002, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + EXPECT_NE(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyFocusChange(event)); +} + +/** + * @tc.name: NotifyRenderStateChange_001 + * @tc.desc: Verify the NotifyRenderStateChange function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyRenderStateChange_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyRenderStateChange(event)); +} + +/** + * @tc.name: NotifyRenderStateChange_002 + * @tc.desc: Verify the NotifyRenderStateChange function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyRenderStateChange_002, TestSize.Level1) +{ + constexpr size_t capacity = 20; + sinkDev_->taskQueue_ = std::make_shared(capacity); + AudioEvent event; + EXPECT_NE(ERR_DH_AUDIO_NULLPTR, sinkDev_->NotifyRenderStateChange(event)); +} + /** * @tc.name: NotifyPlayStatusChange_001 * @tc.desc: Verify the NotifyPlayStatusChange function. diff --git a/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp b/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp index 7aaca6f4d886e8c82b1a8a986e3b670ccbaa0ec9..313eff39a595ead1260f973a0486b1e7b2e3cf4a 100644 --- a/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp +++ b/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp @@ -53,6 +53,23 @@ HWTEST_F(DAudioSinkManagerTest, CreateAudioDevice_001, TestSize.Level1) std::string devId = "devId"; EXPECT_EQ(DH_SUCCESS, daudioSinkManager.CreateAudioDevice(devId)); daudioSinkManager.ClearAudioDev(devId); + daudioSinkManager.OnSinkDevReleased(devId); +} + +/** + * @tc.name: DAudioNotify_001 + * @tc.desc: Verify the DAudioNotify function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkManagerTest, DAudioNotify_001, TestSize.Level1) +{ + std::string devId = "devId"; + std::string dhId = "dhId"; + const int32_t eventType = 1; + const std::string eventContent = "eventContent"; + EXPECT_EQ(ERR_DH_AUDIO_SA_GET_REMOTE_SINK_FAILED, + daudioSinkManager.DAudioNotify(devId, dhId, eventType, eventContent)); } } // DistributedHardware } // OHOS diff --git a/services/audiomanager/test/unittest/servicesink/BUILD.gn b/services/audiomanager/test/unittest/servicesink/BUILD.gn index be48b8182162a75635717aad3901e9b7b7cb7921..dadbe7251f8a4bc4ff6f3fec0c91702139201d8f 100644 --- a/services/audiomanager/test/unittest/servicesink/BUILD.gn +++ b/services/audiomanager/test/unittest/servicesink/BUILD.gn @@ -14,15 +14,14 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audiomanager/service_sink_test" config("module_private_config") { visibility = [ ":*" ] - include_dirs = [ + include_dirs = [ "//foundation/multimedia/audio_framework/services/audio_service/client/include", "${audio_framework_path}/audiopolicy/include", @@ -79,27 +78,25 @@ config("module_private_config") { ohos_unittest("DaudioSinkServiceTest") { module_out_path = module_out_path - sources = [ - "${services_path}/audiomanager/test/unittest/servicesink/src/daudio_sink_service_test.cpp", - ] + sources = [ "${services_path}/audiomanager/test/unittest/servicesink/src/daudio_sink_service_test.cpp" ] configs = [ ":module_private_config" ] deps = [ + "${services_path}/audiomanager/servicesink:distributed_audio_sink", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", - "${services_path}/audiomanager/servicesink:distributed_audio_sink", ] external_deps = [ "c_utils:utils", "hitrace_native:hitrace_meter", "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "multimedia_audio_framework:audio_client", "multimedia_audio_framework:audio_capturer", + "multimedia_audio_framework:audio_client", "multimedia_audio_framework:audio_renderer", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] } diff --git a/services/audiomanager/test/unittest/servicesource/BUILD.gn b/services/audiomanager/test/unittest/servicesource/BUILD.gn index 055058dc8fd8047177e0852de5a890b724099190..cd9bcd62d56c5b0eebd47152dbf1d016e8360b9c 100644 --- a/services/audiomanager/test/unittest/servicesource/BUILD.gn +++ b/services/audiomanager/test/unittest/servicesource/BUILD.gn @@ -14,15 +14,14 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audiomanager/service_source_test" config("module_private_config") { visibility = [ ":*" ] - include_dirs = [ + include_dirs = [ "//foundation/multimedia/audio_framework/services/audio_service/client/include", "${audio_framework_path}/audiopolicy/include", @@ -89,27 +88,25 @@ config("module_private_config") { ohos_unittest("DaudioSourceServiceTest") { module_out_path = module_out_path - sources = [ - "${services_path}/audiomanager/test/unittest/servicesource/src/daudio_source_service_test.cpp", - ] + sources = [ "${services_path}/audiomanager/test/unittest/servicesource/src/daudio_source_service_test.cpp" ] configs = [ ":module_private_config" ] deps = [ + "${services_path}/audiomanager/servicesource:distributed_audio_source", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", - "${services_path}/audiomanager/servicesource:distributed_audio_source", ] external_deps = [ "c_utils:utils", "hitrace_native:hitrace_meter", "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "multimedia_audio_framework:audio_client", "multimedia_audio_framework:audio_capturer", + "multimedia_audio_framework:audio_client", "multimedia_audio_framework:audio_renderer", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] } diff --git a/services/audiomanager/test/unittest/servicesource/src/daudio_source_service_test.cpp b/services/audiomanager/test/unittest/servicesource/src/daudio_source_service_test.cpp index 8576c3b5c0397a89ebc9c7280e2fab2ce9423949..4b7acc2254ca6b922c554d1ded686154d90b6d11 100644 --- a/services/audiomanager/test/unittest/servicesource/src/daudio_source_service_test.cpp +++ b/services/audiomanager/test/unittest/servicesource/src/daudio_source_service_test.cpp @@ -93,5 +93,18 @@ HWTEST_F(DAudioSourceServiceTest, ConfigDistributedHardware_001, TestSize.Level1 EXPECT_EQ(ERR_DH_AUDIO_SA_FUNCTION_NOT_IMPLEMENT, sourceSrv_->ConfigDistributedHardware(devId, dhId, key, value)); } + +/** + * @tc.name: Dump_001 + * @tc.desc: Verify the Dump function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSourceServiceTest, Dump_001, TestSize.Level1) +{ + int32_t fd = 0; + const std::vector args; + EXPECT_EQ(DH_SUCCESS, sourceSrv_->Dump(fd, args)); +} } // DistributedHardware } // OHOS diff --git a/services/audiomanager/test/unittest/source_device/BUILD.gn b/services/audiomanager/test/unittest/source_device/BUILD.gn index 67a6422c27ee46f508a685700111a37e057b7ee2..5fd18fc6d1bedb360f5ca2cdd3ad730a5dd60411 100644 --- a/services/audiomanager/test/unittest/source_device/BUILD.gn +++ b/services/audiomanager/test/unittest/source_device/BUILD.gn @@ -12,11 +12,9 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") -module_out_path = - "distributed_audio/services/audiomanager/source_device_test" +module_out_path = "distributed_audio/services/audiomanager/source_device_test" config("module_private_config") { visibility = [ ":*" ] @@ -75,8 +73,8 @@ ohos_unittest("DaudioSourceDevTest") { configs = [ ":module_private_config" ] deps = [ - "${services_path}/audiomanager/servicesource:distributed_audio_source", "${hdf_interfaces_path}/audioext/v1_0:libdaudioext_proxy_1.0", + "${services_path}/audiomanager/servicesource:distributed_audio_source", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", ] @@ -92,8 +90,8 @@ ohos_unittest("DMicDevTest") { deps = [ "${audio_transport_path}/decodetransport:distributed_audio_decode_transport", - "${services_path}/audiomanager/servicesource:distributed_audio_source", "${hdf_interfaces_path}/audioext/v1_0:libdaudioext_proxy_1.0", + "${services_path}/audiomanager/servicesource:distributed_audio_source", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", ] @@ -109,8 +107,8 @@ ohos_unittest("DSpeakerDevTest") { deps = [ "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", - "${services_path}/audiomanager/servicesource:distributed_audio_source", "${hdf_interfaces_path}/audioext/v1_0:libdaudioext_proxy_1.0", + "${services_path}/audiomanager/servicesource:distributed_audio_source", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", ] @@ -118,9 +116,9 @@ ohos_unittest("DSpeakerDevTest") { group("daudio_source_dev_test") { testonly = true - deps = [ - ":DaudioSourceDevTest", + deps = [ ":DMicDevTest", ":DSpeakerDevTest", + ":DaudioSourceDevTest", ] } diff --git a/services/audiomanager/test/unittest/source_device/src/daudio_source_dev_test.cpp b/services/audiomanager/test/unittest/source_device/src/daudio_source_dev_test.cpp index 24c082eceda2cb8176495ed656bcd62875c01b52..4031b69e3ee036544e653d588d9a96f8939929b4 100644 --- a/services/audiomanager/test/unittest/source_device/src/daudio_source_dev_test.cpp +++ b/services/audiomanager/test/unittest/source_device/src/daudio_source_dev_test.cpp @@ -172,6 +172,18 @@ HWTEST_F(DAudioSourceDevTest, HandlePlayStatusChange_001, TestSize.Level1) EXPECT_EQ(ERR_DH_AUDIO_FAILED, sourceDev_->HandlePlayStatusChange(event)); } +/** + * @tc.name: WaitForRPC_001 + * @tc.desc: Verify the WaitForRPC function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSourceDevTest, WaitForRPC_001, TestSize.Level1) +{ + AudioEventType type = NOTIFY_OPEN_SPEAKER_RESULT; + EXPECT_EQ(ERR_DH_AUDIO_SA_RPC_WAIT_TIMEOUT, sourceDev_->WaitForRPC(type)); +} + /** * @tc.name: HandleDMicClosed_001 * @tc.desc: Verify the HandleDMicClosed function. @@ -198,6 +210,55 @@ HWTEST_F(DAudioSourceDevTest, HandleDMicClosed_002, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, sourceDev_->HandleDMicClosed(event)); } +/** + * @tc.name: OpenCtrlTrans_001 + * @tc.desc: Verify the OpenCtrlTrans function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSourceDevTest, OpenCtrlTrans_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_SA_OPEN_CTRL_FAILED, sourceDev_->OpenCtrlTrans(event)); +} + +/** + * @tc.name: CloseCtrlTrans_001 + * @tc.desc: Verify the CloseCtrlTrans function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSourceDevTest, CloseCtrlTrans_001, TestSize.Level1) +{ + AudioEvent event; + bool isSpk = false; + EXPECT_EQ(DH_SUCCESS, sourceDev_->CloseCtrlTrans(event, isSpk)); +} + +/** + * @tc.name: HandleOpenCtrlTrans_001 + * @tc.desc: Verify the HandleOpenCtrlTrans function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSourceDevTest, HandleOpenCtrlTrans_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sourceDev_->HandleOpenCtrlTrans(event)); +} + +/** + * @tc.name: HandleCloseCtrlTrans_001 + * @tc.desc: Verify the HandleCloseCtrlTrans function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSourceDevTest, HandleCloseCtrlTrans_001, TestSize.Level1) +{ + AudioEvent event; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sourceDev_->HandleCloseCtrlTrans(event)); +} + /** * @tc.name: HandleNotifyRPC_001 * @tc.desc: Verify the HandleNotifyRPC function. @@ -636,19 +697,5 @@ HWTEST_F(DAudioSourceDevTest, NotifySinkDev_001, TestSize.Level1) json jAudioParam; EXPECT_EQ(ERR_DH_AUDIO_SA_RPC_WAIT_TIMEOUT, sourceDev_->NotifySinkDev(CLOSE_MIC, jAudioParam, DH_ID_SPK)); } - -/** - * @tc.name: CheckIsNum_001 - * @tc.desc: Verify the CheckIsNum function. - * @tc.type: FUNC - * @tc.require: AR000H0E5F - */ -HWTEST_F(DAudioSourceDevTest, CheckIsNum_001, TestSize.Level1) -{ - json jAudioParam; - EXPECT_FALSE(sourceDev_->CheckIsNum("")); - EXPECT_FALSE(sourceDev_->CheckIsNum("a5q")); - EXPECT_TRUE(sourceDev_->CheckIsNum("11")); -} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiomanager/test/unittest/source_device/src/dmic_dev_test.cpp b/services/audiomanager/test/unittest/source_device/src/dmic_dev_test.cpp index dbf5e4a548eab5a5d4ebc13043ddf75277ed9e4b..f441e1d32ff410baeb24af13cffa3d50b75a2152 100644 --- a/services/audiomanager/test/unittest/source_device/src/dmic_dev_test.cpp +++ b/services/audiomanager/test/unittest/source_device/src/dmic_dev_test.cpp @@ -261,6 +261,7 @@ HWTEST_F(DMicDevTest, Release_001, TestSize.Level1) */ HWTEST_F(DMicDevTest, ReadStreamData_001, TestSize.Level1) { + mic_->curStatus_ = AudioStatus::STATUS_START; const size_t capacity = 1; auto writeData = std::make_shared(capacity); EXPECT_EQ(DH_SUCCESS, mic_->WriteStreamData(DEV_ID, DH_ID, writeData)); diff --git a/services/audiomanager/test/unittest/sourcemanager/BUILD.gn b/services/audiomanager/test/unittest/sourcemanager/BUILD.gn index cebcf3891bd660bfd0c058b6fec61d42cb9db239..7083d45c664c3374ca8c292e32c91d952f9642a3 100644 --- a/services/audiomanager/test/unittest/sourcemanager/BUILD.gn +++ b/services/audiomanager/test/unittest/sourcemanager/BUILD.gn @@ -12,11 +12,9 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") -module_out_path = - "distributed_audio/services/audiomanager/source_manager_test" +module_out_path = "distributed_audio/services/audiomanager/source_manager_test" config("module_private_config") { visibility = [ ":*" ] diff --git a/services/audiomanager/test/unittest/sourcemanager/src/daudio_source_mgr_test.cpp b/services/audiomanager/test/unittest/sourcemanager/src/daudio_source_mgr_test.cpp index cce5d18edb464bd900e41c299a2b1bbf3a63bb36..297a923802342f977c3179e785bc0f8291b27f50 100644 --- a/services/audiomanager/test/unittest/sourcemanager/src/daudio_source_mgr_test.cpp +++ b/services/audiomanager/test/unittest/sourcemanager/src/daudio_source_mgr_test.cpp @@ -119,7 +119,7 @@ HWTEST_F(DAudioSourceMgrTest, EnableDAudio_003, TestSize.Level1) std::string reqId1 = GetRandomID(); DAudioSourceManager::AudioDevice device = { DEV_ID, nullptr }; sourceMgr.audioDevMap_[DEV_ID] = device; - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sourceMgr.DisableDAudio(DEV_ID, DH_ID, reqId1)); + EXPECT_EQ(DH_SUCCESS, sourceMgr.DisableDAudio(DEV_ID, DH_ID, reqId1)); EXPECT_EQ(DH_SUCCESS, sourceMgr.UnInit()); } @@ -153,7 +153,7 @@ HWTEST_F(DAudioSourceMgrTest, HandleDAudioNotify_001, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, sourceMgr.HandleDAudioNotify(DEV_ID, DH_ID, OPEN_SPEAKER, "openspk")); EXPECT_EQ(DH_SUCCESS, sourceMgr.DisableDAudio(DEV_ID, DH_ID, reqId)); - EXPECT_EQ(ERR_DH_AUDIO_SA_DEVICE_NOT_EXIST, sourceMgr.HandleDAudioNotify(DEV_ID + "1", DH_ID, CLOSE_CTRL, "")); + EXPECT_EQ(ERR_DH_AUDIO_FAILED, sourceMgr.HandleDAudioNotify(DEV_ID + "1", DH_ID, CLOSE_CTRL, "")); EXPECT_EQ(DH_SUCCESS, sourceMgr.UnInit()); } diff --git a/services/audioprocessor/effectcomponent/BUILD.gn b/services/audioprocessor/effectcomponent/BUILD.gn deleted file mode 100644 index 21fc266325149b213b090872d98b8aecfe6041ba..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/BUILD.gn +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//foundation/distributedhardware/distributed_audio/distributedaudio.gni") - -ohos_shared_library("daudio_effect_component") -{ - include_dirs = [ - "./audiopipeline/include", - "./pipelinemanager/include", - "./elements/include", - "./element_factoy/include", - "${services_path}/common/audiodata/include", - "${common_path}/include", - "${fwk_common_path}/utils/include", - ] - - sources = [ - "${services_path}/audioprocessor/effectcomponent/audiopipeline/src/pipeline_impl.cpp", - "${services_path}/audioprocessor/effectcomponent/pipelinemanager/src/pipeline_manager.cpp", - "${services_path}/audioprocessor/effectcomponent/element_factoy/src/element_factory.cpp", - "${services_path}/audioprocessor/effectcomponent/elements/src/down_stream_element.cpp", - "${services_path}/audioprocessor/effectcomponent/elements/src/render_sink_element.cpp", - "${services_path}/audioprocessor/effectcomponent/elements/src/source_element.cpp", - ] - - deps = [ "${services_path}/common:distributed_audio_utils", ] - - external_deps = [ - "c_utils:utils", - ] - - defines = [ - "HI_LOG_ENABLE", - "LOG_DOMAIN=0xD004100", - ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_audio" -} diff --git a/services/audioprocessor/effectcomponent/audiopipeline/include/ipipeline.h b/services/audioprocessor/effectcomponent/audiopipeline/include/ipipeline.h deleted file mode 100644 index 4103b5d9ad940eb823b5ca9915eb9731cc32d633..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/audiopipeline/include/ipipeline.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IPIPELINE_H -#define IPIPELINE_H - -#include -#include - -#include "audio_data.h" -#include "life_cycle.h" - -namespace OHOS { -namespace DistributedHardware { -enum class PipeType { - RENDER_PIPE, - CAPTURE_PIPE, - UNKNOWN, -}; - -class IPipeline : public ILifeCycle { -public: - virtual ~IPipeline() = default; - virtual int32_t FeedData(std::shared_ptr &inData, std::shared_ptr &outData) = 0; -}; -} // DistributedHardware -} // OHOS -#endif // IPIPELINE_H \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/audiopipeline/include/life_cycle.h b/services/audioprocessor/effectcomponent/audiopipeline/include/life_cycle.h deleted file mode 100644 index a94270c2481bdc77f12af8549f56d85df461f2c1..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/audiopipeline/include/life_cycle.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LIFE_CYCLE_H -#define LIFE_CYCLE_H - -#include - -namespace OHOS { -namespace DistributedHardware { -class ILifeCycle { -public: - virtual ~ILifeCycle() = default; - virtual int32_t Init(const std::string config) = 0; - virtual int32_t StartUp() = 0; - virtual int32_t ShutDown() = 0; - virtual int32_t Release() = 0; -}; -} // OHOS -} // DistributedHardware -#endif // LIFE_CYCLE_H \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/audiopipeline/include/pipeline_impl.h b/services/audioprocessor/effectcomponent/audiopipeline/include/pipeline_impl.h deleted file mode 100644 index 6c6d1e23f600d505c295dd72652f837bfca8237a..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/audiopipeline/include/pipeline_impl.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PIPELINE_IMPL_H -#define PIPELINE_IMPL_H - -#include -#include - -#include "audio_data.h" -#include "element_factory.h" -#include "ielement.h" -#include "ipipeline.h" - -namespace OHOS { -namespace DistributedHardware { -class PipelineImpl : public IPipeline { -public: - PipelineImpl(PipeType pipeType); - ~PipelineImpl() = default; - virtual int32_t Init(const std::string config) override; - virtual int32_t StartUp() override; - virtual int32_t ShutDown() override; - virtual int32_t Release() override; - virtual int32_t FeedData(std::shared_ptr &inData, std::shared_ptr &outData) override; - int32_t BuildPipeStream(const std::list &config); - -private: - PipeType pipeType_; - std::shared_ptr sourceNode_ = nullptr; -}; -} // DistributedHardware -} // OHOS -#endif // PIPELINE_IMPL_H \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/audiopipeline/src/pipeline_impl.cpp b/services/audioprocessor/effectcomponent/audiopipeline/src/pipeline_impl.cpp deleted file mode 100644 index f7d96e5d33e6da1d2d3e68de1c8d9c90ebda4199..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/audiopipeline/src/pipeline_impl.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2023 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 "pipeline_impl.h" - -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "PipelineImpl" - -namespace OHOS { -namespace DistributedHardware { -PipelineImpl::PipelineImpl(PipeType pipeType) - : pipeType_(pipeType) -{ - DHLOGI("Pipeline is construct, type: %d.", pipeType_); -} - -int32_t PipelineImpl::Init(const std::string config) -{ - DHLOGI("Init pipeline."); - - if (sourceNode_ == nullptr) { - DHLOGE("Source node is null."); - return ERR_DH_AUDIO_NULLPTR; - } - sourceNode_->Init(config); - return DH_SUCCESS; -} - -int32_t PipelineImpl::StartUp() -{ - if (sourceNode_ == nullptr) { - DHLOGE("Source node is null."); - return ERR_DH_AUDIO_NULLPTR; - } - sourceNode_->StartUp(); - return DH_SUCCESS; -} - -int32_t PipelineImpl::ShutDown() -{ - if (sourceNode_ == nullptr) { - DHLOGE("Source node is null."); - return ERR_DH_AUDIO_NULLPTR; - } - sourceNode_->ShutDown(); - return DH_SUCCESS; -} - -int32_t PipelineImpl::Release() -{ - if (sourceNode_ == nullptr) { - DHLOGE("Source node is null."); - return ERR_DH_AUDIO_NULLPTR; - } - sourceNode_->Release(); - - return DH_SUCCESS; -} - -int32_t PipelineImpl::FeedData(std::shared_ptr &inData, std::shared_ptr &outData) -{ - if (sourceNode_ == nullptr) { - DHLOGE("Source node is null."); - return ERR_DH_AUDIO_NULLPTR; - } - return sourceNode_->PushData(inData, outData); -} - -int32_t PipelineImpl::BuildPipeStream(const std::list &config) -{ - auto elemFac = ElementFactory(); - std::shared_ptr currentNode = elemFac.CreateElement(ElementType::SOURCE); - if (currentNode == nullptr) { - DHLOGE("Create source element node failed."); - return ERR_DH_AUDIO_NULLPTR; - } - sourceNode_ = currentNode; - - for (auto iter = ++config.begin(); iter != config.end(); iter++) { - auto elemNode = elemFac.CreateElement(*iter); - if (currentNode == nullptr) { - DHLOGE("Current pipe stream contains null node."); - return ERR_DH_AUDIO_NULLPTR; - } - currentNode->AddDownStream(elemNode); - currentNode = elemNode; - } - return DH_SUCCESS; -} -} // DistributedHardware -} // OHOS \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/element_factoy/include/element_factory.h b/services/audioprocessor/effectcomponent/element_factoy/include/element_factory.h deleted file mode 100644 index e9849cf8ca5e38367a5f701d26a5564086f3d0a5..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/element_factoy/include/element_factory.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ELEMENT_FACTORY_H -#define ELEMENT_FACTORY_H - -#include - -#include "down_stream_element.h" - -namespace OHOS { -namespace DistributedHardware { -enum class ElementType { - UNKNOWN, - SOURCE, - REF_SINK, - MIC_SINK, - BUFFER_QUEUE, - RESAMPLER, - ECHO_CANSELLER, -}; - -class ElementFactory { -public: - ElementFactory() = default; - ~ElementFactory() = default; - std::shared_ptr CreateElement(enum ElementType elementType); -}; -} // DistributedHardware -} // OHOS -#endif // ELEMENT_FACTORY_H \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/element_factoy/src/element_factory.cpp b/services/audioprocessor/effectcomponent/element_factoy/src/element_factory.cpp deleted file mode 100644 index 4f6e08ce692a2dd3a0c206bc72c065b68de5edd6..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/element_factoy/src/element_factory.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2023 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 "element_factory.h" - -#include "daudio_errorcode.h" -#include "daudio_log.h" -#include "render_sink_element.h" -#include "source_element.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "ElementFactory" - -namespace OHOS { -namespace DistributedHardware { -std::shared_ptr ElementFactory::CreateElement(ElementType elementType) -{ - switch (elementType) { - case ElementType::SOURCE: - DHLOGI("Factory: creating source."); - return std::make_shared(); - case ElementType::REF_SINK: - DHLOGI("Factory: creating sink."); - return std::make_shared(); - case ElementType::MIC_SINK: - case ElementType::BUFFER_QUEUE: - case ElementType::RESAMPLER: - case ElementType::ECHO_CANSELLER: - default: - DHLOGE("This element type is not exist."); - break; - } - return nullptr; -} -} // DistributedHardware -} // OHOS \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/elements/include/capture_sink_element.h b/services/audioprocessor/effectcomponent/elements/include/capture_sink_element.h deleted file mode 100644 index 31eb55759432526233b606ed740fbd3fa2e03792..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/elements/include/capture_sink_element.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CAPTURE_SINK_ELEMENT_H -#define CAPTURE_SINK_ELEMENT_H - -#include "down_stream_element.h" - -namespace OHOS { -namespace DistributedHardware { - -class CaptureSinkElement : public DownStreamElement { -public: - CaptureSinkElement() = default; - ~CaptureSinkElement() = defualt; - int32_t Init(const std::string config) override; - int32_t StartUp() override; - int32_t ShutDown() override; - int32_t Release() override; - std::string GetType() override; - int32_t PushData(std::shared_ptr &inData, std::shared_ptr &outData) override; - -protected: - int32_t DoProcessData(std::shared_ptr &inData, std::shared_ptr &outData) override; - -private: - std::string elemType_ = SINK_MIC; -}; -} // OHOS -} // DistributedHardware -#endif // CAPTURE_SINK_ELEMENT_H diff --git a/services/audioprocessor/effectcomponent/elements/include/down_stream_element.h b/services/audioprocessor/effectcomponent/elements/include/down_stream_element.h deleted file mode 100644 index ffa56647a6b27fcce13858a4bbf0ef2c021e84c1..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/elements/include/down_stream_element.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DOWN_STREAM_ELEMENT_H -#define DOWN_STREAM_ELEMENT_H - -#include -#include - -#include "audio_data.h" -#include "ielement.h" - -namespace OHOS { -namespace DistributedHardware { -const std::string SOURCE_REF = "source_ref"; -const std::string SOURCE_MIC = "source_mic"; -const std::string SINK_REF = "sink_ref"; -const std::string SINK_MIC = "sink_mic"; -const std::string RESAMPLER = "resampler"; -const std::string AEC = "aec"; -const std::string BUFFER_QUEUE = "buffer_queue"; - -class DownStreamElement : public IElement { -public: - virtual ~DownStreamElement() {} - int32_t AddDownStream(const std::shared_ptr &element); -protected: - const std::unordered_set>& GetDownStreams(); - virtual int32_t DoProcessData(std::shared_ptr &inData, std::shared_ptr &outData) = 0; - -private: - std::unordered_set> downStreams_; -}; -} // DistributedHardware -} // OHOS -#endif // DOWN_STREAM_ELEMENT_H \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/elements/include/ielement.h b/services/audioprocessor/effectcomponent/elements/include/ielement.h deleted file mode 100644 index 40e5df345c03263f186e0c78750d0d820e65f83d..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/elements/include/ielement.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IELEMENT_H -#define IELEMENT_H - -#include -#include - -#include "audio_data.h" -#include "life_cycle.h" - -namespace OHOS { -namespace DistributedHardware { -class IElement : public ILifeCycle { -public: - virtual ~IElement() = default; - virtual std::string GetType() = 0; - virtual int32_t PushData(std::shared_ptr &inData, std::shared_ptr &outData) = 0; -}; -} // OHOS -} // DistributedHardware -#endif // IELEMENT_H \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/elements/include/render_sink_element.h b/services/audioprocessor/effectcomponent/elements/include/render_sink_element.h deleted file mode 100644 index baccefbe94636856415fcdd4f484d5e098b5c4c2..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/elements/include/render_sink_element.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef RENDER_SINK_ELEMENT_H -#define RENDER_SINK_ELEMENT_H - -#include "down_stream_element.h" - -namespace OHOS { -namespace DistributedHardware { - -class RenderSinkElement : public DownStreamElement { -public: - RenderSinkElement() = default; - ~RenderSinkElement() = default; - int32_t Init(const std::string config) override; - int32_t StartUp() override; - int32_t ShutDown() override; - int32_t Release() override; - std::string GetType() override; - int32_t PushData(std::shared_ptr &inData, std::shared_ptr &outData) override; - -protected: - int32_t DoProcessData(std::shared_ptr &inData, std::shared_ptr &outData) override; - -private: - std::string elemType_ = SINK_REF; -}; -} // OHOS -} // DistributedHardware -#endif // RENDER_SINK_ELEMENT_H \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/elements/include/source_element.h b/services/audioprocessor/effectcomponent/elements/include/source_element.h deleted file mode 100644 index 6023bae6c90ec3741cb41200acd19e0b2fd50fa2..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/elements/include/source_element.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SOURCE_ELEMENT_H -#define SOURCE_ELEMENT_H - -#include "down_stream_element.h" - -namespace OHOS { -namespace DistributedHardware { - -class SourceElement : public DownStreamElement { -public: - SourceElement() = default; - ~SourceElement() = default; - int32_t Init(const std::string config) override; - int32_t StartUp() override; - int32_t ShutDown() override; - int32_t Release() override; - std::string GetType() override; - int32_t PushData(std::shared_ptr &inData, std::shared_ptr &outData) override; - -protected: - int32_t DoProcessData(std::shared_ptr &inData, std::shared_ptr &outData) override; - -private: - std::string elemType_ = SOURCE_REF; -}; -} // OHOS -} // DistributedHardware -#endif // SOURCE_ELEMENT_H \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/elements/src/capture_sink_element.cpp b/services/audioprocessor/effectcomponent/elements/src/capture_sink_element.cpp deleted file mode 100644 index ccdc8674d6926770f2a29dfc0dc16c46da148f11..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/elements/src/capture_sink_element.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2023 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 "capture_sink_element.h" - -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "CaptureSinkElement" - -using namespace std; -namespace OHOS { -namespace DistributedHardware { -int32_t CaptureSinkElement::Init(const std::string config) -{ - DHLOGI("[init prcedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->Init(config); - if (ret != DH_SUCCESS) { - DHLOGE("Current node init failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -int32_t CaptureSinkElement::StartUp() -{ - DHLOGI("[startup prcedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->StartUp(); - if (ret != DH_SUCCESS) { - DHLOGE("Current node start up failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -int32_t CaptureSinkElement::ShutDown() -{ - DHLOGI("[shutdown prcedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->ShutDown(); - if (ret != DH_SUCCESS) { - DHLOGE("Current node shut down failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -int32_t CaptureSinkElement::Release() -{ - DHLOGI("[release prcedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->Release(); - if (ret != DH_SUCCESS) { - DHLOGE("Current node release failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} -std::string CaptureSinkElement::GetType() -{ - return elemType_; -} -int32_t CaptureSinkElement::PushData(std::shared_ptr &inData, std::shared_ptr &outData) -{ - std::shared_ptr tmpData; - int32_t ret = DoProcessData(inData, tmpData); - if (ret != DH_SUCCESS) { - DHLOGI("Current element process data failed."); - return ERR_DH_AUDIO_FAILED; - } - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - ret = obj->PushData(tmpData, outData); - if (ret != DH_SUCCESS) { - DHLOGE("Current node release failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} -int32_t CaptureSinkElement::DoProcessData(std::shared_ptr &inData, std::shared_ptr &outData) -{ - DHLOGI("Element of type: %s is processing data.", GetType().c_str()); - (void)inData; - (void)outData; - return DH_SUCCESS; -} -} // DistributedHardware -} // OHOS \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/elements/src/down_stream_element.cpp b/services/audioprocessor/effectcomponent/elements/src/down_stream_element.cpp deleted file mode 100644 index 5c1a00e88c36884e25febce04f92c87822da44ed..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/elements/src/down_stream_element.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2023 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 "down_stream_element.h" - -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "DownStreamElement" -namespace OHOS { -namespace DistributedHardware { -int32_t DownStreamElement::AddDownStream(const std::shared_ptr &element) -{ - downStreams_.insert(element); - return DH_SUCCESS; -} - -const std::unordered_set>& DownStreamElement::GetDownStreams() -{ - return downStreams_; -} -} // DistributedHardware -} // OHOS \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/elements/src/render_sink_element.cpp b/services/audioprocessor/effectcomponent/elements/src/render_sink_element.cpp deleted file mode 100644 index a6739eaf5154398e4b2153bfed1ca4e09018793a..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/elements/src/render_sink_element.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2023 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 "render_sink_element.h" - -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "RenderSinkElement" - -using namespace std; -namespace OHOS { -namespace DistributedHardware { -int32_t RenderSinkElement::Init(const std::string config) -{ - DHLOGI("[init procedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->Init(config); - if (ret != DH_SUCCESS) { - DHLOGE("Current node init failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -int32_t RenderSinkElement::StartUp() -{ - DHLOGI("[startup procedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->StartUp(); - if (ret != DH_SUCCESS) { - DHLOGE("Current node start up failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -int32_t RenderSinkElement::ShutDown() -{ - DHLOGI("[shutdown procedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->ShutDown(); - if (ret != DH_SUCCESS) { - DHLOGE("Current node shut down failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -int32_t RenderSinkElement::Release() -{ - DHLOGI("[release procedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->Release(); - if (ret != DH_SUCCESS) { - DHLOGE("Current node release failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -std::string RenderSinkElement::GetType() -{ - return elemType_; -} - -int32_t RenderSinkElement::PushData(std::shared_ptr &inData, std::shared_ptr &outData) -{ - std::shared_ptr tmpData; - int32_t ret = DoProcessData(inData, tmpData); - if (ret != DH_SUCCESS) { - DHLOGI("Current element process data failed."); - return ERR_DH_AUDIO_FAILED; - } - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - ret = obj->PushData(tmpData, outData); - if (ret != DH_SUCCESS) { - DHLOGE("Current node release failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -int32_t RenderSinkElement::DoProcessData(std::shared_ptr &inData, std::shared_ptr &outData) -{ - DHLOGI("Element of type: %s is processing data.", GetType().c_str()); - (void)inData; - (void)outData; - return DH_SUCCESS; -} -} // DistributedHardware -} // OHOS \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/elements/src/source_element.cpp b/services/audioprocessor/effectcomponent/elements/src/source_element.cpp deleted file mode 100644 index 74ceaf48834932d19d875127c0a420fe60ea7286..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/elements/src/source_element.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2023 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 "source_element.h" - -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "SourceElement" - -namespace OHOS { -namespace DistributedHardware { -int32_t SourceElement::Init(std::string config) -{ - DHLOGI("[init procedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->Init(config); - if (ret != DH_SUCCESS) { - DHLOGE("Current node init failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -int32_t SourceElement::StartUp() -{ - DHLOGI("[startup procedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->StartUp(); - if (ret != DH_SUCCESS) { - DHLOGE("Current node start up failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -int32_t SourceElement::ShutDown() -{ - DHLOGI("[shutdown procedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->ShutDown(); - if (ret != DH_SUCCESS) { - DHLOGE("Current node shut down failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -int32_t SourceElement::Release() -{ - DHLOGI("[release procedure] : %s", GetType().c_str()); - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = obj->Release(); - if (ret != DH_SUCCESS) { - DHLOGE("Current node release failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -std::string SourceElement::GetType() -{ - return elemType_; -} - -int32_t SourceElement::PushData(std::shared_ptr &inData, std::shared_ptr &outData) -{ - std::shared_ptr tmpData; - int32_t ret = DoProcessData(inData, tmpData); - if (ret != DH_SUCCESS) { - DHLOGI("Current element process data failed."); - return ERR_DH_AUDIO_FAILED; - } - for (auto &&obj : GetDownStreams()) { - if (obj == nullptr) { - DHLOGE("Next node is null, type: %d.", GetType().c_str()); - return ERR_DH_AUDIO_NULLPTR; - } - ret = obj->PushData(tmpData, outData); - if (ret != DH_SUCCESS) { - DHLOGE("Current node release failed."); - return ERR_DH_AUDIO_FAILED; - } - } - return DH_SUCCESS; -} - -int32_t SourceElement::DoProcessData(std::shared_ptr &inData, std::shared_ptr &outData) -{ - DHLOGI("Element of type: %s is processing data.", GetType().c_str()); - (void)inData; - (void)outData; - return DH_SUCCESS; -} -} // DistributedHardware -} // OHOS \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/pipelinemanager/include/pipeline_manager.h b/services/audioprocessor/effectcomponent/pipelinemanager/include/pipeline_manager.h deleted file mode 100644 index 8ee8f53bd3f39e694282e618ba1af9776a446d55..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/pipelinemanager/include/pipeline_manager.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DAUDIO_EFFECT_COMPONENT_H -#define DAUDIO_EFFECT_COMPONENT_H - -#include -#include -#include - -#include "element_factory.h" -#include "ipipeline.h" -#include "single_instance.h" - -namespace OHOS { -namespace DistributedHardware { -constexpr int32_t ERR_PIPE_ID = -1; -constexpr int32_t INITIAL_PIPE_ID = -1; -constexpr int32_t MAX_PIPELINE_SIZE = 1000000; - -class PipelineManager { - DECLARE_SINGLE_INSTANCE_BASE(PipelineManager); -public: - int32_t CreatePipeline(const PipeType &pipeType, const std::list &config, - std::shared_ptr &pipe); - int32_t ClearPipeline(int32_t pipeId); - -private: - PipelineManager() = default; - ~PipelineManager() = default; - int32_t GeneratePipeId(); - bool CheckPipeConfig(const std::list &config); - -private: - std::map> mapPipelines_; -}; -} // DistributedHardware -} // OHOS -#endif // DAUDIO_EFFECT_COMPONENT_H \ No newline at end of file diff --git a/services/audioprocessor/effectcomponent/pipelinemanager/src/pipeline_manager.cpp b/services/audioprocessor/effectcomponent/pipelinemanager/src/pipeline_manager.cpp deleted file mode 100644 index 9f7b1495579d3edaeecca857fc0e29045bf44b9b..0000000000000000000000000000000000000000 --- a/services/audioprocessor/effectcomponent/pipelinemanager/src/pipeline_manager.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2023 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 "pipeline_manager.h" - -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#include "ipipeline.h" -#include "pipeline_impl.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "PipelineManager" -namespace OHOS { -namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(PipelineManager); - -int32_t PipelineManager::CreatePipeline(const PipeType &pipeType, - const std::list &config, std::shared_ptr &pipe) -{ - DHLOGI("Pipeline is creating, type: %d", static_cast(pipeType)); - if (CheckPipeConfig(config) != true) { - DHLOGE("Pipeline config error."); - return ERR_PIPE_ID; - } - auto pipeImpl = std::make_shared(pipeType); - if (pipeImpl == nullptr) { - DHLOGE("Creating pipeline failed."); - return ERR_PIPE_ID; - } - int32_t ret = pipeImpl->BuildPipeStream(config); - if (ret != DH_SUCCESS) { - DHLOGE("Build pipe stream failed."); - return ERR_PIPE_ID; - } - - pipe = pipeImpl; - int32_t pipeId = GeneratePipeId(); - if (pipeId == ERR_PIPE_ID) { - DHLOGE("Pipeline ID generated error."); - return ERR_PIPE_ID; - } - mapPipelines_[pipeId] = pipe; - return pipeId; -} - -int32_t PipelineManager::ClearPipeline(int32_t pipeId) -{ - DHLOGI("Clearing pipeline."); - auto ret = mapPipelines_.find(pipeId); - if (ret == mapPipelines_.end()) { - DHLOGE("pipe ID is not exist."); - return ERR_DH_AUDIO_FAILED; - } - mapPipelines_.erase(pipeId); - return DH_SUCCESS; -} - -int32_t PipelineManager::GeneratePipeId() -{ - static int32_t pipeId = INITIAL_PIPE_ID; - ++pipeId; - if (pipeId > MAX_PIPELINE_SIZE) { - DHLOGE("Pipe number is out the max size."); - return ERR_PIPE_ID; - } - return pipeId; -} - -bool PipelineManager::CheckPipeConfig(const std::list &config) -{ - DHLOGI("Checking pipeline's configure."); - if (config.front() != ElementType::SOURCE) { - return false; - } - if (config.back() != ElementType::REF_SINK && config.back() != ElementType::MIC_SINK) { - return false; - } - return true; -} -} // DistributedHardware -} // OHOS \ No newline at end of file diff --git a/services/audioprocessor/lowlatencyprocessor/include/audio_lowlatency_processor.h b/services/audioprocessor/lowlatencyprocessor/include/audio_lowlatency_processor.h deleted file mode 100644 index 9f7650444d395bff8ad03df5b3e76bb6b7a256c4..0000000000000000000000000000000000000000 --- a/services/audioprocessor/lowlatencyprocessor/include/audio_lowlatency_processor.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_IAUDIO_LOWLATENCY_PROCESSOR_H -#define OHOS_IAUDIO_LOWLATENCY_PROCESSOR_H - -#include - -#include "audio_data.h" -#include "audio_event.h" -#include "audio_param.h" -#include "iaudio_codec.h" -#include "iaudio_codec_callback.h" -#include "iaudio_processor.h" -#include "iaudio_processor_callback.h" - -namespace OHOS { -namespace DistributedHardware { -class AudioLowlatencyProcessor : public IAudioProcessor, - public std::enable_shared_from_this { -public: - AudioLowlatencyProcessor() = default; - ~AudioLowlatencyProcessor() = default; - - int32_t ConfigureAudioProcessor(const AudioCommonParam &localDevParam, const AudioCommonParam &remoteDevParam, - const std::shared_ptr &procCallback) override; - int32_t ReleaseAudioProcessor() override; - int32_t StartAudioProcessor() override; - int32_t StopAudioProcessor() override; - int32_t FeedAudioProcessor(const std::shared_ptr &inputData) override; - -private: - std::weak_ptr procCallback_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_IAUDIO_ENCODER_PROCESSOR_H diff --git a/services/audioprocessor/lowlatencyprocessor/src/audio_lowlatency_processor.cpp b/services/audioprocessor/lowlatencyprocessor/src/audio_lowlatency_processor.cpp deleted file mode 100644 index 2aa587c214c98f5633c2a607588a58222516464b..0000000000000000000000000000000000000000 --- a/services/audioprocessor/lowlatencyprocessor/src/audio_lowlatency_processor.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "audio_lowlatency_processor.h" - -#include "daudio_constants.h" -#include "daudio_errorcode.h" -#include "daudio_hisysevent.h" -#include "daudio_hitrace.h" -#include "daudio_log.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioLowlatencyProcessor" - -namespace OHOS { -namespace DistributedHardware { -int32_t AudioLowlatencyProcessor::ConfigureAudioProcessor(const AudioCommonParam &localDevParam, - const AudioCommonParam &remoteDevParam, const std::shared_ptr &procCallback) -{ - DHLOGI("Configure audio processor."); - if (procCallback == nullptr) { - DHLOGE("Processor callback is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - procCallback_ = procCallback; - DHLOGI("Frame size is not default 4096, do not need to config audio processor."); - return DH_SUCCESS; -} - -int32_t AudioLowlatencyProcessor::ReleaseAudioProcessor() -{ - DHLOGI("Release audio processor."); - return DH_SUCCESS; -} - -int32_t AudioLowlatencyProcessor::StartAudioProcessor() -{ - DHLOGI("Start audio processor."); - return DH_SUCCESS; -} - -int32_t AudioLowlatencyProcessor::StopAudioProcessor() -{ - DHLOGI("Stop audio processor."); - return DH_SUCCESS; -} - -int32_t AudioLowlatencyProcessor::FeedAudioProcessor(const std::shared_ptr &inputData) -{ - DHLOGD("Feed audio processor."); - if (inputData == nullptr) { - DHLOGE("Input data is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - auto cbObj = procCallback_.lock(); - if (cbObj == nullptr) { - DHLOGE("Processor callback is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - cbObj->OnAudioDataDone(inputData); - return DH_SUCCESS; -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/audioprocessor/test/unittest/BUILD.gn b/services/audioprocessor/test/unittest/BUILD.gn index 350ef0eb85bd5dcbc5fe7e5ea38486a66f054fb3..5954b958e58f8ef913b2064f74b5c11913300367 100644 --- a/services/audioprocessor/test/unittest/BUILD.gn +++ b/services/audioprocessor/test/unittest/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") group("daudio_processor_test") { testonly = true diff --git a/services/audioprocessor/test/unittest/common/decodeprocessor/BUILD.gn b/services/audioprocessor/test/unittest/common/decodeprocessor/BUILD.gn index 563703ad2765dc5931fc5793feb55f9621be0cea..2217620a5630dfa385990729d73af597b1b27797 100644 --- a/services/audioprocessor/test/unittest/common/decodeprocessor/BUILD.gn +++ b/services/audioprocessor/test/unittest/common/decodeprocessor/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") module_output_path = "distributed_audio/services/audioprocessor/decode_processor_test" diff --git a/services/audioprocessor/test/unittest/common/decodeprocessor/decoder_test.cpp b/services/audioprocessor/test/unittest/common/decodeprocessor/decoder_test.cpp index db6f5ab3d00a51e363471abb255f6a062fb16063..36741443078365b2a0b9a11dce5792a3cc43ec7e 100644 --- a/services/audioprocessor/test/unittest/common/decodeprocessor/decoder_test.cpp +++ b/services/audioprocessor/test/unittest/common/decodeprocessor/decoder_test.cpp @@ -75,6 +75,7 @@ HWTEST_F(DecoderTest, decode_test_001, TestSize.Level1) { EXPECT_EQ(DH_SUCCESS, audiodecoder_->ConfigureAudioCodec(LOC_COMPARA_ENC_TEST, decodeCb_)); audiodecoder_ = std::make_shared(); + EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audiodecoder_->ConfigureAudioCodec(LOC_COMPARA_ENC_TEST, nullptr)); } /** @@ -211,5 +212,30 @@ HWTEST_F(DecoderTest, ProcessData_001, TestSize.Level1) EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audiodecoder_->ProcessData(inputData, bufferIndex)); audiodecoder_->OnOutputBufferAvailable(index, info, flag); } + +/** + * @tc.name: IsInDecodeRange_001 + * @tc.desc: Verify IsInDecodeRange function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DecoderTest, IsInDecodeRange_001, TestSize.Level1) +{ + AudioCommonParam codecParam; + EXPECT_EQ(false, audiodecoder_->IsInDecodeRange(codecParam)); +} + +/** + * @tc.name: IsInDecodeRange_002 + * @tc.desc: Verify IsInDecodeRange function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DecoderTest, IsInDecodeRange_002, TestSize.Level1) +{ + AudioCommonParam codecParam; + codecParam.bitFormat = SAMPLE_S16LE; + EXPECT_EQ(true, audiodecoder_->IsInDecodeRange(codecParam)); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audioprocessor/test/unittest/common/encodeprocessor/BUILD.gn b/services/audioprocessor/test/unittest/common/encodeprocessor/BUILD.gn index d6c6e124e16c138693cb8234ff96d842c196fab5..d8e50fe23a1b311d6ccba70f4fb931f1e48bee33 100644 --- a/services/audioprocessor/test/unittest/common/encodeprocessor/BUILD.gn +++ b/services/audioprocessor/test/unittest/common/encodeprocessor/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") module_output_path = "distributed_audio/services/audioprocessor/encode_processor_test" diff --git a/services/audioprocessor/test/unittest/common/encodeprocessor/encoder_test.cpp b/services/audioprocessor/test/unittest/common/encodeprocessor/encoder_test.cpp index 3e0d81dcc9c4e9166ee0d37450e204a17f4880b9..8e08c02f15772c720a49113e6e9736e157f38106 100644 --- a/services/audioprocessor/test/unittest/common/encodeprocessor/encoder_test.cpp +++ b/services/audioprocessor/test/unittest/common/encodeprocessor/encoder_test.cpp @@ -75,6 +75,7 @@ HWTEST_F(EncoderTest, encode_test_001, TestSize.Level1) { EXPECT_EQ(DH_SUCCESS, audioEncoder_->ConfigureAudioCodec(LOC_COMPARA_ENC_TEST, encodeCb_)); audioEncoder_ = std::make_shared(); + EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audioEncoder_->ConfigureAudioCodec(LOC_COMPARA_ENC_TEST, nullptr)); } /** diff --git a/services/audiotransport/audiochannel/audiodatachannel/BUILD.gn b/services/audiotransport/audiochannel/audiodatachannel/BUILD.gn index ec33274ade8f8b1e9255b7a72b99089f46f5fb0d..ebf19ad8ad495e2a784712402255b44e96e6e4bc 100644 --- a/services/audiotransport/audiochannel/audiodatachannel/BUILD.gn +++ b/services/audiotransport/audiochannel/audiodatachannel/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") ohos_shared_library("distributed_audio_data_channel") { include_dirs = [ diff --git a/services/audiotransport/audioctrltransport/BUILD.gn b/services/audiotransport/audioctrltransport/BUILD.gn index 3b56c31f4b2846656e0cfb3a920d626f46b52fa5..863e5953dc1046c3f4b4ba0d88319e25222cd599 100644 --- a/services/audiotransport/audioctrltransport/BUILD.gn +++ b/services/audiotransport/audioctrltransport/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../distributedaudio.gni") ohos_shared_library("distributed_audio_control") { include_dirs = [ @@ -37,9 +36,9 @@ ohos_shared_library("distributed_audio_control") { "${audio_transport_path}/audiochannel/audioctrlchannel/include", ] - sources = [ - "src/audio_ctrl_transport.cpp", + sources = [ "${audio_transport_path}/audiochannel/audioctrlchannel/src/audio_ctrl_channel.cpp", + "src/audio_ctrl_transport.cpp", ] deps = [ diff --git a/services/audiotransport/audiotransportstatus/BUILD.gn b/services/audiotransport/audiotransportstatus/BUILD.gn index 9678df294801198f2d4b1964c11d13fad874b99b..f877bd1fa892d052731baf16b48e58cd33484a48 100644 --- a/services/audiotransport/audiotransportstatus/BUILD.gn +++ b/services/audiotransport/audiotransportstatus/BUILD.gn @@ -1,73 +1,71 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") - -ohos_shared_library("distributed_audio_transport_status") { - include_dirs = [ - "//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include", - "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter", - "//foundation/communication/dsoftbus/interfaces/kits/transport", - "${fwk_common_path}/utils/include", - "${mediastandard_path}/interfaces/innerkits/native/media/include", - "${mediastandardfwk_path}/audiocommon/include", - "//third_party/json/include", - ] - - include_dirs += [ - "include", - "interface", - "${common_path}/include", - "${audio_processor_path}/decoder/include", - "${audio_processor_path}/decodeprocessor/include", - "${audio_processor_path}/interface", - "${audio_transport_path}/audiochannel/interface", - "${audio_transport_path}/audiochannel/audiodatachannel/include", - "${audio_transport_path}/audiotransportstatus/include", - "${audio_transport_path}/audiotransportstatus/interface", - "${audio_transport_path}/audiotransportstatus/interface", - "${services_path}/common/audioparam", - "${services_path}/common/audiodata/include", - ] - - sources = [ - "${audio_transport_path}/audiotransportstatus/src/audio_transport_context.cpp", - "${audio_transport_path}/audiotransportstatus/src/audio_transport_pause_status.cpp", - "${audio_transport_path}/audiotransportstatus/src/audio_transport_start_status.cpp", - "${audio_transport_path}/audiotransportstatus/src/audio_transport_status_factory.cpp", - "${audio_transport_path}/audiotransportstatus/src/audio_transport_stop_status.cpp", - ] - - deps = [ - "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "hitrace_native:hitrace_meter", - "multimedia_player_framework:media_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "LOG_DOMAIN=0xD004100", - ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_audio" -} +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos_var.gni") +import("../../../distributedaudio.gni") + +ohos_shared_library("distributed_audio_transport_status") { + include_dirs = [ + "${fwk_common_path}/utils/include", + "${mediastandard_path}/interfaces/innerkits/native/media/include", + "${mediastandardfwk_path}/audiocommon/include", + "//third_party/json/include", + ] + + include_dirs += [ + "include", + "interface", + "${common_path}/include", + "${audio_processor_path}/decoder/include", + "${audio_processor_path}/decodeprocessor/include", + "${audio_processor_path}/interface", + "${audio_transport_path}/audiochannel/interface", + "${audio_transport_path}/audiochannel/audiodatachannel/include", + "${audio_transport_path}/audiotransportstatus/include", + "${audio_transport_path}/audiotransportstatus/interface", + "${audio_transport_path}/audiotransportstatus/interface", + "${services_path}/common/audioparam", + "${services_path}/common/audiodata/include", + ] + + sources = [ + "${audio_transport_path}/audiotransportstatus/src/audio_transport_context.cpp", + "${audio_transport_path}/audiotransportstatus/src/audio_transport_pause_status.cpp", + "${audio_transport_path}/audiotransportstatus/src/audio_transport_start_status.cpp", + "${audio_transport_path}/audiotransportstatus/src/audio_transport_status_factory.cpp", + "${audio_transport_path}/audiotransportstatus/src/audio_transport_stop_status.cpp", + ] + + deps = [ + "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "dsoftbus:softbus_client", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "multimedia_player_framework:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "LOG_DOMAIN=0xD004100", + ] + + subsystem_name = "distributedhardware" + + part_name = "distributed_audio" +} diff --git a/services/audiotransport/decodetransport/BUILD.gn b/services/audiotransport/decodetransport/BUILD.gn index 14703c9e794a0a8f69806e9868254aa57f6b75e1..2c920c4ddf678d1f83873cbbd81e57978c147e20 100644 --- a/services/audiotransport/decodetransport/BUILD.gn +++ b/services/audiotransport/decodetransport/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../distributedaudio.gni") ohos_shared_library("distributed_audio_decode_transport") { include_dirs = [ @@ -33,7 +32,6 @@ ohos_shared_library("distributed_audio_decode_transport") { "${common_path}/dfx_utils/include", "${audio_processor_path}/decoder/include", "${audio_processor_path}/decodeprocessor/include", - "${audio_processor_path}/lowlatencyprocessor/include", "${audio_processor_path}/interface", "${audio_transport_path}/audiochannel/interface", "${audio_transport_path}/audiochannel/audiodatachannel/include", @@ -46,12 +44,11 @@ ohos_shared_library("distributed_audio_decode_transport") { ] sources = [ - "src/audio_decode_transport.cpp", + "${audio_processor_path}/decodeprocessor/src/audio_decoder_processor.cpp", "${audio_processor_path}/decoder/src/audio_decoder.cpp", "${audio_processor_path}/decoder/src/audio_decoder_callback.cpp", - "${audio_processor_path}/decodeprocessor/src/audio_decoder_processor.cpp", - "${audio_processor_path}/lowlatencyprocessor/src/audio_lowlatency_processor.cpp", "${services_path}/common/audiodata/src/audio_data.cpp", + "src/audio_decode_transport.cpp", ] deps = [ diff --git a/services/audiotransport/decodetransport/include/audio_decode_transport.h b/services/audiotransport/decodetransport/include/audio_decode_transport.h index f743575426b34b6be3e01c28dae0d0f475c37751..1ff3e7795ca60bdf6a68e623df8c93831bd309fb 100644 --- a/services/audiotransport/decodetransport/include/audio_decode_transport.h +++ b/services/audiotransport/decodetransport/include/audio_decode_transport.h @@ -70,7 +70,6 @@ private: private: static constexpr size_t DATA_QUEUE_MAX_SIZE = 10; static constexpr size_t SLEEP_TIME = 20000; - static constexpr int32_t MMAP_FLAG = 1; std::weak_ptr dataTransCallback_; std::shared_ptr audioChannel_ = nullptr; diff --git a/services/audiotransport/decodetransport/src/audio_decode_transport.cpp b/services/audiotransport/decodetransport/src/audio_decode_transport.cpp index 22519b5cb6f49a75f3a5735e46d99dd11638474c..ce6bd135b33ee3fed2f081fad830d1e31f510ba9 100644 --- a/services/audiotransport/decodetransport/src/audio_decode_transport.cpp +++ b/services/audiotransport/decodetransport/src/audio_decode_transport.cpp @@ -17,7 +17,6 @@ #include "audio_data_channel.h" #include "audio_decoder_processor.h" -#include "audio_lowlatency_processor.h" #include "audio_param.h" #include "daudio_errorcode.h" #include "daudio_log.h" @@ -238,13 +237,7 @@ int32_t AudioDecodeTransport::RegisterChannelListener(const PortCapType capType) int32_t AudioDecodeTransport::RegisterProcessorListener(const AudioParam &localParam, const AudioParam &remoteParam) { DHLOGI("Register processor listener."); - if (localParam.renderOpts.renderFlags == MMAP_FLAG || localParam.captureOpts.capturerFlags == MMAP_FLAG) { - DHLOGE("Decode trans low-latency mode. renderFlags: %d, captureFlags: %d", - localParam.renderOpts.renderFlags, localParam.captureOpts.capturerFlags); - processor_ = std::make_shared(); - } else { - processor_ = std::make_shared(); - } + processor_ = std::make_shared(); int32_t ret = processor_->ConfigureAudioProcessor(localParam.comParam, remoteParam.comParam, shared_from_this()); if (ret != DH_SUCCESS) { DHLOGE("Configure audio processor failed."); diff --git a/services/audiotransport/encodetransport/BUILD.gn b/services/audiotransport/encodetransport/BUILD.gn index ad9274843aa7c492d2fde9f389543587bdeebe04..7dbd57b4cb5342c44e6b3f9dc770c310c40430d0 100644 --- a/services/audiotransport/encodetransport/BUILD.gn +++ b/services/audiotransport/encodetransport/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../distributedaudio.gni") ohos_shared_library("distributed_audio_encode_transport") { include_dirs = [ @@ -32,7 +31,6 @@ ohos_shared_library("distributed_audio_encode_transport") { "${common_path}/include", "${common_path}/dfx_utils/include", "${audio_processor_path}/encodeprocessor/include", - "${audio_processor_path}/lowlatencyprocessor/include", "${audio_processor_path}/encoder/include", "${audio_processor_path}/interface", "${audio_transport_path}/audiochannel/interface", @@ -46,12 +44,11 @@ ohos_shared_library("distributed_audio_encode_transport") { ] sources = [ - "src/audio_encode_transport.cpp", "${audio_processor_path}/encodeprocessor/src/audio_encoder_processor.cpp", - "${audio_processor_path}/lowlatencyprocessor/src/audio_lowlatency_processor.cpp", "${audio_processor_path}/encoder/src/audio_encoder.cpp", "${audio_processor_path}/encoder/src/audio_encoder_callback.cpp", "${services_path}/common/audiodata/src/audio_data.cpp", + "src/audio_encode_transport.cpp", ] deps = [ @@ -66,7 +63,6 @@ ohos_shared_library("distributed_audio_encode_transport") { "multimedia_player_framework:media_client", ] - defines = [ "HI_LOG_ENABLE", "LOG_DOMAIN=0xD004100", diff --git a/services/audiotransport/encodetransport/include/audio_encode_transport.h b/services/audiotransport/encodetransport/include/audio_encode_transport.h index 0c3930486d7396df6214d7a90b7d4d878fcea0da..7616081c569e9bffc0512a542ce67b072688f127 100644 --- a/services/audiotransport/encodetransport/include/audio_encode_transport.h +++ b/services/audiotransport/encodetransport/include/audio_encode_transport.h @@ -64,7 +64,6 @@ private: private: static const constexpr uint8_t SESSION_WAIT_SECONDS = 5; - static constexpr int32_t MMAP_FLAG = 1; std::weak_ptr dataTransCallback_; std::shared_ptr audioChannel_ = nullptr; diff --git a/services/audiotransport/encodetransport/src/audio_encode_transport.cpp b/services/audiotransport/encodetransport/src/audio_encode_transport.cpp index c84c11c1edc27a46e64b3597b22d072f648e3b8c..8f1bcbf6fa25b1601514ce7c3e45957bfa1e91cf 100644 --- a/services/audiotransport/encodetransport/src/audio_encode_transport.cpp +++ b/services/audiotransport/encodetransport/src/audio_encode_transport.cpp @@ -17,7 +17,6 @@ #include "audio_data_channel.h" #include "audio_encoder_processor.h" -#include "audio_lowlatency_processor.h" #include "audio_param.h" #include "daudio_errorcode.h" #include "daudio_log.h" @@ -188,13 +187,7 @@ int32_t AudioEncodeTransport::RegisterChannelListener(const PortCapType capType) int32_t AudioEncodeTransport::RegisterProcessorListener(const AudioParam &localParam, const AudioParam &remoteParam) { DHLOGI("Register processor listener."); - if (localParam.renderOpts.renderFlags == MMAP_FLAG || localParam.captureOpts.capturerFlags == MMAP_FLAG) { - DHLOGE("Encode trans low-latency mode. renderFlags: %d, captureFlags: %d", - localParam.renderOpts.renderFlags, localParam.captureOpts.capturerFlags); - processor_ = std::make_shared(); - } else { - processor_ = std::make_shared(); - } + processor_ = std::make_shared(); if (audioChannel_ == nullptr) { DHLOGE("Create audio processor failed."); return ERR_DH_AUDIO_TRANS_ERROR; diff --git a/services/audiotransport/test/unittest/BUILD.gn b/services/audiotransport/test/unittest/BUILD.gn index 3b18ab01dab860c66fcd4374c4449e4bd82a6b3a..9df9215adc4ab79a63fdf7b74960ee047e5ffedf 100644 --- a/services/audiotransport/test/unittest/BUILD.gn +++ b/services/audiotransport/test/unittest/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") group("daudio_transport_test") { testonly = true @@ -22,8 +21,8 @@ group("daudio_transport_test") { "${audio_transport_path}/test/unittest/audioctrlchannel:audio_ctrl_channel_test", "${audio_transport_path}/test/unittest/audioctrltransport:audio_ctrl_transport_test", "${audio_transport_path}/test/unittest/audiodatachannel:audio_data_channel_test", + "${audio_transport_path}/test/unittest/audiotransportstatus:transport_status_test", "${audio_transport_path}/test/unittest/decodetransport:decode_transport_test", "${audio_transport_path}/test/unittest/encodetransport:encode_transport_test", - "${audio_transport_path}/test/unittest/audiotransportstatus:transport_status_test", ] } diff --git a/services/audiotransport/test/unittest/audioctrlchannel/BUILD.gn b/services/audiotransport/test/unittest/audioctrlchannel/BUILD.gn index f2d152c7b07b174d37455e1768b2c602376b2f5f..5f2a8b4148705c086c3ca77cde34b326ce9f8de7 100644 --- a/services/audiotransport/test/unittest/audioctrlchannel/BUILD.gn +++ b/services/audiotransport/test/unittest/audioctrlchannel/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audiotransport/audio_ctrl_channel_test" @@ -50,8 +49,8 @@ ohos_unittest("AudioCtrlChannelTest") { configs = [ ":module_private_config" ] deps = [ - "${services_path}/common:distributed_audio_utils", "${audio_transport_path}/audioctrltransport:distributed_audio_control", + "${services_path}/common:distributed_audio_utils", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", ] diff --git a/services/audiotransport/test/unittest/audioctrlchannel/src/audio_ctrl_channel_test.cpp b/services/audiotransport/test/unittest/audioctrlchannel/src/audio_ctrl_channel_test.cpp index b36c33308fb5113c901cebc7f99d3e628ab7f437..a80a315c715240826dec35758d8a894886ff75fe 100644 --- a/services/audiotransport/test/unittest/audioctrlchannel/src/audio_ctrl_channel_test.cpp +++ b/services/audiotransport/test/unittest/audioctrlchannel/src/audio_ctrl_channel_test.cpp @@ -133,12 +133,12 @@ HWTEST_F(AudioCtrlChannelTest, OnSessionClosed_001, TestSize.Level1) } /** - * @tc.name: OnBytesReceived_001 - * @tc.desc: Verify the OnBytesReceived function. + * @tc.name: SendMsg_001 + * @tc.desc: Verify the SendMsg function. * @tc.type: FUNC * @tc.require: AR000H0E5U */ -HWTEST_F(AudioCtrlChannelTest, OnBytesReceived_001, TestSize.Level1) +HWTEST_F(AudioCtrlChannelTest, SendMsg_001, TestSize.Level1) { std::shared_ptr listener = std::make_shared(); ctrlChannel_->channelListener_ = listener; @@ -155,6 +155,9 @@ HWTEST_F(AudioCtrlChannelTest, OnBytesReceived_001, TestSize.Level1) StreamData *ext; StreamFrameInfo *streamFrameInfo; ctrlChannel_->OnStreamReceived(sessionId, datas, ext, streamFrameInfo); + + string message = "sendMag"; + EXPECT_NE(ERR_DH_AUDIO_CTRL_CHANNEL_SEND_MSG_FAIL, ctrlChannel_->SendMsg(message)); } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiotransport/test/unittest/audioctrltransport/BUILD.gn b/services/audiotransport/test/unittest/audioctrltransport/BUILD.gn index a8ab114fc427de018601bf698b46c6714944c7bc..98a9b97996f724ec4aa5cd1eda6403d86edbfc2a 100644 --- a/services/audiotransport/test/unittest/audioctrltransport/BUILD.gn +++ b/services/audiotransport/test/unittest/audioctrltransport/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audiotransport/audio_ctrl_transport_test" diff --git a/services/audiotransport/test/unittest/audioctrltransport/src/audio_ctrl_transport_test.cpp b/services/audiotransport/test/unittest/audioctrltransport/src/audio_ctrl_transport_test.cpp index 85f85bbc631de2c30fbe3cf26be9b0908b4abcd8..db02da256061c56b73bea9997cc76d33a6335f71 100644 --- a/services/audiotransport/test/unittest/audioctrltransport/src/audio_ctrl_transport_test.cpp +++ b/services/audiotransport/test/unittest/audioctrltransport/src/audio_ctrl_transport_test.cpp @@ -88,6 +88,7 @@ HWTEST_F(AudioCtrlTransportTest, Release_002, TestSize.Level1) */ HWTEST_F(AudioCtrlTransportTest, Start_001, TestSize.Level1) { + trans->OnSessionOpened(); EXPECT_EQ(ERR_DH_AUDIO_TRANS_NULL_VALUE, trans->Start()); } @@ -112,6 +113,9 @@ HWTEST_F(AudioCtrlTransportTest, Start_002, TestSize.Level1) */ HWTEST_F(AudioCtrlTransportTest, Stop_001, TestSize.Level1) { + AudioEvent event; + trans->OnEventReceived(event); + trans->OnSessionClosed(); EXPECT_EQ(DH_SUCCESS, trans->Stop()); } @@ -179,5 +183,19 @@ HWTEST_F(AudioCtrlTransportTest, RegisterChannelListener_002, TestSize.Level1) std::shared_ptr listener = std::make_shared(); EXPECT_EQ(DH_SUCCESS, trans->RegisterChannelListener()); } + +/** + * @tc.name: InitAudioCtrlTrans_002 + * @tc.desc: Verify the InitAudioCtrlTrans function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(AudioCtrlTransportTest, InitAudioCtrlTrans_002, TestSize.Level1) +{ + std::string peerDevId = "peerDevId"; + const std::string netWorkId = "netWorkId"; + trans->audioChannel_ = std::make_shared(peerDevId); + EXPECT_EQ(DH_SUCCESS, trans->InitAudioCtrlTrans(netWorkId)); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiotransport/test/unittest/audiodatachannel/BUILD.gn b/services/audiotransport/test/unittest/audiodatachannel/BUILD.gn index cce8e1ca7bb191755780f36471c011ec3fc1f55f..144688b1bab6290f71c4f96ff2cb5f4cb87b5ab3 100644 --- a/services/audiotransport/test/unittest/audiodatachannel/BUILD.gn +++ b/services/audiotransport/test/unittest/audiodatachannel/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/audiotransport/audio_data_channel_test" diff --git a/services/audiotransport/test/unittest/audiodatachannel/src/audio_data_channel_test.cpp b/services/audiotransport/test/unittest/audiodatachannel/src/audio_data_channel_test.cpp index 28c8f393dedc01d9a65f1711c3daf32df81e892e..ee04f28db3677eac47e9a4af33f917d8ef89078e 100644 --- a/services/audiotransport/test/unittest/audiodatachannel/src/audio_data_channel_test.cpp +++ b/services/audiotransport/test/unittest/audiodatachannel/src/audio_data_channel_test.cpp @@ -81,6 +81,7 @@ HWTEST_F(AudioDataChannelTest, OpenSession_002, TestSize.Level1) dataChannel_->OnStreamReceived(sessionIdTmp, &data, ext, param); delete[] data.buf; + EXPECT_NE(DH_SUCCESS, dataChannel_->CreateSession(channelListener, DATA_SPEAKER_SESSION_NAME)); EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, dataChannel_->OpenSession()); EXPECT_EQ(DH_SUCCESS, dataChannel_->CloseSession()); } diff --git a/services/audiotransport/test/unittest/audiotransportstatus/BUILD.gn b/services/audiotransport/test/unittest/audiotransportstatus/BUILD.gn index 4564fd4b51ac22143beb5f0ef4c951098f5e0b62..27a29a3bd978f0aa977205646811ec241ff68d91 100644 --- a/services/audiotransport/test/unittest/audiotransportstatus/BUILD.gn +++ b/services/audiotransport/test/unittest/audiotransportstatus/BUILD.gn @@ -1,79 +1,78 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") - -module_output_path = - "distributed_audio/services/audiotransport/transport_status_test" - -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include", - "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter", - "//foundation/communication/dsoftbus/interfaces/kits/transport", - "${fwk_common_path}/utils/include", - "${mediastandard_path}/interfaces/innerkits/native/media/include", - "${mediastandardfwk_path}/audiocommon/include", - "//third_party/json/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_processor_path}/decoder/include", - "${audio_processor_path}/decodeprocessor/include", - "${audio_processor_path}/interface", - "${audio_transport_path}/audiochannel/interface", - "${audio_transport_path}/audiochannel/audiodatachannel/include", - "${audio_transport_path}/audiotransportstatus/include", - "${audio_transport_path}/audiotransportstatus/interface", - "${audio_transport_path}/test/unittest/audiotranstestutils/include", - "${services_path}/common/audioparam", - "${services_path}/common/audiodata/include", - ] -} - -ohos_unittest("TransportStatusTest") { - module_out_path = module_output_path - - sources = [ "src/audio_transport_pause_status_test.cpp", - "src/audio_transport_stop_status_test.cpp", - "src/audio_transport_start_status_test.cpp", - ] - - configs = [ ":module_private_config" ] - - deps = [ - "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", - "${audio_transport_path}/audiotransportstatus:distributed_audio_transport_status", - "${services_path}/common:distributed_audio_utils", - "//third_party/googletest:gtest_main", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"daudio_trans_test\"", - "LOG_DOMAIN=0xD004100", - ] -} - -group("transport_status_test") { - testonly = true - deps = [ ":TransportStatusTest" ] -} +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos_var.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +module_output_path = + "distributed_audio/services/audiotransport/transport_status_test" + +config("module_private_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${fwk_common_path}/utils/include", + "${mediastandard_path}/interfaces/innerkits/native/media/include", + "${mediastandardfwk_path}/audiocommon/include", + "//third_party/json/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${audio_processor_path}/decoder/include", + "${audio_processor_path}/decodeprocessor/include", + "${audio_processor_path}/interface", + "${audio_transport_path}/audiochannel/interface", + "${audio_transport_path}/audiochannel/audiodatachannel/include", + "${audio_transport_path}/audiotransportstatus/include", + "${audio_transport_path}/audiotransportstatus/interface", + "${audio_transport_path}/test/unittest/audiotranstestutils/include", + "${services_path}/common/audioparam", + "${services_path}/common/audiodata/include", + ] +} + +ohos_unittest("TransportStatusTest") { + module_out_path = module_output_path + + sources = [ + "src/audio_transport_pause_status_test.cpp", + "src/audio_transport_start_status_test.cpp", + "src/audio_transport_stop_status_test.cpp", + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", + "${audio_transport_path}/audiotransportstatus:distributed_audio_transport_status", + "${services_path}/common:distributed_audio_utils", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ "dsoftbus:softbus_client" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"daudio_trans_test\"", + "LOG_DOMAIN=0xD004100", + ] +} + +group("transport_status_test") { + testonly = true + deps = [ ":TransportStatusTest" ] +} diff --git a/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_pause_status_test.cpp b/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_pause_status_test.cpp index d573af0213964e8223c317e456b6ad102f8da7f5..f4671539b04b54b0d4180be26db0abb36093da89 100644 --- a/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_pause_status_test.cpp +++ b/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_pause_status_test.cpp @@ -60,6 +60,7 @@ HWTEST_F(AudioTransportPauseStatusTest, transport_pause_test_001, TestSize.Level std::shared_ptr audioChannel_ = std::make_shared(peerDevId); std::shared_ptr processor_ = std::make_shared(); EXPECT_EQ(ERR_DH_AUDIO_TRANS_ILLEGAL_OPERATION, audioStatus_->Start(audioChannel_, processor_)); + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Stop(nullptr, processor_)); } /** @@ -107,12 +108,12 @@ HWTEST_F(AudioTransportPauseStatusTest, transport_pause_test_004, TestSize.Level }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE, }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE, } }; AudioParam testRemoteParaEnc = { @@ -124,18 +125,31 @@ HWTEST_F(AudioTransportPauseStatusTest, transport_pause_test_004, TestSize.Level }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE, }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE, } }; std::string peerDevId = "peerDevId"; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Restart(testLocalParaEnc, testRemoteParaEnc, nullptr)); + std::shared_ptr audioChannel_ = std::make_shared(peerDevId); std::shared_ptr processor_ = std::make_shared(); EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Restart(testLocalParaEnc, testRemoteParaEnc, processor_)); } + +/** + * @tc.name: transport_getstatetype_test_001 + * @tc.desc: Verify pause action when status is start. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(AudioTransportPauseStatusTest, transport_getstatetype_test_001, TestSize.Level1) +{ + EXPECT_EQ(TRANSPORT_STATE_PAUSE, audioStatus_->GetStateType()); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_start_status_test.cpp b/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_start_status_test.cpp index aa534aee5d6d7a700fdb555ab079af40bb6b9fee..2b096dbde0a269e6472c7dc25d407c63cb1da991 100644 --- a/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_start_status_test.cpp +++ b/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_start_status_test.cpp @@ -64,34 +64,58 @@ HWTEST_F(AudioTransportStartStatusTest, transport_start_test_001, TestSize.Level } /** - * @tc.name: transport_start_test_002 + * @tc.name: transport_Stop_test_001 + * @tc.desc: Verify stop action when status is stop. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(AudioTransportStartStatusTest, transport_Stop_test_001, TestSize.Level1) +{ + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Stop(audioChannel_, processor_)); +} + +/** + * @tc.name: transport_stop_test_002 * @tc.desc: Verify stop action when status is start. * @tc.type: FUNC * @tc.require: AR000H0E5U */ -HWTEST_F(AudioTransportStartStatusTest, transport_start_test_002, TestSize.Level1) +HWTEST_F(AudioTransportStartStatusTest, transport_stop_test_002, TestSize.Level1) { + std::shared_ptr processor_ = std::make_shared(); EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Stop(audioChannel_, processor_)); } /** - * @tc.name: transport_start_test_003 + * @tc.name: transport_Pause_test_001 * @tc.desc: Verify pause action when status is start. * @tc.type: FUNC * @tc.require: AR000H0E5U */ -HWTEST_F(AudioTransportStartStatusTest, transport_start_test_003, TestSize.Level1) +HWTEST_F(AudioTransportStartStatusTest, transport_pause_test_001, TestSize.Level1) { EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Pause(processor_)); } /** - * @tc.name: transport_start_test_004 + * @tc.name: transport_Pause_test_002 + * @tc.desc: Verify pause action when status is start. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(AudioTransportStartStatusTest, transport_Pause_test_002, TestSize.Level1) +{ + processor_ = std::make_shared(); + EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audioStatus_->Pause(processor_)); +} + +/** + * @tc.name: transport_Restart_test_001 * @tc.desc: Verify action when status is start. * @tc.type: FUNC * @tc.require: AR000H0E5U */ -HWTEST_F(AudioTransportStartStatusTest, transport_start_test_004, TestSize.Level1) +HWTEST_F(AudioTransportStartStatusTest, transport_restart_test_001, TestSize.Level1) { AudioParam testLocalParaEnc = { { @@ -102,12 +126,12 @@ HWTEST_F(AudioTransportStartStatusTest, transport_start_test_004, TestSize.Level }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; AudioParam testRemoteParaEnc = { @@ -119,15 +143,26 @@ HWTEST_F(AudioTransportStartStatusTest, transport_start_test_004, TestSize.Level }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; EXPECT_EQ(DH_SUCCESS, audioStatus_->Restart(testLocalParaEnc, testRemoteParaEnc, processor_)); } + +/** + * @tc.name: transport_getstatetype_test_001 + * @tc.desc: Verify pause action when status is start. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(AudioTransportStartStatusTest, transport_getstatetype_test_001, TestSize.Level1) +{ + EXPECT_EQ(TRANSPORT_STATE_START, audioStatus_->GetStateType()); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_stop_status_test.cpp b/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_stop_status_test.cpp index b28ae741fb26c3bf4154c8d6d410b20c53cf71ac..36e2878848cb4c70ec5d40197c558269aed80ece 100644 --- a/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_stop_status_test.cpp +++ b/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_stop_status_test.cpp @@ -60,7 +60,11 @@ void AudioTransportStopStatusTest::TearDown(void) */ HWTEST_F(AudioTransportStopStatusTest, transport_stop_test_001, TestSize.Level1) { - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Start(audioChannel_, processor_)); + std::string peerDevId = "peerDevId"; + std::shared_ptr audioChannel_ = std::make_shared(peerDevId); + std::shared_ptr processor_ = std::make_shared(); + EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audioStatus_->Start(audioChannel_, processor_)); + EXPECT_EQ(DH_SUCCESS, audioStatus_->Stop(audioChannel_, processor_)); } /** @@ -71,6 +75,7 @@ HWTEST_F(AudioTransportStopStatusTest, transport_stop_test_001, TestSize.Level1) */ HWTEST_F(AudioTransportStopStatusTest, transport_stop_test_002, TestSize.Level1) { + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Start(audioChannel_, nullptr)); EXPECT_EQ(DH_SUCCESS, audioStatus_->Stop(audioChannel_, processor_)); } @@ -102,12 +107,12 @@ HWTEST_F(AudioTransportStopStatusTest, transport_stop_test_004, TestSize.Level1) }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; AudioParam testRemoteParaEnc = { @@ -119,16 +124,27 @@ HWTEST_F(AudioTransportStopStatusTest, transport_stop_test_004, TestSize.Level1) }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; EXPECT_EQ(ERR_DH_AUDIO_TRANS_ILLEGAL_OPERATION, audioStatus_->Restart(testLocalParaEnc, testRemoteParaEnc, processor_)); } + +/** + * @tc.name: transport_getstatetype_test_001 + * @tc.desc: Verify pause action when status is start. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(AudioTransportStopStatusTest, transport_getstatetype_test_001, TestSize.Level1) +{ + EXPECT_EQ(TRANSPORT_STATE_STOP, audioStatus_->GetStateType()); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiotransport/test/unittest/decodetransport/BUILD.gn b/services/audiotransport/test/unittest/decodetransport/BUILD.gn index 3a702efbd51bade188c82e69e3f09e31473f77f7..3d9b8588b7482fec561b8ec09a54d82185ce7035 100644 --- a/services/audiotransport/test/unittest/decodetransport/BUILD.gn +++ b/services/audiotransport/test/unittest/decodetransport/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_output_path = "distributed_audio/services/audiotransport/decode_transport_test" diff --git a/services/audiotransport/test/unittest/decodetransport/src/decode_transport_test.cpp b/services/audiotransport/test/unittest/decodetransport/src/decode_transport_test.cpp index eecf722bad07fd763421767029a24a3a63d238cb..8153cad9f2711e01626740abea2f6a49cd954cf3 100644 --- a/services/audiotransport/test/unittest/decodetransport/src/decode_transport_test.cpp +++ b/services/audiotransport/test/unittest/decodetransport/src/decode_transport_test.cpp @@ -71,12 +71,12 @@ HWTEST_F(DecodeTransportTest, decode_transport_test_001, TestSize.Level1) }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; AudioParam testRemoteParaEnc = { @@ -88,12 +88,12 @@ HWTEST_F(DecodeTransportTest, decode_transport_test_001, TestSize.Level1) }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; EXPECT_NE(DH_SUCCESS, decodeTrans_->SetUp(testLocalParaEnc, testRemoteParaEnc, transCallback_, ROLE_TEST)); @@ -115,6 +115,9 @@ HWTEST_F(DecodeTransportTest, decode_transport_test_002, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, decodeTrans_->Release()); decodeTrans_->audioChannel_ = std::make_shared(); + decodeTrans_->context_ = std::make_shared(); + decodeTrans_->capType_ = CAP_MIC; + EXPECT_EQ(ERR_DH_AUDIO_TRANS_SESSION_NOT_OPEN, decodeTrans_->Start()); EXPECT_NE(DH_SUCCESS, decodeTrans_->Release()); } @@ -135,12 +138,12 @@ HWTEST_F(DecodeTransportTest, decode_transport_test_003, TestSize.Level1) }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; AudioParam testRemoteParaEnc = { @@ -152,14 +155,17 @@ HWTEST_F(DecodeTransportTest, decode_transport_test_003, TestSize.Level1) }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; + EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, decodeTrans_->RegisterProcessorListener(testLocalParaEnc, testRemoteParaEnc)); + EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, + decodeTrans_->InitAudioDecodeTransport(testLocalParaEnc, testRemoteParaEnc, ROLE_TEST)); EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, decodeTrans_->Pause()); EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, decodeTrans_->Restart(testLocalParaEnc, testRemoteParaEnc)); } @@ -183,5 +189,16 @@ HWTEST_F(DecodeTransportTest, decode_transport_test_004, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, decodeTrans_->FeedAudioData(audioData)); } + +/** + * @tc.name: decode_transport_test_005 + * @tc.desc: Verify the RegisterChannelListener function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DecodeTransportTest, decode_transport_test_005, TestSize.Level1) +{ + EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, decodeTrans_->RegisterChannelListener(ROLE_TEST)); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiotransport/test/unittest/encodetransport/BUILD.gn b/services/audiotransport/test/unittest/encodetransport/BUILD.gn index e3121a42007a0d21a9dd8e06cf14fe3389dcd07d..0303a744b28b73f5e3a8183a077f616800d28950 100644 --- a/services/audiotransport/test/unittest/encodetransport/BUILD.gn +++ b/services/audiotransport/test/unittest/encodetransport/BUILD.gn @@ -14,8 +14,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_output_path = "distributed_audio/services/audiotransport/encode_transport_test" @@ -55,8 +54,8 @@ ohos_unittest("EncodeTransportTest") { configs = [ ":module_private_config" ] deps = [ - "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", "${audio_transport_path}/audiotransportstatus:distributed_audio_transport_status", + "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", "${services_path}/common:distributed_audio_utils", "//third_party/googletest:gtest_main", ] diff --git a/services/audiotransport/test/unittest/encodetransport/src/encode_transport_test.cpp b/services/audiotransport/test/unittest/encodetransport/src/encode_transport_test.cpp index 39a0da7c008b40006a2ad7fbdf193016a39514df..31016a8338c06c51eb408efcd4f6097fc123d830 100644 --- a/services/audiotransport/test/unittest/encodetransport/src/encode_transport_test.cpp +++ b/services/audiotransport/test/unittest/encodetransport/src/encode_transport_test.cpp @@ -74,12 +74,12 @@ HWTEST_F(EncodeTransportTest, encode_transport_test_001, TestSize.Level1) }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; AudioParam testRemoteParaEnc = { @@ -91,12 +91,12 @@ HWTEST_F(EncodeTransportTest, encode_transport_test_001, TestSize.Level1) }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; EXPECT_NE(DH_SUCCESS, encodeTrans_->SetUp(testLocalParaEnc, testRemoteParaEnc, transCallback_, ROLE_TEST)); @@ -140,12 +140,12 @@ HWTEST_F(EncodeTransportTest, encode_transport_test_003, TestSize.Level1) }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; AudioParam testRemoteParaEnc = { @@ -157,14 +157,18 @@ HWTEST_F(EncodeTransportTest, encode_transport_test_003, TestSize.Level1) }, { SOURCE_TYPE_INVALID, - 0 + NORMAL_MODE }, { CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN, - 0 + NORMAL_MODE } }; + + EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, encodeTrans_->RegisterProcessorListener(testLocalParaEnc, testRemoteParaEnc)); + EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, + encodeTrans_->InitAudioEncodeTrans(testLocalParaEnc, testRemoteParaEnc, ROLE_TEST)); encodeTrans_->context_ = std::make_shared(); auto stateContext = std::shared_ptr(encodeTrans_->context_); encodeTrans_->context_->currentState_ = @@ -172,5 +176,36 @@ HWTEST_F(EncodeTransportTest, encode_transport_test_003, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, encodeTrans_->Pause()); EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, encodeTrans_->Restart(testLocalParaEnc, testRemoteParaEnc)); } + +/** + * @tc.name: encode_transport_test_004 + * @tc.desc: Verify encode_transport_test function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(EncodeTransportTest, encode_transport_test_004, TestSize.Level1) +{ + std::shared_ptr audioData = nullptr; + AudioEvent event; + encodeTrans_->OnSessionOpened(); + encodeTrans_->OnSessionClosed(); + encodeTrans_->OnDataReceived(audioData); + encodeTrans_->OnEventReceived(event); + encodeTrans_->OnStateNotify(event); + encodeTrans_->OnAudioDataDone(audioData); + + EXPECT_EQ(ERR_DH_AUDIO_TRANS_NULL_VALUE, encodeTrans_->FeedAudioData(audioData)); +} + +/** + * @tc.name: encode_transport_test_005 + * @tc.desc: Verify RegisterChannelListener function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(EncodeTransportTest, encode_transport_test_005, TestSize.Level1) +{ + EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, encodeTrans_->RegisterChannelListener(ROLE_TEST)); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index c61316cb3d4768238d72d5a282732223560fff25..fd1793ed3ad4fa4845b96ffacfc78920a9255546 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -13,10 +13,17 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../distributedaudio.gni") -ohos_shared_library("distributed_audio_utils") { +config("daudio_common_pub_config") { + include_dirs = [ + "audiodata/include", + "audioparam", + "${common_path}/include", + ] +} + +config("daudio_common_private_config") { include_dirs = [ "//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include", "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter", @@ -25,21 +32,25 @@ ohos_shared_library("distributed_audio_utils") { ] include_dirs += [ - "audiodata/include", - "audioparam", "taskProcessor/include", "${common_path}/include", "${common_path}/dfx_utils/include", ] +} + +ohos_shared_library("distributed_audio_utils") { + configs = [ ":daudio_common_private_config" ] + + public_configs = [ ":daudio_common_pub_config" ] sources = [ - "audiodata/src/audio_data.cpp", - "taskProcessor/src/task_impl.cpp", - "taskProcessor/src/task_queue.cpp", "${common_path}/dfx_utils/src/daudio_hisysevent.cpp", "${common_path}/dfx_utils/src/daudio_hitrace.cpp", "${common_path}/src/daudio_log.cpp", "${common_path}/src/daudio_util.cpp", + "audiodata/src/audio_data.cpp", + "taskProcessor/src/task_impl.cpp", + "taskProcessor/src/task_queue.cpp", ] external_deps = [ diff --git a/services/common/audioparam/audio_event.h b/services/common/audioparam/audio_event.h index 515e4375bed24baf955962c5851b7a43a33ce0f0..6952ae2ce76be3d527b7019f0b27ec0b57431b0b 100644 --- a/services/common/audioparam/audio_event.h +++ b/services/common/audioparam/audio_event.h @@ -63,10 +63,6 @@ typedef enum { CHANGE_PLAY_STATUS = 71, - MMAP_START = 81, - MMAP_STOP = 82, - MMAP_START_MIC = 83, - MMAP_STOP_MIC = 84, AUDIO_START = 85, AUDIO_STOP = 86, } AudioEventType; @@ -86,10 +82,6 @@ typedef enum { AUDIO_EVENT_RENDER_STATE_CHANGE = 11, AUDIO_EVENT_MUTE_SET = 12, AUDIO_EVENT_CHANGE_PLAY_STATUS = 13, - AUDIO_EVENT_MMAP_START = 14, - AUDIO_EVENT_MMAP_STOP = 15, - AUDIO_EVENT_MIC_MMAP_START = 16, - AUDIO_EVENT_MIC_MMAP_STOP = 17, AUDIO_EVENT_START = 18, AUDIO_EVENT_STOP = 19, } AudioEventHDF; diff --git a/services/common/audioparam/audio_param.h b/services/common/audioparam/audio_param.h index c41d2cc25d25a09da7d279deea17949e67a30738..77453d21bf760450f6c5d4955dce0c508dad6fa2 100644 --- a/services/common/audioparam/audio_param.h +++ b/services/common/audioparam/audio_param.h @@ -77,6 +77,11 @@ typedef enum { STREAM_USAGE_NOTIFICATION_RINGTONE = 6 } StreamUsage; +typedef enum { + NORMAL_MODE = 0, + MMAP_MODE = 1, +} PortOperationMode; + typedef struct AudioCommonParam { AudioSampleRate sampleRate = SAMPLE_RATE_8000; AudioChannel channelMask = MONO; @@ -85,16 +90,15 @@ typedef struct AudioCommonParam { uint32_t frameSize = 0; } AudioCommonParam; - typedef struct AudioCaptureOptions { SourceType sourceType = SOURCE_TYPE_INVALID; - int32_t capturerFlags = 0; + PortOperationMode capturerFlags = NORMAL_MODE; } AudioCaptureOptions; typedef struct AudioRenderOptions { ContentType contentType = CONTENT_TYPE_UNKNOWN; StreamUsage streamUsage = STREAM_USAGE_UNKNOWN; - int32_t renderFlags = 0; + PortOperationMode renderFlags = NORMAL_MODE; } AudioRenderOptions; typedef struct AudioParamHDF { @@ -104,8 +108,8 @@ typedef struct AudioParamHDF { StreamUsage streamUsage = STREAM_USAGE_UNKNOWN; uint32_t frameSize = 0; uint32_t period = 0; - int32_t renderFlags = 0; - int32_t capturerFlags = 0; + PortOperationMode renderFlags = NORMAL_MODE; + PortOperationMode capturerFlags = NORMAL_MODE; std::string ext; } AudioParamHDF; @@ -126,6 +130,11 @@ typedef enum { CAP_SPK = 1, CAP_MIC = 2, } PortCapType; + +typedef struct { + int64_t tvSec; + int64_t tvNSec; +} CurrentTimeHDF; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DAUDIO_AUDIO_PARAM_H diff --git a/services/common/taskProcessor/test/unittest/BUILD.gn b/services/common/taskProcessor/test/unittest/BUILD.gn index 295971e0a5b0e469cd78245a9b394ba948425ec3..26686b3495c5a49511ac12ae971691968b6e719b 100644 --- a/services/common/taskProcessor/test/unittest/BUILD.gn +++ b/services/common/taskProcessor/test/unittest/BUILD.gn @@ -13,12 +13,9 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") group("task_processor_test") { testonly = true - deps = [ - "${services_path}/common/taskProcessor/test/unittest/task_queue:task_queue_test", - ] + deps = [ "${services_path}/common/taskProcessor/test/unittest/task_queue:task_queue_test" ] } diff --git a/services/common/taskProcessor/test/unittest/task_queue/BUILD.gn b/services/common/taskProcessor/test/unittest/task_queue/BUILD.gn index dbb9fd2ef76328489bd4d6b5b36668c173e5ac24..c2049f5b8436d449c12a68c84d30bfe3ad085fd1 100644 --- a/services/common/taskProcessor/test/unittest/task_queue/BUILD.gn +++ b/services/common/taskProcessor/test/unittest/task_queue/BUILD.gn @@ -14,15 +14,14 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/common/taskProcessor/test" config("module_private_config") { visibility = [ ":*" ] - include_dirs = [ "//third_party/json/include", ] + include_dirs = [ "//third_party/json/include" ] include_dirs += [ "${common_path}/include", @@ -37,16 +36,14 @@ config("module_private_config") { ohos_unittest("TaskQueueTest") { module_out_path = module_out_path - sources = [ - "${services_path}/common/taskProcessor/test/unittest/task_queue/src/task_queue_test.cpp", - ] + sources = [ "${services_path}/common/taskProcessor/test/unittest/task_queue/src/task_queue_test.cpp" ] configs = [ ":module_private_config" ] deps = [ + "${services_path}/common:distributed_audio_utils", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", - "${services_path}/common:distributed_audio_utils", ] } diff --git a/services/common/test/unittest/audiodata/BUILD.gn b/services/common/test/unittest/audiodata/BUILD.gn index 4664caa55dcef4e4b51a88f3c3f07bd433cf4a72..e8a3953aacbfc12e02c5b45240356d21e66bd5eb 100644 --- a/services/common/test/unittest/audiodata/BUILD.gn +++ b/services/common/test/unittest/audiodata/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/common/audio_data_test" diff --git a/services/hdfaudioclient/BUILD.gn b/services/hdfaudioclient/BUILD.gn index 16b0bbac9c8ab61129c8f5b7b76c0e4985ae9961..1bb5fd875da570c46a1202a50e9e23df23d735c8 100644 --- a/services/hdfaudioclient/BUILD.gn +++ b/services/hdfaudioclient/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../distributedaudio.gni") ohos_shared_library("daudio_client") { include_dirs = [ "//drivers//peripheral/audio/interfaces/include/" ] diff --git a/services/hdfaudioclient/test/unittest/BUILD.gn b/services/hdfaudioclient/test/unittest/BUILD.gn index cbf3abc0f5b55fc46f6022ffdd54636c7e32ed2f..0c714fb02fbf85c556a46504e106d547bd110a76 100644 --- a/services/hdfaudioclient/test/unittest/BUILD.gn +++ b/services/hdfaudioclient/test/unittest/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") module_output_path = "distributed_audio/hdfaudioclient" @@ -125,15 +124,13 @@ ohos_unittest("AudioAdapterInternalTest") { sources = [ "audio_adapter_internal/audio_adapter_internal_test.cpp" ] deps = [ - "${services_path}/hdfaudioclient:daudio_client", "${hdf_interfaces_path}/audio/v1_0:libdaudio_proxy_1.0", + "${services_path}/hdfaudioclient:daudio_client", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] - external_deps = [ - "c_utils:utils", - ] + external_deps = [ "c_utils:utils" ] defines = [ "HI_LOG_ENABLE", @@ -155,8 +152,8 @@ group("audio_adapter_hdi_test") { testonly = true deps = [ ":AudioAdapterHdiTest", - ":AudioRenderInternalTest", - ":AudioCaptureInternalTest", ":AudioAdapterInternalTest", - ] + ":AudioCaptureInternalTest", + ":AudioRenderInternalTest", + ] } diff --git a/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h b/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h index fe7b9c66af45ef229f18141d950db854b44da1fe..03567108063256a49148e97c22ef0e99af25b7d0 100644 --- a/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h +++ b/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h @@ -13,6 +13,9 @@ * limitations under the License. */ +#ifndef DAUDIO_ADAPTER_INTERNAL_TEST_H +#define DAUDIO_ADAPTER_INTERNAL_TEST_H + #include #include "daudio_adapter_internal.h" @@ -133,4 +136,5 @@ public: } }; } // DistributedHardware -} // OHOS \ No newline at end of file +} // OHOS +#endif \ No newline at end of file diff --git a/services/softbusadapter/BUILD.gn b/services/softbusadapter/BUILD.gn index 8a5815d1b4f472f3b891b03d282d4fc1c51d5074..811ce50ebe73d6ea0a199e6f7e8fcbdd23265a5e 100644 --- a/services/softbusadapter/BUILD.gn +++ b/services/softbusadapter/BUILD.gn @@ -13,8 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../distributedaudio.gni") ohos_shared_library("distributed_audio_softbus_adapter") { include_dirs = [ @@ -36,7 +35,7 @@ ohos_shared_library("distributed_audio_softbus_adapter") { "src/softbus_adapter.cpp", ] - deps = [ "${services_path}/common:distributed_audio_utils", ] + deps = [ "${services_path}/common:distributed_audio_utils" ] external_deps = [ "c_utils:utils", diff --git a/services/softbusadapter/test/unittest/BUILD.gn b/services/softbusadapter/test/unittest/BUILD.gn index 6285150b7ec2d4ffeb5b0c7a46261168d6adcd17..7d8641afa2cdd8151576979bf3e7cdbacf088881 100644 --- a/services/softbusadapter/test/unittest/BUILD.gn +++ b/services/softbusadapter/test/unittest/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_audio/distributedaudio.gni") +import("../../../../distributedaudio.gni") module_out_path = "distributed_audio/services/softbusadapter" diff --git a/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp b/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp index 31f85b9c214d5736c6535da055fd595990321138..42205527e2d4c07050ef08af42e011abe0098f4f 100644 --- a/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp +++ b/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp @@ -148,17 +148,6 @@ HWTEST_F(SoftbusAdapterTest, OnSoftbusSessionOpened_002, TestSize.Level1) int32_t result = 0; EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, softbusAdapter.OnSoftbusSessionOpened(sessionId, result)); -} - -/** - * @tc.name: OnSoftbusSessionClosed_001 - * @tc.desc: Verify the OnSoftbusSessionClosed function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(SoftbusAdapterTest, OnSoftbusSessionClosed_001, TestSize.Level1) -{ - int32_t sessionId = 1; softbusAdapter.OnSoftbusSessionClosed(sessionId); } } // namespace DistributedHardware