Mercurial > libavcodec.hg
comparison mlp_parser.c @ 7559:fd24c8628221 libavcodec
mlp: Split common code from parser and decoder to be used by encoder.
author | ramiro |
---|---|
date | Wed, 13 Aug 2008 18:47:03 +0000 |
parents | 8813c715eb9d |
children | 45cfe1d44e86 |
comparison
equal
deleted
inserted
replaced
7558:aa55cb6a440d | 7559:fd24c8628221 |
---|---|
28 | 28 |
29 #include "libavutil/crc.h" | 29 #include "libavutil/crc.h" |
30 #include "bitstream.h" | 30 #include "bitstream.h" |
31 #include "parser.h" | 31 #include "parser.h" |
32 #include "mlp_parser.h" | 32 #include "mlp_parser.h" |
33 #include "mlp.h" | |
33 | 34 |
34 static const uint8_t mlp_quants[16] = { | 35 static const uint8_t mlp_quants[16] = { |
35 16, 20, 24, 0, 0, 0, 0, 0, | 36 16, 20, 24, 0, 0, 0, 0, 0, |
36 0, 0, 0, 0, 0, 0, 0, 0, | 37 0, 0, 0, 0, 0, 0, 0, 0, |
37 }; | 38 }; |
60 | 61 |
61 for (i = 0; i < 13; i++) | 62 for (i = 0; i < 13; i++) |
62 channels += thd_chancount[i] * ((chanmap >> i) & 1); | 63 channels += thd_chancount[i] * ((chanmap >> i) & 1); |
63 | 64 |
64 return channels; | 65 return channels; |
65 } | |
66 | |
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 } | 66 } |
94 | 67 |
95 /** Read a major sync info header - contains high level information about | 68 /** Read a major sync info header - contains high level information about |
96 * the stream - sample rate, channel arrangement etc. Most of this | 69 * the stream - sample rate, channel arrangement etc. Most of this |
97 * information is not actually necessary for decoding, only for playback. | 70 * information is not actually necessary for decoding, only for playback. |
108 if (gb->size_in_bits < 28 << 3) { | 81 if (gb->size_in_bits < 28 << 3) { |
109 av_log(log, AV_LOG_ERROR, "packet too short, unable to read major sync\n"); | 82 av_log(log, AV_LOG_ERROR, "packet too short, unable to read major sync\n"); |
110 return -1; | 83 return -1; |
111 } | 84 } |
112 | 85 |
113 checksum = mlp_checksum16(gb->buffer, 26); | 86 checksum = ff_mlp_checksum16(gb->buffer, 26); |
114 if (checksum != AV_RL16(gb->buffer+26)) { | 87 if (checksum != AV_RL16(gb->buffer+26)) { |
115 av_log(log, AV_LOG_ERROR, "major sync info header checksum error\n"); | 88 av_log(log, AV_LOG_ERROR, "major sync info header checksum error\n"); |
116 return -1; | 89 return -1; |
117 } | 90 } |
118 | 91 |
308 } | 281 } |
309 | 282 |
310 AVCodecParser mlp_parser = { | 283 AVCodecParser mlp_parser = { |
311 { CODEC_ID_MLP }, | 284 { CODEC_ID_MLP }, |
312 sizeof(MLPParseContext), | 285 sizeof(MLPParseContext), |
313 mlp_parse_init, | 286 ff_mlp_init_crc2D, |
314 mlp_parse, | 287 mlp_parse, |
315 NULL, | 288 NULL, |
316 }; | 289 }; |