---
 libavcodec/mpegvideo_enc.c | 129 +++++++++++++++++++++++----------------------
 1 file changed, 65 insertions(+), 64 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 9e155b0..ecf40c7 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -247,7 +247,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
             avctx->pix_fmt != AV_PIX_FMT_YUV422P) {
             av_log(avctx, AV_LOG_ERROR,
                    "only YUV420 and YUV422 are supported\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         break;
     case AV_CODEC_ID_MJPEG:
@@ -267,13 +267,13 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 
         if (!format_supported) {
             av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         break;
     default:
         if (avctx->pix_fmt != AV_PIX_FMT_YUV420P) {
             av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
     }
 
@@ -349,7 +349,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_ERROR,
                "a vbv buffer size is needed, "
                "for encoding with a maximum bitrate\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate) {
@@ -359,12 +359,12 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 
     if (avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate) {
         av_log(avctx, AV_LOG_ERROR, "bitrate below min bitrate\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate) {
         av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (avctx->rc_max_rate &&
@@ -378,7 +378,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         avctx->bit_rate * (int64_t)avctx->time_base.num >
             avctx->rc_buffer_size * (int64_t)avctx->time_base.den) {
         av_log(avctx, AV_LOG_ERROR, "VBV buffer too small for bitrate\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (!s->fixed_qscale &&
@@ -386,7 +386,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
             avctx->bit_rate_tolerance) {
         av_log(avctx, AV_LOG_ERROR,
                "bitrate tolerance too small for bitrate\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (s->avctx->rc_max_rate &&
@@ -404,18 +404,18 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         s->codec_id != AV_CODEC_ID_H263 && s->codec_id != AV_CODEC_ID_H263P &&
         s->codec_id != AV_CODEC_ID_FLV1) {
         av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE) {
         av_log(avctx, AV_LOG_ERROR,
                "OBMC is only supported with simple mb decision\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (s->quarter_sample && s->codec_id != AV_CODEC_ID_MPEG4) {
         av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (s->max_b_frames                    &&
@@ -423,7 +423,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         s->codec_id != AV_CODEC_ID_MPEG1VIDEO &&
         s->codec_id != AV_CODEC_ID_MPEG2VIDEO) {
         av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if ((s->codec_id == AV_CODEC_ID_MPEG4 ||
@@ -434,31 +434,31 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_ERROR,
                "Invalid pixel aspect ratio %i/%i, limit is 255/255\n",
                avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if ((s->flags & (CODEC_FLAG_INTERLACED_DCT | CODEC_FLAG_INTERLACED_ME)) &&
         s->codec_id != AV_CODEC_ID_MPEG4 && s->codec_id != 
AV_CODEC_ID_MPEG2VIDEO) {
         av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     // FIXME mpeg2 uses that too
     if (s->mpeg_quant && s->codec_id != AV_CODEC_ID_MPEG4) {
         av_log(avctx, AV_LOG_ERROR,
                "mpeg2 style quantization not supported by codec\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if ((s->mpv_flags & FF_MPV_FLAG_CBP_RD) && !avctx->trellis) {
         av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) &&
         s->avctx->mb_decision != FF_MB_DECISION_RD) {
         av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (s->avctx->scenechange_threshold < 1000000000 &&
@@ -466,19 +466,19 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_ERROR,
                "closed gop with scene change detection are not supported yet, "
                "set threshold to 1000000000\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (s->flags & CODEC_FLAG_LOW_DELAY) {
         if (s->codec_id != AV_CODEC_ID_MPEG2VIDEO) {
             av_log(avctx, AV_LOG_ERROR,
                   "low delay forcing is only available for mpeg2\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         if (s->max_b_frames != 0) {
             av_log(avctx, AV_LOG_ERROR,
                    "b frames cannot be used with low delay\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
     }
 
@@ -486,7 +486,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         if (avctx->qmax > 12) {
             av_log(avctx, AV_LOG_ERROR,
                    "non linear quant only supports qmax <= 12 currently\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
     }
 
@@ -497,14 +497,14 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         (s->codec_id != AV_CODEC_ID_H263P)) {
         av_log(avctx, AV_LOG_ERROR,
                "multi threaded encoding not supported by codec\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (s->avctx->thread_count < 1) {
         av_log(avctx, AV_LOG_ERROR,
                "automatic thread number detection not supported by codec,"
                "patch welcome\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (s->avctx->thread_count > 1)
@@ -512,7 +512,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 
     if (!avctx->time_base.den || !avctx->time_base.num) {
         av_log(avctx, AV_LOG_ERROR, "framerate not set\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (avctx->b_frame_strategy && (avctx->flags & CODEC_FLAG_PASS2)) {
@@ -552,7 +552,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
                "the maximum admitted value for the timebase denominator "
                "is %d\n", s->avctx->time_base.num, s->avctx->time_base.den,
                (1 << 16) - 1);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
     s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
 
@@ -571,21 +571,22 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
     case AV_CODEC_ID_MJPEG:
         s->out_format = FMT_MJPEG;
         s->intra_only = 1; /* force intra only for jpeg */
-        if (!CONFIG_MJPEG_ENCODER ||
-            ff_mjpeg_encode_init(s) < 0)
-            return -1;
+        if (!CONFIG_MJPEG_ENCODER)
+            return AVERROR_INVALIDDATA;
+        if ((ret = ff_mjpeg_encode_init(s)) < 0)
+            return ret;
         avctx->delay = 0;
         s->low_delay = 1;
         break;
     case AV_CODEC_ID_H261:
         if (!CONFIG_H261_ENCODER)
-            return -1;
-        if (ff_h261_get_picture_format(s->width, s->height) < 0) {
+            return AVERROR_INVALIDDATA;
+        if ((ret = ff_h261_get_picture_format(s->width, s->height)) < 0) {
             av_log(avctx, AV_LOG_ERROR,
                    "The specified picture size of %dx%d is not valid for the "
                    "H.261 codec.\nValid sizes are 176x144, 352x288\n",
                     s->width, s->height);
-            return -1;
+            return ret;
         }
         s->out_format = FMT_H261;
         avctx->delay  = 0;
@@ -594,7 +595,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         break;
     case AV_CODEC_ID_H263:
         if (!CONFIG_H263_ENCODER)
-        return -1;
+            return AVERROR_INVALIDDATA;
         if (ff_match_2uint16(ff_h263_format, FF_ARRAY_ELEMS(ff_h263_format),
                              s->width, s->height) == 8) {
             av_log(avctx, AV_LOG_INFO,
@@ -602,7 +603,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
                    "the H.263 codec.\nValid sizes are 128x96, 176x144, "
                    "352x288, 704x576, and 1408x1152."
                    "Try H.263+.\n", s->width, s->height);
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         s->out_format = FMT_H263;
         avctx->delay  = 0;
@@ -688,7 +689,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         s->low_delay         = 1;
         break;
     default:
-        return -1;
+        return AVERROR_UNKNOWN;
     }
 
     avctx->has_b_frames = !s->low_delay;
@@ -702,8 +703,8 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 
     /* init */
     ff_mpv_idct_init(s);
-    if (ff_mpv_common_init(s) < 0)
-        return -1;
+    if ((ret = ff_mpv_common_init(s)) < 0)
+        return ret;
 
     if (ARCH_X86)
         ff_mpv_encode_init_x86(s);
@@ -798,8 +799,8 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
                           31, 0);
     }
 
-    if (ff_rate_control_init(s) < 0)
-        return -1;
+    if ((ret = ff_rate_control_init(s)) < 0)
+        return ret;
 
 #if FF_API_ERROR_RATE
     FF_DISABLE_DEPRECATION_WARNINGS
@@ -964,7 +965,7 @@ static int load_input_picture(MpegEncContext *s, const 
AVFrame *pic_arg)
                     av_log(s->avctx, AV_LOG_ERROR,
                            "Error, Invalid timestamp=%"PRId64", "
                            "last=%"PRId64"\n", pts, s->user_specified_pts);
-                    return -1;
+                    return AVERROR_INVALIDDATA;
                 }
 
                 if (!s->low_delay && display_picture_number == 1)
@@ -1006,12 +1007,12 @@ static int load_input_picture(MpegEncContext *s, const 
AVFrame *pic_arg)
         if (direct) {
             if ((ret = av_frame_ref(pic->f, pic_arg)) < 0)
                 return ret;
-            if (ff_alloc_picture(s, pic, 1) < 0) {
-                return -1;
+            if ((ret = ff_alloc_picture(s, pic, 1)) < 0) {
+                return ret;
             }
         } else {
-            if (ff_alloc_picture(s, pic, 0) < 0) {
-                return -1;
+            if ((ret = ff_alloc_picture(s, pic, 0)) < 0) {
+                return ret;
             }
 
             if (pic->f->data[0] + INPLACE_OFFSET == pic_arg->data[0] &&
@@ -1132,7 +1133,7 @@ static int estimate_best_b_count(MpegEncContext *s)
     AVCodec *codec    = avcodec_find_encoder(s->avctx->codec_id);
     AVCodecContext *c = avcodec_alloc_context3(NULL);
     const int scale = s->avctx->brd_scale;
-    int i, j, out_size, p_lambda, b_lambda, lambda2;
+    int i, j, ret, out_size, p_lambda, b_lambda, lambda2;
     int64_t best_rd  = INT64_MAX;
     int best_b_count = -1;
 
@@ -1160,8 +1161,8 @@ static int estimate_best_b_count(MpegEncContext *s)
     c->time_base    = s->avctx->time_base;
     c->max_b_frames = s->max_b_frames;
 
-    if (avcodec_open2(c, codec, NULL) < 0)
-        return -1;
+    if ((ret = avcodec_open2(c, codec, NULL)) < 0)
+        return ret;
 
     for (i = 0; i < s->max_b_frames + 2; i++) {
         Picture pre_input, *pre_input_ptr = i ? s->input_picture[i - 1] :
@@ -1387,8 +1388,8 @@ no_output_pic:
             pic = &s->picture[i];
 
             pic->reference = s->reordered_input_picture[0]->reference;
-            if (ff_alloc_picture(s, pic, 0) < 0) {
-                return -1;
+            if ((ret = ff_alloc_picture(s, pic, 0)) < 0) {
+                return ret;
             }
 
             ret = av_frame_copy_props(pic->f, 
s->reordered_input_picture[0]->f);
@@ -1568,11 +1569,11 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, 
AVPacket *pkt,
 
     s->picture_in_gop_number++;
 
-    if (load_input_picture(s, pic_arg) < 0)
-        return -1;
+    if ((ret = load_input_picture(s, pic_arg)) < 0)
+        return ret;
 
-    if (select_input_picture(s) < 0) {
-        return -1;
+    if ((ret = select_input_picture(s)) < 0) {
+        return ret;
     }
 
     /* output? */
@@ -1603,8 +1604,8 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket 
*pkt,
         if (ret < 0)
             return ret;
 vbv_retry:
-        if (encode_picture(s, s->picture_number) < 0)
-            return -1;
+        if ((ret = encode_picture(s, s->picture_number)) < 0)
+            return ret;
 
         avctx->header_bits = s->header_bits;
         avctx->mv_bits     = s->mv_bits;
@@ -1679,7 +1680,7 @@ vbv_retry:
             if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) <
                     stuffing_count + 50) {
                 av_log(s->avctx, AV_LOG_ERROR, "stuffing too large\n");
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
 
             switch (s->codec_id) {
@@ -2605,13 +2606,13 @@ static int encode_thread(AVCodecContext *c, void *arg){
 
             if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 
MAX_MB_BYTES){
                 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
             if(s->data_partitioning){
                 if(   s->pb2   .buf_end - s->pb2   .buf - (put_bits_count(&s-> 
   pb2)>>3) < MAX_MB_BYTES
                    || s->tex_pb.buf_end - s->tex_pb.buf - 
(put_bits_count(&s->tex_pb )>>3) < MAX_MB_BYTES){
                     av_log(s->avctx, AV_LOG_ERROR, "encoded frame too 
large\n");
-                    return -1;
+                    return AVERROR_INVALIDDATA;
                 }
             }
 
@@ -3208,7 +3209,7 @@ static int estimate_qp(MpegEncContext *s, int dry_run){
         s->current_picture_ptr->f->quality =
         s->current_picture.f->quality = ff_rate_estimate_qscale(s, dry_run);
         if (s->current_picture.f->quality < 0)
-            return -1;
+            return AVERROR_INVALIDDATA;
     }
 
     if(s->adaptive_quant){
@@ -3282,8 +3283,8 @@ static int encode_picture(MpegEncContext *s, int 
picture_number)
     }
 
     if(s->flags & CODEC_FLAG_PASS2){
-        if (estimate_qp(s,1) < 0)
-            return -1;
+        if ((ret = estimate_qp(s,1)) < 0)
+            return ret;
         ff_get_2pass_fcode(s);
     }else if(!(s->flags & CODEC_FLAG_QSCALE)){
         if(s->pict_type==AV_PICTURE_TYPE_B)
@@ -3300,8 +3301,8 @@ static int encode_picture(MpegEncContext *s, int 
picture_number)
             return ret;
     }
 
-    if(ff_init_me(s)<0)
-        return -1;
+    if((ret = ff_init_me(s)) < 0)
+        return ret;
 
     /* Estimate motion for every MB */
     if(s->pict_type != AV_PICTURE_TYPE_I){
@@ -3393,8 +3394,8 @@ static int encode_picture(MpegEncContext *s, int 
picture_number)
         }
     }
 
-    if (estimate_qp(s, 0) < 0)
-        return -1;
+    if ((ret = estimate_qp(s, 0)) < 0)
+        return ret;
 
     if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==AV_PICTURE_TYPE_I 
&& !(s->flags & CODEC_FLAG_QSCALE))
         s->qscale= 3; //reduce clipping problems
-- 
1.8.3.2

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to