/src/x265/source/common/slice.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * Copyright (C) 2013-2020 MulticoreWare, Inc |
3 | | * |
4 | | * Authors: 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 "common.h" |
25 | | #include "frame.h" |
26 | | #include "piclist.h" |
27 | | #include "picyuv.h" |
28 | | #include "slice.h" |
29 | | |
30 | | using namespace X265_NS; |
31 | | |
32 | | void Slice::setRefPicList(PicList& picList) |
33 | 698 | { |
34 | 698 | if (m_sliceType == I_SLICE) |
35 | 698 | { |
36 | 698 | memset(m_refFrameList, 0, sizeof(m_refFrameList)); |
37 | 698 | memset(m_refReconPicList, 0, sizeof(m_refReconPicList)); |
38 | 698 | memset(m_refPOCList, 0, sizeof(m_refPOCList)); |
39 | 698 | m_numRefIdx[1] = m_numRefIdx[0] = 0; |
40 | 698 | return; |
41 | 698 | } |
42 | | |
43 | 0 | Frame* refPic = NULL; |
44 | 0 | Frame* refPicSetStCurr0[MAX_NUM_REF]; |
45 | 0 | Frame* refPicSetStCurr1[MAX_NUM_REF]; |
46 | 0 | Frame* refPicSetLtCurr[MAX_NUM_REF]; |
47 | 0 | int numPocStCurr0 = 0; |
48 | 0 | int numPocStCurr1 = 0; |
49 | 0 | int numPocLtCurr = 0; |
50 | 0 | int i; |
51 | |
|
52 | 0 | for (i = 0; i < m_rps.numberOfNegativePictures; i++) |
53 | 0 | { |
54 | 0 | if (m_rps.bUsed[i]) |
55 | 0 | { |
56 | 0 | refPic = picList.getPOC(m_poc + m_rps.deltaPOC[i]); |
57 | 0 | refPicSetStCurr0[numPocStCurr0] = refPic; |
58 | 0 | numPocStCurr0++; |
59 | 0 | } |
60 | 0 | } |
61 | |
|
62 | 0 | for (; i < m_rps.numberOfNegativePictures + m_rps.numberOfPositivePictures; i++) |
63 | 0 | { |
64 | 0 | if (m_rps.bUsed[i]) |
65 | 0 | { |
66 | 0 | refPic = picList.getPOC(m_poc + m_rps.deltaPOC[i]); |
67 | 0 | refPicSetStCurr1[numPocStCurr1] = refPic; |
68 | 0 | numPocStCurr1++; |
69 | 0 | } |
70 | 0 | } |
71 | |
|
72 | 0 | X265_CHECK(m_rps.numberOfPictures == m_rps.numberOfNegativePictures + m_rps.numberOfPositivePictures, |
73 | 0 | "unexpected picture in RPS\n"); |
74 | | |
75 | | // ref_pic_list_init |
76 | 0 | Frame* rpsCurrList0[MAX_NUM_REF + 1]; |
77 | 0 | Frame* rpsCurrList1[MAX_NUM_REF + 1]; |
78 | 0 | int numPocTotalCurr = numPocStCurr0 + numPocStCurr1 + numPocLtCurr; |
79 | |
|
80 | 0 | int cIdx = 0; |
81 | 0 | for (i = 0; i < numPocStCurr0; i++, cIdx++) |
82 | 0 | rpsCurrList0[cIdx] = refPicSetStCurr0[i]; |
83 | |
|
84 | 0 | for (i = 0; i < numPocStCurr1; i++, cIdx++) |
85 | 0 | rpsCurrList0[cIdx] = refPicSetStCurr1[i]; |
86 | |
|
87 | 0 | for (i = 0; i < numPocLtCurr; i++, cIdx++) |
88 | 0 | rpsCurrList0[cIdx] = refPicSetLtCurr[i]; |
89 | |
|
90 | 0 | X265_CHECK(cIdx == numPocTotalCurr, "RPS index check fail\n"); |
91 | |
|
92 | 0 | if (m_sliceType == B_SLICE) |
93 | 0 | { |
94 | 0 | cIdx = 0; |
95 | 0 | for (i = 0; i < numPocStCurr1; i++, cIdx++) |
96 | 0 | rpsCurrList1[cIdx] = refPicSetStCurr1[i]; |
97 | |
|
98 | 0 | for (i = 0; i < numPocStCurr0; i++, cIdx++) |
99 | 0 | rpsCurrList1[cIdx] = refPicSetStCurr0[i]; |
100 | |
|
101 | 0 | for (i = 0; i < numPocLtCurr; i++, cIdx++) |
102 | 0 | rpsCurrList1[cIdx] = refPicSetLtCurr[i]; |
103 | |
|
104 | 0 | X265_CHECK(cIdx == numPocTotalCurr, "RPS index check fail\n"); |
105 | 0 | } |
106 | |
|
107 | 0 | for (int rIdx = 0; rIdx < m_numRefIdx[0]; rIdx++) |
108 | 0 | { |
109 | 0 | cIdx = rIdx % numPocTotalCurr; |
110 | 0 | X265_CHECK(cIdx >= 0 && cIdx < numPocTotalCurr, "RPS index check fail\n"); |
111 | 0 | m_refFrameList[0][rIdx] = rpsCurrList0[cIdx]; |
112 | 0 | } |
113 | |
|
114 | 0 | if (m_sliceType != B_SLICE) |
115 | 0 | { |
116 | 0 | m_numRefIdx[1] = 0; |
117 | 0 | memset(m_refFrameList[1], 0, sizeof(m_refFrameList[1])); |
118 | 0 | } |
119 | 0 | else |
120 | 0 | { |
121 | 0 | for (int rIdx = 0; rIdx < m_numRefIdx[1]; rIdx++) |
122 | 0 | { |
123 | 0 | cIdx = rIdx % numPocTotalCurr; |
124 | 0 | X265_CHECK(cIdx >= 0 && cIdx < numPocTotalCurr, "RPS index check fail\n"); |
125 | 0 | m_refFrameList[1][rIdx] = rpsCurrList1[cIdx]; |
126 | 0 | } |
127 | 0 | } |
128 | |
|
129 | 0 | for (int dir = 0; dir < 2; dir++) |
130 | 0 | for (int numRefIdx = 0; numRefIdx < m_numRefIdx[dir]; numRefIdx++) |
131 | 0 | m_refPOCList[dir][numRefIdx] = m_refFrameList[dir][numRefIdx]->m_poc; |
132 | 0 | } |
133 | | |
134 | | void Slice::disableWeights() |
135 | 1.39k | { |
136 | 4.18k | for (int l = 0; l < 2; l++) |
137 | 47.4k | for (int i = 0; i < MAX_NUM_REF; i++) |
138 | 178k | for (int yuv = 0; yuv < 3; yuv++) |
139 | 134k | { |
140 | 134k | WeightParam& wp = m_weightPredTable[l][i][yuv]; |
141 | 134k | wp.wtPresent = 0; |
142 | 134k | wp.log2WeightDenom = 0; |
143 | 134k | wp.inputWeight = 1; |
144 | 134k | wp.inputOffset = 0; |
145 | 134k | } |
146 | 1.39k | } |
147 | | |
148 | | /* Sorts the deltaPOC and Used by current values in the RPS based on the |
149 | | * deltaPOC values. deltaPOC values are sorted with -ve values before the +ve |
150 | | * values. -ve values are in decreasing order. +ve values are in increasing |
151 | | * order */ |
152 | | void RPS::sortDeltaPOC() |
153 | 698 | { |
154 | | // sort in increasing order (smallest first) |
155 | 698 | for (int j = 1; j < numberOfPictures; j++) |
156 | 0 | { |
157 | 0 | int dPOC = deltaPOC[j]; |
158 | 0 | bool used = bUsed[j]; |
159 | 0 | for (int k = j - 1; k >= 0; k--) |
160 | 0 | { |
161 | 0 | int temp = deltaPOC[k]; |
162 | 0 | if (dPOC < temp) |
163 | 0 | { |
164 | 0 | deltaPOC[k + 1] = temp; |
165 | 0 | bUsed[k + 1] = bUsed[k]; |
166 | 0 | deltaPOC[k] = dPOC; |
167 | 0 | bUsed[k] = used; |
168 | 0 | } |
169 | 0 | } |
170 | 0 | } |
171 | | |
172 | | // flip the negative values to largest first |
173 | 698 | int numNegPics = numberOfNegativePictures; |
174 | 698 | for (int j = 0, k = numNegPics - 1; j < numNegPics >> 1; j++, k--) |
175 | 0 | { |
176 | 0 | int dPOC = deltaPOC[j]; |
177 | 0 | bool used = bUsed[j]; |
178 | 0 | deltaPOC[j] = deltaPOC[k]; |
179 | 0 | bUsed[j] = bUsed[k]; |
180 | 0 | deltaPOC[k] = dPOC; |
181 | 0 | bUsed[k] = used; |
182 | 0 | } |
183 | 698 | } |
184 | | |
185 | | uint32_t Slice::realEndAddress(uint32_t endCUAddr) const |
186 | 698 | { |
187 | | // Calculate end address |
188 | 698 | uint32_t internalAddress = (endCUAddr - 1) % m_param->num4x4Partitions; |
189 | 698 | uint32_t externalAddress = (endCUAddr - 1) / m_param->num4x4Partitions; |
190 | 698 | uint32_t xmax = m_sps->picWidthInLumaSamples - (externalAddress % m_sps->numCuInWidth) * m_param->maxCUSize; |
191 | 698 | uint32_t ymax = m_sps->picHeightInLumaSamples - (externalAddress / m_sps->numCuInWidth) * m_param->maxCUSize; |
192 | | |
193 | 69.6k | while (g_zscanToPelX[internalAddress] >= xmax || g_zscanToPelY[internalAddress] >= ymax) |
194 | 68.9k | internalAddress--; |
195 | | |
196 | 698 | internalAddress++; |
197 | 698 | if (internalAddress == m_param->num4x4Partitions) |
198 | 117 | { |
199 | 117 | internalAddress = 0; |
200 | 117 | externalAddress++; |
201 | 117 | } |
202 | | |
203 | 698 | return externalAddress * m_param->num4x4Partitions + internalAddress; |
204 | 698 | } |
205 | | |
206 | | |