From 3e2e7038e6c2d338fbfebcb44cf9365cd1396d47 Mon Sep 17 00:00:00 2001 From: "marpan@webrtc.org" Date: Mon, 16 Apr 2012 15:58:14 +0000 Subject: [PATCH] VPM: Allow for option to compute the content metrics every nth frame. Review URL: https://webrtc-codereview.appspot.com/492006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2034 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/source/frame_preprocessor.cc | 19 +++++++++++++------ .../main/source/frame_preprocessor.h | 6 +++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/modules/video_processing/main/source/frame_preprocessor.cc b/src/modules/video_processing/main/source/frame_preprocessor.cc index 76fdac8384..c317528abc 100644 --- a/src/modules/video_processing/main/source/frame_preprocessor.cc +++ b/src/modules/video_processing/main/source/frame_preprocessor.cc @@ -18,7 +18,8 @@ _id(0), _contentMetrics(NULL), _maxFrameRate(0), _resampledFrame(), -_enableCA(false) +_enableCA(false), +_frameCnt(0) { _spatialResampler = new VPMSimpleSpatialResampler(); _ca = new VPMContentAnalysis(true); @@ -49,6 +50,7 @@ VPMFramePreprocessor::Reset() _contentMetrics = NULL; _spatialResampler->Reset(); _enableCA = false; + _frameCnt = 0; } @@ -160,14 +162,19 @@ VPMFramePreprocessor::PreprocessFrame(const VideoFrame* frame, VideoFrame** proc *processedFrame = &_resampledFrame; } - // Perform content analysis on the frame to be encoded + // Perform content analysis on the frame to be encoded. if (_enableCA) { - if (*processedFrame == NULL) { - _contentMetrics = _ca->ComputeContentMetrics(frame); - } else { - _contentMetrics = _ca->ComputeContentMetrics(&_resampledFrame); + // Compute new metrics every |kSkipFramesCA| frames, starting with + // the first frame. + if (_frameCnt % kSkipFrameCA == 0) { + if (*processedFrame == NULL) { + _contentMetrics = _ca->ComputeContentMetrics(frame); + } else { + _contentMetrics = _ca->ComputeContentMetrics(&_resampledFrame); + } } + ++_frameCnt; } return VPM_OK; } diff --git a/src/modules/video_processing/main/source/frame_preprocessor.h b/src/modules/video_processing/main/source/frame_preprocessor.h index 3c07a47e54..2d89c4e7fd 100644 --- a/src/modules/video_processing/main/source/frame_preprocessor.h +++ b/src/modules/video_processing/main/source/frame_preprocessor.h @@ -63,15 +63,19 @@ public: VideoContentMetrics* ContentMetrics() const; private: + // The content does not change so much every frame, so to reduce complexity + // we can compute new content metrics every |kSkipFrameCA| frames. + enum { kSkipFrameCA = 2 }; WebRtc_Word32 _id; VideoContentMetrics* _contentMetrics; WebRtc_UWord32 _maxFrameRate; - VideoFrame _resampledFrame; + VideoFrame _resampledFrame; VPMSpatialResampler* _spatialResampler; VPMContentAnalysis* _ca; VPMVideoDecimator* _vd; bool _enableCA; + int _frameCnt; }; // end of VPMFramePreprocessor class definition