pans
2017-08-30 71c92f101b6c8b4a678a8c3cfe2d8edbf488efa4
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "PL_Payer.h"
#include "MaterialBuffer.h"
#include "logger.h"
 
#include <string.h> // for memcpy
 
struct PL_Payer_Internal
{
    PL_Payer_Config config;
    PipeMaterial lastPm;
    MB_Frame lastFrame;
 
    PL_Payer_Internal() : 
        config(), lastPm(), lastFrame()
    {
    }
    
    ~PL_Payer_Internal()
    {
    }
    
    void reset()
    {
        PL_Payer_Config _config;
        config = _config;
        
        PipeMaterial _lastPm;
        lastPm = _lastPm;
        
        MB_Frame _lastFrame;
        lastFrame = _lastFrame;
    }
};
 
PipeLineElem* create_PL_Payer()
{
    return new PL_Payer;
}
 
PL_Payer::PL_Payer() : internal(new PL_Payer_Internal)
{
}
 
PL_Payer::~PL_Payer()
{
}
 
bool PL_Payer::init(void* args)
{
    PL_Payer_Internal* in = (PL_Payer_Internal*)internal;
    in->reset();
    
    if (args != nullptr)
    {
        PL_Payer_Config* config = (PL_Payer_Config*)args;
        in->config = *config;
    }
 
    return true;
}
 
void PL_Payer::finit()
{
    PL_Payer_Internal* in = (PL_Payer_Internal*)internal;
    
}
 
void pl_payer_deleter_func(PipeMaterial* pm)
{//#todo
}
 
bool PL_Payer::pay(const PipeMaterial& pm)
{
    PL_Payer_Internal* in = (PL_Payer_Internal*)internal;
    
    in->lastPm = pm;
    
    if (in->config.copyData)
    {
        switch(pm.type)
        {
        case PipeMaterial::PMT_BYTES:
        {
            in->lastPm.buffer = new uint8_t[pm.buffSize];
            memcpy(in->lastPm.buffer, pm.buffer, pm.buffSize);
            in->lastPm.args = in;
            in->lastPm.deleter = pl_payer_deleter_func;
        }
        break;
        case PipeMaterial::PMT_FRAME:
        {
            MB_Frame* pmFrame = (MB_Frame*)(pm.buffer);
            in->lastFrame = *pmFrame;
            in->lastFrame.buffer = new uint8_t[pmFrame->buffSize];
            memcpy(in->lastFrame.buffer, pmFrame->buffer, pmFrame->buffSize);
            
            in->lastPm.buffer = &(in->lastFrame);
            in->lastPm.args = in;
            in->lastPm.deleter = pl_payer_deleter_func;
        }
        break;
        default:
            //#todo support list or pm::copier operator
            LOG_ERROR << "Only support PMT_BYTES / PMT_FRAME" << std::endl;
        }
    }
 
    in->lastPm.former = this;
    return true;
}
 
bool PL_Payer::gain(PipeMaterial& pm)
{
    //PL_Payer_Internal* in = (PL_Payer_Internal*)internal;
    //
    //pm = in->lastPm;
    //
    //return true;
    
    return false;
}