为什么在尝试创建解码器时会出现OutOfMemory异常

时间:2013-08-05 14:30:14

标签: c++ windows-phone-8 directx h.264

我正在尝试使用h264解码器配置文件获取ID3D11VideoDecoder解码器,但在Windows Phone 8上捕获异常。 使用此代码:

DX::ThrowIfFailed(device.Get()->QueryInterface(__uuidof(ID3D11VideoDevice), (void**)&videoDevice));
GUID guid = {0x1b81be68, 0xa0c7,0x11d3,{0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5}};

D3D11_VIDEO_DECODER_DESC *desc = new D3D11_VIDEO_DECODER_DESC();
desc->Guid = guid;
desc->OutputFormat = DXGI_FORMAT_420_OPAQUE;
desc->SampleHeight = 480;
desc->SampleWidth = 800;

D3D11_VIDEO_DECODER_CONFIG *conf = new D3D11_VIDEO_DECODER_CONFIG();
ID3D11VideoDecoder *decoder;
DX::ThrowIfFailed(videoDevice.Get()->CreateVideoDecoder(desc, conf, &decoder));

PS。我为此尝试了SharpDX并遇到了同样的问题。

2 个答案:

答案 0 :(得分:0)

您似乎没有传入有效的D3D11_VIDEO_DECODER_CONFIG变量。你只需定义struct D3D11_VIDEO_DECODER_CONFIG的指针,并在调用函数CreateVideoDecoder之前没有设置它的值。

D3D11_VIDEO_DECODER_CONFIG *conf = new D3D11_VIDEO_DECODER_CONFIG();
DX::ThrowIfFailed(videoDevice.Get()->CreateVideoDecoder(desc, conf, &decoder));

您可以尝试如下。

D3D11_VIDEO_DECODER_CONFIG conf
ZeroMemory(&conf, sizeof(conf));
conf.guidConfigBitstreamEncryption = xxx;
...
conf.ConfigDecoderSpecific = xxx;
DX::ThrowIfFailed(videoDevice.Get()->CreateVideoDecoder(desc, conf, &decoder));

答案 1 :(得分:0)

所以,我找到了解决方案。

对于H264解码器,

ConfigBitstreamRaw字段必须为“2”。不是“1”,不是“0”。只有“2”。喜欢这个

    VideoDecoderDescription decoderDescription = new VideoDecoderDescription();
    decoderDescription.OutputFormat = Format.Opaque420;
    decoderDescription.SampleHeight = 480;
    decoderDescription.SampleWidth = 800;
    decoderDescription.Guid = _formatGuid;

    VideoDecoderConfig config = new VideoDecoderConfig();
    config.ConfigMinRenderTargetBuffCount = 1;
    config.ConfigBitstreamRaw = 2;