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
#pragma once
 
#include <functional>
#include <mutex>
#include <string>
#include <memory>
 
namespace vp_nodes {
    // stream info created by src nodes.
    struct vp_stream_info {
        int channel_index = -1;   // channel index
        int original_fps = 0;     // original fps of stream
        int original_width = 0;   // width of resolution
        int original_height = 0;  // height of resolution
        std::string uri = "";     // uri of stream
    };
    
    // callback when stream info changed, happens in src nodes. MUST not be blocked.
    typedef std::function<void(std::string, vp_stream_info)> vp_stream_info_hooker;
 
    // allow hookers attached to the pipe (src nodes specifically), hookers get notified when stream info changed.
    // this class is inherited by vp_src_node only.
    class vp_stream_info_hookable
    {
    private:
        /* data */
    protected:
        std::mutex stream_info_hooker_lock;
        vp_stream_info_hooker stream_info_hooker;
    public:
        vp_stream_info_hookable(/* args */) {}
        ~vp_stream_info_hookable() {}
 
        void set_stream_info_hooker(vp_stream_info_hooker stream_info_hooker) {
            std::lock_guard<std::mutex> guard(stream_info_hooker_lock);
            this->stream_info_hooker = stream_info_hooker;
        }
 
        void invoke_stream_info_hooker(std::string node_name, vp_stream_info stream_info) {
            std::lock_guard<std::mutex> guard(stream_info_hooker_lock);
            if (this->stream_info_hooker) {
                this->stream_info_hooker(node_name, stream_info);
            }
        }
    };
}