11 #if defined(_WIN32) || defined(WIN32)
51 std::string
GetEnv(
const std::string& name)
53 char *data=getenv(name.c_str());
55 return std::string(data);
62 bool stopthread=
false;
64 #if defined(_WIN32) || defined(WIN32)
66 _setmode(_fileno(stdin), _O_BINARY);
67 _setmode(_fileno(stdout), _O_BINARY);
75 std::cerr <<
"ProcessLoop: input stopped"<< std::endl;
79 if (stopthread)
break;
84 std::cerr <<
"Failed to write audio output" << std::endl;
93 std::cerr <<
"Usage: " << progname << std::endl;;
94 std::cerr <<
" Reads audio from stdin and return processed audio in stdout" << std::endl;
95 std::cerr <<
"Environment:"<< std::endl;;
96 std::cerr <<
" - S4STORE_PATH : path to store config [default: (no storage)]"<< std::endl;;
97 std::cerr <<
" - S4LOGINKEY : SOUND4 Login key (or S4USERID)"<< std::endl;;
98 std::cerr <<
" - RADIO_NAME : SOUND4 Radio Name"<< std::endl;;
99 std::cerr <<
" - S4_AWS_ACCESS_KEY_ID : SOUND4 Access Key ID"<< std::endl;;
100 std::cerr <<
" - S4_AWS_SECRET_ACCESS_KEY: SOUND4 Access Key Secret"<< std::endl;;
102 std::cerr << std::endl;
103 std::cerr <<
"Example:"<< std::endl;
105 #if defined(_WIN32) || defined(WIN32)
115 std::cerr << msg << std::endl;
124 bool SetupPath(
const std::filesystem::path& a_preset_path)
126 m_preset_path=a_preset_path;
127 if ( !std::filesystem::exists(m_preset_path ) ) {
131 if ( !std::filesystem::is_directory(m_preset_path, ec) ) {
137 virtual bool Exists(
const std::filesystem::path &name)
override
140 return std::filesystem::exists(GetRealPath(name), ec);
142 virtual bool Remove(
const std::filesystem::path &name)
override
145 return std::filesystem::remove(GetRealPath(name), ec);
147 virtual bool Rename(
const std::filesystem::path &from,
const std::filesystem::path &to)
override
150 std::filesystem::rename(GetRealPath(from), GetRealPath(to), ec);
153 virtual std::vector<std::filesystem::path>
GetAll()
override
155 std::vector<std::filesystem::path> list;
156 for (
const auto & entry : std::filesystem::directory_iterator(m_preset_path.c_str(), std::filesystem::directory_options::skip_permission_denied)) {
157 if (entry.is_regular_file()) {
158 list.push_back(std::filesystem::relative(entry.path(),m_preset_path).native());
163 virtual std::string
Read(
const std::filesystem::path &filename)
override
165 std::ifstream f(GetRealPath(filename));
167 return std::string();
169 std::ostringstream ss;
173 virtual bool Write(
const std::filesystem::path &filename,
const std::string &content)
override
175 std::ofstream f(GetRealPath(filename));
186 std::filesystem::path m_preset_path;
187 std::filesystem::path GetRealPath(
const std::filesystem::path &name)
189 return m_preset_path / name;
194 int main(
int argc,
const char **argv)
196 #if (IMPACT_HAS_WEBSERVER)
197 int listen_port = 8080;
199 auto store_path_str=
GetEnv(
"S4STORE_PATH");
202 auto LoginKey=
GetEnv(
"S4LOGINKEY");
203 if (LoginKey.empty()) {
204 LoginKey=
GetEnv(
"S4USERID");
206 auto RadioName=
GetEnv(
"RADIO_NAME");
207 auto KeyId=
GetEnv(
"S4_AWS_ACCESS_KEY_ID");
208 auto AccessKey=
GetEnv(
"S4_AWS_SECRET_ACCESS_KEY");
210 const char *progname=argv[0];
215 if (!dynlib.
Load()) {
216 std::cerr <<
"Failed to load processing library" << std::endl;
222 if ((strcasecmp(argv[1],
"-h")==0) || (strcasecmp(argv[1],
"--help")==0)) {
223 Usage(progname,dynlib);
227 if (LoginKey.empty() || RadioName.empty() || KeyId.empty() || AccessKey.empty()) {
228 std::cerr <<
"Missing credentials in environment" << std::endl;
229 Usage(progname,dynlib);
232 std::filesystem::path store_path;
233 if (!store_path_str.empty()) {
234 store_path = std::filesystem::path(store_path_str);
235 if (!std::filesystem::exists(store_path) || !std::filesystem::is_directory(store_path)) {
236 std::cerr <<
"Storage folder '"<<store_path.c_str()<<
"' is not a valid directory" << std::endl;
237 Usage(progname,dynlib);
243 sound4::impact::dyn::SetLogSeverity(dynlib,
verbose5);
244 sound4::impact::dyn::SetLoggerCallback(dynlib,
MyLogger);
247 instance.
SetParam(
"ADMIN_USER",
"admin");
248 instance.
SetParam(
"ADMIN_SECRET",
"admin");
253 if (!store_path.empty()) {
254 if (!preset_manager.
SetupPath(store_path)) {
255 std::cerr <<
"Failed to setup the custom preset manager on path " << store_path.c_str() << std::endl;
262 std::cerr <<
"Creating" << std::endl;
264 if (!instance.
Create(LoginKey, RadioName, KeyId, AccessKey, {})) {
265 std::cerr <<
"Failed to create the processing instance" << std::endl;
270 #if (IMPACT_HAS_WEBSERVER)
271 std::cerr <<
"Starting web server" << std::endl;
274 std::cerr <<
"Failed to create the web server on port " << listen_port << std::endl;
283 auto answer = client->ProcessJson(R
"JSON({"get":{"processorname":null}})JSON");
284 std::cerr << "Request for processor name returned "<<answer<<std::endl;
290 std::cerr <<
"Stopping now" << std::endl;
293 std::cerr <<
"End" << std::endl;
virtual bool Rename(const std::filesystem::path &from, const std::filesystem::path &to) override
virtual ~MyPresetManager()=default
virtual bool Exists(const std::filesystem::path &name) override
virtual bool IsReadOnly() override
virtual bool Write(const std::filesystem::path &filename, const std::string &content) override
MyPresetManager()=default
virtual bool Remove(const std::filesystem::path &name) override
virtual std::string Read(const std::filesystem::path &filename) override
bool SetupPath(const std::filesystem::path &a_preset_path)
virtual std::vector< std::filesystem::path > GetAll() override
Dynamic library interface.
bool Load(const std::filesystem::path &path=std::filesystem::current_path())
Loads the library.
helper::DynFuncHolder< decltype(impact_GetChannelCount) > GetChannelCount
bool IsOk() const
Check if the library was loaded correctly.
helper::DynFuncHolder< decltype(impact_GetSampleRate) > GetSampleRate
std::array< float, InputSampleSize > & GetBufferIn()
std::array< float, OutputSampleSize > & GetBufferOut()
bool StartWebServer(int http_port, int https_port=0)
bool Create(const std::string &LoginKey, const std::string &RadioName, const std::string &AWS_Access_ID, const std::string &AWS_Access_Secret, const std::filesystem::path &save_path, int json_port=0, unsigned int frames_per_chunk=64)
std::shared_ptr< CClient > NewClient()
void SetPresetManager(CPresetLoader *preset_manager)
void SetParam(const std::string &name, const std::string &value)
const size_t InputSampleSize
const size_t OutputSampleSize
int main(int argc, const char **argv)
[Custom preset manager]
std::string GetEnv(const std::string &name)
void ProcessLoop(sound4::impact::dyn::CInstance &instance)
void MyLogger(sound4::impact::dyn::LogSeverity severity, const std::string &msg)
void Usage(const char *progname, sound4::impact::dyn::CDynLib &dynlib)
C++ wrapper for dynamic loading library.