blob: 19923c0c659bdf6c782e35e51aecf8d42b1f6df9
1 | /* |
2 | * Copyright (C) 2017 Amlogic, Inc. All rights reserved. |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
12 | * more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 | * |
18 | * Description: |
19 | */ |
20 | #ifndef _AML_VCODEC_DEC_H_ |
21 | #define _AML_VCODEC_DEC_H_ |
22 | |
23 | #include <media/videobuf2-core.h> |
24 | #include <media/videobuf2-v4l2.h> |
25 | #include <linux/amlogic/media/codec_mm/codec_mm.h> |
26 | #include "aml_vcodec_util.h" |
27 | |
28 | #define VCODEC_CAPABILITY_4K_DISABLED 0x10 |
29 | #define VCODEC_DEC_4K_CODED_WIDTH 4096U |
30 | #define VCODEC_DEC_4K_CODED_HEIGHT 2304U |
31 | #define AML_VDEC_MAX_W 2048U |
32 | #define AML_VDEC_MAX_H 1088U |
33 | |
34 | #define AML_VDEC_IRQ_STATUS_DEC_SUCCESS 0x10000 |
35 | #define V4L2_BUF_FLAG_LAST 0x00100000 |
36 | |
37 | #define VDEC_GATHER_MEMORY_TYPE 0 |
38 | #define VDEC_SCATTER_MEMORY_TYPE 1 |
39 | |
40 | #define AML_V4L2_SET_DECMODE (V4L2_CID_USER_AMLOGIC_BASE + 0) |
41 | |
42 | /** |
43 | * struct vdec_fb - decoder frame buffer |
44 | * @mem_type : gather or scatter memory. |
45 | * @num_planes : used number of the plane |
46 | * @mem[4] : array mem for used planes, |
47 | * mem[0]: Y, mem[1]: C/U, mem[2]: V |
48 | * @vf_fd : the file handle of video frame |
49 | * @vf_handle : video frame handle |
50 | * @status : frame buffer status (vdec_fb_status) |
51 | */ |
52 | |
53 | struct vdec_v4l2_buffer { |
54 | int mem_type; |
55 | int num_planes; |
56 | union { |
57 | struct aml_vcodec_mem mem[4]; |
58 | u32 vf_fd; |
59 | } m; |
60 | ulong vf_handle; |
61 | u32 status; |
62 | }; |
63 | |
64 | |
65 | /** |
66 | * struct aml_video_dec_buf - Private data related to each VB2 buffer. |
67 | * @b: VB2 buffer |
68 | * @list: link list |
69 | * @used: Capture buffer contain decoded frame data and keep in |
70 | * codec data structure |
71 | * @ready_to_display: Capture buffer not display yet |
72 | * @queued_in_vb2: Capture buffer is queue in vb2 |
73 | * @queued_in_v4l2: Capture buffer is in v4l2 driver, but not in vb2 |
74 | * queue yet |
75 | * @lastframe: Intput buffer is last buffer - EOS |
76 | * @error: An unrecoverable error occurs on this buffer. |
77 | * @frame_buffer: Decode status, and buffer information of Capture buffer |
78 | * |
79 | * Note : These status information help us track and debug buffer state |
80 | */ |
81 | struct aml_video_dec_buf { |
82 | struct vb2_v4l2_buffer vb; |
83 | struct list_head list; |
84 | |
85 | struct vdec_v4l2_buffer frame_buffer; |
86 | struct codec_mm_s *mem[2]; |
87 | char mem_onwer[32]; |
88 | bool used; |
89 | bool ready_to_display; |
90 | bool que_in_m2m; |
91 | bool queued_in_vb2; |
92 | bool queued_in_v4l2; |
93 | bool lastframe; |
94 | bool error; |
95 | }; |
96 | |
97 | struct aml_vdec_pic_infos { |
98 | u32 visible_width; |
99 | u32 visible_height; |
100 | u32 coded_width; |
101 | u32 coded_height; |
102 | int dpb_size; |
103 | }; |
104 | |
105 | extern const struct v4l2_ioctl_ops aml_vdec_ioctl_ops; |
106 | extern const struct v4l2_m2m_ops aml_vdec_m2m_ops; |
107 | |
108 | |
109 | /* |
110 | * aml_vdec_lock/aml_vdec_unlock are for ctx instance to |
111 | * get/release lock before/after access decoder hw. |
112 | * aml_vdec_lock get decoder hw lock and set curr_ctx |
113 | * to ctx instance that get lock |
114 | */ |
115 | void aml_vdec_unlock(struct aml_vcodec_ctx *ctx); |
116 | void aml_vdec_lock(struct aml_vcodec_ctx *ctx); |
117 | int aml_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq, |
118 | struct vb2_queue *dst_vq); |
119 | void aml_vcodec_dec_set_default_params(struct aml_vcodec_ctx *ctx); |
120 | void aml_vcodec_dec_release(struct aml_vcodec_ctx *ctx); |
121 | int aml_vcodec_dec_ctrls_setup(struct aml_vcodec_ctx *ctx); |
122 | |
123 | void vdec_device_vf_run(struct aml_vcodec_ctx *ctx); |
124 | |
125 | void try_to_capture(struct aml_vcodec_ctx *ctx); |
126 | void aml_thread_notify(struct aml_vcodec_ctx *ctx, |
127 | enum aml_thread_type type); |
128 | int aml_thread_start(struct aml_vcodec_ctx *ctx, aml_thread_func func, |
129 | enum aml_thread_type type, const char *thread_name); |
130 | void aml_thread_stop(struct aml_vcodec_ctx *ctx); |
131 | void wait_vcodec_ending(struct aml_vcodec_ctx *ctx); |
132 | |
133 | #endif /* _AML_VCODEC_DEC_H_ */ |
134 |