2024-03-12 14:46:37 +08:00
|
|
|
#include "BoostLog.h"
|
2024-03-13 11:40:55 +08:00
|
|
|
#include "DateTime.h"
|
|
|
|
#include "IoContext.h"
|
|
|
|
#include "Live555RtspPusher.h"
|
2024-03-13 18:01:36 +08:00
|
|
|
#include "RtspServer.h"
|
2024-03-13 11:40:55 +08:00
|
|
|
#include "VideoInput.h"
|
|
|
|
#include "rw_mpp_api.h"
|
|
|
|
#include <boost/asio/signal_set.hpp>
|
|
|
|
#include <fstream>
|
2024-03-12 14:46:37 +08:00
|
|
|
|
2024-03-13 11:40:55 +08:00
|
|
|
int main(int argc, char const *argv[]) {
|
|
|
|
LOG(info) << "app start...";
|
|
|
|
int status = rw_mpp__init();
|
|
|
|
if (status != 0) {
|
|
|
|
LOG(error) << "rw_mpp__init() failed, status: " << status;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
auto ioContext = Amass::Singleton<IoContext>::instance<Amass::Construct>();
|
|
|
|
auto pusher = std::make_shared<Live555RtspPusher>(*ioContext->ioContext());
|
2024-03-13 18:01:36 +08:00
|
|
|
auto rtsp = std::make_shared<RtspServer>();
|
2024-03-13 11:40:55 +08:00
|
|
|
|
|
|
|
std::shared_ptr<std::ofstream> ofs;
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "/data/sdcard/video/record_" << DateTime::currentDateTime().toString("%Y%m%d%H%M%S") << ".h264";
|
|
|
|
auto path = oss.str();
|
|
|
|
LOG(info) << "write h264 to " << path;
|
|
|
|
ofs = std::make_shared<std::ofstream>(path, std::ofstream::binary);
|
|
|
|
|
|
|
|
auto video = std::make_shared<VideoInput>(2592, 1536);
|
|
|
|
video->setPacketHandler([&](const uint8_t *data, uint32_t size) {
|
|
|
|
ofs->write(reinterpret_cast<const char *>(data), size);
|
2024-03-13 18:01:36 +08:00
|
|
|
// pusher->push(data, size);
|
|
|
|
rtsp->push(data, size);
|
2024-03-13 11:40:55 +08:00
|
|
|
});
|
2024-03-13 18:01:36 +08:00
|
|
|
// video->start();
|
|
|
|
video->startFileInput("/data/sdcard/HM1.264", 1280, 720);
|
2024-03-13 11:40:55 +08:00
|
|
|
video->startEncode();
|
|
|
|
boost::asio::signal_set signals(*ioContext->ioContext(), SIGINT);
|
|
|
|
signals.async_wait([&](boost::system::error_code const &, int signal) {
|
|
|
|
LOG(info) << "capture " << (signal == SIGINT ? "SIGINT" : "SIGTERM") << ",stop!";
|
|
|
|
video.reset();
|
|
|
|
rw_mpp__finalize();
|
|
|
|
ioContext->ioContext()->stop();
|
|
|
|
});
|
|
|
|
|
|
|
|
ioContext->run<IoContext::Mode::Synchronous>();
|
|
|
|
} catch (const boost::exception &e) {
|
|
|
|
LOG(error) << "error";
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
LOG(error) << e.what();
|
|
|
|
}
|
|
|
|
|
|
|
|
rw_mpp__finalize();
|
2024-03-12 14:46:37 +08:00
|
|
|
return 0;
|
|
|
|
}
|