# HG changeset patch # User jbr # Date 1280610533 0 # Node ID 784ddf9d158a00b12683bc4ad5c0db9553902adf # Parent 18c7965807bf6cd6495a77e5aa8dcf66328591f3 Simplify verbatim mode fallback by checking the frame size before writing. diff -r 18c7965807bf -r 784ddf9d158a flacenc.c --- a/flacenc.c Sat Jul 31 20:52:33 2010 +0000 +++ b/flacenc.c Sat Jul 31 21:08:53 2010 +0000 @@ -1285,24 +1285,20 @@ channel_decorrelation(s); frame_bytes = encode_frame(s); + + /* fallback to verbatim mode if the compressed frame is larger than it + would be if encoded uncompressed. */ + if (frame_bytes > s->max_framesize) { + s->frame.verbatim_only = 1; + frame_bytes = encode_frame(s); + } + if (buf_size < frame_bytes) { av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); return 0; } out_bytes = write_frame(s, frame, buf_size); - /* fallback to verbatim mode if the compressed frame is larger than it - would be if encoded uncompressed. */ - if (out_bytes > s->max_framesize) { - s->frame.verbatim_only = 1; - frame_bytes = encode_frame(s); - if (buf_size < frame_bytes) { - av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); - return 0; - } - out_bytes = write_frame(s, frame, buf_size); - } - s->frame_count++; avctx->coded_frame->pts = s->sample_count; s->sample_count += avctx->frame_size;