henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame^] | 28 | #ifndef WEBRTC_MEDIA_BASE_FAKEVIDEORENDERER_H_ |
| 29 | #define WEBRTC_MEDIA_BASE_FAKEVIDEORENDERER_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 31 | #include "webrtc/base/logging.h" |
| 32 | #include "webrtc/base/sigslot.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame^] | 33 | #include "webrtc/media/base/videoframe.h" |
| 34 | #include "webrtc/media/base/videorenderer.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | |
| 36 | namespace cricket { |
| 37 | |
| 38 | // Faked video renderer that has a callback for actions on rendering. |
| 39 | class FakeVideoRenderer : public VideoRenderer { |
| 40 | public: |
| 41 | FakeVideoRenderer() |
| 42 | : errors_(0), |
| 43 | width_(0), |
| 44 | height_(0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | num_rendered_frames_(0), |
magjed | b09b660 | 2015-10-01 03:02:44 -0700 | [diff] [blame] | 46 | black_frame_(false) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | } |
| 48 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 49 | virtual bool RenderFrame(const VideoFrame* frame) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 50 | rtc::CritScope cs(&crit_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 51 | // TODO(zhurunz) Check with VP8 team to see if we can remove this |
| 52 | // tolerance on Y values. |
| 53 | black_frame_ = CheckFrameColorYuv(6, 48, 128, 128, 128, 128, frame); |
| 54 | // Treat unexpected frame size as error. |
nisse | c4c8485 | 2016-01-19 00:52:47 -0800 | [diff] [blame] | 55 | if (!frame) { |
| 56 | LOG(LS_WARNING) << "RenderFrame expected non-null frame."; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | ++errors_; |
| 58 | return false; |
| 59 | } |
| 60 | ++num_rendered_frames_; |
nisse | c4c8485 | 2016-01-19 00:52:47 -0800 | [diff] [blame] | 61 | width_ = static_cast<int>(frame->GetWidth()); |
| 62 | height_ = static_cast<int>(frame->GetHeight()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | SignalRenderFrame(frame); |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | int errors() const { return errors_; } |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 68 | int width() const { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 69 | rtc::CritScope cs(&crit_); |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 70 | return width_; |
| 71 | } |
| 72 | int height() const { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 73 | rtc::CritScope cs(&crit_); |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 74 | return height_; |
| 75 | } |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 76 | int num_rendered_frames() const { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 77 | rtc::CritScope cs(&crit_); |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 78 | return num_rendered_frames_; |
| 79 | } |
| 80 | bool black_frame() const { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 81 | rtc::CritScope cs(&crit_); |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 82 | return black_frame_; |
| 83 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | |
| 85 | sigslot::signal3<int, int, int> SignalSetSize; |
| 86 | sigslot::signal1<const VideoFrame*> SignalRenderFrame; |
| 87 | |
| 88 | private: |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 89 | static bool CheckFrameColorYuv(uint8_t y_min, |
| 90 | uint8_t y_max, |
| 91 | uint8_t u_min, |
| 92 | uint8_t u_max, |
| 93 | uint8_t v_min, |
| 94 | uint8_t v_max, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | const cricket::VideoFrame* frame) { |
| 96 | if (!frame) { |
| 97 | return false; |
| 98 | } |
| 99 | // Y |
| 100 | size_t y_width = frame->GetWidth(); |
| 101 | size_t y_height = frame->GetHeight(); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 102 | const uint8_t* y_plane = frame->GetYPlane(); |
| 103 | const uint8_t* y_pos = y_plane; |
| 104 | int32_t y_pitch = frame->GetYPitch(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 105 | for (size_t i = 0; i < y_height; ++i) { |
| 106 | for (size_t j = 0; j < y_width; ++j) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 107 | uint8_t y_value = *(y_pos + j); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | if (y_value < y_min || y_value > y_max) { |
| 109 | return false; |
| 110 | } |
| 111 | } |
| 112 | y_pos += y_pitch; |
| 113 | } |
| 114 | // U and V |
| 115 | size_t chroma_width = frame->GetChromaWidth(); |
| 116 | size_t chroma_height = frame->GetChromaHeight(); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 117 | const uint8_t* u_plane = frame->GetUPlane(); |
| 118 | const uint8_t* v_plane = frame->GetVPlane(); |
| 119 | const uint8_t* u_pos = u_plane; |
| 120 | const uint8_t* v_pos = v_plane; |
| 121 | int32_t u_pitch = frame->GetUPitch(); |
| 122 | int32_t v_pitch = frame->GetVPitch(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | for (size_t i = 0; i < chroma_height; ++i) { |
| 124 | for (size_t j = 0; j < chroma_width; ++j) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 125 | uint8_t u_value = *(u_pos + j); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 126 | if (u_value < u_min || u_value > u_max) { |
| 127 | return false; |
| 128 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 129 | uint8_t v_value = *(v_pos + j); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | if (v_value < v_min || v_value > v_max) { |
| 131 | return false; |
| 132 | } |
| 133 | } |
| 134 | u_pos += u_pitch; |
| 135 | v_pos += v_pitch; |
| 136 | } |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | int errors_; |
| 141 | int width_; |
| 142 | int height_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | int num_rendered_frames_; |
| 144 | bool black_frame_; |
pbos | 5ad935c | 2016-01-25 03:52:44 -0800 | [diff] [blame] | 145 | rtc::CriticalSection crit_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | } // namespace cricket |
| 149 | |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame^] | 150 | #endif // WEBRTC_MEDIA_BASE_FAKEVIDEORENDERER_H_ |