1 /*
2 * Copyright (C) 2018 NVIDIA CORPORATION.
3 * Author: Amit Pandya <apandya@nvidia.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 "gstv4l2h265enc.h"
34 #include "gstv4l2h265codec.h"
35
36 #include <string.h>
37 #include <gst/gst-i18n-plugin.h>
38
39 GST_DEBUG_CATEGORY_STATIC (gst_v4l2_h265_enc_debug);
40 #define GST_CAT_DEFAULT gst_v4l2_h265_enc_debug
41
42 static GstStaticCaps src_template_caps =
43 GST_STATIC_CAPS ("video/x-h265, stream-format=(string) byte-stream, "
44 "alignment=(string) au");
45
46 enum
47 {
48 PROP_0,
49 V4L2_STD_OBJECT_PROPS,
50 /* TODO add H265 controls */
51 };
52
53 #define gst_v4l2_h265_enc_parent_class parent_class
54 G_DEFINE_TYPE (GstV4l2H265Enc, gst_v4l2_h265_enc, GST_TYPE_V4L2_VIDEO_ENC);
55
56 static void
gst_v4l2_h265_enc_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)57 gst_v4l2_h265_enc_set_property (GObject * object,
58 guint prop_id, const GValue * value, GParamSpec * pspec)
59 {
60 /* TODO */
61 }
62
63 static void
gst_v4l2_h265_enc_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)64 gst_v4l2_h265_enc_get_property (GObject * object,
65 guint prop_id, GValue * value, GParamSpec * pspec)
66 {
67 /* TODO */
68 }
69
70 static void
gst_v4l2_h265_enc_init(GstV4l2H265Enc * self)71 gst_v4l2_h265_enc_init (GstV4l2H265Enc * self)
72 {
73 }
74
75 static void
gst_v4l2_h265_enc_class_init(GstV4l2H265EncClass * klass)76 gst_v4l2_h265_enc_class_init (GstV4l2H265EncClass * klass)
77 {
78 GstElementClass *element_class;
79 GObjectClass *gobject_class;
80 GstV4l2VideoEncClass *baseclass;
81
82 parent_class = g_type_class_peek_parent (klass);
83
84 element_class = (GstElementClass *) klass;
85 gobject_class = (GObjectClass *) klass;
86 baseclass = (GstV4l2VideoEncClass *) (klass);
87
88 GST_DEBUG_CATEGORY_INIT (gst_v4l2_h265_enc_debug, "v4l2h265enc", 0,
89 "V4L2 H.265 Encoder");
90
91 gst_element_class_set_static_metadata (element_class,
92 "V4L2 H.265 Encoder",
93 "Codec/Encoder/Video/Hardware",
94 "Encode H.265 video streams via V4L2 API",
95 "Amit Pandya <apandya@nvidia.com>");
96
97 gobject_class->set_property =
98 GST_DEBUG_FUNCPTR (gst_v4l2_h265_enc_set_property);
99 gobject_class->get_property =
100 GST_DEBUG_FUNCPTR (gst_v4l2_h265_enc_get_property);
101
102 baseclass->codec_name = "H265";
103 }
104
105 /* Probing functions */
106 gboolean
gst_v4l2_is_h265_enc(GstCaps * sink_caps,GstCaps * src_caps)107 gst_v4l2_is_h265_enc (GstCaps * sink_caps, GstCaps * src_caps)
108 {
109 return gst_v4l2_is_video_enc (sink_caps, src_caps,
110 gst_static_caps_get (&src_template_caps));
111 }
112
113 void
gst_v4l2_h265_enc_register(GstPlugin * plugin,const gchar * basename,const gchar * device_path,gint video_fd,GstCaps * sink_caps,GstCaps * src_caps)114 gst_v4l2_h265_enc_register (GstPlugin * plugin, const gchar * basename,
115 const gchar * device_path, gint video_fd, GstCaps * sink_caps,
116 GstCaps * src_caps)
117 {
118 const GstV4l2Codec *codec = gst_v4l2_h265_get_codec ();
119 gst_v4l2_video_enc_register (plugin, GST_TYPE_V4L2_H265_ENC,
120 "h265", basename, device_path, codec, video_fd, sink_caps,
121 gst_static_caps_get (&src_template_caps), src_caps);
122 }
123