blob: f7e62efb0f018b707128499e39d0801e89e59363
1 | /* |
2 | * drivers/amlogic/media/frame_provider/decoder/utils/vdec_input.h |
3 | * |
4 | * Copyright (C) 2016 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 VDEC_INPUT_H |
19 | #define VDEC_INPUT_H |
20 | |
21 | struct vdec_s; |
22 | struct vdec_input_s; |
23 | |
24 | struct vframe_block_list_s { |
25 | u32 magic; |
26 | int id; |
27 | struct list_head list; |
28 | ulong start; |
29 | void *start_virt; |
30 | ulong addr; |
31 | bool is_mapped; |
32 | int type; |
33 | u32 size; |
34 | u32 wp; |
35 | u32 rp; |
36 | int data_size; |
37 | int chunk_count; |
38 | int is_out_buf; |
39 | u32 handle; |
40 | struct vdec_input_s *input; |
41 | }; |
42 | |
43 | #define VFRAME_CHUNK_FLAG_CONSUMED 0x0001 |
44 | |
45 | struct vframe_chunk_s { |
46 | u32 magic; |
47 | struct list_head list; |
48 | int flag; |
49 | u32 offset; |
50 | u32 size; |
51 | u32 pts; |
52 | u32 pading_size; |
53 | u64 pts64; |
54 | bool pts_valid; |
55 | u64 timestamp; |
56 | bool timestamp_valid; |
57 | u64 sequence; |
58 | struct vframe_block_list_s *block; |
59 | u32 hdr10p_data_size; |
60 | char *hdr10p_data_buf; |
61 | }; |
62 | |
63 | #define VDEC_INPUT_TARGET_VLD 0 |
64 | #define VDEC_INPUT_TARGET_HEVC 1 |
65 | #define VLD_PADDING_SIZE 1024 |
66 | #define HEVC_PADDING_SIZE (1024*16) |
67 | |
68 | struct vdec_input_s { |
69 | struct list_head vframe_block_list; |
70 | struct list_head vframe_chunk_list; |
71 | struct list_head vframe_block_free_list; |
72 | struct vframe_block_list_s *wr_block; |
73 | int have_free_blocks; |
74 | int no_mem_err_cnt;/*when alloc no mem cnt++*/ |
75 | int block_nums; |
76 | int block_id_seq; |
77 | int id; |
78 | spinlock_t lock; |
79 | int type; |
80 | int target; |
81 | struct vdec_s *vdec; |
82 | bool swap_valid; |
83 | bool swap_needed; |
84 | bool eos; |
85 | void *swap_page; |
86 | dma_addr_t swap_page_phys; |
87 | u64 total_wr_count; |
88 | u64 total_rd_count; |
89 | u64 streaming_rp; |
90 | u32 swap_rp; |
91 | bool last_swap_slave; |
92 | int dirty_count; |
93 | u64 sequence; |
94 | unsigned start; |
95 | unsigned size; |
96 | int default_block_size; |
97 | int data_size; |
98 | int frame_max_size; |
99 | int prepare_level; |
100 | /*for check frame delay.*/ |
101 | u64 last_inpts_u64; |
102 | u64 last_comsumed_pts_u64; |
103 | int last_in_nopts_cnt; |
104 | int last_comsumed_no_pts_cnt; |
105 | int last_duration; |
106 | /*for check frame delay.*/ |
107 | int have_frame_num; |
108 | int stream_cookie; /* wrap count for vld_mem and |
109 | HEVC_SHIFT_BYTE_COUNT for hevc */ |
110 | bool (*vdec_is_input_frame_empty)(struct vdec_s *); |
111 | void (*vdec_up)(struct vdec_s *); |
112 | }; |
113 | |
114 | struct vdec_input_status_s { |
115 | int size; |
116 | int data_len; |
117 | int free_len; |
118 | int read_pointer; |
119 | }; |
120 | |
121 | #define input_frame_based(input) \ |
122 | (((input)->type == VDEC_TYPE_FRAME_BLOCK) || \ |
123 | ((input)->type == VDEC_TYPE_FRAME_CIRCULAR)) |
124 | #define input_stream_based(input) \ |
125 | (((input)->type == VDEC_TYPE_STREAM_PARSER) || \ |
126 | ((input)->type == VDEC_TYPE_SINGLE)) |
127 | |
128 | /* Initialize vdec_input structure */ |
129 | extern void vdec_input_init(struct vdec_input_s *input, struct vdec_s *vdec); |
130 | extern int vdec_input_prepare_bufs(struct vdec_input_s *input, |
131 | int frame_width, int frame_height); |
132 | |
133 | /* Get available input data size */ |
134 | extern int vdec_input_level(struct vdec_input_s *input); |
135 | |
136 | /* Set input type and target */ |
137 | extern void vdec_input_set_type(struct vdec_input_s *input, int type, |
138 | int target); |
139 | |
140 | /* Set stream buffer information for stream based input */ |
141 | extern int vdec_input_set_buffer(struct vdec_input_s *input, u32 start, |
142 | u32 size); |
143 | |
144 | /* Add enqueue video data into decoder's input */ |
145 | extern int vdec_input_add_frame(struct vdec_input_s *input, const char *buf, |
146 | size_t count); |
147 | |
148 | extern int vdec_input_add_frame_with_dma(struct vdec_input_s *input, ulong addr, |
149 | size_t count, u32 handle); |
150 | |
151 | /* Peek next frame data from decoder's input */ |
152 | extern struct vframe_chunk_s *vdec_input_next_chunk( |
153 | struct vdec_input_s *input); |
154 | |
155 | /* Peek next frame data from decoder's input, not marked as consumed */ |
156 | extern struct vframe_chunk_s *vdec_input_next_input_chunk( |
157 | struct vdec_input_s *input); |
158 | |
159 | /* Consume next frame data from decoder's input */ |
160 | extern void vdec_input_release_chunk(struct vdec_input_s *input, |
161 | struct vframe_chunk_s *chunk); |
162 | |
163 | /* Get decoder input buffer status */ |
164 | extern int vdec_input_get_status(struct vdec_input_s *input, |
165 | struct vdec_input_status_s *status); |
166 | |
167 | extern unsigned long vdec_input_lock(struct vdec_input_s *input); |
168 | |
169 | extern void vdec_input_unlock(struct vdec_input_s *input, unsigned long lock); |
170 | |
171 | /* release all resource for decoder's input */ |
172 | extern void vdec_input_release(struct vdec_input_s *input); |
173 | /* return block handle and free block */ |
174 | extern u32 vdec_input_get_freed_handle(struct vdec_s *vdec); |
175 | int vdec_input_dump_chunks(int id, struct vdec_input_s *input, |
176 | char *bufs, int size); |
177 | int vdec_input_dump_blocks(struct vdec_input_s *input, |
178 | char *bufs, int size); |
179 | |
180 | int vdec_input_get_duration_u64(struct vdec_input_s *input); |
181 | |
182 | #endif /* VDEC_INPUT_H */ |
183 |