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