Beispiel #1
0
bool CDXVAContext::CreateSurfaces(D3D11_VIDEO_DECODER_DESC format, unsigned int count, unsigned int alignment, ID3D11VideoDecoderOutputView **surfaces) const
{
  HRESULT hr = S_OK;
  ID3D11Device* pDevice = g_Windowing.Get3D11Device();
  ID3D11DeviceContext1* pContext = g_Windowing.GetImmediateContext();

  unsigned bindFlags = D3D11_BIND_DECODER;

  if (g_Windowing.IsFormatSupport(format.OutputFormat, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE))
    bindFlags |= D3D11_BIND_SHADER_RESOURCE;

  CD3D11_TEXTURE2D_DESC texDesc(format.OutputFormat, 
                                FFALIGN(format.SampleWidth, alignment), 
                                FFALIGN(format.SampleHeight, alignment), 
                                count, 1, bindFlags);

  ID3D11Texture2D *texture = nullptr;
  if (FAILED(pDevice->CreateTexture2D(&texDesc, NULL, &texture)))
  {
    CLog::LogF(LOGERROR, "failed creating decoder texture array.");
    return false;
  }

  D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC vdovDesc;
  vdovDesc.DecodeProfile = format.Guid;
  vdovDesc.Texture2D.ArraySlice = 0;
  vdovDesc.ViewDimension = D3D11_VDOV_DIMENSION_TEXTURE2D;
  float clearColor[] = { 0.0625f, 0.5f, 0.5f, 1.0f }; // black color in YUV

  size_t i;
  for (i = 0; i < count; ++i)
  {
    vdovDesc.Texture2D.ArraySlice = D3D11CalcSubresource(0, i, texDesc.MipLevels);
    hr = m_service->CreateVideoDecoderOutputView(texture, &vdovDesc, &surfaces[i]);
    if (FAILED(hr))
    {
      CLog::LogF(LOGERROR, "failed creating surfaces.");
      break;
    }
    pContext->ClearView(surfaces[i], clearColor, nullptr, 0);
  }
  SAFE_RELEASE(texture);

  if (FAILED(hr))
  {
    for (size_t j = 0; j < i; ++j)
      SAFE_RELEASE(surfaces[j]);
  }

  return SUCCEEDED(hr);
}