vector<string> UI::getAllFilesInFolder(string folder) { vector<string> names; char search_path[200]; sprintf(search_path, "%s*.*", folder.c_str()); WIN32_FIND_DATA fd; HANDLE hFind = ::FindFirstFile(convertCharArrayToLPCWSTR(search_path), &fd); if (hFind != INVALID_HANDLE_VALUE) { do { // read all (real) files in current folder, delete '!' read other 2 default folder . and .. if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { //wide char array WCHAR* wc = fd.cFileName; //convert from wide char to narrow char array char chr[260]; char DefChar = ' '; WideCharToMultiByte(CP_ACP, 0, wc, -1, chr, 260, &DefChar, NULL); //A std:string using the char* constructor. std::string ss(chr); names.push_back(ss); } } while (::FindNextFile(hFind, &fd)); ::FindClose(hFind); } return names; }
vector<string> getFilesPathWithinFolder(string folder, bool recursive, string extension) { vector<string> names; char search_path[200]; sprintf(search_path, "%s*.*", folder.c_str()); WIN32_FIND_DATA fd; wchar_t *w_search_path = convertCharArrayToLPCWSTR(search_path); HANDLE hFind = ::FindFirstFile(w_search_path, &fd); if (hFind != INVALID_HANDLE_VALUE) { do { // read all (real) files in current folder // , delete '!' read other 2 default folder . and .. if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { CHAR dest[MAX_PATH]; std::transform(fd.cFileName, fd.cFileName + MAX_PATH, dest, wide_to_narrow); bool append = true; if (strcmp(extension.c_str(), "") != 0){ string destStr(dest); size_t iIndex = destStr.rfind(extension); if (iIndex < 0 || iIndex > destStr.size()) append = false; } if (append) { string fileName = folder + dest; names.push_back(fileName); } } else if (recursive) { CHAR dest[MAX_PATH]; std::transform(fd.cFileName, fd.cFileName + MAX_PATH, dest, wide_to_narrow); if (strcmp(dest, ".") && strcmp(dest, "..")) { string subFolder = folder + dest + "/"; // recursive call vector<string> subNames = getFilesPathWithinFolder(subFolder, recursive, extension); names.insert(names.end(), subNames.begin(), subNames.end()); } } } while (::FindNextFile(hFind, &fd)); ::FindClose(hFind); } return names; }
BOOL systray_shutdown_notify(HWND hWnd, UINT uniqueID) { // http://www.codeproject.com/kb/shell/stealthdialog.aspx?display=printall HICON hicon = LoadIcon(NULL,MAKEINTRESOURCE(IDI_INFORMATION)); // Tray icon NOTIFYICONDATA tnid = {}; tnid.cbSize = sizeof(NOTIFYICONDATA); memset( &tnid, 0, sizeof(tnid) ); tnid.hWnd = hWnd; tnid.uID = uniqueID; tnid.uVersion = NOTIFYICON_VERSION; tnid.uFlags = NIF_ICON; tnid.uCallbackMessage = WM_USER_SYSTRAY; tnid.hIcon = hicon; Shell_NotifyIcon(NIM_DELETE, &tnid); Shell_NotifyIcon(NIM_SETVERSION, &tnid); Shell_NotifyIcon(NIM_ADD, &tnid); // Notification balloon // https://stackoverflow.com/questions/1414947/display-balloon-tooltip-in-systemtray tnid.hWnd = GetActiveWindow(); tnid.cbSize =sizeof(NOTIFYICONDATA); tnid.uCallbackMessage = WM_USER_SYSTRAY; tnid.hIcon = hicon; tnid.uTimeout = 300000; tnid.uVersion = NOTIFYICON_VERSION; tnid.uFlags = NIF_INFO | NIF_MESSAGE | NIF_ICON | NIF_TIP; tnid.uID = uniqueID; tnid.dwInfoFlags = NIIF_INFO; StrCpyW(tnid.szInfoTitle,_T("MicroSIP: Shutting Down...")); char cInfo[256]; sprintf(cInfo, "%s", "Unbinding uPnP"); StrCpyW(tnid.szInfo, convertCharArrayToLPCWSTR(cInfo)); StrCpyW(tnid.szTip, _T("MicroSIP: Shutting Down...\nUnbinding uPnP")); Shell_NotifyIcon(NIM_MODIFY,&tnid); if (hicon) DestroyIcon(hicon); // Play windows notification sound as we have put a notification on the box PlaySound(TEXT("SystemExit"), NULL, SND_ALIAS); return true; }
vector<string> get_all_files_names_within_folder(string folder) { vector<string> names; char search_path[200]; sprintf(search_path, "%s*.*", folder.c_str()); WIN32_FIND_DATA fd; wchar_t *w_search_path = convertCharArrayToLPCWSTR(search_path); HANDLE hFind = ::FindFirstFile(w_search_path, &fd); if (hFind != INVALID_HANDLE_VALUE) { do { // read all (real) files in current folder // , delete '!' read other 2 default folder . and .. if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { CHAR dest[MAX_PATH]; std::transform(fd.cFileName, fd.cFileName + MAX_PATH, dest, wide_to_narrow); names.push_back(dest); } } while (::FindNextFile(hFind, &fd)); ::FindClose(hFind); } return names; }
void Upgrader::launcher(int launchtarget, int launcharg) { if (bfs::exists(GetProgramDir() / targetswitch(launchtarget))) { #ifndef WIN32 std::stringstream pidstream; pidstream << getpid(); std::string pid = pidstream.str(); printf("Parent: %s\n", pid.c_str()); if(!fork()) { if(launchtarget!=UPGRADER) { execl((GetProgramDir() / targetswitch(launchtarget)).c_str(), targetswitch(launchtarget).c_str(), NULL); } else { std::stringstream launcher; #ifdef QT_GUI launcher << QT; #else launcher << DAEMON; #endif execl((GetProgramDir() / targetswitch(launchtarget)).c_str(), targetswitch(launchtarget).c_str(), targetswitch(launcharg).c_str() , pid.c_str(), launcher.str().c_str(), NULL); } } #else PROCESS_INFORMATION ProcessInfo; STARTUPINFO StartupInfo; ZeroMemory(&StartupInfo, sizeof(StartupInfo)); StartupInfo.cb = sizeof StartupInfo; std::string argumentstring = targetswitch(launchtarget); argumentstring.append(" "); argumentstring.append(targetswitch(launcharg)); argumentstring.append(" "); long unsigned int pid = GetCurrentProcessId(); argumentstring.append(boost::lexical_cast<std::string>(pid)); argumentstring.append(" "); #ifdef QT_GUI argumentstring.append(boost::lexical_cast<std::string>(QT)); #else argumentstring.append(boost::lexical_cast<std::string>(DAEMON)); #endif argumentstring.append(" "); char * argument = new char[argumentstring.length() + sizeof(char)]; strcpy(argument, argumentstring.c_str()); std::string programstring = (GetProgramDir() / targetswitch(launchtarget)).string(); char * program = new char[programstring.length()]; strcpy(program, programstring.c_str()); #if defined QT_GUI && defined WIN32 wchar_t* wcProgram = convertCharArrayToLPCWSTR(program); wchar_t* wcArgument = convertCharArrayToLPCWSTR(argument); CreateProcess(wcProgram, wcArgument, NULL, NULL, FALSE, 0, NULL, NULL, &StartupInfo, &ProcessInfo); #else CreateProcess(program, argument, NULL, NULL, FALSE, 0, NULL, NULL, &StartupInfo, &ProcessInfo); #endif delete argument; delete program; #endif } else { printf("Could not find %s\n", targetswitch(launchtarget).c_str()); } #ifndef UPGRADERFLAG StartShutdown(); #endif }
int NameToBthAddr(char *pszRemoteName, PSOCKADDR_BTH pRemoteBthAddr) { INT iResult = CXN_SUCCESS; BOOL bContinueLookup = FALSE, bRemoteDeviceFound = FALSE; ULONG ulFlags = 0, ulPQSSize = sizeof(WSAQUERYSET); HANDLE hLookup = NULL; PWSAQUERYSET pWSAQuerySet = NULL; ZeroMemory(pRemoteBthAddr, sizeof(*pRemoteBthAddr)); pWSAQuerySet = (PWSAQUERYSET)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ulPQSSize); if (NULL == pWSAQuerySet) { iResult = STATUS_NO_MEMORY; printf("[BTClient] Unable to allocate memory for WSAQUERYSET\n"); } // // Search for the device with the correct name // printf("[BTClient] Looking for %s...\n", pszRemoteName); if (CXN_SUCCESS == iResult) { for (INT iRetryCount = 0; !bRemoteDeviceFound && (iRetryCount < CXN_MAX_INQUIRY_RETRY); iRetryCount++) { // // WSALookupService is used for both service search and device inquiry // LUP_CONTAINERS is the flag which signals that we're doing a device inquiry. // ulFlags = LUP_CONTAINERS; // // Friendly device name (if available) will be returned in lpszServiceInstanceName // ulFlags |= LUP_RETURN_NAME; // // BTH_ADDR will be returned in lpcsaBuffer member of WSAQUERYSET // ulFlags |= LUP_RETURN_ADDR; if (0 == iRetryCount) { printf("[BTClient] Inquiring device from cache...\n"); } else { // // Flush the device cache for all inquiries, except for the first inquiry // // By setting LUP_FLUSHCACHE flag, we're asking the lookup service to do // a fresh lookup instead of pulling the information from device cache. // ulFlags |= LUP_FLUSHCACHE; // // Pause for some time before all the inquiries after the first inquiry // // Remote Name requests will arrive after device inquiry has // completed. Without a window to receive IN_RANGE notifications, // we don't have a direct mechanism to determine when remote // name requests have completed. // printf("[BTClient] Unable to find device. Waiting for %d seconds before re-inquiry...\n", CXN_DELAY_NEXT_INQUIRY); Sleep(CXN_DELAY_NEXT_INQUIRY * 1000); printf("[BTClient] Inquiring device ...\n"); } // // Start the lookup service // iResult = CXN_SUCCESS; hLookup = 0; bContinueLookup = FALSE; ZeroMemory(pWSAQuerySet, ulPQSSize); pWSAQuerySet->dwNameSpace = NS_BTH; pWSAQuerySet->dwSize = sizeof(WSAQUERYSET); printf("[BTClient] before WSALookupServiceBegin\n"); iResult = WSALookupServiceBegin(pWSAQuerySet, ulFlags, &hLookup); printf("[BTClient] after WSALookupServiceBegin\n"); // // Even if we have an error, we want to continue until we // reach the CXN_MAX_INQUIRY_RETRY // if ((NO_ERROR == iResult) && (NULL != hLookup)) { bContinueLookup = TRUE; } else if (0 < iRetryCount) { printf("[BTClient] WSALookupServiceBegin() failed with error code %d, WSAGetLastError = %d\n", iResult, WSAGetLastError()); break; } while (bContinueLookup) { // // Get information about next bluetooth device // // Note you may pass the same WSAQUERYSET from LookupBegin // as long as you don't need to modify any of the pointer // members of the structure, etc. // // ZeroMemory(pWSAQuerySet, ulPQSSize); // pWSAQuerySet->dwNameSpace = NS_BTH; // pWSAQuerySet->dwSize = sizeof(WSAQUERYSET); printf("[BTClient] Before WSALookupServiceNext\n"); if (NO_ERROR == WSALookupServiceNext(hLookup, ulFlags, &ulPQSSize, pWSAQuerySet)) { // // Compare the name to see if this is the device we are looking for. // wchar_t* wcRemoteName = convertCharArrayToLPCWSTR(pszRemoteName); if ((pWSAQuerySet->lpszServiceInstanceName != NULL) && (0 == wcscmp(pWSAQuerySet->lpszServiceInstanceName, wcRemoteName))) { delete wcRemoteName; // // Found a remote bluetooth device with matching name. // Get the address of the device and exit the lookup. // wprintf(L"[BTClient] Found %s!\n", pWSAQuerySet->lpszServiceInstanceName); //printf("[BTClient] lpszServiceInstanceName addr %d\n", (pWSAQuerySet->lpszServiceInstanceName)); //printf("[BTClient] lpcsaBuffer address is %d\n", (pWSAQuerySet->lpcsaBuffer)); //printf("[BTClient]\t pResults->...->btAddr: %012X\n", ((PSOCKADDR_BTH)pWSAQuerySet->lpcsaBuffer->RemoteAddr.lpSockaddr)->btAddr); //printf("[BTClient] RemoteAddr address is %d\n", (pWSAQuerySet->lpcsaBuffer->RemoteAddr)); CopyMemory(pRemoteBthAddr, (PSOCKADDR_BTH)pWSAQuerySet->lpcsaBuffer->RemoteAddr.lpSockaddr, sizeof(*pRemoteBthAddr)); bRemoteDeviceFound = TRUE; bContinueLookup = FALSE; printf("[BTClient] Finished copy\n"); } else { wprintf(L"[BTClient] Found %s, still looking...\n", pWSAQuerySet->lpszServiceInstanceName); } } else { iResult = WSAGetLastError(); if (WSA_E_NO_MORE == iResult) { //No more data printf("[BTClient] WSA_E_NO_MORE\n"); // // No more devices found. Exit the lookup. // bContinueLookup = FALSE; } else if (WSAEFAULT == iResult) { // // The buffer for QUERYSET was insufficient. // In such case 3rd parameter "ulPQSSize" of function "WSALookupServiceNext()" receives // the required size. So we can use this parameter to reallocate memory for QUERYSET. // HeapFree(GetProcessHeap(), 0, pWSAQuerySet); pWSAQuerySet = (PWSAQUERYSET)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ulPQSSize); printf("[BTClient] Got WSAEFAULT\n"); if (NULL == pWSAQuerySet) { printf("[BTClient] Unable to allocate memory for WSAQERYSET\n"); iResult = STATUS_NO_MEMORY; bContinueLookup = FALSE; } } else { printf("[BTClient] WSALookupServiceNext() failed with error code %d\n", iResult); bContinueLookup = FALSE; } } } // // End the lookup service // WSALookupServiceEnd(hLookup); if (STATUS_NO_MEMORY == iResult) { break; } } } if (NULL != pWSAQuerySet) { HeapFree(GetProcessHeap(), 0, pWSAQuerySet); pWSAQuerySet = NULL; } if (bRemoteDeviceFound) { iResult = CXN_SUCCESS; } else { iResult = CXN_ERROR; } return iResult; }
void MsgBox(char *str) { MessageBoxW(NULL, convertCharArrayToLPCWSTR(str), NULL, MB_HELP); }
// ============================================================================= // BTDeviceIsNear // ============================================================================= bool BTDeviceIsNear() { //Initialising winsock WSADATA data; int result; result = WSAStartup(MAKEWORD(2, 2), &data); if (result != 0){ MsgBox("An error occured while initialising winsock, closing...."); return false; } //Initialising query for device WSAQUERYSET queryset; memset(&queryset, 0, sizeof(WSAQUERYSET)); queryset.dwSize = sizeof(WSAQUERYSET); queryset.dwNameSpace = NS_BTH; HANDLE hLookup; result = WSALookupServiceBegin(&queryset, LUP_CONTAINERS, &hLookup); if (result != 0){ MsgBox("An error occured while initialising look for devices, closing...."); return false; } //Initialisation succeed, start looking for devices BYTE buffer[4096]; memset(buffer, 0, sizeof(buffer)); DWORD bufferLength = sizeof(buffer); WSAQUERYSET *pResults = (WSAQUERYSET*)&buffer; while (result == 0) { result = WSALookupServiceNext(hLookup, LUP_RETURN_NAME | LUP_CONTAINERS | LUP_RETURN_ADDR | LUP_FLUSHCACHE | LUP_RETURN_TYPE | LUP_RETURN_BLOB | LUP_RES_SERVICE, &bufferLength, pResults); if (result == 0) { // A device found LPTSTR deviceFoundName = pResults->lpszServiceInstanceName; PSOCKADDR_BTH sa = PSOCKADDR_BTH(pResults->lpcsaBuffer->RemoteAddr.lpSockaddr); if (sa->addressFamily != AF_BTH) { // Address family is not AF_BTH for bluetooth device discovered continue; } //the MAC address is available in sa->btAddr printf("[HookExe] Device found\n"); if ((deviceFoundName != NULL) && (0 == _wcsicmp(deviceFoundName, convertCharArrayToLPCWSTR("btdevice")))) { printf("[HookExe] Found the device!\n"); printf("[HookExe] Device name is %S\t Device addr is 0x%0x\n", deviceFoundName, sa->btAddr); if (BluetoothIsConnectable(hLookup)) { //if (pResults->dwOutputFlags == BTHNS_RESULT_DEVICE_CONNECTED) { printf("[HookExe] Device is CONNECTED!!! 0x%0x \n", pResults->dwOutputFlags); } else { printf("[HookExe] Device is NOOOOOOOT CONNECTED!!! - 0x%0x\n", pResults->dwOutputFlags); } return true; } else { printf("[HookExe] Didn't find the device...\n"); printf("[HookExe] Device name is %S\t Device addr is 0x%0x\n", deviceFoundName, sa->btAddr); } } } WSALookupServiceEnd(hLookup); return false; }
bool ofxVideoRecorder::setupCustomOutput(int w, int h, float fps, int sampleRate, int channels, string outputString, bool sysClockSync, bool silent) { if (bIsInitialized) { close(); } bIsSilent = silent; bSysClockSync = sysClockSync; bRecordAudio = (sampleRate > 0 && channels > 0); bRecordVideo = (w > 0 && h > 0 && fps > 0); bFinishing = false; videoFramesRecorded = 0; audioSamplesRecorded = 0; if (!bRecordVideo && !bRecordAudio) { ofLogWarning() << "ofxVideoRecorder::setupCustomOutput(): invalid parameters, could not setup video or audio stream.\n" << "video: " << w << "x" << h << "@" << fps << "fps\n" << "audio: " << "channels: " << channels << " @ " << sampleRate << "Hz\n"; return false; } videoPipePath = ""; audioPipePath = ""; pipeNumber = requestPipeNumber(); if (bRecordVideo) { width = w; height = h; frameRate = fps; #if defined( TARGET_OSX ) || defined( TARGET_LINUX ) // recording video, create a FIFO pipe videoPipePath = ofFilePath::getAbsolutePath("ofxvrpipe" + ofToString(pipeNumber)); ofStringReplace(videoPipePath, " ", "\\ "); if (!ofFile::doesFileExist(videoPipePath)) { string cmd = "bash --login -c 'mkfifo " + videoPipePath + "'"; system(cmd.c_str()); } #endif #ifdef TARGET_WIN32 char vpip[128]; int num = ofRandom(1024); sprintf(vpip, "\\\\.\\pipe\\videoPipe%d", num); vPipename = convertCharArrayToLPCWSTR(vpip); hVPipe = CreateNamedPipe( vPipename, // name of the pipe PIPE_ACCESS_OUTBOUND, // 1-way pipe -- send only PIPE_TYPE_BYTE, // send data as a byte stream 1, // only allow 1 instance of this pipe 0, // outbound buffer defaults to system default 0, // no inbound buffer 0, // use default wait time NULL // use default security attributes ); if (!(hVPipe != INVALID_HANDLE_VALUE)) { if (GetLastError() != ERROR_PIPE_BUSY) { ofLogError("Video Pipe") << "Could not open video pipe."; } // All pipe instances are busy, so wait for 5 seconds. if (!WaitNamedPipe(vPipename, 5000)) { ofLogError("Video Pipe") << "Could not open video pipe: 5 second wait timed out."; } } #endif } if (bRecordAudio) { this->sampleRate = sampleRate; audioChannels = channels; #if defined( TARGET_OSX ) || defined( TARGET_LINUX ) // recording video, create a FIFO pipe audioPipePath = ofFilePath::getAbsolutePath("ofxarpipe" + ofToString(pipeNumber)); ofStringReplace(audioPipePath, " ", "\\ "); if (!ofFile::doesFileExist(audioPipePath)) { string cmd = "bash --login -c 'mkfifo " + audioPipePath + "'"; system(cmd.c_str()); } #endif #ifdef TARGET_WIN32 char apip[128]; int num = ofRandom(1024); sprintf(apip, "\\\\.\\pipe\\videoPipe%d", num); aPipename = convertCharArrayToLPCWSTR(apip); hAPipe = CreateNamedPipe( aPipename, PIPE_ACCESS_OUTBOUND, // 1-way pipe -- send only PIPE_TYPE_BYTE, // send data as a byte stream 1, // only allow 1 instance of this pipe 0, // outbound buffer defaults to system default 0, // no inbound buffer 0, // use default wait time NULL // use default security attributes ); if (!(hAPipe != INVALID_HANDLE_VALUE)) { if (GetLastError() != ERROR_PIPE_BUSY) { ofLogError("Audio Pipe") << "Could not open audio pipe."; } // All pipe instances are busy, so wait for 5 seconds. if (!WaitNamedPipe(aPipename, 5000)) { ofLogError("Audio Pipe") << "Could not open pipe: 5 second wait timed out."; } } #endif } stringstream cmd; // basic ffmpeg invocation, -y option overwrites output file #if defined( TARGET_OSX ) || defined( TARGET_LINUX ) cmd << "bash --login -c '" << ffmpegLocation << (bIsSilent ? " -loglevel quiet " : " ") << "-y"; if (bRecordAudio) { cmd << " -acodec pcm_s16le -f s16le -ar " << sampleRate << " -ac " << audioChannels << " -i " << audioPipePath; } else { // no audio stream cmd << " -an"; } if (bRecordVideo) { // video input options and file cmd << " -r " << fps << " -s " << w << "x" << h << " -f rawvideo -pix_fmt " << pixelFormat << " -i " << videoPipePath << " -r " << fps; } else { // no video stream cmd << " -vn"; } cmd << " " + outputString + "' &"; //cerr << cmd.str(); ffmpegThread.setup(cmd.str()); // start ffmpeg thread, will wait for input pipes to be opened if (bRecordAudio) { audioThread.setup(audioPipePath, &audioFrames); } if (bRecordVideo) { videoThread.setup(videoPipePath, &frames); } #endif #ifdef TARGET_WIN32 //evidently there are issues with multiple named pipes http://trac.ffmpeg.org/ticket/1663 if (bRecordAudio && bRecordVideo) { bool fSuccess; // Audio Thread stringstream aCmd; aCmd << ffmpegLocation << " -y " << " -f s16le -acodec " << audioCodec << " -ar " << sampleRate << " -ac " << audioChannels; aCmd << " -i " << convertWideToNarrow(aPipename) << " -b:a " << audioBitrate << " " << outputString << "_atemp" << audioFileExt; ffmpegAudioThread.setup(aCmd.str()); ofLogNotice("FFMpeg Command") << aCmd.str() << endl; fSuccess = ConnectNamedPipe(hAPipe, NULL); if (!fSuccess) { LPTSTR errorText = NULL; FormatMessageW( // use system message tables to retrieve error text FORMAT_MESSAGE_FROM_SYSTEM // allocate buffer on local heap for error text | FORMAT_MESSAGE_ALLOCATE_BUFFER // Important! will fail otherwise, since we're not // (and CANNOT) pass insertion parameters | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, // unused with FORMAT_MESSAGE_FROM_SYSTEM GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errorText, // output 0, // minimum size for output buffer NULL); // arguments - see note wstring ws = errorText; string error(ws.begin(), ws.end()); ofLogError("Audio Pipe") << "SetNamedPipeHandleState failed: " << error; } else { ofLogNotice("Audio Pipe") << "\n==========================\nAudio Pipe Connected Successfully\n==========================\n" << endl; audioThread.setup(hAPipe, &audioFrames); } // Video Thread stringstream vCmd; vCmd << ffmpegLocation << " -y " << " -r " << fps << " -s " << w << "x" << h << " -f rawvideo -pix_fmt " << pixelFormat; vCmd << " -i " << convertWideToNarrow(vPipename) << " -vcodec " << videoCodec << " -b:v " << videoBitrate << " " << outputString << "_vtemp" << movFileExt; ffmpegVideoThread.setup(vCmd.str()); ofLogNotice("FFMpeg Command") << vCmd.str() << endl; fSuccess = ConnectNamedPipe(hVPipe, NULL); if (!fSuccess) { LPTSTR errorText = NULL; FormatMessageW( // use system message tables to retrieve error text FORMAT_MESSAGE_FROM_SYSTEM // allocate buffer on local heap for error text | FORMAT_MESSAGE_ALLOCATE_BUFFER // Important! will fail otherwise, since we're not // (and CANNOT) pass insertion parameters | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, // unused with FORMAT_MESSAGE_FROM_SYSTEM GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errorText, // output 0, // minimum size for output buffer NULL); // arguments - see note wstring ws = errorText; string error(ws.begin(), ws.end()); ofLogError("Video Pipe") << "SetNamedPipeHandleState failed: " << error; } else { ofLogNotice("Video Pipe") << "\n==========================\nVideo Pipe Connected Successfully\n==========================\n" << endl; videoThread.setup(hVPipe, &frames); } } else { cmd << ffmpegLocation << " -y "; if (bRecordAudio) { cmd << " -f s16le -acodec " << audioCodec << " -ar " << sampleRate << " -ac " << audioChannels << " -i " << convertWideToNarrow(aPipename); } else { // no audio stream cmd << " -an"; } if (bRecordVideo) { // video input options and file cmd << " -r " << fps << " -s " << w << "x" << h << " -f rawvideo -pix_fmt " << pixelFormat << " -i " << convertWideToNarrow(vPipename); } else { // no video stream cmd << " -vn"; } if (bRecordAudio) cmd << " -b:a " << audioBitrate; if (bRecordVideo) cmd << " -vcodec " << videoCodec << " -b:v " << videoBitrate; cmd << " " << outputString << movFileExt; ofLogNotice("FFMpeg Command") << cmd.str() << endl; ffmpegThread.setup(cmd.str()); // start ffmpeg thread, will wait for input pipes to be opened if (bRecordAudio) { //this blocks, so we have to call it after ffmpeg is listening for a pipe bool fSuccess = ConnectNamedPipe(hAPipe, NULL); if (!fSuccess) { LPTSTR errorText = NULL; FormatMessageW( // use system message tables to retrieve error text FORMAT_MESSAGE_FROM_SYSTEM // allocate buffer on local heap for error text | FORMAT_MESSAGE_ALLOCATE_BUFFER // Important! will fail otherwise, since we're not // (and CANNOT) pass insertion parameters | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, // unused with FORMAT_MESSAGE_FROM_SYSTEM GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errorText, // output 0, // minimum size for output buffer NULL); // arguments - see note wstring ws = errorText; string error(ws.begin(), ws.end()); ofLogError("Audio Pipe") << "SetNamedPipeHandleState failed: " << error; } else { ofLogNotice("Audio Pipe") << "\n==========================\nAudio Pipe Connected Successfully\n==========================\n" << endl; audioThread.setup(hAPipe, &audioFrames); } } if (bRecordVideo) { //this blocks, so we have to call it after ffmpeg is listening for a pipe bool fSuccess = ConnectNamedPipe(hVPipe, NULL); if (!fSuccess) { LPTSTR errorText = NULL; FormatMessageW( // use system message tables to retrieve error text FORMAT_MESSAGE_FROM_SYSTEM // allocate buffer on local heap for error text | FORMAT_MESSAGE_ALLOCATE_BUFFER // Important! will fail otherwise, since we're not // (and CANNOT) pass insertion parameters | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, // unused with FORMAT_MESSAGE_FROM_SYSTEM GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errorText, // output 0, // minimum size for output buffer NULL); // arguments - see note wstring ws = errorText; string error(ws.begin(), ws.end()); ofLogError("Video Pipe") << "SetNamedPipeHandleState failed: " << error; } else { ofLogNotice("Video Pipe") << "\n==========================\nVideo Pipe Connected Successfully\n==========================\n" << endl; videoThread.setup(hVPipe, &frames); } } } #endif bIsInitialized = true; bIsRecording = false; bIsPaused = false; startTime = 0; recordingDuration = 0; totalRecordingDuration = 0; return bIsInitialized; }