aboutsummaryrefslogtreecommitdiff
path: root/webrtc/common_video/video_frame.cc
diff options
context:
space:
mode:
Diffstat (limited to 'webrtc/common_video/video_frame.cc')
-rw-r--r--webrtc/common_video/video_frame.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/webrtc/common_video/video_frame.cc b/webrtc/common_video/video_frame.cc
index 7cdbd53f9d..710a06d3dc 100644
--- a/webrtc/common_video/video_frame.cc
+++ b/webrtc/common_video/video_frame.cc
@@ -19,6 +19,29 @@
namespace webrtc {
+bool EqualPlane(const uint8_t* data1,
+ const uint8_t* data2,
+ int stride,
+ int width,
+ int height) {
+ for (int y = 0; y < height; ++y) {
+ if (memcmp(data1, data2, width) != 0)
+ return false;
+ data1 += stride;
+ data2 += stride;
+ }
+ return true;
+}
+
+int ExpectedSize(int plane_stride, int image_height, PlaneType type) {
+ if (type == kYPlane) {
+ return (plane_stride * image_height);
+ } else {
+ int half_height = (image_height + 1) / 2;
+ return (plane_stride * half_height);
+ }
+}
+
VideoFrame::VideoFrame() {
// Intentionally using Reset instead of initializer list so that any missed
// fields in Reset will be caught by memory checkers.
@@ -202,4 +225,24 @@ VideoFrame VideoFrame::ConvertNativeToI420Frame() const {
return frame;
}
+bool VideoFrame::EqualsFrame(const VideoFrame& frame) const {
+ if ((this->width() != frame.width()) || (this->height() != frame.height()) ||
+ (this->stride(kYPlane) != frame.stride(kYPlane)) ||
+ (this->stride(kUPlane) != frame.stride(kUPlane)) ||
+ (this->stride(kVPlane) != frame.stride(kVPlane)) ||
+ (this->timestamp() != frame.timestamp()) ||
+ (this->ntp_time_ms() != frame.ntp_time_ms()) ||
+ (this->render_time_ms() != frame.render_time_ms())) {
+ return false;
+ }
+ const int half_width = (this->width() + 1) / 2;
+ const int half_height = (this->height() + 1) / 2;
+ return EqualPlane(this->buffer(kYPlane), frame.buffer(kYPlane),
+ this->stride(kYPlane), this->width(), this->height()) &&
+ EqualPlane(this->buffer(kUPlane), frame.buffer(kUPlane),
+ this->stride(kUPlane), half_width, half_height) &&
+ EqualPlane(this->buffer(kVPlane), frame.buffer(kVPlane),
+ this->stride(kVPlane), half_width, half_height);
+}
+
} // namespace webrtc