-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfarsight.cpp
84 lines (72 loc) · 2.24 KB
/
farsight.cpp
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
// std
#include <cstdio>
#include <cstdlib>
#include <exception>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
// json
#include <nlohmann/json.hpp>
// IFF SDK
#include <iff.h>
#ifdef __aarch64__
#pragma message("Make sure that configuration file uses YV12 output format instead of default NV12")
#endif
constexpr char CONFIG_FILENAME[] = "farsight.json";
int main()
{
nlohmann::json config;
try
{
config = nlohmann::json::parse(std::ifstream(CONFIG_FILENAME), nullptr, true, true);
}
catch(const std::exception& e)
{
std::cerr << "Invalid configuration provided: " << e.what() << "\n";
return EXIT_FAILURE;
}
const auto it_chains = config.find("chains");
if(it_chains == config.end())
{
std::cerr << "Invalid configuration provided: missing `chains` section\n";
return EXIT_FAILURE;
}
if(!it_chains->is_array())
{
std::cerr << "Invalid configuration provided: section `chains` must be an array\n";
return EXIT_FAILURE;
}
if(it_chains->empty())
{
std::cerr << "Invalid configuration provided: section `chains` must not be empty\n";
return EXIT_FAILURE;
}
const auto it_iff = config.find("IFF");
if(it_iff == config.end())
{
std::cerr << "Invalid configuration provided: missing `IFF` section\n";
return EXIT_FAILURE;
}
iff_initialize(it_iff->dump().c_str());
std::vector<iff_chain_handle_t> chain_handles;
for(const auto& chain_config : *it_chains)
{
const auto chain_handle = iff_create_chain(chain_config.dump().c_str(),
[](const char* const element_name, const int error_code)
{
std::ostringstream message;
message << "Chain element `" << element_name << "` reported an error: " << error_code;
iff_log(IFF_LOG_LEVEL_ERROR, message.str().c_str());
});
chain_handles.push_back(chain_handle);
}
iff_log(IFF_LOG_LEVEL_INFO, "Press Enter to terminate the program");
std::getchar();
for(const auto chain_handle : chain_handles)
{
iff_release_chain(chain_handle);
}
iff_finalize();
return EXIT_SUCCESS;
}