Skip to content

Commit 697ceb8

Browse files
committed
onebinary: working header generation
1 parent 6e095ab commit 697ceb8

File tree

12 files changed

+195
-78
lines changed

12 files changed

+195
-78
lines changed

meson.build

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,88 @@ subdir('test')
203203

204204
exec_tgts = []
205205

206+
make_header = find_program('scripts/make_header.sh')
207+
208+
onebinary_stuff = []
209+
onebinary_stuff += 'MistOutRTMP'
210+
onebinary_stuff += 'MistOutHLS'
211+
onebinary_stuff += 'MistOutHTTP'
212+
onebinary_stuff += 'MistInBuffer'
213+
214+
onebinary_tgts = []
215+
206216
## This makes sure all (installable) executables are build in top level directory
207217
## Done because MistController expects its binaries to all be in the same directory
208218
foreach exec : executables
209-
exec_tgts += executable(
219+
my_exec = executable(
210220
exec.get('name'),
211221
exec.get('sources'),
212222
dependencies: exec.get('deps'),
213223
cpp_args: exec.get('defines'),
214224
install: true,
215225
)
226+
exec_tgts += my_exec
227+
gen_src_name = exec.get('name') + '.json'
228+
gen_src = custom_target(gen_src_name,
229+
input: [my_exec],
230+
output: [exec.get('name') + '.json'],
231+
command: [make_header, '@INPUT@', '@OUTPUT0@']
232+
)
233+
if onebinary_stuff.contains(exec.get('name'))
234+
onebinary_tgts += gen_src
235+
endif
216236
endforeach
217237

238+
prog_python = find_program('python3')
239+
240+
onebinary_header = custom_target('onebinary',
241+
input: [onebinary_tgts],
242+
output: ['controller_static_capabilities.cpp'],
243+
command: [prog_python, '../scripts/onebinary_gen.py', '--cap-header', '@OUTPUT0@', '--entrypoint', 'foo.cpp', '@INPUT@'],
244+
depends: [onebinary_tgts]
245+
)
246+
247+
onebinary = executable(
248+
'MistServer',
249+
[
250+
files(
251+
'src/mistserver.cpp',
252+
'src/input/input.cpp',
253+
'src/input/input_buffer.cpp',
254+
'src/output/output.cpp',
255+
'src/output/output_hls.cpp',
256+
'src/output/output_http.cpp',
257+
'src/output/output_http_internal.cpp',
258+
'src/output/output_ts.cpp',
259+
'src/output/output_ts_base.cpp',
260+
'src/output/output_rtmp.cpp',
261+
'src/controller/controller_external_writers.cpp',
262+
'src/controller/controller_updater.cpp',
263+
'src/controller/controller_streams.cpp',
264+
'src/controller/controller_storage.cpp',
265+
'src/controller/controller_connectors.cpp',
266+
'src/controller/controller_statistics.cpp',
267+
'src/controller/controller_limits.cpp',
268+
'src/controller/controller_capabilities.cpp',
269+
'src/controller/controller_uplink.cpp',
270+
'src/controller/controller_api.cpp',
271+
'src/controller/controller_push.cpp',
272+
'src/controller/controller_variables.cpp',
273+
),
274+
io_cpp,
275+
header_tgts,
276+
embed_tgts,
277+
server_html,
278+
onebinary_header,
279+
],
280+
cpp_args: [
281+
'-DTS_BASECLASS=HTTPOutput',
282+
'-DONE_BINARY=1',
283+
],
284+
dependencies : [libmist_dep],
285+
install: true,
286+
)
287+
218288
# Docs
219289
doxygen = find_program('doxygen', required: false)
220290
if doxygen.found()

scripts/make_header.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
set +e
6+
json="$(./$1 -j)"
7+
status=$?
8+
set -e
9+
echo "$json" > $2
10+
if [[ "$status" == "255" ]]; then
11+
exit 0
12+
fi
13+
exit $status

scripts/onebinary_gen.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python
2+
3+
# Generates files necessary with hardcoded capabilities for Python
4+
5+
import os
6+
from pathlib import Path
7+
import json
8+
import argparse
9+
10+
parser = argparse.ArgumentParser(
11+
prog='onebinary_gen.py',
12+
description='Generates header files necessary to create the MistServer combined binary'
13+
)
14+
15+
parser.add_argument('--cap-header', help="location of the generated capabilities header", required=True)
16+
parser.add_argument('--entrypoint', help="location of the generated entrypoint file", required=True)
17+
parser.add_argument('files', metavar='N', type=str, nargs='+', help='input binary json files generated elsewhere')
18+
19+
args = parser.parse_args()
20+
21+
MIST_IN = "MistIn"
22+
MIST_OUT = "MistOut"
23+
CAP_LINE = ' capabilities["{category}"]["{connector}"] = JSON::fromString({json_str});'
24+
25+
capabilities = []
26+
27+
for name in args.files:
28+
path = Path(name)
29+
stem = path.stem
30+
text = path.read_text().strip("\n")
31+
json_str = json.dumps(text)
32+
category = ''
33+
connector = ''
34+
if stem.startswith(MIST_IN):
35+
category = "inputs"
36+
connector = stem[len(MIST_IN):]
37+
elif stem.startswith(MIST_OUT):
38+
category = "connectors"
39+
connector = stem[len(MIST_OUT):]
40+
else:
41+
raise Exception("unknown binary naming convention: " + stem)
42+
capabilities.append({
43+
'json_str': json_str,
44+
'category': category,
45+
'connector': connector,
46+
})
47+
48+
cap_lines = [
49+
'#include "src/controller/controller_capabilities_static.h"',
50+
'namespace Controller{',
51+
' void addStaticCapabilities(JSON::Value &capabilities) {',
52+
]
53+
54+
for cap in capabilities:
55+
line = CAP_LINE.format(**cap)
56+
cap_lines.append(line)
57+
58+
cap_lines.extend([
59+
' }',
60+
'}',
61+
])
62+
63+
out_fullpath = os.path.join(os.getcwd(), args.cap_header)
64+
Path(out_fullpath).write_text('\n'.join(cap_lines))

src/controller/controller.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,3 +677,8 @@ int ControllerMain(int argc, char **argv){
677677
return 0;
678678
}
679679

680+
#ifndef ONE_BINARY
681+
int main(int argc, char **argv){
682+
return ControllerMain(argc, argv);
683+
}
684+
#endif

src/controller/controller_capabilities.cpp

Lines changed: 5 additions & 9 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <mist/config.h>
2+
3+
namespace Controller{
4+
5+
/// Add capabilities
6+
void addStaticCapabilities(JSON::Value &capabilities);
7+
}

src/input/input_buffer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ namespace Mist{
5858
std::map<size_t, size_t> sourcePids;
5959
};
6060
}// namespace Mist
61+
62+
#ifndef ONE_BINARY
63+
typedef Mist::inputBuffer mistIn;
64+
#endif

