OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 filter_(DenoiserFilter::Create(runtime_cpu_detection, &cpu_type_)), | 74 filter_(DenoiserFilter::Create(runtime_cpu_detection, &cpu_type_)), |
75 ne_(new NoiseEstimation()) {} | 75 ne_(new NoiseEstimation()) {} |
76 | 76 |
77 void VideoDenoiser::DenoiserReset(const VideoFrame& frame, | 77 void VideoDenoiser::DenoiserReset(const VideoFrame& frame, |
78 VideoFrame* denoised_frame, | 78 VideoFrame* denoised_frame, |
79 VideoFrame* denoised_frame_prev) { | 79 VideoFrame* denoised_frame_prev) { |
80 width_ = frame.width(); | 80 width_ = frame.width(); |
81 height_ = frame.height(); | 81 height_ = frame.height(); |
82 mb_cols_ = width_ >> 4; | 82 mb_cols_ = width_ >> 4; |
83 mb_rows_ = height_ >> 4; | 83 mb_rows_ = height_ >> 4; |
84 stride_y_ = frame.stride(kYPlane); | 84 stride_y_ = frame.video_frame_buffer()->StrideY(); |
85 stride_u_ = frame.stride(kUPlane); | 85 stride_u_ = frame.video_frame_buffer()->StrideU(); |
86 stride_v_ = frame.stride(kVPlane); | 86 stride_v_ = frame.video_frame_buffer()->StrideV(); |
87 | 87 |
88 // Allocate an empty buffer for denoised_frame_prev. | 88 // Allocate an empty buffer for denoised_frame_prev. |
89 denoised_frame_prev->CreateEmptyFrame(width_, height_, stride_y_, stride_u_, | 89 denoised_frame_prev->CreateEmptyFrame(width_, height_, stride_y_, stride_u_, |
90 stride_v_); | 90 stride_v_); |
91 // Allocate and initialize denoised_frame with key frame. | 91 // Allocate and initialize denoised_frame with key frame. |
92 denoised_frame->CreateFrame(frame.buffer(kYPlane), frame.buffer(kUPlane), | 92 denoised_frame->CreateFrame( |
93 frame.buffer(kVPlane), width_, height_, stride_y_, | 93 frame.video_frame_buffer()->DataY(), |
94 stride_u_, stride_v_, kVideoRotation_0); | 94 frame.video_frame_buffer()->DataU(), |
| 95 frame.video_frame_buffer()->DataV(), |
| 96 width_, height_, stride_y_, stride_u_, stride_v_, kVideoRotation_0); |
95 // Set time parameters to the output frame. | 97 // Set time parameters to the output frame. |
96 denoised_frame->set_timestamp(frame.timestamp()); | 98 denoised_frame->set_timestamp(frame.timestamp()); |
97 denoised_frame->set_render_time_ms(frame.render_time_ms()); | 99 denoised_frame->set_render_time_ms(frame.render_time_ms()); |
98 | 100 |
99 // Init noise estimator and allocate buffers. | 101 // Init noise estimator and allocate buffers. |
100 ne_->Init(width_, height_, cpu_type_); | 102 ne_->Init(width_, height_, cpu_type_); |
101 moving_edge_.reset(new uint8_t[mb_cols_ * mb_rows_]); | 103 moving_edge_.reset(new uint8_t[mb_cols_ * mb_rows_]); |
102 mb_filter_decision_.reset(new DenoiserDecision[mb_cols_ * mb_rows_]); | 104 mb_filter_decision_.reset(new DenoiserDecision[mb_cols_ * mb_rows_]); |
103 x_density_.reset(new uint8_t[mb_cols_]); | 105 x_density_.reset(new uint8_t[mb_cols_]); |
104 y_density_.reset(new uint8_t[mb_rows_]); | 106 y_density_.reset(new uint8_t[mb_rows_]); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 VideoFrame* denoised_frame_prev, | 214 VideoFrame* denoised_frame_prev, |
213 bool noise_estimation_enabled) { | 215 bool noise_estimation_enabled) { |
214 // If previous width and height are different from current frame's, need to | 216 // If previous width and height are different from current frame's, need to |
215 // reallocate the buffers and no denoising for the current frame. | 217 // reallocate the buffers and no denoising for the current frame. |
216 if (width_ != frame.width() || height_ != frame.height()) { | 218 if (width_ != frame.width() || height_ != frame.height()) { |
217 DenoiserReset(frame, denoised_frame, denoised_frame_prev); | 219 DenoiserReset(frame, denoised_frame, denoised_frame_prev); |
218 return; | 220 return; |
219 } | 221 } |
220 | 222 |
221 // Set buffer pointers. | 223 // Set buffer pointers. |
222 const uint8_t* y_src = frame.buffer(kYPlane); | 224 const uint8_t* y_src = frame.video_frame_buffer()->DataY(); |
223 const uint8_t* u_src = frame.buffer(kUPlane); | 225 const uint8_t* u_src = frame.video_frame_buffer()->DataU(); |
224 const uint8_t* v_src = frame.buffer(kVPlane); | 226 const uint8_t* v_src = frame.video_frame_buffer()->DataV(); |
225 uint8_t* y_dst = denoised_frame->buffer(kYPlane); | 227 uint8_t* y_dst = denoised_frame->video_frame_buffer()->MutableDataY(); |
226 uint8_t* u_dst = denoised_frame->buffer(kUPlane); | 228 uint8_t* u_dst = denoised_frame->video_frame_buffer()->MutableDataU(); |
227 uint8_t* v_dst = denoised_frame->buffer(kVPlane); | 229 uint8_t* v_dst = denoised_frame->video_frame_buffer()->MutableDataV(); |
228 uint8_t* y_dst_prev = denoised_frame_prev->buffer(kYPlane); | 230 uint8_t* y_dst_prev = |
| 231 denoised_frame_prev->video_frame_buffer()->MutableDataY(); |
229 memset(x_density_.get(), 0, mb_cols_); | 232 memset(x_density_.get(), 0, mb_cols_); |
230 memset(y_density_.get(), 0, mb_rows_); | 233 memset(y_density_.get(), 0, mb_rows_); |
231 memset(moving_object_.get(), 1, mb_cols_ * mb_rows_); | 234 memset(moving_object_.get(), 1, mb_cols_ * mb_rows_); |
232 | 235 |
233 uint8_t noise_level = noise_estimation_enabled ? ne_->GetNoiseLevel() : 0; | 236 uint8_t noise_level = noise_estimation_enabled ? ne_->GetNoiseLevel() : 0; |
234 int thr_var_base = 16 * 16 * 5; | 237 int thr_var_base = 16 * 16 * 5; |
235 // Loop over blocks to accumulate/extract noise level and update x/y_density | 238 // Loop over blocks to accumulate/extract noise level and update x/y_density |
236 // factors for moving object detection. | 239 // factors for moving object detection. |
237 for (int mb_row = 0; mb_row < mb_rows_; ++mb_row) { | 240 for (int mb_row = 0; mb_row < mb_rows_; ++mb_row) { |
238 const int mb_index_base = mb_row * mb_cols_; | 241 const int mb_index_base = mb_row * mb_cols_; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 denoised_frame->set_render_time_ms(frame.render_time_ms()); | 322 denoised_frame->set_render_time_ms(frame.render_time_ms()); |
320 | 323 |
321 #if DISPLAY // Rectangle diagnostics | 324 #if DISPLAY // Rectangle diagnostics |
322 // Show rectangular region | 325 // Show rectangular region |
323 ShowRect(filter_, moving_edge_, moving_object_, x_density_, y_density_, u_src, | 326 ShowRect(filter_, moving_edge_, moving_object_, x_density_, y_density_, u_src, |
324 v_src, u_dst, v_dst, mb_rows_, mb_cols_, stride_u_, stride_v_); | 327 v_src, u_dst, v_dst, mb_rows_, mb_cols_, stride_u_, stride_v_); |
325 #endif | 328 #endif |
326 } | 329 } |
327 | 330 |
328 } // namespace webrtc | 331 } // namespace webrtc |
OLD | NEW |