---
 libavcodec/h264_slice.c     |  6 +++---
 libavcodec/vdpau.c          | 11 +++++++++++
 libavcodec/vdpau_h264.c     | 29 ++++++++++++++++++++++++++++-
 libavcodec/vdpau_internal.h |  3 +++
 4 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index fe9c0e9..6379d29 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -970,6 +970,9 @@ static enum AVPixelFormat get_pixel_format(H264Context *h)
             *fmt++ = AV_PIX_FMT_YUV420P10;
         break;
     case 8:
+#if CONFIG_H264_VDPAU_HWACCEL
+        *fmt++ = AV_PIX_FMT_VDPAU;
+#endif
         if (CHROMA444(h)) {
             if (h->avctx->colorspace == AVCOL_SPC_RGB)
                 *fmt++ = AV_PIX_FMT_GBRP;
@@ -993,9 +996,6 @@ static enum AVPixelFormat get_pixel_format(H264Context *h)
             *fmt++ = AV_PIX_FMT_VDA_VLD;
             *fmt++ = AV_PIX_FMT_VDA;
 #endif
-#if CONFIG_H264_VDPAU_HWACCEL
-            *fmt++ = AV_PIX_FMT_VDPAU;
-#endif
             if (h->avctx->codec->pix_fmts)
                 choices = h->avctx->codec->pix_fmts;
             else if (h->avctx->color_range == AVCOL_RANGE_JPEG)
diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index 463e600..e22ab1e 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -70,6 +70,17 @@ int av_vdpau_get_surface_parameters(AVCodecContext *avctx, 
VdpChromaType *type,
     VdpChromaType t = VDP_CHROMA_TYPE_420;
     uint32_t w = avctx->coded_width;
     uint32_t h = avctx->coded_height;
+    int val = 0;
+
+    switch (avctx->codec_id)
+    {
+    case AV_CODEC_ID_H264:
+        val = ff_vdpau_h264_get_chroma_type(avctx, &t);
+        break;
+    }
+
+    if (val < 0)
+        return val;
 
     /* See <vdpau/vdpau.h> for per-type alignment constraints. */
     switch (t)
diff --git a/libavcodec/vdpau_h264.c b/libavcodec/vdpau_h264.c
index 6774882..578b711 100644
--- a/libavcodec/vdpau_h264.c
+++ b/libavcodec/vdpau_h264.c
@@ -203,10 +203,37 @@ static int vdpau_h264_end_frame(AVCodecContext *avctx)
     return 0;
 }
 
+int ff_vdpau_h264_get_chroma_type(const AVCodecContext *avctx,
+                                  VdpChromaType *type)
+{
+    const H264Context *h = avctx->priv_data;
+
+    switch (h->sps.chroma_format_idc) {
+    case 1:
+        *type = VDP_CHROMA_TYPE_420;
+        break;
+    case 2:
+        *type = VDP_CHROMA_TYPE_422;
+        break;
+    case 3:
+        *type = VDP_CHROMA_TYPE_444;
+        break;
+    default:
+        return AVERROR(ENOSYS);
+    }
+    return 0;
+}
+
 static int vdpau_h264_init(AVCodecContext *avctx)
 {
     VdpDecoderProfile profile;
     uint32_t level = avctx->level;
+    VdpChromaType type;
+    int val;
+
+    val = ff_vdpau_h264_get_chroma_type(avctx, &type);
+    if (val < 0)
+        return val;
 
     switch (avctx->profile & ~FF_PROFILE_H264_INTRA) {
     case FF_PROFILE_H264_BASELINE:
@@ -235,7 +262,7 @@ static int vdpau_h264_init(AVCodecContext *avctx)
     if ((avctx->profile & FF_PROFILE_H264_INTRA) && avctx->level == 11)
         level = VDP_DECODER_LEVEL_H264_1b;
 
-    return ff_vdpau_common_init(avctx, profile, level, VDP_CHROMA_TYPE_420);
+    return ff_vdpau_common_init(avctx, profile, level, type);
 }
 
 AVHWAccel ff_h264_vdpau_hwaccel = {
diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h
index bcdeb90..05b3361 100644
--- a/libavcodec/vdpau_internal.h
+++ b/libavcodec/vdpau_internal.h
@@ -116,4 +116,7 @@ int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx);
 int ff_vdpau_add_buffer(struct vdpau_picture_context *pic, const uint8_t *buf,
                         uint32_t buf_size);
 
+int ff_vdpau_h264_get_chroma_type(const AVCodecContext *avctx,
+                                  VdpChromaType *type);
+
 #endif /* AVCODEC_VDPAU_INTERNAL_H */
-- 
2.1.3

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

Reply via email to