From: Constantin Kaplinsky Date: Tue, 9 Oct 2007 12:03:15 +0000 (+0000) Subject: Code improvement -- the code from detectVideo() was split into two functions, handleV... X-Git-Tag: v0.0.90~384^2~113 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6bb4bf15b95ff783beee10e869d428edd9bbbd81;p=tigervnc.git Code improvement -- the code from detectVideo() was split into two functions, handleVideo() and detectVideo(). git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2353 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/unix/x0vncserver/PollingManager.cxx b/unix/x0vncserver/PollingManager.cxx index 0ec67349..b2d4757d 100644 --- a/unix/x0vncserver/PollingManager.cxx +++ b/unix/x0vncserver/PollingManager.cxx @@ -164,9 +164,12 @@ bool PollingManager::pollScreen() } // Do the work related to video area detection. - bool videoDetected = detectVideo(mxChanged); + bool haveVideoRect = handleVideo(mxChanged); // Inform the server about the changes. + // FIXME: It's possible that (nTilesChanged != 0) but mxChanged[] + // array is empty. That's possible because handleVideo() + // modifies mxChanged[]. if (nTilesChanged) sendChanges(mxChanged); @@ -179,7 +182,7 @@ bool PollingManager::pollScreen() } #endif - return (nTilesChanged != 0 || videoDetected); + return (nTilesChanged != 0 || haveVideoRect); } int PollingManager::checkRow(int x, int y, int w, bool *pmxChanged) @@ -239,53 +242,18 @@ void PollingManager::sendChanges(bool *pmxChanged) } } -bool PollingManager::detectVideo(bool *pmxChanged) +bool PollingManager::handleVideo(bool *pmxChanged) { - // Configurable parameters. - const int VIDEO_THRESHOLD_0 = 3; - const int VIDEO_THRESHOLD_1 = 5; - - // Each call: update counters in m_rateMatrix. + // 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 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; - } else if (m_rateMatrix[i] >= VIDEO_THRESHOLD_1) { - m_videoFlags[i] = 1; - } - 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); - } + // Once per eight calls: detect video rectangle by examining + // m_rateMatrix[], then reset counters in m_rateMatrix[]. + if (m_pollingStep % 8 == 0) { + detectVideo(); + memset(m_rateMatrix, 0, numTiles); } // Grab the pixels of video area. Also, exclude video rectangle from @@ -305,6 +273,43 @@ bool PollingManager::detectVideo(bool *pmxChanged) return false; // video rectangle is empty } +void +PollingManager::detectVideo() +{ + // Configurable parameters. + const int VIDEO_THRESHOLD_0 = 3; + const int VIDEO_THRESHOLD_1 = 5; + + // 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[]. + int numTiles = m_heightTiles * m_widthTiles; + 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; + } + } + + // 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); + } +} + void PollingManager::getVideoAreaRect(Rect *result) { diff --git a/unix/x0vncserver/PollingManager.h b/unix/x0vncserver/PollingManager.h index 7d5a1230..3f77081d 100644 --- a/unix/x0vncserver/PollingManager.h +++ b/unix/x0vncserver/PollingManager.h @@ -99,7 +99,8 @@ private: int checkRow(int x, int y, int w, bool *pmxChanged); void sendChanges(bool *pmxChanged); - bool detectVideo(bool *pmxChanged); + bool handleVideo(bool *pmxChanged); + void detectVideo(); void getVideoAreaRect(Rect *result);