pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2014 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 | #ifndef TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_UNITTEST_H_ |
| 29 | #define TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_UNITTEST_H_ |
| 30 | |
| 31 | #include <map> |
| 32 | #include <vector> |
| 33 | |
| 34 | #include "webrtc/call.h" |
| 35 | #include "webrtc/video_receive_stream.h" |
| 36 | #include "webrtc/video_send_stream.h" |
| 37 | |
| 38 | namespace cricket { |
| 39 | class FakeVideoSendStream : public webrtc::VideoSendStream { |
| 40 | public: |
| 41 | FakeVideoSendStream(const webrtc::VideoSendStream::Config& config, |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 42 | const webrtc::VideoEncoderConfig& encoder_config); |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 43 | webrtc::VideoSendStream::Config GetConfig(); |
| 44 | std::vector<webrtc::VideoStream> GetVideoStreams(); |
| 45 | |
pbos@webrtc.org | 85f4294 | 2014-07-22 09:14:58 +0000 | [diff] [blame] | 46 | bool IsSending() const; |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 47 | bool GetVp8Settings(webrtc::VideoCodecVP8* settings) const; |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | virtual webrtc::VideoSendStream::Stats GetStats() const OVERRIDE; |
| 51 | |
| 52 | virtual bool ReconfigureVideoEncoder( |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 53 | const webrtc::VideoEncoderConfig& config) OVERRIDE; |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 54 | |
| 55 | virtual webrtc::VideoSendStreamInput* Input() OVERRIDE; |
| 56 | |
| 57 | virtual void Start() OVERRIDE; |
| 58 | virtual void Stop() OVERRIDE; |
| 59 | |
| 60 | bool sending_; |
| 61 | webrtc::VideoSendStream::Config config_; |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 62 | webrtc::VideoEncoderConfig encoder_config_; |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 63 | bool codec_settings_set_; |
| 64 | webrtc::VideoCodecVP8 vp8_settings_; |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | class FakeVideoReceiveStream : public webrtc::VideoReceiveStream { |
| 68 | public: |
| 69 | explicit FakeVideoReceiveStream( |
| 70 | const webrtc::VideoReceiveStream::Config& config); |
| 71 | |
| 72 | webrtc::VideoReceiveStream::Config GetConfig(); |
| 73 | |
pbos@webrtc.org | 85f4294 | 2014-07-22 09:14:58 +0000 | [diff] [blame] | 74 | bool IsReceiving() const; |
| 75 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 76 | private: |
| 77 | virtual webrtc::VideoReceiveStream::Stats GetStats() const OVERRIDE; |
| 78 | |
| 79 | virtual void Start() OVERRIDE; |
| 80 | virtual void Stop() OVERRIDE; |
| 81 | virtual void GetCurrentReceiveCodec(webrtc::VideoCodec* codec); |
| 82 | |
| 83 | webrtc::VideoReceiveStream::Config config_; |
| 84 | bool receiving_; |
| 85 | }; |
| 86 | |
| 87 | class FakeCall : public webrtc::Call { |
| 88 | public: |
| 89 | FakeCall(); |
| 90 | ~FakeCall(); |
| 91 | |
| 92 | void SetVideoCodecs(const std::vector<webrtc::VideoCodec> codecs); |
| 93 | |
| 94 | std::vector<FakeVideoSendStream*> GetVideoSendStreams(); |
| 95 | std::vector<FakeVideoReceiveStream*> GetVideoReceiveStreams(); |
| 96 | |
| 97 | webrtc::VideoCodec GetEmptyVideoCodec(); |
| 98 | |
| 99 | webrtc::VideoCodec GetVideoCodecVp8(); |
| 100 | webrtc::VideoCodec GetVideoCodecVp9(); |
| 101 | |
| 102 | std::vector<webrtc::VideoCodec> GetDefaultVideoCodecs(); |
| 103 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 104 | webrtc::Call::NetworkState GetNetworkState() const; |
| 105 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 106 | private: |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 107 | virtual webrtc::VideoSendStream* CreateVideoSendStream( |
| 108 | const webrtc::VideoSendStream::Config& config, |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 109 | const webrtc::VideoEncoderConfig& encoder_config) OVERRIDE; |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 110 | |
| 111 | virtual void DestroyVideoSendStream( |
| 112 | webrtc::VideoSendStream* send_stream) OVERRIDE; |
| 113 | |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 114 | virtual webrtc::VideoReceiveStream* CreateVideoReceiveStream( |
| 115 | const webrtc::VideoReceiveStream::Config& config) OVERRIDE; |
| 116 | |
| 117 | virtual void DestroyVideoReceiveStream( |
| 118 | webrtc::VideoReceiveStream* receive_stream) OVERRIDE; |
| 119 | virtual webrtc::PacketReceiver* Receiver() OVERRIDE; |
| 120 | |
| 121 | virtual uint32_t SendBitrateEstimate() OVERRIDE; |
| 122 | virtual uint32_t ReceiveBitrateEstimate() OVERRIDE; |
| 123 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 124 | virtual void SignalNetworkState(webrtc::Call::NetworkState state) OVERRIDE; |
| 125 | |
| 126 | webrtc::Call::NetworkState network_state_; |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 127 | std::vector<webrtc::VideoCodec> codecs_; |
| 128 | std::vector<FakeVideoSendStream*> video_send_streams_; |
| 129 | std::vector<FakeVideoReceiveStream*> video_receive_streams_; |
| 130 | }; |
| 131 | |
| 132 | class FakeWebRtcVideoChannel2 : public WebRtcVideoChannel2 { |
| 133 | public: |
| 134 | FakeWebRtcVideoChannel2(FakeCall* call, |
| 135 | WebRtcVideoEngine2* engine, |
| 136 | VoiceMediaChannel* voice_channel); |
| 137 | virtual ~FakeWebRtcVideoChannel2(); |
| 138 | |
| 139 | VoiceMediaChannel* GetVoiceChannel(); |
| 140 | FakeCall* GetFakeCall(); |
| 141 | |
| 142 | private: |
| 143 | FakeCall* fake_call_; |
| 144 | VoiceMediaChannel* voice_channel_; |
| 145 | }; |
| 146 | |
| 147 | class FakeWebRtcVideoMediaChannelFactory : public WebRtcVideoChannelFactory { |
| 148 | public: |
| 149 | FakeWebRtcVideoChannel2* GetFakeChannel(VideoMediaChannel* channel); |
| 150 | |
| 151 | private: |
| 152 | virtual WebRtcVideoChannel2* Create( |
| 153 | WebRtcVideoEngine2* engine, |
| 154 | VoiceMediaChannel* voice_channel) OVERRIDE; |
| 155 | |
| 156 | std::map<VideoMediaChannel*, FakeWebRtcVideoChannel2*> channel_map_; |
| 157 | }; |
| 158 | |
| 159 | |
| 160 | } // namespace cricket |
| 161 | #endif // TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_UNITTEST_H_ |