[FFmpeg-devel] [PATCH] tiff: Return more meaningful error codes

James Almer jamrial at gmail.com
Sun Mar 29 06:41:36 CEST 2015


On 29/03/15 1:18 AM, Himangi Saraogi wrote:
> ---
>  libavcodec/tiffenc.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
> index 44cd956..a94b700 100644
> --- a/libavcodec/tiffenc.c
> +++ b/libavcodec/tiffenc.c
> @@ -164,7 +164,8 @@ static int add_entry1(TiffEncoderContext *s,
>   * @param dst output buffer
>   * @param n size of input buffer
>   * @param compr compression method
> - * @return number of output bytes. If an output error is encountered, -1 is returned
> + * @return number of output bytes. If an output error is encountered, a negative
> + * value corresponding to an AVERROR error code is returned.
>   */
>  static int encode_strip(TiffEncoderContext *s, const int8_t *src,
>                          uint8_t *dst, int n, int compr)
> @@ -177,14 +178,14 @@ static int encode_strip(TiffEncoderContext *s, const int8_t *src,
>          unsigned long zlen = s->buf_size - (*s->buf - s->buf_start);
>          if (compress(dst, &zlen, src, n) != Z_OK) {
>              av_log(s->avctx, AV_LOG_ERROR, "Compressing failed\n");
> -            return -1;
> +            return AVERROR_EXTERNAL;
>          }
>          return zlen;
>      }
>  #endif
>      case TIFF_RAW:
>          if (check_size(s, n))
> -            return -1;
> +            return AVERROR(EINVAL);

I'm not sure this qualifies as "Invalid argument", so I'll let someone else comment.

>          memcpy(dst, src, n);
>          return n;
>      case TIFF_PACKBITS:
> @@ -193,7 +194,7 @@ static int encode_strip(TiffEncoderContext *s, const int8_t *src,
>      case TIFF_LZW:
>          return ff_lzw_encode(s->lzws, src, n);
>      default:
> -        return -1;
> +        return AVERROR_BUG;

AVERROR(EINVAL) here.

If i do "ffmpeg -i INPUT -compression_algo 2 OUTPUT.tiff" I'm not triggering a bug, I'm 
passing an invalid/unsupported argument to the encoder.

>      }
>  }
>  
> @@ -304,7 +305,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
>      default:
>          av_log(s->avctx, AV_LOG_ERROR,
>                 "This colors format is not supported\n");
> -        return -1;
> +        return AVERROR(EINVAL);
>      }
>  
>      for (i = 0; i < s->bpp_tab_size; i++)
> 



More information about the ffmpeg-devel mailing list