void KisCsConversionTest::testColorSpaceConversion() { QTime t; t.start(); QList<const KoColorSpace*> colorSpaces = TestUtil::allColorSpaces(); int failedColorSpaces = 0; QImage image(QString(FILES_DATA_DIR) + QDir::separator() + "tile.png"); foreach(const KoColorSpace * srcCs, colorSpaces) { foreach(const KoColorSpace * dstCs, colorSpaces) { KisPaintDeviceSP dev = new KisPaintDevice(srcCs); dev->convertFromQImage(image, 0); dev->move(10, 10); // Unalign with tile boundaries dev->convertTo(dstCs); if (dev->exactBounds() != QRect(10, 10, image.width(), image.height())) { logFailure("bounds", srcCs, dstCs); failedColorSpaces++; } if (dev->pixelSize() != dstCs->pixelSize()) { logFailure("pixelsize", srcCs, dstCs); failedColorSpaces++; } if (!(*dev->colorSpace() == *dstCs)) { logFailure("dest cs", srcCs, dstCs); failedColorSpaces++; } }
/** Adds an asynchronous request to the event log. */ void asynclog_delete(proxy_t* proxy, const ProxyClientCommon& pclient, folly::StringPiece key, folly::StringPiece poolName) { dynamic json = {}; const auto& host = pclient.ap->getHost(); const auto& port = pclient.ap->getPort(); if (proxy->opts.use_asynclog_version2) { json = dynamic::object; json["f"] = proxy->opts.flavor_name; json["h"] = folly::sformat("[{}]:{}", host, port); json["p"] = poolName.str(); json["k"] = key.str(); } else { /* ["host", port, escaped_command] */ json.push_back(host); json.push_back(port); json.push_back(folly::sformat("delete {}\r\n", key)); } auto fd = asynclog_open(proxy); if (!fd) { logFailure(proxy->router, memcache::failure::Category::kSystemError, "asynclog_open() failed (key {}, pool {})", key, poolName); return; } // ["AS1.0", 1289416829.836, "C", ["10.0.0.1", 11302, "delete foo\r\n"]] // OR ["AS2.0", 1289416829.836, "C", {"f":"flavor","h":"[10.0.0.1]:11302", // "p":"pool_name","k":"foo\r\n"}] dynamic jsonOut = {}; if (proxy->opts.use_asynclog_version2) { jsonOut.push_back(ASYNCLOG_MAGIC2); } else { jsonOut.push_back(ASYNCLOG_MAGIC); } struct timeval timestamp; CHECK(gettimeofday(×tamp, nullptr) == 0); auto timestamp_ms = facebook::memcache::to<std::chrono::milliseconds>(timestamp).count(); jsonOut.push_back(1e-3 * timestamp_ms); jsonOut.push_back(std::string("C")); jsonOut.push_back(json); auto jstr = folly::toJson(jsonOut) + "\n"; ssize_t size = folly::writeFull(fd->fd(), jstr.data(), jstr.size()); if (size == -1 || size_t(size) < jstr.size()) { logFailure(proxy->router, memcache::failure::Category::kSystemError, "Error fully writing asynclog request (key {}, pool {})", key, poolName); } }
void ConfigApi::configThreadRun() { mcrouterSetThreadName(pthread_self(), opts_, "mcrcfg"); if (opts_.constantly_reload_configs) { while (!finish_) { LOG(INFO) << "Reload config due to constantly_reload_configs"; callbacks_.notify(); { std::unique_lock<std::mutex> lk(finishMutex_); finishCV_.wait_for(lk, std::chrono::milliseconds(10), [this] { return finish_.load(); }); } } return; } while (!finish_) { bool hasUpdate = false; try { hasUpdate = checkFileUpdate(); } catch (const std::exception& e) { logFailure(memcache::failure::Category::kOther, "Check for config update failed: {}", e.what()); } catch (...) { logFailure(memcache::failure::Category::kOther, "Check for config update failed with unknown error"); } // There are a couple of races that can happen here // First, the IN_MODIFY event can be fired before the write is complete, // resulting in a malformed JSON error. Second, text editors may do // some of their own shuffling of the file (e.g. between .swp and the // real thing in Vim) after the write. This may can result in a file // access error router_configure_from_file below. That's just a theory, // but that error does happen. Race 1 can be fixed by changing the // watch for IN_MODIFY to IN_CLOSE_WRITE, but Race 2 has no apparent // elegant solution. The following jankiness fixes both. { std::unique_lock<std::mutex> lk(finishMutex_); finishCV_.wait_for( lk, std::chrono::milliseconds(opts_.reconfiguration_delay_ms), [this] { return finish_.load(); }); } if (hasUpdate) { callbacks_.notify(); } // Otherwise there was nothing to read, so check that we aren't shutting // down, and wait on the FD again. } }
const String open (const BitArray& inputChannels, const BitArray& outputChannels, double sampleRate, int bufferSizeSamples) { close(); lastError = String::empty; if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0) { lastError = "The input and output devices don't share a common sample rate!"; return lastError; } currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize); currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate; if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels)) { lastError = "Couldn't open the input device!"; return lastError; } if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels)) { close(); lastError = "Couldn't open the output device!"; return lastError; } if (inputDevice != 0) ResetEvent (inputDevice->clientEvent); if (outputDevice != 0) ResetEvent (outputDevice->clientEvent); startThread (8); Thread::sleep (5); if (inputDevice != 0 && inputDevice->client != 0) { latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize; HRESULT hr = inputDevice->client->Start(); logFailure (hr); //xxx handle this } if (outputDevice != 0 && outputDevice->client != 0) { latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize; HRESULT hr = outputDevice->client->Start(); logFailure (hr); //xxx handle this } isOpen_ = true; return lastError; }
void spawnManagedChild() { installSignalHandlers(); // Loops forever to make sure the parent process never leaves. while (true) { switch (childPid = fork()) { case -1: // error logFailure(failure::Category::kSystemError, "Can't spawn child process, sleeping"); std::this_thread::sleep_for(std::chrono::seconds(SpawnWait)); break; case 0: // child process. cleanup and continue with the startup logic. uninstallSignalHandlers(); return; default: // parent process. LOG(INFO) << "Spawned child process " << childPid; int rv; do { rv = wait(nullptr); } while (rv == -1 && errno != ECHILD && running); if (running) { // Child died accidentally. Cleanup and restart. LOG(INFO) << "Child process " << childPid << " exited"; waitpid(childPid, nullptr, 0); } else { // Child was killed. Shutdown parent. if (!waitpidTimeout(childPid, TermSignalTimeout)) { logFailure(failure::Category::kSystemError, "Child process did not exit in {} microseconds. Sending SIGKILL.", TermSignalTimeout); kill(childPid, SIGKILL); } exit(0); } break; } } }
const ComSmartPtr <IAudioClient> createClient() { ComSmartPtr <IAudioClient> client; if (device != 0) { HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client); logFailure (hr); } return client; }
bool AsyncWriter::start(folly::StringPiece threadName) { std::lock_guard<SFRWriteLock> lock(runLock_.writeLock()); if (thread_.joinable() || stopped_) { return false; } try { thread_ = std::thread([this]() { // will return after terminateLoopSoon is called eventBase_.loopForever(); while (fiberManager_.hasTasks()) { fiberManager_.loopUntilNoReady(); } }); folly::setThreadName(thread_.native_handle(), threadName); } catch (const std::system_error& e) { logFailure(memcache::failure::Category::kSystemError, "Can not start AsyncWriter thread {}: {}", threadName, e.what()); return false; } return true; }
bool check (HRESULT hr) { logFailure (hr); return SUCCEEDED (hr); }
static bool wasapi_checkResult (HRESULT hr) { logFailure (hr); return SUCCEEDED (hr); }
bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry) { WAVEFORMATEXTENSIBLE format; zerostruct (format); if (numChannels <= 2 && bytesPerSampleToTry <= 2) { format.Format.wFormatTag = WAVE_FORMAT_PCM; } else { format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX); } format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate); format.Format.nChannels = (WORD) numChannels; format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry); format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry); format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry); format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM; format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample; switch (numChannels) { case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break; case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break; case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break; case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break; case 8: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_FRONT_LEFT_OF_CENTER | SPEAKER_FRONT_RIGHT_OF_CENTER; break; default: break; } WAVEFORMATEXTENSIBLE* nearestFormat = 0; HRESULT hr = client->IsFormatSupported (AUDCLNT_SHAREMODE_SHARED, (WAVEFORMATEX*) &format, (WAVEFORMATEX**) &nearestFormat); logFailure (hr); if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec) { wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat); hr = S_OK; } CoTaskMemFree (nearestFormat); GUID session; if (hr == S_OK && OK (client->Initialize (AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 0, 0, (WAVEFORMATEX*) &format, &session))) { actualNumChannels = format.Format.nChannels; const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; bytesPerSample = format.Format.wBitsPerSample / 8; dataFormat = isFloat ? AudioDataConverters::float32LE : (bytesPerSample == 4 ? AudioDataConverters::int32LE : ((bytesPerSample == 3 ? AudioDataConverters::int24LE : AudioDataConverters::int16LE))); return true; } return false; }