| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2010 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 #ifndef WEBRTC_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_ | |
| 12 #define WEBRTC_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_ | |
| 13 | |
| 14 #include <map> | |
| 15 #include <set> | |
| 16 #include <vector> | |
| 17 | |
| 18 #include "webrtc/base/basictypes.h" | |
| 19 #include "webrtc/base/criticalsection.h" | |
| 20 #include "webrtc/base/gunit.h" | |
| 21 #include "webrtc/base/stringutils.h" | |
| 22 #include "webrtc/base/thread_annotations.h" | |
| 23 #include "webrtc/media/base/codec.h" | |
| 24 #include "webrtc/media/webrtc/fakewebrtccommon.h" | |
| 25 #include "webrtc/media/webrtc/webrtcvideodecoderfactory.h" | |
| 26 #include "webrtc/media/webrtc/webrtcvideoencoderfactory.h" | |
| 27 #include "webrtc/modules/video_coding/include/video_error_codes.h" | |
| 28 #include "webrtc/video_decoder.h" | |
| 29 #include "webrtc/video_encoder.h" | |
| 30 | |
| 31 namespace cricket { | |
| 32 | |
| 33 static const int kMinVideoBitrate = 100; | |
| 34 static const int kStartVideoBitrate = 300; | |
| 35 static const int kMaxVideoBitrate = 1000; | |
| 36 | |
| 37 // WebRtc channel id and capture id share the same number space. | |
| 38 // This is how AddRenderer(renderId, ...) is able to tell if it is adding a | |
| 39 // renderer for a channel or it is adding a renderer for a capturer. | |
| 40 static const int kViEChannelIdBase = 0; | |
| 41 static const int kViEChannelIdMax = 1000; | |
| 42 | |
| 43 // Fake class for mocking out webrtc::VideoDecoder | |
| 44 class FakeWebRtcVideoDecoder : public webrtc::VideoDecoder { | |
| 45 public: | |
| 46 FakeWebRtcVideoDecoder() | |
| 47 : num_frames_received_(0) { | |
| 48 } | |
| 49 | |
| 50 virtual int32_t InitDecode(const webrtc::VideoCodec*, int32_t) { | |
| 51 return WEBRTC_VIDEO_CODEC_OK; | |
| 52 } | |
| 53 | |
| 54 virtual int32_t Decode(const webrtc::EncodedImage&, | |
| 55 bool, | |
| 56 const webrtc::RTPFragmentationHeader*, | |
| 57 const webrtc::CodecSpecificInfo*, | |
| 58 int64_t) { | |
| 59 num_frames_received_++; | |
| 60 return WEBRTC_VIDEO_CODEC_OK; | |
| 61 } | |
| 62 | |
| 63 virtual int32_t RegisterDecodeCompleteCallback( | |
| 64 webrtc::DecodedImageCallback*) { | |
| 65 return WEBRTC_VIDEO_CODEC_OK; | |
| 66 } | |
| 67 | |
| 68 virtual int32_t Release() { return WEBRTC_VIDEO_CODEC_OK; } | |
| 69 | |
| 70 int GetNumFramesReceived() const { | |
| 71 return num_frames_received_; | |
| 72 } | |
| 73 | |
| 74 private: | |
| 75 int num_frames_received_; | |
| 76 }; | |
| 77 | |
| 78 // Fake class for mocking out WebRtcVideoDecoderFactory. | |
| 79 class FakeWebRtcVideoDecoderFactory : public WebRtcVideoDecoderFactory { | |
| 80 public: | |
| 81 FakeWebRtcVideoDecoderFactory() | |
| 82 : num_created_decoders_(0) { | |
| 83 } | |
| 84 | |
| 85 virtual webrtc::VideoDecoder* CreateVideoDecoder( | |
| 86 webrtc::VideoCodecType type) { | |
| 87 if (supported_codec_types_.count(type) == 0) { | |
| 88 return NULL; | |
| 89 } | |
| 90 FakeWebRtcVideoDecoder* decoder = new FakeWebRtcVideoDecoder(); | |
| 91 decoders_.push_back(decoder); | |
| 92 num_created_decoders_++; | |
| 93 return decoder; | |
| 94 } | |
| 95 | |
| 96 virtual void DestroyVideoDecoder(webrtc::VideoDecoder* decoder) { | |
| 97 decoders_.erase( | |
| 98 std::remove(decoders_.begin(), decoders_.end(), decoder), | |
| 99 decoders_.end()); | |
| 100 delete decoder; | |
| 101 } | |
| 102 | |
| 103 void AddSupportedVideoCodecType(webrtc::VideoCodecType type) { | |
| 104 supported_codec_types_.insert(type); | |
| 105 } | |
| 106 | |
| 107 int GetNumCreatedDecoders() { | |
| 108 return num_created_decoders_; | |
| 109 } | |
| 110 | |
| 111 const std::vector<FakeWebRtcVideoDecoder*>& decoders() { | |
| 112 return decoders_; | |
| 113 } | |
| 114 | |
| 115 private: | |
| 116 std::set<webrtc::VideoCodecType> supported_codec_types_; | |
| 117 std::vector<FakeWebRtcVideoDecoder*> decoders_; | |
| 118 int num_created_decoders_; | |
| 119 }; | |
| 120 | |
| 121 // Fake class for mocking out webrtc::VideoEnoder | |
| 122 class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder { | |
| 123 public: | |
| 124 FakeWebRtcVideoEncoder() : num_frames_encoded_(0) {} | |
| 125 | |
| 126 virtual int32_t InitEncode(const webrtc::VideoCodec* codecSettings, | |
| 127 int32_t numberOfCores, | |
| 128 size_t maxPayloadSize) { | |
| 129 rtc::CritScope lock(&crit_); | |
| 130 codec_settings_ = *codecSettings; | |
| 131 return WEBRTC_VIDEO_CODEC_OK; | |
| 132 } | |
| 133 | |
| 134 webrtc::VideoCodec GetCodecSettings() { | |
| 135 rtc::CritScope lock(&crit_); | |
| 136 return codec_settings_; | |
| 137 } | |
| 138 | |
| 139 virtual int32_t Encode(const webrtc::VideoFrame& inputImage, | |
| 140 const webrtc::CodecSpecificInfo* codecSpecificInfo, | |
| 141 const std::vector<webrtc::FrameType>* frame_types) { | |
| 142 rtc::CritScope lock(&crit_); | |
| 143 ++num_frames_encoded_; | |
| 144 return WEBRTC_VIDEO_CODEC_OK; | |
| 145 } | |
| 146 | |
| 147 virtual int32_t RegisterEncodeCompleteCallback( | |
| 148 webrtc::EncodedImageCallback* callback) { | |
| 149 return WEBRTC_VIDEO_CODEC_OK; | |
| 150 } | |
| 151 | |
| 152 virtual int32_t Release() { return WEBRTC_VIDEO_CODEC_OK; } | |
| 153 | |
| 154 virtual int32_t SetChannelParameters(uint32_t packetLoss, int64_t rtt) { | |
| 155 return WEBRTC_VIDEO_CODEC_OK; | |
| 156 } | |
| 157 | |
| 158 virtual int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) { | |
| 159 return WEBRTC_VIDEO_CODEC_OK; | |
| 160 } | |
| 161 | |
| 162 int GetNumEncodedFrames() { | |
| 163 rtc::CritScope lock(&crit_); | |
| 164 return num_frames_encoded_; | |
| 165 } | |
| 166 | |
| 167 private: | |
| 168 rtc::CriticalSection crit_; | |
| 169 int num_frames_encoded_ GUARDED_BY(crit_); | |
| 170 webrtc::VideoCodec codec_settings_ GUARDED_BY(crit_); | |
| 171 }; | |
| 172 | |
| 173 // Fake class for mocking out WebRtcVideoEncoderFactory. | |
| 174 class FakeWebRtcVideoEncoderFactory : public WebRtcVideoEncoderFactory { | |
| 175 public: | |
| 176 FakeWebRtcVideoEncoderFactory() | |
| 177 : num_created_encoders_(0), encoders_have_internal_sources_(false) {} | |
| 178 | |
| 179 virtual webrtc::VideoEncoder* CreateVideoEncoder( | |
| 180 webrtc::VideoCodecType type) { | |
| 181 if (supported_codec_types_.count(type) == 0) { | |
| 182 return NULL; | |
| 183 } | |
| 184 FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder(); | |
| 185 encoders_.push_back(encoder); | |
| 186 num_created_encoders_++; | |
| 187 return encoder; | |
| 188 } | |
| 189 | |
| 190 virtual void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) { | |
| 191 encoders_.erase( | |
| 192 std::remove(encoders_.begin(), encoders_.end(), encoder), | |
| 193 encoders_.end()); | |
| 194 delete encoder; | |
| 195 } | |
| 196 | |
| 197 virtual const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs() | |
| 198 const { | |
| 199 return codecs_; | |
| 200 } | |
| 201 | |
| 202 virtual bool EncoderTypeHasInternalSource( | |
| 203 webrtc::VideoCodecType type) const override { | |
| 204 return encoders_have_internal_sources_; | |
| 205 } | |
| 206 | |
| 207 void set_encoders_have_internal_sources(bool internal_source) { | |
| 208 encoders_have_internal_sources_ = internal_source; | |
| 209 } | |
| 210 | |
| 211 void AddSupportedVideoCodecType(webrtc::VideoCodecType type, | |
| 212 const std::string& name) { | |
| 213 supported_codec_types_.insert(type); | |
| 214 codecs_.push_back( | |
| 215 WebRtcVideoEncoderFactory::VideoCodec(type, name, 1280, 720, 30)); | |
| 216 } | |
| 217 | |
| 218 int GetNumCreatedEncoders() { | |
| 219 return num_created_encoders_; | |
| 220 } | |
| 221 | |
| 222 const std::vector<FakeWebRtcVideoEncoder*>& encoders() { | |
| 223 return encoders_; | |
| 224 } | |
| 225 | |
| 226 private: | |
| 227 std::set<webrtc::VideoCodecType> supported_codec_types_; | |
| 228 std::vector<WebRtcVideoEncoderFactory::VideoCodec> codecs_; | |
| 229 std::vector<FakeWebRtcVideoEncoder*> encoders_; | |
| 230 int num_created_encoders_; | |
| 231 bool encoders_have_internal_sources_; | |
| 232 }; | |
| 233 | |
| 234 } // namespace cricket | |
| 235 | |
| 236 #endif // WEBRTC_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_ | |
| OLD | NEW |