2 * Copyright (C) <2017> Sean DuBois <sean@siobud.com>
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.
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.
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.
20 * SECTION:element-av1enc
24 * ## Example launch line
27 * gst-launch-1.0 videotestsrc num-buffers=50 ! av1enc ! webmmux ! filesink location=av1.webm
35 #include "gstav1enc.h"
36 #include "gstav1utils.h"
37 #include <gst/video/video.h>
38 #include <gst/video/gstvideometa.h>
39 #include <gst/base/base.h>
41 #define GST_AV1_ENC_APPLY_CODEC_CONTROL(av1enc, flag, value) \
42 if (av1enc->encoder_inited) { \
43 if (aom_codec_control (&av1enc->encoder, flag, \
44 value) != AOM_CODEC_OK) { \
45 gst_av1_codec_error (&av1enc->encoder, "Failed to set " #flag); \
49 GST_DEBUG_CATEGORY_STATIC (av1_enc_debug);
50 #define GST_CAT_DEFAULT av1_enc_debug
52 #define GST_TYPE_RESIZE_MODE (gst_resize_mode_get_type())
54 gst_resize_mode_get_type (void)
56 static GType resize_mode_type = 0;
57 static const GEnumValue resize_mode[] = {
58 {GST_AV1_ENC_RESIZE_NONE, "No frame resizing allowed", "none"},
59 {GST_AV1_ENC_RESIZE_FIXED, "All frames are coded at the specified scale",
61 {GST_AV1_ENC_RESIZE_RANDOM, "All frames are coded at a random scale",
66 if (!resize_mode_type) {
68 g_enum_register_static ("GstAV1EncResizeMode", resize_mode);
70 return resize_mode_type;
73 #define GST_TYPE_SUPERRES_MODE (gst_superres_mode_get_type())
75 gst_superres_mode_get_type (void)
77 static GType superres_mode_type = 0;
78 static const GEnumValue superres_mode[] = {
79 {GST_AV1_ENC_SUPERRES_NONE, "No frame superres allowed", "none"},
80 {GST_AV1_ENC_SUPERRES_FIXED,
81 "All frames are coded at the specified scale and super-resolved",
83 {GST_AV1_ENC_SUPERRES_RANDOM,
84 "All frames are coded at a random scale and super-resolved",
86 {GST_AV1_ENC_SUPERRES_QTHRESH,
87 "Superres scale for a frame is determined based on q_index",
92 if (!superres_mode_type) {
94 g_enum_register_static ("GstAV1EncSuperresMode", superres_mode);
96 return superres_mode_type;
99 #define GST_TYPE_END_USAGE_MODE (gst_end_usage_mode_get_type())
101 gst_end_usage_mode_get_type (void)
103 static GType end_usage_mode_type = 0;
104 static const GEnumValue end_usage_mode[] = {
105 {GST_AV1_ENC_END_USAGE_VBR, "Variable Bit Rate Mode", "vbr"},
106 {GST_AV1_ENC_END_USAGE_CBR, "Constant Bit Rate Mode", "cbr"},
107 {GST_AV1_ENC_END_USAGE_CQ, "Constrained Quality Mode", "cq"},
108 {GST_AV1_ENC_END_USAGE_Q, "Constant Quality Mode", "q"},
112 if (!end_usage_mode_type) {
113 end_usage_mode_type =
114 g_enum_register_static ("GstAV1EncEndUsageMode", end_usage_mode);
116 return end_usage_mode_type;
119 #define GST_TYPE_KF_MODE (gst_kf_mode_get_type())
121 gst_kf_mode_get_type (void)
123 static GType kf_mode_type = 0;
124 static const GEnumValue kf_mode[] = {
125 {GST_AV1_ENC_KF_AUTO,
126 "Encoder determines optimal keyframe placement automatically",
128 {GST_AV1_ENC_KF_DISABLED, "Encoder does not place keyframes", "disabled"},
133 kf_mode_type = g_enum_register_static ("GstAV1EncKFMode", kf_mode);
138 #define GST_TYPE_ENC_PASS (gst_enc_pass_get_type())
140 gst_enc_pass_get_type (void)
142 static GType enc_pass_type = 0;
143 static const GEnumValue enc_pass[] = {
144 {GST_AV1_ENC_ONE_PASS, "Single pass mode", "one-pass"},
145 {GST_AV1_ENC_FIRST_PASS, "First pass of multi-pass mode", "first-pass"},
146 {GST_AV1_ENC_SECOND_PASS, "Second pass of multi-pass mode", "second-pass"},
147 {GST_AV1_ENC_THIRD_PASS, "Third pass of multi-pass mode", "third-pass"},
151 if (!enc_pass_type) {
152 enc_pass_type = g_enum_register_static ("GstAV1EncEncPass", enc_pass);
154 return enc_pass_type;
157 #define GST_TYPE_USAGE_PROFILE (gst_usage_profile_get_type())
159 gst_usage_profile_get_type (void)
161 static GType usage_profile_type = 0;
162 static const GEnumValue usage_profile[] = {
163 {GST_AV1_ENC_USAGE_GOOD_QUALITY, "Good Quality profile", "good-quality"},
164 {GST_AV1_ENC_USAGE_REALTIME, "Realtime profile", "realtime"},
165 {GST_AV1_ENC_USAGE_ALL_INTRA, "All Intra profile", "all-intra"},
169 if (!usage_profile_type) {
171 g_enum_register_static ("GstAV1EncUsageProfile", usage_profile);
173 return usage_profile_type;
187 PROP_RESIZE_DENOMINATOR,
188 PROP_RESIZE_KF_DENOMINATOR,
190 PROP_SUPERRES_DENOMINATOR,
191 PROP_SUPERRES_KF_DENOMINATOR,
192 PROP_SUPERRES_QTHRESH,
193 PROP_SUPERRES_KF_QTHRESH,
211 PROP_KEYFRAME_MAX_DIST
214 /* From av1/av1_cx_iface.c */
215 #define DEFAULT_PROFILE 0
216 #define DEFAULT_CPU_USED 0
217 #define DEFAULT_DROP_FRAME 0
218 #define DEFAULT_RESIZE_MODE GST_AV1_ENC_RESIZE_NONE
219 #define DEFAULT_RESIZE_DENOMINATOR 8
220 #define DEFAULT_RESIZE_KF_DENOMINATOR 8
221 #define DEFAULT_SUPERRES_MODE GST_AV1_ENC_SUPERRES_NONE
222 #define DEFAULT_SUPERRES_DENOMINATOR 8
223 #define DEFAULT_SUPERRES_KF_DENOMINATOR 8
224 #define DEFAULT_SUPERRES_QTHRESH 63
225 #define DEFAULT_SUPERRES_KF_QTHRESH 63
226 #define DEFAULT_END_USAGE GST_AV1_ENC_END_USAGE_VBR
227 #define DEFAULT_TARGET_BITRATE 256
228 #define DEFAULT_MIN_QUANTIZER 0
229 #define DEFAULT_MAX_QUANTIZER 0
230 #define DEFAULT_UNDERSHOOT_PCT 25
231 #define DEFAULT_OVERSHOOT_PCT 25
232 #define DEFAULT_BUF_SZ 6000
233 #define DEFAULT_BUF_INITIAL_SZ 4000
234 #define DEFAULT_BUF_OPTIMAL_SZ 5000
235 #define DEFAULT_TIMEBASE_N 1
236 #define DEFAULT_TIMEBASE_D 90000
237 #define DEFAULT_BIT_DEPTH AOM_BITS_8
238 #define DEFAULT_THREADS 0
239 #define DEFAULT_ROW_MT TRUE
240 #define DEFAULT_TILE_COLUMNS 0
241 #define DEFAULT_TILE_ROWS 0
242 #define DEFAULT_KF_MODE GST_AV1_ENC_KF_AUTO
243 #define DEFAULT_ENC_PASS GST_AV1_ENC_ONE_PASS
244 #define DEFAULT_USAGE_PROFILE GST_AV1_ENC_USAGE_GOOD_QUALITY
245 #define DEFAULT_LAG_IN_FRAMES 0
246 #define DEFAULT_KEYFRAME_MAX_DIST 30
248 static void gst_av1_enc_finalize (GObject * object);
249 static void gst_av1_enc_set_property (GObject * object, guint prop_id,
250 const GValue * value, GParamSpec * pspec);
251 static void gst_av1_enc_get_property (GObject * object, guint prop_id,
252 GValue * value, GParamSpec * pspec);
254 static gboolean gst_av1_enc_start (GstVideoEncoder * encoder);
255 static gboolean gst_av1_enc_stop (GstVideoEncoder * encoder);
256 static gboolean gst_av1_enc_set_format (GstVideoEncoder * encoder,
257 GstVideoCodecState * state);
258 static GstFlowReturn gst_av1_enc_handle_frame (GstVideoEncoder * encoder,
259 GstVideoCodecFrame * frame);
260 static GstFlowReturn gst_av1_enc_finish (GstVideoEncoder * encoder);
261 static gboolean gst_av1_enc_propose_allocation (GstVideoEncoder * encoder,
264 static void gst_av1_enc_destroy_encoder (GstAV1Enc * av1enc);
266 #define gst_av1_enc_parent_class parent_class
267 G_DEFINE_TYPE (GstAV1Enc, gst_av1_enc, GST_TYPE_VIDEO_ENCODER);
268 GST_ELEMENT_REGISTER_DEFINE (av1enc, "av1enc", GST_RANK_PRIMARY,
272 static GstStaticPadTemplate gst_av1_enc_sink_pad_template =
273 GST_STATIC_PAD_TEMPLATE ("sink",
276 GST_STATIC_CAPS ("video/x-raw, "
277 "format = (string) { I420, Y42B, Y444, YV12 }, "
278 "framerate = (fraction) [0, MAX], "
279 "width = (int) [ 4, MAX ], "
280 "height = (int) [ 4, MAX ]")
284 static GstStaticPadTemplate gst_av1_enc_src_pad_template =
285 GST_STATIC_PAD_TEMPLATE ("src",
288 GST_STATIC_CAPS ("video/x-av1, "
289 "stream-format = (string) obu-stream, " "alignment = (string) tu")
293 gst_av1_enc_class_init (GstAV1EncClass * klass)
295 GObjectClass *gobject_class;
296 GstElementClass *element_class;
297 GstVideoEncoderClass *venc_class;
299 gobject_class = (GObjectClass *) klass;
300 element_class = (GstElementClass *) klass;
301 venc_class = (GstVideoEncoderClass *) klass;
303 parent_class = g_type_class_peek_parent (klass);
305 gobject_class->finalize = gst_av1_enc_finalize;
306 gobject_class->set_property = gst_av1_enc_set_property;
307 gobject_class->get_property = gst_av1_enc_get_property;
309 gst_element_class_add_static_pad_template (element_class,
310 &gst_av1_enc_sink_pad_template);
311 gst_element_class_add_static_pad_template (element_class,
312 &gst_av1_enc_src_pad_template);
313 gst_element_class_set_static_metadata (element_class, "AV1 Encoder",
314 "Codec/Encoder/Video", "Encode AV1 video streams",
315 "Sean DuBois <sean@siobud.com>");
317 venc_class->start = gst_av1_enc_start;
318 venc_class->stop = gst_av1_enc_stop;
319 venc_class->set_format = gst_av1_enc_set_format;
320 venc_class->handle_frame = gst_av1_enc_handle_frame;
321 venc_class->finish = gst_av1_enc_finish;
322 venc_class->propose_allocation = gst_av1_enc_propose_allocation;
324 klass->codec_algo = &aom_codec_av1_cx_algo;
325 GST_DEBUG_CATEGORY_INIT (av1_enc_debug, "av1enc", 0, "AV1 encoding element");
327 g_object_class_install_property (gobject_class, PROP_CPU_USED,
328 g_param_spec_int ("cpu-used", "CPU Used",
329 "CPU Used. A Value greater than 0 will increase encoder speed at the expense of quality.",
330 0, 10, DEFAULT_CPU_USED, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
332 /* Rate control configurations */
333 g_object_class_install_property (gobject_class, PROP_DROP_FRAME,
334 g_param_spec_uint ("drop-frame", "Drop frame",
335 "Temporal resampling configuration, drop frames as a strategy to meet "
336 "its target data rate Set to zero (0) to disable this feature.",
337 0, G_MAXUINT, DEFAULT_DROP_FRAME,
338 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
340 g_object_class_install_property (gobject_class, PROP_RESIZE_MODE,
341 g_param_spec_enum ("resize-mode", "Resize mode",
342 "Frame resize mode", GST_TYPE_RESIZE_MODE,
343 DEFAULT_RESIZE_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
345 g_object_class_install_property (gobject_class, PROP_RESIZE_DENOMINATOR,
346 g_param_spec_uint ("resize-denominator", "Resize denominator",
347 "Frame resize denominator, assuming 8 as the numerator",
348 8, 16, DEFAULT_RESIZE_DENOMINATOR,
349 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
351 g_object_class_install_property (gobject_class, PROP_RESIZE_KF_DENOMINATOR,
352 g_param_spec_uint ("resize-kf-denominator", "Resize keyframe denominator",
353 "Frame resize keyframe denominator, assuming 8 as the numerator",
354 8, 16, DEFAULT_RESIZE_KF_DENOMINATOR,
355 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
357 g_object_class_install_property (gobject_class, PROP_SUPERRES_MODE,
358 g_param_spec_enum ("superres-mode", "Super-resolution scaling mode",
359 "It integrates upscaling after the encode/decode process",
360 GST_TYPE_SUPERRES_MODE,
361 DEFAULT_SUPERRES_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
363 g_object_class_install_property (gobject_class, PROP_SUPERRES_DENOMINATOR,
364 g_param_spec_uint ("superres-denominator", "Super-resolution denominator",
365 "Frame super-resolution denominator, used only by SUPERRES_FIXED mode",
366 8, 16, DEFAULT_SUPERRES_DENOMINATOR,
367 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
369 g_object_class_install_property (gobject_class, PROP_SUPERRES_KF_DENOMINATOR,
370 g_param_spec_uint ("superres-kf-denominator",
371 "Keyframe super-resolution denominator",
372 "Keyframe super-resolution denominator",
373 8, 16, DEFAULT_SUPERRES_KF_DENOMINATOR,
374 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
376 g_object_class_install_property (gobject_class, PROP_SUPERRES_QTHRESH,
377 g_param_spec_uint ("superres-qthresh",
378 "Frame super-resolution qindex threshold",
379 "Frame super-resolution qindex threshold, used only by SUPERRES_QTHRESH mode",
380 1, 63, DEFAULT_SUPERRES_QTHRESH,
381 (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
383 g_object_class_install_property (gobject_class, PROP_SUPERRES_KF_QTHRESH,
384 g_param_spec_uint ("superres-kf-qthresh",
385 "Keyframe super-resolution qindex threshold",
386 "Keyframe super-resolution qindex threshold, used only by SUPERRES_QTHRESH mode",
387 1, 63, DEFAULT_SUPERRES_KF_QTHRESH,
388 (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
390 g_object_class_install_property (gobject_class, PROP_END_USAGE,
391 g_param_spec_enum ("end-usage", "Rate control mode",
392 "Rate control algorithm to use, indicates the end usage of this stream",
393 GST_TYPE_END_USAGE_MODE, DEFAULT_END_USAGE,
394 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
396 g_object_class_install_property (gobject_class, PROP_TARGET_BITRATE,
397 g_param_spec_uint ("target-bitrate", "Target bitrate",
398 "Target bitrate, in kilobits per second",
399 1, G_MAXUINT, DEFAULT_TARGET_BITRATE,
400 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
402 g_object_class_install_property (gobject_class, PROP_MIN_QUANTIZER,
403 g_param_spec_uint ("min-quantizer", "Minimum (best quality) quantizer",
404 "Minimum (best quality) quantizer",
405 0, G_MAXUINT, DEFAULT_MIN_QUANTIZER,
406 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
408 g_object_class_install_property (gobject_class, PROP_MAX_QUANTIZER,
409 g_param_spec_uint ("max-quantizer", "Maximum (worst quality) quantizer",
410 "Maximum (worst quality) quantizer",
411 0, G_MAXUINT, DEFAULT_MAX_QUANTIZER,
412 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
414 g_object_class_install_property (gobject_class, PROP_UNDERSHOOT_PCT,
415 g_param_spec_uint ("undershoot-pct", "Datarate undershoot (min) target",
416 "Rate control adaptation undershoot control",
417 0, 1000, DEFAULT_UNDERSHOOT_PCT,
418 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
420 g_object_class_install_property (gobject_class, PROP_OVERSHOOT_PCT,
421 g_param_spec_uint ("overshoot-pct", "Datarate overshoot (max) target",
422 "Rate control adaptation overshoot control",
423 0, 1000, DEFAULT_OVERSHOOT_PCT,
424 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
426 g_object_class_install_property (gobject_class, PROP_BUF_SZ,
427 g_param_spec_uint ("buf-sz", "Decoder buffer size",
428 "Decoder buffer size, expressed in units of time (milliseconds)",
429 0, G_MAXUINT, DEFAULT_BUF_SZ,
430 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
432 g_object_class_install_property (gobject_class, PROP_BUF_INITIAL_SZ,
433 g_param_spec_uint ("buf-initial-sz", "Decoder buffer initial size",
434 "Decoder buffer initial size, expressed in units of time (milliseconds)",
435 0, G_MAXUINT, DEFAULT_BUF_INITIAL_SZ,
436 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
438 g_object_class_install_property (gobject_class, PROP_BUF_OPTIMAL_SZ,
439 g_param_spec_uint ("buf-optimal-sz", "Decoder buffer optimal size",
440 "Decoder buffer optimal size, expressed in units of time (milliseconds)",
441 0, G_MAXUINT, DEFAULT_BUF_OPTIMAL_SZ,
442 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
444 g_object_class_install_property (gobject_class, PROP_THREADS,
445 g_param_spec_uint ("threads", "Max number of threads to use",
446 "Max number of threads to use encoding, set to 0 determine the "
447 "approximate number of threads that the system schedule",
448 0, G_MAXUINT, DEFAULT_THREADS,
449 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
451 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
452 g_object_class_install_property (gobject_class, PROP_ROW_MT,
453 g_param_spec_boolean ("row-mt", "Row based multi-threading",
454 "Enable row based multi-threading",
455 DEFAULT_ROW_MT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
458 g_object_class_install_property (gobject_class, PROP_TILE_COLUMNS,
459 g_param_spec_uint ("tile-columns", "Number of tile columns",
460 "Partition into separate vertical tile columns from image frame which "
461 "can enable parallel encoding",
462 0, 6, DEFAULT_TILE_COLUMNS,
463 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
465 g_object_class_install_property (gobject_class, PROP_TILE_ROWS,
466 g_param_spec_uint ("tile-rows", "Number of tile rows",
467 "Partition into separate horizontal tile rows from image frame which "
468 "can enable parallel encoding",
469 0, 6, DEFAULT_TILE_ROWS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
472 * av1enc:keyframe-mode:
476 g_object_class_install_property (gobject_class, PROP_KF_MODE,
477 g_param_spec_enum ("keyframe-mode", "Keyframe placement mode",
478 "Determines whether keyframes are placed automatically by the encoder",
479 GST_TYPE_KF_MODE, DEFAULT_KF_MODE,
480 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
487 g_object_class_install_property (gobject_class, PROP_ENC_PASS,
488 g_param_spec_enum ("enc-pass", "Multi-pass Encoding Pass",
489 "Current phase for multi-pass encoding or @GST_AV1_ENC_ONE_PASS for single pass",
490 GST_TYPE_ENC_PASS, DEFAULT_ENC_PASS,
491 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
494 * av1enc:usage-profile:
498 g_object_class_install_property (gobject_class, PROP_USAGE_PROFILE,
499 g_param_spec_enum ("usage-profile", "Usage value",
500 "Usage profile is used to guide the default config for the encoder",
501 GST_TYPE_USAGE_PROFILE, DEFAULT_USAGE_PROFILE,
502 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
505 * av1enc:lag-in-frames:
509 g_object_class_install_property (gobject_class, PROP_LAG_IN_FRAMES,
510 g_param_spec_uint ("lag-in-frames", "Allow lagged encoding",
511 "Maximum number of future frames the encoder is allowed to consume "
512 "before producing the current output frame. "
513 "Set value to 0 for disabling lagged encoding.",
514 0, G_MAXUINT, DEFAULT_LAG_IN_FRAMES,
515 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
518 * av1enc:keyframe-max-dist:
522 g_object_class_install_property (gobject_class, PROP_KEYFRAME_MAX_DIST,
523 g_param_spec_int ("keyframe-max-dist", "Keyframe max distance",
524 "Maximum distance between keyframes (number of frames)",
525 0, G_MAXINT, DEFAULT_KEYFRAME_MAX_DIST,
526 (GParamFlags) (G_PARAM_READWRITE |
527 G_PARAM_STATIC_STRINGS | GST_PARAM_DOC_SHOW_DEFAULT)));
529 gst_type_mark_as_plugin_api (GST_TYPE_END_USAGE_MODE, 0);
530 gst_type_mark_as_plugin_api (GST_TYPE_RESIZE_MODE, 0);
531 gst_type_mark_as_plugin_api (GST_TYPE_SUPERRES_MODE, 0);
532 gst_type_mark_as_plugin_api (GST_TYPE_KF_MODE, 0);
533 gst_type_mark_as_plugin_api (GST_TYPE_ENC_PASS, 0);
534 gst_type_mark_as_plugin_api (GST_TYPE_USAGE_PROFILE, 0);
538 gst_av1_codec_error (aom_codec_ctx_t * ctx, const char *s)
540 const char *detail = aom_codec_error_detail (ctx);
542 GST_ERROR ("%s: %s %s", s, aom_codec_error (ctx), detail ? detail : "");
546 gst_av1_enc_init (GstAV1Enc * av1enc)
548 GST_PAD_SET_ACCEPT_TEMPLATE (GST_VIDEO_ENCODER_SINK_PAD (av1enc));
550 av1enc->encoder_inited = FALSE;
552 av1enc->cpu_used = DEFAULT_CPU_USED;
553 av1enc->format = AOM_IMG_FMT_I420;
554 av1enc->threads = DEFAULT_THREADS;
555 av1enc->row_mt = DEFAULT_ROW_MT;
556 av1enc->tile_columns = DEFAULT_TILE_COLUMNS;
557 av1enc->tile_rows = DEFAULT_TILE_ROWS;
559 #ifdef FIXED_QP_OFFSET_COUNT
560 av1enc->aom_cfg.fixed_qp_offsets[0] = -1;
561 av1enc->aom_cfg.fixed_qp_offsets[1] = -1;
562 av1enc->aom_cfg.fixed_qp_offsets[2] = -1;
563 av1enc->aom_cfg.fixed_qp_offsets[3] = -1;
564 av1enc->aom_cfg.fixed_qp_offsets[4] = -1;
566 av1enc->aom_cfg.kf_max_dist = DEFAULT_KEYFRAME_MAX_DIST;
567 av1enc->aom_cfg.rc_dropframe_thresh = DEFAULT_DROP_FRAME;
568 av1enc->aom_cfg.rc_resize_mode = DEFAULT_RESIZE_MODE;
569 av1enc->aom_cfg.rc_resize_denominator = DEFAULT_RESIZE_DENOMINATOR;
570 av1enc->aom_cfg.rc_resize_kf_denominator = DEFAULT_RESIZE_KF_DENOMINATOR;
571 av1enc->aom_cfg.rc_superres_mode = DEFAULT_SUPERRES_MODE;
572 av1enc->aom_cfg.rc_superres_denominator = DEFAULT_SUPERRES_DENOMINATOR;
573 av1enc->aom_cfg.rc_superres_kf_denominator = DEFAULT_SUPERRES_KF_DENOMINATOR;
574 av1enc->aom_cfg.rc_superres_qthresh = DEFAULT_SUPERRES_QTHRESH;
575 av1enc->aom_cfg.rc_superres_kf_qthresh = DEFAULT_SUPERRES_KF_QTHRESH;
576 av1enc->aom_cfg.rc_end_usage = (enum aom_rc_mode) DEFAULT_END_USAGE;
577 av1enc->aom_cfg.rc_target_bitrate = DEFAULT_TARGET_BITRATE;
578 av1enc->aom_cfg.rc_min_quantizer = DEFAULT_MIN_QUANTIZER;
579 av1enc->aom_cfg.rc_max_quantizer = DEFAULT_MAX_QUANTIZER;
580 av1enc->aom_cfg.rc_undershoot_pct = DEFAULT_UNDERSHOOT_PCT;
581 av1enc->aom_cfg.rc_overshoot_pct = DEFAULT_OVERSHOOT_PCT;
582 av1enc->aom_cfg.rc_buf_sz = DEFAULT_BUF_SZ;
583 av1enc->aom_cfg.rc_buf_initial_sz = DEFAULT_BUF_INITIAL_SZ;
584 av1enc->aom_cfg.rc_buf_optimal_sz = DEFAULT_BUF_OPTIMAL_SZ;
585 av1enc->aom_cfg.g_timebase.num = DEFAULT_TIMEBASE_N;
586 av1enc->aom_cfg.g_timebase.den = DEFAULT_TIMEBASE_D;
587 av1enc->aom_cfg.g_bit_depth = DEFAULT_BIT_DEPTH;
588 av1enc->aom_cfg.g_input_bit_depth = (unsigned int) DEFAULT_BIT_DEPTH;
589 av1enc->aom_cfg.kf_mode = (enum aom_kf_mode) DEFAULT_KF_MODE;
590 av1enc->aom_cfg.g_pass = (enum aom_enc_pass) DEFAULT_ENC_PASS;
591 av1enc->aom_cfg.g_usage = (unsigned int) DEFAULT_USAGE_PROFILE;
592 av1enc->aom_cfg.g_lag_in_frames = DEFAULT_LAG_IN_FRAMES;
594 g_mutex_init (&av1enc->encoder_lock);
598 gst_av1_enc_finalize (GObject * object)
600 GstAV1Enc *av1enc = GST_AV1_ENC (object);
602 if (av1enc->input_state) {
603 gst_video_codec_state_unref (av1enc->input_state);
605 av1enc->input_state = NULL;
607 gst_av1_enc_destroy_encoder (av1enc);
608 g_mutex_clear (&av1enc->encoder_lock);
610 G_OBJECT_CLASS (parent_class)->finalize (object);
614 gst_av1_enc_set_latency (GstAV1Enc * av1enc)
616 GstClockTime latency;
619 if (av1enc->input_state->info.fps_n && av1enc->input_state->info.fps_d) {
620 fps_n = av1enc->input_state->info.fps_n;
621 fps_d = av1enc->input_state->info.fps_d;
628 gst_util_uint64_scale (av1enc->aom_cfg.g_lag_in_frames * GST_SECOND,
630 gst_video_encoder_set_latency (GST_VIDEO_ENCODER (av1enc), latency, latency);
632 GST_DEBUG_OBJECT (av1enc, "Latency set to %" GST_TIME_FORMAT
633 " = %d frames at %d/%d fps ", GST_TIME_ARGS (latency),
634 av1enc->aom_cfg.g_lag_in_frames, fps_n, fps_d);
638 gst_av1_enc_get_aom_rc_mode_name (enum aom_rc_mode rc_mode)
642 return "VBR (Variable Bit Rate)";
644 return "CBR (Constant Bit Rate)";
646 return "CQ (Constrained Quality)";
648 return "Q (Constant Quality)";
655 gst_av1_enc_debug_encoder_cfg (struct aom_codec_enc_cfg *cfg)
657 GST_DEBUG ("g_usage : %u", cfg->g_usage);
658 GST_DEBUG ("g_threads : %u", cfg->g_threads);
659 GST_DEBUG ("g_profile : %u", cfg->g_profile);
660 GST_DEBUG ("g_w x g_h : %u x %u", cfg->g_w, cfg->g_h);
661 GST_DEBUG ("g_bit_depth : %d", cfg->g_bit_depth);
662 GST_DEBUG ("g_input_bit_depth : %u", cfg->g_input_bit_depth);
663 GST_DEBUG ("g_timebase : %d / %d", cfg->g_timebase.num, cfg->g_timebase.den);
664 GST_DEBUG ("g_error_resilient : 0x%x", cfg->g_error_resilient);
665 GST_DEBUG ("g_pass : %d", cfg->g_pass);
666 GST_DEBUG ("g_lag_in_frames : %u", cfg->g_lag_in_frames);
667 GST_DEBUG ("rc_dropframe_thresh : %u", cfg->rc_dropframe_thresh);
668 GST_DEBUG ("rc_resize_mode : %u", cfg->rc_resize_mode);
669 GST_DEBUG ("rc_resize_denominator : %u", cfg->rc_resize_denominator);
670 GST_DEBUG ("rc_resize_kf_denominator : %u", cfg->rc_resize_kf_denominator);
671 GST_DEBUG ("rc_superres_mode : %u", cfg->rc_superres_mode);
672 GST_DEBUG ("rc_superres_denominator : %u", cfg->rc_superres_denominator);
673 GST_DEBUG ("rc_superres_kf_denominator : %u",
674 cfg->rc_superres_kf_denominator);
675 GST_DEBUG ("rc_superres_qthresh : %u", cfg->rc_superres_qthresh);
676 GST_DEBUG ("rc_superres_kf_qthresh : %u", cfg->rc_superres_kf_qthresh);
677 GST_DEBUG ("rc_end_usage : %s",
678 gst_av1_enc_get_aom_rc_mode_name (cfg->rc_end_usage));
679 /* rc_twopass_stats_in */
680 /* rc_firstpass_mb_stats_in */
681 GST_DEBUG ("rc_target_bitrate : %u (kbps)", cfg->rc_target_bitrate);
682 GST_DEBUG ("rc_min_quantizer : %u", cfg->rc_min_quantizer);
683 GST_DEBUG ("rc_max_quantizer : %u", cfg->rc_max_quantizer);
684 GST_DEBUG ("rc_undershoot_pct : %u", cfg->rc_undershoot_pct);
685 GST_DEBUG ("rc_overshoot_pct : %u", cfg->rc_overshoot_pct);
686 GST_DEBUG ("rc_buf_sz : %u (ms)", cfg->rc_buf_sz);
687 GST_DEBUG ("rc_buf_initial_sz : %u (ms)", cfg->rc_buf_initial_sz);
688 GST_DEBUG ("rc_buf_optimal_sz : %u (ms)", cfg->rc_buf_optimal_sz);
689 GST_DEBUG ("rc_2pass_vbr_bias_pct : %u (%%)", cfg->rc_2pass_vbr_bias_pct);
690 GST_DEBUG ("rc_2pass_vbr_minsection_pct : %u (%%)",
691 cfg->rc_2pass_vbr_minsection_pct);
692 GST_DEBUG ("rc_2pass_vbr_maxsection_pct : %u (%%)",
693 cfg->rc_2pass_vbr_maxsection_pct);
694 GST_DEBUG ("kf_mode : %u", cfg->kf_mode);
695 GST_DEBUG ("kf_min_dist : %u", cfg->kf_min_dist);
696 GST_DEBUG ("kf_max_dist : %u", cfg->kf_max_dist);
697 GST_DEBUG ("large_scale_tile : %u", cfg->large_scale_tile);
698 /* Tile-related values */
702 gst_av1_enc_get_downstream_profile (GstAV1Enc * av1enc)
706 gint profile = DEFAULT_PROFILE;
708 allowed = gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (av1enc));
710 allowed = gst_caps_truncate (allowed);
711 s = gst_caps_get_structure (allowed, 0);
712 if (gst_structure_has_field (s, "profile")) {
713 const GValue *v = gst_structure_get_value (s, "profile");
714 const gchar *profile_str = NULL;
716 if (GST_VALUE_HOLDS_LIST (v) && gst_value_list_get_size (v) > 0) {
717 profile_str = g_value_get_string (gst_value_list_get_value (v, 0));
718 } else if (G_VALUE_HOLDS_STRING (v)) {
719 profile_str = g_value_get_string (v);
723 gchar *endptr = NULL;
725 if (g_strcmp0 (profile_str, "main") == 0) {
726 GST_DEBUG_OBJECT (av1enc, "Downstream profile is \"main\"");
728 } else if (g_strcmp0 (profile_str, "high") == 0) {
730 GST_DEBUG_OBJECT (av1enc, "Downstream profile is \"high\"");
731 } else if (g_strcmp0 (profile_str, "professional") == 0) {
733 GST_DEBUG_OBJECT (av1enc, "Downstream profile is \"professional\"");
735 profile = g_ascii_strtoull (profile_str, &endptr, 10);
736 if (*endptr != '\0' || profile < 0 || profile > 3) {
737 GST_ERROR_OBJECT (av1enc, "Invalid profile '%s'", profile_str);
738 profile = DEFAULT_PROFILE;
740 GST_DEBUG_OBJECT (av1enc,
741 "Downstream profile is \"%s\"", profile_str);
746 gst_caps_unref (allowed);
749 GST_DEBUG_OBJECT (av1enc, "Using profile %d", profile);
755 gst_av1_enc_adjust_profile (GstAV1Enc * av1enc, GstVideoFormat format)
757 guint depth = av1enc->aom_cfg.g_bit_depth;
758 guint profile = av1enc->aom_cfg.g_profile;
759 gboolean update = FALSE;
763 if (depth < 12 && format == GST_VIDEO_FORMAT_Y444) {
766 } else if (depth == 12 || format == GST_VIDEO_FORMAT_Y42B) {
772 if (depth == 12 || format == GST_VIDEO_FORMAT_Y42B) {
775 } else if (depth < 12 && format == GST_VIDEO_FORMAT_I420) {
782 if (format == GST_VIDEO_FORMAT_Y444) {
785 } else if (format == GST_VIDEO_FORMAT_I420) {
796 GST_INFO_OBJECT (av1enc, "profile updated to %d from %d",
797 profile, av1enc->aom_cfg.g_profile);
798 av1enc->aom_cfg.g_profile = profile;
803 gst_av1_enc_set_format (GstVideoEncoder * encoder, GstVideoCodecState * state)
805 GstVideoCodecState *output_state;
806 GstAV1Enc *av1enc = GST_AV1_ENC_CAST (encoder);
807 GstAV1EncClass *av1enc_class = GST_AV1_ENC_GET_CLASS (av1enc);
808 GstVideoInfo *info = &state->info;
811 gst_video_encoder_set_output_state (encoder,
812 gst_pad_get_pad_template_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder)),
814 gst_video_codec_state_unref (output_state);
816 if (av1enc->input_state) {
817 gst_video_codec_state_unref (av1enc->input_state);
819 av1enc->input_state = gst_video_codec_state_ref (state);
821 g_mutex_lock (&av1enc->encoder_lock);
822 gst_av1_enc_set_latency (av1enc);
824 av1enc->aom_cfg.g_profile = gst_av1_enc_get_downstream_profile (av1enc);
826 /* Scale default bitrate to our size */
827 if (!av1enc->target_bitrate_set)
828 av1enc->aom_cfg.rc_target_bitrate =
829 gst_util_uint64_scale (DEFAULT_TARGET_BITRATE,
830 GST_VIDEO_INFO_WIDTH (info) * GST_VIDEO_INFO_HEIGHT (info), 320 * 240);
832 av1enc->aom_cfg.g_w = GST_VIDEO_INFO_WIDTH (info);
833 av1enc->aom_cfg.g_h = GST_VIDEO_INFO_HEIGHT (info);
834 /* Recommended method is to set the timebase to that of the parent
835 * container or multimedia framework (ex: 1/1000 for ms, as in FLV) */
836 if (GST_VIDEO_INFO_FPS_D (info) != 0 && GST_VIDEO_INFO_FPS_N (info) != 0) {
837 av1enc->aom_cfg.g_timebase.num = GST_VIDEO_INFO_FPS_D (info);
838 av1enc->aom_cfg.g_timebase.den = GST_VIDEO_INFO_FPS_N (info);
840 av1enc->aom_cfg.g_timebase.num = DEFAULT_TIMEBASE_N;
841 av1enc->aom_cfg.g_timebase.den = DEFAULT_TIMEBASE_D;
843 av1enc->aom_cfg.g_error_resilient = AOM_ERROR_RESILIENT_DEFAULT;
845 if (av1enc->threads == DEFAULT_THREADS)
846 av1enc->aom_cfg.g_threads = g_get_num_processors ();
848 av1enc->aom_cfg.g_threads = av1enc->threads;
849 /* TODO: do more configuration including bit_depth config */
852 gst_video_format_to_av1_img_format (GST_VIDEO_INFO_FORMAT (info));
854 if (av1enc->aom_cfg.g_bit_depth != DEFAULT_BIT_DEPTH) {
855 av1enc->aom_cfg.g_input_bit_depth = av1enc->aom_cfg.g_bit_depth;
856 if (av1enc->aom_cfg.g_bit_depth > 8)
857 av1enc->format |= AOM_IMG_FMT_HIGHBITDEPTH;
860 /* Adjust profile according to format and bit-depth */
861 gst_av1_enc_adjust_profile (av1enc, GST_VIDEO_INFO_FORMAT (info));
863 GST_DEBUG_OBJECT (av1enc, "Calling encoder init with config:");
864 gst_av1_enc_debug_encoder_cfg (&av1enc->aom_cfg);
866 if (aom_codec_enc_init (&av1enc->encoder, av1enc_class->codec_algo,
867 &av1enc->aom_cfg, 0)) {
868 gst_av1_codec_error (&av1enc->encoder, "Failed to initialize encoder");
869 g_mutex_unlock (&av1enc->encoder_lock);
872 av1enc->encoder_inited = TRUE;
874 GST_AV1_ENC_APPLY_CODEC_CONTROL (av1enc, AOME_SET_CPUUSED, av1enc->cpu_used);
875 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
876 GST_AV1_ENC_APPLY_CODEC_CONTROL (av1enc, AV1E_SET_ROW_MT,
877 (av1enc->row_mt ? 1 : 0));
879 GST_AV1_ENC_APPLY_CODEC_CONTROL (av1enc, AV1E_SET_TILE_COLUMNS,
880 av1enc->tile_columns);
881 GST_AV1_ENC_APPLY_CODEC_CONTROL (av1enc, AV1E_SET_TILE_ROWS,
883 g_mutex_unlock (&av1enc->encoder_lock);
889 gst_av1_enc_process (GstAV1Enc * encoder)
891 aom_codec_iter_t iter = NULL;
892 const aom_codec_cx_pkt_t *pkt;
893 GstVideoCodecFrame *frame;
894 GstVideoEncoder *video_encoder;
895 GstFlowReturn ret = GST_FLOW_CUSTOM_SUCCESS;
897 video_encoder = GST_VIDEO_ENCODER (encoder);
899 while ((pkt = aom_codec_get_cx_data (&encoder->encoder, &iter)) != NULL) {
900 if (pkt->kind == AOM_CODEC_STATS_PKT) {
901 GST_WARNING_OBJECT (encoder, "Unhandled stats packet");
902 } else if (pkt->kind == AOM_CODEC_FPMB_STATS_PKT) {
903 GST_WARNING_OBJECT (encoder, "Unhandled FPMB pkt");
904 } else if (pkt->kind == AOM_CODEC_PSNR_PKT) {
905 GST_WARNING_OBJECT (encoder, "Unhandled PSNR packet");
906 } else if (pkt->kind == AOM_CODEC_CX_FRAME_PKT) {
907 frame = gst_video_encoder_get_oldest_frame (video_encoder);
908 g_assert (frame != NULL);
909 if ((pkt->data.frame.flags & AOM_FRAME_IS_KEY) != 0) {
910 GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (frame);
912 GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT (frame);
915 frame->output_buffer =
916 gst_buffer_new_memdup (pkt->data.frame.buf, pkt->data.frame.sz);
918 if ((pkt->data.frame.flags & AOM_FRAME_IS_DROPPABLE) != 0)
919 GST_BUFFER_FLAG_SET (frame->output_buffer, GST_BUFFER_FLAG_DROPPABLE);
921 ret = gst_video_encoder_finish_frame (video_encoder, frame);
922 if (ret != GST_FLOW_OK)
931 gst_av1_enc_fill_image (GstAV1Enc * enc, GstVideoFrame * frame,
934 image->planes[AOM_PLANE_Y] = GST_VIDEO_FRAME_COMP_DATA (frame, 0);
935 image->planes[AOM_PLANE_U] = GST_VIDEO_FRAME_COMP_DATA (frame, 1);
936 image->planes[AOM_PLANE_V] = GST_VIDEO_FRAME_COMP_DATA (frame, 2);
938 image->stride[AOM_PLANE_Y] = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0);
939 image->stride[AOM_PLANE_U] = GST_VIDEO_FRAME_COMP_STRIDE (frame, 1);
940 image->stride[AOM_PLANE_V] = GST_VIDEO_FRAME_COMP_STRIDE (frame, 2);
944 gst_av1_enc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame)
946 GstAV1Enc *av1enc = GST_AV1_ENC_CAST (encoder);
949 GstFlowReturn ret = GST_FLOW_OK;
950 GstVideoFrame vframe;
951 aom_codec_pts_t scaled_pts;
953 unsigned long duration;
955 if (!aom_img_alloc (&raw, av1enc->format, av1enc->aom_cfg.g_w,
956 av1enc->aom_cfg.g_h, 1)) {
957 GST_ERROR_OBJECT (encoder, "Failed to initialize encoder");
961 gst_video_frame_map (&vframe, &av1enc->input_state->info,
962 frame->input_buffer, GST_MAP_READ);
963 gst_av1_enc_fill_image (av1enc, &vframe, &raw);
964 gst_video_frame_unmap (&vframe);
966 // aom_codec_encode requires pts to be strictly increasing
968 gst_segment_to_running_time (&encoder->input_segment,
969 GST_FORMAT_TIME, frame->pts);
971 if (GST_CLOCK_TIME_IS_VALID (av1enc->next_pts)
972 && pts_rt <= av1enc->next_pts) {
973 GST_WARNING_OBJECT (av1enc,
974 "decreasing pts %" GST_TIME_FORMAT " previous buffer was %"
975 GST_TIME_FORMAT " enforce increasing pts", GST_TIME_ARGS (pts_rt),
976 GST_TIME_ARGS (av1enc->next_pts));
977 pts_rt = av1enc->next_pts + 1;
980 av1enc->next_pts = pts_rt;
982 // Convert the pts from nanoseconds to timebase units
984 gst_util_uint64_scale_int (pts_rt,
985 av1enc->aom_cfg.g_timebase.den,
986 av1enc->aom_cfg.g_timebase.num * (GstClockTime) GST_SECOND);
988 if (frame->duration != GST_CLOCK_TIME_NONE) {
990 gst_util_uint64_scale (frame->duration, av1enc->aom_cfg.g_timebase.den,
991 av1enc->aom_cfg.g_timebase.num * (GstClockTime) GST_SECOND);
994 av1enc->next_pts += frame->duration;
996 /* We force the path ignoring the duration if we end up with a zero
997 * value for duration after scaling (e.g. duration value too small) */
998 GST_WARNING_OBJECT (av1enc,
999 "Ignoring too small frame duration %" GST_TIME_FORMAT,
1000 GST_TIME_ARGS (frame->duration));
1002 av1enc->next_pts += 1;
1006 av1enc->next_pts += 1;
1009 if (aom_codec_encode (&av1enc->encoder, &raw, scaled_pts, duration, flags)
1011 gst_av1_codec_error (&av1enc->encoder, "Failed to encode frame");
1012 ret = GST_FLOW_ERROR;
1015 aom_img_free (&raw);
1016 gst_video_codec_frame_unref (frame);
1018 if (ret == GST_FLOW_ERROR)
1021 ret = gst_av1_enc_process (av1enc);
1023 if (ret == GST_FLOW_CUSTOM_SUCCESS)
1029 static GstFlowReturn
1030 gst_av1_enc_finish (GstVideoEncoder * encoder)
1032 GstFlowReturn ret = GST_FLOW_OK;
1033 GstAV1Enc *av1enc = GST_AV1_ENC_CAST (encoder);
1034 aom_codec_pts_t scaled_pts;
1035 GstClockTime pts = 0;
1037 while (ret == GST_FLOW_OK) {
1038 GST_DEBUG_OBJECT (encoder, "Calling finish");
1039 g_mutex_lock (&av1enc->encoder_lock);
1041 if (GST_CLOCK_TIME_IS_VALID (av1enc->next_pts))
1042 pts = av1enc->next_pts;
1044 gst_util_uint64_scale (pts,
1045 av1enc->aom_cfg.g_timebase.den,
1046 av1enc->aom_cfg.g_timebase.num * (GstClockTime) GST_SECOND);
1048 if (aom_codec_encode (&av1enc->encoder, NULL, scaled_pts, 1, 0)
1050 gst_av1_codec_error (&av1enc->encoder, "Failed to encode frame");
1051 ret = GST_FLOW_ERROR;
1053 g_mutex_unlock (&av1enc->encoder_lock);
1055 ret = gst_av1_enc_process (av1enc);
1059 if (ret == GST_FLOW_CUSTOM_SUCCESS)
1066 gst_av1_enc_destroy_encoder (GstAV1Enc * av1enc)
1068 g_mutex_lock (&av1enc->encoder_lock);
1069 if (av1enc->encoder_inited) {
1070 aom_codec_destroy (&av1enc->encoder);
1071 av1enc->encoder_inited = FALSE;
1074 av1enc->next_pts = GST_CLOCK_TIME_NONE;
1076 g_mutex_unlock (&av1enc->encoder_lock);
1080 gst_av1_enc_propose_allocation (GstVideoEncoder * encoder, GstQuery * query)
1082 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
1084 return GST_VIDEO_ENCODER_CLASS (parent_class)->propose_allocation (encoder,
1089 gst_av1_enc_set_property (GObject * object, guint prop_id,
1090 const GValue * value, GParamSpec * pspec)
1092 GstAV1Enc *av1enc = GST_AV1_ENC_CAST (object);
1093 gboolean global = FALSE;
1094 aom_codec_err_t status;
1096 GST_OBJECT_LOCK (av1enc);
1098 g_mutex_lock (&av1enc->encoder_lock);
1101 av1enc->cpu_used = g_value_get_int (value);
1102 GST_AV1_ENC_APPLY_CODEC_CONTROL (av1enc, AOME_SET_CPUUSED,
1105 case PROP_DROP_FRAME:
1106 av1enc->aom_cfg.rc_dropframe_thresh = g_value_get_uint (value);
1109 case PROP_RESIZE_MODE:
1110 av1enc->aom_cfg.rc_resize_mode = g_value_get_enum (value);
1113 case PROP_RESIZE_DENOMINATOR:
1114 av1enc->aom_cfg.rc_resize_denominator = g_value_get_uint (value);
1117 case PROP_RESIZE_KF_DENOMINATOR:
1118 av1enc->aom_cfg.rc_resize_kf_denominator = g_value_get_uint (value);
1121 case PROP_SUPERRES_MODE:
1122 av1enc->aom_cfg.rc_superres_mode = g_value_get_enum (value);
1125 case PROP_SUPERRES_DENOMINATOR:
1126 av1enc->aom_cfg.rc_superres_denominator = g_value_get_uint (value);
1129 case PROP_SUPERRES_KF_DENOMINATOR:
1130 av1enc->aom_cfg.rc_superres_kf_denominator = g_value_get_uint (value);
1133 case PROP_SUPERRES_QTHRESH:
1134 av1enc->aom_cfg.rc_superres_qthresh = g_value_get_uint (value);
1137 case PROP_SUPERRES_KF_QTHRESH:
1138 av1enc->aom_cfg.rc_superres_kf_qthresh = g_value_get_uint (value);
1141 case PROP_END_USAGE:
1142 av1enc->aom_cfg.rc_end_usage = g_value_get_enum (value);
1145 case PROP_TARGET_BITRATE:
1146 av1enc->aom_cfg.rc_target_bitrate = g_value_get_uint (value);
1147 av1enc->target_bitrate_set = TRUE;
1150 case PROP_MIN_QUANTIZER:
1151 av1enc->aom_cfg.rc_min_quantizer = g_value_get_uint (value);
1154 case PROP_MAX_QUANTIZER:
1155 av1enc->aom_cfg.rc_max_quantizer = g_value_get_uint (value);
1158 case PROP_UNDERSHOOT_PCT:
1159 av1enc->aom_cfg.rc_undershoot_pct = g_value_get_uint (value);
1162 case PROP_OVERSHOOT_PCT:
1163 av1enc->aom_cfg.rc_overshoot_pct = g_value_get_uint (value);
1167 av1enc->aom_cfg.rc_buf_sz = g_value_get_uint (value);
1170 case PROP_BUF_INITIAL_SZ:
1171 av1enc->aom_cfg.rc_buf_initial_sz = g_value_get_uint (value);
1174 case PROP_BUF_OPTIMAL_SZ:
1175 av1enc->aom_cfg.rc_buf_optimal_sz = g_value_get_uint (value);
1179 av1enc->threads = g_value_get_uint (value);
1182 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
1184 av1enc->row_mt = g_value_get_boolean (value);
1185 GST_AV1_ENC_APPLY_CODEC_CONTROL (av1enc, AV1E_SET_ROW_MT,
1186 (av1enc->row_mt ? 1 : 0));
1189 case PROP_TILE_COLUMNS:
1190 av1enc->tile_columns = g_value_get_uint (value);
1191 GST_AV1_ENC_APPLY_CODEC_CONTROL (av1enc, AV1E_SET_TILE_COLUMNS,
1192 av1enc->tile_columns);
1194 case PROP_TILE_ROWS:
1195 av1enc->tile_rows = g_value_get_uint (value);
1196 GST_AV1_ENC_APPLY_CODEC_CONTROL (av1enc, AV1E_SET_TILE_ROWS,
1200 av1enc->aom_cfg.kf_mode = g_value_get_enum (value);
1204 av1enc->aom_cfg.g_pass = g_value_get_enum (value);
1207 case PROP_USAGE_PROFILE:
1208 av1enc->aom_cfg.g_usage = g_value_get_enum (value);
1211 case PROP_LAG_IN_FRAMES:
1212 av1enc->aom_cfg.g_lag_in_frames = g_value_get_uint (value);
1215 case PROP_KEYFRAME_MAX_DIST:
1216 av1enc->aom_cfg.kf_max_dist = g_value_get_int (value);
1220 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1224 if (global &&av1enc->encoder_inited) {
1225 status = aom_codec_enc_config_set (&av1enc->encoder, &av1enc->aom_cfg);
1226 GST_DEBUG_OBJECT (av1enc, "Set %s encoder configuration, ret = %s",
1227 pspec->name, gst_av1_get_error_name (status));
1230 g_mutex_unlock (&av1enc->encoder_lock);
1231 GST_OBJECT_UNLOCK (av1enc);
1235 gst_av1_enc_get_property (GObject * object, guint prop_id, GValue * value,
1238 GstAV1Enc *av1enc = GST_AV1_ENC_CAST (object);
1240 GST_OBJECT_LOCK (av1enc);
1244 g_value_set_int (value, av1enc->cpu_used);
1246 case PROP_DROP_FRAME:
1247 g_value_set_uint (value, av1enc->aom_cfg.rc_dropframe_thresh);
1249 case PROP_RESIZE_MODE:
1250 g_value_set_enum (value, av1enc->aom_cfg.rc_resize_mode);
1252 case PROP_RESIZE_DENOMINATOR:
1253 g_value_set_uint (value, av1enc->aom_cfg.rc_resize_denominator);
1255 case PROP_RESIZE_KF_DENOMINATOR:
1256 g_value_set_uint (value, av1enc->aom_cfg.rc_resize_kf_denominator);
1258 case PROP_SUPERRES_MODE:
1259 g_value_set_enum (value, av1enc->aom_cfg.rc_superres_mode);
1261 case PROP_SUPERRES_DENOMINATOR:
1262 g_value_set_uint (value, av1enc->aom_cfg.rc_superres_denominator);
1264 case PROP_SUPERRES_KF_DENOMINATOR:
1265 g_value_set_uint (value, av1enc->aom_cfg.rc_superres_kf_denominator);
1267 case PROP_SUPERRES_QTHRESH:
1268 g_value_set_uint (value, av1enc->aom_cfg.rc_superres_qthresh);
1270 case PROP_SUPERRES_KF_QTHRESH:
1271 g_value_set_uint (value, av1enc->aom_cfg.rc_superres_kf_qthresh);
1273 case PROP_END_USAGE:
1274 g_value_set_enum (value, av1enc->aom_cfg.rc_end_usage);
1276 case PROP_TARGET_BITRATE:
1277 g_value_set_uint (value, av1enc->aom_cfg.rc_target_bitrate);
1279 case PROP_MIN_QUANTIZER:
1280 g_value_set_uint (value, av1enc->aom_cfg.rc_min_quantizer);
1282 case PROP_MAX_QUANTIZER:
1283 g_value_set_uint (value, av1enc->aom_cfg.rc_max_quantizer);
1285 case PROP_UNDERSHOOT_PCT:
1286 g_value_set_uint (value, av1enc->aom_cfg.rc_undershoot_pct);
1288 case PROP_OVERSHOOT_PCT:
1289 g_value_set_uint (value, av1enc->aom_cfg.rc_overshoot_pct);
1292 g_value_set_uint (value, av1enc->aom_cfg.rc_buf_sz);
1294 case PROP_BUF_INITIAL_SZ:
1295 g_value_set_uint (value, av1enc->aom_cfg.rc_buf_initial_sz);
1297 case PROP_BUF_OPTIMAL_SZ:
1298 g_value_set_uint (value, av1enc->aom_cfg.rc_buf_optimal_sz);
1301 g_value_set_uint (value, av1enc->threads);
1303 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
1305 g_value_set_boolean (value, av1enc->row_mt);
1308 case PROP_TILE_COLUMNS:
1309 g_value_set_uint (value, av1enc->tile_columns);
1311 case PROP_TILE_ROWS:
1312 g_value_set_uint (value, av1enc->tile_rows);
1315 g_value_set_enum (value, av1enc->aom_cfg.kf_mode);
1318 g_value_set_enum (value, av1enc->aom_cfg.g_pass);
1320 case PROP_USAGE_PROFILE:
1321 g_value_set_enum (value, av1enc->aom_cfg.g_usage);
1323 case PROP_LAG_IN_FRAMES:
1324 g_value_set_uint (value, av1enc->aom_cfg.g_lag_in_frames);
1326 case PROP_KEYFRAME_MAX_DIST:
1327 g_value_set_int (value, av1enc->aom_cfg.kf_max_dist);
1330 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1334 GST_OBJECT_UNLOCK (av1enc);
1338 gst_av1_enc_start (GstVideoEncoder * encoder)
1344 gst_av1_enc_stop (GstVideoEncoder * encoder)
1346 GstAV1Enc *av1enc = GST_AV1_ENC_CAST (encoder);
1348 if (av1enc->input_state) {
1349 gst_video_codec_state_unref (av1enc->input_state);
1351 av1enc->input_state = NULL;
1353 gst_av1_enc_destroy_encoder (av1enc);