1 /*
2 * Copyright (C) 2017 Collabora Inc.
3 * Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
4 * Factored out from gstv4l2vp8enc 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 "gstv4l2vp8codec.h"
28
29 #include <gst/gst.h>
30 #include "ext/v4l2-controls.h"
31
32 static gint
v4l2_profile_from_string(const gchar * profile)33 v4l2_profile_from_string (const gchar * profile)
34 {
35 gint v4l2_profile = -1;
36
37 if (g_str_equal (profile, "0"))
38 v4l2_profile = 0;
39 else if (g_str_equal (profile, "1"))
40 v4l2_profile = 1;
41 else if (g_str_equal (profile, "2"))
42 v4l2_profile = 2;
43 else if (g_str_equal (profile, "3"))
44 v4l2_profile = 3;
45 else
46 GST_WARNING ("Unsupported profile string '%s'", profile);
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 0:
56 return "0";
57 case 1:
58 return "1";
59 case 2:
60 return "2";
61 case 3:
62 return "3";
63 default:
64 GST_WARNING ("Unsupported V4L2 profile %i", v4l2_profile);
65 break;
66 }
67
68 return NULL;
69 }
70
71 const GstV4l2Codec *
gst_v4l2_vp8_get_codec(void)72 gst_v4l2_vp8_get_codec (void)
73 {
74 static GstV4l2Codec *codec = NULL;
75 if (g_once_init_enter (&codec)) {
76 static GstV4l2Codec c;
77 c.profile_cid = V4L2_CID_MPEG_VIDEO_VPX_PROFILE;
78 c.profile_to_string = v4l2_profile_to_string;
79 c.profile_from_string = v4l2_profile_from_string;
80 g_once_init_leave (&codec, &c);
81 }
82 return codec;
83 }
84