summaryrefslogtreecommitdiff
path: root/drivers/frame_provider/decoder/h264_multi/h264_dpb.h (plain)
blob: 471ffa598be9b569f2c7e3fcb6d0f7232d616142
1/*
2* Copyright (C) 2017 Amlogic, Inc. All rights reserved.
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful, but WITHOUT
10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12* more details.
13*
14* You should have received a copy of the GNU General Public License along
15* with this program; if not, write to the Free Software Foundation, Inc.,
16* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*
18* Description:
19*/
20#ifndef H264_DPB_H_
21#define H264_DPB_H_
22
23#define ERROR_CHECK
24
25#define OUTPUT_BUFFER_IN_C
26
27#define PRINT_FLAG_ERROR 0x0
28#define PRINT_FLAG_VDEC_STATUS 0X0001
29#define PRINT_FLAG_UCODE_EVT 0x0002
30#define PRINT_FLAG_MMU_DETAIL 0x0004
31#define PRINT_FLAG_ERRORFLAG_DBG 0x0008
32#define PRINT_FLAG_DPB_DETAIL 0x0010
33#define PRINT_FLAG_DEC_DETAIL 0x0020
34#define PRINT_FLAG_VDEC_DETAIL 0x0040
35#define PRINT_FLAG_DUMP_DPB 0x0080
36#define PRINT_FRAMEBASE_DATA 0x0100
37#define PRINT_FLAG_DEBUG_POC 0x0200
38#define RRINT_FLAG_RPM 0x0400
39#define DEBUG_DISABLE_RUNREADY_RMBUF 0x0800
40#define PRINT_FLAG_DUMP_BUFSPEC 0x1000
41#define PRINT_FLAG_V4L_DETAIL 0x8000
42#define DISABLE_ERROR_HANDLE 0x10000
43#define DEBUG_DUMP_STAT 0x80000
44/*setting canvas mode and endian.
45 if this flag is set, value of canvas mode
46 will according to the value of mem_map_mode.
47 endian will be forced set to 0 in
48 CANVAS_BLKMODE_LINEAR mode.
49 otherwise picture will display abnormal.
50 if this flag is not set, value of canvas mode
51 will be determined by the user speace config.
52 endian will be set 7 in CANVAS_BLKMODE_LINEAR mode.
53*/
54#define IGNORE_PARAM_FROM_CONFIG 0x8000000
55
56
57#define PIC_SINGLE_FRAME 0
58#define PIC_TOP_BOT_TOP 1
59#define PIC_BOT_TOP_BOT 2
60#define PIC_DOUBLE_FRAME 3
61#define PIC_TRIPLE_FRAME 4
62#define PIC_TOP_BOT 5
63#define PIC_BOT_TOP 6
64#define PIC_INVALID 7
65
66#define MVC_EXTENSION_ENABLE 0
67#define PRINTREFLIST 0
68
69#define MAX_LIST_SIZE 33
70
71#define H264_OUTPUT_MODE_NORMAL 0x4
72#define H264_OUTPUT_MODE_FAST 0x8
73
74#define FALSE 0
75
76#define H264_SLICE_HEAD_DONE 0x01
77#define H264_PIC_DATA_DONE 0x02
78/*#define H264_SPS_DONE 0x03*/
79/*#define H264_PPS_DONE 0x04*/
80/*#define H264_SLICE_DATA_DONE 0x05*/
81/*#define H264_DATA_END 0x06*/
82
83#define H264_CONFIG_REQUEST 0x11
84#define H264_DATA_REQUEST 0x12
85#define H264_WRRSP_REQUEST 0x13
86#define H264_WRRSP_DONE 0x14
87
88#define H264_DECODE_BUFEMPTY 0x20
89#define H264_DECODE_TIMEOUT 0x21
90#define H264_SEARCH_BUFEMPTY 0x22
91#define H264_DECODE_OVER_SIZE 0x23
92
93#define VIDEO_SIGNAL_LOW 0x26
94#define VIDEO_SIGNAL_HIGHT 0x27
95
96
97#define H264_FIND_NEXT_PIC_NAL 0x50
98#define H264_FIND_NEXT_DVEL_NAL 0x51
99#define H264_AUX_DATA_READY 0x52
100
101#define H264_SEI_DATA_READY 0x53
102#define H264_SEI_DATA_DONE 0x54
103
104 /* 0x8x, search state*/
105#define H264_STATE_SEARCH_AFTER_SPS 0x80
106#define H264_STATE_SEARCH_AFTER_PPS 0x81
107#define H264_STATE_PARSE_SLICE_HEAD 0x82
108#define H264_STATE_SEARCH_HEAD 0x83
109 /**/
110#define H264_ACTION_SEARCH_HEAD 0xf0
111#define H264_ACTION_DECODE_SLICE 0xf1
112#define H264_ACTION_CONFIG_DONE 0xf2
113#define H264_ACTION_DECODE_NEWPIC 0xf3
114#define H264_ACTION_DECODE_START 0xff
115
116#define RPM_BEGIN 0x0
117#define RPM_END 0x400
118
119#define val(s) (s[0]|(s[1]<<16))
120
121#define FRAME_IN_DPB 24
122#define DPB_OFFSET 0x100
123#define MMCO_OFFSET 0x200
124union param {
125#if 0
126#define H_TIME_STAMP_START 0X00
127#define H_TIME_STAMP_END 0X17
128#define PTS_ZERO_0 0X18
129#define PTS_ZERO_1 0X19
130#endif
131#define FIXED_FRAME_RATE_FLAG 0X21
132
133#define OFFSET_DELIMITER_LO 0x2f
134#define OFFSET_DELIMITER_HI 0x30
135
136
137#define SLICE_IPONLY_BREAK 0X5C
138#define PREV_MAX_REFERENCE_FRAME_NUM 0X5D
139#define EOS 0X5E
140#define FRAME_PACKING_TYPE 0X5F
141#define OLD_POC_PAR_1 0X60
142#define OLD_POC_PAR_2 0X61
143#define PREV_MBX 0X62
144#define PREV_MBY 0X63
145#define ERROR_SKIP_MB_NUM 0X64
146#define ERROR_MB_STATUS 0X65
147#define L0_PIC0_STATUS 0X66
148#define TIMEOUT_COUNTER 0X67
149#define BUFFER_SIZE 0X68
150#define BUFFER_SIZE_HI 0X69
151#define CROPPING_LEFT_RIGHT 0X6A
152#define CROPPING_TOP_BOTTOM 0X6B
153#if 1
154 /* sps_flags2:
155 *bit 3, bitstream_restriction_flag
156 *bit 2, pic_struct_present_flag
157 *bit 1, vcl_hrd_parameters_present_flag
158 *bit 0, nal_hrd_parameters_present_flag
159 */
160#define SPS_FLAGS2 0x6c
161#define NUM_REORDER_FRAMES 0x6d
162#else
163#define POC_SELECT_NEED_SWAP 0X6C
164#define POC_SELECT_SWAP 0X6D
165#endif
166#define MAX_BUFFER_FRAME 0X6E
167
168#define NON_CONFORMING_STREAM 0X70
169#define RECOVERY_POINT 0X71
170#define POST_CANVAS 0X72
171#define POST_CANVAS_H 0X73
172#define SKIP_PIC_COUNT 0X74
173#define TARGET_NUM_SCALING_LIST 0X75
174#define FF_POST_ONE_FRAME 0X76
175#define PREVIOUS_BIT_CNT 0X77
176#define MB_NOT_SHIFT_COUNT 0X78
177#define PIC_STATUS 0X79
178#define FRAME_COUNTER 0X7A
179#define NEW_SLICE_TYPE 0X7B
180#define NEW_PICTURE_STRUCTURE 0X7C
181#define NEW_FRAME_NUM 0X7D
182#define NEW_IDR_PIC_ID 0X7E
183#define IDR_PIC_ID 0X7F
184
185/* h264 LOCAL */
186#define NAL_UNIT_TYPE 0X80
187#define NAL_REF_IDC 0X81
188#define SLICE_TYPE 0X82
189#define LOG2_MAX_FRAME_NUM 0X83
190#define FRAME_MBS_ONLY_FLAG 0X84
191#define PIC_ORDER_CNT_TYPE 0X85
192#define LOG2_MAX_PIC_ORDER_CNT_LSB 0X86
193#define PIC_ORDER_PRESENT_FLAG 0X87
194#define REDUNDANT_PIC_CNT_PRESENT_FLAG 0X88
195#define PIC_INIT_QP_MINUS26 0X89
196#define DEBLOCKING_FILTER_CONTROL_PRESENT_FLAG 0X8A
197#define NUM_SLICE_GROUPS_MINUS1 0X8B
198#define MODE_8X8_FLAGS 0X8C
199#define ENTROPY_CODING_MODE_FLAG 0X8D
200#define SLICE_QUANT 0X8E
201#define TOTAL_MB_HEIGHT 0X8F
202#define PICTURE_STRUCTURE 0X90
203#define TOP_INTRA_TYPE 0X91
204#define RV_AI_STATUS 0X92
205#define AI_READ_START 0X93
206#define AI_WRITE_START 0X94
207#define AI_CUR_BUFFER 0X95
208#define AI_DMA_BUFFER 0X96
209#define AI_READ_OFFSET 0X97
210#define AI_WRITE_OFFSET 0X98
211#define AI_WRITE_OFFSET_SAVE 0X99
212#define RV_AI_BUFF_START 0X9A
213#define I_PIC_MB_COUNT 0X9B
214#define AI_WR_DCAC_DMA_CTRL 0X9C
215#define SLICE_MB_COUNT 0X9D
216#define PICTYPE 0X9E
217#define SLICE_GROUP_MAP_TYPE 0X9F
218#define MB_TYPE 0XA0
219#define MB_AFF_ADDED_DMA 0XA1
220#define PREVIOUS_MB_TYPE 0XA2
221#define WEIGHTED_PRED_FLAG 0XA3
222#define WEIGHTED_BIPRED_IDC 0XA4
223/* bit 3:2 - PICTURE_STRUCTURE
224 * bit 1 - MB_ADAPTIVE_FRAME_FIELD_FLAG
225 * bit 0 - FRAME_MBS_ONLY_FLAG
226 */
227#define MBFF_INFO 0XA5
228#define TOP_INTRA_TYPE_TOP 0XA6
229
230#define RV_AI_BUFF_INC 0xa7
231
232#define DEFAULT_MB_INFO_LO 0xa8
233
234/* 0 -- no need to read
235 * 1 -- need to wait Left
236 * 2 -- need to read Intra
237 * 3 -- need to read back MV
238 */
239#define NEED_READ_TOP_INFO 0xa9
240/* 0 -- idle
241 * 1 -- wait Left
242 * 2 -- reading top Intra
243 * 3 -- reading back MV
244 */
245#define READ_TOP_INFO_STATE 0xaa
246#define DCAC_MBX 0xab
247#define TOP_MB_INFO_OFFSET 0xac
248#define TOP_MB_INFO_RD_IDX 0xad
249#define TOP_MB_INFO_WR_IDX 0xae
250
251#define VLD_NO_WAIT 0
252#define VLD_WAIT_BUFFER 1
253#define VLD_WAIT_HOST 2
254#define VLD_WAIT_GAP 3
255
256#define VLD_WAITING 0xaf
257
258#define MB_X_NUM 0xb0
259/* #define MB_WIDTH 0xb1 */
260#define MB_HEIGHT 0xb2
261#define MBX 0xb3
262#define TOTAL_MBY 0xb4
263#define INTR_MSK_SAVE 0xb5
264
265/* #define has_time_stamp 0xb6 */
266#define NEED_DISABLE_PPE 0xb6
267#define IS_NEW_PICTURE 0XB7
268#define PREV_NAL_REF_IDC 0XB8
269#define PREV_NAL_UNIT_TYPE 0XB9
270#define FRAME_MB_COUNT 0XBA
271#define SLICE_GROUP_UCODE 0XBB
272#define SLICE_GROUP_CHANGE_RATE 0XBC
273#define SLICE_GROUP_CHANGE_CYCLE_LEN 0XBD
274#define DELAY_LENGTH 0XBE
275#define PICTURE_STRUCT 0XBF
276/* #define pre_picture_struct 0xc0 */
277#define DCAC_PREVIOUS_MB_TYPE 0xc1
278
279#define TIME_STAMP 0XC2
280#define H_TIME_STAMP 0XC3
281#define VPTS_MAP_ADDR 0XC4
282#define H_VPTS_MAP_ADDR 0XC5
283
284/*#define MAX_DPB_SIZE 0XC6*/
285#define PIC_INSERT_FLAG 0XC7
286
287#define TIME_STAMP_START 0XC8
288#define TIME_STAMP_END 0XDF
289
290#define OFFSET_FOR_NON_REF_PIC 0XE0
291#define OFFSET_FOR_TOP_TO_BOTTOM_FIELD 0XE2
292#define MAX_REFERENCE_FRAME_NUM 0XE4
293#define FRAME_NUM_GAP_ALLOWED 0XE5
294#define NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE 0XE6
295#define PROFILE_IDC_MMCO 0XE7
296#define LEVEL_IDC_MMCO 0XE8
297#define FRAME_SIZE_IN_MB 0XE9
298#define DELTA_PIC_ORDER_ALWAYS_ZERO_FLAG 0XEA
299#define PPS_NUM_REF_IDX_L0_ACTIVE_MINUS1 0XEB
300#define PPS_NUM_REF_IDX_L1_ACTIVE_MINUS1 0XEC
301#define CURRENT_SPS_ID 0XED
302#define CURRENT_PPS_ID 0XEE
303/* bit 0 - sequence parameter set may change
304 * bit 1 - picture parameter set may change
305 * bit 2 - new dpb just inited
306 * bit 3 - IDR picture not decoded yet
307 * bit 5:4 - 0: mb level code loaded 1: picture
308 * level code loaded 2: slice level code loaded
309 */
310#define DECODE_STATUS 0XEF
311#define FIRST_MB_IN_SLICE 0XF0
312#define PREV_MB_WIDTH 0XF1
313#define PREV_FRAME_SIZE_IN_MB 0XF2
314/*#define MAX_REFERENCE_FRAME_NUM_IN_MEM 0XF3*/
315/* bit 0 - aspect_ratio_info_present_flag
316 * bit 1 - timing_info_present_flag
317 * bit 2 - nal_hrd_parameters_present_flag
318 * bit 3 - vcl_hrd_parameters_present_flag
319 * bit 4 - pic_struct_present_flag
320 * bit 5 - bitstream_restriction_flag
321 */
322#define VUI_STATUS 0XF4
323#define ASPECT_RATIO_IDC 0XF5
324#define ASPECT_RATIO_SAR_WIDTH 0XF6
325#define ASPECT_RATIO_SAR_HEIGHT 0XF7
326#define NUM_UNITS_IN_TICK 0XF8
327#define TIME_SCALE 0XFA
328#define CURRENT_PIC_INFO 0XFC
329#define DPB_BUFFER_INFO 0XFD
330#define REFERENCE_POOL_INFO 0XFE
331#define REFERENCE_LIST_INFO 0XFF
332 struct{
333 unsigned short data[RPM_END-RPM_BEGIN];
334 } l;
335 struct{
336 unsigned short dump[DPB_OFFSET];
337 unsigned short dpb_base[FRAME_IN_DPB<<3];
338
339 unsigned short dpb_max_buffer_frame;
340 unsigned short actual_dpb_size;
341
342 unsigned short colocated_buf_status;
343
344 unsigned short num_forward_short_term_reference_pic;
345 unsigned short num_short_term_reference_pic;
346 unsigned short num_reference_pic;
347
348 unsigned short current_dpb_index;
349 unsigned short current_decoded_frame_num;
350 unsigned short current_reference_frame_num;
351
352 unsigned short l0_size;
353 unsigned short l1_size;
354
355 /* [6:5] : nal_ref_idc */
356 /* [4:0] : nal_unit_type */
357 unsigned short NAL_info_mmco;
358
359 /* [1:0] : 00 - top field, 01 - bottom field,
360 * 10 - frame, 11 - mbaff frame
361 */
362 unsigned short picture_structure_mmco;
363
364 unsigned short frame_num;
365 unsigned short pic_order_cnt_lsb;
366
367 unsigned short num_ref_idx_l0_active_minus1;
368 unsigned short num_ref_idx_l1_active_minus1;
369
370 unsigned short PrevPicOrderCntLsb;
371 unsigned short PreviousFrameNum;
372
373 /* 32 bits variables */
374 unsigned short delta_pic_order_cnt_bottom[2];
375 unsigned short delta_pic_order_cnt_0[2];
376 unsigned short delta_pic_order_cnt_1[2];
377
378 unsigned short PrevPicOrderCntMsb[2];
379 unsigned short PrevFrameNumOffset[2];
380
381 unsigned short frame_pic_order_cnt[2];
382 unsigned short top_field_pic_order_cnt[2];
383 unsigned short bottom_field_pic_order_cnt[2];
384
385 unsigned short colocated_mv_addr_start[2];
386 unsigned short colocated_mv_addr_end[2];
387 unsigned short colocated_mv_wr_addr[2];
388 } dpb;
389 struct {
390 unsigned short dump[MMCO_OFFSET];
391
392 /* array base address for offset_for_ref_frame */
393 unsigned short offset_for_ref_frame_base[128];
394
395 /* 0 - Index in DPB
396 * 1 - Picture Flag
397 * [ 2] : 0 - short term reference,
398 * 1 - long term reference
399 * [ 1] : bottom field
400 * [ 0] : top field
401 * 2 - Picture Number (short term or long term) low 16 bits
402 * 3 - Picture Number (short term or long term) high 16 bits
403 */
404 unsigned short reference_base[128];
405
406 /* command and parameter, until command is 3 */
407 unsigned short l0_reorder_cmd[66];
408 unsigned short l1_reorder_cmd[66];
409
410 /* command and parameter, until command is 0 */
411 unsigned short mmco_cmd[44];
412
413 unsigned short l0_base[40];
414 unsigned short l1_base[40];
415 } mmco;
416 struct {
417 /* from ucode lmem, do not change this struct */
418 } p;
419};
420
421
422struct StorablePicture;
423struct VideoParameters;
424struct DecodedPictureBuffer;
425
426/* New enum for field processing */
427enum PictureStructure {
428 FRAME,
429 TOP_FIELD,
430 BOTTOM_FIELD
431};
432
433#define I_Slice 2
434#define P_Slice 5
435#define B_Slice 6
436#define P_Slice_0 0
437#define B_Slice_1 1
438#define I_Slice_7 7
439
440enum SliceType {
441 P_SLICE = 0,
442 B_SLICE = 1,
443 I_SLICE = 2,
444 SP_SLICE = 3,
445 SI_SLICE = 4,
446 NUM_SLICE_TYPES = 5
447};
448
449enum ProfileIDC {
450 FREXT_CAVLC444 = 44, /*!< YUV 4:4:4/14 "CAVLC 4:4:4"*/
451 BASELINE = 66, /*!< YUV 4:2:0/8 "Baseline"*/
452 MAIN = 77, /*!< YUV 4:2:0/8 "Main"*/
453 EXTENDED = 88, /*!< YUV 4:2:0/8 "Extended"*/
454 FREXT_HP = 100, /*!< YUV 4:2:0/8 "High"*/
455 FREXT_Hi10P = 110, /*!< YUV 4:2:0/10 "High 10"*/
456 FREXT_Hi422 = 122, /*!< YUV 4:2:2/10 "High 4:2:2"*/
457 FREXT_Hi444 = 244, /*!< YUV 4:4:4/14 "High 4:4:4"*/
458 MVC_HIGH = 118, /*!< YUV 4:2:0/8 "Multiview High"*/
459 STEREO_HIGH = 128 /*!< YUV 4:2:0/8 "Stereo High"*/
460};
461
462enum FirstInsertFrm_State {
463 FirstInsertFrm_IDLE = 0,
464 FirstInsertFrm_OUT = 1,
465 FirstInsertFrm_SKIPDONE = 2,
466};
467
468
469struct SPSParameters {
470 unsigned int profile_idc;
471 int pic_order_cnt_type;
472 int log2_max_pic_order_cnt_lsb_minus4;
473 int num_ref_frames_in_pic_order_cnt_cycle;
474 short offset_for_ref_frame[128];
475 short offset_for_non_ref_pic;
476 short offset_for_top_to_bottom_field;
477
478 /**/
479 int frame_mbs_only_flag;
480 int num_ref_frames;
481 int max_dpb_size;
482
483 int log2_max_frame_num_minus4;
484};
485
486#define DEC_REF_PIC_MARKING_BUFFER_NUM_MAX 45
487struct DecRefPicMarking_s {
488 int memory_management_control_operation;
489 int difference_of_pic_nums_minus1;
490 int long_term_pic_num;
491 int long_term_frame_idx;
492 int max_long_term_frame_idx_plus1;
493 struct DecRefPicMarking_s *Next;
494};
495
496#define REORDERING_COMMAND_MAX_SIZE 33
497struct Slice {
498 int first_mb_in_slice;
499 int mode_8x8_flags;
500 int picture_structure_mmco;
501
502 int frame_num;
503 int idr_flag;
504 int toppoc;
505 int bottompoc;
506 int framepoc;
507 int pic_order_cnt_lsb;
508 int PicOrderCntMsb;
509 unsigned char field_pic_flag;
510 unsigned char bottom_field_flag;
511 int ThisPOC;
512 int nal_reference_idc;
513 int AbsFrameNum;
514 int delta_pic_order_cnt_bottom;
515 int delta_pic_order_cnt[2];
516
517 /**/
518 char listXsize[6];
519 struct StorablePicture *listX[6][MAX_LIST_SIZE * 2];
520
521 /**/
522 enum PictureStructure structure;
523 int long_term_reference_flag;
524 int no_output_of_prior_pics_flag;
525 int adaptive_ref_pic_buffering_flag;
526
527 struct VideoParameters *p_Vid;
528 struct DecodedPictureBuffer *p_Dpb;
529 int num_ref_idx_active[2]; /* number of available list references */
530
531 /*modification*/
532 int slice_type; /* slice type */
533 int ref_pic_list_reordering_flag[2];
534 int modification_of_pic_nums_idc[2][REORDERING_COMMAND_MAX_SIZE];
535 int abs_diff_pic_num_minus1[2][REORDERING_COMMAND_MAX_SIZE];
536 int long_term_pic_idx[2][REORDERING_COMMAND_MAX_SIZE];
537 /**/
538 unsigned char dec_ref_pic_marking_buffer_valid;
539 struct DecRefPicMarking_s
540 dec_ref_pic_marking_buffer[DEC_REF_PIC_MARKING_BUFFER_NUM_MAX];
541 int pic_struct;
542};
543
544struct OldSliceParams {
545 unsigned int field_pic_flag;
546 unsigned int frame_num;
547 int nal_ref_idc;
548 unsigned int pic_oder_cnt_lsb;
549 int delta_pic_oder_cnt_bottom;
550 int delta_pic_order_cnt[2];
551 unsigned char bottom_field_flag;
552 unsigned char idr_flag;
553 int idr_pic_id;
554 int pps_id;
555#if (MVC_EXTENSION_ENABLE)
556 int view_id;
557 int inter_view_flag;
558 int anchor_pic_flag;
559#endif
560 int layer_id;
561};
562
563struct VideoParameters {
564 int PrevPicOrderCntMsb;
565 int PrevPicOrderCntLsb;
566 unsigned char last_has_mmco_5;
567 unsigned char last_pic_bottom_field;
568 int ThisPOC;
569 int PreviousFrameNum;
570 int FrameNumOffset;
571 int PreviousFrameNumOffset;
572 int max_frame_num;
573 unsigned int pre_frame_num;
574 int ExpectedDeltaPerPicOrderCntCycle;
575 int PicOrderCntCycleCnt;
576 int FrameNumInPicOrderCntCycle;
577 int ExpectedPicOrderCnt;
578
579 /**/
580 struct SPSParameters *active_sps;
581 struct Slice **ppSliceList;
582 int iSliceNumOfCurrPic;
583 int conceal_mode;
584 int earlier_missing_poc;
585 int pocs_in_dpb[100];
586
587 struct OldSliceParams old_slice;
588 /**/
589 struct StorablePicture *dec_picture;
590 struct StorablePicture *no_reference_picture;
591
592 /*modification*/
593 int non_conforming_stream;
594 int recovery_point;
595};
596
597static inline int imin(int a, int b)
598{
599 return ((a) < (b)) ? (a) : (b);
600}
601
602static inline int imax(int a, int b)
603{
604 return ((a) > (b)) ? (a) : (b);
605}
606
607#define MAX_PIC_BUF_NUM 128
608#define MAX_NUM_SLICES 50
609
610struct StorablePicture {
611/**/
612 int width;
613 int height;
614
615 int y_canvas_index;
616 int u_canvas_index;
617 int v_canvas_index;
618/**/
619 int index;
620 unsigned char is_used;
621
622 enum PictureStructure structure;
623
624 int poc;
625 int top_poc;
626 int bottom_poc;
627 int frame_poc;
628 unsigned int frame_num;
629 unsigned int recovery_frame;
630
631 int pic_num;
632 int buf_spec_num;
633 int buf_spec_is_alloced;
634 int colocated_buf_index;
635 int long_term_pic_num;
636 int long_term_frame_idx;
637
638 unsigned char is_long_term;
639 int used_for_reference;
640 int is_output;
641#if 1
642 /* rain */
643 int pre_output;
644#endif
645 int non_existing;
646 int separate_colour_plane_flag;
647
648 short max_slice_id;
649
650 int size_x, size_y, size_x_cr, size_y_cr;
651 int size_x_m1, size_y_m1, size_x_cr_m1, size_y_cr_m1;
652 int coded_frame;
653 int mb_aff_frame_flag;
654 unsigned int PicWidthInMbs;
655 unsigned int PicSizeInMbs;
656 int iLumaPadY, iLumaPadX;
657 int iChromaPadY, iChromaPadX;
658
659 /* for mb aff, if frame for referencing the top field */
660 struct StorablePicture *top_field;
661 /* for mb aff, if frame for referencing the bottom field */
662 struct StorablePicture *bottom_field;
663 /* for mb aff, if field for referencing the combined frame */
664 struct StorablePicture *frame;
665
666 int slice_type;
667 int idr_flag;
668 int no_output_of_prior_pics_flag;
669 int long_term_reference_flag;
670 int adaptive_ref_pic_buffering_flag;
671
672 int chroma_format_idc;
673 int frame_mbs_only_flag;
674 int frame_cropping_flag;
675 int frame_crop_left_offset;
676 int frame_crop_right_offset;
677 int frame_crop_top_offset;
678 int frame_crop_bottom_offset;
679 int qp;
680 int chroma_qp_offset[2];
681 int slice_qp_delta;
682 /* stores the memory management control operations */
683 struct DecRefPicMarking_s *dec_ref_pic_marking_buffer;
684
685 /* picture error concealment */
686 /*indicates if this is a concealed picture */
687 int concealed_pic;
688
689 /* variables for tone mapping */
690 int seiHasTone_mapping;
691 int tone_mapping_model_id;
692 int tonemapped_bit_depth;
693 /* imgpel* tone_mapping_lut; tone mapping look up table */
694
695 int proc_flag;
696#if (MVC_EXTENSION_ENABLE)
697 int view_id;
698 int inter_view_flag;
699 int anchor_pic_flag;
700#endif
701 int iLumaStride;
702 int iChromaStride;
703 int iLumaExpandedHeight;
704 int iChromaExpandedHeight;
705 /* imgpel **cur_imgY; for more efficient get_block_luma */
706 int no_ref;
707 int iCodingType;
708
709 char listXsize[MAX_NUM_SLICES][2];
710 struct StorablePicture **listX[MAX_NUM_SLICES][2];
711 int layer_id;
712 u32 offset_delimiter;
713 u32 pts;
714 u64 pts64;
715 u64 timestamp;
716 unsigned char data_flag;
717 int pic_struct;
718
719 /* picture qos infomation*/
720 int frame_size;
721 int max_qp;
722 int avg_qp;
723 int min_qp;
724 int max_skip;
725 int avg_skip;
726 int min_skip;
727 int max_mv;
728 int min_mv;
729 int avg_mv;
730};
731
732struct FrameStore {
733 /* rain */
734 int buf_spec_num;
735 /* rain */
736 int colocated_buf_index;
737
738 /* 0=empty; 1=top; 2=bottom; 3=both fields (or frame) */
739 int is_used;
740 /* 0=not used for ref; 1=top used; 2=bottom used;
741 * 3=both fields (or frame) used
742 */
743 int is_reference;
744 /* 0=not used for ref; 1=top used; 2=bottom used;
745 * 3=both fields (or frame) used
746 */
747 int is_long_term;
748 /* original marking by nal_ref_idc: 0=not used for ref; 1=top used;
749 * 2=bottom used; 3=both fields (or frame) used
750 */
751 int is_orig_reference;
752
753 int is_non_existent;
754
755 unsigned int frame_num;
756 unsigned int recovery_frame;
757
758 int frame_num_wrap;
759 int long_term_frame_idx;
760 int is_output;
761#if 1
762 /* rain */
763 int pre_output;
764 /* index in gFrameStore */
765 int index;
766#define I_FLAG 0x01
767#define IDR_FLAG 0x02
768#define ERROR_FLAG 0x10
769#define NULL_FLAG 0x20
770#define NODISP_FLAG 0x80
771 unsigned char data_flag;
772#endif
773 int poc;
774
775 /* picture error concealment */
776 int concealment_reference;
777
778 struct StorablePicture *frame;
779 struct StorablePicture *top_field;
780 struct StorablePicture *bottom_field;
781
782#if (MVC_EXTENSION_ENABLE)
783 int view_id;
784 int inter_view_flag[2];
785 int anchor_pic_flag[2];
786#endif
787 int layer_id;
788 u32 offset_delimiter;
789 u32 pts;
790 u64 pts64;
791 u64 timestamp;
792
793
794 /* picture qos infomation*/
795 int slice_type;
796 int frame_size;
797
798 int max_qp;
799 int avg_qp;
800 int min_qp;
801 int max_skip;
802 int avg_skip;
803 int min_skip;
804 int max_mv;
805 int min_mv;
806 int avg_mv;
807};
808
809
810/* #define DPB_SIZE_MAX 16 */
811#define DPB_SIZE_MAX 32
812struct DecodedPictureBuffer {
813 struct VideoParameters *p_Vid;
814 /* InputParameters *p_Inp; ??? */
815 struct FrameStore *fs[DPB_SIZE_MAX];
816 struct FrameStore *fs_ref[DPB_SIZE_MAX];
817 struct FrameStore *fs_ltref[DPB_SIZE_MAX];
818 /* inter-layer reference (for multi-layered codecs) */
819 struct FrameStore *fs_ilref[DPB_SIZE_MAX];
820 /**/
821 struct FrameStore *fs_list0[DPB_SIZE_MAX];
822 struct FrameStore *fs_list1[DPB_SIZE_MAX];
823 struct FrameStore *fs_listlt[DPB_SIZE_MAX];
824
825 /**/
826 unsigned int size;
827 unsigned int used_size;
828 unsigned int ref_frames_in_buffer;
829 unsigned int ltref_frames_in_buffer;
830 int last_output_poc;
831#if (MVC_EXTENSION_ENABLE)
832 int last_output_view_id;
833#endif
834 int max_long_term_pic_idx;
835
836
837 int init_done;
838 int first_pic_done; /*by rain*/
839 int num_ref_frames;
840
841 struct FrameStore *last_picture;
842 unsigned int used_size_il;
843 int layer_id;
844
845 /* DPB related function; */
846};
847
848struct h264_dpb_stru {
849 struct vdec_s *vdec;
850 int decoder_index;
851
852 union param dpb_param;
853
854 int decode_idx;
855 int buf_num;
856 int curr_POC;
857 int reorder_pic_num;
858 u8 fast_output_enable;
859 /*poc_even_flag:
860 0, init; 1, odd; 2, even*/
861 u8 poc_even_odd_flag;
862 u32 decode_pic_count;
863 /**/
864 unsigned int max_reference_size;
865
866 unsigned int colocated_buf_map;
867 unsigned int colocated_buf_count;
868 unsigned int colocated_mv_addr_start;
869 unsigned int colocated_mv_addr_end;
870 unsigned int colocated_buf_size;
871
872 struct DecodedPictureBuffer mDPB;
873 struct Slice mSlice;
874 struct VideoParameters mVideo;
875 struct SPSParameters mSPS;
876
877 struct StorablePicture m_PIC[MAX_PIC_BUF_NUM];
878 struct FrameStore mFrameStore[DPB_SIZE_MAX];
879
880 /*vui*/
881 unsigned int vui_status;
882 unsigned int num_units_in_tick;
883 unsigned int time_scale;
884 unsigned int fixed_frame_rate_flag;
885 unsigned int aspect_ratio_idc;
886 unsigned int aspect_ratio_sar_width;
887 unsigned int aspect_ratio_sar_height;
888 u8 bitstream_restriction_flag;
889 u16 num_reorder_frames;
890 u16 max_dec_frame_buffering;
891
892 unsigned int dec_dpb_status;
893 unsigned int last_dpb_status;
894 unsigned char buf_alloc_fail;
895 unsigned int dpb_error_flag;
896 unsigned int origin_max_reference;
897 unsigned int first_insert_frame;
898 int first_output_poc;
899};
900
901
902extern unsigned int h264_debug_flag;
903extern unsigned int h264_debug_mask;
904
905int dpb_print(int indext, int debug_flag, const char *fmt, ...);
906
907int dpb_print_cont(int index, int debug_flag, const char *fmt, ...);
908
909unsigned char dpb_is_debug(int index, int debug_flag);
910
911int prepare_display_buf(struct vdec_s *vdec, struct FrameStore *frame);
912
913int release_buf_spec_num(struct vdec_s *vdec, int buf_spec_num);
914
915void set_frame_output_flag(struct h264_dpb_stru *p_H264_Dpb, int index);
916
917int is_there_unused_frame_from_dpb(struct DecodedPictureBuffer *p_Dpb);
918
919int h264_slice_header_process(struct h264_dpb_stru *p_H264_Dpb);
920
921void dpb_init_global(struct h264_dpb_stru *p_H264_Dpb,
922 int id, int actual_dpb_size, int max_reference_size);
923
924void init_colocate_buf(struct h264_dpb_stru *p_H264_Dpb, int count);
925
926int release_colocate_buf(struct h264_dpb_stru *p_H264_Dpb, int index);
927
928int get_free_buf_idx(struct vdec_s *vdec);
929
930int store_picture_in_dpb(struct h264_dpb_stru *p_H264_Dpb,
931 struct StorablePicture *p, unsigned char data_flag);
932
933int release_picture(struct h264_dpb_stru *p_H264_Dpb,
934 struct StorablePicture *pic);
935
936void remove_dpb_pictures(struct h264_dpb_stru *p_H264_Dpb);
937
938void bufmgr_post(struct h264_dpb_stru *p_H264_Dpb);
939
940void bufmgr_force_recover(struct h264_dpb_stru *p_H264_Dpb);
941
942int get_long_term_flag_by_buf_spec_num(struct h264_dpb_stru *p_H264_Dpb,
943 int buf_spec_num);
944
945void bufmgr_h264_remove_unused_frame(struct h264_dpb_stru *p_H264_Dpb,
946 u8 force_flag);
947
948void flush_dpb(struct h264_dpb_stru *p_H264_Dpb);
949
950void print_pic_info(int decindex, const char *info,
951 struct StorablePicture *pic,
952 int slice_type);
953void dump_dpb(struct DecodedPictureBuffer *p_Dpb, u8 force);
954
955void dump_pic(struct h264_dpb_stru *p_H264_Dpb);
956
957enum PictureStructure get_cur_slice_picture_struct(
958 struct h264_dpb_stru *p_H264_Dpb);
959
960int dpb_check_ref_list_error(
961 struct h264_dpb_stru *p_H264_Dpb);
962#endif
963