Revision f1f373c2

View differences:

libavcodec/flacenc.c
1242 1242
    FlacEncodeContext *s;
1243 1243
    int16_t *samples = data;
1244 1244
    int out_bytes;
1245
    int reencoded=0;
1245 1246

  
1246 1247
    s = avctx->priv_data;
1247 1248

  
1249
    if(buf_size < s->max_framesize*2) {
1250
        av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");
1251
        return 0;
1252
    }
1253

  
1248 1254
    init_frame(s);
1249 1255

  
1250 1256
    copy_samples(s, samples);
......
1254 1260
    for(ch=0; ch<s->channels; ch++) {
1255 1261
        encode_residual(s, ch);
1256 1262
    }
1263

  
1264
write_frame:
1257 1265
    init_put_bits(&s->pb, frame, buf_size);
1258 1266
    output_frame_header(s);
1259 1267
    output_subframes(s);
1260 1268
    output_frame_footer(s);
1261 1269
    out_bytes = put_bits_count(&s->pb) >> 3;
1262 1270

  
1263
    if(out_bytes > s->max_framesize || out_bytes >= buf_size) {
1264
        /* frame too large. use verbatim mode */
1265
        for(ch=0; ch<s->channels; ch++) {
1266
            encode_residual_v(s, ch);
1267
        }
1268
        init_put_bits(&s->pb, frame, buf_size);
1269
        output_frame_header(s);
1270
        output_subframes(s);
1271
        output_frame_footer(s);
1272
        out_bytes = put_bits_count(&s->pb) >> 3;
1273

  
1274
        if(out_bytes > s->max_framesize || out_bytes >= buf_size) {
1271
    if(out_bytes > s->max_framesize) {
1272
        if(reencoded) {
1275 1273
            /* still too large. must be an error. */
1276 1274
            av_log(avctx, AV_LOG_ERROR, "error encoding frame\n");
1277 1275
            return -1;
1278 1276
        }
1277

  
1278
        /* frame too large. use verbatim mode */
1279
        for(ch=0; ch<s->channels; ch++) {
1280
            encode_residual_v(s, ch);
1281
        }
1282
        reencoded = 1;
1283
        goto write_frame;
1279 1284
    }
1280 1285

  
1281 1286
    s->frame_count++;

Also available in: Unified diff