1 /*
2 * Copyright (C) 2017 Collabora Inc.
3 * Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
4 * Factored out from gstv4l2vp9enc 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 "gstv4l2vp9codec.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, "0"))
39 v4l2_profile = 0;
40 else if (g_str_equal (profile, "1"))
41 v4l2_profile = 1;
42 else if (g_str_equal (profile, "2"))
43 v4l2_profile = 2;
44 else if (g_str_equal (profile, "3"))
45 v4l2_profile = 3;
46 else
47 GST_WARNING ("Unsupported profile string '%s'", profile);
48
49 return v4l2_profile;
50 }
51
52 static const gchar *
v4l2_profile_to_string(gint v4l2_profile)53 v4l2_profile_to_string (gint v4l2_profile)
54 {
55 switch (v4l2_profile) {
56 case 0:
57 return "0";
58 case 1:
59 return "1";
60 case 2:
61 return "2";
62 case 3:
63 return "3";
64 default:
65 GST_WARNING ("Unsupported V4L2 profile %i", v4l2_profile);
66 break;
67 }
68
69 return NULL;
70 }
71
72 const GstV4l2Codec *
gst_v4l2_vp9_get_codec(void)73 gst_v4l2_vp9_get_codec (void)
74 {
75 static GstV4l2Codec *codec = NULL;
76 if (g_once_init_enter (&codec)) {
77 static GstV4l2Codec c;
78 c.profile_cid = V4L2_CID_MPEG_VIDEO_VPX_PROFILE;
79 c.profile_to_string = v4l2_profile_to_string;
80 c.profile_from_string = v4l2_profile_from_string;
81 g_once_init_leave (&codec, &c);
82 }
83 return codec;
84 }
85