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
38namespace cricket {
39class FakeVideoSendStream : public webrtc::VideoSendStream {
40 public:
41  FakeVideoSendStream(const webrtc::VideoSendStream::Config& config,
42                      const std::vector<webrtc::VideoStream>& video_streams);
43  webrtc::VideoSendStream::Config GetConfig();
44  std::vector<webrtc::VideoStream> GetVideoStreams();
45
46  bool IsSending();
47
48 private:
49  virtual webrtc::VideoSendStream::Stats GetStats() const OVERRIDE;
50
51  virtual bool ReconfigureVideoEncoder(
52      const std::vector<webrtc::VideoStream>& streams,
53      const void* encoder_specific);
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_;
62  std::vector<webrtc::VideoStream> video_streams_;
63};
64
65class FakeVideoReceiveStream : public webrtc::VideoReceiveStream {
66 public:
67  explicit FakeVideoReceiveStream(
68      const webrtc::VideoReceiveStream::Config& config);
69
70  webrtc::VideoReceiveStream::Config GetConfig();
71
72 private:
73  virtual webrtc::VideoReceiveStream::Stats GetStats() const OVERRIDE;
74
75  virtual void Start() OVERRIDE;
76  virtual void Stop() OVERRIDE;
77  virtual void GetCurrentReceiveCodec(webrtc::VideoCodec* codec);
78
79  webrtc::VideoReceiveStream::Config config_;
80  bool receiving_;
81};
82
83class FakeCall : public webrtc::Call {
84 public:
85  FakeCall();
86  ~FakeCall();
87
88  void SetVideoCodecs(const std::vector<webrtc::VideoCodec> codecs);
89
90  std::vector<FakeVideoSendStream*> GetVideoSendStreams();
91  std::vector<FakeVideoReceiveStream*> GetVideoReceiveStreams();
92
93  webrtc::VideoCodec GetEmptyVideoCodec();
94
95  webrtc::VideoCodec GetVideoCodecVp8();
96  webrtc::VideoCodec GetVideoCodecVp9();
97
98  std::vector<webrtc::VideoCodec> GetDefaultVideoCodecs();
99
100 private:
101  virtual webrtc::VideoSendStream::Config GetDefaultSendConfig() OVERRIDE;
102
103  virtual webrtc::VideoSendStream* CreateVideoSendStream(
104      const webrtc::VideoSendStream::Config& config,
105      const std::vector<webrtc::VideoStream>& video_streams,
106      const void* encoder_settings) OVERRIDE;
107
108  virtual void DestroyVideoSendStream(
109      webrtc::VideoSendStream* send_stream) OVERRIDE;
110
111  virtual webrtc::VideoReceiveStream::Config GetDefaultReceiveConfig() OVERRIDE;
112
113  virtual webrtc::VideoReceiveStream* CreateVideoReceiveStream(
114      const webrtc::VideoReceiveStream::Config& config) OVERRIDE;
115
116  virtual void DestroyVideoReceiveStream(
117      webrtc::VideoReceiveStream* receive_stream) OVERRIDE;
118  virtual webrtc::PacketReceiver* Receiver() OVERRIDE;
119
120  virtual uint32_t SendBitrateEstimate() OVERRIDE;
121  virtual uint32_t ReceiveBitrateEstimate() OVERRIDE;
122
123  std::vector<webrtc::VideoCodec> codecs_;
124  std::vector<FakeVideoSendStream*> video_send_streams_;
125  std::vector<FakeVideoReceiveStream*> video_receive_streams_;
126};
127
128class FakeWebRtcVideoChannel2 : public WebRtcVideoChannel2 {
129 public:
130  FakeWebRtcVideoChannel2(FakeCall* call,
131                          WebRtcVideoEngine2* engine,
132                          VoiceMediaChannel* voice_channel);
133  virtual ~FakeWebRtcVideoChannel2();
134
135  VoiceMediaChannel* GetVoiceChannel();
136  FakeCall* GetFakeCall();
137
138 private:
139  FakeCall* fake_call_;
140  VoiceMediaChannel* voice_channel_;
141};
142
143class FakeWebRtcVideoMediaChannelFactory : public WebRtcVideoChannelFactory {
144 public:
145  FakeWebRtcVideoChannel2* GetFakeChannel(VideoMediaChannel* channel);
146
147 private:
148  virtual WebRtcVideoChannel2* Create(
149      WebRtcVideoEngine2* engine,
150      VoiceMediaChannel* voice_channel) OVERRIDE;
151
152  std::map<VideoMediaChannel*, FakeWebRtcVideoChannel2*> channel_map_;
153};
154
155
156}  // namespace cricket
157#endif  // TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_UNITTEST_H_
158