From 0f5cc12c4f7282fa35a2bfd34519ac7b04eed7a3 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sat, 31 Jul 2010 16:46:32 +0000 Subject: Remove duplicate code by adding a flag for encoding in verbatim mode. Originally committed as revision 24621 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/flacenc.c | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) (limited to 'libavcodec/flacenc.c') diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index 7eabd9c..487d023 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -77,6 +77,7 @@ typedef struct FlacFrame { int bs_code[2]; uint8_t crc8; int ch_mode; + int verbatim_only; } FlacFrame; typedef struct FlacEncodeContext { @@ -472,6 +473,8 @@ static void init_frame(FlacEncodeContext *s) for (ch = 0; ch < s->channels; ch++) frame->subframes[ch].obits = 16; + + frame->verbatim_only = 0; } @@ -819,7 +822,7 @@ static int encode_residual_ch(FlacEncodeContext *s, int ch) } /* VERBATIM */ - if (n < 5) { + if (frame->verbatim_only || n < 5) { sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM; encode_residual_verbatim(res, smp, n); return sub->obits * n; @@ -985,36 +988,6 @@ static int encode_frame(FlacEncodeContext *s) } -static int encode_residual_v(FlacEncodeContext *s, int ch) -{ - int i, n; - FlacFrame *frame; - FlacSubframe *sub; - int32_t *res, *smp; - - frame = &s->frame; - sub = &frame->subframes[ch]; - res = sub->residual; - smp = sub->samples; - n = frame->blocksize; - - /* CONSTANT */ - for (i = 1; i < n; i++) - if (smp[i] != smp[0]) - break; - if (i == n) { - sub->type = sub->type_code = FLAC_SUBFRAME_CONSTANT; - res[0] = smp[0]; - return sub->obits; - } - - /* VERBATIM */ - sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM; - encode_residual_verbatim(res, smp, n); - return sub->obits * n; -} - - static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n) { int i, best; @@ -1236,7 +1209,6 @@ static void update_md5_sum(FlacEncodeContext *s, const int16_t *samples) static int flac_encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, void *data) { - int ch; FlacEncodeContext *s; const int16_t *samples = data; int out_bytes; @@ -1280,8 +1252,8 @@ write_frame: } /* frame too large. use verbatim mode */ - for (ch = 0; ch < s->channels; ch++) - encode_residual_v(s, ch); + s->frame.verbatim_only = 1; + encode_frame(s); reencoded = 1; goto write_frame; } -- cgit v1.1