diff --git a/webrtc/modules/video_processing/main/interface/video_processing.h b/webrtc/modules/video_processing/main/interface/video_processing.h index fbee00d93..1aaade3c3 100644 --- a/webrtc/modules/video_processing/main/interface/video_processing.h +++ b/webrtc/modules/video_processing/main/interface/video_processing.h @@ -266,7 +266,8 @@ public: virtual WebRtc_UWord32 DecimatedHeight() const = 0 ; /** - Set the spatial resampling settings of the VPM: The resampler may either be disabled or one of the following: + Set the spatial resampling settings of the VPM: The resampler may either be + disabled or one of the following: scaling to a close to target dimension followed by crop/pad \param[in] resamplingMode @@ -279,8 +280,8 @@ public: Get Processed (decimated) frame \param[in] frame pointer to the video frame. - - \param[in] processedFrame pointer (double) to the processed frame + \param[in] processedFrame pointer (double) to the processed frame. If no + processing is required, processedFrame will be NULL. \return VPM_OK on success, a negative value on error (see error codes) */ diff --git a/webrtc/modules/video_processing/main/source/frame_preprocessor.cc b/webrtc/modules/video_processing/main/source/frame_preprocessor.cc index 588054165..4b342cefb 100644 --- a/webrtc/modules/video_processing/main/source/frame_preprocessor.cc +++ b/webrtc/modules/video_processing/main/source/frame_preprocessor.cc @@ -152,9 +152,8 @@ VPMFramePreprocessor::PreprocessFrame(const I420VideoFrame& frame, return 1; // drop 1 frame } - // Resizing incoming frame if needed. - // Note that we must make a copy of it. - // We are not allowed to resample the input frame. + // Resizing incoming frame if needed. Otherwise, remains NULL. + // We are not allowed to resample the input frame (must make a copy of it). *processedFrame = NULL; if (_spatialResampler->ApplyResample(frame.width(), frame.height())) { WebRtc_Word32 ret = _spatialResampler->ResampleFrame(frame, diff --git a/webrtc/modules/video_processing/main/source/spatial_resampler.cc b/webrtc/modules/video_processing/main/source/spatial_resampler.cc index 5f1359fa6..207260e49 100644 --- a/webrtc/modules/video_processing/main/source/spatial_resampler.cc +++ b/webrtc/modules/video_processing/main/source/spatial_resampler.cc @@ -65,12 +65,13 @@ WebRtc_Word32 VPMSimpleSpatialResampler::ResampleFrame(const I420VideoFrame& inFrame, I420VideoFrame* outFrame) { + // Don't copy if frame remains as is. if (_resamplingMode == kNoRescaling) - return outFrame->CopyFrame(inFrame); + return VPM_OK; // Check if re-sampling is needed - if ((inFrame.width() == _targetWidth) && + else if ((inFrame.width() == _targetWidth) && (inFrame.height() == _targetHeight)) { - return outFrame->CopyFrame(inFrame); + return VPM_OK; } // Setting scaler diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc index c29808a7e..e4775fc06 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -213,20 +213,31 @@ TEST_F(VideoProcessingModuleTest, FrameStats) TEST_F(VideoProcessingModuleTest, PreprocessorLogic) { - // Disable temporal sampling + // Disable temporal sampling. + int resolution = 100; _vpm->EnableTemporalDecimation(false); - ASSERT_EQ(VPM_OK, _vpm->SetMaxFrameRate(30)); - ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 15)); + EXPECT_EQ(VPM_OK, _vpm->SetMaxFrameRate(30)); + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 15)); // Revert _vpm->EnableTemporalDecimation(true); - ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 30)); - // Disable spatial sampling + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); + // Disable spatial sampling. _vpm->SetInputFrameResampleMode(kNoRescaling); - ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 30)); - I420VideoFrame *outFrame = NULL; - ASSERT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); - // No rescaling=> output frame = NULL - ASSERT_TRUE(outFrame == NULL); + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); + I420VideoFrame* outFrame = NULL; + // Set rescaling => output frame != NULL. + _vpm->SetInputFrameResampleMode(kFastRescaling); + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); + EXPECT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); + EXPECT_FALSE(outFrame == NULL); + if (outFrame) { + EXPECT_EQ(resolution, outFrame->width()); + EXPECT_EQ(resolution, outFrame->height()); + } + // No rescaling=> output frame = NULL. + _vpm->SetInputFrameResampleMode(kNoRescaling); + EXPECT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); + EXPECT_TRUE(outFrame == NULL); } TEST_F(VideoProcessingModuleTest, Resampler)