chenke
2017-08-09 2a12817d4ae31a591f788f3fbb82916e385e9e2d
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "PL_BlockPredictor.h"
#include "MaterialBuffer.h"
#include "logger.h"
#include "MediaHelper.h"
 
#include <string.h> // for memcpy
#include <opencv2/core/mat.hpp>
#include <opencv2/imgproc.hpp>
 
struct PL_BlockPredictor_Internal
{
    uint8_t* buffer;
    size_t buffSize;
 
    PL_BlockPredictor_Config config;
    PipeMaterial pmList[2];
    MB_Frame lastMbfBuffOrigin;
    MB_Frame lastMbfBuffCopy;
    
    bool payError;
 
    PL_BlockPredictor_Internal() : 
        buffer(nullptr), buffSize(), config(), pmList(),
        lastMbfBuffOrigin(), lastMbfBuffCopy(),
        payError(true)
    {
    }
    
    ~PL_BlockPredictor_Internal()
    {
        reset();
    }
    
    void reset()
    {
        delete buffer;
        buffer = nullptr;
        buffSize = 0;
        
        PL_BlockPredictor_Config _config;
        config = _config;
        
        PipeMaterial _pm;
        pmList[0] = _pm;
        pmList[1] = _pm;
        
        MB_Frame _lastMbfBuff;
        lastMbfBuffOrigin = _lastMbfBuff;
        lastMbfBuffCopy = _lastMbfBuff;
        
        payError = true;
    }
};
 
PipeLineElem* create_PL_BlockPredictor()
{
    return new PL_BlockPredictor;
}
 
PL_BlockPredictor::PL_BlockPredictor() : internal(new PL_BlockPredictor_Internal)
{
}
 
PL_BlockPredictor::~PL_BlockPredictor()
{
    delete (PL_BlockPredictor_Internal*)internal;
    internal= nullptr;
}
 
bool PL_BlockPredictor::init(void* args)
{
    PL_BlockPredictor_Internal* in = (PL_BlockPredictor_Internal*)internal;
    in->reset();
    
    if (args != nullptr)
    {
        PL_BlockPredictor_Config* config = (PL_BlockPredictor_Config*)args;
        in->config = *config;
    }
 
    return true;
}
 
void PL_BlockPredictor::finit()
{
    PL_BlockPredictor_Internal* in = (PL_BlockPredictor_Internal*)internal;
    
}
 
bool PL_BlockPredictor::pay(const PipeMaterial& pm)
{
    PL_BlockPredictor_Internal* in = (PL_BlockPredictor_Internal*)internal;
    in->payError = true;
    pm.breake(PipeMaterial::PMT_PTR, MB_Frame::MBFT__FIRST, fc_pm_breaker_ptr, _ctx);
    pm.breake(PipeMaterial::PMT_FRAME, MB_Frame::MBFT__FIRST, fc_pm_breaker_frame, _ctx);
 
    //#todo support RGB
    
    return !(in->payError);
}
 
bool PL_BlockPredictor::gain(PipeMaterial& pm)
{
    PL_BlockPredictor_Internal* in = (PL_BlockPredictor_Internal*)internal;
 
    if (in->payError)
    {
        pm.former = this;
        return false;
    }
 
    if (!in->config.copyData)
    {
        pm.type = PipeMaterial::PMT_FRAME;
        pm.buffer = &(in->lastMbfBuffOrigin);
        pm.buffSize = 0;
    }
    else
    {
        in->pmList[0].type = PipeMaterial::PMT_FRAME;
        in->pmList[0].buffer = &(in->lastMbfBuffCopy);
        in->pmList[0].buffSize = 0;
        in->pmList[0].former = this;
        
        in->pmList[1].type = PipeMaterial::PMT_FRAME;
        in->pmList[1].buffer = &(in->lastMbfBuffOrigin);
        in->pmList[1].buffSize = 0;
        in->pmList[1].former = this;
        
        pm.type = PipeMaterial::PMT_PM_LIST;
        pm.buffer = in->pmList;
        pm.buffSize = sizeof(in->pmList) / sizeof(PipeMaterial);
    }
    
    pm.former = this;
    return true;
}