Merge commit '2ef87815fec059504370ae3050cc243a53553915'
authorHendrik Leppkes <h.leppkes@gmail.com>
Mon, 14 Nov 2016 14:15:19 +0000 (15:15 +0100)
committerHendrik Leppkes <h.leppkes@gmail.com>
Mon, 14 Nov 2016 14:15:19 +0000 (15:15 +0100)
* commit '2ef87815fec059504370ae3050cc243a53553915':
  hwcontext_dxva2: add support for p010

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
1  2 
libavutil/hwcontext_dxva2.c

@@@ -1,18 -1,18 +1,18 @@@
  /*
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg 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,
 + * FFmpeg 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
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -29,7 -29,6 +29,7 @@@
  #include <dxva2api.h>
  #include <initguid.h>
  
 +#include "avassert.h"
  #include "common.h"
  #include "hwcontext.h"
  #include "hwcontext_dxva2.h"
@@@ -37,7 -36,6 +37,7 @@@
  #include "imgutils.h"
  #include "pixdesc.h"
  #include "pixfmt.h"
 +#include "compat/w32dlfcn.h"
  
  typedef IDirect3D9* WINAPI pDirect3DCreate9(UINT);
  typedef HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **);
@@@ -251,19 -249,11 +251,11 @@@ static int dxva2_transfer_data(AVHWFram
      D3DLOCKED_RECT     LockedRect;
      HRESULT            hr;
  
-     int download = !!src->hw_frames_ctx;
-     int bytes_per_component;
+     uint8_t *surf_data[4]     = { NULL };
+     int      surf_linesize[4] = { 0 };
+     int i;
  
-     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);
-     }
+     int download = !!src->hw_frames_ctx;
  
      surface = (IDirect3DSurface9*)(download ? src->data[3] : dst->data[3]);
  
          return AVERROR_UNKNOWN;
      }
  
+     for (i = 0; download ? dst->data[i] : src->data[i]; i++)
+         surf_linesize[i] = LockedRect.Pitch;
+     av_image_fill_pointers(surf_data, ctx->sw_format, surfaceDesc.Height,
+                            (uint8_t*)LockedRect.pBits, surf_linesize);
      if (download) {
-         av_image_copy_plane(dst->data[0], dst->linesize[0],
-                             (uint8_t*)LockedRect.pBits, LockedRect.Pitch,
-                             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 * bytes_per_component, src->height / 2);
+         av_image_copy(dst->data, dst->linesize, surf_data, surf_linesize,
+                       ctx->sw_format, src->width, src->height);
      } else {
-         av_image_copy_plane((uint8_t*)LockedRect.pBits, LockedRect.Pitch,
-                             dst->data[0], dst->linesize[0],
-                             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 * bytes_per_component, src->height / 2);
+         av_image_copy(surf_data, surf_linesize, src->data, src->linesize,
+                       ctx->sw_format, src->width, src->height);
      }
  
      IDirect3DSurface9_UnlockRect(surface);
@@@ -319,10 -307,10 +309,10 @@@ static void dxva2_device_free(AVHWDevic
          IDirect3D9_Release(priv->d3d9);
  
      if (priv->d3dlib)
 -        FreeLibrary(priv->d3dlib);
 +        dlclose(priv->d3dlib);
  
      if (priv->dxva2lib)
 -        FreeLibrary(priv->dxva2lib);
 +        dlclose(priv->dxva2lib);
  
      av_freep(&ctx->user_opaque);
  }
@@@ -353,24 -341,24 +343,24 @@@ static int dxva2_device_create(AVHWDevi
  
      priv->device_handle = INVALID_HANDLE_VALUE;
  
 -    priv->d3dlib = LoadLibrary("d3d9.dll");
 +    priv->d3dlib = dlopen("d3d9.dll", 0);
      if (!priv->d3dlib) {
          av_log(ctx, AV_LOG_ERROR, "Failed to load D3D9 library\n");
          return AVERROR_UNKNOWN;
      }
 -    priv->dxva2lib = LoadLibrary("dxva2.dll");
 +    priv->dxva2lib = dlopen("dxva2.dll", 0);
      if (!priv->dxva2lib) {
          av_log(ctx, AV_LOG_ERROR, "Failed to load DXVA2 library\n");
          return AVERROR_UNKNOWN;
      }
  
 -    createD3D = (pDirect3DCreate9 *)GetProcAddress(priv->d3dlib, "Direct3DCreate9");
 +    createD3D = (pDirect3DCreate9 *)dlsym(priv->d3dlib, "Direct3DCreate9");
      if (!createD3D) {
          av_log(ctx, AV_LOG_ERROR, "Failed to locate Direct3DCreate9\n");
          return AVERROR_UNKNOWN;
      }
 -    createDeviceManager = (pCreateDeviceManager9 *)GetProcAddress(priv->dxva2lib,
 -                                                                  "DXVA2CreateDirect3DDeviceManager9");
 +    createDeviceManager = (pCreateDeviceManager9 *)dlsym(priv->dxva2lib,
 +                                                         "DXVA2CreateDirect3DDeviceManager9");
      if (!createDeviceManager) {
          av_log(ctx, AV_LOG_ERROR, "Failed to locate DXVA2CreateDirect3DDeviceManager9\n");
          return AVERROR_UNKNOWN;
      d3dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
      d3dpp.Flags            = D3DPRESENTFLAG_VIDEO;
  
 -    hr = IDirect3D9_CreateDevice(priv->d3d9, adapter, D3DDEVTYPE_HAL, GetShellWindow(),
 +    hr = IDirect3D9_CreateDevice(priv->d3d9, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
                                   &d3dpp, &priv->d3d9device);
      if (FAILED(hr)) {