2013-06-21 11:07:30 +00:00
|
|
|
/* VP9
|
|
|
|
* Copyright (C) 2006 David Schleef <ds@schleef.org>
|
|
|
|
* Copyright (C) 2010 Entropy Wave Inc
|
|
|
|
* Copyright (C) 2010-2013 Sebastian Dröge <slomo@circular-chaos.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* SECTION:element-vp9enc
|
2018-10-22 09:39:24 +00:00
|
|
|
* @title: vp9enc
|
2013-06-21 11:07:30 +00:00
|
|
|
* @see_also: vp9dec, webmmux, oggmux
|
|
|
|
*
|
|
|
|
* This element encodes raw video into a VP9 stream.
|
2019-08-23 16:56:01 +00:00
|
|
|
* [VP9](http://www.webmproject.org) is a royalty-free video codec maintained by
|
|
|
|
* [Google](http://www.google.com/). It's the successor of On2 VP3, which was
|
|
|
|
* the base of the Theora video codec.
|
2013-06-21 11:07:30 +00:00
|
|
|
*
|
2020-06-23 16:47:44 +00:00
|
|
|
* To control the quality of the encoding, the #GstVPXEnc:target-bitrate,
|
|
|
|
* #GstVPXEnc:min-quantizer, #GstVPXEnc:max-quantizer or #GstVPXEnc:cq-level
|
2013-06-21 11:07:30 +00:00
|
|
|
* properties can be used. Which one is used depends on the mode selected by
|
2020-06-23 16:47:44 +00:00
|
|
|
* the #GstVPXEnc:end-usage property.
|
2019-08-23 16:56:01 +00:00
|
|
|
* See [Encoder Parameters](http://www.webmproject.org/docs/encoder-parameters/)
|
2013-06-21 11:07:30 +00:00
|
|
|
* for explanation, examples for useful encoding parameters and more details
|
|
|
|
* on the encoding parameters.
|
|
|
|
*
|
2018-10-22 09:39:24 +00:00
|
|
|
* ## Example pipeline
|
2013-06-21 11:07:30 +00:00
|
|
|
* |[
|
2015-05-10 10:05:00 +00:00
|
|
|
* gst-launch-1.0 -v videotestsrc num-buffers=1000 ! vp9enc ! webmmux ! filesink location=videotestsrc.webm
|
2013-06-21 11:07:30 +00:00
|
|
|
* ]| This example pipeline will encode a test video source to VP9 muxed in an
|
|
|
|
* WebM container.
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
2013-06-21 11:07:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_VP9_ENCODER
|
|
|
|
|
|
|
|
/* glib decided in 2.32 it would be a great idea to deprecated GValueArray without
|
|
|
|
* providing an alternative
|
|
|
|
*
|
|
|
|
* See https://bugzilla.gnome.org/show_bug.cgi?id=667228
|
|
|
|
* */
|
|
|
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
|
|
|
#include <gst/tag/tag.h>
|
|
|
|
#include <gst/video/video.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-02-15 10:00:46 +00:00
|
|
|
#include "gstvpxelements.h"
|
2013-06-21 11:07:30 +00:00
|
|
|
#include "gstvp8utils.h"
|
|
|
|
#include "gstvp9enc.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vp9enc_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_vp9enc_debug
|
|
|
|
|
2020-08-28 15:39:47 +00:00
|
|
|
#define DEFAULT_TILE_COLUMNS 6
|
|
|
|
#define DEFAULT_TILE_ROWS 0
|
2020-08-28 16:09:15 +00:00
|
|
|
#define DEFAULT_ROW_MT 0
|
|
|
|
|
2020-08-28 15:39:47 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_TILE_COLUMNS,
|
|
|
|
PROP_TILE_ROWS,
|
2020-08-28 16:09:15 +00:00
|
|
|
PROP_ROW_MT,
|
2020-08-28 15:39:47 +00:00
|
|
|
};
|
2013-06-21 11:07:30 +00:00
|
|
|
|
2020-03-23 20:44:30 +00:00
|
|
|
/* FIXME: Y42B do not work yet it seems */
|
2013-06-21 11:07:30 +00:00
|
|
|
static GstStaticPadTemplate gst_vp9_enc_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2013-06-22 08:57:41 +00:00
|
|
|
/*GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ I420, YV12, Y42B, Y444 }")) */
|
2020-03-24 18:35:07 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
|
|
|
|
("{ I420, YV12, Y444, I420_10LE, I422_10LE }"))
|
2013-06-21 11:07:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_vp9_enc_src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-vp9, " "profile = (string) {0, 1, 2, 3}")
|
|
|
|
);
|
|
|
|
|
|
|
|
#define parent_class gst_vp9_enc_parent_class
|
2015-09-24 07:27:00 +00:00
|
|
|
G_DEFINE_TYPE (GstVP9Enc, gst_vp9_enc, GST_TYPE_VPX_ENC);
|
2021-02-15 10:00:46 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (vp9enc, "vp9enc", GST_RANK_PRIMARY,
|
|
|
|
gst_vp9_enc_get_type (), vpx_element_init (plugin));
|
2015-09-24 07:27:00 +00:00
|
|
|
|
|
|
|
static vpx_codec_iface_t *gst_vp9_enc_get_algo (GstVPXEnc * enc);
|
|
|
|
static gboolean gst_vp9_enc_enable_scaling (GstVPXEnc * enc);
|
|
|
|
static void gst_vp9_enc_set_image_format (GstVPXEnc * enc, vpx_image_t * image);
|
|
|
|
static GstCaps *gst_vp9_enc_get_new_simple_caps (GstVPXEnc * enc);
|
|
|
|
static void gst_vp9_enc_set_stream_info (GstVPXEnc * enc, GstCaps * caps,
|
|
|
|
GstVideoInfo * info);
|
|
|
|
static void *gst_vp9_enc_process_frame_user_data (GstVPXEnc * enc,
|
|
|
|
GstVideoCodecFrame * frame);
|
|
|
|
static GstFlowReturn gst_vp9_enc_handle_invisible_frame_buffer (GstVPXEnc * enc,
|
|
|
|
void *user_data, GstBuffer * buffer);
|
|
|
|
static void gst_vp9_enc_set_frame_user_data (GstVPXEnc * enc,
|
|
|
|
GstVideoCodecFrame * frame, vpx_image_t * image);
|
2020-08-28 15:39:47 +00:00
|
|
|
static void gst_vp9_enc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_vp9_enc_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2021-05-06 18:51:31 +00:00
|
|
|
static gboolean gst_vp9_enc_configure_encoder (GstVPXEnc * encoder,
|
|
|
|
GstVideoCodecState * state);
|
2013-06-21 11:07:30 +00:00
|
|
|
|
2015-11-26 16:52:29 +00:00
|
|
|
#define DEFAULT_BITS_PER_PIXEL 0.0289
|
|
|
|
|
2013-06-21 11:07:30 +00:00
|
|
|
static void
|
|
|
|
gst_vp9_enc_class_init (GstVP9EncClass * klass)
|
|
|
|
{
|
2020-08-28 15:39:47 +00:00
|
|
|
GObjectClass *gobject_class;
|
2013-06-21 11:07:30 +00:00
|
|
|
GstElementClass *element_class;
|
2015-09-24 07:27:00 +00:00
|
|
|
GstVPXEncClass *vpx_encoder_class;
|
2013-06-21 11:07:30 +00:00
|
|
|
|
2020-08-28 15:39:47 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2013-06-21 11:07:30 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
2015-09-24 07:27:00 +00:00
|
|
|
vpx_encoder_class = GST_VPX_ENC_CLASS (klass);
|
2013-06-21 11:07:30 +00:00
|
|
|
|
2020-08-28 15:39:47 +00:00
|
|
|
gobject_class->set_property = gst_vp9_enc_set_property;
|
|
|
|
gobject_class->get_property = gst_vp9_enc_get_property;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstVP9Enc:tile-columns:
|
|
|
|
*
|
|
|
|
* Number of tile columns, log2
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TILE_COLUMNS,
|
|
|
|
g_param_spec_int ("tile-columns", "Tile Columns",
|
|
|
|
"Number of tile columns, log2",
|
|
|
|
0, 6, DEFAULT_TILE_COLUMNS,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstVP9Enc:tile-rows:
|
|
|
|
*
|
|
|
|
* Number of tile rows, log2
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TILE_ROWS,
|
|
|
|
g_param_spec_int ("tile-rows", "Tile Rows",
|
|
|
|
"Number of tile rows, log2",
|
|
|
|
0, 2, DEFAULT_TILE_ROWS,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2020-08-28 16:09:15 +00:00
|
|
|
/**
|
|
|
|
* GstVP9Enc:row-mt:
|
|
|
|
*
|
|
|
|
* Whether each row should be encoded using multiple threads
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_ROW_MT,
|
|
|
|
g_param_spec_boolean ("row-mt", "Row Multithreading",
|
|
|
|
"Whether each row should be encoded using multiple threads",
|
|
|
|
DEFAULT_ROW_MT,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2016-03-04 01:30:12 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_vp9_enc_src_template);
|
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_vp9_enc_sink_template);
|
2013-06-21 11:07:30 +00:00
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (element_class,
|
|
|
|
"On2 VP9 Encoder",
|
|
|
|
"Codec/Encoder/Video",
|
|
|
|
"Encode VP9 video streams", "David Schleef <ds@entropywave.com>, "
|
|
|
|
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
|
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
vpx_encoder_class->get_algo = gst_vp9_enc_get_algo;
|
|
|
|
vpx_encoder_class->enable_scaling = gst_vp9_enc_enable_scaling;
|
|
|
|
vpx_encoder_class->set_image_format = gst_vp9_enc_set_image_format;
|
|
|
|
vpx_encoder_class->get_new_vpx_caps = gst_vp9_enc_get_new_simple_caps;
|
|
|
|
vpx_encoder_class->set_stream_info = gst_vp9_enc_set_stream_info;
|
|
|
|
vpx_encoder_class->process_frame_user_data =
|
|
|
|
gst_vp9_enc_process_frame_user_data;
|
|
|
|
vpx_encoder_class->handle_invisible_frame_buffer =
|
|
|
|
gst_vp9_enc_handle_invisible_frame_buffer;
|
|
|
|
vpx_encoder_class->set_frame_user_data = gst_vp9_enc_set_frame_user_data;
|
2020-08-28 15:39:47 +00:00
|
|
|
vpx_encoder_class->configure_encoder = gst_vp9_enc_configure_encoder;
|
2013-06-21 11:07:30 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_vp9enc_debug, "vp9enc", 0, "VP9 Encoder");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp9_enc_init (GstVP9Enc * gst_vp9_enc)
|
|
|
|
{
|
|
|
|
vpx_codec_err_t status;
|
2015-09-24 07:27:00 +00:00
|
|
|
GstVPXEnc *gst_vpx_enc = GST_VPX_ENC (gst_vp9_enc);
|
|
|
|
GST_DEBUG_OBJECT (gst_vp9_enc, "gst_vp9_enc_init");
|
2013-06-21 11:07:30 +00:00
|
|
|
status =
|
2015-09-24 07:27:00 +00:00
|
|
|
vpx_codec_enc_config_default (gst_vp9_enc_get_algo (gst_vpx_enc),
|
|
|
|
&gst_vpx_enc->cfg, 0);
|
2013-06-21 11:07:30 +00:00
|
|
|
if (status != VPX_CODEC_OK) {
|
2015-09-24 07:27:00 +00:00
|
|
|
GST_ERROR_OBJECT (gst_vpx_enc,
|
2013-06-21 11:07:30 +00:00
|
|
|
"Failed to get default encoder configuration: %s",
|
|
|
|
gst_vpx_error_name (status));
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_vpx_enc->have_default_config = FALSE;
|
2013-06-21 11:07:30 +00:00
|
|
|
} else {
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_vpx_enc->have_default_config = TRUE;
|
2013-06-21 11:07:30 +00:00
|
|
|
}
|
2015-11-26 16:52:29 +00:00
|
|
|
gst_vpx_enc->bits_per_pixel = DEFAULT_BITS_PER_PIXEL;
|
2020-08-28 15:39:47 +00:00
|
|
|
|
|
|
|
gst_vp9_enc->tile_columns = DEFAULT_TILE_COLUMNS;
|
|
|
|
gst_vp9_enc->tile_rows = DEFAULT_TILE_ROWS;
|
2020-08-28 16:09:15 +00:00
|
|
|
gst_vp9_enc->row_mt = DEFAULT_ROW_MT;
|
2020-08-28 15:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp9_enc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVPXEnc *gst_vpx_enc = GST_VPX_ENC (object);
|
|
|
|
GstVP9Enc *gst_vp9_enc = GST_VP9_ENC (object);
|
|
|
|
vpx_codec_err_t status;
|
|
|
|
|
|
|
|
g_mutex_lock (&gst_vpx_enc->encoder_lock);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_TILE_COLUMNS:
|
|
|
|
gst_vp9_enc->tile_columns = g_value_get_int (value);
|
|
|
|
if (gst_vpx_enc->inited) {
|
|
|
|
status =
|
|
|
|
vpx_codec_control (&gst_vpx_enc->encoder, VP9E_SET_TILE_COLUMNS,
|
|
|
|
gst_vp9_enc->tile_columns);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (gst_vpx_enc,
|
|
|
|
"Failed to set VP9E_SET_TILE_COLUMNS: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROP_TILE_ROWS:
|
|
|
|
gst_vp9_enc->tile_rows = g_value_get_int (value);
|
|
|
|
if (gst_vpx_enc->inited) {
|
|
|
|
status =
|
|
|
|
vpx_codec_control (&gst_vpx_enc->encoder, VP9E_SET_TILE_ROWS,
|
|
|
|
gst_vp9_enc->tile_rows);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (gst_vpx_enc,
|
|
|
|
"Failed to set VP9E_SET_TILE_ROWS: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-08-28 16:09:15 +00:00
|
|
|
case PROP_ROW_MT:
|
|
|
|
gst_vp9_enc->row_mt = g_value_get_boolean (value);
|
|
|
|
if (gst_vpx_enc->inited) {
|
|
|
|
status =
|
|
|
|
vpx_codec_control (&gst_vpx_enc->encoder, VP9E_SET_ROW_MT,
|
|
|
|
gst_vp9_enc->row_mt ? 1 : 0);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (gst_vpx_enc,
|
|
|
|
"Failed to set VP9E_SET_ROW_MT: %s", gst_vpx_error_name (status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-08-28 15:39:47 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&gst_vpx_enc->encoder_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp9_enc_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVPXEnc *gst_vpx_enc = GST_VPX_ENC (object);
|
|
|
|
GstVP9Enc *gst_vp9_enc = GST_VP9_ENC (object);
|
|
|
|
|
|
|
|
g_mutex_lock (&gst_vpx_enc->encoder_lock);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_TILE_COLUMNS:
|
|
|
|
g_value_set_int (value, gst_vp9_enc->tile_columns);
|
|
|
|
break;
|
|
|
|
case PROP_TILE_ROWS:
|
|
|
|
g_value_set_int (value, gst_vp9_enc->tile_rows);
|
|
|
|
break;
|
2020-08-28 16:09:15 +00:00
|
|
|
case PROP_ROW_MT:
|
|
|
|
g_value_set_boolean (value, gst_vp9_enc->row_mt);
|
|
|
|
break;
|
2020-08-28 15:39:47 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&gst_vpx_enc->encoder_lock);
|
|
|
|
}
|
|
|
|
|
2021-05-06 18:51:31 +00:00
|
|
|
static vpx_color_space_t
|
|
|
|
gst_vp9_get_vpx_colorspace (GstVPXEnc * encoder, GstVideoColorimetry * cinfo,
|
|
|
|
GstVideoFormat format)
|
|
|
|
{
|
|
|
|
vpx_color_space_t colorspace = VPX_CS_UNKNOWN;
|
|
|
|
gchar *colorimetry_str;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const gchar *str;
|
|
|
|
vpx_color_space_t vpx_color_space;
|
|
|
|
} colorimetry_map[] = {
|
|
|
|
{
|
|
|
|
GST_VIDEO_COLORIMETRY_BT601, VPX_CS_BT_601}, {
|
|
|
|
GST_VIDEO_COLORIMETRY_BT709, VPX_CS_BT_709}, {
|
|
|
|
GST_VIDEO_COLORIMETRY_SMPTE240M, VPX_CS_SMPTE_240}, {
|
|
|
|
GST_VIDEO_COLORIMETRY_BT2020, VPX_CS_BT_2020}
|
|
|
|
};
|
|
|
|
|
|
|
|
colorimetry_str = gst_video_colorimetry_to_string (cinfo);
|
|
|
|
|
|
|
|
if (colorimetry_str != NULL) {
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (colorimetry_map); ++i) {
|
|
|
|
if (g_strcmp0 (colorimetry_map[i].str, colorimetry_str) == 0) {
|
|
|
|
colorspace = colorimetry_map[i].vpx_color_space;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (colorspace == VPX_CS_UNKNOWN) {
|
|
|
|
if (format == GST_VIDEO_FORMAT_GBR
|
|
|
|
|| format == GST_VIDEO_FORMAT_GBR_10BE
|
|
|
|
|| format == GST_VIDEO_FORMAT_GBR_10LE
|
|
|
|
|| format == GST_VIDEO_FORMAT_GBR_12BE
|
|
|
|
|| format == GST_VIDEO_FORMAT_GBR_12LE) {
|
|
|
|
/* Currently has no effect because vp*enc elements only accept YUV video
|
|
|
|
* formats.
|
|
|
|
*
|
|
|
|
* FIXME: Support encoding GST_VIDEO_FORMAT_GBR and its high bits variants.
|
|
|
|
*/
|
|
|
|
colorspace = VPX_CS_SRGB;
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (encoder, "Unsupported colorspace \"%s\"",
|
|
|
|
GST_STR_NULL (colorimetry_str));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (colorimetry_str);
|
|
|
|
|
|
|
|
return colorspace;
|
|
|
|
}
|
|
|
|
|
2020-08-28 15:39:47 +00:00
|
|
|
static gboolean
|
2021-05-06 18:48:36 +00:00
|
|
|
gst_vp9_enc_configure_encoder (GstVPXEnc * encoder, GstVideoCodecState * state)
|
2020-08-28 15:39:47 +00:00
|
|
|
{
|
|
|
|
GstVP9Enc *vp9enc = GST_VP9_ENC (encoder);
|
2021-05-06 18:51:31 +00:00
|
|
|
GstVideoInfo *info = &state->info;
|
2020-08-28 15:39:47 +00:00
|
|
|
vpx_codec_err_t status;
|
|
|
|
|
2021-05-06 18:51:31 +00:00
|
|
|
status = vpx_codec_control (&encoder->encoder, VP9E_SET_COLOR_SPACE,
|
|
|
|
gst_vp9_get_vpx_colorspace (encoder, &GST_VIDEO_INFO_COLORIMETRY (info),
|
|
|
|
GST_VIDEO_INFO_FORMAT (info)));
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
|
|
|
"Failed to set VP9E_SET_COLOR_SPACE: %s", gst_vpx_error_name (status));
|
|
|
|
}
|
|
|
|
|
2020-08-28 15:39:47 +00:00
|
|
|
status =
|
|
|
|
vpx_codec_control (&encoder->encoder, VP9E_SET_TILE_COLUMNS,
|
|
|
|
vp9enc->tile_columns);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_DEBUG_OBJECT (encoder, "Failed to set VP9E_SET_TILE_COLUMNS: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
|
|
|
|
|
|
|
status =
|
|
|
|
vpx_codec_control (&encoder->encoder, VP9E_SET_TILE_ROWS,
|
|
|
|
vp9enc->tile_rows);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_DEBUG_OBJECT (encoder, "Failed to set VP9E_SET_TILE_ROWS: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
2020-08-28 16:09:15 +00:00
|
|
|
status =
|
|
|
|
vpx_codec_control (&encoder->encoder, VP9E_SET_ROW_MT,
|
|
|
|
vp9enc->row_mt ? 1 : 0);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_DEBUG_OBJECT (encoder,
|
|
|
|
"Failed to set VP9E_SET_ROW_MT: %s", gst_vpx_error_name (status));
|
|
|
|
}
|
2020-08-28 15:39:47 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2013-06-21 11:07:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
static vpx_codec_iface_t *
|
|
|
|
gst_vp9_enc_get_algo (GstVPXEnc * enc)
|
2013-06-21 11:07:30 +00:00
|
|
|
{
|
2015-09-24 07:27:00 +00:00
|
|
|
return &vpx_codec_vp9_cx_algo;
|
2013-06-21 11:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_vp9_enc_enable_scaling (GstVPXEnc * enc)
|
2013-06-21 11:07:30 +00:00
|
|
|
{
|
2015-09-24 07:27:00 +00:00
|
|
|
return FALSE;
|
2013-06-21 11:07:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-09 15:46:02 +00:00
|
|
|
static void
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_vp9_enc_set_image_format (GstVPXEnc * enc, vpx_image_t * image)
|
2013-06-21 11:07:30 +00:00
|
|
|
{
|
2015-09-24 07:27:00 +00:00
|
|
|
switch (enc->input_state->info.finfo->format) {
|
2013-06-22 08:57:41 +00:00
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
image->fmt = VPX_IMG_FMT_I420;
|
|
|
|
image->bps = 12;
|
|
|
|
image->x_chroma_shift = image->y_chroma_shift = 1;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
image->fmt = VPX_IMG_FMT_YV12;
|
|
|
|
image->bps = 12;
|
|
|
|
image->x_chroma_shift = image->y_chroma_shift = 1;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_Y42B:
|
|
|
|
image->fmt = VPX_IMG_FMT_I422;
|
|
|
|
image->bps = 16;
|
|
|
|
image->x_chroma_shift = 1;
|
|
|
|
image->y_chroma_shift = 0;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_Y444:
|
|
|
|
image->fmt = VPX_IMG_FMT_I444;
|
|
|
|
image->bps = 24;
|
|
|
|
image->x_chroma_shift = image->y_chroma_shift = 0;
|
|
|
|
break;
|
2020-03-24 16:16:59 +00:00
|
|
|
case GST_VIDEO_FORMAT_I420_10LE:
|
|
|
|
image->fmt = VPX_IMG_FMT_I42016;
|
|
|
|
image->bps = 15;
|
|
|
|
image->x_chroma_shift = image->y_chroma_shift = 1;
|
|
|
|
break;
|
2020-03-24 18:35:07 +00:00
|
|
|
case GST_VIDEO_FORMAT_I422_10LE:
|
|
|
|
image->fmt = VPX_IMG_FMT_I42216;
|
|
|
|
image->bps = 20;
|
|
|
|
image->x_chroma_shift = 1;
|
|
|
|
image->y_chroma_shift = 0;
|
|
|
|
break;
|
2013-06-22 08:57:41 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
2015-09-24 07:27:00 +00:00
|
|
|
}
|
2013-06-21 11:07:30 +00:00
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_vp9_enc_get_new_simple_caps (GstVPXEnc * enc)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
gchar *profile_str = g_strdup_printf ("%d", enc->cfg.g_profile);
|
2013-06-21 11:07:30 +00:00
|
|
|
caps = gst_caps_new_simple ("video/x-vp9",
|
|
|
|
"profile", G_TYPE_STRING, profile_str, NULL);
|
|
|
|
g_free (profile_str);
|
2015-09-24 07:27:00 +00:00
|
|
|
return caps;
|
2013-06-21 11:07:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
static void
|
|
|
|
gst_vp9_enc_set_stream_info (GstVPXEnc * enc, GstCaps * caps,
|
|
|
|
GstVideoInfo * info)
|
2013-06-21 11:07:30 +00:00
|
|
|
{
|
2015-09-24 07:27:00 +00:00
|
|
|
return;
|
2013-06-21 11:07:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
static void *
|
|
|
|
gst_vp9_enc_process_frame_user_data (GstVPXEnc * enc,
|
|
|
|
GstVideoCodecFrame * frame)
|
2015-03-09 15:46:02 +00:00
|
|
|
{
|
2015-09-24 07:27:00 +00:00
|
|
|
return NULL;
|
2015-03-09 15:46:02 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 08:31:43 +00:00
|
|
|
static GstFlowReturn
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_vp9_enc_handle_invisible_frame_buffer (GstVPXEnc * enc, void *user_data,
|
|
|
|
GstBuffer * buffer)
|
2014-09-30 08:31:43 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret;
|
2015-09-24 07:27:00 +00:00
|
|
|
g_mutex_unlock (&enc->encoder_lock);
|
|
|
|
ret = gst_pad_push (GST_VIDEO_ENCODER_SRC_PAD (enc), buffer);
|
|
|
|
g_mutex_lock (&enc->encoder_lock);
|
2014-09-30 08:31:43 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-06 15:03:36 +00:00
|
|
|
static void
|
|
|
|
gst_vp9_enc_user_data_free (vpx_image_t * image)
|
|
|
|
{
|
|
|
|
g_slice_free (vpx_image_t, image);
|
|
|
|
}
|
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
static void
|
|
|
|
gst_vp9_enc_set_frame_user_data (GstVPXEnc * enc, GstVideoCodecFrame * frame,
|
|
|
|
vpx_image_t * image)
|
2013-06-21 11:07:30 +00:00
|
|
|
{
|
2016-06-06 15:03:36 +00:00
|
|
|
gst_video_codec_frame_set_user_data (frame, image,
|
|
|
|
(GDestroyNotify) gst_vp9_enc_user_data_free);
|
2015-09-24 07:27:00 +00:00
|
|
|
return;
|
2013-06-21 11:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_VP9_ENCODER */
|