diff --git a/HxIVA/HxDevice.cpp b/HxIVA/HxDevice.cpp index 18599a8..0fe050e 100644 --- a/HxIVA/HxDevice.cpp +++ b/HxIVA/HxDevice.cpp @@ -1,7 +1,6 @@ #include "HxDevice.h" -HxDevice::HxDevice(int millisecond) - : HxThread{ millisecond } +HxDevice::HxDevice() { type = -1; frame_id = 0; @@ -36,7 +35,7 @@ void HxDevice::startup(int type, QString url, QString file) { HxTask::run(this, &HxDevice::frame_read_process, 5000, "_frame_read_process"); - this->start(); + HxTask::run(this, &HxDevice::frame_decode_process, 5, "_frame_decode_process"); } } @@ -68,7 +67,8 @@ void HxDevice::frame_read_process(void) mutex.lock(); frames.enqueue(mat); mutex.unlock(); - msleep(10); + + QThread::msleep(10); } /* 关闭,释放 */ @@ -77,6 +77,34 @@ void HxDevice::frame_read_process(void) HxTrace::debug_write_line("videolivestream", QString("type=%1, video close").arg(type)); } +void HxDevice::frame_decode_process(void) +{ + if (frames.isEmpty()) + return; + + mutex.lock(); + auto frame = frames.dequeue(); + mutex.unlock(); + + if (frame.data != nullptr) + { + if (car_info.fVelocity >= 10) + { + bgr_frame_buffer.nFrameId = frame_id; // 帧号 + bgr_frame_buffer.u64PTS = QDateTime::currentMSecsSinceEpoch(); // 时间戳(毫秒) + memcpy(bgr_frame_buffer.pu8VirAddr, frame.data, 1280 * 720 * 3); + + mv_convert_images(&bgr_frame_buffer, &detect_frame_buffer); // bgr->nv16 +#if USE_ALGORITHM + MvObjectEventDetect(type, &detect_frame_buffer, &car_info); + + HxTrace::debug_write_line("device", QString("send frame_id=%1").arg(frame_id + 1)); +#endif + frame_id++; + } + } +} + int HxDevice::mv_convert_images(VideoFrameDataInfo *src_buffer, VideoFrameDataInfo *dst_buffer) { Q_UNUSED(src_buffer); @@ -111,36 +139,3 @@ int HxDevice::mv_convert_images(VideoFrameDataInfo *src_buffer, VideoFrameDataIn return 0; } - -void HxDevice::action() -{ - if (frames.isEmpty()) - return; - - mutex.lock(); - auto frame = frames.dequeue(); - mutex.unlock(); - - if (frame.data != nullptr) - { - if (car_info.fVelocity >= 10) - { - bgr_frame_buffer.nFrameId = frame_id; // 帧号 - bgr_frame_buffer.u64PTS = QDateTime::currentMSecsSinceEpoch(); // 时间戳(毫秒) - memcpy(bgr_frame_buffer.pu8VirAddr, frame.data, 1280 * 720 * 3); - - mv_convert_images(&bgr_frame_buffer, &detect_frame_buffer); // bgr->nv16 -#if USE_ALGORITHM - MvObjectEventDetect(type, &detect_frame_buffer, &car_info); - -// HxTrace::debug_write_line("device", QString("send frame_id=%1").arg(frame_id + 1)); -#endif - frame_id++; - } - } -} - -void HxDevice::continue_with() -{ - -} diff --git a/HxIVA/HxDevice.h b/HxIVA/HxDevice.h index 0f42212..ebe4cf5 100644 --- a/HxIVA/HxDevice.h +++ b/HxIVA/HxDevice.h @@ -9,21 +9,17 @@ typedef enum __CONNECTION_TYPE_ Rtsp = 1, }connection_type; -class HxDevice : public HxThread +class HxDevice { - Q_OBJECT public: - HxDevice(int millisecond = 1); + HxDevice(); void startup(int type, QString url, QString file = ""); private: void frame_read_process(void); + void frame_decode_process(void); int mv_convert_images(VideoFrameDataInfo *src_buffer, VideoFrameDataInfo *dst_buffer); -protected: - void action() override; - void continue_with() override; - private: int type; int connection_type; diff --git a/HxIVA/HxIVA.pro b/HxIVA/HxIVA.pro index 84e5f98..14a3cda 100644 --- a/HxIVA/HxIVA.pro +++ b/HxIVA/HxIVA.pro @@ -54,24 +54,24 @@ unix { } - # LIBS += $$PWD/../resources/libraries/HxUtils/lib/libHxUtils_linux.a - # LIBS += -L/usr/local/lib -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio -lopencv_core - # LIBS += -L/usr/local/ffmpeg/lib -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc -lswresample -lswscale + LIBS += $$PWD/../resources/libraries/HxUtils/lib/libHxUtils_linux.a + LIBS += -L/usr/local/lib -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio -lopencv_core + LIBS += -L/usr/local/ffmpeg/lib -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc -lswresample -lswscale - LIBS += $$PWD/../resources/libraries/HxUtils/lib/libHxUtils_arm64.a - LIBS += /usr/lib/libopencv_highgui.so.3.4 \ - /usr/lib/libopencv_imgproc.so.3.4 \ - /usr/lib/libopencv_imgcodecs.so.3.4 \ - /usr/lib/libopencv_videoio.so.3.4 \ - /usr/lib/libopencv_core.so.3.4 \ - /usr/lib/libavcodec.so.58 \ - /usr/lib/libavdevice.so.58 \ - /usr/lib/libavfilter.so.7 \ - /usr/lib/libavformat.so.58 \ - /usr/lib/libavutil.so.56 \ - /usr/lib/libpostproc.so.55 \ - /usr/lib/libswresample.so.3 \ - /usr/lib/libswscale.so.5 +# LIBS += $$PWD/../resources/libraries/HxUtils/lib/libHxUtils_aarch.a +# LIBS += /usr/lib/libopencv_highgui.so.3.4 \ +# /usr/lib/libopencv_imgproc.so.3.4 \ +# /usr/lib/libopencv_imgcodecs.so.3.4 \ +# /usr/lib/libopencv_videoio.so.3.4 \ +# /usr/lib/libopencv_core.so.3.4 \ +# /usr/lib/libavcodec.so.58 \ +# /usr/lib/libavdevice.so.58 \ +# /usr/lib/libavfilter.so.7 \ +# /usr/lib/libavformat.so.58 \ +# /usr/lib/libavutil.so.56 \ +# /usr/lib/libpostproc.so.55 \ +# /usr/lib/libswresample.so.3 \ +# /usr/lib/libswscale.so.5 } win32 { diff --git a/HxIVA/main.cpp b/HxIVA/main.cpp index 57342c3..8fcc984 100644 --- a/HxIVA/main.cpp +++ b/HxIVA/main.cpp @@ -1,4 +1,4 @@ -#include "main.h" +#include "main.h" #include "HxDevice.h" @@ -40,6 +40,13 @@ int main(int argc, char* argv[]) car_info.fVelocity = 50; + /* 向服务程序发送 心跳数据 */ + HxTask::run([=]() + { + HxBroadcast::publish_json(0, { {"name", "HxIVA"}, {"version", "1.00"} }); + + }, 5000, "heart_third"); + return a.exec(); } diff --git a/HxServer/HxServer/Peripheral/HxIVA.cs b/HxServer/HxServer/Peripheral/HxIVA.cs index 2319b71..10e189a 100644 --- a/HxServer/HxServer/Peripheral/HxIVA.cs +++ b/HxServer/HxServer/Peripheral/HxIVA.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -115,7 +116,7 @@ namespace HxServer.Peripheral DataBase.ReplaceIVARecord(data); /* 产生预录报警数据 */ - MonitorServer.SendMessage("HxVideoCaptor", new Model(10, new { timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), uuid = uuid, channel = data.Channel, id = data.EventType })); + MonitorServer.SendMessage("HxVideoCaptor", new Model(10, new { timestamp = data.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"), uuid = uuid, channel = data.Channel, id = data.EventType })); /* 等待结果 30s超时 */ TaskUtils.Wait(() => @@ -128,15 +129,40 @@ namespace HxServer.Peripheral { if (result != null) { + /* 生成图片 */ - var alarm_recording_prepend_time = DataBase.ReadSettings()["alarm_recording_prepend_time"]; - System.Diagnostics.Process.Start($"ffmpeg -ss 00:00:{alarm_recording_prepend_time:D2} -i {result.FilePath} test.jpg -r 1 -vframes 1 -an -f mjepg"); - //data.ImagePath = $""; + var settings = DataBase.ReadSettings(); + var disks = settings["disks"].ToString().Split(";"); + var drivers = DriveInfo.GetDrives(); + var alarm_recording_prepend_time = Convert.ToInt32(settings["alarm_recording_prepend_time"]); + + foreach (var driver in drivers) + DebugTrace.WriteLine(nameof(HxIVA), $"disk: {driver.Name}"); + + string root_path = ""; + foreach (var disk in disks) + { + DriveInfo driver; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + driver = drivers.FirstOrDefault(d => d.Name == disk.Replace(":/", ":\\")); + else + driver = drivers.FirstOrDefault(d => d.Name == disk); + + if (driver != null) + root_path = Path.Combine(driver.Name, "HXNVR_IMAGE", $"{DateTime.Now:yyyyMMdd}", $"{data.Channel + 1}:D2"); + } + + Directory.CreateDirectory(root_path); + + data.ImagePath = Path.Combine(root_path, FileUtils.GetName(result.FilePath).Replace(".avi", ".jpg")); data.RecordPath = result.FilePath; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + System.Diagnostics.Process.Start("D:/Library/ffmpeg/4.0.2/bin/ffmpeg.exe", $"-ss 00:00:{alarm_recording_prepend_time:D2} -i {result.FilePath} {data.ImagePath} -r 1 -vframes 1 -an -f mjepg"); + else + System.Diagnostics.Process.Start("ffmpeg", $"-ss 00:00:{alarm_recording_prepend_time:D2} -i {result.FilePath} test.jpg -r 1 -vframes 1 -an -f mjepg"); /* 更新数据库 */ - data.RecordPath = result.FilePath; DataBase.ReplaceIVARecord(data); } } diff --git a/HxVideoCaptor/main.h b/HxVideoCaptor/main.h index f734045..c534802 100644 --- a/HxVideoCaptor/main.h +++ b/HxVideoCaptor/main.h @@ -43,8 +43,7 @@ extern "C" {"name", record.name}, \ {"path", record.path}}) /* 发送预录视频路径 */ -#define WRITE_PRE_RECORD_STATUS(uuid, filepath) HxBroadcast::publish_json(10, {{"uuid", uuid}, \ - {"filepath", filepath}}) +#define WRITE_PRE_RECORD_STATUS(uuid, filepath) HxBroadcast::publish_json(10, {{"uuid", uuid}, {"filepath", filepath}}) typedef enum { Null, Recording, Recorded, } RecordStatus;