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 if ((ref_buffer.width() != test_buffer.width()) || | 294 if ((ref_buffer.width() < test_buffer.width()) || |
295 (ref_buffer.height() != test_buffer.height())) | 295 (ref_buffer.height() < test_buffer.height())) { |
296 return -1; | 296 return -1; |
297 else if (ref_buffer.width() < 0 || ref_buffer.height() < 0) | 297 } else if (ref_buffer.width() < 0 || ref_buffer.height() < 0) { |
298 return -1; | 298 return -1; |
299 | 299 } else if ((ref_buffer.width() > test_buffer.width()) || |
300 (ref_buffer.height() > test_buffer.height())) { | |
301 rtc::scoped_refptr<I420Buffer> upscaled_buffer = | |
sprang_webrtc
2017/02/09 17:10:39
Maybe you can move this declaration up to method s
ilnik
2017/02/10 10:11:43
Done.
| |
302 I420Buffer::Create(ref_buffer.width(), ref_buffer.height()); | |
303 int result = libyuv::I420Scale( | |
sprang_webrtc
2017/02/09 17:10:39
Don't need this temporary
ilnik
2017/02/10 10:11:43
Done.
| |
304 test_buffer.DataY(), test_buffer.StrideY(), test_buffer.DataU(), | |
305 test_buffer.StrideU(), test_buffer.DataV(), test_buffer.StrideV(), | |
306 test_buffer.width(), test_buffer.height(), | |
307 upscaled_buffer->MutableDataY(), upscaled_buffer->StrideY(), | |
308 upscaled_buffer->MutableDataU(), upscaled_buffer->StrideU(), | |
309 upscaled_buffer->MutableDataV(), upscaled_buffer->StrideV(), | |
310 upscaled_buffer->width(), upscaled_buffer->height(), | |
311 libyuv::kFilterBilinear); | |
312 if (result != 0) { | |
313 return -1; | |
314 } | |
315 double psnr = libyuv::I420Psnr( | |
316 ref_buffer.DataY(), ref_buffer.StrideY(), ref_buffer.DataU(), | |
317 ref_buffer.StrideU(), ref_buffer.DataV(), ref_buffer.StrideV(), | |
318 upscaled_buffer->DataY(), upscaled_buffer->StrideY(), | |
319 upscaled_buffer->DataU(), upscaled_buffer->StrideU(), | |
320 upscaled_buffer->DataV(), upscaled_buffer->StrideV(), | |
321 upscaled_buffer->width(), upscaled_buffer->height()); | |
322 // LibYuv sets the max psnr value to 128, we restrict it here. | |
323 // In case of 0 mse in one frame, 128 can skew the results significantly. | |
324 return (psnr > kPerfectPSNR) ? kPerfectPSNR : psnr; | |
325 } | |
300 double psnr = libyuv::I420Psnr(ref_buffer.DataY(), ref_buffer.StrideY(), | 326 double psnr = libyuv::I420Psnr(ref_buffer.DataY(), ref_buffer.StrideY(), |
301 ref_buffer.DataU(), ref_buffer.StrideU(), | 327 ref_buffer.DataU(), ref_buffer.StrideU(), |
302 ref_buffer.DataV(), ref_buffer.StrideV(), | 328 ref_buffer.DataV(), ref_buffer.StrideV(), |
303 test_buffer.DataY(), test_buffer.StrideY(), | 329 test_buffer.DataY(), test_buffer.StrideY(), |
304 test_buffer.DataU(), test_buffer.StrideU(), | 330 test_buffer.DataU(), test_buffer.StrideU(), |
305 test_buffer.DataV(), test_buffer.StrideV(), | 331 test_buffer.DataV(), test_buffer.StrideV(), |
306 test_buffer.width(), test_buffer.height()); | 332 test_buffer.width(), test_buffer.height()); |
307 // LibYuv sets the max psnr value to 128, we restrict it here. | 333 // 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. | 334 // In case of 0 mse in one frame, 128 can skew the results significantly. |
309 return (psnr > kPerfectPSNR) ? kPerfectPSNR : psnr; | 335 return (psnr > kPerfectPSNR) ? kPerfectPSNR : psnr; |
310 } | 336 } |
311 | 337 |
312 // Compute PSNR for an I420 frame (all planes) | 338 // Compute PSNR for an I420 frame (all planes) |
313 double I420PSNR(const VideoFrame* ref_frame, const VideoFrame* test_frame) { | 339 double I420PSNR(const VideoFrame* ref_frame, const VideoFrame* test_frame) { |
314 if (!ref_frame || !test_frame) | 340 if (!ref_frame || !test_frame) |
315 return -1; | 341 return -1; |
316 return I420PSNR(*ref_frame->video_frame_buffer(), | 342 return I420PSNR(*ref_frame->video_frame_buffer(), |
317 *test_frame->video_frame_buffer()); | 343 *test_frame->video_frame_buffer()); |
318 } | 344 } |
319 | 345 |
320 // Compute SSIM for an I420 frame (all planes) | 346 // Compute SSIM for an I420 frame (all planes). Can upscale test_buffer. |
321 double I420SSIM(const VideoFrameBuffer& ref_buffer, | 347 double I420SSIM(const VideoFrameBuffer& ref_buffer, |
322 const VideoFrameBuffer& test_buffer) { | 348 const VideoFrameBuffer& test_buffer) { |
323 if ((ref_buffer.width() != test_buffer.width()) || | 349 if ((ref_buffer.width() < test_buffer.width()) || |
324 (ref_buffer.height() != test_buffer.height())) | 350 (ref_buffer.height() < test_buffer.height())) { |
325 return -1; | 351 return -1; |
326 else if (ref_buffer.width() < 0 || ref_buffer.height() < 0) | 352 } else if (ref_buffer.width() < 0 || ref_buffer.height() < 0) { |
327 return -1; | 353 return -1; |
328 | 354 } else if ((ref_buffer.width() > test_buffer.width()) || |
355 (ref_buffer.height() > test_buffer.height())) { | |
356 rtc::scoped_refptr<I420Buffer> upscaled_buffer = | |
sprang_webrtc
2017/02/09 17:10:39
dito
ilnik
2017/02/10 10:11:43
Done.
| |
357 I420Buffer::Create(ref_buffer.width(), ref_buffer.height()); | |
358 int result = libyuv::I420Scale( | |
359 test_buffer.DataY(), test_buffer.StrideY(), test_buffer.DataU(), | |
360 test_buffer.StrideU(), test_buffer.DataV(), test_buffer.StrideV(), | |
361 test_buffer.width(), test_buffer.height(), | |
362 upscaled_buffer->MutableDataY(), upscaled_buffer->StrideY(), | |
363 upscaled_buffer->MutableDataU(), upscaled_buffer->StrideU(), | |
364 upscaled_buffer->MutableDataV(), upscaled_buffer->StrideV(), | |
365 upscaled_buffer->width(), upscaled_buffer->height(), | |
366 libyuv::kFilterBilinear); | |
367 if (result != 0) { | |
368 return -1; | |
369 } | |
370 return libyuv::I420Ssim( | |
371 ref_buffer.DataY(), ref_buffer.StrideY(), ref_buffer.DataU(), | |
372 ref_buffer.StrideU(), ref_buffer.DataV(), ref_buffer.StrideV(), | |
373 upscaled_buffer->DataY(), upscaled_buffer->StrideY(), | |
374 upscaled_buffer->DataU(), upscaled_buffer->StrideU(), | |
375 upscaled_buffer->DataV(), upscaled_buffer->StrideV(), | |
376 upscaled_buffer->width(), upscaled_buffer->height()); | |
377 } | |
329 return libyuv::I420Ssim(ref_buffer.DataY(), ref_buffer.StrideY(), | 378 return libyuv::I420Ssim(ref_buffer.DataY(), ref_buffer.StrideY(), |
330 ref_buffer.DataU(), ref_buffer.StrideU(), | 379 ref_buffer.DataU(), ref_buffer.StrideU(), |
331 ref_buffer.DataV(), ref_buffer.StrideV(), | 380 ref_buffer.DataV(), ref_buffer.StrideV(), |
332 test_buffer.DataY(), test_buffer.StrideY(), | 381 test_buffer.DataY(), test_buffer.StrideY(), |
333 test_buffer.DataU(), test_buffer.StrideU(), | 382 test_buffer.DataU(), test_buffer.StrideU(), |
334 test_buffer.DataV(), test_buffer.StrideV(), | 383 test_buffer.DataV(), test_buffer.StrideV(), |
335 test_buffer.width(), test_buffer.height()); | 384 test_buffer.width(), test_buffer.height()); |
336 } | 385 } |
337 double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame) { | 386 double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame) { |
338 if (!ref_frame || !test_frame) | 387 if (!ref_frame || !test_frame) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 src_v, src_uv_width, | 491 src_v, src_uv_width, |
443 src_width, src_height, | 492 src_width, src_height, |
444 dst_y, dst_stride_y, | 493 dst_y, dst_stride_y, |
445 dst_u, dst_stride_u, | 494 dst_u, dst_stride_u, |
446 dst_v, dst_stride_v, | 495 dst_v, dst_stride_v, |
447 dst_width, dst_height, | 496 dst_width, dst_height, |
448 libyuv::kFilterBox); | 497 libyuv::kFilterBox); |
449 } | 498 } |
450 | 499 |
451 } // namespace webrtc | 500 } // namespace webrtc |
OLD | NEW |