ref: 0223e82f5d691ea45acb32f70dfa7987ab68c369
parent: 7760836ddbcc9250ccb717d13918a37e3722604a
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon May 1 22:09:36 EDT 2023
a bit of h.264 bitstream parsing
--- a/hantest.c
+++ b/hantest.c
@@ -1,6 +1,7 @@
#include <u.h>
#include <libc.h>
#include "g1regs.h"
+#include "vpuctx.h"
enum {
DecodeH264,
@@ -9,91 +10,6 @@
High = 100,
};
-typedef struct VPUctx VPUctx;
-
-#define Default_4x4_Intra {6, 13, 13, 20, 20, 20, 28, 28, 28, 28, 32, 32, 32, 37, 37, 42}
-#define Default_4x4_Inter {10, 14, 14, 20, 20, 20, 24, 24, 24, 24, 27, 27, 27, 30, 30, 34}
-#define Default_8x8_Intra \
- {6, 10, 10, 13, 11, 13, 16, 16, 16, 16, 18, 18, 18, 18, 18, 23, \
- 23, 23, 23, 23, 23, 25, 25, 25, 25, 25, 25, 25, 27, 27, 27, 27, \
- 27, 27, 27, 27, 29, 29, 29, 29, 29, 29, 29, 31, 31, 31, 31, 31, \
- 31, 33, 33, 33, 33, 33, 36, 36, 36, 36, 38, 38, 38, 40, 40, 42}
-#define Default_8x8_Inter \
- {9, 13, 13, 15, 13, 15, 17, 17, 17, 17, 19, 19, 19, 19, 19, 21, \
- 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 24, 24, 24, 24, \
- 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 27, 27, 27, 27, 27, \
- 27, 28, 28, 28, 28, 28, 30, 30, 30, 30, 32, 32, 32, 33, 33, 35}
-
-static u8int defsl4x4[6][16] = {
- Default_4x4_Intra, /* Sl_4x4_Intra_Y */
- Default_4x4_Intra, /* Sl_4x4_Intra_Cb */
- Default_4x4_Intra, /* Sl_4x4_Intra_Cr */
- Default_4x4_Inter, /* Sl_4x4_Inter_Y */
- Default_4x4_Inter, /* Sl_4x4_Inter_Cb */
- Default_4x4_Inter, /* Sl_4x4_Inter_Cr */
-};
-
-static u8int defs8x8[6][64] = {
- Default_8x8_Intra, /* Sl_8x8_Intra_Y */
- Default_8x8_Inter, /* Sl_8x8_Inter_Y */
- Default_8x8_Intra, /* Sl_8x8_Intra_Cb */
- Default_8x8_Inter, /* Sl_8x8_Inter_Cb */
- Default_8x8_Intra, /* Sl_8x8_Intra_Cr */
- Default_8x8_Inter, /* Sl_8x8_Inter_Cr */
-};
-
-struct VPUctx {
- int process;
- int slen;
-
- union {
- /* h.264 decoding */
- struct {
- struct {
- u16int pic_height_in_map_units_minus1;
- u16int pic_width_in_mbs_minus1;
- u8int chroma_format_idc;
- u8int frame_mbs_only_flag;
- u8int log2_max_frame_num_minus4;
- u8int max_num_ref_frames;
- u8int nal_ref_idc;
- u8int profile_idc;
- u8int direct_8x8_inference_flag;
- u8int mb_adaptive_frame_field_flag;
- u8int seq_scaling_matrix_present_flag;
- }sps;
- struct {
- 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;
- u8int num_ref_idx_l1_default_active_minus1;
- u8int constrained_intra_pred_flag;
- u8int deblocking_filter_control_present_flag;
- u8int entropy_coding_mode_flag;
- u8int pic_scaling_matrix_present_flag;
- u8int redundant_pic_cnt_present_flag;
- u8int transform_8x8_mode_flag;
- u8int weighted_pred_flag;
- }pps;
- struct {
- u16int frame_num;
- u16int idr_pic_id;
- u32int size_dec_ref_pic_marking;
- u8int size_pic_order_cnt_lsb;
- u8int size_delta_pic_order_cnt_bottom;
- u8int size_delta_pic_order_cnt0;
- u8int size_delta_pic_order_cnt1;
- u8int nal_unit_type;
- u8int field_pic_flag;
- u8int bottom_field_flag;
- }sh;
- };
- };
-};
-
static u32int *g1, *g2;
static void
@@ -109,7 +25,7 @@
(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 > Baseline && c->sps.nal_ref_idc != 0) << SW_WRITE_MVS_E |
+ (c->sps.profile_idc > Baseline && c->nal_ref_idc != 0) << SW_WRITE_MVS_E |
c->sps.mb_adaptive_frame_field_flag << SW_SEQ_MBAFF_E |
(c->sps.profile_idc > Baseline) << SW_PICORD_COUNT_E |
0xff << SW_DEC_AXI_WR_ID;
@@ -140,8 +56,8 @@
c->pps.deblocking_filter_control_present_flag << SW_FILT_CTRL_PRES |
c->pps.redundant_pic_cnt_present_flag << SW_RDPIC_CNT_PRES |
c->pps.transform_8x8_mode_flag << SW_8X8TRANS_FLAG_E |
- (c->sps.nal_ref_idc != 0 ? c->sh.size_dec_ref_pic_marking : 0) << SW_REFPIC_MK_LEN |
- (c->sh.nal_unit_type == 5) << SW_IDR_PIC_E |
+ (c->nal_ref_idc != 0 ? c->sh.size_dec_ref_pic_marking : 0) << SW_REFPIC_MK_LEN |
+ (c->nal_unit_type == 5) << SW_IDR_PIC_E |
c->sh.idr_pic_id << SW_IDR_PIC_ID;
g1[9] = c->pps.pic_parameter_set_id << SW_PPS_ID |
@@ -188,7 +104,7 @@
value("chroma_format_idc", c->sps.chroma_format_idc, 0, 3);
value("log2_max_frame_num_minus4", c->sps.log2_max_frame_num_minus4, 0, 12);
value("max_num_ref_frames", c->sps.max_num_ref_frames, 0, 16);
- value("nal_ref_idc", c->sps.nal_ref_idc, 0, 3);
+ value("nal_ref_idc", c->nal_ref_idc, 0, 3);
value("profile_idc", c->sps.profile_idc, 0, 0xff);
value("direct_8x8_inference_flag", c->sps.direct_8x8_inference_flag, 0, 1);
value("frame_mbs_only_flag", c->sps.frame_mbs_only_flag, 0, 1);
@@ -212,7 +128,7 @@
}else if(strcmp(a[0], "sh") == 0){
value("frame_num", c->sh.frame_num, 0, 0xffff);
value("idr_pic_id", c->sh.idr_pic_id, 0, 0xffff);
- value("nal_unit_type", c->sh.nal_unit_type, 0, 0xff);
+ value("nal_unit_type", c->nal_unit_type, 0, 0xff);
value("size_dec_ref_pic_marking", c->sh.size_dec_ref_pic_marking, 0, 0x1ffff);
value("size_pic_order_cnt_lsb", c->sh.size_pic_order_cnt_lsb, 0, 0xff);
value("size_delta_pic_order_cnt_bottom", c->sh.size_delta_pic_order_cnt_bottom, 0, 0xff);
--- a/mkfile
+++ b/mkfile
@@ -1,6 +1,6 @@
</$objtype/mkfile
-TARG=hantest cabac
+TARG=h264 hantest cabac
BIN=/$objtype/bin
default:V: all
--- /dev/null
+++ b/vpuctx.h
@@ -1,0 +1,75 @@
+typedef struct VPUctx VPUctx;
+
+struct VPUctx {
+ int process;
+ int slen;
+
+ union {
+ /* h.264 decoding */
+ struct {
+ /* FIXME userspace */
+ u32int useDefaultScalingMatrixFlag;
+ int PicSizeInMapUnits;
+ u8int IdrPicFlag;
+ u8int sl4x4[6*16];
+ u8int sl8x8[6*64];
+ struct {
+ int left, right;
+ int top, bottom;
+ }crop;
+
+ u8int nal_ref_idc;
+ u8int nal_unit_type;
+ struct {
+ u16int pic_height_in_map_units_minus1;
+ u16int pic_width_in_mbs_minus1;
+ u8int chroma_format_idc;
+ u8int frame_mbs_only_flag;
+ u8int log2_max_frame_num_minus4;
+ u8int max_num_ref_frames;
+ u8int profile_idc;
+ u8int direct_8x8_inference_flag;
+ u8int mb_adaptive_frame_field_flag;
+ u8int seq_scaling_matrix_present_flag;
+ u8int separate_colour_plane_flag;
+
+ /* FIXME userspace */
+ u8int log2_max_pic_order_cnt_lsb_minus4; /* FIXME correct type? */
+ u8int pic_order_cnt_type; /* FIXME correct type? */
+ u8int delta_pic_order_always_zero_flag;
+ }sps;
+ struct {
+ s8int chroma_qp_index_offset;
+ s8int pic_init_qp_minus26;
+ s8int second_chroma_qp_index_offset;
+ u8int weighted_bipred_idc;
+ u8int num_ref_idx_l0_default_active_minus1;
+ u8int num_ref_idx_l1_default_active_minus1;
+ u8int constrained_intra_pred_flag;
+ u8int deblocking_filter_control_present_flag;
+ u8int entropy_coding_mode_flag;
+ u8int pic_scaling_matrix_present_flag;
+ u8int redundant_pic_cnt_present_flag;
+ u8int transform_8x8_mode_flag;
+ u8int weighted_pred_flag;
+ u8int pic_parameter_set_id;
+
+ /* FIXME userspace */
+ u8int bottom_field_pic_order_in_frame_present_flag;
+ u8int num_slice_groups_minus1;
+ u8int slice_group_map_type;
+ }pps;
+ struct {
+ u16int frame_num;
+ u16int idr_pic_id;
+ u32int size_dec_ref_pic_marking;
+ u8int size_pic_order_cnt_lsb;
+ u8int size_delta_pic_order_cnt_bottom;
+ u8int size_delta_pic_order_cnt0;
+ u8int size_delta_pic_order_cnt1;
+ u8int field_pic_flag;
+ u8int bottom_field_flag;
+ }sh;
+ };
+ };
+};