2013-11-20 08:21:32 +00:00
|
|
|
/*
|
|
|
|
* gstvaapiencode_mpeg2.c - VA-API MPEG2 encoder
|
|
|
|
*
|
2014-01-22 17:54:14 +00:00
|
|
|
* Copyright (C) 2012-2014 Intel Corporation
|
2014-01-22 17:49:20 +00:00
|
|
|
* Author: Guangxin Xu <guangxin.xu@intel.com>
|
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2013-11-20 08:21:32 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2016-01-29 19:41:27 +00:00
|
|
|
/**
|
2016-02-03 18:07:40 +00:00
|
|
|
* SECTION:element-vaapimpeg2enc
|
2016-01-29 19:41:27 +00:00
|
|
|
* @short_description: A VA-API based MPEG2 video encoder
|
|
|
|
*
|
|
|
|
* Encodes raw video streams into MPEG2 bitstreams.
|
|
|
|
*
|
2019-05-29 21:08:22 +00:00
|
|
|
* ## Example launch line
|
|
|
|
*
|
2016-01-29 19:41:27 +00:00
|
|
|
* |[
|
2016-02-03 18:07:40 +00:00
|
|
|
* gst-launch-1.0 -ev videotestsrc num-buffers=60 ! timeoverlay ! vaapimpeg2enc ! matroskamux ! filesink location=test.mkv
|
2016-01-29 19:41:27 +00:00
|
|
|
* ]|
|
|
|
|
*/
|
|
|
|
|
2015-04-03 14:08:30 +00:00
|
|
|
#include "gstcompat.h"
|
2013-11-26 15:34:14 +00:00
|
|
|
#include <gst/vaapi/gstvaapidisplay.h>
|
|
|
|
#include <gst/vaapi/gstvaapiencoder_mpeg2.h>
|
2020-07-08 10:46:58 +00:00
|
|
|
#include <gst/vaapi/gstvaapiutils_mpeg2.h>
|
2013-11-20 08:21:32 +00:00
|
|
|
#include "gstvaapiencode_mpeg2.h"
|
|
|
|
#include "gstvaapipluginutil.h"
|
2013-11-07 09:42:21 +00:00
|
|
|
#include "gstvaapivideomemory.h"
|
2013-11-20 08:21:32 +00:00
|
|
|
|
2016-02-03 18:07:40 +00:00
|
|
|
#define GST_PLUGIN_NAME "vaapimpeg2enc"
|
2013-11-28 09:54:36 +00:00
|
|
|
#define GST_PLUGIN_DESC "A VA-API based MPEG-2 video encoder"
|
|
|
|
|
2013-11-20 08:21:32 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vaapi_mpeg2_encode_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_vaapi_mpeg2_encode_debug
|
|
|
|
|
2014-01-09 17:10:35 +00:00
|
|
|
#define GST_CODEC_CAPS \
|
|
|
|
"video/mpeg, mpegversion = (int) 2, " \
|
|
|
|
"systemstream = (boolean) false"
|
2013-11-20 08:21:32 +00:00
|
|
|
|
2020-04-10 14:04:34 +00:00
|
|
|
#define EXTRA_FORMATS {}
|
|
|
|
|
2013-11-20 08:21:32 +00:00
|
|
|
/* mpeg2 encode */
|
2020-07-08 10:46:58 +00:00
|
|
|
GST_VAAPI_ENCODE_REGISTER_TYPE (mpeg2, MPEG2, Mpeg2, EXTRA_FORMATS,
|
|
|
|
gst_vaapi_utils_mpeg2_get_profile_string);
|
2013-11-20 08:21:32 +00:00
|
|
|
|
|
|
|
static void
|
2013-11-28 12:57:54 +00:00
|
|
|
gst_vaapiencode_mpeg2_init (GstVaapiEncodeMpeg2 * encode)
|
2013-11-20 08:21:32 +00:00
|
|
|
{
|
2019-08-20 15:56:33 +00:00
|
|
|
/* nothing to do here */
|
2013-11-20 08:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapiencode_mpeg2_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (gst_vaapiencode_mpeg2_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2014-01-09 17:10:35 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_vaapiencode_mpeg2_get_caps (GstVaapiEncode * base_encode)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
caps = gst_caps_from_string (GST_CODEC_CAPS);
|
|
|
|
|
|
|
|
/* XXX: update profile and level information */
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2013-11-20 08:21:32 +00:00
|
|
|
static GstVaapiEncoder *
|
2014-01-09 09:09:38 +00:00
|
|
|
gst_vaapiencode_mpeg2_alloc_encoder (GstVaapiEncode * base,
|
2013-11-20 08:21:32 +00:00
|
|
|
GstVaapiDisplay * display)
|
|
|
|
{
|
2014-01-08 17:36:46 +00:00
|
|
|
return gst_vaapi_encoder_mpeg2_new (display);
|
2013-11-20 08:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-04-10 14:04:34 +00:00
|
|
|
gst_vaapiencode_mpeg2_class_init (GstVaapiEncodeMpeg2Class * klass,
|
|
|
|
gpointer data)
|
2013-11-20 08:21:32 +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:00:39 +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;
|
2013-11-20 08:21:32 +00:00
|
|
|
|
|
|
|
object_class->finalize = gst_vaapiencode_mpeg2_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;
|
2013-11-20 08:21:32 +00:00
|
|
|
|
2014-01-09 17:10:35 +00:00
|
|
|
encode_class->get_caps = gst_vaapiencode_mpeg2_get_caps;
|
2014-01-09 09:09:38 +00:00
|
|
|
encode_class->alloc_encoder = gst_vaapiencode_mpeg2_alloc_encoder;
|
2013-11-20 08:21:32 +00:00
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (element_class,
|
2013-11-28 09:54:36 +00:00
|
|
|
"VA-API MPEG-2 encoder",
|
2018-10-12 14:39:53 +00:00
|
|
|
"Codec/Encoder/Video/Hardware",
|
2013-11-28 09:54:36 +00:00
|
|
|
GST_PLUGIN_DESC, "Guangxin Xu <guangxin.xu@intel.com>");
|
2013-11-20 08:21:32 +00:00
|
|
|
|
|
|
|
/* sink pad */
|
2020-04-10 14:04:34 +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:04:34 +00:00
|
|
|
gst_caps_unref (sink_caps);
|
2013-11-20 08:21:32 +00:00
|
|
|
|
|
|
|
/* src pad */
|
2020-07-08 11:00:39 +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:00:39 +00:00
|
|
|
gst_caps_unref (src_caps);
|
2013-11-20 08:21:32 +00:00
|
|
|
|
2019-08-20 15:56:33 +00:00
|
|
|
encoder_class = g_type_class_ref (GST_TYPE_VAAPI_ENCODER_MPEG2);
|
|
|
|
g_assert (encoder_class);
|
|
|
|
gst_vaapiencode_class_install_properties (encode_class, encoder_class);
|
|
|
|
g_type_class_unref (encoder_class);
|
2013-11-20 08:21:32 +00:00
|
|
|
}
|