OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 src_frame.video_frame_buffer()->StrideY(), | 281 src_frame.video_frame_buffer()->StrideY(), |
282 src_frame.video_frame_buffer()->DataU(), | 282 src_frame.video_frame_buffer()->DataU(), |
283 src_frame.video_frame_buffer()->StrideU(), | 283 src_frame.video_frame_buffer()->StrideU(), |
284 src_frame.video_frame_buffer()->DataV(), | 284 src_frame.video_frame_buffer()->DataV(), |
285 src_frame.video_frame_buffer()->StrideV(), | 285 src_frame.video_frame_buffer()->StrideV(), |
286 dst_frame, dst_sample_size, | 286 dst_frame, dst_sample_size, |
287 src_frame.width(), src_frame.height(), | 287 src_frame.width(), src_frame.height(), |
288 ConvertVideoType(dst_video_type)); | 288 ConvertVideoType(dst_video_type)); |
289 } | 289 } |
290 | 290 |
291 // Compute PSNR for an I420 frame (all planes) | 291 // Compute PSNR for an I420 frame (all planes). Can upscale test frame. |
292 double I420PSNR(const VideoFrameBuffer& ref_buffer, | 292 double I420PSNR(const VideoFrameBuffer& ref_buffer, |
293 const VideoFrameBuffer& test_buffer) { | 293 const VideoFrameBuffer& test_buffer) { |
294 rtc::scoped_refptr<const VideoFrameBuffer> temp_buffer(&test_buffer); | |
magjed_webrtc
2017/02/14 12:47:49
Taking the address of a const-ref argument is sket
ilnik
2017/02/14 13:04:16
That is a great idea!
| |
295 RTC_DCHECK_GE(ref_buffer.width(), test_buffer.width()); | |
296 RTC_DCHECK_GE(ref_buffer.height(), test_buffer.height()); | |
297 RTC_DCHECK_GE(ref_buffer.width(), 0); | |
magjed_webrtc
2017/02/14 12:47:49
This check is really paranoid. Width/height is nev
ilnik
2017/02/14 13:04:16
Acknowledged.
| |
298 RTC_DCHECK_GE(ref_buffer.height(), 0); | |
294 if ((ref_buffer.width() != test_buffer.width()) || | 299 if ((ref_buffer.width() != test_buffer.width()) || |
295 (ref_buffer.height() != test_buffer.height())) | 300 (ref_buffer.height() != test_buffer.height())) { |
296 return -1; | 301 rtc::scoped_refptr<I420Buffer> scaled_buffer = |
297 else if (ref_buffer.width() < 0 || ref_buffer.height() < 0) | 302 I420Buffer::Create(ref_buffer.width(), ref_buffer.height()); |
298 return -1; | 303 scaled_buffer->ScaleFrom(test_buffer); |
299 | 304 temp_buffer = static_cast<VideoFrameBuffer*>(scaled_buffer.get()); |
300 double psnr = libyuv::I420Psnr(ref_buffer.DataY(), ref_buffer.StrideY(), | 305 } |
301 ref_buffer.DataU(), ref_buffer.StrideU(), | 306 double psnr = libyuv::I420Psnr( |
302 ref_buffer.DataV(), ref_buffer.StrideV(), | 307 ref_buffer.DataY(), ref_buffer.StrideY(), ref_buffer.DataU(), |
303 test_buffer.DataY(), test_buffer.StrideY(), | 308 ref_buffer.StrideU(), ref_buffer.DataV(), ref_buffer.StrideV(), |
304 test_buffer.DataU(), test_buffer.StrideU(), | 309 temp_buffer->DataY(), temp_buffer->StrideY(), temp_buffer->DataU(), |
305 test_buffer.DataV(), test_buffer.StrideV(), | 310 temp_buffer->StrideU(), temp_buffer->DataV(), temp_buffer->StrideV(), |
306 test_buffer.width(), test_buffer.height()); | 311 temp_buffer->width(), temp_buffer->height()); |
307 // LibYuv sets the max psnr value to 128, we restrict it here. | 312 // LibYuv sets the max psnr value to 128, we restrict it here. |
308 // In case of 0 mse in one frame, 128 can skew the results significantly. | 313 // In case of 0 mse in one frame, 128 can skew the results significantly. |
309 return (psnr > kPerfectPSNR) ? kPerfectPSNR : psnr; | 314 return (psnr > kPerfectPSNR) ? kPerfectPSNR : psnr; |
310 } | 315 } |
311 | 316 |
312 // Compute PSNR for an I420 frame (all planes) | 317 // Compute PSNR for an I420 frame (all planes) |
313 double I420PSNR(const VideoFrame* ref_frame, const VideoFrame* test_frame) { | 318 double I420PSNR(const VideoFrame* ref_frame, const VideoFrame* test_frame) { |
314 if (!ref_frame || !test_frame) | 319 if (!ref_frame || !test_frame) |
315 return -1; | 320 return -1; |
316 return I420PSNR(*ref_frame->video_frame_buffer(), | 321 return I420PSNR(*ref_frame->video_frame_buffer(), |
317 *test_frame->video_frame_buffer()); | 322 *test_frame->video_frame_buffer()); |
318 } | 323 } |
319 | 324 |
320 // Compute SSIM for an I420 frame (all planes) | 325 // Compute SSIM for an I420 frame (all planes). Can upscale test_buffer. |
321 double I420SSIM(const VideoFrameBuffer& ref_buffer, | 326 double I420SSIM(const VideoFrameBuffer& ref_buffer, |
322 const VideoFrameBuffer& test_buffer) { | 327 const VideoFrameBuffer& test_buffer) { |
328 rtc::scoped_refptr<const VideoFrameBuffer> temp_buffer(&test_buffer); | |
329 RTC_DCHECK_GE(ref_buffer.width(), test_buffer.width()); | |
330 RTC_DCHECK_GE(ref_buffer.height(), test_buffer.height()); | |
331 RTC_DCHECK_GE(ref_buffer.width(), 0); | |
332 RTC_DCHECK_GE(ref_buffer.height(), 0); | |
323 if ((ref_buffer.width() != test_buffer.width()) || | 333 if ((ref_buffer.width() != test_buffer.width()) || |
324 (ref_buffer.height() != test_buffer.height())) | 334 (ref_buffer.height() != test_buffer.height())) { |
325 return -1; | 335 rtc::scoped_refptr<I420Buffer> scaled_buffer = |
326 else if (ref_buffer.width() < 0 || ref_buffer.height() < 0) | 336 I420Buffer::Create(ref_buffer.width(), ref_buffer.height()); |
327 return -1; | 337 scaled_buffer->ScaleFrom(test_buffer); |
328 | 338 temp_buffer = static_cast<VideoFrameBuffer*>(scaled_buffer.get()); |
329 return libyuv::I420Ssim(ref_buffer.DataY(), ref_buffer.StrideY(), | 339 } |
330 ref_buffer.DataU(), ref_buffer.StrideU(), | 340 return libyuv::I420Ssim( |
331 ref_buffer.DataV(), ref_buffer.StrideV(), | 341 ref_buffer.DataY(), ref_buffer.StrideY(), ref_buffer.DataU(), |
332 test_buffer.DataY(), test_buffer.StrideY(), | 342 ref_buffer.StrideU(), ref_buffer.DataV(), ref_buffer.StrideV(), |
333 test_buffer.DataU(), test_buffer.StrideU(), | 343 temp_buffer->DataY(), temp_buffer->StrideY(), temp_buffer->DataU(), |
334 test_buffer.DataV(), test_buffer.StrideV(), | 344 temp_buffer->StrideU(), temp_buffer->DataV(), temp_buffer->StrideV(), |
335 test_buffer.width(), test_buffer.height()); | 345 temp_buffer->width(), temp_buffer->height()); |
336 } | 346 } |
337 double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame) { | 347 double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame) { |
338 if (!ref_frame || !test_frame) | 348 if (!ref_frame || !test_frame) |
339 return -1; | 349 return -1; |
340 return I420SSIM(*ref_frame->video_frame_buffer(), | 350 return I420SSIM(*ref_frame->video_frame_buffer(), |
341 *test_frame->video_frame_buffer()); | 351 *test_frame->video_frame_buffer()); |
342 } | 352 } |
343 | 353 |
344 void NV12Scale(std::vector<uint8_t>* tmp_buffer, | 354 void NV12Scale(std::vector<uint8_t>* tmp_buffer, |
345 const uint8_t* src_y, int src_stride_y, | 355 const uint8_t* src_y, int src_stride_y, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 src_v, src_uv_width, | 452 src_v, src_uv_width, |
443 src_width, src_height, | 453 src_width, src_height, |
444 dst_y, dst_stride_y, | 454 dst_y, dst_stride_y, |
445 dst_u, dst_stride_u, | 455 dst_u, dst_stride_u, |
446 dst_v, dst_stride_v, | 456 dst_v, dst_stride_v, |
447 dst_width, dst_height, | 457 dst_width, dst_height, |
448 libyuv::kFilterBox); | 458 libyuv::kFilterBox); |
449 } | 459 } |
450 | 460 |
451 } // namespace webrtc | 461 } // namespace webrtc |
OLD | NEW |