Skip to content

Commit 45f7d93

Browse files
authored
Merge pull request #40 from mpeg5/dev-FixSyntaxNaluLength
fixed nal_unit_length syntax
2 parents 9e69854 + 39d97f0 commit 45f7d93

File tree

6 files changed

+55
-44
lines changed

6 files changed

+55
-44
lines changed

src_base/xeve.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ int xeve_pic(XEVE_CTX * ctx, XEVE_BITB * bitb, XEVE_STAT * stat)
166166
u8 * tiles_in_slice;
167167
u16 total_tiles_in_slice;
168168
int tile_cnt = 0;
169-
u8 * curr_temp = ctx->bs[0].cur;;
169+
u8 * curr_temp = ctx->bs[0].cur;
170170
int last_intra_poc = INT_MAX;
171171

172172
for (ctx->slice_num = 0; ctx->slice_num < num_slice_in_pic; ctx->slice_num++)
@@ -380,7 +380,7 @@ int xeve_pic(XEVE_CTX * ctx, XEVE_BITB * bitb, XEVE_STAT * stat)
380380

381381
/* Send available APSs */
382382
int aps_nalu_size = 0;
383-
int* size_field = (int*)(*(&bs->cur));
383+
u8 * nalu_len_buf = bs->cur;
384384
u8* cur_tmp = bs->cur;
385385

386386
/* Encode nalu header */
@@ -507,7 +507,8 @@ int xeve_pic(XEVE_CTX * ctx, XEVE_BITB * bitb, XEVE_STAT * stat)
507507
}
508508

509509
xeve_bsw_deinit(bs);
510-
*size_field = (int)(bs->cur - cur_tmp) - 4;
510+
xeve_eco_nalu_len_update(nalu_len_buf, (int)(bs->cur - cur_tmp) - 4);
511+
511512
curr_temp = bs->cur;
512513

513514
/* slice header re-writing */

src_base/xeve_eco.c

