1 /*
2 * Copyright (C) 2018 NVIDIA CORPORATION.
3 * Author: Amit Pandya <apandya@nvidia.com>
4 * Factored out from gstv4l2h264enc 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 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "gstv4l2h265codec.h"
28
29 #include <gst/gst.h>
30 #include "ext/v4l2-controls.h"
31
32
33 static gint
v4l2_profile_from_string(const gchar * profile)34 v4l2_profile_from_string (const gchar * profile)
35 {
36 gint v4l2_profile = -1;
37
38 if (g_str_equal (profile, "main")) {
39 v4l2_profile = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN;
40 } else if (g_str_equal (profile, "main-still-picture")) {
41 v4l2_profile = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE;
42 } else if (g_str_equal (profile, "main-10")) {
43 v4l2_profile = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10;
44 } else {
45 GST_WARNING ("Unsupported profile string '%s'", profile);
46 }
47
48 return v4l2_profile;
49 }
50
51 static const gchar *
v4l2_profile_to_string(gint v4l2_profile)52 v4l2_profile_to_string (gint v4l2_profile)
53 {
54 switch (v4l2_profile) {
55 case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN:
56 return "main";
57 case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE:
58 return "main-still-picture";
59 case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10:
60 return "main-10";
61 default:
62 GST_WARNING ("Unsupported V4L2 profile %i", v4l2_profile);
63 break;
64 }
65 return NULL;
66 }
67
68 static gint
v4l2_level_from_string(const gchar * level)69 v4l2_level_from_string (const gchar * level)
70 {
71 gint v4l2_level = -1;
72
73 if (g_str_equal (level, "1"))
74 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_1;
75 else if (g_str_equal (level, "2"))
76 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_2;
77 else if (g_str_equal (level, "2.1"))
78 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_2_1;
79 else if (g_str_equal (level, "3"))
80 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_3;
81 else if (g_str_equal (level, "3.1"))
82 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_3_1;
83 else if (g_str_equal (level, "4"))
84 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_4;
85 else if (g_str_equal (level, "4.1"))
86 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_4_1;
87 else if (g_str_equal (level, "5"))
88 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_5;
89 else if (g_str_equal (level, "5.1"))
90 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1;
91 else if (g_str_equal (level, "5.2"))
92 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_5_2;
93 else if (g_str_equal (level, "6"))
94 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_6;
95 else if (g_str_equal (level, "6.1"))
96 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_6_1;
97 else if (g_str_equal (level, "6.2"))
98 v4l2_level = V4L2_MPEG_VIDEO_HEVC_LEVEL_6_2;
99 else
100 GST_WARNING ("Unsupported level '%s'", level);
101
102 return v4l2_level;
103 }
104
105 static const gchar *
v4l2_level_to_string(gint v4l2_level)106 v4l2_level_to_string (gint v4l2_level)
107 {
108 switch (v4l2_level) {
109 case V4L2_MPEG_VIDEO_HEVC_LEVEL_1:
110 return "1";
111 case V4L2_MPEG_VIDEO_HEVC_LEVEL_2:
112 return "2";
113 case V4L2_MPEG_VIDEO_HEVC_LEVEL_2_1:
114 return "2.1";
115 case V4L2_MPEG_VIDEO_HEVC_LEVEL_3:
116 return "3";
117 case V4L2_MPEG_VIDEO_HEVC_LEVEL_3_1:
118 return "3.1";
119 case V4L2_MPEG_VIDEO_HEVC_LEVEL_4:
120 return "4";
121 case V4L2_MPEG_VIDEO_HEVC_LEVEL_4_1:
122 return "4.1";
123 case V4L2_MPEG_VIDEO_HEVC_LEVEL_5:
124 return "5";
125 case V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1:
126 return "5.1";
127 case V4L2_MPEG_VIDEO_HEVC_LEVEL_5_2:
128 return "5.2";
129 case V4L2_MPEG_VIDEO_HEVC_LEVEL_6:
130 return "6";
131 case V4L2_MPEG_VIDEO_HEVC_LEVEL_6_1:
132 return "6.1";
133 case V4L2_MPEG_VIDEO_HEVC_LEVEL_6_2:
134 return "6.2";
135 default:
136 GST_WARNING ("Unsupported V4L2 level %i", v4l2_level);
137 break;
138 }
139
140 return NULL;
141 }
142
143 const GstV4l2Codec *
gst_v4l2_h265_get_codec(void)144 gst_v4l2_h265_get_codec (void)
145 {
146 static GstV4l2Codec *codec = NULL;
147 if (g_once_init_enter (&codec)) {
148 static GstV4l2Codec c;
149 c.profile_cid = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE;
150 c.profile_to_string = v4l2_profile_to_string;
151 c.profile_from_string = v4l2_profile_from_string;
152 c.level_cid = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL;
153 c.level_to_string = v4l2_level_to_string;
154 c.level_from_string = v4l2_level_from_string;
155 g_once_init_leave (&codec, &c);
156 }
157 return codec;
158 }
159