2 * gstvaapiencode_mpeg2.c - VA-API MPEG2 encoder
4 * Copyright (C) 2012-2013 Intel Corporation
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 #include "gst/vaapi/sysdeps.h"
23 #include <gst/vaapi/gstvaapidisplay.h>
24 #include <gst/vaapi/gstvaapiencoder_mpeg2.h>
25 #include "gstvaapiencode_mpeg2.h"
26 #include "gstvaapipluginutil.h"
27 #if GST_CHECK_VERSION(1,0,0)
28 #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 #if GST_CHECK_VERSION(1,1,0)
44 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE,
45 "{ ENCODED, NV12, I420, YV12 }") ", "
47 GST_VAAPI_SURFACE_CAPS ", "
49 GST_CAPS_INTERLACED_FALSE "; "
50 #if GST_CHECK_VERSION(1,0,0)
51 GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) ", "
54 "width = (int) [ 1, MAX ], "
55 "height = (int) [ 1, MAX ], "
57 GST_CAPS_INTERLACED_FALSE;
61 static const char gst_vaapiencode_mpeg2_src_caps_str[] =
66 static GstStaticPadTemplate gst_vaapiencode_mpeg2_sink_factory =
67 GST_STATIC_PAD_TEMPLATE ("sink",
70 GST_STATIC_CAPS (gst_vaapiencode_mpeg2_sink_caps_str));
74 static GstStaticPadTemplate gst_vaapiencode_mpeg2_src_factory =
75 GST_STATIC_PAD_TEMPLATE ("src",
78 GST_STATIC_CAPS (gst_vaapiencode_mpeg2_src_caps_str));
82 G_DEFINE_TYPE (GstVaapiEncodeMpeg2, gst_vaapiencode_mpeg2,
83 GST_TYPE_VAAPIENCODE);
86 gst_vaapiencode_mpeg2_init (GstVaapiEncodeMpeg2 * encode)
88 gst_vaapiencode_init_properties (GST_VAAPIENCODE_CAST (encode));
92 gst_vaapiencode_mpeg2_finalize (GObject * object)
94 G_OBJECT_CLASS (gst_vaapiencode_mpeg2_parent_class)->finalize (object);
98 gst_vaapiencode_mpeg2_set_property (GObject * object,
99 guint prop_id, const GValue * value, GParamSpec * pspec)
101 GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_GET_CLASS (object);
102 GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (object);
106 if (!encode_class->set_property (base_encode, prop_id, value))
107 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
113 gst_vaapiencode_mpeg2_get_property (GObject * object,
114 guint prop_id, GValue * value, GParamSpec * pspec)
116 GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_GET_CLASS (object);
117 GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (object);
121 if (!encode_class->get_property (base_encode, prop_id, value))
122 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
128 gst_vaapiencode_mpeg2_get_caps (GstVaapiEncode * base_encode)
132 caps = gst_caps_from_string (GST_CODEC_CAPS);
134 /* XXX: update profile and level information */
138 static GstVaapiEncoder *
139 gst_vaapiencode_mpeg2_alloc_encoder (GstVaapiEncode * base,
140 GstVaapiDisplay * display)
142 return gst_vaapi_encoder_mpeg2_new (display);
146 gst_vaapiencode_mpeg2_class_init (GstVaapiEncodeMpeg2Class * klass)
148 GObjectClass *const object_class = G_OBJECT_CLASS (klass);
149 GstElementClass *const element_class = GST_ELEMENT_CLASS (klass);
150 GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_CLASS (klass);
152 GST_DEBUG_CATEGORY_INIT (gst_vaapi_mpeg2_encode_debug,
153 GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
155 object_class->finalize = gst_vaapiencode_mpeg2_finalize;
156 object_class->set_property = gst_vaapiencode_mpeg2_set_property;
157 object_class->get_property = gst_vaapiencode_mpeg2_get_property;
159 encode_class->get_properties = gst_vaapi_encoder_mpeg2_get_default_properties;
160 encode_class->get_caps = gst_vaapiencode_mpeg2_get_caps;
161 encode_class->alloc_encoder = gst_vaapiencode_mpeg2_alloc_encoder;
163 gst_element_class_set_static_metadata (element_class,
164 "VA-API MPEG-2 encoder",
165 "Codec/Encoder/Video",
166 GST_PLUGIN_DESC, "Guangxin Xu <guangxin.xu@intel.com>");
169 gst_element_class_add_pad_template (element_class,
170 gst_static_pad_template_get (&gst_vaapiencode_mpeg2_sink_factory));
173 gst_element_class_add_pad_template (element_class,
174 gst_static_pad_template_get (&gst_vaapiencode_mpeg2_src_factory));
176 gst_vaapiencode_class_init_properties (encode_class);