blob: b3014ad869bfa9fdb260adccaf8fbbf7997be7d0 [file] [log] [blame]
pbos@webrtc.org86f613d2014-06-10 08:53:05 +00001/*
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
38namespace cricket {
pbos@webrtc.org42684be2014-10-03 11:25:45 +000039class FakeVideoSendStream : public webrtc::VideoSendStream,
40 public webrtc::VideoSendStreamInput {
pbos@webrtc.org86f613d2014-06-10 08:53:05 +000041 public:
42 FakeVideoSendStream(const webrtc::VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +000043 const webrtc::VideoEncoderConfig& encoder_config);
pbos@webrtc.org86f613d2014-06-10 08:53:05 +000044 webrtc::VideoSendStream::Config GetConfig();
45 std::vector<webrtc::VideoStream> GetVideoStreams();
46
pbos@webrtc.org85f42942014-07-22 09:14:58 +000047 bool IsSending() const;
pbos@webrtc.org6f48f1b2014-07-22 16:29:54 +000048 bool GetVp8Settings(webrtc::VideoCodecVP8* settings) const;
pbos@webrtc.org86f613d2014-06-10 08:53:05 +000049
pbos@webrtc.org42684be2014-10-03 11:25:45 +000050 int GetNumberOfSwappedFrames() const;
51 int GetLastWidth() const;
52 int GetLastHeight() const;
53
pbos@webrtc.org86f613d2014-06-10 08:53:05 +000054 private:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000055 virtual void SwapFrame(webrtc::I420VideoFrame* frame) OVERRIDE;
pbos@webrtc.org86f613d2014-06-10 08:53:05 +000056 virtual webrtc::VideoSendStream::Stats GetStats() const OVERRIDE;
57
58 virtual bool ReconfigureVideoEncoder(
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +000059 const webrtc::VideoEncoderConfig& config) OVERRIDE;
pbos@webrtc.org86f613d2014-06-10 08:53:05 +000060
61 virtual webrtc::VideoSendStreamInput* Input() OVERRIDE;
62
63 virtual void Start() OVERRIDE;
64 virtual void Stop() OVERRIDE;
65
66 bool sending_;
67 webrtc::VideoSendStream::Config config_;
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +000068 webrtc::VideoEncoderConfig encoder_config_;
pbos@webrtc.org6f48f1b2014-07-22 16:29:54 +000069 bool codec_settings_set_;
70 webrtc::VideoCodecVP8 vp8_settings_;
pbos@webrtc.org42684be2014-10-03 11:25:45 +000071 int num_swapped_frames_;
72 webrtc::I420VideoFrame last_frame_;
pbos@webrtc.org86f613d2014-06-10 08:53:05 +000073};
74
75class FakeVideoReceiveStream : public webrtc::VideoReceiveStream {
76 public:
77 explicit FakeVideoReceiveStream(
78 const webrtc::VideoReceiveStream::Config& config);
79
80 webrtc::VideoReceiveStream::Config GetConfig();
81
pbos@webrtc.org85f42942014-07-22 09:14:58 +000082 bool IsReceiving() const;
83
pbos@webrtc.org86f613d2014-06-10 08:53:05 +000084 private:
85 virtual webrtc::VideoReceiveStream::Stats GetStats() const OVERRIDE;
86
87 virtual void Start() OVERRIDE;
88 virtual void Stop() OVERRIDE;
89 virtual void GetCurrentReceiveCodec(webrtc::VideoCodec* codec);
90
91 webrtc::VideoReceiveStream::Config config_;
92 bool receiving_;
93};
94
95class FakeCall : public webrtc::Call {
96 public:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000097 FakeCall(const webrtc::Call::Config& config);
pbos@webrtc.org86f613d2014-06-10 08:53:05 +000098 ~FakeCall();
99
100 void SetVideoCodecs(const std::vector<webrtc::VideoCodec> codecs);
101
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000102 webrtc::Call::Config GetConfig() const;
pbos@webrtc.org86f613d2014-06-10 08:53:05 +0000103 std::vector<FakeVideoSendStream*> GetVideoSendStreams();
104 std::vector<FakeVideoReceiveStream*> GetVideoReceiveStreams();
105
106 webrtc::VideoCodec GetEmptyVideoCodec();
107
108 webrtc::VideoCodec GetVideoCodecVp8();
109 webrtc::VideoCodec GetVideoCodecVp9();
110
111 std::vector<webrtc::VideoCodec> GetDefaultVideoCodecs();
112
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000113 webrtc::Call::NetworkState GetNetworkState() const;
114
pbos@webrtc.org86f613d2014-06-10 08:53:05 +0000115 private:
pbos@webrtc.org86f613d2014-06-10 08:53:05 +0000116 virtual webrtc::VideoSendStream* CreateVideoSendStream(
117 const webrtc::VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000118 const webrtc::VideoEncoderConfig& encoder_config) OVERRIDE;
pbos@webrtc.org86f613d2014-06-10 08:53:05 +0000119
120 virtual void DestroyVideoSendStream(
121 webrtc::VideoSendStream* send_stream) OVERRIDE;
122
pbos@webrtc.org86f613d2014-06-10 08:53:05 +0000123 virtual webrtc::VideoReceiveStream* CreateVideoReceiveStream(
124 const webrtc::VideoReceiveStream::Config& config) OVERRIDE;
125
126 virtual void DestroyVideoReceiveStream(
127 webrtc::VideoReceiveStream* receive_stream) OVERRIDE;
128 virtual webrtc::PacketReceiver* Receiver() OVERRIDE;
129
130 virtual uint32_t SendBitrateEstimate() OVERRIDE;
131 virtual uint32_t ReceiveBitrateEstimate() OVERRIDE;
132
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000133 virtual void SignalNetworkState(webrtc::Call::NetworkState state) OVERRIDE;
134
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000135 const webrtc::Call::Config config_;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000136 webrtc::Call::NetworkState network_state_;
pbos@webrtc.org86f613d2014-06-10 08:53:05 +0000137 std::vector<webrtc::VideoCodec> codecs_;
138 std::vector<FakeVideoSendStream*> video_send_streams_;
139 std::vector<FakeVideoReceiveStream*> video_receive_streams_;
140};
141
pbos@webrtc.org86f613d2014-06-10 08:53:05 +0000142} // namespace cricket
143#endif // TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_UNITTEST_H_