Revision ce15710f libavcodec/mlp_parser.c

View differences:

libavcodec/mlp_parser.c
30 30
#include "bitstream.h"
31 31
#include "parser.h"
32 32
#include "mlp_parser.h"
33
#include "mlp.h"
33 34

  
34 35
static const uint8_t mlp_quants[16] = {
35 36
    16, 20, 24, 0, 0, 0, 0, 0,
......
64 65
    return channels;
65 66
}
66 67

  
67
static int crc_init = 0;
68
static AVCRC crc_2D[1024];
69

  
70
/** MLP uses checksums that seem to be based on the standard CRC algorithm, but
71
 *  are not (in implementation terms, the table lookup and XOR are reversed).
72
 *  We can implement this behavior using a standard av_crc on all but the
73
 *  last element, then XOR that with the last element.
74
 */
75

  
76
static uint16_t mlp_checksum16(const uint8_t *buf, unsigned int buf_size)
77
{
78
    uint16_t crc;
79

  
80
    crc = av_crc(crc_2D, 0, buf, buf_size - 2);
81
    crc ^= AV_RL16(buf + buf_size - 2);
82
    return crc;
83
}
84

  
85
static int av_cold mlp_parse_init(AVCodecParserContext *s)
86
{
87
    if (!crc_init) {
88
        av_crc_init(crc_2D, 0, 16, 0x002D, sizeof(crc_2D));
89
        crc_init = 1;
90
    }
91

  
92
    return 0;
93
}
94

  
95 68
/** Read a major sync info header - contains high level information about
96 69
 *  the stream - sample rate, channel arrangement etc. Most of this
97 70
 *  information is not actually necessary for decoding, only for playback.
......
110 83
        return -1;
111 84
    }
112 85

  
113
    checksum = mlp_checksum16(gb->buffer, 26);
86
    checksum = ff_mlp_checksum16(gb->buffer, 26);
114 87
    if (checksum != AV_RL16(gb->buffer+26)) {
115 88
        av_log(log, AV_LOG_ERROR, "major sync info header checksum error\n");
116 89
        return -1;
......
310 283
AVCodecParser mlp_parser = {
311 284
    { CODEC_ID_MLP },
312 285
    sizeof(MLPParseContext),
313
    mlp_parse_init,
286
    ff_mlp_init_crc2D,
314 287
    mlp_parse,
315 288
    NULL,
316 289
};

Also available in: Unified diff