2016-01-11 21:34:07 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2016-03-02 01:01:11 -08:00
|
|
|
#include <memory>
|
|
|
|
|
|
2016-01-11 21:34:07 -08:00
|
|
|
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
|
|
|
|
|
#include "webrtc/modules/video_processing/include/video_processing.h"
|
|
|
|
|
#include "webrtc/modules/video_processing/test/video_processing_unittest.h"
|
|
|
|
|
#include "webrtc/modules/video_processing/video_denoiser.h"
|
2016-02-29 13:11:45 +01:00
|
|
|
#include "webrtc/test/frame_utils.h"
|
2016-01-11 21:34:07 -08:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2016-04-25 07:36:51 -07:00
|
|
|
TEST_F(VideoProcessingTest, CopyMem) {
|
2016-04-01 07:46:58 -07:00
|
|
|
std::unique_ptr<DenoiserFilter> df_c(DenoiserFilter::Create(false, nullptr));
|
|
|
|
|
std::unique_ptr<DenoiserFilter> df_sse_neon(
|
|
|
|
|
DenoiserFilter::Create(true, nullptr));
|
2016-01-11 21:34:07 -08:00
|
|
|
uint8_t src[16 * 16], dst[16 * 16];
|
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
|
|
|
|
src[i * 16 + j] = i * 16 + j;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(dst, 0, 16 * 16);
|
|
|
|
|
df_c->CopyMem16x16(src, 16, dst, 16);
|
|
|
|
|
EXPECT_EQ(0, memcmp(src, dst, 16 * 16));
|
|
|
|
|
|
|
|
|
|
memset(dst, 0, 16 * 16);
|
|
|
|
|
df_sse_neon->CopyMem16x16(src, 16, dst, 16);
|
|
|
|
|
EXPECT_EQ(0, memcmp(src, dst, 16 * 16));
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-25 07:36:51 -07:00
|
|
|
TEST_F(VideoProcessingTest, Variance) {
|
2016-04-01 07:46:58 -07:00
|
|
|
std::unique_ptr<DenoiserFilter> df_c(DenoiserFilter::Create(false, nullptr));
|
|
|
|
|
std::unique_ptr<DenoiserFilter> df_sse_neon(
|
|
|
|
|
DenoiserFilter::Create(true, nullptr));
|
2016-01-11 21:34:07 -08:00
|
|
|
uint8_t src[16 * 16], dst[16 * 16];
|
|
|
|
|
uint32_t sum = 0, sse = 0, var;
|
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
|
|
|
|
src[i * 16 + j] = i * 16 + j;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Compute the 16x8 variance of the 16x16 block.
|
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
|
|
|
|
sum += (i * 32 + j);
|
|
|
|
|
sse += (i * 32 + j) * (i * 32 + j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var = sse - ((sum * sum) >> 7);
|
|
|
|
|
memset(dst, 0, 16 * 16);
|
|
|
|
|
EXPECT_EQ(var, df_c->Variance16x8(src, 16, dst, 16, &sse));
|
|
|
|
|
EXPECT_EQ(var, df_sse_neon->Variance16x8(src, 16, dst, 16, &sse));
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-25 07:36:51 -07:00
|
|
|
TEST_F(VideoProcessingTest, MbDenoise) {
|
2016-04-01 07:46:58 -07:00
|
|
|
std::unique_ptr<DenoiserFilter> df_c(DenoiserFilter::Create(false, nullptr));
|
|
|
|
|
std::unique_ptr<DenoiserFilter> df_sse_neon(
|
|
|
|
|
DenoiserFilter::Create(true, nullptr));
|
|
|
|
|
uint8_t running_src[16 * 16], src[16 * 16];
|
|
|
|
|
uint8_t dst[16 * 16], dst_sse_neon[16 * 16];
|
2016-01-11 21:34:07 -08:00
|
|
|
|
|
|
|
|
// Test case: |diff| <= |3 + shift_inc1|
|
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
|
|
|
|
running_src[i * 16 + j] = i * 11 + j;
|
|
|
|
|
src[i * 16 + j] = i * 11 + j + 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
memset(dst, 0, 16 * 16);
|
2016-04-12 23:02:55 -07:00
|
|
|
df_c->MbDenoise(running_src, 16, dst, 16, src, 16, 0, 1);
|
2016-04-01 07:46:58 -07:00
|
|
|
memset(dst_sse_neon, 0, 16 * 16);
|
2016-04-12 23:02:55 -07:00
|
|
|
df_sse_neon->MbDenoise(running_src, 16, dst_sse_neon, 16, src, 16, 0, 1);
|
2016-04-01 07:46:58 -07:00
|
|
|
EXPECT_EQ(0, memcmp(dst, dst_sse_neon, 16 * 16));
|
2016-01-11 21:34:07 -08:00
|
|
|
|
|
|
|
|
// Test case: |diff| >= |4 + shift_inc1|
|
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
|
|
|
|
running_src[i * 16 + j] = i * 11 + j;
|
|
|
|
|
src[i * 16 + j] = i * 11 + j + 5;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
memset(dst, 0, 16 * 16);
|
2016-04-12 23:02:55 -07:00
|
|
|
df_c->MbDenoise(running_src, 16, dst, 16, src, 16, 0, 1);
|
2016-04-01 07:46:58 -07:00
|
|
|
memset(dst_sse_neon, 0, 16 * 16);
|
2016-04-12 23:02:55 -07:00
|
|
|
df_sse_neon->MbDenoise(running_src, 16, dst_sse_neon, 16, src, 16, 0, 1);
|
2016-04-01 07:46:58 -07:00
|
|
|
EXPECT_EQ(0, memcmp(dst, dst_sse_neon, 16 * 16));
|
2016-01-11 21:34:07 -08:00
|
|
|
|
|
|
|
|
// Test case: |diff| >= 8
|
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
|
|
|
|
running_src[i * 16 + j] = i * 11 + j;
|
|
|
|
|
src[i * 16 + j] = i * 11 + j + 8;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
memset(dst, 0, 16 * 16);
|
2016-04-12 23:02:55 -07:00
|
|
|
df_c->MbDenoise(running_src, 16, dst, 16, src, 16, 0, 1);
|
2016-04-01 07:46:58 -07:00
|
|
|
memset(dst_sse_neon, 0, 16 * 16);
|
2016-04-12 23:02:55 -07:00
|
|
|
df_sse_neon->MbDenoise(running_src, 16, dst_sse_neon, 16, src, 16, 0, 1);
|
2016-04-01 07:46:58 -07:00
|
|
|
EXPECT_EQ(0, memcmp(dst, dst_sse_neon, 16 * 16));
|
2016-01-11 21:34:07 -08:00
|
|
|
|
|
|
|
|
// Test case: |diff| > 15
|
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
|
|
|
|
running_src[i * 16 + j] = i * 11 + j;
|
|
|
|
|
src[i * 16 + j] = i * 11 + j + 16;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
memset(dst, 0, 16 * 16);
|
|
|
|
|
DenoiserDecision decision =
|
2016-04-12 23:02:55 -07:00
|
|
|
df_c->MbDenoise(running_src, 16, dst, 16, src, 16, 0, 1);
|
2016-01-11 21:34:07 -08:00
|
|
|
EXPECT_EQ(COPY_BLOCK, decision);
|
2016-04-12 23:02:55 -07:00
|
|
|
decision = df_sse_neon->MbDenoise(running_src, 16, dst, 16, src, 16, 0, 1);
|
2016-01-11 21:34:07 -08:00
|
|
|
EXPECT_EQ(COPY_BLOCK, decision);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-25 07:36:51 -07:00
|
|
|
TEST_F(VideoProcessingTest, Denoiser) {
|
2016-04-12 23:02:55 -07:00
|
|
|
// Used in swap buffer.
|
|
|
|
|
int denoised_frame_toggle = 0;
|
2016-01-11 21:34:07 -08:00
|
|
|
// Create pure C denoiser.
|
|
|
|
|
VideoDenoiser denoiser_c(false);
|
|
|
|
|
// Create SSE or NEON denoiser.
|
|
|
|
|
VideoDenoiser denoiser_sse_neon(true);
|
2016-06-17 09:12:44 +02:00
|
|
|
rtc::scoped_refptr<I420Buffer> denoised_frame_c;
|
|
|
|
|
rtc::scoped_refptr<I420Buffer> denoised_frame_prev_c;
|
|
|
|
|
rtc::scoped_refptr<I420Buffer> denoised_frame_sse_neon;
|
|
|
|
|
rtc::scoped_refptr<I420Buffer> denoised_frame_prev_sse_neon;
|
2016-01-11 21:34:07 -08:00
|
|
|
|
2016-03-02 01:01:11 -08:00
|
|
|
std::unique_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
2016-01-11 21:34:07 -08:00
|
|
|
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
|
|
|
|
frame_length_) {
|
|
|
|
|
// Using ConvertToI420 to add stride to the image.
|
Reland of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #1 id:1 of https://codereview.webrtc.org/2354223002/ )
Reason for revert:
Downstream application now fixed.
Original issue's description:
> Revert of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #14 id:260001 of https://codereview.webrtc.org/2278883002/ )
>
> Reason for revert:
> Broke downstream application.
>
> Original issue's description:
> > Move MutableDataY{,U,V} methods to I420Buffer only.
> >
> > Deleted from the VideoFrameBuffer base class.
> >
> > BUG=webrtc:5921
> >
> > Committed: https://crrev.com/5539ef6c03c273f39fadae41ace47fdc11ac6d60
> > Cr-Commit-Position: refs/heads/master@{#14317}
>
> TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5921
>
> Committed: https://crrev.com/776870a2599b8f43ad56987f9031690e3ccecde8
> Cr-Commit-Position: refs/heads/master@{#14325}
TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5921
Review-Url: https://codereview.webrtc.org/2372483002
Cr-Commit-Position: refs/heads/master@{#14389}
2016-09-27 00:17:25 -07:00
|
|
|
rtc::scoped_refptr<webrtc::I420Buffer> input_buffer =
|
|
|
|
|
I420Buffer::Create(width_, height_, width_, half_width_, half_width_);
|
2016-01-11 21:34:07 -08:00
|
|
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
Reland of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #1 id:1 of https://codereview.webrtc.org/2354223002/ )
Reason for revert:
Downstream application now fixed.
Original issue's description:
> Revert of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #14 id:260001 of https://codereview.webrtc.org/2278883002/ )
>
> Reason for revert:
> Broke downstream application.
>
> Original issue's description:
> > Move MutableDataY{,U,V} methods to I420Buffer only.
> >
> > Deleted from the VideoFrameBuffer base class.
> >
> > BUG=webrtc:5921
> >
> > Committed: https://crrev.com/5539ef6c03c273f39fadae41ace47fdc11ac6d60
> > Cr-Commit-Position: refs/heads/master@{#14317}
>
> TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5921
>
> Committed: https://crrev.com/776870a2599b8f43ad56987f9031690e3ccecde8
> Cr-Commit-Position: refs/heads/master@{#14325}
TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5921
Review-Url: https://codereview.webrtc.org/2372483002
Cr-Commit-Position: refs/heads/master@{#14389}
2016-09-27 00:17:25 -07:00
|
|
|
0, kVideoRotation_0, input_buffer.get()));
|
2016-01-11 21:34:07 -08:00
|
|
|
|
2016-06-17 09:12:44 +02:00
|
|
|
rtc::scoped_refptr<I420Buffer>* p_denoised_c = &denoised_frame_c;
|
|
|
|
|
rtc::scoped_refptr<I420Buffer>* p_denoised_prev_c = &denoised_frame_prev_c;
|
|
|
|
|
rtc::scoped_refptr<I420Buffer>* p_denoised_sse_neon =
|
|
|
|
|
&denoised_frame_sse_neon;
|
|
|
|
|
rtc::scoped_refptr<I420Buffer>* p_denoised_prev_sse_neon =
|
|
|
|
|
&denoised_frame_prev_sse_neon;
|
2016-04-12 23:02:55 -07:00
|
|
|
// Swap the buffer to save one memcpy in DenoiseFrame.
|
|
|
|
|
if (denoised_frame_toggle) {
|
|
|
|
|
p_denoised_c = &denoised_frame_prev_c;
|
|
|
|
|
p_denoised_prev_c = &denoised_frame_c;
|
|
|
|
|
p_denoised_sse_neon = &denoised_frame_prev_sse_neon;
|
|
|
|
|
p_denoised_prev_sse_neon = &denoised_frame_sse_neon;
|
|
|
|
|
}
|
Reland of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #1 id:1 of https://codereview.webrtc.org/2354223002/ )
Reason for revert:
Downstream application now fixed.
Original issue's description:
> Revert of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #14 id:260001 of https://codereview.webrtc.org/2278883002/ )
>
> Reason for revert:
> Broke downstream application.
>
> Original issue's description:
> > Move MutableDataY{,U,V} methods to I420Buffer only.
> >
> > Deleted from the VideoFrameBuffer base class.
> >
> > BUG=webrtc:5921
> >
> > Committed: https://crrev.com/5539ef6c03c273f39fadae41ace47fdc11ac6d60
> > Cr-Commit-Position: refs/heads/master@{#14317}
>
> TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5921
>
> Committed: https://crrev.com/776870a2599b8f43ad56987f9031690e3ccecde8
> Cr-Commit-Position: refs/heads/master@{#14325}
TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5921
Review-Url: https://codereview.webrtc.org/2372483002
Cr-Commit-Position: refs/heads/master@{#14389}
2016-09-27 00:17:25 -07:00
|
|
|
denoiser_c.DenoiseFrame(input_buffer, p_denoised_c, p_denoised_prev_c,
|
2016-04-12 23:02:55 -07:00
|
|
|
false);
|
Reland of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #1 id:1 of https://codereview.webrtc.org/2354223002/ )
Reason for revert:
Downstream application now fixed.
Original issue's description:
> Revert of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #14 id:260001 of https://codereview.webrtc.org/2278883002/ )
>
> Reason for revert:
> Broke downstream application.
>
> Original issue's description:
> > Move MutableDataY{,U,V} methods to I420Buffer only.
> >
> > Deleted from the VideoFrameBuffer base class.
> >
> > BUG=webrtc:5921
> >
> > Committed: https://crrev.com/5539ef6c03c273f39fadae41ace47fdc11ac6d60
> > Cr-Commit-Position: refs/heads/master@{#14317}
>
> TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5921
>
> Committed: https://crrev.com/776870a2599b8f43ad56987f9031690e3ccecde8
> Cr-Commit-Position: refs/heads/master@{#14325}
TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5921
Review-Url: https://codereview.webrtc.org/2372483002
Cr-Commit-Position: refs/heads/master@{#14389}
2016-09-27 00:17:25 -07:00
|
|
|
denoiser_sse_neon.DenoiseFrame(input_buffer, p_denoised_sse_neon,
|
2016-04-12 23:02:55 -07:00
|
|
|
p_denoised_prev_sse_neon, false);
|
|
|
|
|
// Invert the flag.
|
|
|
|
|
denoised_frame_toggle ^= 1;
|
2016-01-11 21:34:07 -08:00
|
|
|
// Denoising results should be the same for C and SSE/NEON denoiser.
|
2016-06-17 09:12:44 +02:00
|
|
|
ASSERT_TRUE(test::FrameBufsEqual(*p_denoised_c, *p_denoised_sse_neon));
|
2016-01-11 21:34:07 -08:00
|
|
|
}
|
|
|
|
|
ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|