/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * 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.
 */

package android.hardware.audio@7.0;

import android.hardware.audio.common@7.0;
import android.hardware.audio.effect@7.0::IEffect;

interface IStream {
    /**
     * Return the frame size (number of bytes per sample).
     *
     * @return frameSize frame size in bytes.
     */
    getFrameSize() generates (uint64_t frameSize);

    /**
     * Return the frame count of the buffer. Calling this method is equivalent
     * to getting AUDIO_PARAMETER_STREAM_FRAME_COUNT on the legacy HAL.
     *
     * @return count frame count.
     */
    getFrameCount() generates (uint64_t count);

    /**
     * Return the size of input/output buffer in bytes for this stream.
     * It must be a multiple of the frame size.
     *
     * @return buffer buffer size in bytes.
     */
    getBufferSize() generates (uint64_t bufferSize);

    /**
     * Return supported audio profiles for this particular stream. This method
     * is normally called for streams opened on devices that use dynamic
     * profiles, e.g. HDMI and USB interfaces. Please note that supported
     * profiles of the stream may differ from the capabilities of the connected
     * physical device.
     *
     * For devices with fixed configurations, e.g. built-in audio devices, all
     * the profiles are specified in the audio_policy_configuration.xml
     * file. For such devices, this method must return the configuration from
     * the config file, or NOT_SUPPORTED retval.
     *
     * @return retval operation completion status.
     * @return formats supported audio profiles.
     *                 Must be non empty if retval is OK.
     */
    getSupportedProfiles()
            generates (Result retval, vec<AudioProfile> profiles);

    /**
     * Retrieves basic stream configuration: sample rate, audio format,
     * channel mask.
     *
     * @return retval operation completion status.
     * @return config basic stream configuration.
     */
    getAudioProperties() generates (Result retval, AudioConfigBase config);

    /**
     * Sets stream parameters. Only sets parameters that are specified.
     *
     * Optional method. If implemented, only called on a stopped stream.
     *
     * @param config basic stream configuration.
     * @return retval operation completion status.
     */
    setAudioProperties(AudioConfigBaseOptional config)
            generates (Result retval);

    /**
     * Applies audio effect to the stream.
     *
     * @param effectId effect ID (obtained from IEffectsFactory.createEffect) of
     *                 the effect to apply.
     * @return retval operation completion status.
     */
    addEffect(uint64_t effectId) generates (Result retval);

    /**
     * Stops application of the effect to the stream.
     *
     * @param effectId effect ID (obtained from IEffectsFactory.createEffect) of
     *                 the effect to remove.
     * @return retval operation completion status.
     */
    removeEffect(uint64_t effectId) generates (Result retval);

    /**
     * Put the audio hardware input/output into standby mode.
     * Driver must exit from standby mode at the next I/O operation.
     *
     * @return retval operation completion status.
     */
    standby() generates (Result retval);

    /**
     * Return the set of devices which this stream is connected to.
     *
     * Optional method
     *
     * @return retval operation completion status: OK or NOT_SUPPORTED.
     * @return device set of devices which this stream is connected to.
     */
    getDevices() generates (Result retval, vec<DeviceAddress> devices);

    /**
     * Connects the stream to one or multiple devices.
     *
     * This method must only be used for HALs that do not support
     * 'IDevice.createAudioPatch' method. Calling this method is
     * equivalent to setting AUDIO_PARAMETER_STREAM_ROUTING preceded
     * with a device address in the legacy HAL interface.
     *
     * @param address device to connect the stream to.
     * @return retval operation completion status.
     */
    setDevices(vec<DeviceAddress> devices) generates (Result retval);

    /**
     * Sets the HW synchronization source. Calling this method is equivalent to
     * setting AUDIO_PARAMETER_STREAM_HW_AV_SYNC on the legacy HAL.
     *
     * Optional method
     *
     * @param hwAvSync HW synchronization source
     * @return retval operation completion status.
     */
    setHwAvSync(AudioHwSync hwAvSync) generates (Result retval);

