wangrong
2025-01-03 2c4b8838f89bebca97615c5f0bac2c58e0349771
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
 
#include <list>
#include <deque>
#include <map>
 
#include "../vp_node.h"
#include "../../objects/vp_image_record_control_meta.h"
#include "../../objects/vp_video_record_control_meta.h"
 
#include "vp_image_record_task.h"
#include "vp_video_record_task.h"
#include "vp_record_status_hookable.h"
 
namespace vp_nodes {
    // video/image recording node, save it to local disk.
    // it is a middle node but works asynchronously, so recording would not block the pipeline.
    // note record node could work on multi channels at the same time.
    class vp_record_node: public vp_node, public vp_record_status_hookable
    {
    private:
        /* config data */
        // video save directory
        std::string video_save_dir;
        // image save directory
        std::string image_save_dir;
        // pre record time for video (seconds)
        int pre_record_video_duration;
        // record time for video (seconds), not including pre_record_video_duration
        int record_video_duration;
        // auto create sub directory by date and channel or not, such as `./video_save_dir/2022-10-8/1/**.mp4`
        bool auto_sub_dir;
        // width and height
        vp_objects::vp_size resolution_w_h = {};
        // bitrate for video record
        int bitrate = 1024;
        // record osd frame or not
        bool osd = false;
 
        // fps for current video
        // int fps = 0;
        std::map<int, int> all_fps;
        
        /* record task list */
        // std::list<std::shared_ptr<vp_nodes::vp_record_task>> record_tasks;
        std::map<int, std::list<std::shared_ptr<vp_nodes::vp_record_task>>> all_record_tasks;
 
        /* pre-record for video */
        // std::deque<std::shared_ptr<vp_objects::vp_frame_meta>> pre_records;
        std::map<int, std::deque<std::shared_ptr<vp_objects::vp_frame_meta>>> all_pre_records;
 
        // new record task
        void auto_new_record_task(std::shared_ptr<vp_objects::vp_control_meta>& meta);
 
    protected:
        // re-implementation
        virtual std::shared_ptr<vp_objects::vp_meta> handle_frame_meta(std::shared_ptr<vp_objects::vp_frame_meta> meta) override; 
        // re-implementation
        virtual std::shared_ptr<vp_objects::vp_meta> handle_control_meta(std::shared_ptr<vp_objects::vp_control_meta> meta) override;
    public:
        vp_record_node(std::string node_name, 
                        std::string video_save_dir, 
                        std::string image_save_dir,
                        vp_objects::vp_size resolution_w_h = {}, 
                        bool osd = false,
                        int pre_record_video_duration = 5, 
                        int record_video_duration = 20,
                        bool auto_sub_dir = true,
                        int bitrate = 1024);
        ~vp_record_node();
    };
}