/*
 * Copyright (c) 2026 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 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.1
 * @version 6.0
 */

package ohos.hdi.distributed_audio.audio.v2_0;

import ohos.hdi.distributed_audio.audio.v2_0.AudioTypes;
import ohos.hdi.distributed_audio.audio.v2_0.IAudioRender;
import ohos.hdi.distributed_audio.audio.v2_0.IAudioCapture;
import ohos.hdi.distributed_audio.audio.v2_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.1
 * @version 2.0
 */
interface IAudioAdapter {
    /**
     * @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 <b>0</b> if the initialization is successful; returns a negative value otherwise.
     *
     * @since 4.1
     * @version 2.0
     */
    InitAllPorts();

    /**
     * @brief Creates an <b>IAudioRender</b> 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 <b>IAudioRender</b> object.
     * @return Returns <b>0</b> if the <b>IAudioRender</b> object is created successfully;
     * returns a negative value otherwise.
     * @see GetPortCapability
     * @see DestroyRender
     *
     * @since 4.1
     * @version 2.0
     */
    CreateRender([in] struct AudioDeviceDescriptor desc, [in] struct AudioSampleAttributes attrs,
                [out] IAudioRender render, [out] unsigned int renderId);

    /**
     * @brief Destroys an <b>IAudioRender</b> 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 <b>IAudioRender</b> object to operate.
     * @return Returns <b>0</b> if the <b>IAudioRender</b> object is destroyed; returns a negative value otherwise.
     * @see CreateRender
     *
     * @since 4.1
     * @version 2.0
     */
    DestroyRender([in] unsigned int renderId);

    /**
     * @brief Creates an <b>IAudioCapture</b> 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 <b>IAudioCapture</b> object.
     * @return Returns <b>0</b> if the <b>IAudioCapture</b> object is created successfully;
     * returns a negative value otherwise.
     * @see GetPortCapability
     * @see DestroyCapture
     *
     * @since 4.1
     * @version 2.0
     */
    CreateCapture([in] struct AudioDeviceDescriptor desc, [in] struct AudioSampleAttributes attrs,
                  [out] IAudioCapture capture, [out] unsigned int captureId);

    /**
     * @brief Destroys an <b>IAudioCapture</b> 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 <b>IAudioCapture</b> object to operate.
     * @return Returns <b>0</b> if the <b>IAudioCapture</b> object is destroyed; returns a negative value otherwise.
     * @see CreateCapture
     *
     * @since 4.1
     * @version 2.0
     */
    DestroyCapture([in] unsigned int captureId);

