#pragma once #include "action_base.h" #include "../uploaders/uploader_base.h" #include "../frame_ring_buffer.h" #include #include #include #include #include #include namespace rk3588 { struct ClipTask { AlarmEvent event; std::vector> pre_frames; std::shared_ptr trigger_frame; }; class ClipAction : public IAlarmAction { public: ~ClipAction(); bool Init(const SimpleJson& config) override; void Execute(AlarmEvent& event, std::shared_ptr frame) override; void Drain() override; std::string Name() const override { return "clip"; } void SetFrameBuffer(std::shared_ptr buffer) { frame_buffer_ = buffer; } void PushPostEventFrame(std::shared_ptr frame); private: void WorkerLoop(); std::string ProcessClip(ClipTask& task); std::string GenerateKey(const AlarmEvent& event); int pre_sec_ = 5; int post_sec_ = 10; std::string format_ = "mp4"; int fps_ = 25; std::unique_ptr uploader_; std::shared_ptr frame_buffer_; std::atomic running_{false}; std::thread worker_; std::mutex queue_mutex_; std::condition_variable queue_cv_; std::queue task_queue_; size_t in_flight_ = 0; // Post-event collection state std::mutex post_mutex_; bool collecting_post_ = false; std::vector> post_frames_; int post_frames_needed_ = 0; ClipTask* current_task_ = nullptr; }; } // namespace rk3588