Home | History | Annotate | Download | only in webrtc
      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,
     42                       const webrtc::VideoEncoderConfig& encoder_config);
     43   webrtc::VideoSendStream::Config GetConfig();
     44   std::vector<webrtc::VideoStream> GetVideoStreams();
     45 
     46   bool IsSending() const;
     47   bool GetVp8Settings(webrtc::VideoCodecVP8* settings) const;
     48 
     49  private:
     50   virtual webrtc::VideoSendStream::Stats GetStats() const OVERRIDE;
     51 
     52   virtual bool ReconfigureVideoEncoder(
     53       const webrtc::VideoEncoderConfig& config) OVERRIDE;
     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   webrtc::VideoEncoderConfig encoder_config_;
     63   bool codec_settings_set_;
     64   webrtc::VideoCodecVP8 vp8_settings_;
     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 
     74   bool IsReceiving() const;
     75 
     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 
    104   webrtc::Call::NetworkState GetNetworkState() const;
    105 
    106  private:
    107   virtual webrtc::VideoSendStream* CreateVideoSendStream(
    108       const webrtc::VideoSendStream::Config& config,
    109       const webrtc::VideoEncoderConfig& encoder_config) OVERRIDE;
    110 
    111   virtual void DestroyVideoSendStream(
    112       webrtc::VideoSendStream* send_stream) OVERRIDE;
    113 
    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 
    124   virtual void SignalNetworkState(webrtc::Call::NetworkState state) OVERRIDE;
    125 
    126   webrtc::Call::NetworkState network_state_;
    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_
    162