blob: 54e6f06217bf2877a86043f1853053f9683989a2 [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 {
39class FakeVideoSendStream : public webrtc::VideoSendStream {
40 public:
41 FakeVideoSendStream(const webrtc::VideoSendStream::Config& config,
pbos@webrtc.org6f48f1b2014-07-22 16:29:54 +000042 const std::vector<webrtc::VideoStream>& video_streams,
43 const void* encoder_settings);
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
50 private:
51 virtual webrtc::VideoSendStream::Stats GetStats() const OVERRIDE;
52
53 virtual bool ReconfigureVideoEncoder(
54 const std::vector<webrtc::VideoStream>& streams,
55 const void* encoder_specific);
56
57 virtual webrtc::VideoSendStreamInput* Input() OVERRIDE;
58
59 virtual void Start() OVERRIDE;
60 virtual void Stop() OVERRIDE;
61
62 bool sending_;
63 webrtc::VideoSendStream::Config config_;
64 std::vector<webrtc::VideoStream> video_streams_;
pbos@webrtc.org6f48f1b2014-07-22 16:29:54 +000065 bool codec_settings_set_;
66 webrtc::VideoCodecVP8 vp8_settings_;
pbos@webrtc.org86f613d2014-06-10 08:53:05 +000067};
68
69class FakeVideoReceiveStream : public webrtc::VideoReceiveStream {
70 public:
71 explicit FakeVideoReceiveStream(
72 const webrtc::VideoReceiveStream::Config& config);
73
74 webrtc::VideoReceiveStream::Config GetConfig();
75
pbos@webrtc.org85f42942014-07-22 09:14:58 +000076 bool IsReceiving() const;
77
pbos@webrtc.org86f613d2014-06-10 08:53:05 +000078 private:
79 virtual webrtc::VideoReceiveStream::Stats GetStats() const OVERRIDE;
80
81 virtual void Start() OVERRIDE;
82 virtual void Stop() OVERRIDE;
83 virtual void GetCurrentReceiveCodec(webrtc::VideoCodec* codec);
84
85 webrtc::VideoReceiveStream::Config config_;
86 bool receiving_;
87};
88
89class FakeCall : public webrtc::Call {
90 public:
91 FakeCall();
92 ~FakeCall();
93
94 void SetVideoCodecs(const std::vector<webrtc::VideoCodec> codecs);
95
96 std::vector<FakeVideoSendStream*> GetVideoSendStreams();
97 std::vector<FakeVideoReceiveStream*> GetVideoReceiveStreams();
98
99 webrtc::VideoCodec GetEmptyVideoCodec();
100
101 webrtc::VideoCodec GetVideoCodecVp8();
102 webrtc::VideoCodec GetVideoCodecVp9();
103
104 std::vector<webrtc::VideoCodec> GetDefaultVideoCodecs();
105
106 private:
pbos@webrtc.org86f613d2014-06-10 08:53:05 +0000107 virtual webrtc::VideoSendStream* CreateVideoSendStream(
108 const webrtc::VideoSendStream::Config& config,
109 const std::vector<webrtc::VideoStream>& video_streams,
110 const void* encoder_settings) OVERRIDE;
111
112 virtual void DestroyVideoSendStream(
113 webrtc::VideoSendStream* send_stream) OVERRIDE;
114
pbos@webrtc.org86f613d2014-06-10 08:53:05 +0000115 virtual webrtc::VideoReceiveStream* CreateVideoReceiveStream(
116 const webrtc::VideoReceiveStream::Config& config) OVERRIDE;
117
118 virtual void DestroyVideoReceiveStream(
119 webrtc::VideoReceiveStream* receive_stream) OVERRIDE;
120 virtual webrtc::PacketReceiver* Receiver() OVERRIDE;
121
122 virtual uint32_t SendBitrateEstimate() OVERRIDE;
123 virtual uint32_t ReceiveBitrateEstimate() OVERRIDE;
124
125 std::vector<webrtc::VideoCodec> codecs_;
126 std::vector<FakeVideoSendStream*> video_send_streams_;
127 std::vector<FakeVideoReceiveStream*> video_receive_streams_;
128};
129
130class FakeWebRtcVideoChannel2 : public WebRtcVideoChannel2 {
131 public:
132 FakeWebRtcVideoChannel2(FakeCall* call,
133 WebRtcVideoEngine2* engine,
134 VoiceMediaChannel* voice_channel);
135 virtual ~FakeWebRtcVideoChannel2();
136
137 VoiceMediaChannel* GetVoiceChannel();
138 FakeCall* GetFakeCall();
139
140 private:
141 FakeCall* fake_call_;
142 VoiceMediaChannel* voice_channel_;
143};
144
145class FakeWebRtcVideoMediaChannelFactory : public WebRtcVideoChannelFactory {
146 public:
147 FakeWebRtcVideoChannel2* GetFakeChannel(VideoMediaChannel* channel);
148
149 private:
150 virtual WebRtcVideoChannel2* Create(
151 WebRtcVideoEngine2* engine,
152 VoiceMediaChannel* voice_channel) OVERRIDE;
153
154 std::map<VideoMediaChannel*, FakeWebRtcVideoChannel2*> channel_map_;
155};
156
157
158} // namespace cricket
159#endif // TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_UNITTEST_H_