sergey-dryabzhinsky / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
1.02k stars 215 forks source link

Incorrect continuity counter in TS header #341

Open winshining opened 2 years ago

winshining commented 2 years ago

The 0xf in the following line should be 0x10:

https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/blob/8e344d799483145666fa875344bddf67a324e561/hls/ngx_rtmp_mpegts.c#L209

So the continuity counter can be 0x0 ~ 0xf, otherwise the range is 0x0 ~ 0xe.

premultiply commented 2 years ago

I think the operator is wrong. Should be &= instead of modulo operator %=.

winshining commented 2 years ago

@premultiply No. &= means getting the 4 least significant bits of the octet of mpegts_cc, but the continuity counter field in TS header loops periodically from 0x0 to 0xf. The operator is ok but the operand should be 0x10 (decimal 16), so the continuity counter will repeat from 0x0 to 0xf:

0 % 16 = 0 (0x0)
1 % 16 = 1 (0x1)
...
15 % 16 = 15 (0xf)
16 % 16 = 0 (0x0)
...
31 % 16 = 15 (0xf)
32 % 16 = 0 (0x0)
...
premultiply commented 2 years ago

Plz try the same with AND operator…