1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci/** 17094332d3Sopenharmony_ci * @addtogroup Audio 18094332d3Sopenharmony_ci * @{ 19094332d3Sopenharmony_ci * 20094332d3Sopenharmony_ci * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, 21094332d3Sopenharmony_ci * accessing a driver adapter, and rendering and capturing audios. 22094332d3Sopenharmony_ci * 23094332d3Sopenharmony_ci * @since 1.0 24094332d3Sopenharmony_ci * @version 1.0 25094332d3Sopenharmony_ci */ 26094332d3Sopenharmony_ci 27094332d3Sopenharmony_ci/** 28094332d3Sopenharmony_ci * @file audio_adapter.h 29094332d3Sopenharmony_ci * 30094332d3Sopenharmony_ci * @brief Declares APIs for operations related to the audio adapter. 31094332d3Sopenharmony_ci * 32094332d3Sopenharmony_ci * @since 1.0 33094332d3Sopenharmony_ci * @version 1.0 34094332d3Sopenharmony_ci */ 35094332d3Sopenharmony_ci 36094332d3Sopenharmony_ci#ifndef AUDIO_ADAPTER_H 37094332d3Sopenharmony_ci#define AUDIO_ADAPTER_H 38094332d3Sopenharmony_ci 39094332d3Sopenharmony_ci#include "audio_types.h" 40094332d3Sopenharmony_ci#include "audio_render.h" 41094332d3Sopenharmony_cinamespace OHOS::HDI::Audio_Bluetooth { 42094332d3Sopenharmony_ci/** 43094332d3Sopenharmony_ci * @brief Provides audio adapter capabilities, including initializing ports, creating rendering and capturing tasks, 44094332d3Sopenharmony_ci * and obtaining the port capability set. 45094332d3Sopenharmony_ci * 46094332d3Sopenharmony_ci * @see AudioRender 47094332d3Sopenharmony_ci * @see AudioCapture 48094332d3Sopenharmony_ci * @since 1.0 49094332d3Sopenharmony_ci * @version 1.0 50094332d3Sopenharmony_ci */ 51094332d3Sopenharmony_cistruct AudioAdapter { 52094332d3Sopenharmony_ci /** 53094332d3Sopenharmony_ci * @brief Initializes all ports of an audio adapter. 54094332d3Sopenharmony_ci * 55094332d3Sopenharmony_ci * Call this function before calling other driver functions to check whether the initialization is complete. 56094332d3Sopenharmony_ci * If the initialization is not complete, wait for a while (for example, 100 ms) and perform the check again 57094332d3Sopenharmony_ci * until the port initialization is complete. 58094332d3Sopenharmony_ci * 59094332d3Sopenharmony_ci * @param adapter Indicates the pointer to the audio adapter to operate. 60094332d3Sopenharmony_ci * @return Returns <b>0</b> if the initialization is successful; returns a negative value otherwise. 61094332d3Sopenharmony_ci */ 62094332d3Sopenharmony_ci int32_t (*InitAllPorts)(struct AudioAdapter *adapter); 63094332d3Sopenharmony_ci 64094332d3Sopenharmony_ci /** 65094332d3Sopenharmony_ci * @brief Creates an <b>AudioRender</b> object. 66094332d3Sopenharmony_ci * 67094332d3Sopenharmony_ci * @param adapter Indicates the pointer to the audio adapter to operate. 68094332d3Sopenharmony_ci * @param desc Indicates the pointer to the descriptor of the audio adapter to start. 69094332d3Sopenharmony_ci * @param attrs Indicates the pointer to the audio sampling attributes to open. 70094332d3Sopenharmony_ci * @param render Indicates the double pointer to the <b>AudioRender</b> object. 71094332d3Sopenharmony_ci * @return Returns <b>0</b> if the <b>AudioRender</b> object is created successfully; 72094332d3Sopenharmony_ci * returns a negative value otherwise. 73094332d3Sopenharmony_ci * @see GetPortCapability 74094332d3Sopenharmony_ci * @see DestroyRender 75094332d3Sopenharmony_ci */ 76094332d3Sopenharmony_ci int32_t (*CreateRender)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, 77094332d3Sopenharmony_ci const struct AudioSampleAttributes *attrs, struct AudioRender **render); 78094332d3Sopenharmony_ci 79094332d3Sopenharmony_ci /** 80094332d3Sopenharmony_ci * @brief Destroys an <b>AudioRender</b> object. 81094332d3Sopenharmony_ci * 82094332d3Sopenharmony_ci * @attention Do not destroy the object during audio rendering. 83094332d3Sopenharmony_ci * 84094332d3Sopenharmony_ci * @param adapter Indicates the pointer to the audio adapter to operate. 85094332d3Sopenharmony_ci * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 86094332d3Sopenharmony_ci * @return Returns <b>0</b> if the <b>AudioRender</b> object is destroyed; returns a negative value otherwise. 87094332d3Sopenharmony_ci * @see CreateRender 88094332d3Sopenharmony_ci */ 89094332d3Sopenharmony_ci int32_t (*DestroyRender)(struct AudioAdapter *adapter, struct AudioRender *render); 90094332d3Sopenharmony_ci 91094332d3Sopenharmony_ci /** 92094332d3Sopenharmony_ci * @brief Obtains the capability set of the port driver for the audio adapter. 93094332d3Sopenharmony_ci * 94094332d3Sopenharmony_ci * @param adapter Indicates the pointer to the audio adapter to operate. 95094332d3Sopenharmony_ci * @param port Indicates the pointer to the port. 96094332d3Sopenharmony_ci * @param capability Indicates the pointer to the capability set to obtain. 97094332d3Sopenharmony_ci * @return Returns <b>0</b> if the capability set is successfully obtained; returns a negative value otherwise. 98094332d3Sopenharmony_ci */ 99094332d3Sopenharmony_ci int32_t (*GetPortCapability)(struct AudioAdapter *adapter, const struct AudioPort *port, 100094332d3Sopenharmony_ci struct AudioPortCapability *capability); 101094332d3Sopenharmony_ci 102094332d3Sopenharmony_ci /** 103094332d3Sopenharmony_ci * @brief Sets the passthrough data transmission mode of the audio port driver. 104094332d3Sopenharmony_ci * 105094332d3Sopenharmony_ci * @param adapter Indicates the pointer to the audio adapter to operate. 106094332d3Sopenharmony_ci * @param port Indicates the pointer to the port. 107094332d3Sopenharmony_ci * @param mode Indicates the passthrough transmission mode to set. 108094332d3Sopenharmony_ci * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 109094332d3Sopenharmony_ci * @see GetPassthroughMode 110094332d3Sopenharmony_ci */ 111094332d3Sopenharmony_ci int32_t (*SetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, 112094332d3Sopenharmony_ci enum AudioPortPassthroughMode mode); 113094332d3Sopenharmony_ci 114094332d3Sopenharmony_ci /** 115094332d3Sopenharmony_ci * @brief Obtains the passthrough data transmission mode of the audio port driver. 116094332d3Sopenharmony_ci * 117094332d3Sopenharmony_ci * @param adapter Indicates the pointer to the audio adapter to operate. 118094332d3Sopenharmony_ci * @param port Indicates the pointer to the port. 119094332d3Sopenharmony_ci * @param mode Indicates the pointer to the passthrough transmission mode to obtain. 120094332d3Sopenharmony_ci * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise. 121094332d3Sopenharmony_ci * @see SetPassthroughMode 122094332d3Sopenharmony_ci */ 123094332d3Sopenharmony_ci int32_t (*GetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, 124094332d3Sopenharmony_ci enum AudioPortPassthroughMode *mode); 125094332d3Sopenharmony_ci 126094332d3Sopenharmony_ci /** 127094332d3Sopenharmony_ci * @brief Sets extra audio parameters. 128094332d3Sopenharmony_ci * 129094332d3Sopenharmony_ci * @param adapter Indicates the audio adapter. 130094332d3Sopenharmony_ci * @param key Indicates what kind of parameter type will be set. 131094332d3Sopenharmony_ci * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. 132094332d3Sopenharmony_ci * @param value Indicates the value of the specified condition. 133094332d3Sopenharmony_ci * 134094332d3Sopenharmony_ci * The format of condition is <i>key=value</i>. Separate multiple key-value pairs by semicolons (;). 135094332d3Sopenharmony_ci * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: 136094332d3Sopenharmony_ci * <i>"EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;"</i> 137094332d3Sopenharmony_ci * EVENT_TYPE indicates sub volume event type: SetVolume = 1; SetMute = 4; 138094332d3Sopenharmony_ci * VOLUME_GROUP_ID indicates which volume group will be set; 139094332d3Sopenharmony_ci * AUDIO_VOLUME_TYPE indicates which volume type will be set; 140094332d3Sopenharmony_ci * 141094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 142094332d3Sopenharmony_ci */ 143094332d3Sopenharmony_ci int32_t (*SetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, 144094332d3Sopenharmony_ci const char *condition, const char *value); 145094332d3Sopenharmony_ci 146094332d3Sopenharmony_ci /** 147094332d3Sopenharmony_ci * @brief Get extra audio parameters. 148094332d3Sopenharmony_ci * 149094332d3Sopenharmony_ci * @param adapter Indicates the audio adapter. 150094332d3Sopenharmony_ci * @param key Indicates what kind of parameter type will be get. 151094332d3Sopenharmony_ci * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. 152094332d3Sopenharmony_ci * @param value Indicates the value of the specified condition. 153094332d3Sopenharmony_ci * @param lenth Indicates the length of the value pointer. 154094332d3Sopenharmony_ci * 155094332d3Sopenharmony_ci * The format of condition is <i>key=value</i>. Separate multiple key-value pairs by semicolons (;). 156094332d3Sopenharmony_ci * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: 157094332d3Sopenharmony_ci * <i>"EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;"</i> 158094332d3Sopenharmony_ci * EVENT_TYPE indicates sub volume event type: GetVolume = 1; GetMinVolume = 2; GetMaxVolume = 3; IsStreamMute = 4; 159094332d3Sopenharmony_ci * VOLUME_GROUP_ID indicates which volume group want get; 160094332d3Sopenharmony_ci * AUDIO_VOLUME_TYPE indicates which volume type want get; 161094332d3Sopenharmony_ci * 162094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 163094332d3Sopenharmony_ci */ 164094332d3Sopenharmony_ci int32_t (*GetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, 165094332d3Sopenharmony_ci const char *condition, char *value, int32_t lenth); 166094332d3Sopenharmony_ci}; 167094332d3Sopenharmony_ci} 168094332d3Sopenharmony_ci#endif /* AUDIO_ADAPTER_H */ 169094332d3Sopenharmony_ci/** @} */ 170