1 /* 2 * Copyright 2021 Rockchip Electronics Co., Ltd 3 * Author: Jeffy Chen <jeffy.chen@rock-chips.com> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, write to the 17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 * 20 */ 21 22 #ifndef __GST_MPP_H__ 23 #define __GST_MPP_H__ 24 25 #include <gst/video/video.h> 26 #include <gst/allocators/gstdmabuf.h> 27 28 #ifdef HAVE_RGA 29 #include <rga/rga.h> 30 #include <rga/RgaApi.h> 31 #endif 32 33 #include <rockchip/rk_mpi.h> 34 35 G_BEGIN_DECLS; 36 37 #ifndef ARRAY_SIZE 38 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) 39 #endif 40 41 #ifndef SWAP 42 #define SWAP(x, y) ({ x ^= y; y ^= x; x ^= y; }) 43 #endif 44 45 #define MPP_FMT_LE(f) (f | MPP_FRAME_FMT_LE_MASK) 46 #define MPP_FMT_RGB565LE MPP_FMT_LE(MPP_FMT_RGB565) 47 #define MPP_FMT_BGR565LE MPP_FMT_LE(MPP_FMT_BGR565) 48 49 #define GST_MPP_VIDEO_INFO_HSTRIDE(i) GST_VIDEO_INFO_PLANE_STRIDE(i, 0) 50 #define GST_MPP_VIDEO_INFO_VSTRIDE(i) \ 51 (GST_VIDEO_INFO_N_PLANES(i) == 1 ? GST_VIDEO_INFO_HEIGHT(i) : \ 52 (gint) (GST_VIDEO_INFO_PLANE_OFFSET(i, 1) / GST_MPP_VIDEO_INFO_HSTRIDE(i))) 53 54 #ifndef GST_VIDEO_FLAG_ARM_AFBC 55 #define GST_VIDEO_FLAG_ARM_AFBC (1UL << 31) 56 #define GST_VIDEO_INFO_SET_AFBC(i) \ 57 GST_VIDEO_INFO_FLAG_SET (i, GST_VIDEO_FLAG_ARM_AFBC) 58 #define GST_VIDEO_INFO_UNSET_AFBC(i) \ 59 GST_VIDEO_INFO_FLAG_UNSET (i, GST_VIDEO_FLAG_ARM_AFBC) 60 #define GST_VIDEO_INFO_IS_AFBC(i) \ 61 GST_VIDEO_INFO_FLAG_IS_SET (i, GST_VIDEO_FLAG_ARM_AFBC) 62 #endif 63 64 /* The MPP requires alignment 16 by default */ 65 #define GST_MPP_ALIGNMENT 16 66 #define GST_MPP_ALIGN(v) GST_ROUND_UP_N (v, GST_MPP_ALIGNMENT) 67 68 #ifdef HAVE_RGA 69 #define GST_RGA_FORMATS \ 70 "NV12, NV21, I420, YV12, NV16, NV61, " \ 71 "BGR16, RGB, BGR, RGBA, BGRA, RGBx, BGRx" 72 #endif 73 74 gboolean gst_mpp_use_rga (); 75 76 const gchar *gst_mpp_video_format_to_string (GstVideoFormat format); 77 78 GstVideoFormat gst_mpp_mpp_format_to_gst_format (MppFrameFormat mpp_format); 79 80 MppFrameFormat gst_mpp_gst_format_to_mpp_format (GstVideoFormat format); 81 82 #ifdef HAVE_RGA 83 gboolean gst_mpp_rga_convert (GstBuffer * inbuf, GstVideoInfo * src_vinfo, 84 GstMemory * out_mem, GstVideoInfo * dst_vinfo, gint rotation); 85 86 gboolean gst_mpp_rga_convert_from_mpp_frame (MppFrame * mframe, 87 GstMemory * out_mem, GstVideoInfo * dst_vinfo, gint rotation); 88 #endif 89 90 /* Apply new format and size without reinit the video info */ 91 void 92 gst_mpp_video_info_update_format (GstVideoInfo * info, GstVideoFormat format, 93 guint width, guint height); 94 95 gboolean gst_mpp_video_info_align (GstVideoInfo * info, 96 gint hstride, gint vstride); 97 98 guint gst_mpp_get_pixel_stride (GstVideoInfo * info); 99 100 G_END_DECLS; 101 102 #endif /* __GST_MPP_H__ */ 103