src/input/mist_in.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef ONE_BINARY
2+
#include INPUTTYPE
3+
#endif
14
#include <mist/util.h>
25

36
template<class T>
@@ -7,3 +10,9 @@ int InputMain(int argc, char *argv[]){
710
T conv(&conf);
811
return conv.boot(argc, argv);
912
}
13+
14+
#ifndef ONE_BINARY
15+
int main(int argc, char *argv[]){
16+
return InputMain<mistIn>(argc, argv);
17+
}
18+
#endif

src/meson.build

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,71 +13,3 @@ executables += {
1313
'defines': [],
1414
'deps' : [libmist_dep]
1515
}
16-
17-
executables += {
18-
'name': 'MistServer',
19-
'sources': [
20-
files(
21-
'mistserver.cpp',
22-
'input/input.cpp',
23-
'input/input_buffer.cpp',
24-
'output/output.cpp',
25-
'output/output_hls.cpp',
26-
'output/output_http.cpp',
27-
'output/output_http_internal.cpp',
28-
'output/output_ts.cpp',
29-
'output/output_ts_base.cpp',
30-
'output/output_rtmp.cpp',
31-
'controller/controller_external_writers.cpp',
32-
'controller/controller_updater.cpp',
33-
'controller/controller_streams.cpp',
34-
'controller/controller_storage.cpp',
35-
'controller/controller_connectors.cpp',
36-
'controller/controller_statistics.cpp',
37-
'controller/controller_limits.cpp',
38-
'controller/controller_capabilities.cpp',
39-
'controller/controller_uplink.cpp',
40-
'controller/controller_api.cpp',
41-
'controller/controller_push.cpp',
42-
'controller/controller_variables.cpp',
43-
),
44-
io_cpp,
45-
header_tgts,
46-
embed_tgts,
47-
server_html
48-
],
49-
'defines': [
50-
'-DTS_BASECLASS=HTTPOutput',
51-
'-DONE_BINARY=true',
52-
],
53-
'deps' : [libmist_dep]
54-
}
55-
56-
# executables += {
57-
# 'name': 'MistServer',
58-
# 'sources': [
59-
# files(
60-
# 'output/mist_out.cpp',
61-
# 'output/output.cpp',
62-
# 'output/output_rtmp.cpp'
63-
# ),
64-
# io_cpp,
65-
# header_tgts
66-
# ],
67-
# 'defines': [
68-
# string_opt.format('OUTPUTTYPE', 'output_rtmp.h')
69-
# ],
70-
# 'deps' : [libmist_dep]
71-
# }
72-
# executables += {
73-
# 'name': 'MistOut'+output.get('name'),
74-
# 'sources' : [
75-
# sources,
76-
# header_tgts
77-
# ],
78-
# 'deps' : deps,
79-
# 'defines' : [
80-
# string_opt.format('OUTPUTTYPE', 'output_'+output.get('format')+'.h'),
81-
# '-DTS_BASECLASS='+tsBaseClass
82-
# ]
83-
# }

src/output/mist_out.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef ONE_BINARY
2+
#include OUTPUTTYPE
3+
#endif
14
#include <mist/config.h>
25
#include <mist/defines.h>
36
#include <mist/socket.h>
@@ -74,3 +77,9 @@ int OutputMain(int argc, char *argv[]){
7477
INFO_MSG("Exit reason: %s", Util::exitReason);
7578
return 0;
7679
}
80+
81+
#ifndef ONE_BINARY
82+
int main(int argc, char *argv[]){
83+
return OutputMain<mistOut>(argc, argv);
84+
}
85+
#endif

0 commit comments

Comments
 (0)