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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 int stride, | 96 int stride, |
97 FILE* file) { | 97 FILE* file) { |
98 for (int i = 0; i < height; i++, buf += stride) { | 98 for (int i = 0; i < height; i++, buf += stride) { |
99 if (fwrite(buf, 1, width, file) != static_cast<unsigned int>(width)) | 99 if (fwrite(buf, 1, width, file) != static_cast<unsigned int>(width)) |
100 return -1; | 100 return -1; |
101 } | 101 } |
102 return 0; | 102 return 0; |
103 } | 103 } |
104 | 104 |
105 // TODO(nisse): Belongs with the test code? | 105 // TODO(nisse): Belongs with the test code? |
106 int PrintVideoFrame(const VideoFrame& frame, FILE* file) { | 106 int PrintVideoFrame(const VideoFrameBuffer& frame, FILE* file) { |
107 if (file == NULL) | 107 int width = frame.width(); |
108 return -1; | 108 int height = frame.height(); |
109 if (frame.IsZeroSize()) | |
110 return -1; | |
111 int width = frame.video_frame_buffer()->width(); | |
112 int height = frame.video_frame_buffer()->height(); | |
113 int chroma_width = (width + 1) / 2; | 109 int chroma_width = (width + 1) / 2; |
114 int chroma_height = (height + 1) / 2; | 110 int chroma_height = (height + 1) / 2; |
115 | 111 |
116 if (PrintPlane(frame.video_frame_buffer()->DataY(), width, height, | 112 if (PrintPlane(frame.DataY(), width, height, |
117 frame.video_frame_buffer()->StrideY(), file) < 0) { | 113 frame.StrideY(), file) < 0) { |
118 return -1; | 114 return -1; |
119 } | 115 } |
120 if (PrintPlane(frame.video_frame_buffer()->DataU(), | 116 if (PrintPlane(frame.DataU(), |
121 chroma_width, chroma_height, | 117 chroma_width, chroma_height, |
122 frame.video_frame_buffer()->StrideU(), file) < 0) { | 118 frame.StrideU(), file) < 0) { |
123 return -1; | 119 return -1; |
124 } | 120 } |
125 if (PrintPlane(frame.video_frame_buffer()->DataV(), | 121 if (PrintPlane(frame.DataV(), |
126 chroma_width, chroma_height, | 122 chroma_width, chroma_height, |
127 frame.video_frame_buffer()->StrideV(), file) < 0) { | 123 frame.StrideV(), file) < 0) { |
128 return -1; | 124 return -1; |
129 } | 125 } |
130 return 0; | 126 return 0; |
131 } | 127 } |
132 | 128 |
| 129 int PrintVideoFrame(const VideoFrame& frame, FILE* file) { |
| 130 if (frame.IsZeroSize()) |
| 131 return -1; |
| 132 return PrintVideoFrame(*frame.video_frame_buffer(), file); |
| 133 } |
| 134 |
133 int ExtractBuffer(const rtc::scoped_refptr<VideoFrameBuffer>& input_frame, | 135 int ExtractBuffer(const rtc::scoped_refptr<VideoFrameBuffer>& input_frame, |
134 size_t size, | 136 size_t size, |
135 uint8_t* buffer) { | 137 uint8_t* buffer) { |
136 assert(buffer); | 138 assert(buffer); |
137 if (!input_frame) | 139 if (!input_frame) |
138 return -1; | 140 return -1; |
139 int width = input_frame->width(); | 141 int width = input_frame->width(); |
140 int height = input_frame->height(); | 142 int height = input_frame->height(); |
141 size_t length = CalcBufferSize(kI420, width, height); | 143 size_t length = CalcBufferSize(kI420, width, height); |
142 if (size < length) { | 144 if (size < length) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 244 |
243 // TODO(nisse): Delete this wrapper, let callers use libyuv directly. | 245 // TODO(nisse): Delete this wrapper, let callers use libyuv directly. |
244 int ConvertToI420(VideoType src_video_type, | 246 int ConvertToI420(VideoType src_video_type, |
245 const uint8_t* src_frame, | 247 const uint8_t* src_frame, |
246 int crop_x, | 248 int crop_x, |
247 int crop_y, | 249 int crop_y, |
248 int src_width, | 250 int src_width, |
249 int src_height, | 251 int src_height, |
250 size_t sample_size, | 252 size_t sample_size, |
251 VideoRotation rotation, | 253 VideoRotation rotation, |
252 VideoFrame* dst_frame) { | 254 I420Buffer* dst_buffer) { |
253 int dst_width = dst_frame->width(); | 255 int dst_width = dst_buffer->width(); |
254 int dst_height = dst_frame->height(); | 256 int dst_height = dst_buffer->height(); |
255 // LibYuv expects pre-rotation values for dst. | 257 // LibYuv expects pre-rotation values for dst. |
256 // Stride values should correspond to the destination values. | 258 // Stride values should correspond to the destination values. |
257 if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { | 259 if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { |
258 dst_width = dst_frame->height(); | 260 std::swap(dst_width, dst_height); |
259 dst_height = dst_frame->width(); | |
260 } | 261 } |
261 return libyuv::ConvertToI420( | 262 return libyuv::ConvertToI420( |
262 src_frame, sample_size, | 263 src_frame, sample_size, |
263 dst_frame->video_frame_buffer()->MutableDataY(), | 264 dst_buffer->MutableDataY(), dst_buffer->StrideY(), |
264 dst_frame->video_frame_buffer()->StrideY(), | 265 dst_buffer->MutableDataU(), dst_buffer->StrideU(), |
265 dst_frame->video_frame_buffer()->MutableDataU(), | 266 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, | 267 crop_x, crop_y, |
270 src_width, src_height, | 268 src_width, src_height, |
271 dst_width, dst_height, | 269 dst_width, dst_height, |
272 ConvertRotationMode(rotation), | 270 ConvertRotationMode(rotation), |
273 ConvertVideoType(src_video_type)); | 271 ConvertVideoType(src_video_type)); |
274 } | 272 } |
275 | 273 |
276 int ConvertFromI420(const VideoFrame& src_frame, | 274 int ConvertFromI420(const VideoFrame& src_frame, |
277 VideoType dst_video_type, | 275 VideoType dst_video_type, |
278 int dst_sample_size, | 276 int dst_sample_size, |
279 uint8_t* dst_frame) { | 277 uint8_t* dst_frame) { |
280 return libyuv::ConvertFromI420( | 278 return libyuv::ConvertFromI420( |
281 src_frame.video_frame_buffer()->DataY(), | 279 src_frame.video_frame_buffer()->DataY(), |
282 src_frame.video_frame_buffer()->StrideY(), | 280 src_frame.video_frame_buffer()->StrideY(), |
283 src_frame.video_frame_buffer()->DataU(), | 281 src_frame.video_frame_buffer()->DataU(), |
284 src_frame.video_frame_buffer()->StrideU(), | 282 src_frame.video_frame_buffer()->StrideU(), |
285 src_frame.video_frame_buffer()->DataV(), | 283 src_frame.video_frame_buffer()->DataV(), |
286 src_frame.video_frame_buffer()->StrideV(), | 284 src_frame.video_frame_buffer()->StrideV(), |
287 dst_frame, dst_sample_size, | 285 dst_frame, dst_sample_size, |
288 src_frame.width(), src_frame.height(), | 286 src_frame.width(), src_frame.height(), |
289 ConvertVideoType(dst_video_type)); | 287 ConvertVideoType(dst_video_type)); |
290 } | 288 } |
291 | 289 |
292 // Compute PSNR for an I420 frame (all planes) | 290 // Compute PSNR for an I420 frame (all planes) |
| 291 double I420PSNR(const VideoFrameBuffer& ref_buffer, |
| 292 const VideoFrameBuffer& test_buffer) { |
| 293 if ((ref_buffer.width() != test_buffer.width()) || |
| 294 (ref_buffer.height() != test_buffer.height())) |
| 295 return -1; |
| 296 else if (ref_buffer.width() < 0 || ref_buffer.height() < 0) |
| 297 return -1; |
| 298 |
| 299 double psnr = libyuv::I420Psnr(ref_buffer.DataY(), ref_buffer.StrideY(), |
| 300 ref_buffer.DataU(), ref_buffer.StrideU(), |
| 301 ref_buffer.DataV(), ref_buffer.StrideV(), |
| 302 test_buffer.DataY(), test_buffer.StrideY(), |
| 303 test_buffer.DataU(), test_buffer.StrideU(), |
| 304 test_buffer.DataV(), test_buffer.StrideV(), |
| 305 test_buffer.width(), test_buffer.height()); |
| 306 // LibYuv sets the max psnr value to 128, we restrict it here. |
| 307 // In case of 0 mse in one frame, 128 can skew the results significantly. |
| 308 return (psnr > kPerfectPSNR) ? kPerfectPSNR : psnr; |
| 309 } |
| 310 |
| 311 // Compute PSNR for an I420 frame (all planes) |
293 double I420PSNR(const VideoFrame* ref_frame, const VideoFrame* test_frame) { | 312 double I420PSNR(const VideoFrame* ref_frame, const VideoFrame* test_frame) { |
294 if (!ref_frame || !test_frame) | 313 if (!ref_frame || !test_frame) |
295 return -1; | 314 return -1; |
296 else if ((ref_frame->width() != test_frame->width()) || | 315 return I420PSNR(*ref_frame->video_frame_buffer(), |
297 (ref_frame->height() != test_frame->height())) | 316 *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 } | 317 } |
319 | 318 |
320 // Compute SSIM for an I420 frame (all planes) | 319 // Compute SSIM for an I420 frame (all planes) |
| 320 double I420SSIM(const VideoFrameBuffer& ref_buffer, |
| 321 const VideoFrameBuffer& test_buffer) { |
| 322 if ((ref_buffer.width() != test_buffer.width()) || |
| 323 (ref_buffer.height() != test_buffer.height())) |
| 324 return -1; |
| 325 else if (ref_buffer.width() < 0 || ref_buffer.height() < 0) |
| 326 return -1; |
| 327 |
| 328 return libyuv::I420Ssim(ref_buffer.DataY(), ref_buffer.StrideY(), |
| 329 ref_buffer.DataU(), ref_buffer.StrideU(), |
| 330 ref_buffer.DataV(), ref_buffer.StrideV(), |
| 331 test_buffer.DataY(), test_buffer.StrideY(), |
| 332 test_buffer.DataU(), test_buffer.StrideU(), |
| 333 test_buffer.DataV(), test_buffer.StrideV(), |
| 334 test_buffer.width(), test_buffer.height()); |
| 335 } |
321 double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame) { | 336 double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame) { |
322 if (!ref_frame || !test_frame) | 337 if (!ref_frame || !test_frame) |
323 return -1; | 338 return -1; |
324 else if ((ref_frame->width() != test_frame->width()) || | 339 return I420SSIM(*ref_frame->video_frame_buffer(), |
325 (ref_frame->height() != test_frame->height())) | 340 *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 } | 341 } |
344 } // namespace webrtc | 342 } // namespace webrtc |
OLD | NEW |