2 * Copyright (C) 2017 Collabora Inc.
3 * Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
32 #include "gstv4l2object.h"
33 #include "gstv4l2mpeg4enc.h"
36 #include <gst/gst-i18n-plugin.h>
38 GST_DEBUG_CATEGORY_STATIC (gst_v4l2_mpeg4_enc_debug);
39 #define GST_CAT_DEFAULT gst_v4l2_mpeg4_enc_debug
41 static GstStaticCaps src_template_caps =
42 GST_STATIC_CAPS ("video/mpeg, mpegversion=(int)4, systemstream=(boolean)FALSE");
47 V4L2_STD_OBJECT_PROPS,
51 #define gst_v4l2_mpeg4_enc_parent_class parent_class
52 G_DEFINE_TYPE (GstV4l2Mpeg4Enc, gst_v4l2_mpeg4_enc, GST_TYPE_V4L2_VIDEO_ENC);
55 gst_v4l2_mpeg4_enc_set_property (GObject * object,
56 guint prop_id, const GValue * value, GParamSpec * pspec)
62 gst_v4l2_mpeg4_enc_get_property (GObject * object,
63 guint prop_id, GValue * value, GParamSpec * pspec)
69 v4l2_profile_from_string (const gchar * profile)
71 gint v4l2_profile = -1;
73 if (g_str_equal (profile, "simple"))
74 v4l2_profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE;
75 else if (g_str_equal (profile, "advanced-simple"))
76 v4l2_profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE;
77 else if (g_str_equal (profile, "core"))
78 v4l2_profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE;
79 else if (g_str_equal (profile, "simple-scalable"))
80 v4l2_profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE;
81 else if (g_str_equal (profile, "advanced-coding-efficiency"))
82 v4l2_profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY;
84 GST_WARNING ("Unsupported profile string '%s'", profile);
90 v4l2_profile_to_string (gint v4l2_profile)
92 switch (v4l2_profile) {
93 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE:
95 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE:
96 return "advanced-simple";
97 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE:
99 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE:
100 return "simple-scalable";
101 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY:
102 return "advanced-coding-efficiency";
104 GST_WARNING ("Unsupported V4L2 profile %i", v4l2_profile);
112 v4l2_level_from_string (const gchar * level)
114 gint v4l2_level = -1;
116 if (g_str_equal (level, "0"))
117 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_0;
118 else if (g_str_equal (level, "0b"))
119 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B;
120 else if (g_str_equal (level, "1"))
121 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_1;
122 else if (g_str_equal (level, "2"))
123 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_2;
124 else if (g_str_equal (level, "3"))
125 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_3;
126 else if (g_str_equal (level, "3b"))
127 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B;
128 else if (g_str_equal (level, "4"))
129 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_4;
130 else if (g_str_equal (level, "5"))
131 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_5;
133 GST_WARNING ("Unsupported level '%s'", level);
139 v4l2_level_to_string (gint v4l2_level)
141 switch (v4l2_level) {
142 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_0:
144 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B:
146 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_1:
148 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_2:
150 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_3:
152 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B:
154 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_4:
156 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_5:
159 GST_WARNING ("Unsupported V4L2 level %i", v4l2_level);
167 gst_v4l2_mpeg4_enc_init (GstV4l2Mpeg4Enc * self)
172 gst_v4l2_mpeg4_enc_class_init (GstV4l2Mpeg4EncClass * klass)
174 GstElementClass *element_class;
175 GObjectClass *gobject_class;
176 GstV4l2VideoEncClass *baseclass;
178 parent_class = g_type_class_peek_parent (klass);
180 element_class = (GstElementClass *) klass;
181 gobject_class = (GObjectClass *) klass;
182 baseclass = (GstV4l2VideoEncClass *) (klass);
184 GST_DEBUG_CATEGORY_INIT (gst_v4l2_mpeg4_enc_debug, "v4l2mpeg4enc", 0,
185 "V4L2 MPEG4 Encoder");
187 gst_element_class_set_static_metadata (element_class,
188 "V4L2 MPEG4 Encoder",
189 "Codec/Encoder/Video",
190 "Encode MPEG4 video streams via V4L2 API",
191 "Nicolas Dufresne <nicolas.dufresne@collabora.com");
193 gobject_class->set_property =
194 GST_DEBUG_FUNCPTR (gst_v4l2_mpeg4_enc_set_property);
195 gobject_class->get_property =
196 GST_DEBUG_FUNCPTR (gst_v4l2_mpeg4_enc_get_property);
198 baseclass->codec_name = "MPEG4";
199 baseclass->profile_cid = V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE;
200 baseclass->profile_to_string = v4l2_profile_to_string;
201 baseclass->profile_from_string = v4l2_profile_from_string;
202 baseclass->level_cid = V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL;
203 baseclass->level_to_string = v4l2_level_to_string;
204 baseclass->level_from_string = v4l2_level_from_string;
207 /* Probing functions */
209 gst_v4l2_is_mpeg4_enc (GstCaps * sink_caps, GstCaps * src_caps)
211 return gst_v4l2_is_video_enc (sink_caps, src_caps,
212 gst_static_caps_get (&src_template_caps));
216 gst_v4l2_mpeg4_enc_register (GstPlugin * plugin, const gchar * basename,
217 const gchar * device_path, GstCaps * sink_caps, GstCaps * src_caps)
219 gst_v4l2_video_enc_register (plugin, GST_TYPE_V4L2_MPEG4_ENC,
220 "mpeg4", basename, device_path, sink_caps,
221 gst_static_caps_get (&src_template_caps), src_caps);