pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2004 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 | |
| 28 | #include <map> |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 29 | #include <vector> |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 30 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 31 | #include "talk/media/base/testutils.h" |
| 32 | #include "talk/media/base/videoengine_unittest.h" |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 33 | #include "talk/media/webrtc/fakewebrtcvideoengine.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 34 | #include "talk/media/webrtc/webrtcvideochannelfactory.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 35 | #include "talk/media/webrtc/webrtcvideoengine2.h" |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 36 | #include "talk/media/webrtc/webrtcvideoengine2_unittest.h" |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 37 | #include "talk/media/webrtc/webrtcvoiceengine.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 38 | #include "webrtc/base/gunit.h" |
| 39 | #include "webrtc/base/stringutils.h" |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 40 | #include "webrtc/video_encoder.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 41 | |
| 42 | namespace { |
| 43 | static const cricket::VideoCodec kVp8Codec720p(100, "VP8", 1280, 720, 30, 0); |
| 44 | static const cricket::VideoCodec kVp8Codec360p(100, "VP8", 640, 360, 30, 0); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 45 | |
| 46 | static const cricket::VideoCodec kVp8Codec(100, "VP8", 640, 400, 30, 0); |
| 47 | static const cricket::VideoCodec kVp9Codec(101, "VP9", 640, 400, 30, 0); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 48 | static const cricket::VideoCodec kH264Codec(102, "H264", 640, 400, 30, 0); |
| 49 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 50 | static const cricket::VideoCodec kRedCodec(116, "red", 0, 0, 0, 0); |
| 51 | static const cricket::VideoCodec kUlpfecCodec(117, "ulpfec", 0, 0, 0, 0); |
| 52 | |
| 53 | static const uint32 kSsrcs1[] = {1}; |
| 54 | static const uint32 kRtxSsrcs1[] = {4}; |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 55 | static const char kUnsupportedExtensionName[] = |
| 56 | "urn:ietf:params:rtp-hdrext:unsupported"; |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 57 | |
| 58 | void VerifyCodecHasDefaultFeedbackParams(const cricket::VideoCodec& codec) { |
| 59 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| 60 | cricket::kRtcpFbParamNack, cricket::kParamValueEmpty))); |
| 61 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| 62 | cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli))); |
| 63 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| 64 | cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty))); |
| 65 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| 66 | cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir))); |
| 67 | } |
| 68 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 69 | } // namespace |
| 70 | |
| 71 | namespace cricket { |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 72 | FakeVideoSendStream::FakeVideoSendStream( |
| 73 | const webrtc::VideoSendStream::Config& config, |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 74 | const webrtc::VideoEncoderConfig& encoder_config) |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 75 | : sending_(false), |
| 76 | config_(config), |
| 77 | codec_settings_set_(false), |
| 78 | num_swapped_frames_(0) { |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 79 | assert(config.encoder_settings.encoder != NULL); |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 80 | ReconfigureVideoEncoder(encoder_config); |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 81 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 82 | |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 83 | webrtc::VideoSendStream::Config FakeVideoSendStream::GetConfig() const { |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 84 | return config_; |
| 85 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 86 | |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 87 | webrtc::VideoEncoderConfig FakeVideoSendStream::GetEncoderConfig() const { |
| 88 | return encoder_config_; |
| 89 | } |
| 90 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 91 | std::vector<webrtc::VideoStream> FakeVideoSendStream::GetVideoStreams() { |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 92 | return encoder_config_.streams; |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 93 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 94 | |
pbos@webrtc.org | 85f4294 | 2014-07-22 09:14:58 +0000 | [diff] [blame] | 95 | bool FakeVideoSendStream::IsSending() const { |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 96 | return sending_; |
| 97 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 98 | |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 99 | bool FakeVideoSendStream::GetVp8Settings( |
| 100 | webrtc::VideoCodecVP8* settings) const { |
| 101 | if (!codec_settings_set_) { |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | *settings = vp8_settings_; |
| 106 | return true; |
| 107 | } |
| 108 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 109 | int FakeVideoSendStream::GetNumberOfSwappedFrames() const { |
| 110 | return num_swapped_frames_; |
| 111 | } |
| 112 | |
| 113 | int FakeVideoSendStream::GetLastWidth() const { |
| 114 | return last_frame_.width(); |
| 115 | } |
| 116 | |
| 117 | int FakeVideoSendStream::GetLastHeight() const { |
| 118 | return last_frame_.height(); |
| 119 | } |
| 120 | |
| 121 | void FakeVideoSendStream::SwapFrame(webrtc::I420VideoFrame* frame) { |
| 122 | ++num_swapped_frames_; |
| 123 | last_frame_.SwapFrame(frame); |
| 124 | } |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 125 | |
| 126 | void FakeVideoSendStream::SetStats( |
| 127 | const webrtc::VideoSendStream::Stats& stats) { |
| 128 | stats_ = stats; |
| 129 | } |
| 130 | |
| 131 | webrtc::VideoSendStream::Stats FakeVideoSendStream::GetStats() { |
| 132 | return stats_; |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 133 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 134 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 135 | bool FakeVideoSendStream::ReconfigureVideoEncoder( |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 136 | const webrtc::VideoEncoderConfig& config) { |
| 137 | encoder_config_ = config; |
| 138 | if (config.encoder_specific_settings != NULL) { |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 139 | assert(config_.encoder_settings.payload_name == "VP8"); |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 140 | vp8_settings_ = *reinterpret_cast<const webrtc::VideoCodecVP8*>( |
| 141 | config.encoder_specific_settings); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 142 | } |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 143 | codec_settings_set_ = config.encoder_specific_settings != NULL; |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 144 | return true; |
| 145 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 146 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 147 | webrtc::VideoSendStreamInput* FakeVideoSendStream::Input() { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 148 | return this; |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 149 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 150 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 151 | void FakeVideoSendStream::Start() { |
| 152 | sending_ = true; |
| 153 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 154 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 155 | void FakeVideoSendStream::Stop() { |
| 156 | sending_ = false; |
| 157 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 158 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 159 | FakeVideoReceiveStream::FakeVideoReceiveStream( |
| 160 | const webrtc::VideoReceiveStream::Config& config) |
| 161 | : config_(config), receiving_(false) { |
| 162 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 163 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 164 | webrtc::VideoReceiveStream::Config FakeVideoReceiveStream::GetConfig() { |
| 165 | return config_; |
| 166 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 167 | |
pbos@webrtc.org | 85f4294 | 2014-07-22 09:14:58 +0000 | [diff] [blame] | 168 | bool FakeVideoReceiveStream::IsReceiving() const { |
| 169 | return receiving_; |
| 170 | } |
| 171 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 172 | webrtc::VideoReceiveStream::Stats FakeVideoReceiveStream::GetStats() const { |
| 173 | return webrtc::VideoReceiveStream::Stats(); |
| 174 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 175 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 176 | void FakeVideoReceiveStream::Start() { |
| 177 | receiving_ = true; |
| 178 | } |
pbos@webrtc.org | 85f4294 | 2014-07-22 09:14:58 +0000 | [diff] [blame] | 179 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 180 | void FakeVideoReceiveStream::Stop() { |
| 181 | receiving_ = false; |
| 182 | } |
pbos@webrtc.org | 85f4294 | 2014-07-22 09:14:58 +0000 | [diff] [blame] | 183 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 184 | FakeCall::FakeCall(const webrtc::Call::Config& config) |
| 185 | : config_(config), network_state_(kNetworkUp) { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 186 | SetVideoCodecs(GetDefaultVideoCodecs()); |
| 187 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 188 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 189 | FakeCall::~FakeCall() { |
| 190 | EXPECT_EQ(0u, video_send_streams_.size()); |
| 191 | EXPECT_EQ(0u, video_receive_streams_.size()); |
| 192 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 193 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 194 | void FakeCall::SetVideoCodecs(const std::vector<webrtc::VideoCodec> codecs) { |
| 195 | codecs_ = codecs; |
| 196 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 197 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 198 | webrtc::Call::Config FakeCall::GetConfig() const { |
| 199 | return config_; |
| 200 | } |
| 201 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 202 | std::vector<FakeVideoSendStream*> FakeCall::GetVideoSendStreams() { |
| 203 | return video_send_streams_; |
| 204 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 205 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 206 | std::vector<FakeVideoReceiveStream*> FakeCall::GetVideoReceiveStreams() { |
| 207 | return video_receive_streams_; |
| 208 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 209 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 210 | webrtc::VideoCodec FakeCall::GetEmptyVideoCodec() { |
| 211 | webrtc::VideoCodec codec; |
| 212 | codec.minBitrate = 300; |
| 213 | codec.startBitrate = 800; |
| 214 | codec.maxBitrate = 1500; |
| 215 | codec.maxFramerate = 10; |
| 216 | codec.width = 640; |
| 217 | codec.height = 480; |
| 218 | codec.qpMax = 56; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 219 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 220 | return codec; |
| 221 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 222 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 223 | webrtc::VideoCodec FakeCall::GetVideoCodecVp8() { |
| 224 | webrtc::VideoCodec vp8_codec = GetEmptyVideoCodec(); |
| 225 | vp8_codec.codecType = webrtc::kVideoCodecVP8; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 226 | rtc::strcpyn( |
| 227 | vp8_codec.plName, ARRAY_SIZE(vp8_codec.plName), kVp8Codec.name.c_str()); |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 228 | vp8_codec.plType = kVp8Codec.id; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 229 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 230 | return vp8_codec; |
| 231 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 232 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 233 | webrtc::VideoCodec FakeCall::GetVideoCodecVp9() { |
| 234 | webrtc::VideoCodec vp9_codec = GetEmptyVideoCodec(); |
| 235 | // TODO(pbos): Add a correct codecType when webrtc has one. |
| 236 | vp9_codec.codecType = webrtc::kVideoCodecVP8; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 237 | rtc::strcpyn( |
| 238 | vp9_codec.plName, ARRAY_SIZE(vp9_codec.plName), kVp9Codec.name.c_str()); |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 239 | vp9_codec.plType = kVp9Codec.id; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 240 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 241 | return vp9_codec; |
| 242 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 243 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 244 | std::vector<webrtc::VideoCodec> FakeCall::GetDefaultVideoCodecs() { |
| 245 | std::vector<webrtc::VideoCodec> codecs; |
| 246 | codecs.push_back(GetVideoCodecVp8()); |
| 247 | // codecs.push_back(GetVideoCodecVp9()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 248 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 249 | return codecs; |
| 250 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 251 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 252 | webrtc::Call::NetworkState FakeCall::GetNetworkState() const { |
| 253 | return network_state_; |
| 254 | } |
| 255 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 256 | webrtc::VideoSendStream* FakeCall::CreateVideoSendStream( |
| 257 | const webrtc::VideoSendStream::Config& config, |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 258 | const webrtc::VideoEncoderConfig& encoder_config) { |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 259 | FakeVideoSendStream* fake_stream = |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 260 | new FakeVideoSendStream(config, encoder_config); |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 261 | video_send_streams_.push_back(fake_stream); |
| 262 | return fake_stream; |
| 263 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 264 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 265 | void FakeCall::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { |
| 266 | FakeVideoSendStream* fake_stream = |
| 267 | static_cast<FakeVideoSendStream*>(send_stream); |
| 268 | for (size_t i = 0; i < video_send_streams_.size(); ++i) { |
| 269 | if (video_send_streams_[i] == fake_stream) { |
| 270 | delete video_send_streams_[i]; |
| 271 | video_send_streams_.erase(video_send_streams_.begin() + i); |
| 272 | return; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 273 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 274 | } |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 275 | ADD_FAILURE() << "DestroyVideoSendStream called with unknown paramter."; |
| 276 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 277 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 278 | webrtc::VideoReceiveStream* FakeCall::CreateVideoReceiveStream( |
| 279 | const webrtc::VideoReceiveStream::Config& config) { |
| 280 | video_receive_streams_.push_back(new FakeVideoReceiveStream(config)); |
| 281 | return video_receive_streams_[video_receive_streams_.size() - 1]; |
| 282 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 283 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 284 | void FakeCall::DestroyVideoReceiveStream( |
| 285 | webrtc::VideoReceiveStream* receive_stream) { |
| 286 | FakeVideoReceiveStream* fake_stream = |
| 287 | static_cast<FakeVideoReceiveStream*>(receive_stream); |
| 288 | for (size_t i = 0; i < video_receive_streams_.size(); ++i) { |
| 289 | if (video_receive_streams_[i] == fake_stream) { |
| 290 | delete video_receive_streams_[i]; |
| 291 | video_receive_streams_.erase(video_receive_streams_.begin() + i); |
| 292 | return; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 293 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 294 | } |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 295 | ADD_FAILURE() << "DestroyVideoReceiveStream called with unknown paramter."; |
| 296 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 297 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 298 | webrtc::PacketReceiver* FakeCall::Receiver() { |
| 299 | // TODO(pbos): Fix this. |
| 300 | return NULL; |
| 301 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 302 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 303 | webrtc::Call::Stats FakeCall::GetStats() const { |
| 304 | webrtc::Call::Stats stats; |
| 305 | return stats; |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 306 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 307 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 308 | void FakeCall::SetBitrateConfig( |
| 309 | const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
| 310 | config_.stream_bitrates = bitrate_config; |
| 311 | } |
| 312 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 313 | void FakeCall::SignalNetworkState(webrtc::Call::NetworkState state) { |
| 314 | network_state_ = state; |
| 315 | } |
| 316 | |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 317 | class WebRtcVideoEngine2Test : public ::testing::Test { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 318 | public: |
pbos@webrtc.org | b648b9d | 2014-08-26 11:08:06 +0000 | [diff] [blame] | 319 | WebRtcVideoEngine2Test() { |
pbos@webrtc.org | 9fbb717 | 2014-06-13 09:34:13 +0000 | [diff] [blame] | 320 | std::vector<VideoCodec> engine_codecs = engine_.codecs(); |
| 321 | assert(!engine_codecs.empty()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 322 | bool codec_set = false; |
pbos@webrtc.org | 9fbb717 | 2014-06-13 09:34:13 +0000 | [diff] [blame] | 323 | for (size_t i = 0; i < engine_codecs.size(); ++i) { |
| 324 | if (engine_codecs[i].name == "red") { |
| 325 | default_red_codec_ = engine_codecs[i]; |
| 326 | } else if (engine_codecs[i].name == "ulpfec") { |
| 327 | default_ulpfec_codec_ = engine_codecs[i]; |
| 328 | } else if (engine_codecs[i].name == "rtx") { |
| 329 | default_rtx_codec_ = engine_codecs[i]; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 330 | } else if (!codec_set) { |
pbos@webrtc.org | 9fbb717 | 2014-06-13 09:34:13 +0000 | [diff] [blame] | 331 | default_codec_ = engine_codecs[i]; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 332 | codec_set = true; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | assert(codec_set); |
| 337 | } |
| 338 | |
| 339 | protected: |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 340 | class FakeCallFactory : public WebRtcCallFactory { |
| 341 | public: |
| 342 | FakeCallFactory() : fake_call_(NULL) {} |
| 343 | FakeCall* GetCall() { return fake_call_; } |
| 344 | |
| 345 | private: |
| 346 | virtual webrtc::Call* CreateCall( |
| 347 | const webrtc::Call::Config& config) OVERRIDE { |
| 348 | assert(fake_call_ == NULL); |
| 349 | fake_call_ = new FakeCall(config); |
| 350 | return fake_call_; |
| 351 | } |
| 352 | |
| 353 | FakeCall* fake_call_; |
| 354 | }; |
| 355 | |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 356 | VideoMediaChannel* SetUpForExternalEncoderFactory( |
| 357 | cricket::WebRtcVideoEncoderFactory* encoder_factory, |
| 358 | const std::vector<VideoCodec>& codecs); |
pbos@webrtc.org | fa553ef | 2014-10-20 11:07:07 +0000 | [diff] [blame] | 359 | |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 360 | VideoMediaChannel* SetUpForExternalDecoderFactory( |
| 361 | cricket::WebRtcVideoDecoderFactory* decoder_factory, |
| 362 | const std::vector<VideoCodec>& codecs); |
| 363 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 364 | WebRtcVideoEngine2 engine_; |
| 365 | VideoCodec default_codec_; |
| 366 | VideoCodec default_red_codec_; |
| 367 | VideoCodec default_ulpfec_codec_; |
| 368 | VideoCodec default_rtx_codec_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 369 | }; |
| 370 | |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 371 | TEST_F(WebRtcVideoEngine2Test, ConfiguresAvSyncForFirstReceiveChannel) { |
| 372 | FakeCallFactory call_factory; |
| 373 | engine_.SetCallFactory(&call_factory); |
| 374 | |
| 375 | WebRtcVoiceEngine voice_engine; |
| 376 | engine_.SetVoiceEngine(&voice_engine); |
| 377 | voice_engine.Init(rtc::Thread::Current()); |
| 378 | engine_.Init(rtc::Thread::Current()); |
| 379 | |
| 380 | rtc::scoped_ptr<VoiceMediaChannel> voice_channel( |
| 381 | voice_engine.CreateChannel()); |
| 382 | ASSERT_TRUE(voice_channel.get() != NULL); |
| 383 | WebRtcVoiceMediaChannel* webrtc_voice_channel = |
| 384 | static_cast<WebRtcVoiceMediaChannel*>(voice_channel.get()); |
| 385 | ASSERT_NE(webrtc_voice_channel->voe_channel(), -1); |
| 386 | rtc::scoped_ptr<VideoMediaChannel> channel( |
| 387 | engine_.CreateChannel(cricket::VideoOptions(), voice_channel.get())); |
| 388 | |
| 389 | FakeCall* fake_call = call_factory.GetCall(); |
| 390 | ASSERT_TRUE(fake_call != NULL); |
| 391 | |
| 392 | webrtc::Call::Config call_config = fake_call->GetConfig(); |
| 393 | |
| 394 | ASSERT_TRUE(voice_engine.voe()->engine() != NULL); |
| 395 | ASSERT_EQ(voice_engine.voe()->engine(), call_config.voice_engine); |
| 396 | |
| 397 | EXPECT_TRUE(channel->AddRecvStream(StreamParams::CreateLegacy(kSsrc))); |
| 398 | EXPECT_TRUE(channel->AddRecvStream(StreamParams::CreateLegacy(kSsrc + 1))); |
| 399 | std::vector<FakeVideoReceiveStream*> receive_streams = |
| 400 | fake_call->GetVideoReceiveStreams(); |
| 401 | |
| 402 | ASSERT_EQ(2u, receive_streams.size()); |
| 403 | EXPECT_EQ(webrtc_voice_channel->voe_channel(), |
| 404 | receive_streams[0]->GetConfig().audio_channel_id); |
| 405 | EXPECT_EQ(-1, receive_streams[1]->GetConfig().audio_channel_id) |
| 406 | << "AV sync should only be set up for the first receive channel."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 407 | } |
| 408 | |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 409 | TEST_F(WebRtcVideoEngine2Test, FindCodec) { |
| 410 | const std::vector<cricket::VideoCodec>& c = engine_.codecs(); |
| 411 | EXPECT_EQ(4U, c.size()); |
| 412 | |
| 413 | cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0); |
| 414 | EXPECT_TRUE(engine_.FindCodec(vp8)); |
| 415 | |
| 416 | cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0); |
| 417 | EXPECT_TRUE(engine_.FindCodec(vp8)); |
| 418 | |
| 419 | cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50); |
| 420 | EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref)); |
| 421 | |
| 422 | cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0); |
| 423 | EXPECT_FALSE(engine_.FindCodec(vp8_diff_id)); |
| 424 | vp8_diff_id.id = 97; |
| 425 | EXPECT_TRUE(engine_.FindCodec(vp8_diff_id)); |
| 426 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 427 | // FindCodec ignores the codec size. |
| 428 | // Test that FindCodec can accept uncommon codec size. |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 429 | cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0); |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 430 | EXPECT_TRUE(engine_.FindCodec(vp8_diff_res)); |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 431 | |
| 432 | // PeerConnection doesn't negotiate the resolution at this point. |
| 433 | // Test that FindCodec can handle the case when width/height is 0. |
| 434 | cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0); |
| 435 | EXPECT_TRUE(engine_.FindCodec(vp8_zero_res)); |
| 436 | |
| 437 | cricket::VideoCodec red(101, "RED", 0, 0, 30, 0); |
| 438 | EXPECT_TRUE(engine_.FindCodec(red)); |
| 439 | |
| 440 | cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0); |
| 441 | EXPECT_TRUE(engine_.FindCodec(red)); |
| 442 | |
| 443 | cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0); |
| 444 | EXPECT_TRUE(engine_.FindCodec(fec)); |
| 445 | |
| 446 | cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0); |
| 447 | EXPECT_TRUE(engine_.FindCodec(fec)); |
| 448 | |
| 449 | cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0); |
| 450 | EXPECT_TRUE(engine_.FindCodec(rtx)); |
| 451 | } |
| 452 | |
| 453 | TEST_F(WebRtcVideoEngine2Test, DefaultRtxCodecHasAssociatedPayloadTypeSet) { |
| 454 | std::vector<VideoCodec> engine_codecs = engine_.codecs(); |
| 455 | for (size_t i = 0; i < engine_codecs.size(); ++i) { |
| 456 | if (engine_codecs[i].name != kRtxCodecName) |
| 457 | continue; |
| 458 | int associated_payload_type; |
| 459 | EXPECT_TRUE(engine_codecs[i].GetParam(kCodecParamAssociatedPayloadType, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 460 | &associated_payload_type)); |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 461 | EXPECT_EQ(default_codec_.id, associated_payload_type); |
| 462 | return; |
| 463 | } |
| 464 | FAIL() << "No RTX codec found among default codecs."; |
| 465 | } |
| 466 | |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 467 | TEST_F(WebRtcVideoEngine2Test, SupportsTimestampOffsetHeaderExtension) { |
| 468 | std::vector<RtpHeaderExtension> extensions = engine_.rtp_header_extensions(); |
| 469 | ASSERT_FALSE(extensions.empty()); |
| 470 | for (size_t i = 0; i < extensions.size(); ++i) { |
| 471 | if (extensions[i].uri == kRtpTimestampOffsetHeaderExtension) { |
| 472 | EXPECT_EQ(kRtpTimestampOffsetHeaderExtensionDefaultId, extensions[i].id); |
| 473 | return; |
| 474 | } |
| 475 | } |
| 476 | FAIL() << "Timestamp offset extension not in header-extension list."; |
| 477 | } |
| 478 | |
| 479 | TEST_F(WebRtcVideoEngine2Test, SupportsAbsoluteSenderTimeHeaderExtension) { |
| 480 | std::vector<RtpHeaderExtension> extensions = engine_.rtp_header_extensions(); |
| 481 | ASSERT_FALSE(extensions.empty()); |
| 482 | for (size_t i = 0; i < extensions.size(); ++i) { |
| 483 | if (extensions[i].uri == kRtpAbsoluteSenderTimeHeaderExtension) { |
| 484 | EXPECT_EQ(kRtpAbsoluteSenderTimeHeaderExtensionDefaultId, |
| 485 | extensions[i].id); |
| 486 | return; |
| 487 | } |
| 488 | } |
| 489 | FAIL() << "Absolute Sender Time extension not in header-extension list."; |
| 490 | } |
| 491 | |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 492 | TEST_F(WebRtcVideoEngine2Test, SetSendFailsBeforeSettingCodecs) { |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 493 | engine_.Init(rtc::Thread::Current()); |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 494 | rtc::scoped_ptr<VideoMediaChannel> channel( |
| 495 | engine_.CreateChannel(cricket::VideoOptions(), NULL)); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 496 | |
| 497 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); |
| 498 | |
| 499 | EXPECT_FALSE(channel->SetSend(true)) |
| 500 | << "Channel should not start without codecs."; |
| 501 | EXPECT_TRUE(channel->SetSend(false)) |
| 502 | << "Channel should be stoppable even without set codecs."; |
| 503 | } |
| 504 | |
pbos@webrtc.org | c3d2bd2 | 2014-08-12 20:55:10 +0000 | [diff] [blame] | 505 | TEST_F(WebRtcVideoEngine2Test, GetStatsWithoutSendCodecsSetDoesNotCrash) { |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 506 | engine_.Init(rtc::Thread::Current()); |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 507 | rtc::scoped_ptr<VideoMediaChannel> channel( |
| 508 | engine_.CreateChannel(cricket::VideoOptions(), NULL)); |
pbos@webrtc.org | c3d2bd2 | 2014-08-12 20:55:10 +0000 | [diff] [blame] | 509 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); |
| 510 | VideoMediaInfo info; |
| 511 | channel->GetStats(&info); |
| 512 | } |
| 513 | |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 514 | TEST_F(WebRtcVideoEngine2Test, UseExternalFactoryForVp8WhenSupported) { |
| 515 | cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| 516 | encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); |
| 517 | std::vector<cricket::VideoCodec> codecs; |
| 518 | codecs.push_back(kVp8Codec); |
| 519 | |
| 520 | rtc::scoped_ptr<VideoMediaChannel> channel( |
| 521 | SetUpForExternalEncoderFactory(&encoder_factory, codecs)); |
| 522 | |
| 523 | EXPECT_TRUE( |
| 524 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 525 | ASSERT_EQ(1u, encoder_factory.encoders().size()); |
| 526 | EXPECT_TRUE(channel->SetSend(true)); |
| 527 | |
| 528 | cricket::FakeVideoCapturer capturer; |
| 529 | EXPECT_TRUE(channel->SetCapturer(kSsrc, &capturer)); |
| 530 | EXPECT_EQ(cricket::CS_RUNNING, |
| 531 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 532 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 533 | |
| 534 | EXPECT_TRUE_WAIT(encoder_factory.encoders()[0]->GetNumEncodedFrames() > 0, |
| 535 | kTimeout); |
| 536 | |
| 537 | // Setting codecs of the same type should not reallocate the encoder. |
| 538 | EXPECT_TRUE(channel->SetSendCodecs(codecs)); |
| 539 | EXPECT_EQ(1, encoder_factory.GetNumCreatedEncoders()); |
| 540 | |
| 541 | // Remove stream previously added to free the external encoder instance. |
| 542 | EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
| 543 | EXPECT_EQ(0u, encoder_factory.encoders().size()); |
| 544 | } |
| 545 | |
| 546 | VideoMediaChannel* WebRtcVideoEngine2Test::SetUpForExternalEncoderFactory( |
| 547 | cricket::WebRtcVideoEncoderFactory* encoder_factory, |
| 548 | const std::vector<VideoCodec>& codecs) { |
| 549 | engine_.SetExternalEncoderFactory(encoder_factory); |
| 550 | engine_.Init(rtc::Thread::Current()); |
| 551 | |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 552 | VideoMediaChannel* channel = |
| 553 | engine_.CreateChannel(cricket::VideoOptions(), NULL); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 554 | EXPECT_TRUE(channel->SetSendCodecs(codecs)); |
| 555 | |
| 556 | return channel; |
| 557 | } |
| 558 | |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 559 | VideoMediaChannel* WebRtcVideoEngine2Test::SetUpForExternalDecoderFactory( |
| 560 | cricket::WebRtcVideoDecoderFactory* decoder_factory, |
| 561 | const std::vector<VideoCodec>& codecs) { |
| 562 | engine_.SetExternalDecoderFactory(decoder_factory); |
| 563 | engine_.Init(rtc::Thread::Current()); |
| 564 | |
| 565 | VideoMediaChannel* channel = |
| 566 | engine_.CreateChannel(cricket::VideoOptions(), NULL); |
| 567 | EXPECT_TRUE(channel->SetRecvCodecs(codecs)); |
| 568 | |
| 569 | return channel; |
| 570 | } |
| 571 | |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 572 | TEST_F(WebRtcVideoEngine2Test, ChannelWithExternalH264CanChangeToInternalVp8) { |
| 573 | cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| 574 | encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecH264, "H264"); |
| 575 | std::vector<cricket::VideoCodec> codecs; |
| 576 | codecs.push_back(kH264Codec); |
| 577 | |
| 578 | rtc::scoped_ptr<VideoMediaChannel> channel( |
| 579 | SetUpForExternalEncoderFactory(&encoder_factory, codecs)); |
| 580 | |
| 581 | EXPECT_TRUE( |
| 582 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 583 | ASSERT_EQ(1u, encoder_factory.encoders().size()); |
| 584 | |
| 585 | codecs.clear(); |
| 586 | codecs.push_back(kVp8Codec); |
| 587 | EXPECT_TRUE(channel->SetSendCodecs(codecs)); |
| 588 | |
| 589 | ASSERT_EQ(0u, encoder_factory.encoders().size()); |
| 590 | } |
| 591 | |
| 592 | TEST_F(WebRtcVideoEngine2Test, |
| 593 | DontUseExternalEncoderFactoryForUnsupportedCodecs) { |
| 594 | cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| 595 | encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecH264, "H264"); |
| 596 | std::vector<cricket::VideoCodec> codecs; |
| 597 | codecs.push_back(kVp8Codec); |
| 598 | |
| 599 | rtc::scoped_ptr<VideoMediaChannel> channel( |
| 600 | SetUpForExternalEncoderFactory(&encoder_factory, codecs)); |
| 601 | |
| 602 | EXPECT_TRUE( |
| 603 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 604 | ASSERT_EQ(0u, encoder_factory.encoders().size()); |
| 605 | } |
| 606 | |
| 607 | // Test external codec with be added to the end of the supported codec list. |
| 608 | TEST_F(WebRtcVideoEngine2Test, ReportSupportedExternalCodecs) { |
| 609 | cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| 610 | encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecH264, "H264"); |
| 611 | engine_.SetExternalEncoderFactory(&encoder_factory); |
| 612 | |
| 613 | engine_.Init(rtc::Thread::Current()); |
| 614 | |
| 615 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 616 | ASSERT_GE(codecs.size(), 2u); |
| 617 | cricket::VideoCodec internal_codec = codecs.front(); |
| 618 | cricket::VideoCodec external_codec = codecs.back(); |
| 619 | |
| 620 | // The external codec will appear at last. |
| 621 | EXPECT_EQ("VP8", internal_codec.name); |
| 622 | EXPECT_EQ("H264", external_codec.name); |
| 623 | } |
| 624 | |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 625 | TEST_F(WebRtcVideoEngine2Test, RegisterExternalDecodersIfSupported) { |
| 626 | cricket::FakeWebRtcVideoDecoderFactory decoder_factory; |
| 627 | decoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8); |
| 628 | std::vector<cricket::VideoCodec> codecs; |
| 629 | codecs.push_back(kVp8Codec); |
| 630 | |
| 631 | rtc::scoped_ptr<VideoMediaChannel> channel( |
| 632 | SetUpForExternalDecoderFactory(&decoder_factory, codecs)); |
| 633 | |
| 634 | EXPECT_TRUE( |
| 635 | channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 636 | ASSERT_EQ(1u, decoder_factory.decoders().size()); |
| 637 | |
| 638 | // Setting codecs of the same type should not reallocate the decoder. |
| 639 | EXPECT_TRUE(channel->SetRecvCodecs(codecs)); |
| 640 | EXPECT_EQ(1, decoder_factory.GetNumCreatedDecoders()); |
| 641 | |
| 642 | // Remove stream previously added to free the external decoder instance. |
| 643 | EXPECT_TRUE(channel->RemoveRecvStream(kSsrc)); |
| 644 | EXPECT_EQ(0u, decoder_factory.decoders().size()); |
| 645 | } |
| 646 | |
| 647 | // Verifies that we can set up decoders that are not internally supported. |
| 648 | TEST_F(WebRtcVideoEngine2Test, RegisterExternalH264DecoderIfSupported) { |
| 649 | // TODO(pbos): Do not assume that encoder/decoder support is symmetric. We |
| 650 | // can't even query the WebRtcVideoDecoderFactory for supported codecs. |
| 651 | // For now we add a FakeWebRtcVideoEncoderFactory to add H264 to supported |
| 652 | // codecs. |
| 653 | cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| 654 | encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecH264, "H264"); |
| 655 | engine_.SetExternalEncoderFactory(&encoder_factory); |
| 656 | cricket::FakeWebRtcVideoDecoderFactory decoder_factory; |
| 657 | decoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecH264); |
| 658 | std::vector<cricket::VideoCodec> codecs; |
| 659 | codecs.push_back(kH264Codec); |
| 660 | |
| 661 | rtc::scoped_ptr<VideoMediaChannel> channel( |
| 662 | SetUpForExternalDecoderFactory(&decoder_factory, codecs)); |
| 663 | |
| 664 | EXPECT_TRUE( |
| 665 | channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 666 | ASSERT_EQ(1u, decoder_factory.decoders().size()); |
| 667 | } |
| 668 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 669 | class WebRtcVideoEngine2BaseTest |
| 670 | : public VideoEngineTest<cricket::WebRtcVideoEngine2> { |
| 671 | protected: |
| 672 | typedef VideoEngineTest<cricket::WebRtcVideoEngine2> Base; |
| 673 | }; |
| 674 | |
| 675 | #define WEBRTC_ENGINE_BASE_TEST(test) \ |
| 676 | TEST_F(WebRtcVideoEngine2BaseTest, test) { Base::test##Body(); } |
| 677 | |
| 678 | WEBRTC_ENGINE_BASE_TEST(ConstrainNewCodec2); |
| 679 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 680 | class WebRtcVideoChannel2BaseTest |
| 681 | : public VideoMediaChannelTest<WebRtcVideoEngine2, WebRtcVideoChannel2> { |
| 682 | protected: |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 683 | typedef VideoMediaChannelTest<WebRtcVideoEngine2, WebRtcVideoChannel2> Base; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 684 | |
| 685 | virtual cricket::VideoCodec DefaultCodec() OVERRIDE { return kVp8Codec; } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 686 | }; |
| 687 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 688 | #define WEBRTC_BASE_TEST(test) \ |
| 689 | TEST_F(WebRtcVideoChannel2BaseTest, test) { Base::test(); } |
| 690 | |
| 691 | #define WEBRTC_DISABLED_BASE_TEST(test) \ |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 692 | TEST_F(WebRtcVideoChannel2BaseTest, DISABLED_##test) { Base::test(); } |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 693 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 694 | // TODO(pbos): Fix WebRtcVideoEngine2BaseTest, where we want CheckCoInitialize. |
| 695 | #if 0 |
| 696 | // TODO(juberti): Figure out why ViE is munging the COM refcount. |
| 697 | #ifdef WIN32 |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 698 | WEBRTC_DISABLED_BASE_TEST(CheckCoInitialize) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 699 | Base::CheckCoInitialize(); |
| 700 | } |
| 701 | #endif |
| 702 | #endif |
| 703 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 704 | WEBRTC_BASE_TEST(SetSend); |
| 705 | WEBRTC_BASE_TEST(SetSendWithoutCodecs); |
| 706 | WEBRTC_BASE_TEST(SetSendSetsTransportBufferSizes); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 707 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 708 | WEBRTC_BASE_TEST(GetStats); |
| 709 | WEBRTC_BASE_TEST(GetStatsMultipleRecvStreams); |
| 710 | WEBRTC_BASE_TEST(GetStatsMultipleSendStreams); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 711 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 712 | WEBRTC_BASE_TEST(SetSendBandwidth); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 713 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 714 | WEBRTC_BASE_TEST(SetSendSsrc); |
| 715 | WEBRTC_BASE_TEST(SetSendSsrcAfterSetCodecs); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 716 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 717 | WEBRTC_BASE_TEST(SetRenderer); |
| 718 | WEBRTC_BASE_TEST(AddRemoveRecvStreams); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 719 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 720 | WEBRTC_DISABLED_BASE_TEST(AddRemoveRecvStreamAndRender); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 721 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 722 | WEBRTC_BASE_TEST(AddRemoveRecvStreamsNoConference); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 723 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 724 | WEBRTC_BASE_TEST(AddRemoveSendStreams); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 725 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 726 | WEBRTC_BASE_TEST(SimulateConference); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 727 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 728 | WEBRTC_BASE_TEST(AddRemoveCapturer); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 729 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 730 | WEBRTC_BASE_TEST(RemoveCapturerWithoutAdd); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 731 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 732 | WEBRTC_BASE_TEST(AddRemoveCapturerMultipleSources); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 733 | |
| 734 | // TODO(pbos): Figure out why this fails so often. |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 735 | WEBRTC_DISABLED_BASE_TEST(HighAspectHighHeightCapturer); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 736 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 737 | WEBRTC_BASE_TEST(RejectEmptyStreamParams); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 738 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 739 | WEBRTC_BASE_TEST(AdaptResolution16x10); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 740 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 741 | WEBRTC_BASE_TEST(AdaptResolution4x3); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 742 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 743 | // TODO(juberti): Restore this test once we support sending 0 fps. |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 744 | WEBRTC_DISABLED_BASE_TEST(AdaptDropAllFrames); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 745 | // TODO(juberti): Understand why we get decode errors on this test. |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 746 | WEBRTC_DISABLED_BASE_TEST(AdaptFramerate); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 747 | |
pbos@webrtc.org | c4175b9 | 2014-09-03 15:25:49 +0000 | [diff] [blame] | 748 | WEBRTC_BASE_TEST(SendsLowerResolutionOnSmallerFrames); |
| 749 | |
| 750 | WEBRTC_BASE_TEST(MuteStream); |
| 751 | |
| 752 | WEBRTC_BASE_TEST(MultipleSendStreams); |
| 753 | |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 754 | WEBRTC_BASE_TEST(SetSendStreamFormat0x0); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 755 | |
| 756 | // TODO(zhurunz): Fix the flakey test. |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 757 | WEBRTC_DISABLED_BASE_TEST(SetSendStreamFormat); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 758 | |
pbos@webrtc.org | 9359cb3 | 2014-07-23 15:44:48 +0000 | [diff] [blame] | 759 | TEST_F(WebRtcVideoChannel2BaseTest, SendAndReceiveVp8Vga) { |
| 760 | SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0)); |
| 761 | } |
| 762 | |
| 763 | TEST_F(WebRtcVideoChannel2BaseTest, SendAndReceiveVp8Qvga) { |
| 764 | SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0)); |
| 765 | } |
| 766 | |
| 767 | TEST_F(WebRtcVideoChannel2BaseTest, SendAndReceiveVp8SvcQqvga) { |
| 768 | SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0)); |
| 769 | } |
| 770 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 771 | TEST_F(WebRtcVideoChannel2BaseTest, TwoStreamsSendAndReceive) { |
| 772 | Base::TwoStreamsSendAndReceive(kVp8Codec); |
| 773 | } |
| 774 | |
| 775 | TEST_F(WebRtcVideoChannel2BaseTest, TwoStreamsReUseFirstStream) { |
| 776 | Base::TwoStreamsReUseFirstStream(kVp8Codec); |
| 777 | } |
| 778 | |
pbos@webrtc.org | 9359cb3 | 2014-07-23 15:44:48 +0000 | [diff] [blame] | 779 | WEBRTC_BASE_TEST(SendManyResizeOnce); |
| 780 | |
| 781 | // TODO(pbos): Enable and figure out why this fails (or should work). |
| 782 | TEST_F(WebRtcVideoChannel2BaseTest, DISABLED_SendVp8HdAndReceiveAdaptedVp8Vga) { |
| 783 | EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); |
| 784 | EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_)); |
| 785 | channel_->UpdateAspectRatio(1280, 720); |
| 786 | video_capturer_.reset(new cricket::FakeVideoCapturer); |
| 787 | const std::vector<cricket::VideoFormat>* formats = |
| 788 | video_capturer_->GetSupportedFormats(); |
| 789 | cricket::VideoFormat capture_format_hd = (*formats)[0]; |
| 790 | EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd)); |
| 791 | EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); |
| 792 | |
| 793 | // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA. |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 794 | cricket::VideoCodec codec = kVp8Codec720p; |
pbos@webrtc.org | 9359cb3 | 2014-07-23 15:44:48 +0000 | [diff] [blame] | 795 | EXPECT_TRUE(SetOneCodec(codec)); |
| 796 | codec.width /= 2; |
| 797 | codec.height /= 2; |
| 798 | EXPECT_TRUE(SetSend(true)); |
| 799 | EXPECT_TRUE(channel_->SetRender(true)); |
| 800 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 801 | EXPECT_TRUE(SendFrame()); |
| 802 | EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout); |
| 803 | } |
| 804 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 805 | class WebRtcVideoChannel2Test : public WebRtcVideoEngine2Test, |
| 806 | public WebRtcCallFactory { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 807 | public: |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 808 | WebRtcVideoChannel2Test() : fake_call_(NULL) {} |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 809 | virtual void SetUp() OVERRIDE { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 810 | engine_.SetCallFactory(this); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 811 | engine_.Init(rtc::Thread::Current()); |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 812 | channel_.reset(engine_.CreateChannel(cricket::VideoOptions(), NULL)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 813 | ASSERT_TRUE(fake_call_ != NULL) << "Call not created through factory."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 814 | last_ssrc_ = 123; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 815 | ASSERT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | protected: |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 819 | virtual webrtc::Call* CreateCall( |
| 820 | const webrtc::Call::Config& config) OVERRIDE { |
| 821 | assert(fake_call_ == NULL); |
| 822 | fake_call_ = new FakeCall(config); |
| 823 | return fake_call_; |
| 824 | } |
| 825 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 826 | FakeVideoSendStream* AddSendStream() { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 827 | return AddSendStream(StreamParams::CreateLegacy(++last_ssrc_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | FakeVideoSendStream* AddSendStream(const StreamParams& sp) { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 831 | size_t num_streams = fake_call_->GetVideoSendStreams().size(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 832 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 833 | std::vector<FakeVideoSendStream*> streams = |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 834 | fake_call_->GetVideoSendStreams(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 835 | EXPECT_EQ(num_streams + 1, streams.size()); |
| 836 | return streams[streams.size() - 1]; |
| 837 | } |
| 838 | |
| 839 | std::vector<FakeVideoSendStream*> GetFakeSendStreams() { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 840 | return fake_call_->GetVideoSendStreams(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | FakeVideoReceiveStream* AddRecvStream() { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 844 | return AddRecvStream(StreamParams::CreateLegacy(++last_ssrc_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | FakeVideoReceiveStream* AddRecvStream(const StreamParams& sp) { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 848 | size_t num_streams = fake_call_->GetVideoReceiveStreams().size(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 849 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 850 | std::vector<FakeVideoReceiveStream*> streams = |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 851 | fake_call_->GetVideoReceiveStreams(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 852 | EXPECT_EQ(num_streams + 1, streams.size()); |
| 853 | return streams[streams.size() - 1]; |
| 854 | } |
| 855 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 856 | void SetSendCodecsShouldWorkForBitrates(const char* min_bitrate_kbps, |
| 857 | int expected_min_bitrate_bps, |
| 858 | const char* start_bitrate_kbps, |
| 859 | int expected_start_bitrate_bps, |
| 860 | const char* max_bitrate_kbps, |
| 861 | int expected_max_bitrate_bps) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 862 | std::vector<VideoCodec> codecs; |
| 863 | codecs.push_back(kVp8Codec); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 864 | codecs[0].params[kCodecParamMinBitrate] = min_bitrate_kbps; |
| 865 | codecs[0].params[kCodecParamStartBitrate] = start_bitrate_kbps; |
| 866 | codecs[0].params[kCodecParamMaxBitrate] = max_bitrate_kbps; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 867 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 868 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 869 | EXPECT_EQ(expected_min_bitrate_bps, |
| 870 | fake_call_->GetConfig().stream_bitrates.min_bitrate_bps); |
| 871 | EXPECT_EQ(expected_start_bitrate_bps, |
| 872 | fake_call_->GetConfig().stream_bitrates.start_bitrate_bps); |
| 873 | EXPECT_EQ(expected_max_bitrate_bps, |
| 874 | fake_call_->GetConfig().stream_bitrates.max_bitrate_bps); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 875 | } |
| 876 | |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 877 | void TestSetSendRtpHeaderExtensions(const std::string& cricket_ext, |
| 878 | const std::string& webrtc_ext) { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 879 | FakeCall* call = fake_call_; |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 880 | // Enable extension. |
| 881 | const int id = 1; |
| 882 | std::vector<cricket::RtpHeaderExtension> extensions; |
| 883 | extensions.push_back(cricket::RtpHeaderExtension(cricket_ext, id)); |
| 884 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); |
| 885 | |
| 886 | FakeVideoSendStream* send_stream = |
| 887 | AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| 888 | |
| 889 | // Verify the send extension id. |
| 890 | ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| 891 | EXPECT_EQ(id, send_stream->GetConfig().rtp.extensions[0].id); |
| 892 | EXPECT_EQ(webrtc_ext, send_stream->GetConfig().rtp.extensions[0].name); |
| 893 | // Verify call with same set of extensions returns true. |
| 894 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); |
| 895 | // Verify that SetSendRtpHeaderExtensions doesn't implicitly add them for |
| 896 | // receivers. |
| 897 | EXPECT_TRUE(AddRecvStream(cricket::StreamParams::CreateLegacy(123)) |
| 898 | ->GetConfig() |
| 899 | .rtp.extensions.empty()); |
| 900 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 901 | // Verify that existing RTP header extensions can be removed. |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 902 | std::vector<cricket::RtpHeaderExtension> empty_extensions; |
| 903 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions)); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 904 | ASSERT_EQ(1u, call->GetVideoSendStreams().size()); |
| 905 | send_stream = call->GetVideoSendStreams()[0]; |
| 906 | EXPECT_TRUE(send_stream->GetConfig().rtp.extensions.empty()); |
| 907 | |
| 908 | // Verify that adding receive RTP header extensions adds them for existing |
| 909 | // streams. |
| 910 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); |
| 911 | send_stream = call->GetVideoSendStreams()[0]; |
| 912 | ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| 913 | EXPECT_EQ(id, send_stream->GetConfig().rtp.extensions[0].id); |
| 914 | EXPECT_EQ(webrtc_ext, send_stream->GetConfig().rtp.extensions[0].name); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | void TestSetRecvRtpHeaderExtensions(const std::string& cricket_ext, |
| 918 | const std::string& webrtc_ext) { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 919 | FakeCall* call = fake_call_; |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 920 | // Enable extension. |
| 921 | const int id = 1; |
| 922 | std::vector<cricket::RtpHeaderExtension> extensions; |
| 923 | extensions.push_back(cricket::RtpHeaderExtension(cricket_ext, id)); |
| 924 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
| 925 | |
| 926 | FakeVideoReceiveStream* recv_stream = |
| 927 | AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| 928 | |
| 929 | // Verify the recv extension id. |
| 930 | ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
| 931 | EXPECT_EQ(id, recv_stream->GetConfig().rtp.extensions[0].id); |
| 932 | EXPECT_EQ(webrtc_ext, recv_stream->GetConfig().rtp.extensions[0].name); |
| 933 | // Verify call with same set of extensions returns true. |
| 934 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 935 | |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 936 | // Verify that SetRecvRtpHeaderExtensions doesn't implicitly add them for |
| 937 | // senders. |
| 938 | EXPECT_TRUE(AddSendStream(cricket::StreamParams::CreateLegacy(123)) |
| 939 | ->GetConfig() |
| 940 | .rtp.extensions.empty()); |
| 941 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 942 | // Verify that existing RTP header extensions can be removed. |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 943 | std::vector<cricket::RtpHeaderExtension> empty_extensions; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 944 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions)); |
| 945 | ASSERT_EQ(1u, call->GetVideoReceiveStreams().size()); |
| 946 | recv_stream = call->GetVideoReceiveStreams()[0]; |
| 947 | EXPECT_TRUE(recv_stream->GetConfig().rtp.extensions.empty()); |
| 948 | |
| 949 | // Verify that adding receive RTP header extensions adds them for existing |
| 950 | // streams. |
| 951 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
| 952 | recv_stream = call->GetVideoReceiveStreams()[0]; |
| 953 | ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
| 954 | EXPECT_EQ(id, recv_stream->GetConfig().rtp.extensions[0].id); |
| 955 | EXPECT_EQ(webrtc_ext, recv_stream->GetConfig().rtp.extensions[0].name); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 956 | } |
| 957 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 958 | void TestCpuAdaptation(bool enable_overuse); |
| 959 | |
| 960 | FakeCall* fake_call_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 961 | rtc::scoped_ptr<VideoMediaChannel> channel_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 962 | uint32 last_ssrc_; |
| 963 | }; |
| 964 | |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 965 | TEST_F(WebRtcVideoChannel2Test, RecvStreamWithSimAndRtx) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 966 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 967 | EXPECT_TRUE(channel_->SetSend(true)); |
| 968 | cricket::VideoOptions options; |
| 969 | options.conference_mode.Set(true); |
| 970 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 971 | |
| 972 | // Send side. |
| 973 | const std::vector<uint32> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 974 | const std::vector<uint32> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
| 975 | FakeVideoSendStream* send_stream = AddSendStream( |
| 976 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| 977 | |
| 978 | ASSERT_EQ(rtx_ssrcs.size(), send_stream->GetConfig().rtp.rtx.ssrcs.size()); |
| 979 | for (size_t i = 0; i < rtx_ssrcs.size(); ++i) |
| 980 | EXPECT_EQ(rtx_ssrcs[i], send_stream->GetConfig().rtp.rtx.ssrcs[i]); |
| 981 | |
| 982 | // Receiver side. |
| 983 | FakeVideoReceiveStream* recv_stream = AddRecvStream( |
| 984 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| 985 | ASSERT_GT(recv_stream->GetConfig().rtp.rtx.size(), 0u) |
| 986 | << "No SSRCs for RTX configured by AddRecvStream."; |
| 987 | ASSERT_EQ(1u, recv_stream->GetConfig().rtp.rtx.size()) |
| 988 | << "This test only works with one receive codec. Please update the test."; |
| 989 | EXPECT_EQ(rtx_ssrcs[0], |
| 990 | recv_stream->GetConfig().rtp.rtx.begin()->second.ssrc); |
| 991 | // TODO(pbos): Make sure we set the RTX for correct payloads etc. |
| 992 | } |
| 993 | |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 994 | TEST_F(WebRtcVideoChannel2Test, RecvStreamWithRtx) { |
| 995 | // Setup one channel with an associated RTX stream. |
| 996 | cricket::StreamParams params = |
| 997 | cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| 998 | params.AddFidSsrc(kSsrcs1[0], kRtxSsrcs1[0]); |
| 999 | FakeVideoReceiveStream* recv_stream = AddRecvStream(params); |
| 1000 | ASSERT_EQ(1u, recv_stream->GetConfig().rtp.rtx.size()); |
| 1001 | EXPECT_EQ(kRtxSsrcs1[0], |
| 1002 | recv_stream->GetConfig().rtp.rtx.begin()->second.ssrc); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 1005 | TEST_F(WebRtcVideoChannel2Test, RecvStreamNoRtx) { |
| 1006 | // Setup one channel without an associated RTX stream. |
| 1007 | cricket::StreamParams params = |
| 1008 | cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| 1009 | FakeVideoReceiveStream* recv_stream = AddRecvStream(params); |
| 1010 | ASSERT_TRUE(recv_stream->GetConfig().rtp.rtx.empty()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 1013 | TEST_F(WebRtcVideoChannel2Test, NoHeaderExtesionsByDefault) { |
| 1014 | FakeVideoSendStream* send_stream = |
| 1015 | AddSendStream(cricket::StreamParams::CreateLegacy(kSsrcs1[0])); |
| 1016 | ASSERT_TRUE(send_stream->GetConfig().rtp.extensions.empty()); |
| 1017 | |
| 1018 | FakeVideoReceiveStream* recv_stream = |
| 1019 | AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrcs1[0])); |
| 1020 | ASSERT_TRUE(recv_stream->GetConfig().rtp.extensions.empty()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 1023 | // Test support for RTP timestamp offset header extension. |
| 1024 | TEST_F(WebRtcVideoChannel2Test, SendRtpTimestampOffsetHeaderExtensions) { |
| 1025 | TestSetSendRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension, |
| 1026 | webrtc::RtpExtension::kTOffset); |
| 1027 | } |
| 1028 | TEST_F(WebRtcVideoChannel2Test, RecvRtpTimestampOffsetHeaderExtensions) { |
| 1029 | TestSetRecvRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension, |
| 1030 | webrtc::RtpExtension::kTOffset); |
| 1031 | } |
| 1032 | |
| 1033 | // Test support for absolute send time header extension. |
| 1034 | TEST_F(WebRtcVideoChannel2Test, SendAbsoluteSendTimeHeaderExtensions) { |
| 1035 | TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension, |
| 1036 | webrtc::RtpExtension::kAbsSendTime); |
| 1037 | } |
| 1038 | TEST_F(WebRtcVideoChannel2Test, RecvAbsoluteSendTimeHeaderExtensions) { |
| 1039 | TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension, |
| 1040 | webrtc::RtpExtension::kAbsSendTime); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1043 | TEST_F(WebRtcVideoChannel2Test, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1044 | SetSendRtpHeaderExtensionsExcludeUnsupportedExtensions) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1045 | const int kUnsupportedId = 1; |
| 1046 | const int kTOffsetId = 2; |
| 1047 | |
| 1048 | std::vector<cricket::RtpHeaderExtension> extensions; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1049 | extensions.push_back( |
| 1050 | cricket::RtpHeaderExtension(kUnsupportedExtensionName, kUnsupportedId)); |
| 1051 | extensions.push_back( |
| 1052 | cricket::RtpHeaderExtension(webrtc::RtpExtension::kTOffset, kTOffsetId)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1053 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); |
| 1054 | FakeVideoSendStream* send_stream = |
| 1055 | AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| 1056 | |
| 1057 | // Only timestamp offset extension is set to send stream, |
| 1058 | // unsupported rtp extension is ignored. |
| 1059 | ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| 1060 | EXPECT_STREQ(webrtc::RtpExtension::kTOffset, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1061 | send_stream->GetConfig().rtp.extensions[0].name.c_str()); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | TEST_F(WebRtcVideoChannel2Test, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1065 | SetRecvRtpHeaderExtensionsExcludeUnsupportedExtensions) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1066 | const int kUnsupportedId = 1; |
| 1067 | const int kTOffsetId = 2; |
| 1068 | |
| 1069 | std::vector<cricket::RtpHeaderExtension> extensions; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1070 | extensions.push_back( |
| 1071 | cricket::RtpHeaderExtension(kUnsupportedExtensionName, kUnsupportedId)); |
| 1072 | extensions.push_back( |
| 1073 | cricket::RtpHeaderExtension(webrtc::RtpExtension::kTOffset, kTOffsetId)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1074 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
| 1075 | FakeVideoReceiveStream* recv_stream = |
| 1076 | AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| 1077 | |
| 1078 | // Only timestamp offset extension is set to receive stream, |
| 1079 | // unsupported rtp extension is ignored. |
| 1080 | ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
| 1081 | EXPECT_STREQ(webrtc::RtpExtension::kTOffset, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1082 | recv_stream->GetConfig().rtp.extensions[0].name.c_str()); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1085 | TEST_F(WebRtcVideoChannel2Test, SetSendRtpHeaderExtensionsRejectsIncorrectIds) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1086 | const size_t kNumIncorrectIds = 4; |
| 1087 | const int kIncorrectIds[kNumIncorrectIds] = {-2, -1, 15, 16}; |
| 1088 | for (size_t i = 0; i < kNumIncorrectIds; ++i) { |
| 1089 | std::vector<cricket::RtpHeaderExtension> extensions; |
| 1090 | extensions.push_back(cricket::RtpHeaderExtension( |
| 1091 | webrtc::RtpExtension::kTOffset, kIncorrectIds[i])); |
| 1092 | EXPECT_FALSE(channel_->SetSendRtpHeaderExtensions(extensions)) |
| 1093 | << "Bad extension id '" << kIncorrectIds[i] << "' accepted."; |
| 1094 | } |
| 1095 | } |
| 1096 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1097 | TEST_F(WebRtcVideoChannel2Test, SetRecvRtpHeaderExtensionsRejectsIncorrectIds) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1098 | const size_t kNumIncorrectIds = 4; |
| 1099 | const int kIncorrectIds[kNumIncorrectIds] = {-2, -1, 15, 16}; |
| 1100 | for (size_t i = 0; i < kNumIncorrectIds; ++i) { |
| 1101 | std::vector<cricket::RtpHeaderExtension> extensions; |
| 1102 | extensions.push_back(cricket::RtpHeaderExtension( |
| 1103 | webrtc::RtpExtension::kTOffset, kIncorrectIds[i])); |
| 1104 | EXPECT_FALSE(channel_->SetRecvRtpHeaderExtensions(extensions)) |
| 1105 | << "Bad extension id '" << kIncorrectIds[i] << "' accepted."; |
| 1106 | } |
| 1107 | } |
| 1108 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1109 | TEST_F(WebRtcVideoChannel2Test, SetSendRtpHeaderExtensionsRejectsDuplicateIds) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1110 | const int id = 1; |
| 1111 | std::vector<cricket::RtpHeaderExtension> extensions; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1112 | extensions.push_back( |
| 1113 | cricket::RtpHeaderExtension(webrtc::RtpExtension::kTOffset, id)); |
| 1114 | extensions.push_back( |
| 1115 | cricket::RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, id)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1116 | EXPECT_FALSE(channel_->SetSendRtpHeaderExtensions(extensions)); |
| 1117 | |
| 1118 | // Duplicate entries are also not supported. |
| 1119 | extensions.clear(); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1120 | extensions.push_back( |
| 1121 | cricket::RtpHeaderExtension(webrtc::RtpExtension::kTOffset, id)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1122 | extensions.push_back(extensions.back()); |
| 1123 | EXPECT_FALSE(channel_->SetSendRtpHeaderExtensions(extensions)); |
| 1124 | } |
| 1125 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1126 | TEST_F(WebRtcVideoChannel2Test, SetRecvRtpHeaderExtensionsRejectsDuplicateIds) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1127 | const int id = 1; |
| 1128 | std::vector<cricket::RtpHeaderExtension> extensions; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1129 | extensions.push_back( |
| 1130 | cricket::RtpHeaderExtension(webrtc::RtpExtension::kTOffset, id)); |
| 1131 | extensions.push_back( |
| 1132 | cricket::RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, id)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1133 | EXPECT_FALSE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
| 1134 | |
| 1135 | // Duplicate entries are also not supported. |
| 1136 | extensions.clear(); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1137 | extensions.push_back( |
| 1138 | cricket::RtpHeaderExtension(webrtc::RtpExtension::kTOffset, id)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1139 | extensions.push_back(extensions.back()); |
| 1140 | EXPECT_FALSE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
| 1141 | } |
| 1142 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1143 | TEST_F(WebRtcVideoChannel2Test, DISABLED_LeakyBucketTest) { |
| 1144 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1145 | } |
| 1146 | |
| 1147 | TEST_F(WebRtcVideoChannel2Test, DISABLED_BufferedModeLatency) { |
| 1148 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1149 | } |
| 1150 | |
| 1151 | TEST_F(WebRtcVideoChannel2Test, DISABLED_AdditiveVideoOptions) { |
| 1152 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1153 | } |
| 1154 | |
| 1155 | TEST_F(WebRtcVideoChannel2Test, AddRecvStreamOnlyUsesOneReceiveStream) { |
| 1156 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1157 | EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 1160 | TEST_F(WebRtcVideoChannel2Test, RembIsEnabledByDefault) { |
| 1161 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 1162 | EXPECT_TRUE(stream->GetConfig().rtp.remb); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 1165 | TEST_F(WebRtcVideoChannel2Test, RembCanBeEnabledAndDisabled) { |
| 1166 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 1167 | EXPECT_TRUE(stream->GetConfig().rtp.remb); |
| 1168 | |
| 1169 | // Verify that REMB is turned off when codecs without REMB are set. |
| 1170 | std::vector<VideoCodec> codecs; |
| 1171 | codecs.push_back(kVp8Codec); |
| 1172 | EXPECT_TRUE(codecs[0].feedback_params.params().empty()); |
| 1173 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1174 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 1175 | EXPECT_FALSE(stream->GetConfig().rtp.remb); |
| 1176 | |
| 1177 | // Verify that REMB is turned on when setting default codecs since the |
| 1178 | // default codecs have REMB enabled. |
| 1179 | EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs())); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1180 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 1181 | EXPECT_TRUE(stream->GetConfig().rtp.remb); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 1184 | TEST_F(WebRtcVideoChannel2Test, NackIsEnabledByDefault) { |
| 1185 | VerifyCodecHasDefaultFeedbackParams(default_codec_); |
| 1186 | |
pbos@webrtc.org | 1986474 | 2014-05-30 07:35:47 +0000 | [diff] [blame] | 1187 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 1188 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1189 | |
| 1190 | // Send side. |
| 1191 | FakeVideoSendStream* send_stream = |
| 1192 | AddSendStream(cricket::StreamParams::CreateLegacy(1)); |
| 1193 | EXPECT_GT(send_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 1194 | |
| 1195 | // Receiver side. |
| 1196 | FakeVideoReceiveStream* recv_stream = |
| 1197 | AddRecvStream(cricket::StreamParams::CreateLegacy(1)); |
| 1198 | EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 1199 | |
| 1200 | // Nack history size should match between sender and receiver. |
| 1201 | EXPECT_EQ(send_stream->GetConfig().rtp.nack.rtp_history_ms, |
| 1202 | recv_stream->GetConfig().rtp.nack.rtp_history_ms); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 1205 | TEST_F(WebRtcVideoChannel2Test, NackCanBeDisabled) { |
| 1206 | std::vector<VideoCodec> codecs; |
| 1207 | codecs.push_back(kVp8Codec); |
| 1208 | |
| 1209 | // Send side. |
| 1210 | ASSERT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1211 | FakeVideoSendStream* send_stream = |
| 1212 | AddSendStream(cricket::StreamParams::CreateLegacy(1)); |
| 1213 | EXPECT_EQ(0, send_stream->GetConfig().rtp.nack.rtp_history_ms); |
| 1214 | |
| 1215 | // Receiver side. |
| 1216 | ASSERT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1217 | FakeVideoReceiveStream* recv_stream = |
| 1218 | AddRecvStream(cricket::StreamParams::CreateLegacy(1)); |
| 1219 | EXPECT_EQ(0, recv_stream->GetConfig().rtp.nack.rtp_history_ms); |
| 1220 | } |
| 1221 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1222 | TEST_F(WebRtcVideoChannel2Test, DISABLED_VideoProtectionInterop) { |
| 1223 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1224 | } |
| 1225 | |
| 1226 | TEST_F(WebRtcVideoChannel2Test, DISABLED_VideoProtectionInteropReversed) { |
| 1227 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1228 | } |
| 1229 | |
| 1230 | TEST_F(WebRtcVideoChannel2Test, DISABLED_HybridNackFecConference) { |
| 1231 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1232 | } |
| 1233 | |
| 1234 | TEST_F(WebRtcVideoChannel2Test, DISABLED_AddRemoveRecvStreamConference) { |
| 1235 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1236 | } |
| 1237 | |
| 1238 | TEST_F(WebRtcVideoChannel2Test, DISABLED_SetRender) { |
| 1239 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1240 | } |
| 1241 | |
| 1242 | TEST_F(WebRtcVideoChannel2Test, DISABLED_SetBandwidthAuto) { |
| 1243 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1244 | } |
| 1245 | |
| 1246 | TEST_F(WebRtcVideoChannel2Test, DISABLED_SetBandwidthAutoCapped) { |
| 1247 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1248 | } |
| 1249 | |
| 1250 | TEST_F(WebRtcVideoChannel2Test, DISABLED_SetBandwidthFixed) { |
| 1251 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1252 | } |
| 1253 | |
| 1254 | TEST_F(WebRtcVideoChannel2Test, DISABLED_SetBandwidthInConference) { |
| 1255 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1256 | } |
| 1257 | |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 1258 | TEST_F(WebRtcVideoChannel2Test, UsesCorrectSettingsForScreencast) { |
| 1259 | static const int kScreenshareMinBitrateKbps = 800; |
| 1260 | cricket::VideoCodec codec = kVp8Codec360p; |
| 1261 | std::vector<cricket::VideoCodec> codecs; |
| 1262 | codecs.push_back(codec); |
| 1263 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1264 | VideoOptions options; |
| 1265 | options.screencast_min_bitrate.Set(kScreenshareMinBitrateKbps); |
| 1266 | channel_->SetOptions(options); |
| 1267 | |
| 1268 | AddSendStream(); |
| 1269 | |
| 1270 | cricket::FakeVideoCapturer capturer; |
| 1271 | capturer.SetScreencast(false); |
| 1272 | EXPECT_TRUE(channel_->SetCapturer(last_ssrc_, &capturer)); |
| 1273 | cricket::VideoFormat capture_format_hd = |
| 1274 | capturer.GetSupportedFormats()->front(); |
| 1275 | EXPECT_EQ(1280, capture_format_hd.width); |
| 1276 | EXPECT_EQ(720, capture_format_hd.height); |
| 1277 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_hd)); |
| 1278 | |
| 1279 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1280 | |
| 1281 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1282 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 1283 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| 1284 | |
| 1285 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| 1286 | |
| 1287 | // Verify non-screencast settings. |
| 1288 | webrtc::VideoEncoderConfig encoder_config = send_stream->GetEncoderConfig(); |
| 1289 | EXPECT_EQ(webrtc::VideoEncoderConfig::kRealtimeVideo, |
| 1290 | encoder_config.content_type); |
| 1291 | EXPECT_EQ(codec.width, encoder_config.streams.front().width); |
| 1292 | EXPECT_EQ(codec.height, encoder_config.streams.front().height); |
| 1293 | EXPECT_EQ(0, encoder_config.min_transmit_bitrate_bps) |
| 1294 | << "Non-screenshare shouldn't use min-transmit bitrate."; |
| 1295 | |
| 1296 | capturer.SetScreencast(true); |
| 1297 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1298 | |
| 1299 | EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
| 1300 | |
| 1301 | // Verify screencast settings. |
| 1302 | encoder_config = send_stream->GetEncoderConfig(); |
| 1303 | EXPECT_EQ(webrtc::VideoEncoderConfig::kScreenshare, |
| 1304 | encoder_config.content_type); |
| 1305 | EXPECT_EQ(kScreenshareMinBitrateKbps * 1000, |
| 1306 | encoder_config.min_transmit_bitrate_bps); |
| 1307 | |
| 1308 | EXPECT_EQ(capture_format_hd.width, encoder_config.streams.front().width); |
| 1309 | EXPECT_EQ(capture_format_hd.height, encoder_config.streams.front().height); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 1310 | EXPECT_TRUE(encoder_config.streams[0].temporal_layer_thresholds_bps.empty()); |
| 1311 | |
| 1312 | EXPECT_TRUE(channel_->SetCapturer(last_ssrc_, NULL)); |
| 1313 | } |
| 1314 | |
| 1315 | TEST_F(WebRtcVideoChannel2Test, |
| 1316 | ConferenceModeScreencastConfiguresTemporalLayer) { |
| 1317 | static const int kConferenceScreencastTemporalBitrateBps = 100000; |
| 1318 | VideoOptions options; |
| 1319 | options.conference_mode.Set(true); |
| 1320 | channel_->SetOptions(options); |
| 1321 | |
| 1322 | AddSendStream(); |
| 1323 | |
| 1324 | cricket::FakeVideoCapturer capturer; |
| 1325 | capturer.SetScreencast(true); |
| 1326 | EXPECT_TRUE(channel_->SetCapturer(last_ssrc_, &capturer)); |
| 1327 | cricket::VideoFormat capture_format_hd = |
| 1328 | capturer.GetSupportedFormats()->front(); |
| 1329 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_hd)); |
| 1330 | |
| 1331 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1332 | |
| 1333 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1334 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 1335 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| 1336 | |
| 1337 | webrtc::VideoEncoderConfig encoder_config = send_stream->GetEncoderConfig(); |
| 1338 | |
| 1339 | // Verify screencast settings. |
| 1340 | encoder_config = send_stream->GetEncoderConfig(); |
| 1341 | EXPECT_EQ(webrtc::VideoEncoderConfig::kScreenshare, |
| 1342 | encoder_config.content_type); |
| 1343 | ASSERT_EQ(1u, encoder_config.streams.size()); |
| 1344 | ASSERT_EQ(1u, encoder_config.streams[0].temporal_layer_thresholds_bps.size()); |
| 1345 | EXPECT_EQ(kConferenceScreencastTemporalBitrateBps, |
| 1346 | encoder_config.streams[0].temporal_layer_thresholds_bps[0]); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 1347 | |
| 1348 | EXPECT_TRUE(channel_->SetCapturer(last_ssrc_, NULL)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | TEST_F(WebRtcVideoChannel2Test, DISABLED_SetSendSsrcAndCname) { |
| 1352 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1353 | } |
| 1354 | |
| 1355 | TEST_F(WebRtcVideoChannel2Test, |
| 1356 | DISABLED_SetSendSsrcAfterCreatingReceiveChannel) { |
| 1357 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1358 | } |
| 1359 | |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 1360 | TEST_F(WebRtcVideoChannel2Test, SuspendBelowMinBitrateDisabledByDefault) { |
| 1361 | FakeVideoSendStream* stream = AddSendStream(); |
| 1362 | EXPECT_FALSE(stream->GetConfig().suspend_below_min_bitrate); |
| 1363 | } |
| 1364 | |
| 1365 | TEST_F(WebRtcVideoChannel2Test, SetOptionsWithSuspendBelowMinBitrate) { |
| 1366 | VideoOptions options; |
| 1367 | options.suspend_below_min_bitrate.Set(true); |
| 1368 | channel_->SetOptions(options); |
| 1369 | |
| 1370 | FakeVideoSendStream* stream = AddSendStream(); |
| 1371 | EXPECT_TRUE(stream->GetConfig().suspend_below_min_bitrate); |
| 1372 | |
| 1373 | options.suspend_below_min_bitrate.Set(false); |
| 1374 | channel_->SetOptions(options); |
| 1375 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1376 | stream = fake_call_->GetVideoSendStreams()[0]; |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 1377 | EXPECT_FALSE(stream->GetConfig().suspend_below_min_bitrate); |
| 1378 | } |
| 1379 | |
pbos@webrtc.org | 543e589 | 2014-07-23 07:01:31 +0000 | [diff] [blame] | 1380 | TEST_F(WebRtcVideoChannel2Test, RedundantPayloadsDisabledByDefault) { |
| 1381 | const std::vector<uint32> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 1382 | const std::vector<uint32> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
| 1383 | FakeVideoSendStream* stream = AddSendStream( |
| 1384 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| 1385 | EXPECT_FALSE(stream->GetConfig().rtp.rtx.pad_with_redundant_payloads); |
| 1386 | } |
| 1387 | |
| 1388 | TEST_F(WebRtcVideoChannel2Test, SetOptionsWithPayloadPadding) { |
| 1389 | VideoOptions options; |
| 1390 | options.use_payload_padding.Set(true); |
| 1391 | channel_->SetOptions(options); |
| 1392 | |
| 1393 | const std::vector<uint32> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 1394 | const std::vector<uint32> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
| 1395 | FakeVideoSendStream* stream = AddSendStream( |
| 1396 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| 1397 | EXPECT_TRUE(stream->GetConfig().rtp.rtx.pad_with_redundant_payloads); |
| 1398 | |
| 1399 | options.use_payload_padding.Set(false); |
| 1400 | channel_->SetOptions(options); |
| 1401 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1402 | stream = fake_call_->GetVideoSendStreams()[0]; |
pbos@webrtc.org | 543e589 | 2014-07-23 07:01:31 +0000 | [diff] [blame] | 1403 | EXPECT_FALSE(stream->GetConfig().rtp.rtx.pad_with_redundant_payloads); |
| 1404 | } |
| 1405 | |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 1406 | TEST_F(WebRtcVideoChannel2Test, Vp8DenoisingEnabledByDefault) { |
| 1407 | FakeVideoSendStream* stream = AddSendStream(); |
| 1408 | webrtc::VideoCodecVP8 vp8_settings; |
| 1409 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 1410 | EXPECT_TRUE(vp8_settings.denoisingOn); |
| 1411 | } |
| 1412 | |
| 1413 | TEST_F(WebRtcVideoChannel2Test, SetOptionsWithDenoising) { |
| 1414 | VideoOptions options; |
| 1415 | options.video_noise_reduction.Set(false); |
| 1416 | channel_->SetOptions(options); |
| 1417 | |
| 1418 | FakeVideoSendStream* stream = AddSendStream(); |
| 1419 | webrtc::VideoCodecVP8 vp8_settings; |
| 1420 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 1421 | EXPECT_FALSE(vp8_settings.denoisingOn); |
| 1422 | |
| 1423 | options.video_noise_reduction.Set(true); |
| 1424 | channel_->SetOptions(options); |
| 1425 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1426 | stream = fake_call_->GetVideoSendStreams()[0]; |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 1427 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 1428 | EXPECT_TRUE(vp8_settings.denoisingOn); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | TEST_F(WebRtcVideoChannel2Test, DISABLED_MultipleSendStreamsWithOneCapturer) { |
| 1432 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1433 | } |
| 1434 | |
pbos@webrtc.org | 8aed945 | 2014-07-26 10:16:49 +0000 | [diff] [blame] | 1435 | TEST_F(WebRtcVideoChannel2Test, DISABLED_SendReceiveBitratesStats) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1436 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1437 | } |
| 1438 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1439 | TEST_F(WebRtcVideoChannel2Test, AdaptsOnOveruse) { |
| 1440 | TestCpuAdaptation(true); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1443 | TEST_F(WebRtcVideoChannel2Test, DoesNotAdaptOnOveruseWhenDisabled) { |
| 1444 | TestCpuAdaptation(false); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1447 | void WebRtcVideoChannel2Test::TestCpuAdaptation(bool enable_overuse) { |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 1448 | cricket::VideoCodec codec = kVp8Codec720p; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1449 | std::vector<cricket::VideoCodec> codecs; |
| 1450 | codecs.push_back(codec); |
| 1451 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1452 | |
| 1453 | if (enable_overuse) { |
| 1454 | VideoOptions options; |
| 1455 | options.cpu_overuse_detection.Set(true); |
| 1456 | channel_->SetOptions(options); |
| 1457 | } |
| 1458 | |
| 1459 | AddSendStream(); |
| 1460 | |
| 1461 | cricket::FakeVideoCapturer capturer; |
| 1462 | EXPECT_TRUE(channel_->SetCapturer(last_ssrc_, &capturer)); |
| 1463 | EXPECT_EQ(cricket::CS_RUNNING, |
| 1464 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 1465 | |
| 1466 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1467 | |
| 1468 | // Trigger overuse. |
| 1469 | webrtc::LoadObserver* overuse_callback = |
| 1470 | fake_call_->GetConfig().overuse_callback; |
| 1471 | ASSERT_TRUE(overuse_callback != NULL); |
| 1472 | overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kOveruse); |
| 1473 | |
| 1474 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1475 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 1476 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| 1477 | |
| 1478 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| 1479 | |
| 1480 | if (enable_overuse) { |
| 1481 | EXPECT_LT(send_stream->GetLastWidth(), codec.width); |
| 1482 | EXPECT_LT(send_stream->GetLastHeight(), codec.height); |
| 1483 | } else { |
| 1484 | EXPECT_EQ(codec.width, send_stream->GetLastWidth()); |
| 1485 | EXPECT_EQ(codec.height, send_stream->GetLastHeight()); |
| 1486 | } |
| 1487 | |
| 1488 | // Trigger underuse which should go back to normal resolution. |
| 1489 | overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kUnderuse); |
| 1490 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1491 | |
| 1492 | EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
| 1493 | |
| 1494 | EXPECT_EQ(codec.width, send_stream->GetLastWidth()); |
| 1495 | EXPECT_EQ(codec.height, send_stream->GetLastHeight()); |
| 1496 | |
| 1497 | EXPECT_TRUE(channel_->SetCapturer(last_ssrc_, NULL)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | TEST_F(WebRtcVideoChannel2Test, DISABLED_WebRtcShouldLog) { |
| 1501 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1502 | } |
| 1503 | |
| 1504 | TEST_F(WebRtcVideoChannel2Test, DISABLED_WebRtcShouldNotLog) { |
| 1505 | FAIL() << "Not implemented."; // TODO(pbos): Implement. |
| 1506 | } |
| 1507 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1508 | TEST_F(WebRtcVideoChannel2Test, SetDefaultSendCodecs) { |
pbos@webrtc.org | 9fbb717 | 2014-06-13 09:34:13 +0000 | [diff] [blame] | 1509 | ASSERT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1510 | |
| 1511 | VideoCodec codec; |
| 1512 | EXPECT_TRUE(channel_->GetSendCodec(&codec)); |
pbos@webrtc.org | 9fbb717 | 2014-06-13 09:34:13 +0000 | [diff] [blame] | 1513 | EXPECT_TRUE(codec.Matches(engine_.codecs()[0])); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1514 | |
| 1515 | // Using a RTX setup to verify that the default RTX payload type is good. |
| 1516 | const std::vector<uint32> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 1517 | const std::vector<uint32> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
| 1518 | FakeVideoSendStream* stream = AddSendStream( |
| 1519 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| 1520 | webrtc::VideoSendStream::Config config = stream->GetConfig(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1521 | |
| 1522 | // Make sure NACK and FEC are enabled on the correct payload types. |
| 1523 | EXPECT_EQ(1000, config.rtp.nack.rtp_history_ms); |
| 1524 | EXPECT_EQ(default_ulpfec_codec_.id, config.rtp.fec.ulpfec_payload_type); |
| 1525 | EXPECT_EQ(default_red_codec_.id, config.rtp.fec.red_payload_type); |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 1526 | |
| 1527 | EXPECT_EQ(1u, config.rtp.rtx.ssrcs.size()); |
| 1528 | EXPECT_EQ(kRtxSsrcs1[0], config.rtp.rtx.ssrcs[0]); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1529 | EXPECT_EQ(static_cast<int>(default_rtx_codec_.id), |
| 1530 | config.rtp.rtx.payload_type); |
| 1531 | // TODO(juberti): Check RTCP, PLI, TMMBR. |
| 1532 | } |
| 1533 | |
| 1534 | TEST_F(WebRtcVideoChannel2Test, SetSendCodecsWithoutFec) { |
| 1535 | std::vector<VideoCodec> codecs; |
| 1536 | codecs.push_back(kVp8Codec); |
| 1537 | ASSERT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1538 | |
| 1539 | FakeVideoSendStream* stream = AddSendStream(); |
| 1540 | webrtc::VideoSendStream::Config config = stream->GetConfig(); |
| 1541 | |
| 1542 | EXPECT_EQ(-1, config.rtp.fec.ulpfec_payload_type); |
| 1543 | EXPECT_EQ(-1, config.rtp.fec.red_payload_type); |
| 1544 | } |
| 1545 | |
| 1546 | TEST_F(WebRtcVideoChannel2Test, |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 1547 | SetSendCodecRejectsRtxWithoutAssociatedPayloadType) { |
| 1548 | std::vector<VideoCodec> codecs; |
| 1549 | cricket::VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0); |
| 1550 | codecs.push_back(rtx_codec); |
| 1551 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)) |
| 1552 | << "RTX codec without associated payload type should be rejected."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | TEST_F(WebRtcVideoChannel2Test, |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 1556 | SetSendCodecRejectsRtxWithoutMatchingVideoCodec) { |
| 1557 | std::vector<VideoCodec> codecs; |
| 1558 | cricket::VideoCodec rtx_codec = |
| 1559 | cricket::VideoCodec::CreateRtxCodec(96, kVp8Codec.id); |
| 1560 | codecs.push_back(kVp8Codec); |
| 1561 | codecs.push_back(rtx_codec); |
| 1562 | ASSERT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1563 | |
| 1564 | cricket::VideoCodec rtx_codec2 = |
| 1565 | cricket::VideoCodec::CreateRtxCodec(96, kVp8Codec.id + 1); |
| 1566 | codecs.pop_back(); |
| 1567 | codecs.push_back(rtx_codec2); |
| 1568 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)) |
| 1569 | << "RTX without matching video codec should be rejected."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 1572 | TEST_F(WebRtcVideoChannel2Test, SetSendCodecsWithoutFecDisablesFec) { |
| 1573 | std::vector<VideoCodec> codecs; |
| 1574 | codecs.push_back(kVp8Codec); |
| 1575 | codecs.push_back(kUlpfecCodec); |
| 1576 | ASSERT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1577 | |
| 1578 | FakeVideoSendStream* stream = AddSendStream(); |
| 1579 | webrtc::VideoSendStream::Config config = stream->GetConfig(); |
| 1580 | |
| 1581 | EXPECT_EQ(kUlpfecCodec.id, config.rtp.fec.ulpfec_payload_type); |
| 1582 | |
| 1583 | codecs.pop_back(); |
| 1584 | ASSERT_TRUE(channel_->SetSendCodecs(codecs)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1585 | stream = fake_call_->GetVideoSendStreams()[0]; |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 1586 | ASSERT_TRUE(stream != NULL); |
| 1587 | config = stream->GetConfig(); |
| 1588 | EXPECT_EQ(-1, config.rtp.fec.ulpfec_payload_type) |
| 1589 | << "SetSendCodec without FEC should disable current FEC."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
pbos@webrtc.org | 38ce7d0 | 2014-07-16 08:01:38 +0000 | [diff] [blame] | 1592 | TEST_F(WebRtcVideoChannel2Test, SetSendCodecsChangesExistingStreams) { |
| 1593 | std::vector<VideoCodec> codecs; |
| 1594 | codecs.push_back(kVp8Codec720p); |
| 1595 | ASSERT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1596 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1597 | std::vector<webrtc::VideoStream> streams = AddSendStream()->GetVideoStreams(); |
pbos@webrtc.org | 38ce7d0 | 2014-07-16 08:01:38 +0000 | [diff] [blame] | 1598 | EXPECT_EQ(kVp8Codec720p.width, streams[0].width); |
| 1599 | EXPECT_EQ(kVp8Codec720p.height, streams[0].height); |
| 1600 | |
| 1601 | codecs.clear(); |
| 1602 | codecs.push_back(kVp8Codec360p); |
| 1603 | ASSERT_TRUE(channel_->SetSendCodecs(codecs)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1604 | streams = fake_call_->GetVideoSendStreams()[0]->GetVideoStreams(); |
pbos@webrtc.org | 38ce7d0 | 2014-07-16 08:01:38 +0000 | [diff] [blame] | 1605 | EXPECT_EQ(kVp8Codec360p.width, streams[0].width); |
| 1606 | EXPECT_EQ(kVp8Codec360p.height, streams[0].height); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 1609 | TEST_F(WebRtcVideoChannel2Test, SetSendCodecsWithBitrates) { |
| 1610 | SetSendCodecsShouldWorkForBitrates("100", 100000, "150", 150000, "200", |
| 1611 | 200000); |
| 1612 | } |
| 1613 | |
| 1614 | TEST_F(WebRtcVideoChannel2Test, |
| 1615 | SetSendCodecsWithoutBitratesUsesCorrectDefaults) { |
| 1616 | SetSendCodecsShouldWorkForBitrates( |
| 1617 | "", 0, "", -1, "", -1); |
| 1618 | } |
| 1619 | |
| 1620 | TEST_F(WebRtcVideoChannel2Test, SetSendCodecsCapsMinAndStartBitrate) { |
| 1621 | SetSendCodecsShouldWorkForBitrates("-1", 0, "-100", -1, "", -1); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectsMaxLessThanMinBitrate) { |
pbos@webrtc.org | 9fbb717 | 2014-06-13 09:34:13 +0000 | [diff] [blame] | 1625 | std::vector<VideoCodec> video_codecs = engine_.codecs(); |
pbos@webrtc.org | 88ef632 | 2014-11-04 15:29:29 +0000 | [diff] [blame] | 1626 | video_codecs[0].params[kCodecParamMinBitrate] = "300"; |
| 1627 | video_codecs[0].params[kCodecParamMaxBitrate] = "200"; |
pbos@webrtc.org | 9fbb717 | 2014-06-13 09:34:13 +0000 | [diff] [blame] | 1628 | EXPECT_FALSE(channel_->SetSendCodecs(video_codecs)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1629 | } |
| 1630 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 1631 | TEST_F(WebRtcVideoChannel2Test, |
| 1632 | SetMaxSendBandwidthShouldPreserveOtherBitrates) { |
| 1633 | SetSendCodecsShouldWorkForBitrates("100", 100000, "150", 150000, "200", |
| 1634 | 200000); |
| 1635 | channel_->SetMaxSendBandwidth(300000); |
| 1636 | EXPECT_EQ(100000, fake_call_->GetConfig().stream_bitrates.min_bitrate_bps) |
| 1637 | << "Setting max bitrate should keep previous min bitrate."; |
| 1638 | EXPECT_EQ(-1, fake_call_->GetConfig().stream_bitrates.start_bitrate_bps) |
| 1639 | << "Setting max bitrate should not reset start bitrate."; |
| 1640 | EXPECT_EQ(300000, fake_call_->GetConfig().stream_bitrates.max_bitrate_bps); |
| 1641 | } |
| 1642 | |
| 1643 | TEST_F(WebRtcVideoChannel2Test, SetMaxSendBandwidthShouldBeRemovable) { |
| 1644 | channel_->SetMaxSendBandwidth(300000); |
| 1645 | EXPECT_EQ(300000, fake_call_->GetConfig().stream_bitrates.max_bitrate_bps); |
| 1646 | // <= 0 means disable (infinite) max bitrate. |
| 1647 | channel_->SetMaxSendBandwidth(0); |
| 1648 | EXPECT_EQ(-1, fake_call_->GetConfig().stream_bitrates.max_bitrate_bps) |
| 1649 | << "Setting zero max bitrate did not reset start bitrate."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | TEST_F(WebRtcVideoChannel2Test, SetSendCodecsWithMaxQuantization) { |
| 1653 | static const char* kMaxQuantization = "21"; |
| 1654 | std::vector<VideoCodec> codecs; |
| 1655 | codecs.push_back(kVp8Codec); |
| 1656 | codecs[0].params[kCodecParamMaxQuantization] = kMaxQuantization; |
| 1657 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 1658 | EXPECT_EQ(static_cast<unsigned int>(atoi(kMaxQuantization)), |
| 1659 | AddSendStream()->GetVideoStreams().back().max_qp); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1660 | |
| 1661 | VideoCodec codec; |
| 1662 | EXPECT_TRUE(channel_->GetSendCodec(&codec)); |
| 1663 | EXPECT_EQ(kMaxQuantization, codec.params[kCodecParamMaxQuantization]); |
| 1664 | } |
| 1665 | |
| 1666 | TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectBadDimensions) { |
| 1667 | std::vector<cricket::VideoCodec> codecs; |
| 1668 | codecs.push_back(kVp8Codec); |
| 1669 | |
| 1670 | codecs[0].width = 0; |
| 1671 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)) |
| 1672 | << "Codec set though codec width is zero."; |
| 1673 | |
| 1674 | codecs[0].width = kVp8Codec.width; |
| 1675 | codecs[0].height = 0; |
| 1676 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)) |
| 1677 | << "Codec set though codec height is zero."; |
| 1678 | } |
| 1679 | |
| 1680 | TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectBadPayloadTypes) { |
| 1681 | // TODO(pbos): Should we only allow the dynamic range? |
| 1682 | static const size_t kNumIncorrectPayloads = 4; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1683 | static const int kIncorrectPayloads[kNumIncorrectPayloads] = { |
| 1684 | -2, -1, 128, 129}; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1685 | std::vector<cricket::VideoCodec> codecs; |
| 1686 | codecs.push_back(kVp8Codec); |
| 1687 | for (size_t i = 0; i < kNumIncorrectPayloads; ++i) { |
| 1688 | int payload_type = kIncorrectPayloads[i]; |
| 1689 | codecs[0].id = payload_type; |
| 1690 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)) |
| 1691 | << "Bad payload type '" << payload_type << "' accepted."; |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | TEST_F(WebRtcVideoChannel2Test, SetSendCodecsAcceptAllValidPayloadTypes) { |
| 1696 | std::vector<cricket::VideoCodec> codecs; |
| 1697 | codecs.push_back(kVp8Codec); |
| 1698 | for (int payload_type = 0; payload_type <= 127; ++payload_type) { |
| 1699 | codecs[0].id = payload_type; |
| 1700 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)) |
| 1701 | << "Payload type '" << payload_type << "' rejected."; |
| 1702 | } |
| 1703 | } |
| 1704 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1705 | TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsWithOnlyVp8) { |
| 1706 | std::vector<cricket::VideoCodec> codecs; |
| 1707 | codecs.push_back(kVp8Codec); |
| 1708 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1709 | } |
| 1710 | |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 1711 | // Test that we set our inbound RTX codecs properly. |
| 1712 | TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsWithRtx) { |
| 1713 | std::vector<cricket::VideoCodec> codecs; |
| 1714 | codecs.push_back(kVp8Codec); |
| 1715 | cricket::VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0); |
| 1716 | codecs.push_back(rtx_codec); |
| 1717 | EXPECT_FALSE(channel_->SetRecvCodecs(codecs)) |
| 1718 | << "RTX codec without associated payload should be rejected."; |
| 1719 | |
| 1720 | codecs[1].SetParam("apt", kVp8Codec.id + 1); |
| 1721 | EXPECT_FALSE(channel_->SetRecvCodecs(codecs)) |
| 1722 | << "RTX codec with invalid associated payload type should be rejected."; |
| 1723 | |
| 1724 | codecs[1].SetParam("apt", kVp8Codec.id); |
| 1725 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1726 | |
| 1727 | cricket::VideoCodec rtx_codec2(97, "rtx", 0, 0, 0, 0); |
| 1728 | rtx_codec2.SetParam("apt", rtx_codec.id); |
| 1729 | codecs.push_back(rtx_codec2); |
| 1730 | |
| 1731 | EXPECT_FALSE(channel_->SetRecvCodecs(codecs)) << "RTX codec with another RTX " |
| 1732 | "as associated payload type " |
| 1733 | "should be rejected."; |
| 1734 | } |
| 1735 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1736 | TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsDifferentPayloadType) { |
| 1737 | std::vector<cricket::VideoCodec> codecs; |
| 1738 | codecs.push_back(kVp8Codec); |
| 1739 | codecs[0].id = 99; |
| 1740 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1741 | } |
| 1742 | |
pbos@webrtc.org | ccbed3b | 2014-07-11 13:02:54 +0000 | [diff] [blame] | 1743 | TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsAcceptDefaultCodecs) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1744 | EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs())); |
pbos@webrtc.org | ccbed3b | 2014-07-11 13:02:54 +0000 | [diff] [blame] | 1745 | |
| 1746 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 1747 | webrtc::VideoReceiveStream::Config config = stream->GetConfig(); |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 1748 | EXPECT_EQ(engine_.codecs()[0].name, config.decoders[0].payload_name); |
| 1749 | EXPECT_EQ(engine_.codecs()[0].id, config.decoders[0].payload_type); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsRejectUnsupportedCodec) { |
| 1753 | std::vector<VideoCodec> codecs; |
| 1754 | codecs.push_back(kVp8Codec); |
| 1755 | codecs.push_back(VideoCodec(101, "WTF3", 640, 400, 30, 0)); |
| 1756 | EXPECT_FALSE(channel_->SetRecvCodecs(codecs)); |
| 1757 | } |
| 1758 | |
| 1759 | // TODO(pbos): Enable VP9 through external codec support |
| 1760 | TEST_F(WebRtcVideoChannel2Test, |
| 1761 | DISABLED_SetRecvCodecsAcceptsMultipleVideoCodecs) { |
| 1762 | std::vector<VideoCodec> codecs; |
| 1763 | codecs.push_back(kVp8Codec); |
| 1764 | codecs.push_back(kVp9Codec); |
| 1765 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1766 | } |
| 1767 | |
| 1768 | TEST_F(WebRtcVideoChannel2Test, |
| 1769 | DISABLED_SetRecvCodecsSetsFecForAllVideoCodecs) { |
| 1770 | std::vector<VideoCodec> codecs; |
| 1771 | codecs.push_back(kVp8Codec); |
| 1772 | codecs.push_back(kVp9Codec); |
| 1773 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1774 | FAIL(); // TODO(pbos): Verify that the FEC parameters are set for all codecs. |
| 1775 | } |
| 1776 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1777 | TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsWithoutFecDisablesFec) { |
| 1778 | std::vector<VideoCodec> codecs; |
| 1779 | codecs.push_back(kVp8Codec); |
| 1780 | codecs.push_back(kUlpfecCodec); |
| 1781 | ASSERT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1782 | |
| 1783 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 1784 | webrtc::VideoReceiveStream::Config config = stream->GetConfig(); |
| 1785 | |
| 1786 | EXPECT_EQ(kUlpfecCodec.id, config.rtp.fec.ulpfec_payload_type); |
| 1787 | |
| 1788 | codecs.pop_back(); |
| 1789 | ASSERT_TRUE(channel_->SetRecvCodecs(codecs)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1790 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1791 | ASSERT_TRUE(stream != NULL); |
| 1792 | config = stream->GetConfig(); |
| 1793 | EXPECT_EQ(-1, config.rtp.fec.ulpfec_payload_type) |
| 1794 | << "SetSendCodec without FEC should disable current FEC."; |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 1795 | } |
| 1796 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1797 | TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectDuplicateFecPayloads) { |
| 1798 | std::vector<VideoCodec> codecs; |
| 1799 | codecs.push_back(kVp8Codec); |
| 1800 | codecs.push_back(kRedCodec); |
| 1801 | codecs[1].id = codecs[0].id; |
| 1802 | EXPECT_FALSE(channel_->SetRecvCodecs(codecs)); |
| 1803 | } |
| 1804 | |
| 1805 | TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsRejectDuplicateCodecPayloads) { |
| 1806 | std::vector<VideoCodec> codecs; |
| 1807 | codecs.push_back(kVp8Codec); |
| 1808 | codecs.push_back(kVp9Codec); |
| 1809 | codecs[1].id = codecs[0].id; |
| 1810 | EXPECT_FALSE(channel_->SetRecvCodecs(codecs)); |
| 1811 | } |
| 1812 | |
| 1813 | TEST_F(WebRtcVideoChannel2Test, |
| 1814 | SetRecvCodecsAcceptSameCodecOnMultiplePayloadTypes) { |
| 1815 | std::vector<VideoCodec> codecs; |
| 1816 | codecs.push_back(kVp8Codec); |
| 1817 | codecs.push_back(kVp8Codec); |
| 1818 | codecs[1].id += 1; |
| 1819 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1820 | } |
| 1821 | |
| 1822 | TEST_F(WebRtcVideoChannel2Test, SendStreamNotSendingByDefault) { |
| 1823 | EXPECT_FALSE(AddSendStream()->IsSending()); |
| 1824 | } |
| 1825 | |
pbos@webrtc.org | 85f4294 | 2014-07-22 09:14:58 +0000 | [diff] [blame] | 1826 | TEST_F(WebRtcVideoChannel2Test, ReceiveStreamReceivingByDefault) { |
| 1827 | EXPECT_TRUE(AddRecvStream()->IsReceiving()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | TEST_F(WebRtcVideoChannel2Test, SetSend) { |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1831 | FakeVideoSendStream* stream = AddSendStream(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1832 | EXPECT_FALSE(stream->IsSending()); |
| 1833 | |
| 1834 | // false->true |
| 1835 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1836 | EXPECT_TRUE(stream->IsSending()); |
| 1837 | // true->true |
| 1838 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1839 | EXPECT_TRUE(stream->IsSending()); |
| 1840 | // true->false |
| 1841 | EXPECT_TRUE(channel_->SetSend(false)); |
| 1842 | EXPECT_FALSE(stream->IsSending()); |
| 1843 | // false->false |
| 1844 | EXPECT_TRUE(channel_->SetSend(false)); |
| 1845 | EXPECT_FALSE(stream->IsSending()); |
| 1846 | |
| 1847 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1848 | FakeVideoSendStream* new_stream = AddSendStream(); |
| 1849 | EXPECT_TRUE(new_stream->IsSending()) |
| 1850 | << "Send stream created after SetSend(true) not sending initially."; |
| 1851 | } |
| 1852 | |
pbos@webrtc.org | d819803 | 2014-11-10 14:41:43 +0000 | [diff] [blame] | 1853 | // This test verifies DSCP settings are properly applied on video media channel. |
| 1854 | TEST_F(WebRtcVideoChannel2Test, TestSetDscpOptions) { |
| 1855 | rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface( |
| 1856 | new cricket::FakeNetworkInterface); |
| 1857 | channel_->SetInterface(network_interface.get()); |
| 1858 | cricket::VideoOptions options; |
| 1859 | options.dscp.Set(true); |
| 1860 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1861 | EXPECT_EQ(rtc::DSCP_AF41, network_interface->dscp()); |
| 1862 | // Verify previous value is not modified if dscp option is not set. |
| 1863 | cricket::VideoOptions options1; |
| 1864 | EXPECT_TRUE(channel_->SetOptions(options1)); |
| 1865 | EXPECT_EQ(rtc::DSCP_AF41, network_interface->dscp()); |
| 1866 | options.dscp.Set(false); |
| 1867 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1868 | EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); |
| 1869 | channel_->SetInterface(NULL); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 1872 | TEST_F(WebRtcVideoChannel2Test, OnReadyToSendSignalsNetworkState) { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1873 | EXPECT_EQ(webrtc::Call::kNetworkUp, fake_call_->GetNetworkState()); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 1874 | |
| 1875 | channel_->OnReadyToSend(false); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1876 | EXPECT_EQ(webrtc::Call::kNetworkDown, fake_call_->GetNetworkState()); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 1877 | |
| 1878 | channel_->OnReadyToSend(true); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1879 | EXPECT_EQ(webrtc::Call::kNetworkUp, fake_call_->GetNetworkState()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1880 | } |
| 1881 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 1882 | TEST_F(WebRtcVideoChannel2Test, GetStatsReportsUpperResolution) { |
| 1883 | FakeVideoSendStream* stream = AddSendStream(); |
| 1884 | webrtc::VideoSendStream::Stats stats; |
| 1885 | stats.substreams[17].sent_width = 123; |
| 1886 | stats.substreams[17].sent_height = 40; |
| 1887 | stats.substreams[42].sent_width = 80; |
| 1888 | stats.substreams[42].sent_height = 31; |
| 1889 | stats.substreams[11].sent_width = 20; |
| 1890 | stats.substreams[11].sent_height = 90; |
| 1891 | stream->SetStats(stats); |
| 1892 | |
| 1893 | cricket::VideoMediaInfo info; |
| 1894 | ASSERT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info)); |
| 1895 | ASSERT_EQ(1u, info.senders.size()); |
| 1896 | EXPECT_EQ(123, info.senders[0].send_frame_width); |
| 1897 | EXPECT_EQ(90, info.senders[0].send_frame_height); |
| 1898 | } |
| 1899 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1900 | } // namespace cricket |