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_DEC_H__ 23 #define __GST_MPP_DEC_H__ 24 25 #include <gst/video/gstvideodecoder.h> 26 27 #include "gstmpp.h" 28 29 G_BEGIN_DECLS; 30 31 #define GST_TYPE_MPP_DEC (gst_mpp_dec_get_type()) 32 #define GST_MPP_DEC(obj) \ 33 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MPP_DEC, GstMppDec)) 34 #define GST_MPP_DEC_CLASS(klass) \ 35 (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_MPP_DEC, GstMppDecClass)) 36 typedef struct _GstMppDec GstMppDec; 37 typedef struct _GstMppDecClass GstMppDecClass; 38 39 struct _GstMppDec 40 { 41 GstVideoDecoder parent; 42 43 GMutex mutex; 44 GstAllocator *allocator; 45 GstVideoCodecState *input_state; 46 47 /* final output video info */ 48 GstVideoInfo info; 49 50 /* specified output format */ 51 GstVideoFormat format; 52 53 gboolean convert; 54 gint rotation; 55 gint width; 56 gint height; 57 58 guint crop_x, crop_y, crop_w, crop_h; 59 60 gboolean arm_afbc; 61 62 gboolean dma_feature; 63 64 gboolean ignore_error; 65 66 gboolean fast_mode; 67 68 /* stop handling new frame when flushing */ 69 gboolean flushing; 70 71 /* drop frames when flushing but not draining */ 72 gboolean draining; 73 74 /* flow return from pad task */ 75 GstFlowReturn task_ret; 76 77 GstVideoInterlaceMode interlace_mode; 78 79 /* seen valid PTS in input frames */ 80 gboolean seen_valid_pts; 81 82 /* for using MPP generated PTS */ 83 gboolean use_mpp_pts; 84 GstClockTime mpp_delta_pts; 85 86 guint32 decoded_frames; 87 88 MppCodingType mpp_type; 89 MppCtx mpp_ctx; 90 MppApi *mpi; 91 }; 92 93 struct _GstMppDecClass 94 { 95 GstVideoDecoderClass parent_class; 96 97 gboolean (*startup) (GstVideoDecoder * decoder); 98 MppPacket (*get_mpp_packet) (GstVideoDecoder * decoder, 99 GstMapInfo * mapinfo); 100 gboolean (*send_mpp_packet) (GstVideoDecoder * decoder, 101 MppPacket mpkt, gint timeout_ms); 102 MppFrame (*poll_mpp_frame) (GstVideoDecoder * decoder, gint timeout_ms); 103 gboolean (*shutdown) (GstVideoDecoder * decoder, gboolean drain); 104 }; 105 106 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GstMppDec, gst_object_unref); 107 GType gst_mpp_dec_get_type (void); 108 109 #define GST_FLOW_TIMEOUT GST_FLOW_CUSTOM_ERROR_1 110 111 #define MPP_DEC_OUT_FORMATS "NV12, NV16, NV12_10LE40, NV16_10LE40" 112 113 #ifdef HAVE_RGA 114 #define MPP_DEC_FORMATS MPP_DEC_OUT_FORMATS "," GST_RGA_FORMATS 115 #else 116 #define MPP_DEC_FORMATS MPP_DEC_OUT_FORMATS 117 #endif 118 119 #define MPP_DEC_FEATURE_ARM_AFBC "arm-afbc" 120 121 #define MPP_DEC_CAPS_MAKE(fmts) \ 122 GST_VIDEO_CAPS_MAKE (fmts) ";" \ 123 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF, fmts) 124 125 #define MPP_DEC_CAPS_MAKE_AFBC(fmts) \ 126 GST_VIDEO_CAPS_MAKE (fmts) ", " MPP_DEC_FEATURE_ARM_AFBC " = (int) 1;" \ 127 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF, fmts) \ 128 ", " MPP_DEC_FEATURE_ARM_AFBC " = (int) 1" 129 130 void gst_mpp_dec_fixup_video_info (GstVideoDecoder * decoder, 131 GstVideoFormat format, gint width, gint height); 132 133 gboolean gst_mpp_dec_update_simple_video_info (GstVideoDecoder * decoder, 134 GstVideoFormat format, guint width, guint height, guint align); 135 136 G_END_DECLS; 137 138 #endif /* __GST_MPP_DEC_H__ */ 139