Fix several bugs in h264bitstream

This commit is contained in:
Cameron Gutman
2026-07-26 18:55:23 -05:00
parent acea86de24
commit 3e24a7a1a5
3 changed files with 51 additions and 15 deletions
+9 -5
View File
@@ -138,15 +138,19 @@ static inline uint32_t bs_read_u8(bs_t* b)
static inline uint32_t bs_read_ue(bs_t* b)
{
int32_t r = 0;
uint32_t r = 0;
int i = 0;
while( (bs_read_u1(b) == 0) && (i < 32) && (!bs_eof(b)) )
while (!bs_eof(b) && (i < 32) && (bs_read_u1(b) == 0))
{
i++;
}
if (i >= 32)
{
return 0;
}
r = bs_read_u(b, i);
r += (1 << i) - 1;
r += (1U << i) - 1U;
return r;
}
@@ -260,11 +264,11 @@ static inline void bs_write_se(bs_t* b, int32_t v)
{
if (v <= 0)
{
bs_write_ue(b, -v*2);
bs_write_ue(b, (-(uint32_t)v) * 2);
}
else
{
bs_write_ue(b, v*2 - 1);
bs_write_ue(b, ((uint32_t)v) * 2 - 1);
}
}