Clang format of video_processing folder.
BUG=webrtc:5259 Review URL: https://codereview.webrtc.org/1508793002 Cr-Commit-Position: refs/heads/master@{#10925}
This commit is contained in:
@ -66,8 +66,8 @@ int32_t VPMBrightnessDetection::ProcessFrame(
|
|||||||
for (int h = 0; h < height; h += (1 << stats.sub_sampling_factor)) {
|
for (int h = 0; h < height; h += (1 << stats.sub_sampling_factor)) {
|
||||||
int row = h * width;
|
int row = h * width;
|
||||||
for (int w = 0; w < width; w += (1 << stats.sub_sampling_factor)) {
|
for (int w = 0; w < width; w += (1 << stats.sub_sampling_factor)) {
|
||||||
std_y += (buffer[w + row] - stats.mean) * (buffer[w + row] -
|
std_y +=
|
||||||
stats.mean);
|
(buffer[w + row] - stats.mean) * (buffer[w + row] - stats.mean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std_y = sqrt(std_y / stats.num_pixels);
|
std_y = sqrt(std_y / stats.num_pixels);
|
||||||
@ -82,8 +82,10 @@ int32_t VPMBrightnessDetection::ProcessFrame(
|
|||||||
float posPerc95 = stats.num_pixels * 0.95f;
|
float posPerc95 = stats.num_pixels * 0.95f;
|
||||||
for (uint32_t i = 0; i < 256; i++) {
|
for (uint32_t i = 0; i < 256; i++) {
|
||||||
sum += stats.hist[i];
|
sum += stats.hist[i];
|
||||||
if (sum < pos_perc05) perc05 = i; // 5th perc.
|
if (sum < pos_perc05)
|
||||||
if (sum < pos_median) median_y = i; // 50th perc.
|
perc05 = i; // 5th perc.
|
||||||
|
if (sum < pos_median)
|
||||||
|
median_y = i; // 50th perc.
|
||||||
if (sum < posPerc95)
|
if (sum < posPerc95)
|
||||||
perc95 = i; // 95th perc.
|
perc95 = i; // 95th perc.
|
||||||
else
|
else
|
||||||
|
@ -135,12 +135,12 @@ int32_t VPMContentAnalysis::Initialize(int width, int height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prev_frame_ = new uint8_t[width_ * height_]; // Y only.
|
prev_frame_ = new uint8_t[width_ * height_]; // Y only.
|
||||||
if (prev_frame_ == NULL) return VPM_MEMORY;
|
if (prev_frame_ == NULL)
|
||||||
|
return VPM_MEMORY;
|
||||||
|
|
||||||
return VPM_OK;
|
return VPM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Compute motion metrics: magnitude over non-zero motion vectors,
|
// Compute motion metrics: magnitude over non-zero motion vectors,
|
||||||
// and size of zero cluster
|
// and size of zero cluster
|
||||||
int32_t VPMContentAnalysis::ComputeMotionMetrics() {
|
int32_t VPMContentAnalysis::ComputeMotionMetrics() {
|
||||||
@ -173,21 +173,26 @@ int32_t VPMContentAnalysis::TemporalDiffMetric_C() {
|
|||||||
uint8_t currPixel = orig_frame_[ssn];
|
uint8_t currPixel = orig_frame_[ssn];
|
||||||
uint8_t prevPixel = prev_frame_[ssn];
|
uint8_t prevPixel = prev_frame_[ssn];
|
||||||
|
|
||||||
tempDiffSum += (uint32_t)abs((int16_t)(currPixel - prevPixel));
|
tempDiffSum +=
|
||||||
pixelSum += (uint32_t) currPixel;
|
static_cast<uint32_t>(abs((int16_t)(currPixel - prevPixel)));
|
||||||
pixelSqSum += (uint64_t) (currPixel * currPixel);
|
pixelSum += static_cast<uint32_t>(currPixel);
|
||||||
|
pixelSqSum += static_cast<uint64_t>(currPixel * currPixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default.
|
// Default.
|
||||||
motion_magnitude_ = 0.0f;
|
motion_magnitude_ = 0.0f;
|
||||||
|
|
||||||
if (tempDiffSum == 0) return VPM_OK;
|
if (tempDiffSum == 0)
|
||||||
|
return VPM_OK;
|
||||||
|
|
||||||
// Normalize over all pixels.
|
// Normalize over all pixels.
|
||||||
float const tempDiffAvg = (float)tempDiffSum / (float)(num_pixels);
|
float const tempDiffAvg =
|
||||||
float const pixelSumAvg = (float)pixelSum / (float)(num_pixels);
|
static_cast<float>(tempDiffSum) / static_cast<float>(num_pixels);
|
||||||
float const pixelSqSumAvg = (float)pixelSqSum / (float)(num_pixels);
|
float const pixelSumAvg =
|
||||||
|
static_cast<float>(pixelSum) / static_cast<float>(num_pixels);
|
||||||
|
float const pixelSqSumAvg =
|
||||||
|
static_cast<float>(pixelSqSum) / static_cast<float>(num_pixels);
|
||||||
float contrast = pixelSqSumAvg - (pixelSumAvg * pixelSumAvg);
|
float contrast = pixelSqSumAvg - (pixelSumAvg * pixelSumAvg);
|
||||||
|
|
||||||
if (contrast > 0.0) {
|
if (contrast > 0.0) {
|
||||||
@ -234,21 +239,22 @@ int32_t VPMContentAnalysis::ComputeSpatialMetrics_C() {
|
|||||||
uint8_t rightPixel = orig_frame_[ssn4];
|
uint8_t rightPixel = orig_frame_[ssn4];
|
||||||
uint8_t leftPixel = orig_frame_[ssn5];
|
uint8_t leftPixel = orig_frame_[ssn5];
|
||||||
|
|
||||||
spatialErrSum += (uint32_t) abs((int16_t)(refPixel2
|
spatialErrSum += static_cast<uint32_t>(abs(static_cast<int16_t>(
|
||||||
- (uint16_t)(bottPixel + topPixel + leftPixel + rightPixel)));
|
refPixel2 - static_cast<uint16_t>(bottPixel + topPixel + leftPixel +
|
||||||
spatialErrVSum += (uint32_t) abs((int16_t)(refPixel1
|
rightPixel))));
|
||||||
- (uint16_t)(bottPixel + topPixel)));
|
spatialErrVSum += static_cast<uint32_t>(abs(static_cast<int16_t>(
|
||||||
spatialErrHSum += (uint32_t) abs((int16_t)(refPixel1
|
refPixel1 - static_cast<uint16_t>(bottPixel + topPixel))));
|
||||||
- (uint16_t)(leftPixel + rightPixel)));
|
spatialErrHSum += static_cast<uint32_t>(abs(static_cast<int16_t>(
|
||||||
|
refPixel1 - static_cast<uint16_t>(leftPixel + rightPixel))));
|
||||||
pixelMSA += orig_frame_[ssn1];
|
pixelMSA += orig_frame_[ssn1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize over all pixels.
|
// Normalize over all pixels.
|
||||||
const float spatialErr = (float)(spatialErrSum >> 2);
|
const float spatialErr = static_cast<float>(spatialErrSum >> 2);
|
||||||
const float spatialErrH = (float)(spatialErrHSum >> 1);
|
const float spatialErrH = static_cast<float>(spatialErrHSum >> 1);
|
||||||
const float spatialErrV = (float)(spatialErrVSum >> 1);
|
const float spatialErrV = static_cast<float>(spatialErrVSum >> 1);
|
||||||
const float norm = (float)pixelMSA;
|
const float norm = static_cast<float>(pixelMSA);
|
||||||
|
|
||||||
// 2X2:
|
// 2X2:
|
||||||
spatial_pred_err_ = spatialErr / norm;
|
spatial_pred_err_ = spatialErr / norm;
|
||||||
@ -260,7 +266,8 @@ int32_t VPMContentAnalysis::ComputeSpatialMetrics_C() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VideoContentMetrics* VPMContentAnalysis::ContentMetrics() {
|
VideoContentMetrics* VPMContentAnalysis::ContentMetrics() {
|
||||||
if (ca_Init_ == false) return NULL;
|
if (ca_Init_ == false)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
content_metrics_->spatial_pred_err = spatial_pred_err_;
|
content_metrics_->spatial_pred_err = spatial_pred_err_;
|
||||||
content_metrics_->spatial_pred_err_h = spatial_pred_err_h_;
|
content_metrics_->spatial_pred_err_h = spatial_pred_err_h_;
|
||||||
|
@ -66,8 +66,8 @@ int32_t VPMContentAnalysis::TemporalDiffMetric_SSE2() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add to 64 bit running sum as to not roll over.
|
// Add to 64 bit running sum as to not roll over.
|
||||||
sqsum_64 = _mm_add_epi64(sqsum_64,
|
sqsum_64 =
|
||||||
_mm_add_epi64(_mm_unpackhi_epi32(sqsum_32,z),
|
_mm_add_epi64(sqsum_64, _mm_add_epi64(_mm_unpackhi_epi32(sqsum_32, z),
|
||||||
_mm_unpacklo_epi32(sqsum_32, z)));
|
_mm_unpacklo_epi32(sqsum_32, z)));
|
||||||
|
|
||||||
imgBufO += width_ * skip_num_;
|
imgBufO += width_ * skip_num_;
|
||||||
@ -96,12 +96,16 @@ int32_t VPMContentAnalysis::TemporalDiffMetric_SSE2() {
|
|||||||
// Default.
|
// Default.
|
||||||
motion_magnitude_ = 0.0f;
|
motion_magnitude_ = 0.0f;
|
||||||
|
|
||||||
if (tempDiffSum == 0) return VPM_OK;
|
if (tempDiffSum == 0)
|
||||||
|
return VPM_OK;
|
||||||
|
|
||||||
// Normalize over all pixels.
|
// Normalize over all pixels.
|
||||||
const float tempDiffAvg = (float)tempDiffSum / (float)(num_pixels);
|
const float tempDiffAvg =
|
||||||
const float pixelSumAvg = (float)pixelSum / (float)(num_pixels);
|
static_cast<float>(tempDiffSum) / static_cast<float>(num_pixels);
|
||||||
const float pixelSqSumAvg = (float)pixelSqSum / (float)(num_pixels);
|
const float pixelSumAvg =
|
||||||
|
static_cast<float>(pixelSum) / static_cast<float>(num_pixels);
|
||||||
|
const float pixelSqSumAvg =
|
||||||
|
static_cast<float>(pixelSqSum) / static_cast<float>(num_pixels);
|
||||||
float contrast = pixelSqSumAvg - (pixelSumAvg * pixelSumAvg);
|
float contrast = pixelSqSumAvg - (pixelSumAvg * pixelSumAvg);
|
||||||
|
|
||||||
if (contrast > 0.0) {
|
if (contrast > 0.0) {
|
||||||
@ -163,16 +167,16 @@ int32_t VPMContentAnalysis::ComputeSpatialMetrics_SSE2() {
|
|||||||
__m128i chi = _mm_unpackhi_epi8(c, z);
|
__m128i chi = _mm_unpackhi_epi8(c, z);
|
||||||
|
|
||||||
// left right pixels unpacked and added together
|
// left right pixels unpacked and added together
|
||||||
const __m128i lrlo = _mm_add_epi16(_mm_unpacklo_epi8(l,z),
|
const __m128i lrlo =
|
||||||
_mm_unpacklo_epi8(r,z));
|
_mm_add_epi16(_mm_unpacklo_epi8(l, z), _mm_unpacklo_epi8(r, z));
|
||||||
const __m128i lrhi = _mm_add_epi16(_mm_unpackhi_epi8(l,z),
|
const __m128i lrhi =
|
||||||
_mm_unpackhi_epi8(r,z));
|
_mm_add_epi16(_mm_unpackhi_epi8(l, z), _mm_unpackhi_epi8(r, z));
|
||||||
|
|
||||||
// top & bottom pixels unpacked and added together
|
// top & bottom pixels unpacked and added together
|
||||||
const __m128i tblo = _mm_add_epi16(_mm_unpacklo_epi8(t,z),
|
const __m128i tblo =
|
||||||
_mm_unpacklo_epi8(b,z));
|
_mm_add_epi16(_mm_unpacklo_epi8(t, z), _mm_unpacklo_epi8(b, z));
|
||||||
const __m128i tbhi = _mm_add_epi16(_mm_unpackhi_epi8(t,z),
|
const __m128i tbhi =
|
||||||
_mm_unpackhi_epi8(b,z));
|
_mm_add_epi16(_mm_unpackhi_epi8(t, z), _mm_unpackhi_epi8(b, z));
|
||||||
|
|
||||||
// running sum of all pixels
|
// running sum of all pixels
|
||||||
msa_16 = _mm_add_epi16(msa_16, _mm_add_epi16(chi, clo));
|
msa_16 = _mm_add_epi16(msa_16, _mm_add_epi16(chi, clo));
|
||||||
@ -190,28 +194,31 @@ int32_t VPMContentAnalysis::ComputeSpatialMetrics_SSE2() {
|
|||||||
const __m128i sethi = _mm_subs_epi16(chi, _mm_add_epi16(lrhi, tbhi));
|
const __m128i sethi = _mm_subs_epi16(chi, _mm_add_epi16(lrhi, tbhi));
|
||||||
|
|
||||||
// Add to 16 bit running sum
|
// Add to 16 bit running sum
|
||||||
se_16 = _mm_add_epi16(se_16, _mm_max_epi16(setlo,
|
se_16 =
|
||||||
_mm_subs_epi16(z, setlo)));
|
_mm_add_epi16(se_16, _mm_max_epi16(setlo, _mm_subs_epi16(z, setlo)));
|
||||||
se_16 = _mm_add_epi16(se_16, _mm_max_epi16(sethi,
|
se_16 =
|
||||||
_mm_subs_epi16(z, sethi)));
|
_mm_add_epi16(se_16, _mm_max_epi16(sethi, _mm_subs_epi16(z, sethi)));
|
||||||
sev_16 = _mm_add_epi16(sev_16, _mm_max_epi16(sevtlo,
|
sev_16 = _mm_add_epi16(sev_16,
|
||||||
_mm_subs_epi16(z, sevtlo)));
|
_mm_max_epi16(sevtlo, _mm_subs_epi16(z, sevtlo)));
|
||||||
sev_16 = _mm_add_epi16(sev_16, _mm_max_epi16(sevthi,
|
sev_16 = _mm_add_epi16(sev_16,
|
||||||
_mm_subs_epi16(z, sevthi)));
|
_mm_max_epi16(sevthi, _mm_subs_epi16(z, sevthi)));
|
||||||
seh_16 = _mm_add_epi16(seh_16, _mm_max_epi16(sehtlo,
|
seh_16 = _mm_add_epi16(seh_16,
|
||||||
_mm_subs_epi16(z, sehtlo)));
|
_mm_max_epi16(sehtlo, _mm_subs_epi16(z, sehtlo)));
|
||||||
seh_16 = _mm_add_epi16(seh_16, _mm_max_epi16(sehthi,
|
seh_16 = _mm_add_epi16(seh_16,
|
||||||
_mm_subs_epi16(z, sehthi)));
|
_mm_max_epi16(sehthi, _mm_subs_epi16(z, sehthi)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to 32 bit running sum as to not roll over.
|
// Add to 32 bit running sum as to not roll over.
|
||||||
se_32 = _mm_add_epi32(se_32, _mm_add_epi32(_mm_unpackhi_epi16(se_16, z),
|
se_32 = _mm_add_epi32(se_32, _mm_add_epi32(_mm_unpackhi_epi16(se_16, z),
|
||||||
_mm_unpacklo_epi16(se_16, z)));
|
_mm_unpacklo_epi16(se_16, z)));
|
||||||
sev_32 = _mm_add_epi32(sev_32, _mm_add_epi32(_mm_unpackhi_epi16(sev_16,z),
|
sev_32 =
|
||||||
|
_mm_add_epi32(sev_32, _mm_add_epi32(_mm_unpackhi_epi16(sev_16, z),
|
||||||
_mm_unpacklo_epi16(sev_16, z)));
|
_mm_unpacklo_epi16(sev_16, z)));
|
||||||
seh_32 = _mm_add_epi32(seh_32, _mm_add_epi32(_mm_unpackhi_epi16(seh_16,z),
|
seh_32 =
|
||||||
|
_mm_add_epi32(seh_32, _mm_add_epi32(_mm_unpackhi_epi16(seh_16, z),
|
||||||
_mm_unpacklo_epi16(seh_16, z)));
|
_mm_unpacklo_epi16(seh_16, z)));
|
||||||
msa_32 = _mm_add_epi32(msa_32, _mm_add_epi32(_mm_unpackhi_epi16(msa_16,z),
|
msa_32 =
|
||||||
|
_mm_add_epi32(msa_32, _mm_add_epi32(_mm_unpackhi_epi16(msa_16, z),
|
||||||
_mm_unpacklo_epi16(msa_16, z)));
|
_mm_unpacklo_epi16(msa_16, z)));
|
||||||
|
|
||||||
imgBuf += width_ * skip_num_;
|
imgBuf += width_ * skip_num_;
|
||||||
@ -244,10 +251,10 @@ int32_t VPMContentAnalysis::ComputeSpatialMetrics_SSE2() {
|
|||||||
const uint32_t pixelMSA = msa_64[0] + msa_64[1];
|
const uint32_t pixelMSA = msa_64[0] + msa_64[1];
|
||||||
|
|
||||||
// Normalize over all pixels.
|
// Normalize over all pixels.
|
||||||
const float spatialErr = (float)(spatialErrSum >> 2);
|
const float spatialErr = static_cast<float>(spatialErrSum >> 2);
|
||||||
const float spatialErrH = (float)(spatialErrHSum >> 1);
|
const float spatialErrH = static_cast<float>(spatialErrHSum >> 1);
|
||||||
const float spatialErrV = (float)(spatialErrVSum >> 1);
|
const float spatialErrV = static_cast<float>(spatialErrVSum >> 1);
|
||||||
const float norm = (float)pixelMSA;
|
const float norm = static_cast<float>(pixelMSA);
|
||||||
|
|
||||||
// 2X2:
|
// 2X2:
|
||||||
spatial_pred_err_ = spatialErr / norm;
|
spatial_pred_err_ = spatialErr / norm;
|
||||||
|
@ -40,16 +40,17 @@ enum { kLog2OfDownsamplingFactor = 3 };
|
|||||||
// >> fprintf('%d, ', probUW16)
|
// >> fprintf('%d, ', probUW16)
|
||||||
// Resolution reduced to avoid overflow when multiplying with the
|
// Resolution reduced to avoid overflow when multiplying with the
|
||||||
// (potentially) large number of pixels.
|
// (potentially) large number of pixels.
|
||||||
const uint16_t VPMDeflickering::prob_uw16_[kNumProbs] = {102, 205, 410, 614,
|
const uint16_t VPMDeflickering::prob_uw16_[kNumProbs] = {
|
||||||
819, 1024, 1229, 1434, 1638, 1843, 1946, 1987}; // <Q11>
|
102, 205, 410, 614, 819, 1024,
|
||||||
|
1229, 1434, 1638, 1843, 1946, 1987}; // <Q11>
|
||||||
|
|
||||||
// To generate in Matlab:
|
// To generate in Matlab:
|
||||||
// >> numQuants = 14; maxOnlyLength = 5;
|
// >> numQuants = 14; maxOnlyLength = 5;
|
||||||
// >> weightUW16 = round(2^15 *
|
// >> weightUW16 = round(2^15 *
|
||||||
// [linspace(0.5, 1.0, numQuants - maxOnlyLength)]);
|
// [linspace(0.5, 1.0, numQuants - maxOnlyLength)]);
|
||||||
// >> fprintf('%d, %d,\n ', weightUW16);
|
// >> fprintf('%d, %d,\n ', weightUW16);
|
||||||
const uint16_t VPMDeflickering::weight_uw16_[kNumQuants - kMaxOnlyLength] =
|
const uint16_t VPMDeflickering::weight_uw16_[kNumQuants - kMaxOnlyLength] = {
|
||||||
{16384, 18432, 20480, 22528, 24576, 26624, 28672, 30720, 32768}; // <Q15>
|
16384, 18432, 20480, 22528, 24576, 26624, 28672, 30720, 32768}; // <Q15>
|
||||||
|
|
||||||
VPMDeflickering::VPMDeflickering() {
|
VPMDeflickering::VPMDeflickering() {
|
||||||
Reset();
|
Reset();
|
||||||
@ -70,8 +71,8 @@ void VPMDeflickering::Reset() {
|
|||||||
quant_hist_uw8_[0][kNumQuants - 1] = 255;
|
quant_hist_uw8_[0][kNumQuants - 1] = 255;
|
||||||
for (int32_t i = 0; i < kNumProbs; i++) {
|
for (int32_t i = 0; i < kNumProbs; i++) {
|
||||||
// Unsigned round. <Q0>
|
// Unsigned round. <Q0>
|
||||||
quant_hist_uw8_[0][i + 1] = static_cast<uint8_t>(
|
quant_hist_uw8_[0][i + 1] =
|
||||||
(prob_uw16_[i] * 255 + (1 << 10)) >> 11);
|
static_cast<uint8_t>((prob_uw16_[i] * 255 + (1 << 10)) >> 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 1; i < kFrameHistory_size; i++) {
|
for (int32_t i = 1; i < kFrameHistory_size; i++) {
|
||||||
@ -80,8 +81,7 @@ void VPMDeflickering::Reset() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t VPMDeflickering::ProcessFrame(
|
int32_t VPMDeflickering::ProcessFrame(VideoFrame* frame,
|
||||||
VideoFrame* frame,
|
|
||||||
VideoProcessing::FrameStats* stats) {
|
VideoProcessing::FrameStats* stats) {
|
||||||
assert(frame);
|
assert(frame);
|
||||||
uint32_t frame_memory;
|
uint32_t frame_memory;
|
||||||
@ -111,7 +111,8 @@ int32_t VPMDeflickering::ProcessFrame(
|
|||||||
return VPM_GENERAL_ERROR;
|
return VPM_GENERAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PreDetection(frame->timestamp(), *stats) == -1) return VPM_GENERAL_ERROR;
|
if (PreDetection(frame->timestamp(), *stats) == -1)
|
||||||
|
return VPM_GENERAL_ERROR;
|
||||||
|
|
||||||
// Flicker detection
|
// Flicker detection
|
||||||
int32_t det_flicker = DetectFlicker();
|
int32_t det_flicker = DetectFlicker();
|
||||||
@ -124,13 +125,13 @@ int32_t VPMDeflickering::ProcessFrame(
|
|||||||
// Size of luminance component.
|
// Size of luminance component.
|
||||||
const uint32_t y_size = height * width;
|
const uint32_t y_size = height * width;
|
||||||
|
|
||||||
const uint32_t y_sub_size = width * (((height - 1) >>
|
const uint32_t y_sub_size =
|
||||||
kLog2OfDownsamplingFactor) + 1);
|
width * (((height - 1) >> kLog2OfDownsamplingFactor) + 1);
|
||||||
uint8_t* y_sorted = new uint8_t[y_sub_size];
|
uint8_t* y_sorted = new uint8_t[y_sub_size];
|
||||||
uint32_t sort_row_idx = 0;
|
uint32_t sort_row_idx = 0;
|
||||||
for (int i = 0; i < height; i += kDownsamplingFactor) {
|
for (int i = 0; i < height; i += kDownsamplingFactor) {
|
||||||
memcpy(y_sorted + sort_row_idx * width,
|
memcpy(y_sorted + sort_row_idx * width, frame->buffer(kYPlane) + i * width,
|
||||||
frame->buffer(kYPlane) + i * width, width);
|
width);
|
||||||
sort_row_idx++;
|
sort_row_idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,9 +191,10 @@ int32_t VPMDeflickering::ProcessFrame(
|
|||||||
// target = w * maxquant_uw8 + (1 - w) * minquant_uw8
|
// target = w * maxquant_uw8 + (1 - w) * minquant_uw8
|
||||||
// Weights w = |weight_uw16_| are in Q15, hence the final output has to be
|
// Weights w = |weight_uw16_| are in Q15, hence the final output has to be
|
||||||
// right shifted by 8 to end up in Q7.
|
// right shifted by 8 to end up in Q7.
|
||||||
target_quant_uw16[i] = static_cast<uint16_t>((
|
target_quant_uw16[i] = static_cast<uint16_t>(
|
||||||
weight_uw16_[i] * maxquant_uw8[i] +
|
(weight_uw16_[i] * maxquant_uw8[i] +
|
||||||
((1 << 15) - weight_uw16_[i]) * minquant_uw8[i]) >> 8); // <Q7>
|
((1 << 15) - weight_uw16_[i]) * minquant_uw8[i]) >>
|
||||||
|
8); // <Q7>
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = kNumQuants - kMaxOnlyLength; i < kNumQuants; i++) {
|
for (int32_t i = kNumQuants - kMaxOnlyLength; i < kNumQuants; i++) {
|
||||||
@ -203,12 +205,13 @@ int32_t VPMDeflickering::ProcessFrame(
|
|||||||
uint16_t mapUW16; // <Q7>
|
uint16_t mapUW16; // <Q7>
|
||||||
for (int32_t i = 1; i < kNumQuants; i++) {
|
for (int32_t i = 1; i < kNumQuants; i++) {
|
||||||
// As quant and targetQuant are limited to UWord8, it's safe to use Q7 here.
|
// As quant and targetQuant are limited to UWord8, it's safe to use Q7 here.
|
||||||
tmp_uw32 = static_cast<uint32_t>(target_quant_uw16[i] -
|
tmp_uw32 =
|
||||||
target_quant_uw16[i - 1]);
|
static_cast<uint32_t>(target_quant_uw16[i] - target_quant_uw16[i - 1]);
|
||||||
tmp_uw16 = static_cast<uint16_t>(quant_uw8[i] - quant_uw8[i - 1]); // <Q0>
|
tmp_uw16 = static_cast<uint16_t>(quant_uw8[i] - quant_uw8[i - 1]); // <Q0>
|
||||||
|
|
||||||
if (tmp_uw16 > 0) {
|
if (tmp_uw16 > 0) {
|
||||||
increment_uw16 = static_cast<uint16_t>(WebRtcSpl_DivU32U16(tmp_uw32,
|
increment_uw16 =
|
||||||
|
static_cast<uint16_t>(WebRtcSpl_DivU32U16(tmp_uw32,
|
||||||
tmp_uw16)); // <Q7>
|
tmp_uw16)); // <Q7>
|
||||||
} else {
|
} else {
|
||||||
// The value is irrelevant; the loop below will only iterate once.
|
// The value is irrelevant; the loop below will only iterate once.
|
||||||
@ -247,7 +250,8 @@ int32_t VPMDeflickering::ProcessFrame(
|
|||||||
zero.\n
|
zero.\n
|
||||||
-1: Error
|
-1: Error
|
||||||
*/
|
*/
|
||||||
int32_t VPMDeflickering::PreDetection(const uint32_t timestamp,
|
int32_t VPMDeflickering::PreDetection(
|
||||||
|
const uint32_t timestamp,
|
||||||
const VideoProcessing::FrameStats& stats) {
|
const VideoProcessing::FrameStats& stats) {
|
||||||
int32_t mean_val; // Mean value of frame (Q4)
|
int32_t mean_val; // Mean value of frame (Q4)
|
||||||
uint32_t frame_rate = 0;
|
uint32_t frame_rate = 0;
|
||||||
@ -262,8 +266,8 @@ int32_t VPMDeflickering::PreDetection(const uint32_t timestamp,
|
|||||||
|
|
||||||
// Update timestamp buffer.
|
// Update timestamp buffer.
|
||||||
// This should be done even though we might end up in an unreliable detection.
|
// This should be done even though we might end up in an unreliable detection.
|
||||||
memmove(timestamp_buffer_ + 1, timestamp_buffer_, (kMeanBufferLength - 1) *
|
memmove(timestamp_buffer_ + 1, timestamp_buffer_,
|
||||||
sizeof(uint32_t));
|
(kMeanBufferLength - 1) * sizeof(uint32_t));
|
||||||
timestamp_buffer_[0] = timestamp;
|
timestamp_buffer_[0] = timestamp;
|
||||||
|
|
||||||
/* Compute current frame rate (Q4) */
|
/* Compute current frame rate (Q4) */
|
||||||
@ -322,7 +326,7 @@ int32_t VPMDeflickering::DetectFlicker() {
|
|||||||
/* Sanity check for mean_buffer_length_ */
|
/* Sanity check for mean_buffer_length_ */
|
||||||
if (mean_buffer_length_ < 2) {
|
if (mean_buffer_length_ < 2) {
|
||||||
/* Not possible to estimate frequency */
|
/* Not possible to estimate frequency */
|
||||||
return(2);
|
return 2;
|
||||||
}
|
}
|
||||||
// Count zero crossings with a dead zone to be robust against noise. If the
|
// Count zero crossings with a dead zone to be robust against noise. If the
|
||||||
// noise std is 2 pixel this corresponds to about 95% confidence interval.
|
// noise std is 2 pixel this corresponds to about 95% confidence interval.
|
||||||
|
@ -53,15 +53,17 @@ void VPMFramePreprocessor::SetInputFrameResampleMode(
|
|||||||
spatial_resampler_->SetInputFrameResampleMode(resampling_mode);
|
spatial_resampler_->SetInputFrameResampleMode(resampling_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t VPMFramePreprocessor::SetTargetResolution(
|
int32_t VPMFramePreprocessor::SetTargetResolution(uint32_t width,
|
||||||
uint32_t width, uint32_t height, uint32_t frame_rate) {
|
uint32_t height,
|
||||||
|
uint32_t frame_rate) {
|
||||||
if ((width == 0) || (height == 0) || (frame_rate == 0)) {
|
if ((width == 0) || (height == 0) || (frame_rate == 0)) {
|
||||||
return VPM_PARAMETER_ERROR;
|
return VPM_PARAMETER_ERROR;
|
||||||
}
|
}
|
||||||
int32_t ret_val = 0;
|
int32_t ret_val = 0;
|
||||||
ret_val = spatial_resampler_->SetTargetFrameSize(width, height);
|
ret_val = spatial_resampler_->SetTargetFrameSize(width, height);
|
||||||
|
|
||||||
if (ret_val < 0) return ret_val;
|
if (ret_val < 0)
|
||||||
|
return ret_val;
|
||||||
|
|
||||||
vd_->SetTargetFramerate(frame_rate);
|
vd_->SetTargetFramerate(frame_rate);
|
||||||
return VPM_OK;
|
return VPM_OK;
|
||||||
@ -84,12 +86,10 @@ uint32_t VPMFramePreprocessor::GetDecimatedFrameRate() {
|
|||||||
return vd_->GetDecimatedFrameRate();
|
return vd_->GetDecimatedFrameRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t VPMFramePreprocessor::GetDecimatedWidth() const {
|
uint32_t VPMFramePreprocessor::GetDecimatedWidth() const {
|
||||||
return spatial_resampler_->TargetWidth();
|
return spatial_resampler_->TargetWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t VPMFramePreprocessor::GetDecimatedHeight() const {
|
uint32_t VPMFramePreprocessor::GetDecimatedHeight() const {
|
||||||
return spatial_resampler_->TargetHeight();
|
return spatial_resampler_->TargetHeight();
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,8 @@ class VPMFramePreprocessor {
|
|||||||
void EnableContentAnalysis(bool enable);
|
void EnableContentAnalysis(bool enable);
|
||||||
|
|
||||||
// Set target resolution: frame rate and dimension.
|
// Set target resolution: frame rate and dimension.
|
||||||
int32_t SetTargetResolution(uint32_t width, uint32_t height,
|
int32_t SetTargetResolution(uint32_t width,
|
||||||
|
uint32_t height,
|
||||||
uint32_t frame_rate);
|
uint32_t frame_rate);
|
||||||
|
|
||||||
// Set target frame rate.
|
// Set target frame rate.
|
||||||
|
@ -8,13 +8,6 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* video_processing.h
|
|
||||||
* This header file contains the API required for the video
|
|
||||||
* processing module class.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_
|
#ifndef WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_
|
||||||
#define WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_
|
#define WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_
|
||||||
|
|
||||||
@ -43,11 +36,7 @@ class VideoProcessing {
|
|||||||
uint32_t sub_sampling_factor; // Sub-sampling factor, in powers of 2.
|
uint32_t sub_sampling_factor; // Sub-sampling factor, in powers of 2.
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BrightnessWarning {
|
enum BrightnessWarning { kNoWarning, kDarkWarning, kBrightWarning };
|
||||||
kNoWarning,
|
|
||||||
kDarkWarning,
|
|
||||||
kBrightWarning
|
|
||||||
};
|
|
||||||
|
|
||||||
static VideoProcessing* Create();
|
static VideoProcessing* Create();
|
||||||
virtual ~VideoProcessing() {}
|
virtual ~VideoProcessing() {}
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#include "webrtc/modules/video_processing/spatial_resampler.h"
|
#include "webrtc/modules/video_processing/spatial_resampler.h"
|
||||||
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
VPMSimpleSpatialResampler::VPMSimpleSpatialResampler()
|
VPMSimpleSpatialResampler::VPMSimpleSpatialResampler()
|
||||||
@ -21,12 +20,13 @@ VPMSimpleSpatialResampler::VPMSimpleSpatialResampler()
|
|||||||
|
|
||||||
VPMSimpleSpatialResampler::~VPMSimpleSpatialResampler() {}
|
VPMSimpleSpatialResampler::~VPMSimpleSpatialResampler() {}
|
||||||
|
|
||||||
|
|
||||||
int32_t VPMSimpleSpatialResampler::SetTargetFrameSize(int32_t width,
|
int32_t VPMSimpleSpatialResampler::SetTargetFrameSize(int32_t width,
|
||||||
int32_t height) {
|
int32_t height) {
|
||||||
if (resampling_mode_ == kNoRescaling) return VPM_OK;
|
if (resampling_mode_ == kNoRescaling)
|
||||||
|
return VPM_OK;
|
||||||
|
|
||||||
if (width < 1 || height < 1) return VPM_PARAMETER_ERROR;
|
if (width < 1 || height < 1)
|
||||||
|
return VPM_PARAMETER_ERROR;
|
||||||
|
|
||||||
target_width_ = width;
|
target_width_ = width;
|
||||||
target_height_ = height;
|
target_height_ = height;
|
||||||
@ -48,10 +48,10 @@ void VPMSimpleSpatialResampler::Reset() {
|
|||||||
int32_t VPMSimpleSpatialResampler::ResampleFrame(const VideoFrame& inFrame,
|
int32_t VPMSimpleSpatialResampler::ResampleFrame(const VideoFrame& inFrame,
|
||||||
VideoFrame* outFrame) {
|
VideoFrame* outFrame) {
|
||||||
// Don't copy if frame remains as is.
|
// Don't copy if frame remains as is.
|
||||||
if (resampling_mode_ == kNoRescaling)
|
if (resampling_mode_ == kNoRescaling) {
|
||||||
return VPM_OK;
|
return VPM_OK;
|
||||||
// Check if re-sampling is needed
|
// Check if re-sampling is needed
|
||||||
else if ((inFrame.width() == target_width_) &&
|
} else if ((inFrame.width() == target_width_) &&
|
||||||
(inFrame.height() == target_height_)) {
|
(inFrame.height() == target_height_)) {
|
||||||
return VPM_OK;
|
return VPM_OK;
|
||||||
}
|
}
|
||||||
@ -60,8 +60,8 @@ int32_t VPMSimpleSpatialResampler::ResampleFrame(const VideoFrame& inFrame,
|
|||||||
// TODO(mikhal/marpan): Should we allow for setting the filter mode in
|
// TODO(mikhal/marpan): Should we allow for setting the filter mode in
|
||||||
// _scale.Set() with |resampling_mode_|?
|
// _scale.Set() with |resampling_mode_|?
|
||||||
int ret_val = 0;
|
int ret_val = 0;
|
||||||
ret_val = scaler_.Set(inFrame.width(), inFrame.height(),
|
ret_val = scaler_.Set(inFrame.width(), inFrame.height(), target_width_,
|
||||||
target_width_, target_height_, kI420, kI420, kScaleBox);
|
target_height_, kI420, kI420, kScaleBox);
|
||||||
if (ret_val < 0)
|
if (ret_val < 0)
|
||||||
return ret_val;
|
return ret_val;
|
||||||
|
|
||||||
@ -86,8 +86,7 @@ int32_t VPMSimpleSpatialResampler::TargetWidth() {
|
|||||||
return target_width_;
|
return target_width_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VPMSimpleSpatialResampler::ApplyResample(int32_t width,
|
bool VPMSimpleSpatialResampler::ApplyResample(int32_t width, int32_t height) {
|
||||||
int32_t height) {
|
|
||||||
if ((width == target_width_ && height == target_height_) ||
|
if ((width == target_width_ && height == target_height_) ||
|
||||||
resampling_mode_ == kNoRescaling)
|
resampling_mode_ == kNoRescaling)
|
||||||
return false;
|
return false;
|
||||||
|
@ -23,10 +23,10 @@ namespace webrtc {
|
|||||||
|
|
||||||
class VPMSpatialResampler {
|
class VPMSpatialResampler {
|
||||||
public:
|
public:
|
||||||
virtual ~VPMSpatialResampler() {};
|
virtual ~VPMSpatialResampler() {}
|
||||||
virtual int32_t SetTargetFrameSize(int32_t width, int32_t height) = 0;
|
virtual int32_t SetTargetFrameSize(int32_t width, int32_t height) = 0;
|
||||||
virtual void SetInputFrameResampleMode(VideoFrameResampling
|
virtual void SetInputFrameResampleMode(
|
||||||
resampling_mode) = 0;
|
VideoFrameResampling resampling_mode) = 0;
|
||||||
virtual void Reset() = 0;
|
virtual void Reset() = 0;
|
||||||
virtual int32_t ResampleFrame(const VideoFrame& inFrame,
|
virtual int32_t ResampleFrame(const VideoFrame& inFrame,
|
||||||
VideoFrame* outFrame) = 0;
|
VideoFrame* outFrame) = 0;
|
||||||
@ -49,7 +49,6 @@ class VPMSimpleSpatialResampler : public VPMSpatialResampler {
|
|||||||
virtual bool ApplyResample(int32_t width, int32_t height);
|
virtual bool ApplyResample(int32_t width, int32_t height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
VideoFrameResampling resampling_mode_;
|
VideoFrameResampling resampling_mode_;
|
||||||
int32_t target_width_;
|
int32_t target_width_;
|
||||||
int32_t target_height_;
|
int32_t target_height_;
|
||||||
|
@ -22,14 +22,14 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(BrightnessDetection)) {
|
|||||||
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
||||||
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
||||||
frame_length_) {
|
frame_length_) {
|
||||||
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
||||||
height_, 0, kVideoRotation_0, &video_frame_));
|
0, kVideoRotation_0, &video_frame_));
|
||||||
frameNum++;
|
frameNum++;
|
||||||
VideoProcessing::FrameStats stats;
|
VideoProcessing::FrameStats stats;
|
||||||
vp_->GetFrameStats(video_frame_, &stats);
|
vp_->GetFrameStats(video_frame_, &stats);
|
||||||
EXPECT_GT(stats.num_pixels, 0u);
|
EXPECT_GT(stats.num_pixels, 0u);
|
||||||
ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_,
|
ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, stats),
|
||||||
stats), 0);
|
0);
|
||||||
if (brightnessWarning != VideoProcessing::kNoWarning) {
|
if (brightnessWarning != VideoProcessing::kNoWarning) {
|
||||||
warningCount++;
|
warningCount++;
|
||||||
}
|
}
|
||||||
@ -48,8 +48,8 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(BrightnessDetection)) {
|
|||||||
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
||||||
frame_length_ &&
|
frame_length_ &&
|
||||||
frameNum < 300) {
|
frameNum < 300) {
|
||||||
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
||||||
height_, 0, kVideoRotation_0, &video_frame_));
|
0, kVideoRotation_0, &video_frame_));
|
||||||
frameNum++;
|
frameNum++;
|
||||||
|
|
||||||
uint8_t* frame = video_frame_.buffer(kYPlane);
|
uint8_t* frame = video_frame_.buffer(kYPlane);
|
||||||
@ -65,8 +65,8 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(BrightnessDetection)) {
|
|||||||
VideoProcessing::FrameStats stats;
|
VideoProcessing::FrameStats stats;
|
||||||
vp_->GetFrameStats(video_frame_, &stats);
|
vp_->GetFrameStats(video_frame_, &stats);
|
||||||
EXPECT_GT(stats.num_pixels, 0u);
|
EXPECT_GT(stats.num_pixels, 0u);
|
||||||
ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_,
|
ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, stats),
|
||||||
stats), 0);
|
0);
|
||||||
EXPECT_NE(VideoProcessing::kDarkWarning, brightnessWarning);
|
EXPECT_NE(VideoProcessing::kDarkWarning, brightnessWarning);
|
||||||
if (brightnessWarning == VideoProcessing::kBrightWarning) {
|
if (brightnessWarning == VideoProcessing::kBrightWarning) {
|
||||||
warningCount++;
|
warningCount++;
|
||||||
@ -83,9 +83,10 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(BrightnessDetection)) {
|
|||||||
frameNum = 0;
|
frameNum = 0;
|
||||||
warningCount = 0;
|
warningCount = 0;
|
||||||
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
||||||
frame_length_ && frameNum < 300) {
|
frame_length_ &&
|
||||||
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
|
frameNum < 300) {
|
||||||
height_, 0, kVideoRotation_0, &video_frame_));
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
||||||
|
0, kVideoRotation_0, &video_frame_));
|
||||||
frameNum++;
|
frameNum++;
|
||||||
|
|
||||||
uint8_t* y_plane = video_frame_.buffer(kYPlane);
|
uint8_t* y_plane = video_frame_.buffer(kYPlane);
|
||||||
@ -98,8 +99,8 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(BrightnessDetection)) {
|
|||||||
VideoProcessing::FrameStats stats;
|
VideoProcessing::FrameStats stats;
|
||||||
vp_->GetFrameStats(video_frame_, &stats);
|
vp_->GetFrameStats(video_frame_, &stats);
|
||||||
EXPECT_GT(stats.num_pixels, 0u);
|
EXPECT_GT(stats.num_pixels, 0u);
|
||||||
ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_,
|
ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, stats),
|
||||||
stats), 0);
|
0);
|
||||||
EXPECT_NE(VideoProcessing::kBrightWarning, brightnessWarning);
|
EXPECT_NE(VideoProcessing::kBrightWarning, brightnessWarning);
|
||||||
if (brightnessWarning == VideoProcessing::kDarkWarning) {
|
if (brightnessWarning == VideoProcessing::kDarkWarning) {
|
||||||
warningCount++;
|
warningCount++;
|
||||||
|
@ -26,8 +26,8 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(ContentAnalysis)) {
|
|||||||
ca__sse.Initialize(width_, height_);
|
ca__sse.Initialize(width_, height_);
|
||||||
|
|
||||||
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
||||||
while (fread(video_buffer.get(), 1, frame_length_, source_file_)
|
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
||||||
== frame_length_) {
|
frame_length_) {
|
||||||
// Using ConvertToI420 to add stride to the image.
|
// Using ConvertToI420 to add stride to the image.
|
||||||
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
||||||
0, kVideoRotation_0, &video_frame_));
|
0, kVideoRotation_0, &video_frame_));
|
||||||
|
@ -33,14 +33,14 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(Deflickering)) {
|
|||||||
const std::string input_file =
|
const std::string input_file =
|
||||||
webrtc::test::ResourcePath("deflicker_before_cif_short", "yuv");
|
webrtc::test::ResourcePath("deflicker_before_cif_short", "yuv");
|
||||||
source_file_ = fopen(input_file.c_str(), "rb");
|
source_file_ = fopen(input_file.c_str(), "rb");
|
||||||
ASSERT_TRUE(source_file_ != NULL) <<
|
ASSERT_TRUE(source_file_ != NULL) << "Cannot read input file: " << input_file
|
||||||
"Cannot read input file: " << input_file << "\n";
|
<< "\n";
|
||||||
|
|
||||||
const std::string output_file =
|
const std::string output_file =
|
||||||
webrtc::test::OutputPath() + "deflicker_output_cif_short.yuv";
|
webrtc::test::OutputPath() + "deflicker_output_cif_short.yuv";
|
||||||
FILE* deflickerFile = fopen(output_file.c_str(), "wb");
|
FILE* deflickerFile = fopen(output_file.c_str(), "wb");
|
||||||
ASSERT_TRUE(deflickerFile != NULL) <<
|
ASSERT_TRUE(deflickerFile != NULL)
|
||||||
"Could not open output file: " << output_file << "\n";
|
<< "Could not open output file: " << output_file << "\n";
|
||||||
|
|
||||||
printf("\nRun time [us / frame]:\n");
|
printf("\nRun time [us / frame]:\n");
|
||||||
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
||||||
@ -54,8 +54,7 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(Deflickering)) {
|
|||||||
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
||||||
frame_length_) {
|
frame_length_) {
|
||||||
frameNum++;
|
frameNum++;
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
|
||||||
0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
|
|
||||||
height_, 0, kVideoRotation_0, &video_frame_));
|
height_, 0, kVideoRotation_0, &video_frame_));
|
||||||
video_frame_.set_timestamp(timeStamp);
|
video_frame_.set_timestamp(timeStamp);
|
||||||
|
|
||||||
|
@ -79,8 +79,8 @@ void VideoProcessingTest::SetUp() {
|
|||||||
const std::string video_file =
|
const std::string video_file =
|
||||||
webrtc::test::ResourcePath("foreman_cif", "yuv");
|
webrtc::test::ResourcePath("foreman_cif", "yuv");
|
||||||
source_file_ = fopen(video_file.c_str(), "rb");
|
source_file_ = fopen(video_file.c_str(), "rb");
|
||||||
ASSERT_TRUE(source_file_ != NULL) <<
|
ASSERT_TRUE(source_file_ != NULL)
|
||||||
"Cannot read source file: " + video_file + "\n";
|
<< "Cannot read source file: " + video_file + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoProcessingTest::TearDown() {
|
void VideoProcessingTest::TearDown() {
|
||||||
@ -110,8 +110,8 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(HandleBadStats)) {
|
|||||||
VideoProcessing::FrameStats stats;
|
VideoProcessing::FrameStats stats;
|
||||||
vp_->ClearFrameStats(&stats);
|
vp_->ClearFrameStats(&stats);
|
||||||
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
||||||
ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_,
|
ASSERT_EQ(frame_length_,
|
||||||
source_file_));
|
fread(video_buffer.get(), 1, frame_length_, source_file_));
|
||||||
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
||||||
0, kVideoRotation_0, &video_frame_));
|
0, kVideoRotation_0, &video_frame_));
|
||||||
|
|
||||||
@ -125,8 +125,8 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(IdenticalResultsAfterReset)) {
|
|||||||
VideoProcessing::FrameStats stats;
|
VideoProcessing::FrameStats stats;
|
||||||
// Only testing non-static functions here.
|
// Only testing non-static functions here.
|
||||||
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
||||||
ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_,
|
ASSERT_EQ(frame_length_,
|
||||||
source_file_));
|
fread(video_buffer.get(), 1, frame_length_, source_file_));
|
||||||
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
||||||
0, kVideoRotation_0, &video_frame_));
|
0, kVideoRotation_0, &video_frame_));
|
||||||
vp_->GetFrameStats(video_frame_, &stats);
|
vp_->GetFrameStats(video_frame_, &stats);
|
||||||
@ -140,8 +140,8 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(IdenticalResultsAfterReset)) {
|
|||||||
ASSERT_EQ(0, vp_->Deflickering(&video_frame2, &stats));
|
ASSERT_EQ(0, vp_->Deflickering(&video_frame2, &stats));
|
||||||
EXPECT_TRUE(CompareFrames(video_frame_, video_frame2));
|
EXPECT_TRUE(CompareFrames(video_frame_, video_frame2));
|
||||||
|
|
||||||
ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_,
|
ASSERT_EQ(frame_length_,
|
||||||
source_file_));
|
fread(video_buffer.get(), 1, frame_length_, source_file_));
|
||||||
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
||||||
0, kVideoRotation_0, &video_frame_));
|
0, kVideoRotation_0, &video_frame_));
|
||||||
vp_->GetFrameStats(video_frame_, &stats);
|
vp_->GetFrameStats(video_frame_, &stats);
|
||||||
@ -157,8 +157,8 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(FrameStats)) {
|
|||||||
VideoProcessing::FrameStats stats;
|
VideoProcessing::FrameStats stats;
|
||||||
vp_->ClearFrameStats(&stats);
|
vp_->ClearFrameStats(&stats);
|
||||||
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
||||||
ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_,
|
ASSERT_EQ(frame_length_,
|
||||||
source_file_));
|
fread(video_buffer.get(), 1, frame_length_, source_file_));
|
||||||
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
||||||
0, kVideoRotation_0, &video_frame_));
|
0, kVideoRotation_0, &video_frame_));
|
||||||
|
|
||||||
@ -204,8 +204,7 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(Resampler)) {
|
|||||||
int64_t total_runtime = 0;
|
int64_t total_runtime = 0;
|
||||||
|
|
||||||
rewind(source_file_);
|
rewind(source_file_);
|
||||||
ASSERT_TRUE(source_file_ != NULL) <<
|
ASSERT_TRUE(source_file_ != NULL) << "Cannot read input file \n";
|
||||||
"Cannot read input file \n";
|
|
||||||
|
|
||||||
// CA not needed here
|
// CA not needed here
|
||||||
vp_->EnableContentAnalysis(false);
|
vp_->EnableContentAnalysis(false);
|
||||||
@ -214,8 +213,8 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(Resampler)) {
|
|||||||
|
|
||||||
// Reading test frame
|
// Reading test frame
|
||||||
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
||||||
ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_,
|
ASSERT_EQ(frame_length_,
|
||||||
source_file_));
|
fread(video_buffer.get(), 1, frame_length_, source_file_));
|
||||||
// Using ConvertToI420 to add stride to the image.
|
// Using ConvertToI420 to add stride to the image.
|
||||||
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
|
||||||
0, kVideoRotation_0, &video_frame_));
|
0, kVideoRotation_0, &video_frame_));
|
||||||
@ -281,8 +280,7 @@ TEST_F(VideoProcessingTest, DISABLED_ON_IOS(Resampler)) {
|
|||||||
|
|
||||||
printf("\nAverage run time = %d us / frame\n",
|
printf("\nAverage run time = %d us / frame\n",
|
||||||
static_cast<int>(total_runtime));
|
static_cast<int>(total_runtime));
|
||||||
printf("Min run time = %d us / frame\n\n",
|
printf("Min run time = %d us / frame\n\n", static_cast<int>(min_runtime));
|
||||||
static_cast<int>(min_runtime));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreprocessFrameAndVerify(const VideoFrame& source,
|
void PreprocessFrameAndVerify(const VideoFrame& source,
|
||||||
@ -349,10 +347,11 @@ void TestSize(const VideoFrame& source_frame,
|
|||||||
// Compute PSNR against the cropped source frame and check expectation.
|
// Compute PSNR against the cropped source frame and check expectation.
|
||||||
double psnr = I420PSNR(&cropped_source_frame, out_frame);
|
double psnr = I420PSNR(&cropped_source_frame, out_frame);
|
||||||
EXPECT_GT(psnr, expected_psnr);
|
EXPECT_GT(psnr, expected_psnr);
|
||||||
printf("PSNR: %f. PSNR is between source of size %d %d, and a modified "
|
printf(
|
||||||
|
"PSNR: %f. PSNR is between source of size %d %d, and a modified "
|
||||||
"source which is scaled down/up to: %d %d, and back to source size \n",
|
"source which is scaled down/up to: %d %d, and back to source size \n",
|
||||||
psnr, source_frame.width(), source_frame.height(),
|
psnr, source_frame.width(), source_frame.height(), target_width,
|
||||||
target_width, target_height);
|
target_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompareFrames(const webrtc::VideoFrame& frame1,
|
bool CompareFrames(const webrtc::VideoFrame& frame1,
|
||||||
|
@ -30,9 +30,7 @@ class VideoProcessingTest : public ::testing::Test {
|
|||||||
std::string trace_file = webrtc::test::OutputPath() + "VPMTrace.txt";
|
std::string trace_file = webrtc::test::OutputPath() + "VPMTrace.txt";
|
||||||
ASSERT_EQ(0, Trace::SetTraceFile(trace_file.c_str()));
|
ASSERT_EQ(0, Trace::SetTraceFile(trace_file.c_str()));
|
||||||
}
|
}
|
||||||
static void TearDownTestCase() {
|
static void TearDownTestCase() { Trace::ReturnTrace(); }
|
||||||
Trace::ReturnTrace();
|
|
||||||
}
|
|
||||||
VideoProcessing* vp_;
|
VideoProcessing* vp_;
|
||||||
FILE* source_file_;
|
FILE* source_file_;
|
||||||
VideoFrame video_frame_;
|
VideoFrame video_frame_;
|
||||||
|
@ -27,8 +27,7 @@ DenoiserFilter* DenoiserFilter::Create() {
|
|||||||
#if defined(WEBRTC_ARCH_X86_FAMILY)
|
#if defined(WEBRTC_ARCH_X86_FAMILY)
|
||||||
// x86 CPU detection required.
|
// x86 CPU detection required.
|
||||||
if (WebRtc_GetCPUInfo(kSSE2)) {
|
if (WebRtc_GetCPUInfo(kSSE2)) {
|
||||||
filter =
|
filter = new DenoiserFilterSSE2();
|
||||||
new DenoiserFilterSSE2();
|
|
||||||
} else {
|
} else {
|
||||||
filter = new DenoiserFilterC();
|
filter = new DenoiserFilterC();
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,6 @@ class DenoiserFilterC : public DenoiserFilter {
|
|||||||
int increase_denoising) override;
|
int increase_denoising) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif // WEBRTC_MODULES_VIDEO_PROCESSING_UTIL_DENOISER_FILTER_C_H_
|
#endif // WEBRTC_MODULES_VIDEO_PROCESSING_UTIL_DENOISER_FILTER_C_H_
|
||||||
|
@ -58,8 +58,8 @@ static void VarianceNeonW8(const uint8_t* a,
|
|||||||
}
|
}
|
||||||
|
|
||||||
*sum = HorizontalAddS16x8(v_sum);
|
*sum = HorizontalAddS16x8(v_sum);
|
||||||
*sse = static_cast<uint32_t>(
|
*sse =
|
||||||
HorizontalAddS32x4(vaddq_s32(v_sse_lo, v_sse_hi)));
|
static_cast<uint32_t>(HorizontalAddS32x4(vaddq_s32(v_sse_lo, v_sse_hi)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DenoiserFilterNEON::CopyMem16x16(const uint8_t* src,
|
void DenoiserFilterNEON::CopyMem16x16(const uint8_t* src,
|
||||||
@ -111,8 +111,7 @@ DenoiserDecision DenoiserFilterNEON::MbDenoise(uint8_t* mc_running_avg_y,
|
|||||||
// increasing the adjustment for each level, level1 adjustment is
|
// increasing the adjustment for each level, level1 adjustment is
|
||||||
// increased, the deltas stay the same.
|
// increased, the deltas stay the same.
|
||||||
int shift_inc =
|
int shift_inc =
|
||||||
(increase_denoising && motion_magnitude <= kMotionMagnitudeThreshold)
|
(increase_denoising && motion_magnitude <= kMotionMagnitudeThreshold) ? 1
|
||||||
? 1
|
|
||||||
: 0;
|
: 0;
|
||||||
const uint8x16_t v_level1_adjustment = vmovq_n_u8(
|
const uint8x16_t v_level1_adjustment = vmovq_n_u8(
|
||||||
(motion_magnitude <= kMotionMagnitudeThreshold) ? 4 + shift_inc : 3);
|
(motion_magnitude <= kMotionMagnitudeThreshold) ? 4 + shift_inc : 3);
|
||||||
|
@ -141,8 +141,7 @@ DenoiserDecision DenoiserFilterSSE2::MbDenoise(uint8_t* mc_running_avg_y,
|
|||||||
uint8_t motion_magnitude,
|
uint8_t motion_magnitude,
|
||||||
int increase_denoising) {
|
int increase_denoising) {
|
||||||
int shift_inc =
|
int shift_inc =
|
||||||
(increase_denoising && motion_magnitude <= kMotionMagnitudeThreshold)
|
(increase_denoising && motion_magnitude <= kMotionMagnitudeThreshold) ? 1
|
||||||
? 1
|
|
||||||
: 0;
|
: 0;
|
||||||
__m128i acc_diff = _mm_setzero_si128();
|
__m128i acc_diff = _mm_setzero_si128();
|
||||||
const __m128i k_0 = _mm_setzero_si128();
|
const __m128i k_0 = _mm_setzero_si128();
|
||||||
@ -239,15 +238,14 @@ DenoiserDecision DenoiserFilterSSE2::MbDenoise(uint8_t* mc_running_avg_y,
|
|||||||
// Calculate differences.
|
// Calculate differences.
|
||||||
const __m128i v_sig =
|
const __m128i v_sig =
|
||||||
_mm_loadu_si128(reinterpret_cast<const __m128i*>(&sig[0]));
|
_mm_loadu_si128(reinterpret_cast<const __m128i*>(&sig[0]));
|
||||||
const __m128i v_mc_running_avg_y = _mm_loadu_si128(
|
const __m128i v_mc_running_avg_y =
|
||||||
reinterpret_cast<__m128i*>(&mc_running_avg_y[0]));
|
_mm_loadu_si128(reinterpret_cast<__m128i*>(&mc_running_avg_y[0]));
|
||||||
const __m128i pdiff = _mm_subs_epu8(v_mc_running_avg_y, v_sig);
|
const __m128i pdiff = _mm_subs_epu8(v_mc_running_avg_y, v_sig);
|
||||||
const __m128i ndiff = _mm_subs_epu8(v_sig, v_mc_running_avg_y);
|
const __m128i ndiff = _mm_subs_epu8(v_sig, v_mc_running_avg_y);
|
||||||
// Obtain the sign. FF if diff is negative.
|
// Obtain the sign. FF if diff is negative.
|
||||||
const __m128i diff_sign = _mm_cmpeq_epi8(pdiff, k_0);
|
const __m128i diff_sign = _mm_cmpeq_epi8(pdiff, k_0);
|
||||||
// Clamp absolute difference to delta to get the adjustment.
|
// Clamp absolute difference to delta to get the adjustment.
|
||||||
const __m128i adj = _mm_min_epu8(
|
const __m128i adj = _mm_min_epu8(_mm_or_si128(pdiff, ndiff), k_delta);
|
||||||
_mm_or_si128(pdiff, ndiff), k_delta);
|
|
||||||
// Restore the sign and get positive and negative adjustments.
|
// Restore the sign and get positive and negative adjustments.
|
||||||
__m128i padj, nadj;
|
__m128i padj, nadj;
|
||||||
padj = _mm_andnot_si128(diff_sign, adj);
|
padj = _mm_andnot_si128(diff_sign, adj);
|
||||||
|
18
webrtc/modules/video_processing/util/skin_detection.cc
Executable file → Normal file
18
webrtc/modules/video_processing/util/skin_detection.cc
Executable file → Normal file
@ -48,19 +48,13 @@ bool MbHasSkinColor(const uint8_t* y_src,
|
|||||||
const int stride_v,
|
const int stride_v,
|
||||||
const int mb_row,
|
const int mb_row,
|
||||||
const int mb_col) {
|
const int mb_col) {
|
||||||
const uint8_t* y =
|
const uint8_t* y = y_src + ((mb_row << 4) + 8) * stride_y + (mb_col << 4) + 8;
|
||||||
y_src + ((mb_row << 4) + 8) * stride_y + (mb_col << 4) + 8;
|
const uint8_t* u = u_src + ((mb_row << 3) + 4) * stride_u + (mb_col << 3) + 4;
|
||||||
const uint8_t* u =
|
const uint8_t* v = v_src + ((mb_row << 3) + 4) * stride_v + (mb_col << 3) + 4;
|
||||||
u_src + ((mb_row << 3) + 4) * stride_u + (mb_col << 3) + 4;
|
|
||||||
const uint8_t* v =
|
|
||||||
v_src + ((mb_row << 3) + 4) * stride_v + (mb_col << 3) + 4;
|
|
||||||
// Use 2x2 average of center pixel to compute skin area.
|
// Use 2x2 average of center pixel to compute skin area.
|
||||||
uint8_t y_avg =
|
uint8_t y_avg = (*y + *(y + 1) + *(y + stride_y) + *(y + stride_y + 1)) >> 2;
|
||||||
(*y + *(y + 1) + *(y + stride_y) + *(y + stride_y + 1)) >> 2;
|
uint8_t u_avg = (*u + *(u + 1) + *(u + stride_u) + *(u + stride_u + 1)) >> 2;
|
||||||
uint8_t u_avg =
|
uint8_t v_avg = (*v + *(v + 1) + *(v + stride_v) + *(v + stride_v + 1)) >> 2;
|
||||||
(*u + *(u + 1) + *(u + stride_u) + *(u + stride_u + 1)) >> 2;
|
|
||||||
uint8_t v_avg =
|
|
||||||
(*v + *(v + 1) + *(v + stride_v) + *(v + stride_v + 1)) >> 2;
|
|
||||||
// Ignore MB with too high or low brightness.
|
// Ignore MB with too high or low brightness.
|
||||||
if (y_avg < y_low || y_avg > y_high)
|
if (y_avg < y_low || y_avg > y_high)
|
||||||
return false;
|
return false;
|
||||||
|
@ -43,14 +43,17 @@ void VPMVideoDecimator::SetTargetFramerate(int frame_rate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool VPMVideoDecimator::DropFrame() {
|
bool VPMVideoDecimator::DropFrame() {
|
||||||
if (!enable_temporal_decimation_) return false;
|
if (!enable_temporal_decimation_)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (incoming_frame_rate_ <= 0) return false;
|
if (incoming_frame_rate_ <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
const uint32_t incomingframe_rate =
|
const uint32_t incomingframe_rate =
|
||||||
static_cast<uint32_t>(incoming_frame_rate_ + 0.5f);
|
static_cast<uint32_t>(incoming_frame_rate_ + 0.5f);
|
||||||
|
|
||||||
if (target_frame_rate_ == 0) return true;
|
if (target_frame_rate_ == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
bool drop = false;
|
bool drop = false;
|
||||||
if (incomingframe_rate > target_frame_rate_) {
|
if (incomingframe_rate > target_frame_rate_) {
|
||||||
@ -91,7 +94,6 @@ bool VPMVideoDecimator::DropFrame() {
|
|||||||
return drop;
|
return drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t VPMVideoDecimator::GetDecimatedFrameRate() {
|
uint32_t VPMVideoDecimator::GetDecimatedFrameRate() {
|
||||||
ProcessIncomingframe_rate(TickTime::MillisecondTimestamp());
|
ProcessIncomingframe_rate(TickTime::MillisecondTimestamp());
|
||||||
if (!enable_temporal_decimation_) {
|
if (!enable_temporal_decimation_) {
|
||||||
|
@ -14,9 +14,7 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
VideoDenoiser::VideoDenoiser()
|
VideoDenoiser::VideoDenoiser()
|
||||||
: width_(0),
|
: width_(0), height_(0), filter_(DenoiserFilter::Create()) {}
|
||||||
height_(0),
|
|
||||||
filter_(DenoiserFilter::Create()) {}
|
|
||||||
|
|
||||||
void VideoDenoiser::TrailingReduction(int mb_rows,
|
void VideoDenoiser::TrailingReduction(int mb_rows,
|
||||||
int mb_cols,
|
int mb_cols,
|
||||||
@ -32,13 +30,13 @@ void VideoDenoiser::TrailingReduction(int mb_rows,
|
|||||||
// do NOT denoise for the block. Set different threshold for skin MB.
|
// do NOT denoise for the block. Set different threshold for skin MB.
|
||||||
// The change of denoising status will not propagate.
|
// The change of denoising status will not propagate.
|
||||||
if (metrics_[mb_index].is_skin) {
|
if (metrics_[mb_index].is_skin) {
|
||||||
// The threshold is high (more strict) for non-skin MB where the trailing
|
// The threshold is high (more strict) for non-skin MB where the
|
||||||
// usually happen.
|
// trailing usually happen.
|
||||||
if (metrics_[mb_index].denoise &&
|
if (metrics_[mb_index].denoise &&
|
||||||
metrics_[mb_index + 1].denoise +
|
metrics_[mb_index + 1].denoise + metrics_[mb_index - 1].denoise +
|
||||||
metrics_[mb_index - 1].denoise +
|
|
||||||
metrics_[mb_index + mb_cols].denoise +
|
metrics_[mb_index + mb_cols].denoise +
|
||||||
metrics_[mb_index - mb_cols].denoise <= 2) {
|
metrics_[mb_index - mb_cols].denoise <=
|
||||||
|
2) {
|
||||||
metrics_[mb_index].denoise = 0;
|
metrics_[mb_index].denoise = 0;
|
||||||
filter_->CopyMem16x16(mb_src, stride_y, mb_dst, stride_y);
|
filter_->CopyMem16x16(mb_src, stride_y, mb_dst, stride_y);
|
||||||
}
|
}
|
||||||
@ -50,7 +48,8 @@ void VideoDenoiser::TrailingReduction(int mb_rows,
|
|||||||
metrics_[mb_index - mb_cols + 1].denoise +
|
metrics_[mb_index - mb_cols + 1].denoise +
|
||||||
metrics_[mb_index - mb_cols - 1].denoise +
|
metrics_[mb_index - mb_cols - 1].denoise +
|
||||||
metrics_[mb_index + mb_cols].denoise +
|
metrics_[mb_index + mb_cols].denoise +
|
||||||
metrics_[mb_index - mb_cols].denoise <= 7) {
|
metrics_[mb_index - mb_cols].denoise <=
|
||||||
|
7) {
|
||||||
filter_->CopyMem16x16(mb_src, stride_y, mb_dst, stride_y);
|
filter_->CopyMem16x16(mb_src, stride_y, mb_dst, stride_y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,23 +90,20 @@ void VideoDenoiser::DenoiseFrame(const VideoFrame& frame,
|
|||||||
uint8_t y_tmp[16 * 16] = {0};
|
uint8_t y_tmp[16 * 16] = {0};
|
||||||
for (int mb_row = 0; mb_row < mb_rows; ++mb_row) {
|
for (int mb_row = 0; mb_row < mb_rows; ++mb_row) {
|
||||||
for (int mb_col = 0; mb_col < mb_cols; ++mb_col) {
|
for (int mb_col = 0; mb_col < mb_cols; ++mb_col) {
|
||||||
const uint8_t* mb_src =
|
const uint8_t* mb_src = y_src + (mb_row << 4) * stride_y + (mb_col << 4);
|
||||||
y_src + (mb_row << 4) * stride_y + (mb_col << 4);
|
|
||||||
uint8_t* mb_dst = y_dst + (mb_row << 4) * stride_y + (mb_col << 4);
|
uint8_t* mb_dst = y_dst + (mb_row << 4) * stride_y + (mb_col << 4);
|
||||||
int mb_index = mb_row * mb_cols + mb_col;
|
int mb_index = mb_row * mb_cols + mb_col;
|
||||||
// Denoise each MB at the very start and save the result to a temporary
|
// Denoise each MB at the very start and save the result to a temporary
|
||||||
// buffer.
|
// buffer.
|
||||||
if (filter_->MbDenoise(
|
if (filter_->MbDenoise(mb_dst, stride_y, y_tmp, 16, mb_src, stride_y, 0,
|
||||||
mb_dst, stride_y, y_tmp, 16, mb_src, stride_y, 0, 1) ==
|
1) == FILTER_BLOCK) {
|
||||||
FILTER_BLOCK) {
|
|
||||||
uint32_t thr_var = 0;
|
uint32_t thr_var = 0;
|
||||||
// Save var and sad to the buffer.
|
// Save var and sad to the buffer.
|
||||||
metrics_[mb_index].var = filter_->Variance16x8(
|
metrics_[mb_index].var = filter_->Variance16x8(
|
||||||
mb_dst, stride_y, y_tmp, 16, &metrics_[mb_index].sad);
|
mb_dst, stride_y, y_tmp, 16, &metrics_[mb_index].sad);
|
||||||
// Get skin map.
|
// Get skin map.
|
||||||
metrics_[mb_index].is_skin =
|
metrics_[mb_index].is_skin = MbHasSkinColor(
|
||||||
MbHasSkinColor(y_src, u_src, v_src, stride_y, stride_u, stride_v,
|
y_src, u_src, v_src, stride_y, stride_u, stride_v, mb_row, mb_col);
|
||||||
mb_row, mb_col);
|
|
||||||
// Variance threshold for skin/non-skin MB is different.
|
// Variance threshold for skin/non-skin MB is different.
|
||||||
// Skin MB use a small threshold to reduce blockiness.
|
// Skin MB use a small threshold to reduce blockiness.
|
||||||
thr_var = metrics_[mb_index].is_skin ? 128 : 12 * 128;
|
thr_var = metrics_[mb_index].is_skin ? 128 : 12 * 128;
|
||||||
|
@ -22,8 +22,11 @@ class VideoDenoiser {
|
|||||||
void DenoiseFrame(const VideoFrame& frame, VideoFrame* denoised_frame);
|
void DenoiseFrame(const VideoFrame& frame, VideoFrame* denoised_frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void TrailingReduction(int mb_rows, int mb_cols, const uint8_t* y_src,
|
void TrailingReduction(int mb_rows,
|
||||||
int stride_y, uint8_t* y_dst);
|
int mb_cols,
|
||||||
|
const uint8_t* y_src,
|
||||||
|
int stride_y,
|
||||||
|
uint8_t* y_dst);
|
||||||
int width_;
|
int width_;
|
||||||
int height_;
|
int height_;
|
||||||
rtc::scoped_ptr<DenoiseMetrics[]> metrics_;
|
rtc::scoped_ptr<DenoiseMetrics[]> metrics_;
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "webrtc/base/logging.h"
|
#include "webrtc/base/logging.h"
|
||||||
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
||||||
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -62,8 +61,8 @@ void VideoProcessing::GetFrameStats(const VideoFrame& frame,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stats->num_pixels = (width * height) /
|
stats->num_pixels = (width * height) / ((1 << stats->sub_sampling_factor) *
|
||||||
((1 << stats->sub_sampling_factor) * (1 << stats->sub_sampling_factor));
|
(1 << stats->sub_sampling_factor));
|
||||||
assert(stats->num_pixels > 0);
|
assert(stats->num_pixels > 0);
|
||||||
|
|
||||||
// Compute mean value of frame
|
// Compute mean value of frame
|
||||||
@ -112,22 +111,19 @@ int32_t VideoProcessingImpl::Deflickering(VideoFrame* frame,
|
|||||||
return deflickering_.ProcessFrame(frame, stats);
|
return deflickering_.ProcessFrame(frame, stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t VideoProcessingImpl::BrightnessDetection(
|
int32_t VideoProcessingImpl::BrightnessDetection(const VideoFrame& frame,
|
||||||
const VideoFrame& frame,
|
|
||||||
const FrameStats& stats) {
|
const FrameStats& stats) {
|
||||||
rtc::CritScope mutex(&mutex_);
|
rtc::CritScope mutex(&mutex_);
|
||||||
return brightness_detection_.ProcessFrame(frame, stats);
|
return brightness_detection_.ProcessFrame(frame, stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void VideoProcessingImpl::EnableTemporalDecimation(bool enable) {
|
void VideoProcessingImpl::EnableTemporalDecimation(bool enable) {
|
||||||
rtc::CritScope mutex(&mutex_);
|
rtc::CritScope mutex(&mutex_);
|
||||||
frame_pre_processor_.EnableTemporalDecimation(enable);
|
frame_pre_processor_.EnableTemporalDecimation(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VideoProcessingImpl::SetInputFrameResampleMode(
|
||||||
void VideoProcessingImpl::SetInputFrameResampleMode(VideoFrameResampling
|
VideoFrameResampling resampling_mode) {
|
||||||
resampling_mode) {
|
|
||||||
rtc::CritScope cs(&mutex_);
|
rtc::CritScope cs(&mutex_);
|
||||||
frame_pre_processor_.SetInputFrameResampleMode(resampling_mode);
|
frame_pre_processor_.SetInputFrameResampleMode(resampling_mode);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user