9 #if defined(_WIN32) || defined(WIN32)
39 std::string
GetEnv(
const std::string& name)
41 char *data=getenv(name.c_str());
43 return std::string(data);
50 bool stopthread=
false;
52 #if defined(_WIN32) || defined(WIN32)
54 _setmode(_fileno(stdin), _O_BINARY);
55 _setmode(_fileno(stdout), _O_BINARY);
63 std::cerr <<
"ProcessLoop: input stopped"<< std::endl;
67 if (stopthread)
break;
72 std::cerr <<
"Failed to write audio output" << std::endl;
79 void Usage(
const char *progname)
81 std::cerr <<
"Usage: " << progname << std::endl;;
82 std::cerr <<
" Reads audio from stdin and return processed audio in stdout" << std::endl;
83 std::cerr <<
"Environment:"<< std::endl;;
84 std::cerr <<
" - S4STORE_PATH : path to store config [default: (no storage)]"<< std::endl;;
85 std::cerr <<
" - S4LOGINKEY : SOUND4 Login key (or S4USERID)"<< std::endl;;
86 std::cerr <<
" - RADIO_NAME : SOUND4 Radio Name"<< std::endl;;
87 std::cerr <<
" - S4_AWS_ACCESS_KEY_ID : SOUND4 Access Key ID"<< std::endl;;
88 std::cerr <<
" - S4_AWS_SECRET_ACCESS_KEY: SOUND4 Access Key Secret"<< std::endl;;
89 std::cerr << std::endl;
90 std::cerr <<
"Example:"<< std::endl;
91 std::cerr <<
"ffmpeg -re -i file.wav -ar "<<sound4::impact::GetSampleRate()<<
" -ac "<<sound4::impact::GetChannelCount()<<
" -f f32le - | "<<progname<<
" | ffplay -f f32le -ar "<<sound4::impact::GetSampleRate()<<
" -ac "<<sound4::impact::GetChannelCount()<<
" -i -" << std::endl;;
92 #if defined(_WIN32) || defined(WIN32)
93 std::cerr <<
"ffmpeg -f dshow -i audio=\"Microphone\" -ar "<<sound4::impact::GetSampleRate()<<
" -ac "<<sound4::impact::GetChannelCount()<<
" -f f32le - | "<<progname<<
" | ffplay -f f32le -ar "<<sound4::impact::GetSampleRate()<<
" -ac "<<sound4::impact::GetChannelCount()<<
" -i -" << std::endl;;
95 std::cerr <<
"ffmpeg -f pulse -i default -ar "<<sound4::impact::GetSampleRate()<<
" -ac "<<sound4::impact::GetChannelCount()<<
" -f f32le - | "<<progname<<
" | ffplay -f f32le -ar "<<sound4::impact::GetSampleRate()<<
" -ac "<<sound4::impact::GetChannelCount()<<
" -i -" << std::endl;;
101 std::cerr << msg << std::endl;
104 int main(
int argc,
const char **argv)
106 int listen_port = 8080;
107 auto store_path=
GetEnv(
"S4STORE_PATH");
110 auto LoginKey=
GetEnv(
"S4LOGINKEY");
111 if (LoginKey.empty()) {
112 LoginKey=
GetEnv(
"S4USERID");
114 auto RadioName=
GetEnv(
"RADIO_NAME");
115 auto KeyId=
GetEnv(
"S4_AWS_ACCESS_KEY_ID");
116 auto AccessKey=
GetEnv(
"S4_AWS_SECRET_ACCESS_KEY");
118 const char *progname=argv[0];
121 if ((strcasecmp(argv[1],
"-h")==0) || (strcasecmp(argv[1],
"--help")==0)) {
126 if (LoginKey.empty() || RadioName.empty() || KeyId.empty() || AccessKey.empty()) {
127 std::cerr <<
"Missing credentials in environment" << std::endl;
131 if (!store_path.empty()) {
132 if (!std::filesystem::exists(store_path) || !std::filesystem::is_directory(store_path)) {
133 std::cerr <<
"Storage folder '"<<store_path<<
"' is not a valid directory" << std::endl;
140 sound4::impact::SetLogSeverity(
verbose5);
141 sound4::impact::SetLoggerCallback(
MyLogger);
144 instance.
SetParam(
"ADMIN_USER",
"admin");
145 instance.
SetParam(
"ADMIN_SECRET",
"admin");
148 std::cerr <<
"Creating" << std::endl;
150 if (!instance.
Create(LoginKey, RadioName, KeyId, AccessKey, store_path)) {
151 std::cerr <<
"Failed to create the processing instance" << std::endl;
156 std::cerr <<
"Starting web server" << std::endl;
159 std::cerr <<
"Failed to create the web server on port " << listen_port << std::endl;
167 auto answer = client->ProcessJson(R
"JSON({"get":{"processorname":null}})JSON");
168 std::cerr << "Request for processor name returned "<<answer<<std::endl;
174 std::cerr <<
"Stopping now" << std::endl;
177 std::cerr <<
"End" << std::endl;
std::shared_ptr< CClient > NewClient()
void SetParam(const std::string &name, const std::string &value)
bool StartWebServer(int http_port, int https_port=0)
std::array< float, OutputSampleSize > & GetBufferOut()
bool Create(const std::string &LoginKey, const std::string &RadioName, const std::string &AWS_Access_ID, const std::string &AWS_Access_Secret, const std::string &save_path, int json_port=0)
std::array< float, InputSampleSize > & GetBufferIn()
const size_t OutputSampleSize
const size_t InputSampleSize
int main(int argc, const char **argv)
std::string GetEnv(const std::string &name)
void MyLogger(sound4::impact::LogSeverity severity, const std::string &msg)
void Usage(const char *progname)
void ProcessLoop(sound4::impact::CInstance &instance)