Reader* Manager::createReader(const ALuint& p_source, const std::string& p_fileName, const bool& p_isEvent, const int& m_posInFile, const int& m_posInBuffer) { Reader* result = NULL ; //Query a buffer a little bigger to evite the case //where openal thread try to use the buffer when we load it if (p_fileName.find(".wav") != std::string::npos) { result = new WavReader(p_source, findFilePath(p_fileName), p_isEvent, m_updateTime*1.10) ; } else if (p_fileName.find(".ogg") != std::string::npos) { result = new OggReader(p_source, findFilePath(p_fileName), p_isEvent, m_updateTime*1.10) ; } else { ErrorMessage("[OpenAl::Manager] unsupported file type") ; return NULL ; } result->onInit(m_posInFile, m_posInBuffer) ; m_readers.push_back(result) ; return result ; }
Stream* Manager::getStream(const std::string& file_name) { /// search for cached streams std::string file_path(findFilePath(file_name)) ; std::map<std::string,Stream*>::const_iterator stream = m_cached_streams.find(file_path) ; if (stream != m_cached_streams.end()) { return stream->second ; } Stream* result = NULL ; if (file_name.find(".ogg") != std::string::npos) { result = new OggFileStream(file_path) ; m_streams.insert(result) ; } else if (file_name.find(".wav") != std::string::npos) { result = new WavFileStream(file_path) ; m_streams.insert(result) ; } else { ErrorMessage("[OpenAl::Manager] unsupported file type") ; } return result ; }
void Manager::cacheRessource(const std::string& file_name) { std::string file_path(findFilePath(file_name)) ; std::map<std::string,Stream*>::const_iterator stream = m_cached_streams.find(file_path) ; if (stream == m_cached_streams.end()) { m_cached_streams[file_path] = new OggCachedStream(file_path) ; } }
int main(int argc, char* argv[]) { shrQAStart(argc, argv); try { std::string sFilename; char *filePath = findFilePath("Lena.pgm", argv[0]); if (filePath) { sFilename = filePath; } else { printf("Error unable to find Lena.pgm\n"); shrQAFinishExit(argc, (const char **)argv, QA_FAILED); } // Parse the command line arguments for proper configuration parseCommandLineArguments(argc, argv); printfNPPinfo(argc, argv); if (g_bQATest == false && (g_nDevice == -1) && argc > 1) { sFilename = argv[1]; } // if we specify the filename at the command line, then we only test sFilename[0]. int file_errors = 0; std::ifstream infile(sFilename.data(), std::ifstream::in); if (infile.good()) { std::cout << "boxFilterNPP opened: <" << sFilename.data() << "> successfully!" << std::endl; file_errors = 0; infile.close(); } else { std::cout << "boxFilterNPP unable to open: <" << sFilename.data() << ">" << std::endl; file_errors++; infile.close(); } if (file_errors > 0) { shrQAFinish(argc, (const char **)argv, QA_FAILED); exit(EXIT_FAILURE); } std::string sResultFilename = sFilename; std::string::size_type dot = sResultFilename.rfind('.'); if (dot != std::string::npos) sResultFilename = sResultFilename.substr(0, dot); sResultFilename += "_boxFilter.pgm"; if (argc >= 3 && !g_bQATest) sResultFilename = argv[2]; // declare a host image object for an 8-bit grayscale image npp::ImageCPU_8u_C1 oHostSrc; // load gray-scale image from disk npp::loadImage(sFilename, oHostSrc); // declare a device image and copy construct from the host image, // i.e. upload host to device npp::ImageNPP_8u_C1 oDeviceSrc(oHostSrc); // create struct with box-filter mask size NppiSize oMaskSize = {5, 5}; // create struct with ROI size given the current mask NppiSize oSizeROI = {oDeviceSrc.width() - oMaskSize.width + 1, oDeviceSrc.height() - oMaskSize.height + 1}; // allocate device image of appropriatedly reduced size npp::ImageNPP_8u_C1 oDeviceDst(oSizeROI.width, oSizeROI.height); // set anchor point inside the mask to (0, 0) NppiPoint oAnchor = {0, 0}; // run box filter NppStatus eStatusNPP; eStatusNPP = nppiFilterBox_8u_C1R(oDeviceSrc.data(), oDeviceSrc.pitch(), oDeviceDst.data(), oDeviceDst.pitch(), oSizeROI, oMaskSize, oAnchor); NPP_ASSERT(NPP_NO_ERROR == eStatusNPP); // declare a host image for the result npp::ImageCPU_8u_C1 oHostDst(oDeviceDst.size()); // and copy the device result data into it oDeviceDst.copyTo(oHostDst.data(), oHostDst.pitch()); saveImage(sResultFilename, oHostDst); std::cout << "Saved image: " << sResultFilename << std::endl; shrQAFinish(argc, (const char **)argv, QA_PASSED); exit(EXIT_SUCCESS); } catch (npp::Exception & rException) { std::cerr << "Program error! The following exception occurred: \n"; std::cerr << rException << std::endl; std::cerr << "Aborting." << std::endl; shrQAFinish(argc, (const char **)argv, QA_FAILED); exit(EXIT_FAILURE); } catch (...) { std::cerr << "Program error! An unknow type of exception occurred. \n"; std::cerr << "Aborting." << std::endl; shrQAFinish(argc, (const char **)argv, QA_FAILED); exit(EXIT_FAILURE); return -1; } return 0; }
bool LuaPath::findAppRoot(std::string const &fn) { _appRoot = findFilePath(fn); return (!_appRoot.empty()); }
QVDoorcom::QVDoorcom(QDomElement xml_desc, QString container, QWidget *parent) : QVElement(xml_desc,container,parent) { if (w < 1) { w = 1; } if (h < 1) { h = 1; } popup = 0; if (instance_count > 0) { w = h = 0; return; } instance_count = 1; doorcom = this; popup = new QVPopupFrame(parent); QDomElement e_server = xml_desc.firstChildElement("server"); QDomElement e_user = xml_desc.firstChildElement("user"); QDomElement e_password = xml_desc.firstChildElement("password"); if (e_server.isNull() || e_user.isNull() || e_password.isNull()) { qDebug() << "SIP client: insufficient auth info"; return; } QString s_server = e_server.text(); QString s_user = e_user.text(); QString s_password = e_password.text(); QDomElement e_caller = xml_desc.firstChildElement("source"); if (!e_caller.isNull()) { accepted_caller = e_caller.text(); } QDomElement e_accept = xml_desc.firstChildElement("accept"); if (!e_accept.isNull()) { code_accept = e_accept.text(); } QDomElement e_hangup = xml_desc.firstChildElement("hangup"); if (!e_hangup.isNull()) { code_hangup = e_hangup.text(); } QDomElement e_dooropen = xml_desc.firstChildElement("dooropen"); if (!e_dooropen.isNull()) { code_dooropen = e_dooropen.text(); } QFile f_doorbell; QString s_doorbell_name; bool doorbell_ok; bell_wav = 0; QDomElement e_doorbell = xml_desc.firstChildElement("ringtone"); if (!e_doorbell.isNull()) { s_doorbell_name = findFilePath(e_doorbell.text()); f_doorbell.setFileName(findFilePath(e_doorbell.text())); f_doorbell.open(QIODevice::ReadOnly); } if (!f_doorbell.isOpen()) { f_doorbell.setFileName(":/sounds/doorbell.wav"); f_doorbell.open(QIODevice::ReadOnly); } #ifndef DOORBELL_WAV QByteArray riff = f_doorbell.read(12); if (riff.length() < 12) { doorbell_ok = false; } else { if (!riff.startsWith("RIFF") || !riff.endsWith("WAVE")) { doorbell_ok = false; } } QByteArray fmthdr = f_doorbell.read(8); if (!fmthdr.startsWith("fmt")) { doorbell_ok = false; } uint32_t fmt_len; memcpy(&fmt_len,fmthdr.mid(4).data(),4); qDebug() << "fmt len" << fmt_len; if (fmt_len < 16) { doorbell_ok = false; } QByteArray fmt = f_doorbell.read(fmt_len); uint16_t audio_format; uint16_t num_channels; uint32_t sample_rate; uint32_t byte_rate; uint16_t block_align; uint16_t bits_per_sample; uint32_t bell_datalen; #if (BYTE_ORDER != __LITTLE_ENDIAN) #error Adapt endianness in __FILE__ #endif if (fmt.length() < fmt_len) { doorbell_ok = false; } else { memcpy(&audio_format,fmt.mid(0).data(),2); memcpy(&num_channels,fmt.mid(2).data(),2); memcpy(&sample_rate,fmt.mid(4).data(),4); memcpy(&byte_rate,fmt.mid(8).data(),4); memcpy(&block_align,fmt.mid(12).data(),2); memcpy(&bits_per_sample,fmt.mid(14).data(),2); } qDebug() << audio_format << "nch" << num_channels << "samplerate" << sample_rate << "byztera" << byte_rate << "blocka" << block_align << "bps" << bits_per_sample; if (audio_format != 0x0001) { doorbell_ok = false; } if (doorbell_ok) { QByteArray datahdr = f_doorbell.read(8); if (!datahdr.startsWith("data") || (datahdr.length() < 8)) { doorbell_ok = false; } else { memcpy(&bell_datalen,datahdr.mid(4).data(),4); } if (doorbell_ok && (bell_datalen > 0)) { QByteArray data = f_doorbell.read(bell_datalen); bell_wav = (char*)malloc(bell_datalen); if (bell_wav != 0) { memcpy(bell_wav,data.data(),bell_datalen); } } } #endif active_call = -1; QObject::connect(this,SIGNAL(incomingCall(int)),this,SLOT(onIncomingCall(int)),Qt::QueuedConnection); QObject::connect(this,SIGNAL(callState(int,QString)),this,SLOT(onCallState(int,QString)),Qt::QueuedConnection); QObject::connect(this,SIGNAL(callMediaState(int)),this,SLOT(onCallMediaState(int)),Qt::QueuedConnection); w_accept = new QVSvgWidget(":/icons/phone_call.svg",popup->content()); w_hangup = new QVSvgWidget(":/icons/phone_call_end.svg",popup->content()); w_dooropen = new QVSvgWidget(":/icons/door_open.svg",popup->content()); QObject::connect(w_accept,SIGNAL(clicked(double,double)),this,SLOT(onAcceptPressed())); QObject::connect(w_hangup,SIGNAL(clicked(double,double)),this,SLOT(onHangupPressed())); QObject::connect(w_dooropen,SIGNAL(clicked(double,double)),this,SLOT(onDoorOpenPressed())); hangup_timer.setSingleShot(true); hangup_timer.setInterval(800); QObject::connect(&hangup_timer,SIGNAL(timeout()),this,SLOT(onHangupTimer())); dtmf_timer.setSingleShot(true); dtmf_timer.setInterval(200); QObject::connect(&dtmf_timer,SIGNAL(timeout()),this,SLOT(onDTMFTimer())); /******* Init PJSUA ********/ pjsua_acc_id acc_id; pj_status_t status; /* Create pjsua first! */ status = pjsua_create(); if (status != PJ_SUCCESS) { qDebug() << "Cannot create PJSUA SIP client, cause:" << status; return; } /* Init pjsua */ pjsua_config cfg; pjsua_logging_config log_cfg; pjsua_media_config media_cfg; pjsua_config_default(&cfg); cfg.cb.on_incoming_call = &on_incoming_call; cfg.cb.on_call_media_state = &on_call_media_state; cfg.cb.on_call_state = &on_call_state; pjsua_logging_config_default(&log_cfg); log_cfg.console_level = 1; pjsua_media_config_default(&media_cfg); media_cfg.clock_rate = 8000; media_cfg.ec_tail_len = 0; status = pjsua_init(&cfg, &log_cfg, &media_cfg); if (status != PJ_SUCCESS) { qDebug() << "Cannot init PJSUA SIP client, cause: " << status; return; } /* Add UDP transport. */ pjsua_transport_config transport_cfg; pjsua_transport_config_default(&transport_cfg); transport_cfg.port = 5060; status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &transport_cfg, NULL); if (status != PJ_SUCCESS) { qDebug() << "Cannot init PJSUA UDP transport, cause: " << status; return; } /* Initialization is done, now start pjsua */ status = pjsua_start(); if (status != PJ_SUCCESS) { qDebug() << "Cannot start PJSUA SIP client, cause: " << status; return; } /* Register to SIP server by creating SIP account. */ pjsua_acc_config acc_cfg; pjsua_acc_config_default(&acc_cfg); QString s_id = "sip:" + s_user + "@" + s_server; QString s_uri = "sip:" + s_server; acc_cfg.cred_count = 1; acc_cfg.cred_info[0].realm = pj_str(strdup(s_server.toLocal8Bit().data())); acc_cfg.cred_info[0].scheme = pj_str("digest"); acc_cfg.cred_info[0].username = pj_str(strdup(s_user.toLocal8Bit().data())); acc_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD; acc_cfg.cred_info[0].data = pj_str(strdup(s_password.toLocal8Bit().data())); acc_cfg.id = pj_str(strdup(s_id.toLocal8Bit().data())); acc_cfg.reg_uri = pj_str(strdup(s_uri.toLocal8Bit().data())); status = pjsua_acc_add(&acc_cfg, PJ_TRUE, &acc_id); if (status != PJ_SUCCESS) { qDebug() << "PJSUA auth data invalid, cause: " << status; return; } qDebug() << "PJSUA ports" << pjsua_conf_get_active_ports(); pjsua_conf_port_info info; pjsua_conf_get_port_info (0, &info); qDebug() << pj2qstring(info.name); // pjsua_conf_adjust_tx_level(0,0.0); pj_caching_pool_init(&pj_cpool, &pj_pool_factory_default_policy, 0); pj_pool = pjsua_pool_create("qvisu", 8192, 8192); #ifndef DOORBELL_WAV if (doorbell_ok && (bell_wav != 0)) { status = pjmedia_mem_player_create(pj_pool, bell_wav, bell_datalen, sample_rate, num_channels, 16384, bits_per_sample, 0,//PJMEDIA_MEM_NO_LOOP, &bell_file_port); qDebug() << "Bell memory player" << status; status = pjsua_conf_add_port(pj_pool,bell_file_port,&bell_port_id); qDebug() << "bell file add status" << status << "id" << bell_port_id; status = pjmedia_mem_player_set_eof_cb (bell_file_port, 0, &on_file_played); } else { bell_file_port = 0; } #else qDebug() << "Doorbell file" << s_doorbell_name; if (s_doorbell_name.isEmpty()) { bell_file_port = 0; } else { /* Create file media port for doorbell from the WAV file */ status = pjmedia_wav_player_port_create(pj_pool, /* memory pool */ strdup(s_doorbell_name.toUtf8().data()), /* file to play */ 20, /* ptime. */ PJMEDIA_FILE_NO_LOOP, /* flags */ 0, /* default buffer */ &bell_file_port/* returned port */ ); if (status != PJ_SUCCESS) { qDebug() << "Cannot open wav file" << status; bell_file_port = 0; } } if (bell_file_port != 0) { status = pjsua_conf_add_port(pj_pool,bell_file_port,&bell_port_id); qDebug() << "bell file add status" << status << "id" << bell_port_id; status = pjmedia_wav_player_set_eof_cb (bell_file_port, 0, &on_file_played); if (status != PJ_SUCCESS) { qDebug() << "Cannot register callback"; bell_file_port = 0; } } #endif }
int main(int argc, char* argv[]) { shrQAStart(argc, argv); try { std::string sFilename; char *filePath = findFilePath("Lena.pgm", argv[0]); if (filePath) { sFilename = filePath; } else { printf("Error unable to find Lena.pgm\n"); shrQAFinishExit(argc, (const char **)argv, QA_FAILED); } // Parse the command line arguments for proper configuration parseCommandLineArguments(argc, argv); printfNPPinfo(argc, argv); if (g_bQATest == false && (g_nDevice == -1) && argc > 1) { sFilename = argv[1]; } // if we specify the filename at the command line, then we only test sFilename. int file_errors = 0; std::ifstream infile(sFilename.data(), std::ifstream::in); if (infile.good()) { std::cout << "histEqualizationNPP opened: <" << sFilename.data() << "> successfully!" << std::endl; file_errors = 0; infile.close(); } else { std::cout << "histEqualizationNPP unable to open: <" << sFilename.data() << ">" << std::endl; file_errors++; infile.close(); } if (file_errors > 0) { shrQAFinishExit(argc, (const char **)argv, QA_FAILED); } std::string dstFileName = sFilename; std::string::size_type dot = dstFileName.rfind('.'); if (dot != std::string::npos) dstFileName = dstFileName.substr(0, dot); dstFileName += "_histEqualization.pgm"; if (argc >= 3 && !g_bQATest) dstFileName = argv[2]; npp::ImageCPU_8u_C1 oHostSrc; npp::loadImage(sFilename, oHostSrc); npp::ImageNPP_8u_C1 oDeviceSrc(oHostSrc); // // allocate arrays for histogram and levels // const int binCount = 256; const int levelCount = binCount + 1; // levels array has one more element Npp32s * histDevice = 0; Npp32s * levelsDevice = 0; NPP_CHECK_CUDA(cudaMalloc((void **)&histDevice, binCount * sizeof(Npp32s))); NPP_CHECK_CUDA(cudaMalloc((void **)&levelsDevice, levelCount * sizeof(Npp32s))); // // compute histogram // NppiSize oSizeROI = {oDeviceSrc.width(), oDeviceSrc.height()}; // full image // create device scratch buffer for nppiHistogram int nDeviceBufferSize; nppiHistogramEvenGetBufferSize_8u_C1R(oSizeROI, levelCount ,&nDeviceBufferSize); Npp8u * pDeviceBuffer; NPP_CHECK_CUDA(cudaMalloc((void **)&pDeviceBuffer, nDeviceBufferSize)); // compute levels values on host Npp32s levelsHost[levelCount]; NPP_CHECK_NPP(nppiEvenLevelsHost_32s(levelsHost, levelCount, 0, binCount)); // compute the histogram NPP_CHECK_NPP(nppiHistogramEven_8u_C1R(oDeviceSrc.data(), oDeviceSrc.pitch(), oSizeROI, histDevice, levelCount, 0, binCount, pDeviceBuffer)); // copy histogram and levels to host memory Npp32s histHost[binCount]; NPP_CHECK_CUDA(cudaMemcpy(histHost, histDevice, binCount * sizeof(Npp32s), cudaMemcpyDeviceToHost)); Npp32s lutHost[binCount + 1]; // fill LUT { Npp32s * pHostHistogram = histHost; Npp32s totalSum = 0; for (; pHostHistogram < histHost + binCount; ++pHostHistogram) totalSum += *pHostHistogram; NPP_ASSERT(totalSum == oSizeROI.width * oSizeROI.height); if (totalSum == 0) totalSum = 1; float multiplier = 1.0f / float(totalSum) * 0xFF; Npp32s runningSum = 0; Npp32s * pLookupTable = lutHost; for (pHostHistogram = histHost; pHostHistogram < histHost + binCount; ++pHostHistogram) { *pLookupTable = (Npp32s)(runningSum * multiplier + 0.5f); pLookupTable++; runningSum += *pHostHistogram; } lutHost[binCount] = 0xFF; // last element is always 1 } // // apply LUT transformation to the image // // Create a device image for the result. npp::ImageNPP_8u_C1 oDeviceDst(oDeviceSrc.size()); NPP_CHECK_NPP(nppiLUT_Linear_8u_C1R(oDeviceSrc.data(), oDeviceSrc.pitch(), oDeviceDst.data(), oDeviceDst.pitch(), oSizeROI, lutHost, // value and level arrays are in host memory levelsHost, binCount+1)); // copy the result image back into the storage that contained the // input image npp::ImageCPU_8u_C1 oHostDst(oDeviceDst.size()); oDeviceDst.copyTo(oHostDst.data(), oHostDst.pitch()); // save the result npp::saveImage(dstFileName.c_str(), oHostDst); std::cout << "Saved image file " << dstFileName << std::endl; shrQAFinishExit(argc, (const char **)argv, QA_PASSED); } catch (npp::Exception & rException) { std::cerr << "Program error! The following exception occurred: \n"; std::cerr << rException << std::endl; std::cerr << "Aborting." << std::endl; shrQAFinishExit(argc, (const char **)argv, QA_FAILED); } catch (...) { std::cerr << "Program error! An unknow type of exception occurred. \n"; std::cerr << "Aborting." << std::endl; shrQAFinishExit(argc, (const char **)argv, QA_FAILED); } return 0; }