diff --git a/common/dfx_utils/include/daudio_hidumper.h b/common/dfx_utils/include/daudio_hidumper.h index 49236b9dbc875d14749b2e58cede3f4ecf4544af..b10c8df4499f13d35d68b2b6a00ee273a48b1dfe 100644 --- a/common/dfx_utils/include/daudio_hidumper.h +++ b/common/dfx_utils/include/daudio_hidumper.h @@ -35,12 +35,14 @@ enum class HidumpFlag { GET_SOURCE_DEVID, GET_SINK_INFO, GET_ABILITY, + DUMP_AUDIO_DATA, }; class DaudioHidumper { DECLARE_SINGLE_INSTANCE_BASE(DaudioHidumper); public: bool Dump(const std::vector &args, std::string &result); + bool GetFlagStatus(); DaudioHidumper(); ~DaudioHidumper(); @@ -52,11 +54,13 @@ private: int32_t GetSourceDevId(std::string &result); int32_t GetSinkInfo(std::string &result); int32_t GetAbilityInfo(std::string &result); + int32_t DumpAudioData(std::string &result); private: std::string g_sourceDevId_ = ""; AudioManager *g_manager = nullptr; AudioAdapterDescriptor *g_devices = nullptr; + bool HidumperFlag_ = false; int32_t g_deviceNum = 0; std::string spkDefault = "1"; std::string micDefault = "134217729"; diff --git a/common/dfx_utils/src/daudio_hidumper.cpp b/common/dfx_utils/src/daudio_hidumper.cpp index 424ff9d27fe14912b8ec7e3cd2f3711f79783bf2..07be7f802d203d13ab607f9de536e4270f4a373f 100644 --- a/common/dfx_utils/src/daudio_hidumper.cpp +++ b/common/dfx_utils/src/daudio_hidumper.cpp @@ -31,12 +31,14 @@ const std::string ARGS_HELP = "-h"; const std::string ARGS_SOURCE_DEVID = "--sourceDevId"; const std::string ARGS_SINK_INFO = "--sinkInfo"; const std::string ARGS_ABILITY = "--ability"; +const std::string ARGS_DUMP_AUDIO_DATA = "--dumpAudioData"; const std::map ARGS_MAP = { { ARGS_HELP, HidumpFlag::GET_HELP }, { ARGS_SOURCE_DEVID, HidumpFlag::GET_SOURCE_DEVID }, { ARGS_SINK_INFO, HidumpFlag::GET_SINK_INFO }, { ARGS_ABILITY, HidumpFlag::GET_ABILITY }, + { ARGS_DUMP_AUDIO_DATA, HidumpFlag::DUMP_AUDIO_DATA }, }; } @@ -94,6 +96,9 @@ int32_t DaudioHidumper::ProcessDump(const std::string &args, std::string &result case HidumpFlag::GET_ABILITY: { return GetAbilityInfo(result); } + case HidumpFlag::DUMP_AUDIO_DATA: { + return DumpAudioData(result); + } default: { return ShowIllegalInfomation(result); } @@ -151,6 +156,19 @@ int32_t DaudioHidumper::GetAbilityInfo(std::string &result) return DH_SUCCESS; } +int32_t DaudioHidumper::DumpAudioData(std::string &result) +{ + DHLOGI("Dump audio data."); + result.append("dump..."); + HidumperFlag_ = true; + return DH_SUCCESS; +} + +bool DaudioHidumper::GetFlagStatus() +{ + return HidumperFlag_; +} + void DaudioHidumper::ShowHelp(std::string &result) { DHLOGI("Show help."); @@ -163,7 +181,9 @@ void DaudioHidumper::ShowHelp(std::string &result) .append("--sinkInfo ") .append(": dump sink info in the system\n") .append("--ability ") - .append(": dump current ability of the audio in the system\n"); + .append(": dump current ability of the audio in the system\n") + .append("--dumpAudioData") + .append(": dump audio data in the system\n"); } int32_t DaudioHidumper::ShowIllegalInfomation(std::string &result) diff --git a/common/include/daudio_constants.h b/common/include/daudio_constants.h index 4c06b3d55f9606936d0595db484aa711dc6bf45d..0eee4b2f75c898538ca23ea6df0fb368138697d3 100644 --- a/common/include/daudio_constants.h +++ b/common/include/daudio_constants.h @@ -68,6 +68,7 @@ constexpr uint32_t DAUDIO_MAX_JSON_LEN = 1024; static constexpr int64_t AUDIO_OFFSET_FRAME_NUM = 10; static constexpr int64_t LOW_LATENCY_INTERVAL_NS = 5000000; static constexpr int64_t LOW_LATENCY_CLIENT_INTERVAL_NS = 20000000; +static constexpr int64_t MAX_TIME_INTERVAL_US = 23000; const std::string DAUDIO_LOG_TITLE_TAG = "DAUDIO"; const std::string DAUDIO_PREFIX = "DISTRIBUTED_AUDIO"; diff --git a/common/include/daudio_util.h b/common/include/daudio_util.h index aa0b05d5ced007892b6fe13fe10341006d98582f..33d4392286dcf7daebc8b92f772b304ba45c229c 100644 --- a/common/include/daudio_util.h +++ b/common/include/daudio_util.h @@ -17,6 +17,7 @@ #define OHOS_DAUDIO_UTIL_H #include +#include #include #include "nlohmann/json.hpp" @@ -47,6 +48,8 @@ int64_t UpdateTimeOffset(const int64_t frameIndex, const int64_t framePeriodNs, void GetCurrentTime(int64_t &tvSec, int64_t &tvNSec); bool CheckIsNum(const std::string &jsonString); bool CheckDevIdIsLegal(const std::string &devId); +bool IsOutDurationRange(int64_t startTime, int64_t endTime, int64_t lastStartTime); +void SaveFile(std::string fileName, uint8_t *audioData, int32_t size); template bool GetSysPara(const char *key, T &value); diff --git a/common/src/daudio_util.cpp b/common/src/daudio_util.cpp index 8536912d1838a679a7fe9900f0c562ed9a5d7c7b..e1a1fc1f7912ec017a893b77bf9d284f5707ebe2 100644 --- a/common/src/daudio_util.cpp +++ b/common/src/daudio_util.cpp @@ -322,6 +322,13 @@ bool CheckDevIdIsLegal(const std::string &devId) return true; } +bool IsOutDurationRange(int64_t startTime, int64_t endTime, int64_t lastStartTime) +{ + int64_t currentInterval = endTime - startTime; + int64_t twiceInterval = startTime - lastStartTime; + return (currentInterval > MAX_TIME_INTERVAL_US || twiceInterval > MAX_TIME_INTERVAL_US) ? true : false; +} + template bool GetSysPara(const char *key, T &value) { @@ -358,5 +365,16 @@ bool IsParamEnabled(const std::string &key, bool &isEnabled) isEnabled = false; return false; } + +void SaveFile(std::string fileName, uint8_t *audioData, int32_t size) +{ + std::ofstream ofs(fileName, std::ios::binary | std::ios::out | std::ios::app); + if (!ofs.is_open()) { + DHLOGE("open file failed"); + return; + } + ofs.write(reinterpret_cast(audioData), size); + ofs.close(); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/common/test/unittest/src/daudio_utils_test.cpp b/common/test/unittest/src/daudio_utils_test.cpp index 49b070b59ab90c869aaf8f83ac0ac24b6b1eede1..881318415547323032d607ab9a8270f5dae898db 100644 --- a/common/test/unittest/src/daudio_utils_test.cpp +++ b/common/test/unittest/src/daudio_utils_test.cpp @@ -129,30 +129,22 @@ HWTEST_F(DAudioUtilsTest, DAudioLatencyTest_003, TestSize.Level1) /** * @tc.name: DAudioLogTest_001 - * @tc.desc: Verify the DHLOG definition and DHLog function. + * @tc.desc: Verify the GetCurrentTime function and DHLOG definition and DHLog function. * @tc.type: FUNC * @tc.require: AR000H0E5U */ -HWTEST_F(DAudioUtilsTest, DAudioLogTest_001, TestSize.Level1) +HWTEST_F(DAudioUtilsTest, DAudioUtilTest_001, TestSize.Level1) { DHLOGD("DAudio TDD test DHLOGD print."); DHLOGI("DAudio TDD test DHLOGI print."); DHLOGW("DAudio TDD test DHLOGW print."); DHLOGE("DAudio TDD test DHLOGE print."); DHLog(DHLogLevel::DH_LOG_ERROR, ""); -} - -/** - * @tc.name: DAudioLogTest_001 - * @tc.desc: Verify the GetCurrentTime function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DAudioUtilsTest, DAudioUtilTest_001, TestSize.Level1) -{ int64_t tvSec; int64_t tvNSec; GetCurrentTime(tvSec, tvNSec); + EXPECT_GE(tvSec, 0); + EXPECT_GE(tvNSec, 0); } /** diff --git a/distributedaudio.gni b/distributedaudio.gni index 9ce5fe6aa41415232518b3eabe86bd709aaedd11..0b98805811c851b5d58cee508f53e5c048a070ec 100644 --- a/distributedaudio.gni +++ b/distributedaudio.gni @@ -43,6 +43,8 @@ fwk_common_path = "${distributedhardwarefwk_path}/common" fwk_services_path = "${distributedhardwarefwk_path}/services" innerkits_path = "${distributedaudio_path}/interfaces/inner_kits" +distributedaudio_fuzz_path = "distributed_audio/distributed_audio" + build_flags = [ "-Werror" ] declare_args() { diff --git a/hdf_interfaces/distributed_audio/audio/v1_0/AudioTypes.idl b/hdf_interfaces/distributed_audio/audio/v1_0/AudioTypes.idl index 38cb481b6baae59cb90084a6a053d28251cea6ce..830a0c5dda0ba844990382811b01d7b5e49cc1f9 100644 --- a/hdf_interfaces/distributed_audio/audio/v1_0/AudioTypes.idl +++ b/hdf_interfaces/distributed_audio/audio/v1_0/AudioTypes.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -13,13 +13,35 @@ * limitations under the License. */ +/** + * @addtogroup HdiAudio + * @{ + * + * @brief Provides unified APIs for audio services to access audio drivers. + * + * An audio service can obtain an audio driver object or agent and then call APIs provided by this object or agent to + * access different types of audio devices based on the audio IDs, thereby obtaining audio information, + * subscribing to or unsubscribing from audio data, enabling or disabling an audio, + * setting the audio data reporting mode, and setting audio options such as the accuracy and measurement range. + * + * @since 4.0 + * @version 1.0 + */ + package ohos.hdi.distributed_audio.audio.v1_0; +/** + * @brief Enumerates the audio port type. + */ enum AudioPortDirection { PORT_OUT = 1, /**< Output port */ PORT_IN = 2, /**< Input port */ PORT_OUT_IN = 3, /**< Input/output port, supporting both audio input and output */ }; + +/** + * @brief Enumerates the pin of an audio adapter. + */ enum AudioPortPin { PIN_NONE = 0, /**< Invalid pin */ PIN_OUT_SPEAKER = 1 << 0, /**< Speaker output pin */ @@ -30,21 +52,32 @@ enum AudioPortPin { PIN_OUT_USB_EXT = 1 << 5, /**< Extended USB output pin*/ PIN_OUT_EARPIECE = 1 << 5 | 1 << 4, /**< Earpiece output pin */ PIN_OUT_BLUETOOTH_SCO = 1 << 6, /**< Bluetooth SCO output pin */ - PIN_OUT_DAUDIO_DEFAULT = 1 << 7, + PIN_OUT_DAUDIO_DEFAULT = 1 << 7, /**< Daudio default output pin */ + PIN_OUT_HEADPHONE = 1 << 8, /**< Wired headphone output pin*/ + PIN_OUT_USB_HEADSET = 1 << 9, /**< ARM USB out pin */ PIN_IN_MIC = 1 << 27 | 1 << 0, /**< Microphone input pin */ PIN_IN_HS_MIC = 1 << 27 | 1 << 1, /**< Wired headset microphone pin for input */ PIN_IN_LINEIN = 1 << 27 | 1 << 2, /**< Line-in pin */ PIN_IN_USB_EXT = 1 << 27 | 1 << 3, /**< Extended USB input pin*/ PIN_IN_BLUETOOTH_SCO_HEADSET = 1 << 27 | 1 << 4, /**< Bluetooth SCO headset input pin */ - PIN_IN_DAUDIO_DEFAULT = 1 << 27 | 1 << 5, + PIN_IN_DAUDIO_DEFAULT = 1 << 27 | 1 << 5, /**< Daudio default input pin */ + PIN_IN_USB_HEADSET = 1 << 27 | 1 << 6, /**< ARM USB input pin */ }; + +/** + * @brief Enumerates the audio category. + */ enum AudioCategory { - AUDIO_IN_MEDIA = 0, - AUDIO_IN_COMMUNICATION = 1, - AUDIO_IN_RINGTONE = 2, - AUDIO_IN_CALL = 3, - AUDIO_MMAP_NOIRQ = 4, + AUDIO_IN_MEDIA = 0, /**< Media */ + AUDIO_IN_COMMUNICATION = 1, /**< Communications */ + AUDIO_IN_RINGTONE = 2, /**< Ringtone */ + AUDIO_IN_CALL = 3, /**< Call */ + AUDIO_MMAP_NOIRQ = 4, /**< Mmap mode */ }; + +/** + * @brief Enumerates the audio format. + */ enum AudioFormat { AUDIO_FORMAT_TYPE_PCM_8_BIT = 1 << 0, /**< 8-bit PCM */ AUDIO_FORMAT_TYPE_PCM_16_BIT = 1 << 1, /**< 16-bit PCM */ @@ -60,12 +93,22 @@ enum AudioFormat { AUDIO_FORMAT_TYPE_G711U = 1 << 25 | 1 << 1, /**< G711u */ AUDIO_FORMAT_TYPE_G726 = 1 << 25 | 1 << 1 | 1 << 0, /**< G726 */ }; + +/** + * @brief Enumerates the audio channel mask. + * + * A mask describes an audio channel position. + */ enum AudioChannelMask { AUDIO_CHANNEL_FRONT_LEFT = 1, /**< Front left channel */ AUDIO_CHANNEL_FRONT_RIGHT = 2, /**< Front right channel */ AUDIO_CHANNEL_MONO = 1, /**< Mono channel */ AUDIO_CHANNEL_STEREO = 3, /**< Stereo channel, consisting of front left and front right channels */ }; + +/** + * @brief Enumerates masks of audio sampling rates. + */ enum AudioSampleRatesMask { AUDIO_SAMPLE_RATE_MASK_8000 = 1 << 0, /**< 8 kHz */ AUDIO_SAMPLE_RATE_MASK_12000 = 1 << 1, /**< 12 kHz */ @@ -80,206 +123,362 @@ enum AudioSampleRatesMask { AUDIO_SAMPLE_RATE_MASK_96000 = 1 << 10, /**< 96 kHz */ AUDIO_SAMPLE_RATE_MASK_INVALID = 4294967295, /**< Invalid sampling rate */ }; + +/** + * @brief Enumerates the passthrough data transmission mode of an audio port. + */ enum AudioPortPassthroughMode { - PORT_PASSTHROUGH_LPCM = 1, - PORT_PASSTHROUGH_RAW = 2, - PORT_PASSTHROUGH_HBR2LBR = 4, - PORT_PASSTHROUGH_AUTO = 8, + PORT_PASSTHROUGH_LPCM = 1 << 0, /**< Stereo PCM */ + PORT_PASSTHROUGH_RAW = 1 << 1, /**< HDMI passthrough */ + PORT_PASSTHROUGH_HBR2LBR = 1 << 2, /**< Blu-ray next-generation audio output with reduced specifications */ + PORT_PASSTHROUGH_AUTO = 1 << 3, /**< Mode automatically matched based on the HDMI EDID */ }; + +/** + * @brief Defines formats of raw audio samples. + */ enum AudioSampleFormat { - AUDIO_SAMPLE_FORMAT_S8 = 0, - AUDIO_SAMPLE_FORMAT_S8P = 1, - AUDIO_SAMPLE_FORMAT_U8 = 2, - AUDIO_SAMPLE_FORMAT_U8P = 3, - AUDIO_SAMPLE_FORMAT_S16 = 4, - AUDIO_SAMPLE_FORMAT_S16P = 5, - AUDIO_SAMPLE_FORMAT_U16 = 6, - AUDIO_SAMPLE_FORMAT_U16P = 7, - AUDIO_SAMPLE_FORMAT_S24 = 8, - AUDIO_SAMPLE_FORMAT_S24P = 9, - AUDIO_SAMPLE_FORMAT_U24 = 10, - AUDIO_SAMPLE_FORMAT_U24P = 11, - AUDIO_SAMPLE_FORMAT_S32 = 12, - AUDIO_SAMPLE_FORMAT_S32P = 13, - AUDIO_SAMPLE_FORMAT_U32 = 14, - AUDIO_SAMPLE_FORMAT_U32P = 15, - AUDIO_SAMPLE_FORMAT_S64 = 16, - AUDIO_SAMPLE_FORMAT_S64P = 17, - AUDIO_SAMPLE_FORMAT_U64 = 18, - AUDIO_SAMPLE_FORMAT_U64P = 19, - AUDIO_SAMPLE_FORMAT_F32 = 20, - AUDIO_SAMPLE_FORMAT_F32P = 21, - AUDIO_SAMPLE_FORMAT_F64 = 22, - AUDIO_SAMPLE_FORMAT_F64P = 23, + /* 8 bits */ + AUDIO_SAMPLE_FORMAT_S8 = 0, /**< signed 8 bit sample */ + AUDIO_SAMPLE_FORMAT_S8P = 1, /**< signed 8 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U8 = 2, /**< unsigned 8 bit sample */ + AUDIO_SAMPLE_FORMAT_U8P = 3, /**< unsigned 8 bit planar sample */ + /* 16 bits */ + AUDIO_SAMPLE_FORMAT_S16 = 4, /**< signed 16 bit sample */ + AUDIO_SAMPLE_FORMAT_S16P = 5, /**< signed 16 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U16 = 6, /**< unsigned 16 bit sample */ + AUDIO_SAMPLE_FORMAT_U16P = 7, /**< unsigned 16 bit planar sample */ + /* 24 bits */ + AUDIO_SAMPLE_FORMAT_S24 = 8, /**< signed 24 bit sample */ + AUDIO_SAMPLE_FORMAT_S24P = 9, /**< signed 24 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U24 = 10, /**< unsigned 24 bit sample */ + AUDIO_SAMPLE_FORMAT_U24P = 11, /**< unsigned 24 bit planar sample */ + /* 32 bits */ + AUDIO_SAMPLE_FORMAT_S32 = 12, /**< signed 32 bit sample */ + AUDIO_SAMPLE_FORMAT_S32P = 13, /**< signed 32 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U32 = 14, /**< unsigned 32 bit sample */ + AUDIO_SAMPLE_FORMAT_U32P = 15, /**< unsigned 32 bit planar sample */ + /* 64 bits */ + AUDIO_SAMPLE_FORMAT_S64 = 16, /**< signed 64 bit sample */ + AUDIO_SAMPLE_FORMAT_S64P = 17, /**< signed 64 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U64 = 18, /**< unsigned 64 bit sample */ + AUDIO_SAMPLE_FORMAT_U64P = 19, /**< unsigned 64 bit planar sample */ + /* float double */ + AUDIO_SAMPLE_FORMAT_F32 = 20, /**< float 32 bit sample */ + AUDIO_SAMPLE_FORMAT_F32P = 21, /**< float 32 bit planar sample */ + AUDIO_SAMPLE_FORMAT_F64 = 22, /**< double 64 bit sample */ + AUDIO_SAMPLE_FORMAT_F64P = 23, /**< double 64 bit planar sample */ }; + +/** + * @brief Enumerates channel modes for audio rendering. + * + * @attention The following modes are set for rendering dual-channel audios. Others are not supported. + */ enum AudioChannelMode { - AUDIO_CHANNEL_NORMAL = 0, - AUDIO_CHANNEL_BOTH_LEFT = 1, - AUDIO_CHANNEL_BOTH_RIGHT = 2, - AUDIO_CHANNEL_EXCHANGE = 3, - AUDIO_CHANNEL_MIX = 4, - AUDIO_CHANNEL_LEFT_MUTE = 5, - AUDIO_CHANNEL_RIGHT_MUTE = 6, - AUDIO_CHANNEL_BOTH_MUTE = 7, + AUDIO_CHANNEL_NORMAL = 0, /**< Normal mode. No processing is required. */ + AUDIO_CHANNEL_BOTH_LEFT = 1, /**< Two left channels */ + AUDIO_CHANNEL_BOTH_RIGHT = 2, /**< Two right channels */ + AUDIO_CHANNEL_EXCHANGE = 3, /**< Data exchange between the left and right channels. The left channel takes the audio + * stream of the right channel, and the right channel takes that of the left channel. + */ + AUDIO_CHANNEL_MIX = 4, /**< Mix of streams of the left and right channels */ + AUDIO_CHANNEL_LEFT_MUTE = 5, /**< Left channel muted. The stream of the right channel is output. */ + AUDIO_CHANNEL_RIGHT_MUTE = 6, /**< Right channel muted. The stream of the left channel is output. */ + AUDIO_CHANNEL_BOTH_MUTE = 7, /**< Both left and right channels are muted */ }; + +/** + * @brief Enumerates the execution types of the DrainBuffer function. + */ enum AudioDrainNotifyType { - AUDIO_DRAIN_NORMAL_MODE = 0, - AUDIO_DRAIN_EARLY_MODE = 1, + AUDIO_DRAIN_NORMAL_MODE = 0, /**< The DrainBuffer function returns after all data finishes playback. */ + AUDIO_DRAIN_EARLY_MODE = 1, /**< The DrainBuffer function returns before all the data of the current track + * finishes playback to reserve time for a smooth track switch by the audio service. + */ + }; + +/** + * @brief Enumerates callback notification events. + */ enum AudioCallbackType { - AUDIO_NONBLOCK_WRITE_COMPELETED = 0, - AUDIO_DRAIN_COMPELETED = 1, - AUDIO_FLUSH_COMPLETED = 2, - AUDIO_RENDER_FULL = 3, - AUDIO_ERROR_OCCUR = 4, + AUDIO_NONBLOCK_WRITE_COMPLETED = 0, /**< The non-block write is complete. */ + AUDIO_DRAIN_COMPLETED = 1, /**< The draining is complete. */ + AUDIO_FLUSH_COMPLETED = 2, /**< The flush is complete. */ + AUDIO_RENDER_FULL = 3, /**< The render buffer is full.*/ + AUDIO_ERROR_OCCUR = 4, /**< An error occurs.*/ }; + +/** + * @brief Describes AudioPortRole. + */ enum AudioPortRole { - AUDIO_PORT_UNASSIGNED_ROLE = 0, - AUDIO_PORT_SOURCE_ROLE = 1, - AUDIO_PORT_SINK_ROLE = 2, + AUDIO_PORT_UNASSIGNED_ROLE = 0, /**< Unassigned port role */ + AUDIO_PORT_SOURCE_ROLE = 1, /**< Assigned source role */ + AUDIO_PORT_SINK_ROLE = 2, /**< Assigned sink role */ }; + +/** + * @brief Describes AudioPortType. + */ enum AudioPortType { - AUDIO_PORT_UNASSIGNED_TYPE = 0, - AUDIO_PORT_DEVICE_TYPE = 1, - AUDIO_PORT_MIX_TYPE = 2, - AUDIO_PORT_SESSION_TYPE = 3, + AUDIO_PORT_UNASSIGNED_TYPE = 0, /**< Unassigned port type */ + AUDIO_PORT_DEVICE_TYPE = 1, /**< Assigned device type */ + AUDIO_PORT_MIX_TYPE = 2, /**< Assigned mix type */ + AUDIO_PORT_SESSION_TYPE = 3, /**< Assigned session type */ }; + +/** + * @brief Describes AudioSessionType. + */ enum AudioSessionType { - AUDIO_OUTPUT_STAGE_SESSION = 0, - AUDIO_OUTPUT_MIX_SESSION = 1, - AUDIO_ALLOCATE_SESSION = 2, - AUDIO_INVALID_SESSION = 3, + AUDIO_OUTPUT_STAGE_SESSION = 0, /**< Assigned output stage session */ + AUDIO_OUTPUT_MIX_SESSION = 1, /**< Assigned output mix session */ + AUDIO_ALLOCATE_SESSION = 2, /**< Assigned allocate session */ + AUDIO_INVALID_SESSION = 3, /**< Assigned invalid session */ }; + +/** + * @brief Describes AudioDeviceType. + */ enum AudioDeviceType { - AUDIO_LINEOUT = 1 << 0, - AUDIO_HEADPHONE = 1 << 1, - AUDIO_HEADSET = 1 << 2, - AUDIO_USB_HEADSET = 1 << 3, - AUDIO_USB_HEADPHONE = 1 << 4, - AUDIO_USBA_HEADSET = 1 << 5, - AUDIO_USBA_HEADPHONE = 1 << 6, - AUDIO_PRIMARY_DEVICE = 1 << 7, - AUDIO_USB_DEVICE = 1 << 8, - AUDIO_A2DP_DEVICE = 1 << 9, - AUDIO_DEVICE_UNKNOWN, + AUDIO_LINEOUT = 1 << 0, /**< Assigned lineout device type */ + AUDIO_HEADPHONE = 1 << 1, /**< Assigned headphone device type */ + AUDIO_HEADSET = 1 << 2, /**< Assigned headset device type */ + AUDIO_USB_HEADSET = 1 << 3, /**< Assigned usb headset device type */ + AUDIO_USB_HEADPHONE = 1 << 4, /**< Assigned usb headphone device type */ + AUDIO_USBA_HEADSET = 1 << 5, /**< Assigned usba headset device type */ + AUDIO_USBA_HEADPHONE = 1 << 6, /**< Assigned usba headphone device type */ + AUDIO_PRIMARY_DEVICE = 1 << 7, /**< Assigned primary device type */ + AUDIO_USB_DEVICE = 1 << 8, /**< Assigned usb device type */ + AUDIO_A2DP_DEVICE = 1 << 9, /**< Assigned a2dp device type */ + AUDIO_HDMI_DEVICE = 1 << 10, /**< Assigned hdmi device type */ + AUDIO_ADAPTER_DEVICE = 1 << 11, /**< Assigned adapter device type */ + AUDIO_DEVICE_UNKNOWN, /**< Assigned unknown device type */ }; + +/** + * @brief Describes AudioEventType. + */ enum AudioEventType { - AUDIO_DEVICE_ADD = 1, - AUDIO_DEVICE_REMOVE = 2, - AUDIO_LOAD_SUCCESS = 3, - AUDIO_LOAD_FAILURE = 4, - AUDIO_UNLOAD = 5, - AUDIO_SERVICE_VALID = 7, - AUDIO_SERVICE_INVALID = 8, - AUDIO_CAPTURE_THRESHOLD = 9, - AUDIO_EVENT_UNKNOWN = 10, + AUDIO_DEVICE_ADD = 1, /**< Assigned add device event type */ + AUDIO_DEVICE_REMOVE = 2, /**< Assigned remove device event type */ + AUDIO_LOAD_SUCCESS = 3, /**< Assigned load sucess event type */ + AUDIO_LOAD_FAILURE = 4, /**< Assigned load failure event type */ + AUDIO_UNLOAD = 5, /**< Assigned unload event type */ + AUDIO_SERVICE_VALID = 7, /**< Assigned valid service event type */ + AUDIO_SERVICE_INVALID = 8, /**< Assigned invalid service event type */ + AUDIO_CAPTURE_THRESHOLD = 9, /**< Assigned threshold capture event type */ + AUDIO_EVENT_UNKNOWN = 10, /**< Assigned unknown event type */ }; + +/** + * @brief Enumerates the restricted key type of the parameters + */ enum AudioExtParamKey { - AUDIO_EXT_PARAM_KEY_NONE = 0, /**< Distributed audio extra param key none */ - AUDIO_EXT_PARAM_KEY_VOLUME = 1, /**< Distributed audio extra param key volume event */ - AUDIO_EXT_PARAM_KEY_FOCUS = 2, /**< Distributed audio extra param key focus event */ - AUDIO_EXT_PARAM_KEY_BUTTON = 3, /**< Distributed audio extra param key media button event */ - AUDIO_EXT_PARAM_KEY_EFFECT = 4, /**< Distributed audio extra param key audio effect event */ - AUDIO_EXT_PARAM_KEY_STATUS = 5, /**< Distributed audio extra param key device status event */ + AUDIO_EXT_PARAM_KEY_NONE = 0, /**< Distributed audio extra param key none */ + AUDIO_EXT_PARAM_KEY_VOLUME = 1, /**< Distributed audio extra param key volume event */ + AUDIO_EXT_PARAM_KEY_FOCUS = 2, /**< Distributed audio extra param key focus event */ + AUDIO_EXT_PARAM_KEY_BUTTON = 3, /**< Distributed audio extra param key media button event */ + AUDIO_EXT_PARAM_KEY_EFFECT = 4, /**< Distributed audio extra param key audio effect event */ + AUDIO_EXT_PARAM_KEY_STATUS = 5, /**< Distributed audio extra param key device status event */ + AUDIO_EXT_PARAM_KEY_USB_DEVICE = 101, /**< Check USB device type ARM or HIFI */ AUDIO_EXT_PARAM_KEY_LOWPOWER = 1000, /**< Low power event type */ }; + +/** + * @brief Describes status of audio deivce.@link enum AudioDeviceType + */ struct AudioDeviceStatus { - unsigned int pnpStatus; + unsigned int pnpStatus; /**< Audio pnp status */ }; + +/** + * @brief Describes the audio scene. + */ union SceneDesc { - unsigned int id; + unsigned int id; /**< Audio scene ID */ }; + +/** + * @brief Defines the audio port. + */ struct AudioPort { - enum AudioPortDirection dir; - unsigned int portId; - String portName; + enum AudioPortDirection dir; /**< Audio port type. For details, see {@link AudioPortDirection} */ + unsigned int portId; /**< Audio port ID */ + String portName; /**< Audio port name */ }; + +/** + * @brief Defines the audio adapter descriptor. + * + * An audio adapter is a set of port drivers for a sound card, including the output and input ports. + * One port corresponds to multiple pins, and each pin belongs to a physical component (such as a + * speaker or a wired headset). + */ struct AudioAdapterDescriptor { - String adapterName; - struct AudioPort[] ports; + String adapterName; /**< Name of the audio adapter */ + struct AudioPort[] ports; /**< List of ports supported by an audio adapter */ }; + +/** + * @brief Defines the audio device descriptor. + */ struct AudioDeviceDescriptor { - unsigned int portId; - enum AudioPortPin pins; - String desc; + unsigned int portId; /**< Audio port ID */ + enum AudioPortPin pins; /**< Pins of audio ports (input and output). For details, see {@link AudioPortPin}. */ + String desc; /**< Audio device name */ }; + +/** + * @brief Defines the audio scene descriptor. + */ struct AudioSceneDescriptor { - union SceneDesc scene; - struct AudioDeviceDescriptor desc; + union SceneDesc scene; /**< Describes the audio scene */ + struct AudioDeviceDescriptor desc; /**< Audio device descriptor */ +}; + +/** + * @brief Defines audio input type. + */ +enum AudioInputType { + AUDIO_INPUT_DEFAULT_TYPE = 0, /**< Assigned default input type */ + AUDIO_INPUT_MIC_TYPE = 1 << 0, /**< Assigned mic input type */ + AUDIO_INPUT_SPEECH_WAKEUP_TYPE = 1 << 1, /**< Assigned speech wakeup input type */ + AUDIO_INPUT_VOICE_COMMUNICATION_TYPE = 1 << 2, /**< Assigned voice communication input type */ + AUDIO_INPUT_VOICE_RECOGNITION_TYPE = 1 << 3, /**< Assigned voice recognition input type */ }; + +/** + * @brief Defines audio sampling attributes. + */ struct AudioSampleAttributes { - enum AudioCategory type; - boolean interleaved; - enum AudioFormat format; - unsigned int sampleRate; - unsigned int channelCount; - unsigned int period; - unsigned int frameSize; - boolean isBigEndian; - boolean isSignedData; - unsigned int startThreshold; - unsigned int stopThreshold; - unsigned int silenceThreshold; - int streamId; + enum AudioCategory type; /**< Audio type. For details, see {@link AudioCategory} */ + boolean interleaved; /**< Interleaving flag of audio data */ + enum AudioFormat format; /**< Audio data format. For details, see {@link AudioFormat}. */ + unsigned int sampleRate; /**< Audio sampling rate */ + unsigned int channelCount; /**< Number of audio channels. For example, for the mono channel, the value is 1, + * and for the stereo channel, the value is 2. + */ + unsigned int period; /**< Audio sampling period */ + unsigned int frameSize; /**< Frame size of the audio data */ + boolean isBigEndian; /**< Big endian flag of audio data */ + boolean isSignedData; /**< Signed or unsigned flag of audio data */ + unsigned int startThreshold; /**< Audio render start threshold. */ + unsigned int stopThreshold; /**< Audio render stop threshold. */ + unsigned int silenceThreshold; /**< Audio capture buffer threshold. */ + int streamId; /**< Audio Identifier of render or capture */ + int sourceType; /**< Audio sourceType of render or capture */ }; + +/** + * @brief Defines the audio timestamp, which is a substitute for POSIX timespec. + */ struct AudioTimeStamp { - long tvSec; - long tvNSec; + long tvSec; /**< Seconds */ + long tvNSec; /**< Nanoseconds */ }; + +/** + * @brief Defines the sub-port capability. + */ struct AudioSubPortCapability { - unsigned int portId; - String desc; - enum AudioPortPassthroughMode mask; + unsigned int portId; /**< Sub-port ID */ + String desc; /**< Sub-port name */ + enum AudioPortPassthroughMode mask; /**< Passthrough mode of data transmission. For details, + * see {@link AudioPortPassthroughMode}. + */ }; + +/** + * @brief Defines the audio port capability. + */ struct AudioPortCapability { - unsigned int deviceType; - unsigned int deviceId; - boolean hardwareMode; - unsigned int formatNum; - enum AudioFormat[] formats; - unsigned int sampleRateMasks; - enum AudioChannelMask channelMasks; - unsigned int channelCount; - struct AudioSubPortCapability[] subPorts; - enum AudioSampleFormat[] supportSampleFormats; + unsigned int deviceType; /**< Device type (output or input) */ + unsigned int deviceId; /**< Device ID used for device binding */ + boolean hardwareMode; /**< Whether to support device binding */ + unsigned int formatNum; /**< Number of the supported audio formats */ + enum AudioFormat[] formats; /**< Supported audio formats. For details, see {@link AudioFormat}. */ + unsigned int sampleRateMasks; /**< Supported audio sampling rates (8 kHz, 16 kHz, 32 kHz, and 48 kHz) */ + enum AudioChannelMask channelMasks; /**< Audio channel layout mask of the device. For details, + * see {@link AudioChannelMask}. + */ + unsigned int channelCount; /**< Supported maximum number of audio channels */ + struct AudioSubPortCapability[] subPorts; /**< List of supported sub-ports */ + enum AudioSampleFormat[] supportSampleFormats; /**< Supported audio sample formats. For details, + * see {@link AudioSampleFormat}. + */ }; + +/** + * @brief Describes a mmap buffer. + */ struct AudioMmapBufferDescriptor { - byte[] memoryAddress; - FileDescriptor memoryFd; - int totalBufferFrames; - int transferFrameSize; - int isShareable; - unsigned int offset; - String filePath; + byte[] memoryAddress; /**< Pointer to the mmap buffer */ + FileDescriptor memoryFd; /**< File descriptor of the mmap buffer */ + int totalBufferFrames; /**< Total size of the mmap buffer (unit: frame )*/ + int transferFrameSize; /**< Transfer size (unit: frame) */ + int isShareable; /**< Whether the mmap buffer can be shared among processes */ + unsigned int offset; /**< off set */ + String filePath; /**< file path */ }; + +/** + * @brief Describes AudioDevExtInfo. + */ struct AudioDevExtInfo { - int moduleId; - enum AudioPortPin type; - String desc; + int moduleId; /**< Identifier of the module stream is attached to */ + enum AudioPortPin type; /**< Device type For details, see {@link AudioPortPin}. */ + String desc; /**< Address */ }; + +/** + * @brief Describes AudioMixInfo. + */ struct AudioMixExtInfo { - int moduleId; - int streamId; + int moduleId; /**< Identifier of the module stream is attached to */ + int streamId; /**< Identifier of the capture or render passed by caller */ }; + +/** + * @brief Describes AudioSessionExtInfo. + */ struct AudioSessionExtInfo { - enum AudioSessionType sessionType; + enum AudioSessionType sessionType; /**< Audio session type */ }; + +/** + * @brief Describes AudioInfo. + */ struct AudioInfo { - struct AudioDevExtInfo device; - struct AudioMixExtInfo mix; - struct AudioSessionExtInfo session; + struct AudioDevExtInfo device; /* Specific Device Ext info */ + struct AudioMixExtInfo mix; /* Specific mix info */ + struct AudioSessionExtInfo session; /* session specific info */ }; + +/** + * @brief Describes AudioRouteNode. + */ struct AudioRouteNode { - int portId; - enum AudioPortRole role; - enum AudioPortType type; - struct AudioInfo ext; + int portId; /**< Audio port ID */ + enum AudioPortRole role; /**< Audio port as a sink or a source */ + enum AudioPortType type; /**< device, mix ... */ + struct AudioInfo ext; /**< The ext object */ }; + +/** + * @brief Describes AudioRoute. + */ struct AudioRoute { - struct AudioRouteNode[] sources; - struct AudioRouteNode[] sinks; + struct AudioRouteNode[] sources; /**< List of sources */ + struct AudioRouteNode[] sinks; /**< List of sinks */ }; + +/** + * @brief Describes AudioEvent. + */ struct AudioEvent { - unsigned int eventType; /**< @link enum AudioEventType */ + unsigned int eventType; /**< @link enum AudioEventType */ unsigned int deviceType; /**< @link enum AudioDeviceType */ }; diff --git a/hdf_interfaces/distributed_audio/audio/v1_0/IAudioAdapter.idl b/hdf_interfaces/distributed_audio/audio/v1_0/IAudioAdapter.idl index 39f5ff59c1e0cc76a76aa1da8596006f282eb880..739a4fa32e269ef94d76efd73799ad1346ef26cb 100644 --- a/hdf_interfaces/distributed_audio/audio/v1_0/IAudioAdapter.idl +++ b/hdf_interfaces/distributed_audio/audio/v1_0/IAudioAdapter.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -20,12 +20,23 @@ import ohos.hdi.distributed_audio.audio.v1_0.IAudioCapture; import ohos.hdi.distributed_audio.audio.v1_0.IAudioRender; import ohos.hdi.distributed_audio.audio.v1_0.IAudioCallback; +/** + * @brief Provides audio adapter capabilities, including initializing ports, creating rendering and capturing tasks, + * and obtaining the port capability set. + * + * @see IAudioRender + * @see IAudioCapture + * @since 4.0 + * @version 1.0 + */ interface IAudioAdapter { InitAllPorts(); - CreateRender([in] struct AudioDeviceDescriptor desc, [in] struct AudioSampleAttributes attrs, [out] IAudioRender render); - DestroyRender([in] struct AudioDeviceDescriptor desc); - CreateCapture([in] struct AudioDeviceDescriptor desc, [in] struct AudioSampleAttributes attrs, [out] IAudioCapture capture); - DestroyCapture([in] struct AudioDeviceDescriptor desc); + CreateRender([in] struct AudioDeviceDescriptor desc, [in] struct AudioSampleAttributes attrs, + [out] IAudioRender render, [out] unsigned int renderId); + DestroyRender([in] unsigned int renderId); + CreateCapture([in] struct AudioDeviceDescriptor desc, [in] struct AudioSampleAttributes attrs, + [out] IAudioCapture capture, [out] unsigned int captureId); + DestroyCapture([in] unsigned int captureId); GetPortCapability([in] struct AudioPort port, [out] struct AudioPortCapability capability); SetPassthroughMode([in] struct AudioPort port, [in] enum AudioPortPassthroughMode mode); GetPassthroughMode([in] struct AudioPort port, [out] enum AudioPortPassthroughMode mode); @@ -38,4 +49,4 @@ interface IAudioAdapter { SetExtraParams([in] enum AudioExtParamKey key, [in] String condition, [in] String value); GetExtraParams([in] enum AudioExtParamKey key, [in] String condition, [out] String value); RegExtraParamObserver([in] IAudioCallback audioCallback, [in] byte cookie); -} +} \ No newline at end of file diff --git a/hdf_interfaces/distributed_audio/audio/v1_0/IAudioCallback.idl b/hdf_interfaces/distributed_audio/audio/v1_0/IAudioCallback.idl index f73ff31b06421ee75bd55528ce8bcf8a4be5726d..7e29d458d442e0d2204900cee956d573dc3a8b64 100644 --- a/hdf_interfaces/distributed_audio/audio/v1_0/IAudioCallback.idl +++ b/hdf_interfaces/distributed_audio/audio/v1_0/IAudioCallback.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -42,5 +42,5 @@ import ohos.hdi.distributed_audio.audio.v1_0.AudioTypes; */ [callback] interface IAudioCallback { RenderCallback([in] enum AudioCallbackType type, [out] byte reserved, [out] byte cookie); - ParamCallback([in] enum AudioExtParamKey key, [in] String condition, [in] String value, [out] byte reserved, [out] byte cookie); + ParamCallback([in] enum AudioExtParamKey key, [in] String condition, [in] String value, [out] byte reserved, [in] byte cookie); } diff --git a/hdf_interfaces/distributed_audio/audio/v1_0/IAudioCapture.idl b/hdf_interfaces/distributed_audio/audio/v1_0/IAudioCapture.idl index c93ae0115a449c2c19b632379a1cfacc5455b33b..51b6f0d30f36a72b5b39ae872c0c6b2a6200fd3b 100644 --- a/hdf_interfaces/distributed_audio/audio/v1_0/IAudioCapture.idl +++ b/hdf_interfaces/distributed_audio/audio/v1_0/IAudioCapture.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -17,8 +17,14 @@ package ohos.hdi.distributed_audio.audio.v1_0; import ohos.hdi.distributed_audio.audio.v1_0.AudioTypes; +/** + * @brief Provides capabilities for audio capturing, including controlling the capturing, setting audio attributes, + * scenes, and volume, and capturing audio frames. + * @since 4.0 + * @version 1.0 + */ interface IAudioCapture { - CaptureFrame([out] byte[] frame, [in] unsigned long requestBytes); + CaptureFrame([out] byte[] frame, [out] unsigned long replyBytes); GetCapturePosition([out] unsigned long frames, [out] struct AudioTimeStamp time); CheckSceneCapability([in] struct AudioSceneDescriptor scene, [out] boolean supported); SelectScene([in] struct AudioSceneDescriptor scene); diff --git a/hdf_interfaces/distributed_audio/audio/v1_0/IAudioManager.idl b/hdf_interfaces/distributed_audio/audio/v1_0/IAudioManager.idl index beef5cafae6a062b16dc6f77e7bb602f8393f531..16061bf17d0f103cd3d5f659b94ba166dc778f86 100644 --- a/hdf_interfaces/distributed_audio/audio/v1_0/IAudioManager.idl +++ b/hdf_interfaces/distributed_audio/audio/v1_0/IAudioManager.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -18,6 +18,14 @@ package ohos.hdi.distributed_audio.audio.v1_0; import ohos.hdi.distributed_audio.audio.v1_0.AudioTypes; import ohos.hdi.distributed_audio.audio.v1_0.IAudioAdapter; +/** + * @brief Manages audio adapters through a specific adapter driver program loaded based on the given audio + * adapter descriptor. + * + * @see IAudioAdapter + * @since 4.0 + * @version 1.0 + */ interface IAudioManager { GetAllAdapters([out] struct AudioAdapterDescriptor[] descs); LoadAdapter([in] struct AudioAdapterDescriptor desc, [out] IAudioAdapter adapter); diff --git a/hdf_interfaces/distributed_audio/audio/v1_0/IAudioRender.idl b/hdf_interfaces/distributed_audio/audio/v1_0/IAudioRender.idl index 4e24e431d9284cfc0c2b9b3495441ece618db2fc..c4a898bf1314a4a5b3ac34fef7158e600e20f61c 100644 --- a/hdf_interfaces/distributed_audio/audio/v1_0/IAudioRender.idl +++ b/hdf_interfaces/distributed_audio/audio/v1_0/IAudioRender.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -18,6 +18,13 @@ package ohos.hdi.distributed_audio.audio.v1_0; import ohos.hdi.distributed_audio.audio.v1_0.AudioTypes; import ohos.hdi.distributed_audio.audio.v1_0.IAudioCallback; +/** + * @brief Provides capabilities for audio rendering, including controlling the rendering, setting audio attributes, + * scenes, and volume, obtaining hardware latency, and rendering audio frames. + * + * @since 4.0 + * @version 1.0 + */ interface IAudioRender { GetLatency([out] unsigned int ms); RenderFrame([in] byte[] frame, [out] unsigned long replyBytes); diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/BUILD.gn index a387c5fb3b902a66d1553d954c2b10b03b6db9e2..7fdbfe6fe44a5a094dc3142041189d745a609a87 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/BUILD.gn @@ -63,6 +63,13 @@ ohos_shared_library("libaudio_manager_daudio_primary_service_1.0") { "LOG_DOMAIN=0xD004100", ] + if (build_variant == "root") { + defines += [ + "DUMP_CAPTURE_FILE", + "DUMP_RENDER_FILE", + ] + } + install_images = [ chipset_base_dir ] subsystem_name = "distributedhardware" part_name = "drivers_peripheral_distributed_audio" diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_adapter_interface_impl.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_adapter_interface_impl.h index cee31f40caa666312a3b1f7d05a3bc906aa18865..7f02f25faee55f1dbd2798de07316c71f191a343 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_adapter_interface_impl.h +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_adapter_interface_impl.h @@ -73,11 +73,11 @@ public: int32_t InitAllPorts() override; int32_t CreateRender(const AudioDeviceDescriptor &desc, const AudioSampleAttributes &attrs, - sptr &render) override; - int32_t DestroyRender(const AudioDeviceDescriptor &desc) override; + sptr &render, uint32_t &renderId) override; + int32_t DestroyRender(uint32_t renderId) override; int32_t CreateCapture(const AudioDeviceDescriptor &desc, const AudioSampleAttributes &attrs, - sptr &capture) override; - int32_t DestroyCapture(const AudioDeviceDescriptor &desc) override; + sptr &capture, uint32_t &captureId) override; + int32_t DestroyCapture(uint32_t captureId) override; int32_t GetPortCapability(const AudioPort &port, AudioPortCapability &capability) override; int32_t SetPassthroughMode(const AudioPort &port, AudioPortPassthroughMode mode) override; int32_t GetPassthroughMode(const AudioPort &port, AudioPortPassthroughMode &mode) override; @@ -119,9 +119,15 @@ private: int32_t WaitForSANotify(const AudioDeviceEvent &event); int32_t HandleDeviceClosed(const DAudioEvent &event); int32_t getEventTypeFromCondition(const std::string& condition); + int32_t InsertRenderImpl(const sptr &audioRender, uint32_t &renderId); + int32_t InsertCapImpl(const sptr &audioCapture, uint32_t &captureId); + inline bool IsIdValid(const uint32_t id); + bool CheckRendersValid(); + bool CheckCapsValid(); + void SetDumpFlag(bool isRender); private: - static constexpr uint8_t WAIT_SECONDS = 10; + static constexpr uint8_t WAIT_SECONDS = 20; static constexpr int32_t TYPE_CONDITION = 11; AudioAdapterDescriptor adpDescriptor_; AudioAdapterStatus status_ = STATUS_OFFLINE; @@ -129,9 +135,11 @@ private: sptr extSpkCallback_ = nullptr; sptr extMicCallback_ = nullptr; sptr paramCallback_ = nullptr; - sptr audioRender_ = nullptr; + std::mutex renderDevMtx_; + std::vector> renderDevs_; AudioParameter renderParam_; - sptr audioCapture_ = nullptr; + std::mutex capDevMtx_; + std::vector> captureDevs_; AudioParameter captureParam_; std::mutex devMapMtx_; diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl.h index e11c2a8ace8176e95054cced19c189214632b3e5..7056d9b395d1ee849d51bd1e82563dd7ba2e19ce 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl.h +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl.h @@ -41,7 +41,7 @@ public: const AudioSampleAttributes &attrs, const sptr &callback); ~AudioCaptureInterfaceImpl() override; - int32_t CaptureFrame(std::vector &frame, uint64_t requestBytes) override; + int32_t CaptureFrame(std::vector &frame, uint64_t &replyBytes) override; int32_t GetCapturePosition(uint64_t &frames, AudioTimeStamp &time) override; int32_t CheckSceneCapability(const AudioSceneDescriptor &scene, bool &supported) override; int32_t SelectScene(const AudioSceneDescriptor &scene) override; @@ -75,16 +75,20 @@ public: const AudioDeviceDescriptor &GetCaptureDesc() override; void SetAttrs(const std::string &adpName, const AudioDeviceDescriptor &desc, const AudioSampleAttributes &attrs, const sptr &callback) override; + void SetDumpFlagInner() override; private: static constexpr int64_t AUDIO_OFFSET_FRAME_NUM = 10; + const std::string FILE_NAME = "/data/hdf_captureframe.pcm"; std::string adapterName_; AudioDeviceDescriptor devDesc_; AudioSampleAttributes devAttrs_; + bool dumpFlag_ = false; uint32_t timeInterval_ = 5; int64_t frameIndex_ = 0; int64_t framePeriodNs_ = 0; int64_t startTime_ = 0; + int64_t lastCaptureStartTime_ = 0; std::mutex captureMtx_; AudioCaptureStatus captureStatus_ = CAPTURE_STATUS_CLOSE; diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl_base.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl_base.h index 4e3c4912fca9871b713a1e4fb5b01f7b61db36e7..8cb3cb3ce96136dbf4eb74ce63fcebf6581eb857 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl_base.h +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_capture_interface_impl_base.h @@ -45,6 +45,7 @@ public: virtual const AudioDeviceDescriptor &GetCaptureDesc() = 0; virtual void SetAttrs(const std::string &adpName, const AudioDeviceDescriptor &desc, const AudioSampleAttributes &attrs, const sptr &callback) = 0; + virtual void SetDumpFlagInner() = 0; }; } // V1_0 } // Audio diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl.h index 48b282eec2d17031ab2a4e2221dddbd75abd645d..ff2d77431299bdf17efa319961a857571ef8e8b6 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl.h +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl.h @@ -93,6 +93,7 @@ public: uint32_t GetMinVolumeInner() override; void SetAttrs(const std::string &adpName, const AudioDeviceDescriptor &desc, const AudioSampleAttributes &attrs, const sptr &callback) override; + void SetDumpFlagInner() override; private: float GetFadeRate(uint32_t currentIndex, const uint32_t durationIndex); @@ -100,6 +101,7 @@ private: private: static constexpr int64_t AUDIO_OFFSET_FRAME_NUM = 10; + const std::string FILE_NAME = "/data/hdf_renderframe.pcm"; std::string adapterName_; AudioDeviceDescriptor devDesc_; @@ -108,6 +110,7 @@ private: std::mutex renderMtx_; std::mutex volMtx_; bool firstOpenFlag_ = true; + bool dumpFlag_ = false; uint32_t timeInterval_ = 5; uint32_t currentFrame_ = 0; uint32_t vol_ = 0; @@ -115,6 +118,7 @@ private: uint32_t volMin_ = 0; int64_t frameIndex_ = 0; float renderSpeed_ = 0; + int64_t lastRenderStartTime_ = 0; AudioChannelMode channelMode_ = AUDIO_CHANNEL_NORMAL; AudioRenderStatus renderStatus_ = RENDER_STATUS_CLOSE; sptr audioExtCallback_ = nullptr; diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl_base.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl_base.h index 5929d137f2c6e9c169fbdb2c9e0f160530d6845a..3675951b962af96354848e71ce56aac42dcb29e2 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl_base.h +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/include/audio_render_interface_impl_base.h @@ -53,6 +53,7 @@ public: virtual uint32_t GetMinVolumeInner() = 0; virtual void SetAttrs(const std::string &adpName, const AudioDeviceDescriptor &desc, const AudioSampleAttributes &attrs, const sptr &callback) = 0; + virtual void SetDumpFlagInner() = 0; }; } // V1_0 } // Audio diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_adapter_interface_impl.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_adapter_interface_impl.cpp index 6fdb2734361dc62850298b83bb6e1897a3357051..1be35bacbba9135fef1c9a1333e7a6fcd9360f1c 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_adapter_interface_impl.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_adapter_interface_impl.cpp @@ -34,11 +34,18 @@ namespace HDI { namespace DistributedAudio { namespace Audio { namespace V1_0 { +static constexpr uint32_t MAX_AUDIO_STREAM_NUM = 10; + AudioAdapterInterfaceImpl::AudioAdapterInterfaceImpl(const AudioAdapterDescriptor &desc) : adpDescriptor_(desc) { + renderDevs_ = std::vector>( + MAX_AUDIO_STREAM_NUM, sptr(nullptr)); + captureDevs_ = std::vector>( + MAX_AUDIO_STREAM_NUM, sptr(nullptr)); renderParam_ = { 0, 0, 0, 0, 0, 0 }; captureParam_ = { 0, 0, 0, 0, 0, 0 }; + DHLOGD("Distributed audio adapter constructed, name(%s).", GetAnonyString(desc.adapterName).c_str()); } @@ -47,7 +54,6 @@ AudioAdapterInterfaceImpl::~AudioAdapterInterfaceImpl() DHLOGD("Distributed audio adapter destructed, name(%s).", GetAnonyString(adpDescriptor_.adapterName).c_str()); } - void AudioAdapterInterfaceImpl::SetSpeakerCallback(const sptr &spkCallback) { if (spkCallback == nullptr) { @@ -73,11 +79,12 @@ int32_t AudioAdapterInterfaceImpl::InitAllPorts() } int32_t AudioAdapterInterfaceImpl::CreateRender(const AudioDeviceDescriptor &desc, - const AudioSampleAttributes &attrs, sptr &render) + const AudioSampleAttributes &attrs, sptr &render, uint32_t &renderId) { DHLOGI("Create distributed audio render, {pin: %zu, sampleRate: %zu, channel: %zu, formats: %zu, type: %d}.", desc.pins, attrs.sampleRate, attrs.channelCount, attrs.format, static_cast(attrs.type)); render = nullptr; + sptr audioRender = nullptr; { std::lock_guard devLck(devMapMtx_); if (mapAudioDevice_.find(desc.pins) == mapAudioDevice_.end()) { @@ -85,64 +92,100 @@ int32_t AudioAdapterInterfaceImpl::CreateRender(const AudioDeviceDescriptor &des return HDF_FAILURE; } } + #ifdef DAUDIO_SUPPORT_EXTENSION if (attrs.type == AUDIO_MMAP_NOIRQ) { DHLOGI("Try to mmap mode."); renderFlags_ = Audioext::V1_0::MMAP_MODE; - audioRender_ = new AudioRenderExtImpl(); - audioRender_->SetAttrs(adpDescriptor_.adapterName, desc, attrs, extSpkCallback_); + audioRender = new AudioRenderExtImpl(); + audioRender->SetAttrs(adpDescriptor_.adapterName, desc, attrs, extSpkCallback_); } else { DHLOGI("Try to normal mode."); renderFlags_ = Audioext::V1_0::NORMAL_MODE; - audioRender_ = new AudioRenderInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extSpkCallback_); + audioRender = new AudioRenderInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extSpkCallback_); } #else renderFlags_ = Audioext::V1_0::NORMAL_MODE; - audioRender_ = new AudioRenderInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extSpkCallback_); + audioRender = new AudioRenderInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extSpkCallback_); #endif - if (audioRender_ == nullptr) { + if (audioRender == nullptr) { DHLOGE("Create render failed."); return HDF_FAILURE; } - int32_t ret = OpenRenderDevice(desc, attrs); if (ret != DH_SUCCESS) { DHLOGE("Open render device failed."); - audioRender_ = nullptr; + audioRender = nullptr; return ret == ERR_DH_AUDIO_HDF_WAIT_TIMEOUT ? HDF_ERR_TIMEOUT : HDF_FAILURE; } - render = audioRender_; - DHLOGI("Create render success."); + render = audioRender; + if (InsertRenderImpl(audioRender, renderId) != HDF_SUCCESS) { + DHLOGE("Generrate render ID and insert render failed."); + return HDF_FAILURE; + } + DHLOGI("Create render success, render ID is %u.", renderId); return HDF_SUCCESS; } -int32_t AudioAdapterInterfaceImpl::DestroyRender(const AudioDeviceDescriptor &desc) +int32_t AudioAdapterInterfaceImpl::InsertRenderImpl(const sptr &audioRender, + uint32_t &renderId) { - DHLOGI("Destroy distributed audio render, {pin: %zu}.", desc.pins); - if (audioRender_ == nullptr) { - DHLOGD("Render has not been created, do not need destroy."); - return HDF_SUCCESS; + std::lock_guard devLck(renderDevMtx_); + if (renderDevs_.size() != MAX_AUDIO_STREAM_NUM) { + DHLOGE("Render device contain check error."); + return HDF_FAILURE; + } + renderId = MAX_AUDIO_STREAM_NUM; + for (uint32_t i = 0; i < MAX_AUDIO_STREAM_NUM; i++) { + if (renderDevs_[i] == nullptr) { + renderId = i; + break; + } } - if (desc.pins != audioRender_->GetRenderDesc().pins) { - DHLOGE("Render pin is wrong, destroy render failed."); + if (renderId == MAX_AUDIO_STREAM_NUM) { + DHLOGE("The device is busy, can't create render anymore."); return HDF_FAILURE; } + renderDevs_[renderId] = audioRender; + return HDF_SUCCESS; +} + +int32_t AudioAdapterInterfaceImpl::DestroyRender(uint32_t renderId) +{ + DHLOGI("Destroy distributed audio render, ID: %u.", renderId); + if (!IsIdValid(renderId)) { + DHLOGE("The input render ID is invalid."); + return HDF_FAILURE; + } + sptr audioRender(nullptr); + { + std::lock_guard devLck(renderDevMtx_); + audioRender = renderDevs_[renderId]; + } + if (audioRender == nullptr) { + DHLOGD("Render has not been created, do not need destroy."); + return HDF_SUCCESS; + } - int32_t ret = CloseRenderDevice(desc); + int32_t ret = CloseRenderDevice(audioRender->GetRenderDesc()); if (ret != DH_SUCCESS) { DHLOGE("Close render device failed."); return HDF_FAILURE; } - audioRender_ = nullptr; + { + std::lock_guard devLck(renderDevMtx_); + renderDevs_[renderId] = nullptr; + } return HDF_SUCCESS; } int32_t AudioAdapterInterfaceImpl::CreateCapture(const AudioDeviceDescriptor &desc, - const AudioSampleAttributes &attrs, sptr &capture) + const AudioSampleAttributes &attrs, sptr &capture, uint32_t &captureId) { DHLOGI("Create distributed audio capture, {pin: %zu, sampleRate: %zu, channel: %zu, formats: %zu}.", desc.pins, attrs.sampleRate, attrs.channelCount, attrs.format); capture = nullptr; + sptr audioCapture(nullptr); { std::lock_guard devLck(devMapMtx_); if (mapAudioDevice_.find(desc.pins) == mapAudioDevice_.end()) { @@ -150,55 +193,90 @@ int32_t AudioAdapterInterfaceImpl::CreateCapture(const AudioDeviceDescriptor &de return HDF_FAILURE; } } + #ifdef DAUDIO_SUPPORT_EXTENSION if (attrs.type == AUDIO_MMAP_NOIRQ) { DHLOGI("Try to mmap mode."); capturerFlags_ = Audioext::V1_0::MMAP_MODE; - audioCapture_ = new AudioCaptureExtImpl(); - audioCapture_->SetAttrs(adpDescriptor_.adapterName, desc, attrs, extMicCallback_); + audioCapture = new AudioCaptureExtImpl(); + audioCapture->SetAttrs(adpDescriptor_.adapterName, desc, attrs, extMicCallback_); } else { DHLOGI("Try to normal mode."); capturerFlags_ = Audioext::V1_0::NORMAL_MODE; - audioCapture_ = new AudioCaptureInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extMicCallback_); + audioCapture = new AudioCaptureInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extMicCallback_); } #else capturerFlags_ = Audioext::V1_0::NORMAL_MODE; - audioCapture_ = new AudioCaptureInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extMicCallback_); + audioCapture = new AudioCaptureInterfaceImpl(adpDescriptor_.adapterName, desc, attrs, extMicCallback_); #endif - if (audioCapture_ == nullptr) { + if (audioCapture == nullptr) { DHLOGE("Create capture failed."); return HDF_FAILURE; } - int32_t ret = OpenCaptureDevice(desc, attrs); if (ret != DH_SUCCESS) { DHLOGE("Open capture device failed."); - audioCapture_ = nullptr; + audioCapture = nullptr; return ret == ERR_DH_AUDIO_HDF_WAIT_TIMEOUT ? HDF_ERR_TIMEOUT : HDF_FAILURE; } - capture = audioCapture_; - DHLOGI("Create capture success."); + capture = audioCapture; + if (InsertCapImpl(audioCapture, captureId) != HDF_SUCCESS) { + DHLOGE("Generrate capture ID and insert capture failed."); + return HDF_FAILURE; + } + DHLOGI("Create capture success, capture ID is %u.", captureId); return HDF_SUCCESS; } -int32_t AudioAdapterInterfaceImpl::DestroyCapture(const AudioDeviceDescriptor &desc) +int32_t AudioAdapterInterfaceImpl::InsertCapImpl(const sptr &audioCapture, + uint32_t &captureId) { - DHLOGI("Destroy distributed audio capture, {pin: %zu}.", desc.pins); - if (audioCapture_ == nullptr) { - DHLOGD("Capture has not been created, do not need destroy."); - return HDF_SUCCESS; + std::lock_guard devLck(capDevMtx_); + if (captureDevs_.size() != MAX_AUDIO_STREAM_NUM) { + DHLOGE("Capture device's size check error."); + return HDF_FAILURE; + } + captureId = MAX_AUDIO_STREAM_NUM; + for (uint32_t i = 0; i < MAX_AUDIO_STREAM_NUM; i++) { + if (captureDevs_[i] == nullptr) { + captureId = i; + break; + } + } + if (captureId == MAX_AUDIO_STREAM_NUM) { + DHLOGE("The device is busy, can't create capture anymore."); + return HDF_FAILURE; } - if (desc.pins != audioCapture_->GetCaptureDesc().pins) { - DHLOGE("Capture pin is wrong, destroy capture failed."); + captureDevs_[captureId] = audioCapture; + return HDF_SUCCESS; +} + +int32_t AudioAdapterInterfaceImpl::DestroyCapture(uint32_t captureId) +{ + DHLOGI("Destroy distributed audio capture, ID: %u.", captureId); + if (!IsIdValid(captureId)) { + DHLOGE("The input capture ID is invalid."); return HDF_FAILURE; } + sptr audioCapture(nullptr); + { + std::lock_guard devLck(capDevMtx_); + audioCapture = captureDevs_[captureId]; + } + if (audioCapture == nullptr) { + DHLOGD("Capture has not been created, do not need destroy."); + return HDF_SUCCESS; + } - int32_t ret = CloseCaptureDevice(desc); + int32_t ret = CloseCaptureDevice(audioCapture->GetCaptureDesc()); if (ret != DH_SUCCESS) { DHLOGE("Close capture device failed."); return HDF_FAILURE; } - audioCapture_ = nullptr; + { + std::lock_guard devLck(capDevMtx_); + captureDevs_[captureId] = nullptr; + } return HDF_SUCCESS; } @@ -349,7 +427,7 @@ int32_t AudioAdapterInterfaceImpl::AdapterLoad() int32_t AudioAdapterInterfaceImpl::AdapterUnload() { - if (audioRender_ != nullptr || audioCapture_ != nullptr) { + if (CheckRendersValid() || CheckCapsValid()) { DHLOGE("Adapter is busy, audio render or capture is not null."); return HDF_ERR_DEVICE_BUSY; } @@ -373,6 +451,8 @@ int32_t AudioAdapterInterfaceImpl::Notify(const uint32_t devId, const DAudioEven case HDF_AUDIO_EVENT_CLOSE_SPK_RESULT: case HDF_AUDIO_EVENT_OPEN_MIC_RESULT: case HDF_AUDIO_EVENT_CLOSE_MIC_RESULT: + case HDF_AUDIO_EVENT_SPK_DUMP: + case HDF_AUDIO_EVENT_MIC_DUMP: return HandleSANotifyEvent(event); case HDF_AUDIO_EVENT_SPK_CLOSED: case HDF_AUDIO_EVENT_MIC_CLOSED: @@ -409,14 +489,15 @@ int32_t AudioAdapterInterfaceImpl::RemoveAudioDevice(const uint32_t devId) } mapAudioDevice_.erase(devId); } - AudioDeviceDescriptor dec; if (devId == spkPinInUse_) { - dec.pins = static_cast(spkPinInUse_); - DestroyRender(dec); + for (uint32_t i = 0; i < MAX_AUDIO_STREAM_NUM; i++) { + DestroyRender(i); + } } if (devId == micPinInUse_) { - dec.pins = static_cast(micPinInUse_); - DestroyCapture(dec); + for (uint32_t capId = 0; capId < MAX_AUDIO_STREAM_NUM; capId++) { + DestroyCapture(capId); + } } DHLOGI("Remove audio device success."); @@ -589,10 +670,6 @@ int32_t AudioAdapterInterfaceImpl::SetAudioVolume(const std::string& condition, DHLOGE("Callback is nullptr."); return ERR_DH_AUDIO_HDF_NULLPTR; } - if (audioRender_ == nullptr) { - DHLOGE("Render has not been created."); - return ERR_DH_AUDIO_HDF_NULLPTR; - } std::string content = condition; int32_t type = getEventTypeFromCondition(content); EXT_PARAM_EVENT eventType; @@ -614,18 +691,32 @@ int32_t AudioAdapterInterfaceImpl::SetAudioVolume(const std::string& condition, SetAudioParamStr(content, VOLUME_LEVEL, param); } DAudioEvent event = { eventType, content }; - int32_t ret = - extSpkCallback_->NotifyEvent(adpDescriptor_.adapterName, audioRender_->GetRenderDesc().pins, event); - if (ret != HDF_SUCCESS) { - DHLOGE("NotifyEvent failed."); - return ERR_DH_AUDIO_HDF_FAIL; + + { + std::lock_guard devLck(renderDevMtx_); + for (auto render : renderDevs_) { + if (render == nullptr) { + continue; + } + if (extSpkCallback_->NotifyEvent(adpDescriptor_.adapterName, + render->GetRenderDesc().pins, event) != HDF_SUCCESS) { + DHLOGE("NotifyEvent failed."); + return ERR_DH_AUDIO_HDF_FAIL; + } + } } return DH_SUCCESS; } int32_t AudioAdapterInterfaceImpl::GetAudioVolume(const std::string& condition, std::string ¶m) { - if (audioRender_ == nullptr) { + int renderId = 0; // fromaudio framwork + sptr audioRender(nullptr); + { + std::lock_guard devLck(renderDevMtx_); + audioRender = renderDevs_[renderId]; + } + if (audioRender == nullptr) { DHLOGE("Render has not been created."); return ERR_DH_AUDIO_HDF_NULLPTR; } @@ -633,13 +724,13 @@ int32_t AudioAdapterInterfaceImpl::GetAudioVolume(const std::string& condition, uint32_t vol; switch (type) { case VolumeEventType::EVENT_GET_VOLUME: - vol = audioRender_->GetVolumeInner(); + vol = audioRender->GetVolumeInner(); break; case VolumeEventType::EVENT_GET_MAX_VOLUME: - vol = audioRender_->GetMaxVolumeInner(); + vol = audioRender->GetMaxVolumeInner(); break; case VolumeEventType::EVENT_GET_MIN_VOLUME: - vol = audioRender_->GetMinVolumeInner(); + vol = audioRender->GetMinVolumeInner(); break; case VolumeEventType::EVENT_IS_STREAM_MUTE: vol = streamMuteStatus_; @@ -662,7 +753,13 @@ int32_t AudioAdapterInterfaceImpl::getEventTypeFromCondition(const std::string & int32_t AudioAdapterInterfaceImpl::HandleVolumeChangeEvent(const DAudioEvent &event) { DHLOGI("Vol change (%s).", event.content.c_str()); - if (audioRender_ == nullptr) { + int renderId = 0; // daudio SA + sptr audioRender(nullptr); + { + std::lock_guard devLck(renderDevMtx_); + audioRender = renderDevs_[renderId]; + } + if (audioRender == nullptr) { DHLOGE("Render has not been created."); return ERR_DH_AUDIO_HDF_NULLPTR; } @@ -684,18 +781,18 @@ int32_t AudioAdapterInterfaceImpl::HandleVolumeChangeEvent(const DAudioEvent &ev if (ret != DH_SUCCESS) { DHLOGE("Get min volume value failed, use defult min volume."); } - audioRender_->SetVolumeInner(vol); - audioRender_->SetVolumeRangeInner(maxVol, minVol); + audioRender->SetVolumeInner(vol); + audioRender->SetVolumeRangeInner(maxVol, minVol); return DH_SUCCESS; } - audioRender_->SetVolumeInner(vol); + audioRender->SetVolumeInner(vol); if (paramCallback_ == nullptr) { DHLOGE("Audio param observer is null."); return ERR_DH_AUDIO_HDF_NULLPTR; } - int8_t reserved; - int8_t cookie; + int8_t reserved = 0; + int8_t cookie = 0; ret = paramCallback_->ParamCallback(AUDIO_EXT_PARAM_KEY_VOLUME, event.content, std::to_string(vol), reserved, cookie); if (ret != DH_SUCCESS) { @@ -712,8 +809,8 @@ int32_t AudioAdapterInterfaceImpl::HandleFocusChangeEvent(const DAudioEvent &eve DHLOGE("Audio param observer is null."); return ERR_DH_AUDIO_HDF_NULLPTR; } - int8_t reserved; - int8_t cookie; + int8_t reserved = 0; + int8_t cookie = 0; int32_t ret = paramCallback_->ParamCallback(AUDIO_EXT_PARAM_KEY_FOCUS, event.content, "", reserved, cookie); if (ret != DH_SUCCESS) { DHLOGE("Notify Focus failed."); @@ -729,8 +826,8 @@ int32_t AudioAdapterInterfaceImpl::HandleRenderStateChangeEvent(const DAudioEven DHLOGE("Audio param observer is null."); return ERR_DH_AUDIO_HDF_NULLPTR; } - int8_t reserved; - int8_t cookie; + int8_t reserved = 0; + int8_t cookie = 0; int32_t ret = paramCallback_->ParamCallback(AUDIO_EXT_PARAM_KEY_STATUS, event.content, "", reserved, cookie); if (ret != DH_SUCCESS) { DHLOGE("Notify render state failed."); @@ -771,6 +868,12 @@ int32_t AudioAdapterInterfaceImpl::HandleSANotifyEvent(const DAudioEvent &event) micNotifyFlag_ = true; micWaitCond_.notify_all(); break; + case HDF_AUDIO_EVENT_SPK_DUMP: + SetDumpFlag(true); + break; + case HDF_AUDIO_EVENT_MIC_DUMP: + SetDumpFlag(false); + break; default: DHLOGE("Notify not support event type %d, event content: %s.", event.type, event.content.c_str()); return ERR_DH_AUDIO_HDF_FAIL; @@ -831,8 +934,8 @@ int32_t AudioAdapterInterfaceImpl::HandleDeviceClosed(const DAudioEvent &event) std::stringstream ss; ss << "ERR_EVENT;DEVICE_TYPE=" << (event.type == HDF_AUDIO_EVENT_SPK_CLOSED ? AUDIO_DEVICE_TYPE_SPEAKER : AUDIO_DEVICE_TYPE_MIC) << ";"; - int8_t reserved; - int8_t cookie; + int8_t reserved = 0; + int8_t cookie = 0; int32_t ret = paramCallback_->ParamCallback(AUDIO_EXT_PARAM_KEY_STATUS, ss.str(), std::to_string(EVENT_DEV_CLOSED), reserved, cookie); if (ret != DH_SUCCESS) { @@ -840,15 +943,24 @@ int32_t AudioAdapterInterfaceImpl::HandleDeviceClosed(const DAudioEvent &event) } } - AudioDeviceDescriptor dec; if (isSpkOpened_ && event.type == HDF_AUDIO_EVENT_SPK_CLOSED) { DHLOGE("Render device status error, close render."); - dec.pins = static_cast(spkPinInUse_); - return DestroyRender(dec); + bool destroyStatus = true; + for (uint32_t i = 0; i < MAX_AUDIO_STREAM_NUM; i++) { + if (DestroyRender(i) != DH_SUCCESS) { + destroyStatus = false; + } + } + return destroyStatus ? DH_SUCCESS : ERR_DH_AUDIO_HDF_FAIL; } else if (isMicOpened_ && event.type == HDF_AUDIO_EVENT_MIC_CLOSED) { DHLOGE("Capture device status error, close capture."); - dec.pins = static_cast(micPinInUse_); - return DestroyCapture(dec); + bool capCloseStatus = true; + for (uint32_t i = 0; i < MAX_AUDIO_STREAM_NUM; i++) { + if (DestroyCapture(i) != DH_SUCCESS) { + capCloseStatus = false; + } + } + return capCloseStatus ? DH_SUCCESS : ERR_DH_AUDIO_HDF_FAIL; } DHLOGI("Handle device closed success."); return DH_SUCCESS; @@ -859,6 +971,64 @@ bool AudioAdapterInterfaceImpl::IsPortsNoReg() std::lock_guard devLck(devMapMtx_); return mapAudioDevice_.empty(); } + +inline bool AudioAdapterInterfaceImpl::IsIdValid(const uint32_t id) +{ + if (id >= MAX_AUDIO_STREAM_NUM) { + DHLOGE("Current id:%u is not supported.", id); + return false; + } + return true; +} + +bool AudioAdapterInterfaceImpl::CheckRendersValid() +{ + { + std::lock_guard devLck(renderDevMtx_); + for (uint32_t i = 0; i < MAX_AUDIO_STREAM_NUM; i++) { + if (renderDevs_[i] != nullptr) { + DHLOGI("Containing active render."); + return true; + } + } + } + return false; +} + +bool AudioAdapterInterfaceImpl::CheckCapsValid() +{ + { + std::lock_guard devLck(capDevMtx_); + for (uint32_t i = 0; i < MAX_AUDIO_STREAM_NUM; i++) { + if (captureDevs_[i] != nullptr) { + DHLOGI("Containing active capture."); + return true; + } + } + } + return false; +} + +void AudioAdapterInterfaceImpl::SetDumpFlag(bool isRender) +{ + if (isRender) { + std::lock_guard renderLck(renderDevMtx_); + for (auto render : renderDevs_) { + if (render == nullptr) { + continue; + } + render->SetDumpFlagInner(); + } + } else { + std::lock_guard capLck(capDevMtx_); + for (auto capture : captureDevs_) { + if (capture == nullptr) { + continue; + } + capture->SetDumpFlagInner(); + } + } +} } // V1_0 } // Audio } // Distributedaudio diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_capture_interface_impl.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_capture_interface_impl.cpp index 39b830a374e8b96e374e71782abf16778102ba4e..603208fb65874f7076c130396a0668437aceef3e 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_capture_interface_impl.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_capture_interface_impl.cpp @@ -60,13 +60,14 @@ int32_t AudioCaptureInterfaceImpl::GetCapturePosition(uint64_t &frames, AudioTim return HDF_SUCCESS; } -int32_t AudioCaptureInterfaceImpl::CaptureFrame(std::vector &frame, uint64_t requestBytes) +int32_t AudioCaptureInterfaceImpl::CaptureFrame(std::vector &frame, uint64_t &replyBytes) { DHLOGD("Capture frame[sampleRate: %d, channelCount: %d, format: %d, frameSize: %d].", devAttrs_.sampleRate, devAttrs_.channelCount, devAttrs_.format, devAttrs_.frameSize); int64_t timeOffset = UpdateTimeOffset(frameIndex_, framePeriodNs_, startTime_); DHLOGD("Capture framIndex: %lld, timeOffset: %lld.", frameIndex_, timeOffset); + int64_t startTime = GetNowTimeUs(); std::lock_guard captureLck(captureMtx_); if (captureStatus_ != CAPTURE_STATUS_START) { DHLOGE("Capture status wrong, return false."); @@ -83,7 +84,11 @@ int32_t AudioCaptureInterfaceImpl::CaptureFrame(std::vector &frame, uint DHLOGE("Read stream data failed."); return HDF_FAILURE; } - +#ifdef DUMP_CAPTURE_FILE + if (dumpFlag_) { + SaveFile(FILE_NAME, reinterpret_cast(audioData.data.data()), audioData.data.size()); + } +#endif frame.resize(devAttrs_.frameSize); ret = memcpy_s(frame.data(), frame.size(), audioData.data.data(), audioData.data.size()); if (ret != EOK) { @@ -93,6 +98,12 @@ int32_t AudioCaptureInterfaceImpl::CaptureFrame(std::vector &frame, uint ++frameIndex_; AbsoluteSleep(startTime_ + frameIndex_ * framePeriodNs_ - timeOffset); DHLOGD("Capture audio frame success."); + int64_t endTime = GetNowTimeUs(); + if (IsOutDurationRange(startTime, endTime, lastCaptureStartTime_)) { + DHLOGD("This time capture frame spend: %lld, The interval of this capture frame time and the last time: %lld", + endTime - startTime, startTime - lastCaptureStartTime_); + } + lastCaptureStartTime_ = startTime; return HDF_SUCCESS; } @@ -327,6 +338,11 @@ void AudioCaptureInterfaceImpl::SetAttrs(const std::string &adpName, const Audio DHLOGI("Set attrs, not support yet."); } +void AudioCaptureInterfaceImpl::SetDumpFlagInner() +{ + dumpFlag_ = true; +} + const AudioDeviceDescriptor &AudioCaptureInterfaceImpl::GetCaptureDesc() { return devDesc_; diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_render_interface_impl.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_render_interface_impl.cpp index 686196cb5baab271dd9abb95a11bb078457b1e01..cb4c219f21bf280dfb1a9e8a1763af760ad4c0ac 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_render_interface_impl.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/src/audio_render_interface_impl.cpp @@ -92,6 +92,7 @@ int32_t AudioRenderInterfaceImpl::RenderFrame(const std::vector &frame, devAttrs_.channelCount, devAttrs_.format, devAttrs_.frameSize); DHLOGD("Render frameIndex: %lld.", frameIndex_); + int64_t startTime = GetNowTimeUs(); std::lock_guard renderLck(renderMtx_); if (renderStatus_ != RENDER_STATUS_START) { DHLOGE("Render status wrong, return false."); @@ -100,6 +101,11 @@ int32_t AudioRenderInterfaceImpl::RenderFrame(const std::vector &frame, AudioParameter param = { devAttrs_.format, devAttrs_.channelCount, devAttrs_.sampleRate, 0, devAttrs_.frameSize}; AudioData data = { param, frame }; +#ifdef DUMP_RENDER_FILE + if (dumpFlag_) { + SaveFile(FILE_NAME, reinterpret_cast(data.data.data()), frame.size()); + } +#endif FadeInProcess(DURATION_FRAMES, data.data.data(), frame.size()); if (audioExtCallback_ == nullptr) { DHLOGE("Callback is nullptr."); @@ -113,6 +119,12 @@ int32_t AudioRenderInterfaceImpl::RenderFrame(const std::vector &frame, ++frameIndex_; DHLOGD("Render audio frame success."); + int64_t endTime = GetNowTimeUs(); + if (IsOutDurationRange(startTime, endTime, lastRenderStartTime_)) { + DHLOGE("This time render frame spend: %lld, The interval of render frame this time and the last time: %lld", + endTime - startTime, startTime - lastRenderStartTime_); + } + lastRenderStartTime_ = startTime; return HDF_SUCCESS; } @@ -436,6 +448,11 @@ void AudioRenderInterfaceImpl::SetAttrs(const std::string &adpName, const AudioD { DHLOGI("Set attrs, not support yet."); } + +void AudioRenderInterfaceImpl::SetDumpFlagInner() +{ + dumpFlag_ = true; +} } // V1_0 } // Audio } // Distributedaudio diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/captureframe_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/captureframe_fuzzer/BUILD.gn index e268f7232d951937e4e8b12cd9aef64004263286..718f13d92a3e054f454b39c812385f20084b6a09 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/captureframe_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/captureframe_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("CaptureFrameFuzzTest") { - module_out_path = "distributed_audio/captureframe_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/captureframe_fuzzer" fuzz_config_file = "${hdf_ser_aud_path}/test/fuzztest/captureframe_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/BUILD.gn index bb6d543f2b0cefe042fab9506ad5e7970b13b098..8a447c484c6c87559f5e9f3cc86a47b491ee8679 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("CreateCaptureFuzzTest") { - module_out_path = "distributed_audio/createcapture_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/createcapture_fuzzer" fuzz_config_file = "${hdf_ser_aud_path}/test/fuzztest/createcapture_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/createcapture_fuzzer.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/createcapture_fuzzer.cpp index 87f0fe8a9adac6ff10574b5b23906f10b46a2aac..d49cd09ab53c4b0ae4283734884a1f594aeb1fab 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/createcapture_fuzzer.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createcapture_fuzzer/createcapture_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -59,7 +59,8 @@ void CreateCaptureFuzzTest(const uint8_t* data, size_t size) }; sptr capture; - audioAdapter->CreateCapture(deviceDes, sampleAttr, capture); + uint32_t capId; + audioAdapter->CreateCapture(deviceDes, sampleAttr, capture, capId); } } // V1_0 } // Audio diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/BUILD.gn index 7638ff96fa55512d40296ac50844a6e2ef4894a2..a80b2dd36aed374efb081bcdbe8acdf0ae32ceb3 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("CreateRenderFuzzTest") { - module_out_path = "distributed_audio/createrender_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/createrender_fuzzer" fuzz_config_file = "${hdf_ser_aud_path}/test/fuzztest/createrender_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/createrender_fuzzer.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/createrender_fuzzer.cpp index d3ba28c74ba45be0af3cf7200faf408e1142c8c1..9b0289cdb440c2cea1143c53586ccefc43245dbb 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/createrender_fuzzer.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/createrender_fuzzer/createrender_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -59,7 +59,8 @@ void CreateRenderFuzzTest(const uint8_t* data, size_t size) }; sptr render; - audioAdapter->CreateRender(deviceDes, sampleAttr, render); + uint32_t renderId; + audioAdapter->CreateRender(deviceDes, sampleAttr, render, renderId); } } // V1_0 } // Audio diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/BUILD.gn index 1c7bb9283d8b968584c485e45c8c717351dffdfd..a36e3ca6eb58e12682c38b97a3154814a3781388 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("DestroyCaptureFuzzTest") { - module_out_path = "distributed_audio/destroycapture_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/destroycapture_fuzzer" fuzz_config_file = "${hdf_ser_aud_path}/test/fuzztest/destroycapture_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/destroycapture_fuzzer.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/destroycapture_fuzzer.cpp index fcf2144be81af0423c939d64af96e0d1de577aee..3cd068680e8301e18703f101b6e7e89800218fef 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/destroycapture_fuzzer.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroycapture_fuzzer/destroycapture_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -36,13 +36,8 @@ void DestroyCaptureFuzzTest(const uint8_t* data, size_t size) AudioAdapterDescriptor desc; auto audioAdapter = std::make_shared(desc); - AudioDeviceDescriptor deviceDes = { - .portId = *(reinterpret_cast(data)), - .pins = *(reinterpret_cast(data)), - .desc = std::string(reinterpret_cast(data), size), - }; - - audioAdapter->DestroyCapture(deviceDes); + uint32_t capId = *(reinterpret_cast(data)); + audioAdapter->DestroyCapture(capId); } } // V1_0 } // Audio diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/BUILD.gn index 7b56240f970b005d3fe0548b64c0c8e8796cb16e..d89604b0124a1ab0857690de827361438d9e20f0 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("DestroyRenderFuzzTest") { - module_out_path = "distributed_audio/destroyrender_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/destroyrender_fuzzer" fuzz_config_file = "${hdf_ser_aud_path}/test/fuzztest/destroyrender_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/destroyrender_fuzzer.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/destroyrender_fuzzer.cpp index c4c39172a78a4bf379f9fa19d22b64c3bc14539d..1ca043aae2a8d1620d295e2846d3a3421f5ac0d9 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/destroyrender_fuzzer.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/destroyrender_fuzzer/destroyrender_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -36,13 +36,8 @@ void DestroyRenderFuzzTest(const uint8_t* data, size_t size) AudioAdapterDescriptor desc; auto audioAdapter = std::make_shared(desc); - AudioDeviceDescriptor deviceDes = { - .portId = *(reinterpret_cast(data)), - .pins = *(reinterpret_cast(data)), - .desc = std::string(reinterpret_cast(data), size), - }; - - audioAdapter->DestroyRender(deviceDes); + uint32_t renderId = *(reinterpret_cast(data)); + audioAdapter->DestroyRender(renderId); } } // V1_0 } // Audio diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getalladapters_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getalladapters_fuzzer/BUILD.gn index 41db6f1944480b09c51a7ec2526f63072f2c47c5..7452483e413e7439ea700f48619d6576f21f17d8 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getalladapters_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getalladapters_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("GetAllAdaptersFuzzTest") { - module_out_path = "distributed_audio/getalladapters_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/getalladapters_fuzzer" fuzz_config_file = "${hdf_ser_aud_path}/test/fuzztest/getalladapters_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getextraparams_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getextraparams_fuzzer/BUILD.gn index f458e4e5843d9919acaa99d4b5e0c3da853732bc..36ce96dfae7e35eb66e7d8c708ea27a574b4bc92 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getextraparams_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/getextraparams_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("GetExtraParamsFuzzTest") { - module_out_path = "distributed_audio/getextraparams_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/getextraparams_fuzzer" fuzz_config_file = "${hdf_ser_aud_path}/test/fuzztest/getextraparams_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/loadadapter_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/loadadapter_fuzzer/BUILD.gn index 4200c0b26aff249beb9e8f722d5ab4fd9dfb2b01..1ae5fd52abb45d2d783fc1abe427b87f1c242dd3 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/loadadapter_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/loadadapter_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("LoadAdapterFuzzTest") { - module_out_path = "distributed_audio/loadadapter_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/loadadapter_fuzzer" fuzz_config_file = "${hdf_ser_aud_path}/test/fuzztest/loadadapter_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/renderframe_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/renderframe_fuzzer/BUILD.gn index 4c63ad9ecc673218b5143ce08c8430f5d6a34907..6931d7689b353d3bf219f6886c3b79ea8a9cb545 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/renderframe_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/renderframe_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("RenderFrameFuzzTest") { - module_out_path = "distributed_audio/renderframe_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/renderframe_fuzzer" fuzz_config_file = "${hdf_ser_aud_path}/test/fuzztest/renderframe_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/setextraparams_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/setextraparams_fuzzer/BUILD.gn index ce3e5249577a15c2c24af5ff39a9469b8d34ea77..e9f951d5968b9105edc7b98215252cb4a5ba57fd 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/setextraparams_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/setextraparams_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SetExtraParamsFuzzTest") { - module_out_path = "distributed_audio/setextraparams_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/setextraparams_fuzzer" fuzz_config_file = "${hdf_ser_aud_path}/test/fuzztest/setextraparams_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/unloadadapter_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/unloadadapter_fuzzer/BUILD.gn index 4086a58cfa6632485db4af5199fb6adab2229c26..cb86345a33f904df9e6208a4a37aa32af46a5550 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/unloadadapter_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/fuzztest/unloadadapter_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("UnloadAdapterFuzzTest") { - module_out_path = "distributed_audio/unloadadapter_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/unloadadapter_fuzzer" fuzz_config_file = "${hdf_ser_aud_path}/test/fuzztest/unloadadapter_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/src/audio_adapter_interface_impl_test.cpp b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/src/audio_adapter_interface_impl_test.cpp index c832d20637e49d27e615512f0049bc1b5694f0ca..c5b38b4e33fc36a927ca977db9087faffffe4964 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/src/audio_adapter_interface_impl_test.cpp +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_adapter_interface/src/audio_adapter_interface_impl_test.cpp @@ -73,14 +73,15 @@ HWTEST_F(AudioAdapterInterfaceImpTest, CreateRender_001, TestSize.Level1) AudioDeviceDescriptor devDesc; AudioSampleAttributes attrs; sptr render = nullptr; + uint32_t renderId = 0; AdapterTest_->extSpkCallback_ = new MockIDAudioCallback(); - EXPECT_NE(HDF_SUCCESS, AdapterTest_->CreateRender(devDesc, attrs, render)); - EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyRender(devDesc)); + EXPECT_NE(HDF_SUCCESS, AdapterTest_->CreateRender(devDesc, attrs, render, renderId)); + EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyRender(renderId)); AdapterTest_->mapAudioDevice_.insert(std::make_pair(PIN_OUT_DAUDIO_DEFAULT, "hello")); devDesc.pins = PIN_OUT_DAUDIO_DEFAULT; - EXPECT_NE(HDF_SUCCESS, AdapterTest_->CreateRender(devDesc, attrs, render)); - EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyRender(devDesc)); + EXPECT_NE(HDF_SUCCESS, AdapterTest_->CreateRender(devDesc, attrs, render, renderId)); + EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyRender(renderId)); } /** @@ -98,12 +99,15 @@ HWTEST_F(AudioAdapterInterfaceImpTest, DestroyRender_001, TestSize.Level1) AdapterTest_->extSpkCallback_ = new MockRevertIDAudioCallback(); devDesc.pins = PIN_OUT_DAUDIO_DEFAULT; - AdapterTest_->audioRender_ = new AudioRenderInterfaceImpl(adpterName, devDesc, attrs, callback); + uint32_t renderId = 0; + AdapterTest_->renderDevs_[renderId] = new AudioRenderInterfaceImpl(adpterName, devDesc, attrs, callback); AdapterTest_->spkPinInUse_ = 0; - EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyRender(devDesc)); - AdapterTest_->spkPinInUse_ = 1; - EXPECT_NE(HDF_FAILURE, AdapterTest_->DestroyRender(devDesc)); + EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyRender(renderId)); + renderId = 10; + EXPECT_EQ(HDF_FAILURE, AdapterTest_->DestroyRender(renderId)); + renderId = 1; + EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyRender(renderId)); } /** @@ -117,14 +121,15 @@ HWTEST_F(AudioAdapterInterfaceImpTest, CreateCapture_001, TestSize.Level1) AudioDeviceDescriptor devDesc; AudioSampleAttributes attrs; sptr capture = nullptr; + uint32_t capId = 0; AdapterTest_->extMicCallback_ = new MockIDAudioCallback(); - EXPECT_NE(HDF_SUCCESS, AdapterTest_->CreateCapture(devDesc, attrs, capture)); - EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyCapture(devDesc)); + EXPECT_NE(HDF_SUCCESS, AdapterTest_->CreateCapture(devDesc, attrs, capture, capId)); + EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyCapture(capId)); AdapterTest_->mapAudioDevice_.insert(std::make_pair(PIN_OUT_DAUDIO_DEFAULT, "hello")); devDesc.pins = PIN_OUT_DAUDIO_DEFAULT; - EXPECT_NE(HDF_SUCCESS, AdapterTest_->CreateCapture(devDesc, attrs, capture)); - EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyCapture(devDesc)); + EXPECT_NE(HDF_SUCCESS, AdapterTest_->CreateCapture(devDesc, attrs, capture, capId)); + EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyCapture(capId)); } /** @@ -142,11 +147,14 @@ HWTEST_F(AudioAdapterInterfaceImpTest, DestroyCapture_001, TestSize.Level1) AdapterTest_->extMicCallback_ = new MockRevertIDAudioCallback(); devDesc.pins = PIN_OUT_DAUDIO_DEFAULT; - AdapterTest_->audioCapture_ = new AudioCaptureInterfaceImpl(adpterName, devDesc, attrs, callback); + uint32_t capId = 0; + AdapterTest_->captureDevs_[capId] = new AudioCaptureInterfaceImpl(adpterName, devDesc, attrs, callback); - EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyCapture(devDesc)); - AdapterTest_->micPinInUse_ = 1; - EXPECT_NE(HDF_FAILURE, AdapterTest_->DestroyCapture(devDesc)); + EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyCapture(capId)); + capId = 10; + EXPECT_EQ(HDF_FAILURE, AdapterTest_->DestroyCapture(capId)); + capId = 1; + EXPECT_EQ(HDF_SUCCESS, AdapterTest_->DestroyCapture(capId)); } /** @@ -423,19 +431,19 @@ HWTEST_F(AudioAdapterInterfaceImpTest, AdapterUnload_001, TestSize.Level1) AudioDeviceDescriptor descSpk; AudioSampleAttributes attrsSpk; sptr callbackSpk = new MockIDAudioCallback(); - AdapterTest_->audioRender_ = new AudioRenderInterfaceImpl(adpterName, descSpk, attrsSpk, callbackSpk); + AdapterTest_->renderDevs_[0] = new AudioRenderInterfaceImpl(adpterName, descSpk, attrsSpk, callbackSpk); EXPECT_EQ(HDF_ERR_DEVICE_BUSY, AdapterTest_->AdapterUnload()); AudioDeviceDescriptor devDescMic; AudioSampleAttributes attrsMic; sptr callbackMic = new MockIDAudioCallback(); - AdapterTest_->audioCapture_ = new AudioCaptureInterfaceImpl(adpterName, devDescMic, attrsMic, callbackMic); + AdapterTest_->captureDevs_[0] = new AudioCaptureInterfaceImpl(adpterName, devDescMic, attrsMic, callbackMic); EXPECT_EQ(HDF_ERR_DEVICE_BUSY, AdapterTest_->AdapterUnload()); - AdapterTest_->audioRender_ = nullptr; + AdapterTest_->renderDevs_[0] = nullptr; EXPECT_EQ(HDF_ERR_DEVICE_BUSY, AdapterTest_->AdapterUnload()); - AdapterTest_->audioCapture_ = nullptr; + AdapterTest_->captureDevs_[0] = nullptr; EXPECT_EQ(HDF_SUCCESS, AdapterTest_->AdapterUnload()); } @@ -593,7 +601,7 @@ HWTEST_F(AudioAdapterInterfaceImpTest, CloseRenderDevice_001, TestSize.Level1) EXPECT_EQ(HDF_SUCCESS, AdapterTest_->CloseRenderDevice(devDesc)); AdapterTest_->spkPinInUse_ = 1; AdapterTest_->extSpkCallback_ = new MockIDAudioCallback(); - EXPECT_EQ(ERR_DH_AUDIO_HDF_WAIT_TIMEOUT, AdapterTest_->CloseRenderDevice(devDesc)); + EXPECT_EQ(HDF_SUCCESS, AdapterTest_->CloseRenderDevice(devDesc)); AdapterTest_->extSpkCallback_ = new MockRevertIDAudioCallback(); EXPECT_EQ(HDF_SUCCESS, AdapterTest_->CloseRenderDevice(devDesc)); } @@ -626,7 +634,7 @@ HWTEST_F(AudioAdapterInterfaceImpTest, CloseCaptureDevice_001, TestSize.Level1) AdapterTest_->extMicCallback_ = new MockIDAudioCallback(); EXPECT_EQ(HDF_SUCCESS, AdapterTest_->CloseCaptureDevice(devDesc)); AdapterTest_->micPinInUse_ = 1; - EXPECT_EQ(ERR_DH_AUDIO_HDF_WAIT_TIMEOUT, AdapterTest_->CloseCaptureDevice(devDesc)); + EXPECT_EQ(HDF_SUCCESS, AdapterTest_->CloseCaptureDevice(devDesc)); } /** @@ -669,13 +677,13 @@ HWTEST_F(AudioAdapterInterfaceImpTest, SetAudioVolume_001, TestSize.Level1) std::string param = "1"; EXPECT_NE(HDF_SUCCESS, AdapterTest_->SetAudioVolume(condition, param)); AdapterTest_->extSpkCallback_ = new MockIDAudioCallback(); - EXPECT_NE(HDF_SUCCESS, AdapterTest_->SetAudioVolume(condition, param)); + EXPECT_EQ(HDF_SUCCESS, AdapterTest_->SetAudioVolume(condition, param)); std::string adpterName = "adbcef"; AudioDeviceDescriptor desc; AudioSampleAttributes attrs; sptr callback = new MockIDAudioCallback(); - AdapterTest_->audioRender_ = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); + AdapterTest_->renderDevs_[0] = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); EXPECT_EQ(HDF_SUCCESS, AdapterTest_->SetAudioVolume(condition, param)); param = "0"; EXPECT_EQ(HDF_SUCCESS, AdapterTest_->SetAudioVolume(condition, param)); @@ -698,7 +706,7 @@ HWTEST_F(AudioAdapterInterfaceImpTest, GetAudioVolume_001, TestSize.Level1) AudioSampleAttributes attrs; sptr callback = new MockIDAudioCallback(); - AdapterTest_->audioRender_ = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); + AdapterTest_->renderDevs_[0] = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); std::string condition = "EVENT_TYPE=1;VOLUME_GROUP_ID=2;AUDIO_VOLUME_TYPE=1;"; std::string param = "1"; @@ -718,7 +726,7 @@ HWTEST_F(AudioAdapterInterfaceImpTest, GetAudioVolume_002, TestSize.Level1) AudioSampleAttributes attrs; sptr callback = new MockIDAudioCallback(); - AdapterTest_->audioRender_ = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); + AdapterTest_->renderDevs_[0] = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); std::string condition = "EVENT_TYPE=3;VOLUME_GROUP_ID=2;AUDIO_VOLUME_TYPE=1;"; std::string param = "1"; @@ -738,7 +746,7 @@ HWTEST_F(AudioAdapterInterfaceImpTest, GetAudioVolume_003, TestSize.Level1) AudioSampleAttributes attrs; sptr callback = new MockIDAudioCallback(); - AdapterTest_->audioRender_ = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); + AdapterTest_->renderDevs_[0] = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); std::string condition = "EVENT_TYPE=2;VOLUME_GROUP_ID=2;AUDIO_VOLUME_TYPE=1;"; std::string param = "1"; @@ -758,7 +766,7 @@ HWTEST_F(AudioAdapterInterfaceImpTest, GetAudioVolume_004, TestSize.Level1) AudioSampleAttributes attrs; sptr callback = new MockIDAudioCallback(); - AdapterTest_->audioRender_ = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); + AdapterTest_->renderDevs_[0] = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); std::string condition = "EVENT_TYPE=4;VOLUME_GROUP_ID=2;AUDIO_VOLUME_TYPE=1;"; std::string param = "1"; @@ -779,7 +787,7 @@ HWTEST_F(AudioAdapterInterfaceImpTest, GetAudioVolume_005, TestSize.Level1) AudioSampleAttributes attrs; sptr callback = new MockIDAudioCallback(); - AdapterTest_->audioRender_ = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); + AdapterTest_->renderDevs_[0] = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); std::string condition = "EVENT_TYPE=66;VOLUME_GROUP_ID=2;AUDIO_VOLUME_TYPE=1;"; std::string param = "1"; @@ -795,7 +803,7 @@ HWTEST_F(AudioAdapterInterfaceImpTest, GetAudioVolume_005, TestSize.Level1) */ HWTEST_F(AudioAdapterInterfaceImpTest, GetAudioVolume_006, TestSize.Level1) { - AdapterTest_->audioRender_ = nullptr; + AdapterTest_->renderDevs_[0] = nullptr; std::string condition = "EVENT_TYPE=1;VOLUME_GROUP_ID=2;AUDIO_VOLUME_TYPE=1;"; std::string param = "1"; @@ -844,10 +852,10 @@ HWTEST_F(AudioAdapterInterfaceImpTest, HandleVolumeChangeEvent_001, TestSize.Lev AudioSampleAttributes attrs; sptr callback = new MockIDAudioCallback(); - AdapterTest_->audioRender_ = nullptr; + AdapterTest_->renderDevs_[0] = nullptr; EXPECT_NE(HDF_SUCCESS, AdapterTest_->HandleVolumeChangeEvent(event)); - AdapterTest_->audioRender_ = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); + AdapterTest_->renderDevs_[0] = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); EXPECT_NE(HDF_SUCCESS, AdapterTest_->HandleVolumeChangeEvent(event)); AdapterTest_->paramCallback_ = new MockIAudioParamCallback(); EXPECT_EQ(HDF_SUCCESS, AdapterTest_->HandleVolumeChangeEvent(event)); @@ -867,7 +875,7 @@ HWTEST_F(AudioAdapterInterfaceImpTest, HandleVolumeChangeEvent_002, TestSize.Lev AudioSampleAttributes attrs; sptr callback = new MockIDAudioCallback(); - AdapterTest_->audioRender_ = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); + AdapterTest_->renderDevs_[0] = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); EXPECT_NE(HDF_SUCCESS, AdapterTest_->HandleVolumeChangeEvent(event)); } @@ -885,7 +893,7 @@ HWTEST_F(AudioAdapterInterfaceImpTest, HandleVolumeChangeEvent_003, TestSize.Lev AudioSampleAttributes attrs; sptr callback = new MockIDAudioCallback(); - AdapterTest_->audioRender_ = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); + AdapterTest_->renderDevs_[0] = new AudioRenderInterfaceImpl(adpterName, desc, attrs, callback); EXPECT_NE(HDF_SUCCESS, AdapterTest_->HandleVolumeChangeEvent(event)); } diff --git a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_test_utils/audio_test_utils.h b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_test_utils/audio_test_utils.h index bc57b7db4ad093b47b48c2df829f84cc46974f3d..c67d95828f5acb046a6e52bbbfea49ef350f10e0 100644 --- a/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_test_utils/audio_test_utils.h +++ b/hdf_service/distributed_audio/hdi_service/audio/v1_0/test/unittest/audio_test_utils/audio_test_utils.h @@ -291,7 +291,7 @@ public: MockIAudioCapture() {} ~MockIAudioCapture() {} - int32_t CaptureFrame(std::vector &frame, uint64_t requestBytes) override + int32_t CaptureFrame(std::vector &frame, uint64_t &replyBytes) override { return DistributedHardware::DH_SUCCESS; } @@ -458,7 +458,7 @@ public: } int32_t ParamCallback(AudioExtParamKey key, const std::string& condition, const std::string& value, - int8_t &reserved, int8_t &cookie) override + int8_t &reserved, int8_t cookie) override { return DistributedHardware::DH_SUCCESS; } @@ -475,7 +475,7 @@ public: } int32_t ParamCallback(AudioExtParamKey key, const std::string& condition, const std::string& value, - int8_t &reserved, int8_t &cookie) override + int8_t &reserved, int8_t cookie) override { return DistributedHardware::ERR_DH_AUDIO_HDF_FAIL; } diff --git a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/notifyevent_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/notifyevent_fuzzer/BUILD.gn index 65a49d173ee6b49d02c0687af3663203478d655e..d790b56512f1c646d735b269eb0089139158d24a 100644 --- a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/notifyevent_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/notifyevent_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("NotifyEventFuzzTest") { - module_out_path = "distributed_audio/notifyevent_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/notifyevent_fuzzer" fuzz_config_file = "${hdf_ser_aud_ext_path}/test/fuzztest/notifyevent_fuzzer" cflags = [ diff --git a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/registeraudiodevice_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/registeraudiodevice_fuzzer/BUILD.gn index 1c19630cbb853a74729eb2b197afb4239414c846..8d0f4724c7c9ebe9c17c94d00e3a7fe6c8034be2 100644 --- a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/registeraudiodevice_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/registeraudiodevice_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("RegisterAudioDeviceFuzzTest") { - module_out_path = "distributed_audio/registeraudiodevice_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/registeraudiodevice_fuzzer" fuzz_config_file = "${hdf_ser_aud_ext_path}/test/fuzztest/registeraudiodevice_fuzzer" diff --git a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/unregisteraudiodevice_fuzzer/BUILD.gn b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/unregisteraudiodevice_fuzzer/BUILD.gn index 429c90ed3aa4711296e1f3b87f72a8b1e676bf8e..0cb4c330e867f93486483647cecd1746b16c9cff 100644 --- a/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/unregisteraudiodevice_fuzzer/BUILD.gn +++ b/hdf_service/distributed_audio/hdi_service/audio_ext/v1_0/test/fuzztest/unregisteraudiodevice_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("UnRegisterAudioDeviceFuzzTest") { - module_out_path = "distributed_audio/unregisteraudiodevice_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/unregisteraudiodevice_fuzzer" fuzz_config_file = "${hdf_ser_aud_ext_path}/test/fuzztest/unregisteraudiodevice_fuzzer" diff --git a/hdf_service/distributed_audio/hdi_service/common/include/daudio_constants.h b/hdf_service/distributed_audio/hdi_service/common/include/daudio_constants.h index 56ef2fb665220d022343983c07033282a4374139..4a669ed7a5940528289b7e2da480b36f0c3242b2 100644 --- a/hdf_service/distributed_audio/hdi_service/common/include/daudio_constants.h +++ b/hdf_service/distributed_audio/hdi_service/common/include/daudio_constants.h @@ -67,6 +67,7 @@ constexpr uint32_t AUDIO_FORMAT_DEFAULT = 16; constexpr int32_t MILLISECOND_PER_SECOND = 1000; constexpr uint32_t DEFAULT_AUDIO_DATA_SIZE = 4096; constexpr int64_t AUDIO_OFFSET_FRAME_NUM = 10; +constexpr int64_t MAX_TIME_INTERVAL_US = 23000; constexpr uint32_t AUDIO_DEFAULT_MAX_VOLUME_LEVEL = 15; constexpr uint32_t AUDIO_DEFAULT_MIN_VOLUME_LEVEL = 0; diff --git a/hdf_service/distributed_audio/hdi_service/common/include/daudio_events.h b/hdf_service/distributed_audio/hdi_service/common/include/daudio_events.h index b8ef012143e536d084c9f68410ec07ed08906c0c..c4355bfe8383ffd1640f15c1b4c4603a44bb294c 100644 --- a/hdf_service/distributed_audio/hdi_service/common/include/daudio_events.h +++ b/hdf_service/distributed_audio/hdi_service/common/include/daudio_events.h @@ -65,6 +65,8 @@ typedef enum AudioExtParamEvent { HDF_AUDIO_EVENT_MMAP_STOP_MIC = 17, HDF_AUDIO_EVENT_START = 18, HDF_AUDIO_EVENT_STOP = 19, + HDF_AUDIO_EVENT_SPK_DUMP = 20, + HDF_AUDIO_EVENT_MIC_DUMP = 21, } EXT_PARAM_EVENT; typedef enum AudioVolumeEvent { diff --git a/hdf_service/distributed_audio/hdi_service/common/utils/include/daudio_utils.h b/hdf_service/distributed_audio/hdi_service/common/utils/include/daudio_utils.h index 538b913040e31c18f4a286cbd6479b66d735b4e7..0bde1ba670c0b7ea7e6230a00d8e4f9b86a4e436 100644 --- a/hdf_service/distributed_audio/hdi_service/common/utils/include/daudio_utils.h +++ b/hdf_service/distributed_audio/hdi_service/common/utils/include/daudio_utils.h @@ -16,6 +16,7 @@ #ifndef OHOS_DAUDIO_UTILS_H #define OHOS_DAUDIO_UTILS_H +#include #include #define AUDIO_MS_PER_SECOND 1000 @@ -37,6 +38,8 @@ int32_t SetAudioParamStr(std::string ¶ms, const std::string &key, const std: int32_t GetDevTypeByDHId(int32_t dhId); +int64_t GetNowTimeUs(); + uint32_t CalculateFrameSize(uint32_t sampleRate, uint32_t channelCount, int32_t format, uint32_t timeInterval, bool isMMAP); @@ -49,6 +52,10 @@ int32_t AbsoluteSleep(int64_t nanoTime); int64_t CalculateOffset(const int64_t frameindex, const int64_t framePeriodNs, const int64_t startTime); int64_t UpdateTimeOffset(const int64_t frameIndex, const int64_t framePeriodNs, int64_t &startTime); + +bool IsOutDurationRange(int64_t startTime, int64_t endTime, int64_t lastStartTime); + +void SaveFile(std::string fileName, uint8_t *audioData, int32_t size); } // DistributedHardware } // OHOS #endif \ No newline at end of file diff --git a/hdf_service/distributed_audio/hdi_service/common/utils/src/daudio_utils.cpp b/hdf_service/distributed_audio/hdi_service/common/utils/src/daudio_utils.cpp index 0ab0bb45fb031c354951a52ea5ee86646c76d683..0e3c0f61632871efc84025f791171df70bfb33ef 100644 --- a/hdf_service/distributed_audio/hdi_service/common/utils/src/daudio_utils.cpp +++ b/hdf_service/distributed_audio/hdi_service/common/utils/src/daudio_utils.cpp @@ -105,6 +105,13 @@ int32_t GetDevTypeByDHId(int32_t dhId) return AUDIO_DEVICE_TYPE_UNKNOWN; } +int64_t GetNowTimeUs() +{ + std::chrono::microseconds nowUs = + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); + return nowUs.count(); +} + uint32_t CalculateFrameSize(uint32_t sampleRate, uint32_t channelCount, int32_t format, uint32_t timeInterval, bool isMMAP) { @@ -161,5 +168,22 @@ int64_t UpdateTimeOffset(const int64_t frameIndex, const int64_t framePeriodNs, } return timeOffset; } + +bool IsOutDurationRange(int64_t startTime, int64_t endTime, int64_t lastStartTime) +{ + int64_t currentInterval = endTime - startTime; + int64_t twiceInterval = startTime - lastStartTime; + return (currentInterval > MAX_TIME_INTERVAL_US || twiceInterval > MAX_TIME_INTERVAL_US) ? true : false; +} + +void SaveFile(std::string fileName, uint8_t *audioData, int32_t size) +{ + std::ofstream ofs(fileName, std::ios::binary | std::ios::out | std::ios::app); + if (!ofs.is_open()) { + return; + } + ofs.write(reinterpret_cast(audioData), size); + ofs.close(); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesinksvrdied_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesinksvrdied_fuzzer/BUILD.gn index 4d3a0fe429da8fc149aa0c453024243ccd2f7828..ad55ca60deb4957a589b67f805daf90cd0fe63c0 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesinksvrdied_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesinksvrdied_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("OnRemoteSinkSvrDiedFuzzTest") { - module_out_path = "distributed_audio/onremotesinksvrdied" + module_out_path = "${distributedaudio_fuzz_path}/onremotesinksvrdied" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/onremotesinksvrdied_fuzzer" diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesourcesvrdied_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesourcesvrdied_fuzzer/BUILD.gn index 5b811441a9bb99e3ab5288819a4d4ef0ca4e4fde..8dbdf65f3b7f43d66025c0da82c114a054c43c2b 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesourcesvrdied_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onremotesourcesvrdied_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("OnRemoteSourceSvrDiedFuzzTest") { - module_out_path = "distributed_audio/onremotesourcesvrdied" + module_out_path = "${distributedaudio_fuzz_path}/onremotesourcesvrdied" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/onremotesourcesvrdied_fuzzer" diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerfinishstartsa_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerfinishstartsa_fuzzer/BUILD.gn index 37e33567fb830b496effe6c9f599855b7de54676..adcebb67dc1f62a746a916059f31f34c38024c38 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerfinishstartsa_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerfinishstartsa_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkHandlerFinishStartSAFuzzTest") { - module_out_path = "distributed_audio/sinkhandlerfinishstartsa" + module_out_path = "${distributedaudio_fuzz_path}/sinkhandlerfinishstartsa" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerfinishstartsa_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn index 408b773fd63b6c9f673c62dfcf4896b610d2b6da..bf05e3407c0d53e00b3c63babab8246872e90966 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkHandlerInitSinkFuzzTest") { - module_out_path = "distributed_audio/sinkhandlerinitsink" + module_out_path = "${distributedaudio_fuzz_path}/sinkhandlerinitsink" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer" diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn index 929a4d0b4972c18b4dd7f49a6a6ccdb0db60d545..2b6dc2b6fd561f5c4c3b7f25d59ae733ddeea99e 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkHandlerSubscribeLocalHardwareFuzzTest") { - module_out_path = "distributed_audio/sinkhandlersubscribelocalhardware" + module_out_path = + "${distributedaudio_fuzz_path}/sinkhandlersubscribelocalhardware" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn index 39cf7a4c359ea70fc8bbade57b0bfddaf54d04bf..ff36b408470908f08256353d325b5e6aa6324af9 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkHandlerUnsubscribeLocalHardwareFuzzTest") { - module_out_path = "distributed_audio/sinkhandlerunsubscribelocalhardware" + module_out_path = + "${distributedaudio_fuzz_path}/sinkhandlerunsubscribelocalhardware" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn index b9ef3e3d7b8cf970ab4d40c3db2b6058e7bb3208..dcdf3f882387f7916fde27354533fc11ead97533 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkOnLoadSystemAbilityFailFuzzTest") { - module_out_path = "distributed_audio/sinkonloadsystemabilityfail" + module_out_path = "${distributedaudio_fuzz_path}/sinkonloadsystemabilityfail" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn index f28ada6f99551c3b33cbe94755135c8318ad5163..2fa40a62b57fb58c1ea03df9b1c38c92013692f2 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkOnLoadSystemAbilitySuccessFuzzTest") { - module_out_path = "distributed_audio/sinkonloadsystemabilitysuccess" + module_out_path = + "${distributedaudio_fuzz_path}/sinkonloadsystemabilitysuccess" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxydaudionotify_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxydaudionotify_fuzzer/BUILD.gn index a185325cc88b55ab8a6070240edc700f4e418599..aad75daba2008e70ce2348145f8db5289ce34a69 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxydaudionotify_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxydaudionotify_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkProxyDAudioNotifyFuzzTest") { - module_out_path = "distributed_audio/sinkproxydaudionotify" + module_out_path = "${distributedaudio_fuzz_path}/sinkproxydaudionotify" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkproxydaudionotify_fuzzer" diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/BUILD.gn index 4a8b1298c06b6447ea9bd652dcdcc69f633663f2..a45b3f1247265d34a6c10f84ba89e167b577a233 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkProxyInitSinkFuzzTest") { - module_out_path = "distributed_audio/sinkproxyinitsink" + module_out_path = "${distributedaudio_fuzz_path}/sinkproxyinitsink" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer" diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn index 1bb9fbcb82aaeb47193c1a5425a6a18f358f9b7d..58299f323357ea3012ea0e841428ddc30b07adc8 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkProxySubscribeLocalHardwareFuzzTest") { - module_out_path = "distributed_audio/sinkproxysubscribelocalhardware" + module_out_path = + "${distributedaudio_fuzz_path}/sinkproxysubscribelocalhardware" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkproxysubscribelocalhardware_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn index 474b0f86ea840771fcb7697aa89c9f9d30f95516..215f659db53a0d6cfb3809f605cd9fe60c3b0d92 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkProxyUnsubscribeLocalHardwareFuzzTest") { - module_out_path = "distributed_audio/sinkproxyunsubscribelocalhardware" + module_out_path = + "${distributedaudio_fuzz_path}/sinkproxyunsubscribelocalhardware" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkproxyunsubscribelocalhardware_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/BUILD.gn index 8871b1862b58e4352cce710b2d687a41a45aca9d..85ab060a95e7ab4d89c0705d4dc5e87d4581edb9 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceHandlerConfigDistributedHardwareFuzzTest") { - module_out_path = "distributed_audio/sourcehandlerconfigdistributedhardware" + module_out_path = + "${distributedaudio_fuzz_path}/sourcehandlerconfigdistributedhardware" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerfinishstartsa_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerfinishstartsa_fuzzer/BUILD.gn index 44efd046c91d22c390a25ab2ba989ed586f66892..bc7b3b00d1bc43573acc6e5019b04c7c22bfc5ac 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerfinishstartsa_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerfinishstartsa_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceHandlerFinishStartSAFuzzTest") { - module_out_path = "distributed_audio/sourcehandlerfinishstartsa" + module_out_path = "${distributedaudio_fuzz_path}/sourcehandlerfinishstartsa" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourcehandlerfinishstartsa_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/BUILD.gn index 34200f70dc8c1114517fc8a0d4fa29455fa0464e..e6ef4e17770712c5a11d6b7c3e68aa9e02547dd5 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceHandlerInitSourceFuzzTest") { - module_out_path = "distributed_audio/sourcehandlerinitsource" + module_out_path = "${distributedaudio_fuzz_path}/sourcehandlerinitsource" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn index 073c3393da2fc7f131d9e0c9c31de25d547d5ce8..ad7dbe68609a25eab358e683500b5ae413f710e0 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceHandlerRegisterDistributedHardwareFuzzTest") { - module_out_path = "distributed_audio/sourcehandlerregisterdistributedhardware" + module_out_path = + "${distributedaudio_fuzz_path}/sourcehandlerregisterdistributedhardware" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn index 9e16e368b74f5c44fb3ffeee391a9e8950496357..648c5812c708d5c9230ba60c72035702d37ba29e 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn @@ -19,7 +19,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceHandlerUnregisterDistributedHardwareFuzzTest") { module_out_path = - "distributed_audio/sourcehandlerunregisterdistributedhardware" + "${distributedaudio_fuzz_path}/sourcehandlerunregisterdistributedhardware" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyregresult_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyregresult_fuzzer/BUILD.gn index fdd640b3da5d39d1abe91f39806c67c008d2866f..7662fb7472c2cd548f94c17fe7f72afb5a76b68f 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyregresult_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyregresult_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceIpcCallbackOnNotifyRegResultFuzzTest") { - module_out_path = "distributed_audio/sourceipccallbackonnotifyregresult" + module_out_path = + "${distributedaudio_fuzz_path}/sourceipccallbackonnotifyregresult" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceipccallbackonnotifyregresult_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyunregresult_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyunregresult_fuzzer/BUILD.gn index 3626682942fc9b39eaaac21b186f34e96e939c06..f2809b121cd7d13bedb971eb8763353bd683a334 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyunregresult_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceipccallbackonnotifyunregresult_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceIpcCallbackOnNotifyUnregResultFuzzTest") { - module_out_path = "distributed_audio/sourceipccallbackonnotifyunregresult" + module_out_path = + "${distributedaudio_fuzz_path}/sourceipccallbackonnotifyunregresult" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceipccallbackonnotifyunregresult_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/BUILD.gn index c65e84baf5d21b763d66813636051b189c572df4..6774d3f80a05c3ce20dcc4c4b7c4d430aebdfcd0 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceOnLoadSystemAbilityFailFuzzTest") { - module_out_path = "distributed_audio/sourceonloadsystemabilityfail" + module_out_path = + "${distributedaudio_fuzz_path}/sourceonloadsystemabilityfail" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/BUILD.gn index feea7683cc70cc402837a099f57cbd3f1ee4eee5..36165a233db8334359166d7c08fd24183100810a 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceOnLoadSystemAbilitySuccessFuzzTest") { - module_out_path = "distributed_audio/sourceonloadsystemabilitysuccess" + module_out_path = + "${distributedaudio_fuzz_path}/sourceonloadsystemabilitysuccess" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyconfigdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyconfigdistributedhardware_fuzzer/BUILD.gn index 2270ad2029aa137dfe45bb35461f1ad628e07ecb..b76999fb48393a643f2e0fa0a61841c92439f066 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyconfigdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyconfigdistributedhardware_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceProxyConfigDistributedHardwareFuzzTest") { - module_out_path = "distributed_audio/sourceproxyconfigdistributedhardware" + module_out_path = + "${distributedaudio_fuzz_path}/sourceproxyconfigdistributedhardware" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceproxyconfigdistributedhardware_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydaudionotify_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydaudionotify_fuzzer/BUILD.gn index 8f4c0eed002a812f63524b37a6537226a2a48e9b..bca45d2b2e35037e343a42e7cda8032e1f42ab6f 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydaudionotify_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydaudionotify_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceProxyDAudioNotifyFuzzTest") { - module_out_path = "distributed_audio/sourceproxydaudionotify" + module_out_path = "${distributedaudio_fuzz_path}/sourceproxydaudionotify" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceproxydaudionotify_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/BUILD.gn index 15b61b4083de782dfbada21be113e0336e4ae20e..c5ecc8d6987b00aef5dab4251233293d95c566c0 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceProxyInitSourceFuzzTest") { - module_out_path = "distributed_audio/sourceproxyinitsource" + module_out_path = "${distributedaudio_fuzz_path}/sourceproxyinitsource" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer" diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/BUILD.gn index 78671f57fd5374e5b5002d0099176257ad85a959..3f7d8fb2b4491c37013005db8f0983e7f5f9f5fb 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceProxyRegisterDistributedHardwareFuzzTest") { - module_out_path = "distributed_audio/sourceproxyregisterdistributedhardware" + module_out_path = + "${distributedaudio_fuzz_path}/sourceproxyregisterdistributedhardware" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer" cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/BUILD.gn index 9fb1a54530a966c9ec168ea58c808c230f4a28f7..cdcb888c65fc653c8d05c64aa2994d9123178c3d 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceProxyUnregisterDistributedHardwareFuzzTest") { - module_out_path = "distributed_audio/sourceproxyunregisterdistributedhardware" + module_out_path = + "${distributedaudio_fuzz_path}/sourceproxyunregisterdistributedhardware" fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer" cflags = [ diff --git a/services/audioclient/micclient/include/dmic_client.h b/services/audioclient/micclient/include/dmic_client.h index edd6190f3c162e5e4ed722d1571fdc776c8d2214..d483980102b49148b062f00b2332ca64d35f3725 100644 --- a/services/audioclient/micclient/include/dmic_client.h +++ b/services/audioclient/micclient/include/dmic_client.h @@ -40,6 +40,9 @@ #include "iaudio_event_callback.h" #include "imic_client.h" +#include "v1_0/audio_types.h" +#include "v1_0/iaudio_manager.h" + namespace OHOS { namespace DistributedHardware { class DMicClient : public IAudioDataTransCallback, @@ -62,6 +65,25 @@ public: void SetAttrs(const std::string &devId, const std::shared_ptr &callback) override; int32_t SendMessage(uint32_t type, std::string content, std::string dstDevId) override; + void AdapterDescFree(struct AudioAdapterDescriptor *dataBlock, bool freeSelf); + void ReleaseAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen); + int32_t GetAudioManager(); + int32_t GetAdapter(); + int32_t GetPrimaryDesc(struct AudioAdapterDescriptor *descs, struct AudioAdapterDescriptor + **primaryDesc); + void ReleaseHDFAudioDevice(); + int32_t InitHDFAudioDevice(); + void GenerateAttr(const AudioParam ¶m); + int32_t AudioFwkClientSetUp(); + int32_t HdfClientSetUp(); + int32_t TransSetUp(); + int32_t HdfClientRelease(); + int32_t TransRelease(); + int32_t HdfClientStartCapture(); + void HdfCaptureAudioData(uint32_t lengthPerCapture, const uint32_t lengthPerTrans, + const uint32_t len); + void AudioFwkCaptureData(); + void OnReadData(size_t length) override; private: void CaptureThreadRunning(); @@ -69,6 +91,7 @@ private: private: constexpr static uint8_t CHANNEL_WAIT_SECONDS = 5; static constexpr const char* CAPTURETHREAD = "captureThread"; + const std::string FILE_NAME = "/data/sink_mic_send.pcm"; std::string devId_; std::thread captureDataThread_; @@ -81,6 +104,29 @@ private: std::weak_ptr eventCallback_; std::unique_ptr audioCapturer_ = nullptr; std::shared_ptr micTrans_ = nullptr; + int64_t lastCaptureStartTime_ = 0; + int64_t lastTransStartTime_ = 0; + + constexpr static uint8_t PORT_ID = 11; + constexpr static size_t FRAME_PER_SECOND = 50; + constexpr static size_t MAX_AUDIO_ADAPTER_DESC = 5; + constexpr static size_t PATH_LEN = 256; + constexpr static size_t INT_32_MAX = 0x7fffffff; + constexpr static size_t BUFFER_PERIOD_SIZE = 4096; + constexpr static size_t AUDIO_BUFFER_SIZE = 16384; + constexpr static size_t FORMATNUM = 2; + static constexpr const char* ADAPTERNAME = "primary"; + static constexpr const char* DEVNAME = "devName"; + + char adapterName_[PATH_LEN] = {0}; + struct IAudioManager *audioManager_ = nullptr; + struct IAudioAdapter *audioAdapter_ = nullptr; + struct IAudioCapture *hdfCapture_ = nullptr; + uint32_t captureId_ = 0; + int64_t frameIndex_ = 0; + bool micInUse_ = false; + struct AudioDeviceDescriptor captureDesc_; + struct AudioSampleAttributes captureAttr_; }; } // DistributedHardware } // OHOS diff --git a/services/audioclient/micclient/src/dmic_client.cpp b/services/audioclient/micclient/src/dmic_client.cpp index 533fecf2484bf04ad9bab25f87dd0b0a761948fa..99d89382854ccae115b04067b9bbade19d94f627 100644 --- a/services/audioclient/micclient/src/dmic_client.cpp +++ b/services/audioclient/micclient/src/dmic_client.cpp @@ -19,6 +19,7 @@ #include "daudio_constants.h" #include "daudio_hisysevent.h" +#include "daudio_sink_hidumper.h" #include "daudio_sink_manager.h" #undef DH_LOG_TAG @@ -78,10 +79,11 @@ int32_t DMicClient::OnStateChange(const AudioEventType type) switch (type) { case AudioEventType::DATA_OPENED: { isBlocking_.store(true); - if (audioParam_.captureOpts.capturerFlags != MMAP_MODE) { - isCaptureReady_.store(true); - captureDataThread_ = std::thread(&DMicClient::CaptureThreadRunning, this); + isCaptureReady_.store(true); + if (audioParam_.captureOpts.capturerFlags == MMAP_MODE) { + frameIndex_ = 0; } + captureDataThread_ = std::thread(&DMicClient::CaptureThreadRunning, this); event.type = AudioEventType::MIC_OPENED; break; } @@ -103,13 +105,166 @@ int32_t DMicClient::OnStateChange(const AudioEventType type) return DH_SUCCESS; } -int32_t DMicClient::SetUp(const AudioParam ¶m) +void DMicClient::AdapterDescFree(struct AudioAdapterDescriptor *dataBlock, bool freeSelf) +{ + if (dataBlock == nullptr) { + return; + } + if (dataBlock->adapterName != nullptr) { + free(dataBlock->adapterName); + dataBlock->adapterName = nullptr; + } + if (dataBlock->ports != nullptr) { + free(dataBlock->ports); + dataBlock->ports = nullptr; + } + if (freeSelf) { + free(dataBlock); + dataBlock = nullptr; + } +} + +void DMicClient::ReleaseAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen) +{ + if (descsLen > 0 && descs != nullptr && (*descs) != nullptr) { + for (uint32_t i = 0; i < descsLen; i++) { + AdapterDescFree(&(*descs)[i], false); + } + free(*descs); + *descs = nullptr; + } +} + +int32_t DMicClient::GetAudioManager() +{ + audioManager_ = IAudioManagerGet(false); + if (audioManager_ == nullptr) { + DHLOGE("Get audio manager fail"); + return ERR_DH_AUDIO_FAILED; + } + return DH_SUCCESS; +} + +int32_t DMicClient::GetAdapter() +{ + size_t adapterSize = sizeof(struct AudioAdapterDescriptor) * (MAX_AUDIO_ADAPTER_DESC); + struct AudioAdapterDescriptor *descs = reinterpret_cast(malloc(adapterSize)); + if (descs == nullptr) { + DHLOGE("malloc for descs failed"); + return ERR_DH_AUDIO_FAILED; + } + if (memset_s(descs, adapterSize, 0, adapterSize) != EOK) { + DHLOGE("memset for descs failed"); + ReleaseAdapterDescs(&descs, MAX_AUDIO_ADAPTER_DESC); + return ERR_DH_AUDIO_FAILED; + } + uint32_t size = MAX_AUDIO_ADAPTER_DESC; + if (audioManager_ == nullptr) { + DHLOGE("AudioManager is nullptr"); + ReleaseAdapterDescs(&descs, MAX_AUDIO_ADAPTER_DESC); + return ERR_DH_AUDIO_FAILED; + } + int32_t ret = audioManager_->GetAllAdapters(audioManager_, descs, &size); + if (size == 0 || descs == nullptr || ret != 0) { + DHLOGE("Get audio adapters failed. ret : %d.", ret); + ReleaseAdapterDescs(&descs, MAX_AUDIO_ADAPTER_DESC); + return ERR_DH_AUDIO_FAILED; + } + struct AudioAdapterDescriptor *primaryDesc = nullptr; + if (GetPrimaryDesc(descs, &primaryDesc) != DH_SUCCESS) { + return ERR_DH_AUDIO_FAILED; + } + ret = audioManager_->LoadAdapter(audioManager_, primaryDesc, &audioAdapter_); + if (ret != DH_SUCCESS || audioAdapter_ == nullptr) { + DHLOGE("Load primary adapter failed."); + ReleaseAdapterDescs(&descs, MAX_AUDIO_ADAPTER_DESC); + return ERR_DH_AUDIO_FAILED; + } + ReleaseAdapterDescs(&descs, MAX_AUDIO_ADAPTER_DESC); + (void)audioAdapter_->InitAllPorts(audioAdapter_); + return DH_SUCCESS; +} + +int32_t DMicClient::GetPrimaryDesc(struct AudioAdapterDescriptor *descs, struct AudioAdapterDescriptor + **primaryDesc) +{ + uint32_t size = MAX_AUDIO_ADAPTER_DESC; + for (uint32_t index = 0; index < size; index++) { + auto desc = &descs[index]; + if (desc == nullptr || desc->adapterName == nullptr) { + continue; + } + if (!strcmp(desc->adapterName, ADAPTERNAME)) { + *primaryDesc = desc; + break; + } + } + if (*primaryDesc == nullptr) { + DHLOGE("Find primary adapter failed."); + ReleaseAdapterDescs(&descs, MAX_AUDIO_ADAPTER_DESC); + return ERR_DH_AUDIO_FAILED; + } + if (strcpy_s(adapterName_, PATH_LEN, (*primaryDesc)->adapterName) < 0) { + DHLOGE("Strcpy adapter name failed."); + ReleaseAdapterDescs(&descs, MAX_AUDIO_ADAPTER_DESC); + return ERR_DH_AUDIO_FAILED; + } + return DH_SUCCESS; +} + +void DMicClient::ReleaseHDFAudioDevice() +{ + if (micInUse_) { + return; + } + if (audioManager_ != nullptr && audioManager_->UnloadAdapter != nullptr) { + audioManager_->UnloadAdapter(audioManager_, adapterName_); + IAudioAdapterRelease(audioAdapter_, false); + audioAdapter_ = nullptr; + IAudioManagerRelease(audioManager_, false); + audioManager_ = nullptr; + } +} + +int32_t DMicClient::InitHDFAudioDevice() +{ + if (micInUse_) { + return DH_SUCCESS; + } + if (GetAudioManager() != DH_SUCCESS) { + DHLOGE("Get audio manager failed"); + ReleaseHDFAudioDevice(); + return ERR_DH_AUDIO_FAILED; + } + + if (GetAdapter() != DH_SUCCESS) { + DHLOGE("Get audio adapter failed"); + ReleaseHDFAudioDevice(); + return ERR_DH_AUDIO_FAILED; + } + return DH_SUCCESS; +} + +void DMicClient::GenerateAttr(const AudioParam ¶m) +{ + captureDesc_.portId = PORT_ID; + captureDesc_.pins = AudioPortPin::PIN_IN_MIC; + captureDesc_.desc = strdup(DEVNAME); + captureAttr_.format = AUDIO_FORMAT_TYPE_PCM_16_BIT; + captureAttr_.interleaved = 0; + captureAttr_.type = AUDIO_IN_MEDIA; + captureAttr_.period = BUFFER_PERIOD_SIZE; + captureAttr_.isBigEndian = false; + captureAttr_.isSignedData = true; + captureAttr_.stopThreshold = INT_32_MAX; + captureAttr_.silenceThreshold = AUDIO_BUFFER_SIZE; + captureAttr_.channelCount = param.comParam.channelMask; + captureAttr_.sampleRate = param.comParam.sampleRate; + captureAttr_.sourceType = 1; +} + +int32_t DMicClient::AudioFwkClientSetUp() { - DHLOGI("Set up mic client, param: {sampleRate: %d, bitFormat: %d," + - "channelMask: %d, sourceType: %d, capturerFlags: %d, frameSize: %d}.", - param.comParam.sampleRate, param.comParam.bitFormat, param.comParam.channelMask, param.captureOpts.sourceType, - param.captureOpts.capturerFlags, param.comParam.frameSize); - audioParam_ = param; AudioStandard::AudioCapturerOptions capturerOptions = { { static_cast(audioParam_.comParam.sampleRate), @@ -119,7 +274,7 @@ int32_t DMicClient::SetUp(const AudioParam ¶m) }, { static_cast(audioParam_.captureOpts.sourceType), - audioParam_.captureOpts.capturerFlags == MMAP_MODE ? AudioStandard::STREAM_FLAG_FAST : 0, + 0, } }; std::lock_guard lck(devMtx_); @@ -135,7 +290,34 @@ int32_t DMicClient::SetUp(const AudioParam ¶m) return ERR_DH_AUDIO_CLIENT_CREATE_CAPTURER_FAILED; } } + return TransSetUp(); +} + +int32_t DMicClient::HdfClientSetUp() +{ + if (InitHDFAudioDevice() != DH_SUCCESS) { + DHLOGE("Init hdf audio device failed."); + return ERR_DH_AUDIO_FAILED; + } + GenerateAttr(audioParam_); + if (audioAdapter_ == nullptr) { + DHLOGE("audio adapter is null"); + return ERR_DH_AUDIO_FAILED; + } + int32_t ret = audioAdapter_->CreateCapture(audioAdapter_, &captureDesc_, &captureAttr_, + &hdfCapture_, &captureId_); + if (ret != DH_SUCCESS || hdfCapture_ == nullptr) { + DHLOGE("CreateCapture failed, ret: %d.", ret); + return ERR_DH_AUDIO_FAILED; + } + micInUse_ = true; + DHLOGI("Create hdf audio capture success"); + return TransSetUp(); +} + +int32_t DMicClient::TransSetUp() +{ if (micTrans_ == nullptr) { DHLOGE("mic trans in engine should be init by dev."); return ERR_DH_AUDIO_NULLPTR; @@ -149,6 +331,84 @@ int32_t DMicClient::SetUp(const AudioParam ¶m) return DH_SUCCESS; } +int32_t DMicClient::HdfClientRelease() +{ + DHLOGI("Release hdf mic client."); + if (audioAdapter_ != nullptr) { + audioAdapter_->DestroyCapture(audioAdapter_, captureId_); + } + IAudioCaptureRelease(hdfCapture_, false); + hdfCapture_ = nullptr; + micInUse_ = false; + ReleaseHDFAudioDevice(); + DHLOGI("Release hdf audio capture success."); + return TransRelease(); +} + +int32_t DMicClient::TransRelease() +{ + if (micTrans_ == nullptr) { + DHLOGE("Mic trans is nullptr."); + return ERR_DH_AUDIO_FAILED; + } + if (micTrans_->Release() != DH_SUCCESS) { + DHLOGE("Mic trans release failed."); + } + micTrans_ = nullptr; + clientStatus_ = AudioStatus::STATUS_IDLE; + return DH_SUCCESS; +} + +int32_t DMicClient::HdfClientStartCapture() +{ + if (hdfCapture_ == nullptr) { + DHLOGE("Audio capturer is nullptr, can not start."); + return ERR_DH_AUDIO_FAILED; + } + hdfCapture_->Start(hdfCapture_); + DHLOGI("Start hdf capture success."); + return DH_SUCCESS; +} + +void DMicClient::HdfCaptureAudioData(uint32_t lengthPerCapture, const uint32_t lengthPerTrans, + const uint32_t len) +{ + auto audioData = std::make_shared(lengthPerCapture); + uint64_t size = 0; + if (hdfCapture_ == nullptr) { + DHLOGE("hdf capture is nullptr."); + return; + } + hdfCapture_->CaptureFrame(hdfCapture_, reinterpret_cast(audioData->Data()), + &lengthPerCapture, &size); + DHLOGD("CaptureFrame success, framesize: %d", lengthPerCapture); + + for (uint32_t i = 0; i < len; i++) { + std::shared_ptr data = std::make_shared(lengthPerTrans); + if (memcpy_s(data->Data(), lengthPerTrans, audioData->Data() + lengthPerTrans * i, + lengthPerTrans) != EOK) { + DHLOGE("Copy audio data %d failed.", i); + } + int32_t ret = micTrans_->FeedAudioData(data); + if (ret != DH_SUCCESS) { + DHLOGE("Failed to send data %d.", i); + } + } +} + +int32_t DMicClient::SetUp(const AudioParam ¶m) +{ + DHLOGI("Set up mic client, param: {sampleRate: %d, bitFormat: %d," + + "channelMask: %d, sourceType: %d, capturerFlags: %d, frameSize: %d}.", + param.comParam.sampleRate, param.comParam.bitFormat, param.comParam.channelMask, param.captureOpts.sourceType, + param.captureOpts.capturerFlags, param.comParam.frameSize); + audioParam_ = param; + if (audioParam_.captureOpts.capturerFlags == MMAP_MODE) { + return HdfClientSetUp(); + } + return AudioFwkClientSetUp(); +} + int32_t DMicClient::SendMessage(uint32_t type, std::string content, std::string dstDevId) { DHLOGI("Send message to remote."); @@ -174,41 +434,39 @@ int32_t DMicClient::Release() DHLOGE("Mic status is wrong or mic trans is null, %d.", (int32_t)clientStatus_); return ERR_DH_AUDIO_SA_STATUS_ERR; } - bool status = true; - if (!audioCapturer_->Release()) { - DHLOGE("Audio capturer release failed."); - status = false; - } - int32_t ret = micTrans_->Release(); - if (ret != DH_SUCCESS) { - DHLOGE("Mic trans release failed."); - status = false; + if (audioParam_.captureOpts.capturerFlags == MMAP_MODE) { + return HdfClientRelease(); } - micTrans_ = nullptr; - clientStatus_ = AudioStatus::STATUS_IDLE; - if (!status) { - return ERR_DH_AUDIO_FAILED; + if (audioCapturer_ == nullptr || !audioCapturer_->Release()) { + DHLOGE("Audio capturer release failed."); } - return DH_SUCCESS; + return TransRelease(); } int32_t DMicClient::StartCapture() { DHLOGI("Start capturer."); std::lock_guard lck(devMtx_); - if (audioCapturer_ == nullptr || micTrans_ == nullptr || clientStatus_ != AudioStatus::STATUS_READY) { + if (micTrans_ == nullptr || clientStatus_ != AudioStatus::STATUS_READY) { DHLOGE("Audio capturer init failed or mic status wrong, status: %d.", (int32_t)clientStatus_); DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ERR_DH_AUDIO_SA_STATUS_ERR, "daudio init failed or mic status wrong."); return ERR_DH_AUDIO_SA_STATUS_ERR; } - - if (!audioCapturer_->Start()) { - DHLOGE("Audio capturer start failed."); - audioCapturer_->Release(); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ERR_DH_AUDIO_CLIENT_CAPTURER_START_FAILED, - "daudio capturer start failed."); - return ERR_DH_AUDIO_CLIENT_CAPTURER_START_FAILED; + if (audioParam_.captureOpts.capturerFlags == MMAP_MODE) { + HdfClientStartCapture(); + } else { + if (audioCapturer_ == nullptr) { + DHLOGE("audio capturer is nullptr."); + return ERR_DH_AUDIO_CLIENT_CAPTURER_START_FAILED; + } + if (!audioCapturer_->Start()) { + DHLOGE("Audio capturer start failed."); + audioCapturer_->Release(); + DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, + ERR_DH_AUDIO_CLIENT_CAPTURER_START_FAILED, "daudio capturer start failed."); + return ERR_DH_AUDIO_CLIENT_CAPTURER_START_FAILED; + } } int32_t ret = micTrans_->Start(); if (ret != DH_SUCCESS) { @@ -221,33 +479,76 @@ int32_t DMicClient::StartCapture() return DH_SUCCESS; } +void DMicClient::AudioFwkCaptureData() +{ + std::shared_ptr audioData = std::make_shared(audioParam_.comParam.frameSize); + size_t bytesRead = 0; + bool errorFlag = false; + int64_t startTime = GetNowTimeUs(); + if (audioCapturer_ == nullptr) { + DHLOGE("audio capturer is nullptr"); + return; + } + while (bytesRead < audioParam_.comParam.frameSize) { + int32_t len = audioCapturer_->Read(*(audioData->Data() + bytesRead), + audioParam_.comParam.frameSize - bytesRead, isBlocking_.load()); + if (len >= 0) { + bytesRead += static_cast(len); + } else { + errorFlag = true; + break; + } + int64_t endTime = GetNowTimeUs(); + if (IsOutDurationRange(startTime, endTime, lastCaptureStartTime_)) { + DHLOGE("This time capture spend: %lld, The interval of capture this time and the last time: %lld", + endTime - startTime, startTime - lastCaptureStartTime_); + } + lastCaptureStartTime_ = startTime; + } + if (errorFlag) { + DHLOGE("Bytes read failed."); + return; + } +#ifdef DUMP_DMICCLIENT_FILE + if (DaudioSinkHidumper::GetInstance().GetFlagStatus()) { + SaveFile(FILE_NAME, const_cast(audioData->Data()), audioData->Size()); + } +#endif + int64_t startTransTime = GetNowTimeUs(); + int32_t ret = micTrans_->FeedAudioData(audioData); + if (ret != DH_SUCCESS) { + DHLOGE("Failed to send data."); + } + int64_t endTransTime = GetNowTimeUs(); + if (IsOutDurationRange(startTransTime, endTransTime, lastTransStartTime_)) { + DHLOGE("This time send data spend: %lld, The interval of send data this time and the last time: %lld", + endTransTime - startTransTime, startTransTime - lastTransStartTime_); + } + lastTransStartTime_ = startTransTime; +} + void DMicClient::CaptureThreadRunning() { DHLOGD("Start the capturer thread."); if (pthread_setname_np(pthread_self(), CAPTURETHREAD) != DH_SUCCESS) { DHLOGE("Capture data thread setname failed."); } + uint32_t lengthPerCapture; + uint32_t lengthPerTrans; + uint32_t len; + if (audioParam_.captureOpts.capturerFlags == MMAP_MODE) { + lengthPerCapture = (audioParam_.comParam.sampleRate * audioParam_.comParam.bitFormat * + FORMATNUM * audioParam_.comParam.channelMask) / FRAME_PER_SECOND; + lengthPerTrans = audioParam_.comParam.frameSize; + len = lengthPerCapture / lengthPerTrans; + } while (isCaptureReady_.load()) { - std::shared_ptr audioData = std::make_shared(audioParam_.comParam.frameSize); - size_t bytesRead = 0; - bool errorFlag = false; - while (bytesRead < audioParam_.comParam.frameSize) { - int32_t len = audioCapturer_->Read(*(audioData->Data() + bytesRead), - audioParam_.comParam.frameSize - bytesRead, isBlocking_.load()); - if (len >= 0) { - bytesRead += static_cast(len); - } else { - errorFlag = true; - break; - } - } - if (errorFlag) { - DHLOGE("Bytes read failed."); - break; - } - int32_t ret = micTrans_->FeedAudioData(audioData); - if (ret != DH_SUCCESS) { - DHLOGE("Failed to send data."); + if (audioParam_.captureOpts.capturerFlags == MMAP_MODE) { + DHLOGD("Capture frameIndex: %lld.", frameIndex_); + HdfCaptureAudioData(lengthPerCapture, lengthPerTrans, len); + ++frameIndex_; + } else { + AudioFwkCaptureData(); } } } @@ -298,7 +599,7 @@ int32_t DMicClient::StopCapture() "daudio capturer is not start or mic status wrong."); return ERR_DH_AUDIO_SA_STATUS_ERR; } - if (audioCapturer_ == nullptr || micTrans_ == nullptr) { + if (micTrans_ == nullptr) { DHLOGE("The capturer or mictrans is not instantiated."); DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ERR_DH_AUDIO_CLIENT_CAPTURER_OR_MICTRANS_INSTANCE, "daudio capturer or mictrans is not instantiated."); @@ -306,11 +607,9 @@ int32_t DMicClient::StopCapture() } isBlocking_.store(false); - if (audioParam_.captureOpts.capturerFlags != MMAP_MODE) { - isCaptureReady_.store(false); - if (captureDataThread_.joinable()) { - captureDataThread_.join(); - } + isCaptureReady_.store(false); + if (captureDataThread_.joinable()) { + captureDataThread_.join(); } bool status = true; @@ -319,9 +618,15 @@ int32_t DMicClient::StopCapture() DHLOGE("Mic trans stop failed."); status = false; } - if (!audioCapturer_->Stop()) { - DHLOGE("Audio capturer stop failed."); - status = false; + if (audioParam_.captureOpts.capturerFlags == MMAP_MODE) { + if (hdfCapture_ != nullptr) { + hdfCapture_->Stop(hdfCapture_); + } + } else { + if (audioCapturer_ == nullptr || !audioCapturer_->Stop()) { + DHLOGE("Audio capturer stop failed."); + status = false; + } } clientStatus_ = AudioStatus::STATUS_STOP; if (!status) { diff --git a/services/audioclient/spkclient/include/dspeaker_client.h b/services/audioclient/spkclient/include/dspeaker_client.h index c213c0ac2d493cdf731ecc7e31badbafd45805f7..f38be3cb6f612a34f34ecee85347bc8c4f47b9ee 100644 --- a/services/audioclient/spkclient/include/dspeaker_client.h +++ b/services/audioclient/spkclient/include/dspeaker_client.h @@ -93,6 +93,7 @@ private: constexpr static size_t DATA_QUEUE_SIZE = 8; constexpr static size_t SLEEP_TIME = 5000; static constexpr const char* RENDERTHREAD = "renderThread"; + const std::string FILE_NAME = "/data/sink_spk_recv.pcm"; std::string devId_; std::thread renderDataThread_; @@ -107,6 +108,8 @@ private: std::unique_ptr audioRenderer_ = nullptr; std::shared_ptr speakerTrans_ = nullptr; std::weak_ptr eventCallback_; + int64_t lastPlayStartTime_ = 0; + int64_t lastReceiveStartTime_ = 0; }; } // DistributedHardware } // OHOS diff --git a/services/audioclient/spkclient/src/dspeaker_client.cpp b/services/audioclient/spkclient/src/dspeaker_client.cpp index 2a2aa376576ef02733833aa424be163d819e4a73..ee90de6af78675a430b8ee8f552206cce2f17911 100644 --- a/services/audioclient/spkclient/src/dspeaker_client.cpp +++ b/services/audioclient/spkclient/src/dspeaker_client.cpp @@ -17,6 +17,7 @@ #include "daudio_constants.h" #include "daudio_hisysevent.h" +#include "daudio_sink_hidumper.h" #include "daudio_util.h" #include "daudio_sink_manager.h" @@ -124,14 +125,14 @@ void DSpeakerClient::OnWriteData(size_t length) std::shared_ptr audioData = nullptr; { std::unique_lock spkLck(dataQueueMtx_); - dataQueueCond_.wait_for(spkLck, std::chrono::milliseconds(REQUEST_DATA_WAIT), - [this]() { return !dataQueue_.empty(); }); if (dataQueue_.empty()) { - return; + audioData = std::make_shared(bufDesc.bufLength); + DHLOGI("Pop spk data, dataQueue is empty. write empty data."); + } else { + audioData = dataQueue_.front(); + dataQueue_.pop(); + DHLOGI("Pop spk data, dataQueue size: %d.", dataQueue_.size()); } - audioData = dataQueue_.front(); - dataQueue_.pop(); - DHLOGD("Pop spk data, dataQueue size: %d.", dataQueue_.size()); } if (audioData->Capacity() != bufDesc.bufLength) { DHLOGE("Audio data length is not equal to buflength. datalength: %d, bufLength: %d", @@ -277,6 +278,7 @@ void DSpeakerClient::PlayThreadRunning() FillJitterQueue(); while (audioRenderer_ != nullptr && isRenderReady_.load()) { + int64_t startTime = GetNowTimeUs(); std::shared_ptr audioData = nullptr; { std::unique_lock spkLck(dataQueueMtx_); @@ -289,7 +291,11 @@ void DSpeakerClient::PlayThreadRunning() dataQueue_.pop(); DHLOGD("Pop spk data, dataqueue size: %d.", dataQueue_.size()); } - +#ifdef DUMP_DSPEAKERCLIENT_FILE + if (DaudioSinkHidumper::GetInstance().GetFlagStatus()) { + SaveFile(FILE_NAME, const_cast(audioData->Data()), audioData->Size()); + } +#endif int32_t writeOffSet = 0; while (writeOffSet < static_cast(audioData->Capacity())) { int32_t writeLen = audioRenderer_->Write(audioData->Data() + writeOffSet, @@ -301,6 +307,12 @@ void DSpeakerClient::PlayThreadRunning() } writeOffSet += writeLen; } + int64_t endTime = GetNowTimeUs(); + if (IsOutDurationRange(startTime, endTime, lastPlayStartTime_)) { + DHLOGE("This time play spend: %lld, The interval of play this time and the last time: %lld", + endTime - startTime, startTime - lastPlayStartTime_); + } + lastPlayStartTime_ = startTime; } } @@ -333,6 +345,7 @@ void DSpeakerClient::FlushJitterQueue() int32_t DSpeakerClient::OnDecodeTransDataDone(const std::shared_ptr &audioData) { DHLOGI("Write stream buffer."); + int64_t startTime = GetNowTimeUs(); if (audioData == nullptr) { DHLOGE("The parameter is empty."); return ERR_DH_AUDIO_CLIENT_PARAM_IS_NULL; @@ -345,6 +358,12 @@ int32_t DSpeakerClient::OnDecodeTransDataDone(const std::shared_ptr & dataQueue_.push(audioData); dataQueueCond_.notify_all(); DHLOGI("Push new spk data, buf len: %d.", dataQueue_.size()); + int64_t endTime = GetNowTimeUs(); + if (IsOutDurationRange(startTime, endTime, lastReceiveStartTime_)) { + DHLOGE("This time receivce data spend: %lld, The interval of receivce data this time and the last time: %lld", + endTime - startTime, startTime - lastReceiveStartTime_); + } + lastReceiveStartTime_ = startTime; return DH_SUCCESS; } @@ -536,6 +555,7 @@ void DSpeakerClient::Pause() } if (audioRenderer_ != nullptr) { audioRenderer_->Flush(); + audioRenderer_->Pause(); } clientStatus_ = AudioStatus::STATUS_START; isRenderReady_.store(true); @@ -551,6 +571,9 @@ void DSpeakerClient::ReStart() isRenderReady_.store(true); renderDataThread_ = std::thread(&DSpeakerClient::PlayThreadRunning, this); } + if (audioRenderer_ != nullptr) { + audioRenderer_->Start(); + } clientStatus_ = AudioStatus::STATUS_START; } diff --git a/services/audioclient/test/unittest/micclient/BUILD.gn b/services/audioclient/test/unittest/micclient/BUILD.gn index aeec741c8fb5ba1f644588a8cbeed5c6372e33bd..9d0c2f90a0aea2c6a26065da2eb57a7074b75def 100644 --- a/services/audioclient/test/unittest/micclient/BUILD.gn +++ b/services/audioclient/test/unittest/micclient/BUILD.gn @@ -67,6 +67,7 @@ ohos_unittest("MicClientTest") { "audio_framework:audio_capturer", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributed_av_sender", + "drivers_interface_audio:libaudio_proxy_1.0", ] } diff --git a/services/audioclient/test/unittest/micclient/src/dmic_client_test.cpp b/services/audioclient/test/unittest/micclient/src/dmic_client_test.cpp index 8010937c84cbb0058bfea6455bd22228fe839890..f844ca24048cbd029b1fef1a24eba16c69e8e81b 100644 --- a/services/audioclient/test/unittest/micclient/src/dmic_client_test.cpp +++ b/services/audioclient/test/unittest/micclient/src/dmic_client_test.cpp @@ -157,7 +157,7 @@ HWTEST_F(DMicClientTest, StopCapture002, TestSize.Level1) micClient_->clientStatus_ = STATUS_START; EXPECT_EQ(ERR_DH_AUDIO_SA_STATUS_ERR, micClient_->StopCapture()); micClient_->isCaptureReady_.store(true); - EXPECT_EQ(ERR_DH_AUDIO_CLIENT_CAPTURER_OR_MICTRANS_INSTANCE, micClient_->StopCapture()); + EXPECT_EQ(ERR_DH_AUDIO_FAILED, micClient_->StopCapture()); micClient_->SetUp(audioParam_); EXPECT_EQ(ERR_DH_AUDIO_SA_STATUS_ERR, micClient_->StopCapture()); } @@ -209,5 +209,97 @@ HWTEST_F(DMicClientTest, SendMessage_001, TestSize.Level1) micClient_->micTrans_ = nullptr; EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, micClient_->SendMessage(NOTIFY_OPEN_MIC_RESULT, content, dstDevId)); } + +/** + * @tc.name: GetAdapter_001 + * @tc.desc: Verify the GetAdapter function. + * @tc.type: FUNC + * @tc.require: AR000H0E6G + */ +HWTEST_F(DMicClientTest, GetAdapter_001, TestSize.Level1) +{ + struct IAudioManager *audioManager_; + audioManager_ = nullptr; + int32_t actual = micClient_->GetAdapter(); + EXPECT_EQ(ERR_DH_AUDIO_FAILED, actual); +} + +/** + * @tc.name: InitHDFAudioDevice_001 + * @tc.desc: Verify the InitHDFAudioDevice function. + * @tc.type: FUNC + * @tc.require: AR000H0E6G + */ +HWTEST_F(DMicClientTest, InitHDFAudioDevice_001, TestSize.Level1) +{ + bool micInUse_ = true; + int32_t actual = micClient_->InitHDFAudioDevice(); + EXPECT_EQ(DH_SUCCESS, actual); + micInUse_ = false; + actual = micClient_->InitHDFAudioDevice(); + EXPECT_EQ(DH_SUCCESS, actual); +} + +/** + * @tc.name: AudioFwkClientSetUp_001 + * @tc.desc: Verify the AudioFwkClientSetUp function. + * @tc.type: FUNC + * @tc.require: AR000H0E6G + */ +HWTEST_F(DMicClientTest, AudioFwkClientSetUp_001, TestSize.Level1) +{ + audioParam_.captureOpts.capturerFlags = MMAP_MODE; + int32_t actual = micClient_->AudioFwkClientSetUp(); + EXPECT_EQ(ERR_DH_AUDIO_CLIENT_CREATE_CAPTURER_FAILED, actual); + audioParam_.captureOpts.capturerFlags = NORMAL_MODE; + actual = micClient_->AudioFwkClientSetUp(); + EXPECT_NE(DH_SUCCESS, actual); +} + +/** + * @tc.name: HdfClientSetUp_001 + * @tc.desc: Verify the HdfClientSetUp function. + * @tc.type: FUNC + * @tc.require: AR000H0E6G + */ +HWTEST_F(DMicClientTest, HdfClientSetUp_001, TestSize.Level1) +{ + bool micInUse_; + micInUse_ = true; + int32_t actual = micClient_->HdfClientSetUp(); + EXPECT_EQ(DH_SUCCESS, actual); + micInUse_ = false; + micClient_->micTrans_ = nullptr; + actual = micClient_->HdfClientSetUp(); + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, actual); +} + +/** + * @tc.name: TransSetUp_001 + * @tc.desc: Verify the TransSetUp function. + * @tc.type: FUNC + * @tc.require: AR000H0E6G + */ +HWTEST_F(DMicClientTest, TransSetUp_001, TestSize.Level1) +{ + int32_t actual = micClient_->TransSetUp(); + EXPECT_EQ(DH_SUCCESS, actual); + micClient_->micTrans_ = nullptr; + actual = micClient_->TransSetUp(); + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, actual); +} + +/** + * @tc.name: HdfClientRelease_001 + * @tc.desc: Verify the HdfClientRelease function. + * @tc.type: FUNC + * @tc.require: AR000H0E6G + */ +HWTEST_F(DMicClientTest, HdfClientRelease_001, TestSize.Level1) +{ + std::shared_ptr audioAdapter_ = std::make_shared(); + int32_t actual = micClient_->HdfClientRelease(); + EXPECT_EQ(DH_SUCCESS, actual); +} } // DistributedHardware } // OHOS diff --git a/services/audiohdiproxy/include/daudio_hdi_handler.h b/services/audiohdiproxy/include/daudio_hdi_handler.h index 8a004e60540c1a3ad36868fbab901b7949848524..d5d15ac2101aaebf3df169c18ea32737c6430526 100644 --- a/services/audiohdiproxy/include/daudio_hdi_handler.h +++ b/services/audiohdiproxy/include/daudio_hdi_handler.h @@ -30,6 +30,7 @@ namespace OHOS { namespace DistributedHardware { +using OHOS::HDI::DistributedAudio::Audioext::V1_0::DAudioEvent; using OHOS::HDI::DistributedAudio::Audioext::V1_0::IDAudioCallback; using OHOS::HDI::DistributedAudio::Audioext::V1_0::IDAudioManager; class DAudioHdiHandler { @@ -50,6 +51,7 @@ public: private: DAudioHdiHandler(); ~DAudioHdiHandler(); + void ProcessEventMsg(const AudioEvent &audioEvent, DAudioEvent &newEvent); const std::string HDF_AUDIO_SERVICE_NAME = "daudio_ext_service"; std::mutex devMapMtx_; diff --git a/services/audiohdiproxy/src/daudio_hdi_handler.cpp b/services/audiohdiproxy/src/daudio_hdi_handler.cpp index 8c07edc934c0b3ad8631e4a61755d8a5fc1c7e75..ba5f08d9845e8850e3f5f7aa003f25376ed30e0e 100644 --- a/services/audiohdiproxy/src/daudio_hdi_handler.cpp +++ b/services/audiohdiproxy/src/daudio_hdi_handler.cpp @@ -162,16 +162,8 @@ int32_t DAudioHdiHandler::UnRegisterAudioDevice(const std::string &devId, const return DH_SUCCESS; } -int32_t DAudioHdiHandler::NotifyEvent(const std::string &devId, const int32_t dhId, - const AudioEvent &audioEvent) +void DAudioHdiHandler::ProcessEventMsg(const AudioEvent &audioEvent, DAudioEvent &newEvent) { - DHLOGD("Notify event adpname: %s, dhId: %d, event type: %d, event content: %s.", - GetAnonyString(devId).c_str(), dhId, audioEvent.type, audioEvent.content.c_str()); - if (audioSrvHdf_ == nullptr) { - DHLOGE("Audio hdi proxy not init"); - return ERR_DH_AUDIO_HDI_PROXY_NOT_INIT; - } - OHOS::HDI::DistributedAudio::Audioext::V1_0::DAudioEvent newEvent = {AUDIO_EVENT_UNKNOWN, audioEvent.content}; switch (audioEvent.type) { case AudioEventType::NOTIFY_OPEN_SPEAKER_RESULT: newEvent.type = AUDIO_EVENT_OPEN_SPK_RESULT; @@ -200,10 +192,29 @@ int32_t DAudioHdiHandler::NotifyEvent(const std::string &devId, const int32_t dh case AudioEventType::AUDIO_RENDER_STATE_CHANGE: newEvent.type = AUDIO_EVENT_RENDER_STATE_CHANGE; break; + case AudioEventType::NOTIFY_HDF_SPK_DUMP: + newEvent.type = AUDIO_EVENT_SPK_DUMP; + break; + case AudioEventType::NOTIFY_HDF_MIC_DUMP: + newEvent.type = AUDIO_EVENT_MIC_DUMP; + break; default: DHLOGE("Unsupport audio event."); break; } +} + +int32_t DAudioHdiHandler::NotifyEvent(const std::string &devId, const int32_t dhId, + const AudioEvent &audioEvent) +{ + DHLOGD("Notify event adpname: %s, dhId: %d, event type: %d, event content: %s.", + GetAnonyString(devId).c_str(), dhId, audioEvent.type, audioEvent.content.c_str()); + if (audioSrvHdf_ == nullptr) { + DHLOGE("Audio hdi proxy not init"); + return ERR_DH_AUDIO_HDI_PROXY_NOT_INIT; + } + DAudioEvent newEvent = {AUDIO_EVENT_UNKNOWN, audioEvent.content}; + ProcessEventMsg(audioEvent, newEvent); int32_t res = audioSrvHdf_->NotifyEvent(devId, dhId, newEvent); if (res != HDF_SUCCESS) { diff --git a/services/audiomanager/managersource/include/daudio_source_dev.h b/services/audiomanager/managersource/include/daudio_source_dev.h index b8a35fabf1e1d8970543df5c93b9a0bf86451d92..7e95e46668e6855002191dbef6094134083bd753 100644 --- a/services/audiomanager/managersource/include/daudio_source_dev.h +++ b/services/audiomanager/managersource/include/daudio_source_dev.h @@ -113,7 +113,7 @@ private: int32_t CloseMicNew(const std::string &args); private: - static constexpr uint8_t RPC_WAIT_SECONDS = 2; + static constexpr uint8_t RPC_WAIT_SECONDS = 10; static constexpr uint8_t TASK_QUEUE_CAPACITY = 20; static constexpr uint8_t EVENT_NOTIFY_OPEN_SPK = 0x01; static constexpr uint8_t EVENT_NOTIFY_CLOSE_SPK = 0x02; diff --git a/services/audiomanager/managersource/include/dmic_dev.h b/services/audiomanager/managersource/include/dmic_dev.h index de80fdaa6361a233eeeab5ff08af170062d9ec33..68d49948b3012b817043f76e1509d11d817c6943 100644 --- a/services/audiomanager/managersource/include/dmic_dev.h +++ b/services/audiomanager/managersource/include/dmic_dev.h @@ -91,6 +91,7 @@ private: static constexpr size_t LOW_LATENCY_DATA_QUEUE_HALF_SIZE = 10; static constexpr uint32_t MMAP_WAIT_FRAME_US = 5000; static constexpr const char* ENQUEUE_THREAD = "micEnqueueTh"; + const std::string FILE_NAME = "/data/source_mic_read.pcm"; std::string devId_; std::weak_ptr audioEventCallback_; @@ -100,6 +101,7 @@ private: int32_t curPort_ = 0; std::atomic isTransReady_ = false; std::atomic isOpened_ = false; + std::atomic dumpFlag_ = false; std::shared_ptr micTrans_ = nullptr; std::queue> dataQueue_; std::set enabledPorts_; @@ -122,6 +124,7 @@ private: uint64_t writeNum_ = 0; int64_t writeTvSec_ = 0; int64_t writeTvNSec_ = 0; + int64_t lastReadStartTime_ = 0; std::thread enqueueDataThread_; std::mutex writeAshmemMutex_; std::condition_variable dataQueueCond_; diff --git a/services/audiomanager/managersource/include/dspeaker_dev.h b/services/audiomanager/managersource/include/dspeaker_dev.h index ef64da75b837a5f4d0aaa5da814c797b1aa38e20..0b2f8a5e34f2a0b13d0932288585e87f40f0f217 100644 --- a/services/audiomanager/managersource/include/dspeaker_dev.h +++ b/services/audiomanager/managersource/include/dspeaker_dev.h @@ -84,6 +84,7 @@ private: private: static constexpr const char* ENQUEUE_THREAD = "spkEnqueueTh"; + const std::string FILE_NAME = "/data/source_spk_write.pcm"; std::string devId_; std::weak_ptr audioEventCallback_; @@ -91,6 +92,7 @@ private: std::condition_variable channelWaitCond_; std::atomic isTransReady_ = false; std::atomic isOpened_ = false; + std::atomic dumpFlag_ = false; int32_t curPort_ = 0; std::shared_ptr speakerTrans_ = nullptr; std::set enabledPorts_; @@ -111,6 +113,7 @@ private: int64_t readTvSec_ = 0; int64_t readTvNSec_ = 0; std::thread enqueueDataThread_; + int64_t lastwriteStartTime_ = 0; }; } // DistributedHardware } // OHOS diff --git a/services/audiomanager/managersource/src/dmic_dev.cpp b/services/audiomanager/managersource/src/dmic_dev.cpp index d7a3f941cb1ad8107a09a5d4962ea755962d4837..e2f15d0c667ebec82da32d6549a16ecd9396b40f 100644 --- a/services/audiomanager/managersource/src/dmic_dev.cpp +++ b/services/audiomanager/managersource/src/dmic_dev.cpp @@ -23,6 +23,7 @@ #include "audio_decode_transport.h" #include "daudio_constants.h" #include "daudio_errorcode.h" +#include "daudio_hidumper.h" #include "daudio_hisysevent.h" #include "daudio_hitrace.h" #include "daudio_log.h" @@ -302,6 +303,7 @@ int32_t DMicDev::Release() DHLOGE("Release mic trans failed, ret: %d.", ret); return ret; } + dumpFlag_.store(false); return DH_SUCCESS; } @@ -320,6 +322,7 @@ int32_t DMicDev::WriteStreamData(const std::string& devId, const int32_t dhId, s int32_t DMicDev::ReadStreamData(const std::string &devId, const int32_t dhId, std::shared_ptr &data) { + int64_t startTime = GetNowTimeUs(); if (curStatus_ != AudioStatus::STATUS_START) { DHLOGE("Distributed audio is not starting status."); return ERR_DH_AUDIO_FAILED; @@ -340,6 +343,22 @@ int32_t DMicDev::ReadStreamData(const std::string &devId, const int32_t dhId, st data = dataQueue_.front(); dataQueue_.pop(); } +#ifdef DUMP_DMICDEV_FILE + if (DaudioHidumper::GetInstance().GetFlagStatus()) { + if (!dumpFlag_) { + AudioEvent event(NOTIFY_HDF_MIC_DUMP, ""); + NotifyHdfAudioEvent(event); + dumpFlag_.store(true); + } + SaveFile(FILE_NAME, const_cast(data->Data()), data->Size()); + } +#endif + int64_t endTime = GetNowTimeUs(); + if (IsOutDurationRange(startTime, endTime, lastReadStartTime_)) { + DHLOGE("This time read data spend: %lld, The interval of read data this time and the last time: %lld", + endTime - startTime, startTime - lastReadStartTime_); + } + lastReadStartTime_ = startTime; return DH_SUCCESS; } diff --git a/services/audiomanager/managersource/src/dspeaker_dev.cpp b/services/audiomanager/managersource/src/dspeaker_dev.cpp index 0d02db95acde13ca3a61f02a8dba5463bb0b365f..bc4bda0545820db00f0fefe742397d39a15b5a1e 100644 --- a/services/audiomanager/managersource/src/dspeaker_dev.cpp +++ b/services/audiomanager/managersource/src/dspeaker_dev.cpp @@ -25,6 +25,7 @@ #include "audio_encode_transport.h" #include "daudio_constants.h" #include "daudio_errorcode.h" +#include "daudio_hidumper.h" #include "daudio_hisysevent.h" #include "daudio_hitrace.h" #include "daudio_log.h" @@ -285,6 +286,7 @@ int32_t DSpeakerDev::Release() if (ret != DH_SUCCESS) { DHLOGE("Release speaker trans failed, ret: %d.", ret); } + dumpFlag_.store(false); return DH_SUCCESS; } @@ -339,15 +341,32 @@ int32_t DSpeakerDev::ReadStreamData(const std::string &devId, const int32_t dhId int32_t DSpeakerDev::WriteStreamData(const std::string &devId, const int32_t dhId, std::shared_ptr &data) { DHLOGD("Write stream data, dhId:%d", dhId); + int64_t startTime = GetNowTimeUs(); if (speakerTrans_ == nullptr) { DHLOGE("Write stream data, speaker trans is null."); return ERR_DH_AUDIO_SA_SPEAKER_TRANS_NULL; } +#ifdef DUMP_DSPEAKERDEV_FILE + if (DaudioHidumper::GetInstance().GetFlagStatus()) { + if (!dumpFlag_) { + AudioEvent event(NOTIFY_HDF_SPK_DUMP, ""); + NotifyHdfAudioEvent(event); + dumpFlag_.store(true); + } + SaveFile(FILE_NAME, const_cast(data->Data()), data->Size()); + } +#endif int32_t ret = speakerTrans_->FeedAudioData(data); if (ret != DH_SUCCESS) { DHLOGE("Write stream data failed, ret: %d.", ret); return ret; } + int64_t endTime = GetNowTimeUs(); + if (IsOutDurationRange(startTime, endTime, lastwriteStartTime_)) { + DHLOGE("This time write data spend: %lld, The interval of write data this time and the last time: %lld", + endTime - startTime, startTime - lastwriteStartTime_); + } + lastwriteStartTime_ = startTime; return DH_SUCCESS; } @@ -404,13 +423,13 @@ void DSpeakerDev::EnqueueThread() readIndex_ = 0; readNum_ = 0; frameIndex_ = 0; - DHLOGD("Enqueue thread start, lengthPerRead length: %d.", lengthPerTrans_); + DHLOGI("Enqueue thread start, lengthPerRead length: %d.", lengthPerTrans_); while (ashmem_ != nullptr && isEnqueueRunning_.load()) { int64_t timeOffset = UpdateTimeOffset(frameIndex_, LOW_LATENCY_INTERVAL_NS, startTime_); DHLOGD("Read frameIndex: %lld, timeOffset: %lld.", frameIndex_, timeOffset); auto readData = ashmem_->ReadFromAshmem(lengthPerTrans_, readIndex_); - DHLOGD("Read from ashmem success! read index: %d, readLength: %d.", readIndex_, lengthPerTrans_); + DHLOGI("Read from ashmem success! read index: %d, readLength: %d.", readIndex_, lengthPerTrans_); std::shared_ptr audioData = std::make_shared(lengthPerTrans_); if (readData != nullptr) { const uint8_t *readAudioData = reinterpret_cast(readData); diff --git a/services/audiomanager/servicesink/BUILD.gn b/services/audiomanager/servicesink/BUILD.gn index 2a6051831656d060bf7a30f871a1ae68ee08bf1e..d7ce250dbab1569d8895ea1855eac41ff78e0b17 100755 --- a/services/audiomanager/servicesink/BUILD.gn +++ b/services/audiomanager/servicesink/BUILD.gn @@ -70,6 +70,7 @@ ohos_shared_library("distributed_audio_sink") { "${innerkits_path}/native_cpp/audio_source/src/daudio_source_proxy.cpp", "${services_path}/audiomanager/managersink/src/daudio_sink_dev.cpp", "${services_path}/audiomanager/managersink/src/daudio_sink_manager.cpp", + "src/daudio_sink_hidumper.cpp", "src/daudio_sink_service.cpp", "src/daudio_sink_stub.cpp", ] @@ -117,6 +118,13 @@ ohos_shared_library("distributed_audio_sink") { "LOG_DOMAIN=0xD004100", ] + if (build_variant == "root") { + defines += [ + "DUMP_DMICCLIENT_FILE", + "DUMP_DSPEAKERCLIENT_FILE", + ] + } + subsystem_name = "distributedhardware" part_name = "distributed_audio" diff --git a/services/audiomanager/servicesink/include/daudio_sink_hidumper.h b/services/audiomanager/servicesink/include/daudio_sink_hidumper.h new file mode 100644 index 0000000000000000000000000000000000000000..fc249dd0a40bfa0f7806d59b95adb921a392d129 --- /dev/null +++ b/services/audiomanager/servicesink/include/daudio_sink_hidumper.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_AUDIO_SINK_HIDUMPER_H +#define OHOS_DISTRIBUTED_AUDIO_SINK_HIDUMPER_H + +#include +#include +#include + +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +enum class HidumpFlag { + UNKNOWN = 0, + GET_HELP, + DUMP_SINK_AUDIO_DATA, +}; +class DaudioSinkHidumper { + DECLARE_SINGLE_INSTANCE_BASE(DaudioSinkHidumper); + +public: + bool Dump(const std::vector &args, std::string &result); + bool GetFlagStatus(); + DaudioSinkHidumper(); + ~DaudioSinkHidumper(); + +private: + void ShowHelp(std::string &result); + int32_t ShowIllegalInfomation(std::string &result); + int32_t ProcessDump(const std::string &args, std::string &result); + + int32_t DumpAudioData(std::string &result); + +private: + bool HidumperFlag_ = false; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_AUDIO_SINK_HIDUMPER_H \ No newline at end of file diff --git a/services/audiomanager/servicesink/include/daudio_sink_service.h b/services/audiomanager/servicesink/include/daudio_sink_service.h index b20cc9a1df46498de781568b33333115c86dcfb6..633d39348231bf84dd212a5fa0387b7f866cbef2 100644 --- a/services/audiomanager/servicesink/include/daudio_sink_service.h +++ b/services/audiomanager/servicesink/include/daudio_sink_service.h @@ -19,6 +19,7 @@ #include "system_ability.h" #include "ipc_object_stub.h" +#include "daudio_sink_hidumper.h" #include "daudio_sink_stub.h" namespace OHOS { @@ -36,6 +37,7 @@ public: int32_t UnsubscribeLocalHardware(const std::string &dhId) override; void DAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType, const std::string &eventContent) override; + int Dump(int32_t fd, const std::vector& args) override; protected: void OnStart() override; diff --git a/services/audiomanager/servicesink/src/daudio_sink_hidumper.cpp b/services/audiomanager/servicesink/src/daudio_sink_hidumper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..41fdfdeedaa50db092d094a03db783ac1b9641a3 --- /dev/null +++ b/services/audiomanager/servicesink/src/daudio_sink_hidumper.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "daudio_sink_hidumper.h" + +#include "daudio_errorcode.h" +#include "daudio_log.h" +#include "daudio_util.h" + +#undef DH_LOG_TAG +#define DH_LOG_TAG "DaudioSinkHidumper" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DaudioSinkHidumper); + +namespace { +const std::string ARGS_HELP = "-h"; +const std::string ARGS_DUMP_SINK_AUDIO_DATA = "--dumpSinkAudioData"; + +const std::map ARGS_MAP = { + { ARGS_HELP, HidumpFlag::GET_HELP }, + { ARGS_DUMP_SINK_AUDIO_DATA, HidumpFlag::DUMP_SINK_AUDIO_DATA }, +}; +} + +DaudioSinkHidumper::DaudioSinkHidumper() +{ + DHLOGI("Distributed audio hidumper constructed."); +} + +DaudioSinkHidumper::~DaudioSinkHidumper() +{ + DHLOGI("Distributed audio hidumper deconstructed."); +} + +bool DaudioSinkHidumper::Dump(const std::vector &args, std::string &result) +{ + DHLOGI("Distributed audio hidumper dump args.size():%d.", args.size()); + result.clear(); + int32_t argsSize = static_cast(args.size()); + for (int32_t i = 0; i < argsSize; i++) { + DHLOGI("Distributed audio hidumper dump args[%d]: %s.", i, args.at(i).c_str()); + } + + if (args.empty()) { + ShowHelp(result); + return true; + } else if (args.size() > 1) { + ShowIllegalInfomation(result); + return true; + } + + return ProcessDump(args[0], result) == DH_SUCCESS; +} + +int32_t DaudioSinkHidumper::ProcessDump(const std::string &args, std::string &result) +{ + DHLOGI("Process dump."); + HidumpFlag hf = HidumpFlag::UNKNOWN; + auto operatorIter = ARGS_MAP.find(args); + if (operatorIter != ARGS_MAP.end()) { + hf = operatorIter->second; + } + + if (hf == HidumpFlag::GET_HELP) { + ShowHelp(result); + return DH_SUCCESS; + } + result.clear(); + switch (hf) { + case HidumpFlag::DUMP_SINK_AUDIO_DATA: { + return DumpAudioData(result); + } + default: { + return ShowIllegalInfomation(result); + } + } +} + +int32_t DaudioSinkHidumper::DumpAudioData(std::string &result) +{ + DHLOGI("Dump audio data."); + result.append("Dump..."); + HidumperFlag_ = true; + return DH_SUCCESS; +} + +bool DaudioSinkHidumper::GetFlagStatus() +{ + return HidumperFlag_; +} + +void DaudioSinkHidumper::ShowHelp(std::string &result) +{ + DHLOGI("Show help."); + result.append("Usage:dump [options]\n") + .append("Description:\n") + .append("-h ") + .append(": show help\n") + .append("--dumpSinkAudioData ") + .append(": dump sink audio data\n"); +} + +int32_t DaudioSinkHidumper::ShowIllegalInfomation(std::string &result) +{ + DHLOGI("Show illegal information."); + result.append("unknown command, -h for help."); + return DH_SUCCESS; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/audiomanager/servicesink/src/daudio_sink_service.cpp b/services/audiomanager/servicesink/src/daudio_sink_service.cpp index fe17dae7a22e390a6a852ab5ec0fedefafa63ef7..dac62574a1754de7985321eb99ae8a545b6ecb16 100644 --- a/services/audiomanager/servicesink/src/daudio_sink_service.cpp +++ b/services/audiomanager/servicesink/src/daudio_sink_service.cpp @@ -116,5 +116,28 @@ void DAudioSinkService::DAudioNotify(const std::string &devId, const std::string dhId.c_str(), eventType); DAudioSinkManager::GetInstance().HandleDAudioNotify(devId, dhId, eventType, eventContent); } + +int DAudioSinkService::Dump(int32_t fd, const std::vector &args) +{ + DHLOGD("Distributed audio sink service dump."); + std::string result; + std::vector argsStr; + + std::transform(args.cbegin(), args.cend(), std::back_inserter(argsStr), + [](const std::u16string& item) { return Str16ToStr8(item); }); + + if (!DaudioSinkHidumper::GetInstance().Dump(argsStr, result)) { + DHLOGE("Hidump error"); + return ERR_DH_AUDIO_BAD_VALUE; + } + + int ret = dprintf(fd, "%s\n", result.c_str()); + if (ret < 0) { + DHLOGE("Dprintf error"); + return ERR_DH_AUDIO_BAD_VALUE; + } + + return DH_SUCCESS; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index b5ad8d023371ac7b462a03b067990a4399866a16..d0a6f69d8406534223f25926e389452270fab35e 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -112,6 +112,13 @@ ohos_shared_library("distributed_audio_source") { "LOG_DOMAIN=0xD004100", ] + if (build_variant == "root") { + defines += [ + "DUMP_DSPEAKERDEV_FILE", + "DUMP_DMICDEV_FILE", + ] + } + subsystem_name = "distributedhardware" part_name = "distributed_audio" diff --git a/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/BUILD.gn index a5633fc77455c2eec6193f44488ab5aeb814e44f..e732427e037ae7cb917ecc56ca63ac0d722e907c 100644 --- a/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkServiceDAudioNotifyFuzzTest") { - module_out_path = "distributed_audio/sinkservicedaudionotify_fuzzer" + module_out_path = + "${distributedaudio_fuzz_path}/sinkservicedaudionotify_fuzzer" fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer" cflags = [ diff --git a/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/BUILD.gn index 752c69d7bd587cec1a46a53e6c9d0bfb668361b0..a8a8ff45bbf3bbf633eaaea411c3e17e4a3aba0a 100644 --- a/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkServiceInitSinkFuzzTest") { - module_out_path = "distributed_audio/sinkserviceinitsink_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/sinkserviceinitsink_fuzzer" fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer" diff --git a/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/BUILD.gn index ef1cfd28f6cd71179a45ad51e03a76294413646e..885f6902139c30664321e419c6043212e8045913 100644 --- a/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkServiceReleaseSinkFuzzTest") { - module_out_path = "distributed_audio/sinkservicereleasesink_fuzzer" + module_out_path = + "${distributedaudio_fuzz_path}/sinkservicereleasesink_fuzzer" fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer" cflags = [ diff --git a/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn index c1e4053fea1fde97fd2c3348c205856ff9f079cd..79a9e4efadfba8de8475e8097cedca764a549cbe 100644 --- a/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkServiceSubscribeLocalHardwareFuzzTest") { - module_out_path = "distributed_audio/sinkservicesubscribelocalhardware_fuzzer" + module_out_path = + "${distributedaudio_fuzz_path}/sinkservicesubscribelocalhardware_fuzzer" fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer" cflags = [ diff --git a/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn index 6df43eabcde7ae31f2f5aa88dfcbba1e4b24a3a4..9b8064314820e7dcdc400f0b00f14271c013b426 100644 --- a/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn @@ -19,7 +19,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SinkServiceUnSubscribeLocalHardwareFuzzTest") { module_out_path = - "distributed_audio/sinkserviceunsubscribelocalhardware_fuzzer" + "${distributedaudio_fuzz_path}/sinkserviceunsubscribelocalhardware_fuzzer" fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer" cflags = [ diff --git a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn index 4e97920a6da3a24a0cdf48c5927784bc8a37b25a..16a24e8ace2bada59cddb8eadefcac73f7c4984d 100644 --- a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceServiceDAudioNotifyFuzzTest") { - module_out_path = "distributed_audio/sourceservicedaudionotify_fuzzer" + module_out_path = + "${distributedaudio_fuzz_path}/sourceservicedaudionotify_fuzzer" fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer" cflags = [ diff --git a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn index 4843d04e283a419197e0e69a41ba5f8d6e4ec025..f8f8552535b29f6c9e584cec67efad2e0c771d24 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceServiceInitSourceFuzzTest") { - module_out_path = "distributed_audio/sourceserviceinitsource_fuzzer" + module_out_path = + "${distributedaudio_fuzz_path}/sourceserviceinitsource_fuzzer" fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer" cflags = [ diff --git a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn index c693288427d6678d3d118b4852d2d776db135481..6f5507582ba7ba0ab04a7d5514e0cbb9fe4aab75 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn @@ -18,8 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceServiceRegisterDistributedHardwareFuzzTest") { - module_out_path = - "distributed_audio/sourceserviceregisterdistributedhardware_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/sourceserviceregisterdistributedhardware_fuzzer" fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer" cflags = [ diff --git a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn index 289fe9af4d503615b5c8b291ea33d51455696080..c1c309edbfa7af427abc195ae0916d5206ca7eb3 100644 --- a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn @@ -18,7 +18,8 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceServiceReleaseSourceFuzzTest") { - module_out_path = "distributed_audio/sourceservicereleasesource_fuzzer" + module_out_path = + "${distributedaudio_fuzz_path}/sourceservicereleasesource_fuzzer" fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer" cflags = [ diff --git a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn index eaa6556f3686f9c9fab03129c5d1854234588ea3..a07af4d0bb552b0debc77fa7de871701fc2bb4c1 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn @@ -18,8 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SourceServiceUnregisterDistributedHardwareFuzzTest") { - module_out_path = - "distributed_audio/sourceserviceunregisterdistributedhardware_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/sourceserviceunregisterdistributedhardware_fuzzer" fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer" cflags = [ diff --git a/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp b/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp index c61c680d9ce30f710dbd5454b2481e596252cae2..08a60b637676776aaeb44dabb13c43a795623f09 100644 --- a/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp +++ b/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp @@ -94,7 +94,7 @@ HWTEST_F(DAudioSinkDevTest, TaskOpenCtrlChannel_001, TestSize.Level1) HWTEST_F(DAudioSinkDevTest, TaskOpenCtrlChannel_002, TestSize.Level1) { std::string args = "args"; - EXPECT_NE(DH_SUCCESS, sinkDev_->TaskOpenCtrlChannel(args)); + EXPECT_EQ(DH_SUCCESS, sinkDev_->TaskOpenCtrlChannel(args)); EXPECT_EQ(DH_SUCCESS, sinkDev_->TaskOpenCtrlChannel(args)); } diff --git a/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp b/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp index 30b2dc90d099553e1ce3d3e2d481d465c8c918db..3c9c4bf59916f4b98789b82a910fa958ad3d5a83 100644 --- a/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp +++ b/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp @@ -51,12 +51,12 @@ HWTEST_F(DAudioSinkManagerTest, Init_001, TestSize.Level1) HWTEST_F(DAudioSinkManagerTest, CreateAudioDevice_001, TestSize.Level1) { std::string devId = "devId"; - EXPECT_EQ(DH_SUCCESS, daudioSinkManager.CreateAudioDevice(devId)); + EXPECT_EQ(ERR_DH_AUDIO_FAILED, daudioSinkManager.CreateAudioDevice(devId)); daudioSinkManager.channelState_ = ChannelState::SPK_CONTROL_OPENED; - daudioSinkManager.rcvProviderPtr_ = std::make_shared().get(); + daudioSinkManager.LoadAVReceiverEngineProvider(); EXPECT_EQ(DH_SUCCESS, daudioSinkManager.CreateAudioDevice(devId)); daudioSinkManager.channelState_ = ChannelState::MIC_CONTROL_OPENED; - daudioSinkManager.sendProviderPtr_ = std::make_shared().get(); + daudioSinkManager.LoadAVSenderEngineProvider(); EXPECT_EQ(DH_SUCCESS, daudioSinkManager.CreateAudioDevice(devId)); auto dev = std::make_shared(devId); daudioSinkManager.audioDevMap_.emplace(devId, dev); diff --git a/services/audiomanager/test/unittest/sourcedevice/src/daudio_source_dev_test.cpp b/services/audiomanager/test/unittest/sourcedevice/src/daudio_source_dev_test.cpp index 7a4b63b61ed75471f88afe6872f8cff1f92459f4..09392ccec1a5da5f970b3a54b0f58e208617bd9f 100644 --- a/services/audiomanager/test/unittest/sourcedevice/src/daudio_source_dev_test.cpp +++ b/services/audiomanager/test/unittest/sourcedevice/src/daudio_source_dev_test.cpp @@ -155,10 +155,10 @@ HWTEST_F(DAudioSourceDevTest, CreatTasks_003, TestSize.Level1) { sourceDev_->AwakeAudioDev(); AudioEvent event = AudioEvent(OPEN_SPEAKER, ""); - EXPECT_EQ(ERR_DH_AUDIO_SA_OPEN_CTRL_FAILED, sourceDev_->HandleOpenDSpeaker(event)); + EXPECT_EQ(DH_SUCCESS, sourceDev_->HandleOpenDSpeaker(event)); event.type = OPEN_MIC; - EXPECT_EQ(ERR_DH_AUDIO_SA_OPEN_CTRL_FAILED, sourceDev_->HandleOpenDMic(event)); + EXPECT_NE(ERR_DH_AUDIO_SA_OPEN_CTRL_FAILED, sourceDev_->HandleOpenDMic(event)); } /** diff --git a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/BUILD.gn index 057426980105037d57444e45703d11ae6ec88750..1975ae8e29ba7c719cf0d8a9b83ff7a31b17ebbf 100644 --- a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/BUILD.gn +++ b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("DecoderOnErrorFuzzTest") { - module_out_path = "distributed_audio/decoderonerror" + module_out_path = "${distributedaudio_fuzz_path}/decoderonerror" fuzz_config_file = "${audio_processor_path}/test/fuzztest/decoderonerror_fuzzer" diff --git a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/BUILD.gn index 888ca204fa47369528f7fdda4156f907965dd758..d8f6b6be56c9205039b462592cd61627c669a441 100644 --- a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/BUILD.gn +++ b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("DecoderOnInputAvailableFuzzTest") { - module_out_path = "distributed_audio/decoderoninputavailable" + module_out_path = "${distributedaudio_fuzz_path}/decoderoninputavailable" fuzz_config_file = "${audio_processor_path}/test/fuzztest/decoderoninputavailable_fuzzer" diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/BUILD.gn index 6b620a8598f7c16147e0ceab6cc72550963c1fad..b9bec389faf6520a59bfaeac95716fc223965b65 100644 --- a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/BUILD.gn +++ b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("DecoderOnOutputAvailableFuzzTest") { - module_out_path = "distributed_audio/decoderonoutputavailable" + module_out_path = "${distributedaudio_fuzz_path}/decoderonoutputavailable" fuzz_config_file = "${audio_processor_path}/test/fuzztest/decoderonoutputavailable_fuzzer" diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/BUILD.gn index e6a835d7c3c043117ad197e227fd5a718bba5704..03ccc2a28690586d079b39d4bf8b487929b85992 100644 --- a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/BUILD.gn +++ b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("DecoderOnOutputChangedFuzzTest") { - module_out_path = "distributed_audio/decoderonoutputchanged" + module_out_path = "${distributedaudio_fuzz_path}/decoderonoutputchanged" fuzz_config_file = "${audio_processor_path}/test/fuzztest/decoderonoutputchanged_fuzzer" diff --git a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/BUILD.gn index 4b1886a81f690b65ad36803d7c437ab1879c1428..c57b1000182c677dc974f65743272ecd853c4aad 100644 --- a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/BUILD.gn +++ b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("EncoderOnErrorFuzzTest") { - module_out_path = "distributed_audio/encoderonerror" + module_out_path = "${distributedaudio_fuzz_path}/encoderonerror" fuzz_config_file = "${audio_processor_path}/test/fuzztest/encoderonerror_fuzzer" diff --git a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/BUILD.gn index 318b77e6c77fec27196e8f30e1a452afa483a37a..5926982e2481d8558b6d0138fcf39378087bf5d3 100644 --- a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/BUILD.gn +++ b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("EncoderOnInputAvailableFuzzTest") { - module_out_path = "distributed_audio/encoderoninputavailable" + module_out_path = "${distributedaudio_fuzz_path}/encoderoninputavailable" fuzz_config_file = "${audio_processor_path}/test/fuzztest/encoderoninputavailable_fuzzer" diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/BUILD.gn index 2ed507fcdcd2ada95eba85175f1f0d8d7763338d..3e8a8790dbafef2374fd9504567b448d41222b4b 100644 --- a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/BUILD.gn +++ b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("EncoderOnOutputAvailableFuzzTest") { - module_out_path = "distributed_audio/encoderonoutputavailable" + module_out_path = "${distributedaudio_fuzz_path}/encoderonoutputavailable" fuzz_config_file = "${audio_processor_path}/test/fuzztest/encoderonoutputavailable_fuzzer" diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/BUILD.gn index b80cacb83001ae93adc409320db5bf1fdd2b33ee..cdc20d10b385435fe967d750bb4b13ac1b5dfeda 100644 --- a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/BUILD.gn +++ b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("EncoderOnOutputChangedFuzzTest") { - module_out_path = "distributed_audio/encoderonoutputchanged" + module_out_path = "${distributedaudio_fuzz_path}/encoderonoutputchanged" fuzz_config_file = "${audio_processor_path}/test/fuzztest/encoderonoutputchanged_fuzzer" diff --git a/services/audiotransport/receiverengine/src/av_receiver_engine_adapter.cpp b/services/audiotransport/receiverengine/src/av_receiver_engine_adapter.cpp index 4c00302b79071e777cdbee0407da3636be1fab2d..035b3cf66fd29f9935d1b6591c8f75afc3bf120d 100644 --- a/services/audiotransport/receiverengine/src/av_receiver_engine_adapter.cpp +++ b/services/audiotransport/receiverengine/src/av_receiver_engine_adapter.cpp @@ -168,12 +168,14 @@ int32_t AVTransReceiverAdapter::OnReceiverEvent(const AVTransEvent &event) { DHLOGI("On Receiver event, type: %d", event.type); switch (event.type) { + case EventType::EVENT_CHANNEL_OPEN_FAIL: case EventType::EVENT_CHANNEL_OPENED: { chnCreateSuccess_ = (event.type == EventType::EVENT_CHANNEL_OPENED); chnCreatedCondVar_.notify_one(); break; } case EventType::EVENT_CHANNEL_CLOSED: + case EventType::EVENT_START_FAIL: case EventType::EVENT_START_SUCCESS: case EventType::EVENT_STOP_SUCCESS: case EventType::EVENT_ENGINE_ERROR: diff --git a/services/audiotransport/senderengine/include/av_sender_engine_adapter.h b/services/audiotransport/senderengine/include/av_sender_engine_adapter.h index a838688e7f1df90fe4e286ea0e6d011e704b85fa..fff731b6f0a3340a9800e0c51f5bd96c00bcd655 100644 --- a/services/audiotransport/senderengine/include/av_sender_engine_adapter.h +++ b/services/audiotransport/senderengine/include/av_sender_engine_adapter.h @@ -58,8 +58,6 @@ public: int32_t CreateControlChannel(const std::string &peerDevId); int32_t RegisterAdapterCallback(const std::shared_ptr &back); - void SaveFile(std::string fileName, uint8_t *lastFrame, int32_t size); - int32_t OnSenderEvent(const AVTransEvent &event) override; int32_t OnMessageReceived(const std::shared_ptr &message) override; private: diff --git a/services/audiotransport/senderengine/src/av_sender_engine_adapter.cpp b/services/audiotransport/senderengine/src/av_sender_engine_adapter.cpp index bf1e0ba9ea295b29a2d80b3802c0b0b22cf69b9b..514db33f96e39e3141d53eb92d5f8523a2728bb6 100644 --- a/services/audiotransport/senderengine/src/av_sender_engine_adapter.cpp +++ b/services/audiotransport/senderengine/src/av_sender_engine_adapter.cpp @@ -145,9 +145,10 @@ int32_t AVTransSenderAdapter::PushData(std::shared_ptr &audioData) int32_t ret = senderEngine_->PushData(transBuffer); if (ret != DH_SUCCESS) { - DHLOGI("Push data to av transport sender failed"); + DHLOGE("Push data to av transport sender failed"); return ERR_DH_AV_TRANS_FEED_DATA_FAILED; } + DHLOGI("Push data to av sender success. data size: %d.", audioData->Size()); return DH_SUCCESS; } diff --git a/services/common/audioparam/audio_event.h b/services/common/audioparam/audio_event.h index 3a6178e8ef633620a982058766d0dd099c8501cd..5660ff40cc1f7552b8504ba6bc3597947d2cc952 100644 --- a/services/common/audioparam/audio_event.h +++ b/services/common/audioparam/audio_event.h @@ -37,6 +37,8 @@ typedef enum { SPEAKER_CLOSED = 14, NOTIFY_OPEN_SPEAKER_RESULT = 15, NOTIFY_CLOSE_SPEAKER_RESULT = 16, + NOTIFY_HDF_SPK_DUMP = 17, + NOTIFY_HDF_MIC_DUMP = 18, OPEN_MIC = 21, CLOSE_MIC = 22, @@ -92,6 +94,8 @@ typedef enum { AUDIO_EVENT_MMAP_STOP_MIC = 17, AUDIO_EVENT_START = 18, AUDIO_EVENT_STOP = 19, + AUDIO_EVENT_SPK_DUMP = 20, + AUDIO_EVENT_MIC_DUMP = 21, } AudioEventHDF; class AudioEvent { public: diff --git a/services/common/test/fuzztest/audiodatasetinit64_fuzzer/BUILD.gn b/services/common/test/fuzztest/audiodatasetinit64_fuzzer/BUILD.gn index c46552a21e480c2664f8ef82560788ec668bd97e..1330a291d6aba9155b72f42249156d9dcf369327 100644 --- a/services/common/test/fuzztest/audiodatasetinit64_fuzzer/BUILD.gn +++ b/services/common/test/fuzztest/audiodatasetinit64_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("AudioDataSetInit64FuzzTest") { - module_out_path = "distributed_audio/audiodatasetinit64_fuzzer" + module_out_path = "${distributedaudio_fuzz_path}/audiodatasetinit64_fuzzer" fuzz_config_file = "${services_path}/common/test/fuzztest/audiodatasetinit64_fuzzer" diff --git a/services/hdfaudioclient/include/daudio_adapter_internal.h b/services/hdfaudioclient/include/daudio_adapter_internal.h index 0f5eaebb07c8dad6489248bba1a1106f054559a0..78d0ebdf5bb893b315290e66efd1ffe41ac949b8 100644 --- a/services/hdfaudioclient/include/daudio_adapter_internal.h +++ b/services/hdfaudioclient/include/daudio_adapter_internal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -45,8 +45,8 @@ struct AudioAdapterContext { std::unique_ptr callbackInternal_ = nullptr; ParamCallback callback_ = nullptr; - std::vector> captures_; - std::vector> renders_; + std::vector>> captures_; + std::vector>> renders_; std::map> caps_; }; } // namespace DistributedHardware diff --git a/services/hdfaudioclient/src/daudio_adapter_internal.cpp b/services/hdfaudioclient/src/daudio_adapter_internal.cpp index 030daea29e62cc6677362fd6f8049bdc837b6f4f..1258b84d23f0b47e221b162c1b4e56645cb546d7 100644 --- a/services/hdfaudioclient/src/daudio_adapter_internal.cpp +++ b/services/hdfaudioclient/src/daudio_adapter_internal.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -87,7 +87,8 @@ static int32_t CreateRenderInternal(struct AudioAdapter *adapter, const struct : AudioSampleAttributes attrsHal; SetAudioSampleAttributesHAL(attrs, attrsHal); sptr renderProxy = nullptr; - int32_t ret = context->proxy_->CreateRender(descHal, attrsHal, renderProxy); + uint32_t renderId; + int32_t ret = context->proxy_->CreateRender(descHal, attrsHal, renderProxy, renderId); if (ret != DH_SUCCESS) { *render = nullptr; return ret; @@ -96,9 +97,10 @@ static int32_t CreateRenderInternal(struct AudioAdapter *adapter, const struct : *render = &renderContext->instance_; renderContext->proxy_ = renderProxy; renderContext->descHal_ = descHal; + DHLOGI("The render ID: %u.", renderId); { std::lock_guard lock(context->mtx_); - context->renders_.push_back(std::move(renderContext)); + context->renders_.push_back(std::make_pair(renderId, std::move(renderContext))); } return DH_SUCCESS; } @@ -120,8 +122,8 @@ static int32_t DestroyRenderInternal(struct AudioAdapter *adapter, struct AudioR std::lock_guard lock(adapterContext->mtx_); for (auto it = adapterContext->renders_.begin(); it != adapterContext->renders_.end(); ++it) { - if ((*it).get() == renderContext) { - int32_t ret = adapterContext->proxy_->DestroyRender(renderContext->descHal_); + if ((it->second).get() == renderContext) { + int32_t ret = adapterContext->proxy_->DestroyRender(it->first); if (ret != DH_SUCCESS) { return ret; } @@ -154,7 +156,8 @@ static int32_t CreateCaptureInternal(struct AudioAdapter *adapter, const struct AudioSampleAttributes attrsHal; SetAudioSampleAttributesHAL(attrs, attrsHal); sptr captureProxy = nullptr; - int32_t ret = context->proxy_->CreateCapture(descHal, attrsHal, captureProxy); + uint32_t captureId; + int32_t ret = context->proxy_->CreateCapture(descHal, attrsHal, captureProxy, captureId); if (ret != DH_SUCCESS) { *capture = nullptr; return ret; @@ -164,9 +167,10 @@ static int32_t CreateCaptureInternal(struct AudioAdapter *adapter, const struct *capture = &captureContext->instance_; captureContext->proxy_ = captureProxy; captureContext->descHal_ = descHal; + DHLOGI("The capture ID: %u.", captureId); { std::lock_guard lock(context->mtx_); - context->captures_.push_back(std::move(captureContext)); + context->captures_.push_back(std::make_pair(captureId, std::move(captureContext))); } return DH_SUCCESS; } @@ -188,8 +192,8 @@ static int32_t DestroyCaptureInternal(struct AudioAdapter *adapter, struct Audio std::lock_guard lock(adapterContext->mtx_); for (auto it = adapterContext->captures_.begin(); it != adapterContext->captures_.end(); ++it) { - if ((*it).get() == captureContext) { - int32_t ret = adapterContext->proxy_->DestroyCapture(captureContext->descHal_); + if ((it->second).get() == captureContext) { + int32_t ret = adapterContext->proxy_->DestroyCapture(it->first); if (ret != DH_SUCCESS) { return ret; } diff --git a/services/hdfaudioclient/src/daudio_capture_internal.cpp b/services/hdfaudioclient/src/daudio_capture_internal.cpp index 13ccf4f1c1b96ae368d871d0402c6af98fcbb577..3aaafa638bf7d27719e7cd9f1e407160f12b5c57 100644 --- a/services/hdfaudioclient/src/daudio_capture_internal.cpp +++ b/services/hdfaudioclient/src/daudio_capture_internal.cpp @@ -70,7 +70,7 @@ static int32_t CaptureFrameInternal(struct AudioCapture *capture, void *frame, u } int8_t *uframe = reinterpret_cast(frame); std::vector frameHal; - int32_t ret = context->proxy_->CaptureFrame(frameHal, requestBytes); + int32_t ret = context->proxy_->CaptureFrame(frameHal, *replyBytes); if (ret != DH_SUCCESS) { DHLOGE("Failed to capture frames."); return ret; diff --git a/services/hdfaudioclient/src/daudio_param_callback_internal.cpp b/services/hdfaudioclient/src/daudio_param_callback_internal.cpp index ea11fa67a2049113b0bd38fb5d606185f9d26c53..cb89b82c84515e1c4693c435437c9ff993f5e274 100644 --- a/services/hdfaudioclient/src/daudio_param_callback_internal.cpp +++ b/services/hdfaudioclient/src/daudio_param_callback_internal.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -36,7 +36,7 @@ public: int32_t RenderCallback(AudioCallbackType type, int8_t &reserved, int8_t &cookie) override; int32_t ParamCallback(AudioExtParamKey key, const std::string& condition, const std::string& value, - int8_t &reserved, int8_t &cookie) override; + int8_t &reserved, int8_t cookie) override; private: ::ParamCallback callback_ = nullptr; void *cookie_ = nullptr; @@ -55,7 +55,7 @@ int32_t AudioParamCallbackImpl::RenderCallback(AudioCallbackType type, int8_t &r } int32_t AudioParamCallbackImpl::ParamCallback(AudioExtParamKey key, const std::string& condition, - const std::string& value, int8_t &reserved, int8_t &cookie) + const std::string& value, int8_t &reserved, int8_t cookie) { (void) cookie; if (callback_ != nullptr) { diff --git a/services/hdfaudioclient/src/daudio_render_callback_internal.cpp b/services/hdfaudioclient/src/daudio_render_callback_internal.cpp index 0e103915c5801178081f91bc1f03c41ec2118e4d..9facc92be22d4a79f90d7bc52c92b7e993121fbd 100644 --- a/services/hdfaudioclient/src/daudio_render_callback_internal.cpp +++ b/services/hdfaudioclient/src/daudio_render_callback_internal.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -32,7 +32,7 @@ public: int32_t RenderCallback(AudioCallbackType type, int8_t &reserved, int8_t &cookie) override; int32_t ParamCallback(AudioExtParamKey key, const std::string& condition, const std::string& value, - int8_t &reserved, int8_t &cookie) override; + int8_t &reserved, int8_t cookie) override; private: ::RenderCallback callback_ = nullptr; @@ -57,7 +57,7 @@ int32_t AudioRenderCallbackImpl::RenderCallback(AudioCallbackType type, int8_t & } int32_t AudioRenderCallbackImpl::ParamCallback(AudioExtParamKey key, const std::string& condition, - const std::string& value, int8_t &reserved, int8_t &cookie) + const std::string& value, int8_t &reserved, int8_t cookie) { (void) reserved; (void) cookie; diff --git a/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.cpp b/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.cpp index a1f167a07513f702b0d3faab491ffda344c38fca..a0f22c09630935e49bd6c4da8d7778c29f3128fe 100644 --- a/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.cpp +++ b/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 diff --git a/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h b/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h index 03567108063256a49148e97c22ef0e99af25b7d0..e083a165d129a771d137b96453b529fe1d93ba6c 100644 --- a/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h +++ b/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -54,23 +54,23 @@ public: } int32_t CreateRender(const AudioDeviceDescriptor& desc, const AudioSampleAttributes& attrs, - sptr& render) override + sptr& render, uint32_t &renderId) override { return DH_SUCCESS; } - int32_t DestroyRender(const AudioDeviceDescriptor& desc) override + int32_t DestroyRender(uint32_t renderId) override { return DH_SUCCESS; } int32_t CreateCapture(const AudioDeviceDescriptor& desc, const AudioSampleAttributes& attrs, - sptr& capture) override + sptr& capture, uint32_t &captureId) override { return DH_SUCCESS; } - int32_t DestroyCapture(const AudioDeviceDescriptor& desc) override + int32_t DestroyCapture(uint32_t captureId) override { return DH_SUCCESS; } diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn index b2690de12705522bfb2ca9d00b2240f0d6b95847..a4b795504796178c92e2cac504fd35a4d8e6a9fe 100644 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn +++ b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SoftbusOnBytesReceivedFuzzTest") { - module_out_path = "distributed_audio/softbusonbytesreceived" + module_out_path = "${distributedaudio_fuzz_path}/softbusonbytesreceived" fuzz_config_file = "${softbusadapter_path}/test/fuzztest/softbusonbytesreceived_fuzzer" diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn index c8ae11449ffa8370b43b0bb65349baeaf5c369df..dac1a93c9414545dbac983c1ede3214cae2cc1f7 100644 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn +++ b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SoftbusOnSessionClosedFuzzTest") { - module_out_path = "distributed_audio/softbusonsessionclosed" + module_out_path = "${distributedaudio_fuzz_path}/softbusonsessionclosed" fuzz_config_file = "${softbusadapter_path}/test/fuzztest/softbusonsessionclosed_fuzzer" diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn index d8e08c9cb7c22858a8c8b0ca9f9a8618c05d9f35..467d2a08a1fb4ee90bac907ec3f2eb411c83b2a7 100644 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn +++ b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SoftbusOnSessionOpenedFuzzTest") { - module_out_path = "distributed_audio/softbusonsessionopened" + module_out_path = "${distributedaudio_fuzz_path}/softbusonsessionopened" fuzz_config_file = "${softbusadapter_path}/test/fuzztest/softbusonsessionopened_fuzzer" diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn index f8a875b642458c46fbb0b5a4e5c123a277cd86eb..f491ff04abbe7b0bf74ba87af04d9910875c82d3 100644 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn +++ b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("../../../../../distributedaudio.gni") ##############################fuzztest########################################## ohos_fuzztest("SoftbusOnStreamReceivedFuzzTest") { - module_out_path = "distributed_audio/softbusonstreamreceived" + module_out_path = "${distributedaudio_fuzz_path}/softbusonstreamreceived" fuzz_config_file = "${softbusadapter_path}/test/fuzztest/softbusonstreamreceived_fuzzer" diff --git a/services/test_example/BUILD.gn b/services/test_example/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6035c81cf2fb6347acb86657dab50e0ea0f4345b --- /dev/null +++ b/services/test_example/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +ohos_executable("audio_distributed_test") { + include_dirs = [ + "./include", + "${driver_audio_path}/include", + "${hdf_service_path}/hdi_service/common/include", + "${services_path}/hdfaudioclient/include", + ] + + sources = [ "distributedaudiotest.cpp" ] + + deps = [ "${services_path}/hdfaudioclient:daudio_client" ] + + external_deps = [ + "c_utils:utils", + "hdf_core:libhdf_utils", + "hilog:libhilog", + ] + + defines = [ + "DH_LOG_TAG=\"daudioTest\"", + "HI_LOG_ENABLE", + "LOG_DOMAIN=0xD004100", + ] + + install_enable = false + subsystem_name = "distributedhardware" + part_name = "distributed_audio" +} diff --git a/services/test_example/distributedaudiotest.cpp b/services/test_example/distributedaudiotest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a527fcc1447017ec9c8f9363e23d662ab8b8af84 --- /dev/null +++ b/services/test_example/distributedaudiotest.cpp @@ -0,0 +1,696 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include "unistd.h" +#include "distributedaudiotest.h" + +namespace { +using namespace OHOS::DistributedHardware; +const int32_t CMD_QUIT = 0; +const int32_t CMD_FIND = 9; +const int32_t CMD_OPEN_SPK = 1; +const int32_t CMD_CLOSE_SPK = 2; +const int32_t CMD_START_SPK = 3; +const int32_t CMD_STOP_SPK = 4; +const int32_t CMD_OPEN_MIC = 5; +const int32_t CMD_CLOSE_MIC = 6; +const int32_t CMD_START_MIC = 7; +const int32_t CMD_STOP_MIC = 8; +const int32_t CMD_SET_VOL = 11; +const int32_t CMD_GET_VOL = 12; + +const char DEV_TYPE_SPK = '1'; +const char DEV_TYPE_MIC = '2'; +const char SPK_FILE_PATH[128] = "/data/test.wav"; +const char MIC_FILE_PATH[128] = "/data/mic.pcm"; +constexpr int32_t TYPE_OFFSET = 12; +constexpr int32_t AUDIO_SAMPLE_RATE = 48000; +constexpr int32_t VOLUME_MIN = 0; +constexpr int32_t VOLUME_MAX = 15; +constexpr int32_t VOLUME_BIT = 3; +constexpr int32_t RENDER_FRAME_SIZE = 4096; +constexpr int32_t RENDER_INTER_LEAVED = 1; +constexpr int32_t RENDER_STREAM_ID = 0; +constexpr int32_t RENDER_CHANNEL_MASK = 2; +constexpr int32_t CAPTURE_INTER_LEAVED = 1; +constexpr int32_t CAPTURE_STREAM_ID = 2; +constexpr int32_t CAPTURE_CHANNEL_MASK = 2; +constexpr int32_t MILLISECOND_PER_SECOND = 1000; +constexpr int64_t AUDIO_FRAME_TIME_INTERFAL_DEFAULT = 21333; +constexpr int32_t CMD_EXECUTING_RETURN_LENGHT_MAX = 500; + +static AudioManager *g_manager = nullptr; +static AudioAdapter *g_adapter = nullptr; +static AudioRender *g_render = nullptr; +static AudioCapture *g_capture = nullptr; +static AudioAdapterDescriptor *g_devices = nullptr; + +static std::string g_devId = ""; + +static constexpr const char* PLAY_THREAD = "playThread"; +static constexpr const char* CAPTURE_THREAD = "captureThread"; + +int32_t g_deviceNum = 0; +int32_t g_frameNum = 0; +int32_t g_frameIndex = 0; +int32_t g_micFrameNum = 0; +bool g_isInitRenderData = false; +static std::vector renderData; + +static DeviceStatus g_spkStatus = DEVICE_IDLE; +static DeviceStatus g_micStatus = DEVICE_IDLE; + +static std::thread g_playingThread; +static std::thread g_capingThread; +FILE *g_micFile = nullptr; + +static std::string CloseSpk(); +static std::string CloseMic(); + +static int64_t GetNowTimeUs() +{ + std::chrono::microseconds nowUs = + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); + return nowUs.count(); +} + +static int32_t GetUserInput() +{ + int32_t res = -1; + size_t count = 3; + std::cout << ">>"; + std::cin >> res; + while (std::cin.fail() && count-- > 0) { + std::cin.clear(); + std::cin.ignore(); + std::cout << "invalid input, not a number! Please retry with a number." << std::endl; + std::cout << ">>"; + std::cin >> res; + } + return res; +} + +static void FindAudioDevice() +{ + if (g_manager == nullptr) { + std::cout << "Audio manager is null, Please Check network!" << std::endl; + return; + } + int32_t ret = g_manager->GetAllAdapters(g_manager, &g_devices, &g_deviceNum); + if (ret != DH_SUCCESS) { + std::cout << "Get audio devices failed!" << std::endl; + return; + } + for (int32_t index = 0; index < g_deviceNum; index++) { + const AudioAdapterDescriptor &desc = g_devices[index]; + if (index == 0) { + g_devId = desc.adapterName; + break; + } + } +} + +static int32_t InitTestDemo() +{ + std::cout << "**********************************************************************************" << std::endl; + std::cout << "Distributed Audio Test Demo Bin v1.3." << std::endl; + std::cout << "**********************************************************************************" << std::endl; + std::cout << std::endl; + std::cout << "Init distributed audio hdf service." << std::endl; + g_manager = GetAudioManagerFuncs(); + if (g_manager == nullptr) { + std::cout << "Distributed audio manager is null, Please Check network!" << std::endl; + return ERR_DH_AUDIO_HDF_FAIL; + } + std::cout << "Load audio manager success." << std::endl; + FindAudioDevice(); + if (g_devId.empty()) { + std::cout << "Cannot find distributed device. Please input 9 to query distribtued device." << std::endl; + } else { + std::cout << "Find one distributed device: " << g_devId << std::endl; + } + return DH_SUCCESS; +} + +static void HandleDevError(const char *condition, const char *value) +{ + if (condition[TYPE_OFFSET] == DEV_TYPE_SPK && g_spkStatus != DEVICE_IDLE) { + CloseSpk(); + } + + if (condition[TYPE_OFFSET] == DEV_TYPE_MIC && g_micStatus == DEVICE_IDLE) { + CloseMic(); + } + + std::cout << "Receive abnormal event, Demo quit." << std::endl; +} + +static int32_t ParamEventCallback(AudioExtParamKey key, const char *condition, const char *value, void *reserved, + void *cookie) +{ + std::string val(value); + std::string con(condition); + std::cout << std::endl; + std::cout << "**********************************************************************************" << std::endl; + std::cout << "Event recived: " << key << std::endl; + std::cout << "Condition: " << con << std::endl; + std::cout << "Value: " << val << std::endl; + std::cout << "**********************************************************************************" << std::endl; + std::cout << std::endl; + + if (key == AudioExtParamKey::AUDIO_EXT_PARAM_KEY_STATUS && con.rfind("ERR_EVENT", 0) == 0) { + HandleDevError(condition, value); + } + return DH_SUCCESS; +} + +static int32_t LoadSpkDev(const std::string &devId) +{ + struct AudioAdapterDescriptor *dev = nullptr; + for (int32_t index = 0; index < g_deviceNum; index++) { + struct AudioAdapterDescriptor &desc = g_devices[index]; + if (desc.adapterName == devId) { + dev = &desc; + break; + } + } + if (dev == nullptr) { + std::cout << "Input device id is wrong." << std::endl; + FindAudioDevice(); + return ERR_DH_AUDIO_HDF_FAIL; + } + if (g_manager == nullptr) { + return ERR_DH_AUDIO_HDF_FAIL; + } + if (g_adapter == nullptr) { + int32_t ret = g_manager->LoadAdapter(g_manager, dev, &g_adapter); + if (ret != DH_SUCCESS || g_adapter == nullptr) { + std::cout << "Load audio device failed, ret: " << ret << std::endl; + return ERR_DH_AUDIO_HDF_FAIL; + } + } + return DH_SUCCESS; +} + +static void OpenSpk(const std::string &devId) +{ + if (g_spkStatus != DEVICE_IDLE) { + std::cout << "Speaker device is already opened." << std::endl; + return; + } + if (LoadSpkDev(devId) != DH_SUCCESS) { + std::cout << "Load spk failed" << std::endl; + return; + } + ParamCallback callback = ParamEventCallback; + int32_t ret = g_adapter->RegExtraParamObserver(g_adapter, callback, nullptr); + if (ret != DH_SUCCESS) { + std::cout << "Register observer failed, ret: " << ret << std::endl; + return; + } + + struct AudioDeviceDescriptor renderDesc; + renderDesc.pins = AudioPortPin::PIN_OUT_SPEAKER; + renderDesc.desc = nullptr; + AudioSampleAttributes g_rattrs = {}; + g_rattrs.type = AUDIO_IN_MEDIA; + g_rattrs.interleaved = RENDER_INTER_LEAVED; + g_rattrs.streamId = RENDER_STREAM_ID; + g_rattrs.channelCount = RENDER_CHANNEL_MASK; + g_rattrs.sampleRate = AUDIO_SAMPLE_RATE; + g_rattrs.format = AudioFormat::AUDIO_FORMAT_TYPE_PCM_16_BIT; + ret = g_adapter->CreateRender(g_adapter, &renderDesc, &g_rattrs, &g_render); + if (ret != DH_SUCCESS || g_render == nullptr) { + std::cout << "Open SPK device failed, ret: " << ret << std::endl; + return; + } + g_spkStatus = DEVICE_OPEN; + std::cout << "Open SPK device success." << std::endl; +} + +static void WriteStreamWait(const int64_t &startTime) +{ + int64_t endTime = GetNowTimeUs(); + int64_t passTime = endTime - startTime; + + if (passTime > AUDIO_FRAME_TIME_INTERFAL_DEFAULT) { + return; + } + int64_t remainTime = AUDIO_FRAME_TIME_INTERFAL_DEFAULT - passTime; + std::this_thread::sleep_for(std::chrono::microseconds(remainTime)); +} + +static void Play() +{ + if (g_render == nullptr) { + std::cout << "SPK device is null." << std::endl; + return; + } + if (pthread_setname_np(pthread_self(), PLAY_THREAD) != DH_SUCCESS) { + std::cout << "Play thread setname failed." << std::endl; + } + std::cout << "Playing thread started." << std::endl; + g_render->control.Start((AudioHandle)g_render); + g_spkStatus = DEVICE_START; + + uint64_t size = 0; + while (g_spkStatus == DEVICE_START) { + int64_t startTime = GetNowTimeUs(); + int32_t ret = g_render->RenderFrame(g_render, renderData[g_frameIndex], RENDER_FRAME_SIZE, &size); + if (ret != DH_SUCCESS) { + std::cout<<"RenderFrame failed, index: "<< g_frameIndex << ", ret: " << ret << std::endl; + } + g_frameIndex++; + if (g_frameNum != 0 && g_frameIndex == g_frameNum) { + g_frameIndex = 0; + } + WriteStreamWait(startTime); + } + std::cout << "Playing thread stopped." << std::endl; +} + +static void StartRender() +{ + if (g_spkStatus == DEVICE_IDLE) { + std::cout << "Speaker device is not opened, start render failed." << std::endl; + return; + } + + if (g_spkStatus == DEVICE_OPEN) { + WavHdr wavHeader; + size_t headerSize = sizeof(WavHdr); + if (!g_isInitRenderData) { + struct stat statbuf; + stat(SPK_FILE_PATH, &statbuf); + int32_t size = statbuf.st_size; + g_frameNum = (size - headerSize) / RENDER_FRAME_SIZE; + std::cout << "Audio file frame num: " << g_frameNum << std::endl; + for (int32_t j = 0; j < g_frameNum; j++) { + uint8_t *frame = new uint8_t[RENDER_FRAME_SIZE](); + renderData.push_back(frame); + } + g_isInitRenderData = true; + } + FILE *wavFile = fopen(SPK_FILE_PATH, "rb"); + fread(&wavHeader, 1, headerSize, wavFile); + for (int32_t i = 0; i < g_frameNum; i++) { + fread(renderData[i], 1, RENDER_FRAME_SIZE, wavFile); + } + fclose(wavFile); + g_frameIndex = 0; + g_playingThread = std::thread(Play); + return; + } + if (g_spkStatus == DEVICE_START) { + std::cout << "Speaker device is started." << std::endl; + return; + } + if (g_spkStatus == DEVICE_STOP) { + g_playingThread = std::thread(Play); + } +} + +static void StopRender() +{ + if (g_render == nullptr) { + std::cout << "SPK device is null." << std::endl; + return; + } + + if (g_spkStatus == DEVICE_IDLE) { + std::cout << "Speaker device is not opened." << std::endl; + return; + } + + if (g_spkStatus == DEVICE_OPEN) { + std::cout << "Speaker device is not started." << std::endl; + return; + } + + if (g_spkStatus == DEVICE_STOP) { + std::cout << "Speaker device is already stoped." << std::endl; + return; + } + + g_spkStatus = DEVICE_STOP; + if (g_playingThread.joinable()) { + g_playingThread.join(); + } + g_render->control.Stop((AudioHandle)g_render); +} + +static void CloseSpk() +{ + if (g_spkStatus == DEVICE_IDLE) { + std::cout << "Speaker device is not opened." << std::endl; + return; + } + + if (g_spkStatus == DEVICE_START) { + StopRender(); + } + + int32_t ret = g_adapter->DestroyRender(g_adapter, g_render); + if (ret != DH_SUCCESS) { + std::cout << "Close speaker failed" << std::endl; + return; + } + if (g_micStatus == DEVICE_IDLE) { + g_manager->UnloadAdapter(g_manager, g_adapter); + g_adapter = nullptr; + } + g_spkStatus = DEVICE_IDLE; + + if (g_isInitRenderData) { + for (auto &p : renderData) { + delete[] p; + } + renderData.clear(); + g_isInitRenderData = false; + } + std::cout << "Close SPK device success." << std::endl; +} + +static int32_t LoadMicDev(const std::string &devId) +{ + struct AudioAdapterDescriptor *dev = nullptr; + for (int32_t index = 0; index < g_deviceNum; index++) { + struct AudioAdapterDescriptor &desc = g_devices[index]; + if (desc.adapterName == devId) { + dev = &desc; + break; + } + } + if (dev == nullptr) { + std::cout << "Input device id is wrong." << std::endl; + FindAudioDevice(); + return ERR_DH_AUDIO_HDF_FAIL; + } + if (g_manager == nullptr) { + return ERR_DH_AUDIO_HDF_FAIL; + } + if (g_adapter == nullptr) { + int32_t ret = g_manager->LoadAdapter(g_manager, dev, &g_adapter); + if (ret != DH_SUCCESS || g_adapter == nullptr) { + std::cout << "Load audio device failed, ret: " << ret << std::endl; + return ERR_DH_AUDIO_HDF_FAIL; + } + } + return DH_SUCCESS; +} + +static void OpenMic(const std::string &devId) +{ + if (g_micStatus != DEVICE_IDLE) { + std::cout << "Mic device is already opened." << std::endl; + return; + } + if (LoadMicDev(devId) != DH_SUCCESS) { + std::cout << "Load audio device failed." << std::endl; + return; + } + + AudioDeviceDescriptor captureDesc; + captureDesc.pins = AudioPortPin::PIN_IN_MIC; + captureDesc.desc = nullptr; + AudioSampleAttributes captureAttr; + captureAttr.type = AUDIO_IN_MEDIA; + captureAttr.interleaved = CAPTURE_INTER_LEAVED; + captureAttr.streamId = CAPTURE_STREAM_ID; + captureAttr.channelCount = CAPTURE_CHANNEL_MASK; + captureAttr.sampleRate = AUDIO_SAMPLE_RATE; + captureAttr.format = AudioFormat::AUDIO_FORMAT_TYPE_PCM_16_BIT; + int32_t ret = g_adapter->CreateCapture(g_adapter, &captureDesc, &captureAttr, &g_capture); + if (ret != DH_SUCCESS || g_capture == nullptr) { + std::cout << "Open MIC device failed." << std::endl; + return; + } + g_micStatus = DEVICE_OPEN; + std::cout << "Open MIC device success." << std::endl; +} + +static void ReadStreamWait(const int64_t &startTime) +{ + int64_t endTime = GetNowTimeUs(); + int32_t passTime = endTime - startTime; + + if (passTime > AUDIO_FRAME_TIME_INTERFAL_DEFAULT) { + return; + } + int64_t remainTime = AUDIO_FRAME_TIME_INTERFAL_DEFAULT - passTime; + std::this_thread::sleep_for(std::chrono::microseconds(remainTime)); +} + +static void Capture() +{ + if (g_capture == nullptr) { + std::cout << "MIC device is null." << std::endl; + return; + } + if (pthread_setname_np(pthread_self(), CAPTURE_THREAD) != DH_SUCCESS) { + std::cout << "Capture thread setname failed." << std::endl; + } + std::cout << "Capturing thread started." << std::endl; + g_capture->control.Start((AudioHandle)g_capture); + g_micStatus = DEVICE_START; + + uint64_t size = 0; + while (g_micStatus == DEVICE_START) { + uint8_t *data[RENDER_FRAME_SIZE]; + int64_t startTime = GetNowTimeUs(); + int32_t ret = g_capture->CaptureFrame(g_capture, data, RENDER_FRAME_SIZE, &size); + if (ret != DH_SUCCESS) { + std::cout << "CaptureFrame failed, ret: " << ret << std::endl; + return; + } + int32_t writeCnt = fwrite(data, 1, RENDER_FRAME_SIZE, g_micFile); + if (writeCnt != RENDER_FRAME_SIZE) { + std::cout << "fwrite data failed." << std::endl; + } + g_micFrameNum++; + ReadStreamWait(startTime); + } + std::cout << "Capturing thread stopped." << std::endl; +} + +static void StartCapture() +{ + if (g_micStatus == DEVICE_IDLE) { + std::cout << "Mic device is not opened, start capture failed." << std::endl; + return; + } + + if (g_micStatus == DEVICE_OPEN) { + g_micFile = fopen(MIC_FILE_PATH, "ab+"); + if (g_micFile == nullptr) { + std::cout << "Open pcm file failed." << std::endl; + return; + } + g_capingThread = std::thread(Capture); + return; + } + + if (g_micStatus == DEVICE_START) { + std::cout << "Mic device is already started." << std::endl; + return; + } + + if (g_micStatus == DEVICE_STOP) { + g_capingThread = std::thread(Capture); + } +} + +static void StopCapture() +{ + if (g_capture == nullptr) { + std::cout << "MIC device is null." << std::endl; + return; + } + if (g_micStatus == DEVICE_IDLE) { + std::cout << "Mic device is not opened." << std::endl; + return; + } + if (g_micStatus == DEVICE_OPEN) { + std::cout << "Mic device is not started." << std::endl; + return; + } + if (g_micStatus == DEVICE_STOP) { + std::cout << "Mic device is already started." << std::endl; + return; + } + g_micStatus = DEVICE_STOP; + if (g_capingThread.joinable()) { + g_capingThread.join(); + } + g_capture->control.Stop((AudioHandle)g_capture); +} + +static void CloseMic() +{ + if (g_micStatus == DEVICE_IDLE) { + std::cout << "Mic device is not opened." << std::endl; + return; + } + + if (g_micStatus == DEVICE_START) { + StopCapture(); + } + + int32_t ret = g_adapter->DestroyCapture(g_adapter, g_capture); + if (ret != DH_SUCCESS) { + std::cout << "Close mic failed." << std::endl; + return; + } + if (g_spkStatus == DEVICE_IDLE) { + g_manager->UnloadAdapter(g_manager, g_adapter); + g_adapter = nullptr; + } + if (g_micFile != nullptr) { + fclose(g_micFile); + g_micFile = nullptr; + } + g_micStatus = DEVICE_IDLE; + std::cout << "Close MIC device success." << std::endl; +} + +static void SetVolume() +{ + if (g_spkStatus == DEVICE_IDLE) { + std::cout << "Speaker is not opened, can not set volume." << std::endl; + return; + } + std::cout << "Please input volum to set [0,15]." << std::endl; + int32_t volInt = GetUserInput(); + if (volInt < VOLUME_MIN || volInt > VOLUME_MAX) { + std::cout << "Volume is invalid." << std::endl; + return; + } + std::cout << "Set volume: " << volInt << std::endl; + AudioExtParamKey key = AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME; + std::string condition = "EVENT_TYPE=1;VOLUME_GROUP_ID=1;AUDIO_VOLUME_TYPE=1;"; + int32_t ret = g_adapter->SetExtraParams(g_adapter, key, condition.c_str(), vol.c_str()); + if (ret != DH_SUCCESS) { + std::cout << "Set volume failed" << std::endl; + } +} + +static void GetVolume() +{ + if (g_spkStatus == DEVICE_IDLE) { + std::cout << "Speaker is not opened, can not get volume." << std::endl; + return; + } + AudioExtParamKey key = AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME; + std::string condition = "EVENT_TYPE=1;VOLUME_GROUP_ID=1;AUDIO_VOLUME_TYPE=1;"; + char vol[VOLUME_BIT]; + int32_t ret = g_adapter->GetExtraParams(g_adapter, key, condition.c_str(), vol, VOLUME_BIT); + if (ret != DH_SUCCESS) { + std::cout << "Get Volume failed." << std::endl; + return; + } + std::cout << "Get volume success. volume: " << vol < +#include +#include +#include +#include +#include +#include + +#include "audio_adapter.h" +#include "audio_manager.h" +#include "audio_types.h" +#include "daudio_errcode.h" + +enum class DeviceStatus : uint32_t { + DEVICE_IDLE = 0, + DEVICE_OPEN = 1, + DEVICE_START = 2, + DEVICE_STOP = 3, +}; + +struct WAV_HEADER { + /* RIFF Chunk Descriptor */ + uint8_t riff[4] = {'R', 'I', 'F', 'F'}; + uint32_t chunkSize = 0; + uint8_t wave[4] = {'W', 'A', 'V', 'E'}; + /* "fmt" sub-chunk */ + uint8_t fmt[4] = {'f', 'm', 't', ' '}; + uint32_t subchunk1Size = 16; + uint16_t audioFormat = 1; + uint16_t numOfChan = 2; + uint32_t samplesPerSec = 44100; + uint32_t bytesPerSec = 176400; + uint16_t blockAlign = 2; + uint16_t bitsPerSample = 16; + /* "data" sub-chunk */ + uint8_t subchunk2ID[4] = {'d', 'a', 't', 'a'}; + uint32_t subchunk2Size = 0; +}; +using WavHdr = struct WAV_HEADER; + +#endif \ No newline at end of file