Why I get OutOfMemory exception when trying create a decoder - c++

I'm trying to get ID3D11VideoDecoder Decoder with h264 decoder profile but catching exception on Windows Phone 8.
Using this code:
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. I tried SharpDX for this and got the same issue.

It seems you didn't pass in a valid D3D11_VIDEO_DECODER_CONFIG variable. you just define a pointer of struct D3D11_VIDEO_DECODER_CONFIG and didn't set the values of it before calling function CreateVideoDecoder.
D3D11_VIDEO_DECODER_CONFIG *conf = new D3D11_VIDEO_DECODER_CONFIG();
DX::ThrowIfFailed(videoDevice.Get()->CreateVideoDecoder(desc, conf, &decoder));
You can try it as below.
D3D11_VIDEO_DECODER_CONFIG conf
ZeroMemory(&conf, sizeof(conf));
conf.guidConfigBitstreamEncryption = xxx;
...
conf.ConfigDecoderSpecific = xxx;
DX::ThrowIfFailed(videoDevice.Get()->CreateVideoDecoder(desc, conf, &decoder));

So, I found solution.
for H264 decoder ConfigBitstreamRaw field must be "2". Not "1", not "0". Only "2". Like this
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;

Related

Using Vulkan memory allocator with Volk

I'm currently trying to use Vulkan memory allocator with the meta loader Volk
here is the link of the two: https://github.com/zeux/volk
https://gpuopen.com/vulkan-memory-allocator/
But I have trouble with creating the VmaAllocator, here is my code:
void VulkApp::Init(PipelineFlags t_Conf, entt::registry& t_reg)
{
volkInitialize();
WindowProps props = {};
props.Height = 600;
props.Width = 800;
props.Title = "Engine";
currentWindow = EngWindow::Create(props);
//Create all physical, logical, instance for vulkan
Prepare();
VolkDeviceTable test;
volkLoadDeviceTable(&test, m_LogicalDevice->GetVkDevice());
VmaAllocatorCreateInfo allocatorCreateInfo = {};
allocatorCreateInfo.vulkanApiVersion = VK_API_VERSION_1_2;
allocatorCreateInfo.physicalDevice = m_PhysicalDevice->GetVkPhysicalDevice();
allocatorCreateInfo.device = m_LogicalDevice->GetVkDevice();
allocatorCreateInfo.instance = m_Instance->GetRawVkInstance();
allocatorCreateInfo.pVulkanFunctions = reinterpret_cast<const VmaVulkanFunctions*> (&test);
VmaAllocator allocator;
vmaCreateAllocator(&allocatorCreateInfo, &allocator);
BuildRenderPipelines(t_Conf, t_reg);
}
void VulkApp::Prepare()
{
m_Instance = std::make_unique<VulkInst>();
volkLoadInstance(m_Instance->GetRawVkInstance());
currentWindow->CreateSurface(m_Instance->GetRawVkInstance(), &m_Surface);
m_PhysicalDevice = std::make_unique<PhysicalDevice>(*m_Instance);
m_LogicalDevice = std::make_unique<LogicalDevice>(*m_Instance, *m_PhysicalDevice, m_Surface);
volkLoadDevice(m_LogicalDevice->GetVkDevice());
m_SwapChain = std::make_unique<SwapChain>(ChooseSwapExtent(), *m_LogicalDevice, *m_PhysicalDevice, m_Surface);
GraphicsHelpers::CreateCommandPool(m_CommandPool, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); //TODO: added Transient bit
CreateFrameSyncResources();
/*
Create Camera
*/
BuildSwapChainResources();
}
I don't have any error when i build, but when i execute, the VmaCreateAllocator return an error:
Exception raised at 0x00007FFAB0CD836B (VkLayer_khronos_validation.dll) in My_Game.exe : 0xC0000005 : access violation reading location 0x0000000000000120.
Not very useful, but it stops on the line 14082 of the file vk_mem_alloc.h:
(*m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties)(m_PhysicalDevice, &m_MemProps);
The program check all the vulkan validation function so my vulkan function table must be good. But still the allocation fail.
I'm sorry i don't put a 'minimal' code, but with vulkan, even the minimum is really long. So, as a first test, maybe some of you have an insight of the error?
If you use a loader like Volk, you need to provide all memory related Vulkan function pointers used by VMA yourself.
This is done via the pVulkanFunctions member of the VmaAllocatorCreateInfo structure.
So when creating your VmaAllactor you set the function pointer in that to those fetched via Volk like this:
VmaVulkanFunctions vma_vulkan_func{};
vma_vulkan_func.vkAllocateMemory = vkAllocateMemory;
vma_vulkan_func.vkBindBufferMemory = vkBindBufferMemory;
vma_vulkan_func.vkBindImageMemory = vkBindImageMemory;
vma_vulkan_func.vkCreateBuffer = vkCreateBuffer;
vma_vulkan_func.vkCreateImage = vkCreateImage;
vma_vulkan_func.vkDestroyBuffer = vkDestroyBuffer;
vma_vulkan_func.vkDestroyImage = vkDestroyImage;
vma_vulkan_func.vkFlushMappedMemoryRanges = vkFlushMappedMemoryRanges;
vma_vulkan_func.vkFreeMemory = vkFreeMemory;
vma_vulkan_func.vkGetBufferMemoryRequirements = vkGetBufferMemoryRequirements;
vma_vulkan_func.vkGetImageMemoryRequirements = vkGetImageMemoryRequirements;
vma_vulkan_func.vkGetPhysicalDeviceMemoryProperties = vkGetPhysicalDeviceMemoryProperties;
vma_vulkan_func.vkGetPhysicalDeviceProperties = vkGetPhysicalDeviceProperties;
vma_vulkan_func.vkInvalidateMappedMemoryRanges = vkInvalidateMappedMemoryRanges;
vma_vulkan_func.vkMapMemory = vkMapMemory;
vma_vulkan_func.vkUnmapMemory = vkUnmapMemory;
vma_vulkan_func.vkCmdCopyBuffer = vkCmdCopyBuffer;
And then pass those to the create info:
VmaAllocatorCreateInfo allocator_info{};
...
allocator_info.pVulkanFunctions = &vma_vulkan_func;

