From 854140e323a8ecc11db36459b069a868c56be148 Mon Sep 17 00:00:00 2001 From: amass <168062547@qq.com> Date: Mon, 17 Mar 2025 18:34:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Main/Camera.cpp | 2 ++ Main/RtspServer.cpp | 18 ++++++++++++------ Main/RtspServer.h | 7 ++++++- Main/main.cpp | 2 +- resources/build.sh | 1 + 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Main/Camera.cpp b/Main/Camera.cpp index 81a9555..d0c2595 100644 --- a/Main/Camera.cpp +++ b/Main/Camera.cpp @@ -1,6 +1,7 @@ #include "Camera.h" #include "Core/Logger.h" #include "sensorsdk_api.h" +#include 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."; } diff --git a/Main/RtspServer.cpp b/Main/RtspServer.cpp index 4b24b02..8fece4b 100644 --- a/Main/RtspServer.cpp +++ b/Main/RtspServer.cpp @@ -1,4 +1,6 @@ #include "RtspServer.h" +#include +#include #include #include #include @@ -12,21 +14,23 @@ lowLatency=1 )"; class RtspServerPrivate { public: + RtspServerPrivate(boost::asio::io_context &ioContext) : strand{ioContext.get_executor()} { + } + boost::asio::strand 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(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(data), size); + boost::asio::post(m_d->strand, [this, frame = std::vector(data, data + size)]() { + mk_h264_splitter_input_data(m_d->splitter, reinterpret_cast(frame.data()), frame.size()); + }); } diff --git a/Main/RtspServer.h b/Main/RtspServer.h index 1249490..9b88fdc 100644 --- a/Main/RtspServer.h +++ b/Main/RtspServer.h @@ -3,11 +3,16 @@ #include +namespace boost { +namespace asio { +class io_context; +} +} // namespace boost class RtspServerPrivate; class RtspServer { public: - RtspServer(); + RtspServer(boost::asio::io_context &ioContext); ~RtspServer(); /** diff --git a/Main/main.cpp b/Main/main.cpp index 9b659c3..d9dcaad 100644 --- a/Main/main.cpp +++ b/Main/main.cpp @@ -21,7 +21,7 @@ int main(int argc, char const *argv[]) { try { auto camera = Singleton::construct(); auto ioContext = Singleton::construct(std::thread::hardware_concurrency()); - auto rtsp = std::make_shared(); + auto rtsp = std::make_shared(*ioContext->ioContext()); auto streamer = std::make_shared(*ioContext->ioContext()); streamer->start("amass.fun", 443); diff --git a/resources/build.sh b/resources/build.sh index f27521b..c7f9ade 100755 --- a/resources/build.sh +++ b/resources/build.sh @@ -64,6 +64,7 @@ function init() { ssh danki "mkdir -p /data/sdcard/PassengerStatistics/lib" echo "put /opt/aarch64-v01c01-linux-gnu-gcc/lib/gdb-10.2/bin/gdbserver /system/bin" | sftp -i resources/ssh_host_rsa_key_ok root@${TARGET_IP} echo "put 3rdparty/rw_mpp/lib/librw_mpp.so /data/sdcard/PassengerStatistics/lib" | sftp danki + echo "put 3rdparty/fsan_sensorsdk/libs/libsensorsdk.so /data/sdcard/PassengerStatistics/lib" | sftp danki echo "put 3rdparty/ds_pedestrian_mot_hisi/libs/libds_pedestrian_mot_Hi3516DV500.so /data/sdcard/PassengerStatistics/lib" | sftp danki echo "put /opt/aarch64-v01c01-linux-gnu-gcc/lib/openssl-3.4.1/lib/libssl.so.3 /data/sdcard/PassengerStatistics/lib" | sftp danki echo "put /opt/aarch64-v01c01-linux-gnu-gcc/lib/openssl-3.4.1/lib/libcrypto.so.3 /data/sdcard/PassengerStatistics/lib" | sftp danki