Skip to content

Commit 9836dd6

Browse files
committed
onebinary: working entrypoint generation
1 parent 697ceb8 commit 9836dd6

File tree

4 files changed

+67
-55
lines changed

4 files changed

+67
-55
lines changed

meson.build

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,10 @@ onebinary_stuff = []
209209
onebinary_stuff += 'MistOutRTMP'
210210
onebinary_stuff += 'MistOutHLS'
211211
onebinary_stuff += 'MistOutHTTP'
212-
onebinary_stuff += 'MistInBuffer'
212+
# onebinary_stuff += 'MistInBuffer'
213213

214214
onebinary_tgts = []
215+
onebinary_sources = []
215216

216217
## This makes sure all (installable) executables are build in top level directory
217218
## Done because MistController expects its binaries to all be in the same directory
@@ -236,19 +237,19 @@ foreach exec : executables
236237
endforeach
237238

238239
prog_python = find_program('python3')
240+
script = files('scripts/onebinary_gen.py')
239241

240242
onebinary_header = custom_target('onebinary',
241243
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+
output: ['controller_static_capabilities.cpp', 'mistserver.cpp'],
245+
command: [prog_python, script, '--cap-header', '@OUTPUT0@', '--entrypoint', '@OUTPUT1@', '@INPUT@'],
244246
depends: [onebinary_tgts]
245247
)
246248

247249
onebinary = executable(
248250
'MistServer',
249251
[
250252
files(
251-
'src/mistserver.cpp',
252253
'src/input/input.cpp',
253254
'src/input/input_buffer.cpp',
254255
'src/output/output.cpp',
@@ -271,6 +272,7 @@ onebinary = executable(
271272
'src/controller/controller_push.cpp',
272273
'src/controller/controller_variables.cpp',
273274
),
275+
onebinary_sources,
274276
io_cpp,
275277
header_tgts,
276278
embed_tgts,

scripts/onebinary_gen.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,23 @@
3131
json_str = json.dumps(text)
3232
category = ''
3333
connector = ''
34+
class_name = ''
3435
if stem.startswith(MIST_IN):
3536
category = "inputs"
3637
connector = stem[len(MIST_IN):]
38+
class_name = "Mist::In" + connector
3739
elif stem.startswith(MIST_OUT):
3840
category = "connectors"
3941
connector = stem[len(MIST_OUT):]
42+
class_name = "Mist::Out" + connector
4043
else:
4144
raise Exception("unknown binary naming convention: " + stem)
4245
capabilities.append({
4346
'json_str': json_str,
4447
'category': category,
4548
'connector': connector,
49+
'class_name': class_name,
50+
'binary_name' : stem,
4651
})
4752

4853
cap_lines = [
@@ -62,3 +67,58 @@
6267

6368
out_fullpath = os.path.join(os.getcwd(), args.cap_header)
6469
Path(out_fullpath).write_text('\n'.join(cap_lines))
70+
71+
entrypoint_lines = []
72+
73+
entrypoint_lines.extend([
74+
'#include <mist/config.h>',
75+
'#include <mist/defines.h>',
76+
'#include <mist/socket.h>',
77+
'#include <mist/util.h>',
78+
'#include <mist/stream.h>',
79+
'#include "src/output/mist_out.cpp"',
80+
'#include "src/output/output_rtmp.h"',
81+
'#include "src/output/output_hls.h"',
82+
'#include "src/output/output_http_internal.h"',
83+
'#include "src/input/mist_in.cpp"',
84+
'#include "src/input/input_buffer.h"',
85+
'#include "src/session.cpp"',
86+
'#include "src/controller/controller.cpp"',
87+
'int main(int argc, char *argv[]){',
88+
' if (argc < 2) {',
89+
' return ControllerMain(argc, argv);',
90+
' }',
91+
' // Create a new argv array without argv[1]',
92+
' int new_argc = argc - 1;',
93+
' char** new_argv = new char*[new_argc];',
94+
' for (int i = 0, j = 0; i < argc; ++i) {',
95+
' if (i != 1) {',
96+
' new_argv[j++] = argv[i];',
97+
' }',
98+
' }',
99+
' if (strcmp(argv[1], "MistController") == 0) {',
100+
' return ControllerMain(new_argc, new_argv);',
101+
' }',
102+
])
103+
104+
for cap in capabilities:
105+
entrypoint_lines.extend([
106+
' else if (strcmp(argv[1], "' + cap['binary_name'] + '") == 0) {',
107+
' return OutputMain<' + cap['class_name'] + '>(new_argc, new_argv);',
108+
' }',
109+
])
110+
111+
entrypoint_lines.extend([
112+
' else if (strcmp(argv[1], "MistSession") == 0) {',
113+
' return SessionMain(new_argc, new_argv);',
114+
' }',
115+
' else {',
116+
' return ControllerMain(argc, argv);',
117+
' }',
118+
' INFO_MSG("binary not found: %s", argv[1]);',
119+
' return 202;',
120+
'}',
121+
])
122+
123+
entrypoint_fullpath = os.path.join(os.getcwd(), args.entrypoint)
124+
Path(entrypoint_fullpath).write_text('\n'.join(entrypoint_lines))

src/input/input_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ namespace Mist{
6060
}// namespace Mist
6161

6262
#ifndef ONE_BINARY
63-
typedef Mist::inputBuffer mistIn;
63+
typedef Mist::InputBuffer mistIn;
6464
#endif

src/mistserver.cpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)