BOOL DMOSetMediaType(ASF_FILE_INFO* pInfo) { if (!SetInputMediaType(pInfo)) return FALSE; if (!SetOutputMediaType(pInfo)) return FALSE; if (FAILED(pInfo->pMediaObject->AllocateStreamingResources())) return FALSE; pInfo->bDiscontinuity = FALSE; return TRUE; }
void EncodeTransform::Init(int width, int height) { VTUNE_TASK(g_pDomain, "Encoder Init"); mStreamHeight = height; mStreamWidth = width; mCompressedBuffer = new DWORD[(width*height) / 2]; HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); if (SUCCEEDED(hr) || (FAILED(hr) && hr == RPC_E_CHANGED_MODE)) { hr = FindEncoder(MFVideoFormat_H264); if (FAILED(hr)) { std::cout << "failed to find/Create specified encoder mft" << std::endl; } // set the media output info hr = SetOutputMediaType(); if (FAILED(hr)) { std::cout << "failed to SetOutputMediaType " << std::endl; } // set the media input info hr = SetInputMediaType(); if (FAILED(hr)) { std::cout << "failed to SetInputMediaType" << std::endl; } // query media input stream info hr = QueryInputStreamInfo(); if (FAILED(hr)) { std::cout << "failed to QueryInputStreamInfo" << std::endl; } { //used to be NUM_PIXELS_YUY2 * 4 HRESULT hr = MFCreateMemoryBuffer((mStreamWidth*mStreamHeight) * 2, &mpInputBuffer); if (FAILED(hr)) { std::cout << "Failed to MFCreateMemoryBuffer" << std::endl; } hr = MFCreateSample(&pSampleProcIn); if (FAILED(hr)) { std::cout << "Failed to MFCreateSample" << std::endl; } hr = pSampleProcIn->AddBuffer(mpInputBuffer); if (FAILED(hr)) { std::cout << "Failed to AddBuffer to sample" << std::endl; } } { //used to be NUM_PIXELS_YUY2 * 4 hr = MFCreateMemoryBuffer(mStreamWidth * mStreamWidth * 2, &mpEncodedBuffer); if (FAILED(hr)) { std::cout << "Failed to MFCreateMemoryBuffer" << std::endl; } hr = MFCreateSample(&pSampleProcOut); if (FAILED(hr)) { std::cout << "Failed to MFCreateSample" << std::endl; } hr = pSampleProcOut->AddBuffer(mpEncodedBuffer); if (FAILED(hr)) { std::cout << "Failed to AddBuffer to sample" << std::endl; } } } }