Revision 3143f133

View differences:

libavformat/matroskadec.c
689 689
}
690 690

  
691 691
/*
692
 * Read the next element as a signed int.
693
 * 0 is success, < 0 is failure.
694
 */
695

  
696
static int
697
ebml_read_sint (MatroskaDemuxContext *matroska,
698
                uint32_t             *id,
699
                int64_t              *num)
700
{
701
    ByteIOContext *pb = matroska->ctx->pb;
702
    int size, n = 1, negative = 0, res;
703
    uint64_t rlength;
704

  
705
    if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
706
        (res = ebml_read_element_length(matroska, &rlength)) < 0)
707
        return res;
708
    size = rlength;
709
    if (size < 1 || size > 8) {
710
        offset_t pos = url_ftell(pb);
711
        av_log(matroska->ctx, AV_LOG_ERROR,
712
               "Invalid sint element size %d at position %"PRId64" (0x%"PRIx64")\n",
713
                size, pos, pos);
714
        return AVERROR_INVALIDDATA;
715
    }
716
    if ((*num = get_byte(pb)) & 0x80) {
717
        negative = 1;
718
        *num &= ~0x80;
719
    }
720
    while (n++ < size)
721
        *num = (*num << 8) | get_byte(pb);
722

  
723
    /* make signed */
724
    if (negative)
725
        *num = *num - (1LL << ((8 * size) - 1));
726

  
727
    return 0;
728
}
729

  
730
/*
731 692
 * Read the next element as a float.
732 693
 * 0 is success, < 0 is failure.
733 694
 */
......
799 760
}
800 761

  
801 762
/*
802
 * Read the next element as a UTF-8 string.
803
 * 0 is success, < 0 is failure.
804
 */
805

  
806
static int
807
ebml_read_utf8 (MatroskaDemuxContext *matroska,
808
                uint32_t             *id,
809
                char                **str)
810
{
811
  return ebml_read_ascii(matroska, id, str);
812
}
813

  
814
/*
815 763
 * Read the next element, but only the header. The contents
816 764
 * are supposed to be sub-elements which can be read separately.
817 765
 * 0 is success, < 0 is failure.

Also available in: Unified diff