diff --git a/bluetooth/a2dp/include/BUILD.gn b/bluetooth/a2dp/include/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ee844322b0138a430c4ac72ad8c2e1c33baaba8e --- /dev/null +++ b/bluetooth/a2dp/include/BUILD.gn @@ -0,0 +1,27 @@ +# Copyright (c) 2025 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") + +config("hdi_audio_bluetooth_header_config") { + include_dirs = [ + "./", + ] +} + +ohos_static_library("hdi_audio_bluetooth_header") { + public_configs = [ ":hdi_audio_bluetooth_header_config" ] + + subsystem_name = "hdf" + part_name = "drivers_interface_bluetooth" +} \ No newline at end of file diff --git a/bluetooth/a2dp/include/audio_adapter.h b/bluetooth/a2dp/include/audio_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..04d4ab776efcbabfa833d0f87943e5a7a2b7c73b --- /dev/null +++ b/bluetooth/a2dp/include/audio_adapter.h @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_adapter.h + * + * @brief Declares APIs for operations related to the audio adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_ADAPTER_H +#define AUDIO_ADAPTER_H + +#include "audio_types.h" +#include "audio_render.h" +#include "audio_capture.h" +namespace OHOS::HDI::Audio_Bluetooth { +/** + * @brief Provides audio adapter capabilities, including initializing ports, creating rendering and capturing tasks, + * and obtaining the port capability set. + * + * @see AudioRender + * @see AudioCapture + * @since 1.0 + * @version 1.0 + */ +struct AudioAdapter { + /** + * @brief Initializes all ports of an audio adapter. + * + * Call this function before calling other driver functions to check whether the initialization is complete. + * If the initialization is not complete, wait for a while (for example, 100 ms) and perform the check again + * until the port initialization is complete. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @return Returns 0 if the initialization is successful; returns a negative value otherwise. + */ + int32_t (*InitAllPorts)(struct AudioAdapter *adapter); + + /** + * @brief Creates an AudioRender object. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param desc Indicates the pointer to the descriptor of the audio adapter to start. + * @param attrs Indicates the pointer to the audio sampling attributes to open. + * @param render Indicates the double pointer to the AudioRender object. + * @return Returns 0 if the AudioRender object is created successfully; + * returns a negative value otherwise. + * @see GetPortCapability + * @see DestroyRender + */ + int32_t (*CreateRender)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, + const struct AudioSampleAttributes *attrs, struct AudioRender **render); + + /** + * @brief Creates an AudioCapture object. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param desc Indicates the pointer to the descriptor of the audio adapter to start. + * @param attrs Indicates the pointer to the audio sampling attributes to open. + * @param capture Indicates the double pointer to the AudioCapture object. + * @return Returns 0 if the AudioCapture object is created successfully; + * returns a negative value otherwise. + * @see GetPortCapability + * @see DestroyCapture + */ + int32_t (*CreateCapture)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, + const struct AudioSampleAttributes *attrs, struct AudioCapture **capture); + + /** + * @brief Destroys an AudioRender object. + * + * @attention Do not destroy the object during audio rendering. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param render Indicates the pointer to the AudioRender object to operate. + * @return Returns 0 if the AudioRender object is destroyed; returns a negative value otherwise. + * @see CreateRender + */ + int32_t (*DestroyRender)(struct AudioAdapter *adapter, struct AudioRender *render); + + /** + * @brief Destroys an AudioCapture object. + * + * @attention Do not destroy the object during audio capturing. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param capture Indicates the pointer to the AudioCapture object to operate. + * @return Returns 0 if the AudioCapture object is destroyed; returns a negative value otherwise. + * @see CreateCapture + */ + int32_t (*DestroyCapture)(struct AudioAdapter *adapter, struct AudioCapture *capture); + + /** + * @brief Obtains the capability set of the port driver for the audio adapter. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param port Indicates the pointer to the port. + * @param capability Indicates the pointer to the capability set to obtain. + * @return Returns 0 if the capability set is successfully obtained; returns a negative value otherwise. + */ + int32_t (*GetPortCapability)(struct AudioAdapter *adapter, const struct AudioPort *port, + struct AudioPortCapability *capability); + + /** + * @brief Sets the passthrough data transmission mode of the audio port driver. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param port Indicates the pointer to the port. + * @param mode Indicates the passthrough transmission mode to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetPassthroughMode + */ + int32_t (*SetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, + enum AudioPortPassthroughMode mode); + + /** + * @brief Obtains the passthrough data transmission mode of the audio port driver. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param port Indicates the pointer to the port. + * @param mode Indicates the pointer to the passthrough transmission mode to obtain. + * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. + * @see SetPassthroughMode + */ + int32_t (*GetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, + enum AudioPortPassthroughMode *mode); + + /** + * @brief Sets extra audio parameters. + * + * @param adapter Indicates the audio adapter. + * @param key Indicates what kind of parameter type will be set. + * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. + * @param value Indicates the value of the specified condition. + * + * The format of condition is key=value. Separate multiple key-value pairs by semicolons (;). + * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: + * "EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;" + * EVENT_TYPE indicates sub volume event type: SetVolume = 1; SetMute = 4; + * VOLUME_GROUP_ID indicates which volume group will be set; + * AUDIO_VOLUME_TYPE indicates which volume type will be set; + * + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*SetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, + const char *condition, const char *value); + + /** + * @brief Get extra audio parameters. + * + * @param adapter Indicates the audio adapter. + * @param key Indicates what kind of parameter type will be get. + * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. + * @param value Indicates the value of the specified condition. + * @param lenth Indicates the length of the value pointer. + * + * The format of condition is key=value. Separate multiple key-value pairs by semicolons (;). + * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: + * "EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;" + * EVENT_TYPE indicates sub volume event type: GetVolume = 1; GetMinVolume = 2; GetMaxVolume = 3; IsStreamMute = 4; + * VOLUME_GROUP_ID indicates which volume group want get; + * AUDIO_VOLUME_TYPE indicates which volume type want get; + * + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, + const char *condition, char *value, int32_t lenth); +}; +} +#endif /* AUDIO_ADAPTER_H */ +/** @} */ diff --git a/bluetooth/a2dp/include/audio_attribute.h b/bluetooth/a2dp/include/audio_attribute.h new file mode 100644 index 0000000000000000000000000000000000000000..7911f587bb1b4b6886533e272e19124976cb9f04 --- /dev/null +++ b/bluetooth/a2dp/include/audio_attribute.h @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_attribute.h + * + * @brief Declares APIs for audio attributes. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_ATTRIBUTE_H +#define AUDIO_ATTRIBUTE_H + +#include "audio_types.h" +namespace OHOS::HDI::Audio_Bluetooth { +/** + * @brief Provides attribute-related APIs for audio rendering or capturing, including functions to + * obtain frame information and set audio sampling attributes. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioAttribute { + /** + * @brief Obtains the audio frame size, that is, the length (in bytes) of a frame. + * + * @param handle Indicates the audio handle. + * @param size Indicates the pointer to the audio frame size (in bytes). + * @return Returns 0 if the audio frame size is obtained; returns a negative value otherwise. + */ + int32_t (*GetFrameSize)(AudioHandle handle, uint64_t *size); + + /** + * @brief Obtains the number of audio frames in the audio buffer. + * + * @param handle Indicates the audio handle. + * @param count Indicates the pointer to the number of audio frames in the audio buffer. + * @return Returns 0 if the number of audio frames is obtained; returns a negative value otherwise. + */ + int32_t (*GetFrameCount)(AudioHandle handle, uint64_t *count); + + /** + * @brief Sets audio sampling attributes. + * + * @param handle Indicates the audio handle. + * @param attrs Indicates the pointer to the audio sampling attributes to set, such as the sampling rate, + * sampling precision, and channel. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetSampleAttributes + */ + int32_t (*SetSampleAttributes)(AudioHandle handle, const struct AudioSampleAttributes *attrs); + + /** + * @brief Obtains audio sampling attributes. + * + * @param handle Indicates the audio handle. + * @param attrs Indicates the pointer to the audio sampling attributes, such as the sampling rate, + * sampling precision, and channel. + * @return Returns 0 if audio sampling attributes are obtained; returns a negative value otherwise. + * @see SetSampleAttributes + */ + int32_t (*GetSampleAttributes)(AudioHandle handle, struct AudioSampleAttributes *attrs); + + /** + * @brief Obtains the data channel ID of the audio. + * + * @param handle Indicates the audio handle. + * @param channelId Indicates the pointer to the data channel ID. + * @return Returns 0 if the data channel ID is obtained; returns a negative value otherwise. + */ + int32_t (*GetCurrentChannelId)(AudioHandle handle, uint32_t *channelId); + + /** + * @brief Sets extra audio parameters. + * + * @param handle Indicates the audio handle. + * @param keyValueList Indicates the pointer to the key-value list of the extra audio parameters. + * The format is key=value. Separate multiple key-value pairs by semicolons (;). + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*SetExtraParams)(AudioHandle handle, const char *keyValueList); + + /** + * @brief Obtains extra audio parameters. + * + * @param handle Indicates the audio handle. + * @param keyValueList Indicates the pointer to the key-value list of the extra audio parameters. + * The format is key=value. Separate multiple key-value pairs by semicolons (;). + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetExtraParams)(AudioHandle handle, char *keyValueList, int32_t listLenth); + + /** + * @brief Requests a mmap buffer. + * + * @param handle Indicates the audio handle. + * @param reqSize Indicates the size of the request mmap buffer. + * @param desc Indicates the pointer to the mmap buffer descriptor. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*ReqMmapBuffer)(AudioHandle handle, int32_t reqSize, struct AudioMmapBufferDescriptor *desc); + + /** + * @brief Obtains the read/write position of the current mmap buffer. + * + * @param handle Indicates the audio handle. + * @param frames Indicates the pointer to the frame where the read/write starts. + * @param time Indicates the pointer to the timestamp associated with the frame where the read/write starts. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetMmapPosition)(AudioHandle handle, uint64_t *frames, struct AudioTimeStamp *time); +}; +} +#endif /* AUDIO_ATTRIBUTE_H */ +/** @} */ diff --git a/bluetooth/a2dp/include/audio_capture.h b/bluetooth/a2dp/include/audio_capture.h new file mode 100644 index 0000000000000000000000000000000000000000..98c15bbd1f6a28f05ad1a83107ef0c0b7c5ebea9 --- /dev/null +++ b/bluetooth/a2dp/include/audio_capture.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_capture.h + * + * @brief Declares APIs for audio capturing. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_CAPTURE_H +#define AUDIO_CAPTURE_H + +#include "audio_control.h" +#include "audio_volume.h" +namespace OHOS::HDI::Audio_Bluetooth { +/** + * @brief Provides capabilities for audio capturing, including controlling the capturing, setting audio attributes, + * scenes, and volume, obtaining hardware latency, and capturing audio frames. + * + * @see AudioControl + * @see AudioAttribute + * @since 1.0 + * @version 1.0 + */ +struct AudioCapture { + /** + * @brief Defines the audio control. For details, see {@link AudioControl}. + */ + struct AudioControl control; + /** + * @brief Defines audio volume. For details, see {@link AudioVolume}. + */ + struct AudioVolume volume; + + /** + * @brief Reads a frame of intput data (uplink data) into the audio driver for capturing. + * + * @param capture Indicates the pointer to the AudioCapture object to operate. + * @param frame Indicates the pointer to the frame to read. + * @param requestBytes Indicates the size of the frame, in bytes. + * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to read. + * @return Returns 0 if the data is read successfully; returns a negative value otherwise. + */ + int32_t (*CaptureFrame)(struct AudioCapture *capture, void *frame, uint64_t requestBytes, uint64_t *replyBytes); +}; +} +#endif diff --git a/bluetooth/a2dp/include/audio_control.h b/bluetooth/a2dp/include/audio_control.h new file mode 100644 index 0000000000000000000000000000000000000000..9f556d7ca14f8c82f75c8025e4784533953c1799 --- /dev/null +++ b/bluetooth/a2dp/include/audio_control.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_control.h + * + * @brief Declares APIs for audio control. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_CONTROL_H +#define AUDIO_CONTROL_H + +#include "audio_types.h" +namespace OHOS::HDI::Audio_Bluetooth { +/** + * @brief Provides control-related APIs for audio rendering or capturing, including functions to + * start, stop, pause, and resume audio rendering or capturing, and flush data in the audio buffer. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioControl { + /** + * @brief Starts audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully started; + * returns a negative value otherwise. + * @see Stop + */ + int32_t (*Start)(AudioHandle handle); + + /** + * @brief Stops audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully stopped; + * returns a negative value otherwise. + * @see Start + */ + int32_t (*Stop)(AudioHandle handle); + + /** + * @brief Pauses audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully paused; + * returns a negative value otherwise. + * @see Resume + */ + int32_t (*Pause)(AudioHandle handle); + + /** + * @brief Resumes audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully resumed; + * returns a negative value otherwise. + * @see Pause + */ + int32_t (*Resume)(AudioHandle handle); + + /** + * @brief Flushes data in the audio buffer. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the flush is successful; returns a negative value otherwise. + */ + int32_t (*Flush)(AudioHandle handle); + + /** + * @brief Sets or cancels the standby mode of the audio device. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the device is set to standby mode; returns a positive value if the standby mode is + * canceled; returns a negative value if the setting fails. + */ + int32_t (*TurnStandbyMode)(AudioHandle handle); + + /** + * @brief Dumps information about the audio device. + * + * @param handle Indicates the audio handle. + * @param range Indicates the range of the device information to dump, which can be brief or full information. + * @param fd Indicates the file to which the device information will be dumped. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*AudioDevDump)(AudioHandle handle, int32_t range, int32_t fd); +}; +} +#endif /* AUDIO_CONTROL_H */ +/** @} */ diff --git a/bluetooth/a2dp/include/audio_manager.h b/bluetooth/a2dp/include/audio_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..6b73d6a0379037c79ec6b6b59584bd72b94cd57c --- /dev/null +++ b/bluetooth/a2dp/include/audio_manager.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_manager.h + * + * @brief Declares APIs for audio adapter management and loading. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_MANAGER_H +#define AUDIO_MANAGER_H + +#include "audio_types.h" +#include "audio_adapter.h" +namespace OHOS::HDI::Audio_Bluetooth { +/** + * @brief Manages audio adapters through a specific adapter driver program loaded based on the given audio + * adapter descriptor. + * + * @see AudioAdapter + * @since 1.0 + * @version 1.0 + */ +struct AudioManager { + /** + * @brief Obtains the list of all adapters supported by an audio driver. + * + * @param manager Indicates the pointer to the audio adapter manager to operate. + * @param descs Indicates the double pointer to the audio adapter list. + * @param size Indicates the pointer to the length of the list. + * @return Returns 0 if the list is obtained successfully; returns a negative value otherwise. + * @see LoadAdapter + */ + int32_t (*GetAllAdapters)(struct AudioManager *manager, struct AudioAdapterDescriptor **descs, int32_t *size); + + /** + * @brief Loads the driver for an audio adapter. + * + * For example, to load a USB driver, you may need to load a dynamic-link library (*.so) in specific implementation. + * + * @param manager Indicates the pointer to the audio adapter manager to operate. + * @param desc Indicates the pointer to the descriptor of the audio adapter. + * @param adapter Indicates the double pointer to the audio adapter. + * @return Returns 0 if the driver is loaded successfully; returns a negative value otherwise. + * @see GetAllAdapters + * @see UnloadAdapter + */ + int32_t (*LoadAdapter)(struct AudioManager *manager, const struct AudioAdapterDescriptor *desc, + struct AudioAdapter **adapter); + + /** + * @brief Unloads the driver of an audio adapter. + * + * @param manager Indicates the pointer to the audio adapter manager to operate. + * @param adapter Indicates the pointer to the audio adapter whose driver will be unloaded. + * @see LoadAdapter + */ + void (*UnloadAdapter)(struct AudioManager *manager, struct AudioAdapter *adapter); +}; + +/** + * @brief Obtains the operation function list of the {@link AudioManager} class. + * + * @return Returns the pointer to the AudioManager object if the list is obtained; returns NULL otherwise. + */ +struct AudioManager *GetAudioManagerFuncs(void); +} +#endif /* AUDIO_MANAGER_H */ +/** @} */ diff --git a/bluetooth/a2dp/include/audio_proxy_manager.h b/bluetooth/a2dp/include/audio_proxy_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..9a01b7cab7ca0d94e7e8aea2b4bdde65dc4e3e9e --- /dev/null +++ b/bluetooth/a2dp/include/audio_proxy_manager.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_manager.h + * + * @brief Declares APIs for audio adapter management and loading. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_PROXY_MANAGER_H +#define AUDIO_PROXY_MANAGER_H +#include +#include "audio_adapter.h" +namespace OHOS::HDI::Audio_Bluetooth { +#ifdef __cplusplus +extern "C" { +#endif + +struct AudioProxyManager { + struct HdfRemoteService *remote; + int32_t (*GetAllAdapters)(struct AudioProxyManager *manager, struct AudioAdapterDescriptor **descs, int32_t *size); + int32_t (*LoadAdapter)(struct AudioProxyManager *manager, const struct AudioAdapterDescriptor *desc, + struct AudioAdapter **adapter); + void (*UnloadAdapter)(const struct AudioProxyManager *manager, const struct AudioAdapter *adapter); +}; + +int32_t AudioProxyManagerGetAllAdapters(struct AudioProxyManager *manager, + struct AudioAdapterDescriptor **descs, + int *size); +int32_t AudioProxyManagerLoadAdapter(struct AudioProxyManager *manager, const struct AudioAdapterDescriptor *desc, + struct AudioAdapter **adapter); +void AudioProxyManagerUnloadAdapter(const struct AudioProxyManager *manager, const struct AudioAdapter *adapter); + +struct AudioProxyManager *GetAudioProxyManagerFuncs(void); + +#ifdef __cplusplus +} +#endif +} +#endif /* AUDIO_MANAGER_H */ +/** @} */ diff --git a/bluetooth/a2dp/include/audio_render.h b/bluetooth/a2dp/include/audio_render.h new file mode 100644 index 0000000000000000000000000000000000000000..a7fb0010450774de60ad6e4d5da4fcd6a0a872b0 --- /dev/null +++ b/bluetooth/a2dp/include/audio_render.h @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_render.h + * + * @brief Declares APIs for audio rendering. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_RENDER_H +#define AUDIO_RENDER_H + +#include "audio_types.h" +#include "audio_control.h" +#include "audio_attribute.h" +#include "audio_scene.h" +#include "audio_volume.h" +namespace OHOS::HDI::Audio_Bluetooth { +/** + * @brief Provides capabilities for audio rendering, including controlling the rendering, setting audio attributes, + * scenes, and volume, obtaining hardware latency, and rendering audio frames. + * + * @see AudioControl + * @see AudioAttribute + * @see AudioScene + * @see AudioVolume + * @since 1.0 + * @version 1.0 + */ +struct AudioRender { + /** + * @brief Defines the audio control. For details, see {@link AudioControl}. + */ + struct AudioControl control; + /** + * @brief Defines the audio attribute. For details, see {@link AudioAttribute}. + */ + struct AudioAttribute attr; + /** + * @brief Defines the audio scene. For details, see {@link AudioScene}. + */ + struct AudioScene scene; + /** + * @brief Defines audio volume. For details, see {@link AudioVolume}. + */ + struct AudioVolume volume; + + /** + * @brief Obtains the estimated latency of the audio device driver. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param ms Indicates the pointer to the latency (in milliseconds) to be obtained. + * @return Returns 0 if the latency is obtained; returns a negative value otherwise. + */ + int32_t (*GetLatency)(struct AudioRender *render, uint32_t *ms); + + /** + * @brief Writes a frame of output data (downlink data) into the audio driver for rendering. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param frame Indicates the pointer to the frame to write. + * @param requestBytes Indicates the size of the frame, in bytes. + * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to write. + * @return Returns 0 if the data is written successfully; returns a negative value otherwise. + */ + int32_t (*RenderFrame)(struct AudioRender *render, const void *frame, uint64_t requestBytes, uint64_t *replyBytes); + + /** + * @brief Obtains the last number of output audio frames. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param frames Indicates the pointer to the last number of output audio frames. + * @param time Indicates the pointer to the timestamp associated with the frame. + * @return Returns 0 if the last number is obtained; returns a negative value otherwise. + * @see RenderFrame + */ + int32_t (*GetRenderPosition)(struct AudioRender *render, uint64_t *frames, struct AudioTimeStamp *time); + + /** + * @brief Sets the audio rendering speed. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param speed Indicates the rendering speed to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetRenderSpeed + */ + int32_t (*SetRenderSpeed)(struct AudioRender *render, float speed); + + /** + * @brief Obtains the current audio rendering speed. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param speed Indicates the pointer to the current rendering speed to obtain. + * @return Returns 0 if the speed is successfully obtained; returns a negative value otherwise. + * @see SetRenderSpeed + */ + int32_t (*GetRenderSpeed)(struct AudioRender *render, float *speed); + + /** + * @brief Sets the channel mode for audio rendering. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param mode Indicates the channel mode to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetChannelMode + */ + int32_t (*SetChannelMode)(struct AudioRender *render, enum AudioChannelMode mode); + + /** + * @brief Obtains the current channel mode for audio rendering. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param mode Indicates the pointer to the channel mode to obtain. + * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. + * @see SetChannelMode + */ + int32_t (*GetChannelMode)(struct AudioRender *render, enum AudioChannelMode *mode); + + /** + * @brief Registers an audio callback that will be invoked during playback when buffer data writing or + * buffer drain is complete. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param callback Indicates the callback to register. + * @param cookie Indicates the pointer to the callback parameters. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + * @see RegCallback + */ + int32_t (*RegCallback)(struct AudioRender *render, RenderCallback callback, void* cookie); + + /** + * @brief Drains the buffer. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param type Indicates the pointer to the execution type of this function. For details, + * see {@link AudioDrainNotifyType}. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + * @see RegCallback + */ + int32_t (*DrainBuffer)(struct AudioRender *render, enum AudioDrainNotifyType *type); +}; +} +#endif /* AUDIO_RENDER_H */ +/** @} */ diff --git a/bluetooth/a2dp/include/audio_scene.h b/bluetooth/a2dp/include/audio_scene.h new file mode 100644 index 0000000000000000000000000000000000000000..ca3f1d4e47d6230b61e82d532a0a8c6497ee157b --- /dev/null +++ b/bluetooth/a2dp/include/audio_scene.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_scene.h + * + * @brief Declares APIs for audio scenes. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_SCENE_H +#define AUDIO_SCENE_H + +#include "audio_types.h" +namespace OHOS::HDI::Audio_Bluetooth { +/** + * @brief Provides scene-related APIs for audio rendering or capturing, including functions to + * select an audio scene and check whether the configuration of an audio scene is supported. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioScene { + /** + * @brief Checks whether the configuration of an audio scene is supported. + * + * @param handle Indicates the audio handle. + * @param scene Indicates the pointer to the descriptor of the audio scene. + * @param supported Indicates the pointer to the variable specifying whether the configuration is supported. + * Value true means that the configuration is supported, and false means the opposite. + * @return Returns 0 if the result is obtained; returns a negative value otherwise. + * @see SelectScene + */ + int32_t (*CheckSceneCapability)(AudioHandle handle, const struct AudioSceneDescriptor *scene, bool *supported); + + /** + * @brief Selects an audio scene. + * + * + * @param handle Indicates the audio handle. + * @param scene Indicates the pointer to the descriptor of the audio scene to select. + * @return Returns 0 if the scene is selected successfully; returns a negative value otherwise. + * @see CheckSceneCapability + */ + int32_t (*SelectScene)(AudioHandle handle, const struct AudioSceneDescriptor *scene); +}; +} +#endif /* AUDIO_SCENE_H */ +/** @} */ diff --git a/bluetooth/a2dp/include/audio_types.h b/bluetooth/a2dp/include/audio_types.h new file mode 100644 index 0000000000000000000000000000000000000000..72262bc6615b7903d5ecac8ad2fdfd0d6a1c7881 --- /dev/null +++ b/bluetooth/a2dp/include/audio_types.h @@ -0,0 +1,318 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_types.h + * + * @brief Defines custom data types used in API declarations for the audio module, including audio ports, + * adapter descriptors, device descriptors, scene descriptors, sampling attributes, and timestamp. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_TYPES_H +#define AUDIO_TYPES_H + +#include +#include +namespace OHOS::HDI::Audio_Bluetooth { +/** + * @brief Defines the audio handle. + */ +typedef void *AudioHandle; + +/** + * @brief Enumerates the audio port type. + */ +enum AudioPortDirection { + PORT_OUT = 0x1u, /**< Output port */ + PORT_IN = 0x2u, /**< Input port */ + PORT_OUT_IN = 0x3u, /**< Input/output port, supporting both audio input and output */ +}; + +/** + * @brief Defines the audio port. + */ +struct AudioPort { + enum AudioPortDirection dir; /**< Audio port type. For details, see {@link AudioPortDirection} */ + uint32_t portId; /**< Audio port ID */ + const char *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 { + const char *adapterName; /**< Name of the audio adapter */ + uint32_t portNum; /**< Number of ports supported by an audio adapter */ + struct AudioPort *ports; /**< List of ports supported by an audio adapter */ +}; + +/** + * @brief Enumerates the pin of an audio adapter. + */ +enum AudioPortPin { + PIN_NONE = 0x0u, /**< Invalid pin */ + PIN_OUT_SPEAKER = 0x1u, /**< Speaker output pin */ + PIN_OUT_HEADSET = 0x2u, /**< Wired headset pin for output */ + PIN_OUT_LINEOUT = 0x4u, /**< Line-out pin */ + PIN_OUT_HDMI = 0x8u, /**< HDMI output pin */ + PIN_IN_MIC = 0x8000001u, /**< Microphone input pin */ + PIN_IN_HS_MIC = 0x8000002u, /**< Wired headset microphone pin for input */ + PIN_IN_LINEIN = 0x8000004u, /**< Line-in pin */ +}; + +/** + * @brief Defines the audio device descriptor. + */ +struct AudioDeviceDescriptor { + uint32_t portId; /**< Audio port ID */ + enum AudioPortPin pins; /**< Pins of audio ports (input and output). For details, see {@link AudioPortPin}. */ + const char *desc; /**< Audio device name */ +}; + +/** + * @brief Enumerates the audio category. + */ +enum AudioCategory { + AUDIO_IN_MEDIA = 0, /**< Media */ + AUDIO_IN_COMMUNICATION, /**< Communications */ + AUDIO_IN_RINGTONE, /**< Ringtone */ + AUDIO_IN_CALL, /**< Call */ + AUDIO_MMAP_NOIRQ, /**< Mmap mode */ +}; + +/** + * @brief Defines the audio scene descriptor. + */ +struct AudioSceneDescriptor { + /** + * @brief Describes the audio scene. + */ + union SceneDesc { + uint32_t id; /**< Audio scene ID */ + const char *desc; /**< Name of the audio scene */ + } scene; /**< The scene object */ + struct AudioDeviceDescriptor desc; /**< Audio device descriptor */ +}; + +/** + * @brief Enumerates the audio format. + */ +enum AudioFormat { + AUDIO_FORMAT_TYPE_PCM_8_BIT = 0x1u, /**< 8-bit PCM */ + AUDIO_FORMAT_TYPE_PCM_16_BIT = 0x2u, /**< 16-bit PCM */ + AUDIO_FORMAT_TYPE_PCM_24_BIT = 0x3u, /**< 24-bit PCM */ + AUDIO_FORMAT_TYPE_PCM_32_BIT = 0x4u, /**< 32-bit PCM */ + AUDIO_FORMAT_TYPE_AAC_MAIN = 0x1000001u, /**< AAC main */ + AUDIO_FORMAT_TYPE_AAC_LC = 0x1000002u, /**< AAC LC */ + AUDIO_FORMAT_TYPE_AAC_LD = 0x1000003u, /**< AAC LD */ + AUDIO_FORMAT_TYPE_AAC_ELD = 0x1000004u, /**< AAC ELD */ + AUDIO_FORMAT_TYPE_AAC_HE_V1 = 0x1000005u, /**< AAC HE_V1 */ + AUDIO_FORMAT_TYPE_AAC_HE_V2 = 0x1000006u, /**< AAC HE_V2 */ + AUDIO_FORMAT_TYPE_G711A = 0x2000001u, /**< G711A */ + AUDIO_FORMAT_TYPE_G711U = 0x2000002u, /**< G711u */ + AUDIO_FORMAT_TYPE_G726 = 0x2000003u, /**< G726 */ +}; + +/** + * @brief Enumerates the audio channel mask. + * + * A mask describes an audio channel position. + */ +enum AudioChannelMask { + AUDIO_CHANNEL_FRONT_LEFT = 0x1, /**< Front left channel */ + AUDIO_CHANNEL_FRONT_RIGHT = 0x2, /**< Front right channel */ + AUDIO_CHANNEL_MONO = 0x1u, /**< Mono channel */ + AUDIO_CHANNEL_STEREO = 0x3u, /**< Stereo channel, consisting of front left and front right channels */ +}; + +/** + * @brief Enumerates masks of audio sampling rates. + */ +enum AudioSampleRatesMask { + AUDIO_SAMPLE_RATE_MASK_8000 = 0x1u, /**< 8 kHz */ + AUDIO_SAMPLE_RATE_MASK_12000 = 0x2u, /**< 12 kHz */ + AUDIO_SAMPLE_RATE_MASK_11025 = 0x4u, /**< 11.025 kHz */ + AUDIO_SAMPLE_RATE_MASK_16000 = 0x8u, /**< 16 kHz */ + AUDIO_SAMPLE_RATE_MASK_22050 = 0x10u, /**< 22.050 kHz */ + AUDIO_SAMPLE_RATE_MASK_24000 = 0x20u, /**< 24 kHz */ + AUDIO_SAMPLE_RATE_MASK_32000 = 0x40u, /**< 32 kHz */ + AUDIO_SAMPLE_RATE_MASK_44100 = 0x80u, /**< 44.1 kHz */ + AUDIO_SAMPLE_RATE_MASK_48000 = 0x100u, /**< 48 kHz */ + AUDIO_SAMPLE_RATE_MASK_64000 = 0x200u, /**< 64 kHz */ + AUDIO_SAMPLE_RATE_MASK_96000 = 0x400u, /**< 96 kHz */ + AUDIO_SAMPLE_RATE_MASK_INVALID = 0xFFFFFFFFu, /**< Invalid sampling rate */ +}; + +/** + * @brief Defines audio sampling attributes. + */ +struct AudioSampleAttributes { + enum AudioCategory type; /**< Audio type. For details, see {@link AudioCategory} */ + bool interleaved; /**< Interleaving flag of audio data */ + enum AudioFormat format; /**< Audio data format. For details, see {@link AudioFormat}. */ + uint32_t sampleRate; /**< Audio sampling rate */ + uint32_t channelCount; /**< Number of audio channels. For example, for the mono channel, the value is 1, + * and for the stereo channel, the value is 2. + */ + uint32_t period; /**< Audio sampling period */ + uint32_t frameSize; /**< Frame size of the audio data */ + bool isBigEndian; /**< Big endian flag of audio data */ + bool isSignedData; /**< Signed or unsigned flag of audio data */ + uint32_t startThreshold; /**< Audio render start threshold. */ + uint32_t stopThreshold; /**< Audio render stop threshold. */ + uint32_t silenceThreshold; /**< Audio capture buffer threshold. */ +}; + +/** + * @brief Defines the audio timestamp, which is a substitute for POSIX timespec. + */ +struct AudioTimeStamp { + int64_t tvSec; /**< Seconds */ + int64_t tvNSec; /**< Nanoseconds */ +}; + +/** + * @brief Enumerates the passthrough data transmission mode of an audio port. + */ +enum AudioPortPassthroughMode { + PORT_PASSTHROUGH_LPCM = 0x1, /**< Stereo PCM */ + PORT_PASSTHROUGH_RAW = 0x2, /**< HDMI passthrough */ + PORT_PASSTHROUGH_HBR2LBR = 0x4, /**< Blu-ray next-generation audio output with reduced specifications */ + PORT_PASSTHROUGH_AUTO = 0x8, /**< Mode automatically matched based on the HDMI EDID */ +}; + +/** + * @brief Defines the sub-port capability. + */ +struct AudioSubPortCapability { + uint32_t portId; /**< Sub-port ID */ + const char *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 { + uint32_t deviceType; /**< Device type (output or input) */ + uint32_t deviceId; /**< Device ID used for device binding */ + bool hardwareMode; /**< Whether to support device binding */ + uint32_t formatNum; /**< Number of the supported audio formats */ + enum AudioFormat *formats; /**< Supported audio formats. For details, see {@link AudioFormat}. */ + uint32_t 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}. + */ + uint32_t channelCount; /**< Supported maximum number of audio channels */ + uint32_t subPortsNum; /**< Number of supported sub-ports (for output devices only) */ + struct AudioSubPortCapability *subPorts; /**< List of supported sub-ports */ +}; + +/** + * @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, /**< Normal mode. No processing is required. */ + AUDIO_CHANNEL_BOTH_LEFT, /**< Two left channels */ + AUDIO_CHANNEL_BOTH_RIGHT, /**< Two right channels */ + AUDIO_CHANNEL_EXCHANGE, /**< 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, /**< Mix of streams of the left and right channels */ + AUDIO_CHANNEL_LEFT_MUTE, /**< Left channel muted. The stream of the right channel is output. */ + AUDIO_CHANNEL_RIGHT_MUTE, /**< Right channel muted. The stream of the left channel is output. */ + AUDIO_CHANNEL_BOTH_MUTE, /**< Both left and right channels muted */ +}; + +/** + * @brief Enumerates the execution types of the DrainBuffer function. + */ +enum AudioDrainNotifyType { + AUDIO_DRAIN_NORMAL_MODE, /**< The DrainBuffer function returns after all data finishes playback. */ + AUDIO_DRAIN_EARLY_MODE, /**< 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_COMPLETED, /**< The non-block write is complete. */ + AUDIO_DRAIN_COMPLETED, /**< The draining is complete. */ + AUDIO_FLUSH_COMPLETED, /**< The flush is complete. */ + AUDIO_RENDER_FULL, /**< The render buffer is full.*/ + AUDIO_ERROR_OCCUR, /**< An error occurs.*/ +}; + +/** + * @brief Describes a mmap buffer. + */ +struct AudioMmapBufferDescriptor { + void *memoryAddress; /**< Pointer to the mmap buffer */ + int32_t memoryFd; /**< File descriptor of the mmap buffer */ + int32_t totalBufferFrames; /**< Total size of the mmap buffer (unit: frame )*/ + int32_t transferFrameSize; /**< Transfer size (unit: frame) */ + int32_t isShareable; /**< Whether the mmap buffer can be shared among processes */ + uint32_t offset; +}; + +/** + * @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_LOWPOWER = 1000, /**< Low power event type */ +}; + +/** + * @brief Called when an event defined in {@link AudioCallbackType} occurs. + * + * @param AudioCallbackType Indicates the occurred event that triggers this callback. + * @param reserved Indicates the pointer to a reserved field. + * @param cookie Indicates the pointer to the cookie for data transmission. + * @return Returns 0 if the callback is successfully executed; returns a negative value otherwise. + * @see RegCallback + */ +typedef int32_t (*RenderCallback)(enum AudioCallbackType, void *reserved, void *cookie); +} +#endif /* AUDIO_TYPES_H */ diff --git a/bluetooth/a2dp/include/audio_volume.h b/bluetooth/a2dp/include/audio_volume.h new file mode 100644 index 0000000000000000000000000000000000000000..68ca334522db5643ad0ce783ec702836d7c1cc92 --- /dev/null +++ b/bluetooth/a2dp/include/audio_volume.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_volume.h + * + * @brief Declares APIs for audio volume. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_VOLUME_H +#define AUDIO_VOLUME_H + +#include "audio_types.h" +namespace OHOS::HDI::Audio_Bluetooth { +/** + * @brief Provides volume-related APIs for audio rendering or capturing, including functions to + * set the mute operation, volume, and gain. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioVolume { + /** + * @brief Sets the mute operation for the audio. + * + * @param handle Indicates the audio handle. + * @param mute Specifies whether to mute the audio. Value true means to mute the audio, + * and false means the opposite. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetMute + */ + int32_t (*SetMute)(AudioHandle handle, bool mute); + + /** + * @brief Obtains the mute operation set for the audio. + * + * @param handle Indicates the audio handle. + * @param mute Indicates the pointer to the mute operation set for the audio. Value true means that + * the audio is muted, and false means the opposite. + * @return Returns 0 if the mute operation is obtained; returns a negative value otherwise. + * @see SetMute + */ + int32_t (*GetMute)(AudioHandle handle, bool *mute); + + /** + * @brief Sets the audio volume. + * + * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15, + * 0.0 indicates that the audio is muted, and 1.0 indicates the maximum volume level (15). + * + * @param handle Indicates the audio handle. + * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetVolume + */ + int32_t (*SetVolume)(AudioHandle handle, float volume); + + /** + * @brief Obtains the audio volume. + * + * @param handle Indicates the audio handle. + * @param volume Indicates the pointer to the volume to obtain. The value ranges from 0.0 to 1.0. + * @return Returns 0 if the volume is obtained; returns a negative value otherwise. + * @see SetVolume + */ + int32_t (*GetVolume)(AudioHandle handle, float *volume); + + /** + * @brief Obtains the range of the audio gain. + * + * The audio gain can be expressed in one of the following two ways (depending on the chip platform), + * corresponding to two types of value ranges: + *
    + *
  • Actual audio gain values, for example, ranging from -50 to 6 dB
  • + *
  • Float numbers ranging from 0.0 to 1.0, where 0.0 means to mute the audio, + * and 1.0 means the maximum gain value, for example, 6 dB
  • + *
