Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: webrtc/modules/video_coding/content_metrics_processing.cc

Issue 1917323002: Remove remaining quality-analysis (QM). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/video_coding/content_metrics_processing.h"
12
13 #include <math.h>
14
15 #include "webrtc/modules/include/module_common_types.h"
16 #include "webrtc/modules/video_coding/include/video_coding_defines.h"
17
18 namespace webrtc {
19 //////////////////////////////////
20 /// VCMContentMetricsProcessing //
21 //////////////////////////////////
22
23 VCMContentMetricsProcessing::VCMContentMetricsProcessing()
24 : recursive_avg_factor_(1 / 150.0f), // matched to 30fps.
25 frame_cnt_uniform_avg_(0),
26 avg_motion_level_(0.0f),
27 avg_spatial_level_(0.0f) {
28 recursive_avg_ = new VideoContentMetrics();
29 uniform_avg_ = new VideoContentMetrics();
30 }
31
32 VCMContentMetricsProcessing::~VCMContentMetricsProcessing() {
33 delete recursive_avg_;
34 delete uniform_avg_;
35 }
36
37 int VCMContentMetricsProcessing::Reset() {
38 recursive_avg_->Reset();
39 uniform_avg_->Reset();
40 frame_cnt_uniform_avg_ = 0;
41 avg_motion_level_ = 0.0f;
42 avg_spatial_level_ = 0.0f;
43 return VCM_OK;
44 }
45
46 void VCMContentMetricsProcessing::UpdateFrameRate(uint32_t frameRate) {
47 if (frameRate == 0)
48 frameRate = 1;
49 // Update factor for recursive averaging.
50 recursive_avg_factor_ = static_cast<float>(1000.0f) /
51 static_cast<float>(frameRate * kQmMinIntervalMs);
52 }
53
54 VideoContentMetrics* VCMContentMetricsProcessing::LongTermAvgData() {
55 return recursive_avg_;
56 }
57
58 VideoContentMetrics* VCMContentMetricsProcessing::ShortTermAvgData() {
59 if (frame_cnt_uniform_avg_ == 0) {
60 return NULL;
61 }
62 // Two metrics are used: motion and spatial level.
63 uniform_avg_->motion_magnitude =
64 avg_motion_level_ / static_cast<float>(frame_cnt_uniform_avg_);
65 uniform_avg_->spatial_pred_err =
66 avg_spatial_level_ / static_cast<float>(frame_cnt_uniform_avg_);
67 return uniform_avg_;
68 }
69
70 void VCMContentMetricsProcessing::ResetShortTermAvgData() {
71 // Reset.
72 avg_motion_level_ = 0.0f;
73 avg_spatial_level_ = 0.0f;
74 frame_cnt_uniform_avg_ = 0;
75 }
76
77 int VCMContentMetricsProcessing::UpdateContentData(
78 const VideoContentMetrics* contentMetrics) {
79 if (contentMetrics == NULL) {
80 return VCM_OK;
81 }
82 return ProcessContent(contentMetrics);
83 }
84
85 int VCMContentMetricsProcessing::ProcessContent(
86 const VideoContentMetrics* contentMetrics) {
87 // Update the recursive averaged metrics: average is over longer window
88 // of time: over QmMinIntervalMs ms.
89 UpdateRecursiveAvg(contentMetrics);
90 // Update the uniform averaged metrics: average is over shorter window
91 // of time: based on ~RTCP reports.
92 UpdateUniformAvg(contentMetrics);
93 return VCM_OK;
94 }
95
96 void VCMContentMetricsProcessing::UpdateUniformAvg(
97 const VideoContentMetrics* contentMetrics) {
98 // Update frame counter.
99 frame_cnt_uniform_avg_ += 1;
100 // Update averaged metrics: motion and spatial level are used.
101 avg_motion_level_ += contentMetrics->motion_magnitude;
102 avg_spatial_level_ += contentMetrics->spatial_pred_err;
103 return;
104 }
105
106 void VCMContentMetricsProcessing::UpdateRecursiveAvg(
107 const VideoContentMetrics* contentMetrics) {
108 // Spatial metrics: 2x2, 1x2(H), 2x1(V).
109 recursive_avg_->spatial_pred_err =
110 (1 - recursive_avg_factor_) * recursive_avg_->spatial_pred_err +
111 recursive_avg_factor_ * contentMetrics->spatial_pred_err;
112
113 recursive_avg_->spatial_pred_err_h =
114 (1 - recursive_avg_factor_) * recursive_avg_->spatial_pred_err_h +
115 recursive_avg_factor_ * contentMetrics->spatial_pred_err_h;
116
117 recursive_avg_->spatial_pred_err_v =
118 (1 - recursive_avg_factor_) * recursive_avg_->spatial_pred_err_v +
119 recursive_avg_factor_ * contentMetrics->spatial_pred_err_v;
120
121 // Motion metric: Derived from NFD (normalized frame difference).
122 recursive_avg_->motion_magnitude =
123 (1 - recursive_avg_factor_) * recursive_avg_->motion_magnitude +
124 recursive_avg_factor_ * contentMetrics->motion_magnitude;
125 }
126 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/content_metrics_processing.h ('k') | webrtc/modules/video_coding/include/video_coding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698