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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gst/vaapi/sysdeps.h"
|
2013-11-26 15:34:14 +00:00
|
|
|
#include <gst/vaapi/gstvaapidisplay.h>
|
|
|
|
#include <gst/vaapi/gstvaapiencoder_mpeg2.h>
|
2013-11-20 08:21:32 +00:00
|
|
|
#include "gstvaapiencode_mpeg2.h"
|
|
|
|
#include "gstvaapipluginutil.h"
|
2013-11-27 15:27:31 +00:00
|
|
|
#if GST_CHECK_VERSION(1,0,0)
|
2013-11-07 09:42:21 +00:00
|
|
|
#include "gstvaapivideomemory.h"
|
2013-11-27 15:27:31 +00:00
|
|
|
#endif
|
2013-11-20 08:21:32 +00:00
|
|
|
|
2013-11-28 09:54:36 +00:00
|
|
|
#define GST_PLUGIN_NAME "vaapiencode_mpeg2"
|
|
|
|
#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
|
|
|
|
2014-01-03 15:57:25 +00:00
|
|
|
/* *INDENT-OFF* */
|
2013-11-20 08:21:32 +00:00
|
|
|
static const char gst_vaapiencode_mpeg2_sink_caps_str[] =
|
2013-11-07 09:42:21 +00:00
|
|
|
#if GST_CHECK_VERSION(1,1,0)
|
2014-01-03 15:57:25 +00:00
|
|
|
GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE,
|
2013-11-07 09:42:21 +00:00
|
|
|
"{ ENCODED, NV12, I420, YV12 }") ", "
|
|
|
|
#else
|
2013-11-26 14:31:03 +00:00
|
|
|
GST_VAAPI_SURFACE_CAPS ", "
|
2013-11-07 09:42:21 +00:00
|
|
|
#endif
|
2013-11-26 14:31:03 +00:00
|
|
|
GST_CAPS_INTERLACED_FALSE "; "
|
2013-11-27 15:27:31 +00:00
|
|
|
#if GST_CHECK_VERSION(1,0,0)
|
2013-11-26 14:31:03 +00:00
|
|
|
GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) ", "
|
2013-11-27 15:27:31 +00:00
|
|
|
#else
|
|
|
|
"video/x-raw-yuv, "
|
|
|
|
"width = (int) [ 1, MAX ], "
|
|
|
|
"height = (int) [ 1, MAX ], "
|
|
|
|
#endif
|
2013-11-26 14:31:03 +00:00
|
|
|
GST_CAPS_INTERLACED_FALSE;
|
2014-01-03 15:57:25 +00:00
|
|
|
/* *INDENT-ON* */
|
2013-11-20 08:21:32 +00:00
|
|
|
|
2014-01-03 15:57:25 +00:00
|
|
|
/* *INDENT-OFF* */
|
2013-11-20 08:21:32 +00:00
|
|
|
static const char gst_vaapiencode_mpeg2_src_caps_str[] =
|
2014-01-09 17:10:35 +00:00
|
|
|
GST_CODEC_CAPS;
|
2014-01-03 15:57:25 +00:00
|
|
|
/* *INDENT-ON* */
|
2013-11-20 08:21:32 +00:00
|
|
|
|
2014-01-03 15:57:25 +00:00
|
|
|
/* *INDENT-OFF* */
|
2013-11-20 08:21:32 +00:00
|
|
|
static GstStaticPadTemplate gst_vaapiencode_mpeg2_sink_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2014-01-03 15:57:25 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (gst_vaapiencode_mpeg2_sink_caps_str));
|
|
|
|
/* *INDENT-ON* */
|
2013-11-20 08:21:32 +00:00
|
|
|
|
2014-01-03 15:57:25 +00:00
|
|
|
/* *INDENT-OFF* */
|
2013-11-20 08:21:32 +00:00
|
|
|
static GstStaticPadTemplate gst_vaapiencode_mpeg2_src_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2014-01-03 15:57:25 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (gst_vaapiencode_mpeg2_src_caps_str));
|
|
|
|
/* *INDENT-ON* */
|
2013-11-20 08:21:32 +00:00
|
|
|
|
|
|
|
/* mpeg2 encode */
|
2014-01-03 15:57:25 +00:00
|
|
|
G_DEFINE_TYPE (GstVaapiEncodeMpeg2, gst_vaapiencode_mpeg2,
|
|
|
|
GST_TYPE_VAAPIENCODE);
|
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
|
|
|
{
|
2014-01-08 17:36:46 +00:00
|
|
|
gst_vaapiencode_init_properties (GST_VAAPIENCODE_CAST (encode));
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapiencode_mpeg2_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2014-01-08 17:36:46 +00:00
|
|
|
GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_GET_CLASS (object);
|
|
|
|
GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (object);
|
2013-11-20 08:21:32 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
2014-01-08 17:36:46 +00:00
|
|
|
if (!encode_class->set_property (base_encode, prop_id, value))
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2013-11-20 08:21:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapiencode_mpeg2_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2014-01-08 17:36:46 +00:00
|
|
|
GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_GET_CLASS (object);
|
|
|
|
GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (object);
|
2013-11-20 08:21:32 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
2014-01-08 17:36:46 +00:00
|
|
|
if (!encode_class->get_property (base_encode, prop_id, value))
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2013-11-20 08:21:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gst_vaapiencode_mpeg2_class_init (GstVaapiEncodeMpeg2Class * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *const object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *const element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_CLASS (klass);
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_vaapi_mpeg2_encode_debug,
|
2013-11-28 09:54:36 +00:00
|
|
|
GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
|
2013-11-20 08:21:32 +00:00
|
|
|
|
|
|
|
object_class->finalize = gst_vaapiencode_mpeg2_finalize;
|
|
|
|
object_class->set_property = gst_vaapiencode_mpeg2_set_property;
|
|
|
|
object_class->get_property = gst_vaapiencode_mpeg2_get_property;
|
|
|
|
|
2014-01-08 17:36:46 +00:00
|
|
|
encode_class->get_properties = gst_vaapi_encoder_mpeg2_get_default_properties;
|
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",
|
2013-11-20 08:21:32 +00:00
|
|
|
"Codec/Encoder/Video",
|
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 */
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2014-01-03 15:57:25 +00:00
|
|
|
gst_static_pad_template_get (&gst_vaapiencode_mpeg2_sink_factory));
|
2013-11-20 08:21:32 +00:00
|
|
|
|
|
|
|
/* src pad */
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2014-01-03 15:57:25 +00:00
|
|
|
gst_static_pad_template_get (&gst_vaapiencode_mpeg2_src_factory));
|
2013-11-20 08:21:32 +00:00
|
|
|
|
2014-01-08 17:36:46 +00:00
|
|
|
gst_vaapiencode_class_init_properties (encode_class);
|
2013-11-20 08:21:32 +00:00
|
|
|
}
|