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