Coverage Report

Created: 2022-08-24 06:11

/src/x265/source/common/framedata.cpp
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
* Copyright (C) 2013-2020 MulticoreWare, Inc
3
*
4
* Author: Steve Borho <steve@borho.org>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
19
*
20
* This program is also available under a commercial proprietary license.
21
* For more information, contact us at license @ x265.com.
22
*****************************************************************************/
23
24
#include "framedata.h"
25
#include "picyuv.h"
26
27
using namespace X265_NS;
28
29
FrameData::FrameData()
30
0
{
31
0
    memset(this, 0, sizeof(*this));
32
0
}
33
34
bool FrameData::create(const x265_param& param, const SPS& sps, int csp)
35
0
{
36
0
    m_param = &param;
37
0
    m_slice  = new Slice;
38
0
    m_picCTU = new CUData[sps.numCUsInFrame];
39
0
    m_picCsp = csp;
40
0
    m_spsrpsIdx = -1;
41
0
    if (param.rc.bStatWrite)
42
0
        m_spsrps = const_cast<RPS*>(sps.spsrps);
43
0
    bool isallocated = m_cuMemPool.create(0, param.internalCsp, sps.numCUsInFrame, param);
44
0
    if (m_param->bDynamicRefine)
45
0
    {
46
0
        CHECKED_MALLOC_ZERO(m_cuMemPool.dynRefineRdBlock, uint64_t, MAX_NUM_DYN_REFINE * sps.numCUsInFrame);
47
0
        CHECKED_MALLOC_ZERO(m_cuMemPool.dynRefCntBlock, uint32_t, MAX_NUM_DYN_REFINE * sps.numCUsInFrame);
48
0
        CHECKED_MALLOC_ZERO(m_cuMemPool.dynRefVarBlock, uint32_t, MAX_NUM_DYN_REFINE * sps.numCUsInFrame);
49
0
    }
50
0
    if (isallocated)
51
0
    {
52
0
        for (uint32_t ctuAddr = 0; ctuAddr < sps.numCUsInFrame; ctuAddr++)
53
0
        {
54
0
            if (m_param->bDynamicRefine)
55
0
            {
56
0
                m_picCTU[ctuAddr].m_collectCURd = m_cuMemPool.dynRefineRdBlock + (ctuAddr * MAX_NUM_DYN_REFINE);
57
0
                m_picCTU[ctuAddr].m_collectCUVariance = m_cuMemPool.dynRefVarBlock + (ctuAddr * MAX_NUM_DYN_REFINE);
58
0
                m_picCTU[ctuAddr].m_collectCUCount = m_cuMemPool.dynRefCntBlock + (ctuAddr * MAX_NUM_DYN_REFINE);
59
0
            }
60
0
            m_picCTU[ctuAddr].initialize(m_cuMemPool, 0, param, ctuAddr);
61
0
        }
62
0
    }
63
0
    else
64
0
        return false;
65
0
    CHECKED_MALLOC_ZERO(m_cuStat, RCStatCU, sps.numCUsInFrame);
66
0
    CHECKED_MALLOC(m_rowStat, RCStatRow, sps.numCuInHeight);
67
0
    reinit(sps);
68
    
69
0
    for (int i = 0; i < INTEGRAL_PLANE_NUM; i++)
70
0
    {
71
0
        m_meBuffer[i] = NULL;
72
0
        m_meIntegral[i] = NULL;
73
0
    }
74
0
    return true;
75
76
0
fail:
77
0
    return false;
78
0
}
79
80
void FrameData::reinit(const SPS& sps)
81
0
{
82
0
    memset(m_cuStat, 0, sps.numCUsInFrame * sizeof(*m_cuStat));
83
0
    memset(m_rowStat, 0, sps.numCuInHeight * sizeof(*m_rowStat));
84
0
    if (m_param->bDynamicRefine)
85
0
    {
86
0
        memset(m_picCTU->m_collectCURd, 0, MAX_NUM_DYN_REFINE * sps.numCUsInFrame * sizeof(uint64_t));
87
0
        memset(m_picCTU->m_collectCUVariance, 0, MAX_NUM_DYN_REFINE * sps.numCUsInFrame * sizeof(uint32_t));
88
0
        memset(m_picCTU->m_collectCUCount, 0, MAX_NUM_DYN_REFINE * sps.numCUsInFrame * sizeof(uint32_t));
89
0
    }
90
0
}
91
92
void FrameData::destroy()
93
0
{
94
0
    delete [] m_picCTU;
95
0
    delete m_slice;
96
0
    delete m_saoParam;
97
98
0
    m_cuMemPool.destroy();
99
100
0
    if (m_param->bDynamicRefine)
101
0
    {
102
0
        X265_FREE(m_cuMemPool.dynRefineRdBlock);
103
0
        X265_FREE(m_cuMemPool.dynRefCntBlock);
104
0
        X265_FREE(m_cuMemPool.dynRefVarBlock);
105
0
    }
106
0
    X265_FREE(m_cuStat);
107
0
    X265_FREE(m_rowStat);
108
0
    for (int i = 0; i < INTEGRAL_PLANE_NUM; i++)
109
0
    {
110
0
        if (m_meBuffer[i] != NULL)
111
0
        {
112
0
            X265_FREE(m_meBuffer[i]);
113
0
            m_meBuffer[i] = NULL;
114
0
        }
115
0
    }
116
0
}