On Fri, Sep 26, 2014 at 01:49:20PM +0200, Hendrik Leppkes wrote:
> --- a/libavcodec/mlp_parser.c
> +++ b/libavcodec/mlp_parser.c
> @@ -119,6 +119,23 @@ static uint64_t truehd_layout(int chanmap)
>
> +static int ff_mlp_get_major_sync_size(const uint8_t * buf, int bufsize)
> +{
> + int has_extension, extensions = 0;
> + int size = 28;
> + if (bufsize < 28)
> + return -1;
AVERROR_INVALIDDATA is likely more appropriate.
> + if (AV_RB32(buf) == 0xf8726fba) {
> + has_extension = buf[25] & 1;
> + if (has_extension) {
> + extensions = buf[26] >> 4;
> + size += 2 + extensions * 2;
> + }
> + }
> + return size;
> +}
> @@ -127,18 +144,19 @@ static uint64_t truehd_layout(int chanmap)
>
> int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb)
> {
> - if (gb->size_in_bits < 28 << 3) {
> + header_size = ff_mlp_get_major_sync_size(gb->buffer, gb->size_in_bits >>
> 3);
> + if (header_size < 0 || gb->size_in_bits < header_size << 3) {
> av_log(log, AV_LOG_ERROR, "packet too short, unable to read major
> sync\n");
> return -1;
> }
>
> - checksum = ff_mlp_checksum16(gb->buffer, 26);
> - if (checksum != AV_RL16(gb->buffer+26)) {
> + checksum = ff_mlp_checksum16(gb->buffer, header_size - 2);
> + if (checksum != AV_RL16(gb->buffer+header_size-2)) {
> av_log(log, AV_LOG_ERROR, "major sync info header checksum error\n");
> return AVERROR_INVALIDDATA;
> }
> @@ -197,7 +216,7 @@ int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh,
> GetBitContext *gb)
>
> mh->num_substreams = get_bits(gb, 4);
>
> - skip_bits_long(gb, 4 + 11 * 8);
> + skip_bits_long(gb, 4 + (header_size - 17) * 8);
>
> return 0;
> }
> --- a/libavcodec/mlpdec.c
> +++ b/libavcodec/mlpdec.c
> @@ -1105,7 +1110,7 @@ static int read_access_unit(AVCodecContext *avctx,
> void* data,
> if (read_major_sync(m, &gb) < 0)
> goto error;
> m->is_major_sync_unit = 1;
> - header_size += 28;
> + header_size += m->major_sync_header_size;
> }
Do you know what all the magic numbers mean? 25, 26, 28, 0xf8726fba ...
The parser code is quite difficult to follow because of this.
Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel