You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "test/frame_utils.h"
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include "api/video/i420_buffer.h"
  14. #include "api/video/video_frame.h"
  15. namespace webrtc {
  16. namespace test {
  17. bool EqualPlane(const uint8_t* data1,
  18. const uint8_t* data2,
  19. int stride1,
  20. int stride2,
  21. int width,
  22. int height) {
  23. for (int y = 0; y < height; ++y) {
  24. if (memcmp(data1, data2, width) != 0)
  25. return false;
  26. data1 += stride1;
  27. data2 += stride2;
  28. }
  29. return true;
  30. }
  31. bool FramesEqual(const webrtc::VideoFrame& f1, const webrtc::VideoFrame& f2) {
  32. if (f1.timestamp() != f2.timestamp() ||
  33. f1.ntp_time_ms() != f2.ntp_time_ms() ||
  34. f1.render_time_ms() != f2.render_time_ms()) {
  35. return false;
  36. }
  37. return FrameBufsEqual(f1.video_frame_buffer(), f2.video_frame_buffer());
  38. }
  39. bool FrameBufsEqual(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f1,
  40. const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f2) {
  41. if (f1 == f2) {
  42. return true;
  43. }
  44. // Exlude nullptr (except if both are nullptr, as above)
  45. if (!f1 || !f2) {
  46. return false;
  47. }
  48. if (f1->width() != f2->width() || f1->height() != f2->height() ||
  49. f1->type() != f2->type()) {
  50. return false;
  51. }
  52. rtc::scoped_refptr<webrtc::I420BufferInterface> f1_i420 = f1->ToI420();
  53. rtc::scoped_refptr<webrtc::I420BufferInterface> f2_i420 = f2->ToI420();
  54. return EqualPlane(f1_i420->DataY(), f2_i420->DataY(), f1_i420->StrideY(),
  55. f2_i420->StrideY(), f1_i420->width(), f1_i420->height()) &&
  56. EqualPlane(f1_i420->DataU(), f2_i420->DataU(), f1_i420->StrideU(),
  57. f2_i420->StrideU(), f1_i420->ChromaWidth(),
  58. f1_i420->ChromaHeight()) &&
  59. EqualPlane(f1_i420->DataV(), f2_i420->DataV(), f1_i420->StrideV(),
  60. f2_i420->StrideV(), f1_i420->ChromaWidth(),
  61. f1_i420->ChromaHeight());
  62. }
  63. rtc::scoped_refptr<I420Buffer> ReadI420Buffer(int width, int height, FILE* f) {
  64. int half_width = (width + 1) / 2;
  65. rtc::scoped_refptr<I420Buffer> buffer(
  66. // Explicit stride, no padding between rows.
  67. I420Buffer::Create(width, height, width, half_width, half_width));
  68. size_t size_y = static_cast<size_t>(width) * height;
  69. size_t size_uv = static_cast<size_t>(half_width) * ((height + 1) / 2);
  70. if (fread(buffer->MutableDataY(), 1, size_y, f) < size_y)
  71. return nullptr;
  72. if (fread(buffer->MutableDataU(), 1, size_uv, f) < size_uv)
  73. return nullptr;
  74. if (fread(buffer->MutableDataV(), 1, size_uv, f) < size_uv)
  75. return nullptr;
  76. return buffer;
  77. }
  78. } // namespace test
  79. } // namespace webrtc