blob: f6a9db034727c65cd319ab393acfb75085937b43
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 AML_V4L2_SET_DECMODE (V4L2_CID_USER_AMLOGIC_BASE + 0) |
38 | |
39 | /** |
40 | * struct vdec_fb - decoder frame buffer |
41 | * @base_y : Y plane memory info |
42 | * @base_c : C plane memory info |
43 | * @status : frame buffer status (vdec_fb_status) |
44 | */ |
45 | struct vdec_fb { |
46 | unsigned long vf_handle; |
47 | struct aml_vcodec_mem base_y; |
48 | struct aml_vcodec_mem base_c; |
49 | unsigned int status; |
50 | }; |
51 | |
52 | /** |
53 | * struct aml_video_dec_buf - Private data related to each VB2 buffer. |
54 | * @b: VB2 buffer |
55 | * @list: link list |
56 | * @used: Capture buffer contain decoded frame data and keep in |
57 | * codec data structure |
58 | * @ready_to_display: Capture buffer not display yet |
59 | * @queued_in_vb2: Capture buffer is queue in vb2 |
60 | * @queued_in_v4l2: Capture buffer is in v4l2 driver, but not in vb2 |
61 | * queue yet |
62 | * @lastframe: Intput buffer is last buffer - EOS |
63 | * @error: An unrecoverable error occurs on this buffer. |
64 | * @frame_buffer: Decode status, and buffer information of Capture buffer |
65 | * |
66 | * Note : These status information help us track and debug buffer state |
67 | */ |
68 | struct aml_video_dec_buf { |
69 | struct vb2_v4l2_buffer vb; |
70 | struct list_head list; |
71 | |
72 | struct vdec_fb frame_buffer; |
73 | struct codec_mm_s *mem[2]; |
74 | char mem_onwer[32]; |
75 | struct list_head node; |
76 | bool used; |
77 | bool ready_to_display; |
78 | bool que_in_m2m; |
79 | bool queued_in_vb2; |
80 | bool queued_in_v4l2; |
81 | bool lastframe; |
82 | bool error; |
83 | }; |
84 | |
85 | extern const struct v4l2_ioctl_ops aml_vdec_ioctl_ops; |
86 | extern const struct v4l2_m2m_ops aml_vdec_m2m_ops; |
87 | |
88 | |
89 | /* |
90 | * aml_vdec_lock/aml_vdec_unlock are for ctx instance to |
91 | * get/release lock before/after access decoder hw. |
92 | * aml_vdec_lock get decoder hw lock and set curr_ctx |
93 | * to ctx instance that get lock |
94 | */ |
95 | void aml_vdec_unlock(struct aml_vcodec_ctx *ctx); |
96 | void aml_vdec_lock(struct aml_vcodec_ctx *ctx); |
97 | int aml_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq, |
98 | struct vb2_queue *dst_vq); |
99 | void aml_vcodec_dec_set_default_params(struct aml_vcodec_ctx *ctx); |
100 | void aml_vcodec_dec_release(struct aml_vcodec_ctx *ctx); |
101 | int aml_vcodec_dec_ctrls_setup(struct aml_vcodec_ctx *ctx); |
102 | |
103 | void vdec_device_vf_run(struct aml_vcodec_ctx *ctx); |
104 | |
105 | void try_to_capture(struct aml_vcodec_ctx *ctx); |
106 | void aml_thread_notify(struct aml_vcodec_ctx *ctx, |
107 | enum aml_thread_type type); |
108 | int aml_thread_start(struct aml_vcodec_ctx *ctx, aml_thread_func func, |
109 | enum aml_thread_type type, const char *thread_name); |
110 | void aml_thread_stop(struct aml_vcodec_ctx *ctx); |
111 | |
112 | #endif /* _AML_VCODEC_DEC_H_ */ |
113 |