mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 10:11:08 +00:00
av1enc: Add configurations
Added rate control and profile related configuration. The profile configuration has been copied from vpx. https://bugzilla.gnome.org/show_bug.cgi?id=791674
This commit is contained in:
parent
498dc9a84d
commit
7d73307bc4
6 changed files with 580 additions and 23 deletions
|
@ -3,7 +3,8 @@ plugin_LTLIBRARIES = libgstaom.la
|
|||
libgstaom_la_SOURCES = \
|
||||
gstaom.c \
|
||||
gstav1enc.c \
|
||||
gstav1dec.c
|
||||
gstav1dec.c \
|
||||
gstav1utils.c
|
||||
|
||||
libgstaom_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(AOM_CFLAGS)
|
||||
libgstaom_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) -lgstvideo-$(GST_API_VERSION) $(AOM_LIBS)
|
||||
|
@ -12,4 +13,5 @@ libgstaom_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
|||
noinst_HEADERS = \
|
||||
gstaom.h \
|
||||
gstav1dec.h \
|
||||
gstav1enc.h
|
||||
gstav1enc.h \
|
||||
gstav1utils.h
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#endif
|
||||
|
||||
#include "gstav1enc.h"
|
||||
#include "gstav1utils.h"
|
||||
#include <gst/video/video.h>
|
||||
#include <gst/video/gstvideometa.h>
|
||||
#include <gst/base/base.h>
|
||||
|
@ -49,6 +50,73 @@
|
|||
GST_DEBUG_CATEGORY_STATIC (av1_enc_debug);
|
||||
#define GST_CAT_DEFAULT av1_enc_debug
|
||||
|
||||
#define GST_TYPE_RESIZE_MODE (gst_resize_mode_get_type())
|
||||
static GType
|
||||
gst_resize_mode_get_type (void)
|
||||
{
|
||||
static GType resize_mode_type = 0;
|
||||
static const GEnumValue resize_mode[] = {
|
||||
{GST_AV1_ENC_RESIZE_NONE, "No frame resizing allowed", "none"},
|
||||
{GST_AV1_ENC_RESIZE_FIXED, "All frames are coded at the specified scale",
|
||||
"fixed"},
|
||||
{GST_AV1_ENC_RESIZE_RANDOM, "All frames are coded at a random scale",
|
||||
"random"},
|
||||
{0, NULL, NULL},
|
||||
};
|
||||
|
||||
if (!resize_mode_type) {
|
||||
resize_mode_type =
|
||||
g_enum_register_static ("GstAV1EncResizeMode", resize_mode);
|
||||
}
|
||||
return resize_mode_type;
|
||||
}
|
||||
|
||||
#define GST_TYPE_SUPERRES_MODE (gst_superres_mode_get_type())
|
||||
static GType
|
||||
gst_superres_mode_get_type (void)
|
||||
{
|
||||
static GType superres_mode_type = 0;
|
||||
static const GEnumValue superres_mode[] = {
|
||||
{GST_AV1_ENC_SUPERRES_NONE, "No frame superres allowed", "none"},
|
||||
{GST_AV1_ENC_SUPERRES_FIXED,
|
||||
"All frames are coded at the specified scale and super-resolved",
|
||||
"fixed"},
|
||||
{GST_AV1_ENC_SUPERRES_RANDOM,
|
||||
"All frames are coded at a random scale and super-resolved",
|
||||
"random"},
|
||||
{GST_AV1_ENC_SUPERRES_QTHRESH,
|
||||
"Superres scale for a frame is determined based on q_index",
|
||||
"qthresh"},
|
||||
{0, NULL, NULL},
|
||||
};
|
||||
|
||||
if (!superres_mode_type) {
|
||||
superres_mode_type =
|
||||
g_enum_register_static ("GstAV1EncSuperresMode", superres_mode);
|
||||
}
|
||||
return superres_mode_type;
|
||||
}
|
||||
|
||||
#define GST_TYPE_END_USAGE_MODE (gst_end_usage_mode_get_type())
|
||||
static GType
|
||||
gst_end_usage_mode_get_type (void)
|
||||
{
|
||||
static GType end_usage_mode_type = 0;
|
||||
static const GEnumValue end_usage_mode[] = {
|
||||
{GST_AV1_ENC_END_USAGE_VBR, "Variable Bit Rate Mode", "vbr"},
|
||||
{GST_AV1_ENC_END_USAGE_CBR, "Constant Bit Rate Mode", "cbr"},
|
||||
{GST_AV1_ENC_END_USAGE_CQ, "Constrained Quality Mode", "cq"},
|
||||
{GST_AV1_ENC_END_USAGE_Q, "Constant Quality Mode", "q"},
|
||||
{0, NULL, NULL},
|
||||
};
|
||||
|
||||
if (!end_usage_mode_type) {
|
||||
end_usage_mode_type =
|
||||
g_enum_register_static ("GstAV1EncEndUsageMode", end_usage_mode);
|
||||
}
|
||||
return end_usage_mode_type;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
LAST_SIGNAL
|
||||
|
@ -57,10 +125,51 @@ enum
|
|||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CPU_USED
|
||||
PROP_CPU_USED,
|
||||
PROP_DROP_FRAME,
|
||||
PROP_RESIZE_MODE,
|
||||
PROP_RESIZE_DENOMINATOR,
|
||||
PROP_RESIZE_KF_DENOMINATOR,
|
||||
PROP_SUPERRES_MODE,
|
||||
PROP_SUPERRES_DENOMINATOR,
|
||||
PROP_SUPERRES_KF_DENOMINATOR,
|
||||
PROP_SUPERRES_QTHRESH,
|
||||
PROP_SUPERRES_KF_QTHRESH,
|
||||
PROP_END_USAGE,
|
||||
PROP_TARGET_BITRATE,
|
||||
PROP_MIN_QUANTIZER,
|
||||
PROP_MAX_QUANTIZER,
|
||||
PROP_UNDERSHOOT_PCT,
|
||||
PROP_OVERSHOOT_PCT,
|
||||
PROP_BUF_SZ,
|
||||
PROP_BUF_INITIAL_SZ,
|
||||
PROP_BUF_OPTIMAL_SZ
|
||||
};
|
||||
|
||||
#define PROP_CPU_USED_DEFAULT 0
|
||||
/* From av1/av1_cx_iface.c */
|
||||
#define DEFAULT_PROFILE 0
|
||||
#define DEFAULT_CPU_USED 0
|
||||
#define DEFAULT_DROP_FRAME 0
|
||||
#define DEFAULT_RESIZE_MODE GST_AV1_ENC_RESIZE_NONE
|
||||
#define DEFAULT_RESIZE_DENOMINATOR 8
|
||||
#define DEFAULT_RESIZE_KF_DENOMINATOR 8
|
||||
#define DEFAULT_SUPERRES_MODE GST_AV1_ENC_SUPERRES_NONE
|
||||
#define DEFAULT_SUPERRES_DENOMINATOR 8
|
||||
#define DEFAULT_SUPERRES_KF_DENOMINATOR 8
|
||||
#define DEFAULT_SUPERRES_QTHRESH 63
|
||||
#define DEFAULT_SUPERRES_KF_QTHRESH 63
|
||||
#define DEFAULT_END_USAGE GST_AV1_ENC_END_USAGE_VBR
|
||||
#define DEFAULT_TARGET_BITRATE 256
|
||||
#define DEFAULT_MIN_QUANTIZER 0
|
||||
#define DEFAULT_MAX_QUANTIZER 0
|
||||
#define DEFAULT_UNDERSHOOT_PCT 25
|
||||
#define DEFAULT_OVERSHOOT_PCT 25
|
||||
#define DEFAULT_BUF_SZ 6000
|
||||
#define DEFAULT_BUF_INITIAL_SZ 4000
|
||||
#define DEFAULT_BUF_OPTIMAL_SZ 5000
|
||||
#define DEFAULT_TIMEBASE_N 1
|
||||
#define DEFAULT_TIMEBASE_D 30
|
||||
#define DEFAULT_BIT_DEPTH AOM_BITS_8
|
||||
|
||||
static void gst_av1_enc_finalize (GObject * object);
|
||||
static void gst_av1_enc_set_property (GObject * object, guint prop_id,
|
||||
|
@ -141,7 +250,118 @@ gst_av1_enc_class_init (GstAV1EncClass * klass)
|
|||
g_object_class_install_property (gobject_class, PROP_CPU_USED,
|
||||
g_param_spec_int ("cpu-used", "CPU Used",
|
||||
"CPU Used. A Value greater than 0 will increase encoder speed at the expense of quality.",
|
||||
0, 8, PROP_CPU_USED_DEFAULT,
|
||||
0, 8, DEFAULT_CPU_USED, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/* Rate control configurations */
|
||||
g_object_class_install_property (gobject_class, PROP_DROP_FRAME,
|
||||
g_param_spec_uint ("drop-frame", "Drop frame",
|
||||
"Temporal resampling configuration, drop frames as a strategy to meet "
|
||||
"its target data rate Set to zero (0) to disable this feature.",
|
||||
0, G_MAXUINT, DEFAULT_DROP_FRAME,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_RESIZE_MODE,
|
||||
g_param_spec_enum ("resize-mode", "Resize mode",
|
||||
"Frame resize mode", GST_TYPE_RESIZE_MODE,
|
||||
DEFAULT_RESIZE_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_RESIZE_DENOMINATOR,
|
||||
g_param_spec_uint ("resize-denominator", "Resize denominator",
|
||||
"Frame resize denominator, assuming 8 as the numerator",
|
||||
8, 16, DEFAULT_RESIZE_DENOMINATOR,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_RESIZE_KF_DENOMINATOR,
|
||||
g_param_spec_uint ("resize-kf-denominator", "Resize keyframe denominator",
|
||||
"Frame resize keyframe denominator, assuming 8 as the numerator",
|
||||
8, 16, DEFAULT_RESIZE_KF_DENOMINATOR,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_SUPERRES_MODE,
|
||||
g_param_spec_enum ("superres-mode", "Super-resolution scaling mode",
|
||||
"It integrates upscaling after the encode/decode process",
|
||||
GST_TYPE_SUPERRES_MODE,
|
||||
DEFAULT_SUPERRES_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_SUPERRES_DENOMINATOR,
|
||||
g_param_spec_uint ("superres-denominator", "Super-resolution denominator",
|
||||
"Frame super-resolution denominator, used only by SUPERRES_FIXED mode",
|
||||
8, 16, DEFAULT_SUPERRES_DENOMINATOR,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_SUPERRES_KF_DENOMINATOR,
|
||||
g_param_spec_uint ("superres-kf-denominator",
|
||||
"Keyframe super-resolution denominator",
|
||||
"Keyframe super-resolution denominator",
|
||||
8, 16, DEFAULT_SUPERRES_KF_DENOMINATOR,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_SUPERRES_QTHRESH,
|
||||
g_param_spec_uint ("superres-qthresh",
|
||||
"Frame super-resolution qindex threshold",
|
||||
"Frame super-resolution qindex threshold, used only by SUPERRES_QTHRESH mode",
|
||||
1, 63, DEFAULT_SUPERRES_QTHRESH,
|
||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_SUPERRES_KF_QTHRESH,
|
||||
g_param_spec_uint ("superres-kf-qthresh",
|
||||
"Keyframe super-resolution qindex threshold",
|
||||
"Keyframe super-resolution qindex threshold, used only by SUPERRES_QTHRESH mode",
|
||||
1, 63, DEFAULT_SUPERRES_KF_QTHRESH,
|
||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_END_USAGE,
|
||||
g_param_spec_enum ("end-usage", "Rate control mode",
|
||||
"Rate control algorithm to use, indicates the end usage of this stream",
|
||||
GST_TYPE_END_USAGE_MODE, DEFAULT_END_USAGE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_TARGET_BITRATE,
|
||||
g_param_spec_uint ("target-bitrate", "Target bitrate",
|
||||
"Target bitrate, in kilobits per second",
|
||||
1, G_MAXUINT, DEFAULT_TARGET_BITRATE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_MIN_QUANTIZER,
|
||||
g_param_spec_uint ("min-quantizer", "Minimum (best quality) quantizer",
|
||||
"Mininum (best quality) quantizer",
|
||||
0, G_MAXUINT, DEFAULT_MIN_QUANTIZER,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_MAX_QUANTIZER,
|
||||
g_param_spec_uint ("max-quantizer", "Maximum (worst quality) quantizer",
|
||||
"Maximum (worst quality) quantizer",
|
||||
0, G_MAXUINT, DEFAULT_MAX_QUANTIZER,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_UNDERSHOOT_PCT,
|
||||
g_param_spec_uint ("undershoot-pct", "Datarate undershoot (min) target",
|
||||
"Rate control adaptation undershoot control",
|
||||
0, 1000, DEFAULT_UNDERSHOOT_PCT,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_OVERSHOOT_PCT,
|
||||
g_param_spec_uint ("overshoot-pct", "Datarate overshoot (max) target",
|
||||
"Rate control adaptation overshoot control",
|
||||
0, 1000, DEFAULT_OVERSHOOT_PCT,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_BUF_SZ,
|
||||
g_param_spec_uint ("buf-sz", "Decoder buffer size",
|
||||
"Decoder buffer size, expressed in units of time (milliseconds)",
|
||||
0, G_MAXUINT, DEFAULT_BUF_SZ,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_BUF_INITIAL_SZ,
|
||||
g_param_spec_uint ("buf-initial-sz", "Decoder buffer initial size",
|
||||
"Decoder buffer initial size, expressed in units of time (milliseconds)",
|
||||
0, G_MAXUINT, DEFAULT_BUF_INITIAL_SZ,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_BUF_OPTIMAL_SZ,
|
||||
g_param_spec_uint ("buf-optimal-sz", "Decoder buffer optimal size",
|
||||
"Decoder buffer optimal size, expressed in units of time (milliseconds)",
|
||||
0, G_MAXUINT, DEFAULT_BUF_OPTIMAL_SZ,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
|
@ -161,7 +381,30 @@ gst_av1_enc_init (GstAV1Enc * av1enc)
|
|||
av1enc->encoder_inited = FALSE;
|
||||
|
||||
av1enc->keyframe_dist = 30;
|
||||
av1enc->cpu_used = PROP_CPU_USED_DEFAULT;
|
||||
av1enc->cpu_used = DEFAULT_CPU_USED;
|
||||
|
||||
av1enc->aom_cfg.rc_dropframe_thresh = DEFAULT_DROP_FRAME;
|
||||
av1enc->aom_cfg.rc_resize_mode = DEFAULT_RESIZE_MODE;
|
||||
av1enc->aom_cfg.rc_resize_denominator = DEFAULT_RESIZE_DENOMINATOR;
|
||||
av1enc->aom_cfg.rc_resize_kf_denominator = DEFAULT_RESIZE_KF_DENOMINATOR;
|
||||
av1enc->aom_cfg.rc_superres_mode = DEFAULT_SUPERRES_MODE;
|
||||
av1enc->aom_cfg.rc_superres_denominator = DEFAULT_SUPERRES_DENOMINATOR;
|
||||
av1enc->aom_cfg.rc_superres_kf_denominator = DEFAULT_SUPERRES_KF_DENOMINATOR;
|
||||
av1enc->aom_cfg.rc_superres_qthresh = DEFAULT_SUPERRES_QTHRESH;
|
||||
av1enc->aom_cfg.rc_superres_kf_qthresh = DEFAULT_SUPERRES_KF_QTHRESH;
|
||||
av1enc->aom_cfg.rc_end_usage = DEFAULT_END_USAGE;
|
||||
av1enc->aom_cfg.rc_target_bitrate = DEFAULT_TARGET_BITRATE;
|
||||
av1enc->aom_cfg.rc_min_quantizer = DEFAULT_MIN_QUANTIZER;
|
||||
av1enc->aom_cfg.rc_max_quantizer = DEFAULT_MAX_QUANTIZER;
|
||||
av1enc->aom_cfg.rc_undershoot_pct = DEFAULT_UNDERSHOOT_PCT;
|
||||
av1enc->aom_cfg.rc_overshoot_pct = DEFAULT_OVERSHOOT_PCT;
|
||||
av1enc->aom_cfg.rc_buf_sz = DEFAULT_BUF_SZ;
|
||||
av1enc->aom_cfg.rc_buf_initial_sz = DEFAULT_BUF_INITIAL_SZ;
|
||||
av1enc->aom_cfg.rc_buf_optimal_sz = DEFAULT_BUF_OPTIMAL_SZ;
|
||||
av1enc->aom_cfg.g_timebase.num = DEFAULT_TIMEBASE_N;
|
||||
av1enc->aom_cfg.g_timebase.den = DEFAULT_TIMEBASE_D;
|
||||
av1enc->aom_cfg.g_bit_depth = DEFAULT_BIT_DEPTH;
|
||||
av1enc->aom_cfg.g_input_bit_depth = (int) DEFAULT_BIT_DEPTH;
|
||||
|
||||
g_mutex_init (&av1enc->encoder_lock);
|
||||
}
|
||||
|
@ -270,12 +513,52 @@ gst_av1_enc_debug_encoder_cfg (struct aom_codec_enc_cfg *cfg)
|
|||
/* Tile-related values */
|
||||
}
|
||||
|
||||
static gint
|
||||
gst_av1_enc_get_downstream_profile (GstAV1Enc * av1enc)
|
||||
{
|
||||
GstCaps *allowed;
|
||||
GstStructure *s;
|
||||
gint profile = DEFAULT_PROFILE;
|
||||
|
||||
allowed = gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (av1enc));
|
||||
if (allowed) {
|
||||
allowed = gst_caps_truncate (allowed);
|
||||
s = gst_caps_get_structure (allowed, 0);
|
||||
if (gst_structure_has_field (s, "profile")) {
|
||||
const GValue *v = gst_structure_get_value (s, "profile");
|
||||
const gchar *profile_str = NULL;
|
||||
|
||||
if (GST_VALUE_HOLDS_LIST (v) && gst_value_list_get_size (v) > 0) {
|
||||
profile_str = g_value_get_string (gst_value_list_get_value (v, 0));
|
||||
} else if (G_VALUE_HOLDS_STRING (v)) {
|
||||
profile_str = g_value_get_string (v);
|
||||
}
|
||||
|
||||
if (profile_str) {
|
||||
gchar *endptr = NULL;
|
||||
|
||||
profile = g_ascii_strtoull (profile_str, &endptr, 10);
|
||||
if (*endptr != '\0' || profile < 0 || profile > 3) {
|
||||
GST_ERROR_OBJECT (av1enc, "Invalid profile '%s'", profile_str);
|
||||
profile = DEFAULT_PROFILE;
|
||||
}
|
||||
}
|
||||
}
|
||||
gst_caps_unref (allowed);
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (av1enc, "Using profile %d", profile);
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_av1_enc_set_format (GstVideoEncoder * encoder, GstVideoCodecState * state)
|
||||
{
|
||||
GstVideoCodecState *output_state;
|
||||
GstAV1Enc *av1enc = GST_AV1_ENC_CAST (encoder);
|
||||
GstAV1EncClass *av1enc_class = GST_AV1_ENC_GET_CLASS (av1enc);
|
||||
GstVideoInfo *info = &state->info;
|
||||
|
||||
output_state =
|
||||
gst_video_encoder_set_output_state (encoder,
|
||||
|
@ -289,24 +572,24 @@ gst_av1_enc_set_format (GstVideoEncoder * encoder, GstVideoCodecState * state)
|
|||
av1enc->input_state = gst_video_codec_state_ref (state);
|
||||
|
||||
g_mutex_lock (&av1enc->encoder_lock);
|
||||
if (aom_codec_enc_config_default (av1enc_class->codec_algo, &av1enc->aom_cfg,
|
||||
0)) {
|
||||
gst_av1_codec_error (&av1enc->encoder,
|
||||
"Failed to get default codec config.");
|
||||
return FALSE;
|
||||
}
|
||||
GST_DEBUG_OBJECT (av1enc, "Got default encoder config");
|
||||
gst_av1_enc_debug_encoder_cfg (&av1enc->aom_cfg);
|
||||
|
||||
gst_av1_enc_set_latency (av1enc);
|
||||
|
||||
av1enc->aom_cfg.g_w = av1enc->input_state->info.width;
|
||||
av1enc->aom_cfg.g_h = av1enc->input_state->info.height;
|
||||
av1enc->aom_cfg.g_timebase.num = av1enc->input_state->info.fps_d;
|
||||
av1enc->aom_cfg.g_timebase.den = av1enc->input_state->info.fps_n;
|
||||
/* FIXME : Make configuration properties */
|
||||
av1enc->aom_cfg.rc_target_bitrate = 3000;
|
||||
av1enc->aom_cfg.g_profile = gst_av1_enc_get_downstream_profile (av1enc);
|
||||
|
||||
/* Scale default bitrate to our size */
|
||||
if (!av1enc->target_bitrate_set)
|
||||
av1enc->aom_cfg.rc_target_bitrate =
|
||||
gst_util_uint64_scale (DEFAULT_TARGET_BITRATE,
|
||||
GST_VIDEO_INFO_WIDTH (info) * GST_VIDEO_INFO_HEIGHT (info), 320 * 240);
|
||||
|
||||
av1enc->aom_cfg.g_w = GST_VIDEO_INFO_WIDTH (info);
|
||||
av1enc->aom_cfg.g_h = GST_VIDEO_INFO_HEIGHT (info);
|
||||
/* Recommended method is to set the timebase to that of the parent
|
||||
* container or multimedia framework (ex: 1/1000 for ms, as in FLV) */
|
||||
av1enc->aom_cfg.g_timebase.num = GST_VIDEO_INFO_FPS_D (info);
|
||||
av1enc->aom_cfg.g_timebase.den = GST_VIDEO_INFO_FPS_N (info);
|
||||
av1enc->aom_cfg.g_error_resilient = AOM_ERROR_RESILIENT_DEFAULT;
|
||||
/* TODO: do more configuration including bit_depth config */
|
||||
|
||||
GST_DEBUG_OBJECT (av1enc, "Calling encoder init with config:");
|
||||
gst_av1_enc_debug_encoder_cfg (&av1enc->aom_cfg);
|
||||
|
@ -360,6 +643,7 @@ gst_av1_enc_process (GstAV1Enc * encoder)
|
|||
if ((pkt->data.frame.flags & AOM_FRAME_IS_INVISIBLE) != 0)
|
||||
GST_BUFFER_FLAG_SET (frame->output_buffer, GST_BUFFER_FLAG_DECODE_ONLY);
|
||||
|
||||
|
||||
ret = gst_video_encoder_finish_frame (video_encoder, frame);
|
||||
if (ret != GST_FLOW_OK)
|
||||
break;
|
||||
|
@ -481,6 +765,8 @@ gst_av1_enc_set_property (GObject * object, guint prop_id,
|
|||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstAV1Enc *av1enc = GST_AV1_ENC_CAST (object);
|
||||
gboolean global = FALSE;
|
||||
aom_codec_err_t status;
|
||||
|
||||
GST_OBJECT_LOCK (av1enc);
|
||||
|
||||
|
@ -491,12 +777,91 @@ gst_av1_enc_set_property (GObject * object, guint prop_id,
|
|||
GST_AV1_ENC_APPLY_CODEC_CONTROL (av1enc, AOME_SET_CPUUSED,
|
||||
av1enc->cpu_used);
|
||||
break;
|
||||
case PROP_DROP_FRAME:
|
||||
av1enc->aom_cfg.rc_dropframe_thresh = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_RESIZE_MODE:
|
||||
av1enc->aom_cfg.rc_resize_mode = g_value_get_enum (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_RESIZE_DENOMINATOR:
|
||||
av1enc->aom_cfg.rc_resize_denominator = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_RESIZE_KF_DENOMINATOR:
|
||||
av1enc->aom_cfg.rc_resize_kf_denominator = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_SUPERRES_MODE:
|
||||
av1enc->aom_cfg.rc_superres_mode = g_value_get_enum (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_SUPERRES_DENOMINATOR:
|
||||
av1enc->aom_cfg.rc_superres_denominator = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_SUPERRES_KF_DENOMINATOR:
|
||||
av1enc->aom_cfg.rc_superres_kf_denominator = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_SUPERRES_QTHRESH:
|
||||
av1enc->aom_cfg.rc_superres_qthresh = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_SUPERRES_KF_QTHRESH:
|
||||
av1enc->aom_cfg.rc_superres_kf_qthresh = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_END_USAGE:
|
||||
av1enc->aom_cfg.rc_end_usage = g_value_get_enum (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_TARGET_BITRATE:
|
||||
av1enc->aom_cfg.rc_target_bitrate = g_value_get_uint (value);
|
||||
av1enc->target_bitrate_set = TRUE;
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_MIN_QUANTIZER:
|
||||
av1enc->aom_cfg.rc_min_quantizer = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_MAX_QUANTIZER:
|
||||
av1enc->aom_cfg.rc_max_quantizer = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_UNDERSHOOT_PCT:
|
||||
av1enc->aom_cfg.rc_undershoot_pct = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_OVERSHOOT_PCT:
|
||||
av1enc->aom_cfg.rc_overshoot_pct = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_BUF_SZ:
|
||||
av1enc->aom_cfg.rc_buf_sz = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_BUF_INITIAL_SZ:
|
||||
av1enc->aom_cfg.rc_buf_initial_sz = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
case PROP_BUF_OPTIMAL_SZ:
|
||||
av1enc->aom_cfg.rc_buf_optimal_sz = g_value_get_uint (value);
|
||||
global = TRUE;
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
g_mutex_unlock (&av1enc->encoder_lock);
|
||||
|
||||
if (global &&av1enc->encoder_inited) {
|
||||
status = aom_codec_enc_config_set (&av1enc->encoder, &av1enc->aom_cfg);
|
||||
GST_DEBUG_OBJECT (av1enc, "Set %s encoder configuration, ret = %s",
|
||||
pspec->name, gst_av1_get_error_name (status));
|
||||
}
|
||||
|
||||
g_mutex_unlock (&av1enc->encoder_lock);
|
||||
GST_OBJECT_UNLOCK (av1enc);
|
||||
}
|
||||
|
||||
|
@ -512,6 +877,60 @@ gst_av1_enc_get_property (GObject * object, guint prop_id, GValue * value,
|
|||
case PROP_CPU_USED:
|
||||
g_value_set_int (value, av1enc->cpu_used);
|
||||
break;
|
||||
case PROP_DROP_FRAME:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_dropframe_thresh);
|
||||
break;
|
||||
case PROP_RESIZE_MODE:
|
||||
g_value_set_enum (value, av1enc->aom_cfg.rc_resize_mode);
|
||||
break;
|
||||
case PROP_RESIZE_DENOMINATOR:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_resize_denominator);
|
||||
break;
|
||||
case PROP_RESIZE_KF_DENOMINATOR:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_resize_kf_denominator);
|
||||
break;
|
||||
case PROP_SUPERRES_MODE:
|
||||
g_value_set_enum (value, av1enc->aom_cfg.rc_superres_mode);
|
||||
break;
|
||||
case PROP_SUPERRES_DENOMINATOR:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_superres_denominator);
|
||||
break;
|
||||
case PROP_SUPERRES_KF_DENOMINATOR:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_superres_kf_denominator);
|
||||
break;
|
||||
case PROP_SUPERRES_QTHRESH:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_superres_qthresh);
|
||||
break;
|
||||
case PROP_SUPERRES_KF_QTHRESH:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_superres_kf_qthresh);
|
||||
break;
|
||||
case PROP_END_USAGE:
|
||||
g_value_set_enum (value, av1enc->aom_cfg.rc_end_usage);
|
||||
break;
|
||||
case PROP_TARGET_BITRATE:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_target_bitrate);
|
||||
break;
|
||||
case PROP_MIN_QUANTIZER:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_min_quantizer);
|
||||
break;
|
||||
case PROP_MAX_QUANTIZER:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_max_quantizer);
|
||||
break;
|
||||
case PROP_UNDERSHOOT_PCT:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_undershoot_pct);
|
||||
break;
|
||||
case PROP_OVERSHOOT_PCT:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_overshoot_pct);
|
||||
break;
|
||||
case PROP_BUF_SZ:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_buf_sz);
|
||||
break;
|
||||
case PROP_BUF_INITIAL_SZ:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_buf_initial_sz);
|
||||
break;
|
||||
case PROP_BUF_OPTIMAL_SZ:
|
||||
g_value_set_uint (value, av1enc->aom_cfg.rc_buf_optimal_sz);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
|
|
@ -49,6 +49,60 @@ G_BEGIN_DECLS
|
|||
typedef struct _GstAV1Enc GstAV1Enc;
|
||||
typedef struct _GstAV1EncClass GstAV1EncClass;
|
||||
|
||||
/**
|
||||
* GstAV1EncResizeMode:
|
||||
* @GST_AV1_ENC_RESIZE_NONE: No frame resizing allowed
|
||||
* @GST_AV1_ENC_RESIZE_FIXED: All frames are coded at the specified scale
|
||||
* @GST_AV1_ENC_RESIZE_RANDOM: All frames are coded at a random scale
|
||||
*
|
||||
* Frame resize mode
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GST_AV1_ENC_RESIZE_NONE = 0,
|
||||
GST_AV1_ENC_RESIZE_FIXED = 1,
|
||||
GST_AV1_ENC_RESIZE_RANDOM = 2,
|
||||
GST_AV1_ENC_RESIZE_MODES
|
||||
} GstAV1EncResizeMode;
|
||||
|
||||
/**
|
||||
* GstAV1EncSuperresMode
|
||||
* @GST_AV1_ENC_SUPERRES_NONE: No frame superres allowed
|
||||
* @GST_AV1_ENC_SUPERRES_FIXED: All frames are coded at the specified scale and
|
||||
* super-resolved
|
||||
* @GST_AV1_ENC_SUPERRES_QTHRESH: Superres scale for a frame is determined based
|
||||
* on q_index
|
||||
*
|
||||
* Frame super-resolution mode
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GST_AV1_ENC_SUPERRES_NONE = 0,
|
||||
GST_AV1_ENC_SUPERRES_FIXED = 1,
|
||||
GST_AV1_ENC_SUPERRES_RANDOM = 2,
|
||||
GST_AV1_ENC_SUPERRES_QTHRESH = 3,
|
||||
GST_AV1_ENC_SUPERRES_MODES
|
||||
} GstAV1EncSuperresMode;
|
||||
|
||||
/**
|
||||
* GstAV1EncEndUsageMode
|
||||
* @GST_AV1_ENC_END_USAGE_VBR: Variable Bit Rate Mode
|
||||
* @GST_AV1_ENC_END_USAGE_CBR: Constant Bit Rate Mode
|
||||
* @GST_AV1_ENC_END_USAGE_CQ: Constrained Quality Mode
|
||||
* @GST_AV1_ENC_END_USAGE_Q: Constant Quality Mode
|
||||
*
|
||||
* Rate control algorithm to use
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GST_AV1_ENC_END_USAGE_VBR = 0,
|
||||
GST_AV1_ENC_END_USAGE_CBR = 1,
|
||||
GST_AV1_ENC_END_USAGE_CQ = 2,
|
||||
GST_AV1_ENC_END_USAGE_Q = 3,
|
||||
GST_AV1_ENC_END_USAGE_MODES
|
||||
} GstAV1EncEndUsageMode;
|
||||
|
||||
struct _GstAV1Enc
|
||||
{
|
||||
GstVideoEncoder base_video_encoder;
|
||||
|
@ -62,7 +116,10 @@ struct _GstAV1Enc
|
|||
GstVideoCodecState *input_state;
|
||||
aom_codec_enc_cfg_t aom_cfg;
|
||||
aom_codec_ctx_t encoder;
|
||||
aom_img_fmt_t format;
|
||||
GMutex encoder_lock;
|
||||
|
||||
gboolean target_bitrate_set;
|
||||
};
|
||||
|
||||
struct _GstAV1EncClass
|
||||
|
|
51
ext/aom/gstav1utils.c
Normal file
51
ext/aom/gstav1utils.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* AV1
|
||||
* Copyright (C) 2018 Wonchul Lee <chul0812@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gstav1utils.h"
|
||||
|
||||
const char *
|
||||
gst_av1_get_error_name (aom_codec_err_t status)
|
||||
{
|
||||
switch (status) {
|
||||
case AOM_CODEC_OK:
|
||||
return "OK";
|
||||
case AOM_CODEC_ERROR:
|
||||
return "error";
|
||||
case AOM_CODEC_MEM_ERROR:
|
||||
return "mem error";
|
||||
case AOM_CODEC_ABI_MISMATCH:
|
||||
return "abi mismatch";
|
||||
case AOM_CODEC_INCAPABLE:
|
||||
return "incapable";
|
||||
case AOM_CODEC_UNSUP_BITSTREAM:
|
||||
return "unsupported bitstream";
|
||||
case AOM_CODEC_UNSUP_FEATURE:
|
||||
return "unsupported feature";
|
||||
case AOM_CODEC_CORRUPT_FRAME:
|
||||
return "corrupt frame";
|
||||
case AOM_CODEC_INVALID_PARAM:
|
||||
return "invalid parameter";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
28
ext/aom/gstav1utils.h
Normal file
28
ext/aom/gstav1utils.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* AV1
|
||||
* Copyright (C) 2018 Wonchul Lee <chul0812@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <aom/aom_codec.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
const char *gst_av1_get_error_name (aom_codec_err_t status);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
aom_dep = dependency('aom', required: get_option('aom'))
|
||||
if aom_dep.found()
|
||||
gstaom = library('gstaom',
|
||||
['gstaom.c', 'gstav1enc.c', 'gstav1dec.c'],
|
||||
['gstaom.c', 'gstav1enc.c', 'gstav1dec.c', 'gstav1utils.c'],
|
||||
c_args : gst_plugins_bad_args,
|
||||
include_directories : [configinc],
|
||||
dependencies : [gstpbutils_dep, gstvideo_dep, aom_dep],
|
||||
|
|
Loading…
Reference in a new issue