# HG changeset patch # User jbr # Date 1280594792 0 # Node ID b2940a8f3db610f0a157f5cd0e4cb36dc0ebfcd6 # Parent 035ca6548e29a9eb9cfcd7005090a84a67779fc2 Remove duplicate code by adding a flag for encoding in verbatim mode. diff -r 035ca6548e29 -r b2940a8f3db6 flacenc.c --- a/flacenc.c Sat Jul 31 16:46:20 2010 +0000 +++ b/flacenc.c Sat Jul 31 16:46:32 2010 +0000 @@ -77,6 +77,7 @@ int bs_code[2]; uint8_t crc8; int ch_mode; + int verbatim_only; } FlacFrame; typedef struct FlacEncodeContext { @@ -472,6 +473,8 @@ for (ch = 0; ch < s->channels; ch++) frame->subframes[ch].obits = 16; + + frame->verbatim_only = 0; } @@ -819,7 +822,7 @@ } /* 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_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 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 @@ } /* 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; }