diff options
author | Constantin Kaplinsky <const@tightvnc.com> | 2007-10-09 09:31:41 +0000 |
---|---|---|
committer | Constantin Kaplinsky <const@tightvnc.com> | 2007-10-09 09:31:41 +0000 |
commit | 646998a6ce14321d5facefca84602fbdca9a9e62 (patch) | |
tree | d3428eaa62b952133fc00911f1b289c06d766af8 /unix | |
parent | d0b15c6d15ddf619dbacb99616eee9bb67feb80e (diff) | |
download | tigervnc-646998a6ce14321d5facefca84602fbdca9a9e62.tar.gz tigervnc-646998a6ce14321d5facefca84602fbdca9a9e62.zip |
Optimized detectVideo() function. Now it does the most work only when needed, not each time it's called. The video rectangle (m_videoRect) is now a member variable so it's remembered between calls to poll().
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2352 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'unix')
-rw-r--r-- | unix/x0vncserver/PollingManager.cxx | 61 | ||||
-rw-r--r-- | unix/x0vncserver/PollingManager.h | 1 |
2 files changed, 39 insertions, 23 deletions
diff --git a/unix/x0vncserver/PollingManager.cxx b/unix/x0vncserver/PollingManager.cxx index aff66ff4..0ec67349 100644 --- a/unix/x0vncserver/PollingManager.cxx +++ b/unix/x0vncserver/PollingManager.cxx @@ -250,11 +250,15 @@ bool PollingManager::detectVideo(bool *pmxChanged) for (int i = 0; i < numTiles; i++) m_rateMatrix[i] += (pmxChanged[i] != false); - // Once per eight calls: detect video region. In other words, mark a - // region that consists of continuously changing pixels. Save the - // result in m_videoFlags[] and reset counters in m_rateMatrix[]. + // Once per eight calls: detect video rectangle. bool isGrandStep = (m_pollingStep % 8 == 0); if (isGrandStep) { + // + // First, detect candidate region that looks like video. In other + // words, find a region that consists of continuously changing + // pixels. Save the result in m_videoFlags[] and reset counters in + // m_rateMatrix[]. + // for (int i = 0; i < numTiles; i++) { if (m_rateMatrix[i] <= VIDEO_THRESHOLD_0) { m_videoFlags[i] = 0; @@ -263,26 +267,42 @@ bool PollingManager::detectVideo(bool *pmxChanged) } m_rateMatrix[i] = 0; } + // + // Now, choose the biggest rectangle from that candidate region. + // + Rect newRect; + getVideoAreaRect(&newRect); + // + // Does new rectangle differ from the previously detected one? + // If it does, save new rectangle and inform the server. + // + if (!newRect.equals(m_videoRect)) { + if (newRect.is_empty()) { + fprintf(stderr, "No video detected\n"); + } else { + fprintf(stderr, "Video rect %dx%d\tat(%d,%d)\n", + newRect.width(), newRect.height(), newRect.tl.x, newRect.tl.y); + } + m_videoRect = newRect; + m_server->set_video_area(newRect); + } } - // Choose the biggest rectangle from the region defined by - // m_videoFlags[]. - Rect r; - getVideoAreaRect(&r); - - // Exclude video rectangle from pmxChanged[]. - for (int y = r.tl.y / 32; y < r.br.y / 32; y++) { - for (int x = r.tl.x / 32; x < r.br.x / 32; x++) { - pmxChanged[y * m_widthTiles + x] = false; + // Grab the pixels of video area. Also, exclude video rectangle from + // pmxChanged[], to prevent grabbing the same pixels twice. + if (!m_videoRect.is_empty()) { + Rect r(m_videoRect.tl.x / 32, m_videoRect.tl.y / 32, + m_videoRect.br.x / 32, m_videoRect.br.y / 32); + for (int y = r.tl.y; y < r.br.y; y++) { + for (int x = r.tl.x; x < r.br.x; x++) { + pmxChanged[y * m_widthTiles + x] = false; + } } + getScreenRect(m_videoRect); + return true; // we've got a video rectangle } - // Inform the server... - m_server->set_video_area(r); - if (!r.is_empty()) - getScreenRect(r); - - return (!r.is_empty()); + return false; // video rectangle is empty } void @@ -323,11 +343,6 @@ PollingManager::getVideoAreaRect(Rect *result) if (max_rect.br.y > m_height) max_rect.br.y = m_height; *result = max_rect; - - if (!result->is_empty()) { - fprintf(stderr, "Video rect %dx%d\tat(%d,%d)\n", - result->width(), result->height(), result->tl.x, result->tl.y); - } } void diff --git a/unix/x0vncserver/PollingManager.h b/unix/x0vncserver/PollingManager.h index 1e76acb2..7d5a1230 100644 --- a/unix/x0vncserver/PollingManager.h +++ b/unix/x0vncserver/PollingManager.h @@ -113,6 +113,7 @@ private: char *m_rateMatrix; char *m_videoFlags; + Rect m_videoRect; unsigned int m_pollingStep; static const int m_pollingOrder[]; |