• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) 2020 Seungha Yang <seungha.yang@navercorp.com>
3  * Copyright (C) 2020 Seungha Yang <seungha@centricular.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 #ifndef __GST_MF_VIDEO_ENC_H__
22 #define __GST_MF_VIDEO_ENC_H__
23 
24 #include "gstmfconfig.h"
25 
26 #include <gst/gst.h>
27 #include <gst/video/video.h>
28 #include "gstmfutils.h"
29 #include "gstmftransform.h"
30 
31 #if GST_MF_HAVE_D3D11
32 #include <gst/d3d11/gstd3d11.h>
33 #endif
34 
35 G_BEGIN_DECLS
36 
37 #define GST_TYPE_MF_VIDEO_ENC           (gst_mf_video_enc_get_type())
38 #define GST_MF_VIDEO_ENC(obj)           (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MF_VIDEO_ENC,GstMFVideoEnc))
39 #define GST_MF_VIDEO_ENC_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_MF_VIDEO_ENC,GstMFVideoEncClass))
40 #define GST_MF_VIDEO_ENC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_MF_VIDEO_ENC,GstMFVideoEncClass))
41 #define GST_IS_MF_VIDEO_ENC(obj)        (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MF_VIDEO_ENC))
42 #define GST_IS_MF_VIDEO_ENC_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_MF_VIDEO_ENC))
43 
44 typedef struct _GstMFVideoEnc GstMFVideoEnc;
45 typedef struct _GstMFVideoEncClass GstMFVideoEncClass;
46 typedef struct _GstMFVideoEncDeviceCaps GstMFVideoEncDeviceCaps;
47 typedef struct _GstMFVideoEncClassData GstMFVideoEncClassData;
48 
49 struct _GstMFVideoEncDeviceCaps
50 {
51   gboolean rc_mode; /* AVEncCommonRateControlMode */
52   gboolean quality; /* AVEncCommonQuality */
53 
54   gboolean adaptive_mode;     /* AVEncAdaptiveMode */
55   gboolean buffer_size;       /* AVEncCommonBufferSize */
56   gboolean max_bitrate;       /* AVEncCommonMaxBitRate */
57   gboolean quality_vs_speed;  /* AVEncCommonQualityVsSpeed */
58   gboolean cabac;             /* AVEncH264CABACEnable */
59   gboolean sps_id;            /* AVEncH264SPSID */
60   gboolean pps_id;            /* AVEncH264PPSID */
61   gboolean bframes;           /* AVEncMPVDefaultBPictureCount */
62   gboolean gop_size;          /* AVEncMPVGOPSize */
63   gboolean threads;           /* AVEncNumWorkerThreads */
64   gboolean content_type;      /* AVEncVideoContentType */
65   gboolean qp;                /* AVEncVideoEncodeQP */
66   gboolean force_keyframe;    /* AVEncVideoForceKeyFrame */
67   gboolean low_latency;       /* AVLowLatencyMode */
68 
69   gboolean min_qp;        /* AVEncVideoMinQP */
70   gboolean max_qp;        /* AVEncVideoMaxQP */
71   gboolean frame_type_qp; /* AVEncVideoEncodeFrameTypeQP */
72   gboolean max_num_ref;   /* AVEncVideoMaxNumRefFrame */
73   guint max_num_ref_high;
74   guint max_num_ref_low;
75 
76   /* TRUE if MFT support d3d11 and also we can use d3d11 interop */
77   gboolean d3d11_aware;
78   /* DXGI adapter LUID, valid only when d3d11_aware == TRUE */
79   gint64 adapter_luid;
80 };
81 
82 struct _GstMFVideoEncClassData
83 {
84   GstCaps *sink_caps;
85   GstCaps *src_caps;
86   gchar *device_name;
87   guint32 enum_flags;
88   guint device_index;
89   GstMFVideoEncDeviceCaps device_caps;
90   gboolean is_default;
91 };
92 
93 struct _GstMFVideoEnc
94 {
95   GstVideoEncoder parent;
96 
97   GstMFTransform *transform;
98   gboolean async_mft;
99   GstFlowReturn last_ret;
100 
101   GstVideoCodecState *input_state;
102 
103   /* Set by subclass */
104   gboolean has_reorder_frame;
105 
106   /* Calculated timestamp offset in MF timescale (100ns scale)
107    * when B-frame is enabled. */
108   LONGLONG mf_pts_offset;
109 
110 #if GST_MF_HAVE_D3D11
111   /* For D3D11 interop. */
112   GstD3D11Device *other_d3d11_device;
113   GstD3D11Device *d3d11_device;
114   IMFDXGIDeviceManager *device_manager;
115   UINT reset_token;
116   IMFVideoSampleAllocatorEx *mf_allocator;
117 #endif
118 };
119 
120 struct _GstMFVideoEncClass
121 {
122   GstVideoEncoderClass parent_class;
123 
124   /* Set by subclass */
125   GUID codec_id;      /* Output subtype of MFT */
126   guint32 enum_flags; /* MFT_ENUM_FLAG */
127   guint device_index; /* Index of enumerated IMFActivate via MFTEnum */
128   GstMFVideoEncDeviceCaps device_caps;
129 
130   gboolean (*set_option)    (GstMFVideoEnc * mfenc,
131                              GstVideoCodecState * state,
132                              IMFMediaType * output_type);
133 
134   gboolean (*set_src_caps)  (GstMFVideoEnc * mfenc,
135                              GstVideoCodecState * state,
136                              IMFMediaType * output_type);
137 };
138 
139 GType gst_mf_video_enc_get_type (void);
140 
141 void  gst_mf_video_enc_register (GstPlugin * plugin,
142                                  guint rank,
143                                  GUID * subtype,
144                                  GTypeInfo * type_info,
145                                  GList * d3d11_device);
146 
147 G_END_DECLS
148 
149 #endif /* __GST_MF_VIDEO_ENC_H__ */