Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 1 | /* |
bo.xiao | 00387eb | 2023-02-24 18:44:29 +0800 | [diff] [blame] | 2 | * Copyright (C) 2021 Amlogic Corporation. |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 3 | * |
bo.xiao | 00387eb | 2023-02-24 18:44:29 +0800 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 15 | * |
| 16 | * Description: |
| 17 | * User space AV sync module. |
| 18 | * |
| 19 | * Author: song.zhao@amlogic.com |
| 20 | */ |
| 21 | #ifndef AML_AVSYNC_H__ |
| 22 | #define AML_AVSYNC_H__ |
| 23 | |
| 24 | #include <stdint.h> |
| 25 | #include <stdbool.h> |
| 26 | #include <time.h> |
| 27 | |
| 28 | enum sync_mode { |
| 29 | AV_SYNC_MODE_VMASTER = 0, |
| 30 | AV_SYNC_MODE_AMASTER = 1, |
| 31 | AV_SYNC_MODE_PCR_MASTER = 2, |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 32 | AV_SYNC_MODE_IPTV = 3, |
| 33 | AV_SYNC_MODE_FREE_RUN = 4, |
Song Zhao | 95bd092 | 2021-09-21 14:07:46 -0700 | [diff] [blame] | 34 | AV_SYNC_MODE_VIDEO_MONO = 5, /* video render by system mono time */ |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 35 | AV_SYNC_MODE_MAX |
| 36 | }; |
| 37 | |
| 38 | enum sync_type { |
| 39 | AV_SYNC_TYPE_AUDIO, |
| 40 | AV_SYNC_TYPE_VIDEO, |
| 41 | AV_SYNC_TYPE_PCR, |
| 42 | AV_SYNC_TYPE_MAX |
| 43 | }; |
| 44 | |
| 45 | enum sync_start_policy { |
| 46 | AV_SYNC_START_NONE = 0, |
| 47 | AV_SYNC_START_V_FIRST = 1, |
| 48 | AV_SYNC_START_A_FIRST = 2, |
| 49 | AV_SYNC_START_ASAP = 3, |
| 50 | AV_SYNC_START_ALIGN = 4, |
| 51 | AV_SYNC_START_V_PEEK = 5, |
| 52 | AV_SYNC_START_MAX |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 53 | }; |
| 54 | |
Song Zhao | 8039f56 | 2021-05-18 18:11:25 -0700 | [diff] [blame] | 55 | enum clock_recovery_stat { |
| 56 | CLK_RECOVERY_NOT_RUNNING = 0, |
| 57 | CLK_RECOVERY_ONGOING = 1, |
| 58 | CLK_RECOVERY_READY = 2, |
wei.du | bcc2ed2 | 2021-05-19 07:16:10 -0400 | [diff] [blame] | 59 | CLK_RECOVERY_ERR, |
Song Zhao | 8039f56 | 2021-05-18 18:11:25 -0700 | [diff] [blame] | 60 | CLK_RECOVERY_MAX |
| 61 | }; |
| 62 | |
Song Zhao | 08fa16b | 2021-12-08 14:30:17 -0800 | [diff] [blame] | 63 | #define AV_SYNC_INVALID_PTS 0xFFFFFFFF |
| 64 | #define AV_SYNC_INVALID_PAUSE_PTS AV_SYNC_INVALID_PTS |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 65 | #define AV_SYNC_STEP_PAUSE_PTS 0xFFFFFFFE |
Song Zhao | 95bd092 | 2021-09-21 14:07:46 -0700 | [diff] [blame] | 66 | #define AV_SYNC_SESSION_V_MONO 64 |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 67 | |
| 68 | typedef uint32_t pts90K; |
| 69 | struct vframe; |
| 70 | typedef void (*free_frame)(struct vframe * frame); |
| 71 | typedef void (*pause_pts_done)(uint32_t pts, void* priv); |
yongchun.li | 428390d | 2022-02-17 17:15:40 -0800 | [diff] [blame] | 72 | typedef void (*underflow_detected)(uint32_t pts, void* priv); |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 73 | |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 74 | typedef enum { |
| 75 | /* good to render */ |
| 76 | AV_SYNC_ASCB_OK, |
| 77 | /* triggered by av_sync_destroy */ |
| 78 | AV_SYNC_ASCB_STOP, |
| 79 | } avs_ascb_reason; |
| 80 | |
| 81 | typedef int (*audio_start_cb)(void *priv, avs_ascb_reason reason); |
| 82 | |
| 83 | typedef enum { |
| 84 | AV_SYNC_ASTART_SYNC = 0, |
| 85 | AV_SYNC_ASTART_ASYNC, |
Song Zhao | d62bb39 | 2021-04-23 12:25:49 -0700 | [diff] [blame] | 86 | AV_SYNC_ASTART_AGAIN, |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 87 | AV_SYNC_ASTART_ERR |
| 88 | } avs_start_ret; |
| 89 | |
| 90 | typedef enum { |
| 91 | /* render ASAP */ |
| 92 | AV_SYNC_AA_RENDER, |
| 93 | /* late, drop to catch up */ |
| 94 | AV_SYNC_AA_DROP, |
| 95 | /* early, insert to hold */ |
| 96 | AV_SYNC_AA_INSERT, |
| 97 | AA_SYNC_AA_MAX |
| 98 | } avs_audio_action; |
| 99 | |
| 100 | struct audio_policy { |
| 101 | avs_audio_action action; |
| 102 | /* delta between apts and ideal render position |
| 103 | * positive means apts is behind wall clock |
| 104 | * negative means apts is ahead of wall clock |
Song Zhao | d62bb39 | 2021-04-23 12:25:49 -0700 | [diff] [blame] | 105 | * 0 is only valid for AV_SYNC_AA_DROP, drop current chunk |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 106 | */ |
| 107 | int delta; |
| 108 | }; |
| 109 | |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 110 | struct vframe { |
| 111 | /* private user data */ |
| 112 | void *private; |
| 113 | pts90K pts; |
Song Zhao | 95bd092 | 2021-09-21 14:07:46 -0700 | [diff] [blame] | 114 | /* mono render time in nanosecdons only use in VIDEO_MONO */ |
| 115 | uint64_t mts; |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 116 | /* duration of this frame. 0 for invalid value */ |
| 117 | pts90K duration; |
| 118 | /* free function, will be called when multi frames are |
| 119 | * toggled in a single VSYNC, on frames not for display. |
| 120 | * For the last toggled frame, free won't be called. Caller |
| 121 | * of av_sync_pop_frame() are responsible for free poped frame. |
| 122 | * For example, if frame 1/2/3 are toggled in a single VSYCN, |
| 123 | * free() of 1/2 will be called, but free() of 3 won't. |
| 124 | */ |
| 125 | free_frame free; |
| 126 | |
| 127 | //For internal usage under this line |
| 128 | /*holding period */ |
| 129 | int hold_period; |
| 130 | }; |
| 131 | |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 132 | struct video_config { |
| 133 | /* AV sync delay. The delay of render. |
| 134 | * For video in VSYNC number unit: |
| 135 | * 2 for video planes |
| 136 | * 1 for osd planes |
| 137 | */ |
| 138 | int delay; |
Song Zhao | 6dce267 | 2022-01-13 11:32:44 -0800 | [diff] [blame] | 139 | /* delayed video for slow audio path, in ms */ |
| 140 | int extra_delay; |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 141 | }; |
| 142 | |
bo.xiao | 5821fc7 | 2021-07-11 22:47:00 -0400 | [diff] [blame] | 143 | struct start_policy { |
| 144 | enum sync_start_policy policy; |
| 145 | /*timeout in ms */ |
| 146 | int timeout; |
| 147 | }; |
yongchun.li | 428390d | 2022-02-17 17:15:40 -0800 | [diff] [blame] | 148 | struct underflow_config { |
| 149 | int time_thresh; /* underflow check time threshold in ms */ |
| 150 | }; |
bo.xiao | 5821fc7 | 2021-07-11 22:47:00 -0400 | [diff] [blame] | 151 | |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 152 | /* Open a new session and create the ID |
| 153 | * Params: |
| 154 | * @session_id: session ID allocated if success |
| 155 | * Return: |
| 156 | * >= 0 session handle. session_id is valid |
| 157 | * < 0 error, session_id is invalid |
| 158 | */ |
| 159 | int av_sync_open_session(int *session_id); |
| 160 | |
| 161 | /* Close session, will also decrease the ref cnt of session ID. |
| 162 | * Params: |
| 163 | * @session: Av sync session handle |
| 164 | */ |
| 165 | void av_sync_close_session(int session); |
| 166 | |
| 167 | /* Attach to kernel session. The returned avsync module will |
| 168 | * associated with @session_id. It is valid to create multi instance |
| 169 | * with the same session_id. For example, one for video, one for audio, |
| 170 | * one for PCR. But it is NOT valid to create 2 video session with the |
| 171 | * same session_id. Create session will increase the ref count of session |
| 172 | * ID. |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 173 | * Params: |
| 174 | * @session_id: unique AV sync session ID to bind audio and video |
| 175 | * usually get from kernel driver. |
Song Zhao | 95bd092 | 2021-09-21 14:07:46 -0700 | [diff] [blame] | 176 | * If ID AV_SYNC_SESSION_V_MONO or bigger is assigned, only |
| 177 | * AV_SYNC_MODE_VIDEO_MONO is accepted. |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 178 | * @mode: AV sync mode of enum sync_mode |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 179 | * @type: AV sync type of enum sync_type. For a stream with both |
| 180 | * video and audio, two instances with each type should be created. |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 181 | * @start_thres: The start threshold of AV sync module. Set it to 0 for |
| 182 | * a default value. For low latency mode, set it to 1. Bigger |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 183 | * value will increase the delay of the first frame rendered. |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 184 | * AV sync will start when frame number reached threshold. |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 185 | * Return: |
| 186 | * null for failure, or handle for avsync module. |
| 187 | */ |
| 188 | void* av_sync_create(int session_id, |
| 189 | enum sync_mode mode, |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 190 | enum sync_type type, |
| 191 | int start_thres); |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 192 | |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 193 | |
| 194 | /* Attach to an existed session. The returned avsync module will |
| 195 | * associated with @session_id. use av_sync_destroy to destroy it. |
| 196 | * Designed for audio path for now. Session created by audio client, |
| 197 | * and attached by audio HAL. Attach sesson will increase the ref count of |
| 198 | * session ID. |
| 199 | * Params: |
| 200 | * @session_id: unique AV sync session ID to bind audio and video |
| 201 | * usually get from kernel driver. |
| 202 | * @type: AV sync type of enum sync_type. For a stream with both |
| 203 | * video and audio, two instances with each type should be created. |
| 204 | * Return: |
| 205 | * null for failure, or handle for avsync module. |
| 206 | */ |
| 207 | |
| 208 | void* av_sync_attach(int session_id, |
| 209 | enum sync_type type); |
| 210 | |
| 211 | /* Dettach from existed session. Decrease the ref count of session ID |
| 212 | * Params: |
| 213 | * @sync: handle for avsync module |
| 214 | */ |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 215 | void av_sync_destroy(void *sync); |
| 216 | |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 217 | int av_sync_video_config(void *sync, struct video_config* config); |
| 218 | |
| 219 | /* Set start policy |
| 220 | * Params: |
| 221 | * @sync: AV sync module handle |
| 222 | * @policy: start policy |
| 223 | * Return: |
| 224 | * 0 for OK, or error code |
| 225 | */ |
bo.xiao | 5821fc7 | 2021-07-11 22:47:00 -0400 | [diff] [blame] | 226 | int avs_sync_set_start_policy(void *sync, struct start_policy* st_policy); |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 227 | |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 228 | /* Pause/Resume AV sync module. |
| 229 | * It will return last frame in @av_sync_pop_frame() in pause state |
| 230 | * Params: |
| 231 | * @sync: AV sync module handle |
| 232 | * @pause: pause for true, or resume. |
| 233 | * Return: |
| 234 | * 0 for OK, or error code |
| 235 | */ |
| 236 | int av_sync_pause(void *sync, bool pause); |
| 237 | |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 238 | /* Push a new video frame to AV sync module |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 239 | * Params: |
| 240 | * @sync: AV sync module handle |
| 241 | * Return: |
| 242 | * 0 for OK, or error code |
| 243 | */ |
| 244 | int av_sync_push_frame(void *sync , struct vframe *frame); |
| 245 | |
Song Zhao | 95bd092 | 2021-09-21 14:07:46 -0700 | [diff] [blame] | 246 | /* notify current system mono time for current VSYNC. |
| 247 | * This API should be VSYNC triggerd. Used only in VIDEO_MONO mode. |
| 248 | * Params: |
| 249 | * @sync: AV sync module handle |
| 250 | * @msys: system mono time of current VSYNC interrupt in nanosecond |
| 251 | * Usually returned by drmWaitVBlank. |
| 252 | * Return: |
| 253 | * 0 for OK, or error code |
| 254 | * */ |
| 255 | int av_sync_set_vsync_mono_time(void *sync , uint64_t msys); |
| 256 | |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 257 | /* Pop video frame for next VSYNC. This API should be VSYNC triggerd. |
| 258 | * Params: |
| 259 | * @sync: AV sync module handle |
| 260 | * Return: |
| 261 | * Old frame if current frame is hold |
| 262 | * New frame if it is time for a frame toggle. |
| 263 | * null if there is no frame to pop out (underrun). |
| 264 | * */ |
| 265 | struct vframe *av_sync_pop_frame(void *sync); |
| 266 | |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 267 | /* Audio start control. Audio render need to check return value and |
Song Zhao | d62bb39 | 2021-04-23 12:25:49 -0700 | [diff] [blame] | 268 | * do sync or async start. NOT thread safe. |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 269 | * Params: |
| 270 | * @sync: AV sync module handle |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 271 | * @pts: first audio pts |
| 272 | * @delay: rendering delay |
| 273 | * @cb: callback to notify rendering start. |
| 274 | * @priv: parameter for cb |
| 275 | * Return: |
| 276 | * AV_SYNC_ASTART_SYNC, audio can start render ASAP. No need to wait for callback. |
| 277 | * AV_SYNC_ASTART_ASYNC, audio need to block until callback is triggered. |
Song Zhao | d62bb39 | 2021-04-23 12:25:49 -0700 | [diff] [blame] | 278 | * AV_SYNC_ASTART_AGAIN, discard current audio chunk and call this API again. |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 279 | * AV_SYNC_ASTART_ERR, something bad happens |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 280 | */ |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 281 | avs_start_ret av_sync_audio_start( |
| 282 | void *sync, |
| 283 | pts90K pts, |
| 284 | pts90K delay, |
| 285 | audio_start_cb cb, |
| 286 | void *priv); |
| 287 | |
| 288 | /* Audio render policy. Indicate render action and the difference from ideal position |
Song Zhao | d62bb39 | 2021-04-23 12:25:49 -0700 | [diff] [blame] | 289 | * NOT thread safe. |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 290 | * Params: |
| 291 | * @sync: AV sync module handle |
| 292 | * @pts: curent audio pts (considering delay) |
| 293 | * @policy: action field indicates the action. |
| 294 | * delta field indicates the diff from ideal position |
| 295 | * Return: |
| 296 | * 0 for OK, or error code |
| 297 | */ |
| 298 | int av_sync_audio_render( |
| 299 | void *sync, |
| 300 | pts90K pts, |
| 301 | struct audio_policy *policy); |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 302 | |
| 303 | /* set playback speed |
| 304 | * Currently only work for VMASTER mode |
| 305 | * Params: |
| 306 | * @speed: 1.0 is normal speed. 2.0 is 2x faster. 0.1 is 10x slower |
| 307 | * Minimium speed is 0.001 |
| 308 | * Max speed is 100 |
| 309 | * Return: |
| 310 | * 0 for OK, or error code |
| 311 | */ |
| 312 | int av_sync_set_speed(void *sync, float speed); |
| 313 | |
| 314 | /* switch avsync mode |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 315 | * PCR master/IPTV handle mode change automatically |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 316 | * Params: |
| 317 | * @sync: AV sync module handle |
| 318 | * @sync_mode: new mode |
| 319 | * Return: |
| 320 | * 0 for OK, or error code |
| 321 | */ |
| 322 | int av_sync_change_mode(void *sync, enum sync_mode mode); |
| 323 | |
Song Zhao | ebc9201 | 2024-03-12 18:36:44 +0000 | [diff] [blame^] | 324 | /* switch avsync mode by session id |
| 325 | * For Ad audio, it won't create avsync session, mode can be changed |
| 326 | * by session id. |
| 327 | * Params: |
| 328 | * @sync: AV sync module handle |
| 329 | * @sync_mode: new mode |
| 330 | * Return: |
| 331 | * 0 for OK, or error code |
| 332 | */ |
| 333 | int av_sync_change_mode_by_id(int id, enum sync_mode mode); |
| 334 | |
Song Zhao | 01031bb | 2021-05-13 21:23:20 -0700 | [diff] [blame] | 335 | /* get avsync mode |
| 336 | * Params: |
| 337 | * @sync: AV sync module handle |
| 338 | * @mode: pointer to return current mode |
| 339 | * Return: |
| 340 | * 0 for OK, or error code |
| 341 | */ |
| 342 | int av_sync_get_mode(void *sync, enum sync_mode *mode); |
| 343 | |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 344 | /* set pause PTS |
| 345 | * av sync will pause after reaching the assigned PTS or do step. |
| 346 | * Need to call @av_sync_pause(false) to resume a the playback. |
| 347 | * Params: |
| 348 | * @sync: AV sync module handle |
| 349 | * @pts: pause pts in uint of 90K. |
| 350 | * AV_SYNC_STEP_PAUSE_PTS: step one frame, and the callback |
| 351 | * will report pts value of the stepped frame. |
| 352 | * AV_SYNC_INVALID_PAUSE_PTS: disable this feature. |
| 353 | * Other value: play until the assigned PTS, and the callback |
| 354 | * will report pts value of the paused frame. |
| 355 | * Return: |
| 356 | * 0 for OK, or error code |
| 357 | */ |
| 358 | int av_sync_set_pause_pts(void *sync, pts90K pts); |
| 359 | |
| 360 | /* set pause PTS call back |
| 361 | * av sync will callback when pause PTS is reached with assigned PTS from |
| 362 | * @av_sync_set_pause_pts. |
| 363 | * Params: |
| 364 | * @sync: AV sync module handle |
| 365 | * @cb: callback function |
| 366 | * @priv: callback function parameter |
| 367 | * Return: |
| 368 | * 0 for OK, or error code |
| 369 | */ |
| 370 | int av_sync_set_pause_pts_cb(void *sync, pause_pts_done cb, void *priv); |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 371 | |
| 372 | /* Update PCR clock. |
| 373 | * Use by AV_SYNC_TYPE_PCR only. |
| 374 | * Params: |
| 375 | * @sync: AV sync module handle |
| 376 | * @pts: PCR clock |
Song Zhao | d62bb39 | 2021-04-23 12:25:49 -0700 | [diff] [blame] | 377 | * @mono_clock: system monotonic clock receiving the pts |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 378 | * Return: |
| 379 | * 0 for OK, or error code |
| 380 | */ |
Song Zhao | d62bb39 | 2021-04-23 12:25:49 -0700 | [diff] [blame] | 381 | int av_sync_set_pcr_clock(void *sync, pts90K pts, uint64_t mono_clock); |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 382 | |
Song Zhao | d62bb39 | 2021-04-23 12:25:49 -0700 | [diff] [blame] | 383 | /* Get PCR clock pair. |
| 384 | * Use for clock recovery |
| 385 | * Params: |
| 386 | * @sync: AV sync module handle |
| 387 | * @pts: PCR clock pointer |
| 388 | * @mono_clock: system monotonic clock pointer receiving the pts |
| 389 | * Return: |
| 390 | * 0 for OK, or error code |
| 391 | */ |
| 392 | int av_sync_get_pcr_clock(void *sync, pts90K *pts, uint64_t *mono_clock); |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 393 | |
| 394 | /* get wall clock |
| 395 | * Params: |
| 396 | * @sync: AV sync module handle |
| 397 | * @pts: return wall clock |
| 398 | * Return: |
| 399 | * 0 for OK, or error code |
| 400 | */ |
| 401 | int av_sync_get_clock(void *sync, pts90K *pts); |
| 402 | |
Song Zhao | f3350d3 | 2023-08-18 16:27:31 -0700 | [diff] [blame] | 403 | /* get render position and system mono raw time pair. |
| 404 | * pts type depends on sync_type of av_sync_create/av_sync_attach |
| 405 | * Params: |
| 406 | * @sync: AV sync module handle |
| 407 | * @pts: last rendered pts |
| 408 | * @mono_clock: CLOCK_MONOTONIC_RAW in nanosecond of the last rendered |
| 409 | * frame. 0 is invalid. |
| 410 | * Return: |
| 411 | * 0 for OK, or error code |
| 412 | */ |
| 413 | int av_sync_get_pos(void *sync, pts90K *pts, uint64_t *mono_clock); |
| 414 | |
Song Zhao | ea5a041 | 2021-01-18 16:40:08 -0800 | [diff] [blame] | 415 | /* set session name for debugging purpose |
| 416 | * The session name will be listed from /sys/class/aml_msync/list_session |
| 417 | * Params: |
| 418 | * @sync: AV sync module handle |
| 419 | * @name: name of current session. |
| 420 | * Return: |
| 421 | * 0 for OK, or error code |
| 422 | */ |
| 423 | int av_sync_set_session_name(void *sync, const char *name); |
yongchun.li | 107a616 | 2021-05-05 02:38:57 -0700 | [diff] [blame] | 424 | |
| 425 | /* Start/finish audio seamless switch |
| 426 | * It declaims the coming audio seamless switch will happen. |
| 427 | * After removing the audio, the video will still play normally. |
| 428 | * After adding back the audio, it will sync with pipe-line without break the playing, |
| 429 | * only short audio break/mute on the switch is expected. |
| 430 | * Params: |
| 431 | * @sync: AV sync module handle |
| 432 | * @start: start the switch for true, or finish/reset for false |
| 433 | * Return: |
| 434 | * 0 for OK, or error code |
| 435 | */ |
| 436 | int av_sync_set_audio_switch(void *sync, bool start); |
| 437 | |
| 438 | /* Get the current audio seamless switch status. |
| 439 | * After setting the seamless switch, upper level can get the result by polling. |
| 440 | * The status will become false when the switching has finished or being termintated |
| 441 | * Params: |
| 442 | * @sync: AV sync module handle |
| 443 | * @status: start the switch for true, or finish/reset for false |
| 444 | * Return: |
| 445 | * 0 for OK, or error code |
| 446 | */ |
| 447 | int av_sync_get_audio_switch(void *sync, bool *status); |
| 448 | |
Song Zhao | 623e2f1 | 2021-09-03 15:54:04 -0700 | [diff] [blame] | 449 | /* Get the current clock deviation between PCR clock and system monotonic clock. |
Song Zhao | 8039f56 | 2021-05-18 18:11:25 -0700 | [diff] [blame] | 450 | * Params: |
| 451 | * @sync: AV sync module handle |
| 452 | * @ppm: part per million. Bigger than 0 is PCR master clock is faster. Less than 0 |
| 453 | * if PCR master clock is slower. |
| 454 | * Return: |
| 455 | * CLK_RECOVERY_NOT_RUNNING: current mode doesn't support clock recovery |
| 456 | * CLK_RECOVERY_ONGOING: still ongoing, need more time to converge. |
| 457 | * CLK_RECOVERY_READY: clock recovery result is ready to be used. The result might |
| 458 | * be updated later for better accuracy. |
wei.du | bcc2ed2 | 2021-05-19 07:16:10 -0400 | [diff] [blame] | 459 | * CLK_RECOVERY_ERR: error happens |
Song Zhao | 8039f56 | 2021-05-18 18:11:25 -0700 | [diff] [blame] | 460 | */ |
Song Zhao | 623e2f1 | 2021-09-03 15:54:04 -0700 | [diff] [blame] | 461 | enum clock_recovery_stat av_sync_get_clock_deviation(void *sync, int32_t *ppm); |
yongchun.li | 428390d | 2022-02-17 17:15:40 -0800 | [diff] [blame] | 462 | |
| 463 | /* set underflow detect call back |
| 464 | * av sync will callback when a buffer underflow detected when normal play |
| 465 | * Params: |
| 466 | * @sync: AV sync module handle |
| 467 | * @cb: callback function |
| 468 | * @priv: callback function parameter |
| 469 | * @cfg: the configuration of the call back, NULL use default value. |
| 470 | * Return: |
| 471 | * 0 for OK, or error code |
| 472 | */ |
| 473 | int av_sync_set_underflow_check_cb(void *sync, underflow_detected cb, void *priv, struct underflow_config *cfg); |
Song Zhao | 6183ca9 | 2022-07-29 09:57:03 -0700 | [diff] [blame] | 474 | |
| 475 | /* Cancel audio waiting. |
| 476 | * When AV_SYNC_ASTART_ASYNC blocks a thread, use this API to unblock it. |
| 477 | * audio_start_cb will be triggered with AV_SYNC_ASCB_STOP. |
| 478 | * Params: |
| 479 | * @sync: AV sync module handle |
| 480 | * Return: |
| 481 | * 0 for OK, or error code |
| 482 | */ |
| 483 | int avs_sync_stop_audio(void *sync); |
bo.xiao | 05ba1ac | 2022-12-13 14:38:13 +0800 | [diff] [blame] | 484 | |
| 485 | /* eos from video decoder. |
| 486 | * when video decoder eos, use this API to set eos to msync. |
| 487 | * Only effect video. |
| 488 | * Params: |
| 489 | * @sync: AV sync module handle |
| 490 | * Return: |
| 491 | * 0 for OK, or error code |
| 492 | */ |
| 493 | int avs_sync_set_eos(void *sync); |
Song Zhao | c03ba12 | 2020-12-23 21:54:02 -0800 | [diff] [blame] | 494 | #endif |