+30-20
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
/*
44
Redistribution and use in source and binary forms, with or without
55
modification, are permitted provided that the following conditions are met:
6-
6+
77
- Redistributions of source code must retain the above copyright notice,
88
this list of conditions and the following disclaimer.
9-
9+
1010
- Redistributions in binary form must reproduce the above copyright notice,
1111
this list of conditions and the following disclaimer in the documentation
1212
and/or other materials provided with the distribution.
13-
13+
1414
- Neither the name of the copyright owner, nor the names of its contributors
1515
may be used to endorse or promote products derived from this software
1616
without specific prior written permission.
17-
17+
1818
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1919
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2020
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -34,6 +34,16 @@
3434

3535
#pragma warning(disable:4018)
3636

37+
int xeve_eco_nalu_len_update(void * buf, int size)
38+
{
39+
int i;
40+
u8 * p = buf;
41+
for(i=0; i<4; i++) {
42+
p[i] = (size >> (24 - (i*8))) & 0xFF;
43+
}
44+
return 0;
45+
}
46+
3747
int xeve_eco_nalu(XEVE_BSW * bs, XEVE_NALU * nalu)
3848
{
3949
#if TRACE_HLS
@@ -223,12 +233,12 @@ int xeve_eco_pps(XEVE_BSW * bs, XEVE_SPS * sps, XEVE_PPS * pps)
223233
xeve_bsw_write_ue(bs, pps->num_ref_idx_default_active_minus1[1]);
224234
xeve_bsw_write_ue(bs, pps->additional_lt_poc_lsb_len);
225235
xeve_bsw_write1(bs, pps->rpl1_idx_present_flag);
226-
xeve_bsw_write1(bs, pps->single_tile_in_pic_flag);
236+
xeve_bsw_write1(bs, pps->single_tile_in_pic_flag);
227237
xeve_bsw_write_ue(bs, pps->tile_id_len_minus1);
228238
xeve_bsw_write1(bs, pps->explicit_tile_id_flag);
229239
xeve_bsw_write1(bs, pps->pic_dra_enabled_flag);
230240
xeve_bsw_write1(bs, pps->arbitrary_slice_present_flag);
231-
xeve_bsw_write1(bs, pps->constrained_intra_pred_flag);
241+
xeve_bsw_write1(bs, pps->constrained_intra_pred_flag);
232242
xeve_bsw_write1(bs, pps->cu_qp_delta_enabled_flag);
233243
if (pps->cu_qp_delta_enabled_flag)
234244
{
@@ -239,7 +249,7 @@ int xeve_eco_pps(XEVE_BSW * bs, XEVE_SPS * sps, XEVE_PPS * pps)
239249
{
240250
xeve_bsw_write1(bs, t0);
241251
}
242-
#if TRACE_HLS
252+
#if TRACE_HLS
243253
XEVE_TRACE_STR("************ PPS End ************\n");
244254
XEVE_TRACE_STR("***********************************\n");
245255
#endif
@@ -248,9 +258,9 @@ int xeve_eco_pps(XEVE_BSW * bs, XEVE_SPS * sps, XEVE_PPS * pps)
248258

249259
int xeve_eco_sh(XEVE_BSW * bs, XEVE_SPS * sps, XEVE_PPS * pps, XEVE_SH * sh, int nut)
250260
{
251-
#if TRACE_HLS
261+
#if TRACE_HLS
252262
XEVE_TRACE_STR("***********************************\n");
253-
XEVE_TRACE_STR("************ SH Start ************\n");
263+
XEVE_TRACE_STR("************ SH Start ************\n");
254264
#endif
255265

256266
xeve_bsw_write_ue(bs, sh->slice_pic_parameter_set_id);
@@ -288,7 +298,7 @@ int xeve_eco_sh(XEVE_BSW * bs, XEVE_SPS * sps, XEVE_PPS * pps, XEVE_SH * sh, int
288298
{
289299
xeve_bsw_write1(bs, t0);
290300
}
291-
#if TRACE_HLS
301+
#if TRACE_HLS
292302
XEVE_TRACE_STR("************ SH End ************\n");
293303
XEVE_TRACE_STR("***********************************\n");
294304
#endif
@@ -388,7 +398,7 @@ static void sbac_put_byte(u8 writing_byte, XEVE_SBAC *sbac, XEVE_BSW *bs)
388398
static void sbac_carry_propagate(XEVE_SBAC *sbac, XEVE_BSW *bs)
389399
{
390400
u32 out_bits = sbac->code >> 17;
391-
401+
392402
sbac->code &= (1 << 17) - 1;
393403

394404
if(out_bits < 0xFF)
@@ -496,7 +506,7 @@ void xeve_sbac_encode_bin(u32 bin, XEVE_SBAC *sbac, SBAC_CTX_MODEL *model, XEVE_
496506
mps = (*model) & 1;
497507

498508
lps = (state * (sbac->range)) >> 9;
499-
lps = lps < 437 ? 437 : lps;
509+
lps = lps < 437 ? 437 : lps;
500510

501511
sbac->range -= lps;
502512

@@ -522,7 +532,7 @@ void xeve_sbac_encode_bin(u32 bin, XEVE_SBAC *sbac, SBAC_CTX_MODEL *model, XEVE_
522532
state = state + ((512 - state + 16) >> 5);
523533
if(state > 256)
524534
{
525-
mps = 1 - mps;
535+
mps = 1 - mps;
526536
state = 512 - state;
527537
}
528538
*model = (state << 1) + mps;
@@ -557,7 +567,7 @@ void xeve_sbac_encode_bin_trm(u32 bin, XEVE_SBAC *sbac, XEVE_BSW *bs)
557567
sbac->code += sbac->range;
558568
sbac->range = 1;
559569
}
560-
570+
561571
while(sbac->range < 8192)
562572
{
563573
sbac->range <<= 1;
@@ -843,7 +853,7 @@ int xeve_eco_cbf(XEVE_BSW * bs, int cbf_y, int cbf_u, int cbf_v, u8 pred_mode, i
843853
if (!cbf_all && sub_pos)
844854
{
845855
return 0;
846-
}
856+
}
847857
if(b_no_cbf == 1)
848858
{
849859
xeve_assert(cbf_all != 0);
@@ -871,7 +881,7 @@ int xeve_eco_cbf(XEVE_BSW * bs, int cbf_y, int cbf_u, int cbf_v, u8 pred_mode, i
871881
XEVE_TRACE_STR("\n");
872882
}
873883
}
874-
884+
875885
if (run[U_C] && chroma_format_idc)
876886
{
877887
xeve_sbac_encode_bin(cbf_u, sbac, sbac_ctx->cbf_cb, bs);
@@ -896,7 +906,7 @@ int xeve_eco_cbf(XEVE_BSW * bs, int cbf_y, int cbf_u, int cbf_v, u8 pred_mode, i
896906
XEVE_TRACE_STR("cbf Y ");
897907
XEVE_TRACE_INT(cbf_y);
898908
XEVE_TRACE_STR("\n");
899-
}
909+
}
900910
}
901911
else
902912
{
@@ -1031,7 +1041,7 @@ static int xeve_eco_coefficient(XEVE_BSW * bs, s16 coef[N_C][MAX_CU_DIM], int lo
10311041
}
10321042
}
10331043
}
1034-
1044+
10351045
for (c = 0; c < N_C; c++)
10361046
{
10371047
if (nnz_sub[c][(j << 1) | i] && run[c])
@@ -1079,7 +1089,7 @@ int xeve_eco_coef(XEVE_CTX * ctx, XEVE_CORE * core, XEVE_BSW * bs, s16 coef[N_C]
10791089
int xeve_eco_pred_mode(XEVE_BSW * bs, u8 pred_mode, int ctx)
10801090
{
10811091
XEVE_SBAC * sbac = GET_SBAC_ENC(bs);
1082-
1092+
10831093
xeve_sbac_encode_bin(pred_mode == MODE_INTRA, sbac, sbac->ctx.pred_mode + ctx, bs);
10841094
XEVE_TRACE_COUNTER;
10851095
XEVE_TRACE_STR("pred mode ");
@@ -1117,7 +1127,7 @@ void xeve_eco_inter_pred_idc(XEVE_BSW *bs, s8 refi[REFP_NUM], int slice_type, in
11171127
if(REFI_IS_VALID(refi[REFP_0]) && REFI_IS_VALID(refi[REFP_1])) /* PRED_BI */
11181128
{
11191129
assert(check_bi_applicability(slice_type, cuw, cuh, is_sps_admvp));
1120-
xeve_sbac_encode_bin(0, sbac, sbac->ctx.inter_dir, bs);
1130+
xeve_sbac_encode_bin(0, sbac, sbac->ctx.inter_dir, bs);
11211131
}
11221132
else
11231133
{

src_base/xeve_eco.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
/*
44
Redistribution and use in source and binary forms, with or without
55
modification, are permitted provided that the following conditions are met:
6-
6+
77
- Redistributions of source code must retain the above copyright notice,
88
this list of conditions and the following disclaimer.
9-
9+
1010
- Redistributions in binary form must reproduce the above copyright notice,
1111
this list of conditions and the following disclaimer in the documentation
1212
and/or other materials provided with the distribution.
13-
13+
1414
- Neither the name of the copyright owner, nor the names of its contributors
1515
may be used to endorse or promote products derived from this software
1616
without specific prior written permission.
17-
17+
1818
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1919
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2020
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -43,6 +43,7 @@ void xeve_sbac_reset(XEVE_SBAC * sbac, u8 slice_type, u8 slice_qp, int sps_cm_in
4343
void xeve_sbac_finish(XEVE_BSW *bs);
4444
void xeve_sbac_encode_bin(u32 bin, XEVE_SBAC *sbac, SBAC_CTX_MODEL *ctx_model, XEVE_BSW *bs);
4545
void xeve_sbac_encode_bin_trm(u32 bin, XEVE_SBAC *sbac, XEVE_BSW *bs);
46+
int xeve_eco_nalu_len_update(void * buf, int size);
4647
int xeve_eco_nalu(XEVE_BSW * bs, XEVE_NALU * nalu);
4748
int xeve_eco_sps(XEVE_BSW * bs, XEVE_SPS * sps);
4849
int xeve_eco_pps(XEVE_BSW * bs, XEVE_SPS * sps, XEVE_PPS * pps);

src_base/xeve_util.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -2647,7 +2647,7 @@ int xeve_pic_finish(XEVE_CTX *ctx, XEVE_BITB *bitb, XEVE_STAT *stat)
26472647
XEVE_NALU sei_nalu;
26482648
xeve_set_nalu(&sei_nalu, XEVE_SEI_NUT, ctx->nalu.nuh_temporal_id);
26492649

2650-
int* size_field = (int*)(*(&bs->cur));
2650+
u8* size_field = bs->cur;
26512651
u8* cur_tmp = bs->cur;
26522652

26532653
xeve_eco_nalu(bs, &sei_nalu);
@@ -2657,7 +2657,7 @@ int xeve_pic_finish(XEVE_CTX *ctx, XEVE_BITB *bitb, XEVE_STAT *stat)
26572657

26582658
xeve_bsw_deinit(bs);
26592659
stat->sei_size = (int)(bs->cur - cur_tmp);
2660-
*size_field = stat->sei_size - 4;
2660+
xeve_eco_nalu_len_update(size_field, stat->sei_size - 4);
26612661
}
26622662

26632663
/* expand current encoding picture, if needs */
@@ -2780,7 +2780,7 @@ void xeve_set_sps(XEVE_CTX * ctx, XEVE_SPS * sps)
27802780

27812781
sps->profile_idc = ctx->param.profile;
27822782
sps->level_idc = ctx->param.level_idc * 3;
2783-
sps->pic_width_in_luma_samples = XEVE_ALIGN_VAL(ctx->param.w, 8);
2783+
sps->pic_width_in_luma_samples = XEVE_ALIGN_VAL(ctx->param.w, 8);
27842784
sps->pic_height_in_luma_samples = XEVE_ALIGN_VAL(ctx->param.h, 8);
27852785
sps->toolset_idc_h = 0;
27862786
sps->toolset_idc_l = 0;
@@ -2948,7 +2948,7 @@ int xeve_ready(XEVE_CTX* ctx)
29482948

29492949
if (ctx->w == 0)
29502950
{
2951-
w = ctx->w = XEVE_ALIGN_VAL(ctx->param.w, 8);
2951+
w = ctx->w = XEVE_ALIGN_VAL(ctx->param.w, 8);
29522952
h = ctx->h = XEVE_ALIGN_VAL(ctx->param.h, 8);
29532953
ctx->f = w * h;
29542954
if ((ctx->w != ctx->param.w) || (ctx->h != ctx->param.h))
@@ -3809,7 +3809,7 @@ int xeve_encode_sps(XEVE_CTX * ctx)
38093809
XEVE_SPS * sps = &ctx->sps;
38103810
XEVE_NALU nalu;
38113811

3812-
int* size_field = (int*)(*(&bs->cur));
3812+
u8* size_field = bs->cur;
38133813
u8* cur_tmp = bs->cur;
38143814

38153815
/* nalu header */
@@ -3824,7 +3824,7 @@ int xeve_encode_sps(XEVE_CTX * ctx)
38243824
xeve_bsw_deinit(bs);
38253825

38263826
/* write the bitstream size */
3827-
*size_field = (int)(bs->cur - cur_tmp) - 4;
3827+
xeve_eco_nalu_len_update(size_field, (int)(bs->cur - cur_tmp) - 4);
38283828

38293829
return XEVE_OK;
38303830
}
@@ -3835,7 +3835,7 @@ int xeve_encode_pps(XEVE_CTX * ctx)
38353835
XEVE_SPS * sps = &ctx->sps;
38363836
XEVE_PPS * pps = &ctx->pps;
38373837
XEVE_NALU nalu;
3838-
int * size_field = (int*)(*(&bs->cur));
3838+
u8 * size_field = bs->cur;
38393839
u8 * cur_tmp = bs->cur;
38403840

38413841
/* nalu header */
@@ -3850,8 +3850,7 @@ int xeve_encode_pps(XEVE_CTX * ctx)
38503850
xeve_bsw_deinit(bs);
38513851

38523852
/* write the bitstream size */
3853-
*size_field = (int)(bs->cur - cur_tmp) - 4;
3854-
3853+
xeve_eco_nalu_len_update(size_field, (int)(bs->cur - cur_tmp) - 4);
38553854
return XEVE_OK;
38563855
}
38573856

