diff options
author | jstebbins <[email protected]> | 2008-11-11 17:20:03 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2008-11-11 17:20:03 +0000 |
commit | 507d870e33c46a7186c647a6d53288123fc60c74 (patch) | |
tree | 8c426197231d90644ddc4d0e4df8c3849ab6373b /libhb | |
parent | 1111f7b15abdea2dea8f242c355fee9e77978ca0 (diff) |
fix pmt processing
there were 2 problems
1. when the program list in the pat contains a network PID, the pmt parsing
code doesn't properly skip this entry. this causes attempts to interpret
a pat as a pmt since the pid entry in the table is left initialized to 0.
2. pmt parsing always waits till the start of the second pmt section before
parsing the first. if for some reason there were only one pmt in the
stream, it would never parse the pmt. I've changed it to parse the pmt
as soon as all the necessary bytes are collected.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1916 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rwxr-xr-x | libhb/stream.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/libhb/stream.c b/libhb/stream.c index a12c4babb..b3942859c 100755 --- a/libhb/stream.c +++ b/libhb/stream.c @@ -1577,19 +1577,6 @@ static int build_program_map(const uint8_t *buf, hb_stream_t *stream) // Get pointer length - only valid in packets with a start flag int pointer_len = 0; - if (start && stream->pmt_info.reading) - { - // We just finished a bunch of packets - parse the program map details - int decode_ok = 0; - if (stream->pmt_info.tablebuf[0] == 0x02) - decode_ok = decode_program_map(stream); - free(stream->pmt_info.tablebuf); - stream->pmt_info.tablebuf = NULL; - stream->pmt_info.tablepos = 0; - stream->pmt_info.reading = 0; - if (decode_ok) - return decode_ok; - } if (start) { @@ -1615,6 +1602,27 @@ static int build_program_map(const uint8_t *buf, hb_stream_t *stream) memcpy(stream->pmt_info.tablebuf + stream->pmt_info.tablepos, buf + 4 + adapt_len + pointer_len, amount_to_copy); stream->pmt_info.tablepos += amount_to_copy; } + if (stream->pmt_info.tablepos > 3) + { + // We have enough to check the section length + int length; + length = ((stream->pmt_info.tablebuf[1] << 8) + + stream->pmt_info.tablebuf[2]) & 0xFFF; + if (stream->pmt_info.tablepos > length + 1) + { + // We just finished a bunch of packets - parse the program map details + int decode_ok = 0; + if (stream->pmt_info.tablebuf[0] == 0x02) + decode_ok = decode_program_map(stream); + free(stream->pmt_info.tablebuf); + stream->pmt_info.tablebuf = NULL; + stream->pmt_info.tablepos = 0; + stream->pmt_info.reading = 0; + if (decode_ok) + return decode_ok; + } + + } return 0; } @@ -1740,6 +1748,7 @@ static void hb_ts_stream_find_pids(hb_stream_t *stream) for (;;) { const uint8_t *buf = next_packet( stream ); + if ( buf == NULL ) { hb_log("hb_ts_stream_find_pids - end of file"); @@ -1769,7 +1778,8 @@ static void hb_ts_stream_find_pids(hb_stream_t *stream) // on the first pat entry for which we find a matching program map PID. The ideal solution would // be to build a title choice popup from the PAT program number details and then select from // their - but right now the API's not capable of that. - if (pid == stream->pat_info[pat_index].program_map_PID) + if (stream->pat_info[pat_index].program_number != 0 && + pid == stream->pat_info[pat_index].program_map_PID) { if (build_program_map(buf, stream) > 0) break; |