summaryrefslogtreecommitdiff
path: root/libavcodec/ac3enc.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2010-12-14 14:53:13 +0000
committerJustin Ruggles <justin.ruggles@gmail.com>2010-12-14 14:53:13 +0000
commit67d979fedef3b302693da10bcadf0dee3f6cda99 (patch)
tree06655312bf0d378a619c60b5b9637e719d2e645c /libavcodec/ac3enc.c
parent084f5c5afefb7a14eb8229b821c2e0313a55391d (diff)
Move writing of frame to the output bitstream to a separate function.
Originally committed as revision 25994 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ac3enc.c')
-rw-r--r--libavcodec/ac3enc.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index be632983a3..ca201604b3 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -914,10 +914,8 @@ static int compute_bit_allocation(AC3EncodeContext *s,
/**
* Write the AC-3 frame header to the output bitstream.
*/
-static void output_frame_header(AC3EncodeContext *s, unsigned char *frame)
+static void output_frame_header(AC3EncodeContext *s)
{
- init_put_bits(&s->pb, frame, AC3_MAX_CODED_FRAME_SIZE);
-
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);
@@ -1295,6 +1293,32 @@ static void output_frame_end(AC3EncodeContext *s)
/**
+ * Write the frame to the output bitstream.
+ */
+static void output_frame(AC3EncodeContext *s,
+ unsigned char *frame,
+ uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
+ uint8_t encoded_exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
+ uint8_t bap[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
+ int32_t mdct_coef[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
+ int8_t exp_shift[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS])
+{
+ int blk;
+
+ init_put_bits(&s->pb, frame, AC3_MAX_CODED_FRAME_SIZE);
+
+ output_frame_header(s);
+
+ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ output_audio_block(s, exp_strategy[blk], encoded_exp[blk],
+ bap[blk], mdct_coef[blk], exp_shift[blk], blk);
+ }
+
+ output_frame_end(s);
+}
+
+
+/**
* Encode a single AC-3 frame.
*/
static int ac3_encode_frame(AVCodecContext *avctx,
@@ -1302,7 +1326,6 @@ static int ac3_encode_frame(AVCodecContext *avctx,
{
AC3EncodeContext *s = avctx->priv_data;
const int16_t *samples = data;
- int blk;
int16_t planar_samples[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE+AC3_FRAME_SIZE];
int32_t mdct_coef[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
@@ -1323,14 +1346,7 @@ static int ac3_encode_frame(AVCodecContext *avctx,
compute_bit_allocation(s, bap, encoded_exp, exp_strategy, frame_bits);
- output_frame_header(s, frame);
-
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
- output_audio_block(s, exp_strategy[blk], encoded_exp[blk],
- bap[blk], mdct_coef[blk], exp_shift[blk], blk);
- }
-
- output_frame_end(s);
+ output_frame(s, frame, exp_strategy, encoded_exp, bap, mdct_coef, exp_shift);
return s->frame_size;
}