summaryrefslogtreecommitdiff
path: root/drivers/amvdec_ports/aml_vcodec_dec.h (plain)
blob: 3406e9fe913848ca497f19341c77a39272e33993
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 <linux/amlogic/media/video_sink/v4lvideo_ext.h>
27#include "aml_vcodec_util.h"
28
29#define VCODEC_CAPABILITY_4K_DISABLED 0x10
30#define VCODEC_DEC_4K_CODED_WIDTH 4096U
31#define VCODEC_DEC_4K_CODED_HEIGHT 2304U
32#define AML_VDEC_MAX_W 2048U
33#define AML_VDEC_MAX_H 1088U
34
35#define AML_VDEC_IRQ_STATUS_DEC_SUCCESS 0x10000
36#define V4L2_BUF_FLAG_LAST 0x00100000
37
38#define VDEC_GATHER_MEMORY_TYPE 0
39#define VDEC_SCATTER_MEMORY_TYPE 1
40
41/**
42 * struct vdec_fb - decoder frame buffer
43 * @mem_type : gather or scatter memory.
44 * @num_planes : used number of the plane
45 * @mem[4] : array mem for used planes,
46 * mem[0]: Y, mem[1]: C/U, mem[2]: V
47 * @vf_fd : the file handle of video frame
48 * @vf_handle : video frame handle
49 * @status : frame buffer status (vdec_fb_status)
50 */
51
52struct vdec_v4l2_buffer {
53 int mem_type;
54 int num_planes;
55 union {
56 struct aml_vcodec_mem mem[4];
57 u32 vf_fd;
58 } m;
59 ulong vf_handle;
60 u32 status;
61};
62
63
64/**
65 * struct aml_video_dec_buf - Private data related to each VB2 buffer.
66 * @b: VB2 buffer
67 * @list: link list
68 * @used: Capture buffer contain decoded frame data and keep in
69 * codec data structure
70 * @ready_to_display: Capture buffer not display yet
71 * @queued_in_vb2: Capture buffer is queue in vb2
72 * @queued_in_v4l2: Capture buffer is in v4l2 driver, but not in vb2
73 * queue yet
74 * @lastframe: Intput buffer is last buffer - EOS
75 * @error: An unrecoverable error occurs on this buffer.
76 * @frame_buffer: Decode status, and buffer information of Capture buffer
77 *
78 * Note : These status information help us track and debug buffer state
79 */
80struct aml_video_dec_buf {
81 struct vb2_v4l2_buffer vb;
82 struct list_head list;
83
84 struct vdec_v4l2_buffer frame_buffer;
85 struct file_private_data privdata;
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
97extern const struct v4l2_ioctl_ops aml_vdec_ioctl_ops;
98extern const struct v4l2_m2m_ops aml_vdec_m2m_ops;
99
100/*
101 * aml_vdec_lock/aml_vdec_unlock are for ctx instance to
102 * get/release lock before/after access decoder hw.
103 * aml_vdec_lock get decoder hw lock and set curr_ctx
104 * to ctx instance that get lock
105 */
106void aml_vdec_unlock(struct aml_vcodec_ctx *ctx);
107void aml_vdec_lock(struct aml_vcodec_ctx *ctx);
108int aml_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq,
109 struct vb2_queue *dst_vq);
110void aml_vcodec_dec_set_default_params(struct aml_vcodec_ctx *ctx);
111void aml_vcodec_dec_release(struct aml_vcodec_ctx *ctx);
112int aml_vcodec_dec_ctrls_setup(struct aml_vcodec_ctx *ctx);
113void vdec_device_vf_run(struct aml_vcodec_ctx *ctx);
114void try_to_capture(struct aml_vcodec_ctx *ctx);
115void aml_thread_notify(struct aml_vcodec_ctx *ctx,
116 enum aml_thread_type type);
117int aml_thread_start(struct aml_vcodec_ctx *ctx, aml_thread_func func,
118 enum aml_thread_type type, const char *thread_name);
119void aml_thread_stop(struct aml_vcodec_ctx *ctx);
120void wait_vcodec_ending(struct aml_vcodec_ctx *ctx);
121void vdec_frame_buffer_release(void *data);
122void aml_vdec_dispatch_event(struct aml_vcodec_ctx *ctx, u32 changes);
123void* v4l_get_vf_handle(int fd);
124
125#endif /* _AML_VCODEC_DEC_H_ */
126