diff options
author | Constantin Kaplinsky <const@tightvnc.com> | 2007-10-08 14:54:18 +0000 |
---|---|---|
committer | Constantin Kaplinsky <const@tightvnc.com> | 2007-10-08 14:54:18 +0000 |
commit | c1984e0e8991f8e1553009ec544a77c2d81746c0 (patch) | |
tree | cf762ec5f9b5b4498749d5ffd1f6d7f3c3e6d936 /unix/x0vncserver/PollingManager.cxx | |
parent | 29d320502679de1452e1145a4e91f4073f067ba5 (diff) | |
download | tigervnc-c1984e0e8991f8e1553009ec544a77c2d81746c0.tar.gz tigervnc-c1984e0e8991f8e1553009ec544a77c2d81746c0.zip |
Combined video detection stuff with new polling code.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2348 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'unix/x0vncserver/PollingManager.cxx')
-rw-r--r-- | unix/x0vncserver/PollingManager.cxx | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/unix/x0vncserver/PollingManager.cxx b/unix/x0vncserver/PollingManager.cxx index d251f5fa..93dce132 100644 --- a/unix/x0vncserver/PollingManager.cxx +++ b/unix/x0vncserver/PollingManager.cxx @@ -259,6 +259,9 @@ bool PollingManager::poll_New() pmxChanged += m_widthTiles; } + // Do the work related to video area detection. + bool videoDetected = detectVideo(mxChanged); + // Inform the server about the changes. if (nTilesChanged) sendChanges(mxChanged); @@ -266,7 +269,13 @@ bool PollingManager::poll_New() // Cleanup. delete[] mxChanged; - return (nTilesChanged != 0); +#ifdef DEBUG + if (nTilesChanged != 0) { + fprintf(stderr, "#%d# ", nTilesChanged); + } +#endif + + return (nTilesChanged != 0 || videoDetected); } int PollingManager::checkRow(int x, int y, int w, bool *pmxChanged) @@ -326,6 +335,52 @@ void PollingManager::sendChanges(bool *pmxChanged) } } +bool PollingManager::detectVideo(bool *pmxChanged) +{ + // Configurable parameters. + const int VIDEO_THRESHOLD_0 = 3; + const int VIDEO_THRESHOLD_1 = 5; + + // Each call: update counters in m_rateMatrix. + int numTiles = m_heightTiles * m_widthTiles; + 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[]. + bool isGrandStep = (m_pollingStep % 8 == 0); + if (isGrandStep) { + for (int i = 0; i < numTiles; i++) { + if (m_rateMatrix[i] <= VIDEO_THRESHOLD_0) { + m_videoFlags[i] = 0; + } else if (m_rateMatrix[i] >= VIDEO_THRESHOLD_1) { + m_videoFlags[i] = 1; + } + m_rateMatrix[i] = 0; + } + } + + // 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; + } + } + + // Inform the server... + m_server->set_video_area(r); + if (!r.is_empty()) + getScreenRect(r); + + return (!r.is_empty()); +} + bool PollingManager::poll_DetectVideo() { if (!m_server) |