2016-05-30 08:24:14 +00:00
|
|
|
/*
|
|
|
|
* gstvaapiencode_vp9.c - VA-API VP9 encoder
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Intel Corporation
|
|
|
|
* Author: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1
|
|
|
|
* 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-vaapivp9enc
|
|
|
|
* @short_description: A VA-API based VP9 video encoder
|
|
|
|
*
|
|
|
|
* Encodes raw video streams into VP9 bitstreams.
|
|
|
|
*
|
2019-05-29 21:08:22 +00:00
|
|
|
* ## Example launch line
|
|
|
|
*
|
2016-05-30 08:24:14 +00:00
|
|
|
* |[
|
|
|
|
* gst-launch-1.0 -ev videotestsrc num-buffers=60 ! timeoverlay ! vaapivp9enc ! matroskamux ! filesink location=test.mkv
|
|
|
|
* ]|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gstcompat.h"
|
|
|
|
#include <gst/vaapi/gstvaapidisplay.h>
|
|
|
|
#include <gst/vaapi/gstvaapiencoder_vp9.h>
|
2020-07-06 16:46:23 +00:00
|
|
|
#include <gst/vaapi/gstvaapiutils_vpx.h>
|
2016-05-30 08:24:14 +00:00
|
|
|
#include "gstvaapiencode_vp9.h"
|
|
|
|
#include "gstvaapipluginutil.h"
|
|
|
|
#include "gstvaapivideomemory.h"
|
|
|
|
|
|
|
|
#define GST_PLUGIN_NAME "vaapivp9enc"
|
|
|
|
#define GST_PLUGIN_DESC "A VA-API based VP9 video encoder"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vaapi_vp9_encode_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_vaapi_vp9_encode_debug
|
|
|
|
|
|
|
|
#define GST_CODEC_CAPS \
|
|
|
|
"video/x-vp9"
|
|
|
|
|
2020-04-10 14:05:50 +00:00
|
|
|
#define EXTRA_FORMATS {}
|
|
|
|
|
2016-05-30 08:24:14 +00:00
|
|
|
/* vp9 encode */
|
2020-07-06 16:46:23 +00:00
|
|
|
GST_VAAPI_ENCODE_REGISTER_TYPE (vp9, VP9, VP9, EXTRA_FORMATS,
|
|
|
|
gst_vaapi_utils_vp9_get_profile_string);
|
2016-05-30 08:24:14 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapiencode_vp9_init (GstVaapiEncodeVP9 * encode)
|
|
|
|
{
|
2019-08-20 15:56:33 +00:00
|
|
|
/* nothing to do here */
|
2016-05-30 08:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapiencode_vp9_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (gst_vaapiencode_vp9_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2020-07-06 16:46:23 +00:00
|
|
|
static GArray *
|
|
|
|
gst_vaapiencode_vp9_get_allowed_profiles (GstVaapiEncode * encode,
|
|
|
|
GstCaps * allowed)
|
|
|
|
{
|
|
|
|
return gst_vaapi_encoder_get_profiles_from_caps (allowed,
|
|
|
|
gst_vaapi_utils_vp9_get_profile_from_string);
|
|
|
|
}
|
|
|
|
|
2016-05-30 08:24:14 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_vaapiencode_vp9_get_caps (GstVaapiEncode * base_encode)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
2020-07-11 15:39:40 +00:00
|
|
|
GstVaapiProfile profile;
|
|
|
|
const gchar *profile_str;
|
2016-05-30 08:24:14 +00:00
|
|
|
|
|
|
|
caps = gst_caps_from_string (GST_CODEC_CAPS);
|
2020-07-11 15:39:40 +00:00
|
|
|
profile = gst_vaapi_encoder_get_profile (base_encode->encoder);
|
|
|
|
profile_str = gst_vaapi_utils_vp9_get_profile_string (profile);
|
|
|
|
if (profile_str)
|
|
|
|
gst_caps_set_simple (caps, "profile", G_TYPE_STRING, profile_str, NULL);
|
2016-05-30 08:24:14 +00:00
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiEncoder *
|
|
|
|
gst_vaapiencode_vp9_alloc_encoder (GstVaapiEncode * base,
|
|
|
|
GstVaapiDisplay * display)
|
|
|
|
{
|
|
|
|
return gst_vaapi_encoder_vp9_new (display);
|
|
|
|
}
|
|
|
|
|
2020-07-11 15:37:29 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vaapiencode_vp9_set_config (GstVaapiEncode * base_encode)
|
|
|
|
{
|
|
|
|
GstVaapiEncoderVP9 *const encoder =
|
|
|
|
GST_VAAPI_ENCODER_VP9 (base_encode->encoder);
|
|
|
|
GstCaps *allowed_caps = NULL;
|
|
|
|
GstCaps *template_caps = NULL;
|
|
|
|
GArray *profiles = NULL;
|
|
|
|
GArray *profiles_hw = NULL;
|
|
|
|
GArray *profiles_allowed = NULL;
|
|
|
|
GstVaapiProfile profile;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
guint i, j;
|
|
|
|
|
|
|
|
profiles_hw = gst_vaapi_display_get_encode_profiles_by_codec
|
|
|
|
(GST_VAAPI_PLUGIN_BASE_DISPLAY (base_encode), GST_VAAPI_CODEC_VP9);
|
|
|
|
if (!profiles_hw) {
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
template_caps =
|
|
|
|
gst_pad_get_pad_template_caps (GST_VAAPI_PLUGIN_BASE_SRC_PAD
|
|
|
|
(base_encode));
|
|
|
|
allowed_caps =
|
|
|
|
gst_pad_get_allowed_caps (GST_VAAPI_PLUGIN_BASE_SRC_PAD (base_encode));
|
|
|
|
if (!allowed_caps || allowed_caps == template_caps) {
|
|
|
|
ret = gst_vaapi_encoder_vp9_set_allowed_profiles (encoder, profiles_hw);
|
|
|
|
goto out;
|
|
|
|
} else if (gst_caps_is_empty (allowed_caps)) {
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
profiles = gst_vaapi_encoder_get_profiles_from_caps (allowed_caps,
|
|
|
|
gst_vaapi_utils_vp9_get_profile_from_string);
|
|
|
|
if (!profiles) {
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
profiles_allowed = g_array_new (FALSE, FALSE, sizeof (GstVaapiProfile));
|
|
|
|
if (!profiles_allowed) {
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < profiles->len; i++) {
|
|
|
|
profile = g_array_index (profiles, GstVaapiProfile, i);
|
|
|
|
for (j = 0; j < profiles_hw->len; j++) {
|
|
|
|
GstVaapiProfile p = g_array_index (profiles_hw, GstVaapiProfile, j);
|
|
|
|
if (p == profile) {
|
|
|
|
g_array_append_val (profiles_allowed, profile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (profiles_allowed->len == 0) {
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gst_vaapi_encoder_vp9_set_allowed_profiles (encoder, profiles_allowed);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (allowed_caps)
|
|
|
|
gst_caps_unref (allowed_caps);
|
|
|
|
if (template_caps)
|
|
|
|
gst_caps_unref (template_caps);
|
|
|
|
if (profiles)
|
|
|
|
g_array_unref (profiles);
|
|
|
|
if (profiles_hw)
|
|
|
|
g_array_unref (profiles_hw);
|
|
|
|
if (profiles_allowed)
|
|
|
|
g_array_unref (profiles_allowed);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-30 08:24:14 +00:00
|
|
|
static void
|
2020-04-10 14:05:50 +00:00
|
|
|
gst_vaapiencode_vp9_class_init (GstVaapiEncodeVP9Class * klass, gpointer data)
|
2016-05-30 08:24:14 +00:00
|
|
|
{
|
|
|
|
GObjectClass *const object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *const element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_CLASS (klass);
|
2020-07-08 10:46:58 +00:00
|
|
|
GstCaps *sink_caps = ((GstVaapiEncodeInitData *) data)->sink_caps;
|
2020-07-08 11:03:14 +00:00
|
|
|
GstCaps *src_caps = ((GstVaapiEncodeInitData *) data)->src_caps;
|
2020-07-09 05:49:29 +00:00
|
|
|
GstPadTemplate *templ;
|
|
|
|
GstCaps *static_caps;
|
2019-08-20 15:56:33 +00:00
|
|
|
gpointer encoder_class;
|
2016-05-30 08:24:14 +00:00
|
|
|
|
|
|
|
object_class->finalize = gst_vaapiencode_vp9_finalize;
|
2019-08-20 15:56:33 +00:00
|
|
|
object_class->set_property = gst_vaapiencode_set_property_subclass;
|
|
|
|
object_class->get_property = gst_vaapiencode_get_property_subclass;
|
2016-05-30 08:24:14 +00:00
|
|
|
|
2020-07-06 16:46:23 +00:00
|
|
|
encode_class->get_allowed_profiles = gst_vaapiencode_vp9_get_allowed_profiles;
|
2016-05-30 08:24:14 +00:00
|
|
|
encode_class->get_caps = gst_vaapiencode_vp9_get_caps;
|
|
|
|
encode_class->alloc_encoder = gst_vaapiencode_vp9_alloc_encoder;
|
2020-07-11 15:37:29 +00:00
|
|
|
encode_class->set_config = gst_vaapiencode_vp9_set_config;
|
2016-05-30 08:24:14 +00:00
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (element_class,
|
|
|
|
"VA-API VP9 encoder",
|
2018-10-12 14:39:53 +00:00
|
|
|
"Codec/Encoder/Video/Hardware",
|
2016-05-30 08:24:14 +00:00
|
|
|
GST_PLUGIN_DESC,
|
|
|
|
"Sreerenj Balachandran <sreerenj.balachandran@intel.com>");
|
|
|
|
|
|
|
|
/* sink pad */
|
2020-04-10 14:05:50 +00:00
|
|
|
g_assert (sink_caps);
|
2020-07-09 05:49:29 +00:00
|
|
|
static_caps = gst_caps_from_string (GST_VAAPI_ENCODE_STATIC_SINK_CAPS);
|
|
|
|
templ =
|
|
|
|
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, sink_caps);
|
|
|
|
gst_pad_template_set_documentation_caps (templ, static_caps);
|
|
|
|
gst_element_class_add_pad_template (element_class, templ);
|
|
|
|
gst_caps_unref (static_caps);
|
2020-04-10 14:05:50 +00:00
|
|
|
gst_caps_unref (sink_caps);
|
2016-05-30 08:24:14 +00:00
|
|
|
|
|
|
|
/* src pad */
|
2020-07-08 11:03:14 +00:00
|
|
|
g_assert (src_caps);
|
2020-07-09 05:49:29 +00:00
|
|
|
static_caps = gst_caps_from_string (GST_CODEC_CAPS);
|
|
|
|
templ = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, src_caps);
|
|
|
|
gst_pad_template_set_documentation_caps (templ, static_caps);
|
|
|
|
gst_element_class_add_pad_template (element_class, templ);
|
|
|
|
gst_caps_unref (static_caps);
|
2020-07-08 11:03:14 +00:00
|
|
|
gst_caps_unref (src_caps);
|
2016-05-30 08:24:14 +00:00
|
|
|
|
2019-08-20 15:56:33 +00:00
|
|
|
encoder_class = g_type_class_ref (GST_TYPE_VAAPI_ENCODER_VP9);
|
|
|
|
g_assert (encoder_class);
|
|
|
|
gst_vaapiencode_class_install_properties (encode_class, encoder_class);
|
|
|
|
g_type_class_unref (encoder_class);
|
2016-05-30 08:24:14 +00:00
|
|
|
}
|