1 /*
2 * Copyright (C) 2019 Philipp Zabel <philipp.zabel@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21 #include "gstv4l2mpeg2codec.h"
22
23 #include <gst/gst.h>
24 #include "ext/v4l2-controls.h"
25
26 static gint
v4l2_profile_from_string(const gchar * profile)27 v4l2_profile_from_string (const gchar * profile)
28 {
29 gint v4l2_profile = -1;
30
31 if (g_str_equal (profile, "simple"))
32 v4l2_profile = V4L2_MPEG_VIDEO_MPEG2_PROFILE_SIMPLE;
33 else if (g_str_equal (profile, "main"))
34 v4l2_profile = V4L2_MPEG_VIDEO_MPEG2_PROFILE_MAIN;
35 else if (g_str_equal (profile, "snr"))
36 v4l2_profile = V4L2_MPEG_VIDEO_MPEG2_PROFILE_SNR_SCALABLE;
37 else if (g_str_equal (profile, "spatial"))
38 v4l2_profile = V4L2_MPEG_VIDEO_MPEG2_PROFILE_SPATIALLY_SCALABLE;
39 else if (g_str_equal (profile, "high"))
40 v4l2_profile = V4L2_MPEG_VIDEO_MPEG2_PROFILE_HIGH;
41 else if (g_str_equal (profile, "multiview"))
42 v4l2_profile = V4L2_MPEG_VIDEO_MPEG2_PROFILE_MULTIVIEW;
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_MPEG2_PROFILE_SIMPLE:
54 return "simple";
55 case V4L2_MPEG_VIDEO_MPEG2_PROFILE_MAIN:
56 return "main";
57 case V4L2_MPEG_VIDEO_MPEG2_PROFILE_SNR_SCALABLE:
58 return "snr";
59 case V4L2_MPEG_VIDEO_MPEG2_PROFILE_SPATIALLY_SCALABLE:
60 return "spatial";
61 case V4L2_MPEG_VIDEO_MPEG2_PROFILE_HIGH:
62 return "high";
63 case V4L2_MPEG_VIDEO_MPEG2_PROFILE_MULTIVIEW:
64 return "multiview";
65 default:
66 GST_WARNING ("Unsupported V4L2 profile %i", v4l2_profile);
67 break;
68 }
69
70 return NULL;
71 }
72
73 static gint
v4l2_level_from_string(const gchar * level)74 v4l2_level_from_string (const gchar * level)
75 {
76 gint v4l2_level = -1;
77
78 if (g_str_equal (level, "low"))
79 v4l2_level = V4L2_MPEG_VIDEO_MPEG2_LEVEL_LOW;
80 else if (g_str_equal (level, "main"))
81 v4l2_level = V4L2_MPEG_VIDEO_MPEG2_LEVEL_MAIN;
82 else if (g_str_equal (level, "high-1440"))
83 v4l2_level = V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH_1440;
84 else if (g_str_equal (level, "high"))
85 v4l2_level = V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH;
86 else
87 GST_WARNING ("Unsupported level '%s'", level);
88
89 return v4l2_level;
90 }
91
92 static const gchar *
v4l2_level_to_string(gint v4l2_level)93 v4l2_level_to_string (gint v4l2_level)
94 {
95 switch (v4l2_level) {
96 case V4L2_MPEG_VIDEO_MPEG2_LEVEL_LOW:
97 return "low";
98 case V4L2_MPEG_VIDEO_MPEG2_LEVEL_MAIN:
99 return "main";
100 case V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH_1440:
101 return "high-1440";
102 case V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH:
103 return "high";
104 default:
105 GST_WARNING ("Unsupported V4L2 level %i", v4l2_level);
106 break;
107 }
108
109 return NULL;
110 }
111
112 const GstV4l2Codec *
gst_v4l2_mpeg2_get_codec(void)113 gst_v4l2_mpeg2_get_codec (void)
114 {
115 static GstV4l2Codec *codec = NULL;
116 if (g_once_init_enter (&codec)) {
117 static GstV4l2Codec c;
118 c.profile_cid = V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE;
119 c.profile_to_string = v4l2_profile_to_string;
120 c.profile_from_string = v4l2_profile_from_string;
121 c.level_cid = V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL;
122 c.level_to_string = v4l2_level_to_string;
123 c.level_from_string = v4l2_level_from_string;
124 g_once_init_leave (&codec, &c);
125 }
126 return codec;
127 }
128