summaryrefslogtreecommitdiff
path: root/libavcodec/ac3enc.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2010-12-23 18:01:26 +0000
committerJustin Ruggles <justin.ruggles@gmail.com>2010-12-23 18:01:26 +0000
commite96dc767e41afcef429149ec87c078b2f8b8a289 (patch)
tree40db0c0e72e286534fb10c5c1c4e7d12377a87ba /libavcodec/ac3enc.c
parenta897423baa09dd651d7c339fdf386c954577d6d6 (diff)
Make sure that the 2nd CRC value does not match the AC-3 sync word.
This is optional for encoders, but it's a good idea and has minimal impact on performance. This will change the output for some files, but it happens not to affect the regression tests. Originally committed as revision 26083 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ac3enc.c')
-rw-r--r--libavcodec/ac3enc.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index ed86e61955..390844711e 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -1572,7 +1572,7 @@ static unsigned int pow_poly(unsigned int a, unsigned int n, unsigned int poly)
static void output_frame_end(AC3EncodeContext *s)
{
const AVCRC *crc_ctx = av_crc_get_table(AV_CRC_16_ANSI);
- int frame_size_58, pad_bytes, crc1, crc2, crc_inv;
+ int frame_size_58, pad_bytes, crc1, crc2_partial, crc2, crc_inv;
uint8_t *frame;
frame_size_58 = ((s->frame_size >> 2) + (s->frame_size >> 4)) << 1;
@@ -1594,9 +1594,15 @@ static void output_frame_end(AC3EncodeContext *s)
AV_WB16(frame + 2, crc1);
/* compute crc2 */
- crc2 = av_bswap16(av_crc(crc_ctx, 0,
- frame + frame_size_58,
- s->frame_size - frame_size_58 - 2));
+ crc2_partial = av_crc(crc_ctx, 0, frame + frame_size_58,
+ s->frame_size - frame_size_58 - 3);
+ crc2 = av_crc(crc_ctx, crc2_partial, frame + s->frame_size - 3, 1);
+ /* ensure crc2 does not match sync word by flipping crcrsv bit if needed */
+ if (crc2 == 0x770B) {
+ frame[s->frame_size - 3] ^= 0x1;
+ crc2 = av_crc(crc_ctx, crc2_partial, frame + s->frame_size - 3, 1);
+ }
+ crc2 = av_bswap16(crc2);
AV_WB16(frame + s->frame_size - 2, crc2);
}