1 /*
2 * include/linux/amlogic/media/frame_sync/tsync.h
3 *
4 * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 */
17
18 #ifndef TSYNC_H
19 #define TSYNC_H
20
21 #define TIME_UNIT90K (90000)
22 #define VIDEO_HOLD_THRESHOLD (TIME_UNIT90K * 3)
23 #define VIDEO_HOLD_SLOWSYNC_THRESHOLD (TIME_UNIT90K / 10)
24 #define AV_DISCONTINUE_THREDHOLD_MIN (TIME_UNIT90K * 3)
25 #define AV_DISCONTINUE_THREDHOLD_MAX (TIME_UNIT90K * 60)
26
27 enum avevent_e {
28 VIDEO_START,
29 VIDEO_PAUSE,
30 VIDEO_STOP,
31 VIDEO_TSTAMP_DISCONTINUITY,
32 AUDIO_START,
33 AUDIO_PAUSE,
34 AUDIO_RESUME,
35 AUDIO_STOP,
36 AUDIO_TSTAMP_DISCONTINUITY,
37 AUDIO_PRE_START,
38 AUDIO_WAIT
39 };
40
41 enum tsync_mode_e {
42 TSYNC_MODE_VMASTER,
43 TSYNC_MODE_AMASTER,
44 TSYNC_MODE_PCRMASTER,
45 };
46
47 enum tysnc_func_type_e {
48 TSYNC_PCRSCR_VALID,
49 TSYNC_PCRSCR_GET,
50 TSYNC_FIRST_PCRSCR_GET,
51 TSYNC_PCRAUDIO_VALID,
52 TSYNC_PCRVIDEO_VALID,
53 TSYNC_BUF_BY_BYTE,
54 TSYNC_STBUF_LEVEL,
55 TSYNC_STBUF_SPACE,
56 TSYNC_STBUF_SIZE,
57 TSYNC_FUNC_TYPE_MAX,
58 };
59
60 extern bool disable_slow_sync;
61
62 typedef u8 (*pfun_tsdemux_pcrscr_valid)(void);
63 extern pfun_tsdemux_pcrscr_valid tsdemux_pcrscr_valid_cb;
64
65 typedef u32 (*pfun_tsdemux_pcrscr_get)(void);
66 extern pfun_tsdemux_pcrscr_get tsdemux_pcrscr_get_cb;
67
68 typedef u32 (*pfun_tsdemux_first_pcrscr_get)(void);
69 extern pfun_tsdemux_first_pcrscr_get tsdemux_first_pcrscr_get_cb;
70
71 typedef u8 (*pfun_tsdemux_pcraudio_valid)(void);
72 extern pfun_tsdemux_pcraudio_valid tsdemux_pcraudio_valid_cb;
73
74 typedef u8 (*pfun_tsdemux_pcrvideo_valid)(void);
75 extern pfun_tsdemux_pcrvideo_valid tsdemux_pcrvideo_valid_cb;
76
77 typedef struct stream_buf_s *(*pfun_get_buf_by_type)(u32 type);
78 extern pfun_get_buf_by_type get_buf_by_type_cb;
79
80 typedef u32 (*pfun_stbuf_level)(struct stream_buf_s *buf);
81 extern pfun_stbuf_level stbuf_level_cb;
82
83 typedef u32 (*pfun_stbuf_space)(struct stream_buf_s *buf);
84 extern pfun_stbuf_space stbuf_space_cb;
85
86 typedef u32 (*pfun_stbuf_size)(struct stream_buf_s *buf);
87 extern pfun_stbuf_size stbuf_size_cb;
88
89 extern int register_tsync_callbackfunc(
90 enum tysnc_func_type_e ntype, void *pfunc);
91
92 #ifdef MODIFY_TIMESTAMP_INC_WITH_PLL
93 extern void set_timestamp_inc_factor(u32 factor);
94 #endif
95
96 #ifdef CALC_CACHED_TIME
97 extern int pts_cached_time(u8 type);
98 #endif
99
100 extern int get_vsync_pts_inc_mode(void);
101
102 extern void tsync_avevent_locked(enum avevent_e event, u32 param);
103
104 extern void tsync_mode_reinit(void);
105
106 extern void tsync_avevent(enum avevent_e event, u32 param);
107
108 extern void tsync_audio_break(int audio_break);
109
110 extern void tsync_trick_mode(int trick_mode);
111
112 extern void tsync_set_avthresh(unsigned int av_thresh);
113
114 extern void tsync_set_syncthresh(unsigned int sync_thresh);
115
116 extern void tsync_set_dec_reset(void);
117
118 extern void tsync_set_enable(int enable);
119
120 extern int tsync_get_mode(void);
121
122 extern int tsync_get_sync_adiscont(void);
123
124 extern int tsync_get_sync_vdiscont(void);
125
126 extern void tsync_set_sync_adiscont(int syncdiscont);
127
128 extern void tsync_set_sync_vdiscont(int syncdiscont);
129
130 extern u32 tsync_get_sync_adiscont_diff(void);
131
132 extern u32 tsync_get_sync_vdiscont_diff(void);
133
134 extern void tsync_set_sync_adiscont_diff(u32 discontinue_diff);
135
136 extern void tsync_set_sync_vdiscont_diff(u32 discontinue_diff);
137 extern int tsync_set_apts(unsigned int pts);
138
139 extern void tsync_init(void);
140
141 extern void tsync_set_automute_on(int automute_on);
142
143 extern int tsync_get_debug_pts_checkin(void);
144
145 extern int tsync_get_debug_pts_checkout(void);
146
147 extern int tsync_get_debug_vpts(void);
148
149 extern int tsync_get_debug_apts(void);
150 extern int tsync_get_av_threshold_min(void);
151
152 extern int tsync_get_av_threshold_max(void);
153
154 extern int tsync_set_av_threshold_min(int min);
155
156 extern int tsync_set_av_threshold_max(int max);
157
158 extern void set_pts_realign(void);
159
160 extern int tsync_set_tunnel_mode(int mode);
161
162 extern int tsync_get_tunnel_mode(void);
163
164 extern void timestamp_set_pcrlatency(u32 latency);
165 extern u32 timestamp_get_pcrlatency(void);
166 extern bool tsync_check_vpts_discontinuity(unsigned int vpts);
167 int tsync_get_vpts_error_num(void);
168 int tsync_get_apts_error_num(void);
169 extern void timestamp_clac_pts_latency(u8 type, u32 pts);
170 extern u32 timestamp_get_pts_latency(u8 type);
171 extern void timestamp_clean_pts_latency(u8 type);
172 extern int tsync_get_vpts_adjust(void);
173 void tsync_set_av_state(u8 type, int state);
174 void timestamp_checkin_firstaoffset_set(u32 offset);
175 u32 timestamp_checkin_firstaoffset_get(void);
176
tsync_vpts_discontinuity_margin(void)177 static inline u32 tsync_vpts_discontinuity_margin(void)
178 {
179 return tsync_get_av_threshold_min();
180 }
181
182 #endif /* TSYNC_H */
183