+ * @param handle Indicates the audio handle. + * @param min Indicates the pointer to the minimum value of the range. + * @param max Indicates the pointer to the maximum value of the range. + * @return Returns 0 if the range is obtained; returns a negative value otherwise. + * @see GetGain + * @see SetGain + */ + int32_t (*GetGainThreshold)(AudioHandle handle, float *min, float *max); + + /** + * @brief Obtains the audio gain. + * + * @param handle Indicates the audio handle. + * @param gain Indicates the pointer to the audio gain. + * @return Returns 0 if the audio gain is obtained; returns a negative value otherwise. + * @see GetGainThreshold + * @see SetGain + */ + int32_t (*GetGain)(AudioHandle handle, float *gain); + + /** + * @brief Sets the audio gain. + * + * @param handle Indicates the audio handle. + * @param gain Indicates the audio gain to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetGainThreshold + * @see GetGain + */ + int32_t (*SetGain)(AudioHandle handle, float gain); +}; +} +#endif /* AUDIO_VOLUME_H */ +/** @} */ diff --git a/bluetooth/a2dp/v1_0/BUILD.gn b/bluetooth/a2dp/v1_0/BUILD.gn index f47fa4cb25700e2974cc9d84c5811191bf00d36a..8ddba96e864eacfa98f117f5a6093f184c707a24 100644 --- a/bluetooth/a2dp/v1_0/BUILD.gn +++ b/bluetooth/a2dp/v1_0/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//drivers/hdf_core/adapter/uhdf2/hdi.gni") +import("//build/config/components/hdi/hdi.gni") hdi("bluetooth_a2dp") { module_name = "bluetooth_a2dp" diff --git a/bluetooth/a2dp/v1_1/BUILD.gn b/bluetooth/a2dp/v1_1/BUILD.gn index 1981bc3faa36b9d8831367c34a1ded9d434fde0e..9a9ea92648f65f14e07b1513dbe99593bfacb6d4 100644 --- a/bluetooth/a2dp/v1_1/BUILD.gn +++ b/bluetooth/a2dp/v1_1/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//drivers/hdf_core/adapter/uhdf2/hdi.gni") +import("//build/config/components/hdi/hdi.gni") hdi("bluetooth_a2dp") { module_name = "bluetooth_a2dp" imports = [ "ohos.hdi.bluetooth.a2dp.v1_0:bluetooth_a2dp" ] diff --git a/bluetooth/a2dp/v2_0/BUILD.gn b/bluetooth/a2dp/v2_0/BUILD.gn index 8de0f223413939eb03bc73cb877ef237a8f99f67..b8c5eb78c187ae9b3f044b88278876f384a9a12e 100644 --- a/bluetooth/a2dp/v2_0/BUILD.gn +++ b/bluetooth/a2dp/v2_0/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//drivers/hdf_core/adapter/uhdf2/hdi.gni") +import("//build/config/components/hdi/hdi.gni") hdi("bluetooth_a2dp") { module_name = "bluetooth_a2dp" diff --git a/bluetooth/bundle.json b/bluetooth/bundle.json index 8431d0edb0666542b9308982b53f6271f7765c4c..a8f560c6d251be161473972ed3f73741bba0ac7a 100644 --- a/bluetooth/bundle.json +++ b/bluetooth/bundle.json @@ -104,6 +104,24 @@ ], "header_base": "//drivers/interface/bluetooth/lp_ble" } + }, + { + "name": "//drivers/interface/bluetooth/a2dp/include:hdi_audio_bluetooth_header", + "header": { + "header_files": [ + "audio_adapter.h", + "audio_attribute.h", + "audio_capture.h", + "audio_control.h", + "audio_manager.h", + "audio_render.h", + "audio_scene.h", + "audio_types.h", + "audio_volume.h", + "audio_proxy_manager.h" + ], + "header_base": "//drivers/interface/bluetooth/a2dp" + } } ] } diff --git a/bluetooth/hci/v1_0/BUILD.gn b/bluetooth/hci/v1_0/BUILD.gn index eb386995071eca4c64714e73bfbb15822baec206..e9748a774d0e89d6c3b3a213f0c82325fdba5def 100644 --- a/bluetooth/hci/v1_0/BUILD.gn +++ b/bluetooth/hci/v1_0/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//drivers/hdf_core/adapter/uhdf2/hdi.gni") +import("//build/config/components/hdi/hdi.gni") hdi("bluetooth_hci") { module_name = "bluetooth_hci" diff --git a/bluetooth/lp_ble/v1_0/BUILD.gn b/bluetooth/lp_ble/v1_0/BUILD.gn index e8b0e78738a98d2412126e77563e438684a89829..20e9fc785ff8ced306cbec20d0f1338be3da8b44 100644 --- a/bluetooth/lp_ble/v1_0/BUILD.gn +++ b/bluetooth/lp_ble/v1_0/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//drivers/hdf_core/adapter/uhdf2/hdi.gni") +import("//build/config/components/hdi/hdi.gni") hdi("bluetooth_lp_ble") { module_name = "bluetooth_lp_ble"