shithub: hantro9

Download patch

ref: 96ecd420fa40b629e6200c7fcbd85d00ad83e139
parent: 1cc6febfeccb6d720972dfb09611341bbf49983d
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Apr 30 12:15:42 EDT 2023

more updates and fixes

--- a/hantest.c
+++ b/hantest.c
@@ -5,11 +5,15 @@
 
 enum {
 	DecodeH264,
+
+	Baseline = 66,
+	High = 100,
 };
 
 typedef struct VPUctx VPUctx;
 
 struct VPUctx {
+	int process;
 	int slen;
 
 	union {
@@ -29,9 +33,9 @@
 				u8int seq_scaling_matrix_present_flag;
 			}sps;
 			struct {
-				u8int chroma_qp_index_offset;
-				u8int pic_init_qp_minus26;
-				u8int second_chroma_qp_index_offset;
+				s8int chroma_qp_index_offset;
+				s8int pic_init_qp_minus26;
+				s8int second_chroma_qp_index_offset;
 				u8int weighted_bipred_idc;
 				u8int pic_parameter_set_id;
 				u8int num_ref_idx_l0_default_active_minus1;
@@ -60,8 +64,6 @@
 	};
 };
 
-static int process;
-
 static u32int *g1, *g2;
 
 static void
@@ -77,9 +79,9 @@
 	         (c->sps.mb_adaptive_frame_field_flag || c->sh.field_pic_flag)) << SW_PIC_INTERLACE_E |
 		(c->sps.frame_mbs_only_flag == 0 && c->sh.field_pic_flag) << SW_PIC_FIELDMODE_E |
 		(c->sps.frame_mbs_only_flag == 0 && c->sh.bottom_field_flag == 0) << SW_PIC_TOPFIELD_E |
-		(c->sps.profile_idc > 66 && c->sps.nal_ref_idc != 0) << SW_WRITE_MVS_E |
+		(c->sps.profile_idc > Baseline && c->sps.nal_ref_idc != 0) << SW_WRITE_MVS_E |
 		c->sps.mb_adaptive_frame_field_flag << SW_SEQ_MBAFF_E |
-		(c->sps.profile_idc > 66) << SW_PICORD_COUNT_E |
+		(c->sps.profile_idc > Baseline) << SW_PICORD_COUNT_E |
 		0xff << SW_DEC_AXI_WR_ID;
 
 	g1[4] = (c->sps.pic_width_in_mbs_minus1 + 1) << SW_PIC_MB_WIDTH |
@@ -88,8 +90,8 @@
 
 	g1[5] = 0 << SW_STRM_START_BIT |
 		c->pps.pic_scaling_matrix_present_flag << SW_TYPE1_QUANT_E |
-		c->pps.chroma_qp_index_offset << SW_CH_QP_OFFSET |
-		c->pps.second_chroma_qp_index_offset << SW_CH_QP_OFFSET2 |
+		(c->pps.chroma_qp_index_offset & ((1<<5)-1)) << SW_CH_QP_OFFSET |
+		(c->pps.second_chroma_qp_index_offset & ((1<<5)-1)) << SW_CH_QP_OFFSET2 |
 		(c->sps.frame_mbs_only_flag == 0) << SW_FIELDPIC_FLAG_E;
 
 	g1[6] = 1 << SW_START_CODE_E |
@@ -97,7 +99,7 @@
 		c->slen << SW_STREAM_LEN;
 
 	g1[7] = c->pps.entropy_coding_mode_flag << SW_CABAC_E |
-		(c->sps.chroma_format_idc == 0 && c->sps.profile_idc >= 100) << SW_BLACKWHITE_E |
+		(c->sps.chroma_format_idc == 0 && c->sps.profile_idc >= High) << SW_BLACKWHITE_E |
 		c->sps.direct_8x8_inference_flag << SW_DIR_8X8_INFER_E |
 		c->pps.weighted_pred_flag << SW_WEIGHT_PRED_E |
 		c->pps.weighted_bipred_idc << SW_WEIGHT_BIPR_IDC |
@@ -130,23 +132,25 @@
 	char *a[4];
 	int n, x;
 
+	if((n = tokenize(s, a, nelem(a))) < 2)
+		return -1;
+
 #define value(name, field, min, max) \
 	if(strcmp(a[1], name) == 0){ \
-		if(x < (min) || x > (max)) \
+		if(x < (min) || x > (max)){ \
+			werrstr("%s: out of range [%d, %d]", a[1], (min), (max)); \
 			return -1; \
+		} \
 		field = x; \
 		return 0; \
 	}
 
-	if((n = tokenize(s, a, nelem(a))) < 2)
-		return -1;
-
 	if(strcmp(a[0], "decode") == 0){
 		if(n == 2 && strcmp(a[1], "h.264") == 0){
-			process = DecodeH264;
+			c->process = DecodeH264;
 			return 0;
 		}
-	}else if(process == DecodeH264 && n == 3){
+	}else if(c->process == DecodeH264 && n == 3){
 		x = atoi(a[2]);
 		if(strcmp(a[0], "sps") == 0){
 			value("pic_height_in_map_units_minus1", c->sps.pic_height_in_map_units_minus1, 0, 0xff);
@@ -161,13 +165,13 @@
 			value("mb_adaptive_frame_field_flag", c->sps.mb_adaptive_frame_field_flag, 0, 1);
 			value("seq_scaling_matrix_present_flag", c->sps.seq_scaling_matrix_present_flag, 0, 1);
 		}else if(strcmp(a[0], "pps") == 0){
-			value("chroma_qp_index_offset", c->pps.chroma_qp_index_offset, 0, (1<<5)-1);
-			value("pic_init_qp_minus26", c->pps.pic_init_qp_minus26, 0, (1<<6)-1);
-			value("second_chroma_qp_index_offset", c->pps.second_chroma_qp_index_offset, 0, (1<<5)-1);
+			value("chroma_qp_index_offset", c->pps.chroma_qp_index_offset, -12, 12);
+			value("pic_init_qp_minus26", c->pps.pic_init_qp_minus26, -26, 25);
+			value("second_chroma_qp_index_offset", c->pps.second_chroma_qp_index_offset, -12, 12);
 			value("weighted_bipred_idc", c->pps.weighted_bipred_idc, 0, 2);
 			value("pic_parameter_set_id", c->pps.pic_parameter_set_id, 0, 0xff);
-			value("num_ref_idx_l0_default_active_minus1", c->pps.num_ref_idx_l0_default_active_minus1, 0, (1<<5)-1);
-			value("num_ref_idx_l1_default_active_minus1", c->pps.num_ref_idx_l1_default_active_minus1, 0, (1<<5)-1);
+			value("num_ref_idx_l0_default_active_minus1", c->pps.num_ref_idx_l0_default_active_minus1, 0, 31);
+			value("num_ref_idx_l1_default_active_minus1", c->pps.num_ref_idx_l1_default_active_minus1, 0, 31);
 			value("constrained_intra_pred_flag", c->pps.constrained_intra_pred_flag, 0, 1);
 			value("deblocking_filter_control_present_flag", c->pps.deblocking_filter_control_present_flag, 0, 1);
 			value("entropy_coding_mode_flag", c->pps.entropy_coding_mode_flag, 0, 1);
@@ -186,7 +190,6 @@
 			value("size_delta_pic_order_cnt1", c->sh.size_delta_pic_order_cnt1, 0, 0xff);
 			value("field_pic_flag", c->sh.field_pic_flag, 0, 1);
 			value("bottom_field_flag", c->sh.bottom_field_flag, 0, 1);
-			return -1;
 		}
 	}
 #undef value