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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 242 |
243 // TODO(nisse): Delete this wrapper, let callers use libyuv directly. | 243 // TODO(nisse): Delete this wrapper, let callers use libyuv directly. |
244 int ConvertToI420(VideoType src_video_type, | 244 int ConvertToI420(VideoType src_video_type, |
245 const uint8_t* src_frame, | 245 const uint8_t* src_frame, |
246 int crop_x, | 246 int crop_x, |
247 int crop_y, | 247 int crop_y, |
248 int src_width, | 248 int src_width, |
249 int src_height, | 249 int src_height, |
250 size_t sample_size, | 250 size_t sample_size, |
251 VideoRotation rotation, | 251 VideoRotation rotation, |
252 VideoFrame* dst_frame) { | 252 const rtc::scoped_refptr<I420Buffer>& dst_buffer) { |
253 int dst_width = dst_frame->width(); | 253 int dst_width = dst_buffer->width(); |
254 int dst_height = dst_frame->height(); | 254 int dst_height = dst_buffer->height(); |
255 // LibYuv expects pre-rotation values for dst. | 255 // LibYuv expects pre-rotation values for dst. |
256 // Stride values should correspond to the destination values. | 256 // Stride values should correspond to the destination values. |
257 if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { | 257 if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { |
258 dst_width = dst_frame->height(); | 258 dst_width = dst_buffer->height(); |
259 dst_height = dst_frame->width(); | 259 dst_height = dst_buffer->width(); |
260 } | 260 } |
261 return libyuv::ConvertToI420( | 261 return libyuv::ConvertToI420( |
262 src_frame, sample_size, | 262 src_frame, sample_size, |
263 dst_frame->video_frame_buffer()->MutableDataY(), | 263 dst_buffer->MutableDataY(), dst_buffer->StrideY(), |
264 dst_frame->video_frame_buffer()->StrideY(), | 264 dst_buffer->MutableDataU(), dst_buffer->StrideU(), |
265 dst_frame->video_frame_buffer()->MutableDataU(), | 265 dst_buffer->MutableDataV(), dst_buffer->StrideV(), |
266 dst_frame->video_frame_buffer()->StrideU(), | |
267 dst_frame->video_frame_buffer()->MutableDataV(), | |
268 dst_frame->video_frame_buffer()->StrideV(), | |
269 crop_x, crop_y, | 266 crop_x, crop_y, |
270 src_width, src_height, | 267 src_width, src_height, |
271 dst_width, dst_height, | 268 dst_width, dst_height, |
272 ConvertRotationMode(rotation), | 269 ConvertRotationMode(rotation), |
273 ConvertVideoType(src_video_type)); | 270 ConvertVideoType(src_video_type)); |
274 } | 271 } |
275 | 272 |
276 int ConvertFromI420(const VideoFrame& src_frame, | 273 int ConvertFromI420(const VideoFrame& src_frame, |
277 VideoType dst_video_type, | 274 VideoType dst_video_type, |
278 int dst_sample_size, | 275 int dst_sample_size, |
279 uint8_t* dst_frame) { | 276 uint8_t* dst_frame) { |
280 return libyuv::ConvertFromI420( | 277 return libyuv::ConvertFromI420( |
281 src_frame.video_frame_buffer()->DataY(), | 278 src_frame.video_frame_buffer()->DataY(), |
282 src_frame.video_frame_buffer()->StrideY(), | 279 src_frame.video_frame_buffer()->StrideY(), |
283 src_frame.video_frame_buffer()->DataU(), | 280 src_frame.video_frame_buffer()->DataU(), |
284 src_frame.video_frame_buffer()->StrideU(), | 281 src_frame.video_frame_buffer()->StrideU(), |
285 src_frame.video_frame_buffer()->DataV(), | 282 src_frame.video_frame_buffer()->DataV(), |
286 src_frame.video_frame_buffer()->StrideV(), | 283 src_frame.video_frame_buffer()->StrideV(), |
287 dst_frame, dst_sample_size, | 284 dst_frame, dst_sample_size, |
288 src_frame.width(), src_frame.height(), | 285 src_frame.width(), src_frame.height(), |
289 ConvertVideoType(dst_video_type)); | 286 ConvertVideoType(dst_video_type)); |
290 } | 287 } |
291 | 288 |
292 // Compute PSNR for an I420 frame (all planes) | 289 // Compute PSNR for an I420 frame (all planes) |
| 290 double I420PSNR(const rtc::scoped_refptr<VideoFrameBuffer>& ref_buffer, |
| 291 const rtc::scoped_refptr<VideoFrameBuffer>& test_buffer) { |
| 292 if (!ref_buffer || !test_buffer) |
| 293 return -1; |
| 294 else if ((ref_buffer->width() != test_buffer->width()) || |
| 295 (ref_buffer->height() != test_buffer->height())) |
| 296 return -1; |
| 297 else if (ref_buffer->width() < 0 || ref_buffer->height() < 0) |
| 298 return -1; |
| 299 |
| 300 double psnr = libyuv::I420Psnr(ref_buffer->DataY(), ref_buffer->StrideY(), |
| 301 ref_buffer->DataU(), ref_buffer->StrideU(), |
| 302 ref_buffer->DataV(), ref_buffer->StrideV(), |
| 303 test_buffer->DataY(), test_buffer->StrideY(), |
| 304 test_buffer->DataU(), test_buffer->StrideU(), |
| 305 test_buffer->DataV(), test_buffer->StrideV(), |
| 306 test_buffer->width(), test_buffer->height()); |
| 307 // 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. |
| 309 return (psnr > kPerfectPSNR) ? kPerfectPSNR : psnr; |
| 310 } |
| 311 |
| 312 // Compute PSNR for an I420 frame (all planes) |
293 double I420PSNR(const VideoFrame* ref_frame, const VideoFrame* test_frame) { | 313 double I420PSNR(const VideoFrame* ref_frame, const VideoFrame* test_frame) { |
294 if (!ref_frame || !test_frame) | 314 if (!ref_frame || !test_frame) |
295 return -1; | 315 return -1; |
296 else if ((ref_frame->width() != test_frame->width()) || | 316 return I420PSNR(ref_frame->video_frame_buffer(), |
297 (ref_frame->height() != test_frame->height())) | 317 test_frame->video_frame_buffer()); |
298 return -1; | |
299 else if (ref_frame->width() < 0 || ref_frame->height() < 0) | |
300 return -1; | |
301 | |
302 double psnr = libyuv::I420Psnr(ref_frame->video_frame_buffer()->DataY(), | |
303 ref_frame->video_frame_buffer()->StrideY(), | |
304 ref_frame->video_frame_buffer()->DataU(), | |
305 ref_frame->video_frame_buffer()->StrideU(), | |
306 ref_frame->video_frame_buffer()->DataV(), | |
307 ref_frame->video_frame_buffer()->StrideV(), | |
308 test_frame->video_frame_buffer()->DataY(), | |
309 test_frame->video_frame_buffer()->StrideY(), | |
310 test_frame->video_frame_buffer()->DataU(), | |
311 test_frame->video_frame_buffer()->StrideU(), | |
312 test_frame->video_frame_buffer()->DataV(), | |
313 test_frame->video_frame_buffer()->StrideV(), | |
314 test_frame->width(), test_frame->height()); | |
315 // LibYuv sets the max psnr value to 128, we restrict it here. | |
316 // In case of 0 mse in one frame, 128 can skew the results significantly. | |
317 return (psnr > kPerfectPSNR) ? kPerfectPSNR : psnr; | |
318 } | 318 } |
319 | 319 |
320 // Compute SSIM for an I420 frame (all planes) | 320 // Compute SSIM for an I420 frame (all planes) |
| 321 double I420SSIM(const rtc::scoped_refptr<VideoFrameBuffer>& ref_buffer, |
| 322 const rtc::scoped_refptr<VideoFrameBuffer>& test_buffer) { |
| 323 if (!ref_buffer || !test_buffer) |
| 324 return -1; |
| 325 else if ((ref_buffer->width() != test_buffer->width()) || |
| 326 (ref_buffer->height() != test_buffer->height())) |
| 327 return -1; |
| 328 else if (ref_buffer->width() < 0 || ref_buffer->height() < 0) |
| 329 return -1; |
| 330 |
| 331 return libyuv::I420Ssim(ref_buffer->DataY(), ref_buffer->StrideY(), |
| 332 ref_buffer->DataU(), ref_buffer->StrideU(), |
| 333 ref_buffer->DataV(), ref_buffer->StrideV(), |
| 334 test_buffer->DataY(), test_buffer->StrideY(), |
| 335 test_buffer->DataU(), test_buffer->StrideU(), |
| 336 test_buffer->DataV(), test_buffer->StrideV(), |
| 337 test_buffer->width(), test_buffer->height()); |
| 338 } |
321 double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame) { | 339 double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame) { |
322 if (!ref_frame || !test_frame) | 340 if (!ref_frame || !test_frame) |
323 return -1; | 341 return -1; |
324 else if ((ref_frame->width() != test_frame->width()) || | 342 return I420SSIM(ref_frame->video_frame_buffer(), |
325 (ref_frame->height() != test_frame->height())) | 343 test_frame->video_frame_buffer()); |
326 return -1; | |
327 else if (ref_frame->width() < 0 || ref_frame->height() < 0) | |
328 return -1; | |
329 | |
330 return libyuv::I420Ssim(ref_frame->video_frame_buffer()->DataY(), | |
331 ref_frame->video_frame_buffer()->StrideY(), | |
332 ref_frame->video_frame_buffer()->DataU(), | |
333 ref_frame->video_frame_buffer()->StrideU(), | |
334 ref_frame->video_frame_buffer()->DataV(), | |
335 ref_frame->video_frame_buffer()->StrideV(), | |
336 test_frame->video_frame_buffer()->DataY(), | |
337 test_frame->video_frame_buffer()->StrideY(), | |
338 test_frame->video_frame_buffer()->DataU(), | |
339 test_frame->video_frame_buffer()->StrideU(), | |
340 test_frame->video_frame_buffer()->DataV(), | |
341 test_frame->video_frame_buffer()->StrideV(), | |
342 test_frame->width(), test_frame->height()); | |
343 } | 344 } |
344 } // namespace webrtc | 345 } // namespace webrtc |
OLD | NEW |