本文整理汇总了C++中MythTimer::start方法的典型用法代码示例。如果您正苦于以下问题:C++ MythTimer::start方法的具体用法?C++ MythTimer::start怎么用?C++ MythTimer::start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MythTimer
的用法示例。
在下文中一共展示了MythTimer::start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: WaitForLock
/** \fn SignalMonitor::WaitForLock(int)
* \brief Wait for a StatusSignaLock(int) of true.
*
* This can be called whether or not the signal
* monitoring thread has been started.
*
* \param timeout maximum time to wait in milliseconds.
* \return true if signal was acquired.
*/
bool SignalMonitor::WaitForLock(int timeout)
{
statusLock.lock();
if (-1 == timeout)
timeout = signalLock.GetTimeout();
statusLock.unlock();
if (timeout<0)
return false;
MythTimer t;
t.start();
if (running)
{
while (t.elapsed()<timeout && running)
{
Kick();
statusLock.lock();
bool ok = signalLock.IsGood();
statusLock.unlock();
if (ok)
return true;
usleep(50);
}
if (!running)
return WaitForLock(timeout-t.elapsed());
}
else
{
while (t.elapsed()<timeout && !running)
{
UpdateValues();
statusLock.lock();
bool ok = signalLock.IsGood();
statusLock.unlock();
if (ok)
return true;
usleep(50);
}
if (running)
return WaitForLock(timeout-t.elapsed());
}
return false;
}
示例3: 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;
}
示例4: startReserved
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);
}
示例5: ReadLine
QString BufferedSocketDevice::ReadLine( int msecs )
{
MythTimer timer;
QString sLine;
if ( CanReadLine() )
return( ReadLine() );
// ----------------------------------------------------------------------
// If the user supplied a timeout, lets loop until we can read a line
// or timeout.
// ----------------------------------------------------------------------
if ( msecs > 0)
{
bool bTimeout = false;
timer.start();
while ( !CanReadLine() && !bTimeout )
{
#if 0
LOG(VB_HTTP, LOG_DEBUG, "Can't Read Line... Waiting for more." );
#endif
WaitForMore( msecs, &bTimeout );
if ( timer.elapsed() >= msecs )
{
bTimeout = true;
LOG(VB_HTTP, LOG_INFO, "Exceeded Total Elapsed Wait Time." );
}
}
if (CanReadLine())
sLine = ReadLine();
}
return( sLine );
}
示例6: TeardownAll
void PreviewGenerator::TeardownAll(void)
{
if (!isConnected)
return;
const QString filename = programInfo.pathname + ".png";
MythTimer t;
t.start();
for (bool done = false; !done;)
{
previewLock.lock();
if (isConnected)
emit previewThreadDone(filename, done);
else
done = true;
previewLock.unlock();
usleep(5000);
}
VERBOSE(VB_PLAYBACK, LOC + "previewThreadDone took "<<t.elapsed()<<"ms");
disconnectSafe();
}
示例7: HTTPLiveStreamThread
DTC::LiveStreamInfo *HTTPLiveStream::StartStream(void)
{
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();
}
示例8: ReadReal
void MythSocket::ReadReal(char *data, int size, int max_wait_ms, int *ret)
{
MythTimer t; t.start();
while ((m_tcpSocket->state() == QAbstractSocket::ConnectedState) &&
(m_tcpSocket->bytesAvailable() < size) &&
(t.elapsed() < max_wait_ms))
{
m_tcpSocket->waitForReadyRead(max(2, max_wait_ms - t.elapsed()));
}
*ret = m_tcpSocket->read(data, size);
if (t.elapsed() > 50)
{
LOG(VB_GENERAL, LOG_INFO,
QString("ReadReal(?, %1, %2) -> %3 took %4 ms")
.arg(size).arg(max_wait_ms).arg(*ret)
.arg(t.elapsed()));
}
m_dataAvailable.fetchAndStoreOrdered(
(m_tcpSocket->bytesAvailable() > 0) ? 1 : 0);
}
示例9: Cleanup
void MThread::Cleanup(void)
{
QMutexLocker locker(&s_all_threads_lock);
QSet<MThread*> badGuys;
QSet<MThread*>::const_iterator it;
for (it = s_all_threads.begin(); it != s_all_threads.end(); ++it)
{
if ((*it)->isRunning())
{
badGuys.insert(*it);
(*it)->exit(1);
}
}
if (badGuys.empty())
return;
// logging has been stopped so we need to use iostream...
cerr<<"Error: Not all threads were shut down properly: "<<endl;
for (it = badGuys.begin(); it != badGuys.end(); ++it)
{
cerr<<"Thread "<<qPrintable((*it)->objectName())
<<" is still running"<<endl;
}
cerr<<endl;
static const int kTimeout = 5000;
MythTimer t;
t.start();
for (it = badGuys.begin();
it != badGuys.end() && t.elapsed() < kTimeout; ++it)
{
int left = kTimeout - t.elapsed();
if (left > 0)
(*it)->wait(left);
}
}
示例10: 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;
if (!player->StartPlaying())
{
LOG(VB_GENERAL, LOG_ERR, LOC + "StartPlaying() Failed to start player");
// no need to call StopPlaying here as the player context will be deleted
// later following the error
return false;
}
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;
}
}
示例11: OpenDevice
bool AudioOutputOSS::OpenDevice()
{
numbadioctls = 0;
MythTimer timer;
timer.start();
VBAUDIO(QString("Opening OSS audio device '%1'.").arg(main_device));
while (timer.elapsed() < 2000 && audiofd == -1)
{
QByteArray device = main_device.toLatin1();
audiofd = open(device.constData(), O_WRONLY);
if (audiofd < 0 && errno != EAGAIN && errno != EINTR)
{
if (errno == EBUSY)
{
VBWARN(QString("Something is currently using: %1.")
.arg(main_device));
return false;
}
VBERRENO(QString("Error opening audio device (%1)")
.arg(main_device));
}
if (audiofd < 0)
usleep(50);
}
if (audiofd == -1)
{
Error(QObject::tr("Error opening audio device (%1)").arg(main_device));
VBERRENO(QString("Error opening audio device (%1)").arg(main_device));
return false;
}
if (fcntl(audiofd, F_SETFL, fcntl(audiofd, F_GETFL) & ~O_NONBLOCK) == -1)
{
VBERRENO(QString("Error removing the O_NONBLOCK flag from audio device FD (%1)").arg(main_device));
}
bool err = false;
int format;
switch (output_format)
{
case FORMAT_U8: format = AFMT_U8; break;
case FORMAT_S16: format = AFMT_S16_NE; break;
default:
VBERROR(QString("Unknown sample format: %1").arg(output_format));
close(audiofd);
audiofd = -1;
return false;
}
#if defined(AFMT_AC3) && defined(SNDCTL_DSP_GETFMTS)
if (passthru)
{
int format_support = 0;
if (!ioctl(audiofd, SNDCTL_DSP_GETFMTS, &format_support) &&
(format_support & AFMT_AC3))
{
format = AFMT_AC3;
}
}
#endif
if (channels > 2)
{
if (ioctl(audiofd, SNDCTL_DSP_CHANNELS, &channels) < 0 ||
ioctl(audiofd, SNDCTL_DSP_SPEED, &samplerate) < 0 ||
ioctl(audiofd, SNDCTL_DSP_SETFMT, &format) < 0)
err = true;
}
else
{
int stereo = channels - 1;
if (ioctl(audiofd, SNDCTL_DSP_STEREO, &stereo) < 0 ||
ioctl(audiofd, SNDCTL_DSP_SPEED, &samplerate) < 0 ||
ioctl(audiofd, SNDCTL_DSP_SETFMT, &format) < 0)
err = true;
}
if (err)
{
VBERRENO(QString("Unable to set audio device (%1) to %2 kHz, %3 bits, "
"%4 channels")
.arg(main_device).arg(samplerate)
.arg(AudioOutputSettings::FormatToBits(output_format))
.arg(channels));
close(audiofd);
audiofd = -1;
return false;
}
audio_buf_info info;
if (ioctl(audiofd, SNDCTL_DSP_GETOSPACE, &info) < 0)
VBERRENO("Error retrieving card buffer size");
// align by frame size
fragment_size = info.fragsize - (info.fragsize % output_bytes_per_frame);
//.........这里部分代码省略.........
示例12: RunEventLoop
/** \fn EITScanner::RunEventLoop(void)
* \brief This runs the event loop for EITScanner until 'exitThread' is true.
*/
void EITScanner::RunEventLoop(void)
{
static const uint sz[] = { 2000, 1800, 1600, 1400, 1200, };
static const float rt[] = { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, };
lock.lock();
exitThread = false;
MythTimer t;
uint eitCount = 0;
while (!exitThread)
{
lock.unlock();
uint list_size = eitHelper->GetListSize();
float rate = 1.0f;
for (uint i = 0; i < 5; i++)
{
if (list_size >= sz[i])
{
rate = rt[i];
break;
}
}
lock.lock();
if (eitSource)
eitSource->SetEITRate(rate);
lock.unlock();
if (list_size)
{
eitCount += eitHelper->ProcessEvents();
t.start();
}
// If there have been any new events and we haven't
// seen any in a while, tell scheduler to run.
if (eitCount && (t.elapsed() > 60 * 1000))
{
VERBOSE(VB_EIT, LOC_ID + "Added "<<eitCount<<" EIT Events");
eitCount = 0;
RescheduleRecordings();
}
if (activeScan && (QDateTime::currentDateTime() > activeScanNextTrig))
{
// if there have been any new events, tell scheduler to run.
if (eitCount)
{
VERBOSE(VB_EIT, LOC_ID + "Added "<<eitCount<<" EIT Events");
eitCount = 0;
RescheduleRecordings();
}
if (activeScanNextChan == activeScanChannels.end())
activeScanNextChan = activeScanChannels.begin();
if (!(*activeScanNextChan).isEmpty())
{
eitHelper->WriteEITCache();
rec->SetChannel(*activeScanNextChan, TVRec::kFlagEITScan);
VERBOSE(VB_EIT, LOC_ID +
QString("Now looking for EIT data on "
"multiplex of channel %1")
.arg(*activeScanNextChan));
}
activeScanNextTrig = QDateTime::currentDateTime()
.addSecs(activeScanTrigTime);
activeScanNextChan++;
// 24 hours ago
eitHelper->PruneEITCache(activeScanNextTrig.toTime_t() - 86400);
}
lock.lock();
if (!exitThread)
exitThreadCond.wait(&lock, 400); // sleep up to 400 ms.
}
lock.unlock();
}
示例13: Read
int RemoteFile::Read(void *data, int size)
{
int recv = 0;
int sent = 0;
bool error = false;
bool response = false;
QMutexLocker locker(&lock);
if (!sock)
{
LOG(VB_NETWORK, LOG_ERR, "RemoteFile::Read(): Called with no socket");
return -1;
}
if (!sock->IsConnected() || !controlSock->IsConnected())
return -1;
if (sock->IsDataAvailable())
{
LOG(VB_NETWORK, LOG_ERR,
"RemoteFile::Read(): Read socket not empty to start!");
sock->Reset();
}
while (controlSock->IsDataAvailable())
{
LOG(VB_NETWORK, LOG_ERR,
"RemoteFile::Read(): Control socket not empty to start!");
controlSock->Reset();
}
QStringList strlist( QString(query).arg(recordernum) );
strlist << "REQUEST_BLOCK";
strlist << QString::number(size);
bool ok = controlSock->WriteStringList(strlist);
if (!ok)
{
LOG(VB_NETWORK, LOG_ERR, "RemoteFile::Read(): Block request failed");
return -1;
}
sent = size;
int waitms = 10;
MythTimer mtimer;
mtimer.start();
while (recv < sent && !error && mtimer.elapsed() < 10000)
{
int ret = sock->Read(((char *)data) + recv, sent - recv, waitms);
if (ret > 0)
recv += ret;
else if (ret < 0)
error = true;
waitms += (waitms < 200) ? 20 : 0;
if (controlSock->IsDataAvailable() &&
controlSock->ReadStringList(strlist, MythSocket::kShortTimeout) &&
!strlist.empty())
{
sent = strlist[0].toInt(); // -1 on backend error
response = true;
}
}
if (!error && !response)
{
if (controlSock->ReadStringList(strlist, MythSocket::kShortTimeout) &&
!strlist.empty())
{
sent = strlist[0].toInt(); // -1 on backend error
}
else
{
LOG(VB_GENERAL, LOG_ERR,
"RemoteFile::Read(): No response from control socket.");
sent = -1;
}
}
LOG(VB_NETWORK, LOG_DEBUG,
QString("Read(): reqd=%1, rcvd=%2, rept=%3, error=%4")
.arg(size).arg(recv).arg(sent).arg(error));
if (sent < 0)
return sent;
if (error || sent != recv)
recv = -1;
return recv;
}
示例14: OpenDevice
bool AudioOutputOSS::OpenDevice()
{
numbadioctls = 0;
MythTimer timer;
timer.start();
VERBOSE(VB_GENERAL, QString("Opening OSS audio device '%1'.")
.arg(audio_main_device));
while (timer.elapsed() < 2000 && audiofd == -1)
{
audiofd = open(audio_main_device.ascii(), O_WRONLY | O_NONBLOCK);
if (audiofd < 0 && errno != EAGAIN && errno != EINTR)
{
if (errno == EBUSY)
{
Error(QString("WARNING: something is currently"
" using: %1, retrying.").arg(audio_main_device));
return false;
}
VERBOSE(VB_IMPORTANT, QString("Error opening audio device (%1), the"
" error was: %2").arg(audio_main_device).arg(strerror(errno)));
perror(audio_main_device.ascii());
}
if (audiofd < 0)
usleep(50);
}
if (audiofd == -1)
{
Error(QString("Error opening audio device (%1), the error was: %2")
.arg(audio_main_device).arg(strerror(errno)));
return false;
}
fcntl(audiofd, F_SETFL, fcntl(audiofd, F_GETFL) & ~O_NONBLOCK);
SetFragSize();
bool err = false;
int format;
switch (audio_bits)
{
case 8:
format = AFMT_S8;
break;
case 16:
#ifdef WORDS_BIGENDIAN
format = AFMT_S16_BE;
#else
format = AFMT_S16_LE;
#endif
break;
default: Error(QString("AudioOutputOSS() - Illegal bitsize of %1")
.arg(audio_bits));
}
#if defined(AFMT_AC3) && defined(SNDCTL_DSP_GETFMTS)
if (audio_passthru)
{
int format_support;
if (!ioctl(audiofd, SNDCTL_DSP_GETFMTS, &format_support) &&
(format_support & AFMT_AC3))
{
format = AFMT_AC3;
}
}
#endif
if (audio_channels > 2)
{
if (ioctl(audiofd, SNDCTL_DSP_SAMPLESIZE, &audio_bits) < 0 ||
ioctl(audiofd, SNDCTL_DSP_CHANNELS, &audio_channels) < 0 ||
ioctl(audiofd, SNDCTL_DSP_SPEED, &audio_samplerate) < 0 ||
ioctl(audiofd, SNDCTL_DSP_SETFMT, &format) < 0)
err = true;
}
else
{
int stereo = audio_channels - 1;
if (ioctl(audiofd, SNDCTL_DSP_SAMPLESIZE, &audio_bits) < 0 ||
ioctl(audiofd, SNDCTL_DSP_STEREO, &stereo) < 0 ||
ioctl(audiofd, SNDCTL_DSP_SPEED, &audio_samplerate) < 0 ||
ioctl(audiofd, SNDCTL_DSP_SETFMT, &format) < 0)
err = true;
}
if (err)
{
Error(QString("Unable to set audio device (%1) to %2 kHz / %3 bits"
" / %4 channels").arg(audio_main_device).arg(audio_samplerate)
.arg(audio_bits).arg(audio_channels));
close(audiofd);
audiofd = -1;
return false;
}
audio_buf_info info;
//.........这里部分代码省略.........
示例15: UpdateSourceIcons
void IconData::UpdateSourceIcons(uint sourceid)
{
VERBOSE(VB_GENERAL, LOC +
QString("Updating icons for sourceid: %1").arg(sourceid));
QString fileprefix = SetupIconCacheDirectory();
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"SELECT ch.chanid, nim.url "
"FROM (channel ch, callsignnetworkmap csm) "
"RIGHT JOIN networkiconmap nim ON csm.network = nim.network "
"WHERE ch.callsign = csm.callsign AND "
" (icon = :NOICON OR icon = '') AND "
" ch.sourceid = :SOURCEID");
query.bindValue(":SOURCEID", sourceid);
query.bindValue(":NOICON", "none");
if (!query.exec())
{
MythDB::DBError("Looking for icons to fetch", query);
return;
}
unsigned int count = 0;
while (query.next())
{
count++;
QString icon_url = expandURLString(query.value(1).toString());
QFileInfo qfi(icon_url);
QFile localfile(fileprefix + "/" + qfi.fileName());
if (!localfile.exists() || 0 == localfile.size())
{
VERBOSE(VB_GENERAL, LOC +
QString("Attempting to fetch icon at '%1'")
.arg(icon_url));
FI fi;
fi.filename = localfile.fileName();
fi.chanid = query.value(0).toUInt();
bool add_request = false;
{
QMutexLocker locker(&m_u2fl_lock);
add_request = m_u2fl[icon_url].empty();
m_u2fl[icon_url].push_back(fi);
}
if (add_request)
MythHttpPool::GetSingleton()->AddUrlRequest(icon_url, this);
// HACK -- begin
// This hack is needed because we don't enter the event loop
// before running this code via qApp->exec()
qApp->processEvents();
// HACK -- end
}
}
MythTimer tm; tm.start();
while (true)
{
// HACK -- begin
// This hack is needed because we don't enter the event loop
// before running this code via qApp->exec()
qApp->processEvents();
// HACK -- end
QMutexLocker locker(&m_u2fl_lock);
if (m_u2fl.empty())
break;
if ((uint)tm.elapsed() > (count * 500) + 2000)
{
VERBOSE(VB_IMPORTANT, LOC_WARN +
"Timed out waiting for some icons to download, "
"you may wish to try again later.");
break;
}
}
}