src_main/xevem.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ int xeve_pic(XEVE_CTX * ctx, XEVE_BITB * bitb, XEVE_STAT * stat)
554554
aps_dra->signal_flag = 0;
555555
}
556556

557-
int* size_field = (int*)(*(&bs->cur));
557+
u8* size_field = bs->cur;
558558
u8* cur_tmp = bs->cur;
559559

560560
/* Encode nalu header */
@@ -708,7 +708,7 @@ int xeve_pic(XEVE_CTX * ctx, XEVE_BITB * bitb, XEVE_STAT * stat)
708708
}
709709

710710
xeve_bsw_deinit(bs);
711-
*size_field = (int)(bs->cur - cur_tmp) - 4;
711+
xeve_eco_nalu_len_update(size_field, (int)(bs->cur - cur_tmp) - 4);
712712
curr_temp = bs->cur;
713713

714714
/* slice header re-writing */

src_main/xevem_util.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -4053,7 +4053,7 @@ int xevem_encode_sps(XEVE_CTX * ctx)
40534053
XEVE_SPS * sps = &ctx->sps;
40544054
XEVE_NALU nalu;
40554055

4056-
int* size_field = (int*)(*(&bs->cur));
4056+
u8* size_field = bs->cur;
40574057
u8* cur_tmp = bs->cur;
40584058

