comparison flacenc.c @ 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
comparison
equal deleted inserted replaced
12330:18c7965807bf 12331:784ddf9d158a
1283 copy_samples(s, samples); 1283 copy_samples(s, samples);
1284 1284
1285 channel_decorrelation(s); 1285 channel_decorrelation(s);
1286 1286
1287 frame_bytes = encode_frame(s); 1287 frame_bytes = encode_frame(s);
1288
1289 /* fallback to verbatim mode if the compressed frame is larger than it
1290 would be if encoded uncompressed. */
1291 if (frame_bytes > s->max_framesize) {
1292 s->frame.verbatim_only = 1;
1293 frame_bytes = encode_frame(s);
1294 }
1295
1288 if (buf_size < frame_bytes) { 1296 if (buf_size < frame_bytes) {
1289 av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); 1297 av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");
1290 return 0; 1298 return 0;
1291 } 1299 }
1292 out_bytes = write_frame(s, frame, buf_size); 1300 out_bytes = write_frame(s, frame, buf_size);
1293
1294 /* fallback to verbatim mode if the compressed frame is larger than it
1295 would be if encoded uncompressed. */
1296 if (out_bytes > s->max_framesize) {
1297 s->frame.verbatim_only = 1;
1298 frame_bytes = encode_frame(s);
1299 if (buf_size < frame_bytes) {
1300 av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");
1301 return 0;
1302 }
1303 out_bytes = write_frame(s, frame, buf_size);
1304 }
1305 1301
1306 s->frame_count++; 1302 s->frame_count++;
1307 avctx->coded_frame->pts = s->sample_count; 1303 avctx->coded_frame->pts = s->sample_count;
1308 s->sample_count += avctx->frame_size; 1304 s->sample_count += avctx->frame_size;
1309 update_md5_sum(s, samples); 1305 update_md5_sum(s, samples);