How to open AVCodec?

I'm tired of searching the solution about this theme. Can anybody help?Types:
AVOutputFormat* m_outFormat;
AVFormatContext* m_formatContext;
AVCodecContext* m_videoCodecContext;
AVCodec* m_videoCodec;
Code:
avcodec_register_all();
av_register_all();
m_outFormat = av_guess_format(NULL,filePath().toUtf8().constData(),NULL);
//filePath ended like ".mp4"
if (!m_outFormat)
return; //all is fine
avformat_alloc_output_context2(&m_formatContext,NULL,NULL,filePath().toUtf8().constData());
m_formatContext->oformat->video_id = CODEC_ID_H264;
m_outFormat=m_formatContext->oformat;
////////////////////////////////////////////////////////////////////
m_videoCodec=avcodec_find_encoder(CODEC_ID_H264);
m_videoStream = avformat_new_stream(m_formatContext,m_videoCodec);
if (m_videoStream)
return; //all is fine
m_videoCodecContext = avcodec_alloc_context3(m_videoCodec);
m_videoCodecContext->codec_id = CODEC_ID_H264;
m_videoCodecContext->width = 1280;
m_videoCodecContext->height = 720;
m_videoCodecContext->codec_type = AVMEDIA_TYPE_VIDEO;
m_videoCodecContext->pix_fmt = PIX_FMT_YUV420P;
av_codec_open2(M_videoCodecContext,m_videoCodec,NULL);
I'm getting an error: [libx264 #.....] Codec type or id mismathes.
av_codec_open2(..) returned (-22 error). Where I did mistake?More info:
last ffmpeg
Mac Os x 10.10
libx264 installed
after av_guess_format(...) I've got audio_codec = CODEC_ID_H264, video_codec = CODEC_ID_NONE, long_name MP4(MPEG-4 Part 14) in m_outFormat.
after avformat_alloc_context3(...) I've got audio_codec_id = video_codec_id = CODEC_ID_NONE in m_formatContext.
after avcodec_find_encoder(CODEC_ID_H264) I've got name = "libx264", id = CODEC_ID_MPEG1VIDEO in m_videoCodec.
I can share more info if You can say, what do You exactly need.
I've found the answer... It's so stupid... I had old headers, from old ffmpeg sources, but with the libs from new sources.. So I replaced new headers and all errors has gone! I don't change code above.

