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