Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -1942,7 +1942,7 @@ static unsigned int pow_poly(unsigned int a, unsigned int n, unsigned int poly) · 1941 unmodified lines | ||
| 1942 | 1942 | static void output_frame_end(AC3EncodeContext *s) |
| 1943 | 1943 | { |
| 1944 | 1944 | const AVCRC *crc_ctx = av_crc_get_table(AV_CRC_16_ANSI); |
| 1945 | − int frame_size_58, pad_bytes, crc1, crc2_partial, crc2, crc_inv; | |
| 1945 | + int frame_size_58, pad_bytes, crc1, crc2, crc_inv; | |
| 1946 | 1946 | uint8_t *frame; |
| 1947 | 1947 | |
| 1948 | 1948 | frame_size_58 = ((s->frame_size >> 2) + (s->frame_size >> 4)) << 1; |
| @@ -1958,7 +1958,7 @@ static void output_frame_end(AC3EncodeContext *s) · 9 unmodified lines | ||
| 1958 | 1958 | |
| 1959 | 1959 | if (s->eac3) { |
| 1960 | 1960 | /* compute crc2 */ |
| 1961 | − crc2_partial = av_crc(crc_ctx, 0, frame + 2, s->frame_size - 5); | |
| 1961 | + crc2 = av_crc(crc_ctx, 0, frame + 2, s->frame_size - 4); | |
| 1962 | 1962 | } else { |
| 1963 | 1963 | /* compute crc1 */ |
| 1964 | 1964 | /* this is not so easy because it is at the beginning of the data... */ |
| @@ -1968,16 +1968,17 @@ static void output_frame_end(AC3EncodeContext *s) · 3 unmodified lines | ||
| 1968 | 1968 | AV_WB16(frame + 2, crc1); |
| 1969 | 1969 | |
| 1970 | 1970 | /* compute crc2 */ |
| 1971 | − crc2_partial = av_crc(crc_ctx, 0, frame + frame_size_58, | |
| 1972 | − s->frame_size - frame_size_58 - 3); | |
| 1971 | + crc2 = av_crc(crc_ctx, 0, frame + frame_size_58, | |
| 1972 | + s->frame_size - frame_size_58 - 2); | |
| 1973 | 1973 | } |
| 1974 | − crc2 = av_crc(crc_ctx, crc2_partial, frame + s->frame_size - 3, 1); | |
| 1974 | + crc2 = av_bswap16(crc2); | |
| 1975 | 1975 | /* ensure crc2 does not match sync word by flipping crcrsv bit if needed */ |
| 1976 | − if (crc2 == 0x770B) { | |
| 1976 | + if (crc2 == 0x0B77) { | |
| 1977 | + /* The CRC generator polynomial is x^16 + x^15 + x^2 + 1, | |
| 1978 | + * so xor'ing with 0x18005 does not affect the CRC. */ | |
| 1977 | 1979 | frame[s->frame_size - 3] ^= 0x1; |
| 1978 | − crc2 = av_crc(crc_ctx, crc2_partial, frame + s->frame_size - 3, 1); | |
| 1980 | + crc2 ^= 0x8005; | |
| 1979 | 1981 | } |
| 1980 | − crc2 = av_bswap16(crc2); | |
| 1981 | 1982 | AV_WB16(frame + s->frame_size - 2, crc2); |
| 1982 | 1983 | } |
| 1983 | 1984 | |