v4l2object: Don't use mmap64 if off_t is 64-bit
[platform/upstream/gst-plugins-good.git] / sys / v4l2 / gstv4l2vp9enc.c
1 /*
2  * Copyright (C) 2017 Collabora Inc.
3  *    Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <sys/stat.h>
27 #include <fcntl.h>
28 #include <errno.h>
29 #include <unistd.h>
30 #include <string.h>
31
32 #include "gstv4l2object.h"
33 #include "gstv4l2vp9enc.h"
34
35 #include <string.h>
36 #include <gst/gst-i18n-plugin.h>
37
38 GST_DEBUG_CATEGORY_STATIC (gst_v4l2_vp9_enc_debug);
39 #define GST_CAT_DEFAULT gst_v4l2_vp9_enc_debug
40
41 static GstStaticCaps src_template_caps =
42 GST_STATIC_CAPS ("video/x-vp9, profile=(string) { 0, 1, 2, 3 }");
43
44 enum
45 {
46   PROP_0,
47   V4L2_STD_OBJECT_PROPS,
48   /* TODO */
49 };
50
51 #define gst_v4l2_vp9_enc_parent_class parent_class
52 G_DEFINE_TYPE (GstV4l2Vp9Enc, gst_v4l2_vp9_enc, GST_TYPE_V4L2_VIDEO_ENC);
53
54 static void
55 gst_v4l2_vp9_enc_set_property (GObject * object,
56     guint prop_id, const GValue * value, GParamSpec * pspec)
57 {
58   /* TODO */
59 }
60
61 static void
62 gst_v4l2_vp9_enc_get_property (GObject * object,
63     guint prop_id, GValue * value, GParamSpec * pspec)
64 {
65   /* TODO */
66 }
67
68 static gint
69 v4l2_profile_from_string (const gchar * profile)
70 {
71   gint v4l2_profile = -1;
72
73   if (g_str_equal (profile, "0"))
74     v4l2_profile = 0;
75   else if (g_str_equal (profile, "1"))
76     v4l2_profile = 1;
77   else if (g_str_equal (profile, "2"))
78     v4l2_profile = 2;
79   else if (g_str_equal (profile, "3"))
80     v4l2_profile = 3;
81   else
82     GST_WARNING ("Unsupported profile string '%s'", profile);
83
84   return v4l2_profile;
85 }
86
87 static const gchar *
88 v4l2_profile_to_string (gint v4l2_profile)
89 {
90   switch (v4l2_profile) {
91     case 0:
92       return "0";
93     case 1:
94       return "1";
95     case 2:
96       return "2";
97     case 3:
98       return "3";
99     default:
100       GST_WARNING ("Unsupported V4L2 profile %i", v4l2_profile);
101       break;
102   }
103
104   return NULL;
105 }
106
107 static void
108 gst_v4l2_vp9_enc_init (GstV4l2Vp9Enc * self)
109 {
110 }
111
112 static void
113 gst_v4l2_vp9_enc_class_init (GstV4l2Vp9EncClass * klass)
114 {
115   GstElementClass *element_class;
116   GObjectClass *gobject_class;
117   GstV4l2VideoEncClass *baseclass;
118
119   parent_class = g_type_class_peek_parent (klass);
120
121   element_class = (GstElementClass *) klass;
122   gobject_class = (GObjectClass *) klass;
123   baseclass = (GstV4l2VideoEncClass *) (klass);
124
125   GST_DEBUG_CATEGORY_INIT (gst_v4l2_vp9_enc_debug, "v4l2vp9enc", 0,
126       "V4L2 VP9 Encoder");
127
128   gst_element_class_set_static_metadata (element_class,
129       "V4L2 VP9 Encoder",
130       "Codec/Encoder/Video",
131       "Encode VP9 video streams via V4L2 API",
132       "Nicolas Dufresne <nicolas.dufresne@collabora.com");
133
134   gobject_class->set_property =
135       GST_DEBUG_FUNCPTR (gst_v4l2_vp9_enc_set_property);
136   gobject_class->get_property =
137       GST_DEBUG_FUNCPTR (gst_v4l2_vp9_enc_get_property);
138
139   baseclass->codec_name = "VP9";
140   baseclass->profile_cid = V4L2_CID_MPEG_VIDEO_VPX_PROFILE;
141   baseclass->profile_to_string = v4l2_profile_to_string;
142   baseclass->profile_from_string = v4l2_profile_from_string;
143 }
144
145 /* Probing functions */
146 gboolean
147 gst_v4l2_is_vp9_enc (GstCaps * sink_caps, GstCaps * src_caps)
148 {
149   return gst_v4l2_is_video_enc (sink_caps, src_caps,
150       gst_static_caps_get (&src_template_caps));
151 }
152
153 void
154 gst_v4l2_vp9_enc_register (GstPlugin * plugin, const gchar * basename,
155     const gchar * device_path, GstCaps * sink_caps, GstCaps * src_caps)
156 {
157   gst_v4l2_video_enc_register (plugin, GST_TYPE_V4L2_VP9_ENC,
158       "vp9", basename, device_path, sink_caps,
159       gst_static_caps_get (&src_template_caps), src_caps);
160 }