pesparse: Fix stuffing byte handling

We in fact get the size of the header (including stuffing bytes), therefore
use that instead of trying to skip 0xff bytes ourselves since some media
streams do start with 0xff (like mpeg audio's initial 0xfff).
This commit is contained in:
Edward Hervey 2011-07-20 19:16:05 +02:00
parent e8d24859ca
commit d0e8427b4e
2 changed files with 14 additions and 11 deletions

View file

@ -52,6 +52,7 @@ mpegts_parse_pes_header (const guint8 * data, gsize length, PESHeader * res,
{
PESParsingResult ret = PES_PARSING_NEED_MORE;
gsize origlength = length;
const guint8 *origdata = data;
guint32 val32;
guint8 val8, flags;
@ -81,6 +82,8 @@ mpegts_parse_pes_header (const guint8 * data, gsize length, PESHeader * res,
res->stream_id = val32 & 0x000000ff;
res->packet_length = GST_READ_UINT16_BE (data);
if (res->packet_length)
res->packet_length += 6;
data += 2;
length -= 2;
@ -122,11 +125,15 @@ mpegts_parse_pes_header (const guint8 * data, gsize length, PESHeader * res,
GST_DEBUG ("PES_flag 0x%02x", flags);
/* PES_header_data_length 8 */
val8 = *data++;
res->header_size = *data++;
length -= 3;
if (G_UNLIKELY (length < val8))
if (G_UNLIKELY (length < res->header_size))
goto need_more_data;
res->header_size += 9; /* We add 9 since that's the offset
* of the field in the header*/
GST_DEBUG ("header_size : %d", res->header_size);
/* PTS/DTS */
/* PTS_DTS_flags == 0x01 is invalid */
@ -231,6 +238,7 @@ mpegts_parse_pes_header (const guint8 * data, gsize length, PESHeader * res,
length -= 2;
}
/* jump if we don't have a PES extension */
if (!(flags & 0x01))
goto stuffing_byte;
@ -344,19 +352,14 @@ mpegts_parse_pes_header (const guint8 * data, gsize length, PESHeader * res,
}
stuffing_byte:
/* There can be no more than 32 stuff bytes */
while (length && *data == 0xff) {
data++;
length--;
}
/* Go to the expected data start position */
data = origdata + res->header_size;
length = origlength - res->header_size;
done_parsing:
GST_DEBUG ("origlength:%" G_GSSIZE_FORMAT ", length:%" G_GSSIZE_FORMAT,
origlength, length);
/* Update the length based on parsed size */
if (res->packet_length)
res->packet_length += 6;
res->header_size = origlength - length;
*offset += res->header_size;
ret = PES_PARSING_OK;

View file

@ -58,7 +58,7 @@ typedef enum {
typedef struct {
guint8 stream_id; /* See ID_* in gstmpegdefs.h */
guint16 packet_length; /* The size of the remaining data
guint16 packet_length; /* The size of the PES header and PES data
* (if 0 => unbounded packet) */
guint16 header_size; /* The complete size of the PES header */