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