/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 | 698 | { |
31 | 698 | memset(this, 0, sizeof(*this)); |
32 | 698 | } |
33 | | |
34 | | bool FrameData::create(const x265_param& param, const SPS& sps, int csp) |
35 | 698 | { |
36 | 698 | m_param = ¶m; |
37 | 698 | m_slice = new Slice; |
38 | 698 | m_picCTU = new CUData[sps.numCUsInFrame]; |
39 | 698 | m_picCsp = csp; |
40 | 698 | m_spsrpsIdx = -1; |
41 | 698 | if (param.rc.bStatWrite) |
42 | 0 | m_spsrps = const_cast<RPS*>(sps.spsrps); |
43 | 698 | bool isallocated = m_cuMemPool.create(0, param.internalCsp, sps.numCUsInFrame, param); |
44 | 698 | 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 | 698 | if (isallocated) |
51 | 698 | { |
52 | 14.6k | for (uint32_t ctuAddr = 0; ctuAddr < sps.numCUsInFrame; ctuAddr++) |
53 | 13.9k | { |
54 | 13.9k | 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 | 13.9k | m_picCTU[ctuAddr].initialize(m_cuMemPool, 0, param, ctuAddr); |
61 | 13.9k | } |
62 | 698 | } |
63 | 0 | else |
64 | 0 | return false; |
65 | 698 | CHECKED_MALLOC_ZERO(m_cuStat, RCStatCU, sps.numCUsInFrame); |
66 | 698 | CHECKED_MALLOC(m_rowStat, RCStatRow, sps.numCuInHeight); |
67 | 698 | reinit(sps); |
68 | | |
69 | 9.07k | for (int i = 0; i < INTEGRAL_PLANE_NUM; i++) |
70 | 8.37k | { |
71 | 8.37k | m_meBuffer[i] = NULL; |
72 | 8.37k | m_meIntegral[i] = NULL; |
73 | 8.37k | } |
74 | 698 | return true; |
75 | | |
76 | 0 | fail: |
77 | 0 | return false; |
78 | 698 | } |
79 | | |
80 | | void FrameData::reinit(const SPS& sps) |
81 | 698 | { |
82 | 698 | memset(m_cuStat, 0, sps.numCUsInFrame * sizeof(*m_cuStat)); |
83 | 698 | memset(m_rowStat, 0, sps.numCuInHeight * sizeof(*m_rowStat)); |
84 | 698 | 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 | 698 | } |
91 | | |
92 | | void FrameData::destroy() |
93 | 698 | { |
94 | 698 | delete [] m_picCTU; |
95 | 698 | delete m_slice; |
96 | 698 | delete m_saoParam; |
97 | | |
98 | 698 | m_cuMemPool.destroy(); |
99 | | |
100 | 698 | 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 | 698 | X265_FREE(m_cuStat); |
107 | 698 | X265_FREE(m_rowStat); |
108 | 9.07k | for (int i = 0; i < INTEGRAL_PLANE_NUM; i++) |
109 | 8.37k | { |
110 | 8.37k | if (m_meBuffer[i] != NULL) |
111 | 0 | { |
112 | 0 | X265_FREE(m_meBuffer[i]); |
113 | 0 | m_meBuffer[i] = NULL; |
114 | 0 | } |
115 | 8.37k | } |
116 | 698 | } |