    /**
     * Generic method for retrieving vendor-specific parameter values.
     * The framework does not interpret the parameters, they are passed
     * in an opaque manner between a vendor application and HAL.
     *
     * Multiple parameters can be retrieved at the same time.
     * The implementation should return as many requested parameters
     * as possible, even if one or more is not supported
     *
     * @param context provides more information about the request
     * @param keys keys of the requested parameters
     * @return retval operation completion status.
     *         OK must be returned if keys is empty.
     *         NOT_SUPPORTED must be returned if at least one key is unknown.
     * @return parameters parameter key value pairs.
     *         Must contain the value of all requested keys if retval == OK
     */
    getParameters(vec<ParameterValue> context, vec<string> keys)
            generates (Result retval, vec<ParameterValue> parameters);

    /**
     * Generic method for setting vendor-specific parameter values.
     * The framework does not interpret the parameters, they are passed
     * in an opaque manner between a vendor application and HAL.
     *
     * Multiple parameters can be set at the same time though this is
     * discouraged as it make failure analysis harder.
     *
     * If possible, a failed setParameters should not impact the platform state.
     *
     * @param context provides more information about the request
     * @param parameters parameter key value pairs.
     * @return retval operation completion status.
     *         All parameters must be successfully set for OK to be returned
     */
    setParameters(vec<ParameterValue> context, vec<ParameterValue> parameters)
            generates (Result retval);

    /**
     * Called by the framework to start a stream operating in mmap mode.
     * createMmapBuffer() must be called before calling start().
     * Function only implemented by streams operating in mmap mode.
     *
     * @return retval OK in case the success.
     *                NOT_SUPPORTED on non mmap mode streams
     *                INVALID_STATE if called out of sequence
     */
    start() generates (Result retval);

    /**
     * Called by the framework to stop a stream operating in mmap mode.
     * Function only implemented by streams operating in mmap mode.
     *
     * @return retval OK in case the success.
     *                NOT_SUPPORTED on non mmap mode streams
     *                INVALID_STATE if called out of sequence
     */
    stop() generates (Result retval) ;

    /**
     * Called by the framework to retrieve information on the mmap buffer used for audio
     * samples transfer.
     * Function only implemented by streams operating in mmap mode.
     *
     * @param minSizeFrames minimum buffer size requested. The actual buffer
     *                     size returned in struct MmapBufferInfo can be larger.
     *                     The size must be a positive value.
     * @return retval OK in case the success.
     *                NOT_SUPPORTED on non mmap mode streams
     *                NOT_INITIALIZED in case of memory allocation error
     *                INVALID_ARGUMENTS if the requested buffer size is invalid
     *                INVALID_STATE if called out of sequence
     * @return info    a MmapBufferInfo struct containing information on the MMMAP buffer created.
     */
    createMmapBuffer(int32_t minSizeFrames)
            generates (Result retval, MmapBufferInfo info);

    /**
     * Called by the framework to read current read/write position in the mmap buffer
     * with associated time stamp.
     * Function only implemented by streams operating in mmap mode.
     *
     * @return retval OK in case the success.
     *                NOT_SUPPORTED on non mmap mode streams
     *                INVALID_STATE if called out of sequence
     * @return position a MmapPosition struct containing current HW read/write position in frames
     *                  with associated time stamp.
     */
    getMmapPosition()
            generates (Result retval, MmapPosition position);

    /**
     * Called by the framework to deinitialize the stream and free up
     * all currently allocated resources. It is recommended to close
     * the stream on the client side as soon as it is becomes unused.
     *
     * The client must ensure that this function is not called while
     * audio data is being transferred through the stream's message queues.
     *
     * @return retval OK in case the success.
     *                NOT_SUPPORTED if called on IStream instead of input or
     *                              output stream interface.
     *                INVALID_STATE if the stream was already closed.
     */
    close() generates (Result retval);
};
