Skip to content

Commit cbde4f5

Browse files
authored
Merge pull request frejoel#8 from frejoel/short-pes-fix
fix: issue with small pes packets
2 parents 9b174a8 + a4ec4b2 commit cbde4f5

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ coverage/*
1212
*.log
1313
*.obj
1414
*.tlog
15+
**/*.o.dSYM/*
1516
**/Debug/*
1617
**/Release/*

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ remove:
5656
rm -r -f $(INSTALL_DIR)/include/libtsdemux
5757
rm -f $(INSTALL_DIR)/lib/libtsdemux.a
5858

59+
test: static $(OBJ_TESTS)
5960
tests: static $(OBJ_TESTS)
6061

6162
examples: static $(OBJ_EXAMPLES)
@@ -74,6 +75,7 @@ endif
7475

7576
clean:
7677
rm -f -r $(ODIR) $(CCDIR)
78+
rm -f -r test/*.o.dSYM
7779
find . -type f -name '*.o' -exec rm {} \;
7880
find . -type f -name '*.o.dSYM' -exec rm {} \;
7981
find . -type f -name '*.o.gcno' -exec rm {} \;

src/tsdemux.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,12 +1378,16 @@ TSDCode demux_pes(TSDemuxContext *ctx, TSDPacket *hdr, int reg_idx)
13781378

13791379
// get the PES length to see if we have the complete packet.
13801380
size_t data_len = dataCtx->write - dataCtx->buffer;
1381+
// make sure we have enough data to parse the PES
1382+
// the PES header starts with 6 bytes:
1383+
// packet_start_code_prefix(24), stream_id(8) and PES_packet_length(16)
13811384
if(data_len > 5) {
13821385
// get the PES length
13831386
uint16_t pes_len = parse_u16(&dataCtx->buffer[4]);
13841387
// if the amount of data in the DataContext matches the PES length
13851388
// we have enough data to parse the PES packet.
1386-
if(pes_len > 0 && data_len >= pes_len) {
1389+
// PES_packet_length doesn't include the first 6 bytes PES header
1390+
if(pes_len > 0 && data_len >= pes_len + 6) {
13871391
TSDPESPacket pes;
13881392
res = tsd_parse_pes(ctx, dataCtx->buffer, data_len, &pes);
13891393
if(res != TSD_OK) {
@@ -1509,7 +1513,7 @@ size_t tsd_demux(TSDemuxContext *ctx,
15091513
}
15101514
}
15111515

1512-
// if this isn't a PMT PID, check to see if the user has registerd it
1516+
// if this isn't a PMT PID, check to see if the user has registered it
15131517
if(parsed == 0) {
15141518
size_t i;
15151519
for(i=0; i < ctx->registered_pids_length; ++i) {

src/tsdemux.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <stdint.h>
3030

3131
// Software version, format MAJOR.MINOR.PATCH
32-
#define TSD_VERSION "0.1.0"
32+
#define TSD_VERSION "0.1.1"
3333

3434
#define TSD_SYNC_BYTE (0x47)
3535
#define TSD_MESSAGE_LEN (128)

0 commit comments

Comments
 (0)