houxiao
2016-12-22 9d9849175b11b3ba9918ad4f980aa4a1c7c2afb0
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
81
#ifndef _PIPELINE_H_
#define _PIPELINE_H_
 
#include <string>
#include <stdint.h>
#include <map>
#include <vector>
 
#define PLGP_RTSP_SDP "RTSP_SDP"
#define PLGP_RTSP_FMTP "RTSP_FMTP"
 
class PipeLineElem;
class PipeLine;
 
struct PipeMaterial
{
    uint8_t* buffer;
    size_t buffSize;
    PipeLineElem* former;
    
    PipeMaterial();
};
 
class PipeLineElem
{
public:
    PipeLineElem() : manager(nullptr) { }
    virtual ~PipeLineElem() { }
 
    virtual bool init(void* args) = 0;
    virtual void finit() = 0;
    
    // buffer: delete it who create it
    virtual bool pay(const PipeMaterial& pm) = 0;
    virtual bool gain(PipeMaterial& pm) = 0;
 
public:
    PipeLine* manager;
};
 
typedef PipeLineElem* (*elem_create_func_t)();
 
// 0 (there is no elem). do nothing
// 1 (there is one elem). gain
// 2 (there is two elems). gain --> pay
// 3 (there is more than two elems). gain --> pay gain --> pay gain --> ... --> pay
class PipeLine
{
public:
    PipeLine();
    
    // stop and delete all managed elements
    ~PipeLine();
    
    bool register_elem_creator(const std::string& type, elem_create_func_t func);
    void push_elem(PipeLineElem* elem);
    PipeLineElem* push_elem(const std::string& type);
    
    // do pipe sync. returns the element who returns false, or the last one.
    PipeLineElem* pipe(PipeMaterial* pm = nullptr);
    
    // do pipe async
    void pipe_start();
    void pipe_notify(PipeLineElem*);
    void pipe_stop();
    
    void set_global_param(const std::string& name, const std::string& value);
    std::string get_global_param(const std::string& name) const;
    
private:
    typedef std::map<const std::string, elem_create_func_t> elem_create_func_map_t;
    elem_create_func_map_t elem_create_func_map;
    
    typedef std::vector<PipeLineElem*> elem_vec_t;
    elem_vec_t elems;
 
    typedef std::map<const std::string, std::string> global_params_map_t;
    global_params_map_t global_params_map;
};
 
#endif