本文整理汇总了C++中MythTimer类的典型用法代码示例。如果您正苦于以下问题:C++ MythTimer类的具体用法?C++ MythTimer怎么用?C++ MythTimer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MythTimer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tr
int SchemaUpgradeWizard::CompareAndWait(const int seconds)
{
if (Compare() > 0) // i.e. if DB is older than expected
{
QString message = tr("%1 database schema is old. Waiting to see if DB "
"is being upgraded.").arg(m_schemaName);
LOG(VB_GENERAL, LOG_CRIT, message);
MSqlQuery query(MSqlQuery::InitCon(MSqlQuery::kDedicatedConnection));
bool backupRunning = false;
bool upgradeRunning = false;
MythTimer elapsedTimer;
elapsedTimer.start();
while (versionsBehind && (elapsedTimer.elapsed() < seconds * 1000))
{
sleep(1);
if (IsBackupInProgress())
{
LOG(VB_GENERAL, LOG_CRIT,
"Waiting for Database Backup to complete.");
if (!backupRunning)
{
elapsedTimer.restart();
backupRunning = true;
}
continue;
}
if (!lockSchema(query))
{
LOG(VB_GENERAL, LOG_CRIT,
"Waiting for Database Upgrade to complete.");
if (!upgradeRunning)
{
elapsedTimer.restart();
upgradeRunning = true;
}
continue;
}
Compare();
unlockSchema(query);
if (m_expertMode)
break;
}
if (versionsBehind)
LOG(VB_GENERAL, LOG_CRIT, "Timed out waiting.");
else
LOG(VB_GENERAL, LOG_CRIT,
"Schema version was upgraded while we were waiting.");
}
// else DB is same version, or newer. Either way, we won't upgrade it
return versionsBehind;
}
示例2: GetLiveStreamInfo
DTC::LiveStreamInfo *HTTPLiveStream::StartStream(void)
{
if (GetDBStatus() != kHLSStatusQueued)
return GetLiveStreamInfo();
HTTPLiveStreamThread *streamThread =
new HTTPLiveStreamThread(GetStreamID());
MThreadPool::globalInstance()->startReserved(streamThread,
"HTTPLiveStream");
MythTimer statusTimer;
int delay = 250000;
statusTimer.start();
HTTPLiveStreamStatus status = GetDBStatus();
while ((status == kHLSStatusQueued) &&
((statusTimer.elapsed() / 1000) < 30))
{
delay = (int)(delay * 1.5);
usleep(delay);
status = GetDBStatus();
}
return GetLiveStreamInfo();
}
示例3: VERBOSE
bool DeviceReadBuffer::Poll(void) const
{
#ifdef USING_MINGW
#warning mingw DeviceReadBuffer::Poll
VERBOSE(VB_IMPORTANT, LOC_ERR +
"mingw DeviceReadBuffer::Poll is not implemented");
return false;
#else
bool retval = true;
MythTimer timer;
timer.start();
while (true)
{
struct pollfd polls;
polls.fd = _stream_fd;
polls.events = POLLIN;
polls.revents = 0;
int ret = poll(&polls, 1 /*number of polls*/, 10 /*msec*/);
if (polls.revents & (POLLHUP | POLLNVAL))
{
VERBOSE(VB_IMPORTANT, LOC + "poll error");
error = true;
return true;
}
if (!run || !IsOpen() || IsPauseRequested())
{
retval = false;
break; // are we supposed to pause, stop, etc.
}
if (ret > 0)
break; // we have data to read :)
else if (ret < 0)
{
if ((EOVERFLOW == errno))
break; // we have an error to handle
if ((EAGAIN == errno) || (EINTR == errno))
continue; // errors that tell you to try again
usleep(2500 /*2.5 ms*/);
}
else // ret == 0
{
if ((uint)timer.elapsed() > max_poll_wait)
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Poll giving up");
QMutexLocker locker(&lock);
error = true;
return true;
}
}
}
return retval;
#endif //!USING_MINGW
}
示例4: run
void run(void)
{
RunProlog();
MythTimer t;
t.start();
QMutexLocker locker(&m_lock);
while (true)
{
if (m_do_run && !m_runnable)
m_wait.wait(locker.mutex(), m_expiry_timeout+1);
if (!m_runnable)
{
m_do_run = false;
locker.unlock();
m_pool.NotifyDone(this);
locker.relock();
break;
}
if (!m_runnable_name.isEmpty())
loggingRegisterThread(m_runnable_name);
bool autodelete = m_runnable->autoDelete();
m_runnable->run();
if (autodelete)
delete m_runnable;
if (m_reserved)
m_pool.ReleaseThread();
m_reserved = false;
m_runnable = NULL;
loggingDeregisterThread();
loggingRegisterThread(objectName());
GetMythDB()->GetDBManager()->PurgeIdleConnections(false);
qApp->processEvents();
qApp->sendPostedEvents(NULL, QEvent::DeferredDelete);
t.start();
if (m_do_run)
{
locker.unlock();
m_pool.NotifyAvailable(this);
locker.relock();
}
else
{
locker.unlock();
m_pool.NotifyDone(this);
locker.relock();
break;
}
}
RunEpilog();
}
示例5: StartPlaying
/** \fn PlayerContext::StartPlaying(int)
* \brief Starts player, must be called after StartRecorder().
* \param maxWait How long to wait for MythPlayer to start playing.
* \return true when successful, false otherwise.
*/
bool PlayerContext::StartPlaying(int maxWait)
{
if (!player)
return false;
player->StartPlaying();
maxWait = (maxWait <= 0) ? 20000 : maxWait;
#ifdef USING_VALGRIND
maxWait = (1<<30);
#endif // USING_VALGRIND
MythTimer t;
t.start();
while (!player->IsPlaying(50, true) && (t.elapsed() < maxWait))
ReloadTVChain();
if (player->IsPlaying())
{
VERBOSE(VB_PLAYBACK, LOC + "StartPlaying(): took "<<t.elapsed()
<<" ms to start player.");
return true;
}
else
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "StartPlaying() "
"Failed to start player");
StopPlaying();
return false;
}
}
示例6: StartPlaying
/** \fn PlayerContext::StartPlaying(int)
* \brief Starts player, must be called after StartRecorder().
* \param maxWait How long to wait for MythPlayer to start playing.
* \return true when successful, false otherwise.
*/
bool PlayerContext::StartPlaying(int maxWait)
{
if (!player)
return false;
player->StartPlaying();
maxWait = (maxWait <= 0) ? 20000 : maxWait;
#ifdef USING_VALGRIND
maxWait = (1<<30);
#endif // USING_VALGRIND
MythTimer t;
t.start();
while (!player->IsPlaying(50, true) && (t.elapsed() < maxWait))
ReloadTVChain();
if (player->IsPlaying())
{
LOG(VB_PLAYBACK, LOG_INFO, LOC +
QString("StartPlaying(): took %1 ms to start player.")
.arg(t.elapsed()));
return true;
}
else
{
LOG(VB_GENERAL, LOG_ERR, LOC + "StartPlaying() Failed to start player");
StopPlaying();
return false;
}
}
示例7: readData
bool ZMClient::readData(unsigned char *data, int dataSize)
{
qint64 read = 0;
int errmsgtime = 0;
MythTimer timer;
timer.start();
int elapsed;
while (dataSize > 0)
{
qint64 sret = m_socket->Read(
(char*) data + read, dataSize, 100 /*ms*/);
if (sret > 0)
{
read += sret;
dataSize -= sret;
if (dataSize > 0)
{
timer.start();
}
}
else if (sret < 0)
{
LOG(VB_GENERAL, LOG_ERR, "readData: Error, readBlock");
m_socket->DisconnectFromHost();
return false;
}
else if (!m_socket->IsConnected())
{
LOG(VB_GENERAL, LOG_ERR,
"readData: Error, socket went unconnected");
m_socket->DisconnectFromHost();
return false;
}
else
{
elapsed = timer.elapsed();
if (elapsed > 10000)
{
if ((elapsed - errmsgtime) > 10000)
{
errmsgtime = elapsed;
LOG(VB_GENERAL, LOG_ERR,
QString("m_socket->: Waiting for data: %1 %2")
.arg(read).arg(dataSize));
}
}
if (elapsed > 100000)
{
LOG(VB_GENERAL, LOG_ERR, "Error, readData timeout (readBlock)");
return false;
}
}
}
return true;
}
示例8: WaitForPause
/** \fn RecorderBase::WaitForPause(int)
* \brief WaitForPause blocks until recorder is actually paused,
* or timeout milliseconds elapse.
* \param timeout number of milliseconds to wait defaults to 1000.
* \return true iff pause happened within timeout period.
*/
bool RecorderBase::WaitForPause(int timeout)
{
MythTimer t;
t.start();
QMutexLocker locker(&pauseLock);
while (!IsPaused(true) && request_pause)
{
int wait = timeout - t.elapsed();
if (wait <= 0)
return false;
pauseWait.wait(&pauseLock, wait);
}
return true;
}
示例9: AddTimer
int MythDatabase::AddTimer(MythTimer &timer)
{
m_database_t->Lock();
int retval=CMYTH->MysqlAddTimer(*m_database_t,timer.ChanID(),timer.m_callsign.Buffer(),timer.m_description.Buffer(),timer.StartTime(), timer.EndTime(),timer.m_title.Buffer(),timer.m_category.Buffer(),
timer.Type(),timer.m_subtitle.Buffer(),timer.Priority(),timer.StartOffset(),timer.EndOffset(),timer.SearchType(),timer.Inactive()?1:0,timer.DupMethod(),timer.CheckDupIn(),timer.RecGroup().Buffer(),
timer.StoreGroup().Buffer(),timer.PlayGroup().Buffer(),timer.AutoTranscode(),timer.Userjobs(),timer.AutoCommFlag(),timer.AutoExpire(),timer.MaxEpisodes(),timer.NewExpireOldRecord(),timer.Transcoder());
timer.m_recordid=retval;
m_database_t->Unlock();
return retval;
}
示例10: WaitForUsed
/** \fn DeviceReadBuffer::WaitForUsed(uint,uint) const
* \param needed Number of bytes we want to read
* \param max_wait Number of milliseconds to wait for the needed data
* \return bytes available for reading
*/
uint DeviceReadBuffer::WaitForUsed(uint needed, uint max_wait) const
{
MythTimer timer;
timer.start();
QMutexLocker locker(&lock);
size_t avail = used;
while ((needed > avail) && isRunning() &&
!request_pause && !error && !eof &&
(timer.elapsed() < (int)max_wait))
{
dataWait.wait(locker.mutex(), 10);
avail = used;
}
return avail;
}
示例11: progress_string
static QString progress_string(
MythTimer &flagTime, uint64_t m_myFramesPlayed, uint64_t totalFrames)
{
if (totalFrames == 0ULL)
{
return QString("%1 frames processed \r")
.arg(m_myFramesPlayed,7);
}
double elapsed = flagTime.elapsed() * 0.001;
double flagFPS = (elapsed > 0.0) ? (m_myFramesPlayed / elapsed) : 0;
double percentage = m_myFramesPlayed * 100.0 / totalFrames;
percentage = (percentage > 100.0 && percentage < 101.0) ?
100.0 : percentage;
if (flagFPS < 10.0)
{
return QString("%1 fps %2% \r")
.arg(flagFPS,4,'f',1).arg(percentage,4,'f',1);
}
else
{
return QString("%1 fps %2% \r")
.arg(flagFPS,4,'f',0).arg(percentage,4,'f',1);
}
}
示例12: progress_string
static QString progress_string(
MythTimer &flagTime, uint64_t m_myFramesPlayed, uint64_t totalFrames)
{
if (totalFrames == 0ULL)
{
return QString("%1 frames processed \r")
.arg(m_myFramesPlayed,7);
}
static char const spin_chars[] = "/-\\|";
static uint spin_cnt = 0;
double elapsed = flagTime.elapsed() * 0.001;
double flagFPS = (elapsed > 0.0) ? (m_myFramesPlayed / elapsed) : 0;
double percentage = m_myFramesPlayed * 100.0 / totalFrames;
percentage = (percentage > 100.0 && percentage < 101.0) ?
100.0 : percentage;
if (m_myFramesPlayed < totalFrames)
return QString("%1 fps %2% \r")
.arg(flagFPS,4,'f', (flagFPS < 10.0 ? 1 : 0)).arg(percentage,4,'f',1);
else
return QString("%1 fps %2 \r")
.arg(flagFPS,4,'f', (flagFPS < 10.0 ? 1 : 0))
.arg(spin_chars[++spin_cnt % 4]);
}
示例13: query
DTC::LiveStreamInfo *HTTPLiveStream::StopStream(int id)
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"UPDATE livestream "
"SET status = :STATUS "
"WHERE id = :STREAMID; ");
query.bindValue(":STATUS", (int)kHLSStatusStopping);
query.bindValue(":STREAMID", id);
if (!query.exec())
{
LOG(VB_GENERAL, LOG_ERR, SLOC +
QString("Unable to remove mark stream stopped for stream %1.")
.arg(id));
return NULL;
}
HTTPLiveStream *hls = new HTTPLiveStream(id);
if (!hls)
return NULL;
MythTimer statusTimer;
int delay = 250000;
statusTimer.start();
HTTPLiveStreamStatus status = hls->GetDBStatus();
while ((status != kHLSStatusStopped) &&
(status != kHLSStatusCompleted) &&
(status != kHLSStatusErrored) &&
((statusTimer.elapsed() / 1000) < 30))
{
delay = (int)(delay * 1.5);
usleep(delay);
status = hls->GetDBStatus();
}
hls->LoadFromDB();
DTC::LiveStreamInfo *pLiveStreamInfo = hls->GetLiveStreamInfo();
delete hls;
return pLiveStreamInfo;
}
示例14: locker
void MThreadPool::startReserved(
QRunnable *runnable, QString debugName, int waitForAvailMS)
{
QMutexLocker locker(&m_priv->m_lock);
if (waitForAvailMS > 0 && m_priv->m_avail_threads.empty() &&
m_priv->m_running_threads.size() >= m_priv->m_max_thread_count)
{
MythTimer t;
t.start();
int left = waitForAvailMS - t.elapsed();
while (left > 0 && m_priv->m_avail_threads.empty() &&
m_priv->m_running_threads.size() >= m_priv->m_max_thread_count)
{
m_priv->m_wait.wait(locker.mutex(), left);
left = waitForAvailMS - t.elapsed();
}
}
TryStartInternal(runnable, debugName, true);
}
示例15: DefaultTimer
void MythConnection::DefaultTimer(MythTimer &timer)
{
timer.SetAutoTranscode(atoi(GetSetting("NULL", "AutoTranscode").c_str()) > 0);
timer.SetUserJob(1, atoi(GetSetting("NULL", "AutoRunUserJob1").c_str()) > 0);
timer.SetUserJob(2, atoi(GetSetting("NULL", "AutoRunUserJob2").c_str()) > 0);
timer.SetUserJob(3, atoi(GetSetting("NULL", "AutoRunUserJob3").c_str()) > 0);
timer.SetUserJob(4, atoi(GetSetting("NULL", "AutoRunUserJob4").c_str()) > 0);
timer.SetAutoCommFlag(atoi(GetSetting("NULL", "AutoCommercialFlag").c_str()) > 0);
timer.SetAutoExpire(atoi(GetSetting("NULL", "AutoExpireDefault").c_str()) > 0);
timer.SetTranscoder(atoi(GetSetting("NULL", "DefaultTranscoder").c_str()));
timer.SetStartOffset(atoi(GetSetting("NULL", "DefaultStartOffset").c_str()));
timer.SetStartOffset(atoi(GetSetting("NULL", "DefaultEndOffset").c_str()));
}