How to parse this JSON in C++ Builder?

I have the following JSON:
{"test1":"1", "test2": {"test21":"21", "test22":"22"}}"
but I'm having troubles parsing it. Actually, I'm somehow trying to read "test21" but don't know how to reach it. I tried this but it's not good:
UnicodeString myJSON = "{\"test1\" :\"1\",\"test2\":{\"test21\":\"21\",\"test22\":\"22\"}}";
TJSONObject *JSON = (TJSONObject*)TJSONObject::ParseJSONValue(myJSON);
TJSONValue *test2 = (TJSONValue*)JSON->Get("test2");
//TJSONString* test21 = (TJSONString*)test2->Get("test21");
TJSONObject *JSON = (TJSONObject*)TJSONObject::ParseJSONValue(myJSON);
TJSONPair *pair = JSON->Get("test2");
TJSONObject *jsonObj = (TJSONObject*) pair->JsonValue;
TJSONPair *test21 = jsonObj->Get("test21");
String value = test21->JsonValue->ToString();

gSoap Exchange Web Services Connection

I'm trying to write an application that would work with the EWS proxy classes. To generate proxy classes I used gsoap (compiled OpenSSL).
I have implemented a library that works with EWS, but. Net.
The problem is this: I have no idea how to implement a connection to the server.
Doing the following:
ExchangeServiceBindingProxy *proxy = new ExchangeServiceBindingProxy("https://192.168.0.49/EWS/exchange.asmx");
soap *pSoap = proxy->soap;
pSoap->userid = "user1";
pSoap->passwd = "password1";
pSoap->recv_timeout = 300;
pSoap->send_timeout = 300;
SOAP_ENV__Header *header = new SOAP_ENV__Header();
header->ns3__RequestServerVersion = new _ns3__RequestServerVersion();
header->ns3__RequestServerVersion->soap = pSoap;
header->ns3__RequestServerVersion->Version = ns3__ExchangeVersionType__Exchange2010;
pSoap->header = header;
//get root folder ID
ns3__DistinguishedFolderIdType *dfit = new ns3__DistinguishedFolderIdType();
dfit->Id = ns3__DistinguishedFolderIdNameType__inbox;
//set the props that we want to retrieve
ns3__FolderResponseShapeType *frst = new ns3__FolderResponseShapeType();
frst->BaseShape = ns3__DefaultShapeNamesType__AllProperties;
//get folder
ns1__GetFolderType *gftRoot = new ns1__GetFolderType();
gftRoot->FolderIds = new ns3__NonEmptyArrayOfBaseFolderIdsType();
gftRoot->FolderIds->__union_NonEmptyArrayOfBaseFolderIdsType = new __ns3__union_NonEmptyArrayOfBaseFolderIdsType();
gftRoot->FolderIds->__union_NonEmptyArrayOfBaseFolderIdsType->union_NonEmptyArrayOfBaseFolderIdsType.DistinguishedFolderId = dfit;
gftRoot->FolderShape = frst;
__ns1__GetFolderResponse response;
int error = proxy->GetFolder(gftRoot, response);
As a result, getting the error: SLL_ERROR.
I know, that i`m doing something wrong. But what? What i should to do, to use proxy classes functions?
I resolved it by myself:
Added to project LibNTLM and added to preprocessor WITH_NTLM.
Also changed code, a little bit:
ExchangeServiceBindingProxy *proxy = new ExchangeServiceBindingProxy(endpoint.c_str());
soap *pSoap = proxy->soap;
pSoap->userid = "Ivan1";
pSoap->passwd = "1";
pSoap->ntlm_challenge = "";
pSoap->authrealm = "Ursa-Minor";
pSoap->ssl_flags = SOAP_SSL_NO_AUTHENTICATION;
//pSoap->keep_alive = true;
pSoap->mode = SOAP_IO_KEEPALIVE;
//get root folder ID
ns3__DistinguishedFolderIdType *dfit = new ns3__DistinguishedFolderIdType();
dfit->Id = ns3__DistinguishedFolderIdNameType__inbox;
//set the props that we want to retrieve
ns3__FolderResponseShapeType *frst = new ns3__FolderResponseShapeType();
frst->BaseShape = ns3__DefaultShapeNamesType__AllProperties;
//get folder
ns1__GetFolderType *gftRoot = new ns1__GetFolderType();
gftRoot->FolderIds = new ns3__NonEmptyArrayOfBaseFolderIdsType();
gftRoot->FolderIds->__size_NonEmptyArrayOfBaseFolderIdsType = 1;
gftRoot->FolderIds->__union_NonEmptyArrayOfBaseFolderIdsType = new __ns3__union_NonEmptyArrayOfBaseFolderIdsType();
gftRoot->FolderIds->__union_NonEmptyArrayOfBaseFolderIdsType->union_NonEmptyArrayOfBaseFolderIdsType.DistinguishedFolderId = dfit;
gftRoot->FolderIds = (ns3__NonEmptyArrayOfBaseFolderIdsType*)dfit;
gftRoot->FolderShape = frst;
__ns1__GetFolderResponse response;
int qq = proxy->GetFolder(gftRoot, response);
return true;
But now i have enother problems: Error 500: Internal Server Error

Codeigniter routing how to permit null parameter

I want paginate my index http:localhost/mysite/home but if I write only this http:localhost/mysite/home the page said: "page not found", but if I write http:localhost/mysite/home/3 its work! how to I can configure my routing to get null parameters? I tried with (:any) and (num) but not work
My route file is:
$route['404_override'] = 'welcome/no_found';
$route['home/'] = "welcome/home/$1";
My controller:
$config['base_url'] = base_url().'/mysite/home';
$config['total_rows'] = $this->mtestmodel->countNews();
$config['per_page'] = 2;
$config['num_links'] = 20;
$this->pagination->initialize($config);
$data['paginator']=$this->pagination->create_links();
$data['news']=$this->mtestmodel->show_news( $config['per_page'],intval($to) );
//$to is a parameter in url base_url()/mysite/home/3
Change your route.php file to the following:
$route['404_override'] = 'welcome/no_found';
$route['home/(:num)'] = "welcome/home/$1";
$route['home'] = "welcome/home";
This way, your application will catch both requests (http://localhost/mysite/home and http://localhost/mysite/home/3), and will send them both to your controller.
You should then be able to access your $to variable (which has been passed as the first argument into your controller's function) or use $this->uri->segment(2) instead.
e.g.
public function home($to = 0) {
$config['base_url'] = base_url().'/mysite/home';
$config['total_rows'] = $this->mtestmodel->countNews();
$config['per_page'] = 2;
$config['num_links'] = 20;
$this->pagination->initialize($config);
$data['paginator'] = $this->pagination->create_links();
$data['news'] = $this->mtestmodel->show_news( $config['per_page'],intval($to) );
}
Hope that helps!