Skip to content

Commit

Permalink
Remove the key list queue in the TV class.
Browse files Browse the repository at this point in the history
Key presses are now delivered directly into the 'correct' thread so
there is no need to pass them through a different queue for processing
in a different thread.

Plum picked from bb144de
  • Loading branch information
Mark Kendall committed Feb 9, 2011
1 parent 54fcb92 commit dd981aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 62 deletions.
78 changes: 19 additions & 59 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -924,7 +924,7 @@ TV::TV(void)
disableDrawUnusedRects(false),
isEmbedded(false), ignoreKeyPresses(false),
// Timers
lcdTimerId(0), keyListTimerId(0),
lcdTimerId(0),
networkControlTimerId(0), jumpMenuTimerId(0),
pipChangeTimerId(0), udpNotifyTimerId(0),
switchToInputTimerId(0), ccInputTimerId(0),
Expand Down Expand Up @@ -2623,49 +2623,6 @@ void TV::timerEvent(QTimerEvent *te)
handled = true;
}

if (handled)
return;

// Check if it matches keyListTimerId
QKeyEvent *keyEvent = NULL;
{
QMutexLocker locker(&timerIdLock);

if (timer_id == keyListTimerId)
{
keyEvent = keyList.dequeue();
if (keyList.empty())
{
KillTimer(keyListTimerId);
keyListTimerId = 0;
}
}
}

if (keyEvent)
{
PlayerContext *actx = GetPlayerWriteLock(-1, __FILE__, __LINE__);
if (actx->HasPlayer())
{
ProcessKeypress(actx, keyEvent);

delete keyEvent;
}
else
{
VERBOSE(VB_IMPORTANT,
"Ignoring key event for now because player is not set");

QMutexLocker locker(&timerIdLock);
keyList.push_front(keyEvent);
if (keyListTimerId)
KillTimer(keyListTimerId);
keyListTimerId = StartTimer(20, __LINE__);
}
ReturnPlayerLock(actx);
handled = true;
}

if (handled)
return;

Expand Down Expand Up @@ -3379,12 +3336,13 @@ bool TV::event(QEvent *e)

if (QEvent::KeyPress == e->type())
{
QKeyEvent *k = new QKeyEvent(*(QKeyEvent *)e);
QMutexLocker locker(&timerIdLock);
keyList.enqueue(k);
if (!keyListTimerId)
keyListTimerId = StartTimer(1, __LINE__);
return true;
bool handled = false;
PlayerContext *actx = GetPlayerWriteLock(-1, __FILE__, __LINE__);
if (actx->HasPlayer())
handled = ProcessKeypress(actx, (QKeyEvent *)e);
ReturnPlayerLock(actx);
if (handled)
return true;
}

switch (e->type())
Expand Down Expand Up @@ -3516,7 +3474,7 @@ static bool has_action(QString action, const QStringList &actions)
return false;
}

void TV::ProcessKeypress(PlayerContext *actx, QKeyEvent *e)
bool TV::ProcessKeypress(PlayerContext *actx, QKeyEvent *e)
{
bool ignoreKeys = actx->IsPlayerChangingBuffers();
#if DEBUG_ACTIONS
Expand All @@ -3539,15 +3497,15 @@ void TV::ProcessKeypress(PlayerContext *actx, QKeyEvent *e)
"TV Playback", e, actions);

if (handled || actions.isEmpty())
return;
return true;

bool esc = has_action("ESCAPE", actions) ||
has_action("BACK", actions);
bool pause = has_action("PAUSE", actions);
bool play = has_action("PLAY", actions);

if ((!esc || browsehelper->IsBrowsing()) && !pause && !play)
return;
return false;
}

OSD *osd = GetOSDLock(actx);
Expand Down Expand Up @@ -3597,7 +3555,7 @@ void TV::ProcessKeypress(PlayerContext *actx, QKeyEvent *e)
}

if (handled)
return;
return true;

// If text is already queued up, be more lax on what is ok.
// This allows hex teletext entry and minor channel entry.
Expand All @@ -3609,7 +3567,7 @@ void TV::ProcessKeypress(PlayerContext *actx, QKeyEvent *e)
if (ok || txt=="_" || txt=="-" || txt=="#" || txt==".")
{
AddKeyToInputQueue(actx, txt.at(0).toLatin1());
return;
return true;
}
}

Expand All @@ -3628,7 +3586,7 @@ void TV::ProcessKeypress(PlayerContext *actx, QKeyEvent *e)
if (actx->player->HandleTeletextAction(tt_actions[i]))
{
actx->UnlockDeletePlayer(__FILE__, __LINE__);
return;
return true;
}
}
}
Expand All @@ -3648,7 +3606,7 @@ void TV::ProcessKeypress(PlayerContext *actx, QKeyEvent *e)
if (actx->player->ITVHandleAction(itv_actions[i]))
{
actx->UnlockDeletePlayer(__FILE__, __LINE__);
return;
return true;
}
}
}
Expand All @@ -3659,7 +3617,7 @@ void TV::ProcessKeypress(PlayerContext *actx, QKeyEvent *e)
"TV Playback", e, actions);

if (handled || actions.isEmpty())
return;
return true;

handled = false;

Expand All @@ -3685,7 +3643,7 @@ void TV::ProcessKeypress(PlayerContext *actx, QKeyEvent *e)
#endif // DEBUG_ACTIONS

if (handled)
return;
return true;

if (!handled)
{
Expand All @@ -3702,6 +3660,8 @@ void TV::ProcessKeypress(PlayerContext *actx, QKeyEvent *e)
}
}
}

return true;
}

bool TV::BrowseHandleAction(PlayerContext *ctx, const QStringList &actions)
Expand Down
4 changes: 1 addition & 3 deletions mythtv/libs/libmythtv/tv_play.h
Expand Up @@ -189,7 +189,7 @@ class MPUBLIC TV : public QObject
bool Init(bool createWindow = true);

// User input processing commands
void ProcessKeypress(PlayerContext*, QKeyEvent *e);
bool ProcessKeypress(PlayerContext*, QKeyEvent *e);
void ProcessNetworkControlCommand(PlayerContext *, const QString &command);
void customEvent(QEvent *e);
bool event(QEvent *e);
Expand Down Expand Up @@ -726,7 +726,6 @@ class MPUBLIC TV : public QObject
int idleDialogTimerId; ///< Timer for idle dialog.

/// Queue of unprocessed key presses.
MythDeque<QKeyEvent*> keyList;
MythTimer keyRepeatTimer; ///< Timeout timer for repeat key filtering

// CC/Teletex input state variables
Expand Down Expand Up @@ -835,7 +834,6 @@ class MPUBLIC TV : public QObject
typedef QMap<int,const PlayerContext*> TimerContextConstMap;
mutable QMutex timerIdLock;
volatile int lcdTimerId;
volatile int keyListTimerId;
volatile int networkControlTimerId;
volatile int jumpMenuTimerId;
volatile int pipChangeTimerId;
Expand Down

0 comments on commit dd981aa

Please sign in to comment.