1 /*
2 * Copyright (C) 2017 Collabora Inc.
3 * Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
4 * Factored out from gstv4l2mpeg4enc by Philippe Normand <philn@igalia.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
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 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "gstv4l2mpeg4codec.h"
24
25 #include <gst/gst.h>
26 #include "ext/v4l2-controls.h"
27
28 static gint
v4l2_profile_from_string(const gchar * profile)29 v4l2_profile_from_string (const gchar * profile)
30 {
31 gint v4l2_profile = -1;
32
33 if (g_str_equal (profile, "simple"))
34 v4l2_profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE;
35 else if (g_str_equal (profile, "advanced-simple"))
36 v4l2_profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE;
37 else if (g_str_equal (profile, "core"))
38 v4l2_profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE;
39 else if (g_str_equal (profile, "simple-scalable"))
40 v4l2_profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE;
41 else if (g_str_equal (profile, "advanced-coding-efficiency"))
42 v4l2_profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY;
43 else
44 GST_WARNING ("Unsupported profile string '%s'", profile);
45
46 return v4l2_profile;
47 }
48
49 static const gchar *
v4l2_profile_to_string(gint v4l2_profile)50 v4l2_profile_to_string (gint v4l2_profile)
51 {
52 switch (v4l2_profile) {
53 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE:
54 return "simple";
55 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE:
56 return "advanced-simple";
57 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE:
58 return "core";
59 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE:
60 return "simple-scalable";
61 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY:
62 return "advanced-coding-efficiency";
63 default:
64 GST_WARNING ("Unsupported V4L2 profile %i", v4l2_profile);
65 break;
66 }
67
68 return NULL;
69 }
70
71 static gint
v4l2_level_from_string(const gchar * level)72 v4l2_level_from_string (const gchar * level)
73 {
74 gint v4l2_level = -1;
75
76 if (g_str_equal (level, "0"))
77 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_0;
78 else if (g_str_equal (level, "0b"))
79 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B;
80 else if (g_str_equal (level, "1"))
81 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_1;
82 else if (g_str_equal (level, "2"))
83 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_2;
84 else if (g_str_equal (level, "3"))
85 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_3;
86 else if (g_str_equal (level, "3b"))
87 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B;
88 else if (g_str_equal (level, "4"))
89 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_4;
90 else if (g_str_equal (level, "5"))
91 v4l2_level = V4L2_MPEG_VIDEO_MPEG4_LEVEL_5;
92 else
93 GST_WARNING ("Unsupported level '%s'", level);
94
95 return v4l2_level;
96 }
97
98 static const gchar *
v4l2_level_to_string(gint v4l2_level)99 v4l2_level_to_string (gint v4l2_level)
100 {
101 switch (v4l2_level) {
102 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_0:
103 return "0";
104 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B:
105 return "0b";
106 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_1:
107 return "1";
108 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_2:
109 return "2";
110 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_3:
111 return "3";
112 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B:
113 return "3b";
114 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_4:
115 return "4";
116 case V4L2_MPEG_VIDEO_MPEG4_LEVEL_5:
117 return "5";
118 default:
119 GST_WARNING ("Unsupported V4L2 level %i", v4l2_level);
120 break;
121 }
122
123 return NULL;
124 }
125
126 const GstV4l2Codec *
gst_v4l2_mpeg4_get_codec(void)127 gst_v4l2_mpeg4_get_codec (void)
128 {
129 static GstV4l2Codec *codec = NULL;
130 if (g_once_init_enter (&codec)) {
131 static GstV4l2Codec c;
132 c.profile_cid = V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE;
133 c.profile_to_string = v4l2_profile_to_string;
134 c.profile_from_string = v4l2_profile_from_string;
135 c.level_cid = V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL;
136 c.level_to_string = v4l2_level_to_string;
137 c.level_from_string = v4l2_level_from_string;
138 g_once_init_leave (&codec, &c);
139 }
140 return codec;
141 }
142