-
Notifications
You must be signed in to change notification settings - Fork 1
/
BinaryFiler.c
107 lines (84 loc) · 2.32 KB
/
BinaryFiler.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
#include <stdio.h> /* fprintf */
#include <stdlib.h> /* calloc */
#include <string.h> /* memcpy */
#include "CTI.h"
#include "BinaryFiler.h"
#include "Images.h"
#include "Cfg.h"
#include "SourceSink.h"
static void Config_handler(Instance *pi, void *msg);
static void H264_handler(Instance *pi, void *msg);
enum { INPUT_CONFIG, INPUT_H264 };
static Input BinaryFiler_inputs[] = {
[ INPUT_CONFIG ] = { .type_label = "Config_msg", .handler = Config_handler },
[ INPUT_H264 ] = { .type_label = "H264_buffer", .handler = H264_handler },
};
//enum { /* OUTPUT_... */ };
static Output BinaryFiler_outputs[] = {
//[ OUTPUT_... ] = { .type_label = "", .destination = 0L },
};
typedef struct {
Instance i;
Sink * sink;
} BinaryFiler_private;
static int set_output(Instance *pi, const char *value)
{
BinaryFiler_private *priv = (BinaryFiler_private *)pi;
if (value[0] == '$') {
value = getenv(value+1);
if (!value) {
fprintf(stderr, "env var %s is not set\n", value+1);
return 1;
}
}
if (priv->sink) {
Sink_free(&priv->sink);
}
priv->sink = Sink_new(value);
return 0;
}
static Config config_table[] = {
{ "output", set_output, 0L, 0L },
};
static void Config_handler(Instance *pi, void *data)
{
Generic_config_handler(pi, data, config_table, table_size(config_table));
}
static void H264_handler(Instance *pi, void *data)
{
BinaryFiler_private *priv = (BinaryFiler_private *)pi;
H264_buffer *h264 = data;
dpf("%s: %d bytes\n", __func__, h264->encoded_length);
if (priv->sink) {
Sink_write(priv->sink, h264->data, h264->encoded_length);
}
H264_buffer_release(h264);
pi->counter += 1;
}
static void BinaryFiler_tick(Instance *pi)
{
Handler_message *hm;
hm = GetData(pi, 1);
if (hm) {
hm->handler(pi, hm->data);
ReleaseMessage(&hm,pi);
}
pi->counter++;
}
static void BinaryFiler_instance_init(Instance *pi)
{
}
static Template BinaryFiler_template = {
.label = "BinaryFiler",
.priv_size = sizeof(BinaryFiler_private),
.inputs = BinaryFiler_inputs,
.num_inputs = table_size(BinaryFiler_inputs),
.outputs = BinaryFiler_outputs,
.num_outputs = table_size(BinaryFiler_outputs),
.tick = BinaryFiler_tick,
.instance_init = BinaryFiler_instance_init,
};
void BinaryFiler_init(void)
{
Template_register(&BinaryFiler_template);
}