2024-09-04 17:57:23 +08:00
|
|
|
#include "main.h"
|
|
|
|
#include "BoostLog.h"
|
|
|
|
#include "DateTime.h"
|
2024-06-18 14:27:48 +08:00
|
|
|
#include "FFmpegResample.h"
|
2024-09-04 17:57:23 +08:00
|
|
|
#include "IoContext.h"
|
2024-06-18 14:27:48 +08:00
|
|
|
#include "OpusCodec.h"
|
2024-09-04 17:57:23 +08:00
|
|
|
#include "RkAudio.h"
|
|
|
|
#include "WebRTCPublisher.h"
|
|
|
|
#include <boost/asio/signal_set.hpp>
|
|
|
|
// #include <boost/program_options.hpp>
|
|
|
|
#include <boost/program_options/options_description.hpp>
|
|
|
|
#include <boost/program_options/parsers.hpp>
|
|
|
|
#include <boost/program_options/variables_map.hpp>
|
|
|
|
#include <com/amazonaws/kinesis/video/webrtcclient/Include.h>
|
2024-06-18 14:27:48 +08:00
|
|
|
#include <fstream>
|
|
|
|
#include <rkmedia/rkmedia_api.h>
|
|
|
|
|
|
|
|
extern void rkDemo();
|
|
|
|
extern int AI_VqeProcess_AO();
|
|
|
|
extern int AI_VqeProcess_AO1();
|
|
|
|
extern void AecTest();
|
|
|
|
extern int opus_test();
|
|
|
|
|
2024-09-04 17:57:23 +08:00
|
|
|
void signal_handler(const boost::system::error_code &error, int signal_number) {
|
|
|
|
if (!error) {
|
|
|
|
LOG(info) << "Caught signal: " << signal_number << std::endl;
|
|
|
|
|
|
|
|
LOG(info) << "task finished.";
|
|
|
|
std::exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-18 14:27:48 +08:00
|
|
|
int main(int argc, char **argv) {
|
2024-09-04 17:57:23 +08:00
|
|
|
using namespace Amass;
|
|
|
|
using namespace std::placeholders;
|
|
|
|
boost::program_options::options_description optionsDescription("Allowed options");
|
|
|
|
// clang-format off
|
|
|
|
optionsDescription.add_options()
|
|
|
|
("help,h", "produce help message")
|
|
|
|
("echo", "Self-recording and self-play test")
|
|
|
|
("record", "Record to file.")
|
|
|
|
("play", "Play pcm file.")
|
|
|
|
("vqe", boost::program_options::value<bool>(), "Enable rk 3a.")
|
|
|
|
("channels", boost::program_options::value<int>(), "set audio channles")
|
|
|
|
("path", boost::program_options::value<std::string>(), "file path")
|
|
|
|
;
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
boost::program_options::variables_map variablesMap;
|
|
|
|
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, optionsDescription), variablesMap);
|
|
|
|
boost::program_options::notify(variablesMap);
|
|
|
|
|
|
|
|
if (variablesMap.count("help")) {
|
|
|
|
std::cout << optionsDescription << std::endl;
|
|
|
|
return 1;
|
2024-06-18 14:27:48 +08:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:57:23 +08:00
|
|
|
std::shared_ptr<Task> task;
|
|
|
|
if (variablesMap.count("echo")) {
|
|
|
|
bool vqe = false;
|
|
|
|
if (variablesMap.count("vqe")) {
|
|
|
|
vqe = variablesMap["vqe"].as<bool>();
|
|
|
|
}
|
|
|
|
|
|
|
|
int channels = 2;
|
|
|
|
if (variablesMap.count("channels")) {
|
|
|
|
channels = variablesMap["channels"].as<int>();
|
2024-06-18 14:27:48 +08:00
|
|
|
}
|
2024-09-04 17:57:23 +08:00
|
|
|
|
|
|
|
auto t = std::make_shared<EchoRecordTask>();
|
|
|
|
t->setVqeEnabled(vqe);
|
|
|
|
t->setChannels(channels);
|
|
|
|
task = std::dynamic_pointer_cast<Task>(t);
|
|
|
|
} else if (variablesMap.count("record")) {
|
|
|
|
task = std::make_shared<RecorderTask>();
|
|
|
|
} else if (variablesMap.count("play")) {
|
|
|
|
std::string path;
|
|
|
|
if (variablesMap.count("path")) {
|
|
|
|
path = variablesMap["path"].as<std::string>();
|
|
|
|
}
|
2024-09-04 20:17:15 +08:00
|
|
|
|
|
|
|
int channels = 2;
|
|
|
|
if (variablesMap.count("channels")) {
|
|
|
|
channels = variablesMap["channels"].as<int>();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:57:23 +08:00
|
|
|
auto t = std::make_shared<PlayerTask>();
|
2024-09-04 20:17:15 +08:00
|
|
|
t->setChannels(channels);
|
2024-09-04 17:57:23 +08:00
|
|
|
t->setPath(path);
|
|
|
|
task = std::dynamic_pointer_cast<Task>(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!task) {
|
|
|
|
std::cout << "there is not task." << std::endl << std::endl;
|
|
|
|
std::cout << optionsDescription << std::endl;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
LOG(info) << "app start.";
|
|
|
|
RK_MPI_SYS_Init();
|
|
|
|
initKvsWebRtc();
|
|
|
|
auto ioConext = Singleton<IoContext>::instance<Construct>();
|
|
|
|
boost::asio::signal_set signals(*ioConext->ioContext(), SIGINT, SIGTERM);
|
|
|
|
signals.async_wait(std::bind(&signal_handler, _1, _2));
|
|
|
|
|
|
|
|
task->run();
|
|
|
|
|
|
|
|
ioConext->run<IoContext::Mode::Synchronous>();
|
|
|
|
} catch (std::exception &e) {
|
|
|
|
LOG(error) << "Exception: " << e.what() << std::endl;
|
2024-06-18 14:27:48 +08:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:57:23 +08:00
|
|
|
// WebRTCPublisher publisher(true, true);
|
|
|
|
// publisher.start("172.16.103.68", "443", "/index/api/webrtc?app=live&stream=test&type=push");
|
2024-06-18 14:27:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|