21 #include <QReadLocker>
22 #include <QWriteLocker>
89 snd_timer_info_malloc(&m_Info);
98 snd_timer_info_malloc(&m_Info);
99 snd_timer_info_copy(m_Info, other);
108 snd_timer_info_malloc(&m_Info);
109 snd_timer_info_copy(m_Info, other.m_Info);
117 snd_timer_info_free(m_Info);
137 snd_timer_info_copy(m_Info, other.m_Info);
148 return (snd_timer_info_is_slave(m_Info) != 0);
158 return snd_timer_info_get_card(m_Info);
168 return QString(snd_timer_info_get_id(m_Info));
178 return QString(snd_timer_info_get_name(m_Info));
188 return snd_timer_info_get_resolution(m_Info);
201 return 1000000000L / res;
213 return snd_timer_info_sizeof();
224 return snd_timer_info_get_ticks(m_Info);
232 snd_timer_id_malloc(&m_Info);
241 snd_timer_id_malloc(&m_Info);
242 snd_timer_id_copy(m_Info, other);
257 snd_timer_id_malloc(&m_Info);
258 snd_timer_id_copy(m_Info, other.m_Info);
277 snd_timer_id_malloc(&m_Info);
290 snd_timer_id_free(m_Info);
311 snd_timer_id_copy(m_Info, other.m_Info);
334 snd_timer_id_set_class(m_Info, devclass);
345 return snd_timer_id_get_class(m_Info);
355 snd_timer_id_set_sclass(m_Info, devsclass);
365 return snd_timer_id_get_sclass(m_Info);
375 snd_timer_id_set_card(m_Info, card);
385 return snd_timer_id_get_card(m_Info);
395 snd_timer_id_set_device(m_Info, device);
405 return snd_timer_id_get_device(m_Info);
415 snd_timer_id_set_subdevice (m_Info, subdevice);
425 return snd_timer_id_get_subdevice(m_Info);
435 return snd_timer_id_sizeof();
446 deviceName.toLocal8Bit().data(),
461 deviceName.toLocal8Bit().data(),
472 snd_timer_query_close(m_Info);
482 snd_timer_id_set_class(tid.m_Info, SND_TIMER_CLASS_NONE);
485 int rc = snd_timer_query_next_device(m_Info, tid.m_Info);
486 if ((rc < 0) || (tid.
getClass() < 0)) {
489 m_timers.append(tid);
509 snd_timer_query_info(m_Info, m_GlobalInfo.m_Info);
520 snd_timer_query_params(m_Info, params);
530 snd_timer_query_params(m_Info, params);
540 snd_timer_query_status(m_Info, status);
548 snd_timer_ginfo_malloc(&m_Info);
557 snd_timer_ginfo_malloc(&m_Info);
558 snd_timer_ginfo_copy(m_Info, other);
567 snd_timer_ginfo_malloc(&m_Info);
568 snd_timer_ginfo_copy(m_Info, other.m_Info);
576 snd_timer_ginfo_free(m_Info);
597 snd_timer_ginfo_copy(m_Info, other.m_Info);
609 snd_timer_ginfo_set_tid (m_Info, m_Id.m_Info);
619 m_Id =
TimerId(snd_timer_ginfo_get_tid (m_Info));
630 return snd_timer_ginfo_get_flags (m_Info);
640 return snd_timer_ginfo_get_card (m_Info);
650 return QString(snd_timer_ginfo_get_id (m_Info));
660 return QString(snd_timer_ginfo_get_name (m_Info));
670 return snd_timer_ginfo_get_resolution (m_Info);
680 return snd_timer_ginfo_get_resolution_min (m_Info);
690 return snd_timer_ginfo_get_resolution_max(m_Info);
700 return snd_timer_ginfo_get_clients(m_Info);
710 return snd_timer_ginfo_sizeof();
718 snd_timer_params_malloc (&m_Info);
727 snd_timer_params_malloc (&m_Info);
728 snd_timer_params_copy (m_Info, other);
737 snd_timer_params_malloc (&m_Info);
738 snd_timer_params_copy (m_Info, other.m_Info);
747 snd_timer_params_free (m_Info);
768 snd_timer_params_copy (m_Info, other.m_Info);
779 snd_timer_params_set_auto_start (m_Info, auto_start ? 1 : 0);
789 return (snd_timer_params_get_auto_start (m_Info) != 0);
799 snd_timer_params_set_exclusive (m_Info, exclusive ? 1 : 0);
809 return (snd_timer_params_get_exclusive (m_Info) != 0);
819 snd_timer_params_set_early_event (m_Info, early_event ? 1 : 0);
829 return (snd_timer_params_get_early_event (m_Info) != 0);
839 snd_timer_params_set_ticks (m_Info, ticks);
849 return snd_timer_params_get_ticks (m_Info);
859 snd_timer_params_set_queue_size (m_Info, queue_size);
869 return snd_timer_params_get_queue_size (m_Info);
879 snd_timer_params_set_filter (m_Info, filter);
889 return snd_timer_params_get_filter (m_Info);
899 return snd_timer_params_sizeof();
907 snd_timer_status_malloc (&m_Info);
916 snd_timer_status_malloc (&m_Info);
917 snd_timer_status_copy (m_Info, other);
926 snd_timer_status_malloc (&m_Info);
927 snd_timer_status_copy (m_Info, other.m_Info);
935 snd_timer_status_free (m_Info);
956 snd_timer_status_copy (m_Info, other.m_Info);
967 return snd_timer_status_get_timestamp (m_Info);
977 return snd_timer_status_get_resolution (m_Info);
987 return snd_timer_status_get_lost (m_Info);
997 return snd_timer_status_get_overrun (m_Info);
1007 return snd_timer_status_get_queue (m_Info);
1017 return snd_timer_status_sizeof();
1033 m_asyncHandler(NULL),
1036 m_deviceName(deviceName)
1038 CHECK_ERROR( snd_timer_open( &m_Info, m_deviceName.toLocal8Bit().data(),
1057 m_asyncHandler(NULL),
1060 m_deviceName(deviceName)
1063 m_deviceName.toLocal8Bit().data(),
1080 m_asyncHandler(NULL),
1084 m_deviceName = QString(
"hw:CLASS=%1,SCLASS=%2,CARD=%3,DEV=%4,SUBDEV=%5")
1086 .arg(
id.getSlaveClass())
1088 .arg(
id.getDevice())
1089 .arg(
id.getSubdevice());
1091 m_deviceName.toLocal8Bit().data(),
1111 int openMode,
QObject* parent )
1113 m_asyncHandler(NULL),
1117 m_deviceName = QString(
"hw:CLASS=%1,SCLASS=%2,CARD=%3,DEV=%4,SUBDEV=%5")
1124 m_deviceName.toLocal8Bit().data(),
1134 if (m_thread != NULL)
1147 CHECK_WARNING(snd_async_add_timer_handler(&m_asyncHandler, m_Info, callback, private_data));
1157 return snd_async_handler_get_timer(m_asyncHandler);
1167 return snd_timer_poll_descriptors_count(m_Info);
1178 CHECK_WARNING(snd_timer_poll_descriptors(m_Info, pfds, space));
1190 CHECK_WARNING(snd_timer_poll_descriptors_revents(m_Info, pfds, nfds, revents));
1200 snd_timer_info (m_Info, m_TimerInfo.m_Info);
1221 CHECK_WARNING( snd_timer_status(m_Info, m_TimerStatus.m_Info) );
1222 return m_TimerStatus;
1261 return snd_timer_read(m_Info, buffer, size);
1275 snd_timer_tread_t tr;
1276 while (
read(&tr,
sizeof(tr)) ==
sizeof(tr) ) {
1277 int msecs = ((tr.tstamp.tv_sec - m_last_time.tv_sec) * 1000) +
1278 round((tr.tstamp.tv_nsec - m_last_time.tv_nsec) / 1000000.0);
1279 m_last_time = tr.tstamp;
1280 if ( m_handler != NULL )
1293 if (m_thread == NULL) {
1294 m_thread =
new TimerInputThread(
this, 500);
1305 if (m_thread != NULL) {
1307 while (!m_thread->wait(500) && (counter < 10)) {
1310 if (!m_thread->isFinished()) {
1311 m_thread->terminate();
1328 snd_timer_info_t* info;
1329 long res, best_res = LONG_MAX;
1332 SND_TIMER_GLOBAL_SYSTEM
1333 , SND_TIMER_GLOBAL_RTC
1334 #ifdef SND_TIMER_GLOBAL_HPET
1335 , SND_TIMER_GLOBAL_HPET
1337 #ifdef SND_TIMER_GLOBAL_HRTIMER
1338 , SND_TIMER_GLOBAL_HRTIMER
1341 int max_global_timers =
sizeof(test_devs)/
sizeof(
int);
1342 int clas = SND_TIMER_CLASS_GLOBAL;
1343 int scls = SND_TIMER_SCLASS_NONE;
1345 int dev = SND_TIMER_GLOBAL_SYSTEM;
1350 snd_timer_info_alloca(&info);
1353 id.setSlaveClass(scls);
1356 id.setSubdevice(sdev);
1358 for( i = 0; i < max_global_timers; ++i )
1361 sprintf( timername,
"hw:CLASS=%i,SCLASS=%i,CARD=%i,DEV=%i,SUBDEV=%i",
1362 clas, scls, card, dev, sdev );
1363 err = snd_timer_open(&timer, timername, SND_TIMER_OPEN_NONBLOCK);
1364 if (err < 0)
continue;
1365 err = snd_timer_info(timer, info);
1367 is_slave = snd_timer_info_is_slave(info);
1368 res = snd_timer_info_get_resolution(info);
1369 if ((is_slave == 0) && (best_res > res)) {
1374 snd_timer_close(timer);
1390 return new Timer(
id, openMode, parent);
1397 Timer::TimerInputThread::run()
1401 if (m_timer == NULL)
return;
1403 count = m_timer->getPollDescriptorsCount();
1404 fds = (pollfd *) calloc(count,
sizeof(
struct pollfd));
1406 qWarning() <<
"allocation error!";
1409 fds->events = POLLIN;
1413 while (!stopped() && (m_timer != NULL)) {
1414 m_timer->pollDescriptors(fds, count);
1415 if ((err = poll(fds, count, m_Wait)) < 0) {
1416 qWarning() <<
"poll error " << err <<
"(" << strerror(err) <<
")";
1420 qWarning() <<
"timer time out";
1423 m_timer->doEvents();
1426 qWarning() <<
"exception in input thread";
1436 Timer::TimerInputThread::stopped()
1438 QReadLocker locker(&m_mutex);
1446 Timer::TimerInputThread::stop()
1448 QWriteLocker locker(&m_mutex);