1 /* 2 * Copyright (c) 2018 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 11 #include "media/base/fake_video_renderer.h" 12 13 namespace cricket { 14 namespace { CheckFrameColorYuv(const webrtc::VideoFrame & frame)15bool CheckFrameColorYuv(const webrtc::VideoFrame& frame) { 16 // TODO(zhurunz) Check with VP8 team to see if we can remove this 17 // tolerance on Y values. Some unit tests produce Y values close 18 // to 16 rather than close to zero, for supposedly black frames. 19 // Largest value observed is 34, e.g., running 20 // PeerConnectionIntegrationTest.SendAndReceive16To9AspectRatio. 21 static constexpr uint8_t y_min = 0; 22 static constexpr uint8_t y_max = 48; 23 static constexpr uint8_t u_min = 128; 24 static constexpr uint8_t u_max = 128; 25 static constexpr uint8_t v_min = 128; 26 static constexpr uint8_t v_max = 128; 27 28 if (!frame.video_frame_buffer()) { 29 return false; 30 } 31 rtc::scoped_refptr<const webrtc::I420BufferInterface> i420_buffer = 32 frame.video_frame_buffer()->ToI420(); 33 // Y 34 int y_width = frame.width(); 35 int y_height = frame.height(); 36 const uint8_t* y_plane = i420_buffer->DataY(); 37 const uint8_t* y_pos = y_plane; 38 int32_t y_pitch = i420_buffer->StrideY(); 39 for (int i = 0; i < y_height; ++i) { 40 for (int j = 0; j < y_width; ++j) { 41 uint8_t y_value = *(y_pos + j); 42 if (y_value < y_min || y_value > y_max) { 43 return false; 44 } 45 } 46 y_pos += y_pitch; 47 } 48 // U and V 49 int chroma_width = i420_buffer->ChromaWidth(); 50 int chroma_height = i420_buffer->ChromaHeight(); 51 const uint8_t* u_plane = i420_buffer->DataU(); 52 const uint8_t* v_plane = i420_buffer->DataV(); 53 const uint8_t* u_pos = u_plane; 54 const uint8_t* v_pos = v_plane; 55 int32_t u_pitch = i420_buffer->StrideU(); 56 int32_t v_pitch = i420_buffer->StrideV(); 57 for (int i = 0; i < chroma_height; ++i) { 58 for (int j = 0; j < chroma_width; ++j) { 59 uint8_t u_value = *(u_pos + j); 60 if (u_value < u_min || u_value > u_max) { 61 return false; 62 } 63 uint8_t v_value = *(v_pos + j); 64 if (v_value < v_min || v_value > v_max) { 65 return false; 66 } 67 } 68 u_pos += u_pitch; 69 v_pos += v_pitch; 70 } 71 return true; 72 } 73 } // namespace 74 75 FakeVideoRenderer::FakeVideoRenderer() = default; 76 OnFrame(const webrtc::VideoFrame & frame)77void FakeVideoRenderer::OnFrame(const webrtc::VideoFrame& frame) { 78 webrtc::MutexLock lock(&mutex_); 79 black_frame_ = CheckFrameColorYuv(frame); 80 ++num_rendered_frames_; 81 width_ = frame.width(); 82 height_ = frame.height(); 83 rotation_ = frame.rotation(); 84 timestamp_us_ = frame.timestamp_us(); 85 } 86 87 } // namespace cricket 88