forked from felipec/gst-av
/
gstav_h263enc.c
136 lines (107 loc) · 2.67 KB
/
gstav_h263enc.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
/*
* Copyright (C) 2009-2012 Felipe Contreras
*
* Author: Felipe Contreras <felipe.contreras@gmail.com>
*
* This file may be used under the terms of the GNU Lesser General Public
* License version 2.1.
*/
#include "gstav_h263enc.h"
#include "gstav_venc.h"
#include "plugin.h"
#include <libavcodec/avcodec.h>
#include <gst/tag/tag.h>
#include <stdlib.h>
#include <string.h> /* for memcpy */
#include <stdbool.h>
#include "util.h"
#define GST_CAT_DEFAULT gstav_debug
struct obj {
struct gst_av_venc parent;
};
struct obj_class {
GstElementClass parent_class;
};
static GstCaps *
generate_src_template(void)
{
GstCaps *caps;
GstStructure *struc;
caps = gst_caps_new_empty();
struc = gst_structure_new("video/x-h263",
"variant", G_TYPE_STRING, "itu",
"h263version", G_TYPE_STRING, "h263",
NULL);
gst_caps_append_structure(caps, struc);
return caps;
}
static GstCaps *
generate_sink_template(void)
{
GstCaps *caps, *templ;
struct size {
int width;
int height;
} sizes[] = {
{ 352, 288 },
{ 704, 576 },
{ 176, 144 },
{ 128, 96 },
};
caps = gst_caps_new_empty();
templ = gst_caps_new_simple("video/x-raw-yuv",
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('I', '4', '2', '0'),
"pixel-aspect-ratio", GST_TYPE_FRACTION, 12, 11,
NULL);
for (unsigned i = 0; i < ARRAY_SIZE(sizes); i++) {
GstCaps *tmp;
tmp = gst_caps_copy(templ);
gst_caps_set_simple(tmp,
"width", G_TYPE_INT, sizes[i].width,
"height", G_TYPE_INT, sizes[i].height,
NULL);
gst_caps_append(caps, tmp);
}
gst_caps_unref(templ);
return caps;
}
static void
instance_init(GTypeInstance *instance, void *g_class)
{
struct gst_av_venc *venc = (struct gst_av_venc *)instance;
venc->codec_id = CODEC_ID_H263;
}
static void
base_init(void *g_class)
{
GstElementClass *element_class = g_class;
GstPadTemplate *template;
gst_element_class_set_details_simple(element_class,
"av h263 video encoder",
"Coder/Encoder/Video",
"H.263 encoder wrapper for libavcodec",
"Felipe Contreras");
template = gst_pad_template_new("src", GST_PAD_SRC,
GST_PAD_ALWAYS,
generate_src_template());
gst_element_class_add_pad_template(element_class, template);
template = gst_pad_template_new("sink", GST_PAD_SINK,
GST_PAD_ALWAYS,
generate_sink_template());
gst_element_class_add_pad_template(element_class, template);
}
GType
gst_av_h263enc_get_type(void)
{
static GType type;
if (G_UNLIKELY(type == 0)) {
GTypeInfo type_info = {
.class_size = sizeof(struct obj_class),
.base_init = base_init,
.instance_size = sizeof(struct obj),
.instance_init = instance_init,
};
type = g_type_register_static(GST_AV_VENC_TYPE, "GstAVH263Enc", &type_info, 0);
}
return type;
}