1 /* GStreamer
2  * Copyright (C) <2017> Sean DuBois <sean@siobud.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 
21 #ifndef __GST_AV1_ENC_H__
22 #define __GST_AV1_ENC_H__
23 
24 
25 #include <gst/gst.h>
26 #include <gst/video/video.h>
27 #include <gst/video/gstvideoencoder.h>
28 
29 #include <aom/aom_codec.h>
30 #include <aom/aom_encoder.h>
31 #include <aom/aomcx.h>
32 
33 G_BEGIN_DECLS
34 #define GST_TYPE_AV1_ENC \
35   (gst_av1_enc_get_type())
36 #define GST_AV1_ENC(obj) \
37   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AV1_ENC,GstAV1Enc))
38 #define GST_AV1_ENC_CLASS(klass) \
39   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AV1_ENC,GstAV1EncClass))
40 #define GST_IS_AV1_ENC(obj) \
41   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AV1_ENC))
42 #define GST_IS_AV1_ENC_CLASS(klass) \
43   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AV1_ENC))
44 #define GST_AV1_ENC_GET_CLASS(obj) \
45   (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_AV1_ENC, GstAV1EncClass))
46 #define GST_AV1_ENC_CAST(obj) \
47   ((GstAV1Enc *) (obj))
48 
49 typedef struct _GstAV1Enc GstAV1Enc;
50 typedef struct _GstAV1EncClass GstAV1EncClass;
51 
52 /**
53  * GstAV1EncResizeMode:
54  * @GST_AV1_ENC_RESIZE_NONE: No frame resizing allowed
55  * @GST_AV1_ENC_RESIZE_FIXED: All frames are coded at the specified scale
56  * @GST_AV1_ENC_RESIZE_RANDOM: All frames are coded at a random scale
57  *
58  * Frame resize mode
59  */
60 typedef enum
61 {
62   GST_AV1_ENC_RESIZE_NONE = 0,
63   GST_AV1_ENC_RESIZE_FIXED = 1,
64   GST_AV1_ENC_RESIZE_RANDOM = 2,
65   GST_AV1_ENC_RESIZE_MODES
66 } GstAV1EncResizeMode;
67 
68 /**
69  * GstAV1EncSuperresMode
70  * @GST_AV1_ENC_SUPERRES_NONE: No frame superres allowed
71  * @GST_AV1_ENC_SUPERRES_FIXED: All frames are coded at the specified scale and
72  *   super-resolved
73  * @GST_AV1_ENC_SUPERRES_QTHRESH: Superres scale for a frame is determined based
74  *   on q_index
75  *
76  * Frame super-resolution mode
77  */
78 typedef enum
79 {
80   GST_AV1_ENC_SUPERRES_NONE = 0,
81   GST_AV1_ENC_SUPERRES_FIXED = 1,
82   GST_AV1_ENC_SUPERRES_RANDOM = 2,
83   GST_AV1_ENC_SUPERRES_QTHRESH = 3,
84   GST_AV1_ENC_SUPERRES_MODES
85 } GstAV1EncSuperresMode;
86 
87 /**
88  * GstAV1EncEndUsageMode
89  * @GST_AV1_ENC_END_USAGE_VBR: Variable Bit Rate Mode
90  * @GST_AV1_ENC_END_USAGE_CBR: Constant Bit Rate Mode
91  * @GST_AV1_ENC_END_USAGE_CQ: Constrained Quality Mode
92  * @GST_AV1_ENC_END_USAGE_Q: Constant Quality Mode
93  *
94  * Rate control algorithm to use
95  */
96 
97 typedef enum
98 {
99   GST_AV1_ENC_END_USAGE_VBR = 0,
100   GST_AV1_ENC_END_USAGE_CBR = 1,
101   GST_AV1_ENC_END_USAGE_CQ = 2,
102   GST_AV1_ENC_END_USAGE_Q = 3,
103   GST_AV1_ENC_END_USAGE_MODES
104 } GstAV1EncEndUsageMode;
105 
106 struct _GstAV1Enc
107 {
108   GstVideoEncoder base_video_encoder;
109 
110   /* properties */
111   guint keyframe_dist;
112   gint cpu_used;
113 
114   /* state */
115   gboolean encoder_inited;
116   GstVideoCodecState *input_state;
117   aom_codec_enc_cfg_t aom_cfg;
118   aom_codec_ctx_t encoder;
119   aom_img_fmt_t format;
120   GMutex encoder_lock;
121 
122   gboolean target_bitrate_set;
123 };
124 
125 struct _GstAV1EncClass
126 {
127   GstVideoEncoderClass parent_class;
128   /*supported aom algo*/
129   aom_codec_iface_t *codec_algo;
130 };
131 
132 GType gst_av1_enc_get_type (void);
133 
134 G_END_DECLS
135 #endif /* __GST_AV1_ENC_H__ */
136