| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * libjingle | |
| 3 * Copyright 2015 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 // This file contains fake implementations, for use in unit tests, of the | |
| 29 // following classes: | |
| 30 // | |
| 31 // webrtc::Call | |
| 32 // webrtc::AudioSendStream | |
| 33 // webrtc::AudioReceiveStream | |
| 34 // webrtc::VideoSendStream | |
| 35 // webrtc::VideoReceiveStream | |
| 36 | |
| 37 #ifndef TALK_MEDIA_WEBRTC_FAKEWEBRTCCALL_H_ | |
| 38 #define TALK_MEDIA_WEBRTC_FAKEWEBRTCCALL_H_ | |
| 39 | |
| 40 #include <vector> | |
| 41 | |
| 42 #include "webrtc/call.h" | |
| 43 #include "webrtc/audio_receive_stream.h" | |
| 44 #include "webrtc/audio_send_stream.h" | |
| 45 #include "webrtc/video_frame.h" | |
| 46 #include "webrtc/video_receive_stream.h" | |
| 47 #include "webrtc/video_send_stream.h" | |
| 48 | |
| 49 namespace cricket { | |
| 50 class FakeAudioSendStream final : public webrtc::AudioSendStream { | |
| 51 public: | |
| 52 struct TelephoneEvent { | |
| 53 int payload_type = -1; | |
| 54 uint8_t event_code = 0; | |
| 55 uint32_t duration_ms = 0; | |
| 56 }; | |
| 57 | |
| 58 explicit FakeAudioSendStream(const webrtc::AudioSendStream::Config& config); | |
| 59 | |
| 60 const webrtc::AudioSendStream::Config& GetConfig() const; | |
| 61 void SetStats(const webrtc::AudioSendStream::Stats& stats); | |
| 62 TelephoneEvent GetLatestTelephoneEvent() const; | |
| 63 | |
| 64 private: | |
| 65 // webrtc::SendStream implementation. | |
| 66 void Start() override {} | |
| 67 void Stop() override {} | |
| 68 void SignalNetworkState(webrtc::NetworkState state) override {} | |
| 69 bool DeliverRtcp(const uint8_t* packet, size_t length) override { | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 // webrtc::AudioSendStream implementation. | |
| 74 bool SendTelephoneEvent(int payload_type, uint8_t event, | |
| 75 uint32_t duration_ms) override; | |
| 76 webrtc::AudioSendStream::Stats GetStats() const override; | |
| 77 | |
| 78 TelephoneEvent latest_telephone_event_; | |
| 79 webrtc::AudioSendStream::Config config_; | |
| 80 webrtc::AudioSendStream::Stats stats_; | |
| 81 }; | |
| 82 | |
| 83 class FakeAudioReceiveStream final : public webrtc::AudioReceiveStream { | |
| 84 public: | |
| 85 explicit FakeAudioReceiveStream( | |
| 86 const webrtc::AudioReceiveStream::Config& config); | |
| 87 | |
| 88 const webrtc::AudioReceiveStream::Config& GetConfig() const; | |
| 89 void SetStats(const webrtc::AudioReceiveStream::Stats& stats); | |
| 90 int received_packets() const { return received_packets_; } | |
| 91 void IncrementReceivedPackets(); | |
| 92 const webrtc::AudioSinkInterface* sink() const { return sink_.get(); } | |
| 93 | |
| 94 private: | |
| 95 // webrtc::ReceiveStream implementation. | |
| 96 void Start() override {} | |
| 97 void Stop() override {} | |
| 98 void SignalNetworkState(webrtc::NetworkState state) override {} | |
| 99 bool DeliverRtcp(const uint8_t* packet, size_t length) override { | |
| 100 return true; | |
| 101 } | |
| 102 bool DeliverRtp(const uint8_t* packet, | |
| 103 size_t length, | |
| 104 const webrtc::PacketTime& packet_time) override { | |
| 105 return true; | |
| 106 } | |
| 107 | |
| 108 // webrtc::AudioReceiveStream implementation. | |
| 109 webrtc::AudioReceiveStream::Stats GetStats() const override; | |
| 110 void SetSink(rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) override; | |
| 111 | |
| 112 webrtc::AudioReceiveStream::Config config_; | |
| 113 webrtc::AudioReceiveStream::Stats stats_; | |
| 114 int received_packets_; | |
| 115 rtc::scoped_ptr<webrtc::AudioSinkInterface> sink_; | |
| 116 }; | |
| 117 | |
| 118 class FakeVideoSendStream final : public webrtc::VideoSendStream, | |
| 119 public webrtc::VideoCaptureInput { | |
| 120 public: | |
| 121 FakeVideoSendStream(const webrtc::VideoSendStream::Config& config, | |
| 122 const webrtc::VideoEncoderConfig& encoder_config); | |
| 123 webrtc::VideoSendStream::Config GetConfig() const; | |
| 124 webrtc::VideoEncoderConfig GetEncoderConfig() const; | |
| 125 std::vector<webrtc::VideoStream> GetVideoStreams(); | |
| 126 | |
| 127 bool IsSending() const; | |
| 128 bool GetVp8Settings(webrtc::VideoCodecVP8* settings) const; | |
| 129 bool GetVp9Settings(webrtc::VideoCodecVP9* settings) const; | |
| 130 | |
| 131 int GetNumberOfSwappedFrames() const; | |
| 132 int GetLastWidth() const; | |
| 133 int GetLastHeight() const; | |
| 134 int64_t GetLastTimestamp() const; | |
| 135 void SetStats(const webrtc::VideoSendStream::Stats& stats); | |
| 136 | |
| 137 private: | |
| 138 void IncomingCapturedFrame(const webrtc::VideoFrame& frame) override; | |
| 139 | |
| 140 // webrtc::SendStream implementation. | |
| 141 void Start() override; | |
| 142 void Stop() override; | |
| 143 void SignalNetworkState(webrtc::NetworkState state) override {} | |
| 144 bool DeliverRtcp(const uint8_t* packet, size_t length) override { | |
| 145 return true; | |
| 146 } | |
| 147 | |
| 148 // webrtc::VideoSendStream implementation. | |
| 149 webrtc::VideoSendStream::Stats GetStats() override; | |
| 150 bool ReconfigureVideoEncoder( | |
| 151 const webrtc::VideoEncoderConfig& config) override; | |
| 152 webrtc::VideoCaptureInput* Input() override; | |
| 153 | |
| 154 bool sending_; | |
| 155 webrtc::VideoSendStream::Config config_; | |
| 156 webrtc::VideoEncoderConfig encoder_config_; | |
| 157 bool codec_settings_set_; | |
| 158 union VpxSettings { | |
| 159 webrtc::VideoCodecVP8 vp8; | |
| 160 webrtc::VideoCodecVP9 vp9; | |
| 161 } vpx_settings_; | |
| 162 int num_swapped_frames_; | |
| 163 webrtc::VideoFrame last_frame_; | |
| 164 webrtc::VideoSendStream::Stats stats_; | |
| 165 }; | |
| 166 | |
| 167 class FakeVideoReceiveStream final : public webrtc::VideoReceiveStream { | |
| 168 public: | |
| 169 explicit FakeVideoReceiveStream( | |
| 170 const webrtc::VideoReceiveStream::Config& config); | |
| 171 | |
| 172 webrtc::VideoReceiveStream::Config GetConfig(); | |
| 173 | |
| 174 bool IsReceiving() const; | |
| 175 | |
| 176 void InjectFrame(const webrtc::VideoFrame& frame, int time_to_render_ms); | |
| 177 | |
| 178 void SetStats(const webrtc::VideoReceiveStream::Stats& stats); | |
| 179 | |
| 180 private: | |
| 181 // webrtc::ReceiveStream implementation. | |
| 182 void Start() override; | |
| 183 void Stop() override; | |
| 184 void SignalNetworkState(webrtc::NetworkState state) override {} | |
| 185 bool DeliverRtcp(const uint8_t* packet, size_t length) override { | |
| 186 return true; | |
| 187 } | |
| 188 bool DeliverRtp(const uint8_t* packet, | |
| 189 size_t length, | |
| 190 const webrtc::PacketTime& packet_time) override { | |
| 191 return true; | |
| 192 } | |
| 193 | |
| 194 // webrtc::VideoReceiveStream implementation. | |
| 195 webrtc::VideoReceiveStream::Stats GetStats() const override; | |
| 196 | |
| 197 webrtc::VideoReceiveStream::Config config_; | |
| 198 bool receiving_; | |
| 199 webrtc::VideoReceiveStream::Stats stats_; | |
| 200 }; | |
| 201 | |
| 202 class FakeCall final : public webrtc::Call, public webrtc::PacketReceiver { | |
| 203 public: | |
| 204 explicit FakeCall(const webrtc::Call::Config& config); | |
| 205 ~FakeCall() override; | |
| 206 | |
| 207 webrtc::Call::Config GetConfig() const; | |
| 208 const std::vector<FakeVideoSendStream*>& GetVideoSendStreams(); | |
| 209 const std::vector<FakeVideoReceiveStream*>& GetVideoReceiveStreams(); | |
| 210 | |
| 211 const std::vector<FakeAudioSendStream*>& GetAudioSendStreams(); | |
| 212 const FakeAudioSendStream* GetAudioSendStream(uint32_t ssrc); | |
| 213 const std::vector<FakeAudioReceiveStream*>& GetAudioReceiveStreams(); | |
| 214 const FakeAudioReceiveStream* GetAudioReceiveStream(uint32_t ssrc); | |
| 215 | |
| 216 rtc::SentPacket last_sent_packet() const { return last_sent_packet_; } | |
| 217 webrtc::NetworkState GetNetworkState() const; | |
| 218 int GetNumCreatedSendStreams() const; | |
| 219 int GetNumCreatedReceiveStreams() const; | |
| 220 void SetStats(const webrtc::Call::Stats& stats); | |
| 221 | |
| 222 private: | |
| 223 webrtc::AudioSendStream* CreateAudioSendStream( | |
| 224 const webrtc::AudioSendStream::Config& config) override; | |
| 225 void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override; | |
| 226 | |
| 227 webrtc::AudioReceiveStream* CreateAudioReceiveStream( | |
| 228 const webrtc::AudioReceiveStream::Config& config) override; | |
| 229 void DestroyAudioReceiveStream( | |
| 230 webrtc::AudioReceiveStream* receive_stream) override; | |
| 231 | |
| 232 webrtc::VideoSendStream* CreateVideoSendStream( | |
| 233 const webrtc::VideoSendStream::Config& config, | |
| 234 const webrtc::VideoEncoderConfig& encoder_config) override; | |
| 235 void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override; | |
| 236 | |
| 237 webrtc::VideoReceiveStream* CreateVideoReceiveStream( | |
| 238 const webrtc::VideoReceiveStream::Config& config) override; | |
| 239 void DestroyVideoReceiveStream( | |
| 240 webrtc::VideoReceiveStream* receive_stream) override; | |
| 241 webrtc::PacketReceiver* Receiver() override; | |
| 242 | |
| 243 DeliveryStatus DeliverPacket(webrtc::MediaType media_type, | |
| 244 const uint8_t* packet, | |
| 245 size_t length, | |
| 246 const webrtc::PacketTime& packet_time) override; | |
| 247 | |
| 248 webrtc::Call::Stats GetStats() const override; | |
| 249 | |
| 250 void SetBitrateConfig( | |
| 251 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; | |
| 252 void SignalNetworkState(webrtc::NetworkState state) override; | |
| 253 void OnSentPacket(const rtc::SentPacket& sent_packet) override; | |
| 254 | |
| 255 webrtc::Call::Config config_; | |
| 256 webrtc::NetworkState network_state_; | |
| 257 rtc::SentPacket last_sent_packet_; | |
| 258 webrtc::Call::Stats stats_; | |
| 259 std::vector<FakeVideoSendStream*> video_send_streams_; | |
| 260 std::vector<FakeAudioSendStream*> audio_send_streams_; | |
| 261 std::vector<FakeVideoReceiveStream*> video_receive_streams_; | |
| 262 std::vector<FakeAudioReceiveStream*> audio_receive_streams_; | |
| 263 | |
| 264 int num_created_send_streams_; | |
| 265 int num_created_receive_streams_; | |
| 266 }; | |
| 267 | |
| 268 } // namespace cricket | |
| 269 #endif // TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_UNITTEST_H_ | |
| OLD | NEW |