PRBool nsMediaDecoder::CanPlayThrough() { Statistics stats = GetStatistics(); if (!stats.mDownloadRateReliable || !stats.mPlaybackRateReliable) { return PR_FALSE; } PRInt64 bytesToDownload = stats.mTotalBytes - stats.mDownloadPosition; PRInt64 bytesToPlayback = stats.mTotalBytes - stats.mPlaybackPosition; double timeToDownload = bytesToDownload / stats.mDownloadRate; double timeToPlay = bytesToPlayback / stats.mPlaybackRate; if (timeToDownload > timeToPlay) { // Estimated time to download is greater than the estimated time to play. // We probably can't play through without having to stop to buffer. return PR_FALSE; } // Estimated time to download is less than the estimated time to play. // We can probably play through without having to buffer, but ensure that // we've got a reasonable amount of data buffered after the current // playback position, so that if the bitrate of the media fluctuates, or if // our download rate or decode rate estimation is otherwise inaccurate, // we don't suddenly discover that we need to buffer. This is particularly // required near the start of the media, when not much data is downloaded. PRInt64 readAheadMargin = stats.mPlaybackRate * CAN_PLAY_THROUGH_MARGIN; return stats.mTotalBytes == stats.mDownloadPosition || stats.mDownloadPosition > stats.mPlaybackPosition + readAheadMargin; }
bool ChannelMediaDecoder::ShouldThrottleDownload() { // We throttle the download if either the throttle override pref is set // (so that we can always throttle in Firefox on mobile) or if the download // is fast enough that there's no concern about playback being interrupted. MOZ_ASSERT(NS_IsMainThread()); NS_ENSURE_TRUE(GetStateMachine(), false); int64_t length = mResource->GetLength(); if (length > 0 && length <= int64_t(MediaPrefs::MediaMemoryCacheMaxSize()) * 1024) { // Don't throttle the download of small resources. This is to speed // up seeking, as seeks into unbuffered ranges would require starting // up a new HTTP transaction, which adds latency. return false; } if (Preferences::GetBool("media.throttle-regardless-of-download-rate", false)) { return true; } MediaStatistics stats = GetStatistics(); if (!stats.mDownloadRateReliable || !stats.mPlaybackRateReliable) { return false; } uint32_t factor = std::max(2u, Preferences::GetUint("media.throttle-factor", 2)); return stats.mDownloadRate > factor * stats.mPlaybackRate; }
bool ChannelMediaDecoder::CanPlayThroughImpl() { MOZ_ASSERT(NS_IsMainThread()); NS_ENSURE_TRUE(GetStateMachine(), false); return GetStatistics().CanPlayThrough(); }
// Save the grid to file returning true if an error occurred bool HeightMap::SaveToFile(FileStore *f) const { char bufferSpace[500]; StringRef buf(bufferSpace, ARRAY_SIZE(bufferSpace)); // Write the header comment buf.copy(HeightMapComment); if (reprap.GetPlatform()->IsDateTimeSet()) { time_t timeNow = reprap.GetPlatform()->GetDateTime(); const struct tm * const timeInfo = gmtime(&timeNow); buf.catf(" generated at %04u-%02u-%02u %02u:%02u", timeInfo->tm_year + 1900, timeInfo->tm_mon, timeInfo->tm_mday, timeInfo->tm_hour, timeInfo->tm_min); } float mean, deviation; (void)GetStatistics(mean, deviation); buf.catf(", mean error %.2f, deviation %.2f\n", mean, deviation); if (!f->Write(buf.Pointer())) { return true; } // Write the grid parameters def.WriteHeadingAndParameters(buf); if (!f->Write(buf.Pointer())) { return true; } // Write the grid heights. We use a fixed field with of 6 characters to make is easier to view. uint32_t index = 0; for (uint32_t i = 0; i < def.numY; ++i) { buf.Clear(); for (uint32_t j = 0; j < def.numX; ++j) { if (j != 0) { buf.cat(','); } if (IsHeightSet(index)) { buf.catf("%7.3f%", gridHeights[index]); } else { buf.cat(" 0"); // write 0 with no decimal point where we didn't probe, so we can tell when we reload it } ++index; } buf.cat('\n'); if (!f->Write(buf.Pointer())) { return true; } } return false; }
/* * Function: wimaxcu_get_stats * Description: Get statistics data * Return: 0 for success or 1 for failure */ int wimaxcu_get_stats(WIMAX_API_DEVICE_ID_P p_device_id) { WIMAX_API_RET wmxStatus; WIMAX_API_CONNECTION_STAT Statistics; WIMAX_API_DEVICE_STATUS DeviceStatus; WIMAX_API_CONNECTION_PROGRESS_INFO ConnectionProgressInfo; wmxStatus = GetDeviceStatus(p_device_id, &DeviceStatus, &ConnectionProgressInfo); if (WIMAX_API_RET_SUCCESS != wmxStatus) { PrintWmxStatus(wmxStatus); return 1; } if (DeviceStatus != WIMAX_API_DEVICE_STATUS_Data_Connected) { // Dispaly a proper message and exit switch (DeviceStatus) { case WIMAX_API_DEVICE_STATUS_UnInitialized: printf("ERROR: Device not Initialized\n"); break; case WIMAX_API_DEVICE_STATUS_RF_OFF_HW_SW: printf("WARNING: HW and SW Radio is turned OFF\n"); break; case WIMAX_API_DEVICE_STATUS_RF_OFF_HW: printf("WARNING: HW Radio is turned OFF\n"); break; case WIMAX_API_DEVICE_STATUS_RF_OFF_SW: printf("WARNING: SW Radio is turned OFF\n"); break; case WIMAX_API_DEVICE_STATUS_Ready: case WIMAX_API_DEVICE_STATUS_Scanning: case WIMAX_API_DEVICE_STATUS_Connecting: printf("WARNING: Network is not Connected\n"); break; default: printf("ERROR: Unknown Device Status\n"); } return 1; } wmxStatus = GetStatistics(p_device_id, &Statistics); if (WIMAX_API_RET_SUCCESS != wmxStatus) { PrintWmxStatus(wmxStatus); return 1; } printf("Statistics:\n"); printf("\tTotal RX Bytes : %lld bytes\n", Statistics.totalRxByte); printf("\tTotal TX Bytes : %lld bytes\n", Statistics.totalTxByte); printf("\tTotal RX Packets : %lld\n", Statistics.totalRxPackets); printf("\tTotal TX Packets : %lld\n", Statistics.totalTxPackets); return 0; }
void TwoDimensionalPlotPage::plotPhase(QualityTablesFormatter::StatisticKind kind, unsigned polarization) { std::ostringstream s; s << "Polarization " << polarization; StartLine(_plot, s.str(), getYDesc()); StatisticsDerivator derivator(*_statCollection); const std::map<double, DefaultStatistics> &statistics = GetStatistics(); for(std::map<double, DefaultStatistics>::const_iterator i=statistics.begin();i!=statistics.end();++i) { const double x = i->first; const std::complex<long double> val = derivator.GetComplexStatistic(kind, i->second, polarization); _plot.PushDataPoint(x, getValue<Phase>(val)); } }
// Render controller scene void CViewerScene::RenderScene () { m_pRenderer->SetClearColor(OGVec4(0.3f, 0.3f, 0.4f, 1.0f)); m_pSg->RenderScene(m_pCamera); unsigned long Verts; unsigned long Faces; unsigned long TextureSwitches; unsigned long VBOSwitches; unsigned long DrawCalls; GetStatistics()->GetStatistics(Verts, Faces, TextureSwitches, VBOSwitches, DrawCalls); m_pRenderer->DisplayString(OGVec2(85.0f, 2.0f), 0.4f, 0x7FFFFFFF, "Vertices: %d", Verts); m_pRenderer->DisplayString(OGVec2(85.0f, 6.0f), 0.4f, 0x7FFFFFFF, "Faces: %d", Faces); m_pRenderer->DisplayString(OGVec2(85.0f,10.0f), 0.4f, 0x7FFFFFFF, "Textures: %d", TextureSwitches); m_pRenderer->DisplayString(OGVec2(85.0f,14.0f), 0.4f, 0x7FFFFFFF, "VBO: %d", VBOSwitches); m_pRenderer->DisplayString(OGVec2(85.0f,18.0f), 0.4f, 0x7FFFFFFF, "DP: %d", DrawCalls); GetStatistics()->Reset(); m_pRenderer->DrawScene(); RenderHelpers(); glFlush(); }
double SDERasterBand::GetMaximum(int *pbSuccess) { double dfMin, dfMax, dfMean, dfStdDev; CPLErr error = GetStatistics( TRUE, TRUE, &dfMin, &dfMax, &dfMean, &dfStdDev ); if (error == CE_None) { *pbSuccess = TRUE; return dfMax; } *pbSuccess = FALSE; return 0.0; }
bool CRSProcessor::ProcessCommand(void) { if( Operation == Operation_RegisterClient ) { return( RegisterClient()); } if( Operation == Operation_WriteData ) { return( WriteData()); } if( Operation == Operation_FlushServerData ) { return( FlushServerData()); } if( Operation == Operation_GetStatistics ) { return( GetStatistics()); } CSmallString error; error << "operation " << Operation.GetStringForm() << " is not implemented"; ES_ERROR(error); return(false); }
void ChannelMediaDecoder::DownloadProgressed() { MOZ_ASSERT(NS_IsMainThread()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); GetOwner()->DownloadProgressed(); using StatsPromise = MozPromise<MediaStatistics, bool, true>; InvokeAsync(GetStateMachine()->OwnerThread(), __func__, [ playbackStats = mPlaybackStatistics, res = RefPtr<BaseMediaResource>(mResource), duration = mDuration, pos = mPlaybackPosition ]() { auto rate = ComputePlaybackRate(playbackStats, res, duration); UpdatePlaybackRate(rate, res); MediaStatistics stats = GetStatistics(rate, res, pos); return StatsPromise::CreateAndResolve(stats, __func__); }) ->Then( mAbstractMainThread, __func__, [ =, self = RefPtr<ChannelMediaDecoder>(this) ](MediaStatistics aStats) { if (IsShutdown()) { return; } mCanPlayThrough = aStats.CanPlayThrough(); GetStateMachine()->DispatchCanPlayThrough(mCanPlayThrough); mResource->ThrottleReadahead(ShouldThrottleDownload(aStats)); // Update readyState since mCanPlayThrough might have changed. GetOwner()->UpdateReadyState(); }, []() { MOZ_ASSERT_UNREACHABLE("Promise not resolved"); }); }
VOID main( // IN ULONG argc, // IN PCHAR argv[], // IN PCHAR envp[] ) /*++ Routine Description: This is the main routine of the floppy test. Arguments: None Return Value: None. --*/ { CHAR Device[256]; while (1) { DbgPrint( "Test program for the floppy driver.\n\n\n" ); DbgPrint( " 0 - Exit\n\n" ); DbgPrint( " 1 - Read statistics\n\n" ); DbgPrint( " 2 - Tune FIFO delay\n\n" ); DbgPrint( " 3 - Get supported media types\n\n" ); DbgPrint( " 4 - Format some tracks\n\n" ); DbgPrint( " 5 - Test power failure recovery\n\n" ); DbgPrint( " 6 - Unload driver\n\n" ); DbgPrompt( "Select: ", Buffer, 256 ); if (Buffer[0] == '0') { break; } switch(Buffer[0]) { case '1': GetStatistics(); break; case '2': TuneFifoDelay(); break; case '3': GetMediaTypes( NULL ); break; case '4': Device[0] = '\0'; DbgPrompt( "Enter device id (1 = \\A:, 2 = \\B:): ", &(Device[0]), 256); if (Device[0] != '\0') { FormatSomeTracks( Device[0] ); } break; case '5': PowerTest(); break; case '6': UnloadDriver(); break; default: break; } } }
void Catalog::ExportToHTML(std::ostream& f) { const bool translated = HasCapability(Catalog::Cap::Translations); f << "<!DOCTYPE html>\n" "<html>\n" "<head>\n" " <title>" << str::to_utf8(m_header.Project) << "</title>\n" " <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>\n" " <style>\n" << CSS_STYLE << "\n" " </style>\n" "</head>\n" "<body>\n" "<div class='container'>\n"; // Metadata section: f << "<table class='metadata'>\n"; if (!m_header.Project.empty()) TableRow(f, _("Project:"), m_header.Project); if (translated && m_header.Lang.IsValid()) TableRow(f, _("Language:"), m_header.Lang.DisplayName()); f << "</table>\n"; // Statistics: if (translated) { int all = 0; int fuzzy = 0; int untranslated = 0; int unfinished = 0; GetStatistics(&all, &fuzzy, nullptr, &untranslated, &unfinished); int percent = (all == 0 ) ? 0 : (100 * (all - unfinished) / all); f << "<div class='stats'>\n" << " <div class='graph'>\n"; if (all > unfinished) f << " <div class='percent-done' style='width: " << 100.0 * (all - unfinished) / all << "%'> </div>\n"; if (fuzzy > 0) f << " <div class='percent-fuzzy' style='width: " << 100.0 * fuzzy / all << "%'> </div>\n"; if (untranslated > 0) f << " <div class='percent-untrans' style='width: " << 100.0 * untranslated / all << "%'> </div>\n"; f << " </div>\n" << " <div class='legend'>"; f << str::to_utf8(wxString::Format(_("Translated: %d of %d (%d %%)"), all - unfinished, all, percent)); if (unfinished > 0) f << str::to_utf8(L" • ") << str::to_utf8(wxString::Format(_("Remaining: %d"), unfinished)); f << " </div>\n" << "</div>\n"; } else { int all = (int)items().size(); f << "<div class='stats'>\n" << " <div class='graph'>\n" << " <div class='percent-untrans' style='width: 100%'> </div>\n" << " </div>\n" << " <div class='legend'>" << str::to_utf8(wxString::Format(wxPLURAL("%d entry", "%d entries", all), all)) << " </div>\n" << "</div>\n"; } // Translations: std::string lang_src, lang_tra; if (m_sourceLanguage.IsValid()) lang_src = " lang='" + m_sourceLanguage.RFC3066() + "'"; if (m_header.Lang.IsValid()) { lang_tra = " lang='" + m_header.Lang.RFC3066() + "'"; if (m_header.Lang.IsRTL()) lang_tra += " dir='rtl'"; } auto thead_src = m_sourceLanguage.IsValid() ? (wxString::Format(_(L"Source text — %s"), m_sourceLanguage.DisplayName())) : _("Source text"); auto thead_tra = wxString::Format(_(L"Translation — %s"), m_header.Lang.IsValid() ? m_header.Lang.DisplayName() : _("unknown language")); f << "<table class='translations'>\n" " <thead>\n" " <tr>\n" " <th>" << str::to_utf8(thead_src) << "</th>\n"; if (translated) { f << " <th>" << str::to_utf8(thead_tra) << "</th>\n"; } f << " </tr>\n" " </thead>\n" " <tbody>\n"; for (auto& item: items()) { bool hasComments = item->HasComment() || item->HasExtractedComments(); std::string klass("i"); if (!item->IsTranslated()) klass += " untrans"; if (item->IsFuzzy()) klass += " fuzzy"; if (hasComments) klass += " with-comments"; f << "<tr class='" << klass << "'>\n"; // Source string: f << "<td class='src' " << lang_src << ">\n"; if (item->HasPlural()) { f << "<ol class='plurals'>\n" << " <li>" << fmt_trans(item->GetString()) << "</li>\n" << " <li>" << fmt_trans(item->GetPluralString()) << "</li>\n" << "</ol>\n"; } else { f << fmt_trans(item->GetString()); } if (item->HasContext()) f << " <span class='msgctxt'>[" << fmt_trans(item->GetContext()) << "]</span>"; f << "</td>\n"; // Translation: if (translated) { f << "<td class='tra' " << lang_tra << ">\n"; if (item->HasPlural()) { if (item->IsTranslated()) { f << "<ol class='plurals'>\n"; for (auto t: item->GetTranslations()) f << " <li>" << fmt_trans(t) << "</li>\n"; f << "</ol>\n"; } } else { f << fmt_trans(item->GetTranslation()); } f << "</td>\n"; } // Notes, if present: if (hasComments) { f << "</tr>\n" << "<tr class='comments'>\n" << " <td colspan='" << (translated ? 2 : 1) << "'><div>"; if (item->HasExtractedComments()) { f << "<p>\n"; for (auto& n: item->GetExtractedComments()) f << fmt_trans(n) << "<br>\n"; f << "</p>\n"; } if (item->HasComment()) { f << "<p>\n" << fmt_trans(item->GetComment()) << "</p>\n"; } f << "</div></td>\n"; } f << "</tr>\n"; } f << "</tbody>\n" "</table>\n" "</div>\n" "</body>\n" "</html>\n"; }
bool Catalog::ExportToHTML(const wxString& filename) { size_t i; wxTextFile f; if ( wxFileExists(filename) ) { wxRemoveFile ( filename); } if (!f.Create(filename)) { return false; } // TODO use some kind of HTML template system to allow different styles wxString line; // HTML HEADER f.AddLine(_T("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">")); f.AddLine("<html>"); f.AddLine("<head>"); line.Printf("<title> %s - %s - Poedit Export </title>", EscapeMarkup(m_header.Project).c_str(), EscapeMarkup(m_header.LanguageCode).c_str()); f.AddLine(line); f.AddLine(_T("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" ) ); f.AddLine("</head>"); f.AddLine("<body bgcolor='#FFFFFF'>"); line.Printf("<h1> %s : %s</h1>", EscapeMarkup(m_header.Project).c_str(), EscapeMarkup(m_header.LanguageCode).c_str()); f.AddLine(line); // po file header information : // String here are duplicates from the ones in setting.xrc // TODO find a way if possible to synchronize them f.AddLine("<table align=center border=1 cellspacing=2 cellpadding=4>"); line.Printf("<tr><th colspan=2>%s</th></tr>", _("Project info")); f.AddLine(line); wxString line_format = "<tr><td>%s</td><td>%s</td></tr>"; line.Printf(line_format, _("Project name and version:"), EscapeMarkup(m_header.Project).c_str()); f.AddLine(line); line.Printf(line_format, _("Language:"), EscapeMarkup(m_header.LanguageCode).c_str()); f.AddLine(line); line.Printf(line_format, _("Team:"), EscapeMarkup(m_header.Team).c_str()); f.AddLine(line); line.Printf(_T("<tr><td>%s</td><td><a href=\"mailto:%s\">%s</a></td></tr>"), _("Team's email address:"), EscapeMarkup(m_header.TeamEmail).c_str(), EscapeMarkup(m_header.TeamEmail).c_str()); f.AddLine(line); line.Printf(line_format, _("Charset:"), EscapeMarkup(m_header.Charset).c_str()); f.AddLine(line); f.AddLine( "</table>" ); // statistics int all = 0; int fuzzy = 0; int untranslated = 0; int badtokens = 0; int unfinished = 0; GetStatistics(&all, &fuzzy, &badtokens, &untranslated, &unfinished); int percent = (all == 0 ) ? 0 : (100 * (all - unfinished) / all); line.Printf(_("%i %% translated, %i strings (%i fuzzy, %i bad tokens, %i not translated)"), percent, all, fuzzy, badtokens, untranslated); f.AddLine(line); // data printed in a table : f.AddLine("<table border=1 cellspacing=2 cellpadding=4>"); f.AddLine("<tr>"); f.AddLine("<th>"); f.AddLine(_("Source")); f.AddLine("</th>"); f.AddLine("<th>"); f.AddLine(_("Translation")); f.AddLine("</th>"); f.AddLine("<th>"); f.AddLine(_("Notes")); f.AddLine("</th>"); f.AddLine("</tr>"); for (i = 0; i < GetCount(); i++) { const CatalogItem& data = m_items[i]; wxColour bgcolor = g_ItemColourNormal[i % 2]; wxString source_string = data.GetString(); wxString translation = data.GetTranslation(); if (translation.empty()) { translation = " "; bgcolor = g_ItemColourUntranslated[i % 2]; } wxString flags; if (data.IsAutomatic()) { flags += EscapeMarkup(_("Automatic translation")); flags += "<BR>"; } if (data.IsFuzzy()) { bgcolor = g_ItemColourFuzzy[i % 2]; flags += EscapeMarkup(_("Fuzzy translation")); flags += "<BR>"; } if (flags.empty()) { flags = " "; } wxString tr; tr.Printf("<tr bgcolor='#%0X%0X%0X'>", bgcolor.Red(), bgcolor.Green(), bgcolor.Blue()); f.AddLine(tr); f.AddLine("<td>"); f.AddLine(EscapeMarkup(source_string)); f.AddLine("</td>"); f.AddLine("<td>"); f.AddLine(EscapeMarkup(translation)); f.AddLine("</td>"); f.AddLine("<td>"); f.AddLine(_T("<font size=\"-1\">")); f.AddLine(flags); f.AddLine("</font>"); f.AddLine("</td>"); f.AddLine("</tr>"); } f.AddLine("</table>"); f.AddLine("</body>"); f.AddLine("</html>"); bool written = f.Write(wxTextFileType_None, wxConvUTF8); f.Close(); return written; }
bool CWaveDevice::InternalClose() //------------------------------- { MPT_TRACE(); if(m_hWaveOut) { waveOutReset(m_hWaveOut); m_JustStarted = false; InterlockedExchange(&m_nBuffersPending, 0); m_nWriteBuffer = 0; m_nDoneBuffer = 0; while(m_nPreparedHeaders > 0) { m_nPreparedHeaders--; waveOutUnprepareHeader(m_hWaveOut, &m_WaveBuffers[m_nPreparedHeaders], sizeof(WAVEHDR)); } waveOutClose(m_hWaveOut); m_hWaveOut = NULL; } #ifdef _DEBUG if(m_DriverBugs.load()) { SendDeviceMessage(LogError, MPT_USTRING("Errors were detected while playing sound:\n") + GetStatistics().text); } #endif m_DriverBugs = 0; m_Failed = false; if(m_ThreadWakeupEvent) { CloseHandle(m_ThreadWakeupEvent); m_ThreadWakeupEvent = NULL; } { MPT_LOCK_GUARD<mpt::mutex> guard(m_PositionWraparoundMutex); MemsetZero(m_PositionLast); m_PositionWrappedCount = 0; } return true; }
void MenuHandler(){ short nArgs; int selectedNode; node * network = NULL; statistics * stats = NULL; char option, buffer[BUFFER_SIZE], arg1[BUFFER_SIZE], garbageDetector[BUFFER_SIZE]; if(executeAtStart){ network = ReadNetwork(path); if(network != NULL){ stats = GetStatistics(network); PrintStatistics(stats); PrintExecutionTime(); FreeEverything(network, stats); return; } else return; } // printing menu PrintMenu(); printf("Please select an option\n"); while(TRUE){ // gets user commands and arguments printf("-> "); fgets (buffer, BUFFER_SIZE, stdin); nArgs = sscanf(buffer, "%c %s %s", &option, arg1, garbageDetector); // selects function based on user option ////////// load if(option == 'f' && nArgs == 2){ if(network != NULL) free(network); network = ReadNetwork(arg1); if(network != NULL) printf("Network loaded from file\n"); } ////////// route else if(option == 'r' && nArgs == 2) { if(network != NULL){ selectedNode = atoi(arg1); if(selectedNode <= numberOfNodes && selectedNode > 0){ results = FindRoutesToNode(network, selectedNode); PrintRoutingTable(network); } else printf("Please select valid node\n"); } else printf("Please load a network first\n"); } ///////// statistics else if(option == 's' && nArgs == 1){ if(network != NULL){ stats = GetStatistics(network); PrintStatistics(stats); PrintExecutionTime(); } else printf("Please load a network first\n"); } //////// others else if(option == 'h' && nArgs == 1) PrintMenu(); else if(option == 'q' && nArgs == 1){ FreeEverything(network, stats); printf("Project by: Diogo Salgueiro 72777 and Ricardo Ferro 72870\n"); printf("Goodbye!\n"); return; } else printf("Invalid command\n"); } };