3 * Copyright 2011 Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
28 #ifndef TALK_MEDIA_BASE_FAKEVIDEORENDERER_H_
29 #define TALK_MEDIA_BASE_FAKEVIDEORENDERER_H_
31 #include "talk/media/base/videoframe.h"
32 #include "talk/media/base/videorenderer.h"
33 #include "webrtc/base/logging.h"
34 #include "webrtc/base/sigslot.h"
38 // Faked video renderer that has a callback for actions on rendering.
39 class FakeVideoRenderer : public VideoRenderer {
46 num_rendered_frames_(0),
50 virtual bool SetSize(int width, int height, int reserved) {
51 rtc::CritScope cs(&crit_);
55 SignalSetSize(width, height, reserved);
59 virtual bool RenderFrame(const VideoFrame* frame) {
60 rtc::CritScope cs(&crit_);
61 // TODO(zhurunz) Check with VP8 team to see if we can remove this
62 // tolerance on Y values.
63 black_frame_ = CheckFrameColorYuv(6, 48, 128, 128, 128, 128, frame);
64 // Treat unexpected frame size as error.
66 frame->GetWidth() != static_cast<size_t>(width_) ||
67 frame->GetHeight() != static_cast<size_t>(height_)) {
69 LOG(LS_WARNING) << "RenderFrame expected non-null frame.";
71 LOG(LS_WARNING) << "RenderFrame expected frame of size " << width_
72 << "x" << height_ << " but received frame of size "
73 << frame->GetWidth() << "x" << frame->GetHeight();
78 ++num_rendered_frames_;
79 SignalRenderFrame(frame);
83 int errors() const { return errors_; }
85 rtc::CritScope cs(&crit_);
89 rtc::CritScope cs(&crit_);
92 int num_set_sizes() const {
93 rtc::CritScope cs(&crit_);
94 return num_set_sizes_;
96 int num_rendered_frames() const {
97 rtc::CritScope cs(&crit_);
98 return num_rendered_frames_;
100 bool black_frame() const {
101 rtc::CritScope cs(&crit_);
105 sigslot::signal3<int, int, int> SignalSetSize;
106 sigslot::signal1<const VideoFrame*> SignalRenderFrame;
109 static bool CheckFrameColorYuv(uint8 y_min, uint8 y_max,
110 uint8 u_min, uint8 u_max,
111 uint8 v_min, uint8 v_max,
112 const cricket::VideoFrame* frame) {
117 size_t y_width = frame->GetWidth();
118 size_t y_height = frame->GetHeight();
119 const uint8* y_plane = frame->GetYPlane();
120 const uint8* y_pos = y_plane;
121 int32 y_pitch = frame->GetYPitch();
122 for (size_t i = 0; i < y_height; ++i) {
123 for (size_t j = 0; j < y_width; ++j) {
124 uint8 y_value = *(y_pos + j);
125 if (y_value < y_min || y_value > y_max) {
132 size_t chroma_width = frame->GetChromaWidth();
133 size_t chroma_height = frame->GetChromaHeight();
134 const uint8* u_plane = frame->GetUPlane();
135 const uint8* v_plane = frame->GetVPlane();
136 const uint8* u_pos = u_plane;
137 const uint8* v_pos = v_plane;
138 int32 u_pitch = frame->GetUPitch();
139 int32 v_pitch = frame->GetVPitch();
140 for (size_t i = 0; i < chroma_height; ++i) {
141 for (size_t j = 0; j < chroma_width; ++j) {
142 uint8 u_value = *(u_pos + j);
143 if (u_value < u_min || u_value > u_max) {
146 uint8 v_value = *(v_pos + j);
147 if (v_value < v_min || v_value > v_max) {
161 int num_rendered_frames_;
163 mutable rtc::CriticalSection crit_;
166 } // namespace cricket
168 #endif // TALK_MEDIA_BASE_FAKEVIDEORENDERER_H_