提交代码。

This commit is contained in:
2025-03-17 18:34:08 +08:00
parent d54ffd6541
commit 854140e323
5 changed files with 22 additions and 8 deletions

View File

@ -1,6 +1,7 @@
#include "Camera.h"
#include "Core/Logger.h"
#include "sensorsdk_api.h"
#include <thread>
Camera::Camera() {
SensorSDK_CameraLens cameraLens = {};
@ -12,6 +13,7 @@ Camera::Camera() {
int status = SensorSdk_Init(7, boardLine, lensType, autoLensParmPath, &cameraLens);
if (status == 0) {
LOG(info) << "SensorSdk_Init() successed.";
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
} else {
LOG(info) << "SensorSdk_Init() failed.";
}

View File

@ -1,4 +1,6 @@
#include "RtspServer.h"
#include <boost/asio/io_context.hpp>
#include <boost/asio/strand.hpp>
#include <chrono>
#include <cstring>
#include <mk_common.h>
@ -12,21 +14,23 @@ lowLatency=1
)";
class RtspServerPrivate {
public:
RtspServerPrivate(boost::asio::io_context &ioContext) : strand{ioContext.get_executor()} {
}
boost::asio::strand<boost::asio::io_context::executor_type> strand;
mk_media media;
mk_h264_splitter splitter;
};
static void on_h264_frame(void *user_data, mk_h264_splitter splitter, const char *data, int size) {
using namespace std::chrono;
using namespace std::chrono_literals;
std::this_thread::sleep_for(40ms);
static int dts = 0;
mk_frame frame = mk_frame_create(MKCodecH264, dts, dts, data, size, NULL, NULL);
dts += 40;
int pts = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
mk_frame frame = mk_frame_create(MKCodecH264, pts, pts, data, size, NULL, NULL);
mk_media_input_frame((mk_media)user_data, frame);
mk_frame_unref(frame);
}
RtspServer::RtspServer() : m_d(new RtspServerPrivate()) {
RtspServer::RtspServer(boost::asio::io_context &ioContext) : m_d(new RtspServerPrivate(ioContext)) {
mk_config config;
std::memset(&config, 0, sizeof(mk_config));
config.ini = iniConfig;
@ -58,5 +62,7 @@ RtspServer::~RtspServer() {
}
void RtspServer::push(const uint8_t *data, uint32_t size) {
mk_h264_splitter_input_data(m_d->splitter, reinterpret_cast<const char *>(data), size);
boost::asio::post(m_d->strand, [this, frame = std::vector<uint8_t>(data, data + size)]() {
mk_h264_splitter_input_data(m_d->splitter, reinterpret_cast<const char *>(frame.data()), frame.size());
});
}

View File

@ -3,11 +3,16 @@
#include <string>
namespace boost {
namespace asio {
class io_context;
}
} // namespace boost
class RtspServerPrivate;
class RtspServer {
public:
RtspServer();
RtspServer(boost::asio::io_context &ioContext);
~RtspServer();
/**

View File

@ -21,7 +21,7 @@ int main(int argc, char const *argv[]) {
try {
auto camera = Singleton<Camera>::construct();
auto ioContext = Singleton<IoContext>::construct(std::thread::hardware_concurrency());
auto rtsp = std::make_shared<RtspServer>();
auto rtsp = std::make_shared<RtspServer>(*ioContext->ioContext());
auto streamer = std::make_shared<Streamer>(*ioContext->ioContext());
streamer->start("amass.fun", 443);