    /**
     * @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 <b>0</b> if the capability set is successfully obtained; returns a negative value otherwise.
     *
     * @since 4.1
     * @version 2.0
     */
    GetPortCapability([in] struct AudioPort port, [out] 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 <b>0</b> if the setting is successful; returns a negative value otherwise.
     * @see GetPassthroughMode
     *
     * @since 4.1
     * @version 2.0
     */
    SetPassthroughMode([in] struct AudioPort port, [in] 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 <b>0</b> if the mode is successfully obtained; returns a negative value otherwise.
     * @see SetPassthroughMode
     *
     * @since 4.1
     * @version 2.0
     */
    GetPassthroughMode([in] struct AudioPort port, [out] enum AudioPortPassthroughMode mode);

    /**
     * @brief Get the device status of an adapter.
     *
     * @param adapter Indicates the audio adapter.
     * @param status Indicates the status of device .
     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
     *
     * @since 4.1
     * @version 2.0
     */
    GetDeviceStatus([out] struct AudioDeviceStatus status);

    /**
     * @brief Update audio route on several source and sink ports.
     *
     * @param adapter Indicates the pointer to the audio adapter to operate.
     * @param route Indicates route information.
     * @param routeHandle Indicates route handle.
     * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise.
     * @see SetPassthroughMode
     *
     * @since 4.1
     * @version 2.0
     */
    UpdateAudioRoute([in] struct AudioRoute route, [out] int routeHandle);

    /**
     * @brief Release an audio route.
     *
     * @param adapter Indicates the pointer to the audio adapter to operate.
     * @param routeHandle Indicates route handle.
     * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise.
     * @see SetPassthroughMode
     *
     * @since 4.1
     * @version 2.0
     */
    ReleaseAudioRoute([in] int routeHandle);

    /**
     * @brief Sets the mute operation for the audio.
     *
     * @param adapter Indicates the pointer to the audio adapter to operate.
     * @param mute Specifies whether to mute the audio. Value <b>true</b> means to mute the audio,
     * and <b>false</b> means the opposite.
     * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise.
     * @see GetMute
     *
     * @since 4.1
     * @version 2.0
     */
    SetMicMute([in] boolean mute);

    /**
     * @brief Obtains the mute operation set for the audio.
     *
     * @param adapter Indicates the pointer to the audio adapter to operate.
     * @param mute Indicates the pointer to the mute operation set for the audio. Value <b>true</b> means that
     * the audio is muted, and <b>false</b> means the opposite.
     * @return Returns <b>0</b> if the mute operation is obtained; returns a negative value otherwise.
     * @see SetMute
     *
     * @since 4.1
     * @version 2.0
     */
    GetMicMute([out] boolean mute);

    /**
     * @brief Sets the audio volume for voice call.
     *
     * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15,
     * <b>0.0</b> indicates that the audio is muted, and <b>1.0</b> indicates the maximum volume level (15).
     *
     * @param adapter Indicates the pointer to the audio adapter to operate.
     * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0.
     * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise.
     * @see GetVolume
     *
     * @since 4.1
     * @version 2.0
     */
    SetVoiceVolume([in] float volume);

    /**
     * @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 <i>key=value</i>. 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:
     * <i>"EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;"</i>
     * 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 <b>0</b> if the operation is successful; returns a negative value otherwise.
     *
     * @since 4.1
     * @version 2.0
     */
    SetExtraParams([in] enum AudioExtParamKey key, [in] String condition, [in] String 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 <i>key=value</i>. 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:
     * <i>"EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;"</i>
     * 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 <b>0</b> if the operation is successful; returns a negative value otherwise.
     *
     * @since 4.1
     * @version 2.0
     */
    GetExtraParams([in] enum AudioExtParamKey key, [in] String condition, [out] String value);

    /**
     * @brief Register extra audio parameters observer.
     *
     * @param adapter Indicates the audio adapter.
     * @param callback Indicates param observer.
     * @param cookie Indicates the pointer to the callback parameters;
     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
     *
     * @since 4.1
     * @version 2.0
     */
    RegExtraParamObserver([in] IAudioCallback audioCallback, [in] byte cookie);

    /**
     * @brief Create a cognition stream.
     *
     * @param handle Indicates the audio handle.
     * @param attrs Indicates the pointer to the audio sampling attributes to create.
     * @param cogStreamId Indicates the pointer to cognition stream identifier.
     * @param desc Indicates the pointer to the mmap buffer descriptor.
     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
     *
     * @since 6.1
     * @version 1.0
     */
    CreateCognitionStream([in] struct AudioSampleAttributes attrs, [out] int cogStreamId, 
                 [out] struct AudioMmapBufferDescriptor desc);
    
    /**
     * @brief Destroy a cognition buffer.
     *
     * @param handle Indicates the audio handle.
     * @param cogStreamId Indicates the cognition stream identifier.
     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
     *
     * @since 6.1
     * @version 1.0
     */
    DestroyCognitionStream([in] int cogStreamId);

    /**
     * @brief Notify cognition data update.
     *
     * @param handle Indicates the audio handle.
     * @param cogStreamId Indicates the cognition stream identifier.
     * @param size Indicates the bufffer update size, in bytes.
     * @param offset Indicates the bufffer update offset, in bytes.
     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
     *
     * @since 6.1
     * @version 1.0
     */
    NotifyCognitionData([in] int cogStreamId, [in] unsigned int size, [in] unsigned int offset);
}
/** @} */