|
31 | 31 | json_str = json.dumps(text) |
32 | 32 | category = '' |
33 | 33 | connector = '' |
| 34 | + class_name = '' |
34 | 35 | if stem.startswith(MIST_IN): |
35 | 36 | category = "inputs" |
36 | 37 | connector = stem[len(MIST_IN):] |
| 38 | + class_name = "Mist::In" + connector |
37 | 39 | elif stem.startswith(MIST_OUT): |
38 | 40 | category = "connectors" |
39 | 41 | connector = stem[len(MIST_OUT):] |
| 42 | + class_name = "Mist::Out" + connector |
40 | 43 | else: |
41 | 44 | raise Exception("unknown binary naming convention: " + stem) |
42 | 45 | capabilities.append({ |
43 | 46 | 'json_str': json_str, |
44 | 47 | 'category': category, |
45 | 48 | 'connector': connector, |
| 49 | + 'class_name': class_name, |
| 50 | + 'binary_name' : stem, |
46 | 51 | }) |
47 | 52 |
|
48 | 53 | cap_lines = [ |
|
62 | 67 |
|
63 | 68 | out_fullpath = os.path.join(os.getcwd(), args.cap_header) |
64 | 69 | 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)) |
0 commit comments