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 _VDEC_DRV_IF_H_ 21 #define _VDEC_DRV_IF_H_ 22 23 #include "aml_vcodec_drv.h" 24 #include "aml_vcodec_dec.h" 25 #include "aml_vcodec_util.h" 26 #include "../stream_input/amports/streambuf.h" 27 28 #define AML_VIDEO_MAGIC CODEC_MODE('A', 'M', 'L', 'V') 29 30 #define V4L_STREAM_TYPE_MATEDATA (0) 31 #define V4L_STREAM_TYPE_FRAME (1) 32 33 struct stream_info { 34 u32 stream_width; 35 u32 stream_height; 36 u32 stream_field; 37 u32 stream_dpb; 38 }; 39 40 struct aml_video_stream { 41 u32 magic; 42 u32 type; 43 union { 44 struct stream_info s; 45 u8 buf[64]; 46 } m; 47 u32 len; 48 u8 data[0]; 49 }; 50 51 /** 52 * struct vdec_fb_status - decoder frame buffer status 53 * @FB_ST_NORMAL : initial state 54 * @FB_ST_DISPLAY : frmae buffer is ready to be displayed 55 * @FB_ST_FREE : frame buffer is not used by decoder any more 56 */ 57 enum vdec_fb_status { 58 FB_ST_NORMAL, 59 FB_ST_DISPLAY, 60 FB_ST_FREE 61 }; 62 63 /* For GET_PARAM_DISP_FRAME_BUFFER and GET_PARAM_FREE_FRAME_BUFFER, 64 * the caller does not own the returned buffer. The buffer will not be 65 * released before vdec_if_deinit. 66 * GET_PARAM_DISP_FRAME_BUFFER : get next displayable frame buffer, 67 * struct vdec_fb** 68 * GET_PARAM_FREE_FRAME_BUFFER : get non-referenced framebuffer, vdec_fb** 69 * GET_PARAM_PIC_INFO : get picture info, struct vdec_pic_info* 70 * GET_PARAM_CROP_INFO : get crop info, struct v4l2_crop* 71 * GET_PARAM_DPB_SIZE : get dpb size, unsigned int* 72 */ 73 enum vdec_get_param_type { 74 GET_PARAM_DISP_FRAME_BUFFER, 75 GET_PARAM_FREE_FRAME_BUFFER, 76 GET_PARAM_PIC_INFO, 77 GET_PARAM_CROP_INFO, 78 GET_PARAM_DPB_SIZE, 79 GET_PARAM_CONFIG_INFO 80 }; 81 82 /* 83 * SET_PARAM_PS_INFO : set picture parms, data parsed from ucode. 84 */ 85 enum vdec_set_param_type { 86 SET_PARAM_WRITE_FRAME_SYNC, 87 SET_PARAM_PS_INFO, 88 SET_PARAM_HDR_INFO, 89 SET_PARAM_POST_EVENT 90 }; 91 92 /** 93 * struct vdec_fb_node - decoder frame buffer node 94 * @list : list to hold this node 95 * @fb : point to frame buffer (vdec_fb), fb could point to frame buffer and 96 * working buffer this is for maintain buffers in different state 97 */ 98 struct vdec_fb_node { 99 struct list_head list; 100 struct vdec_fb *fb; 101 }; 102 103 /** 104 * vdec_if_init() - initialize decode driver 105 * @ctx : [in] v4l2 context 106 * @fourcc : [in] video format fourcc, V4L2_PIX_FMT_H264/VP8/VP9.. 107 */ 108 int vdec_if_init(struct aml_vcodec_ctx *ctx, unsigned int fourcc); 109 110 int vdec_if_probe(struct aml_vcodec_ctx *ctx, 111 struct aml_vcodec_mem *bs, void *out); 112 113 /** 114 * vdec_if_deinit() - deinitialize decode driver 115 * @ctx : [in] v4l2 context 116 * 117 */ 118 void vdec_if_deinit(struct aml_vcodec_ctx *ctx); 119 120 /** 121 * vdec_if_decode() - trigger decode 122 * @ctx : [in] v4l2 context 123 * @bs : [in] input bitstream 124 * @fb : [in] frame buffer to store decoded frame, when null menas parse 125 * header only 126 * @res_chg : [out] resolution change happens if current bs have different 127 * picture width/height 128 * Note: To flush the decoder when reaching EOF, set input bitstream as NULL. 129 * 130 * Return: 0 on success. -EIO on unrecoverable error. 131 */ 132 int vdec_if_decode(struct aml_vcodec_ctx *ctx, struct aml_vcodec_mem *bs, 133 u64 timestamp, bool *res_chg); 134 135 /** 136 * vdec_if_get_param() - get driver's parameter 137 * @ctx : [in] v4l2 context 138 * @type : [in] input parameter type 139 * @out : [out] buffer to store query result 140 */ 141 int vdec_if_get_param(struct aml_vcodec_ctx *ctx, enum vdec_get_param_type type, 142 void *out); 143 144 #endif 145