40594059
/* nalu header */
@@ -4068,7 +4068,7 @@ int xevem_encode_sps(XEVE_CTX * ctx)
40684068
xeve_bsw_deinit(bs);
40694069

40704070
/* write the bitstream size */
4071-
*size_field = (int)(bs->cur - cur_tmp) - 4;
4071+
xeve_eco_nalu_len_update(size_field, (int)(bs->cur - cur_tmp) - 4);
40724072

40734073
return XEVE_OK;
40744074
}
@@ -4077,7 +4077,7 @@ int xevem_encode_aps(XEVE_CTX * ctx, XEVE_APS_GEN * aps)
40774077
{
40784078
XEVE_BSW * bs = &ctx->bs[0];
40794079
XEVE_NALU nalu;
4080-
int * size_field = (int*)(*(&bs->cur));
4080+
u8 * size_field = bs->cur;
40814081
u8 * cur_tmp = bs->cur;
40824082

40834083
/* nalu header */
@@ -4088,7 +4088,7 @@ int xevem_encode_aps(XEVE_CTX * ctx, XEVE_APS_GEN * aps)
40884088
xeve_assert_rv(xevem_eco_aps_gen(bs, aps, ctx->sps.bit_depth_luma_minus8 + 8) == XEVE_OK, XEVE_ERR_INVALID_ARGUMENT);
40894089

40904090
xeve_bsw_deinit(bs);
4091-
*size_field = (int)(bs->cur - cur_tmp) - 4;
4091+
xeve_eco_nalu_len_update(size_field, (int)(bs->cur - cur_tmp) - 4);
40924092

40934093
return XEVE_OK;
40944094
}
@@ -4098,7 +4098,7 @@ int xevem_encode_pps(XEVE_CTX * ctx)
40984098
XEVE_SPS * sps = &ctx->sps;
40994099
XEVE_PPS * pps = &ctx->pps;
41004100
XEVE_NALU nalu;
4101-
int * size_field = (int*)(*(&bs->cur));
4101+
u8 * size_field = bs->cur;
41024102
u8 * cur_tmp = bs->cur;
41034103

41044104
/* nalu header */
@@ -4113,7 +4113,7 @@ int xevem_encode_pps(XEVE_CTX * ctx)
41134113
xeve_bsw_deinit(bs);
41144114

41154115
/* write the bitstream size */
4116-
*size_field = (int)(bs->cur - cur_tmp) - 4;
4116+
xeve_eco_nalu_len_update(size_field, (int)(bs->cur - cur_tmp) - 4);
41174117

41184118
return XEVE_OK;
41194119
}

0 commit comments

Comments
 (0)