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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 VideoFrame* denoised_frame_prev, | 231 VideoFrame* denoised_frame_prev, |
230 bool noise_estimation_enabled) { | 232 bool noise_estimation_enabled) { |
231 // If previous width and height are different from current frame's, need to | 233 // If previous width and height are different from current frame's, need to |
232 // reallocate the buffers and no denoising for the current frame. | 234 // reallocate the buffers and no denoising for the current frame. |
233 if (width_ != frame.width() || height_ != frame.height()) { | 235 if (width_ != frame.width() || height_ != frame.height()) { |
234 DenoiserReset(frame, denoised_frame, denoised_frame_prev); | 236 DenoiserReset(frame, denoised_frame, denoised_frame_prev); |
235 return; | 237 return; |
236 } | 238 } |
237 | 239 |
238 // Set buffer pointers. | 240 // Set buffer pointers. |
239 const uint8_t* y_src = frame.buffer(kYPlane); | 241 const uint8_t* y_src = frame.video_frame_buffer()->DataY(); |
240 const uint8_t* u_src = frame.buffer(kUPlane); | 242 const uint8_t* u_src = frame.video_frame_buffer()->DataU(); |
241 const uint8_t* v_src = frame.buffer(kVPlane); | 243 const uint8_t* v_src = frame.video_frame_buffer()->DataV(); |
242 uint8_t* y_dst = denoised_frame->buffer(kYPlane); | 244 uint8_t* y_dst = denoised_frame->video_frame_buffer()->MutableDataY(); |
243 uint8_t* u_dst = denoised_frame->buffer(kUPlane); | 245 uint8_t* u_dst = denoised_frame->video_frame_buffer()->MutableDataU(); |
244 uint8_t* v_dst = denoised_frame->buffer(kVPlane); | 246 uint8_t* v_dst = denoised_frame->video_frame_buffer()->MutableDataV(); |
245 uint8_t* y_dst_prev = denoised_frame_prev->buffer(kYPlane); | 247 uint8_t* y_dst_prev = |
| 248 denoised_frame_prev->video_frame_buffer()->MutableDataY(); |
246 memset(x_density_.get(), 0, mb_cols_); | 249 memset(x_density_.get(), 0, mb_cols_); |
247 memset(y_density_.get(), 0, mb_rows_); | 250 memset(y_density_.get(), 0, mb_rows_); |
248 memset(moving_object_.get(), 1, mb_cols_ * mb_rows_); | 251 memset(moving_object_.get(), 1, mb_cols_ * mb_rows_); |
249 | 252 |
250 uint8_t noise_level = noise_estimation_enabled ? ne_->GetNoiseLevel() : 0; | 253 uint8_t noise_level = noise_estimation_enabled ? ne_->GetNoiseLevel() : 0; |
251 int thr_var_base = 16 * 16 * 2; | 254 int thr_var_base = 16 * 16 * 2; |
252 // Loop over blocks to accumulate/extract noise level and update x/y_density | 255 // Loop over blocks to accumulate/extract noise level and update x/y_density |
253 // factors for moving object detection. | 256 // factors for moving object detection. |
254 for (int mb_row = 0; mb_row < mb_rows_; ++mb_row) { | 257 for (int mb_row = 0; mb_row < mb_rows_; ++mb_row) { |
255 const int mb_index_base = mb_row * mb_cols_; | 258 const int mb_index_base = mb_row * mb_cols_; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 denoised_frame->set_render_time_ms(frame.render_time_ms()); | 344 denoised_frame->set_render_time_ms(frame.render_time_ms()); |
342 | 345 |
343 #if DISPLAY || DISPLAYNEON | 346 #if DISPLAY || DISPLAYNEON |
344 // Show rectangular region | 347 // Show rectangular region |
345 ShowRect(filter_, moving_edge_, moving_object_, x_density_, y_density_, u_src, | 348 ShowRect(filter_, moving_edge_, moving_object_, x_density_, y_density_, u_src, |
346 v_src, u_dst, v_dst, mb_rows_, mb_cols_, stride_u_, stride_v_); | 349 v_src, u_dst, v_dst, mb_rows_, mb_cols_, stride_u_, stride_v_); |
347 #endif | 350 #endif |
348 } | 351 } |
349 | 352 |
350 } // namespace webrtc | 353 } // namespace webrtc |
OLD | NEW |