wangrong
2025-01-20 d4675814490906969a39daa3e79ac560fe705410
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
#pragma once
 
#include <functional>
#include <mutex>
#include <string>
#include <memory>
 
namespace vp_nodes {
    // stream status created by des nodes.
    struct vp_stream_status {
        int channel_index = -1;  // channel index
        int frame_index = -1;    // latest frame index
        int latency = 0;         // latency(ms) relative to src node
 
        float fps = 0;           // output fps of stream, maybe it is not equal to original_fps
        int width = 0;           // output width of stream, maybe it is not equal to original_width
        int height = 0;          // output height of stream, maybe it is not equal to original_height
        std::string direction;   // where the stream goes to
    };
 
    // callback when stream is going out of pipe, happens in des nodes. MUST not be blocked.
    typedef std::function<void(std::string, vp_stream_status)> vp_stream_status_hooker;
 
    // allow hookers attached to the pipe (des nodes specifically), hookers get notified when stream is going out of pipe.
    // this class is inherited by vp_des_node only.
    class vp_stream_status_hookable
    {
    private:
        /* data */
    protected:
        std::mutex stream_status_hooker_lock;
        vp_stream_status_hooker stream_status_hooker;
    public:
        vp_stream_status_hookable(/* args */) {}
        ~vp_stream_status_hookable() {}
        
        void set_stream_status_hooker(vp_stream_status_hooker stream_status_hooker) {
            std::lock_guard<std::mutex> guard(stream_status_hooker_lock);
            this->stream_status_hooker = stream_status_hooker;
        }
 
        void invoke_stream_status_hooker(std::string node_name, vp_stream_status stream_status) {
            std::lock_guard<std::mutex> guard(stream_status_hooker_lock);
            if (this->stream_status_hooker) {
                this->stream_status_hooker(node_name, stream_status);
            }
        }
    };
}