1 /*
2 * Copyright (C) 2014 SUMOMO Computer Association
3 * Author: ayaka <ayaka@soulik.info>
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 "gstv4l2h264enc.h"
34 #include "gstv4l2h264codec.h"
35
36 #include <string.h>
37 #include <gst/gst-i18n-plugin.h>
38
39 GST_DEBUG_CATEGORY_STATIC (gst_v4l2_h264_enc_debug);
40 #define GST_CAT_DEFAULT gst_v4l2_h264_enc_debug
41
42
43 static GstStaticCaps src_template_caps =
44 GST_STATIC_CAPS ("video/x-h264, stream-format=(string) byte-stream, "
45 "alignment=(string) au");
46
47 enum
48 {
49 PROP_0,
50 V4L2_STD_OBJECT_PROPS,
51 /* TODO add H264 controls
52 * PROP_I_FRAME_QP,
53 * PROP_P_FRAME_QP,
54 * PROP_B_FRAME_QP,
55 * PROP_MIN_QP,
56 * PROP_MAX_QP,
57 * PROP_8x8_TRANSFORM,
58 * PROP_CPB_SIZE,
59 * PROP_ENTROPY_MODE,
60 * PROP_I_PERIOD,
61 * PROP_LOOP_FILTER_ALPHA,
62 * PROP_LOOP_FILTER_BETA,
63 * PROP_LOOP_FILTER_MODE,
64 * PROP_VUI_EXT_SAR_HEIGHT,
65 * PROP_VUI_EXT_SAR_WIDTH,
66 * PROP_VUI_SAR_ENABLED,
67 * PROP_VUI_SAR_IDC,
68 * PROP_SEI_FRAME_PACKING,
69 * PROP_SEI_FP_CURRENT_FRAME_0,
70 * PROP_SEI_FP_ARRANGEMENT_TYP,
71 * ...
72 * */
73 };
74
75 #define gst_v4l2_h264_enc_parent_class parent_class
76 G_DEFINE_TYPE (GstV4l2H264Enc, gst_v4l2_h264_enc, GST_TYPE_V4L2_VIDEO_ENC);
77
78 static void
gst_v4l2_h264_enc_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)79 gst_v4l2_h264_enc_set_property (GObject * object,
80 guint prop_id, const GValue * value, GParamSpec * pspec)
81 {
82 /* TODO */
83 }
84
85 static void
gst_v4l2_h264_enc_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)86 gst_v4l2_h264_enc_get_property (GObject * object,
87 guint prop_id, GValue * value, GParamSpec * pspec)
88 {
89 /* TODO */
90 }
91
92 static void
gst_v4l2_h264_enc_init(GstV4l2H264Enc * self)93 gst_v4l2_h264_enc_init (GstV4l2H264Enc * self)
94 {
95 }
96
97 static void
gst_v4l2_h264_enc_class_init(GstV4l2H264EncClass * klass)98 gst_v4l2_h264_enc_class_init (GstV4l2H264EncClass * klass)
99 {
100 GstElementClass *element_class;
101 GObjectClass *gobject_class;
102 GstV4l2VideoEncClass *baseclass;
103
104 parent_class = g_type_class_peek_parent (klass);
105
106 element_class = (GstElementClass *) klass;
107 gobject_class = (GObjectClass *) klass;
108 baseclass = (GstV4l2VideoEncClass *) (klass);
109
110 GST_DEBUG_CATEGORY_INIT (gst_v4l2_h264_enc_debug, "v4l2h264enc", 0,
111 "V4L2 H.264 Encoder");
112
113 gst_element_class_set_static_metadata (element_class,
114 "V4L2 H.264 Encoder",
115 "Codec/Encoder/Video/Hardware",
116 "Encode H.264 video streams via V4L2 API", "ayaka <ayaka@soulik.info>");
117
118 gobject_class->set_property =
119 GST_DEBUG_FUNCPTR (gst_v4l2_h264_enc_set_property);
120 gobject_class->get_property =
121 GST_DEBUG_FUNCPTR (gst_v4l2_h264_enc_get_property);
122
123 baseclass->codec_name = "H264";
124 }
125
126 /* Probing functions */
127 gboolean
gst_v4l2_is_h264_enc(GstCaps * sink_caps,GstCaps * src_caps)128 gst_v4l2_is_h264_enc (GstCaps * sink_caps, GstCaps * src_caps)
129 {
130 return gst_v4l2_is_video_enc (sink_caps, src_caps,
131 gst_static_caps_get (&src_template_caps));
132 }
133
134 void
gst_v4l2_h264_enc_register(GstPlugin * plugin,const gchar * basename,const gchar * device_path,gint video_fd,GstCaps * sink_caps,GstCaps * src_caps)135 gst_v4l2_h264_enc_register (GstPlugin * plugin, const gchar * basename,
136 const gchar * device_path, gint video_fd, GstCaps * sink_caps,
137 GstCaps * src_caps)
138 {
139 const GstV4l2Codec *codec = gst_v4l2_h264_get_codec ();
140 gst_v4l2_video_enc_register (plugin, GST_TYPE_V4L2_H264_ENC,
141 "h264", basename, device_path, codec, video_fd, sink_caps,
142 gst_static_caps_get (&src_template_caps), src_caps);
143 }
144