int main() { // GPIO-PIN mraa::Gpio* gpio = mraa::initIo<mraa::Gpio>("gpio-1"); // GPIO-RAW-RAWPIN mmraa::Gpio* gpioraw = mraa::initIo<mraa::Gpio> initIo("gpio-raw-131"); // AIO-PIN mraa::Aio aio = mraa::initIo<mraa::Aio>("aio-0"); // PWM-PIN mraa::Pwm pwm = mraa::initIo<mraa::Pwm>("pwm-6"); // PWM-RAW-CHIPID-PIN mraa::Pwm pwmraw = mraa::initIo<mraa::Pwm>("pwm-raw-0,1"); // UART-INDEX: the index is the one represented internally in the uart_dev array mraa::Uart uart = mraa::initIo<mraa::Uart>("uart-1"); // UART-RAW-PATH mraa::Uart uartraw = mraa::initIo<mraa::Uart>("uart-raw-/dev/ttyS0"); // SPI-INDEX: same as UART mraa::Spi spi = mraa::initIo<mraa::Spi>("spi-0"); // SPI-RAW-BUS-CS: USED to open and use /dev/spidev<BUS>.<CS> mraa::Spi spiraw = mraa::initIo<mraa::Spi>("spi-raw-0-1"); // I2C-INDEX: same as UART mraa::I2c i2c = mraa::initIo<mraa::I2c>("i2c-0"); // I2C-RAW-BUS mraa::I2c i2craw = mraa::initIo<mraa::I2c>("i2c-raw-0"); // FREE STUFF delete gpio; delete gpioraw; delete aio; delete pwm; delete pwmraw; delete uart; delete uartraw; delete spi; delete spiraw; delete i2c; delete i2craw; }
int main(int argc, char **argv) { FdEventHandlerPtr listener; int i; int rc; int expire = 0, printConfig = 0; initAtoms(); CONFIG_VARIABLE(daemonise, CONFIG_BOOLEAN, "Run as a daemon"); CONFIG_VARIABLE(pidFile, CONFIG_ATOM, "File with pid of running daemon."); preinitChunks(); preinitLog(); preinitObject(); preinitIo(); preinitDns(); preinitServer(); preinitHttp(); preinitDiskcache(); preinitLocal(); preinitForbidden(); preinitSocks(); preinitOffline(); i = 1; while(i < argc) { if(argv[i][0] != '-') break; if(strcmp(argv[i], "--") == 0) { i++; break; } else if(strcmp(argv[i], "-h") == 0) { usage(argv[0]); exit(0); } else if(strcmp(argv[i], "-v") == 0) { printConfig = 1; i++; } else if(strcmp(argv[i], "-x") == 0) { expire = 1; i++; } else if(strcmp(argv[i], "-c") == 0) { i++; if(i >= argc) { usage(argv[0]); exit(1); } if(configFile) releaseAtom(configFile); configFile = internAtom(argv[i]); i++; } else { usage(argv[0]); exit(1); } } if(configFile) configFile = expandTilde(configFile); if(configFile == NULL) { configFile = expandTilde(internAtom("~/.polipo")); if(configFile) if(access(configFile->string, F_OK) < 0) { releaseAtom(configFile); configFile = NULL; } } if(configFile == NULL) { if(access("/etc/polipo/config", F_OK) >= 0) configFile = internAtom("/etc/polipo/config"); if(configFile && access(configFile->string, F_OK) < 0) { releaseAtom(configFile); configFile = NULL; } } rc = parseConfigFile(configFile); if(rc < 0) exit(1); while(i < argc) { rc = parseConfigLine(argv[i], "command line", 0, 0); if(rc < 0) exit(1); i++; } initChunks(); initLog(); initObject(); if(!expire && !printConfig) initEvents(); initIo(); initDns(); initHttp(); initServer(); initDiskcache(); initForbidden(); initSocks(); initOffline(); if(printConfig) { printConfigVariables(stdout, 0); exit(0); } if(expire) { expireDiskObjects(); exit(0); } if(daemonise) do_daemonise(logFile == NULL || logFile->length == 0); if(pidFile) writePid(pidFile->string); listener = create_listener(proxyAddress->string, proxyPort, httpAccept, NULL); if(!listener) { if(pidFile) unlink(pidFile->string); exit(1); } eventLoop(); if(pidFile) unlink(pidFile->string); return 0; }
int psiphonMain( int bindAll, int proxyPortParam, int localParentProxyPortParam) { FdEventHandlerPtr listener; initAtoms(); CONFIG_VARIABLE(daemonise, CONFIG_BOOLEAN, "Run as a daemon"); CONFIG_VARIABLE(pidFile, CONFIG_ATOM, "File with pid of running daemon."); preinitChunks(); preinitLog(); preinitObject(); preinitIo(); preinitDns(); preinitServer(); preinitHttp(); preinitDiskcache(); preinitLocal(); preinitForbidden(); preinitSocks(); const int MAX_SIZE = 80; char proxyAddressParamLine[MAX_SIZE]; char proxyPortParamLine[MAX_SIZE]; char localParentProxyPortParamLine[MAX_SIZE]; snprintf( proxyAddressParamLine, MAX_SIZE, (0 == bindAll) ? "proxyAddress=127.0.0.1" : "proxyAddress=0.0.0.0"); snprintf( proxyPortParamLine, MAX_SIZE, "proxyPort=%d", proxyPortParam); snprintf( localParentProxyPortParamLine, MAX_SIZE, "socksParentProxy=127.0.0.1:%d", localParentProxyPortParam); if (0 > parseConfigLine(proxyAddressParamLine, "psiphon", 0, 0) || 0 > parseConfigLine(proxyPortParamLine, "psiphon", 0, 0) || 0 > parseConfigLine(localParentProxyPortParamLine, "psiphon", 0, 0) || 0 > parseConfigLine("disableLocalInterface=true", "psiphon", 0, 0) || 0 > parseConfigLine("logLevel=1", "psiphon", 0, 0) /* Allow HTTPS on all ports */ || 0 > parseConfigLine("tunnelAllowedPorts=1-65535", "psiphon", 0, 0)) { return -1; } initChunks(); initLog(); initObject(); initEvents(); initIo(); initDns(); initHttp(); initServer(); initDiskcache(); initForbidden(); initSocks(); listener = create_listener( proxyAddress->string, proxyPort, httpAccept, NULL); if (!listener) { return -1; } eventLoop(); return 0; }
Omm::AvStream::Meta* FFmpegTagger::tag(std::istream& istr) { FFmpegMeta* pMeta = new FFmpegMeta; int error; pMeta->_pInputFormat = probeInputFormat(istr); pMeta->_pIoBuffer = new unsigned char[_IoBufferSize]; pMeta->_pIoContext = initIo(istr, false, pMeta->_pIoBuffer); // pMeta->_pIoContext = initIo(istr, true, pMeta->_pIoBuffer); pMeta->_useAvOpenInputStream = true; AVFormatParameters avFormatParameters; memset(&avFormatParameters, 0, sizeof(avFormatParameters)); avFormatParameters.prealloced_context = 1; pMeta->_pFormatContext->probesize = 20000; pMeta->_pFormatContext->max_analyze_duration = 5000000; // pMeta->_pFormatContext->flags |= AVFMT_FLAG_NONBLOCK; LOG(ffmpeg, trace, "ffmpeg::av_open_input_stream() ..."); // FIXME: av_open_input_stream needs to read several megabytes of a TS. error = av_open_input_stream(&pMeta->_pFormatContext, pMeta->_pIoContext, "std::istream", pMeta->_pInputFormat, &avFormatParameters); // error = av_open_input_stream(&pMeta->_pFormatContext, pMeta->_pIoContext, "std::istream", pMeta->_pInputFormat, 0); // error = av_open_input_file(&pMeta->_pFormatContext, "std::istream", pMeta->_pInputFormat, 0, 0); if (error < 0) { LOGNS(Omm::AvStream, avstream, error, "av_open_input_stream() failed"); return 0; } LOG(ffmpeg, trace, "probesize: " + Poco::NumberFormatter::format(pMeta->_pFormatContext->probesize) +\ ", max_analyze_duration: " + Poco::NumberFormatter::format(pMeta->_pFormatContext->max_analyze_duration)); AVMetadataTag* tag = 0; LOG(ffmpeg, trace, "ffmpeg::av_metadata_get() ..."); while ((tag = av_metadata_get(pMeta->_pFormatContext->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) { std::clog << tag->key << ", " << tag->value << std::endl; pMeta->setTag(tag->key, tag->value); } LOG(ffmpeg, trace, "ffmpeg::av_find_stream_info() ..."); error = av_find_stream_info(pMeta->_pFormatContext); if (error < 0) { LOGNS(Omm::AvStream, avstream, error, "av_find_stream_info() failed, could not find codec parameters"); return 0; } // pMeta->_pFormatContext->flags |= AVFMT_FLAG_NONBLOCK; // if (pMeta->_pFormatContext->flags & AVFMT_FLAG_NONBLOCK) { // std::clog << "frame reading is set to NONBLOCK" << std::endl; // } // else { // std::clog << "frame reading is set to BLOCK" << std::endl; // } for(int streamNr = 0; streamNr < pMeta->_pFormatContext->nb_streams; streamNr++) { FFmpegStreamInfo* pStreamInfo = new FFmpegStreamInfo; pStreamInfo->_pAvStream = pMeta->_pFormatContext->streams[streamNr]; pMeta->addStream(pStreamInfo); } return pMeta; }