wangrong
2025-03-19 291afb9c81aae1d15d9e3edcea618d0a2e1fc5a6
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
73
74
75
76
77
78
79
80
 
#pragma once
 
#include <memory>
#include <opencv2/core.hpp>
 
#include "../../nodes/vp_node.h"
#include "../../nodes/vp_src_node.h"
#include "../../nodes/vp_des_node.h"
#include "../../objects/shapes/vp_rect.h"
#include "../vp_utils.h"
 
namespace vp_utils {
 
    // mainly used to store data from meta hookers' callback
    struct vp_meta_hooker_storage {
        int queue_size = -1;                      // size of in/out queue of node
        int latency = 0;                          // latency(ms) relative to src node at current port
        int called_count_since_epoch_start = -1;  // used for calculating fps at current port 
        std::chrono::system_clock::time_point time_epoch_start;      // used for calculating fps at current port
        std::shared_ptr<vp_objects::vp_meta> meta = nullptr;         // the latest meta (ptr) flowing through current port inside node (total 4 ports) 
        std::string pre_fps;  // cache
    };
 
    // a class corresponding to vp_node, used to display node on screen and map the whole pipe from memery to screen.
    class vp_node_on_screen
    {
    private:
        // orignal node in memery
        std::shared_ptr<vp_nodes::vp_node> original_node = nullptr;
        // node location and size on screen
        vp_objects::vp_rect node_rect;
        // layer index in pipe
        int layer;
        // nodes in next layer on screen
        std::vector<std::shared_ptr<vp_node_on_screen>> next_nodes_on_screen; 
 
        // period to calculate fps, milliseconds
        int fps_epoch = 500;
 
        // reset fps if it has been long time no update, seconds
        int fps_timeout = 5;
 
        // font for display
        int font_face = cv::FONT_HERSHEY_SIMPLEX;
 
        // container to store data from meta hookers' callbacks
        vp_meta_hooker_storage meta_arriving_hooker_storage;
        vp_meta_hooker_storage meta_handling_hooker_storage;
        vp_meta_hooker_storage meta_handled_hooker_storage;
        vp_meta_hooker_storage meta_leaving_hooker_storage;
 
        // container to store data from stream info hooker's callback
        vp_nodes::vp_stream_info stream_info_hooker_storage;
 
        // container to store data from stream status hooker's callback
        vp_nodes::vp_stream_status stream_status_hooker_storage;
 
        // render configure
        const int node_title_h = 24;
        const int node_queue_width = 30;
 
        const int node_queue_port_w_h = 6;
        const int node_queue_port_padding = 8;
        const int node_gap_horizontal = 40;
        const int node_gap_vertical = 10;
    public:
        vp_node_on_screen(std::shared_ptr<vp_nodes::vp_node> original_node, vp_objects::vp_rect node_rect, int layer);
        ~vp_node_on_screen();
 
        // render static parts for node, which keep unchanged all the time.
        void render_static_parts(cv::Mat& canvas);
        // render dynamic parts for node, which change frequently.
        void render_dynamic_parts(cv::Mat& canvas);
 
        std::shared_ptr<vp_nodes::vp_node>& get_orginal_node();
 
        std::vector<std::shared_ptr<vp_node_on_screen>>& get_next_nodes_on_screen();
    };
}