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_render.h
29094332d3Sopenharmony_ci *
30094332d3Sopenharmony_ci * @brief Declares APIs for audio rendering.
31094332d3Sopenharmony_ci *
32094332d3Sopenharmony_ci * @since 1.0
33094332d3Sopenharmony_ci * @version 1.0
34094332d3Sopenharmony_ci */
35094332d3Sopenharmony_ci
36094332d3Sopenharmony_ci#ifndef AUDIO_RENDER_H
37094332d3Sopenharmony_ci#define AUDIO_RENDER_H
38094332d3Sopenharmony_ci
39094332d3Sopenharmony_ci#include "audio_types.h"
40094332d3Sopenharmony_ci#include "audio_control.h"
41094332d3Sopenharmony_ci#include "audio_attribute.h"
42094332d3Sopenharmony_ci#include "audio_scene.h"
43094332d3Sopenharmony_ci#include "audio_volume.h"
44094332d3Sopenharmony_cinamespace OHOS::HDI::Audio_Bluetooth {
45094332d3Sopenharmony_ci/**
46094332d3Sopenharmony_ci * @brief Provides capabilities for audio rendering, including controlling the rendering, setting audio attributes,
47094332d3Sopenharmony_ci * scenes, and volume, obtaining hardware latency, and rendering audio frames.
48094332d3Sopenharmony_ci *
49094332d3Sopenharmony_ci * @see AudioControl
50094332d3Sopenharmony_ci * @see AudioAttribute
51094332d3Sopenharmony_ci * @see AudioScene
52094332d3Sopenharmony_ci * @see AudioVolume
53094332d3Sopenharmony_ci * @since 1.0
54094332d3Sopenharmony_ci * @version 1.0
55094332d3Sopenharmony_ci */
56094332d3Sopenharmony_cistruct AudioRender {
57094332d3Sopenharmony_ci    /**
58094332d3Sopenharmony_ci     * @brief Defines the audio control. For details, see {@link AudioControl}.
59094332d3Sopenharmony_ci     */
60094332d3Sopenharmony_ci    struct AudioControl control;
61094332d3Sopenharmony_ci    /**
62094332d3Sopenharmony_ci     * @brief Defines the audio attribute. For details, see {@link AudioAttribute}.
63094332d3Sopenharmony_ci     */
64094332d3Sopenharmony_ci    struct AudioAttribute attr;
65094332d3Sopenharmony_ci    /**
66094332d3Sopenharmony_ci     * @brief Defines the audio scene. For details, see {@link AudioScene}.
67094332d3Sopenharmony_ci     */
68094332d3Sopenharmony_ci    struct AudioScene scene;
69094332d3Sopenharmony_ci    /**
70094332d3Sopenharmony_ci     * @brief Defines audio volume. For details, see {@link AudioVolume}.
71094332d3Sopenharmony_ci     */
72094332d3Sopenharmony_ci    struct AudioVolume volume;
73094332d3Sopenharmony_ci
74094332d3Sopenharmony_ci    /**
75094332d3Sopenharmony_ci     * @brief Obtains the estimated latency of the audio device driver.
76094332d3Sopenharmony_ci     *
77094332d3Sopenharmony_ci     * @param render Indicates the pointer to the <b>AudioRender</b> object to operate.
78094332d3Sopenharmony_ci     * @param ms Indicates the pointer to the latency (in milliseconds) to be obtained.
79094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the latency is obtained; returns a negative value otherwise.
80094332d3Sopenharmony_ci     */
81094332d3Sopenharmony_ci    int32_t (*GetLatency)(struct AudioRender *render, uint32_t *ms);
82094332d3Sopenharmony_ci
83094332d3Sopenharmony_ci    /**
84094332d3Sopenharmony_ci     * @brief Writes a frame of output data (downlink data) into the audio driver for rendering.
85094332d3Sopenharmony_ci     *
86094332d3Sopenharmony_ci     * @param render Indicates the pointer to the <b>AudioRender</b> object to operate.
87094332d3Sopenharmony_ci     * @param frame Indicates the pointer to the frame to write.
88094332d3Sopenharmony_ci     * @param requestBytes Indicates the size of the frame, in bytes.
89094332d3Sopenharmony_ci     * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to write.
90094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the data is written successfully; returns a negative value otherwise.
91094332d3Sopenharmony_ci     */
92094332d3Sopenharmony_ci    int32_t (*RenderFrame)(struct AudioRender *render, const void *frame, uint64_t requestBytes, uint64_t *replyBytes);
93094332d3Sopenharmony_ci
94094332d3Sopenharmony_ci    /**
95094332d3Sopenharmony_ci     * @brief Obtains the last number of output audio frames.
96094332d3Sopenharmony_ci     *
97094332d3Sopenharmony_ci     * @param render Indicates the pointer to the <b>AudioRender</b> object to operate.
98094332d3Sopenharmony_ci     * @param frames Indicates the pointer to the last number of output audio frames.
99094332d3Sopenharmony_ci     * @param time Indicates the pointer to the timestamp associated with the frame.
100094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the last number is obtained; returns a negative value otherwise.
101094332d3Sopenharmony_ci     * @see RenderFrame
102094332d3Sopenharmony_ci     */
103094332d3Sopenharmony_ci    int32_t (*GetRenderPosition)(struct AudioRender *render, uint64_t *frames, struct AudioTimeStamp *time);
104094332d3Sopenharmony_ci
105094332d3Sopenharmony_ci    /**
106094332d3Sopenharmony_ci     * @brief Sets the audio rendering speed.
107094332d3Sopenharmony_ci     *
108094332d3Sopenharmony_ci     * @param render Indicates the pointer to the <b>AudioRender</b> object to operate.
109094332d3Sopenharmony_ci     * @param speed Indicates the rendering speed to set.
110094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise.
111094332d3Sopenharmony_ci     * @see GetRenderSpeed
112094332d3Sopenharmony_ci     */
113094332d3Sopenharmony_ci    int32_t (*SetRenderSpeed)(struct AudioRender *render, float speed);
114094332d3Sopenharmony_ci
115094332d3Sopenharmony_ci    /**
116094332d3Sopenharmony_ci     * @brief Obtains the current audio rendering speed.
117094332d3Sopenharmony_ci     *
118094332d3Sopenharmony_ci     * @param render Indicates the pointer to the <b>AudioRender</b> object to operate.
119094332d3Sopenharmony_ci     * @param speed Indicates the pointer to the current rendering speed to obtain.
120094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the speed is successfully obtained; returns a negative value otherwise.
121094332d3Sopenharmony_ci     * @see SetRenderSpeed
122094332d3Sopenharmony_ci     */
123094332d3Sopenharmony_ci    int32_t (*GetRenderSpeed)(struct AudioRender *render, float *speed);
124094332d3Sopenharmony_ci
125094332d3Sopenharmony_ci    /**
126094332d3Sopenharmony_ci     * @brief Sets the channel mode for audio rendering.
127094332d3Sopenharmony_ci     *
128094332d3Sopenharmony_ci     * @param render Indicates the pointer to the <b>AudioRender</b> object to operate.
129094332d3Sopenharmony_ci     * @param mode Indicates the channel mode to set.
130094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise.
131094332d3Sopenharmony_ci     * @see GetChannelMode
132094332d3Sopenharmony_ci     */
133094332d3Sopenharmony_ci    int32_t (*SetChannelMode)(struct AudioRender *render, enum AudioChannelMode mode);
134094332d3Sopenharmony_ci
135094332d3Sopenharmony_ci    /**
136094332d3Sopenharmony_ci     * @brief Obtains the current channel mode for audio rendering.
137094332d3Sopenharmony_ci     *
138094332d3Sopenharmony_ci     * @param render Indicates the pointer to the <b>AudioRender</b> object to operate.
139094332d3Sopenharmony_ci     * @param mode Indicates the pointer to the channel mode to obtain.
140094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise.
141094332d3Sopenharmony_ci     * @see SetChannelMode
142094332d3Sopenharmony_ci     */
143094332d3Sopenharmony_ci    int32_t (*GetChannelMode)(struct AudioRender *render, enum AudioChannelMode *mode);
144094332d3Sopenharmony_ci
145094332d3Sopenharmony_ci    /**
146094332d3Sopenharmony_ci     * @brief Registers an audio callback that will be invoked during playback when buffer data writing or
147094332d3Sopenharmony_ci     * buffer drain is complete.
148094332d3Sopenharmony_ci     *
149094332d3Sopenharmony_ci     * @param render Indicates the pointer to the <b>AudioRender</b> object to operate.
150094332d3Sopenharmony_ci     * @param callback Indicates the callback to register.
151094332d3Sopenharmony_ci     * @param cookie Indicates the pointer to the callback parameters.
152094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
153094332d3Sopenharmony_ci     * @see RegCallback
154094332d3Sopenharmony_ci     */
155094332d3Sopenharmony_ci    int32_t (*RegCallback)(struct AudioRender *render, RenderCallback callback, void* cookie);
156094332d3Sopenharmony_ci
157094332d3Sopenharmony_ci    /**
158094332d3Sopenharmony_ci     * @brief Drains the buffer.
159094332d3Sopenharmony_ci     *
160094332d3Sopenharmony_ci     * @param render Indicates the pointer to the <b>AudioRender</b> object to operate.
161094332d3Sopenharmony_ci     * @param type Indicates the pointer to the execution type of this function. For details,
162094332d3Sopenharmony_ci     * see {@link AudioDrainNotifyType}.
163094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
164094332d3Sopenharmony_ci     * @see RegCallback
165094332d3Sopenharmony_ci     */
166094332d3Sopenharmony_ci    int32_t (*DrainBuffer)(struct AudioRender *render, enum AudioDrainNotifyType *type);
167094332d3Sopenharmony_ci};
168094332d3Sopenharmony_ci}
169094332d3Sopenharmony_ci#endif /* AUDIO_RENDER_H */
170094332d3Sopenharmony_ci/** @} */
171