+ // init
+ int result;
+ fd_set readset;
+ struct timeval timeout;
+
+ /* enter thread loop */
+ while (!stop_me) {
+ /* reset the read set */
+ FD_ZERO(&readset);
+ FD_SET(mc.fd, &readset);
+
+ // reinit the timeout structure
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 400000; /* 400 ms */
+
+ // do select in blocked mode and wake up after timeout
+ // for stop_me evaluation
+ result = select(mc.fd + 1, &readset, NULL, NULL, &timeout);
+
+ /* see if there was an error or timeout else process event */
+ if (result < 0 && errno == EINTR) {
+ // EINTR event catched. This is not a problem - continue processing
+ kDebug() << strerror(errno) << "\n";
+ // continue processing
+ continue;
+ } else if (result < 0) {
+ /* stop thread */
+ stop_me = true;
+ kDebug() << strerror(errno) << "\n";
+ } else if (result > 0) {
+ // we have input
+ if (FD_ISSET(mc.fd, &readset)) {
+ struct media_ctrl_event mev;
+ mev.type = MEDIA_CTRL_EVENT_NONE;
+ // read input
+ media_ctrl_read_event(&mc, &mev);
+ // process event
+ handle_event(mev);
+ }
+ } else if (result == 0) {
+ // on timeout. let it here for debug
+ }
+ }
+
+ kDebug() << "------- STOPPING SHUTTLE: ";
+ /* close the handle and return thread */
+ media_ctrl_close(&mc);
+}
+
+void ShuttleThread::handle_event(const struct media_ctrl_event& ev)
+{
+ if (ev.type == MEDIA_CTRL_EVENT_KEY)
+ key(ev);
+ else if (ev.type == MEDIA_CTRL_EVENT_JOG)
+ jog(ev);
+ else if (ev.type == MEDIA_CTRL_EVENT_SHUTTLE)
+ shuttle(ev);
+}
+
+void ShuttleThread::key(const struct media_ctrl_event& ev)
+{
+ if (ev.value == KEY_PRESS) {
+ int code = ev.index + 1;
+ QApplication::postEvent(m_parent,
+ new QEvent((QEvent::Type)(KEY_EVENT_OFFSET + code)));