// Creates DeviceInfo object for the current GPU DeviceInfo() : device_id_(getDevice()) { query(); }
void deviceSystemHandleRawData(char header, InputStream* inputStream, OutputStream* outputStream) { if (header == COMMAND_PING) { // data ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_PING); // Read and write in output the pingIndex (to control that it's the right which does the response) unsigned char pingIndex = readHex2(inputStream); appendHex2(outputStream, pingIndex); } // Last Error else if (header == COMMAND_GET_LAST_ERROR) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_GET_LAST_ERROR); unsigned int lastError = getLastError(); appendHex4(outputStream, lastError); } else if (header == COMMAND_CLEAR_LAST_ERROR) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_CLEAR_LAST_ERROR); clearLastError(); } // Device list else if (header == COMMAND_DEVICE_LIST) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_DEVICE_LIST); printDeviceList(getInfoOutputStreamLogger()); // Usage } else if (header == COMMAND_USAGE) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_USAGE); printDeviceListUsage(getInfoOutputStreamLogger(), false); } else if (header == COMMAND_USAGE_PROBLEM) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_USAGE_PROBLEM); printDeviceListUsage(getInfoOutputStreamLogger(), true); } else if (header == COMMAND_USAGE_SPECIFIC_DEVICE) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_USAGE_SPECIFIC_DEVICE); char deviceHeader = readBinaryChar(inputStream); int size = getDeviceCount(); int i; for (i = 0; i < size; i++) { Device* device = getDevice(i); if (deviceHeader == device->deviceInterface->deviceHeader) { println(getInfoOutputStreamLogger()); printDeviceUsage(getInfoOutputStreamLogger(), device, false); return; } } appendString(getErrorOutputStreamLogger(), "Device Not Found ! "); } else if (header == COMMAND_CLS) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_CLS); #ifdef PC_COMPILER system("cls"); #else appendString(outputStream, "Unsupported Operation"); #endif // PC_COMPILER } else if (header == COMMAND_RESET) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_RESET); #ifdef PC_COMPILER appendString(outputStream, "Unsupported Operation"); #else // goto 0; #endif // PC_COMPILER } // Notifications else if (header == COMMAND_NOTIFICATION) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_NOTIFICATION); printDeviceListNotification(getInfoOutputStreamLogger(), false); } else if (header == COMMAND_WAIT) { appendAck(outputStream); int mSec = readHex4(inputStream); delaymSec(mSec); append(outputStream, SYSTEM_DEVICE_HEADER); append(outputStream, COMMAND_WAIT); } else if (header == COMMAND_BOARD_NAME) { appendString(getInfoOutputStreamLogger(), getBoardName()); println(getInfoOutputStreamLogger()); ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_BOARD_NAME); } }
bool StandardRequestHandler::operator()(const std::string& request_path, const std::string& full_request_path, const osc::ReceivedMessage& m) { try { std::string path = osgDB::getFilePath(full_request_path); std::string last_elem = osgDB::getSimpleFileName(full_request_path); osg::ref_ptr<osgGA::Event> ea = getDevice()->getOrCreateUserDataEvent(); osg::UserDataContainer* udc = ea->getOrCreateUserDataContainer(); ea->setName(_treatFirstArgumentAsValueName ? full_request_path : path); udc->setName(ea->getName()); if (m.ArgumentCount() == 0) { return true; } // if we have only one argument, get it and save it to the udc else if (m.ArgumentCount() == 1) { addArgumentToUdc(udc, last_elem, m.ArgumentsBegin()); return true; } else { unsigned int i(0); osc::ReceivedMessageArgumentIterator start = m.ArgumentsBegin(); if ((_treatFirstArgumentAsValueName) && (start->TypeTag() == osc::STRING_TYPE_TAG)) { last_elem = start->AsString(); ++start; // if we hav only 2 arguments, then save the value and return if (m.ArgumentCount() == 2) { addArgumentToUdc(udc, last_elem, start); return true; } } std::vector<float> float_vec; std::vector<double> double_vec; bool mixed_arguments(false); for(osc::ReceivedMessageArgumentIterator itr = start; itr != m.ArgumentsEnd(); ++itr, ++i) { if(itr->TypeTag() == osc::FLOAT_TYPE_TAG) { float_vec.push_back(itr->AsFloat()); } else if(itr->TypeTag() == osc::DOUBLE_TYPE_TAG) { double_vec.push_back(itr->AsDouble()); } else if(itr->TypeTag() == osc::INT32_TYPE_TAG) { float_vec.push_back(itr->AsInt32()); } else { mixed_arguments = true; break; } } if (!mixed_arguments) { unsigned int sum = float_vec.size() + double_vec.size(); if (sum == float_vec.size()) { if (addNativeTypeFromVector(udc, last_elem, float_vec)) return true; } else if (sum == double_vec.size()) { if (addNativeTypeFromVector(udc, last_elem, double_vec)) return true; } } for(osc::ReceivedMessageArgumentIterator itr = start; itr != m.ArgumentsEnd(); ++itr, ++i) { std::ostringstream ss; ss << last_elem << "_" << i; addArgumentToUdc(udc, ss.str(), itr); } } return true; } catch(osc::Exception& e) { handleException(e); return false; } return false; }
BlendState* D3D11Device::createBlendState(const BlendStateDesc& desc) { D3DBlendState* presult = new D3DBlendState(); presult->create(getDevice(), desc); return presult; }
int main() { // // Engine initialization. // if (!vkts::engineInit()) { return -1; } vkts::logSetLevel(VKTS_LOG_INFO); // VkResult result; // if (!vkts::wsiGatherNeededInstanceExtensions()) { vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not gather instance extensions."); terminateApp(); return -1; } auto instance = vkts::instanceCreate(VKTS_EXAMPLE_NAME, VK_MAKE_VERSION(1, 0, 0), VK_MAKE_VERSION(1, 0, 0), 0, 0, nullptr, vkts::extensionGetNeededInstanceExtensionCount(), vkts::extensionGetNeededInstanceExtensionNames()); if (!instance.get()) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create instance."); terminateApp(); return -1; } if (!vkts::wsiInitInstanceExtensions(instance->getInstance())) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not initialize instance extension."); terminateApp(); return -1; } auto physicalDevice = vkts::physicalDeviceCreate(instance->getInstance(), 0); if (!physicalDevice.get()) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not get physical device."); terminateApp(); return -1; } // VkPhysicalDeviceProperties physicalDeviceProperties; physicalDevice->getPhysicalDeviceProperties(physicalDeviceProperties); // Check, if uniform buffer size is large enough. if (physicalDeviceProperties.limits.maxUniformBufferRange < VKTS_MAX_JOINTS_BUFFERSIZE) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Physical device does not have needed uniform buffer range: %u < %u", physicalDeviceProperties.limits.maxUniformBufferRange, VKTS_MAX_JOINTS_BUFFERSIZE); return VK_FALSE; } // if (!vkts::wsiGatherNeededDeviceExtensions(physicalDevice->getPhysicalDevice())) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not gather device extension."); terminateApp(); return -1; } // // Visual initialization. // if (!vkts::visualInit(instance->getInstance(), physicalDevice->getPhysicalDevice())) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not initialize visual."); terminateApp(); return -1; } display = vkts::visualCreateDefaultDisplay().lock(); if (!display.get()) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create display."); terminateApp(); return -1; } window = vkts::visualCreateWindow(display, VKTS_EXAMPLE_NAME, 1024, 768, VK_FALSE, VK_TRUE, VK_FALSE).lock(); if (!window.get()) { window = vkts::visualGetWindow(VKTS_DEFAULT_WINDOW_INDEX).lock(); if (!window.get()) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create window."); terminateApp(); return -1; } } // surface = vkts::wsiSurfaceCreate(instance->getInstance(), display->getNativeDisplay(), window->getNativeWindow()); if (!surface.get()) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create surface."); terminateApp(); return -1; } // std::vector<VkBool32> supportFilter; result = vkts::wsiGetPhysicalDeviceSurfaceSupport(physicalDevice->getPhysicalDevice(), surface->getSurface(), (uint32_t) physicalDevice->getAllQueueFamilyProperties().size(), supportFilter); if (result != VK_SUCCESS || supportFilter.size() == 0) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not get physical device surface support."); terminateApp(); return -1; } // uint32_t queueFamilyIndex; if (!vkts::queueGetFamilyIndex(physicalDevice->getAllQueueFamilyProperties(), VK_QUEUE_GRAPHICS_BIT, 0, &supportFilter, queueFamilyIndex)) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not find queue family index."); terminateApp(); return -1; } // float queuePriorities[1] = {0.0f}; VkDeviceQueueCreateInfo deviceQueueCreateInfo; memset(&deviceQueueCreateInfo, 0, sizeof(VkDeviceQueueCreateInfo)); deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; deviceQueueCreateInfo.flags = 0; deviceQueueCreateInfo.queueFamilyIndex = 0; deviceQueueCreateInfo.queueCount = 1; deviceQueueCreateInfo.pQueuePriorities = queuePriorities; auto device = vkts::deviceCreate(physicalDevice->getPhysicalDevice(), 0, 1, &deviceQueueCreateInfo, 0, nullptr, vkts::extensionGetNeededDeviceExtensionCount(), vkts::extensionGetNeededDeviceExtensionNames(), nullptr); if (!device.get()) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create device."); terminateApp(); return -1; } if (!vkts::wsiInitDeviceExtensions(device->getDevice())) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not initialize device extension."); terminateApp(); return -1; } // auto queue = vkts::queueGet(device->getDevice(), queueFamilyIndex, 0); if (!queue.get()) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not get device queue."); terminateApp(); return -1; } // initialResources = vkts::initialResourcesCreate(instance, physicalDevice, device, queue); if (!initialResources.get()) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create initial resources."); terminateApp(); return -1; } // // Example setup. // // Single threaded application, so it is safe to pass display and window. vkts::IUpdateThreadSP example = vkts::IUpdateThreadSP(new Example(initialResources, window->getIndex(), surface)); if (!example.get()) { vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create application."); terminateApp(); return -1; } // This update thread is executed in the main loop. No additional thread is launched. vkts::engineAddUpdateThread(example); // // Execution. // vkts::engineRun(); // // Termination. // terminateApp(); return 0; }
bool Blit::setFormatConvertShaders(GLenum destFormat) { bool okay = setVertexShader(SHADER_VS_STANDARD); switch (destFormat) { default: UNREACHABLE(); case GL_RGBA: case GL_BGRA_EXT: case GL_RGB: case GL_ALPHA: okay = okay && setPixelShader(SHADER_PS_COMPONENTMASK); break; case GL_LUMINANCE: case GL_LUMINANCE_ALPHA: okay = okay && setPixelShader(SHADER_PS_LUMINANCE); break; } if (!okay) { return false; } enum { X = 0, Y = 1, Z = 2, W = 3 }; // The meaning of this constant depends on the shader that was selected. // See the shader assembly code above for details. float psConst0[4] = { 0, 0, 0, 0 }; switch (destFormat) { default: UNREACHABLE(); case GL_RGBA: case GL_BGRA_EXT: psConst0[X] = 1; psConst0[Z] = 1; break; case GL_RGB: psConst0[X] = 1; psConst0[W] = 1; break; case GL_ALPHA: psConst0[Z] = 1; break; case GL_LUMINANCE: psConst0[Y] = 1; break; case GL_LUMINANCE_ALPHA: psConst0[X] = 1; break; } getDevice()->SetPixelShaderConstantF(0, psConst0, 1); return true; }
inline DeviceInfo::DeviceInfo() { device_id_ = getDevice(); }
double getLocalTime(double time_stamp) { return getDevice()->getLocalTime(time_stamp); }
HRESULT doCreateShader(ID3DBlob* blob, ID3D11DeviceChild** pHandle) { return getDevice()->CreatePixelShader(blob->GetBufferPointer(), blob->GetBufferSize(), NULL, reinterpret_cast<ID3D11PixelShader**>(pHandle)); }
int main(int argc, const char *argv[]) { vector<ocl::Info> oclinfo; int num_devices = getDevice(oclinfo); if (num_devices < 1) { cerr << "no device found\n"; return -1; } // set this to overwrite binary cache every time the test starts ocl::setBinaryDiskCache(ocl::CACHE_UPDATE); int devidx = 0; for (size_t i = 0; i < oclinfo.size(); i++) { for (size_t j = 0; j < oclinfo[i].DeviceName.size(); j++) { printf("device %d: %s\n", devidx++, oclinfo[i].DeviceName[j].c_str()); } } const char *keys = "{ h help | false | print help message }" "{ f filter | | filter for test }" "{ w workdir | | set working directory }" "{ l list | false | show all tests }" "{ d device | 0 | device id }" "{ i iters | 10 | iteration count }" "{ m warmup | 1 | gpu warm up iteration count}" "{ t xtop | 1.1 | xfactor top boundary}" "{ b xbottom | 0.9 | xfactor bottom boundary}" "{ v verify | false | only run gpu once to verify if problems occur}"; CommandLineParser cmd(argc, argv, keys); if (cmd.has("help")) { cout << "Avaible options:" << endl; cmd.printMessage(); return 0; } int device = cmd.get<int>("device"); if (device < 0 || device >= num_devices) { cerr << "Invalid device ID" << endl; return -1; } if (cmd.get<bool>("verify")) { TestSystem::instance().setNumIters(1); TestSystem::instance().setGPUWarmupIters(0); TestSystem::instance().setCPUIters(0); } devidx = 0; for (size_t i = 0; i < oclinfo.size(); i++) { for (size_t j = 0; j < oclinfo[i].DeviceName.size(); j++, devidx++) { if (device == devidx) { ocl::setDevice(oclinfo[i], (int)j); TestSystem::instance().setRecordName(oclinfo[i].DeviceName[j]); printf("\nuse %d: %s\n", devidx, oclinfo[i].DeviceName[j].c_str()); goto END_DEV; } } } END_DEV: string filter = cmd.get<string>("filter"); string workdir = cmd.get<string>("workdir"); bool list = cmd.has("list"); int iters = cmd.get<int>("iters"); int wu_iters = cmd.get<int>("warmup"); double x_top = cmd.get<double>("xtop"); double x_bottom = cmd.get<double>("xbottom"); TestSystem::instance().setTopThreshold(x_top); TestSystem::instance().setBottomThreshold(x_bottom); if (!filter.empty()) { TestSystem::instance().setTestFilter(filter); } if (!workdir.empty()) { if (workdir[workdir.size() - 1] != '/' && workdir[workdir.size() - 1] != '\\') { workdir += '/'; } TestSystem::instance().setWorkingDir(workdir); } if (list) { TestSystem::instance().setListMode(true); } TestSystem::instance().setNumIters(iters); TestSystem::instance().setGPUWarmupIters(wu_iters); TestSystem::instance().run(); return 0; }
return numSubdevices; } //Gets the n-th subdevice ExpanduinoSubdevice* Expanduino::getDevice(uint8_t devNum) { ExpanduinoSubdevice* dev = &this->metaSubdevice; for (int i=0; i<devNum && dev; i++) { dev = dev->next; } return dev; } //Dispatches a request to the correct device void Expanduino::dispatch(uint8_t cmd, Stream& request, Print& response) { uint8_t devNum = (cmd >> 4) & 0x0F; ExpanduinoSubdevice* dev = getDevice(devNum); if (!dev) { //Invalid devNum return; } uint8_t opcode = cmd & 0x0F; dev->dispatch(opcode, request, response); } void Expanduino::getVendorName(Print& out) { out.print(vendorName ? vendorName : "Generic"); } void Expanduino::getProductName(Print& out) { out.print(productName ? productName : "Expanduino"); } void Expanduino::getSerialNumber(Print& out) {
std::vector<CameraConfig> videoInputCamera::getCameraConfigs(int dev_id) { std::vector<CameraConfig> cfg_list; int count = getDeviceCount(); if (count==0) return cfg_list; comInit(); HRESULT hr; ICaptureGraphBuilder2 *lpCaptureGraphBuilder; IGraphBuilder *lpGraphBuilder; IBaseFilter *lpInputFilter; IAMStreamConfig *lpStreamConfig; char nDeviceName[255]; WCHAR wDeviceName[255]; for (int cam_id=0;cam_id<count;cam_id++) { if ((dev_id>=0) && (dev_id!=cam_id)) continue; hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void **)&lpCaptureGraphBuilder); if (FAILED(hr)) // FAILED is a macro that tests the return value { printf("ERROR - Could not create the Filter Graph Manager\n"); comUnInit(); return cfg_list; } // Create the Filter Graph Manager. hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void**)&lpGraphBuilder); if (FAILED(hr)) { printf("ERROR - Could not add the graph builder!\n"); lpCaptureGraphBuilder->Release(); comUnInit(); return cfg_list; } hr = lpCaptureGraphBuilder->SetFiltergraph(lpGraphBuilder); if (FAILED(hr)) { printf("ERROR - Could not set filtergraph\n"); lpGraphBuilder->Release(); lpCaptureGraphBuilder->Release(); comUnInit(); return cfg_list; } memset(wDeviceName, 0, sizeof(WCHAR) * 255); memset(nDeviceName, 0, sizeof(char) * 255); hr = getDevice(&lpInputFilter, cam_id, wDeviceName, nDeviceName); if (SUCCEEDED(hr)){ hr = lpGraphBuilder->AddFilter(lpInputFilter, wDeviceName); }else{ printf("ERROR - Could not find specified video device\n"); lpGraphBuilder->Release(); lpCaptureGraphBuilder->Release(); comUnInit(); return cfg_list; } hr = lpCaptureGraphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, lpInputFilter, IID_IAMStreamConfig, (void **)&lpStreamConfig); if(FAILED(hr)){ printf("ERROR: Couldn't config the stream!\n"); lpInputFilter->Release(); lpGraphBuilder->Release(); lpCaptureGraphBuilder->Release(); comUnInit(); return cfg_list; } CameraConfig cam_cfg; CameraTool::initCameraConfig(&cam_cfg); cam_cfg.driver = DRIVER_DEFAULT; cam_cfg.device = cam_id; sprintf(cam_cfg.name, "%s", nDeviceName); int iCount = 0; int iSize = 0; hr = lpStreamConfig->GetNumberOfCapabilities(&iCount, &iSize); std::vector<CameraConfig> fmt_list; if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS)) { GUID lastFormat = MEDIASUBTYPE_None; for (int iFormat = 0; iFormat < iCount; iFormat+=2) { VIDEO_STREAM_CONFIG_CAPS scc; AM_MEDIA_TYPE *pmtConfig; hr = lpStreamConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc); if (SUCCEEDED(hr)){ if ( pmtConfig->subtype != lastFormat) { if (fmt_list.size()>0) { std::sort(fmt_list.begin(), fmt_list.end()); cfg_list.insert( cfg_list.end(), fmt_list.begin(), fmt_list.end() ); fmt_list.clear(); } cam_cfg.cam_format = getMediaSubtype(pmtConfig->subtype); lastFormat = pmtConfig->subtype; } int stepX = scc.OutputGranularityX; int stepY = scc.OutputGranularityY; if(stepX < 1 || stepY < 1) continue; else if ((stepX==1) && (stepY==1)) { cam_cfg.cam_width = scc.InputSize.cx; cam_cfg.cam_height = scc.InputSize.cy; int maxFrameInterval = scc.MaxFrameInterval; if (maxFrameInterval==0) maxFrameInterval = 10000000; float last_fps=-1; VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat; for (int iv=scc.MinFrameInterval;iv<=maxFrameInterval;iv=iv*2) { pVih->AvgTimePerFrame = iv; hr = lpStreamConfig->SetFormat(pmtConfig); if (hr==S_OK) { hr = lpStreamConfig->GetFormat(&pmtConfig); float fps = ((int)floor(100000000.0f/(float)pVih->AvgTimePerFrame + 0.5f))/10.0f; if (fps!=last_fps) { cam_cfg.cam_fps = fps; fmt_list.push_back(cam_cfg); last_fps=fps; } } } } else { int x,y; for (x=scc.MinOutputSize.cx,y=scc.MinOutputSize.cy;x<=scc.MaxOutputSize.cx,y<=scc.MaxOutputSize.cy;x+=stepX,y+=stepY) { cam_cfg.cam_width = x; cam_cfg.cam_height = y; int maxFrameInterval = scc.MaxFrameInterval; if (maxFrameInterval==0) maxFrameInterval = 10000000; float last_fps=-1; VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat; for (int iv=scc.MinFrameInterval;iv<=maxFrameInterval;iv=iv*2) { pVih->AvgTimePerFrame = iv; hr = lpStreamConfig->SetFormat(pmtConfig); if (hr==S_OK) { hr = lpStreamConfig->GetFormat(&pmtConfig); float fps = ((int)floor(100000000.0f/(float)pVih->AvgTimePerFrame + 0.5f))/10.0f; if (fps!=last_fps) { cam_cfg.cam_fps = fps; fmt_list.push_back(cam_cfg); last_fps=fps; } } } } } deleteMediaType(pmtConfig); } } } if (fmt_list.size()>0) { std::sort(fmt_list.begin(), fmt_list.end()); cfg_list.insert( cfg_list.end(), fmt_list.begin(), fmt_list.end() ); fmt_list.clear(); } lpStreamConfig->Release(); lpInputFilter->Release(); lpGraphBuilder->Release(); lpCaptureGraphBuilder->Release(); } comUnInit(); return cfg_list; }
HRESULT videoInputCamera::setupDevice() { comInit(); GUID CAPTURE_MODE = PIN_CATEGORY_CAPTURE; //Don't worry - it ends up being preview (which is faster) //printf("SETUP: Setting up device %i\n",deviceID); // CREATE THE GRAPH BUILDER // // Create the filter graph manager and query for interfaces. HRESULT hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void **)&pCaptureGraphBuilder); if (FAILED(hr)) // FAILED is a macro that tests the return value { printf("ERROR - Could not create the Filter Graph Manager\n"); return hr; } //FITLER GRAPH MANAGER// // Create the Filter Graph Manager. hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void**)&pGraphBuilder); if (FAILED(hr)) { printf("ERROR - Could not add the graph builder!\n"); stopDevice(); return hr; } //SET THE FILTERGRAPH// hr = pCaptureGraphBuilder->SetFiltergraph(pGraphBuilder); if (FAILED(hr)) { printf("ERROR - Could not set filtergraph\n"); stopDevice(); return hr; } //MEDIA CONTROL (START/STOPS STREAM)// // Using QueryInterface on the graph builder, // Get the Media Control object. hr = pGraphBuilder->QueryInterface(IID_IMediaControl, (void **)&pMediaControl); if (FAILED(hr)) { printf("ERROR - Could not create the Media Control object\n"); stopDevice(); return hr; } char nDeviceName[255]; WCHAR wDeviceName[255]; memset(wDeviceName, 0, sizeof(WCHAR) * 255); memset(nDeviceName, 0, sizeof(char) * 255); //FIND VIDEO DEVICE AND ADD TO GRAPH// //gets the device specified by the second argument. hr = getDevice(&pInputFilter, cfg->device, wDeviceName, nDeviceName); if (SUCCEEDED(hr)){ sprintf(cfg->name,nDeviceName); //printf("SETUP: %s\n", nDeviceName); hr = pGraphBuilder->AddFilter(pInputFilter, wDeviceName); }else{ printf("ERROR - Could not find specified video device\n"); stopDevice(); return hr; } //LOOK FOR PREVIEW PIN IF THERE IS NONE THEN WE USE CAPTURE PIN AND THEN SMART TEE TO PREVIEW IAMStreamConfig *streamConfTest = NULL; hr = pCaptureGraphBuilder->FindInterface(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pInputFilter, IID_IAMStreamConfig, (void **)&streamConfTest); if(FAILED(hr)){ //printf("SETUP: Couldn't find preview pin using SmartTee\n"); }else{ CAPTURE_MODE = PIN_CATEGORY_PREVIEW; streamConfTest->Release(); streamConfTest = NULL; } //CROSSBAR (SELECT PHYSICAL INPUT TYPE)// //my own function that checks to see if the device can support a crossbar and if so it routes it. //webcams tend not to have a crossbar so this function will also detect a webcams and not apply the crossbar /*if(useCrossbar) { //printf("SETUP: Checking crossbar\n"); routeCrossbar(pCaptureGraphBuilder, pInputFilter, connection, CAPTURE_MODE); }*/ //we do this because webcams don't have a preview mode hr = pCaptureGraphBuilder->FindInterface(&CAPTURE_MODE, &MEDIATYPE_Video, pInputFilter, IID_IAMStreamConfig, (void **)&pStreamConfig); if(FAILED(hr)){ printf("ERROR: Couldn't config the stream!\n"); stopDevice(); return hr; } //NOW LETS DEAL WITH GETTING THE RIGHT SIZE hr = pStreamConfig->GetFormat(&pAmMediaType); if(FAILED(hr)){ printf("ERROR: Couldn't getFormat for pAmMediaType!\n"); stopDevice(); return hr; } if (!setSizeAndSubtype()) return false; VIDEOINFOHEADER *pVih = reinterpret_cast<VIDEOINFOHEADER*>(pAmMediaType->pbFormat); cfg->cam_width = HEADER(pVih)->biWidth; cfg->cam_height = HEADER(pVih)->biHeight; cfg->cam_fps = ((int)floor(100000000.0f/(float)pVih->AvgTimePerFrame + 0.5f))/10.0f; long bufferSize = cfg->cam_width*cfg->cam_height*3; sgCallback->setupBuffer(bufferSize); // Create the Sample Grabber. hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,IID_IBaseFilter, (void**)&pGrabberFilter); if (FAILED(hr)){ printf("Could not Create Sample Grabber - CoCreateInstance()\n"); stopDevice(); return hr; } hr = pGraphBuilder->AddFilter(pGrabberFilter, L"Sample Grabber"); if (FAILED(hr)){ printf("Could not add Sample Grabber - AddFilter()\n"); stopDevice(); return hr; } hr = pGrabberFilter->QueryInterface(IID_ISampleGrabber, (void**)&pSampleGrabber); if (FAILED(hr)){ printf("ERROR: Could not query SampleGrabber\n"); stopDevice(); return hr; } //Get video properties from the stream's mediatype and apply to the grabber (otherwise we don't get an RGB image) AM_MEDIA_TYPE mt; ZeroMemory(&mt,sizeof(AM_MEDIA_TYPE)); mt.majortype = MEDIATYPE_Video; mt.subtype = MEDIASUBTYPE_RGB24; //mt.subtype = MEDIASUBTYPE_YUY2; mt.formattype = FORMAT_VideoInfo; //Set Params - One Shot should be false unless you want to capture just one buffer hr = pSampleGrabber->SetMediaType(&mt); hr = pSampleGrabber->SetOneShot(FALSE); hr = pSampleGrabber->SetBufferSamples(FALSE); //Tell the grabber to use our callback function - 0 is for SampleCB and 1 for BufferCB //We use SampleCB hr = pSampleGrabber->SetCallback(sgCallback, 0); if (FAILED(hr)) { printf("ERROR: problem setting callback\n"); stopDevice(); return hr; } /*else { printf("SETUP: Capture callback set\n"); }*/ //lets try freeing our stream conf here too //this will fail if the device is already running /* if(pStreamConfig) { pStreamConfig->Release(); pStreamConfig = NULL; } else { printf("ERROR: connecting device - prehaps it is already being used?\n"); stopDevice(); return S_FALSE; }*/ //used to give the video stream somewhere to go to. hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)(&pDestFilter)); if (FAILED(hr)){ printf("ERROR: Could not create filter - NullRenderer\n"); stopDevice(); return hr; } hr = pGraphBuilder->AddFilter(pDestFilter, L"NullRenderer"); if (FAILED(hr)){ printf("ERROR: Could not add filter - NullRenderer\n"); stopDevice(); return hr; } //This is where the stream gets put together. hr = pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pInputFilter, pGrabberFilter, pDestFilter); if (FAILED(hr)){ printf("ERROR: Could not connect pins - RenderStream()\n"); stopDevice(); return hr; } //EXP - lets try setting the sync source to null - and make it run as fast as possible { IMediaFilter *pMediaFilter = 0; hr = pGraphBuilder->QueryInterface(IID_IMediaFilter, (void**)&pMediaFilter); if (FAILED(hr)){ printf("ERROR: Could not get IID_IMediaFilter interface\n"); }else{ pMediaFilter->SetSyncSource(NULL); pMediaFilter->Release(); } } //printf("SETUP: Device is setup and ready to capture.\n\n"); //if we release this then we don't have access to the settings //we release our video input filter but then reconnect with it //each time we need to use it //pInputFilter->Release(); //pInputFilter = NULL; pGrabberFilter->Release(); pGrabberFilter = NULL; pDestFilter->Release(); pDestFilter = NULL; return S_OK; }
int deviceget() { return getDevice(); }
int getDeviceId(const array &in) { int device = getDevice(); ; AF_THROW(af_get_device_id(&device, in.get())); return device; }
MouseDialogNavigationTool::MouseDialogNavigationTool(const ToolFactory* factory,const ToolInputAssignment& inputAssignment) :NavigationTool(factory,inputAssignment), mouseAdapter(0), navigationDialogPopup(0), navigationMode(ROTATING), spinning(false), showScreenCenter(false) { /* Find the mouse input device adapter controlling the input device: */ mouseAdapter=dynamic_cast<InputDeviceAdapterMouse*>(getInputDeviceManager()->findInputDeviceAdapter(getDevice(0))); /* Create the tool's GUI: */ navigationDialogPopup=new GLMotif::PopupWindow("NavigationDialogPopup",getWidgetManager(),"Mouse Navigation Dialog"); GLMotif::RowColumn* navigationDialog=new GLMotif::RowColumn("NavigationDialog",navigationDialogPopup,false); GLMotif::RadioBox* navigationModes=new GLMotif::RadioBox("NavigationModes",navigationDialog,false); navigationModes->setOrientation(GLMotif::RowColumn::VERTICAL); navigationModes->setPacking(GLMotif::RowColumn::PACK_GRID); navigationModes->setSelectionMode(GLMotif::RadioBox::ALWAYS_ONE); navigationModes->addToggle("Rotate"); navigationModes->addToggle("Pan"); navigationModes->addToggle("Dolly"); navigationModes->addToggle("Scale"); switch(navigationMode) { case ROTATING: navigationModes->setSelectedToggle(0); break; case PANNING: navigationModes->setSelectedToggle(1); break; case DOLLYING: navigationModes->setSelectedToggle(2); break; case SCALING: navigationModes->setSelectedToggle(3); break; } navigationModes->getValueChangedCallbacks().add(this,&MouseDialogNavigationTool::navigationModesValueChangedCallback); navigationModes->manageChild(); GLMotif::ToggleButton* showScreenCenterToggle=new GLMotif::ToggleButton("ShowScreenCenterToggle",navigationDialog,"Show Screen Center"); showScreenCenterToggle->setToggle(showScreenCenter); showScreenCenterToggle->getValueChangedCallbacks().add(this,&MouseDialogNavigationTool::showScreenCenterToggleValueChangedCallback); navigationDialog->manageChild(); /* Pop up the navigation dialog: */ popupPrimaryWidget(navigationDialogPopup,getNavigationTransformation().transform(getDisplayCenter())); }