vaapisink: Expose the overlay capability for compatibility with dvbsuboverlay.
[platform/upstream/gstreamer.git] / gst / vaapi / gstvaapiencode_mpeg2.c
1 /*
2  *  gstvaapiencode_mpeg2.c - VA-API MPEG2 encoder
3  *
4  *  Copyright (C) 2012-2014 Intel Corporation
5  *    Author: Guangxin Xu <guangxin.xu@intel.com>
6  *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
7  *
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.
12  *
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.
17  *
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
22  */
23
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"
30
31 #define GST_PLUGIN_NAME "vaapiencode_mpeg2"
32 #define GST_PLUGIN_DESC "A VA-API based MPEG-2 video encoder"
33
34 GST_DEBUG_CATEGORY_STATIC (gst_vaapi_mpeg2_encode_debug);
35 #define GST_CAT_DEFAULT gst_vaapi_mpeg2_encode_debug
36
37 #define GST_CODEC_CAPS                          \
38   "video/mpeg, mpegversion = (int) 2, "         \
39   "systemstream = (boolean) false"
40
41 /* *INDENT-OFF* */
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;
48 /* *INDENT-ON* */
49
50 /* *INDENT-OFF* */
51 static const char gst_vaapiencode_mpeg2_src_caps_str[] =
52   GST_CODEC_CAPS;
53 /* *INDENT-ON* */
54
55 /* *INDENT-OFF* */
56 static GstStaticPadTemplate gst_vaapiencode_mpeg2_sink_factory =
57   GST_STATIC_PAD_TEMPLATE ("sink",
58       GST_PAD_SINK,
59       GST_PAD_ALWAYS,
60       GST_STATIC_CAPS (gst_vaapiencode_mpeg2_sink_caps_str));
61 /* *INDENT-ON* */
62
63 /* *INDENT-OFF* */
64 static GstStaticPadTemplate gst_vaapiencode_mpeg2_src_factory =
65   GST_STATIC_PAD_TEMPLATE ("src",
66       GST_PAD_SRC,
67       GST_PAD_ALWAYS,
68       GST_STATIC_CAPS (gst_vaapiencode_mpeg2_src_caps_str));
69 /* *INDENT-ON* */
70
71 /* mpeg2 encode */
72 G_DEFINE_TYPE (GstVaapiEncodeMpeg2, gst_vaapiencode_mpeg2,
73     GST_TYPE_VAAPIENCODE);
74
75 static void
76 gst_vaapiencode_mpeg2_init (GstVaapiEncodeMpeg2 * encode)
77 {
78   gst_vaapiencode_init_properties (GST_VAAPIENCODE_CAST (encode));
79 }
80
81 static void
82 gst_vaapiencode_mpeg2_finalize (GObject * object)
83 {
84   G_OBJECT_CLASS (gst_vaapiencode_mpeg2_parent_class)->finalize (object);
85 }
86
87 static void
88 gst_vaapiencode_mpeg2_set_property (GObject * object,
89     guint prop_id, const GValue * value, GParamSpec * pspec)
90 {
91   GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_GET_CLASS (object);
92   GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (object);
93
94   switch (prop_id) {
95     default:
96       if (!encode_class->set_property (base_encode, prop_id, value))
97         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
98       break;
99   }
100 }
101
102 static void
103 gst_vaapiencode_mpeg2_get_property (GObject * object,
104     guint prop_id, GValue * value, GParamSpec * pspec)
105 {
106   GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_GET_CLASS (object);
107   GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (object);
108
109   switch (prop_id) {
110     default:
111       if (!encode_class->get_property (base_encode, prop_id, value))
112         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
113       break;
114   }
115 }
116
117 static GstCaps *
118 gst_vaapiencode_mpeg2_get_caps (GstVaapiEncode * base_encode)
119 {
120   GstCaps *caps;
121
122   caps = gst_caps_from_string (GST_CODEC_CAPS);
123
124   /* XXX: update profile and level information */
125   return caps;
126 }
127
128 static GstVaapiEncoder *
129 gst_vaapiencode_mpeg2_alloc_encoder (GstVaapiEncode * base,
130     GstVaapiDisplay * display)
131 {
132   return gst_vaapi_encoder_mpeg2_new (display);
133 }
134
135 static void
136 gst_vaapiencode_mpeg2_class_init (GstVaapiEncodeMpeg2Class * klass)
137 {
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);
141
142   GST_DEBUG_CATEGORY_INIT (gst_vaapi_mpeg2_encode_debug,
143       GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
144
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;
148
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;
152
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>");
157
158   /* sink pad */
159   gst_element_class_add_pad_template (element_class,
160       gst_static_pad_template_get (&gst_vaapiencode_mpeg2_sink_factory));
161
162   /* src pad */
163   gst_element_class_add_pad_template (element_class,
164       gst_static_pad_template_get (&gst_vaapiencode_mpeg2_src_factory));
165
166   gst_vaapiencode_class_init_properties (encode_class);
167 }