1 // Copyright (c) 2017-2018 Intel Corporation
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20
21 #include "umc_defs.h"
22 #if defined (MFX_ENABLE_H264_VIDEO_DECODE)
23
24 #ifndef __UMC_H264_DEC_DEFS_DEC_H__
25 #define __UMC_H264_DEC_DEFS_DEC_H__
26
27
28 #include <vector>
29 #include "umc_structures.h"
30
31 namespace UMC
32 {
33
34 // NAL unit definitions
35 enum
36 {
37 NAL_STORAGE_IDC_BITS = 0x60,
38 NAL_UNITTYPE_BITS = 0x1f
39 };
40
41
42 // Although the standard allows for a minimum width or height of 4, this
43 // implementation restricts the minimum value to 32.
44
45 enum {
46 FLD_STRUCTURE = 0,
47 TOP_FLD_STRUCTURE = 0,
48 BOTTOM_FLD_STRUCTURE = 1,
49 FRM_STRUCTURE = 2,
50 AFRM_STRUCTURE = 3
51 };
52
53 enum DisplayPictureStruct {
54 DPS_UNKNOWN = 100,
55 DPS_FRAME = 0,
56 DPS_TOP, // one field
57 DPS_BOTTOM, // one field
58 DPS_TOP_BOTTOM,
59 DPS_BOTTOM_TOP,
60 DPS_TOP_BOTTOM_TOP,
61 DPS_BOTTOM_TOP_BOTTOM,
62 DPS_FRAME_DOUBLING,
63 DPS_FRAME_TRIPLING
64 };
65
66 enum // Valid QP range
67 {
68 QP_MAX = 51,
69 QP_MIN = 0
70 };
71
72 enum
73 {
74 LIST_0 = 0, // Ref/mvs list 0 (L0)
75 LIST_1 = 1 // Ref/mvs list 1 (L1)
76 };
77
78 // default plane & coeffs types:
79 typedef uint8_t PlaneYCommon;
80 typedef uint8_t PlaneUVCommon;
81
82 typedef PlaneYCommon * PlanePtrYCommon;
83 typedef PlaneUVCommon * PlanePtrUVCommon;
84
85 typedef enum {
86 NAL_UT_UNSPECIFIED = 0, // Unspecified
87 NAL_UT_SLICE = 1, // Coded Slice - slice_layer_no_partioning_rbsp
88 NAL_UT_DPA = 2, // Coded Data partition A - dpa_layer_rbsp
89 NAL_UT_DPB = 3, // Coded Data partition A - dpa_layer_rbsp
90 NAL_UT_DPC = 4, // Coded Data partition A - dpa_layer_rbsp
91 NAL_UT_IDR_SLICE = 5, // Coded Slice of a IDR Picture - slice_layer_no_partioning_rbsp
92 NAL_UT_SEI = 6, // Supplemental Enhancement Information - sei_rbsp
93 NAL_UT_SPS = 7, // Sequence Parameter Set - seq_parameter_set_rbsp
94 NAL_UT_PPS = 8, // Picture Parameter Set - pic_parameter_set_rbsp
95 NAL_UT_AUD = 9, // Access Unit Delimiter - access_unit_delimiter_rbsp
96 NAL_UT_END_OF_SEQ = 10, // End of sequence end_of_seq_rbsp()
97 NAL_UT_END_OF_STREAM = 11, // End of stream end_of_stream_rbsp
98 NAL_UT_FD = 12, // Filler Data - filler_data_rbsp
99 NAL_UT_SPS_EX = 13, // Sequence Parameter Set Extension - seq_parameter_set_extension_rbsp
100 NAL_UT_PREFIX = 14, // Prefix NAL unit in scalable extension - prefix_nal_unit_rbsp
101 NAL_UT_SUBSET_SPS = 15, // Subset Sequence Parameter Set - subset_seq_parameter_set_rbsp
102 NAL_UT_AUXILIARY = 19, // Auxiliary coded picture
103 NAL_UT_CODED_SLICE_EXTENSION = 20 // Coded slice in scalable/multiview extension
104 } NAL_Unit_Type;
105
106 // Note! The Picture Code Type values below are no longer used in the
107 // core encoder. It only knows about slice types, and whether or not
108 // the frame is IDR, Reference or Disposable. See enum above.
109
110 enum EnumSliceCodType // Permitted MB Prediction Types
111 { // ------------------------------------
112 PREDSLICE = 0, // I (Intra), P (Pred)
113 BPREDSLICE = 1, // I, P, B (BiPred)
114 INTRASLICE = 2, // I
115 S_PREDSLICE = 3, // SP (SPred), I
116 S_INTRASLICE = 4 // SI (SIntra), I
117 };
118
119 inline
SliceTypeToFrameType(EnumSliceCodType slice_type)120 FrameType SliceTypeToFrameType(EnumSliceCodType slice_type)
121 {
122 switch(slice_type)
123 {
124 case PREDSLICE:
125 case S_PREDSLICE:
126 return P_PICTURE;
127 case BPREDSLICE:
128 return B_PICTURE;
129 case INTRASLICE:
130 case S_INTRASLICE:
131 return I_PICTURE;
132 }
133
134 return NONE_PICTURE;
135 }
136
137 typedef enum
138 {
139 SEI_BUFFERING_PERIOD_TYPE = 0,
140 SEI_PIC_TIMING_TYPE = 1,
141 SEI_PAN_SCAN_RECT_TYPE = 2,
142 SEI_FILLER_TYPE = 3,
143 SEI_USER_DATA_REGISTERED_TYPE = 4,
144 SEI_USER_DATA_UNREGISTERED_TYPE = 5,
145 SEI_RECOVERY_POINT_TYPE = 6,
146 SEI_DEC_REF_PIC_MARKING_TYPE = 7,
147 SEI_SPARE_PIC_TYPE = 8,
148 SEI_SCENE_INFO_TYPE = 9,
149 SEI_SUB_SEQ_INFO_TYPE = 10,
150 SEI_SUB_SEQ_LAYER_TYPE = 11,
151 SEI_SUB_SEQ_TYPE = 12,
152 SEI_FULL_FRAME_FREEZE_TYPE = 13,
153 SEI_FULL_FRAME_FREEZE_RELEASE_TYPE = 14,
154 SEI_FULL_FRAME_SNAPSHOT_TYPE = 15,
155 SEI_PROGRESSIVE_REF_SEGMENT_START_TYPE = 16,
156 SEI_PROGRESSIVE_REF_SEGMENT_END_TYPE = 17,
157 SEI_MOTION_CONSTRAINED_SG_SET_TYPE = 18,
158 SEI_FILM_GRAIN_CHARACTERISTICS = 19,
159
160 SEI_DEBLOCKING_FILTER_DISPLAY_PREFERENCE = 20,
161 SEI_STEREO_VIDEO_INFO = 21,
162 SEI_POST_FILTER_HINT = 22,
163 SEI_TONE_MAPPING_INFO = 23,
164 SEI_SCALABILITY_INFO = 24,
165 SEI_SUB_PIC_SCALABLE_LAYER = 25,
166 SEI_NON_REQUIRED_LAYER_REP = 26,
167 SEI_PRIORITY_LAYER_INFO = 27,
168 SEI_LAYERS_NOT_PRESENT = 28,
169 SEI_LAYER_DEPENDENCY_CHANGE = 29,
170 SEI_SCALABLE_NESTING = 30,
171 SEI_BASE_LAYER_TEMPORAL_HRD = 31,
172 SEI_QUALITY_LAYER_INTEGRITY_CHECK = 32,
173 SEI_REDUNDANT_PIC_PROPERTY = 33,
174 SEI_TL0_DEP_REP_INDEX = 34,
175 SEI_TL_SWITCHING_POINT = 35,
176 SEI_PARALLEL_DECODING_INFO = 36,
177 SEI_MVC_SCAOLABLE_NESTING = 37,
178 SEI_VIEW_SCALABILITY_INFO = 38,
179 SEI_MULTIVIEW_SCENE_INFO = 39,
180 SEI_MULTIVIEW_ACQUISITION_INFO = 40,
181 SEI_NONT_REQUERED_VIEW_COMPONENT = 41,
182 SEI_VIEW_DEPENDENCY_CHANGE = 42,
183 SEI_OPERATION_POINTS_NOT_PRESENT = 43,
184 SEI_BASE_VIEW_TEMPORAL_HRD = 44,
185 SEI_FRAME_PACKING_ARRANGEMENT = 45,
186
187 SEI_RESERVED = 50,
188
189 SEI_NUM_MESSAGES
190
191 } SEI_TYPE;
192
193 #define IS_SKIP_DEBLOCKING_MODE_NON_REF (m_PermanentTurnOffDeblocking == 1)
194 #define IS_SKIP_DEBLOCKING_MODE_PERMANENT (m_PermanentTurnOffDeblocking == 2)
195 #define IS_SKIP_DEBLOCKING_MODE_PREVENTIVE (m_PermanentTurnOffDeblocking == 3)
196
197 enum // unsigned enum
198 {
199 INVALID_DPB_OUTPUT_DELAY = 0xffffffff,
200 };
201
202 enum // usual int
203 {
204 MAX_NUM_SEQ_PARAM_SETS = 32,
205 MAX_NUM_PIC_PARAM_SETS = 256,
206
207 MAX_NUM_REF_FRAMES = 32,
208 MAX_NUM_REF_FIELDS = 32,
209
210 MAX_REF_FRAMES_IN_POC_CYCLE = 256,
211
212 MAX_NUM_SLICE_GROUPS = 8,
213 MAX_SLICE_GROUP_MAP_TYPE = 6,
214
215 NUM_INTRA_TYPE_ELEMENTS = 16,
216
217 COEFFICIENTS_BUFFER_SIZE = 16 * 51,
218
219 MINIMAL_DATA_SIZE = 4,
220 MAX_NUM_LAYERS = 16,
221
222 DEFAULT_NU_HEADER_TAIL_VALUE = 0, // for sei
223 DEFAULT_NU_TAIL_VALUE = 0,
224 DEFAULT_NU_TAIL_SIZE = 128,
225 DEFAULT_NU_SLICE_TAIL_SIZE = 512,
226 };
227
228 // Possible values for disable_deblocking_filter_idc:
229 enum DeblockingModes_t
230 {
231 DEBLOCK_FILTER_ON = 0,
232 DEBLOCK_FILTER_OFF = 1,
233 DEBLOCK_FILTER_ON_NO_SLICE_EDGES = 2,
234 DEBLOCK_FILTER_ON_2_PASS = 3,
235 DEBLOCK_FILTER_ON_NO_CHROMA = 4,
236 DEBLOCK_FILTER_ON_NO_SLICE_EDGES_NO_CHROMA = 5,
237 DEBLOCK_FILTER_ON_2_PASS_NO_CHROMA = 6
238 };
239
240 enum
241 {
242 H264_MAX_DEPENDENCY_ID = 7, // svc decoder
243 H264_MAX_QUALITY_ID = 15,// svc decoder
244 H264_MAX_TEMPORAL_ID = 7, // svc decoder
245
246 H264_MAX_NUM_VIEW = 1024,
247 H264_MAX_NUM_OPS = 64,
248 H264_MAX_NUM_VIEW_REF = 16
249 };
250
251 struct H264ScalingList4x4
252 {
253 uint8_t ScalingListCoeffs[16];
254 };
255
256 struct H264ScalingList8x8
257 {
258 uint8_t ScalingListCoeffs[64];
259 };
260
261 struct H264WholeQPLevelScale4x4
262 {
263 int16_t LevelScaleCoeffs[88]/*since we do not support 422 and 444*/[16];
264 };
265 struct H264WholeQPLevelScale8x8
266 {
267 int16_t LevelScaleCoeffs[88]/*since we do not support 422 and 444*/[64];
268 };
269
270 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
271 // Memory class
272 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
273 class RefCounter
274 {
275 public:
276
RefCounter()277 RefCounter() : m_refCounter(0)
278 {
279 }
280
281 void IncrementReference() const;
282
283 void DecrementReference();
284
ResetRefCounter()285 void ResetRefCounter() {m_refCounter = 0;}
286
GetRefCounter()287 uint32_t GetRefCounter() {return m_refCounter;}
288
289 protected:
290 volatile mutable int32_t m_refCounter;
291
~RefCounter()292 virtual ~RefCounter()
293 {
294 }
295
Free()296 virtual void Free()
297 {
298 }
299 };
300
301 class HeapObject : public RefCounter
302 {
303 public:
304
~HeapObject()305 virtual ~HeapObject() {}
306
Reset()307 virtual void Reset()
308 {
309 }
310
311 virtual void Free();
312 };
313
314 } // end namespace UMC
315
316 namespace UMC_H264_DECODER
317 {
318
319 struct H264VUI
320 {
ResetH264VUI321 void Reset()
322 {
323 H264VUI vui = {};
324 // set some parameters by default
325 vui.video_format = 5; // unspecified
326 vui.video_full_range_flag = 0;
327 vui.colour_primaries = 2; // unspecified
328 vui.transfer_characteristics = 2; // unspecified
329 vui.matrix_coefficients = 2; // unspecified
330
331 *this = vui;
332 }
333
334 uint8_t aspect_ratio_info_present_flag;
335 uint8_t aspect_ratio_idc;
336 uint16_t sar_width;
337 uint16_t sar_height;
338 uint8_t overscan_info_present_flag;
339 uint8_t overscan_appropriate_flag;
340 uint8_t video_signal_type_present_flag;
341 uint8_t video_format;
342 uint8_t video_full_range_flag;
343 uint8_t colour_description_present_flag;
344 uint8_t colour_primaries;
345 uint8_t transfer_characteristics;
346 uint8_t matrix_coefficients;
347 uint8_t chroma_loc_info_present_flag;
348 uint8_t chroma_sample_loc_type_top_field;
349 uint8_t chroma_sample_loc_type_bottom_field;
350 uint8_t timing_info_present_flag;
351 uint32_t num_units_in_tick;
352 uint32_t time_scale;
353 uint8_t fixed_frame_rate_flag;
354 uint8_t nal_hrd_parameters_present_flag;
355 uint8_t vcl_hrd_parameters_present_flag;
356 uint8_t low_delay_hrd_flag;
357 uint8_t pic_struct_present_flag;
358 uint8_t bitstream_restriction_flag;
359 uint8_t motion_vectors_over_pic_boundaries_flag;
360 uint8_t max_bytes_per_pic_denom;
361 uint8_t max_bits_per_mb_denom;
362 uint8_t log2_max_mv_length_horizontal;
363 uint8_t log2_max_mv_length_vertical;
364 uint8_t num_reorder_frames;
365 uint8_t max_dec_frame_buffering;
366 //hrd_parameters
367 uint8_t cpb_cnt;
368 uint8_t bit_rate_scale;
369 uint8_t cpb_size_scale;
370 uint32_t bit_rate_value[32];
371 uint32_t cpb_size_value[32];
372 uint8_t cbr_flag[32];
373 uint8_t initial_cpb_removal_delay_length;
374 uint8_t cpb_removal_delay_length;
375 uint8_t dpb_output_delay_length;
376 uint8_t time_offset_length;
377 };
378
379 // Sequence parameter set structure, corresponding to the H.264 bitstream definition.
380 struct H264SeqParamSetBase
381 {
382 uint8_t profile_idc; // baseline, main, etc.
383 uint8_t level_idc;
384 uint8_t constraint_set0_flag;
385 uint8_t constraint_set1_flag;
386 uint8_t constraint_set2_flag;
387 uint8_t constraint_set3_flag;
388 uint8_t constraint_set4_flag;
389 uint8_t constraint_set5_flag;
390 uint8_t chroma_format_idc;
391 uint8_t residual_colour_transform_flag;
392 uint8_t bit_depth_luma;
393 uint8_t bit_depth_chroma;
394 uint8_t qpprime_y_zero_transform_bypass_flag;
395 uint8_t type_of_scaling_list_used[8];
396 uint8_t seq_scaling_matrix_present_flag;
397 UMC::H264ScalingList4x4 ScalingLists4x4[6];
398 UMC::H264ScalingList8x8 ScalingLists8x8[2];
399 uint8_t gaps_in_frame_num_value_allowed_flag;
400 uint8_t frame_cropping_flag;
401 uint32_t frame_cropping_rect_left_offset;
402 uint32_t frame_cropping_rect_right_offset;
403 uint32_t frame_cropping_rect_top_offset;
404 uint32_t frame_cropping_rect_bottom_offset;
405
406 uint8_t seq_parameter_set_id; // id of this sequence parameter set
407 uint8_t log2_max_frame_num; // Number of bits to hold the frame_num
408 uint8_t pic_order_cnt_type; // Picture order counting method
409
410 uint8_t delta_pic_order_always_zero_flag; // If zero, delta_pic_order_cnt fields are
411 // present in slice header.
412 uint8_t frame_mbs_only_flag; // Nonzero indicates all pictures in sequence
413 // are coded as frames (not fields).
414
415 uint8_t mb_adaptive_frame_field_flag; // Nonzero indicates frame/field switch
416 // at macroblock level
417 uint8_t direct_8x8_inference_flag; // Direct motion vector derivation method
418 uint8_t vui_parameters_present_flag; // Zero indicates default VUI parameters
419 uint32_t log2_max_pic_order_cnt_lsb; // Value of MaxPicOrderCntLsb.
420 int32_t offset_for_non_ref_pic;
421
422 int32_t offset_for_top_to_bottom_field; // Expected pic order count difference from
423 // top field to bottom field.
424
425 uint32_t num_ref_frames_in_pic_order_cnt_cycle;
426 uint32_t num_ref_frames; // total number of pics in decoded pic buffer
427 uint32_t frame_width_in_mbs;
428 uint32_t frame_height_in_mbs;
429
430 // These fields are calculated from values above. They are not written to the bitstream
431 uint32_t MaxPicOrderCntLsb;
432
433 // vui part
434 H264VUI vui;
435
436 int32_t poffset_for_ref_frame[UMC::MAX_REF_FRAMES_IN_POC_CYCLE]; // for pic order cnt type 1
437
438 uint8_t errorFlags;
439
ResetH264SeqParamSetBase440 void Reset()
441 {
442 H264SeqParamSetBase sps = {};
443 *this = sps;
444 }
445
446 }; // H264SeqParamSet
447
448 // Sequence parameter set structure, corresponding to the H.264 bitstream definition.
449 struct H264SeqParamSet : public UMC::HeapObject, public H264SeqParamSetBase
450 {
H264SeqParamSetH264SeqParamSet451 H264SeqParamSet()
452 : HeapObject()
453 , H264SeqParamSetBase()
454 {
455 Reset();
456 }
457
~H264SeqParamSetH264SeqParamSet458 ~H264SeqParamSet()
459 {
460 }
461
GetIDH264SeqParamSet462 int32_t GetID() const
463 {
464 return seq_parameter_set_id;
465 }
466
ResetH264SeqParamSet467 virtual void Reset()
468 {
469 H264SeqParamSetBase::Reset();
470
471 seq_parameter_set_id = UMC::MAX_NUM_SEQ_PARAM_SETS;
472 vui.Reset();
473 }
474 }; // H264SeqParamSet
475
476 // Sequence parameter set extension structure, corresponding to the H.264 bitstream definition.
477 struct H264SeqParamSetExtension : public UMC::HeapObject
478 {
479 uint8_t seq_parameter_set_id;
480 uint8_t aux_format_idc;
481 uint8_t bit_depth_aux;
482 uint8_t alpha_incr_flag;
483 uint8_t alpha_opaque_value;
484 uint8_t alpha_transparent_value;
485 uint8_t additional_extension_flag;
486
H264SeqParamSetExtensionH264SeqParamSetExtension487 H264SeqParamSetExtension()
488 {
489 Reset();
490 }
491
ResetH264SeqParamSetExtension492 virtual void Reset()
493 {
494 aux_format_idc = 0;
495 seq_parameter_set_id = UMC::MAX_NUM_SEQ_PARAM_SETS; // illegal id
496 bit_depth_aux = 0;
497 alpha_incr_flag = 0;
498 alpha_opaque_value = 0;
499 alpha_transparent_value = 0;
500 additional_extension_flag = 0;
501 }
502
GetIDH264SeqParamSetExtension503 int32_t GetID() const
504 {
505 return seq_parameter_set_id;
506 }
507 }; // H264SeqParamSetExtension
508
509 // MVC view's reference info structure
510 struct H264ViewRefInfo
511 {
512 // ue(v) specifies the view_id of the view with VOIdx equal to i.
513 uint32_t view_id;
514
515 // ue(v) specifies the number of view components for inter-view prediction
516 // in the initialised RefPicListX in decoding anchor view components with
517 // VOIdx equal to i. The value of num_anchor_refs_lx[ i ] shall not
518 // be greater than 15.
519 uint8_t num_anchor_refs_lx[2];
520 // ue(v) specifies the view_id of the j-th view component for inter-view
521 // prediction in the initialised RefPicListX in decoding anchor view
522 // components with VOIdx equal to i.
523 uint16_t anchor_refs_lx[2][UMC::H264_MAX_NUM_VIEW_REF];
524
525 // ue(v) specifies the number of view components for inter-view prediction
526 // in the initialised RefPicListX in decoding non-anchor view components
527 // with VOIdx equal to i. The value of num_non_anchor_refs_lx[ i ]
528 // shall not be greater than 15
529 uint8_t num_non_anchor_refs_lx[2];
530 // ue(v) specifies the view_id of the j-th view component for inter-view
531 // prediction in the initialised RefPicListX in decoding non-anchor view
532 // components with VOIdx equal to i.
533 uint16_t non_anchor_refs_lx[2][UMC::H264_MAX_NUM_VIEW_REF];
534
535 };
536
537 struct H264ApplicableOp
538 {
539 // u(3) specifies the temporal_id of the j-th operation point to which the
540 // the level indicated by level_idc[ i ] applies.
541 uint8_t applicable_op_temporal_id;
542 // ue(v) plus 1 specifies the number of target output views for the j-th
543 // operation point to which the level indicated by level_idc[ i ] applies.
544 // The value of applicable_op_num_target_views_minus1[ i ][ j ] shall be in
545 // the range of 0 to 1023, inclusive.
546 uint16_t applicable_op_num_target_views_minus1;
547 // ue(v) specifies the k-th target output view for the j-th operation point
548 // to which the the level indicated by level_idc[ i ] applies. The value of
549 // applicable_op_num_target_views_minus1[ i ][ j ] shall be in the
550 // range of 0 to 1023, inclusive.
551 std::vector<uint16_t> applicable_op_target_view_id;
552 // ue(v) plus 1 specifies the number of views required for decoding the
553 // target output views corresponding to the j-th operation point to which
554 // the level indicated by level_idc[ i ] applies.
555 uint16_t applicable_op_num_views_minus1;
556
557 };
558
559 struct H264LevelValueSignaled
560 {
561 // u(8) specifies the i-th level value signalled for the coded video sequence.
562 uint8_t level_idc;
563 // ue(v) plus 1 specifies the number of operation points to which the level
564 // indicated by level_idc[ i ] applies. The value of
565 // num_applicable_ops_minus1[ i ] shall be in the range of 0 to 1023, inclusive.
566 uint16_t num_applicable_ops_minus1;
567
568 // Array of applicable operation points for the current level value signalled
569 std::vector<H264ApplicableOp> opsInfo;
570
571 };
572
573 // MVC extensions for sequence parameter set
574 struct H264SeqParamSetMVCExtension : public H264SeqParamSet
575 {
576 // ue(v) plus 1 specifies the maximum number of coded views in the coded
577 // video sequence. The value of num_view_minus1 shall be in the range of
578 // 0 to 1023, inclusive
579 uint32_t num_views_minus1;
580
581 // Array of views reference info structures.
582 std::vector<H264ViewRefInfo> viewInfo;
583
584 // ue(v) plus 1 specifies the number of level values signalled for
585 // the coded video sequence. The value of num_level_values_signalled_minus1
586 // shall be in the range of 0 to 63, inclusive.
587 uint32_t num_level_values_signalled_minus1;
588
589 // Array of level value signaled structures
590 std::vector<H264LevelValueSignaled> levelInfo;
591
ResetH264SeqParamSetMVCExtension592 virtual void Reset()
593 {
594 //H264SeqParamSetBase::Reset();
595
596 num_views_minus1 = 0;
597 num_level_values_signalled_minus1 = 0;
598 //viewInfo.Clean();
599 //levelInfo.Clean();
600 }
601 };
602
603 // SVC extensions for sequence parameter set
604 struct H264SeqParamSetSVCExtension : public H264SeqParamSet
605 {
606 /* For scalable stream */
607 uint8_t inter_layer_deblocking_filter_control_present_flag;
608 uint8_t extended_spatial_scalability;
609 int8_t chroma_phase_x;
610 int8_t chroma_phase_y;
611 int8_t seq_ref_layer_chroma_phase_x;
612 int8_t seq_ref_layer_chroma_phase_y;
613
614 uint8_t seq_tcoeff_level_prediction_flag;
615 uint8_t adaptive_tcoeff_level_prediction_flag;
616 uint8_t slice_header_restriction_flag;
617
618 int32_t seq_scaled_ref_layer_left_offset;
619 int32_t seq_scaled_ref_layer_top_offset;
620 int32_t seq_scaled_ref_layer_right_offset;
621 int32_t seq_scaled_ref_layer_bottom_offset;
622
ResetH264SeqParamSetSVCExtension623 virtual void Reset()
624 {
625 //H264SeqParamSetBase::Reset();
626
627 inter_layer_deblocking_filter_control_present_flag = 0;
628 extended_spatial_scalability = 0;
629 chroma_phase_x = 0;
630 chroma_phase_y = 0;
631 seq_ref_layer_chroma_phase_x = 0;
632 seq_ref_layer_chroma_phase_y = 0;
633
634 seq_tcoeff_level_prediction_flag = 0;
635 adaptive_tcoeff_level_prediction_flag = 0;
636 slice_header_restriction_flag = 0;
637
638 seq_scaled_ref_layer_left_offset = 0;
639 seq_scaled_ref_layer_top_offset = 0;
640 seq_scaled_ref_layer_right_offset = 0;
641 seq_scaled_ref_layer_bottom_offset = 0;
642 }
643 };
644
645 struct H264ScalingPicParams
646 {
647 UMC::H264ScalingList4x4 ScalingLists4x4[6];
648 UMC::H264ScalingList8x8 ScalingLists8x8[2];
649
650 // Level Scale addition
651 UMC::H264WholeQPLevelScale4x4 m_LevelScale4x4[6];
652 UMC::H264WholeQPLevelScale8x8 m_LevelScale8x8[2];
653 };
654
655 // Picture parameter set structure, corresponding to the H.264 bitstream definition.
656 struct H264PicParamSetBase
657 {
658 // Flexible macroblock order structure, defining the FMO map for a picture
659 // paramter set.
660
661 struct SliceGroupInfoStruct
662 {
663 uint8_t slice_group_map_type; // 0..6
664
665 // The additional slice group data depends upon map type
666 union
667 {
668 // type 0
669 uint32_t run_length[UMC::MAX_NUM_SLICE_GROUPS];
670
671 // type 2
672 struct
673 {
674 uint32_t top_left[UMC::MAX_NUM_SLICE_GROUPS-1];
675 uint32_t bottom_right[UMC::MAX_NUM_SLICE_GROUPS-1];
676 }t1;
677
678 // types 3-5
679 struct
680 {
681 uint8_t slice_group_change_direction_flag;
682 uint32_t slice_group_change_rate;
683 }t2;
684
685 // type 6
686 struct
687 {
688 uint32_t pic_size_in_map_units; // number of macroblocks if no field coding
689 }t3;
690 };
691
692 std::vector<uint8_t> pSliceGroupIDMap; // Id for each slice group map unit (for t3 struct of)
693 }; // SliceGroupInfoStruct
694
695 uint16_t pic_parameter_set_id; // of this picture parameter set
696 uint8_t seq_parameter_set_id; // of seq param set used for this pic param set
697 uint8_t entropy_coding_mode; // zero: CAVLC, else CABAC
698
699 uint8_t bottom_field_pic_order_in_frame_present_flag; // Zero indicates only delta_pic_order_cnt[0] is
700 // present in slice header; nonzero indicates
701 // delta_pic_order_cnt[1] is also present.
702
703 uint8_t weighted_pred_flag; // Nonzero indicates weighted prediction applied to
704 // P and SP slices
705 uint8_t weighted_bipred_idc; // 0: no weighted prediction in B slices
706 // 1: explicit weighted prediction
707 // 2: implicit weighted prediction
708 int8_t pic_init_qp; // default QP for I,P,B slices
709 int8_t pic_init_qs; // default QP for SP, SI slices
710
711 int8_t chroma_qp_index_offset[2]; // offset to add to QP for chroma
712
713 uint8_t deblocking_filter_variables_present_flag; // If nonzero, deblock filter params are
714 // present in the slice header.
715 uint8_t constrained_intra_pred_flag; // Nonzero indicates constrained intra mode
716
717 uint8_t redundant_pic_cnt_present_flag; // Nonzero indicates presence of redundant_pic_cnt
718 // in slice header
719 uint32_t num_slice_groups; // One: no FMO
720 uint32_t num_ref_idx_l0_active; // num of ref pics in list 0 used to decode the picture
721 uint32_t num_ref_idx_l1_active; // num of ref pics in list 1 used to decode the picture
722 uint8_t transform_8x8_mode_flag;
723
724 uint8_t pic_scaling_matrix_present_flag;
725 uint8_t pic_scaling_list_present_flag[8];
726
727 uint8_t type_of_scaling_list_used[8];
728
729 SliceGroupInfoStruct SliceGroupInfo; // Used only when num_slice_groups > 1
730
731 H264ScalingPicParams scaling[2];
732
733 uint8_t initialized[2];
734
735 uint8_t errorFlags;
736
ResetH264PicParamSetBase737 void Reset()
738 {
739 H264PicParamSetBase pps = {};
740 *this = pps;
741 }
742 };
743
744 // Picture parameter set structure, corresponding to the H.264 bitstream definition.
745 struct H264PicParamSet : public UMC::HeapObject, public H264PicParamSetBase
746 {
H264PicParamSetH264PicParamSet747 H264PicParamSet()
748 : H264PicParamSetBase()
749 {
750 Reset();
751 }
752
ResetH264PicParamSet753 void Reset()
754 {
755 H264PicParamSetBase::Reset();
756
757 pic_parameter_set_id = UMC::MAX_NUM_PIC_PARAM_SETS;
758 seq_parameter_set_id = UMC::MAX_NUM_SEQ_PARAM_SETS;
759 num_slice_groups = 0;
760 SliceGroupInfo.pSliceGroupIDMap.clear();
761 }
762
~H264PicParamSetH264PicParamSet763 ~H264PicParamSet()
764 {
765 }
766
GetIDH264PicParamSet767 int32_t GetID() const
768 {
769 return pic_parameter_set_id;
770 }
771
772 }; // H264PicParamSet
773
774 struct RefPicListReorderInfo
775 {
776 uint32_t num_entries; // number of currently valid idc,value pairs
777 uint8_t reordering_of_pic_nums_idc[UMC::MAX_NUM_REF_FRAMES];
778 uint32_t reorder_value[UMC::MAX_NUM_REF_FRAMES]; // abs_diff_pic_num or long_term_pic_num
779 };
780
781 struct AdaptiveMarkingInfo
782 {
783 uint32_t num_entries; // number of currently valid mmco,value pairs
784 uint8_t mmco[UMC::MAX_NUM_REF_FRAMES]; // memory management control operation id
785 uint32_t value[UMC::MAX_NUM_REF_FRAMES*2]; // operation-dependent data, max 2 per operation
786 };
787
788 struct PredWeightTable
789 {
790 uint8_t luma_weight_flag; // nonzero: luma weight and offset in bitstream
791 uint8_t chroma_weight_flag; // nonzero: chroma weight and offset in bitstream
792 int8_t luma_weight; // luma weighting factor
793 int8_t luma_offset; // luma weighting offset
794 int8_t chroma_weight[2]; // chroma weighting factor (Cb,Cr)
795 int8_t chroma_offset[2]; // chroma weighting offset (Cb,Cr)
796 }; // PredWeightTable
797
798 typedef int32_t H264DecoderMBAddr;
799 // NAL unit SVC extension structure
800 struct H264NalSvcExtension
801 {
802 uint8_t idr_flag;
803 uint8_t priority_id;
804 uint8_t no_inter_layer_pred_flag;
805 uint8_t dependency_id;
806 uint8_t quality_id;
807 uint8_t temporal_id;
808 uint8_t use_ref_base_pic_flag;
809 uint8_t discardable_flag;
810 uint8_t output_flag;
811
812 uint8_t store_ref_base_pic_flag;
813 uint8_t adaptive_ref_base_pic_marking_mode_flag;
814 AdaptiveMarkingInfo adaptiveMarkingInfo;
815
ResetH264NalSvcExtension816 void Reset()
817 {
818 idr_flag = 0;
819 priority_id = 0;
820 no_inter_layer_pred_flag = 0;
821 dependency_id = 0;
822 quality_id = 0;
823 temporal_id = 0;
824 use_ref_base_pic_flag = 0;
825 discardable_flag = 0;
826 output_flag = 0;
827
828 store_ref_base_pic_flag = 0;
829 adaptive_ref_base_pic_marking_mode_flag = 0;
830 }
831 };
832
833 // NAL unit SVC extension structure
834 struct H264NalMvcExtension
835 {
836 uint8_t non_idr_flag;
837 uint16_t priority_id;
838 // view_id variable is duplicated to the slice header itself
839 uint16_t view_id;
840 uint8_t temporal_id;
841 uint8_t anchor_pic_flag;
842 uint8_t inter_view_flag;
843
844 uint8_t padding[3];
845
ResetH264NalMvcExtension846 void Reset()
847 {
848 non_idr_flag = 0;
849 priority_id = 0;
850 view_id = 0;
851 temporal_id = 0;
852 anchor_pic_flag = 0;
853 inter_view_flag = 0;
854 }
855 };
856
857 // NAL unit extension structure
858 struct H264NalExtension
859 {
860 uint8_t extension_present;
861 uint8_t svc_extension_flag; // equal to 1 specifies that NAL extension contains SVC related parameters
862
863 H264NalSvcExtension svc;
864 H264NalMvcExtension mvc;
865
ResetH264NalExtension866 void Reset()
867 {
868 memset(this, 0, sizeof(H264NalExtension));
869 }
870 };
871
872 // Slice header structure, corresponding to the H.264 bitstream definition.
873 struct H264SliceHeader
874 {
875 // flag equal 1 means that the slice belong to IDR or anchor access unit
876 uint32_t IdrPicFlag;
877
878 // specified that NAL unit contains any information accessed from
879 // the decoding process of other NAL units.
880 uint32_t nal_ref_idc;
881 // specifies the type of RBSP data structure contained in the NAL unit as
882 // specified in Table 7-1 of h264 standard
883 UMC::NAL_Unit_Type nal_unit_type;
884
885 // NAL unit extension parameters
886 H264NalExtension nal_ext;
887
888 uint16_t pic_parameter_set_id; // of pic param set used for this slice
889 uint8_t field_pic_flag; // zero: frame picture, else field picture
890 uint8_t MbaffFrameFlag;
891 uint8_t bottom_field_flag; // zero: top field, else bottom field
892 uint8_t direct_spatial_mv_pred_flag; // zero: temporal direct, else spatial direct
893 uint8_t num_ref_idx_active_override_flag; // nonzero: use ref_idx_active from slice header
894 // instead of those from pic param set
895 uint8_t no_output_of_prior_pics_flag; // nonzero: remove previously decoded pictures
896 // from decoded picture buffer
897 uint8_t long_term_reference_flag; // How to set MaxLongTermFrameIdx
898 uint32_t cabac_init_idc; // CABAC initialization table index (0..2)
899 uint8_t adaptive_ref_pic_marking_mode_flag; // Ref pic marking mode of current picture
900 int32_t slice_qp_delta; // to calculate default slice QP
901 uint8_t sp_for_switch_flag; // SP slice decoding control
902 int32_t slice_qs_delta; // to calculate default SP,SI slice QS
903 uint32_t disable_deblocking_filter_idc; // deblock filter control, 0=filter all edges
904 int32_t slice_alpha_c0_offset; // deblock filter c0, alpha table offset
905 int32_t slice_beta_offset; // deblock filter beta table offset
906 H264DecoderMBAddr first_mb_in_slice;
907 int32_t frame_num;
908 UMC::EnumSliceCodType slice_type;
909 uint32_t idr_pic_id; // ID of an IDR picture
910 int32_t pic_order_cnt_lsb; // picture order count (mod MaxPicOrderCntLsb)
911 int32_t delta_pic_order_cnt_bottom; // Pic order count difference, top & bottom fields
912 uint32_t difference_of_pic_nums; // Ref pic memory mgmt
913 uint32_t long_term_pic_num; // Ref pic memory mgmt
914 uint32_t long_term_frame_idx; // Ref pic memory mgmt
915 uint32_t max_long_term_frame_idx; // Ref pic memory mgmt
916 int32_t delta_pic_order_cnt[2]; // picture order count differences
917 uint32_t redundant_pic_cnt; // for redundant slices
918 int32_t num_ref_idx_l0_active; // num of ref pics in list 0 used to decode the slice,
919 // see num_ref_idx_active_override_flag
920 int32_t num_ref_idx_l1_active; // num of ref pics in list 1 used to decode the slice
921 // see num_ref_idx_active_override_flag
922 uint32_t slice_group_change_cycle; // for FMO
923 uint8_t luma_log2_weight_denom; // luma weighting denominator
924 uint8_t chroma_log2_weight_denom; // chroma weighting denominator
925
926 bool is_auxiliary;
927
928 /* for scalable stream */
929 uint8_t scan_idx_start;
930 uint8_t scan_idx_end;
931
932 uint32_t hw_wa_redundant_elimination_bits[3]; // [0] - start redundant element, [1] - end redundant element [2] - header size in bits
933 }; // H264SliceHeader
934
935 typedef struct
936 {
937 uint32_t layer_id;
938 uint8_t priority_id;
939 uint8_t discardable_flag;
940 uint8_t dependency_id;
941 uint8_t quality_id;
942 uint8_t temporal_id;
943
944 uint32_t frm_width_in_mbs;
945 uint32_t frm_height_in_mbs;
946
947 // frm_rate_info_present_flag section
948 uint32_t constant_frm_rate_idc;
949 uint32_t avg_frm_rate;
950
951 // layer_dependency_info_present_flag
952 uint32_t num_directly_dependent_layers;
953 uint32_t directly_dependent_layer_id_delta_minus1[256];
954 uint32_t layer_dependency_info_src_layer_id_delta;
955
956 } scalability_layer_info;
957
958 struct H264SEIPayLoadBase
959 {
960 UMC::SEI_TYPE payLoadType;
961 uint32_t payLoadSize;
962 uint8_t isValid;
963
964 union SEIMessages
965 {
966 struct BufferingPeriod
967 {
968 uint32_t initial_cpb_removal_delay[2][32];
969 uint32_t initial_cpb_removal_delay_offset[2][32];
970 }buffering_period;
971
972 struct PicTiming
973 {
974 int32_t cbp_removal_delay;
975 int32_t dpb_output_delay;
976 UMC::DisplayPictureStruct pic_struct;
977 uint8_t clock_timestamp_flag[16];
978 struct ClockTimestamps
979 {
980 uint8_t ct_type;
981 uint8_t nunit_field_based_flag;
982 uint8_t counting_type;
983 uint8_t full_timestamp_flag;
984 uint8_t discontinuity_flag;
985 uint8_t cnt_dropped_flag;
986 uint8_t n_frames;
987 uint8_t seconds_value;
988 uint8_t minutes_value;
989 uint8_t hours_value;
990 uint8_t time_offset;
991 }clock_timestamps[16];
992 }pic_timing;
993
994 struct PanScanRect
995 {
996 uint8_t pan_scan_rect_id;
997 uint8_t pan_scan_rect_cancel_flag;
998 uint8_t pan_scan_cnt;
999 uint32_t pan_scan_rect_left_offset[32];
1000 uint32_t pan_scan_rect_right_offset[32];
1001 uint32_t pan_scan_rect_top_offset[32];
1002 uint32_t pan_scan_rect_bottom_offset[32];
1003 uint8_t pan_scan_rect_repetition_period;
1004 }pan_scan_rect;
1005
1006 struct UserDataRegistered
1007 {
1008 uint8_t itu_t_t35_country_code;
1009 uint8_t itu_t_t35_country_code_extension_byte;
1010 } user_data_registered;
1011
1012 struct RecoveryPoint
1013 {
1014 uint8_t recovery_frame_cnt;
1015 uint8_t exact_match_flag;
1016 uint8_t broken_link_flag;
1017 uint8_t changing_slice_group_idc;
1018 }recovery_point;
1019
1020 struct DecRefPicMarkingRepetition
1021 {
1022 uint8_t original_idr_flag;
1023 uint8_t original_frame_num;
1024 uint8_t original_field_pic_flag;
1025 uint8_t original_bottom_field_flag;
1026 uint8_t long_term_reference_flag;
1027 AdaptiveMarkingInfo adaptiveMarkingInfo;
1028 }dec_ref_pic_marking_repetition;
1029
1030 struct SparePic
1031 {
1032 uint32_t target_frame_num;
1033 uint8_t spare_field_flag;
1034 uint8_t target_bottom_field_flag;
1035 uint8_t num_spare_pics;
1036 uint8_t delta_spare_frame_num[16];
1037 uint8_t spare_bottom_field_flag[16];
1038 uint8_t spare_area_idc[16];
1039 uint8_t *spare_unit_flag[16];
1040 uint8_t *zero_run_length[16];
1041 }spare_pic;
1042
1043 struct SceneInfo
1044 {
1045 uint8_t scene_info_present_flag;
1046 uint8_t scene_id;
1047 uint8_t scene_transition_type;
1048 uint8_t second_scene_id;
1049 }scene_info;
1050
1051 struct SubSeqInfo
1052 {
1053 uint8_t sub_seq_layer_num;
1054 uint8_t sub_seq_id;
1055 uint8_t first_ref_pic_flag;
1056 uint8_t leading_non_ref_pic_flag;
1057 uint8_t last_pic_flag;
1058 uint8_t sub_seq_frame_num_flag;
1059 uint8_t sub_seq_frame_num;
1060 }sub_seq_info;
1061
1062 struct SubSeqLayerCharacteristics
1063 {
1064 uint8_t num_sub_seq_layers;
1065 uint8_t accurate_statistics_flag[16];
1066 uint16_t average_bit_rate[16];
1067 uint16_t average_frame_rate[16];
1068 }sub_seq_layer_characteristics;
1069
1070 struct SubSeqCharacteristics
1071 {
1072 uint8_t sub_seq_layer_num;
1073 uint8_t sub_seq_id;
1074 uint8_t duration_flag;
1075 uint8_t sub_seq_duration;
1076 uint8_t average_rate_flag;
1077 uint8_t accurate_statistics_flag;
1078 uint16_t average_bit_rate;
1079 uint16_t average_frame_rate;
1080 uint8_t num_referenced_subseqs;
1081 uint8_t ref_sub_seq_layer_num[16];
1082 uint8_t ref_sub_seq_id[16];
1083 uint8_t ref_sub_seq_direction[16];
1084 }sub_seq_characteristics;
1085
1086 struct FullFrameFreeze
1087 {
1088 uint32_t full_frame_freeze_repetition_period;
1089 }full_frame_freeze;
1090
1091 struct FullFrameSnapshot
1092 {
1093 uint8_t snapshot_id;
1094 }full_frame_snapshot;
1095
1096 struct ProgressiveRefinementSegmentStart
1097 {
1098 uint8_t progressive_refinement_id;
1099 uint8_t num_refinement_steps;
1100 }progressive_refinement_segment_start;
1101
1102 struct MotionConstrainedSliceGroupSet
1103 {
1104 uint8_t num_slice_groups_in_set;
1105 uint8_t slice_group_id[8];
1106 uint8_t exact_sample_value_match_flag;
1107 uint8_t pan_scan_rect_flag;
1108 uint8_t pan_scan_rect_id;
1109 }motion_constrained_slice_group_set;
1110
1111 struct FilmGrainCharacteristics
1112 {
1113 uint8_t film_grain_characteristics_cancel_flag;
1114 uint8_t model_id;
1115 uint8_t separate_colour_description_present_flag;
1116 uint8_t film_grain_bit_depth_luma;
1117 uint8_t film_grain_bit_depth_chroma;
1118 uint8_t film_grain_full_range_flag;
1119 uint8_t film_grain_colour_primaries;
1120 uint8_t film_grain_transfer_characteristics;
1121 uint8_t film_grain_matrix_coefficients;
1122 uint8_t blending_mode_id;
1123 uint8_t log2_scale_factor;
1124 uint8_t comp_model_present_flag[3];
1125 uint8_t num_intensity_intervals[3];
1126 uint8_t num_model_values[3];
1127 uint8_t intensity_interval_lower_bound[3][256];
1128 uint8_t intensity_interval_upper_bound[3][256];
1129 uint8_t comp_model_value[3][3][256];
1130 uint8_t film_grain_characteristics_repetition_period;
1131 }film_grain_characteristics;
1132
1133 struct DeblockingFilterDisplayPreference
1134 {
1135 uint8_t deblocking_display_preference_cancel_flag;
1136 uint8_t display_prior_to_deblocking_preferred_flag;
1137 uint8_t dec_frame_buffering_constraint_flag;
1138 uint8_t deblocking_display_preference_repetition_period;
1139 }deblocking_filter_display_preference;
1140
1141 struct StereoVideoInfo
1142 {
1143 uint8_t field_views_flag;
1144 uint8_t top_field_is_left_view_flag;
1145 uint8_t current_frame_is_left_view_flag;
1146 uint8_t next_frame_is_second_view_flag;
1147 uint8_t left_view_self_contained_flag;
1148 uint8_t right_view_self_contained_flag;
1149 }stereo_video_info;
1150
1151 struct ScalabilityInfo
1152 {
1153 uint8_t temporal_id_nesting_flag;
1154 uint8_t priority_layer_info_present_flag;
1155 uint8_t priority_id_setting_flag;
1156
1157 uint32_t num_layers;
1158 } scalability_info;
1159
1160 }SEI_messages;
1161
ResetH264SEIPayLoadBase1162 void Reset()
1163 {
1164 memset(this, 0, sizeof(H264SEIPayLoadBase));
1165
1166 payLoadType = UMC::SEI_RESERVED;
1167 payLoadSize = 0;
1168 }
1169 };
1170
1171 struct H264SEIPayLoad : public UMC::HeapObject, public H264SEIPayLoadBase
1172 {
1173 std::vector<uint8_t> user_data; // for UserDataRegistered or UserDataUnRegistered
1174
H264SEIPayLoadH264SEIPayLoad1175 H264SEIPayLoad()
1176 : H264SEIPayLoadBase()
1177 {
1178 }
1179
ResetH264SEIPayLoad1180 virtual void Reset()
1181 {
1182 H264SEIPayLoadBase::Reset();
1183 user_data.clear();
1184 }
1185
GetIDH264SEIPayLoad1186 int32_t GetID() const
1187 {
1188 return payLoadType;
1189 }
1190 };
1191 } // end of namespace UMC_H264_DECODER
1192
1193 namespace UMC
1194 {
1195
1196 enum
1197 {
1198 CHROMA_FORMAT_400 = 0,
1199 CHROMA_FORMAT_420 = 1,
1200 CHROMA_FORMAT_422 = 2,
1201 CHROMA_FORMAT_444 = 3
1202 };
1203
1204 ///////////////// New structures
1205
1206 struct ReferenceFlags // flags use for reference frames of slice
1207 {
1208 char field : 3;
1209 unsigned char isShortReference : 1;
1210 unsigned char isLongReference : 1;
1211 };
1212
1213 class h264_exception
1214 {
1215 public:
1216 h264_exception(int32_t status = -1)
m_Status(status)1217 : m_Status(status)
1218 {
1219 }
1220
~h264_exception()1221 virtual ~h264_exception()
1222 {
1223 }
1224
GetStatus()1225 int32_t GetStatus() const
1226 {
1227 return m_Status;
1228 }
1229
1230 private:
1231 int32_t m_Status;
1232 };
1233
1234 template <typename T>
h264_new_array_throw(int32_t size)1235 inline T * h264_new_array_throw(int32_t size)
1236 {
1237 T * t = new T[size];
1238 if (!t)
1239 throw h264_exception(UMC_ERR_ALLOC);
1240 return t;
1241 }
1242
1243 template <typename T>
h264_new_throw()1244 inline T * h264_new_throw()
1245 {
1246 T * t = new T();
1247 if (!t)
1248 throw h264_exception(UMC_ERR_ALLOC);
1249 return t;
1250 }
1251
GetUMCColorFormat(int32_t color_format)1252 inline ColorFormat GetUMCColorFormat(int32_t color_format)
1253 {
1254 ColorFormat format;
1255 switch(color_format)
1256 {
1257 case 0:
1258 format = GRAY;
1259 break;
1260 case 2:
1261 format = NV16;
1262 break;
1263 case 3:
1264 format = YUV444;
1265 break;
1266 case 1:
1267 default:
1268 format = NV12;
1269 break;
1270 }
1271
1272 return format;
1273 }
1274
GetH264ColorFormat(ColorFormat color_format)1275 inline int32_t GetH264ColorFormat(ColorFormat color_format)
1276 {
1277 int32_t format;
1278 switch(color_format)
1279 {
1280 case GRAY:
1281 case GRAYA:
1282 format = 0;
1283 break;
1284 case YUV422A:
1285 case YUV422:
1286 case NV16:
1287 format = 2;
1288 break;
1289 case YUV444:
1290 case YUV444A:
1291 format = 3;
1292 break;
1293 case YUV420:
1294 case YUV420A:
1295 case NV12:
1296 case YV12:
1297 default:
1298 format = 1;
1299 break;
1300 }
1301
1302 return format;
1303 }
1304
CalculateSuggestedSize(const UMC_H264_DECODER::H264SeqParamSet * sps)1305 inline size_t CalculateSuggestedSize(const UMC_H264_DECODER::H264SeqParamSet * sps)
1306 {
1307 size_t base_size = sps->frame_width_in_mbs * sps->frame_height_in_mbs * 256;
1308 size_t size = 0;
1309
1310 switch (sps->chroma_format_idc)
1311 {
1312 case 0: // YUV400
1313 size = base_size;
1314 break;
1315 case 1: // YUV420
1316 size = (base_size * 3) / 2;
1317 break;
1318 case 2: // YUV422
1319 size = base_size + base_size;
1320 break;
1321 case 3: // YUV444
1322 size = base_size + base_size + base_size;
1323 break;
1324 };
1325
1326 return size;
1327 }
1328
1329 extern const uint32_t SubWidthC[4];
1330 extern const uint32_t SubHeightC[4];
1331
1332 } // end namespace UMC
1333
1334
1335 #endif // __UMC_H264_DEC_DEFS_DEC_H__
1336 #endif // MFX_ENABLE_H264_VIDEO_DECODE
1337