hwcontext_dxva2: support P010 10-bit surfaces
authorHendrik Leppkes <h.leppkes@gmail.com>
Wed, 22 Jun 2016 21:27:30 +0000 (23:27 +0200)
committerHendrik Leppkes <h.leppkes@gmail.com>
Wed, 22 Jun 2016 21:28:47 +0000 (23:28 +0200)
libavutil/hwcontext_dxva2.c

index 56ae317ddde66d3c8faafa3cc2b7c40315fb8e74..ccee287ee654a307407db734f9d5b44726d14b6e 100644 (file)
@@ -29,6 +29,7 @@
 #include <dxva2api.h>
 #include <initguid.h>
 
+#include "avassert.h"
 #include "common.h"
 #include "hwcontext.h"
 #include "hwcontext_dxva2.h"
@@ -52,6 +53,7 @@ static const struct {
     enum AVPixelFormat pix_fmt;
 } supported_formats[] = {
     { MKTAG('N', 'V', '1', '2'), AV_PIX_FMT_NV12 },
+    { MKTAG('P', '0', '1', '0'), AV_PIX_FMT_P010 },
 };
 
 DEFINE_GUID(video_decoder_service,   0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
@@ -236,6 +238,18 @@ static int dxva2_transfer_data(AVHWFramesContext *ctx, AVFrame *dst,
     HRESULT            hr;
 
     int download = !!src->hw_frames_ctx;
+    int bytes_per_component;
+
+    switch (ctx->sw_format) {
+        case AV_PIX_FMT_NV12:
+            bytes_per_component = 1;
+            break;
+        case AV_PIX_FMT_P010:
+            bytes_per_component = 2;
+            break;
+        default:
+            av_assert0(0);
+    }
 
     surface = (IDirect3DSurface9*)(download ? src->data[3] : dst->data[3]);
 
@@ -255,17 +269,17 @@ static int dxva2_transfer_data(AVHWFramesContext *ctx, AVFrame *dst,
     if (download) {
         av_image_copy_plane(dst->data[0], dst->linesize[0],
                             (uint8_t*)LockedRect.pBits, LockedRect.Pitch,
-                            src->width, src->height);
+                            src->width * bytes_per_component, src->height);
         av_image_copy_plane(dst->data[1], dst->linesize[1],
                             (uint8_t*)LockedRect.pBits + LockedRect.Pitch * surfaceDesc.Height,
-                            LockedRect.Pitch, src->width, src->height / 2);
+                            LockedRect.Pitch, src->width * bytes_per_component, src->height / 2);
     } else {
         av_image_copy_plane((uint8_t*)LockedRect.pBits, LockedRect.Pitch,
                             dst->data[0], dst->linesize[0],
-                            src->width, src->height);
+                            src->width * bytes_per_component, src->height);
         av_image_copy_plane((uint8_t*)LockedRect.pBits + LockedRect.Pitch * surfaceDesc.Height,
                             LockedRect.Pitch, dst->data[1], dst->linesize[1],
-                            src->width, src->height / 2);
+                            src->width * bytes_per_component, src->height / 2);
     }
 
     IDirect3DSurface9_UnlockRect(surface);