Coverage Report

Created: 2026-03-08 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/x265/source/common/framedata.cpp
Line
Count
Source
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
#include "search.h"
27
#include "threadedme.h"
28
29
using namespace X265_NS;
30
31
FrameData::FrameData()
32
654
{
33
654
    memset(this, 0, sizeof(*this));
34
654
}
35
36
bool FrameData::create(const x265_param& param, const SPS& sps, int csp)
37
654
{
38
654
    m_param = &param;
39
654
    m_slice  = new Slice;
40
654
    if (m_param->bThreadedME)
41
0
    {
42
0
        uint32_t numCUs = sps.numCuInWidth * sps.numCuInHeight;
43
0
        uint32_t totalPUs = numCUs * MAX_NUM_PUS_PER_CTU;
44
0
        m_slice->m_ctuMV = X265_MALLOC(MEData, totalPUs);
45
0
    }
46
47
654
    m_picCTU = new CUData[sps.numCUsInFrame];
48
654
    m_picCsp = csp;
49
654
    m_spsrpsIdx = -1;
50
654
    if (param.rc.bStatWrite)
51
0
        m_spsrps = const_cast<RPS*>(sps.spsrps);
52
654
    bool isallocated = m_cuMemPool.create(0, param.internalCsp, sps.numCUsInFrame, param);
53
654
    if (m_param->bDynamicRefine)
54
0
    {
55
0
        CHECKED_MALLOC_ZERO(m_cuMemPool.dynRefineRdBlock, uint64_t, MAX_NUM_DYN_REFINE * sps.numCUsInFrame);
56
0
        CHECKED_MALLOC_ZERO(m_cuMemPool.dynRefCntBlock, uint32_t, MAX_NUM_DYN_REFINE * sps.numCUsInFrame);
57
0
        CHECKED_MALLOC_ZERO(m_cuMemPool.dynRefVarBlock, uint32_t, MAX_NUM_DYN_REFINE * sps.numCUsInFrame);
58
0
    }
59
654
    if (isallocated)
60
654
    {
61
14.3k
        for (uint32_t ctuAddr = 0; ctuAddr < sps.numCUsInFrame; ctuAddr++)
62
13.7k
        {
63
13.7k
            if (m_param->bDynamicRefine)
64
0
            {
65
0
                m_picCTU[ctuAddr].m_collectCURd = m_cuMemPool.dynRefineRdBlock + (ctuAddr * MAX_NUM_DYN_REFINE);
66
0
                m_picCTU[ctuAddr].m_collectCUVariance = m_cuMemPool.dynRefVarBlock + (ctuAddr * MAX_NUM_DYN_REFINE);
67
0
                m_picCTU[ctuAddr].m_collectCUCount = m_cuMemPool.dynRefCntBlock + (ctuAddr * MAX_NUM_DYN_REFINE);
68
0
            }
69
13.7k
            m_picCTU[ctuAddr].initialize(m_cuMemPool, 0, param, ctuAddr);
70
13.7k
        }
71
654
    }
72
0
    else
73
0
        return false;
74
654
    CHECKED_MALLOC_ZERO(m_cuStat, RCStatCU, sps.numCUsInFrame + 1);
75
654
    CHECKED_MALLOC(m_rowStat, RCStatRow, sps.numCuInHeight);
76
654
    reinit(sps);
77
    
78
8.50k
    for (int i = 0; i < INTEGRAL_PLANE_NUM; i++)
79
7.84k
    {
80
7.84k
        m_meBuffer[i] = NULL;
81
7.84k
        m_meIntegral[i] = NULL;
82
7.84k
    }
83
654
    return true;
84
85
0
fail:
86
0
    return false;
87
654
}
88
89
void FrameData::reinit(const SPS& sps)
90
654
{
91
654
    memset(m_cuStat, 0, sps.numCUsInFrame * sizeof(*m_cuStat));
92
654
    memset(m_rowStat, 0, sps.numCuInHeight * sizeof(*m_rowStat));
93
654
    if (m_param->bDynamicRefine)
94
0
    {
95
0
        memset(m_picCTU->m_collectCURd, 0, MAX_NUM_DYN_REFINE * sps.numCUsInFrame * sizeof(uint64_t));
96
0
        memset(m_picCTU->m_collectCUVariance, 0, MAX_NUM_DYN_REFINE * sps.numCUsInFrame * sizeof(uint32_t));
97
0
        memset(m_picCTU->m_collectCUCount, 0, MAX_NUM_DYN_REFINE * sps.numCUsInFrame * sizeof(uint32_t));
98
0
    }
99
654
}
100
101
void FrameData::destroy()
102
654
{
103
654
    delete [] m_picCTU;
104
105
654
    X265_FREE(m_slice->m_ctuMV);
106
654
    delete m_slice;
107
654
    delete m_saoParam;
108
109
654
    m_cuMemPool.destroy();
110
111
654
    if (m_param->bDynamicRefine)
112
0
    {
113
0
        X265_FREE(m_cuMemPool.dynRefineRdBlock);
114
0
        X265_FREE(m_cuMemPool.dynRefCntBlock);
115
0
        X265_FREE(m_cuMemPool.dynRefVarBlock);
116
0
    }
117
654
    X265_FREE(m_cuStat);
118
654
    X265_FREE(m_rowStat);
119
8.50k
    for (int i = 0; i < INTEGRAL_PLANE_NUM; i++)
120
7.84k
    {
121
7.84k
        if (m_meBuffer[i] != NULL)
122
0
        {
123
0
            X265_FREE(m_meBuffer[i]);
124
            m_meBuffer[i] = NULL;
125
0
        }
126
7.84k
    }
127
654
}