1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2012, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TEncCavlc.cpp |
---|
35 | \brief CAVLC encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "../TLibCommon/CommonDef.h" |
---|
39 | #include "TEncCavlc.h" |
---|
40 | #include "SEIwrite.h" |
---|
41 | |
---|
42 | //! \ingroup TLibEncoder |
---|
43 | //! \{ |
---|
44 | |
---|
45 | #if ENC_DEC_TRACE |
---|
46 | |
---|
47 | #define WRITE_CODE( value, length, name) xWriteCodeTr ( value, length, name ) |
---|
48 | #define WRITE_UVLC( value, name) xWriteUvlcTr ( value, name ) |
---|
49 | #define WRITE_SVLC( value, name) xWriteSvlcTr ( value, name ) |
---|
50 | #define WRITE_FLAG( value, name) xWriteFlagTr ( value, name ) |
---|
51 | |
---|
52 | Void xWriteUvlcTr ( UInt value, const Char *pSymbolName); |
---|
53 | Void xWriteSvlcTr ( Int value, const Char *pSymbolName); |
---|
54 | Void xWriteFlagTr ( UInt value, const Char *pSymbolName); |
---|
55 | |
---|
56 | Void xTraceSPSHeader (TComSPS *pSPS) |
---|
57 | { |
---|
58 | fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() ); |
---|
59 | } |
---|
60 | |
---|
61 | Void xTracePPSHeader (TComPPS *pPPS) |
---|
62 | { |
---|
63 | fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() ); |
---|
64 | } |
---|
65 | |
---|
66 | Void xTraceAPSHeader (TComAPS *pAPS) |
---|
67 | { |
---|
68 | fprintf( g_hTrace, "=========== Adaptation Parameter Set ===========\n"); |
---|
69 | } |
---|
70 | |
---|
71 | Void xTraceSliceHeader (TComSlice *pSlice) |
---|
72 | { |
---|
73 | fprintf( g_hTrace, "=========== Slice ===========\n"); |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | Void TEncCavlc::xWriteCodeTr (UInt value, UInt length, const Char *pSymbolName) |
---|
78 | { |
---|
79 | xWriteCode (value,length); |
---|
80 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ ); |
---|
81 | fprintf( g_hTrace, "%-40s u(%d) : %d\n", pSymbolName, length, value ); |
---|
82 | } |
---|
83 | |
---|
84 | Void TEncCavlc::xWriteUvlcTr (UInt value, const Char *pSymbolName) |
---|
85 | { |
---|
86 | xWriteUvlc (value); |
---|
87 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ ); |
---|
88 | fprintf( g_hTrace, "%-40s u(v) : %d\n", pSymbolName, value ); |
---|
89 | } |
---|
90 | |
---|
91 | Void TEncCavlc::xWriteSvlcTr (Int value, const Char *pSymbolName) |
---|
92 | { |
---|
93 | xWriteSvlc(value); |
---|
94 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ ); |
---|
95 | fprintf( g_hTrace, "%-40s s(v) : %d\n", pSymbolName, value ); |
---|
96 | } |
---|
97 | |
---|
98 | Void TEncCavlc::xWriteFlagTr(UInt value, const Char *pSymbolName) |
---|
99 | { |
---|
100 | xWriteFlag(value); |
---|
101 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ ); |
---|
102 | fprintf( g_hTrace, "%-40s u(1) : %d\n", pSymbolName, value ); |
---|
103 | } |
---|
104 | |
---|
105 | #else |
---|
106 | |
---|
107 | #define WRITE_CODE( value, length, name) xWriteCode ( value, length ) |
---|
108 | #define WRITE_UVLC( value, name) xWriteUvlc ( value ) |
---|
109 | #define WRITE_SVLC( value, name) xWriteSvlc ( value ) |
---|
110 | #define WRITE_FLAG( value, name) xWriteFlag ( value ) |
---|
111 | |
---|
112 | #endif |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | // ==================================================================================================================== |
---|
117 | // Constructor / destructor / create / destroy |
---|
118 | // ==================================================================================================================== |
---|
119 | |
---|
120 | TEncCavlc::TEncCavlc() |
---|
121 | { |
---|
122 | m_pcBitIf = NULL; |
---|
123 | m_uiCoeffCost = 0; |
---|
124 | m_bAlfCtrl = false; |
---|
125 | m_uiMaxAlfCtrlDepth = 0; |
---|
126 | |
---|
127 | m_iSliceGranularity = 0; |
---|
128 | } |
---|
129 | |
---|
130 | TEncCavlc::~TEncCavlc() |
---|
131 | { |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | // ==================================================================================================================== |
---|
136 | // Public member functions |
---|
137 | // ==================================================================================================================== |
---|
138 | |
---|
139 | Void TEncCavlc::resetEntropy() |
---|
140 | { |
---|
141 | } |
---|
142 | |
---|
143 | /** |
---|
144 | * marshall the SEI message sei. |
---|
145 | */ |
---|
146 | void TEncCavlc::codeSEI(const SEI& sei) |
---|
147 | { |
---|
148 | writeSEImessage(*m_pcBitIf, sei); |
---|
149 | } |
---|
150 | |
---|
151 | Void TEncCavlc::codeAPSInitInfo(TComAPS* pcAPS) |
---|
152 | { |
---|
153 | |
---|
154 | #if ENC_DEC_TRACE |
---|
155 | xTraceAPSHeader(pcAPS); |
---|
156 | #endif |
---|
157 | //APS ID |
---|
158 | WRITE_UVLC( pcAPS->getAPSID(), "aps_id" ); |
---|
159 | |
---|
160 | WRITE_FLAG( pcAPS->getScalingListEnabled()?1:0, "aps_scaling_list_data_present_flag"); |
---|
161 | //DF flag |
---|
162 | WRITE_FLAG(pcAPS->getLoopFilterOffsetInAPS()?1:0, "aps_deblocking_filter_flag"); |
---|
163 | } |
---|
164 | Void TEncCavlc::codeAPSAlflag(UInt uiCode) |
---|
165 | { |
---|
166 | WRITE_FLAG(uiCode, "aps_adaptive_loop_filter_flag"); |
---|
167 | } |
---|
168 | |
---|
169 | Void TEncCavlc::codeDFFlag(UInt uiCode, const Char *pSymbolName) |
---|
170 | { |
---|
171 | WRITE_FLAG(uiCode, pSymbolName); |
---|
172 | } |
---|
173 | Void TEncCavlc::codeDFSvlc(Int iCode, const Char *pSymbolName) |
---|
174 | { |
---|
175 | WRITE_SVLC(iCode, pSymbolName); |
---|
176 | } |
---|
177 | |
---|
178 | Void TEncCavlc::codeShortTermRefPicSet( TComSPS* pcSPS, TComReferencePictureSet* rps ) |
---|
179 | { |
---|
180 | #if PRINT_RPS_INFO |
---|
181 | int lastBits = getNumberOfWrittenBits(); |
---|
182 | #endif |
---|
183 | WRITE_FLAG( rps->getInterRPSPrediction(), "inter_ref_pic_set_prediction_flag" ); // inter_RPS_prediction_flag |
---|
184 | if (rps->getInterRPSPrediction()) |
---|
185 | { |
---|
186 | Int deltaRPS = rps->getDeltaRPS(); |
---|
187 | WRITE_UVLC( rps->getDeltaRIdxMinus1(), "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1 |
---|
188 | WRITE_CODE( (deltaRPS >=0 ? 0: 1), 1, "delta_rps_sign" ); //delta_rps_sign |
---|
189 | WRITE_UVLC( abs(deltaRPS) - 1, "abs_delta_rps_minus1"); // absolute delta RPS minus 1 |
---|
190 | |
---|
191 | for(Int j=0; j < rps->getNumRefIdc(); j++) |
---|
192 | { |
---|
193 | Int refIdc = rps->getRefIdc(j); |
---|
194 | WRITE_CODE( (refIdc==1? 1: 0), 1, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1 |
---|
195 | if (refIdc != 1) |
---|
196 | { |
---|
197 | WRITE_CODE( refIdc>>1, 1, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise. |
---|
198 | } |
---|
199 | } |
---|
200 | } |
---|
201 | else |
---|
202 | { |
---|
203 | WRITE_UVLC( rps->getNumberOfNegativePictures(), "num_negative_pics" ); |
---|
204 | WRITE_UVLC( rps->getNumberOfPositivePictures(), "num_positive_pics" ); |
---|
205 | Int prev = 0; |
---|
206 | for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++) |
---|
207 | { |
---|
208 | WRITE_UVLC( prev-rps->getDeltaPOC(j)-1, "delta_poc_s0_minus1" ); |
---|
209 | prev = rps->getDeltaPOC(j); |
---|
210 | WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s0_flag"); |
---|
211 | } |
---|
212 | prev = 0; |
---|
213 | for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++) |
---|
214 | { |
---|
215 | WRITE_UVLC( rps->getDeltaPOC(j)-prev-1, "delta_poc_s1_minus1" ); |
---|
216 | prev = rps->getDeltaPOC(j); |
---|
217 | WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s1_flag" ); |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | #if PRINT_RPS_INFO |
---|
222 | printf("irps=%d (%2d bits) ", rps->getInterRPSPrediction(), getNumberOfWrittenBits() - lastBits); |
---|
223 | rps->printDeltaPOC(); |
---|
224 | #endif |
---|
225 | } |
---|
226 | |
---|
227 | |
---|
228 | Void TEncCavlc::codePPS( TComPPS* pcPPS ) |
---|
229 | { |
---|
230 | #if ENC_DEC_TRACE |
---|
231 | xTracePPSHeader (pcPPS); |
---|
232 | #endif |
---|
233 | |
---|
234 | WRITE_UVLC( pcPPS->getPPSId(), "pic_parameter_set_id" ); |
---|
235 | WRITE_UVLC( pcPPS->getSPSId(), "seq_parameter_set_id" ); |
---|
236 | |
---|
237 | WRITE_FLAG( pcPPS->getSignHideFlag(), "sign_data_hiding_flag" ); |
---|
238 | if( pcPPS->getSignHideFlag() ) |
---|
239 | { |
---|
240 | WRITE_CODE(pcPPS->getTSIG(), 4, "sign_hiding_threshold"); |
---|
241 | } |
---|
242 | #if CABAC_INIT_FLAG |
---|
243 | WRITE_FLAG( pcPPS->getCabacInitPresentFlag() ? 1 : 0, "cabac_init_present_flag" ); |
---|
244 | #endif |
---|
245 | // entropy_coding_mode_flag |
---|
246 | // We code the entropy_coding_mode_flag, it's needed for tests. |
---|
247 | WRITE_FLAG( pcPPS->getEntropyCodingMode() ? 1 : 0, "entropy_coding_mode_flag" ); |
---|
248 | if (pcPPS->getEntropyCodingMode()) |
---|
249 | { |
---|
250 | } |
---|
251 | // num_ref_idx_l0_default_active_minus1 |
---|
252 | // num_ref_idx_l1_default_active_minus1 |
---|
253 | WRITE_SVLC( pcPPS->getPicInitQPMinus26(), "pic_init_qp_minus26"); |
---|
254 | WRITE_FLAG( pcPPS->getConstrainedIntraPred() ? 1 : 0, "constrained_intra_pred_flag" ); |
---|
255 | WRITE_FLAG( pcPPS->getEnableTMVPFlag() ? 1 : 0, "enable_temporal_mvp_flag" ); |
---|
256 | WRITE_CODE( pcPPS->getSliceGranularity(), 2, "slice_granularity"); |
---|
257 | WRITE_UVLC( pcPPS->getMaxCuDQPDepth() + pcPPS->getUseDQP(), "max_cu_qp_delta_depth" ); |
---|
258 | |
---|
259 | WRITE_SVLC( pcPPS->getChromaQpOffset(), "chroma_qp_offset" ); |
---|
260 | WRITE_SVLC( pcPPS->getChromaQpOffset2nd(), "chroma_qp_offset_2nd" ); |
---|
261 | |
---|
262 | WRITE_FLAG( pcPPS->getUseWP() ? 1 : 0, "weighted_pred_flag" ); // Use of Weighting Prediction (P_SLICE) |
---|
263 | WRITE_CODE( pcPPS->getWPBiPredIdc(), 2, "weighted_bipred_idc" ); // Use of Weighting Bi-Prediction (B_SLICE) |
---|
264 | WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0, "output_flag_present_flag" ); |
---|
265 | if(pcPPS->getSPS()->getTilesOrEntropyCodingSyncIdc()==1) |
---|
266 | { |
---|
267 | WRITE_FLAG( pcPPS->getColumnRowInfoPresent(), "tile_info_present_flag" ); |
---|
268 | WRITE_FLAG( pcPPS->getTileBehaviorControlPresentFlag(), "tile_control_present_flag"); |
---|
269 | if( pcPPS->getColumnRowInfoPresent() == 1 ) |
---|
270 | { |
---|
271 | WRITE_UVLC( pcPPS->getNumColumnsMinus1(), "num_tile_columns_minus1" ); |
---|
272 | WRITE_UVLC( pcPPS->getNumRowsMinus1(), "num_tile_rows_minus1" ); |
---|
273 | WRITE_FLAG( pcPPS->getUniformSpacingIdr(), "uniform_spacing_flag" ); |
---|
274 | if( pcPPS->getUniformSpacingIdr() == 0 ) |
---|
275 | { |
---|
276 | for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++) |
---|
277 | { |
---|
278 | WRITE_UVLC( pcPPS->getColumnWidth(i), "column_width" ); |
---|
279 | } |
---|
280 | for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++) |
---|
281 | { |
---|
282 | WRITE_UVLC( pcPPS->getRowHeight(i), "row_height" ); |
---|
283 | } |
---|
284 | } |
---|
285 | } |
---|
286 | |
---|
287 | if(pcPPS->getTileBehaviorControlPresentFlag() == 1) |
---|
288 | { |
---|
289 | Int iNumColTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumColumnsMinus1()); |
---|
290 | Int iNumRowTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumRowsMinus1()); |
---|
291 | |
---|
292 | if(iNumColTilesMinus1 !=0 || iNumRowTilesMinus1 !=0) |
---|
293 | { |
---|
294 | WRITE_FLAG( pcPPS->getLFCrossTileBoundaryFlag()?1 : 0, "loop_filter_across_tile_flag"); |
---|
295 | } |
---|
296 | } |
---|
297 | } |
---|
298 | else if(pcPPS->getSPS()->getTilesOrEntropyCodingSyncIdc()==2) |
---|
299 | { |
---|
300 | WRITE_UVLC( pcPPS->getNumSubstreams()-1, "num_substreams_minus1" ); |
---|
301 | } |
---|
302 | |
---|
303 | WRITE_FLAG( pcPPS->getDeblockingFilterControlPresent()?1 : 0, "deblocking_filter_control_present_flag"); |
---|
304 | WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2"); |
---|
305 | WRITE_FLAG( 0, "pps_extension_flag" ); |
---|
306 | } |
---|
307 | |
---|
308 | #if QC_MVHEVC_B0046 |
---|
309 | Void TEncCavlc::codeVPS( TComVPS* pcVPS ) |
---|
310 | { |
---|
311 | WRITE_CODE( pcVPS->getVPSId(), 4, "video_parameter_set_id" ); |
---|
312 | WRITE_FLAG( pcVPS->getTemporalNestingFlag() -1, "temporal_id_nesting_flag" ); |
---|
313 | WRITE_CODE( 0, 2, "vps_reserved_zero_2bits" ); |
---|
314 | WRITE_CODE( pcVPS->getMaxLayers() - 1, 6, "vps_max_layers_minus1" ); |
---|
315 | WRITE_CODE( pcVPS->getMaxTLayers() - 1, 3, "vps_max_sub_layers_minus1" ); |
---|
316 | //to be determined |
---|
317 | //profile_tier_level( 1, vps_max_sub_layers_minus1 ); |
---|
318 | //to be modified |
---|
319 | WRITE_CODE( 0, 12, "vps_extension_offset" ); |
---|
320 | for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++) |
---|
321 | { |
---|
322 | WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i), "max_dec_pic_buffering[i]" ); |
---|
323 | WRITE_UVLC( pcVPS->getNumReorderPics(i), "num_reorder_pics[i]" ); |
---|
324 | WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i), "max_latency_increase[i]" ); |
---|
325 | } |
---|
326 | //!!!waste one bit: 3-view, 3; 2-view or more views: 1 |
---|
327 | WRITE_UVLC(pcVPS->getNumHRDParameters(), "vps_num_hrd_parameters" ); |
---|
328 | assert(pcVPS->getNumHRDParameters()==0); |
---|
329 | for ( UInt i = 0; i < pcVPS->getNumHRDParameters(); i ++) |
---|
330 | { |
---|
331 | // if( i > 0 ) |
---|
332 | //{ |
---|
333 | // WRITE_UVLC (0, "op_num_layer_id_values_minus1[ opIdx ]"); |
---|
334 | // for( i = 0; i <= op_num_layer_id_values_minus1[ opIdx ]; i++ ) |
---|
335 | // WRITE_CODE(0, 6, "op_layer_id[ opIdx ][ i ]"); |
---|
336 | //} |
---|
337 | //hrd_parameters( i = = 0, vps_max_sub_layers_minus1 ); |
---|
338 | } |
---|
339 | WRITE_CODE( 1, 1, "bit_equal_to_one" ); |
---|
340 | //btye aligned |
---|
341 | m_pcBitIf->writeAlignOne(); |
---|
342 | |
---|
343 | if(pcVPS->getMaxLayers() == 3) |
---|
344 | pcVPS->setNumAddiLayerOperationPoints (pcVPS->getMaxLayers()); //may be configured |
---|
345 | else |
---|
346 | pcVPS->setNumAddiLayerOperationPoints (1); |
---|
347 | pcVPS->setNumAddiProLevelSets (1); |
---|
348 | WRITE_CODE( pcVPS->getNumAddiLayerOperationPoints(), 8, "num_additional_layer_operation_points" ); |
---|
349 | WRITE_CODE( pcVPS->getNumAddiProLevelSets(), 8, "num_additional_profile_level_sets" ); |
---|
350 | for(UInt i=0; i <= pcVPS->getMaxLayers()-1; i++) |
---|
351 | { |
---|
352 | WRITE_CODE( 0, 4, "num_types_zero_4bits[i]" ); |
---|
353 | WRITE_CODE( 0, 4, "type_zero_4bits[i]" ); |
---|
354 | WRITE_CODE( pcVPS->getViewId(i), 8, "view_id[i]" ); |
---|
355 | if(i) |
---|
356 | { |
---|
357 | WRITE_CODE( pcVPS->getNumDirectRefLayer(i), 6, "num_direct_ref_layers[ i ]" ); |
---|
358 | for (UInt j = 0; j< pcVPS->getNumDirectRefLayer(i); j++) |
---|
359 | { |
---|
360 | WRITE_CODE( pcVPS->getDirectRefLayerId (i, j), 6, "ref_layer_id[i][j]" ); |
---|
361 | } |
---|
362 | } |
---|
363 | } |
---|
364 | for( UInt i=1; i<=pcVPS->getNumAddiProLevelSets(); i++) |
---|
365 | { |
---|
366 | //profile_tier_level |
---|
367 | } |
---|
368 | for( UInt i=1; i<= pcVPS->getNumAddiLayerOperationPoints(); i++) |
---|
369 | { |
---|
370 | if(pcVPS->getMaxLayers() == 3) |
---|
371 | { |
---|
372 | pcVPS->setNumOpLayerIdMinus1((i < pcVPS->getNumAddiLayerOperationPoints() ? 1: 2), (i-1)); |
---|
373 | } |
---|
374 | else if( i==1 ) |
---|
375 | { |
---|
376 | assert(pcVPS->getNumAddiLayerOperationPoints()==1); |
---|
377 | pcVPS->setNumOpLayerIdMinus1(pcVPS->getMaxLayers()-1, (i-1)); |
---|
378 | } |
---|
379 | WRITE_UVLC( pcVPS->getNumOpLayerIdMinus1(i-1), "op_num_layer_id_values_minus1[ opIdx ]" ); |
---|
380 | for(UInt j = 0; j <= pcVPS->getNumOpLayerIdMinus1(i-1); j++ ) |
---|
381 | { |
---|
382 | if(pcVPS->getMaxLayers() == 3 && i== 2 && j==1) |
---|
383 | pcVPS->setNumOpLayerId (2, i-1, j); |
---|
384 | else |
---|
385 | pcVPS->setNumOpLayerId (j, i-1, j); |
---|
386 | WRITE_UVLC( pcVPS->getNumOpLayerId(i-1, j), "op_layer_id[ opIdx ][ i ]" ); |
---|
387 | } |
---|
388 | if (pcVPS->getNumAddiProLevelSets()) |
---|
389 | { |
---|
390 | //profile_level_idx[ i ] |
---|
391 | } |
---|
392 | } |
---|
393 | return; |
---|
394 | } |
---|
395 | #else |
---|
396 | #if VIDYO_VPS_INTEGRATION |
---|
397 | Void TEncCavlc::codeVPS( TComVPS* pcVPS ) |
---|
398 | { |
---|
399 | WRITE_CODE( pcVPS->getMaxTLayers() - 1, 3, "max_temporal_layers_minus1" ); |
---|
400 | WRITE_CODE( pcVPS->getMaxLayers() - 1, 5, "max_layers_minus1" ); |
---|
401 | WRITE_FLAG( pcVPS->getTemporalNestingFlag() - 1, "temporal_id_nesting_flag" ); |
---|
402 | WRITE_UVLC( pcVPS->getVPSId(), "video_parameter_set_id" ); |
---|
403 | for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++) |
---|
404 | { |
---|
405 | WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i), "max_dec_pic_buffering[i]" ); |
---|
406 | WRITE_UVLC( pcVPS->getNumReorderPics(i), "num_reorder_pics[i]" ); |
---|
407 | WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i), "max_latency_increase[i]" ); |
---|
408 | } |
---|
409 | |
---|
410 | WRITE_CODE( 1, 1, "bit_equal_to_one" ); |
---|
411 | |
---|
412 | if( pcVPS->getMaxLayers() - 1 > 0 ) |
---|
413 | { |
---|
414 | WRITE_UVLC( pcVPS->getExtensionType(), "extension_type" ); |
---|
415 | |
---|
416 | for(UInt i=1; i <= pcVPS->getMaxLayers()-1; i++) |
---|
417 | { |
---|
418 | WRITE_FLAG( pcVPS->getDependentFlag(i), "dependent_flag[i]" ); |
---|
419 | if( pcVPS->getDependentFlag(i) ) |
---|
420 | { |
---|
421 | WRITE_UVLC( i - pcVPS->getDependentLayer(i) - 1, "delta_reference_layer_id_minus1[i]" ); |
---|
422 | if( pcVPS->getExtensionType() == VPS_EXTENSION_TYPE_MULTI_VIEW ) |
---|
423 | { |
---|
424 | WRITE_UVLC( pcVPS->getViewId(i), "view_id[i]" ); |
---|
425 | WRITE_FLAG( pcVPS->getDepthFlag(i), "depth_flag[i]" ); |
---|
426 | WRITE_SVLC( pcVPS->getViewOrderIdx(i), "view_order_idx[i]" ); |
---|
427 | } |
---|
428 | |
---|
429 | } |
---|
430 | } |
---|
431 | #if INTER_VIEW_VECTOR_SCALING_C0115 |
---|
432 | WRITE_FLAG( pcVPS->getIVScalingFlag(), "inter_view_vector_scaling_flag" ); |
---|
433 | #endif |
---|
434 | } |
---|
435 | |
---|
436 | WRITE_FLAG( 0, "vps_extension_flag" ); |
---|
437 | |
---|
438 | //future extensions here.. |
---|
439 | |
---|
440 | return; |
---|
441 | } |
---|
442 | #endif |
---|
443 | #endif |
---|
444 | #if HHI_MPI || H3D_QTL |
---|
445 | Void TEncCavlc::codeSPS( TComSPS* pcSPS, Bool bIsDepth ) |
---|
446 | #else |
---|
447 | Void TEncCavlc::codeSPS( TComSPS* pcSPS ) |
---|
448 | #endif |
---|
449 | { |
---|
450 | #if ENC_DEC_TRACE |
---|
451 | xTraceSPSHeader (pcSPS); |
---|
452 | #endif |
---|
453 | WRITE_CODE( pcSPS->getProfileIdc (), 8, "profile_idc" ); |
---|
454 | WRITE_CODE( 0, 8, "reserved_zero_8bits" ); |
---|
455 | WRITE_CODE( pcSPS->getLevelIdc (), 8, "level_idc" ); |
---|
456 | WRITE_UVLC( pcSPS->getSPSId (), "seq_parameter_set_id" ); |
---|
457 | #if VIDYO_VPS_INTEGRATION |
---|
458 | WRITE_UVLC( pcSPS->getVPSId (), "video_parameter_set_id" ); |
---|
459 | #endif |
---|
460 | WRITE_UVLC( pcSPS->getChromaFormatIdc (), "chroma_format_idc" ); |
---|
461 | WRITE_CODE( pcSPS->getMaxTLayers() - 1, 3, "max_temporal_layers_minus1" ); |
---|
462 | WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (), "pic_width_in_luma_samples" ); |
---|
463 | WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(), "pic_height_in_luma_samples" ); |
---|
464 | WRITE_FLAG( pcSPS->getPicCroppingFlag(), "pic_cropping_flag" ); |
---|
465 | if (pcSPS->getPicCroppingFlag()) |
---|
466 | { |
---|
467 | WRITE_UVLC( pcSPS->getPicCropLeftOffset(), "pic_crop_left_offset" ); |
---|
468 | WRITE_UVLC( pcSPS->getPicCropRightOffset(), "pic_crop_right_offset" ); |
---|
469 | WRITE_UVLC( pcSPS->getPicCropTopOffset(), "pic_crop_top_offset" ); |
---|
470 | WRITE_UVLC( pcSPS->getPicCropBottomOffset(), "pic_crop_bottom_offset" ); |
---|
471 | } |
---|
472 | |
---|
473 | #if FULL_NBIT |
---|
474 | WRITE_UVLC( pcSPS->getBitDepth() - 8, "bit_depth_luma_minus8" ); |
---|
475 | #else |
---|
476 | WRITE_UVLC( pcSPS->getBitIncrement(), "bit_depth_luma_minus8" ); |
---|
477 | #endif |
---|
478 | #if FULL_NBIT |
---|
479 | WRITE_UVLC( pcSPS->getBitDepth() - 8, "bit_depth_chroma_minus8" ); |
---|
480 | #else |
---|
481 | WRITE_UVLC( pcSPS->getBitIncrement(), "bit_depth_chroma_minus8" ); |
---|
482 | #endif |
---|
483 | |
---|
484 | WRITE_FLAG( pcSPS->getUsePCM() ? 1 : 0, "pcm_enabled_flag"); |
---|
485 | |
---|
486 | if( pcSPS->getUsePCM() ) |
---|
487 | { |
---|
488 | WRITE_CODE( pcSPS->getPCMBitDepthLuma() - 1, 4, "pcm_bit_depth_luma_minus1" ); |
---|
489 | WRITE_CODE( pcSPS->getPCMBitDepthChroma() - 1, 4, "pcm_bit_depth_chroma_minus1" ); |
---|
490 | } |
---|
491 | |
---|
492 | #if LOSSLESS_CODING |
---|
493 | WRITE_FLAG( (pcSPS->getUseLossless ()) ? 1 : 0, "qpprime_y_zero_transquant_bypass_flag" ); |
---|
494 | #endif |
---|
495 | |
---|
496 | WRITE_UVLC( pcSPS->getBitsForPOC()-4, "log2_max_pic_order_cnt_lsb_minus4" ); |
---|
497 | for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++) |
---|
498 | { |
---|
499 | WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i), "max_dec_pic_buffering[i]" ); |
---|
500 | WRITE_UVLC( pcSPS->getNumReorderPics(i), "num_reorder_pics[i]" ); |
---|
501 | WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i), "max_latency_increase[i]" ); |
---|
502 | } |
---|
503 | assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() ); |
---|
504 | |
---|
505 | UInt MinCUSize = pcSPS->getMaxCUWidth() >> ( pcSPS->getMaxCUDepth()-g_uiAddCUDepth ); |
---|
506 | UInt log2MinCUSize = 0; |
---|
507 | while(MinCUSize > 1) |
---|
508 | { |
---|
509 | MinCUSize >>= 1; |
---|
510 | log2MinCUSize++; |
---|
511 | } |
---|
512 | |
---|
513 | WRITE_FLAG( pcSPS->getRestrictedRefPicListsFlag(), "restricted_ref_pic_lists_flag" ); |
---|
514 | if( pcSPS->getRestrictedRefPicListsFlag() ) |
---|
515 | { |
---|
516 | WRITE_FLAG( pcSPS->getListsModificationPresentFlag(), "lists_modification_present_flag" ); |
---|
517 | } |
---|
518 | WRITE_UVLC( log2MinCUSize - 3, "log2_min_coding_block_size_minus3" ); |
---|
519 | WRITE_UVLC( pcSPS->getMaxCUDepth()-g_uiAddCUDepth, "log2_diff_max_min_coding_block_size" ); |
---|
520 | WRITE_UVLC( pcSPS->getQuadtreeTULog2MinSize() - 2, "log2_min_transform_block_size_minus2" ); |
---|
521 | WRITE_UVLC( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize(), "log2_diff_max_min_transform_block_size" ); |
---|
522 | |
---|
523 | if(log2MinCUSize == 3) |
---|
524 | { |
---|
525 | xWriteFlag ( (pcSPS->getDisInter4x4()) ? 1 : 0 ); |
---|
526 | } |
---|
527 | |
---|
528 | if( pcSPS->getUsePCM() ) |
---|
529 | { |
---|
530 | WRITE_UVLC( pcSPS->getPCMLog2MinSize() - 3, "log2_min_pcm_coding_block_size_minus3" ); |
---|
531 | WRITE_UVLC( pcSPS->getPCMLog2MaxSize() - pcSPS->getPCMLog2MinSize(), "log2_diff_max_min_pcm_coding_block_size" ); |
---|
532 | } |
---|
533 | WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthInter() - 1, "max_transform_hierarchy_depth_inter" ); |
---|
534 | WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1, "max_transform_hierarchy_depth_intra" ); |
---|
535 | WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0, "scaling_list_enabled_flag" ); |
---|
536 | WRITE_FLAG( pcSPS->getUseLMChroma () ? 1 : 0, "chroma_pred_from_luma_enabled_flag" ); |
---|
537 | WRITE_FLAG( pcSPS->getUseDF() ? 1 : 0, "deblocking_filter_in_aps_enabled_flag"); |
---|
538 | WRITE_FLAG( pcSPS->getLFCrossSliceBoundaryFlag()?1 : 0, "seq_loop_filter_across_slices_enabled_flag"); |
---|
539 | WRITE_FLAG( pcSPS->getUseAMP(), "asymmetric_motion_partitions_enabled_flag" ); |
---|
540 | WRITE_FLAG( pcSPS->getUseNSQT(), "non_square_quadtree_enabled_flag" ); |
---|
541 | WRITE_FLAG( pcSPS->getUseSAO() ? 1 : 0, "sample_adaptive_offset_enabled_flag"); |
---|
542 | WRITE_FLAG( pcSPS->getUseALF () ? 1 : 0, "adaptive_loop_filter_enabled_flag"); |
---|
543 | if(pcSPS->getUseALF()) |
---|
544 | { |
---|
545 | WRITE_FLAG( (pcSPS->getUseALFCoefInSlice()) ? 1 : 0, "alf_coef_in_slice_flag"); |
---|
546 | } |
---|
547 | |
---|
548 | if( pcSPS->getUsePCM() ) |
---|
549 | { |
---|
550 | WRITE_FLAG( pcSPS->getPCMFilterDisableFlag()?1 : 0, "pcm_loop_filter_disable_flag"); |
---|
551 | } |
---|
552 | |
---|
553 | assert( pcSPS->getMaxTLayers() > 0 ); |
---|
554 | |
---|
555 | WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0, "temporal_id_nesting_flag" ); |
---|
556 | |
---|
557 | TComRPSList* rpsList = pcSPS->getRPSList(); |
---|
558 | TComReferencePictureSet* rps; |
---|
559 | |
---|
560 | WRITE_UVLC(rpsList->getNumberOfReferencePictureSets(), "num_short_term_ref_pic_sets" ); |
---|
561 | for(Int i=0; i < rpsList->getNumberOfReferencePictureSets(); i++) |
---|
562 | { |
---|
563 | rps = rpsList->getReferencePictureSet(i); |
---|
564 | codeShortTermRefPicSet(pcSPS,rps); |
---|
565 | } |
---|
566 | WRITE_FLAG( pcSPS->getLongTermRefsPresent() ? 1 : 0, "long_term_ref_pics_present_flag" ); |
---|
567 | // AMVP mode for each depth |
---|
568 | for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++) |
---|
569 | { |
---|
570 | xWriteFlag( pcSPS->getAMVPMode(i) ? 1 : 0); |
---|
571 | } |
---|
572 | |
---|
573 | Int tilesOrEntropyCodingSyncIdc = 0; |
---|
574 | if ( pcSPS->getNumColumnsMinus1() > 0 || pcSPS->getNumRowsMinus1() > 0) |
---|
575 | { |
---|
576 | tilesOrEntropyCodingSyncIdc = 1; |
---|
577 | } |
---|
578 | else if ( pcSPS->getNumSubstreams() > 1 ) |
---|
579 | { |
---|
580 | tilesOrEntropyCodingSyncIdc = 2; |
---|
581 | } |
---|
582 | pcSPS->setTilesOrEntropyCodingSyncIdc( tilesOrEntropyCodingSyncIdc ); |
---|
583 | WRITE_CODE(tilesOrEntropyCodingSyncIdc, 2, "tiles_or_entropy_coding_sync_idc"); |
---|
584 | |
---|
585 | if(tilesOrEntropyCodingSyncIdc == 1) |
---|
586 | { |
---|
587 | WRITE_UVLC( pcSPS->getNumColumnsMinus1(), "num_tile_columns_minus1" ); |
---|
588 | WRITE_UVLC( pcSPS->getNumRowsMinus1(), "num_tile_rows_minus1" ); |
---|
589 | WRITE_FLAG( pcSPS->getUniformSpacingIdr(), "uniform_spacing_flag" ); |
---|
590 | |
---|
591 | if( pcSPS->getUniformSpacingIdr()==0 ) |
---|
592 | { |
---|
593 | for(UInt i=0; i<pcSPS->getNumColumnsMinus1(); i++) |
---|
594 | { |
---|
595 | WRITE_UVLC( pcSPS->getColumnWidth(i), "column_width" ); |
---|
596 | } |
---|
597 | for(UInt i=0; i<pcSPS->getNumRowsMinus1(); i++) |
---|
598 | { |
---|
599 | WRITE_UVLC( pcSPS->getRowHeight(i), "row_height" ); |
---|
600 | } |
---|
601 | } |
---|
602 | |
---|
603 | if( pcSPS->getNumColumnsMinus1() !=0 || pcSPS->getNumRowsMinus1() != 0) |
---|
604 | { |
---|
605 | WRITE_FLAG( pcSPS->getLFCrossTileBoundaryFlag()?1 : 0, "loop_filter_across_tile_flag"); |
---|
606 | } |
---|
607 | } |
---|
608 | WRITE_FLAG( 1, "sps_extension_flag" ); |
---|
609 | #if !QC_MVHEVC_B0046 |
---|
610 | WRITE_FLAG( (pcSPS->getNumberOfUsableInterViewRefs() > 0) ? 1 : 0, "interview_refs_present_flag" ); |
---|
611 | if( pcSPS->getNumberOfUsableInterViewRefs() > 0 ) |
---|
612 | { |
---|
613 | WRITE_UVLC( pcSPS->getNumberOfUsableInterViewRefs() - 1, "num_usable_interview_refs_minus1" ); |
---|
614 | |
---|
615 | Int prev = 0; |
---|
616 | for( Int j = 0 ; j < pcSPS->getNumberOfUsableInterViewRefs(); j++ ) |
---|
617 | { |
---|
618 | WRITE_UVLC( prev - pcSPS->getUsableInterViewRef( j ) - 1, "delta_usable_interview_ref_minus1" ); |
---|
619 | prev = pcSPS->getUsableInterViewRef( j ); |
---|
620 | } |
---|
621 | } |
---|
622 | |
---|
623 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
624 | WRITE_FLAG( pcSPS->getUseDMM(), "enable_dmm_flag" ); |
---|
625 | #endif |
---|
626 | |
---|
627 | #if HHI_MPI |
---|
628 | if( bIsDepth ) |
---|
629 | { |
---|
630 | WRITE_FLAG( pcSPS->getUseMVI() ? 1 : 0, "use_mvi_flag" ); |
---|
631 | } |
---|
632 | #endif |
---|
633 | |
---|
634 | #if H3D_QTL |
---|
635 | if( bIsDepth ) |
---|
636 | { |
---|
637 | WRITE_FLAG( pcSPS->getUseQTLPC() ? 1 : 0, "use_qtlpc_flag"); |
---|
638 | } |
---|
639 | #endif |
---|
640 | |
---|
641 | #if RWTH_SDC_DLT_B0036 |
---|
642 | if( bIsDepth ) |
---|
643 | { |
---|
644 | WRITE_FLAG( pcSPS->getUseDLT() ? 1 : 0, "use_dlt_flag" ); |
---|
645 | if( pcSPS->getUseDLT() ) |
---|
646 | { |
---|
647 | // code mapping |
---|
648 | xWriteUvlc ( pcSPS->getNumDepthValues() ); |
---|
649 | for(UInt i=0; i<pcSPS->getNumDepthValues(); i++) |
---|
650 | { |
---|
651 | xWriteUvlc( pcSPS->idx2DepthValue(i) ); |
---|
652 | } |
---|
653 | } |
---|
654 | } |
---|
655 | #endif |
---|
656 | |
---|
657 | if( pcSPS->getViewId() || pcSPS->isDepth() ) |
---|
658 | { |
---|
659 | WRITE_FLAG( 0, "base_view_flag" ); |
---|
660 | if( pcSPS->isDepth() ) |
---|
661 | { |
---|
662 | WRITE_FLAG( 1, "depth_flag" ); |
---|
663 | WRITE_UVLC( pcSPS->getViewId(), "view_id" ); |
---|
664 | WRITE_SVLC( pcSPS->getViewOrderIdx(), "view_order_idx" ); |
---|
665 | #if FCO_FIX_SPS_CHANGE |
---|
666 | if ( pcSPS->getViewId() ) |
---|
667 | { |
---|
668 | WRITE_UVLC( pcSPS->getCamParPrecision(), "camera_parameter_precision" ); |
---|
669 | WRITE_FLAG( pcSPS->hasCamParInSliceHeader() ? 1 : 0, "camera_parameter_in_slice_header" ); |
---|
670 | if( !pcSPS->hasCamParInSliceHeader() ) |
---|
671 | { |
---|
672 | for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ ) |
---|
673 | { |
---|
674 | WRITE_SVLC( pcSPS->getCodedScale ()[ uiId ], "coded_scale" ); |
---|
675 | WRITE_SVLC( pcSPS->getCodedOffset ()[ uiId ], "coded_offset" ); |
---|
676 | WRITE_SVLC( pcSPS->getInvCodedScale ()[ uiId ] + pcSPS->getCodedScale ()[ uiId ], "inverse_coded_scale_plus_coded_scale" ); |
---|
677 | WRITE_SVLC( pcSPS->getInvCodedOffset()[ uiId ] + pcSPS->getCodedOffset()[ uiId ], "inverse_coded_offset_plus_coded_offset" ); |
---|
678 | } |
---|
679 | } |
---|
680 | } |
---|
681 | #endif |
---|
682 | } |
---|
683 | else |
---|
684 | { |
---|
685 | WRITE_FLAG( 0, "depth_flag" ); |
---|
686 | WRITE_UVLC( pcSPS->getViewId() - 1, "view_id_minus1" ); |
---|
687 | WRITE_SVLC( pcSPS->getViewOrderIdx(), "view_order_idx" ); |
---|
688 | WRITE_UVLC( pcSPS->getCamParPrecision(), "camera_parameter_precision" ); |
---|
689 | WRITE_FLAG( pcSPS->hasCamParInSliceHeader() ? 1 : 0, "camera_parameter_in_slice_header" ); |
---|
690 | if( !pcSPS->hasCamParInSliceHeader() ) |
---|
691 | { |
---|
692 | for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ ) |
---|
693 | { |
---|
694 | WRITE_SVLC( pcSPS->getCodedScale ()[ uiId ], "coded_scale" ); |
---|
695 | WRITE_SVLC( pcSPS->getCodedOffset ()[ uiId ], "coded_offset" ); |
---|
696 | WRITE_SVLC( pcSPS->getInvCodedScale ()[ uiId ] + pcSPS->getCodedScale ()[ uiId ], "inverse_coded_scale_plus_coded_scale" ); |
---|
697 | WRITE_SVLC( pcSPS->getInvCodedOffset()[ uiId ] + pcSPS->getCodedOffset()[ uiId ], "inverse_coded_offset_plus_coded_offset" ); |
---|
698 | } |
---|
699 | } |
---|
700 | #if DEPTH_MAP_GENERATION |
---|
701 | WRITE_UVLC( pcSPS->getPredDepthMapGeneration(), "Pdm_generation" ); |
---|
702 | if( pcSPS->getPredDepthMapGeneration() ) |
---|
703 | { |
---|
704 | WRITE_UVLC( pcSPS->getPdmPrecision(), "Pdm_precision" ); |
---|
705 | for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ ) |
---|
706 | { |
---|
707 | WRITE_SVLC( pcSPS->getPdmScaleNomDelta()[ uiId ], "Pdm_scale_nom_delta" ); |
---|
708 | WRITE_SVLC( pcSPS->getPdmOffset ()[ uiId ], "Pdm_offset" ); |
---|
709 | } |
---|
710 | #if H3D_IVMP |
---|
711 | WRITE_UVLC( pcSPS->getMultiviewMvPredMode(), "multi_view_mv_pred_mode" ); |
---|
712 | #endif |
---|
713 | #if H3D_IVRP & !QC_ARP_D0177 |
---|
714 | WRITE_FLAG ( pcSPS->getMultiviewResPredMode(), "multi_view_residual_pred_mode" ); |
---|
715 | #endif |
---|
716 | } |
---|
717 | #endif |
---|
718 | #if QC_ARP_D0177 |
---|
719 | WRITE_FLAG( pcSPS->getUseAdvRP () ? 1 : 0, "advanced_residual_pred_flag" ); |
---|
720 | #endif |
---|
721 | } |
---|
722 | } |
---|
723 | else |
---|
724 | { |
---|
725 | WRITE_FLAG( 1, "base_view_flag" ); |
---|
726 | } |
---|
727 | WRITE_FLAG( 0, "sps_extension2_flag" ); |
---|
728 | #endif |
---|
729 | } |
---|
730 | |
---|
731 | Void TEncCavlc::writeTileMarker( UInt uiTileIdx, UInt uiBitsUsed ) |
---|
732 | { |
---|
733 | xWriteCode( uiTileIdx, uiBitsUsed ); |
---|
734 | } |
---|
735 | |
---|
736 | Void TEncCavlc::codeSliceHeader ( TComSlice* pcSlice ) |
---|
737 | { |
---|
738 | #if ENC_DEC_TRACE |
---|
739 | xTraceSliceHeader (pcSlice); |
---|
740 | #endif |
---|
741 | |
---|
742 | // if( nal_ref_idc != 0 ) |
---|
743 | // dec_ref_pic_marking( ) |
---|
744 | // if( entropy_coding_mode_flag && slice_type != I) |
---|
745 | // cabac_init_idc |
---|
746 | // first_slice_in_pic_flag |
---|
747 | // if( first_slice_in_pic_flag == 0 ) |
---|
748 | // slice_address |
---|
749 | //calculate number of bits required for slice address |
---|
750 | Int maxAddrOuter = pcSlice->getPic()->getNumCUsInFrame(); |
---|
751 | Int reqBitsOuter = 0; |
---|
752 | while(maxAddrOuter>(1<<reqBitsOuter)) |
---|
753 | { |
---|
754 | reqBitsOuter++; |
---|
755 | } |
---|
756 | Int maxAddrInner = pcSlice->getPic()->getNumPartInCU()>>(2); |
---|
757 | maxAddrInner = (1<<(pcSlice->getPPS()->getSliceGranularity()<<1)); |
---|
758 | Int reqBitsInner = 0; |
---|
759 | |
---|
760 | while(maxAddrInner>(1<<reqBitsInner)) |
---|
761 | { |
---|
762 | reqBitsInner++; |
---|
763 | } |
---|
764 | Int lCUAddress; |
---|
765 | Int innerAddress; |
---|
766 | if (pcSlice->isNextSlice()) |
---|
767 | { |
---|
768 | // Calculate slice address |
---|
769 | lCUAddress = (pcSlice->getSliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU()); |
---|
770 | innerAddress = (pcSlice->getSliceCurStartCUAddr()%(pcSlice->getPic()->getNumPartInCU()))>>((pcSlice->getSPS()->getMaxCUDepth()-pcSlice->getPPS()->getSliceGranularity())<<1); |
---|
771 | } |
---|
772 | else |
---|
773 | { |
---|
774 | // Calculate slice address |
---|
775 | lCUAddress = (pcSlice->getEntropySliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU()); |
---|
776 | innerAddress = (pcSlice->getEntropySliceCurStartCUAddr()%(pcSlice->getPic()->getNumPartInCU()))>>((pcSlice->getSPS()->getMaxCUDepth()-pcSlice->getPPS()->getSliceGranularity())<<1); |
---|
777 | |
---|
778 | } |
---|
779 | //write slice address |
---|
780 | Int address = (pcSlice->getPic()->getPicSym()->getCUOrderMap(lCUAddress) << reqBitsInner) + innerAddress; |
---|
781 | WRITE_FLAG( address==0, "first_slice_in_pic_flag" ); |
---|
782 | |
---|
783 | #if LGE_ILLUCOMP_B0045 |
---|
784 | // IC flag is on only first_slice_in_pic |
---|
785 | if (address==0) |
---|
786 | { |
---|
787 | if( pcSlice->getSPS()->getViewId() |
---|
788 | #if !LGE_ILLUCOMP_DEPTH_C0046 |
---|
789 | && !pcSlice->getIsDepth() |
---|
790 | #endif |
---|
791 | ) |
---|
792 | { |
---|
793 | WRITE_FLAG( pcSlice->getApplyIC() ? 1 : 0, "applying IC flag" ); |
---|
794 | } |
---|
795 | } |
---|
796 | #endif |
---|
797 | |
---|
798 | if(address>0) |
---|
799 | { |
---|
800 | WRITE_CODE( address, reqBitsOuter+reqBitsInner, "slice_address" ); |
---|
801 | } |
---|
802 | |
---|
803 | WRITE_UVLC( pcSlice->getSliceType(), "slice_type" ); |
---|
804 | Bool bEntropySlice = (!pcSlice->isNextSlice()); |
---|
805 | WRITE_FLAG( bEntropySlice ? 1 : 0, "lightweight_slice_flag" ); |
---|
806 | |
---|
807 | if (!bEntropySlice) |
---|
808 | { |
---|
809 | #if QC_MVHEVC_B0046 |
---|
810 | WRITE_UVLC( 0, "pic_parameter_set_id" ); |
---|
811 | #else |
---|
812 | WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "pic_parameter_set_id" ); |
---|
813 | #endif |
---|
814 | if( pcSlice->getPPS()->getOutputFlagPresentFlag() ) |
---|
815 | { |
---|
816 | WRITE_FLAG( pcSlice->getPicOutputFlag() ? 1 : 0, "pic_output_flag" ); |
---|
817 | } |
---|
818 | #if QC_REM_IDV_B0046 |
---|
819 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_IDR && pcSlice->getViewId() == 0) |
---|
820 | #else |
---|
821 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_IDR) |
---|
822 | #endif |
---|
823 | { |
---|
824 | WRITE_UVLC( 0, "idr_pic_id" ); |
---|
825 | WRITE_FLAG( 0, "no_output_of_prior_pics_flag" ); |
---|
826 | } |
---|
827 | else |
---|
828 | { |
---|
829 | WRITE_CODE( (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC()), pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb"); |
---|
830 | #if QC_REM_IDV_B0046 |
---|
831 | if( pcSlice->getPOC() == 0 && !(pcSlice->getSPS()->getViewId() && (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))) |
---|
832 | #else |
---|
833 | if( pcSlice->getPOC() == 0 && pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDV ) |
---|
834 | #endif |
---|
835 | { |
---|
836 | TComReferencePictureSet* rps = pcSlice->getRPS(); |
---|
837 | if(pcSlice->getRPSidx() < 0) |
---|
838 | { |
---|
839 | WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag"); |
---|
840 | codeShortTermRefPicSet(pcSlice->getSPS(), rps); |
---|
841 | } |
---|
842 | else |
---|
843 | { |
---|
844 | WRITE_FLAG( 1, "short_term_ref_pic_set_sps_flag"); |
---|
845 | WRITE_UVLC( pcSlice->getRPSidx(), "short_term_ref_pic_set_idx" ); |
---|
846 | } |
---|
847 | if(pcSlice->getSPS()->getLongTermRefsPresent()) |
---|
848 | { |
---|
849 | WRITE_UVLC( rps->getNumberOfLongtermPictures(), "num_long_term_pics"); |
---|
850 | Int maxPocLsb = 1<<pcSlice->getSPS()->getBitsForPOC(); |
---|
851 | Int prev = 0; |
---|
852 | Int prevDeltaPocLt=0; |
---|
853 | Int currDeltaPocLt=0; |
---|
854 | for(Int i=rps->getNumberOfPictures()-1 ; i > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; i--) |
---|
855 | { |
---|
856 | WRITE_UVLC((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb, "delta_poc_lsb_lt"); |
---|
857 | |
---|
858 | currDeltaPocLt=((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb)+prevDeltaPocLt; |
---|
859 | |
---|
860 | Int deltaMsbCycle=0; |
---|
861 | if( (i==(rps->getNumberOfPictures()-1)) ) |
---|
862 | { |
---|
863 | deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1; |
---|
864 | } |
---|
865 | else if( prevDeltaPocLt!=currDeltaPocLt ) |
---|
866 | { |
---|
867 | deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1; |
---|
868 | if( ((prevDeltaPocLt==maxPocLsb-1) && (currDeltaPocLt==maxPocLsb+1)) || ((prevDeltaPocLt==maxPocLsb-2) && (currDeltaPocLt==maxPocLsb))) |
---|
869 | { |
---|
870 | deltaMsbCycle=deltaMsbCycle-1; |
---|
871 | } |
---|
872 | } |
---|
873 | else |
---|
874 | { |
---|
875 | deltaMsbCycle=((rps->getDeltaPOC(i+1)-rps->getDeltaPOC(i))/maxPocLsb)-1; |
---|
876 | } |
---|
877 | |
---|
878 | if(deltaMsbCycle>=0) |
---|
879 | { |
---|
880 | WRITE_FLAG( 1, "delta_poc_msb_present_flag"); |
---|
881 | WRITE_UVLC(deltaMsbCycle, "delta_poc_msb_cycle_lt_minus1"); |
---|
882 | } |
---|
883 | else |
---|
884 | { |
---|
885 | WRITE_FLAG( 0, "delta_poc_msb_present_flag"); |
---|
886 | } |
---|
887 | prevDeltaPocLt=currDeltaPocLt; |
---|
888 | prev = rps->getDeltaPOC(i); |
---|
889 | WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag"); |
---|
890 | } |
---|
891 | } |
---|
892 | } |
---|
893 | if( pcSlice->getPOC() != 0 ) |
---|
894 | { |
---|
895 | TComReferencePictureSet* rps = pcSlice->getRPS(); |
---|
896 | if(pcSlice->getRPSidx() < 0) |
---|
897 | { |
---|
898 | WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag"); |
---|
899 | codeShortTermRefPicSet(pcSlice->getSPS(), rps); |
---|
900 | } |
---|
901 | else |
---|
902 | { |
---|
903 | WRITE_FLAG( 1, "short_term_ref_pic_set_sps_flag"); |
---|
904 | WRITE_UVLC( pcSlice->getRPSidx(), "short_term_ref_pic_set_idx" ); |
---|
905 | } |
---|
906 | if(pcSlice->getSPS()->getLongTermRefsPresent()) |
---|
907 | { |
---|
908 | WRITE_UVLC( rps->getNumberOfLongtermPictures(), "num_long_term_pics"); |
---|
909 | Int maxPocLsb = 1<<pcSlice->getSPS()->getBitsForPOC(); |
---|
910 | Int prev = 0; |
---|
911 | Int prevDeltaPocLt=0; |
---|
912 | Int currDeltaPocLt=0; |
---|
913 | for(Int i=rps->getNumberOfPictures()-1 ; i > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; i--) |
---|
914 | { |
---|
915 | WRITE_UVLC((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb, "delta_poc_lsb_lt"); |
---|
916 | |
---|
917 | currDeltaPocLt=((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb)+prevDeltaPocLt; |
---|
918 | |
---|
919 | Int deltaMsbCycle=0; |
---|
920 | if( (i==(rps->getNumberOfPictures()-1)) ) |
---|
921 | { |
---|
922 | deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1; |
---|
923 | } |
---|
924 | else if( prevDeltaPocLt!=currDeltaPocLt ) |
---|
925 | { |
---|
926 | deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1; |
---|
927 | if( ((prevDeltaPocLt==maxPocLsb-1) && (currDeltaPocLt==maxPocLsb+1)) || ((prevDeltaPocLt==maxPocLsb-2) && (currDeltaPocLt==maxPocLsb))) |
---|
928 | { |
---|
929 | deltaMsbCycle=deltaMsbCycle-1; |
---|
930 | } |
---|
931 | } |
---|
932 | else |
---|
933 | { |
---|
934 | deltaMsbCycle=((rps->getDeltaPOC(i+1)-rps->getDeltaPOC(i))/maxPocLsb)-1; |
---|
935 | } |
---|
936 | |
---|
937 | if(deltaMsbCycle>=0) |
---|
938 | { |
---|
939 | WRITE_FLAG( 1, "delta_poc_msb_present_flag"); |
---|
940 | WRITE_UVLC(deltaMsbCycle, "delta_poc_msb_cycle_lt_minus1"); |
---|
941 | } |
---|
942 | else |
---|
943 | { |
---|
944 | WRITE_FLAG( 0, "delta_poc_msb_present_flag"); |
---|
945 | } |
---|
946 | prevDeltaPocLt=currDeltaPocLt; |
---|
947 | prev = rps->getDeltaPOC(i); |
---|
948 | WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag"); |
---|
949 | } |
---|
950 | } |
---|
951 | } |
---|
952 | } |
---|
953 | |
---|
954 | if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF()|| pcSlice->getSPS()->getScalingListFlag() || pcSlice->getSPS()->getUseDF()) |
---|
955 | { |
---|
956 | if (pcSlice->getSPS()->getUseALF()) |
---|
957 | { |
---|
958 | WRITE_FLAG( pcSlice->getAlfEnabledFlag(), "ALF on/off flag in slice header" ); |
---|
959 | } |
---|
960 | if (pcSlice->getSPS()->getUseSAO()) |
---|
961 | { |
---|
962 | WRITE_FLAG( pcSlice->getSaoInterleavingFlag(), "SAO interleaving flag" ); |
---|
963 | assert (pcSlice->getSaoEnabledFlag() == pcSlice->getAPS()->getSaoEnabled()); |
---|
964 | WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "SAO on/off flag in slice header" ); |
---|
965 | if (pcSlice->getSaoInterleavingFlag()&&pcSlice->getSaoEnabledFlag() ) |
---|
966 | { |
---|
967 | WRITE_FLAG( pcSlice->getAPS()->getSaoParam()->bSaoFlag[1], "SAO on/off flag for Cb in slice header" ); |
---|
968 | WRITE_FLAG( pcSlice->getAPS()->getSaoParam()->bSaoFlag[2], "SAO on/off flag for Cr in slice header" ); |
---|
969 | } |
---|
970 | } |
---|
971 | WRITE_UVLC( pcSlice->getAPS()->getAPSID(), "aps_id"); |
---|
972 | } |
---|
973 | |
---|
974 | // we always set num_ref_idx_active_override_flag equal to one. this might be done in a more intelligent way |
---|
975 | if (!pcSlice->isIntra()) |
---|
976 | { |
---|
977 | WRITE_FLAG( 1 , "num_ref_idx_active_override_flag"); |
---|
978 | WRITE_CODE( pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) - 1, 3, "num_ref_idx_l0_active_minus1" ); |
---|
979 | } |
---|
980 | else |
---|
981 | { |
---|
982 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, 0); |
---|
983 | } |
---|
984 | if (pcSlice->isInterB()) |
---|
985 | { |
---|
986 | WRITE_CODE( pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) - 1, 3, "num_ref_idx_l1_active_minus1" ); |
---|
987 | } |
---|
988 | else |
---|
989 | { |
---|
990 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
991 | } |
---|
992 | if( pcSlice->getSPS()->getListsModificationPresentFlag() ) |
---|
993 | { |
---|
994 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
995 | if( !pcSlice->isIntra() ) |
---|
996 | { |
---|
997 | WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0() ? 1 : 0, "ref_pic_list_modification_flag_l0" ); |
---|
998 | if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0()) |
---|
999 | { |
---|
1000 | Int NumPocTotalCurr = pcSlice->getNumPocTotalCurrMvc(); |
---|
1001 | if (NumPocTotalCurr > 1) |
---|
1002 | { |
---|
1003 | Int length = 1; |
---|
1004 | NumPocTotalCurr --; |
---|
1005 | while ( NumPocTotalCurr >>= 1) |
---|
1006 | { |
---|
1007 | length ++; |
---|
1008 | } |
---|
1009 | for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++) |
---|
1010 | { |
---|
1011 | WRITE_CODE( refPicListModification->getRefPicSetIdxL0(i), length, "list_entry_l0"); |
---|
1012 | } |
---|
1013 | } |
---|
1014 | } |
---|
1015 | } |
---|
1016 | if(pcSlice->isInterB()) |
---|
1017 | { |
---|
1018 | WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1() ? 1 : 0, "ref_pic_list_modification_flag_l1" ); |
---|
1019 | if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1()) |
---|
1020 | { |
---|
1021 | Int NumPocTotalCurr = pcSlice->getNumPocTotalCurrMvc(); |
---|
1022 | if ( NumPocTotalCurr > 1 ) |
---|
1023 | { |
---|
1024 | Int length = 1; |
---|
1025 | NumPocTotalCurr --; |
---|
1026 | while ( NumPocTotalCurr >>= 1) |
---|
1027 | { |
---|
1028 | length ++; |
---|
1029 | } |
---|
1030 | for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++) |
---|
1031 | { |
---|
1032 | WRITE_CODE( refPicListModification->getRefPicSetIdxL1(i), length, "list_entry_l1"); |
---|
1033 | } |
---|
1034 | } |
---|
1035 | } |
---|
1036 | } |
---|
1037 | } |
---|
1038 | } |
---|
1039 | // ref_pic_list_combination( ) |
---|
1040 | // maybe move to own function? |
---|
1041 | if (pcSlice->isInterB()) |
---|
1042 | { |
---|
1043 | WRITE_FLAG(pcSlice->getRefPicListCombinationFlag() ? 1 : 0, "ref_pic_list_combination_flag" ); |
---|
1044 | if(pcSlice->getRefPicListCombinationFlag()) |
---|
1045 | { |
---|
1046 | WRITE_UVLC( pcSlice->getNumRefIdx(REF_PIC_LIST_C) - 1, "num_ref_idx lc_active_minus1"); |
---|
1047 | |
---|
1048 | if( pcSlice->getSPS()->getListsModificationPresentFlag() ) |
---|
1049 | { |
---|
1050 | WRITE_FLAG( pcSlice->getRefPicListModificationFlagLC() ? 1 : 0, "ref_pic_list_modification_flag_lc" ); |
---|
1051 | if(pcSlice->getRefPicListModificationFlagLC()) |
---|
1052 | { |
---|
1053 | for (UInt i=0;i<pcSlice->getNumRefIdx(REF_PIC_LIST_C);i++) |
---|
1054 | { |
---|
1055 | WRITE_FLAG( pcSlice->getListIdFromIdxOfLC(i), "pic_from_list_0_flag" ); |
---|
1056 | if (((pcSlice->getListIdFromIdxOfLC(i)==REF_PIC_LIST_0) && pcSlice->getNumRefIdx( REF_PIC_LIST_0 )>1 ) || ((pcSlice->getListIdFromIdxOfLC(i)==REF_PIC_LIST_1) && pcSlice->getNumRefIdx( REF_PIC_LIST_1 )>1 ) ) |
---|
1057 | { |
---|
1058 | WRITE_UVLC( pcSlice->getRefIdxFromIdxOfLC(i), "ref_idx_list_curr" ); |
---|
1059 | } |
---|
1060 | } |
---|
1061 | } |
---|
1062 | } |
---|
1063 | } |
---|
1064 | } |
---|
1065 | |
---|
1066 | if (pcSlice->isInterB()) |
---|
1067 | { |
---|
1068 | WRITE_FLAG( pcSlice->getMvdL1ZeroFlag() ? 1 : 0, "mvd_l1_zero_flag"); |
---|
1069 | } |
---|
1070 | |
---|
1071 | if(pcSlice->getPPS()->getEntropyCodingMode() && !pcSlice->isIntra()) |
---|
1072 | { |
---|
1073 | #if CABAC_INIT_FLAG |
---|
1074 | if (!pcSlice->isIntra() && pcSlice->getPPS()->getCabacInitPresentFlag()) |
---|
1075 | { |
---|
1076 | SliceType sliceType = pcSlice->getSliceType(); |
---|
1077 | Int encCABACTableIdx = pcSlice->getPPS()->getEncCABACTableIdx(); |
---|
1078 | Bool encCabacInitFlag = (sliceType!=encCABACTableIdx && encCABACTableIdx!=0) ? true : false; |
---|
1079 | pcSlice->setCabacInitFlag( encCabacInitFlag ); |
---|
1080 | WRITE_FLAG( encCabacInitFlag?1:0, "cabac_init_flag" ); |
---|
1081 | } |
---|
1082 | #else |
---|
1083 | WRITE_UVLC(pcSlice->getCABACinitIDC(), "cabac_init_idc"); |
---|
1084 | #endif |
---|
1085 | } |
---|
1086 | |
---|
1087 | // if( !lightweight_slice_flag ) { |
---|
1088 | if (!bEntropySlice) |
---|
1089 | { |
---|
1090 | Int iCode = pcSlice->getSliceQp() - ( pcSlice->getPPS()->getPicInitQPMinus26() + 26 ); |
---|
1091 | WRITE_SVLC( iCode, "slice_qp_delta" ); |
---|
1092 | if (pcSlice->getPPS()->getDeblockingFilterControlPresent()) |
---|
1093 | { |
---|
1094 | if ( pcSlice->getSPS()->getUseDF() ) |
---|
1095 | { |
---|
1096 | WRITE_FLAG(pcSlice->getInheritDblParamFromAPS(), "inherit_dbl_param_from_APS_flag"); |
---|
1097 | } |
---|
1098 | if (!pcSlice->getInheritDblParamFromAPS()) |
---|
1099 | { |
---|
1100 | WRITE_FLAG(pcSlice->getLoopFilterDisable(), "loop_filter_disable"); // should be an IDC |
---|
1101 | if(!pcSlice->getLoopFilterDisable()) |
---|
1102 | { |
---|
1103 | WRITE_SVLC (pcSlice->getLoopFilterBetaOffset(), "beta_offset_div2"); |
---|
1104 | WRITE_SVLC (pcSlice->getLoopFilterTcOffset(), "tc_offset_div2"); |
---|
1105 | } |
---|
1106 | } |
---|
1107 | } |
---|
1108 | if ( pcSlice->getSliceType() == B_SLICE ) |
---|
1109 | { |
---|
1110 | WRITE_FLAG( pcSlice->getColDir(), "collocated_from_l0_flag" ); |
---|
1111 | } |
---|
1112 | |
---|
1113 | #if COLLOCATED_REF_IDX |
---|
1114 | if ( pcSlice->getSliceType() != I_SLICE && |
---|
1115 | ((pcSlice->getColDir()==0 && pcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)|| |
---|
1116 | (pcSlice->getColDir()==1 && pcSlice->getNumRefIdx(REF_PIC_LIST_1)>1))) |
---|
1117 | { |
---|
1118 | WRITE_UVLC( pcSlice->getColRefIdx(), "collocated_ref_idx" ); |
---|
1119 | } |
---|
1120 | #endif |
---|
1121 | |
---|
1122 | #if FIX_LGE_WP_FOR_3D_C0223 |
---|
1123 | if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPredIdc() && pcSlice->getSliceType()==B_SLICE) ) |
---|
1124 | #else |
---|
1125 | if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE) ) |
---|
1126 | #endif |
---|
1127 | { |
---|
1128 | xCodePredWeightTable( pcSlice ); |
---|
1129 | } |
---|
1130 | } |
---|
1131 | |
---|
1132 | // !!!! sytnax elements not in the WD !!!! |
---|
1133 | if (!bEntropySlice) |
---|
1134 | { |
---|
1135 | if( pcSlice->getSPS()->hasCamParInSliceHeader() ) |
---|
1136 | { |
---|
1137 | for( UInt uiId = 0; uiId < pcSlice->getSPS()->getViewId(); uiId++ ) |
---|
1138 | { |
---|
1139 | WRITE_SVLC( pcSlice->getCodedScale ()[ uiId ], "coded_scale" ); |
---|
1140 | WRITE_SVLC( pcSlice->getCodedOffset ()[ uiId ], "coded_offset" ); |
---|
1141 | WRITE_SVLC( pcSlice->getInvCodedScale ()[ uiId ] + pcSlice->getCodedScale ()[ uiId ], "inverse_coded_scale_plus_coded_scale" ); |
---|
1142 | WRITE_SVLC( pcSlice->getInvCodedOffset()[ uiId ] + pcSlice->getCodedOffset()[ uiId ], "inverse_coded_offset_plus_coded_offset" ); |
---|
1143 | } |
---|
1144 | } |
---|
1145 | } |
---|
1146 | |
---|
1147 | #if ( HHI_MPI || H3D_IVMP ) |
---|
1148 | #if ( HHI_MPI && H3D_IVMP ) |
---|
1149 | const int iExtraMergeCandidates = ( pcSlice->getSPS()->getUseMVI() || pcSlice->getSPS()->getMultiviewMvPredMode() ) ? 1 : 0; |
---|
1150 | #elif HHI_MPI |
---|
1151 | const int iExtraMergeCandidates = pcSlice->getSPS()->getUseMVI() ? 1 : 0; |
---|
1152 | #elif MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137 |
---|
1153 | const int iExtraMergeCandidates = ( pcSlice->getIsDepth() || pcSlice->getSPS()->getMultiviewMvPredMode() ) ? 1 : 0; |
---|
1154 | #else |
---|
1155 | const int iExtraMergeCandidates = pcSlice->getSPS()->getMultiviewMvPredMode() ? 1 : 0; |
---|
1156 | #endif |
---|
1157 | assert(pcSlice->getMaxNumMergeCand()<=(MRG_MAX_NUM_CANDS_SIGNALED+iExtraMergeCandidates)); |
---|
1158 | assert(MRG_MAX_NUM_CANDS_SIGNALED<=MRG_MAX_NUM_CANDS); |
---|
1159 | WRITE_UVLC(MRG_MAX_NUM_CANDS + iExtraMergeCandidates - pcSlice->getMaxNumMergeCand(), "maxNumMergeCand"); |
---|
1160 | #else |
---|
1161 | assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS_SIGNALED); |
---|
1162 | assert(MRG_MAX_NUM_CANDS_SIGNALED<=MRG_MAX_NUM_CANDS); |
---|
1163 | WRITE_UVLC(MRG_MAX_NUM_CANDS - pcSlice->getMaxNumMergeCand(), "maxNumMergeCand"); |
---|
1164 | #endif |
---|
1165 | } |
---|
1166 | |
---|
1167 | |
---|
1168 | Void TEncCavlc::codeTileMarkerFlag(TComSlice* pcSlice) |
---|
1169 | { |
---|
1170 | Bool bEntropySlice = (!pcSlice->isNextSlice()); |
---|
1171 | if (!bEntropySlice) |
---|
1172 | { |
---|
1173 | xWriteFlag (pcSlice->getTileMarkerFlag() ? 1 : 0 ); |
---|
1174 | } |
---|
1175 | } |
---|
1176 | |
---|
1177 | /** |
---|
1178 | - write wavefront substreams sizes for the slice header. |
---|
1179 | . |
---|
1180 | \param pcSlice Where we find the substream size information. |
---|
1181 | */ |
---|
1182 | Void TEncCavlc::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
1183 | { |
---|
1184 | Int tilesOrEntropyCodingSyncIdc = pSlice->getSPS()->getTilesOrEntropyCodingSyncIdc(); |
---|
1185 | |
---|
1186 | if ( tilesOrEntropyCodingSyncIdc == 0 ) |
---|
1187 | { |
---|
1188 | return; |
---|
1189 | } |
---|
1190 | |
---|
1191 | UInt numEntryPointOffsets = 0, offsetLenMinus1 = 0, maxOffset = 0; |
---|
1192 | UInt *entryPointOffset = NULL; |
---|
1193 | if (tilesOrEntropyCodingSyncIdc == 1) // tiles |
---|
1194 | { |
---|
1195 | numEntryPointOffsets = pSlice->getTileLocationCount(); |
---|
1196 | entryPointOffset = new UInt[numEntryPointOffsets]; |
---|
1197 | for (Int idx=0; idx<pSlice->getTileLocationCount(); idx++) |
---|
1198 | { |
---|
1199 | if ( idx == 0 ) |
---|
1200 | { |
---|
1201 | entryPointOffset [ idx ] = pSlice->getTileLocation( 0 ); |
---|
1202 | } |
---|
1203 | else |
---|
1204 | { |
---|
1205 | entryPointOffset [ idx ] = pSlice->getTileLocation( idx ) - pSlice->getTileLocation( idx-1 ); |
---|
1206 | } |
---|
1207 | |
---|
1208 | if ( entryPointOffset[ idx ] > maxOffset ) |
---|
1209 | { |
---|
1210 | maxOffset = entryPointOffset[ idx ]; |
---|
1211 | } |
---|
1212 | } |
---|
1213 | } |
---|
1214 | else if (tilesOrEntropyCodingSyncIdc == 2) // wavefront |
---|
1215 | { |
---|
1216 | Int numZeroSubstreamsAtEndOfSlice = 0; |
---|
1217 | UInt* pSubstreamSizes = pSlice->getSubstreamSizes(); |
---|
1218 | // Find number of zero substreams at the end of slice |
---|
1219 | for (Int idx=pSlice->getPPS()->getNumSubstreams()-2; idx>=0; idx--) |
---|
1220 | { |
---|
1221 | if ( pSubstreamSizes[ idx ] == 0 ) |
---|
1222 | { |
---|
1223 | numZeroSubstreamsAtEndOfSlice++; |
---|
1224 | } |
---|
1225 | else |
---|
1226 | { |
---|
1227 | break; |
---|
1228 | } |
---|
1229 | } |
---|
1230 | numEntryPointOffsets = pSlice->getPPS()->getNumSubstreams() - 1 - numZeroSubstreamsAtEndOfSlice; |
---|
1231 | entryPointOffset = new UInt[numEntryPointOffsets]; |
---|
1232 | for (Int idx=0; idx<numEntryPointOffsets; idx++) |
---|
1233 | { |
---|
1234 | entryPointOffset[ idx ] = ( pSubstreamSizes[ idx ] >> 3 ) ; |
---|
1235 | if ( entryPointOffset[ idx ] > maxOffset ) |
---|
1236 | { |
---|
1237 | maxOffset = entryPointOffset[ idx ]; |
---|
1238 | } |
---|
1239 | } |
---|
1240 | } |
---|
1241 | |
---|
1242 | maxOffset += ((m_pcBitIf->getNumberOfWrittenBits() + 16) >> 3) + 8 + 2; // allowing for NALU header, slice header, bytes added for "offset_len_minus1" and "num_entry_point_offsets" |
---|
1243 | |
---|
1244 | // Determine number of bits "offsetLenMinus1+1" required for entry point information |
---|
1245 | offsetLenMinus1 = 0; |
---|
1246 | while (1) |
---|
1247 | { |
---|
1248 | if (maxOffset >= (1 << offsetLenMinus1) ) |
---|
1249 | { |
---|
1250 | offsetLenMinus1++; |
---|
1251 | if ( offsetLenMinus1 > 32 ) |
---|
1252 | { |
---|
1253 | FATAL_ERROR_0("exceeded 32-bits", -1); |
---|
1254 | } |
---|
1255 | } |
---|
1256 | else |
---|
1257 | { |
---|
1258 | break; |
---|
1259 | } |
---|
1260 | } |
---|
1261 | |
---|
1262 | WRITE_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); |
---|
1263 | if (numEntryPointOffsets>0) |
---|
1264 | { |
---|
1265 | WRITE_UVLC(offsetLenMinus1, "offset_len_minus1"); |
---|
1266 | } |
---|
1267 | |
---|
1268 | for (UInt idx=0; idx<numEntryPointOffsets; idx++) |
---|
1269 | { |
---|
1270 | if ( idx == 0 ) |
---|
1271 | { |
---|
1272 | // Adding sizes of NALU header and slice header information to entryPointOffset[ 0 ] |
---|
1273 | Int bitDistFromNALUHdrStart = m_pcBitIf->getNumberOfWrittenBits() + 16; |
---|
1274 | entryPointOffset[ idx ] += ( bitDistFromNALUHdrStart + numEntryPointOffsets*(offsetLenMinus1+1) ) >> 3; |
---|
1275 | } |
---|
1276 | WRITE_CODE(entryPointOffset[ idx ], offsetLenMinus1+1, "entry_point_offset"); |
---|
1277 | } |
---|
1278 | |
---|
1279 | delete [] entryPointOffset; |
---|
1280 | } |
---|
1281 | |
---|
1282 | Void TEncCavlc::codeTerminatingBit ( UInt uilsLast ) |
---|
1283 | { |
---|
1284 | } |
---|
1285 | |
---|
1286 | Void TEncCavlc::codeSliceFinish () |
---|
1287 | { |
---|
1288 | } |
---|
1289 | |
---|
1290 | #if H3D_IVMP |
---|
1291 | Void TEncCavlc::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Int iNum ) |
---|
1292 | #else |
---|
1293 | Void TEncCavlc::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1294 | #endif |
---|
1295 | { |
---|
1296 | assert(0); |
---|
1297 | } |
---|
1298 | |
---|
1299 | Void TEncCavlc::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1300 | { |
---|
1301 | assert(0); |
---|
1302 | } |
---|
1303 | |
---|
1304 | Void TEncCavlc::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1305 | { |
---|
1306 | assert(0); |
---|
1307 | } |
---|
1308 | |
---|
1309 | Void TEncCavlc::codeMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1310 | { |
---|
1311 | assert(0); |
---|
1312 | } |
---|
1313 | |
---|
1314 | Void TEncCavlc::codeMergeIndex ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1315 | { |
---|
1316 | assert(0); |
---|
1317 | } |
---|
1318 | |
---|
1319 | #if H3D_IVRP |
---|
1320 | Void |
---|
1321 | TEncCavlc::codeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1322 | { |
---|
1323 | assert(0); |
---|
1324 | } |
---|
1325 | #endif |
---|
1326 | #if QC_ARP_D0177 |
---|
1327 | Void TEncCavlc::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1328 | { |
---|
1329 | assert( false ); |
---|
1330 | } |
---|
1331 | #endif |
---|
1332 | Void TEncCavlc::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1333 | { |
---|
1334 | if (!m_bAlfCtrl) |
---|
1335 | { |
---|
1336 | return; |
---|
1337 | } |
---|
1338 | |
---|
1339 | if( pcCU->getDepth(uiAbsPartIdx) > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth)) |
---|
1340 | { |
---|
1341 | return; |
---|
1342 | } |
---|
1343 | |
---|
1344 | // get context function is here |
---|
1345 | UInt uiSymbol = pcCU->getAlfCtrlFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
1346 | |
---|
1347 | xWriteFlag( uiSymbol ); |
---|
1348 | } |
---|
1349 | |
---|
1350 | Void TEncCavlc::codeApsExtensionFlag () |
---|
1351 | { |
---|
1352 | WRITE_FLAG(0, "aps_extension_flag"); |
---|
1353 | } |
---|
1354 | |
---|
1355 | Void TEncCavlc::codeAlfCtrlDepth() |
---|
1356 | { |
---|
1357 | if (!m_bAlfCtrl) |
---|
1358 | { |
---|
1359 | return; |
---|
1360 | } |
---|
1361 | |
---|
1362 | UInt uiDepth = m_uiMaxAlfCtrlDepth; |
---|
1363 | |
---|
1364 | xWriteUvlc(uiDepth); |
---|
1365 | } |
---|
1366 | |
---|
1367 | Void TEncCavlc::codeInterModeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiEncMode ) |
---|
1368 | { |
---|
1369 | assert(0); |
---|
1370 | } |
---|
1371 | |
---|
1372 | Void TEncCavlc::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1373 | { |
---|
1374 | assert(0); |
---|
1375 | } |
---|
1376 | |
---|
1377 | #if LGE_ILLUCOMP_B0045 |
---|
1378 | Void TEncCavlc::codeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1379 | { |
---|
1380 | assert(0); |
---|
1381 | } |
---|
1382 | #endif |
---|
1383 | |
---|
1384 | Void TEncCavlc::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1385 | { |
---|
1386 | assert(0); |
---|
1387 | } |
---|
1388 | |
---|
1389 | Void TEncCavlc::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
1390 | { |
---|
1391 | assert(0); |
---|
1392 | } |
---|
1393 | |
---|
1394 | Void TEncCavlc::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1395 | { |
---|
1396 | assert(0); |
---|
1397 | } |
---|
1398 | |
---|
1399 | Void TEncCavlc::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1400 | { |
---|
1401 | assert(0); |
---|
1402 | } |
---|
1403 | |
---|
1404 | /** Code I_PCM information. |
---|
1405 | * \param pcCU pointer to CU |
---|
1406 | * \param uiAbsPartIdx CU index |
---|
1407 | * \param numIPCM the number of succesive IPCM blocks with the same size |
---|
1408 | * \param firstIPCMFlag |
---|
1409 | * \returns Void |
---|
1410 | */ |
---|
1411 | Void TEncCavlc::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Int numIPCM, Bool firstIPCMFlag) |
---|
1412 | { |
---|
1413 | assert(0); |
---|
1414 | } |
---|
1415 | |
---|
1416 | Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1417 | { |
---|
1418 | assert(0); |
---|
1419 | } |
---|
1420 | |
---|
1421 | Void TEncCavlc::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1422 | { |
---|
1423 | assert(0); |
---|
1424 | } |
---|
1425 | |
---|
1426 | Void TEncCavlc::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1427 | { |
---|
1428 | assert(0); |
---|
1429 | } |
---|
1430 | |
---|
1431 | Void TEncCavlc::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1432 | { |
---|
1433 | assert(0); |
---|
1434 | } |
---|
1435 | |
---|
1436 | Void TEncCavlc::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1437 | { |
---|
1438 | assert(0); |
---|
1439 | } |
---|
1440 | |
---|
1441 | Void TEncCavlc::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1442 | { |
---|
1443 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
1444 | |
---|
1445 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
1446 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
1447 | |
---|
1448 | xWriteSvlc( iDQp ); |
---|
1449 | |
---|
1450 | return; |
---|
1451 | } |
---|
1452 | |
---|
1453 | Void TEncCavlc::codeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
1454 | { |
---|
1455 | assert(0); |
---|
1456 | } |
---|
1457 | |
---|
1458 | Void TEncCavlc::codeAlfFlag( UInt uiCode ) |
---|
1459 | { |
---|
1460 | xWriteFlag( uiCode ); |
---|
1461 | } |
---|
1462 | |
---|
1463 | Void TEncCavlc::codeAlfCtrlFlag( UInt uiSymbol ) |
---|
1464 | { |
---|
1465 | xWriteFlag( uiSymbol ); |
---|
1466 | } |
---|
1467 | |
---|
1468 | Void TEncCavlc::codeAlfUvlc( UInt uiCode ) |
---|
1469 | { |
---|
1470 | xWriteUvlc( uiCode ); |
---|
1471 | } |
---|
1472 | |
---|
1473 | Void TEncCavlc::codeAlfSvlc( Int iCode ) |
---|
1474 | { |
---|
1475 | xWriteSvlc( iCode ); |
---|
1476 | } |
---|
1477 | /** Code the fixed length code (smaller than one max value) in OSALF |
---|
1478 | * \param idx: coded value |
---|
1479 | * \param maxValue: max value |
---|
1480 | */ |
---|
1481 | Void TEncCavlc::codeAlfFixedLengthIdx( UInt idx, UInt maxValue) |
---|
1482 | { |
---|
1483 | UInt length = 0; |
---|
1484 | assert(idx<=maxValue); |
---|
1485 | |
---|
1486 | UInt temp = maxValue; |
---|
1487 | for(UInt i=0; i<32; i++) |
---|
1488 | { |
---|
1489 | if(temp&0x1) |
---|
1490 | { |
---|
1491 | length = i+1; |
---|
1492 | } |
---|
1493 | temp = (temp >> 1); |
---|
1494 | } |
---|
1495 | |
---|
1496 | if(length) |
---|
1497 | { |
---|
1498 | xWriteCode( idx, length ); |
---|
1499 | } |
---|
1500 | } |
---|
1501 | |
---|
1502 | Void TEncCavlc::codeSaoFlag( UInt uiCode ) |
---|
1503 | { |
---|
1504 | xWriteFlag( uiCode ); |
---|
1505 | } |
---|
1506 | |
---|
1507 | Void TEncCavlc::codeSaoUvlc( UInt uiCode ) |
---|
1508 | { |
---|
1509 | xWriteUvlc( uiCode ); |
---|
1510 | } |
---|
1511 | |
---|
1512 | Void TEncCavlc::codeSaoSvlc( Int iCode ) |
---|
1513 | { |
---|
1514 | xWriteSvlc( iCode ); |
---|
1515 | } |
---|
1516 | /** Code SAO run. |
---|
1517 | * \param uiCode |
---|
1518 | * \param maxValue |
---|
1519 | */ |
---|
1520 | Void TEncCavlc::codeSaoRun( UInt uiCode, UInt maxValue) |
---|
1521 | { |
---|
1522 | UInt uiLength = 0; |
---|
1523 | if (!maxValue) |
---|
1524 | { |
---|
1525 | return; |
---|
1526 | } |
---|
1527 | assert(uiCode<=maxValue); |
---|
1528 | |
---|
1529 | for(UInt i=0; i<32; i++) |
---|
1530 | { |
---|
1531 | if(maxValue&0x1) |
---|
1532 | { |
---|
1533 | uiLength = i+1; |
---|
1534 | } |
---|
1535 | maxValue = (maxValue >> 1); |
---|
1536 | } |
---|
1537 | WRITE_CODE( uiCode, uiLength, "sao_run_diff"); |
---|
1538 | } |
---|
1539 | |
---|
1540 | Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, Int width, Int height, TextType eTType ) |
---|
1541 | { |
---|
1542 | // printf("error : no VLC mode support in this version\n"); |
---|
1543 | return; |
---|
1544 | } |
---|
1545 | |
---|
1546 | // ==================================================================================================================== |
---|
1547 | // Protected member functions |
---|
1548 | // ==================================================================================================================== |
---|
1549 | |
---|
1550 | Void TEncCavlc::xWriteCode ( UInt uiCode, UInt uiLength ) |
---|
1551 | { |
---|
1552 | assert ( uiLength > 0 ); |
---|
1553 | m_pcBitIf->write( uiCode, uiLength ); |
---|
1554 | } |
---|
1555 | |
---|
1556 | Void TEncCavlc::xWriteUvlc ( UInt uiCode ) |
---|
1557 | { |
---|
1558 | UInt uiLength = 1; |
---|
1559 | UInt uiTemp = ++uiCode; |
---|
1560 | |
---|
1561 | assert ( uiTemp ); |
---|
1562 | |
---|
1563 | while( 1 != uiTemp ) |
---|
1564 | { |
---|
1565 | uiTemp >>= 1; |
---|
1566 | uiLength += 2; |
---|
1567 | } |
---|
1568 | |
---|
1569 | //m_pcBitIf->write( uiCode, uiLength ); |
---|
1570 | // Take care of cases where uiLength > 32 |
---|
1571 | m_pcBitIf->write( 0, uiLength >> 1); |
---|
1572 | m_pcBitIf->write( uiCode, (uiLength+1) >> 1); |
---|
1573 | } |
---|
1574 | |
---|
1575 | Void TEncCavlc::xWriteSvlc ( Int iCode ) |
---|
1576 | { |
---|
1577 | UInt uiCode; |
---|
1578 | |
---|
1579 | uiCode = xConvertToUInt( iCode ); |
---|
1580 | xWriteUvlc( uiCode ); |
---|
1581 | } |
---|
1582 | |
---|
1583 | Void TEncCavlc::xWriteFlag( UInt uiCode ) |
---|
1584 | { |
---|
1585 | m_pcBitIf->write( uiCode, 1 ); |
---|
1586 | } |
---|
1587 | |
---|
1588 | /** Write PCM alignment bits. |
---|
1589 | * \returns Void |
---|
1590 | */ |
---|
1591 | Void TEncCavlc::xWritePCMAlignZero () |
---|
1592 | { |
---|
1593 | m_pcBitIf->writeAlignZero(); |
---|
1594 | } |
---|
1595 | |
---|
1596 | Void TEncCavlc::xWriteUnaryMaxSymbol( UInt uiSymbol, UInt uiMaxSymbol ) |
---|
1597 | { |
---|
1598 | if (uiMaxSymbol == 0) |
---|
1599 | { |
---|
1600 | return; |
---|
1601 | } |
---|
1602 | xWriteFlag( uiSymbol ? 1 : 0 ); |
---|
1603 | if ( uiSymbol == 0 ) |
---|
1604 | { |
---|
1605 | return; |
---|
1606 | } |
---|
1607 | |
---|
1608 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
1609 | |
---|
1610 | while( --uiSymbol ) |
---|
1611 | { |
---|
1612 | xWriteFlag( 1 ); |
---|
1613 | } |
---|
1614 | if( bCodeLast ) |
---|
1615 | { |
---|
1616 | xWriteFlag( 0 ); |
---|
1617 | } |
---|
1618 | return; |
---|
1619 | } |
---|
1620 | |
---|
1621 | Void TEncCavlc::xWriteExGolombLevel( UInt uiSymbol ) |
---|
1622 | { |
---|
1623 | if( uiSymbol ) |
---|
1624 | { |
---|
1625 | xWriteFlag( 1 ); |
---|
1626 | UInt uiCount = 0; |
---|
1627 | Bool bNoExGo = (uiSymbol < 13); |
---|
1628 | |
---|
1629 | while( --uiSymbol && ++uiCount < 13 ) |
---|
1630 | { |
---|
1631 | xWriteFlag( 1 ); |
---|
1632 | } |
---|
1633 | if( bNoExGo ) |
---|
1634 | { |
---|
1635 | xWriteFlag( 0 ); |
---|
1636 | } |
---|
1637 | else |
---|
1638 | { |
---|
1639 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
1640 | } |
---|
1641 | } |
---|
1642 | else |
---|
1643 | { |
---|
1644 | xWriteFlag( 0 ); |
---|
1645 | } |
---|
1646 | return; |
---|
1647 | } |
---|
1648 | |
---|
1649 | Void TEncCavlc::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
1650 | { |
---|
1651 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
1652 | { |
---|
1653 | xWriteFlag( 1 ); |
---|
1654 | uiSymbol -= 1<<uiCount; |
---|
1655 | uiCount ++; |
---|
1656 | } |
---|
1657 | xWriteFlag( 0 ); |
---|
1658 | while( uiCount-- ) |
---|
1659 | { |
---|
1660 | xWriteFlag( (uiSymbol>>uiCount) & 1 ); |
---|
1661 | } |
---|
1662 | return; |
---|
1663 | } |
---|
1664 | |
---|
1665 | /** code explicit wp tables |
---|
1666 | * \param TComSlice* pcSlice |
---|
1667 | * \returns Void |
---|
1668 | */ |
---|
1669 | Void TEncCavlc::xCodePredWeightTable( TComSlice* pcSlice ) |
---|
1670 | { |
---|
1671 | wpScalingParam *wp; |
---|
1672 | Bool bChroma = true; // color always present in HEVC ? |
---|
1673 | Int iNbRef = (pcSlice->getSliceType() == B_SLICE ) ? (2) : (1); |
---|
1674 | Bool bDenomCoded = false; |
---|
1675 | |
---|
1676 | UInt uiMode = 0; |
---|
1677 | if ( (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag()==0 ) ) |
---|
1678 | uiMode = 1; // explicit |
---|
1679 | else if ( pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==2 ) |
---|
1680 | uiMode = 2; // implicit (does not use this mode in this syntax) |
---|
1681 | if (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag()) |
---|
1682 | uiMode = 3; // combined explicit |
---|
1683 | if(uiMode == 1) |
---|
1684 | { |
---|
1685 | for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) |
---|
1686 | { |
---|
1687 | RefPicList eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
1688 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
1689 | { |
---|
1690 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
1691 | if ( !bDenomCoded ) |
---|
1692 | { |
---|
1693 | Int iDeltaDenom; |
---|
1694 | WRITE_UVLC( wp[0].uiLog2WeightDenom, "luma_log2_weight_denom" ); // ue(v): luma_log2_weight_denom |
---|
1695 | |
---|
1696 | if( bChroma ) |
---|
1697 | { |
---|
1698 | iDeltaDenom = (wp[1].uiLog2WeightDenom - wp[0].uiLog2WeightDenom); |
---|
1699 | WRITE_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" ); // se(v): delta_chroma_log2_weight_denom |
---|
1700 | } |
---|
1701 | bDenomCoded = true; |
---|
1702 | } |
---|
1703 | |
---|
1704 | WRITE_FLAG( wp[0].bPresentFlag, "luma_weight_lX_flag" ); // u(1): luma_weight_lX_flag |
---|
1705 | |
---|
1706 | if ( wp[0].bPresentFlag ) |
---|
1707 | { |
---|
1708 | Int iDeltaWeight = (wp[0].iWeight - (1<<wp[0].uiLog2WeightDenom)); |
---|
1709 | WRITE_SVLC( iDeltaWeight, "delta_luma_weight_lX" ); // se(v): delta_luma_weight_lX |
---|
1710 | WRITE_SVLC( wp[0].iOffset, "luma_offset_lX" ); // se(v): luma_offset_lX |
---|
1711 | } |
---|
1712 | |
---|
1713 | if ( bChroma ) |
---|
1714 | { |
---|
1715 | WRITE_FLAG( wp[1].bPresentFlag, "chroma_weight_lX_flag" ); // u(1): chroma_weight_lX_flag |
---|
1716 | |
---|
1717 | if ( wp[1].bPresentFlag ) |
---|
1718 | { |
---|
1719 | for ( Int j=1 ; j<3 ; j++ ) |
---|
1720 | { |
---|
1721 | Int iDeltaWeight = (wp[j].iWeight - (1<<wp[1].uiLog2WeightDenom)); |
---|
1722 | WRITE_SVLC( iDeltaWeight, "delta_chroma_weight_lX" ); // se(v): delta_chroma_weight_lX |
---|
1723 | |
---|
1724 | Int iDeltaChroma = (wp[j].iOffset + ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) - (g_uiIBDI_MAX>>1)); |
---|
1725 | WRITE_SVLC( iDeltaChroma, "delta_chroma_offset_lX" ); // se(v): delta_chroma_offset_lX |
---|
1726 | } |
---|
1727 | } |
---|
1728 | } |
---|
1729 | } |
---|
1730 | } |
---|
1731 | } |
---|
1732 | else if (uiMode == 3) |
---|
1733 | { |
---|
1734 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx++ ) |
---|
1735 | { |
---|
1736 | RefPicList eRefPicList = (RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIdx); |
---|
1737 | Int iCombRefIdx = pcSlice->getRefIdxFromIdxOfLC(iRefIdx); |
---|
1738 | |
---|
1739 | pcSlice->getWpScaling(eRefPicList, iCombRefIdx, wp); |
---|
1740 | if ( !bDenomCoded ) |
---|
1741 | { |
---|
1742 | Int iDeltaDenom; |
---|
1743 | WRITE_UVLC( wp[0].uiLog2WeightDenom, "luma_log2_weight_denom" ); // ue(v): luma_log2_weight_denom |
---|
1744 | |
---|
1745 | if( bChroma ) |
---|
1746 | { |
---|
1747 | iDeltaDenom = (wp[1].uiLog2WeightDenom - wp[0].uiLog2WeightDenom); |
---|
1748 | WRITE_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" ); // se(v): delta_chroma_log2_weight_denom |
---|
1749 | } |
---|
1750 | bDenomCoded = true; |
---|
1751 | } |
---|
1752 | |
---|
1753 | WRITE_FLAG( wp[0].bPresentFlag, "luma_weight_lc_flag" ); // u(1): luma_weight_lc_flag |
---|
1754 | |
---|
1755 | if ( wp[0].bPresentFlag ) |
---|
1756 | { |
---|
1757 | Int iDeltaWeight = (wp[0].iWeight - (1<<wp[0].uiLog2WeightDenom)); |
---|
1758 | WRITE_SVLC( iDeltaWeight, "delta_luma_weight_lc" ); // se(v): delta_luma_weight_lc |
---|
1759 | WRITE_SVLC( wp[0].iOffset, "luma_offset_lc" ); // se(v): luma_offset_lc |
---|
1760 | } |
---|
1761 | if ( bChroma ) |
---|
1762 | { |
---|
1763 | WRITE_FLAG( wp[1].bPresentFlag, "chroma_weight_lc_flag" ); // u(1): luma_weight_lc_flag |
---|
1764 | |
---|
1765 | if ( wp[1].bPresentFlag ) |
---|
1766 | { |
---|
1767 | for ( Int j=1 ; j<3 ; j++ ) |
---|
1768 | { |
---|
1769 | Int iDeltaWeight = (wp[j].iWeight - (1<<wp[1].uiLog2WeightDenom)); |
---|
1770 | WRITE_SVLC( iDeltaWeight, "delta_chroma_weight_lc" ); // se(v): delta_chroma_weight_lc |
---|
1771 | |
---|
1772 | Int iDeltaChroma = (wp[j].iOffset + ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) - (g_uiIBDI_MAX>>1)); |
---|
1773 | WRITE_SVLC( iDeltaChroma, "delta_chroma_offset_lc" ); // se(v): delta_chroma_offset_lc |
---|
1774 | } |
---|
1775 | } |
---|
1776 | } |
---|
1777 | } |
---|
1778 | } |
---|
1779 | } |
---|
1780 | |
---|
1781 | /** code quantization matrix |
---|
1782 | * \param scalingList quantization matrix information |
---|
1783 | */ |
---|
1784 | Void TEncCavlc::codeScalingList( TComScalingList* scalingList ) |
---|
1785 | { |
---|
1786 | UInt listId,sizeId; |
---|
1787 | Bool scalingListPredModeFlag; |
---|
1788 | |
---|
1789 | #if SCALING_LIST_OUTPUT_RESULT |
---|
1790 | Int startBit; |
---|
1791 | Int startTotalBit; |
---|
1792 | startBit = m_pcBitIf->getNumberOfWrittenBits(); |
---|
1793 | startTotalBit = m_pcBitIf->getNumberOfWrittenBits(); |
---|
1794 | #endif |
---|
1795 | |
---|
1796 | WRITE_FLAG( scalingList->getScalingListPresentFlag (), "scaling_list_present_flag" ); |
---|
1797 | |
---|
1798 | if(scalingList->getScalingListPresentFlag () == false) |
---|
1799 | { |
---|
1800 | #if SCALING_LIST_OUTPUT_RESULT |
---|
1801 | printf("Header Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startBit); |
---|
1802 | #endif |
---|
1803 | //for each size |
---|
1804 | for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
1805 | { |
---|
1806 | for(listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
1807 | { |
---|
1808 | #if SCALING_LIST_OUTPUT_RESULT |
---|
1809 | startBit = m_pcBitIf->getNumberOfWrittenBits(); |
---|
1810 | #endif |
---|
1811 | scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId ); |
---|
1812 | WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" ); |
---|
1813 | if(!scalingListPredModeFlag)// Copy Mode |
---|
1814 | { |
---|
1815 | WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId) - 1, "scaling_list_pred_matrix_id_delta"); |
---|
1816 | } |
---|
1817 | else// DPCM Mode |
---|
1818 | { |
---|
1819 | xCodeScalingList(scalingList, sizeId, listId); |
---|
1820 | } |
---|
1821 | #if SCALING_LIST_OUTPUT_RESULT |
---|
1822 | printf("Matrix [%d][%d] Bit %d\n",sizeId,listId,m_pcBitIf->getNumberOfWrittenBits() - startBit); |
---|
1823 | #endif |
---|
1824 | } |
---|
1825 | } |
---|
1826 | } |
---|
1827 | #if SCALING_LIST_OUTPUT_RESULT |
---|
1828 | else |
---|
1829 | { |
---|
1830 | printf("Header Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit); |
---|
1831 | } |
---|
1832 | printf("Total Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit); |
---|
1833 | #endif |
---|
1834 | return; |
---|
1835 | } |
---|
1836 | /** code DPCM |
---|
1837 | * \param scalingList quantization matrix information |
---|
1838 | * \param sizeIdc size index |
---|
1839 | * \param listIdc list index |
---|
1840 | */ |
---|
1841 | Void TEncCavlc::xCodeScalingList(TComScalingList* scalingList, UInt sizeId, UInt listId) |
---|
1842 | { |
---|
1843 | Int coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]); |
---|
1844 | UInt* scan = g_auiFrameScanXY [ (sizeId == 0)? 1 : 2]; |
---|
1845 | Int nextCoef = SCALING_LIST_START_VALUE; |
---|
1846 | Int data; |
---|
1847 | Int *src = scalingList->getScalingListAddress(sizeId, listId); |
---|
1848 | if(sizeId > SCALING_LIST_8x8 && scalingList->getUseDefaultScalingMatrixFlag(sizeId,listId)) |
---|
1849 | { |
---|
1850 | WRITE_SVLC( -8, "scaling_list_dc_coef_minus8"); |
---|
1851 | } |
---|
1852 | else if(sizeId < SCALING_LIST_16x16 && scalingList->getUseDefaultScalingMatrixFlag(sizeId,listId)) |
---|
1853 | { |
---|
1854 | WRITE_SVLC( -8, "scaling_list_delta_coef"); |
---|
1855 | } |
---|
1856 | else |
---|
1857 | { |
---|
1858 | if( sizeId > SCALING_LIST_8x8 ) |
---|
1859 | { |
---|
1860 | WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8"); |
---|
1861 | } |
---|
1862 | for(Int i=0;i<coefNum;i++) |
---|
1863 | { |
---|
1864 | data = src[scan[i]] - nextCoef; |
---|
1865 | nextCoef = src[scan[i]]; |
---|
1866 | if(data > 127) |
---|
1867 | { |
---|
1868 | data = data - 256; |
---|
1869 | } |
---|
1870 | if(data < -128) |
---|
1871 | { |
---|
1872 | data = data + 256; |
---|
1873 | } |
---|
1874 | |
---|
1875 | WRITE_SVLC( data, "scaling_list_delta_coef"); |
---|
1876 | } |
---|
1877 | } |
---|
1878 | } |
---|
1879 | Bool TComScalingList::checkPredMode(UInt sizeId, UInt listId) |
---|
1880 | { |
---|
1881 | for(Int predListIdx = (Int)listId -1 ; predListIdx >= 0; predListIdx--) |
---|
1882 | { |
---|
1883 | if( !memcmp(getScalingListAddress(sizeId,listId),getScalingListAddress(sizeId, predListIdx),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix |
---|
1884 | && ((sizeId < SCALING_LIST_16x16) || (getScalingListDC(sizeId,listId) == getScalingListDC(sizeId,predListIdx)))) // check DC value |
---|
1885 | { |
---|
1886 | setRefMatrixId(sizeId, listId, predListIdx); |
---|
1887 | return false; |
---|
1888 | } |
---|
1889 | } |
---|
1890 | return true; |
---|
1891 | } |
---|
1892 | |
---|
1893 | #if RWTH_SDC_DLT_B0036 |
---|
1894 | Void TEncCavlc::codeSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1895 | { |
---|
1896 | assert(0); |
---|
1897 | } |
---|
1898 | |
---|
1899 | Void TEncCavlc::codeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) |
---|
1900 | { |
---|
1901 | assert(0); |
---|
1902 | } |
---|
1903 | |
---|
1904 | Void TEncCavlc::codeSDCPredMode ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1905 | { |
---|
1906 | assert(0); |
---|
1907 | } |
---|
1908 | #endif |
---|
1909 | //! \} |
---|