xref: /OK3568_Linux_fs/external/gstreamer-rockchip/gst/rockchipmpp/gstmppdec.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright 2021 Rockchip Electronics Co., Ltd
3*4882a593Smuzhiyun  *     Author: Jeffy Chen <jeffy.chen@rock-chips.com>
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * This library is free software; you can redistribute it and/or
6*4882a593Smuzhiyun  * modify it under the terms of the GNU Library General Public
7*4882a593Smuzhiyun  * License as published by the Free Software Foundation; either
8*4882a593Smuzhiyun  * version 2 of the License, or (at your option) any later version.
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * This library is distributed in the hope that it will be useful,
11*4882a593Smuzhiyun  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*4882a593Smuzhiyun  * Library General Public License for more details.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * You should have received a copy of the GNU Library General Public
16*4882a593Smuzhiyun  * License along with this library; if not, write to the
17*4882a593Smuzhiyun  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18*4882a593Smuzhiyun  * Boston, MA 02110-1301, USA.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  */
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #ifndef  __GST_MPP_DEC_H__
23*4882a593Smuzhiyun #define  __GST_MPP_DEC_H__
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #include <gst/video/gstvideodecoder.h>
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #include "gstmpp.h"
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun G_BEGIN_DECLS;
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #define GST_TYPE_MPP_DEC	(gst_mpp_dec_get_type())
32*4882a593Smuzhiyun #define GST_MPP_DEC(obj) \
33*4882a593Smuzhiyun 	(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MPP_DEC, GstMppDec))
34*4882a593Smuzhiyun #define GST_MPP_DEC_CLASS(klass) \
35*4882a593Smuzhiyun 	(G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_MPP_DEC, GstMppDecClass))
36*4882a593Smuzhiyun typedef struct _GstMppDec GstMppDec;
37*4882a593Smuzhiyun typedef struct _GstMppDecClass GstMppDecClass;
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun struct _GstMppDec
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun   GstVideoDecoder parent;
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun   GMutex mutex;
44*4882a593Smuzhiyun   GstAllocator *allocator;
45*4882a593Smuzhiyun   GstVideoCodecState *input_state;
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun   /* final output video info */
48*4882a593Smuzhiyun   GstVideoInfo info;
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun   /* specified output format */
51*4882a593Smuzhiyun   GstVideoFormat format;
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun   gboolean convert;
54*4882a593Smuzhiyun   gint rotation;
55*4882a593Smuzhiyun   gint width;
56*4882a593Smuzhiyun   gint height;
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun   guint crop_x, crop_y, crop_w, crop_h;
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun   gboolean arm_afbc;
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun   gboolean dma_feature;
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun   gboolean ignore_error;
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun   gboolean fast_mode;
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun   /* stop handling new frame when flushing */
69*4882a593Smuzhiyun   gboolean flushing;
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun   /* drop frames when flushing but not draining */
72*4882a593Smuzhiyun   gboolean draining;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun   /* flow return from pad task */
75*4882a593Smuzhiyun   GstFlowReturn task_ret;
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun   GstVideoInterlaceMode interlace_mode;
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun   /* seen valid PTS in input frames */
80*4882a593Smuzhiyun   gboolean seen_valid_pts;
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun   /* for using MPP generated PTS */
83*4882a593Smuzhiyun   gboolean use_mpp_pts;
84*4882a593Smuzhiyun   GstClockTime mpp_delta_pts;
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun   guint32 decoded_frames;
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun   MppCodingType mpp_type;
89*4882a593Smuzhiyun   MppCtx mpp_ctx;
90*4882a593Smuzhiyun   MppApi *mpi;
91*4882a593Smuzhiyun };
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun struct _GstMppDecClass
94*4882a593Smuzhiyun {
95*4882a593Smuzhiyun   GstVideoDecoderClass parent_class;
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun     gboolean (*startup) (GstVideoDecoder * decoder);
98*4882a593Smuzhiyun     MppPacket (*get_mpp_packet) (GstVideoDecoder * decoder,
99*4882a593Smuzhiyun       GstMapInfo * mapinfo);
100*4882a593Smuzhiyun     gboolean (*send_mpp_packet) (GstVideoDecoder * decoder,
101*4882a593Smuzhiyun       MppPacket mpkt, gint timeout_ms);
102*4882a593Smuzhiyun     MppFrame (*poll_mpp_frame) (GstVideoDecoder * decoder, gint timeout_ms);
103*4882a593Smuzhiyun     gboolean (*shutdown) (GstVideoDecoder * decoder, gboolean drain);
104*4882a593Smuzhiyun };
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun G_DEFINE_AUTOPTR_CLEANUP_FUNC (GstMppDec, gst_object_unref);
107*4882a593Smuzhiyun GType gst_mpp_dec_get_type (void);
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun #define GST_FLOW_TIMEOUT GST_FLOW_CUSTOM_ERROR_1
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun #define MPP_DEC_OUT_FORMATS "NV12, NV16, NV12_10LE40, NV16_10LE40"
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun #ifdef HAVE_RGA
114*4882a593Smuzhiyun #define MPP_DEC_FORMATS MPP_DEC_OUT_FORMATS "," GST_RGA_FORMATS
115*4882a593Smuzhiyun #else
116*4882a593Smuzhiyun #define MPP_DEC_FORMATS MPP_DEC_OUT_FORMATS
117*4882a593Smuzhiyun #endif
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun #define MPP_DEC_FEATURE_ARM_AFBC "arm-afbc"
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun #define MPP_DEC_CAPS_MAKE(fmts) \
122*4882a593Smuzhiyun     GST_VIDEO_CAPS_MAKE (fmts) ";" \
123*4882a593Smuzhiyun     GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF, fmts)
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun #define MPP_DEC_CAPS_MAKE_AFBC(fmts) \
126*4882a593Smuzhiyun     GST_VIDEO_CAPS_MAKE (fmts) ", " MPP_DEC_FEATURE_ARM_AFBC " = (int) 1;" \
127*4882a593Smuzhiyun     GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF, fmts) \
128*4882a593Smuzhiyun     ", " MPP_DEC_FEATURE_ARM_AFBC " = (int) 1"
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun void gst_mpp_dec_fixup_video_info (GstVideoDecoder * decoder,
131*4882a593Smuzhiyun     GstVideoFormat format, gint width, gint height);
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun gboolean gst_mpp_dec_update_simple_video_info (GstVideoDecoder * decoder,
134*4882a593Smuzhiyun     GstVideoFormat format, guint width, guint height, guint align);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun G_END_DECLS;
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun #endif /* __GST_MPP_DEC_H__ */
139