Handle possible failure of ff_eval.
authorPanagiotis Issaris <takis.issaris@uhasselt.be>
Tue, 26 Sep 2006 14:04:36 +0000 (14:04 +0000)
committerPanagiotis Issaris <takis.issaris@uhasselt.be>
Tue, 26 Sep 2006 14:04:36 +0000 (14:04 +0000)
Originally committed as revision 6338 to svn://svn.ffmpeg.org/ffmpeg/trunk

ffmpeg.c
libavcodec/mpegvideo.c
libavcodec/ratecontrol.c
libavcodec/snow.c

index d2a169b1a7460f36223856aa75b0ef5b9587ddc6..dc8673fd5c064558ae9d9b9645dd306b86296696 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -827,6 +827,10 @@ static void do_video_out(AVFormatContext *s,
             ret = avcodec_encode_video(enc,
                                        bit_buffer, bit_buffer_size,
                                        &big_picture);
+            if (ret == -1) {
+                fprintf(stderr, "Video encoding failed\n");
+                exit(1);
+            }
             //enc->frame_number = enc->real_pict_num;
             if(ret>0){
                 pkt.data= bit_buffer;
index c7a76597a7a4f3a9965cac3cf553d5c344f73a38..0c61df33af4d6cdd7797b5bd98973e71cea140f3 100644 (file)
@@ -39,7 +39,7 @@
 //#include <assert.h>
 
 #ifdef CONFIG_ENCODERS
-static void encode_picture(MpegEncContext *s, int picture_number);
+static int encode_picture(MpegEncContext *s, int picture_number);
 #endif //CONFIG_ENCODERS
 static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s,
                                    DCTELEM *block, int n, int qscale);
@@ -2502,7 +2502,8 @@ int MPV_encode_picture(AVCodecContext *avctx,
 //printf("qs:%f %f %d\n", s->new_picture.quality, s->current_picture.quality, s->qscale);
         MPV_frame_start(s, avctx);
 
-        encode_picture(s, s->picture_number);
+        if (encode_picture(s, s->picture_number) < 0)
+            return -1;
 
         avctx->real_pict_num  = s->picture_number;
         avctx->header_bits = s->header_bits;
@@ -5463,10 +5464,13 @@ static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src)
     flush_put_bits(&dst->pb);
 }
 
-static void estimate_qp(MpegEncContext *s, int dry_run){
-    if (!s->fixed_qscale)
+static int estimate_qp(MpegEncContext *s, int dry_run){
+    if (!s->fixed_qscale) {
         s->current_picture_ptr->quality=
         s->current_picture.quality = ff_rate_estimate_qscale(s, dry_run);
+        if (s->current_picture.quality < 0)
+            return -1;
+    }
 
     if(s->adaptive_quant){
         switch(s->codec_id){
@@ -5488,7 +5492,7 @@ static void estimate_qp(MpegEncContext *s, int dry_run){
     update_qscale(s);
 }
 
-static void encode_picture(MpegEncContext *s, int picture_number)
+static int encode_picture(MpegEncContext *s, int picture_number)
 {
     int i;
     int bits;
@@ -5517,7 +5521,8 @@ static void encode_picture(MpegEncContext *s, int picture_number)
     }
 
     if(s->flags & CODEC_FLAG_PASS2){
-        estimate_qp(s, 1);
+        if (estimate_qp(s,1) < 0)
+            return -1;
         ff_get_2pass_fcode(s);
     }else if(!(s->flags & CODEC_FLAG_QSCALE)){
         if(s->pict_type==B_TYPE)
@@ -5623,7 +5628,8 @@ static void encode_picture(MpegEncContext *s, int picture_number)
         }
     }
 
-    estimate_qp(s, 0);
+    if (estimate_qp(s, 0) < 0)
+        return -1;
 
     if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==I_TYPE && !(s->flags & CODEC_FLAG_QSCALE))
         s->qscale= 3; //reduce clipping problems
index 02108248eca64f5bc38d4bf9aa20cad526f2675b..5c339fa152fa711d23340eaaa051fa2c97456548 100644 (file)
@@ -326,6 +326,10 @@ static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_f
     };
 
     bits= ff_eval(s->avctx->rc_eq, const_values, const_names, func1, func1_names, NULL, NULL, rce);
+    if (isnan(bits)) {
+        av_log(s->avctx, AV_LOG_ERROR, "Unable to parse rc_eq \"%s\".\n", s->avctx->rc_eq);
+        return -1;
+    }
 
     rcc->pass1_rc_eq_output_sum+= bits;
     bits*=rate_factor;
@@ -726,6 +730,8 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
         rate_factor= rcc->pass1_wanted_bits/rcc->pass1_rc_eq_output_sum * br_compensation;
 
         q= get_qscale(s, rce, rate_factor, picture_number);
+        if (q < 0)
+            return -1;
 
         assert(q>0.0);
 //printf("%f ", q);
index f4b9ee85f0b7efa178c2edc76c666f1593bd8985..c154f4ebc75352587430a5a38ae1ef65e11f757d 100644 (file)
@@ -3875,6 +3875,8 @@ static int ratecontrol_1pass(SnowContext *s, AVFrame *pict)
     }
 
     pict->quality= ff_rate_estimate_qscale(&s->m, 1);
+    if (pict->quality < 0)
+        return -1;
     s->lambda= pict->quality * 3/2;
     delta_qlog= qscale2qlog(pict->quality) - s->qlog;
     s->qlog+= delta_qlog;
@@ -4060,8 +4062,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
         s->m.pict_type =
         pict->pict_type= s->m.rc_context.entry[avctx->frame_number].new_pict_type;
         s->keyframe= pict->pict_type==FF_I_TYPE;
-        if(!(avctx->flags&CODEC_FLAG_QSCALE))
+        if(!(avctx->flags&CODEC_FLAG_QSCALE)) {
             pict->quality= ff_rate_estimate_qscale(&s->m, 0);
+            if (pict->quality < 0)
+                return -1;
+        }
     }else{
         s->keyframe= avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0;
         s->m.pict_type=
@@ -4181,6 +4186,8 @@ redo_frame:
 
         if(s->pass1_rc && plane_index==0){
             int delta_qlog = ratecontrol_1pass(s, pict);
+            if (delta_qlog < 0)
+                return -1;
             if(delta_qlog){
                 //reordering qlog in the bitstream would eliminate this reset
                 ff_init_range_encoder(c, buf, buf_size);
@@ -4267,7 +4274,8 @@ STOP_TIMER("pred-conv")}
     s->m.current_picture.quality = pict->quality;
     s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start);
     if(s->pass1_rc)
-        ff_rate_estimate_qscale(&s->m, 0);
+        if (ff_rate_estimate_qscale(&s->m, 0) < 0)
+            return -1;
     if(avctx->flags&CODEC_FLAG_PASS1)
         ff_write_pass1_stats(&s->m);
     s->m.last_pict_type = s->m.pict_type;