[vlc-devel] [PATCH 2/3] vpx: Decode additional profiles and high bit depth formats

Vittorio Giovara vittorio.giovara at gmail.com
Sun Sep 25 06:58:14 CEST 2016


This effectively bumps the minimum libvpx version to 1.4.
---
Not sure whether the place I added the conversion function is appropriate.
Also should the new minimum version requirement be enforced? If so, how?

Thanks,
    Vittorio

 modules/codec/vpx.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/modules/codec/vpx.c b/modules/codec/vpx.c
index fbe9995..d0dd57f 100644
--- a/modules/codec/vpx.c
+++ b/modules/codec/vpx.c
@@ -99,8 +99,76 @@ static void vpx_err_msg(vlc_object_t *this, struct vpx_codec_ctx *ctx,
 struct decoder_sys_t
 {
     struct vpx_codec_ctx ctx;
+    vpx_codec_caps_t codec_caps;
 };
 
+static const struct
+{
+    vlc_fourcc_t     i_chroma;
+    enum vpx_img_fmt i_chroma_id;
+    int              i_range;
+    int              i_bitdepth;
+    int              i_needs_hack;
+
+} chroma_table[] =
+{
+    { VLC_CODEC_I420, VPX_IMG_FMT_I420, 0, 8, 0 },
+    { VLC_CODEC_I422, VPX_IMG_FMT_I422, 0, 8, 0 },
+    { VLC_CODEC_I444, VPX_IMG_FMT_I444, 0, 8, 0 },
+    { VLC_CODEC_I440, VPX_IMG_FMT_I440, 0, 8, 0 },
+
+    { VLC_CODEC_J420, VPX_IMG_FMT_I420, 1, 8, 0 },
+    { VLC_CODEC_J422, VPX_IMG_FMT_I422, 1, 8, 0 },
+    { VLC_CODEC_J444, VPX_IMG_FMT_I444, 1, 8, 0 },
+    { VLC_CODEC_J440, VPX_IMG_FMT_I440, 1, 8, 0 },
+
+    { VLC_CODEC_YV12, VPX_IMG_FMT_YV12, 0, 8, 0 },
+    { VLC_CODEC_YUVA, VPX_IMG_FMT_444A, 0, 8, 0 },
+    { VLC_CODEC_YUYV, VPX_IMG_FMT_YUY2, 0, 8, 0 },
+    { VLC_CODEC_UYVY, VPX_IMG_FMT_UYVY, 0, 8, 0 },
+    { VLC_CODEC_YVYU, VPX_IMG_FMT_YVYU, 0, 8, 0 },
+
+    { VLC_CODEC_RGB15, VPX_IMG_FMT_RGB555, 0, 8, 0 },
+    { VLC_CODEC_RGB16, VPX_IMG_FMT_RGB565, 0, 8, 0 },
+    { VLC_CODEC_RGB24, VPX_IMG_FMT_RGB24, 0, 8, 0 },
+    { VLC_CODEC_RGB32, VPX_IMG_FMT_RGB32, 0, 8, 0 },
+
+    { VLC_CODEC_ARGB, VPX_IMG_FMT_ARGB, 0, 8, 0 },
+    { VLC_CODEC_BGRA, VPX_IMG_FMT_ARGB_LE, 0, 8, 0 },
+
+    { VLC_CODEC_GBR_PLANAR, VPX_IMG_FMT_I444, 0, 8, 1 }
+    { VLC_CODEC_GBR_PLANAR_10L, VPX_IMG_FMT_I44416, 0, 10, 1 }
+
+    { VLC_CODEC_I420_10L, VPX_IMG_FMT_I42016, 0, 10, 0 },
+    { VLC_CODEC_I422_10L, VPX_IMG_FMT_I42216, 0, 10, 0 },
+    { VLC_CODEC_I444_10L, VPX_IMG_FMT_I44416, 0, 10, 0 },
+
+    { VLC_CODEC_I420_12L, VPX_IMG_FMT_I42016, 0, 12, 0 },
+    { VLC_CODEC_I422_12L, VPX_IMG_FMT_I42216, 0, 12, 0 },
+    { VLC_CODEC_I444_12L, VPX_IMG_FMT_I44416, 0, 12, 0 },
+
+    { VLC_CODEC_I444_16L, VPX_IMG_FMT_I44416, 0, 16, 0 },
+
+    { 0, 0, 0, 0, 0 },
+};
+
+static vlc_fourcc_t FindVlcChroma( struct vpx_image *img, vpx_codec_caps_t codec_caps )
+{
+    int hack = (img->fmt & VPX_IMG_FMT_I444) && (img->cs == VPX_CS_SRGB);
+
+    if( img->bit_depth > 8 && !(codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) )
+        return 0;
+
+    for( int i = 0; chroma_table[i].i_chroma != 0; i++ )
+        if( chroma_table[i].i_chroma_id == img->fmt &&
+            chroma_table[i].i_range == img->range &&
+            chroma_table[i].i_bitdepth == img->bit_depth &&
+            chroma_table[i].i_needs_hack == hack )
+            return chroma_table[i].i_chroma;
+
+    return 0;
+}
+
 /****************************************************************************
  * Decode: the whole thing
  ****************************************************************************/
@@ -151,7 +219,9 @@ static picture_t *Decode(decoder_t *dec, block_t **pp_block)
     mtime_t pts = *pkt_pts;
     free(pkt_pts);
 
-    if (img->fmt != VPX_IMG_FMT_I420) {
+    dec->fmt_out.i_codec = FindVlcChroma(img, dec->p_sys->codec_caps);
+
+    if( dec->fmt_out.i_codec == 0 ) {
         msg_Err(dec, "Unsupported output colorspace %d", img->fmt);
         return NULL;
     }
@@ -200,6 +270,7 @@ static int OpenDecoder(vlc_object_t *p_this)
 {
     decoder_t *dec = (decoder_t *)p_this;
     const struct vpx_codec_iface *iface;
+    vpx_codec_caps_t codec_caps = 0;
     int vp_version;
 
     switch (dec->fmt_in.i_codec)
@@ -212,6 +283,7 @@ static int OpenDecoder(vlc_object_t *p_this)
 #endif
 #ifdef ENABLE_VP9_DECODER
     case VLC_CODEC_VP9:
+        codec_caps = vpx_codec_get_caps(vpx_codec_vp9_cx());
         iface = &vpx_codec_vp9_dx_algo;
         vp_version = 9;
         break;
@@ -238,12 +310,13 @@ static int OpenDecoder(vlc_object_t *p_this)
         return VLC_EGENERIC;;
     }
 
+    dec->p_sys->codec_caps = codec_caps;
+
     dec->pf_decode_video = Decode;
 
     dec->fmt_out.i_cat = VIDEO_ES;
     dec->fmt_out.video.i_width = dec->fmt_in.video.i_width;
     dec->fmt_out.video.i_height = dec->fmt_in.video.i_height;
-    dec->fmt_out.i_codec = VLC_CODEC_I420;
 
     return VLC_SUCCESS;
 }
-- 
2.10.0



More information about the vlc-devel mailing list