On 19/05/15 7:49 AM, Vittorio Giovara wrote:
> ---
> Another set of eyes for the pixel format mapping would be welcome.
> Vittorio
> 
>  libavcodec/libvpx.c    | 26 ++++++++++++++++++++++++++
>  libavcodec/libvpx.h    |  2 ++
>  libavcodec/libvpxdec.c |  4 ++--
>  3 files changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/libvpx.c b/libavcodec/libvpx.c
> index 20f4484..5adad66 100644
> --- a/libavcodec/libvpx.c
> +++ b/libavcodec/libvpx.c
> @@ -33,3 +33,29 @@ int ff_vp9_check_experimental(AVCodecContext *avctx)
>      }
>      return 0;
>  }
> +
> +enum AVPixelFormat ff_vpx_imgfmt_to_pixfmt(vpx_img_fmt_t img)
> +{
> +    switch(img) {
> +    case VPX_IMG_FMT_RGB24:     return AV_PIX_FMT_RGB24;
> +    case VPX_IMG_FMT_RGB565:    return AV_PIX_FMT_RGB565BE;
> +    case VPX_IMG_FMT_RGB555:    return AV_PIX_FMT_RGB555BE;
> +    case VPX_IMG_FMT_UYVY:      return AV_PIX_FMT_UYVY422;
> +    case VPX_IMG_FMT_YUY2:      return AV_PIX_FMT_YUYV422;
> +    case VPX_IMG_FMT_YVYU:      return AV_PIX_FMT_YVYU422;
> +    case VPX_IMG_FMT_BGR24:     return AV_PIX_FMT_BGR24;
> +    case VPX_IMG_FMT_ARGB:      return AV_PIX_FMT_ARGB;
> +    case VPX_IMG_FMT_ARGB_LE:   return AV_PIX_FMT_BGRA;
> +    case VPX_IMG_FMT_RGB565_LE: return AV_PIX_FMT_RGB565LE;
> +    case VPX_IMG_FMT_RGB555_LE: return AV_PIX_FMT_RGB555LE;
> +    case VPX_IMG_FMT_I420:      return AV_PIX_FMT_YUV420P;

vp8 supports only this one. Every other pix_fmt is vp9 only and should be 
guarded by a
CONFIG_LIBVPX_VP9_DECODER preprocessor check.

> +    case VPX_IMG_FMT_I422:      return AV_PIX_FMT_YUV422P;
> +    case VPX_IMG_FMT_I444:      return AV_PIX_FMT_YUV444P;
> +    case VPX_IMG_FMT_I440:      return AV_PIX_FMT_YUV440P;

This was added starting with libvpx 1.4.0. It will fail to compile with any 
prior version.
A quick preprocessor check to make sure this define is available is 
VPX_IMAGE_ABI_VERSION >= 3

> +    case VPX_IMG_FMT_444A:      return AV_PIX_FMT_YUVA444P;
> +    case VPX_IMG_FMT_I42016:    return AV_PIX_FMT_YUV420P16BE;
> +    case VPX_IMG_FMT_I42216:    return AV_PIX_FMT_YUV422P16BE;
> +    case VPX_IMG_FMT_I44416:    return AV_PIX_FMT_YUV444P16BE;

Likewise, these three were added with libvpx 1.4.0. Checking for 
VPX_IMG_FMT_HIGHBITDEPTH should
suffice here, or alternatively, the same abi version check as above if git 
snapshots before 1.4.0
was tagged are not important.
And the value of img->bit_depth should probably be checked instead and these 
high bitdepth pix_fmts
set accordingly.

> +    default:                    return AV_PIX_FMT_NONE;
> +    }
> +}
> diff --git a/libavcodec/libvpx.h b/libavcodec/libvpx.h
> index cb1ed09..79a05f4 100644
> --- a/libavcodec/libvpx.h
> +++ b/libavcodec/libvpx.h
> @@ -25,4 +25,6 @@
>  
>  int ff_vp9_check_experimental(AVCodecContext *avctx);
>  
> +enum AVPixelFormat ff_vpx_imgfmt_to_pixfmt(vpx_img_fmt_t img);
> +
>  #endif /* AVCODEC_LIBVPX_H */
> diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c
> index 6052207..a1f9c22 100644
> --- a/libavcodec/libvpxdec.c
> +++ b/libavcodec/libvpxdec.c
> @@ -56,7 +56,6 @@ static av_cold int vpx_init(AVCodecContext *avctx,
>          return AVERROR(EINVAL);
>      }
>  
> -    avctx->pix_fmt = AV_PIX_FMT_YUV420P;
>      return 0;
>  }
>  
> @@ -82,7 +81,8 @@ static int vp8_decode(AVCodecContext *avctx,
>      }
>  
>      if ((img = vpx_codec_get_frame(&ctx->decoder, &iter))) {
> -        if (img->fmt != VPX_IMG_FMT_I420) {
> +        avctx->pix_fmt = ff_vpx_imgfmt_to_pixfmt(img->fmt);
> +        if (avctx->pix_fmt == AV_PIX_FMT_NONE) {
>              av_log(avctx, AV_LOG_ERROR, "Unsupported output colorspace 
> (%d)\n",
>                     img->fmt);
>              return AVERROR_INVALIDDATA;
> 

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to