---
libavcodec/ac3enc.c | 30 +++++++++++++++---------------
1 files changed, 15 insertions(+), 15 deletions(-)
diff --git libavcodec/ac3enc.c libavcodec/ac3enc.c
index 911a684..314dc70 100644
--- libavcodec/ac3enc.c
+++ libavcodec/ac3enc.c
@@ -51,7 +51,7 @@ typedef struct AC3EncodeContext {
int sample_rate; ///< sampling frequency, in Hz
int frame_size_min; ///< minimum frame size in case rounding is necessary
- int frame_size; ///< current frame size in words
+ int frame_size; ///< current frame size in bytes
int frame_size_code; ///< frame size code (frmsizecod)
int bits_written; ///< total bits written (used to avg. bitrate)
int samples_written; ///< total samples written (used to avg. bitrate)
@@ -635,7 +635,7 @@ static int bit_alloc(AC3EncodeContext *s,
}
#ifdef DEBUG_BITALLOC
dprintf(s->avctx, "snr=%d mant_bits=%d diff=%d\n", snr_offset, mant_bits,
- 16 * s->frame_size - (s->frame_bits + s->exp_bits + mant_bits));
+ 8 * s->frame_size - (s->frame_bits + s->exp_bits + mant_bits));
#endif
return mant_bits;
}
@@ -717,7 +717,7 @@ static int cbr_bit_alloc(AC3EncodeContext *s,
int ch;
int snr_offset, snr_incr, bits_left;
- bits_left = 16 * s->frame_size - (s->frame_bits + s->exp_bits);
+ bits_left = 8 * s->frame_size - (s->frame_bits + s->exp_bits);
snr_offset = s->coarse_snr_offset << 4;
if ((snr_offset | s->fine_snr_offset[0]) == 1023)
@@ -857,7 +857,7 @@ static av_cold int AC3_encode_init(AVCodecContext *avctx)
return -1;
s->bit_rate = bitrate;
s->frame_size_code = i << 1;
- s->frame_size_min = ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];
+ s->frame_size_min = ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code] * 2;
s->bits_written = 0;
s->samples_written = 0;
s->frame_size = s->frame_size_min;
@@ -944,7 +944,7 @@ static void output_frame_header(AC3EncodeContext *s, unsigned char *frame)
put_bits(&s->pb, 16, 0x0b77); /* frame header */
put_bits(&s->pb, 16, 0); /* crc1: will be filled later */
put_bits(&s->pb, 2, s->bit_alloc.sr_code);
- put_bits(&s->pb, 6, s->frame_size_code + (s->frame_size - s->frame_size_min));
+ put_bits(&s->pb, 6, s->frame_size_code + (s->frame_size - s->frame_size_min)/2);
put_bits(&s->pb, 5, s->bitstream_id);
put_bits(&s->pb, 3, s->bitstream_mode);
put_bits(&s->pb, 3, s->channel_mode);
@@ -1278,25 +1278,25 @@ static void output_frame_end(AC3EncodeContext *s)
flush_put_bits(&s->pb);
/* add zero bytes to reach the frame size */
frame = s->pb.buf;
- n = 2 * s->frame_size - (put_bits_ptr(&s->pb) - frame) - 2;
+ n = s->frame_size - (put_bits_ptr(&s->pb) - frame) - 2;
assert(n >= 0);
if (n > 0)
memset(put_bits_ptr(&s->pb), 0, n);
/* Now we must compute both crcs : this is not so easy for crc1
because it is at the beginning of the data... */
- frame_size_58 = (frame_size >> 1) + (frame_size >> 3);
+ frame_size_58 = ((frame_size >> 2) + (frame_size >> 4)) << 1;
crc1 = av_bswap16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
- frame + 4, 2 * frame_size_58 - 4));
+ frame + 4, frame_size_58 - 4));
/* XXX: could precompute crc_inv */
- crc_inv = pow_poly((CRC16_POLY >> 1), (16 * frame_size_58) - 16, CRC16_POLY);
+ crc_inv = pow_poly((CRC16_POLY >> 1), (8 * frame_size_58) - 16, CRC16_POLY);
crc1 = mul_poly(crc_inv, crc1, CRC16_POLY);
AV_WB16(frame+2,crc1);
crc2 = av_bswap16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
- frame + 2 * frame_size_58,
- (frame_size - frame_size_58) * 2 - 2));
- AV_WB16(frame+2*frame_size-2, crc2);
+ frame + frame_size_58,
+ (frame_size - frame_size_58) - 2));
+ AV_WB16(frame+frame_size-2, crc2);
// printf("n=%d frame_size=%d\n", n, frame_size);
}
@@ -1328,7 +1328,7 @@ static void adjust_frame_size(AC3EncodeContext *s)
s->bits_written -= s->bit_rate;
s->samples_written -= s->sample_rate;
}
- s->frame_size = s->frame_size_min + (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate);
+ s->frame_size = s->frame_size_min + 2 * (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate);
}
/**
@@ -1440,10 +1440,10 @@ static int AC3_encode_frame(AVCodecContext *avctx,
}
output_frame_end(s);
- s->bits_written += s->frame_size * 16;
+ s->bits_written += s->frame_size * 8;
s->samples_written += AC3_FRAME_SIZE;
- return s->frame_size * 2;
+ return s->frame_size;
}
static av_cold int AC3_encode_close(AVCodecContext *avctx)
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc