-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranscode.c
More file actions
122 lines (106 loc) · 3.14 KB
/
transcode.c
File metadata and controls
122 lines (106 loc) · 3.14 KB
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
#include <templatizer.h>
#include <csv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <libintl.h>
#include <locale.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <templatizer.h>
#include <templatizer/query.h>
typedef struct query_context
{
tmpl_ctx_t tmpl;
tmpl_cb_t cb;
char *input_format;
char *output_format;
} *query_context_t;
/*
* Functions for interfacing with FFmpeg
*/
void initialize_ffmpeg(tmpl_ctx_t data, tmpl_cb_t cb)
{
const AVInputFormat *av_in = NULL;
void *av_ctx = NULL;
const char *p;
while((av_in = av_demuxer_iterate(&av_ctx)) != NULL) {
cb->add_control_flow(data, SWHILE_TRUE);
p = av_in->name;
cb->add_filler_text(data, p? p : "");
p = av_in->long_name;
cb->add_filler_text(data, p? p : "");
p = av_in->extensions;
cb->add_filler_text(data, p? p : "");
}
cb->add_control_flow(data, SWHILE_FALSE);
avformat_network_init();
}
/*
* Entry points
*/
int handle_key_pair
(void *data,
void *key, size_t key_len,
void *value, size_t value_len)
{
struct query_context *ctx = (struct query_context *) data;
//size_t len = value_len + 1;
//ctx->s = ctx->cb->templatizer_malloc(ctx->tmpl, len);
//memset(ctx->s, 0, len);
if (strncmp(key, "input-format", key_len) == 0)
ctx->input_format = strndup(value, value_len);
if (strncmp(key, "output-format", key_len) == 0)
ctx->output_format = strndup(value, value_len);
return 0;
}
static int init(tmpl_ctx_t data, tmpl_cb_t cb)
{
const char *method = NULL;
const char *text_audio_format = "";
const char *text_video_format = "";
const char *media_audio_format = "";
const char *media_video_format = "";
query_context_t query = NULL;
query = cb->malloc(data, sizeof(*query));
query->tmpl = data;
query->cb = cb;
tmpl_parse_query_string_get(query, handle_key_pair);
setlocale (LC_ALL, "");
bindtextdomain ("quick-transcode", "/usr/share/local/");
textdomain ("quick-transcode");
text_audio_format =
gettext("Audio format");
text_video_format =
gettext("Video format");
method = getenv("REQUEST_METHOD");
TMPL_ASSERT(method != NULL);
if (strcmp(method, "GET") == 0) {
cb->add_filler_text(data, text_audio_format);
cb->add_filler_text(data, media_audio_format);
cb->add_filler_text(data, text_video_format);
cb->add_filler_text(data, media_video_format);
/* Does FFmpeg use gettext? If so, this should come after
* gettext initialization. */
initialize_ffmpeg(data, cb);
} else if (strcmp(method, "POST") == 0) {
} else {
fputs("Status: 404 Not found\r\n"
"Content-Type: text/plain\r\n"
"\r\n"
"Page not found.",
stdout);
return 0;
}
cb->set_output_format(data, TMPL_FMT_HTML);
cb->send_default_headers(data);
puts("<!DOCTYPE html>");
cb->free(data, query);
return 0;
}
static void quit() {}
struct pollen_plugin templatizer_plugin_v1 = {
&init,
&quit
};