2 * gstvaapiencode_mpeg2.c - VA-API MPEG2 encoder
4 * Copyright (C) 2012-2014 Intel Corporation
5 * Author: Guangxin Xu <guangxin.xu@intel.com>
6 * Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1
11 * of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA
24 #include "gstcompat.h"
25 #include <gst/vaapi/gstvaapidisplay.h>
26 #include <gst/vaapi/gstvaapiencoder_mpeg2.h>
27 #include "gstvaapiencode_mpeg2.h"
28 #include "gstvaapipluginutil.h"
29 #include "gstvaapivideomemory.h"
31 #define GST_PLUGIN_NAME "vaapiencode_mpeg2"
32 #define GST_PLUGIN_DESC "A VA-API based MPEG-2 video encoder"
34 GST_DEBUG_CATEGORY_STATIC (gst_vaapi_mpeg2_encode_debug);
35 #define GST_CAT_DEFAULT gst_vaapi_mpeg2_encode_debug
37 #define GST_CODEC_CAPS \
38 "video/mpeg, mpegversion = (int) 2, " \
39 "systemstream = (boolean) false"
42 static const char gst_vaapiencode_mpeg2_sink_caps_str[] =
43 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE,
44 "{ ENCODED, NV12, I420, YV12 }") ", "
45 GST_CAPS_INTERLACED_FALSE "; "
46 GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) ", "
47 GST_CAPS_INTERLACED_FALSE;
51 static const char gst_vaapiencode_mpeg2_src_caps_str[] =
56 static GstStaticPadTemplate gst_vaapiencode_mpeg2_sink_factory =
57 GST_STATIC_PAD_TEMPLATE ("sink",
60 GST_STATIC_CAPS (gst_vaapiencode_mpeg2_sink_caps_str));
64 static GstStaticPadTemplate gst_vaapiencode_mpeg2_src_factory =
65 GST_STATIC_PAD_TEMPLATE ("src",
68 GST_STATIC_CAPS (gst_vaapiencode_mpeg2_src_caps_str));
72 G_DEFINE_TYPE (GstVaapiEncodeMpeg2, gst_vaapiencode_mpeg2,
73 GST_TYPE_VAAPIENCODE);
76 gst_vaapiencode_mpeg2_init (GstVaapiEncodeMpeg2 * encode)
78 gst_vaapiencode_init_properties (GST_VAAPIENCODE_CAST (encode));
82 gst_vaapiencode_mpeg2_finalize (GObject * object)
84 G_OBJECT_CLASS (gst_vaapiencode_mpeg2_parent_class)->finalize (object);
88 gst_vaapiencode_mpeg2_set_property (GObject * object,
89 guint prop_id, const GValue * value, GParamSpec * pspec)
91 GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_GET_CLASS (object);
92 GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (object);
96 if (!encode_class->set_property (base_encode, prop_id, value))
97 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
103 gst_vaapiencode_mpeg2_get_property (GObject * object,
104 guint prop_id, GValue * value, GParamSpec * pspec)
106 GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_GET_CLASS (object);
107 GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (object);
111 if (!encode_class->get_property (base_encode, prop_id, value))
112 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
118 gst_vaapiencode_mpeg2_get_caps (GstVaapiEncode * base_encode)
122 caps = gst_caps_from_string (GST_CODEC_CAPS);
124 /* XXX: update profile and level information */
128 static GstVaapiEncoder *
129 gst_vaapiencode_mpeg2_alloc_encoder (GstVaapiEncode * base,
130 GstVaapiDisplay * display)
132 return gst_vaapi_encoder_mpeg2_new (display);
136 gst_vaapiencode_mpeg2_class_init (GstVaapiEncodeMpeg2Class * klass)
138 GObjectClass *const object_class = G_OBJECT_CLASS (klass);
139 GstElementClass *const element_class = GST_ELEMENT_CLASS (klass);
140 GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_CLASS (klass);
142 GST_DEBUG_CATEGORY_INIT (gst_vaapi_mpeg2_encode_debug,
143 GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
145 object_class->finalize = gst_vaapiencode_mpeg2_finalize;
146 object_class->set_property = gst_vaapiencode_mpeg2_set_property;
147 object_class->get_property = gst_vaapiencode_mpeg2_get_property;
149 encode_class->get_properties = gst_vaapi_encoder_mpeg2_get_default_properties;
150 encode_class->get_caps = gst_vaapiencode_mpeg2_get_caps;
151 encode_class->alloc_encoder = gst_vaapiencode_mpeg2_alloc_encoder;
153 gst_element_class_set_static_metadata (element_class,
154 "VA-API MPEG-2 encoder",
155 "Codec/Encoder/Video",
156 GST_PLUGIN_DESC, "Guangxin Xu <guangxin.xu@intel.com>");
159 gst_element_class_add_pad_template (element_class,
160 gst_static_pad_template_get (&gst_vaapiencode_mpeg2_sink_factory));
163 gst_element_class_add_pad_template (element_class,
164 gst_static_pad_template_get (&gst_vaapiencode_mpeg2_src_factory));
166 gst_vaapiencode_class_init_properties (encode_class);