int camera_close(camera_t *camera) { // TODO: release reader and stuff MFShutdown(); free(camera); return 1; }
MfVideoEncoder::~MfVideoEncoder() { MFShutdown(); CoUninitialize(); }
static void test_MFCreateMediaType(void) { HRESULT hr; IMFMediaType *mediatype; hr = MFStartup(MAKELONG( MF_API_VERSION, 0xdead ), MFSTARTUP_FULL); ok(hr == MF_E_BAD_STARTUP_VERSION, "got 0x%08x\n", hr); hr = MFStartup(MF_VERSION, MFSTARTUP_FULL); ok(hr == S_OK, "got 0x%08x\n", hr); if(0) { /* Crash on Windows Vista/7 */ hr = MFCreateMediaType(NULL); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); } hr = MFCreateMediaType(&mediatype); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IMFMediaType_SetGUID(mediatype, &MF_MT_MAJOR_TYPE, &MFMediaType_Video); todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); IMFMediaType_Release(mediatype); MFShutdown(); }
void ofxWMFVideoPlayer::forceExit() { if (_instanceCount != 0) { cout << "Shutting down MF some ofxWMFVideoPlayer remains" << endl; MFShutdown(); } }
void WWMFResampler::Finalize(void) { SafeRelease(&m_pTransform); if (m_isMFStartuped) { MFShutdown(); m_isMFStartuped = false; } }
MediaFoundationCaptureLibrary::~MediaFoundationCaptureLibrary(void) { HRESULT hr = MFShutdown(); if(!SUCCEEDED(hr)) { LOG_ERROR("MEDIA FOUNDATION: Resources cannot be released."); } }
virtual void ShutdownModule() override { if( MovieStreamer.IsValid() ) { MovieStreamer.Reset(); MFShutdown(); } }
INT WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE /*hPrevInstance*/, _In_ LPWSTR /*lpCmdLine*/, _In_ INT nCmdShow) { bool bCoInit = false, bMFStartup = false; // Initialize the common controls const INITCOMMONCONTROLSEX icex = { sizeof(INITCOMMONCONTROLSEX), ICC_WIN95_CLASSES }; InitCommonControlsEx(&icex); // Note: The shell common File dialog requires apartment threading. HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (FAILED(hr)) { goto done; } bCoInit = true; hr = MFStartup(MF_VERSION); if (FAILED(hr)) { goto done; } bMFStartup = true; HWND hwnd = CreateMainWindow(hInstance); if (hwnd == 0) { ShowError(NULL, L"CreateMainWindow failed.", hr); goto done; } ShowWindow(hwnd, nCmdShow); // Run the message loop. MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } done: if (FAILED(hr)) { ShowError(NULL, L"Failed to start application", hr); } if (bMFStartup) { MFShutdown(); } if (bCoInit) { CoUninitialize(); } return 0; }
SoundSourceMediaFoundation::~SoundSourceMediaFoundation() { delete [] m_wcFilename; delete [] m_leftoverBuffer; safeRelease(&m_pReader); safeRelease(&m_pAudioType); MFShutdown(); CoUninitialize(); }
int main(int argc, char** argv) { if_failed_return(CoInitializeEx(0, COINIT_MULTITHREADED | COINIT_SPEED_OVER_MEMORY), GetLastError()); if_failed_return_result(MFStartup(MF_VERSION)); if_failed_return_result(mf_enumerate_cameras(mf_get_media_types)); if_failed_return_result(MFShutdown()); if_failed_return_result(ds_enumerate_cameras(ds_get_media_types)); getchar(); CoUninitialize(); return 0; }
CASFManager::~CASFManager() { //Release memory Reset(); // Shutdown the Media Foundation platform (void)MFShutdown(); }
wmf_backend::~wmf_backend() { try { MFShutdown(); CoUninitialize(); } catch(...) { // TODO: Write to log } }
CMFCamCapture::~CMFCamCapture() { stop(); if (m_spSource) { m_spSource->Shutdown(); } if (m_spSession) { m_spSession->Shutdown(); } MFShutdown(); CoUninitialize(); }
void CleanUp() { for (DWORD i = 0; i < MAX_SPRITES; i++) { g_pSprites[i].Clear(); } SafeRelease(&g_pRT); MFShutdown(); CoUninitialize(); }
void SoundSourceMediaFoundation::close() { safeRelease(&m_pSourceReader); if (SUCCEEDED(m_hrMFStartup)) { MFShutdown(); m_hrMFStartup = E_FAIL; } if (SUCCEEDED(m_hrCoInitialize)) { CoUninitialize(); m_hrCoInitialize = E_FAIL; } }
// Release all resources held by this object. void Player_::shutdown( ev::Close const& ev) { // Close the session CloseSession(); // Shutdown the Media Foundation platform MFShutdown(); if (m_hCloseEvent) { CloseHandle(m_hCloseEvent); m_hCloseEvent = NULL; } }
void SoundSourceMediaFoundation::close() { delete[] m_leftoverBuffer; m_leftoverBuffer = nullptr; safeRelease(&m_pReader); if (SUCCEEDED(m_hrMFStartup)) { MFShutdown(); m_hrMFStartup = E_FAIL; } if (SUCCEEDED(m_hrCoInitialize)) { CoUninitialize(); m_hrCoInitialize = E_FAIL; } }
EXTERN_C DLLEXPORT void WolframLibrary_uninitialize(WolframLibraryData libData) { VR.~VidReader(); // destruct the class instances VW.~VidWriter(); // Shut down media foundation and close the COM library hr = MFShutdown(); if (FAILED(hr)) { libData->Message("mfshutdownfail"); } CoUninitialize(); return; }
MFPlayerService::~MFPlayerService() { #ifndef Q_WS_SIMULATOR if (m_videoWindowControl) delete m_videoWindowControl; #endif if (m_videoRendererControl) delete m_videoRendererControl; m_session->shutdown(); m_session->Release(); MFShutdown(); CoUninitialize(); }
void SoundSourceMediaFoundation::close() { delete[] m_wcFilename; m_wcFilename = NULL; delete[] m_leftoverBuffer; m_leftoverBuffer = NULL; safeRelease(&m_pReader); safeRelease(&m_pAudioType); if (SUCCEEDED(m_hrMFStartup)) { MFShutdown(); m_hrMFStartup = E_FAIL; } if (SUCCEEDED(m_hrCoInitialize)) { CoUninitialize(); m_hrCoInitialize = E_FAIL; } }
ofxWMFVideoPlayer::~ofxWMFVideoPlayer() { //forceExit(); if (_player) { _player->Shutdown(); //if (_sharedTextureCreated) _player->m_pEVRPresenter->releaseSharedTexture(); SafeRelease(&_player); } cout << "Player " << _id << " Terminated" << endl; _instanceCount--; if (_instanceCount == 0) { MFShutdown(); cout << "Shutting down MF" << endl; } int i = 1; }
HRESULT CPlayer::Shutdown() { TRACE((L"CPlayer::ShutDown\n")); HRESULT hr = S_OK; // Close the session hr = CloseSession(); // Shutdown the Media Foundation platform MFShutdown(); if (m_hCloseEvent) { CloseHandle(m_hCloseEvent); m_hCloseEvent = NULL; } return hr; }
virtual void ShutdownModule() override { if (!Initialized) { return; } Initialized = false; // unregister video player factory IMediaModule* MediaModule = FModuleManager::GetModulePtr<IMediaModule>("Media"); if (MediaModule != nullptr) { MediaModule->UnregisterPlayerFactory(*this); } // shutdown Windows Media Foundation MFShutdown(); }
tTVPMFPlayer::~tTVPMFPlayer() { Shutdown = true; ReleaseAll(); MFShutdown(); CoUninitialize(); }
MfVideoOut::~MfVideoOut() { MFShutdown(); CoUninitialize(); }
VideoCapture::~VideoCapture() { MFShutdown(); }
static void MediaFoundation_quit(void) { MFShutdown(); CoUninitialize(); } /* MediaFoundation_quit */
/** * Shuts down Media Foundation and uninitializes COM. */ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) { MFShutdown(); CoUninitialize(); }
HRESULT VideoEncoder::Encode() { HRESULT hr = S_OK; Photo* pPhoto = nullptr; DWORD streamIndex = 0; BYTE* pCurrentBitmap = nullptr; BYTE* pPreviousBitmap = nullptr; BYTE* pFrameBuffer = nullptr; LONGLONG startTime = 0; UINT64 sampleDuration = 0; UINT64 transitionSampleDuration = 0; CheckHR(this->Initialize()); this->m_logFileStream << "已成功初始化非托管视频编码器." << endl; CheckHR(this->ParseInputXml()); this->m_logFileStream << "Xml配置文件解析成功." << endl; CheckHR(this->CreateSinkWriter(&this->m_pSinkWriter, &streamIndex)); this->m_logFileStream << "Sink writer创建成功." << endl; // 循环访问照片. for (list<Photo*>::iterator it = this->m_photos.begin(); it != this->m_photos.end(); it++) { pPhoto = *it; int frameSize = 0; // 解码位图. CheckHR(this->DecodeFrame(pPhoto, &pCurrentBitmap, &frameSize)); this->m_logFileStream << "图片 " << pPhoto->GetFile().c_str() << " 成功解码." << endl; // 编写特效示例. if (pPreviousBitmap != nullptr) { transitionSampleDuration = (UINT64)(pPhoto->GetTransitionDuration() * this->m_fps); if (pPhoto->GetTransition() != nullptr) { pPhoto->GetTransition()->SetForegroundFrame(pPreviousBitmap); pPhoto->GetTransition()->SetBackgroundFrame(pCurrentBitmap); CheckHR(this->WriteTransitionSample(transitionSampleDuration, pPhoto->GetTransition(), streamIndex, &startTime)); this->m_logFileStream << "照片" << pPhoto->GetFile().c_str() << "的特效示例编写成功." << endl; } } // 编写照片示例. sampleDuration = (UINT64)(pPhoto->GetPhotoDuration() * this->m_fps); CheckHR(this->WritePhotoSample(sampleDuration, pCurrentBitmap, streamIndex, &startTime)); this->m_logFileStream << "照片" << pPhoto->GetFile().c_str() << "的静态示例编写成功." << endl; // 释放与此照片关联的资源. delete pPreviousBitmap; pPreviousBitmap = pCurrentBitmap; } hr = this->m_pSinkWriter->Finalize(); this->m_logFileStream << "提交成功." << endl; CheckHR(hr); CheckHR(MFShutdown()); cleanup: if (pPreviousBitmap != pCurrentBitmap && pPreviousBitmap != nullptr) { delete pPreviousBitmap; pPreviousBitmap = nullptr; } if (pCurrentBitmap != nullptr) { delete pCurrentBitmap; pCurrentBitmap = nullptr; } this->Dispose(); return hr; }
int wmain(int argc, wchar_t *argv[]) { Parameters commandLineParameters; if (argc < 1) { printf("Command line help goes here..."); return 0; } CommandLineParser::Parse(argc, argv, &commandLineParameters); AudioEncoderParameters* encoderParameters = nullptr; if (commandLineParameters.Quality == 100) { encoderParameters = AudioEncoderParameters::CreateLosslessEncoderParameters(2, 44100, 16); } else { encoderParameters = AudioEncoderParameters::CreateQualityBasedVbrParameters(commandLineParameters.Quality, 2, 44100, 16); } // Verify that output folder exists, if specified // (and add a '\' to it if it doesn't exist) if (*commandLineParameters.OutputFolder) { WIN32_FILE_ATTRIBUTE_DATA fileData; BOOL success = GetFileAttributesEx(commandLineParameters.OutputFolder, GET_FILEEX_INFO_LEVELS::GetFileExInfoStandard, &fileData); // check if the file system object exists, but it's not a directory... if (success && ((fileData.dwFileAttributes & 0x10) == 0)) { printf("Specified output directory is not a directory"); return 0; } if (!success) { printf("Specified output directory does not exist"); return 0; } size_t outputFolderLength = wcslen(commandLineParameters.OutputFolder); if (outputFolderLength < MAX_PATH - 1) { if (*(commandLineParameters.OutputFolder + outputFolderLength - 1) != '\\') { *(commandLineParameters.OutputFolder + outputFolderLength) = '\\'; *(commandLineParameters.OutputFolder + outputFolderLength + 1) = '\0'; } } } // Initialize COM & Media Foundation if (!SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))) { wprintf_s(L"Unable to initialize COM"); return -1; } if (!SUCCEEDED(MFStartup(MF_VERSION))) { CoUninitialize(); wprintf_s(L"Unable to initialize MediaFoundation"); return -1; } try { // Use the Windows shell API to extract the path component from the input filename WCHAR srcFileFolder[MAX_PATH]; WCHAR srcFileName[MAX_PATH]; wcscpy_s(srcFileFolder, commandLineParameters.InputFilename); BOOL ret = PathRemoveFileSpec(srcFileFolder); size_t srcFolderLength = wcslen(srcFileFolder); if (srcFolderLength < MAX_PATH - 1) { if (srcFolderLength > 0) { if (*(srcFileFolder + srcFolderLength - 1) != '\\') { *(srcFileFolder + srcFolderLength) = '\\'; *(srcFileFolder + srcFolderLength + 1) = '\0'; } } } // do some basic parsing of input filename, as FirstFirstFile / FindNext // does not return the full path so we'll have to prepend // any directory info specified WIN32_FIND_DATA findData; HANDLE hFindFile = FindFirstFile(commandLineParameters.InputFilename, &findData); if (hFindFile != INVALID_HANDLE_VALUE) { do { if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // skip directories continue; } wcscpy_s(srcFileName, srcFileFolder); wcscat_s(srcFileName, findData.cFileName); MediaSource* mediaSource = MediaSource::Open(srcFileName); // if an output folder is specified, use that WCHAR outputFilename[MAX_PATH]; if (*commandLineParameters.OutputFolder) { wcscpy_s(outputFilename, commandLineParameters.OutputFolder); wcscat_s(outputFilename, findData.cFileName); PathRenameExtension(outputFilename, L".wma"); } else { wcscpy_s(outputFilename, commandLineParameters.OutputFilename); } AsfContentInfoBuilder *contentInfo = new AsfContentInfoBuilder(); contentInfo->AddStreamSink(1, encoderParameters); SetMediaSinkContentInfoMetadata(contentInfo, mediaSource, &commandLineParameters); MediaSink* mediaSink = MediaSink::Create(outputFilename, contentInfo->ConstructMfAsfContentInfo()); wprintf_s(L"Encoding %s\n", findData.cFileName); AudioEncoder::Encode(mediaSource, mediaSink, encoderParameters); delete mediaSink; delete mediaSource; } while (FindNextFile(hFindFile, &findData)); FindClose(hFindFile); } else { // input file does not exit throw std::invalid_argument("Input filename does not exist"); } MFShutdown(); CoUninitialize(); } catch (std::exception &ex) { printf("ERROR: %s\n", ex.what()); } return 0; }