From 98937eb78fa1f7832db72889fde2362715363a82 Mon Sep 17 00:00:00 2001 From: w30042960 Date: Mon, 25 Dec 2023 14:51:31 +0800 Subject: [PATCH] delete code Signed-off-by: w30042960 --- bundle.json | 2 - common/dfx_utils/test/unittest/BUILD.gn | 1 - distributedaudio.gni | 1 - .../native_cpp/test/fuzztest/BUILD.gn | 12 - .../native_cpp/test/unittest/BUILD.gn | 1 - .../test/unittest/micclient/BUILD.gn | 1 - .../test/unittest/spkclient/BUILD.gn | 1 - .../managersource/src/dspeaker_dev.cpp | 3 +- services/audiomanager/servicesink/BUILD.gn | 1 - services/audiomanager/servicesource/BUILD.gn | 1 - .../test/unittest/servicesource/BUILD.gn | 1 - .../test/unittest/sourcedevice/BUILD.gn | 1 - .../sourcedevice/src/dspeaker_dev_test.cpp | 8 +- .../test/unittest/sourcemanager/BUILD.gn | 1 - .../include/audio_decoder_processor.h | 55 --- .../src/audio_decoder_processor.cpp | 166 ------- .../decoder/include/audio_decoder.h | 99 ---- .../decoder/include/audio_decoder_callback.h | 47 -- .../decoder/src/audio_decoder.cpp | 438 ------------------ .../decoder/src/audio_decoder_callback.cpp | 72 --- .../include/audio_encoder_processor.h | 55 --- .../src/audio_encoder_processor.cpp | 164 ------- .../encoder/include/audio_encoder.h | 99 ---- .../encoder/include/audio_encoder_callback.h | 46 -- .../encoder/src/audio_encoder.cpp | 434 ----------------- .../encoder/src/audio_encoder_callback.cpp | 72 --- .../fuzztest/decoderonerror_fuzzer/BUILD.gn | 68 --- .../decoderonerror_fuzzer/corpus/init | 16 - .../decoderonerror_fuzzer.cpp | 48 -- .../decoderonerror_fuzzer.h | 21 - .../decoderonerror_fuzzer/project.xml | 25 - .../decoderoninputavailable_fuzzer/BUILD.gn | 68 --- .../corpus/init | 16 - .../decoderoninputavailable_fuzzer.cpp | 47 -- .../decoderoninputavailable_fuzzer.h | 21 - .../project.xml | 25 - .../decoderonoutputavailable_fuzzer/BUILD.gn | 68 --- .../corpus/init | 16 - .../decoderonoutputavailable_fuzzer.cpp | 53 --- .../decoderonoutputavailable_fuzzer.h | 21 - .../project.xml | 25 - .../decoderonoutputchanged_fuzzer/BUILD.gn | 68 --- .../decoderonoutputchanged_fuzzer/corpus/init | 16 - .../decoderonoutputchanged_fuzzer.cpp | 47 -- .../decoderonoutputchanged_fuzzer.h | 21 - .../decoderonoutputchanged_fuzzer/project.xml | 25 - .../fuzztest/encoderonerror_fuzzer/BUILD.gn | 68 --- .../encoderonerror_fuzzer/corpus/init | 16 - .../encoderonerror_fuzzer.cpp | 48 -- .../encoderonerror_fuzzer.h | 21 - .../encoderonerror_fuzzer/project.xml | 25 - .../encoderoninputavailable_fuzzer/BUILD.gn | 68 --- .../corpus/init | 16 - .../encoderoninputavailable_fuzzer.cpp | 47 -- .../encoderoninputavailable_fuzzer.h | 21 - .../project.xml | 25 - .../encoderonoutputavailable_fuzzer/BUILD.gn | 68 --- .../corpus/init | 16 - .../encoderonoutputavailable_fuzzer.cpp | 53 --- .../encoderonoutputavailable_fuzzer.h | 21 - .../project.xml | 25 - .../encoderonoutputchanged_fuzzer/BUILD.gn | 68 --- .../encoderonoutputchanged_fuzzer/corpus/init | 16 - .../encoderonoutputchanged_fuzzer.cpp | 47 -- .../encoderonoutputchanged_fuzzer.h | 21 - .../encoderonoutputchanged_fuzzer/project.xml | 25 - .../audioprocessor/test/unittest/BUILD.gn | 5 +- .../unittest/common/decodeprocessor/BUILD.gn | 35 +- .../decodeprocessor/decode_process_test.cpp | 266 ----------- .../common/decodeprocessor/decoder_test.cpp | 241 ---------- .../unittest/common/encodeprocessor/BUILD.gn | 74 --- .../encodeprocessor/encode_process_test.cpp | 333 ------------- .../common/encodeprocessor/encoder_test.cpp | 210 --------- .../audiochannel/audiodatachannel/BUILD.gn | 6 +- .../include/audio_data_channel.h | 11 +- .../src/audio_data_channel.cpp | 99 +--- .../audiotransport/decodetransport/BUILD.gn | 6 - .../include/audio_decode_transport.h | 1 + .../src/audio_decode_transport.cpp | 3 - .../audiotransport/encodetransport/BUILD.gn | 6 - .../include/audio_encode_transport.h | 1 + .../src/audio_encode_transport.cpp | 3 - .../audiotransport/test/unittest/BUILD.gn | 3 - .../test/unittest/audiodatachannel/BUILD.gn | 62 --- .../include/audio_data_channel_test.h | 42 -- .../src/audio_data_channel_test.cpp | 127 ----- .../test/unittest/decodetransport/BUILD.gn | 1 - .../test/unittest/encodetransport/BUILD.gn | 1 - .../test/unittest/receiverengine/BUILD.gn | 1 - .../test/unittest/senderengine/BUILD.gn | 1 - services/softbusadapter/BUILD.gn | 61 --- .../include/isoftbus_listener.h | 35 -- .../softbusadapter/include/softbus_adapter.h | 98 ---- .../softbusadapter/src/softbus_adapter.cpp | 386 --------------- .../softbusonbytesreceived_fuzzer/BUILD.gn | 71 --- .../softbusonbytesreceived_fuzzer/corpus/init | 16 - .../softbusonbytesreceived_fuzzer/project.xml | 25 - .../softbusonbytesreceived_fuzzer.cpp | 49 -- .../softbusonbytesreceived_fuzzer.h | 21 - .../softbusonsessionclosed_fuzzer/BUILD.gn | 71 --- .../softbusonsessionclosed_fuzzer/corpus/init | 16 - .../softbusonsessionclosed_fuzzer/project.xml | 25 - .../softbusonsessionclosed_fuzzer.cpp | 47 -- .../softbusonsessionclosed_fuzzer.h | 21 - .../softbusonsessionopened_fuzzer/BUILD.gn | 71 --- .../softbusonsessionopened_fuzzer/corpus/init | 16 - .../softbusonsessionopened_fuzzer/project.xml | 25 - .../softbusonsessionopened_fuzzer.cpp | 48 -- .../softbusonsessionopened_fuzzer.h | 21 - .../softbusonstreamreceived_fuzzer/BUILD.gn | 71 --- .../corpus/init | 16 - .../project.xml | 25 - .../softbusonstreamreceived_fuzzer.cpp | 50 -- .../softbusonstreamreceived_fuzzer.h | 21 - .../softbusadapter/test/unittest/BUILD.gn | 56 --- .../unittest/include/softbus_adapter_test.h | 42 -- .../include/softbus_adapter_test_utils.h | 36 -- .../unittest/src/softbus_adapter_test.cpp | 154 ------ 118 files changed, 15 insertions(+), 6329 deletions(-) delete mode 100644 services/audioprocessor/decodeprocessor/include/audio_decoder_processor.h delete mode 100644 services/audioprocessor/decodeprocessor/src/audio_decoder_processor.cpp delete mode 100644 services/audioprocessor/decoder/include/audio_decoder.h delete mode 100644 services/audioprocessor/decoder/include/audio_decoder_callback.h delete mode 100644 services/audioprocessor/decoder/src/audio_decoder.cpp delete mode 100644 services/audioprocessor/decoder/src/audio_decoder_callback.cpp delete mode 100644 services/audioprocessor/encodeprocessor/include/audio_encoder_processor.h delete mode 100644 services/audioprocessor/encodeprocessor/src/audio_encoder_processor.cpp delete mode 100644 services/audioprocessor/encoder/include/audio_encoder.h delete mode 100644 services/audioprocessor/encoder/include/audio_encoder_callback.h delete mode 100644 services/audioprocessor/encoder/src/audio_encoder.cpp delete mode 100644 services/audioprocessor/encoder/src/audio_encoder_callback.cpp delete mode 100644 services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/BUILD.gn delete mode 100644 services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/corpus/init delete mode 100644 services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.cpp delete mode 100644 services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.h delete mode 100644 services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/project.xml delete mode 100644 services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/BUILD.gn delete mode 100644 services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/corpus/init delete mode 100644 services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.cpp delete mode 100644 services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.h delete mode 100644 services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/project.xml delete mode 100644 services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/BUILD.gn delete mode 100644 services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/corpus/init delete mode 100644 services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.cpp delete mode 100644 services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.h delete mode 100644 services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/project.xml delete mode 100644 services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/BUILD.gn delete mode 100644 services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/corpus/init delete mode 100644 services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.cpp delete mode 100644 services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.h delete mode 100644 services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/project.xml delete mode 100644 services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/BUILD.gn delete mode 100644 services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/corpus/init delete mode 100644 services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.cpp delete mode 100644 services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.h delete mode 100644 services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/project.xml delete mode 100644 services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/BUILD.gn delete mode 100644 services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/corpus/init delete mode 100644 services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.cpp delete mode 100644 services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.h delete mode 100644 services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/project.xml delete mode 100644 services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/BUILD.gn delete mode 100644 services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/corpus/init delete mode 100644 services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.cpp delete mode 100644 services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.h delete mode 100644 services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/project.xml delete mode 100644 services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/BUILD.gn delete mode 100644 services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/corpus/init delete mode 100644 services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.cpp delete mode 100644 services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.h delete mode 100644 services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/project.xml delete mode 100644 services/audioprocessor/test/unittest/common/decodeprocessor/decode_process_test.cpp delete mode 100644 services/audioprocessor/test/unittest/common/decodeprocessor/decoder_test.cpp delete mode 100644 services/audioprocessor/test/unittest/common/encodeprocessor/BUILD.gn delete mode 100644 services/audioprocessor/test/unittest/common/encodeprocessor/encode_process_test.cpp delete mode 100644 services/audioprocessor/test/unittest/common/encodeprocessor/encoder_test.cpp delete mode 100644 services/audiotransport/test/unittest/audiodatachannel/BUILD.gn delete mode 100644 services/audiotransport/test/unittest/audiodatachannel/include/audio_data_channel_test.h delete mode 100644 services/audiotransport/test/unittest/audiodatachannel/src/audio_data_channel_test.cpp delete mode 100644 services/softbusadapter/BUILD.gn delete mode 100644 services/softbusadapter/include/isoftbus_listener.h delete mode 100644 services/softbusadapter/include/softbus_adapter.h delete mode 100644 services/softbusadapter/src/softbus_adapter.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h delete mode 100644 services/softbusadapter/test/unittest/BUILD.gn delete mode 100644 services/softbusadapter/test/unittest/include/softbus_adapter_test.h delete mode 100644 services/softbusadapter/test/unittest/include/softbus_adapter_test_utils.h delete mode 100644 services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp diff --git a/bundle.json b/bundle.json index 46171115..c104ef9a 100755 --- a/bundle.json +++ b/bundle.json @@ -71,8 +71,6 @@ "//foundation/distributedhardware/distributed_audio/services/audiomanager/servicesource:distributed_audio_source", "//foundation/distributedhardware/distributed_audio/services/audiomanager/servicesink:distributed_audio_sink", - "//foundation/distributedhardware/distributed_audio/services/softbusadapter:distributed_audio_softbus_adapter", - "//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", diff --git a/common/dfx_utils/test/unittest/BUILD.gn b/common/dfx_utils/test/unittest/BUILD.gn index a9d5dfde..0fe58a99 100644 --- a/common/dfx_utils/test/unittest/BUILD.gn +++ b/common/dfx_utils/test/unittest/BUILD.gn @@ -51,7 +51,6 @@ config("module_private_config") { "${services_path}/common/audiodata/include", "${services_path}/common/audioeventcallback", "${services_path}/audiomanager/managersource/include", - "${softbusadapter_path}/include", "//third_party/json/include", "${fwk_common_path}/utils/include", "${mediastandardfwk_path}/audiocapturer/include", diff --git a/distributedaudio.gni b/distributedaudio.gni index 264438a5..06e5b9b9 100644 --- a/distributedaudio.gni +++ b/distributedaudio.gni @@ -30,7 +30,6 @@ audio_control_path = "${services_path}/audiocontrol" audio_hdi_proxy_path = "${services_path}/audiohdiproxy" audio_processor_path = "${services_path}/audioprocessor" audio_transport_path = "${services_path}/audiotransport" -softbusadapter_path = "${services_path}/softbusadapter" interfaces_path = "${distributedaudio_path}/interfaces" hdf_interfaces_path = "//drivers/interface/distributed_audio" hdf_service_path = "//drivers/peripheral/distributed_audio" diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 5e3e3b7b..588e4a1a 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -30,19 +30,7 @@ group("fuzztest") { "${services_path}/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer:fuzztest", - "${services_path}/audioprocessor/test/fuzztest/decoderonerror_fuzzer:fuzztest", - "${services_path}/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer:fuzztest", - "${services_path}/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer:fuzztest", - "${services_path}/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer:fuzztest", - "${services_path}/audioprocessor/test/fuzztest/encoderonerror_fuzzer:fuzztest", - "${services_path}/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer:fuzztest", - "${services_path}/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer:fuzztest", - "${services_path}/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer:fuzztest", "${services_path}/common/test/fuzztest/audiodatasetinit64_fuzzer:fuzztest", - "${services_path}/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer:fuzztest", - "${services_path}/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer:fuzztest", - "${services_path}/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer:fuzztest", - "${services_path}/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer:fuzztest", "onremotesinksvrdied_fuzzer:fuzztest", "onremotesourcesvrdied_fuzzer:fuzztest", "sinkhandlerfinishstartsa_fuzzer:fuzztest", diff --git a/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn index 0e901571..a6bc0c5b 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn @@ -29,6 +29,5 @@ group("unittest") { "${services_path}/audioprocessor/test/unittest:daudio_processor_test", "${services_path}/audiotransport/test/unittest:daudio_transport_test", "${services_path}/hdfaudioclient/test/unittest:audio_adapter_hdi_test", - "${services_path}/softbusadapter/test/unittest:audio_soft_bus_adapter_test", ] } diff --git a/services/audioclient/test/unittest/micclient/BUILD.gn b/services/audioclient/test/unittest/micclient/BUILD.gn index aeec741c..b7cbbe12 100644 --- a/services/audioclient/test/unittest/micclient/BUILD.gn +++ b/services/audioclient/test/unittest/micclient/BUILD.gn @@ -43,7 +43,6 @@ config("module_private_config") { "${services_path}/common/audioeventcallback", "${services_path}/common/audiodata/include", "${services_path}/common/audioparam", - "${softbusadapter_path}/include", ] } diff --git a/services/audioclient/test/unittest/spkclient/BUILD.gn b/services/audioclient/test/unittest/spkclient/BUILD.gn index 190b39ce..13752c18 100644 --- a/services/audioclient/test/unittest/spkclient/BUILD.gn +++ b/services/audioclient/test/unittest/spkclient/BUILD.gn @@ -48,7 +48,6 @@ config("module_private_config") { "${services_path}/common/audioeventcallback", "${services_path}/common/audiodata/include", "${services_path}/common/audioparam", - "${softbusadapter_path}/include", ] } diff --git a/services/audiomanager/managersource/src/dspeaker_dev.cpp b/services/audiomanager/managersource/src/dspeaker_dev.cpp index c6227b17..fe8fd85d 100644 --- a/services/audiomanager/managersource/src/dspeaker_dev.cpp +++ b/services/audiomanager/managersource/src/dspeaker_dev.cpp @@ -182,7 +182,8 @@ int32_t DSpeakerDev::SetUp() { DHLOGI("Set up speaker device."); if (speakerTrans_ == nullptr) { - speakerTrans_ = std::make_shared(devId_); + DHLOGE("Spk trans should be init by dev."); + return ERR_DH_AUDIO_NULLPTR; } int32_t ret = speakerTrans_->SetUp(param_, param_, shared_from_this(), CAP_SPK); diff --git a/services/audiomanager/servicesink/BUILD.gn b/services/audiomanager/servicesink/BUILD.gn index 1fbb8415..cacc815e 100755 --- a/services/audiomanager/servicesink/BUILD.gn +++ b/services/audiomanager/servicesink/BUILD.gn @@ -60,7 +60,6 @@ ohos_shared_library("distributed_audio_sink") { "${services_path}/common/audioeventcallback", "${services_path}/common/audiodata/include", "${services_path}/common/audioparam", - "${softbusadapter_path}/include", ] sources = [ diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index ef24912c..69558dc5 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -70,7 +70,6 @@ ohos_shared_library("distributed_audio_source") { "${services_path}/common/audioparam", "${services_path}/hdfaudioclient/include", "${services_path}/audiomanager/common/include", - "${softbusadapter_path}/include", ] sources = [ diff --git a/services/audiomanager/test/unittest/servicesource/BUILD.gn b/services/audiomanager/test/unittest/servicesource/BUILD.gn index a451284d..02053202 100644 --- a/services/audiomanager/test/unittest/servicesource/BUILD.gn +++ b/services/audiomanager/test/unittest/servicesource/BUILD.gn @@ -70,7 +70,6 @@ config("module_private_config") { "${services_path}/common/audioeventcallback", "${services_path}/common/audioparam", "${services_path}/hdfaudioclient/include", - "${softbusadapter_path}/include", ] } diff --git a/services/audiomanager/test/unittest/sourcedevice/BUILD.gn b/services/audiomanager/test/unittest/sourcedevice/BUILD.gn index 471bd430..88988381 100644 --- a/services/audiomanager/test/unittest/sourcedevice/BUILD.gn +++ b/services/audiomanager/test/unittest/sourcedevice/BUILD.gn @@ -56,7 +56,6 @@ config("module_private_config") { "${services_path}/common/audiodata/include", "${services_path}/common/audioeventcallback", "${services_path}/hdfaudioclient/include", - "${softbusadapter_path}/include", ] } diff --git a/services/audiomanager/test/unittest/sourcedevice/src/dspeaker_dev_test.cpp b/services/audiomanager/test/unittest/sourcedevice/src/dspeaker_dev_test.cpp index bac98e50..e3aae6f8 100644 --- a/services/audiomanager/test/unittest/sourcedevice/src/dspeaker_dev_test.cpp +++ b/services/audiomanager/test/unittest/sourcedevice/src/dspeaker_dev_test.cpp @@ -165,7 +165,7 @@ HWTEST_F(DSpeakerDevTest, NotifyEvent_001, TestSize.Level1) HWTEST_F(DSpeakerDevTest, SetUp_001, TestSize.Level1) { spk_->speakerTrans_ = nullptr; - EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, spk_->SetUp()); + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, spk_->SetUp()); spk_->speakerTrans_ = std::make_shared(); EXPECT_EQ(DH_SUCCESS, spk_->SetUp()); @@ -196,7 +196,7 @@ HWTEST_F(DSpeakerDevTest, Start_001, TestSize.Level1) HWTEST_F(DSpeakerDevTest, Start_002, TestSize.Level1) { spk_->speakerTrans_ = nullptr; - EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, spk_->SetUp()); + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, spk_->SetUp()); EXPECT_NE(DH_SUCCESS, spk_->Start()); EXPECT_FALSE(spk_->IsOpened()); } @@ -228,7 +228,7 @@ HWTEST_F(DSpeakerDevTest, Stop_001, TestSize.Level1) { spk_->speakerTrans_ = nullptr; EXPECT_EQ(DH_SUCCESS, spk_->Stop()); - EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, spk_->SetUp()); + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, spk_->SetUp()); EXPECT_EQ(DH_SUCCESS, spk_->Stop()); spk_->speakerTrans_ = std::make_shared(); @@ -245,7 +245,7 @@ HWTEST_F(DSpeakerDevTest, Stop_001, TestSize.Level1) HWTEST_F(DSpeakerDevTest, Stop_002, TestSize.Level1) { spk_->speakerTrans_ = nullptr; - EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, spk_->SetUp()); + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, spk_->SetUp()); EXPECT_NE(DH_SUCCESS, spk_->Start()); EXPECT_EQ(DH_SUCCESS, spk_->Stop()); EXPECT_FALSE(spk_->IsOpened()); diff --git a/services/audiomanager/test/unittest/sourcemanager/BUILD.gn b/services/audiomanager/test/unittest/sourcemanager/BUILD.gn index c5d37879..a257aad0 100644 --- a/services/audiomanager/test/unittest/sourcemanager/BUILD.gn +++ b/services/audiomanager/test/unittest/sourcemanager/BUILD.gn @@ -54,7 +54,6 @@ config("module_private_config") { "${services_path}/common/audioparam", "${services_path}/common/taskProcessor/include", "${services_path}/hdfaudioclient/include", - "${softbusadapter_path}/include", ] } diff --git a/services/audioprocessor/decodeprocessor/include/audio_decoder_processor.h b/services/audioprocessor/decodeprocessor/include/audio_decoder_processor.h deleted file mode 100644 index 07f7c55e..00000000 --- a/services/audioprocessor/decodeprocessor/include/audio_decoder_processor.h +++ /dev/null @@ -1,55 +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_DECODER_PROCESSOR_H -#define OHOS_IAUDIO_DECODER_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 AudioDecoderProcessor : public IAudioProcessor, public IAudioCodecCallback, - public std::enable_shared_from_this { -public: - AudioDecoderProcessor() = default; - ~AudioDecoderProcessor() override; - - 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; - - void OnCodecDataDone(const std::shared_ptr &outputData) override; - void OnCodecStateNotify(const AudioEvent &event) override; - -private: - std::shared_ptr audioDecoder_ = nullptr; - AudioCommonParam localDevParam_; - AudioCommonParam remoteDevParam_; - std::weak_ptr procCallback_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_IAUDIO_DECODER_PROCESSOR_H diff --git a/services/audioprocessor/decodeprocessor/src/audio_decoder_processor.cpp b/services/audioprocessor/decodeprocessor/src/audio_decoder_processor.cpp deleted file mode 100644 index 11ffdbe4..00000000 --- a/services/audioprocessor/decodeprocessor/src/audio_decoder_processor.cpp +++ /dev/null @@ -1,166 +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_decoder_processor.h" - -#include "daudio_errorcode.h" -#include "daudio_hisysevent.h" -#include "daudio_hitrace.h" -#include "daudio_log.h" -#include "audio_decoder.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioDecoderProcessor" - -namespace OHOS { -namespace DistributedHardware { -AudioDecoderProcessor::~AudioDecoderProcessor() -{ - if (audioDecoder_ != nullptr) { - DHLOGI("Release audio processor."); - StopAudioProcessor(); - ReleaseAudioProcessor(); - } -} - -int32_t AudioDecoderProcessor::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; - } - - localDevParam_ = localDevParam; - remoteDevParam_ = remoteDevParam; - procCallback_ = procCallback; - - audioDecoder_ = std::make_shared(); - int32_t ret = audioDecoder_->ConfigureAudioCodec(localDevParam, shared_from_this()); - if (ret != DH_SUCCESS) { - DHLOGE("Configure decoder fail. Error code: %d.", ret); - ReleaseAudioProcessor(); - return ret; - } - return DH_SUCCESS; -} - -int32_t AudioDecoderProcessor::ReleaseAudioProcessor() -{ - DHLOGI("Release audio processor."); - if (audioDecoder_ == nullptr) { - DHLOGE("Decoder is null."); - return DH_SUCCESS; - } - - DAUDIO_SYNC_TRACE(DAUDIO_RELEASE_DECODER_PROCESSOR); - int32_t ret = audioDecoder_->ReleaseAudioCodec(); - if (ret != DH_SUCCESS) { - DHLOGE("Release decoder fail. Error code: %d.", ret); - } - - audioDecoder_ = nullptr; - return DH_SUCCESS; -} - -int32_t AudioDecoderProcessor::StartAudioProcessor() -{ - DHLOGI("Start audio processor."); - if (audioDecoder_ == nullptr) { - DHLOGE("Decoder is null."); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ERR_DH_AUDIO_BAD_VALUE, - "daudio decoder is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - - DAUDIO_SYNC_TRACE(DAUDIO_START_DECODER_PROCESSOR); - int32_t ret = audioDecoder_->StartAudioCodec(); - if (ret != DH_SUCCESS) { - DHLOGE("Start decoder fail. Error code: %d.", ret); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ret, - "daudio start decoder fail."); - return ret; - } - - DHLOGI("Start audio processor success."); - return DH_SUCCESS; -} - -int32_t AudioDecoderProcessor::StopAudioProcessor() -{ - DHLOGI("Stop audio processor."); - if (audioDecoder_ == nullptr) { - DHLOGE("Decoder is null."); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ERR_DH_AUDIO_BAD_VALUE, - "daudio decoder is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - - DAUDIO_SYNC_TRACE(DAUDIO_STOP_DECODER_PROCESSOR); - int32_t ret = audioDecoder_->StopAudioCodec(); - if (ret != DH_SUCCESS) { - DHLOGE("Stop decoder fail. Error code: %d.", ret); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ret, - "daudio stop decoder fail."); - return ret; - } - - return DH_SUCCESS; -} - -int32_t AudioDecoderProcessor::FeedAudioProcessor(const std::shared_ptr &inputData) -{ - DHLOGD("Feed audio processor."); - if (inputData == nullptr) { - DHLOGE("Input data is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - - if (audioDecoder_ == nullptr) { - DHLOGE("Decoder is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - return audioDecoder_->FeedAudioData(inputData); -} - -void AudioDecoderProcessor::OnCodecDataDone(const std::shared_ptr &outputData) -{ - if (outputData == nullptr) { - DHLOGE("Output data is null."); - return; - } - DHLOGD("Codec done. Output data size %zu.", outputData->Size()); - - auto cbObj = procCallback_.lock(); - if (cbObj == nullptr) { - DHLOGE("Processor callback is null."); - return; - } - cbObj->OnAudioDataDone(outputData); -} - -void AudioDecoderProcessor::OnCodecStateNotify(const AudioEvent &event) -{ - DHLOGI("Codec state notify."); - auto cbObj = procCallback_.lock(); - if (cbObj == nullptr) { - DHLOGE("Processor callback is null."); - return; - } - cbObj->OnStateNotify(event); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/audioprocessor/decoder/include/audio_decoder.h b/services/audioprocessor/decoder/include/audio_decoder.h deleted file mode 100644 index 6c9f628d..00000000 --- a/services/audioprocessor/decoder/include/audio_decoder.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2022-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_DECODER_H -#define OHOS_AUDIO_DECODER_H - -#include -#include -#include -#include - -#include "avcodec_common.h" -#include "avcodec_audio_decoder.h" -#include "format.h" - -#include "audio_data.h" -#include "audio_event.h" -#include "audio_param.h" -#include "iaudio_codec.h" -#include "iaudio_codec_callback.h" - -namespace OHOS { -namespace DistributedHardware { -class AudioDecoder : public IAudioCodec, public std::enable_shared_from_this { -public: - AudioDecoder() = default; - ~AudioDecoder() override; - - int32_t ConfigureAudioCodec(const AudioCommonParam &codecParam, - const std::shared_ptr &codecCallback) override; - int32_t ReleaseAudioCodec() override; - int32_t StartAudioCodec() override; - int32_t StopAudioCodec() override; - int32_t FeedAudioData(const std::shared_ptr &inputData) override; - - void OnInputBufferAvailable(uint32_t index); - void OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, Media::AVCodecBufferFlag flag); - void OnOutputFormatChanged(const Media::Format &format); - void OnError(const AudioEvent &event); - -private: - int32_t InitAudioDecoder(const AudioCommonParam &codecParam); - int32_t SetDecoderFormat(const AudioCommonParam &codecParam); - bool IsInDecodeRange(const AudioCommonParam &codecParam); - void StartInputThread(); - void StopInputThread(); - void IncreaseWaitDecodeCnt(); - void ReduceWaitDecodeCnt(); - void InputDecodeAudioData(); - int32_t ProcessData(const std::shared_ptr &audioData, const int32_t bufferIndex); - int64_t GetDecoderTimeStamp(); - int32_t DecodeDone(const std::shared_ptr &outputData); - -private: - constexpr static int32_t AUDIO_DECODER_QUEUE_MAX = 100; - constexpr static uint32_t DECODE_WAIT_MILLISECONDS = 50; - constexpr static int32_t INVALID_MEMORY_SIZE = -1; - constexpr static int32_t CHANNEL_MASK_MIN = 1; - constexpr static int32_t CHANNEL_MASK_MAX = 2; - constexpr static int32_t SAMPLE_RATE_MIN = 8000; - constexpr static int32_t SAMPLE_RATE_MAX = 96000; - const static std::string DECODE_MIME_AAC; - static constexpr const char* DECODE_THREAD = "decodeThread"; - - std::mutex mtxData_; - std::mutex mtxCnt_; - std::thread decodeThread_; - std::condition_variable decodeCond_; - - std::atomic isDecoderRunning_ = false; - int64_t firstInputTimeUs_ = 0; - int64_t inputTimeStampUs_ = 0; - int64_t outputTimeStampUs_ = 0; - int32_t waitOutputCount_ = 0; - - Media::Format cfgFormat_; - Media::Format outputFormat_; - AudioCommonParam codecParam_; - std::weak_ptr codecCallback_; - std::shared_ptr audioDecoder_ = nullptr; - std::shared_ptr decoderCallback_ = nullptr; - std::queue> inputBufQueue_; - std::queue bufIndexQueue_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_AUDIO_DECODER_H diff --git a/services/audioprocessor/decoder/include/audio_decoder_callback.h b/services/audioprocessor/decoder/include/audio_decoder_callback.h deleted file mode 100644 index 36168f94..00000000 --- a/services/audioprocessor/decoder/include/audio_decoder_callback.h +++ /dev/null @@ -1,47 +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_AUDIO_DECODER_CALLBACK_H -#define OHOS_AUDIO_DECODER_CALLBACK_H - -#include - -#include "avcodec_common.h" -#include "media_errors.h" -#include "format.h" - -#include "audio_decoder.h" - -namespace OHOS { -namespace DistributedHardware { -class AudioDecoder; - -class AudioDecoderCallback : public Media::AVCodecCallback { -public: - explicit AudioDecoderCallback(const std::weak_ptr &decoder) - : audioDecoder_(decoder) {}; - ~AudioDecoderCallback() override = default; - - void OnError(Media::AVCodecErrorType errorType, int32_t errorCode) override; - void OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, Media::AVCodecBufferFlag flag) override; - void OnInputBufferAvailable(uint32_t index) override; - void OnOutputFormatChanged(const Media::Format &format) override; - -private: - std::weak_ptr audioDecoder_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_AUDIO_DECODER_CALLBACK_H diff --git a/services/audioprocessor/decoder/src/audio_decoder.cpp b/services/audioprocessor/decoder/src/audio_decoder.cpp deleted file mode 100644 index 2d532421..00000000 --- a/services/audioprocessor/decoder/src/audio_decoder.cpp +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Copyright (c) 2022-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_decoder.h" - -#include "audio_info.h" -#include "avsharedmemory.h" -#include "media_errors.h" -#include "securec.h" - -#include "audio_decoder_callback.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" -#include "daudio_util.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioDecoder" - -namespace OHOS { -namespace DistributedHardware { -const std::string AudioDecoder::DECODE_MIME_AAC = "audio/mp4a-latm"; - -AudioDecoder::~AudioDecoder() -{ - if (audioDecoder_ != nullptr) { - DHLOGI("Release audio codec."); - StopAudioCodec(); - ReleaseAudioCodec(); - } -} - -int32_t AudioDecoder::ConfigureAudioCodec(const AudioCommonParam &codecParam, - const std::shared_ptr &codecCallback) -{ - DHLOGI("Configure audio codec."); - if (!IsInDecodeRange(codecParam) || codecCallback == nullptr) { - DHLOGE("Codec param error or callback is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - codecParam_ = codecParam; - codecCallback_ = codecCallback; - - int32_t ret = InitAudioDecoder(codecParam); - if (ret != DH_SUCCESS) { - DHLOGE("Init audio decoder fail. Error code %d.", ret); - return ret; - } - - ret = SetDecoderFormat(codecParam); - if (ret != DH_SUCCESS) { - DHLOGE("Set decoder format fail. Error code %d.", ret); - return ret; - } - return DH_SUCCESS; -} - -bool AudioDecoder::IsInDecodeRange(const AudioCommonParam &codecParam) -{ - if (codecParam.channelMask >= CHANNEL_MASK_MIN && codecParam.channelMask <= CHANNEL_MASK_MAX && - codecParam.sampleRate >= SAMPLE_RATE_MIN && codecParam.sampleRate <= SAMPLE_RATE_MAX && - codecParam.bitFormat == SAMPLE_S16LE && codecParam.codecType == AUDIO_CODEC_AAC) { - return true; - } - - DHLOGE("Param error, codec type %d, channel count %d, sample rate %d, sample format %d.", - codecParam.codecType, codecParam.channelMask, codecParam.sampleRate, codecParam.bitFormat); - return false; -} - -int32_t AudioDecoder::InitAudioDecoder(const AudioCommonParam &codecParam) -{ - DHLOGI("Init audio decoder."); - audioDecoder_ = Media::AudioDecoderFactory::CreateByMime(DECODE_MIME_AAC); - if (audioDecoder_ == nullptr) { - DHLOGE("Create audio decoder fail."); - return ERR_DH_AUDIO_CODEC_CONFIG; - } - - decoderCallback_ = std::make_shared(shared_from_this()); - int32_t ret = audioDecoder_->SetCallback(decoderCallback_); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Set decoder callback fail. Error code %d.", ret); - decoderCallback_ = nullptr; - return ERR_DH_AUDIO_CODEC_CONFIG; - } - - return DH_SUCCESS; -} - -int32_t AudioDecoder::SetDecoderFormat(const AudioCommonParam &codecParam) -{ - if (audioDecoder_ == nullptr) { - DHLOGE("Decoder is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - - DHLOGI("Set encoder format, codec type %d, channel count %d, sample rate %d, sample format %d.", - codecParam.codecType, codecParam.channelMask, codecParam.sampleRate, codecParam.bitFormat); - cfgFormat_.PutIntValue("channel_count", codecParam.channelMask); - cfgFormat_.PutIntValue("sample_rate", codecParam.sampleRate); - cfgFormat_.PutIntValue("audio_sample_format", - static_cast(codecParam.bitFormat)); - - int32_t ret = audioDecoder_->Configure(cfgFormat_); - if (ret != Media::MSERR_OK) { - DHLOGE("Configure decoder format fail. Error code %d.", ret); - return ERR_DH_AUDIO_CODEC_CONFIG; - } - - ret = audioDecoder_->Prepare(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Decoder prepare fail. Error code %d.", ret); - return ERR_DH_AUDIO_CODEC_CONFIG; - } - return DH_SUCCESS; -} - -int32_t AudioDecoder::ReleaseAudioCodec() -{ - DHLOGI("Release audio codec."); - if (audioDecoder_ == nullptr) { - DHLOGE("Decoder is null."); - return DH_SUCCESS; - } - - int32_t ret = audioDecoder_->Release(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Decoder release fail. Error code %d.", ret); - return ERR_DH_AUDIO_BAD_OPERATE; - } - decoderCallback_ = nullptr; - audioDecoder_ = nullptr; - - DHLOGI("Release audio codec end."); - return DH_SUCCESS; -} - -int32_t AudioDecoder::StartAudioCodec() -{ - DHLOGI("Start audio codec."); - if (audioDecoder_ == nullptr) { - DHLOGE("Decoder is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - - int32_t ret = audioDecoder_->Start(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Decoder start fail. Error code %d.", ret); - return ERR_DH_AUDIO_CODEC_START; - } - StartInputThread(); - return DH_SUCCESS; -} - -void AudioDecoder::StartInputThread() -{ - DHLOGI("Start input thread."); - isDecoderRunning_.store(true); - decodeThread_ = std::thread(&AudioDecoder::InputDecodeAudioData, this); - if (pthread_setname_np(decodeThread_.native_handle(), DECODE_THREAD) != DH_SUCCESS) { - DHLOGE("Decode thread setname failed."); - } -} - -int32_t AudioDecoder::StopAudioCodec() -{ - DHLOGI("Stop audio codec."); - StopInputThread(); - if (audioDecoder_ == nullptr) { - DHLOGE("Decoder is null."); - return DH_SUCCESS; - } - - bool isSuccess = true; - int32_t ret = audioDecoder_->Flush(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Decoder flush fail. Error type: %d.", ret); - isSuccess = false; - } - ret = audioDecoder_->Stop(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Decoder stop fail. Error type: %d.", ret); - isSuccess = false; - } - if (!isSuccess) { - return ERR_DH_AUDIO_CODEC_STOP; - } - - firstInputTimeUs_ = 0; - inputTimeStampUs_ = 0; - outputTimeStampUs_ = 0; - waitOutputCount_ = 0; - DHLOGI("Stop audio codec end."); - return DH_SUCCESS; -} - -void AudioDecoder::StopInputThread() -{ - isDecoderRunning_.store(false); - decodeCond_.notify_all(); - if (decodeThread_.joinable()) { - decodeThread_.join(); - } - - std::lock_guard dataLock(mtxData_); - std::queue().swap(bufIndexQueue_); - std::queue>().swap(inputBufQueue_); - DHLOGI("Stop input thread success."); -} - -int32_t AudioDecoder::FeedAudioData(const std::shared_ptr &inputData) -{ - DHLOGD("Feed audio data."); - if (!isDecoderRunning_.load()) { - DHLOGE("Decoder is stopped."); - return ERR_DH_AUDIO_CODEC_INPUT; - } - if (inputData == nullptr) { - DHLOGE("Input data is nullptr."); - return ERR_DH_AUDIO_BAD_VALUE; - } - - std::lock_guard dataLock(mtxData_); - while (inputBufQueue_.size() > AUDIO_DECODER_QUEUE_MAX) { - DHLOGE("Input data queue overflow."); - inputBufQueue_.pop(); - } - inputBufQueue_.push(inputData); - decodeCond_.notify_all(); - - return DH_SUCCESS; -} - -void AudioDecoder::InputDecodeAudioData() -{ - DHLOGI("Input decode audio data thread start."); - while (isDecoderRunning_.load()) { - std::shared_ptr audioData; - int32_t bufferIndex = 0; - { - std::unique_lock lock(mtxData_); - decodeCond_.wait_for(lock, std::chrono::milliseconds(DECODE_WAIT_MILLISECONDS), - [this]() { - return (!inputBufQueue_.empty() && !bufIndexQueue_.empty()) || !isDecoderRunning_.load(); - }); - - if (inputBufQueue_.empty() || bufIndexQueue_.empty()) { - continue; - } - bufferIndex = (int32_t)bufIndexQueue_.front(); - bufIndexQueue_.pop(); - audioData = inputBufQueue_.front(); - inputBufQueue_.pop(); - } - - int32_t ret = ProcessData(audioData, bufferIndex); - if (ret == ERR_DH_AUDIO_BAD_VALUE) { - DHLOGE("Decoder is stopped or null."); - return; - } else if (ret != DH_SUCCESS) { - DHLOGE("Process data fail. Error type: %d.", ret); - continue; - } - } -} - -int32_t AudioDecoder::ProcessData(const std::shared_ptr &audioData, const int32_t bufferIndex) -{ - if (!isDecoderRunning_.load() || audioDecoder_ == nullptr) { - DHLOGE("Decoder is stopped or null, isRunning %d.", isDecoderRunning_.load()); - return ERR_DH_AUDIO_BAD_VALUE; - } - - auto inMem = audioDecoder_->GetInputBuffer(bufferIndex); - if (inMem == nullptr) { - DHLOGE("Get input buffer fail."); - return ERR_DH_AUDIO_CODEC_INPUT; - } - if (inMem->GetSize() == INVALID_MEMORY_SIZE || static_cast(inMem->GetSize()) < audioData->Size()) { - DHLOGE("Input buffer size error. Memory size %d, data size %zu.", - inMem->GetSize(), audioData->Size()); - return ERR_DH_AUDIO_CODEC_INPUT; - } - - errno_t err = memcpy_s(inMem->GetBase(), inMem->GetSize(), audioData->Data(), audioData->Size()); - if (err != EOK) { - DHLOGE("Copy input data fail. Error code %d. Memory size %d, data size %zu.", - err, inMem->GetSize(), audioData->Size()); - return ERR_DH_AUDIO_BAD_OPERATE; - } - - inputTimeStampUs_ = GetDecoderTimeStamp(); - Media::AVCodecBufferInfo bufferInfo = {inputTimeStampUs_, static_cast(audioData->Size()), 0}; - auto bufferFlag = - bufferInfo.presentationTimeUs == 0 ? Media::AVCODEC_BUFFER_FLAG_CODEC_DATA : Media::AVCODEC_BUFFER_FLAG_NONE; - DHLOGD("Queue input buffer. AVCodec Info: input time stamp %lld, data size %zu.", - (long long)bufferInfo.presentationTimeUs, audioData->Size()); - int32_t ret = audioDecoder_->QueueInputBuffer(bufferIndex, bufferInfo, bufferFlag); - if (ret != Media::MSERR_OK) { - DHLOGE("Queue input buffer fail. Error code %d", ret); - return ERR_DH_AUDIO_CODEC_INPUT; - } - - IncreaseWaitDecodeCnt(); - return DH_SUCCESS; -} - -int64_t AudioDecoder::GetDecoderTimeStamp() -{ - int64_t TimeIntervalStampUs = 0; - int64_t nowTimeUs = GetNowTimeUs(); - if (firstInputTimeUs_ == 0) { - firstInputTimeUs_ = nowTimeUs; - return TimeIntervalStampUs; - } - - TimeIntervalStampUs = nowTimeUs - firstInputTimeUs_; - return TimeIntervalStampUs; -} - -void AudioDecoder::IncreaseWaitDecodeCnt() -{ - std::lock_guard countLock(mtxCnt_); - waitOutputCount_++; - DHLOGD("Wait decoder output frames number is %d.", waitOutputCount_); -} - -void AudioDecoder::ReduceWaitDecodeCnt() -{ - std::lock_guard countLock(mtxCnt_); - if (waitOutputCount_ <= 0) { - DHLOGE("Wait decoder output count %d.", waitOutputCount_); - } - waitOutputCount_--; - DHLOGD("Wait decoder output frames number is %d.", waitOutputCount_); -} - -void AudioDecoder::OnInputBufferAvailable(uint32_t index) -{ - std::lock_guard countLock(mtxData_); - while (bufIndexQueue_.size() > AUDIO_DECODER_QUEUE_MAX) { - DHLOGE("Index queue overflow."); - bufIndexQueue_.pop(); - } - - bufIndexQueue_.push(index); - decodeCond_.notify_all(); -} - -void AudioDecoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, - Media::AVCodecBufferFlag flag) -{ - if (!isDecoderRunning_.load() || audioDecoder_ == nullptr) { - DHLOGE("Decoder is stopped or null, isRunning %d.", isDecoderRunning_.load()); - return; - } - - auto outMem = audioDecoder_->GetOutputBuffer(index); - if (outMem == nullptr) { - DHLOGE("Get output buffer fail. index %u.", index); - return; - } - if (info.size <= 0 || info.size > outMem->GetSize()) { - DHLOGE("Codec output info error. AVCodec info: size %d, memory size %d.", - info.size, outMem->GetSize()); - return; - } - - auto outBuf = std::make_shared(static_cast(info.size)); - errno_t err = memcpy_s(outBuf->Data(), outBuf->Size(), outMem->GetBase(), static_cast(info.size)); - if (err != EOK) { - DHLOGE("Copy output data fail. Error code %d. Buffer Size %zu, AVCodec info: size %d.", - err, outBuf->Size(), info.size); - return; - } - outBuf->SetInt64("timeUs", info.presentationTimeUs); - outputTimeStampUs_ = info.presentationTimeUs; - DHLOGD("Get output buffer. AVCodec info: output time stamp %lld, data size %zu.", - (long long)info.presentationTimeUs, outBuf->Size()); - - ReduceWaitDecodeCnt(); - err = DecodeDone(outBuf); - if (err != DH_SUCCESS) { - DHLOGE("Decode done fail. Error code: %d.", err); - return; - } - - err = audioDecoder_->ReleaseOutputBuffer(index); - if (err != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Release output buffer fail. Error code: %d, index %u.", err, index); - } -} - -void AudioDecoder::OnOutputFormatChanged(const Media::Format &format) -{ - if (format.GetFormatMap().empty()) { - DHLOGE("The first changed output frame format is null."); - return; - } - outputFormat_ = format; -} - -void AudioDecoder::OnError(const AudioEvent &event) -{ - DHLOGE("Decoder error."); - std::shared_ptr cbObj = codecCallback_.lock(); - if (cbObj == nullptr) { - DHLOGE("Codec callback is null."); - return; - } - cbObj->OnCodecStateNotify(event); -} - -int32_t AudioDecoder::DecodeDone(const std::shared_ptr &outputData) -{ - DHLOGD("Decode done."); - std::shared_ptr cbObj = codecCallback_.lock(); - if (cbObj == nullptr) { - DHLOGE("Codec callback is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - cbObj->OnCodecDataDone(outputData); - return DH_SUCCESS; -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/audioprocessor/decoder/src/audio_decoder_callback.cpp b/services/audioprocessor/decoder/src/audio_decoder_callback.cpp deleted file mode 100644 index 410bc928..00000000 --- a/services/audioprocessor/decoder/src/audio_decoder_callback.cpp +++ /dev/null @@ -1,72 +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_decoder_callback.h" - -#include "daudio_log.h" -#include "audio_event.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioDecoderCallback" - -namespace OHOS { -namespace DistributedHardware { -void AudioDecoderCallback::OnError(Media::AVCodecErrorType errorType, int32_t errorCode) -{ - DHLOGE("On error. Error type: %d, Error code: %d ", errorType, errorCode); - std::shared_ptr decObj = audioDecoder_.lock(); - if (decObj == nullptr) { - DHLOGE("Decoder is nullptr."); - return; - } - AudioEvent decoderErr = {AUDIO_DECODER_ERR, ""}; - decObj->OnError(decoderErr); -} - -void AudioDecoderCallback::OnInputBufferAvailable(uint32_t index) -{ - DHLOGD("On input buffer available. index %u.", index); - std::shared_ptr decObj = audioDecoder_.lock(); - if (decObj == nullptr) { - DHLOGE("Decoder is nullptr."); - return; - } - decObj->OnInputBufferAvailable(index); -} - -void AudioDecoderCallback::OnOutputFormatChanged(const Media::Format &format) -{ - DHLOGD("On output format changed."); - std::shared_ptr decObj = audioDecoder_.lock(); - if (decObj == nullptr) { - DHLOGE("Decoder is nullptr."); - return; - } - decObj->OnOutputFormatChanged(format); -} - -void AudioDecoderCallback::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, - Media::AVCodecBufferFlag flag) -{ - DHLOGD("On output buffer available. index %u.", index); - std::shared_ptr decObj = audioDecoder_.lock(); - if (decObj == nullptr) { - DHLOGE("Decoder is nullptr."); - return; - } - decObj->OnOutputBufferAvailable(index, info, flag); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/audioprocessor/encodeprocessor/include/audio_encoder_processor.h b/services/audioprocessor/encodeprocessor/include/audio_encoder_processor.h deleted file mode 100644 index f8a97b24..00000000 --- a/services/audioprocessor/encodeprocessor/include/audio_encoder_processor.h +++ /dev/null @@ -1,55 +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_ENCODER_PROCESSOR_H -#define OHOS_IAUDIO_ENCODER_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 AudioEncoderProcessor : public IAudioProcessor, public IAudioCodecCallback, - public std::enable_shared_from_this { -public: - AudioEncoderProcessor() = default; - ~AudioEncoderProcessor() override; - - 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; - - void OnCodecDataDone(const std::shared_ptr &outputData) override; - void OnCodecStateNotify(const AudioEvent &event) override; - -private: - std::shared_ptr audioEncoder_ = nullptr; - AudioCommonParam localDevParam_; - AudioCommonParam remoteDevParam_; - std::weak_ptr procCallback_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_IAUDIO_ENCODER_PROCESSOR_H diff --git a/services/audioprocessor/encodeprocessor/src/audio_encoder_processor.cpp b/services/audioprocessor/encodeprocessor/src/audio_encoder_processor.cpp deleted file mode 100644 index d3473b05..00000000 --- a/services/audioprocessor/encodeprocessor/src/audio_encoder_processor.cpp +++ /dev/null @@ -1,164 +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_encoder_processor.h" - -#include "daudio_errorcode.h" -#include "daudio_hisysevent.h" -#include "daudio_hitrace.h" -#include "daudio_log.h" -#include "audio_encoder.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioEncoderProcessor" - -namespace OHOS { -namespace DistributedHardware { -AudioEncoderProcessor::~AudioEncoderProcessor() -{ - if (audioEncoder_ != nullptr) { - DHLOGD("Release audio processor."); - StopAudioProcessor(); - ReleaseAudioProcessor(); - } -} - -int32_t AudioEncoderProcessor::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; - } - localDevParam_ = localDevParam; - remoteDevParam_ = remoteDevParam; - procCallback_ = procCallback; - - audioEncoder_ = std::make_shared(); - int32_t ret = audioEncoder_->ConfigureAudioCodec(localDevParam, shared_from_this()); - if (ret != DH_SUCCESS) { - DHLOGE("Configure encoder fail. Error code: %d.", ret); - ReleaseAudioProcessor(); - return ret; - } - return DH_SUCCESS; -} - -int32_t AudioEncoderProcessor::ReleaseAudioProcessor() -{ - DHLOGI("Release audio processor."); - if (audioEncoder_ == nullptr) { - DHLOGE("Encoder is null."); - return DH_SUCCESS; - } - - DAUDIO_SYNC_TRACE(DAUDIO_RELEASE_ENCODER_PROCESSOR); - int32_t ret = audioEncoder_->ReleaseAudioCodec(); - if (ret != DH_SUCCESS) { - DHLOGE("Release encoder fail. Error code: %d.", ret); - } - - audioEncoder_ = nullptr; - return DH_SUCCESS; -} - -int32_t AudioEncoderProcessor::StartAudioProcessor() -{ - DHLOGI("Start audio processor."); - if (audioEncoder_ == nullptr) { - DHLOGE("Encoder is null."); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ERR_DH_AUDIO_BAD_VALUE, - "daudio encoder is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - - DAUDIO_SYNC_TRACE(DAUDIO_START_ENCODER_PROCESSOR); - int32_t ret = audioEncoder_->StartAudioCodec(); - if (ret != DH_SUCCESS) { - DHLOGE("Start encoder fail. Error code: %d.", ret); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ret, - "daudio start encoder fail."); - return ret; - } - - return DH_SUCCESS; -} - -int32_t AudioEncoderProcessor::StopAudioProcessor() -{ - DHLOGI("Stop audio processor."); - if (audioEncoder_ == nullptr) { - DHLOGE("Encoder is null."); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ERR_DH_AUDIO_BAD_VALUE, - "daudio encoder is null."); - return DH_SUCCESS; - } - - DAUDIO_SYNC_TRACE(DAUDIO_STOP_ENCODER_PROCESSOR); - int32_t ret = audioEncoder_->StopAudioCodec(); - if (ret != DH_SUCCESS) { - DHLOGE("Stop encoder fail. Error code: %d.", ret); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ret, - "daudio stop decoder fail."); - return ret; - } - - return DH_SUCCESS; -} - -int32_t AudioEncoderProcessor::FeedAudioProcessor(const std::shared_ptr &inputData) -{ - DHLOGD("Feed audio processor."); - if (inputData == nullptr) { - DHLOGE("Input data is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - - if (audioEncoder_ == nullptr) { - DHLOGE("Encoder is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - return audioEncoder_->FeedAudioData(inputData); -} - -void AudioEncoderProcessor::OnCodecDataDone(const std::shared_ptr &outputData) -{ - if (outputData == nullptr) { - DHLOGE("Output data is null."); - return; - } - DHLOGD("Codec done. Output data size %zu.", outputData->Size()); - - auto cbObj = procCallback_.lock(); - if (cbObj == nullptr) { - DHLOGE("Processor callback is null."); - return; - } - cbObj->OnAudioDataDone(outputData); -} - -void AudioEncoderProcessor::OnCodecStateNotify(const AudioEvent &event) -{ - DHLOGD("Codec state notify."); - auto cbObj = procCallback_.lock(); - if (cbObj == nullptr) { - DHLOGE("Processor callback is null."); - return; - } - cbObj->OnStateNotify(event); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/audioprocessor/encoder/include/audio_encoder.h b/services/audioprocessor/encoder/include/audio_encoder.h deleted file mode 100644 index 5a9ef594..00000000 --- a/services/audioprocessor/encoder/include/audio_encoder.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2022-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_ENCODER_H -#define OHOS_AUDIO_ENCODER_H - -#include -#include -#include -#include - -#include "avcodec_common.h" -#include "avcodec_audio_encoder.h" -#include "format.h" - -#include "audio_data.h" -#include "audio_event.h" -#include "audio_param.h" -#include "iaudio_codec.h" -#include "iaudio_codec_callback.h" - -namespace OHOS { -namespace DistributedHardware { -class AudioEncoder : public IAudioCodec, public std::enable_shared_from_this { -public: - AudioEncoder() = default; - ~AudioEncoder() override; - - int32_t ConfigureAudioCodec(const AudioCommonParam &codecParam, - const std::shared_ptr &codecCallback) override; - int32_t ReleaseAudioCodec() override; - int32_t StartAudioCodec() override; - int32_t StopAudioCodec() override; - int32_t FeedAudioData(const std::shared_ptr &inputData) override; - - void OnInputBufferAvailable(uint32_t index); - void OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, Media::AVCodecBufferFlag flag); - void OnOutputFormatChanged(const Media::Format &format); - void OnError(const AudioEvent &event); - -private: - int32_t InitAudioEncoder(const AudioCommonParam &codecParam); - int32_t SetEncoderFormat(const AudioCommonParam &codecParam); - bool IsInEncodeRange(const AudioCommonParam &codecParam); - void StartInputThread(); - void StopInputThread(); - void IncreaseWaitEncodeCnt(); - void ReduceWaitEncodeCnt(); - void InputEncodeAudioData(); - int32_t ProcessData(const std::shared_ptr &audioData, const int32_t bufferIndex); - int64_t GetEncoderTimeStamp(); - int32_t EncodeDone(const std::shared_ptr &outputData); - -private: - constexpr static int32_t AUDIO_ENCODER_QUEUE_MAX = 100; - constexpr static uint32_t ENCODE_WAIT_MILLISECONDS = 50; - constexpr static int32_t INVALID_MEMORY_SIZE = -1; - constexpr static int32_t CHANNEL_MASK_MIN = 1; - constexpr static int32_t CHANNEL_MASK_MAX = 2; - constexpr static int32_t SAMPLE_RATE_MIN = 8000; - constexpr static int32_t SAMPLE_RATE_MAX = 96000; - const static std::string ENCODE_MIME_AAC; - static constexpr const char* ENCODE_THREAD = "encodeThread"; - - std::mutex mtxData_; - std::mutex mtxCnt_; - std::thread encodeThread_; - std::condition_variable encodeCond_; - - std::atomic isEncoderRunning_ = false; - int64_t firstInputTimeUs_ = 0; - int64_t inputTimeStampUs_ = 0; - int64_t outputTimeStampUs_ = 0; - int32_t waitOutputCount_ = 0; - - Media::Format cfgFormat_; - Media::Format outputFormat_; - AudioCommonParam codecParam_; - std::weak_ptr codecCallback_; - std::shared_ptr audioEncoder_ = nullptr; - std::shared_ptr encoderCallback_ = nullptr; - std::queue> inputBufQueue_; - std::queue bufIndexQueue_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_AUDIO_ENCODER_H diff --git a/services/audioprocessor/encoder/include/audio_encoder_callback.h b/services/audioprocessor/encoder/include/audio_encoder_callback.h deleted file mode 100644 index 1614ffac..00000000 --- a/services/audioprocessor/encoder/include/audio_encoder_callback.h +++ /dev/null @@ -1,46 +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_AUDIO_ENCODER_CALLBACK_H -#define OHOS_AUDIO_ENCODER_CALLBACK_H - -#include - -#include "avcodec_common.h" -#include "media_errors.h" -#include "format.h" - -#include "audio_encoder.h" - -namespace OHOS { -namespace DistributedHardware { -class AudioEncoder; -class AudioEncoderCallback : public Media::AVCodecCallback { -public: - explicit AudioEncoderCallback(const std::weak_ptr &encoder) - : audioEncoder_(encoder) {}; - ~AudioEncoderCallback() override = default; - - void OnError(Media::AVCodecErrorType errorType, int32_t errorCode) override; - void OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, Media::AVCodecBufferFlag flag) override; - void OnInputBufferAvailable(uint32_t index) override; - void OnOutputFormatChanged(const Media::Format &format) override; - -private: - std::weak_ptr audioEncoder_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_AUDIO_ENCODER_CALLBACK_H diff --git a/services/audioprocessor/encoder/src/audio_encoder.cpp b/services/audioprocessor/encoder/src/audio_encoder.cpp deleted file mode 100644 index 7283efbe..00000000 --- a/services/audioprocessor/encoder/src/audio_encoder.cpp +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Copyright (c) 2022-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_encoder.h" - -#include "audio_info.h" -#include "avsharedmemory.h" -#include "media_errors.h" -#include "securec.h" - -#include "audio_encoder_callback.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" -#include "daudio_util.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioEncoder" - -namespace OHOS { -namespace DistributedHardware { -const std::string AudioEncoder::ENCODE_MIME_AAC = "audio/mp4a-latm"; - -AudioEncoder::~AudioEncoder() -{ - if (audioEncoder_ != nullptr) { - DHLOGD("Release audio codec."); - StopAudioCodec(); - ReleaseAudioCodec(); - } -} - -int32_t AudioEncoder::ConfigureAudioCodec(const AudioCommonParam &codecParam, - const std::shared_ptr &codecCallback) -{ - DHLOGD("Configure audio codec."); - if (!IsInEncodeRange(codecParam) || codecCallback == nullptr) { - DHLOGE("Codec param error or callback is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - codecParam_ = codecParam; - codecCallback_ = codecCallback; - - int32_t ret = InitAudioEncoder(codecParam); - if (ret != DH_SUCCESS) { - DHLOGE("Init audio encoder fail. Error code %d.", ret); - return ret; - } - - ret = SetEncoderFormat(codecParam); - if (ret != DH_SUCCESS) { - DHLOGE("Set encoder format fail. Error code %d.", ret); - return ret; - } - return DH_SUCCESS; -} - -bool AudioEncoder::IsInEncodeRange(const AudioCommonParam &codecParam) -{ - if (codecParam.channelMask >= CHANNEL_MASK_MIN && codecParam.channelMask <= CHANNEL_MASK_MAX && - codecParam.sampleRate >= SAMPLE_RATE_MIN && codecParam.sampleRate <= SAMPLE_RATE_MAX && - codecParam.bitFormat == SAMPLE_S16LE && codecParam.codecType == AUDIO_CODEC_AAC) { - return true; - } - - DHLOGE("Param error, codec type %d, channel count %d, sample rate %d, sample format %d.", - codecParam.codecType, codecParam.channelMask, codecParam.sampleRate, codecParam.bitFormat); - return false; -} - -int32_t AudioEncoder::InitAudioEncoder(const AudioCommonParam &codecParam) -{ - DHLOGI("Init audio encoder."); - audioEncoder_ = Media::AudioEncoderFactory::CreateByMime(ENCODE_MIME_AAC); - if (audioEncoder_ == nullptr) { - DHLOGE("Create audio encoder fail."); - return ERR_DH_AUDIO_CODEC_CONFIG; - } - - encoderCallback_ = std::make_shared(shared_from_this()); - int32_t ret = audioEncoder_->SetCallback(encoderCallback_); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Set encoder callback fail. Error code %d.", ret); - encoderCallback_ = nullptr; - return ERR_DH_AUDIO_CODEC_CONFIG; - } - return DH_SUCCESS; -} - -int32_t AudioEncoder::SetEncoderFormat(const AudioCommonParam &codecParam) -{ - if (audioEncoder_ == nullptr) { - DHLOGE("Encoder is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - - DHLOGI("Set encoder format, codec type %d, channel count %d, sample rate %d, sample format %d.", - codecParam.codecType, codecParam.channelMask, codecParam.sampleRate, codecParam.bitFormat); - cfgFormat_.PutIntValue("channel_count", codecParam.channelMask); - cfgFormat_.PutIntValue("sample_rate", codecParam.sampleRate); - cfgFormat_.PutIntValue("audio_sample_format", - static_cast(codecParam.bitFormat)); - - int32_t ret = audioEncoder_->Configure(cfgFormat_); - if (ret != Media::MSERR_OK) { - DHLOGE("Configure encoder format fail. Error code %d.", ret); - return ERR_DH_AUDIO_CODEC_CONFIG; - } - - ret = audioEncoder_->Prepare(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Encoder prepare fail. Error code %d.", ret); - return ERR_DH_AUDIO_CODEC_CONFIG; - } - return DH_SUCCESS; -} - -int32_t AudioEncoder::ReleaseAudioCodec() -{ - DHLOGI("Release audio codec."); - if (audioEncoder_ == nullptr) { - DHLOGE("Encoder is null."); - return DH_SUCCESS; - } - - int32_t ret = audioEncoder_->Release(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Encoder release fail. Error type: %d.", ret); - return ERR_DH_AUDIO_CODEC_RELEASE; - } - encoderCallback_ = nullptr; - audioEncoder_ = nullptr; - DHLOGI("Release audio codec end."); - return DH_SUCCESS; -} - -int32_t AudioEncoder::StartAudioCodec() -{ - DHLOGI("Start audio codec."); - if (audioEncoder_ == nullptr) { - DHLOGE("Encoder is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - - int32_t ret = audioEncoder_->Start(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Encoder start fail. Error code %d.", ret); - return ERR_DH_AUDIO_CODEC_START; - } - StartInputThread(); - return DH_SUCCESS; -} - -void AudioEncoder::StartInputThread() -{ - DHLOGI("Start input thread."); - isEncoderRunning_.store(true); - encodeThread_ = std::thread(&AudioEncoder::InputEncodeAudioData, this); - if (pthread_setname_np(encodeThread_.native_handle(), ENCODE_THREAD) != DH_SUCCESS) { - DHLOGE("Encode thread setname failed."); - } -} - -int32_t AudioEncoder::StopAudioCodec() -{ - DHLOGI("Stop audio codec."); - StopInputThread(); - if (audioEncoder_ == nullptr) { - DHLOGE("Encoder is null."); - return DH_SUCCESS; - } - - bool isSuccess = true; - int32_t ret = audioEncoder_->Flush(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Encoder flush fail. Error type: %d.", ret); - isSuccess = false; - } - ret = audioEncoder_->Stop(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Encoder stop fail. Error type: %d.", ret); - isSuccess = false; - } - if (!isSuccess) { - return ERR_DH_AUDIO_CODEC_STOP; - } - - firstInputTimeUs_ = 0; - inputTimeStampUs_ = 0; - outputTimeStampUs_ = 0; - waitOutputCount_ = 0; - DHLOGI("Stop audio codec end."); - return DH_SUCCESS; -} - -void AudioEncoder::StopInputThread() -{ - isEncoderRunning_.store(false); - encodeCond_.notify_all(); - if (encodeThread_.joinable()) { - encodeThread_.join(); - } - - std::lock_guard dataLock(mtxData_); - std::queue().swap(bufIndexQueue_); - std::queue>().swap(inputBufQueue_); - DHLOGI("Stop input thread success."); -} - -int32_t AudioEncoder::FeedAudioData(const std::shared_ptr &inputData) -{ - DHLOGD("Feed audio data."); - if (!isEncoderRunning_.load()) { - DHLOGE("Encoder is stopped."); - return ERR_DH_AUDIO_CODEC_INPUT; - } - if (inputData == nullptr) { - DHLOGE("Input data is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - - std::lock_guard dataLock(mtxData_); - while (inputBufQueue_.size() > AUDIO_ENCODER_QUEUE_MAX) { - DHLOGE("Input data queue overflow."); - inputBufQueue_.pop(); - } - inputBufQueue_.push(inputData); - encodeCond_.notify_all(); - - return DH_SUCCESS; -} - -void AudioEncoder::InputEncodeAudioData() -{ - DHLOGI("Input encode audio data thread start."); - while (isEncoderRunning_.load()) { - std::shared_ptr audioData; - int32_t bufferIndex = 0; - { - std::unique_lock lock(mtxData_); - encodeCond_.wait_for(lock, std::chrono::milliseconds(ENCODE_WAIT_MILLISECONDS), - [this]() { - return (!inputBufQueue_.empty() && !bufIndexQueue_.empty()) || !isEncoderRunning_.load(); - }); - - if (inputBufQueue_.empty() || bufIndexQueue_.empty()) { - continue; - } - bufferIndex = (int32_t)bufIndexQueue_.front(); - bufIndexQueue_.pop(); - audioData = inputBufQueue_.front(); - inputBufQueue_.pop(); - } - - int32_t ret = ProcessData(audioData, bufferIndex); - if (ret == ERR_DH_AUDIO_BAD_VALUE) { - DHLOGE("Encoder is stopped or null."); - return; - } else if (ret != DH_SUCCESS) { - DHLOGE("Process data fail. Error type: %d.", ret); - continue; - } - } -} - -int32_t AudioEncoder::ProcessData(const std::shared_ptr &audioData, const int32_t bufferIndex) -{ - if (!isEncoderRunning_.load() || audioEncoder_ == nullptr) { - DHLOGE("Encoder is stopped or null, isRunning %d.", isEncoderRunning_.load()); - return ERR_DH_AUDIO_BAD_VALUE; - } - - auto inMem = audioEncoder_->GetInputBuffer(bufferIndex); - if (inMem == nullptr) { - DHLOGE("Get input buffer fail."); - return ERR_DH_AUDIO_CODEC_INPUT; - } - if (inMem->GetSize() == INVALID_MEMORY_SIZE || static_cast(inMem->GetSize()) < audioData->Size()) { - DHLOGE("Input buffer size error. Memory size %d, data size %zu.", - inMem->GetSize(), audioData->Size()); - return ERR_DH_AUDIO_CODEC_INPUT; - } - - errno_t err = memcpy_s(inMem->GetBase(), inMem->GetSize(), audioData->Data(), audioData->Size()); - if (err != EOK) { - DHLOGE("Copy input data fail. Error code %d. Memory size %d, data size %zu.", - err, inMem->GetSize(), audioData->Size()); - return ERR_DH_AUDIO_BAD_OPERATE; - } - - inputTimeStampUs_ = GetEncoderTimeStamp(); - Media::AVCodecBufferInfo bufferInfo = {inputTimeStampUs_, static_cast(audioData->Size()), 0}; - DHLOGD("Queue input buffer. AVCodec info: input time stamp %lld, data size %zu.", - (long long)bufferInfo.presentationTimeUs, audioData->Size()); - int32_t ret = audioEncoder_->QueueInputBuffer(bufferIndex, bufferInfo, Media::AVCODEC_BUFFER_FLAG_NONE); - if (ret != Media::MSERR_OK) { - DHLOGE("Queue input buffer fail. Error code %d.", ret); - return ERR_DH_AUDIO_CODEC_INPUT; - } - - IncreaseWaitEncodeCnt(); - return DH_SUCCESS; -} - -int64_t AudioEncoder::GetEncoderTimeStamp() -{ - int64_t TimeIntervalStampUs = 0; - int64_t nowTimeUs = GetNowTimeUs(); - if (firstInputTimeUs_ == 0) { - firstInputTimeUs_ = nowTimeUs; - return TimeIntervalStampUs; - } - - TimeIntervalStampUs = nowTimeUs - firstInputTimeUs_; - return TimeIntervalStampUs; -} - -void AudioEncoder::IncreaseWaitEncodeCnt() -{ - std::lock_guard lck(mtxCnt_); - waitOutputCount_++; - DHLOGD("Wait encoder output frames number is %d.", waitOutputCount_); -} - -void AudioEncoder::ReduceWaitEncodeCnt() -{ - std::lock_guard lck(mtxCnt_); - if (waitOutputCount_ <= 0) { - DHLOGE("Wait encoder output count %d.", waitOutputCount_); - } - waitOutputCount_--; - DHLOGD("Wait encoder output frames number is %d.", waitOutputCount_); -} - -void AudioEncoder::OnInputBufferAvailable(uint32_t index) -{ - std::lock_guard lck(mtxData_); - while (bufIndexQueue_.size() > AUDIO_ENCODER_QUEUE_MAX) { - DHLOGE("Index queue overflow."); - bufIndexQueue_.pop(); - } - - bufIndexQueue_.push(index); - encodeCond_.notify_all(); -} - -void AudioEncoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, - Media::AVCodecBufferFlag flag) -{ - if (!isEncoderRunning_.load() || audioEncoder_ == nullptr) { - DHLOGE("Encoder is stopped or null, isRunning %d.", isEncoderRunning_.load()); - return; - } - - auto outMem = audioEncoder_->GetOutputBuffer(index); - if (outMem == nullptr) { - DHLOGE("Get output buffer fail. index %u.", index); - return; - } - if (info.size <= 0 || info.size > outMem->GetSize()) { - DHLOGE("Codec output info error. AVCodec info: size %d, memory size %d.", - info.size, outMem->GetSize()); - return; - } - - auto outBuf = std::make_shared(static_cast(info.size)); - errno_t err = memcpy_s(outBuf->Data(), outBuf->Size(), outMem->GetBase(), info.size); - if (err != EOK) { - DHLOGE("Copy output data fail. Error code %d. Output Buffer Size %zu, AVCodec info: size %d.", - err, outBuf->Size(), info.size); - return; - } - outBuf->SetInt64("timeUs", info.presentationTimeUs); - outputTimeStampUs_ = info.presentationTimeUs; - DHLOGD("Get output buffer. AVCodec info: output time stamp %lld, data size %zu.", - (long long)info.presentationTimeUs, outBuf->Size()); - - ReduceWaitEncodeCnt(); - err = EncodeDone(outBuf); - if (err != DH_SUCCESS) { - DHLOGE("Encode done fail. Error code: %d.", err); - return; - } - - err = audioEncoder_->ReleaseOutputBuffer(index); - if (err != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Release output buffer fail. Error code: %d, index %u.", err, index); - } -} - -void AudioEncoder::OnOutputFormatChanged(const Media::Format &format) -{ - if (format.GetFormatMap().empty()) { - DHLOGE("The first changed output data format is null."); - return; - } - outputFormat_ = format; -} - -void AudioEncoder::OnError(const AudioEvent &event) -{ - DHLOGE("Encoder error."); - std::shared_ptr cbObj = codecCallback_.lock(); - if (cbObj == nullptr) { - DHLOGE("Codec callback is null."); - return; - } - cbObj->OnCodecStateNotify(event); -} - -int32_t AudioEncoder::EncodeDone(const std::shared_ptr &outputData) -{ - DHLOGD("Encode done."); - std::shared_ptr cbObj = codecCallback_.lock(); - if (cbObj == nullptr) { - DHLOGE("Codec callback is null."); - return ERR_DH_AUDIO_BAD_VALUE; - } - cbObj->OnCodecDataDone(outputData); - return DH_SUCCESS; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/audioprocessor/encoder/src/audio_encoder_callback.cpp b/services/audioprocessor/encoder/src/audio_encoder_callback.cpp deleted file mode 100644 index 5849843f..00000000 --- a/services/audioprocessor/encoder/src/audio_encoder_callback.cpp +++ /dev/null @@ -1,72 +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_encoder_callback.h" - -#include "daudio_log.h" -#include "audio_event.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioEncoderCallback" - -namespace OHOS { -namespace DistributedHardware { -void AudioEncoderCallback::OnError(Media::AVCodecErrorType errorType, int32_t errorCode) -{ - DHLOGE("On error. Error type: %d, Error code: %d.", errorType, errorCode); - std::shared_ptr encObj = audioEncoder_.lock(); - if (encObj == nullptr) { - DHLOGE("Encoder is nullptr."); - return; - } - AudioEvent encoderErr = {AUDIO_ENCODER_ERR, ""}; - encObj->OnError(encoderErr); -} - -void AudioEncoderCallback::OnInputBufferAvailable(uint32_t index) -{ - DHLOGD("On input buffer available. index %u.", index); - std::shared_ptr encObj = audioEncoder_.lock(); - if (encObj == nullptr) { - DHLOGE("Encoder is nullptr."); - return; - } - encObj->OnInputBufferAvailable(index); -} - -void AudioEncoderCallback::OnOutputFormatChanged(const Media::Format &format) -{ - DHLOGD("On output format changed."); - std::shared_ptr encObj = audioEncoder_.lock(); - if (encObj == nullptr) { - DHLOGE("Encoder is nullptr."); - return; - } - encObj->OnOutputFormatChanged(format); -} - -void AudioEncoderCallback::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, - Media::AVCodecBufferFlag flag) -{ - DHLOGD("On output buffer available. index %u.", index); - std::shared_ptr encObj = audioEncoder_.lock(); - if (encObj == nullptr) { - DHLOGE("Encoder is nullptr."); - return; - } - encObj->OnOutputBufferAvailable(index, info, flag); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/BUILD.gn deleted file mode 100644 index 1975ae8e..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("DecoderOnErrorFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/decoderonerror" - fuzz_config_file = - "${audio_processor_path}/test/fuzztest/decoderonerror_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "decoderonerror_fuzzer.cpp" ] - - include_dirs = [ - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_processor_path}/decoder/include", - ] - - deps = [ - "${audio_transport_path}/decodetransport:distributed_audio_decode_transport", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "player_framework:media_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DecoderOnErrorFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":DecoderOnErrorFuzzTest" ] -} -############################################################################### diff --git a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.cpp b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.cpp deleted file mode 100644 index 76c6248b..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.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 "decoderonerror_fuzzer.h" - -#include -#include - -#include "audio_decoder.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void DecoderOnErrorFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - int32_t type = *(reinterpret_cast(data)); - - std::shared_ptr decoder = std::make_shared(); - AudioEvent event(static_cast(type), ""); - decoder->OnError(event); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::DecoderOnErrorFuzzTest(data, size); - return 0; -} - diff --git a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.h b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.h deleted file mode 100644 index 7f5ab292..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.h +++ /dev/null @@ -1,21 +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 DECODERONERROR_FUZZER_H -#define DECODERONERROR_FUZZER_H - -#define FUZZ_PROJECT_NAME "decoderonerror_fuzzer" - -#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/BUILD.gn deleted file mode 100644 index d8f6b6be..00000000 --- a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("DecoderOnInputAvailableFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/decoderoninputavailable" - fuzz_config_file = - "${audio_processor_path}/test/fuzztest/decoderoninputavailable_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "decoderoninputavailable_fuzzer.cpp" ] - - include_dirs = [ - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_processor_path}/decoder/include", - ] - - deps = [ - "${audio_transport_path}/decodetransport:distributed_audio_decode_transport", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "player_framework:media_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DecoderOnInputAvailableFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":DecoderOnInputAvailableFuzzTest" ] -} -############################################################################### diff --git a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.cpp b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.cpp deleted file mode 100644 index 5f6699f1..00000000 --- a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.cpp +++ /dev/null @@ -1,47 +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 "decoderoninputavailable_fuzzer.h" - -#include -#include - -#include "audio_decoder.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void DecoderOnInputAvailabelFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(uint32_t))) { - return; - } - - uint32_t index = *(reinterpret_cast(data)); - std::shared_ptr decoder = std::make_shared(); - decoder->OnInputBufferAvailable(index); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::DecoderOnInputAvailabelFuzzTest(data, size); - return 0; -} - diff --git a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.h b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.h deleted file mode 100644 index decf9c8c..00000000 --- a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.h +++ /dev/null @@ -1,21 +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 DECODERONINPUTAVAILABLE_FUZZER_H -#define DECODERONINPUTAVAILABLE_FUZZER_H - -#define FUZZ_PROJECT_NAME "decoderoninputavailable_fuzzer" - -#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/BUILD.gn deleted file mode 100644 index b9bec389..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("DecoderOnOutputAvailableFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/decoderonoutputavailable" - fuzz_config_file = - "${audio_processor_path}/test/fuzztest/decoderonoutputavailable_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "decoderonoutputavailable_fuzzer.cpp" ] - - include_dirs = [ - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_processor_path}/decoder/include", - ] - - deps = [ - "${audio_transport_path}/decodetransport:distributed_audio_decode_transport", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "player_framework:media_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DecoderOnOutputAvailableFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":DecoderOnOutputAvailableFuzzTest" ] -} -############################################################################### diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.cpp b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.cpp deleted file mode 100644 index 6b9f7f5c..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.cpp +++ /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. - */ - -#include "decoderonoutputavailable_fuzzer.h" - -#include -#include - -#include "audio_decoder.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void DecoderOnOutputAvailabelFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(int64_t))) { - return; - } - - uint32_t index = *(reinterpret_cast(data)); - int64_t presentTimeUs = *(reinterpret_cast(data)); - int32_t infoSize = *(reinterpret_cast(data)); - int32_t offset = *(reinterpret_cast(data)); - int32_t bufferFlag = *(reinterpret_cast(data)); - Media::AVCodecBufferInfo info = {presentTimeUs, infoSize, offset}; - Media::AVCodecBufferFlag flag = static_cast(bufferFlag); - std::shared_ptr decoder = std::make_shared(); - decoder->OnOutputBufferAvailable(index, info, flag); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::DecoderOnOutputAvailabelFuzzTest(data, size); - return 0; -} - diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.h b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.h deleted file mode 100644 index 1b5f7177..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.h +++ /dev/null @@ -1,21 +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 DECODERONOUTPUTAVAILABLE_FUZZER_H -#define DECODERONOUTPUTAVAILABLE_FUZZER_H - -#define FUZZ_PROJECT_NAME "decoderonoutputavailable_fuzzer" - -#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/BUILD.gn deleted file mode 100644 index 03ccc2a2..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("DecoderOnOutputChangedFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/decoderonoutputchanged" - fuzz_config_file = - "${audio_processor_path}/test/fuzztest/decoderonoutputchanged_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "decoderonoutputchanged_fuzzer.cpp" ] - - include_dirs = [ - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_processor_path}/decoder/include", - ] - - deps = [ - "${audio_transport_path}/decodetransport:distributed_audio_decode_transport", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "player_framework:media_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DecoderOnOutputChangedFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":DecoderOnOutputChangedFuzzTest" ] -} -############################################################################### diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.cpp b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.cpp deleted file mode 100644 index 9e8f79f1..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.cpp +++ /dev/null @@ -1,47 +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 "decoderonoutputchanged_fuzzer.h" - -#include -#include - -#include "audio_decoder.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void DecoderOnOutputChangedFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr) { - return; - } - - Media::Format format; - std::shared_ptr decoder = std::make_shared(); - decoder->OnOutputFormatChanged(format); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::DecoderOnOutputChangedFuzzTest(data, size); - return 0; -} - diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.h b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.h deleted file mode 100644 index c8115c18..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.h +++ /dev/null @@ -1,21 +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 DECODERONOUTPUTCHANGED_FUZZER_H -#define DECODERONOUTPUTCHANGED_FUZZER_H - -#define FUZZ_PROJECT_NAME "decoderonoutputchanged_fuzzer" - -#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/BUILD.gn deleted file mode 100644 index c57b1000..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("EncoderOnErrorFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/encoderonerror" - fuzz_config_file = - "${audio_processor_path}/test/fuzztest/encoderonerror_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "encoderonerror_fuzzer.cpp" ] - - include_dirs = [ - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_processor_path}/encoder/include", - ] - - deps = [ - "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "player_framework:media_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"EncoderOnErrorFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":EncoderOnErrorFuzzTest" ] -} -############################################################################### diff --git a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.cpp b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.cpp deleted file mode 100644 index 2bf262a7..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.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 "encoderonerror_fuzzer.h" - -#include -#include - -#include "audio_encoder.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void EncoderOnErrorFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - - int32_t type = *(reinterpret_cast(data)); - std::shared_ptr encoder = std::make_shared(); - AudioEvent event(static_cast(type), ""); - encoder->OnError(event); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::EncoderOnErrorFuzzTest(data, size); - return 0; -} - diff --git a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.h b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.h deleted file mode 100644 index b797dcab..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.h +++ /dev/null @@ -1,21 +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 ENCODERONERROR_FUZZER_H -#define ENCODERONERROR_FUZZER_H - -#define FUZZ_PROJECT_NAME "encoderonerror_fuzzer" - -#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/BUILD.gn deleted file mode 100644 index 5926982e..00000000 --- a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("EncoderOnInputAvailableFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/encoderoninputavailable" - fuzz_config_file = - "${audio_processor_path}/test/fuzztest/encoderoninputavailable_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "encoderoninputavailable_fuzzer.cpp" ] - - include_dirs = [ - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_processor_path}/encoder/include", - ] - - deps = [ - "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "player_framework:media_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"EncoderOnInputAvailableFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":EncoderOnInputAvailableFuzzTest" ] -} -############################################################################### diff --git a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.cpp b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.cpp deleted file mode 100644 index 885fffe1..00000000 --- a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.cpp +++ /dev/null @@ -1,47 +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 "encoderoninputavailable_fuzzer.h" - -#include -#include - -#include "audio_encoder.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void EncoderOnInputAvailabelFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(uint32_t))) { - return; - } - - uint32_t index = *(reinterpret_cast(data)); - std::shared_ptr encoder = std::make_shared(); - encoder->OnInputBufferAvailable(index); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::EncoderOnInputAvailabelFuzzTest(data, size); - return 0; -} - diff --git a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.h b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.h deleted file mode 100644 index b33bee90..00000000 --- a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.h +++ /dev/null @@ -1,21 +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 ENCODERONINPUTAVAILABLE_FUZZER_H -#define ENCODERONINPUTAVAILABLE_FUZZER_H - -#define FUZZ_PROJECT_NAME "encoderoninputavailable_fuzzer" - -#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/BUILD.gn deleted file mode 100644 index 3e8a8790..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("EncoderOnOutputAvailableFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/encoderonoutputavailable" - fuzz_config_file = - "${audio_processor_path}/test/fuzztest/encoderonoutputavailable_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "encoderonoutputavailable_fuzzer.cpp" ] - - include_dirs = [ - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_processor_path}/encoder/include", - ] - - deps = [ - "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "player_framework:media_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"EncoderOnOutputAvailableFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":EncoderOnOutputAvailableFuzzTest" ] -} -############################################################################### diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.cpp b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.cpp deleted file mode 100644 index 0faeb512..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.cpp +++ /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. - */ - -#include "encoderonoutputavailable_fuzzer.h" - -#include -#include - -#include "audio_encoder.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void EncoderOnOutputAvailabelFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(int64_t))) { - return; - } - - uint32_t index = *(reinterpret_cast(data)); - int64_t presentTimeUs = *(reinterpret_cast(data)); - int32_t infoSize = *(reinterpret_cast(data)); - int32_t offset = *(reinterpret_cast(data)); - int32_t bufferFlag = *(reinterpret_cast(data)); - Media::AVCodecBufferInfo info = {presentTimeUs, infoSize, offset}; - Media::AVCodecBufferFlag flag = static_cast(bufferFlag); - std::shared_ptr encoder = std::make_shared(); - encoder->OnOutputBufferAvailable(index, info, flag); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::EncoderOnOutputAvailabelFuzzTest(data, size); - return 0; -} - diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.h b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.h deleted file mode 100644 index 4634e562..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.h +++ /dev/null @@ -1,21 +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 ENCODERONOUTPUTAVAILABLE_FUZZER_H -#define ENCODERONOUTPUTAVAILABLE_FUZZER_H - -#define FUZZ_PROJECT_NAME "encoderonoutputavailable_fuzzer" - -#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/BUILD.gn deleted file mode 100644 index cdc20d10..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("EncoderOnOutputChangedFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/encoderonoutputchanged" - fuzz_config_file = - "${audio_processor_path}/test/fuzztest/encoderonoutputchanged_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "encoderonoutputchanged_fuzzer.cpp" ] - - include_dirs = [ - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_processor_path}/encoder/include", - ] - - deps = [ - "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "player_framework:media_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"EncoderOnOutputChangedFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":EncoderOnOutputChangedFuzzTest" ] -} -############################################################################### diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.cpp b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.cpp deleted file mode 100644 index 8c5b65e5..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.cpp +++ /dev/null @@ -1,47 +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 "encoderonoutputchanged_fuzzer.h" - -#include -#include - -#include "audio_encoder.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void EncoderOnOutputChangedFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr) { - return; - } - - Media::Format format; - std::shared_ptr encoder = std::make_shared(); - encoder->OnOutputFormatChanged(format); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::EncoderOnOutputChangedFuzzTest(data, size); - return 0; -} - diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.h b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.h deleted file mode 100644 index 103dd122..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.h +++ /dev/null @@ -1,21 +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 ENCODERONOUTPUTCHANGED_FUZZER_H -#define ENCODERONOUTPUTCHANGED_FUZZER_H - -#define FUZZ_PROJECT_NAME "encoderonoutputchanged_fuzzer" - -#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/audioprocessor/test/unittest/BUILD.gn b/services/audioprocessor/test/unittest/BUILD.gn index 5954b958..342e1d6e 100644 --- a/services/audioprocessor/test/unittest/BUILD.gn +++ b/services/audioprocessor/test/unittest/BUILD.gn @@ -17,8 +17,5 @@ import("../../../../distributedaudio.gni") group("daudio_processor_test") { testonly = true - deps = [ - "${audio_processor_path}/test/unittest/common/decodeprocessor:decode_processor_test", - "${audio_processor_path}/test/unittest/common/encodeprocessor:encode_processor_test", - ] + deps = [ "${audio_processor_path}/test/unittest/common/decodeprocessor:decode_processor_test" ] } diff --git a/services/audioprocessor/test/unittest/common/decodeprocessor/BUILD.gn b/services/audioprocessor/test/unittest/common/decodeprocessor/BUILD.gn index f68c7fa5..226c325b 100644 --- a/services/audioprocessor/test/unittest/common/decodeprocessor/BUILD.gn +++ b/services/audioprocessor/test/unittest/common/decodeprocessor/BUILD.gn @@ -33,42 +33,12 @@ config("module_private_config") { "${common_path}/include", "${services_path}/common/audioparam", "${services_path}/common/audiodata/include", - "${audio_processor_path}/decodeprocessor/include", - "${audio_processor_path}/decoder/include", "${audio_processor_path}/directprocessor/include", "${audio_processor_path}/interface", "${audio_processor_path}/test/unittest/common", ] } -ohos_unittest("DecodeProcessTest") { - module_out_path = module_output_path - - sources = [ - "decode_process_test.cpp", - "decoder_test.cpp", - ] - - configs = [ ":module_private_config" ] - - deps = [ - "${audio_transport_path}/decodetransport:distributed_audio_decode_transport", - "${services_path}/common:distributed_audio_utils", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "c_utils:utils", - "player_framework:media_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"daudio_proc_test\"", - "LOG_DOMAIN=0xD004100", - ] -} - ohos_unittest("DirectProcessorTest") { module_out_path = module_output_path @@ -96,8 +66,5 @@ ohos_unittest("DirectProcessorTest") { group("decode_processor_test") { testonly = true - deps = [ - ":DecodeProcessTest", - ":DirectProcessorTest", - ] + deps = [ ":DirectProcessorTest" ] } diff --git a/services/audioprocessor/test/unittest/common/decodeprocessor/decode_process_test.cpp b/services/audioprocessor/test/unittest/common/decodeprocessor/decode_process_test.cpp deleted file mode 100644 index 89cad267..00000000 --- a/services/audioprocessor/test/unittest/common/decodeprocessor/decode_process_test.cpp +++ /dev/null @@ -1,266 +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 -#include - -#include "audio_data.h" -#include "audio_event.h" -#include "audio_decoder_processor.h" -#include "audio_param.h" -#include "audio_processor_callback_test.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" -#include "daudio_util.h" -#include "iaudio_processor.h" -#include "iaudio_processor_callback.h" -#include "securec.h" - -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -class DecodeProcessTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - std::shared_ptr proCallback_; - std::shared_ptr decodeProc_; -}; - -const AudioCommonParam LOC_COMPARA_DEC_TEST = {SAMPLE_RATE_48000, STEREO, SAMPLE_S16LE, AUDIO_CODEC_AAC}; -const AudioCommonParam RMT_COMPARA_DEC_TEST = {SAMPLE_RATE_48000, STEREO, SAMPLE_S16LE, AUDIO_CODEC_AAC}; - -void DecodeProcessTest::SetUpTestCase(void) -{ -} - -void DecodeProcessTest::TearDownTestCase(void) -{ -} - -void DecodeProcessTest::SetUp(void) -{ - proCallback_ = std::make_shared(); - decodeProc_ = std::make_shared(); -} - -void DecodeProcessTest::TearDown(void) -{ - proCallback_ = nullptr; - decodeProc_ = nullptr; -} - -/** - * @tc.name: decode_process_test_001 - * @tc.desc: Verify the configure and release processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecodeProcessTest, decode_process_test_001, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, decodeProc_->ConfigureAudioProcessor(LOC_COMPARA_DEC_TEST, - RMT_COMPARA_DEC_TEST, proCallback_)); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: decode_process_test_002 - * @tc.desc: Verify the configure processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecodeProcessTest, decode_process_test_002, TestSize.Level1) -{ - const AudioCommonParam testLocalComPara = {SAMPLE_RATE_48000, STEREO, SAMPLE_S32LE, AUDIO_CODEC_FLAC}; - const AudioCommonParam testRemoteComPara = {SAMPLE_RATE_48000, STEREO, SAMPLE_S32LE, AUDIO_CODEC_FLAC}; - EXPECT_NE(DH_SUCCESS, decodeProc_->ConfigureAudioProcessor(testLocalComPara, testRemoteComPara, proCallback_)); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: decode_process_test_003 - * @tc.desc: Verify the start and stop processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecodeProcessTest, decode_process_test_003, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, decodeProc_->ConfigureAudioProcessor(LOC_COMPARA_DEC_TEST, - RMT_COMPARA_DEC_TEST, proCallback_)); - EXPECT_EQ(DH_SUCCESS, decodeProc_->StartAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, decodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: decode_process_test_004 - * @tc.desc: Verify the start processor without configure processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecodeProcessTest, decode_process_test_004, TestSize.Level1) -{ - EXPECT_NE(DH_SUCCESS, decodeProc_->StartAudioProcessor()); - - EXPECT_NE(DH_SUCCESS, decodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, decodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: decode_process_test_005 - * @tc.desc: Verify the stop processor without start processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecodeProcessTest, decode_process_test_005, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, decodeProc_->ConfigureAudioProcessor(LOC_COMPARA_DEC_TEST, - RMT_COMPARA_DEC_TEST, proCallback_)); - - EXPECT_NE(DH_SUCCESS, decodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, decodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: decode_process_test_006 - * @tc.desc: Verify the start and stop processor again function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecodeProcessTest, decode_process_test_006, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, decodeProc_->ConfigureAudioProcessor(LOC_COMPARA_DEC_TEST, - RMT_COMPARA_DEC_TEST, proCallback_)); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->StartAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, decodeProc_->StopAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->StartAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, decodeProc_->StopAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: decode_process_test_007 - * @tc.desc: Verify the start processor again function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecodeProcessTest, decode_process_test_007, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, decodeProc_->ConfigureAudioProcessor(LOC_COMPARA_DEC_TEST, - RMT_COMPARA_DEC_TEST, proCallback_)); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->StartAudioProcessor()); - EXPECT_NE(DH_SUCCESS, decodeProc_->StartAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, decodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: decode_process_test_008 - * @tc.desc: Verify the stop processor again function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecodeProcessTest, decode_process_test_008, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, decodeProc_->ConfigureAudioProcessor(LOC_COMPARA_DEC_TEST, - RMT_COMPARA_DEC_TEST, proCallback_)); - EXPECT_EQ(DH_SUCCESS, decodeProc_->StartAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->StopAudioProcessor()); - EXPECT_NE(DH_SUCCESS, decodeProc_->StopAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: decode_process_test_009 - * @tc.desc: Verify feed audio processor function. - * @tc.type: FUNC - * @tc.require: AR000H0J88 SR000H0J7O - */ -HWTEST_F(DecodeProcessTest, decode_process_test_009, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, decodeProc_->ConfigureAudioProcessor(LOC_COMPARA_DEC_TEST, - RMT_COMPARA_DEC_TEST, proCallback_)); - EXPECT_EQ(DH_SUCCESS, decodeProc_->StartAudioProcessor()); - - size_t bufLen = 4096; - std::shared_ptr inputData = std::make_shared(bufLen); - EXPECT_EQ(EOK, memset_s(inputData->Data(), inputData->Size(), 0, inputData->Size())); - EXPECT_EQ(DH_SUCCESS, decodeProc_->FeedAudioProcessor(inputData)); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, decodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: decode_process_test_0010 - * @tc.desc: Verify feed audio processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecodeProcessTest, decode_process_test_0010, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, decodeProc_->ConfigureAudioProcessor(LOC_COMPARA_DEC_TEST, - RMT_COMPARA_DEC_TEST, proCallback_)); - EXPECT_EQ(DH_SUCCESS, decodeProc_->StartAudioProcessor()); - - std::shared_ptr inputData = nullptr; - EXPECT_NE(DH_SUCCESS, decodeProc_->FeedAudioProcessor(inputData)); - decodeProc_->OnCodecDataDone(inputData); - AudioEvent event; - decodeProc_->OnCodecStateNotify(event); - - EXPECT_EQ(DH_SUCCESS, decodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, decodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: decode_process_test_0011 - * @tc.desc: Verify feed audio processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecodeProcessTest, decode_process_test_0011, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, decodeProc_->ConfigureAudioProcessor(LOC_COMPARA_DEC_TEST, - RMT_COMPARA_DEC_TEST, proCallback_)); - decodeProc_ = std::make_shared(); - EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, decodeProc_->ConfigureAudioProcessor(LOC_COMPARA_DEC_TEST, - RMT_COMPARA_DEC_TEST, nullptr)); - - decodeProc_->OnCodecDataDone(nullptr); - size_t bufLen = 4096; - std::shared_ptr inputData = std::make_shared(bufLen); - EXPECT_EQ(EOK, memset_s(inputData->Data(), inputData->Size(), 0, inputData->Size())); - decodeProc_->OnCodecDataDone(inputData); - AudioEvent event; - decodeProc_->OnCodecStateNotify(event); - EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, decodeProc_->FeedAudioProcessor(inputData)); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/audioprocessor/test/unittest/common/decodeprocessor/decoder_test.cpp b/services/audioprocessor/test/unittest/common/decodeprocessor/decoder_test.cpp deleted file mode 100644 index 36741443..00000000 --- a/services/audioprocessor/test/unittest/common/decodeprocessor/decoder_test.cpp +++ /dev/null @@ -1,241 +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 -#include - -#define private public -#include "audio_decoder.h" -#undef private - -#include "audio_data.h" -#include "audio_event.h" -#include "decoder_callback_test.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" -#include "daudio_util.h" -#include "audio_decoder.h" - -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -class DecoderTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - std::shared_ptr audiodecoder_ = nullptr; - std::shared_ptr decodeCb_ = nullptr; -}; - -const AudioCommonParam LOC_COMPARA_ENC_TEST = {SAMPLE_RATE_48000, STEREO, SAMPLE_S16LE, AUDIO_CODEC_AAC}; - -void DecoderTest::SetUpTestCase(void) -{ -} - -void DecoderTest::TearDownTestCase(void) -{ -} - -void DecoderTest::SetUp(void) -{ - audiodecoder_ = std::make_shared(); - decodeCb_ = std::make_shared(); -} - -void DecoderTest::TearDown(void) -{ - audiodecoder_ = nullptr; - decodeCb_ = nullptr; -} - -/** - * @tc.name: decode_test_001 - * @tc.desc: Verify decode destruct function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -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)); -} - -/** - * @tc.name: decode_test_002 - * @tc.desc: Verify start stop decoder function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecoderTest, decode_test_002, TestSize.Level1) -{ - EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audiodecoder_->StartAudioCodec()); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->StopAudioCodec()); - size_t bufLen = 4096; - std::shared_ptr inputData = std::make_shared(bufLen); - EXPECT_EQ(EOK, memset_s(inputData->Data(), inputData->Size(), 0, inputData->Size())); - EXPECT_EQ(ERR_DH_AUDIO_CODEC_INPUT, audiodecoder_->FeedAudioData(inputData)); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->ConfigureAudioCodec(LOC_COMPARA_ENC_TEST, decodeCb_)); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->StartAudioCodec()); - EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audiodecoder_->FeedAudioData(nullptr)); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->StopAudioCodec()); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->ReleaseAudioCodec()); -} - -/** - * @tc.name: decode_test_003 - * @tc.desc: Verify decode data function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecoderTest, decode_test_003, TestSize.Level1) -{ - audiodecoder_ = std::make_shared(); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->ConfigureAudioCodec(LOC_COMPARA_ENC_TEST, decodeCb_)); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->StartAudioCodec()); - - for (int32_t i = 0; i < 200; i++) { - size_t bufLen = 4096; - std::shared_ptr inputData = std::make_shared(bufLen); - EXPECT_EQ(EOK, memset_s(inputData->Data(), inputData->Size(), 0, inputData->Size())); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->FeedAudioData(inputData)); - } - - EXPECT_EQ(DH_SUCCESS, audiodecoder_->StopAudioCodec()); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->ReleaseAudioCodec()); -} - -/** - * @tc.name: decode_test_004 - * @tc.desc: Verify decode data function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecoderTest, decode_test_004, TestSize.Level1) -{ - audiodecoder_ = std::make_shared(); - for (int32_t i = 0; i < 200; i++) { - audiodecoder_->OnInputBufferAvailable(1); - } - Media::AVCodecBufferInfo info; - Media::AVCodecBufferFlag flag = static_cast(0); - audiodecoder_->OnOutputBufferAvailable(1, info, flag); - Media::Format format; - AudioEvent event; - audiodecoder_->OnOutputFormatChanged(format); - audiodecoder_->OnError(event); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->ConfigureAudioCodec(LOC_COMPARA_ENC_TEST, decodeCb_)); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->ReleaseAudioCodec()); -} - -/** - * @tc.name: DecodeDone_001 - * @tc.desc: Verify DecodeDone function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecoderTest, DecodeDone_001, TestSize.Level1) -{ - audiodecoder_ = std::make_shared(); - size_t bufLen = 4096; - std::shared_ptr outputData = std::make_shared(bufLen); - std::shared_ptr decodeCb = std::make_shared(); - audiodecoder_->codecCallback_ = decodeCb; - EXPECT_EQ(DH_SUCCESS, audiodecoder_->DecodeDone(outputData)); - audiodecoder_->ReduceWaitDecodeCnt(); -} - -/** - * @tc.name: DecodeDone_002 - * @tc.desc: Verify DecodeDone function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecoderTest, DecodeDone_002, TestSize.Level1) -{ - AudioEvent event; - audiodecoder_ = std::make_shared(); - size_t bufLen = 4096; - std::shared_ptr outputData = std::make_shared(bufLen); - std::shared_ptr callback = nullptr; - audiodecoder_->codecCallback_ = callback; - EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audiodecoder_->DecodeDone(outputData)); - audiodecoder_->OnError(event); -} - -/** - * @tc.name: InitAudioDecoder_001 - * @tc.desc: Verify InitAudioDecoder function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecoderTest, InitAudioDecoder_001, TestSize.Level1) -{ - AudioCommonParam codecParam; - audiodecoder_ = std::make_shared(); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->InitAudioDecoder(codecParam)); - EXPECT_EQ(DH_SUCCESS, audiodecoder_->SetDecoderFormat(codecParam)); -} - -/** - * @tc.name: ProcessData_001 - * @tc.desc: Verify ProcessData function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DecoderTest, ProcessData_001, TestSize.Level1) -{ - size_t bufLen = 4096; - std::shared_ptr inputData = std::make_shared(bufLen); - int32_t bufferIndex = 0; - audiodecoder_ = std::make_shared(); - uint32_t index = 1; - Media::AVCodecBufferInfo info; - Media::AVCodecBufferFlag flag = static_cast(0); - 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 deleted file mode 100644 index 83c58e0a..00000000 --- a/services/audioprocessor/test/unittest/common/encodeprocessor/BUILD.gn +++ /dev/null @@ -1,74 +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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//build/test.gni") -import("../../../../../../distributedaudio.gni") - -module_output_path = - "distributed_audio/services/audioprocessor/encode_processor_test" - -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "${mediastandard_path}/interfaces/innerkits/native/media/include", - "${mediastandardfwk_path}/audiocommon/include", - "${fwk_common_path}/utils/include", - "//third_party/json/include", - ] - - include_dirs += [ - "${common_path}/include", - "${services_path}/common/audioparam", - "${services_path}/common/audiodata/include", - "${audio_processor_path}/encodeprocessor/include", - "${audio_processor_path}/encoder/include", - "${audio_processor_path}/interface", - "${audio_processor_path}/test/unittest/common", - ] -} - -ohos_unittest("EncodeProcessTest") { - module_out_path = module_output_path - - sources = [ - "encode_process_test.cpp", - "encoder_test.cpp", - ] - - configs = [ ":module_private_config" ] - - deps = [ - "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", - "${services_path}/common:distributed_audio_utils", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "c_utils:utils", - "player_framework:media_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"daudio_proc_test\"", - "LOG_DOMAIN=0xD004100", - ] -} - -group("encode_processor_test") { - testonly = true - deps = [ ":EncodeProcessTest" ] -} diff --git a/services/audioprocessor/test/unittest/common/encodeprocessor/encode_process_test.cpp b/services/audioprocessor/test/unittest/common/encodeprocessor/encode_process_test.cpp deleted file mode 100644 index 0c15ddd8..00000000 --- a/services/audioprocessor/test/unittest/common/encodeprocessor/encode_process_test.cpp +++ /dev/null @@ -1,333 +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 -#include -#include - -#include "audio_data.h" -#include "audio_encoder_processor.h" -#include "audio_event.h" -#include "audio_param.h" -#include "audio_processor_callback_test.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" -#include "daudio_util.h" -#include "iaudio_processor.h" -#include "iaudio_processor_callback.h" -#include "securec.h" - -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -class EncodeProcessTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - std::shared_ptr proCallback_ = nullptr; - std::shared_ptr encodeProc_ = nullptr; -}; - -const AudioCommonParam LOC_COMPARA_ENC_TEST = {SAMPLE_RATE_48000, STEREO, SAMPLE_S16LE, AUDIO_CODEC_AAC}; -const AudioCommonParam RMT_COMPARA_ENC_TEST = {SAMPLE_RATE_48000, STEREO, SAMPLE_S16LE, AUDIO_CODEC_AAC}; - -void EncodeProcessTest::SetUpTestCase(void) -{ -} - -void EncodeProcessTest::TearDownTestCase(void) -{ -} - -void EncodeProcessTest::SetUp(void) -{ - proCallback_ = std::make_shared(); - encodeProc_ = std::make_shared(); -} - -void EncodeProcessTest::TearDown(void) -{ - proCallback_ = nullptr; - encodeProc_ = nullptr; -} - -/** - * @tc.name: encode_process_test_001 - * @tc.desc: Verify the configure and release processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_001, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, proCallback_)); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: encode_process_test_002 - * @tc.desc: Verify the configure processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_002, TestSize.Level1) -{ - const AudioCommonParam testLocalComPara = {SAMPLE_RATE_48000, STEREO, SAMPLE_S32LE, AUDIO_CODEC_FLAC}; - const AudioCommonParam testRemoteComPara = {SAMPLE_RATE_48000, STEREO, SAMPLE_S32LE, AUDIO_CODEC_FLAC}; - EXPECT_NE(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(testLocalComPara, testRemoteComPara, proCallback_)); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: encode_process_test_003 - * @tc.desc: Verify the start and stop processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_003, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, proCallback_)); - EXPECT_EQ(DH_SUCCESS, encodeProc_->StartAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: encode_process_test_004 - * @tc.desc: Verify the start processor without configure processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_004, TestSize.Level1) -{ - EXPECT_NE(DH_SUCCESS, encodeProc_->StartAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: encode_process_test_005 - * @tc.desc: Verify the stop processor without start processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_005, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, proCallback_)); - - EXPECT_NE(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: encode_process_test_006 - * @tc.desc: Verify the start and stop processor again function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_006, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, proCallback_)); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->StartAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->StartAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: encode_process_test_007 - * @tc.desc: Verify the start processor again function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_007, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, proCallback_)); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->StartAudioProcessor()); - EXPECT_NE(DH_SUCCESS, encodeProc_->StartAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: encode_process_test_008 - * @tc.desc: Verify the stop processor again function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_008, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, proCallback_)); - EXPECT_EQ(DH_SUCCESS, encodeProc_->StartAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - EXPECT_NE(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: encode_process_test_009 - * @tc.desc: Verify feed audio processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_009, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, proCallback_)); - EXPECT_EQ(DH_SUCCESS, encodeProc_->StartAudioProcessor()); - - size_t bufLen = 4096; - std::shared_ptr inputData = std::make_shared(bufLen); - EXPECT_EQ(EOK, memset_s(inputData->Data(), inputData->Size(), 0, inputData->Size())); - EXPECT_EQ(DH_SUCCESS, encodeProc_->FeedAudioProcessor(inputData)); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: encode_process_test_0010 - * @tc.desc: Verify feed audio processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_0010, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, proCallback_)); - EXPECT_EQ(DH_SUCCESS, encodeProc_->StartAudioProcessor()); - - std::shared_ptr inputData = nullptr; - EXPECT_NE(DH_SUCCESS, encodeProc_->FeedAudioProcessor(inputData)); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: encode_process_test_0011 - * @tc.desc: Verify audio processor encode function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_0011, TestSize.Level1) -{ - size_t bufLen = 4096; - std::shared_ptr inputData = std::make_shared(bufLen); - EXPECT_EQ(EOK, memset_s(inputData->Data(), inputData->Size(), 0, inputData->Size())); - EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, encodeProc_->FeedAudioProcessor(inputData)); -} - -/** - * @tc.name: encode_process_test_0012 - * @tc.desc: Verify audio processor destruct function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_0012, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, proCallback_)); - encodeProc_ = std::make_shared(); -} - -/** - * @tc.name: encode_process_test_0013 - * @tc.desc: Verify config audio processor function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_0013, TestSize.Level1) -{ - EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, nullptr)); -} - -/** - * @tc.name: encode_process_test_0014 - * @tc.desc: Verify audio processor encode data function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_0014, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, proCallback_)); - EXPECT_EQ(DH_SUCCESS, encodeProc_->StartAudioProcessor()); - encodeProc_->OnCodecDataDone(nullptr); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} - -/** - * @tc.name: encode_process_test_0015 - * @tc.desc: Verify audio processor encode data function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_0015, TestSize.Level1) -{ - std::shared_ptr inputData = std::make_shared(4096); - EXPECT_EQ(EOK, memset_s(inputData->Data(), inputData->Size(), 0, inputData->Size())); - encodeProc_->OnCodecDataDone(inputData); - AudioEvent event; - encodeProc_->OnCodecStateNotify(event); -} - -/** - * @tc.name: encode_process_test_0016 - * @tc.desc: Verify audio processor encode data function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncodeProcessTest, encode_process_test_0016, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, encodeProc_->ConfigureAudioProcessor(LOC_COMPARA_ENC_TEST, - RMT_COMPARA_ENC_TEST, proCallback_)); - EXPECT_EQ(DH_SUCCESS, encodeProc_->StartAudioProcessor()); - - std::shared_ptr inputData = std::make_shared(4096); - EXPECT_EQ(EOK, memset_s(inputData->Data(), inputData->Size(), 0, inputData->Size())); - encodeProc_->OnCodecDataDone(inputData); - AudioEvent event = {1, "test"}; - encodeProc_->OnCodecStateNotify(event); - - EXPECT_EQ(DH_SUCCESS, encodeProc_->StopAudioProcessor()); - EXPECT_EQ(DH_SUCCESS, encodeProc_->ReleaseAudioProcessor()); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/audioprocessor/test/unittest/common/encodeprocessor/encoder_test.cpp b/services/audioprocessor/test/unittest/common/encodeprocessor/encoder_test.cpp deleted file mode 100644 index 8e08c02f..00000000 --- a/services/audioprocessor/test/unittest/common/encodeprocessor/encoder_test.cpp +++ /dev/null @@ -1,210 +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 -#include - -#define private public -#include "audio_encoder.h" -#undef private - -#include "audio_data.h" -#include "audio_event.h" -#include "encoder_callback_test.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" -#include "daudio_util.h" -#include "audio_encoder.h" - -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -class EncoderTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - std::shared_ptr audioEncoder_ = nullptr; - std::shared_ptr encodeCb_ = nullptr; -}; - -const AudioCommonParam LOC_COMPARA_ENC_TEST = {SAMPLE_RATE_48000, STEREO, SAMPLE_S16LE, AUDIO_CODEC_AAC}; - -void EncoderTest::SetUpTestCase(void) -{ -} - -void EncoderTest::TearDownTestCase(void) -{ -} - -void EncoderTest::SetUp(void) -{ - audioEncoder_ = std::make_shared(); - encodeCb_ = std::make_shared(); -} - -void EncoderTest::TearDown(void) -{ - audioEncoder_ = nullptr; - encodeCb_ = nullptr; -} - -/** - * @tc.name: encode_test_001 - * @tc.desc: Verify encode destruct function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -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)); -} - -/** - * @tc.name: encode_test_002 - * @tc.desc: Verify start stop encoder function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncoderTest, encode_test_002, TestSize.Level1) -{ - EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audioEncoder_->StartAudioCodec()); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->StopAudioCodec()); - size_t bufLen = 4096; - std::shared_ptr inputData = std::make_shared(bufLen); - EXPECT_EQ(EOK, memset_s(inputData->Data(), inputData->Size(), 0, inputData->Size())); - EXPECT_EQ(ERR_DH_AUDIO_CODEC_INPUT, audioEncoder_->FeedAudioData(inputData)); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->ConfigureAudioCodec(LOC_COMPARA_ENC_TEST, encodeCb_)); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->StartAudioCodec()); - EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audioEncoder_->FeedAudioData(nullptr)); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->StopAudioCodec()); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->ReleaseAudioCodec()); -} - -/** - * @tc.name: encode_test_003 - * @tc.desc: Verify encode data function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncoderTest, encode_test_003, TestSize.Level1) -{ - audioEncoder_ = std::make_shared(); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->ConfigureAudioCodec(LOC_COMPARA_ENC_TEST, encodeCb_)); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->StartAudioCodec()); - - for (int32_t i = 0; i < 200; i++) { - size_t bufLen = 4096; - std::shared_ptr inputData = std::make_shared(bufLen); - EXPECT_EQ(EOK, memset_s(inputData->Data(), inputData->Size(), 0, inputData->Size())); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->FeedAudioData(inputData)); - } - - EXPECT_EQ(DH_SUCCESS, audioEncoder_->StopAudioCodec()); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->ReleaseAudioCodec()); -} - -/** - * @tc.name: encode_test_004 - * @tc.desc: Verify encode data function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncoderTest, encode_test_004, TestSize.Level1) -{ - audioEncoder_ = std::make_shared(); - for (int32_t i = 0; i < 200; i++) { - audioEncoder_->OnInputBufferAvailable(1); - } - Media::AVCodecBufferInfo info; - Media::AVCodecBufferFlag flag = static_cast(0); - audioEncoder_->OnOutputBufferAvailable(1, info, flag); - Media::Format format; - AudioEvent event; - audioEncoder_->OnOutputFormatChanged(format); - audioEncoder_->OnError(event); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->ConfigureAudioCodec(LOC_COMPARA_ENC_TEST, encodeCb_)); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->ReleaseAudioCodec()); -} - -/** - * @tc.name: EncodeDone_001 - * @tc.desc: Verify EncodeDone function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncoderTest, EncodeDone_001, TestSize.Level1) -{ - audioEncoder_ = std::make_shared(); - size_t bufLen = 4096; - AudioEvent event; - std::shared_ptr outputData = std::make_shared(bufLen); - std::shared_ptr encodeCb = std::make_shared(); - audioEncoder_->codecCallback_ = encodeCb; - EXPECT_EQ(DH_SUCCESS, audioEncoder_->EncodeDone(outputData)); -} - -/** - * @tc.name: EncodeDone_002 - * @tc.desc: Verify EncodeDone function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncoderTest, EncodeDone_002, TestSize.Level1) -{ - audioEncoder_ = std::make_shared(); - size_t bufLen = 4096; - std::shared_ptr outputData = std::make_shared(bufLen); - std::shared_ptr callback = nullptr; - audioEncoder_->codecCallback_ = callback; - EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audioEncoder_->EncodeDone(outputData)); -} - -/** - * @tc.name: InitAudioDecoder_001 - * @tc.desc: Verify InitAudioDecoder function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncoderTest, InitAudioDecoder_001, TestSize.Level1) -{ - AudioCommonParam codecParam; - audioEncoder_ = std::make_shared(); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->InitAudioEncoder(codecParam)); - EXPECT_EQ(DH_SUCCESS, audioEncoder_->SetEncoderFormat(codecParam)); -} - -/** - * @tc.name: ProcessData_001 - * @tc.desc: Verify ProcessData function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(EncoderTest, ProcessData_001, TestSize.Level1) -{ - size_t bufLen = 4096; - std::shared_ptr audioData = std::make_shared(bufLen); - int32_t bufferIndex = 0; - audioEncoder_ = std::make_shared(); - EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audioEncoder_->ProcessData(audioData, bufferIndex)); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/audiotransport/audiochannel/audiodatachannel/BUILD.gn b/services/audiotransport/audiochannel/audiodatachannel/BUILD.gn index c1374731..2ce55616 100644 --- a/services/audiotransport/audiochannel/audiodatachannel/BUILD.gn +++ b/services/audiotransport/audiochannel/audiodatachannel/BUILD.gn @@ -38,15 +38,11 @@ ohos_shared_library("distributed_audio_data_channel") { "${services_path}/common/audioparam", "${services_path}/common/audiodata/include", "${audio_transport_path}/audiochannel/interface", - "${softbusadapter_path}/include", ] sources = [ "src/audio_data_channel.cpp" ] - deps = [ - "${services_path}/common:distributed_audio_utils", - "${softbusadapter_path}:distributed_audio_softbus_adapter", - ] + deps = [ "${services_path}/common:distributed_audio_utils" ] external_deps = [ "c_utils:utils", diff --git a/services/audiotransport/audiochannel/audiodatachannel/include/audio_data_channel.h b/services/audiotransport/audiochannel/audiodatachannel/include/audio_data_channel.h index e442ce18..4bf679b6 100644 --- a/services/audiotransport/audiochannel/audiodatachannel/include/audio_data_channel.h +++ b/services/audiotransport/audiochannel/audiodatachannel/include/audio_data_channel.h @@ -21,12 +21,13 @@ #include "iaudio_channel_listener.h" #include "iaudio_channel.h" -#include "softbus_adapter.h" +#include "daudio_errorcode.h" +#include "daudio_log.h" +#include "daudio_util.h" namespace OHOS { namespace DistributedHardware { class AudioDataChannel : public IAudioChannel, - public ISoftbusListener, public std::enable_shared_from_this { public: explicit AudioDataChannel(const std::string &peerDevId) : peerDevId_(peerDevId) {}; @@ -40,12 +41,6 @@ public: int32_t SendData(const std::shared_ptr &audioData) override; int32_t SendEvent(const AudioEvent &audioEvent) override; - void OnSessionOpened(int32_t sessionId, int32_t result) override; - void OnSessionClosed(int32_t sessionId) override; - void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) override; - void OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *streamFrameInfo) override; - private: const std::string peerDevId_; int32_t sessionId_ = 0; diff --git a/services/audiotransport/audiochannel/audiodatachannel/src/audio_data_channel.cpp b/services/audiotransport/audiochannel/audiodatachannel/src/audio_data_channel.cpp index 0d524d4b..355c3af8 100644 --- a/services/audiotransport/audiochannel/audiodatachannel/src/audio_data_channel.cpp +++ b/services/audiotransport/audiochannel/audiodatachannel/src/audio_data_channel.cpp @@ -34,18 +34,6 @@ int32_t AudioDataChannel::CreateSession(const std::shared_ptr &audioData) { DHLOGD("Send data, sessionId: %d.", sessionId_); - return SoftbusAdapter::GetInstance().SendSoftbusStream(sessionId_, audioData); -} - -void AudioDataChannel::OnSessionOpened(int32_t sessionId, int32_t result) -{ - DHLOGD("On audio session opened, sessionId: %d, result: %d.", sessionId, result); - if (result != 0) { - DHLOGE("Session open failed."); - return; - } - - auto listener = channelListener_.lock(); - if (listener == nullptr) { - DHLOGE("Channel listener is null."); - return; - } - - listener->OnSessionOpened(); - sessionId_ = sessionId; - DaudioFinishAsyncTrace(DAUDIO_OPEN_DATA_SESSION, DAUDIO_OPEN_DATA_SESSION_TASKID); -} - -void AudioDataChannel::OnSessionClosed(int32_t sessionId) -{ - DHLOGI("On audio session closed, sessionId: %d.", sessionId); - if (sessionId_ == 0) { - DHLOGD("Session already closed."); - return; - } - auto listener = channelListener_.lock(); - if (listener == nullptr) { - DHLOGE("Channel listener is null."); - return; - } - listener->OnSessionClosed(); -} - -void AudioDataChannel::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) -{ - (void) sessionId; - (void) data; - (void) dataLen; - - DHLOGI("Data channel not support yet."); -} - -void AudioDataChannel::OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *streamFrameInfo) -{ - (void) ext; - (void) streamFrameInfo; - - auto listener = channelListener_.lock(); - if (listener == nullptr) { - DHLOGE("Channel listener is null."); - return; - } - - if (data == nullptr) { - DHLOGE("Received stream data is nullptr."); - return; - } - DHLOGI("On audio stream received, sessionId: %d dataSize: %zu.", sessionId, data->bufLen); - auto audioData = std::make_shared(data->bufLen); - if (memcpy_s(audioData->Data(), audioData->Capacity(), reinterpret_cast(data->buf), data->bufLen) - != EOK) { - DHLOGE("Received stream data copy failed."); - return; - } - listener->OnDataReceived(audioData); + return DH_SUCCESS; } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiotransport/decodetransport/BUILD.gn b/services/audiotransport/decodetransport/BUILD.gn index acb4b7a1..3bbf508a 100644 --- a/services/audiotransport/decodetransport/BUILD.gn +++ b/services/audiotransport/decodetransport/BUILD.gn @@ -45,8 +45,6 @@ ohos_shared_library("distributed_audio_decode_transport") { include_dirs += [ "include", - "${audio_processor_path}/decodeprocessor/include", - "${audio_processor_path}/decoder/include", "${audio_processor_path}/directprocessor/include", "${audio_processor_path}/interface", "${audio_transport_path}/audiochannel/audiodatachannel/include", @@ -59,15 +57,11 @@ ohos_shared_library("distributed_audio_decode_transport") { "${common_path}/dfx_utils/include", "${services_path}/common/audiodata/include", "${services_path}/common/audioparam", - "${softbusadapter_path}/include", ] public_configs = [ ":decode_transport_pub_config" ] sources = [ - "${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}/directprocessor/src/audio_direct_processor.cpp", "${audio_transport_path}/receiverengine/src/av_receiver_engine_adapter.cpp", "${audio_transport_path}/receiverengine/src/av_receiver_engine_transport.cpp", diff --git a/services/audiotransport/decodetransport/include/audio_decode_transport.h b/services/audiotransport/decodetransport/include/audio_decode_transport.h index 180590e5..90027e62 100644 --- a/services/audiotransport/decodetransport/include/audio_decode_transport.h +++ b/services/audiotransport/decodetransport/include/audio_decode_transport.h @@ -23,6 +23,7 @@ #include "audio_event.h" #include "audio_transport_context.h" +#include "daudio_constants.h" #include "iaudio_channel.h" #include "iaudio_datatrans_callback.h" #include "iaudio_data_transport.h" diff --git a/services/audiotransport/decodetransport/src/audio_decode_transport.cpp b/services/audiotransport/decodetransport/src/audio_decode_transport.cpp index 88c600e0..178ee56b 100644 --- a/services/audiotransport/decodetransport/src/audio_decode_transport.cpp +++ b/services/audiotransport/decodetransport/src/audio_decode_transport.cpp @@ -16,7 +16,6 @@ #include "audio_decode_transport.h" #include "audio_data_channel.h" -#include "audio_decoder_processor.h" #include "audio_direct_processor.h" #include "audio_param.h" #include "daudio_errorcode.h" @@ -263,8 +262,6 @@ int32_t AudioDecodeTransport::RegisterProcessorListener(const AudioParam &localP DHLOGI("Use direct processor, renderFlags: %d, capturerFlags: %d.", localParam.renderOpts.renderFlags, localParam.captureOpts.capturerFlags); processor_ = std::make_shared(); - } else { - processor_ = std::make_shared(); } int32_t ret = processor_->ConfigureAudioProcessor(localParam.comParam, remoteParam.comParam, shared_from_this()); if (ret != DH_SUCCESS) { diff --git a/services/audiotransport/encodetransport/BUILD.gn b/services/audiotransport/encodetransport/BUILD.gn index 6801655b..86417298 100644 --- a/services/audiotransport/encodetransport/BUILD.gn +++ b/services/audiotransport/encodetransport/BUILD.gn @@ -46,8 +46,6 @@ ohos_shared_library("distributed_audio_encode_transport") { include_dirs += [ "include", "${audio_processor_path}/directprocessor/include", - "${audio_processor_path}/encodeprocessor/include", - "${audio_processor_path}/encoder/include", "${audio_processor_path}/interface", "${audio_transport_path}/audiochannel/interface", "${audio_transport_path}/audiochannel/audiodatachannel/include", @@ -59,16 +57,12 @@ ohos_shared_library("distributed_audio_encode_transport") { "${common_path}/include", "${services_path}/common/audiodata/include", "${services_path}/common/audioparam", - "${softbusadapter_path}/include", ] public_configs = [ ":encode_transport_pub_config" ] sources = [ "${audio_processor_path}/directprocessor/src/audio_direct_processor.cpp", - "${audio_processor_path}/encodeprocessor/src/audio_encoder_processor.cpp", - "${audio_processor_path}/encoder/src/audio_encoder.cpp", - "${audio_processor_path}/encoder/src/audio_encoder_callback.cpp", "${audio_transport_path}/senderengine/src/av_sender_engine_adapter.cpp", "${audio_transport_path}/senderengine/src/av_sender_engine_transport.cpp", "${services_path}/common/audiodata/src/audio_data.cpp", diff --git a/services/audiotransport/encodetransport/include/audio_encode_transport.h b/services/audiotransport/encodetransport/include/audio_encode_transport.h index 52397b31..5106b0cf 100644 --- a/services/audiotransport/encodetransport/include/audio_encode_transport.h +++ b/services/audiotransport/encodetransport/include/audio_encode_transport.h @@ -24,6 +24,7 @@ #include "audio_event.h" #include "audio_transport_context.h" +#include "daudio_constants.h" #include "iaudio_channel.h" #include "iaudio_datatrans_callback.h" #include "iaudio_data_transport.h" diff --git a/services/audiotransport/encodetransport/src/audio_encode_transport.cpp b/services/audiotransport/encodetransport/src/audio_encode_transport.cpp index 763b266e..1ce3b332 100644 --- a/services/audiotransport/encodetransport/src/audio_encode_transport.cpp +++ b/services/audiotransport/encodetransport/src/audio_encode_transport.cpp @@ -16,7 +16,6 @@ #include "audio_encode_transport.h" #include "audio_data_channel.h" -#include "audio_encoder_processor.h" #include "audio_direct_processor.h" #include "audio_param.h" #include "daudio_errorcode.h" @@ -213,8 +212,6 @@ int32_t AudioEncodeTransport::RegisterProcessorListener(const AudioParam &localP DHLOGI("Use direct processor, renderFlags: %d, capturerFlags: %d.", localParam.renderOpts.renderFlags, localParam.captureOpts.capturerFlags); processor_ = std::make_shared(); - } else { - processor_ = std::make_shared(); } if (audioChannel_ == nullptr) { DHLOGE("Create audio processor failed."); diff --git a/services/audiotransport/test/unittest/BUILD.gn b/services/audiotransport/test/unittest/BUILD.gn index c0c8266d..e2dd9df6 100644 --- a/services/audiotransport/test/unittest/BUILD.gn +++ b/services/audiotransport/test/unittest/BUILD.gn @@ -18,10 +18,7 @@ import("../../../../distributedaudio.gni") group("daudio_transport_test") { testonly = true deps = [ - "${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/receiverengine:av_receiver_engine_adapter_test", "${audio_transport_path}/test/unittest/senderengine:av_sender_engine_adapter_test", ] diff --git a/services/audiotransport/test/unittest/audiodatachannel/BUILD.gn b/services/audiotransport/test/unittest/audiodatachannel/BUILD.gn deleted file mode 100644 index 55297b02..00000000 --- a/services/audiotransport/test/unittest/audiodatachannel/BUILD.gn +++ /dev/null @@ -1,62 +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. - -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -module_out_path = - "distributed_audio/services/audiotransport/audio_data_channel_test" - -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "//third_party/cJSON", - "//third_party/json/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${services_path}/common/audioparam", - "${services_path}/common/audiodata/include", - "${softbusadapter_path}/include", - "${audio_transport_path}/audiochannel/interface", - "${audio_transport_path}/audiochannel/audiodatachannel/include", - "${audio_transport_path}/audioctrltransport/interface", - "${audio_transport_path}/test/unittest/audiotranstestutils/include", - ] -} - -## UnitTest audio_data_channel_test -ohos_unittest("AudioDataChannelTest") { - module_out_path = module_out_path - - sources = [ "src/audio_data_channel_test.cpp" ] - - configs = [ ":module_private_config" ] - - deps = [ - "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", - "${softbusadapter_path}:distributed_audio_softbus_adapter", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] -} - -group("audio_data_channel_test") { - testonly = true - deps = [ ":AudioDataChannelTest" ] -} diff --git a/services/audiotransport/test/unittest/audiodatachannel/include/audio_data_channel_test.h b/services/audiotransport/test/unittest/audiodatachannel/include/audio_data_channel_test.h deleted file mode 100644 index 65f8db6b..00000000 --- a/services/audiotransport/test/unittest/audiodatachannel/include/audio_data_channel_test.h +++ /dev/null @@ -1,42 +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_AUDIO_DATA_CHANNEL_TEST_H -#define OHOS_AUDIO_DATA_CHANNEL_TEST_H - -#include - -#include "daudio_constants.h" -#include "daudio_errorcode.h" -#include "audiotrans_test_utils.h" - -#define private public -#include "audio_data_channel.h" -#undef private - -namespace OHOS { -namespace DistributedHardware { -class AudioDataChannelTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - std::shared_ptr dataChannel_ = nullptr; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_AUDIO_DATA_CHANNEL_TEST_H 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 deleted file mode 100644 index 582dafd6..00000000 --- a/services/audiotransport/test/unittest/audiodatachannel/src/audio_data_channel_test.cpp +++ /dev/null @@ -1,127 +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_data_channel_test.h" - -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -void AudioDataChannelTest::SetUpTestCase(void) {} - -void AudioDataChannelTest::TearDownTestCase(void) {} - -void AudioDataChannelTest::SetUp(void) -{ - std::string peerDevId = "peerDevId"; - dataChannel_ = std::make_shared(peerDevId); -} - -void AudioDataChannelTest::TearDown(void) -{ - dataChannel_ = nullptr; -} - -/** - * @tc.name: CreateSession_001 - * @tc.desc: Verify the CreateSession and ReleaseSession function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioDataChannelTest, CreateSession_001, TestSize.Level1) -{ - std::shared_ptr listener = nullptr; - dataChannel_->channelListener_ = listener; - int32_t sessionId = 0; - - dataChannel_->OnSessionClosed(sessionId); - - EXPECT_NE(DH_SUCCESS, dataChannel_->CreateSession(listener, DATA_SPEAKER_SESSION_NAME)); - EXPECT_EQ(DH_SUCCESS, dataChannel_->ReleaseSession()); -} - -/** - * @tc.name: OpenSession_002 - * @tc.desc: Verify the OpenSession and CloseSession function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioDataChannelTest, OpenSession_002, TestSize.Level1) -{ - std::shared_ptr listener = nullptr; - dataChannel_->channelListener_ = listener; - int32_t sessionId = 0; - int32_t result = 0; - - dataChannel_->OnSessionOpened(sessionId, result); - - std::shared_ptr channelListener = std::make_shared(); - dataChannel_->channelListener_ = channelListener; - - StreamData *ext = nullptr; - StreamFrameInfo *param = nullptr; - - int32_t sessionIdTmp = 0; - StreamData data; - data.buf = new char[DATA_LEN]; - data.bufLen = DATA_LEN; - - 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()); -} - -/** - * @tc.name: SendData_001 - * @tc.desc: Verify the SendData function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioDataChannelTest, SendData_001, TestSize.Level1) -{ - std::shared_ptr listener = std::make_shared(); - dataChannel_->channelListener_ = listener; - int32_t sessionId = -1; - int32_t result = -1; - - dataChannel_->OnSessionOpened(sessionId, result); - - std::shared_ptr data = nullptr; - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, dataChannel_->SendData(data)); -} - -/** - * @tc.name: SendData_002 - * @tc.desc: Verify the SendData function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioDataChannelTest, SendData_002, TestSize.Level1) -{ - std::shared_ptr listener = std::make_shared(); - dataChannel_->channelListener_ = listener; - int32_t sessionId = 0; - int32_t result = 0; - - dataChannel_->OnSessionOpened(sessionId, result); - - std::shared_ptr audioData = std::make_shared(DEFAULT_AUDIO_DATA_SIZE); - EXPECT_EQ(DH_SUCCESS, dataChannel_->SendData(audioData)); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/audiotransport/test/unittest/decodetransport/BUILD.gn b/services/audiotransport/test/unittest/decodetransport/BUILD.gn index 75cefc1b..81b38831 100644 --- a/services/audiotransport/test/unittest/decodetransport/BUILD.gn +++ b/services/audiotransport/test/unittest/decodetransport/BUILD.gn @@ -43,7 +43,6 @@ config("module_private_config") { "${common_path}/include", "${services_path}/common/audiodata/include", "${services_path}/common/audioparam", - "${softbusadapter_path}/include", ] } diff --git a/services/audiotransport/test/unittest/encodetransport/BUILD.gn b/services/audiotransport/test/unittest/encodetransport/BUILD.gn index 22e4b574..66b2d087 100644 --- a/services/audiotransport/test/unittest/encodetransport/BUILD.gn +++ b/services/audiotransport/test/unittest/encodetransport/BUILD.gn @@ -43,7 +43,6 @@ config("module_private_config") { "${common_path}/include", "${services_path}/common/audiodata/include", "${services_path}/common/audioparam", - "${softbusadapter_path}/include", ] } diff --git a/services/audiotransport/test/unittest/receiverengine/BUILD.gn b/services/audiotransport/test/unittest/receiverengine/BUILD.gn index 814d3dce..f7572da0 100644 --- a/services/audiotransport/test/unittest/receiverengine/BUILD.gn +++ b/services/audiotransport/test/unittest/receiverengine/BUILD.gn @@ -35,7 +35,6 @@ config("module_private_config") { "${audio_transport_path}/senderengine/include", "${services_path}/common/audiodata/include", "${services_path}/common/audioparam", - "${softbusadapter_path}/include", ] } diff --git a/services/audiotransport/test/unittest/senderengine/BUILD.gn b/services/audiotransport/test/unittest/senderengine/BUILD.gn index cded03c1..a8e84186 100644 --- a/services/audiotransport/test/unittest/senderengine/BUILD.gn +++ b/services/audiotransport/test/unittest/senderengine/BUILD.gn @@ -34,7 +34,6 @@ config("module_private_config") { "${audio_transport_path}/senderengine/include", "${services_path}/common/audiodata/include", "${services_path}/common/audioparam", - "${softbusadapter_path}/include", ] } diff --git a/services/softbusadapter/BUILD.gn b/services/softbusadapter/BUILD.gn deleted file mode 100644 index 62086d13..00000000 --- a/services/softbusadapter/BUILD.gn +++ /dev/null @@ -1,61 +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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("../../distributedaudio.gni") - -ohos_shared_library("distributed_audio_softbus_adapter") { - branch_protector_ret = "pac_ret" - sanitize = { - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - debug = false - integer_overflow = true - ubsan = true - } - stack_protector_ret = true - include_dirs = [ - "${fwk_common_path}/utils/include", - "//third_party/json/include", - ] - - include_dirs += [ - "${common_path}/include", - "${services_path}/common/audioparam", - "${services_path}/common/audiodata/include", - "${softbusadapter_path}/include", - ] - - sources = [ - "${services_path}/common/audiodata/src/audio_data.cpp", - "src/softbus_adapter.cpp", - ] - - deps = [ "${services_path}/common:distributed_audio_utils" ] - - external_deps = [ - "c_utils:utils", - "dsoftbus:softbus_client", - ] - - defines = [ - "HI_LOG_ENABLE", - "LOG_DOMAIN=0xD004100", - ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_audio" -} diff --git a/services/softbusadapter/include/isoftbus_listener.h b/services/softbusadapter/include/isoftbus_listener.h deleted file mode 100644 index ffe37a3e..00000000 --- a/services/softbusadapter/include/isoftbus_listener.h +++ /dev/null @@ -1,35 +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_ISOFTBUS_LISTENER -#define OHOS_ISOFTBUS_LISTENER - -#include "session.h" - -namespace OHOS { -namespace DistributedHardware { -class ISoftbusListener { -public: - virtual ~ISoftbusListener() = default; - - virtual void OnSessionOpened(int32_t sessionId, int32_t result) = 0; - virtual void OnSessionClosed(int32_t sessionId) = 0; - virtual void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) = 0; - virtual void OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *streamFrameInfo) = 0; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_ISOFTBUS_LISTENER diff --git a/services/softbusadapter/include/softbus_adapter.h b/services/softbusadapter/include/softbus_adapter.h deleted file mode 100644 index 55c694b9..00000000 --- a/services/softbusadapter/include/softbus_adapter.h +++ /dev/null @@ -1,98 +0,0 @@ - /* - * Copyright (c) 2022-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_SOFTBUS_ADAPTER_H -#define OHOS_SOFTBUS_ADAPTER_H - -#include -#include -#include -#include -#include -#include -#include - -#include "single_instance.h" - -#include "audio_data.h" -#include "daudio_constants.h" -#include "daudio_log.h" -#include "daudio_errorcode.h" -#include "daudio_util.h" -#include "isoftbus_listener.h" - -namespace OHOS { -namespace DistributedHardware { -class SoftbusAdapter { -public: - DECLARE_SINGLE_INSTANCE_BASE(SoftbusAdapter); -public: - int32_t CreateSoftbusSessionServer(const std::string &pkgName, const std::string &sessionName, - const std::string &peerDevId); - int32_t RemoveSoftbusSessionServer(const std::string &pkgname, const std::string &sessionName, - const std::string &peerDevId); - int32_t OpenSoftbusSession(const std::string &mySessionName, const std::string &peerSessionName, - const std::string &peerDevId); - int32_t CloseSoftbusSession(int32_t sessionId); - int32_t SendSoftbusBytes(int32_t sessionId, const void *data, int32_t dataLen); - int32_t SendSoftbusStream(int32_t sessionId, const std::shared_ptr &audioData); - int32_t RegisterSoftbusListener(const std::shared_ptr &listener, const std::string &sessionName, - const std::string &peerDevId); - int32_t UnRegisterSoftbusListener(const std::string &sessionName, const std::string &peerDevId); - - int32_t OnSoftbusSessionOpened(int32_t sessionId, int32_t result); - void OnSoftbusSessionClosed(int32_t sessionId); - void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); - void OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *streamFrameInfo); - void OnMessageReceived(int sessionId, const void *data, unsigned int dataLen); - void OnQosEvent(int sessionId, int eventId, int tvCount, const QosTv *tvList); - -private: - SoftbusAdapter(); - ~SoftbusAdapter(); - std::shared_ptr &GetSoftbusListenerByName(int32_t sessionId); - std::shared_ptr &GetSoftbusListenerById(int32_t sessionId); - void SendAudioData(); - void StopSendDataThread(); - - struct SoftbusStreamData { - SoftbusStreamData() = default; - SoftbusStreamData(const std::shared_ptr &data, const int32_t id) : data_(data), sessionId_(id) {}; - ~SoftbusStreamData() = default; - std::shared_ptr data_; - int32_t sessionId_; - }; - -private: - static constexpr size_t DATA_QUEUE_MAX_SIZE = 500; - static constexpr const char* SENDDATA_THREAD = "sendDataThread"; - std::mutex listenerMtx_; - std::mutex sessSetMtx_; - std::mutex dataQueueMtx_; - std::condition_variable sendDataCond_; - std::thread sendDataThread_; - - std::atomic isSessionOpened_ = false; - ISessionListener sessListener_; - std::shared_ptr nullListener_; - std::unordered_map> mapSessionSet_; - std::unordered_map> mapListenersN_; - std::unordered_map> mapListenersI_; - std::queue> audioDataQueue_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_SOFTBUS_ADAPTER_H diff --git a/services/softbusadapter/src/softbus_adapter.cpp b/services/softbusadapter/src/softbus_adapter.cpp deleted file mode 100644 index b947346c..00000000 --- a/services/softbusadapter/src/softbus_adapter.cpp +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (c) 2022-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 "softbus_adapter.h" -#include "softbus_error_code.h" - -#include - -#undef DH_LOG_TAG -#define DH_LOG_TAG "SoftbusAdapter" - -namespace OHOS { -namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(SoftbusAdapter); -static int32_t AudioOnSoftbusSessionOpened(int32_t sessionId, int32_t result) -{ - return SoftbusAdapter::GetInstance().OnSoftbusSessionOpened(sessionId, result); -} - -static void AudioOnSoftbusSessionClosed(int32_t sessionId) -{ - SoftbusAdapter::GetInstance().OnSoftbusSessionClosed(sessionId); -} - -static void AudioOnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) -{ - SoftbusAdapter::GetInstance().OnBytesReceived(sessionId, data, dataLen); -} - -static void AudioOnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *frameInfo) -{ - SoftbusAdapter::GetInstance().OnStreamReceived(sessionId, data, ext, frameInfo); -} - -static void AudioOnMessageReceived(int sessionId, const void *data, unsigned int dataLen) -{ - SoftbusAdapter::GetInstance().OnMessageReceived(sessionId, data, dataLen); -} - -static void AudioOnQosEvent(int sessionId, int eventId, int tvCount, const QosTv *tvList) -{ - SoftbusAdapter::GetInstance().OnQosEvent(sessionId, eventId, tvCount, tvList); -} - -SoftbusAdapter::SoftbusAdapter() -{ - DHLOGD("Softbus adapter constructed."); - sessListener_.OnSessionOpened = AudioOnSoftbusSessionOpened; - sessListener_.OnSessionClosed = AudioOnSoftbusSessionClosed; - sessListener_.OnBytesReceived = AudioOnBytesReceived; - sessListener_.OnStreamReceived = AudioOnStreamReceived; - sessListener_.OnMessageReceived = AudioOnMessageReceived; - sessListener_.OnQosEvent = AudioOnQosEvent; -} - -SoftbusAdapter::~SoftbusAdapter() -{ - DHLOGD("Softbus adapter destructed."); -} - -int32_t SoftbusAdapter::CreateSoftbusSessionServer(const std::string &pkgName, const std::string &sessionName, - const std::string &peerDevId) -{ - DHLOGI("Create server, sessName: %s peerDevId: %s.", sessionName.c_str(), GetAnonyString(peerDevId).c_str()); - std::lock_guard setLock(sessSetMtx_); - if (mapSessionSet_.find(sessionName) == mapSessionSet_.end()) { - int32_t ret = CreateSessionServer(pkgName.c_str(), sessionName.c_str(), &sessListener_); - if (ret != SOFTBUS_OK) { - DHLOGE("Create session server failed, ret %d.", ret); - return ret; - } - } else { - DHLOGD("Session is already created."); - return DH_SUCCESS; - } - - mapSessionSet_[sessionName].insert(peerDevId); - DHLOGI("Create session server success."); - return DH_SUCCESS; -} - -int32_t SoftbusAdapter::RemoveSoftbusSessionServer(const std::string &pkgName, const std::string &sessionName, - const std::string &peerDevId) -{ - DHLOGI("Remove server, sessName: %s peerDevId: %s.", sessionName.c_str(), GetAnonyString(peerDevId).c_str()); - std::lock_guard setLock(sessSetMtx_); - if (mapSessionSet_.find(sessionName) == mapSessionSet_.end()) { - DHLOGE("Session server already removed."); - return DH_SUCCESS; - } - mapSessionSet_[sessionName].erase(peerDevId); - if (mapSessionSet_[sessionName].empty()) { - mapSessionSet_.erase(sessionName); - int32_t ret = RemoveSessionServer(pkgName.c_str(), sessionName.c_str()); - if (ret != SOFTBUS_OK) { - DHLOGE("Remove session server failed. Error code %d.", ret); - } - } - DHLOGI("Remove session server success."); - return DH_SUCCESS; -} - -int32_t SoftbusAdapter::OpenSoftbusSession(const std::string &localSessionName, const std::string &peerSessionName, - const std::string &peerDevId) -{ - DHLOGI("Open softbus session, localSess: %s peerSess: %s peerDevId: %s.", localSessionName.c_str(), - peerSessionName.c_str(), GetAnonyString(peerDevId).c_str()); - int dataType = TYPE_BYTES; - int streamType = -1; - if (localSessionName != CTRL_SESSION_NAME) { - dataType = TYPE_STREAM; - streamType = RAW_STREAM; - } - - SessionAttribute attr = { 0 }; - attr.dataType = dataType; - attr.linkTypeNum = LINK_TYPE_MAX; - LinkType linkTypeList[LINK_TYPE_MAX] = { - LINK_TYPE_WIFI_P2P, - LINK_TYPE_WIFI_WLAN_5G, - LINK_TYPE_WIFI_WLAN_2G, - LINK_TYPE_BR, - }; - if (memcpy_s(attr.linkType, sizeof(attr.linkType), linkTypeList, sizeof(linkTypeList)) != EOK) { - DHLOGE("Softbus open session params copy failed."); - return ERR_DH_AUDIO_FAILED; - } - attr.attr.streamAttr.streamType = streamType; - int32_t sessionId = OpenSession(localSessionName.c_str(), peerSessionName.c_str(), peerDevId.c_str(), "0", &attr); - if (sessionId < 0) { - DHLOGE("Open softbus session failed sessionId: %d.", sessionId); - return ERR_DH_AUDIO_FAILED; - } - DHLOGI("Open softbus session success."); - return sessionId; -} - -int32_t SoftbusAdapter::CloseSoftbusSession(int32_t sessionId) -{ - DHLOGI("Close softbus session: %d.", sessionId); - CloseSession(sessionId); - std::lock_guard LisLock(listenerMtx_); - mapListenersI_.erase(sessionId); - StopSendDataThread(); - DHLOGI("Close softbus session success."); - return DH_SUCCESS; -} - -int32_t SoftbusAdapter::SendSoftbusBytes(int32_t sessionId, const void *data, int32_t dataLen) -{ - DHLOGI("Send audio event, sessionId: %d.", sessionId); - int32_t ret = SendBytes(sessionId, data, dataLen); - if (ret != SOFTBUS_OK) { - DHLOGE("Send bytes failed, ret:%d.", ret); - return ERR_DH_AUDIO_TRANS_ERROR; - } - return DH_SUCCESS; -} - -int32_t SoftbusAdapter::SendSoftbusStream(int32_t sessionId, const std::shared_ptr &audioData) -{ - DHLOGI("Send audio data, sessionId: %d.", sessionId); - if (audioData == nullptr) { - DHLOGE("Audio data is null."); - return ERR_DH_AUDIO_NULLPTR; - } - std::lock_guard lck(dataQueueMtx_); - while (audioDataQueue_.size() >= DATA_QUEUE_MAX_SIZE) { - DHLOGE("Softbus data queue overflow. data queue size: %d", audioDataQueue_.size()); - audioDataQueue_.pop(); - } - auto data = std::make_shared(audioData, sessionId); - audioDataQueue_.push(data); - sendDataCond_.notify_all(); - return DH_SUCCESS; -} - -int32_t SoftbusAdapter::RegisterSoftbusListener(const std::shared_ptr &listener, - const std::string &sessionName, const std::string &peerDevId) -{ - DHLOGI("Register listener sess: %s peerDevId: %s.", sessionName.c_str(), GetAnonyString(peerDevId).c_str()); - std::string strListenerKey = sessionName + "_" + peerDevId; - std::lock_guard lisLock(listenerMtx_); - if (mapListenersN_.find(strListenerKey) != mapListenersN_.end()) { - DHLOGD("Session listener already register."); - return DH_SUCCESS; - } - mapListenersN_.insert(std::make_pair(strListenerKey, listener)); - return DH_SUCCESS; -} - -int32_t SoftbusAdapter::UnRegisterSoftbusListener(const std::string &sessionName, const std::string &peerDevId) -{ - DHLOGI("Unregister listener sess: %s peerDevId: %s.", sessionName.c_str(), GetAnonyString(peerDevId).c_str()); - std::string strListenerKey = sessionName + "_" + peerDevId; - std::lock_guard lisLock(listenerMtx_); - mapListenersN_.erase(strListenerKey); - return DH_SUCCESS; -} - -int32_t SoftbusAdapter::OnSoftbusSessionOpened(int32_t sessionId, int32_t result) -{ - DHLOGI("On session opened, sessionId: %d, result: %d.", sessionId, result); - if (result != SOFTBUS_OK) { - DHLOGE("Session open failed."); - return ERR_DH_AUDIO_FAILED; - } - auto &listener = GetSoftbusListenerByName(sessionId); - if (!listener) { - DHLOGE("Get softbus listener failed."); - return ERR_DH_AUDIO_TRANS_ERROR; - } - - std::lock_guard lisLock(listenerMtx_); - if (mapListenersI_.empty()) { - DHLOGD("Start softbus send thread."); - isSessionOpened_.store(true); - sendDataThread_ = std::thread(&SoftbusAdapter::SendAudioData, this); - if (pthread_setname_np(sendDataThread_.native_handle(), SENDDATA_THREAD) != DH_SUCCESS) { - DHLOGE("Send data thread setname failed."); - } - } - mapListenersI_.insert(std::make_pair(sessionId, listener)); - listener->OnSessionOpened(sessionId, result); - return DH_SUCCESS; -} - -void SoftbusAdapter::OnSoftbusSessionClosed(int32_t sessionId) -{ - DHLOGI("On session closed, sessionId: %d.", sessionId); - auto &listener = GetSoftbusListenerById(sessionId); - if (!listener) { - DHLOGE("Get softbus listener failed."); - return; - } - listener->OnSessionClosed(sessionId); - - std::lock_guard lisLock(listenerMtx_); - mapListenersI_.erase(sessionId); - StopSendDataThread(); -} - -void SoftbusAdapter::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) -{ - DHLOGI("On audio event received from session: %d.", sessionId); - if (data == nullptr) { - DHLOGE("Bytes data is null."); - return; - } else if (dataLen == 0 || dataLen > DAUDIO_MAX_RECV_DATA_LEN) { - DHLOGE("Stream data length is illegal, dataLen: %d.", dataLen); - return; - } - - auto &listener = GetSoftbusListenerById(sessionId); - if (listener == nullptr) { - DHLOGE("Get softbus listener failed."); - return; - } - listener->OnBytesReceived(sessionId, data, dataLen); -} - -void SoftbusAdapter::OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *streamFrameInfo) -{ - DHLOGI("On audio data received from session: %d.", sessionId); - if (data == nullptr) { - DHLOGE("Stream data is null."); - return; - } else if (data->bufLen <= 0 || (uint32_t)(data->bufLen) > DAUDIO_MAX_RECV_DATA_LEN) { - DHLOGE("Stream data length is illegal, dataLen: %d.", data->bufLen); - return; - } - - auto &listener = GetSoftbusListenerById(sessionId); - if (!listener) { - DHLOGE("Get softbus listener failed."); - return; - } - listener->OnStreamReceived(sessionId, data, ext, streamFrameInfo); -} - -void SoftbusAdapter::OnMessageReceived(int sessionId, const void *data, unsigned int dataLen) -{ - DHLOGD("On message received, sessionId: %d.", sessionId); -} - -void SoftbusAdapter::OnQosEvent(int sessionId, int eventId, int tvCount, const QosTv *tvList) -{ - DHLOGD("On qos event received, sessionId: %d.", sessionId); -} - -std::shared_ptr &SoftbusAdapter::GetSoftbusListenerByName(int32_t sessionId) -{ - char sessionName[DAUDIO_MAX_SESSION_NAME_LEN] = ""; - char peerDevId[DAUDIO_MAX_DEVICE_ID_LEN] = ""; - int32_t ret = GetPeerSessionName(sessionId, sessionName, sizeof(sessionName)); - if (ret != SOFTBUS_OK) { - DHLOGE("Get peer session name failed ret: %d.", ret); - return nullListener_; - } - ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId)); - if (ret != SOFTBUS_OK) { - DHLOGE("Get peer deviceId failed ret: %d.", ret); - return nullListener_; - } - std::string sessionNameStr(sessionName); - std::string peerDevIdStr(peerDevId); - std::string strListenerKey = sessionNameStr + "_" + peerDevIdStr; - - DHLOGI("Get listener sess: %s, peerDevId: %s.", sessionNameStr.c_str(), GetAnonyString(peerDevIdStr).c_str()); - std::lock_guard lisLock(listenerMtx_); - if (mapListenersN_.find(strListenerKey) == mapListenersN_.end()) { - DHLOGE("Find listener failed."); - return nullListener_; - } - return mapListenersN_[strListenerKey]; -} - -std::shared_ptr &SoftbusAdapter::GetSoftbusListenerById(int32_t sessionId) -{ - std::lock_guard lisLock(listenerMtx_); - if (mapListenersI_.find(sessionId) == mapListenersI_.end()) { - DHLOGE("Find listener failed."); - return nullListener_; - } - return mapListenersI_[sessionId]; -} - -void SoftbusAdapter::SendAudioData() -{ - constexpr uint8_t DATA_WAIT_TIME = 20; - while (isSessionOpened_.load()) { - std::shared_ptr audioData; - { - std::unique_lock lock(dataQueueMtx_); - sendDataCond_.wait_for(lock, std::chrono::milliseconds(DATA_WAIT_TIME), - [this]() { return !audioDataQueue_.empty(); }); - if (audioDataQueue_.empty()) { - continue; - } - audioData = audioDataQueue_.front(); - audioDataQueue_.pop(); - } - if (audioData == nullptr || audioData->data_ == nullptr) { - DHLOGE("Audio data is null."); - continue; - } - - StreamData data = { reinterpret_cast(audioData->data_->Data()), audioData->data_->Capacity() }; - StreamData ext; - StreamFrameInfo frameInfo; - DHLOGI("Send audio data, sessionId: %d.", audioData->sessionId_); - int32_t ret = SendStream(audioData->sessionId_, &data, &ext, &frameInfo); - if (ret != SOFTBUS_OK) { - DHLOGE("Send data failed. ret: %d.", ret); - } else { - DHLOGI("Send audio data successs."); - } - } -} - -void SoftbusAdapter::StopSendDataThread() -{ - if (mapListenersI_.empty()) { - DHLOGI("Stop softbus send thread."); - isSessionOpened_.store(false); - if (sendDataThread_.joinable()) { - sendDataThread_.join(); - } - } -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn deleted file mode 100644 index a4b79550..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn +++ /dev/null @@ -1,71 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnBytesReceivedFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/softbusonbytesreceived" - fuzz_config_file = - "${softbusadapter_path}/test/fuzztest/softbusonbytesreceived_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "softbusonbytesreceived_fuzzer.cpp" ] - - include_dirs = [ - "${audio_transport_path}/audiochannel/interface", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${softbusadapter_path}/include", - "//third_party/json/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_transport_path}/audiochannel/audiodatachannel/include", - ] - - deps = [ - "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "ipc:ipc_core", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnBytesReceivedFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnBytesReceivedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp deleted file mode 100644 index 1023f6e8..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp +++ /dev/null @@ -1,49 +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 "softbusonbytesreceived_fuzzer.h" - -#include -#include - -#include "audio_data_channel.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnBytesReceivedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - std::string peerDevId(reinterpret_cast(data), size); - int32_t sessionId = *(reinterpret_cast(data)); - uint32_t len = *(reinterpret_cast(data)); - void *bytes = nullptr; - std::shared_ptr dataChannel = std::make_shared(peerDevId); - dataChannel->OnBytesReceived(sessionId, bytes, len); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SoftbusOnBytesReceivedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h deleted file mode 100644 index 245aaab3..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h +++ /dev/null @@ -1,21 +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 SOFTBUSONBYTESRECEIVED_FUZZER_H -#define SOFTBUSONBYTESRECEIVED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonbytesreceived_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn deleted file mode 100644 index dac1a93c..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn +++ /dev/null @@ -1,71 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnSessionClosedFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/softbusonsessionclosed" - fuzz_config_file = - "${softbusadapter_path}/test/fuzztest/softbusonsessionclosed_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "softbusonsessionclosed_fuzzer.cpp" ] - - include_dirs = [ - "${audio_transport_path}/audiochannel/interface", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${softbusadapter_path}/include", - "//third_party/json/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_transport_path}/audiochannel/audiodatachannel/include", - ] - - deps = [ - "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "ipc:ipc_core", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnSessionClosedFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnSessionClosedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp deleted file mode 100644 index 4bf40259..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp +++ /dev/null @@ -1,47 +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 "softbusonsessionclosed_fuzzer.h" - -#include -#include - -#include "audio_data_channel.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnSessionClosedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - std::string peerDevId(reinterpret_cast(data), size); - int32_t sessionId = *(reinterpret_cast(data)); - std::shared_ptr dataChannel = std::make_shared(peerDevId); - dataChannel->OnSessionClosed(sessionId); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SoftbusOnSessionClosedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h deleted file mode 100644 index 8641aaaa..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h +++ /dev/null @@ -1,21 +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 SOFTBUSONSESSIONCLOSED_FUZZER_H -#define SOFTBUSONSESSIONCLOSED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonsessionclosed_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn deleted file mode 100644 index 467d2a08..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn +++ /dev/null @@ -1,71 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnSessionOpenedFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/softbusonsessionopened" - fuzz_config_file = - "${softbusadapter_path}/test/fuzztest/softbusonsessionopened_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "softbusonsessionopened_fuzzer.cpp" ] - - include_dirs = [ - "${audio_transport_path}/audiochannel/interface", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${softbusadapter_path}/include", - "//third_party/json/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_transport_path}/audiochannel/audiodatachannel/include", - ] - - deps = [ - "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "ipc:ipc_core", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnSessionOpenedFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnSessionOpenedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp deleted file mode 100644 index 6c540e5b..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.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 "softbusonsessionopened_fuzzer.h" - -#include -#include - -#include "audio_data_channel.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnSessionOpenedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - std::string peerDevId(reinterpret_cast(data), size); - int32_t sessionId = *(reinterpret_cast(data)); - int32_t result = *(reinterpret_cast(data)); - std::shared_ptr dataChannel = std::make_shared(peerDevId); - dataChannel->OnSessionOpened(sessionId, result); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SoftbusOnSessionOpenedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h deleted file mode 100644 index 8dbb5a98..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h +++ /dev/null @@ -1,21 +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 SOFTBUSONSESSIONOPENED_FUZZER_H -#define SOFTBUSONSESSIONOPENED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonsessionopened_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn deleted file mode 100644 index f491ff04..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn +++ /dev/null @@ -1,71 +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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnStreamReceivedFuzzTest") { - module_out_path = "${distributedaudio_fuzz_path}/softbusonstreamreceived" - fuzz_config_file = - "${softbusadapter_path}/test/fuzztest/softbusonstreamreceived_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "softbusonstreamreceived_fuzzer.cpp" ] - - include_dirs = [ - "${audio_transport_path}/audiochannel/interface", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${softbusadapter_path}/include", - "//third_party/json/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${audio_transport_path}/audiochannel/audiodatachannel/include", - ] - - deps = [ - "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", - "${services_path}/common:distributed_audio_utils", - ] - - external_deps = [ - "c_utils:utils", - "ipc:ipc_core", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnStreamReceivedFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnStreamReceivedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init +++ /dev/null @@ -1,16 +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. - */ - -FUZZ \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp deleted file mode 100644 index 3dcfab24..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp +++ /dev/null @@ -1,50 +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 "softbusonstreamreceived_fuzzer.h" - -#include -#include - -#include "audio_data_channel.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnStreamReceivedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - std::string peerDevId(reinterpret_cast(data), size); - int32_t sessionId = *(reinterpret_cast(data)); - StreamData *stream = nullptr; - StreamData *ext = nullptr; - StreamFrameInfo *info = nullptr; - std::shared_ptr dataChannel = std::make_shared(peerDevId); - dataChannel->OnStreamReceived(sessionId, stream, ext, info); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SoftbusOnStreamReceivedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h deleted file mode 100644 index 245aaab3..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h +++ /dev/null @@ -1,21 +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 SOFTBUSONBYTESRECEIVED_FUZZER_H -#define SOFTBUSONBYTESRECEIVED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonbytesreceived_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/unittest/BUILD.gn b/services/softbusadapter/test/unittest/BUILD.gn deleted file mode 100644 index aaf8946f..00000000 --- a/services/softbusadapter/test/unittest/BUILD.gn +++ /dev/null @@ -1,56 +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. - -import("//build/test.gni") -import("../../../../distributedaudio.gni") - -module_out_path = "distributed_audio/services/softbusadapter" - -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "//third_party/cJSON", - "//third_party/json/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${services_path}/common/audioparam", - "${services_path}/common/audiodata/include", - "${softbusadapter_path}/include", - ] -} - -## UnitTest audio_soft_bus_adapter_test -ohos_unittest("SoftBusAdapterTest") { - module_out_path = module_out_path - - sources = [ "src/softbus_adapter_test.cpp" ] - - configs = [ ":module_private_config" ] - - deps = [ - "${softbusadapter_path}:distributed_audio_softbus_adapter", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] -} - -group("audio_soft_bus_adapter_test") { - testonly = true - deps = [ ":SoftBusAdapterTest" ] -} diff --git a/services/softbusadapter/test/unittest/include/softbus_adapter_test.h b/services/softbusadapter/test/unittest/include/softbus_adapter_test.h deleted file mode 100644 index 6c5260b7..00000000 --- a/services/softbusadapter/test/unittest/include/softbus_adapter_test.h +++ /dev/null @@ -1,42 +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_SOFTBUS_ADAPTER_TEST_H -#define OHOS_SOFTBUS_ADAPTER_TEST_H - -#include - -#include "daudio_constants.h" -#include "daudio_errorcode.h" -#include "softbus_adapter_test_utils.h" - -#define private public -#include "softbus_adapter.h" -#undef private - -namespace OHOS { -namespace DistributedHardware { -class SoftbusAdapterTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - SoftbusAdapter softbusAdapter; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_SOFTBUS_ADAPTER_TEST_H diff --git a/services/softbusadapter/test/unittest/include/softbus_adapter_test_utils.h b/services/softbusadapter/test/unittest/include/softbus_adapter_test_utils.h deleted file mode 100644 index 802a5d66..00000000 --- a/services/softbusadapter/test/unittest/include/softbus_adapter_test_utils.h +++ /dev/null @@ -1,36 +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_SOFTBUS_ADAPTER_TEST_UTILS_H -#define OHOS_SOFTBUS_ADAPTER_TEST_UTILS_H - -#include "isoftbus_listener.h" - -namespace OHOS { -namespace DistributedHardware { -class MockISoftbusListener : public ISoftbusListener { -public: - MockISoftbusListener() {} - ~MockISoftbusListener() {} - - void OnSessionOpened(int32_t sessionId, int32_t result) {} - void OnSessionClosed(int32_t sessionId) {} - void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) {} - void OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *streamFrameInfo) {} -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_SOFTBUS_ADAPTER_TEST_UTILS_H diff --git a/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp b/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp deleted file mode 100644 index cff9bd70..00000000 --- a/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp +++ /dev/null @@ -1,154 +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 "softbus_adapter_test.h" - -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -void SoftbusAdapterTest::SetUpTestCase(void) {} - -void SoftbusAdapterTest::TearDownTestCase(void) {} - -void SoftbusAdapterTest::SetUp(void) {} - -void SoftbusAdapterTest::TearDown(void) {} - -/** - * @tc.name: RegisterSoftbusListener_001 - * @tc.desc: Verify the RegisterSoftbusListener and UnRegisterSoftbusListener function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(SoftbusAdapterTest, RegisterSoftbusListener_001, TestSize.Level1) -{ - std::string sessionName = CTRL_SESSION_NAME; - std::string peerDevId = "peerDevId"; - std::shared_ptr listener = std::make_shared(); - - EXPECT_EQ(DH_SUCCESS, softbusAdapter.RegisterSoftbusListener(listener, sessionName, peerDevId)); - EXPECT_EQ(DH_SUCCESS, softbusAdapter.UnRegisterSoftbusListener(sessionName, peerDevId)); -} - -/** - * @tc.name: CreateSoftbusSessionServer_001 - * @tc.desc: Verify the CreateSoftbusSessionServer and RemoveSoftbusSessionServer function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(SoftbusAdapterTest, CreateSoftbusSessionServer_001, TestSize.Level1) -{ - std::string pkgname; - std::string sessionName = CTRL_SESSION_NAME; - std::string peerDevId = "peerDevId"; - - EXPECT_NE(DH_SUCCESS, softbusAdapter.CreateSoftbusSessionServer(pkgname, sessionName, peerDevId)); - EXPECT_EQ(DH_SUCCESS, softbusAdapter.RemoveSoftbusSessionServer(pkgname, sessionName, peerDevId)); -} - -/** - * @tc.name: OpenSoftbusSession_001 - * @tc.desc: Verify the OpenSoftbusSession and CloseSoftbusSession function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(SoftbusAdapterTest, OpenSoftbusSession_001, TestSize.Level1) -{ - std::string localSessionName; - std::string peerSessionName; - std::string peerDevId; - int32_t actual = softbusAdapter.OpenSoftbusSession(localSessionName, peerSessionName, peerDevId); - - EXPECT_EQ(ERR_DH_AUDIO_FAILED, actual); - EXPECT_EQ(DH_SUCCESS, softbusAdapter.CloseSoftbusSession(actual)); -} - -/** - * @tc.name: OpenSoftbusSession_002 - * @tc.desc: Verify the OpenSoftbusSession and CloseSoftbusSession function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(SoftbusAdapterTest, OpenSoftbusSession_002, TestSize.Level1) -{ - std::string localSessionName = CTRL_SESSION_NAME; - std::string peerSessionName = CTRL_SESSION_NAME; - std::string peerDevId = "peerDevId"; - int actual = softbusAdapter.OpenSoftbusSession(localSessionName, peerSessionName, peerDevId); - - EXPECT_NE(DH_SUCCESS, actual); - EXPECT_EQ(DH_SUCCESS, softbusAdapter.CloseSoftbusSession(actual)); -} - -/** - * @tc.name: SendSoftbusBytes_001 - * @tc.desc: Verify the SendSoftbusBytes function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(SoftbusAdapterTest, SendSoftbusBytes_001, TestSize.Level1) -{ - int32_t sessionId = -1; - uint8_t *data = nullptr; - int32_t dataLen = 0; - - EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, softbusAdapter.SendSoftbusBytes(sessionId, data, dataLen)); -} - -/** - * @tc.name: SendSoftbusStream_001 - * @tc.desc: Verify the SendSoftbusStream function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(SoftbusAdapterTest, SendSoftbusStream_001, TestSize.Level1) -{ - int32_t sessionId = 0; - std::shared_ptr audioData = std::make_shared(DEFAULT_AUDIO_DATA_SIZE); - - EXPECT_EQ(DH_SUCCESS, softbusAdapter.SendSoftbusStream(sessionId, audioData)); -} - -/** - * @tc.name: OnSoftbusSessionOpened_001 - * @tc.desc: Verify the OnSoftbusSessionOpened function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(SoftbusAdapterTest, OnSoftbusSessionOpened_001, TestSize.Level1) -{ - int32_t sessionId = 1; - int32_t result = -1; - - EXPECT_EQ(ERR_DH_AUDIO_FAILED, softbusAdapter.OnSoftbusSessionOpened(sessionId, result)); -} - -/** - * @tc.name: OnSoftbusSessionOpened_001 - * @tc.desc: Verify the OnSoftbusSessionClosed function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(SoftbusAdapterTest, OnSoftbusSessionOpened_002, TestSize.Level1) -{ - int32_t sessionId = 1; - int32_t result = 0; - - EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, softbusAdapter.OnSoftbusSessionOpened(sessionId, result)); - softbusAdapter.OnSoftbusSessionClosed(sessionId); -} -} // namespace DistributedHardware -} // namespace OHOS -- Gitee