[4/5] libaom: Templatize code shared with libvpx to avoid code duplication

Message ID 1472056128-7656-5-git-send-email-diego@biurrun.de
State New
Headers show

Commit Message

Diego Biurrun Aug. 24, 2016, 4:28 p.m.
---
 libavcodec/libaom.c                          |  57 +-------------
 libavcodec/libaom.c_template.c               | 111 +++++++++++++++++++++++++++
 libavcodec/libaom.h                          |  10 +--
 libavcodec/{libaom.h => libaom.h_template.c} |  13 +---
 libavcodec/libvpx.c                          |  57 +-------------
 libavcodec/libvpx.h                          |   6 +-
 libavcodec/libvpxdec.c                       |   2 +-
 libavcodec/libvpxenc.c                       |   2 +-
 8 files changed, 126 insertions(+), 132 deletions(-)
 create mode 100644 libavcodec/libaom.c_template.c
 copy libavcodec/{libaom.h => libaom.h_template.c} (72%)

Comments

Luca Barbato Aug. 24, 2016, 6:01 p.m. | #1
On 24/08/16 18:28, Diego Biurrun wrote:
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index c6c9105..4044ccd 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -375,7 +375,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>      codecctl_int(avctx, VP8E_SET_CQ_LEVEL,          ctx->crf);
>  
>      //provide dummy value to initialize wrapper, values will be updated each _encode()
> -    vpx_img_wrap(&ctx->rawimg, ff_vpx_pixfmt_to_imgfmt(avctx->pix_fmt),
> +    vpx_img_wrap(&ctx->rawimg, ff_aom_pixfmt_to_imgfmt(avctx->pix_fmt),
>                   avctx->width, avctx->height, 1, (unsigned char *)1);

Looks wrong to me, and I'm not sure it simplifies a lot.

lu
Diego Biurrun Aug. 25, 2016, 8:45 a.m. | #2
On Wed, Aug 24, 2016 at 08:01:52PM +0200, Luca Barbato wrote:
> On 24/08/16 18:28, Diego Biurrun wrote:
> > --- a/libavcodec/libvpxenc.c
> > +++ b/libavcodec/libvpxenc.c
> > @@ -375,7 +375,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> >      codecctl_int(avctx, VP8E_SET_CQ_LEVEL,          ctx->crf);
> >  
> >      //provide dummy value to initialize wrapper, values will be updated each _encode()
> > -    vpx_img_wrap(&ctx->rawimg, ff_vpx_pixfmt_to_imgfmt(avctx->pix_fmt),
> > +    vpx_img_wrap(&ctx->rawimg, ff_aom_pixfmt_to_imgfmt(avctx->pix_fmt),
> >                   avctx->width, avctx->height, 1, (unsigned char *)1);
> 
> Looks wrong to me, and I'm not sure it simplifies a lot.

I can call it ff_aom_vpx_pixfmt_to_imgfmt(), or anything else really, if
you prefer.

Diego
Luca Barbato Aug. 25, 2016, 1:16 p.m. | #3
On 25/08/16 10:45, Diego Biurrun wrote:
> On Wed, Aug 24, 2016 at 08:01:52PM +0200, Luca Barbato wrote:
>> On 24/08/16 18:28, Diego Biurrun wrote:
>>> --- a/libavcodec/libvpxenc.c
>>> +++ b/libavcodec/libvpxenc.c
>>> @@ -375,7 +375,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>>      codecctl_int(avctx, VP8E_SET_CQ_LEVEL,          ctx->crf);
>>>  
>>>      //provide dummy value to initialize wrapper, values will be updated each _encode()
>>> -    vpx_img_wrap(&ctx->rawimg, ff_vpx_pixfmt_to_imgfmt(avctx->pix_fmt),
>>> +    vpx_img_wrap(&ctx->rawimg, ff_aom_pixfmt_to_imgfmt(avctx->pix_fmt),
>>>                   avctx->width, avctx->height, 1, (unsigned char *)1);
>>
>> Looks wrong to me, and I'm not sure it simplifies a lot.
> 
> I can call it ff_aom_vpx_pixfmt_to_imgfmt(), or anything else really, if
> you prefer.
> 

If you have both vpx and aom enabled what that function is supposed to do?

lu
Diego Biurrun Aug. 25, 2016, 1:34 p.m. | #4
On Thu, Aug 25, 2016 at 03:16:19PM +0200, Luca Barbato wrote:
> On 25/08/16 10:45, Diego Biurrun wrote:
> > On Wed, Aug 24, 2016 at 08:01:52PM +0200, Luca Barbato wrote:
> >> On 24/08/16 18:28, Diego Biurrun wrote:
> >>> --- a/libavcodec/libvpxenc.c
> >>> +++ b/libavcodec/libvpxenc.c
> >>> @@ -375,7 +375,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> >>>      codecctl_int(avctx, VP8E_SET_CQ_LEVEL,          ctx->crf);
> >>>  
> >>>      //provide dummy value to initialize wrapper, values will be updated each _encode()
> >>> -    vpx_img_wrap(&ctx->rawimg, ff_vpx_pixfmt_to_imgfmt(avctx->pix_fmt),
> >>> +    vpx_img_wrap(&ctx->rawimg, ff_aom_pixfmt_to_imgfmt(avctx->pix_fmt),
> >>>                   avctx->width, avctx->height, 1, (unsigned char *)1);
> >>
> >> Looks wrong to me, and I'm not sure it simplifies a lot.
> > 
> > I can call it ff_aom_vpx_pixfmt_to_imgfmt(), or anything else really, if
> > you prefer.
> 
> If you have both vpx and aom enabled what that function is supposed to do?

Translate between vpx/aom and libav pixel formats of course.  In any
case I have another patch pending.

Diego

Patch

diff --git a/libavcodec/libaom.c b/libavcodec/libaom.c
index f8bcc37..fbf35a3 100644
--- a/libavcodec/libaom.c
+++ b/libavcodec/libaom.c
@@ -1,6 +1,4 @@ 
 /*
- * Copyright (c) 2013 Guillaume Martres <smarter@ubuntu.com>
- *
  * This file is part of Libav.
  *
  * Libav is free software; you can redistribute it and/or
@@ -18,58 +16,9 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include <aom/aom_image.h>
-
 #include "libaom.h"
 
-enum AVPixelFormat ff_aom_imgfmt_to_pixfmt(aom_img_fmt_t img)
-{
-    switch (img) {
-    case AOM_IMG_FMT_RGB24:     return AV_PIX_FMT_RGB24;
-    case AOM_IMG_FMT_RGB565:    return AV_PIX_FMT_RGB565BE;
-    case AOM_IMG_FMT_RGB555:    return AV_PIX_FMT_RGB555BE;
-    case AOM_IMG_FMT_UYVY:      return AV_PIX_FMT_UYVY422;
-    case AOM_IMG_FMT_YUY2:      return AV_PIX_FMT_YUYV422;
-    case AOM_IMG_FMT_YVYU:      return AV_PIX_FMT_YVYU422;
-    case AOM_IMG_FMT_BGR24:     return AV_PIX_FMT_BGR24;
-    case AOM_IMG_FMT_ARGB:      return AV_PIX_FMT_ARGB;
-    case AOM_IMG_FMT_ARGB_LE:   return AV_PIX_FMT_BGRA;
-    case AOM_IMG_FMT_RGB565_LE: return AV_PIX_FMT_RGB565LE;
-    case AOM_IMG_FMT_RGB555_LE: return AV_PIX_FMT_RGB555LE;
-    case AOM_IMG_FMT_I420:      return AV_PIX_FMT_YUV420P;
-    case AOM_IMG_FMT_I422:      return AV_PIX_FMT_YUV422P;
-    case AOM_IMG_FMT_I444:      return AV_PIX_FMT_YUV444P;
-    case AOM_IMG_FMT_444A:      return AV_PIX_FMT_YUVA444P;
-    case AOM_IMG_FMT_I440:      return AV_PIX_FMT_YUV440P;
-    case AOM_IMG_FMT_I42016:    return AV_PIX_FMT_YUV420P16BE;
-    case AOM_IMG_FMT_I42216:    return AV_PIX_FMT_YUV422P16BE;
-    case AOM_IMG_FMT_I44416:    return AV_PIX_FMT_YUV444P16BE;
-    default:                    return AV_PIX_FMT_NONE;
-    }
-}
+#include "libaom.c_template.c"
 
-aom_img_fmt_t ff_aom_pixfmt_to_imgfmt(enum AVPixelFormat pix)
-{
-    switch (pix) {
-    case AV_PIX_FMT_RGB24:        return AOM_IMG_FMT_RGB24;
-    case AV_PIX_FMT_RGB565BE:     return AOM_IMG_FMT_RGB565;
-    case AV_PIX_FMT_RGB555BE:     return AOM_IMG_FMT_RGB555;
-    case AV_PIX_FMT_UYVY422:      return AOM_IMG_FMT_UYVY;
-    case AV_PIX_FMT_YUYV422:      return AOM_IMG_FMT_YUY2;
-    case AV_PIX_FMT_YVYU422:      return AOM_IMG_FMT_YVYU;
-    case AV_PIX_FMT_BGR24:        return AOM_IMG_FMT_BGR24;
-    case AV_PIX_FMT_ARGB:         return AOM_IMG_FMT_ARGB;
-    case AV_PIX_FMT_BGRA:         return AOM_IMG_FMT_ARGB_LE;
-    case AV_PIX_FMT_RGB565LE:     return AOM_IMG_FMT_RGB565_LE;
-    case AV_PIX_FMT_RGB555LE:     return AOM_IMG_FMT_RGB555_LE;
-    case AV_PIX_FMT_YUV420P:      return AOM_IMG_FMT_I420;
-    case AV_PIX_FMT_YUV422P:      return AOM_IMG_FMT_I422;
-    case AV_PIX_FMT_YUV444P:      return AOM_IMG_FMT_I444;
-    case AV_PIX_FMT_YUVA444P:     return AOM_IMG_FMT_444A;
-    case AV_PIX_FMT_YUV440P:      return AOM_IMG_FMT_I440;
-    case AV_PIX_FMT_YUV420P16BE:  return AOM_IMG_FMT_I42016;
-    case AV_PIX_FMT_YUV422P16BE:  return AOM_IMG_FMT_I42216;
-    case AV_PIX_FMT_YUV444P16BE:  return AOM_IMG_FMT_I44416;
-    default:                      return AOM_IMG_FMT_NONE;
-    }
-}
+FF_AOM_IMGFMT_TO_PIXFMT(TYPE, AOM)
+FF_AOM_PIXFMT_TO_IMGFMT(TYPE, AOM)
diff --git a/libavcodec/libaom.c_template.c b/libavcodec/libaom.c_template.c
new file mode 100644
index 0000000..7b69580
--- /dev/null
+++ b/libavcodec/libaom.c_template.c
@@ -0,0 +1,111 @@ 
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define FF_AOM_IMGFMT_TO_PIXFMT(TYPE, PREFIX)                          \
+enum AVPixelFormat ff_aom_imgfmt_to_pixfmt(TYPE img)                   \
+{                                                                      \
+    switch (img) {                                                     \
+    case PREFIX ## _IMG_FMT_RGB24:                                     \
+        return AV_PIX_FMT_RGB24;                                       \
+    case PREFIX ## _IMG_FMT_RGB565:                                    \
+        return AV_PIX_FMT_RGB565BE;                                    \
+    case PREFIX ## _IMG_FMT_RGB555:                                    \
+        return AV_PIX_FMT_RGB555BE;                                    \
+    case PREFIX ## _IMG_FMT_UYVY:                                      \
+        return AV_PIX_FMT_UYVY422;                                     \
+    case PREFIX ## _IMG_FMT_YUY2:                                      \
+        return AV_PIX_FMT_YUYV422;                                     \
+    case PREFIX ## _IMG_FMT_YVYU:                                      \
+        return AV_PIX_FMT_YVYU422;                                     \
+    case PREFIX ## _IMG_FMT_BGR24:                                     \
+        return AV_PIX_FMT_BGR24;                                       \
+    case PREFIX ## _IMG_FMT_ARGB:                                      \
+        return AV_PIX_FMT_ARGB;                                        \
+    case PREFIX ## _IMG_FMT_ARGB_LE:                                   \
+        return AV_PIX_FMT_BGRA;                                        \
+    case PREFIX ## _IMG_FMT_RGB565_LE:                                 \
+        return AV_PIX_FMT_RGB565LE;                                    \
+    case PREFIX ## _IMG_FMT_RGB555_LE:                                 \
+        return AV_PIX_FMT_RGB555LE;                                    \
+    case PREFIX ## _IMG_FMT_I420:                                      \
+        return AV_PIX_FMT_YUV420P;                                     \
+    case PREFIX ## _IMG_FMT_I422:                                      \
+        return AV_PIX_FMT_YUV422P;                                     \
+    case PREFIX ## _IMG_FMT_I444:                                      \
+        return AV_PIX_FMT_YUV444P;                                     \
+    case PREFIX ## _IMG_FMT_444A:                                      \
+        return AV_PIX_FMT_YUVA444P;                                    \
+    case PREFIX ## _IMG_FMT_I440:                                      \
+        return AV_PIX_FMT_YUV440P;                                     \
+    case PREFIX ## _IMG_FMT_I42016:                                    \
+        return AV_PIX_FMT_YUV420P16BE;                                 \
+    case PREFIX ## _IMG_FMT_I42216:                                    \
+        return AV_PIX_FMT_YUV422P16BE;                                 \
+    case PREFIX ## _IMG_FMT_I44416:                                    \
+        return AV_PIX_FMT_YUV444P16BE;                                 \
+    default:                                                           \
+        return AV_PIX_FMT_NONE;                                        \
+    }                                                                  \
+}
+
+#define FF_AOM_PIXFMT_TO_IMGFMT(TYPE, PREFIX)                          \
+TYPE ff_aom_pixfmt_to_imgfmt(enum AVPixelFormat pix)                   \
+{                                                                      \
+    switch (pix) {                                                     \
+    case AV_PIX_FMT_RGB24:                                             \
+        return PREFIX ## _IMG_FMT_RGB24;                               \
+    case AV_PIX_FMT_RGB565BE:                                          \
+        return PREFIX ## _IMG_FMT_RGB565;                              \
+    case AV_PIX_FMT_RGB555BE:                                          \
+        return PREFIX ## _IMG_FMT_RGB555;                              \
+    case AV_PIX_FMT_UYVY422:                                           \
+        return PREFIX ## _IMG_FMT_UYVY;                                \
+    case AV_PIX_FMT_YUYV422:                                           \
+        return PREFIX ## _IMG_FMT_YUY2;                                \
+    case AV_PIX_FMT_YVYU422:                                           \
+        return PREFIX ## _IMG_FMT_YVYU;                                \
+    case AV_PIX_FMT_BGR24:                                             \
+        return PREFIX ## _IMG_FMT_BGR24;                               \
+    case AV_PIX_FMT_ARGB:                                              \
+        return PREFIX ## _IMG_FMT_ARGB;                                \
+    case AV_PIX_FMT_BGRA:                                              \
+        return PREFIX ## _IMG_FMT_ARGB_LE;                             \
+    case AV_PIX_FMT_RGB565LE:                                          \
+        return PREFIX ## _IMG_FMT_RGB565_LE;                           \
+    case AV_PIX_FMT_RGB555LE:                                          \
+        return PREFIX ## _IMG_FMT_RGB555_LE;                           \
+    case AV_PIX_FMT_YUV420P:                                           \
+        return PREFIX ## _IMG_FMT_I420;                                \
+    case AV_PIX_FMT_YUV422P:                                           \
+        return PREFIX ## _IMG_FMT_I422;                                \
+    case AV_PIX_FMT_YUV444P:                                           \
+        return PREFIX ## _IMG_FMT_I444;                                \
+    case AV_PIX_FMT_YUVA444P:                                          \
+        return PREFIX ## _IMG_FMT_444A;                                \
+    case AV_PIX_FMT_YUV440P:                                           \
+        return PREFIX ## _IMG_FMT_I440;                                \
+    case AV_PIX_FMT_YUV420P16BE:                                       \
+        return PREFIX ## _IMG_FMT_I42016;                              \
+    case AV_PIX_FMT_YUV422P16BE:                                       \
+        return PREFIX ## _IMG_FMT_I42216;                              \
+    case AV_PIX_FMT_YUV444P16BE:                                       \
+        return PREFIX ## _IMG_FMT_I44416;                              \
+    default:                                                           \
+        return PREFIX ## _IMG_FMT_NONE;                                \
+    }                                                                  \
+}
diff --git a/libavcodec/libaom.h b/libavcodec/libaom.h
index 7a7b8db..eebc672 100644
--- a/libavcodec/libaom.h
+++ b/libavcodec/libaom.h
@@ -1,6 +1,4 @@ 
 /*
- * Copyright (c) 2013 Guillaume Martres <smarter@ubuntu.com>
- *
  * This file is part of Libav.
  *
  * Libav is free software; you can redistribute it and/or
@@ -21,11 +19,9 @@ 
 #ifndef AVCODEC_LIBAOM_H
 #define AVCODEC_LIBAOM_H
 
-#include <aom/aom_codec.h>
-
-#include "libavutil/pixfmt.h"
+#include <aom/aom_image.h>
 
-enum AVPixelFormat ff_aom_imgfmt_to_pixfmt(aom_img_fmt_t img);
-aom_img_fmt_t ff_aom_pixfmt_to_imgfmt(enum AVPixelFormat pix);
+#define TYPE aom_img_fmt_t
+#include "libaom.h_template.c"
 
 #endif /* AVCODEC_LIBAOM_H */
diff --git a/libavcodec/libaom.h b/libavcodec/libaom.h_template.c
similarity index 72%
copy from libavcodec/libaom.h
copy to libavcodec/libaom.h_template.c
index 7a7b8db..3ad2f14 100644
--- a/libavcodec/libaom.h
+++ b/libavcodec/libaom.h_template.c
@@ -1,6 +1,4 @@ 
 /*
- * Copyright (c) 2013 Guillaume Martres <smarter@ubuntu.com>
- *
  * This file is part of Libav.
  *
  * Libav is free software; you can redistribute it and/or
@@ -18,14 +16,7 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef AVCODEC_LIBAOM_H
-#define AVCODEC_LIBAOM_H
-
-#include <aom/aom_codec.h>
-
 #include "libavutil/pixfmt.h"
 
-enum AVPixelFormat ff_aom_imgfmt_to_pixfmt(aom_img_fmt_t img);
-aom_img_fmt_t ff_aom_pixfmt_to_imgfmt(enum AVPixelFormat pix);
-
-#endif /* AVCODEC_LIBAOM_H */
+enum AVPixelFormat ff_aom_imgfmt_to_pixfmt(TYPE img);
+TYPE ff_aom_pixfmt_to_imgfmt(enum AVPixelFormat pix);
diff --git a/libavcodec/libvpx.c b/libavcodec/libvpx.c
index cb07177..014935b 100644
--- a/libavcodec/libvpx.c
+++ b/libavcodec/libvpx.c
@@ -1,6 +1,4 @@ 
 /*
- * Copyright (c) 2013 Guillaume Martres <smarter@ubuntu.com>
- *
  * This file is part of Libav.
  *
  * Libav is free software; you can redistribute it and/or
@@ -18,58 +16,9 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include <vpx/vpx_codec.h>
-
 #include "libvpx.h"
 
-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;
-    case VPX_IMG_FMT_I422:      return AV_PIX_FMT_YUV422P;
-    case VPX_IMG_FMT_I444:      return AV_PIX_FMT_YUV444P;
-    case VPX_IMG_FMT_444A:      return AV_PIX_FMT_YUVA444P;
-    case VPX_IMG_FMT_I440:      return AV_PIX_FMT_YUV440P;
-    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;
-    default:                    return AV_PIX_FMT_NONE;
-    }
-}
+#include "libaom.c_template.c"
 
-vpx_img_fmt_t ff_vpx_pixfmt_to_imgfmt(enum AVPixelFormat pix)
-{
-    switch (pix) {
-    case AV_PIX_FMT_RGB24:        return VPX_IMG_FMT_RGB24;
-    case AV_PIX_FMT_RGB565BE:     return VPX_IMG_FMT_RGB565;
-    case AV_PIX_FMT_RGB555BE:     return VPX_IMG_FMT_RGB555;
-    case AV_PIX_FMT_UYVY422:      return VPX_IMG_FMT_UYVY;
-    case AV_PIX_FMT_YUYV422:      return VPX_IMG_FMT_YUY2;
-    case AV_PIX_FMT_YVYU422:      return VPX_IMG_FMT_YVYU;
-    case AV_PIX_FMT_BGR24:        return VPX_IMG_FMT_BGR24;
-    case AV_PIX_FMT_ARGB:         return VPX_IMG_FMT_ARGB;
-    case AV_PIX_FMT_BGRA:         return VPX_IMG_FMT_ARGB_LE;
-    case AV_PIX_FMT_RGB565LE:     return VPX_IMG_FMT_RGB565_LE;
-    case AV_PIX_FMT_RGB555LE:     return VPX_IMG_FMT_RGB555_LE;
-    case AV_PIX_FMT_YUV420P:      return VPX_IMG_FMT_I420;
-    case AV_PIX_FMT_YUV422P:      return VPX_IMG_FMT_I422;
-    case AV_PIX_FMT_YUV444P:      return VPX_IMG_FMT_I444;
-    case AV_PIX_FMT_YUVA444P:     return VPX_IMG_FMT_444A;
-    case AV_PIX_FMT_YUV440P:      return VPX_IMG_FMT_I440;
-    case AV_PIX_FMT_YUV420P16BE:  return VPX_IMG_FMT_I42016;
-    case AV_PIX_FMT_YUV422P16BE:  return VPX_IMG_FMT_I42216;
-    case AV_PIX_FMT_YUV444P16BE:  return VPX_IMG_FMT_I44416;
-    default:                      return VPX_IMG_FMT_NONE;
-    }
-}
+FF_AOM_IMGFMT_TO_PIXFMT(TYPE, VPX)
+FF_AOM_PIXFMT_TO_IMGFMT(TYPE, VPX)
diff --git a/libavcodec/libvpx.h b/libavcodec/libvpx.h
index b437f37..7494ab7 100644
--- a/libavcodec/libvpx.h
+++ b/libavcodec/libvpx.h
@@ -23,9 +23,7 @@ 
 
 #include <vpx/vpx_codec.h>
 
-#include "avcodec.h"
-
-enum AVPixelFormat ff_vpx_imgfmt_to_pixfmt(vpx_img_fmt_t img);
-vpx_img_fmt_t ff_vpx_pixfmt_to_imgfmt(enum AVPixelFormat pix);
+#define TYPE vpx_img_fmt_t
+#include "libaom.h_template.c"
 
 #endif /* AVCODEC_LIBVPX_H */
diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c
index 93a720f..43484ef 100644
--- a/libavcodec/libvpxdec.c
+++ b/libavcodec/libvpxdec.c
@@ -81,7 +81,7 @@  static int vp8_decode(AVCodecContext *avctx,
     }
 
     if ((img = vpx_codec_get_frame(&ctx->decoder, &iter))) {
-        avctx->pix_fmt = ff_vpx_imgfmt_to_pixfmt(img->fmt);
+        avctx->pix_fmt = ff_aom_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);
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index c6c9105..4044ccd 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -375,7 +375,7 @@  FF_ENABLE_DEPRECATION_WARNINGS
     codecctl_int(avctx, VP8E_SET_CQ_LEVEL,          ctx->crf);
 
     //provide dummy value to initialize wrapper, values will be updated each _encode()
-    vpx_img_wrap(&ctx->rawimg, ff_vpx_pixfmt_to_imgfmt(avctx->pix_fmt),
+    vpx_img_wrap(&ctx->rawimg, ff_aom_pixfmt_to_imgfmt(avctx->pix_fmt),
                  avctx->width, avctx->height, 1, (unsigned char *)1);
 
     cpb_props = ff_add_cpb_side_data(avctx);