changeset 12331:784ddf9d158a libavcodec

Simplify verbatim mode fallback by checking the frame size before writing.
author jbr
date Sat, 31 Jul 2010 21:08:53 +0000
parents 18c7965807bf
children eeb078c8830a
files flacenc.c
diffstat 1 files changed, 8 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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;