summaryrefslogtreecommitdiff
path: root/audio_hwsync.h (plain)
blob: 99bf8ae783415d3049a22b2b0aee4083f0b2b113
1#ifndef _AUDIO_HWSYNC_H_
2#define _AUDIO_HWSYNC_H_
3
4#define TSYNC_FIRSTAPTS "/sys/class/tsync/firstapts"
5#define TSYNC_PCRSCR "/sys/class/tsync/pts_pcrscr"
6#define TSYNC_EVENT "/sys/class/tsync/event"
7#define TSYNC_APTS "/sys/class/tsync/pts_audio"
8#define SYSTIME_CORRECTION_THRESHOLD (90000*10/100)
9#define NSEC_PER_SECOND 1000000000ULL
10#define HW_SYNC_STATE_HEADER 0
11#define HW_SYNC_STATE_BODY 1
12#define HW_SYNC_STATE_RESYNC 2
13#define APTS_DISCONTINUE_THRESHOLD (90000)
14#define APTS_DISCONTINUE_THRESHOLD_MIN (90000/1000*100)
15#define APTS_DISCONTINUE_THRESHOLD_MAX (5*90000)
16
17typedef struct audio_hwsync {
18 uint8_t hw_sync_header[16];
19 size_t hw_sync_header_cnt;
20 int hw_sync_state;
21 size_t hw_sync_body_cnt;
22 int hw_sync_frame_size;
23 uint8_t hw_sync_body_buf[4096];
24 uint8_t body_align[64];
25 uint8_t body_align_cnt;
26 bool first_apts_flag;//flag to indicate set first apts
27 uint64_t first_apts;
28 uint64_t last_apts_from_header;
29} audio_hwsync_t;
30static inline bool hwsync_header_valid(uint8_t *header)
31{
32 return (header[0] == 0x55) &&
33 (header[1] == 0x55) &&
34 (header[2] == 0x00) &&
35 (header[3] == 0x01);
36}
37
38static inline uint64_t hwsync_header_get_pts(uint8_t *header)
39{
40 return (((uint64_t)header[8]) << 56) |
41 (((uint64_t)header[9]) << 48) |
42 (((uint64_t)header[10]) << 40) |
43 (((uint64_t)header[11]) << 32) |
44 (((uint64_t)header[12]) << 24) |
45 (((uint64_t)header[13]) << 16) |
46 (((uint64_t)header[14]) << 8) |
47 ((uint64_t)header[15]);
48}
49
50static inline uint32_t hwsync_header_get_size(uint8_t *header)
51{
52 return (((uint32_t)header[4]) << 24) |
53 (((uint32_t)header[5]) << 16) |
54 (((uint32_t)header[6]) << 8) |
55 ((uint32_t)header[7]);
56}
57
58static inline uint64_t pts_abs(uint64_t a, uint64_t b)
59{
60 if (a >= b)
61 return (a - b);
62 else
63 return (b - a);
64}
65
66struct aml_stream_out;
67
68void aml_audio_hwsync_clear_status(struct aml_stream_out *out);
69int aml_audio_hwsync_find_frame(struct aml_stream_out *out,
70 const void *in_buffer, size_t in_bytes, uint64_t *cur_pts, int *outsize);
71#endif
72