/
gstdsph264enc.c
180 lines (150 loc) · 4.34 KB
/
gstdsph264enc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* Copyright (C) 2009-2010 Felipe Contreras
* Copyright (C) 2009-2010 Nokia Corporation
*
* Authors:
* Juha Alanen <juha.m.alanen@nokia.com>
* Felipe Contreras <felipe.contreras@nokia.com>
*
* This file may be used under the terms of the GNU Lesser General Public
* License version 2.1, a copy of which is found in LICENSE included in the
* packaging of this file.
*/
#include "gstdsph264enc.h"
#include "plugin.h"
#include "util.h"
#include "dsp_bridge.h"
#include "log.h"
#define GST_CAT_DEFAULT gstdsp_debug
/*
* H.264 supported levels
* Source http://www.itu.int/rec/T-REC-H.264-201003-I/ page 294 - Annex A table A-1
* the bitrates of the last 2 levels is not up to standard due to encdoder
* limitations.
*/
static struct gstdsp_codec_level levels[] = {
{10, 99, 1485 , 64000 }, /* Level 1 - QCIF@15fps */
{10, 99, 1485 , 128000 }, /* Level 1b - QCIF@15fps */
{11, 396, 3000 , 192000 }, /* Level 1.1 - QCIF@30fps */
{12, 396, 6000 , 384000 }, /* Level 1.2 - CIF@15fps */
{13, 396, 11880 , 768000 }, /* Level 1.3- CIF@30fps */
{20, 396, 11880 , 2000000 }, /* Level 2 - CIF@30fps */
{21, 792, 19800 , 4000000 }, /* Level 2.1 - 352x480@30fps */
{22, 1620, 20250 , 4000000 }, /* Level 2.2 - 720x480@15fps */
{30, 1620, 40500 , 8000000 }, /* Level 3 - D1@25/30fps (PAL/NTSC) --> 10Mbps */
{31, 3600, 48600 , 8000000 }, /* Max supported (WVGA) - 864x480@30fps */
};
enum {
ARG_0,
#ifdef GST_DSP_ENABLE_DEPRECATED
ARG_BYTESTREAM,
#endif
};
static inline GstCaps *
generate_src_template(void)
{
GstCaps *caps;
GstStructure *struc;
caps = gst_caps_new_empty();
struc = gst_structure_new("video/x-h264",
NULL);
gst_caps_append_structure(caps, struc);
return caps;
}
static void
instance_init(GTypeInstance *instance,
gpointer g_class)
{
GstDspBase *base = GST_DSP_BASE(instance);
GstDspVEnc *self = GST_DSP_VENC(instance);
base->alg = GSTDSP_H264ENC;
base->codec = &td_h264enc_codec;
self->priv.h264.bytestream = true;
self->supported_levels = levels;
self->nr_supported_levels = ARRAY_SIZE(levels);
base->use_pinned = true;
}
static void
base_init(gpointer g_class)
{
GstElementClass *element_class;
GstPadTemplate *template;
element_class = GST_ELEMENT_CLASS(g_class);
gst_element_class_set_details_simple(element_class,
"DSP video encoder",
"Codec/Encoder/Video",
"Encodes H.264 video with TI's DSP algorithms",
"Juha Alanen");
template = gst_pad_template_new("src", GST_PAD_SRC,
GST_PAD_ALWAYS,
generate_src_template());
gst_element_class_add_pad_template(element_class, template);
gst_object_unref(template);
}
static void
set_property(GObject *obj,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GstDspVEnc *self G_GNUC_UNUSED = GST_DSP_VENC(obj);
switch (prop_id) {
#ifdef GST_DSP_ENABLE_DEPRECATED
case ARG_BYTESTREAM:
self->priv.h264.bytestream = g_value_get_boolean(value);
break;
#endif
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
break;
}
}
static void
get_property(GObject *obj,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GstDspVEnc *self G_GNUC_UNUSED = GST_DSP_VENC(obj);
switch (prop_id) {
#ifdef GST_DSP_ENABLE_DEPRECATED
case ARG_BYTESTREAM:
g_value_set_boolean(value, self->priv.h264.bytestream);
break;
#endif
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
break;
}
}
static void
class_init(gpointer g_class,
gpointer class_data)
{
GObjectClass *gobject_class;
gobject_class = G_OBJECT_CLASS(g_class);
/* Properties stuff */
gobject_class->set_property = set_property;
gobject_class->get_property = get_property;
#ifdef GST_DSP_ENABLE_DEPRECATED
g_object_class_install_property(gobject_class, ARG_BYTESTREAM,
g_param_spec_boolean("bytestream", "BYTESTREAM", "bytestream",
true, G_PARAM_READWRITE));
#endif
}
GType
gst_dsp_h264enc_get_type(void)
{
static GType type;
if (G_UNLIKELY(type == 0)) {
GTypeInfo type_info = {
.class_size = sizeof(GstDspH264EncClass),
.base_init = base_init,
.class_init = class_init,
.instance_size = sizeof(GstDspH264Enc),
.instance_init = instance_init,
};
type = g_type_register_static(GST_DSP_VENC_TYPE, "GstDspH264Enc", &type_info, 0);
}
return type;
}