Home | History | Annotate | Download | only in webrtc
      1 /*
      2  * libjingle
      3  * Copyright 2010 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_FAKEWEBRTCVIDEOENGINE_H_
     29 #define TALK_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_
     30 
     31 #include <map>
     32 #include <set>
     33 #include <vector>
     34 
     35 #include "talk/base/basictypes.h"
     36 #include "talk/base/gunit.h"
     37 #include "talk/base/stringutils.h"
     38 #include "talk/media/base/codec.h"
     39 #include "talk/media/webrtc/fakewebrtccommon.h"
     40 #include "talk/media/webrtc/webrtcvideodecoderfactory.h"
     41 #include "talk/media/webrtc/webrtcvideoencoderfactory.h"
     42 #include "talk/media/webrtc/webrtcvie.h"
     43 
     44 namespace webrtc {
     45 
     46 bool operator==(const webrtc::VideoCodec& c1, const webrtc::VideoCodec& c2) {
     47   return memcmp(&c1, &c2, sizeof(c1)) == 0;
     48 }
     49 
     50 }
     51 
     52 namespace cricket {
     53 
     54 #define WEBRTC_CHECK_CAPTURER(capturer) \
     55   if (capturers_.find(capturer) == capturers_.end()) return -1;
     56 
     57 #define WEBRTC_ASSERT_CAPTURER(capturer) \
     58   ASSERT(capturers_.find(capturer) != capturers_.end());
     59 
     60 static const int kMinVideoBitrate = 100;
     61 static const int kStartVideoBitrate = 300;
     62 static const int kMaxVideoBitrate = 1000;
     63 
     64 // WebRtc channel id and capture id share the same number space.
     65 // This is how AddRenderer(renderId, ...) is able to tell if it is adding a
     66 // renderer for a channel or it is adding a renderer for a capturer.
     67 static const int kViEChannelIdBase = 0;
     68 static const int kViEChannelIdMax = 1000;
     69 static const int kViECaptureIdBase = 10000;  // Make sure there is a gap.
     70 static const int kViECaptureIdMax = 11000;
     71 
     72 // Fake class for mocking out webrtc::VideoDecoder
     73 class FakeWebRtcVideoDecoder : public webrtc::VideoDecoder {
     74  public:
     75   FakeWebRtcVideoDecoder()
     76       : num_frames_received_(0) {
     77   }
     78 
     79   virtual int32 InitDecode(const webrtc::VideoCodec*, int32) {
     80     return WEBRTC_VIDEO_CODEC_OK;
     81   }
     82 
     83   virtual int32 Decode(
     84       const webrtc::EncodedImage&, bool, const webrtc::RTPFragmentationHeader*,
     85       const webrtc::CodecSpecificInfo*, int64) {
     86     num_frames_received_++;
     87     return WEBRTC_VIDEO_CODEC_OK;
     88   }
     89 
     90   virtual int32 RegisterDecodeCompleteCallback(
     91       webrtc::DecodedImageCallback*) {
     92     return WEBRTC_VIDEO_CODEC_OK;
     93   }
     94 
     95   virtual int32 Release() {
     96     return WEBRTC_VIDEO_CODEC_OK;
     97   }
     98 
     99   virtual int32 Reset() {
    100     return WEBRTC_VIDEO_CODEC_OK;
    101   }
    102 
    103   int GetNumFramesReceived() const {
    104     return num_frames_received_;
    105   }
    106 
    107  private:
    108   int num_frames_received_;
    109 };
    110 
    111 // Fake class for mocking out WebRtcVideoDecoderFactory.
    112 class FakeWebRtcVideoDecoderFactory : public WebRtcVideoDecoderFactory {
    113  public:
    114   FakeWebRtcVideoDecoderFactory()
    115       : num_created_decoders_(0) {
    116   }
    117 
    118   virtual webrtc::VideoDecoder* CreateVideoDecoder(
    119       webrtc::VideoCodecType type) {
    120     if (supported_codec_types_.count(type) == 0) {
    121       return NULL;
    122     }
    123     FakeWebRtcVideoDecoder* decoder = new FakeWebRtcVideoDecoder();
    124     decoders_.push_back(decoder);
    125     num_created_decoders_++;
    126     return decoder;
    127   }
    128 
    129   virtual void DestroyVideoDecoder(webrtc::VideoDecoder* decoder) {
    130     decoders_.erase(
    131         std::remove(decoders_.begin(), decoders_.end(), decoder),
    132         decoders_.end());
    133     delete decoder;
    134   }
    135 
    136   void AddSupportedVideoCodecType(webrtc::VideoCodecType type) {
    137     supported_codec_types_.insert(type);
    138   }
    139 
    140   int GetNumCreatedDecoders() {
    141     return num_created_decoders_;
    142   }
    143 
    144   const std::vector<FakeWebRtcVideoDecoder*>& decoders() {
    145     return decoders_;
    146   }
    147 
    148  private:
    149   std::set<webrtc::VideoCodecType> supported_codec_types_;
    150   std::vector<FakeWebRtcVideoDecoder*> decoders_;
    151   int num_created_decoders_;
    152 };
    153 
    154 // Fake class for mocking out webrtc::VideoEnoder
    155 class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder {
    156  public:
    157   FakeWebRtcVideoEncoder() {}
    158 
    159   virtual int32 InitEncode(const webrtc::VideoCodec* codecSettings,
    160                            int32 numberOfCores,
    161                            uint32 maxPayloadSize) {
    162     return WEBRTC_VIDEO_CODEC_OK;
    163   }
    164 
    165   virtual int32 Encode(
    166       const webrtc::I420VideoFrame& inputImage,
    167             const webrtc::CodecSpecificInfo* codecSpecificInfo,
    168             const std::vector<webrtc::VideoFrameType>* frame_types) {
    169     return WEBRTC_VIDEO_CODEC_OK;
    170   }
    171 
    172   virtual int32 RegisterEncodeCompleteCallback(
    173       webrtc::EncodedImageCallback* callback) {
    174     return WEBRTC_VIDEO_CODEC_OK;
    175   }
    176 
    177   virtual int32 Release() {
    178     return WEBRTC_VIDEO_CODEC_OK;
    179   }
    180 
    181   virtual int32 SetChannelParameters(uint32 packetLoss,
    182                                      int rtt) {
    183     return WEBRTC_VIDEO_CODEC_OK;
    184   }
    185 
    186   virtual int32 SetRates(uint32 newBitRate,
    187                          uint32 frameRate) {
    188     return WEBRTC_VIDEO_CODEC_OK;
    189   }
    190 };
    191 
    192 // Fake class for mocking out WebRtcVideoEncoderFactory.
    193 class FakeWebRtcVideoEncoderFactory : public WebRtcVideoEncoderFactory {
    194  public:
    195   FakeWebRtcVideoEncoderFactory()
    196       : num_created_encoders_(0) {
    197   }
    198 
    199   virtual webrtc::VideoEncoder* CreateVideoEncoder(
    200       webrtc::VideoCodecType type) {
    201     if (supported_codec_types_.count(type) == 0) {
    202       return NULL;
    203     }
    204     FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder();
    205     encoders_.push_back(encoder);
    206     num_created_encoders_++;
    207     return encoder;
    208   }
    209 
    210   virtual void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) {
    211     encoders_.erase(
    212         std::remove(encoders_.begin(), encoders_.end(), encoder),
    213         encoders_.end());
    214     delete encoder;
    215   }
    216 
    217   virtual void AddObserver(WebRtcVideoEncoderFactory::Observer* observer) {
    218     bool inserted = observers_.insert(observer).second;
    219     EXPECT_TRUE(inserted);
    220   }
    221 
    222   virtual void RemoveObserver(WebRtcVideoEncoderFactory::Observer* observer) {
    223     size_t erased = observers_.erase(observer);
    224     EXPECT_EQ(erased, 1UL);
    225   }
    226 
    227   virtual const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs()
    228       const {
    229     return codecs_;
    230   }
    231 
    232   void AddSupportedVideoCodecType(webrtc::VideoCodecType type,
    233                                   const std::string& name) {
    234     supported_codec_types_.insert(type);
    235     codecs_.push_back(
    236         WebRtcVideoEncoderFactory::VideoCodec(type, name, 1280, 720, 30));
    237   }
    238 
    239   void NotifyCodecsAvailable() {
    240     std::set<WebRtcVideoEncoderFactory::Observer*>::iterator it;
    241     for (it = observers_.begin(); it != observers_.end(); ++it)
    242       (*it)->OnCodecsAvailable();
    243   }
    244 
    245   int GetNumCreatedEncoders() {
    246     return num_created_encoders_;
    247   }
    248 
    249   const std::vector<FakeWebRtcVideoEncoder*>& encoders() {
    250     return encoders_;
    251   }
    252 
    253  private:
    254   std::set<webrtc::VideoCodecType> supported_codec_types_;
    255   std::vector<WebRtcVideoEncoderFactory::VideoCodec> codecs_;
    256   std::vector<FakeWebRtcVideoEncoder*> encoders_;
    257   std::set<WebRtcVideoEncoderFactory::Observer*> observers_;
    258   int num_created_encoders_;
    259 };
    260 
    261 class FakeWebRtcVideoEngine
    262     : public webrtc::ViEBase,
    263       public webrtc::ViECodec,
    264       public webrtc::ViECapture,
    265       public webrtc::ViENetwork,
    266       public webrtc::ViERender,
    267       public webrtc::ViERTP_RTCP,
    268       public webrtc::ViEImageProcess,
    269       public webrtc::ViEExternalCodec {
    270  public:
    271   struct Channel {
    272     Channel()
    273         : capture_id_(-1),
    274           original_channel_id_(-1),
    275           has_renderer_(false),
    276           render_started_(false),
    277           send(false),
    278           receive_(false),
    279           can_transmit_(true),
    280           remote_rtx_ssrc_(-1),
    281           rtx_send_payload_type(-1),
    282           rtcp_status_(webrtc::kRtcpNone),
    283           key_frame_request_method_(webrtc::kViEKeyFrameRequestNone),
    284           tmmbr_(false),
    285           remb_contribute_(false),
    286           remb_bw_partition_(false),
    287           rtp_offset_send_id_(0),
    288           rtp_offset_receive_id_(0),
    289           rtp_absolute_send_time_send_id_(0),
    290           rtp_absolute_send_time_receive_id_(0),
    291           sender_target_delay_(0),
    292           receiver_target_delay_(0),
    293           transmission_smoothing_(false),
    294           nack_(false),
    295           hybrid_nack_fec_(false),
    296           send_video_bitrate_(0),
    297           send_fec_bitrate_(0),
    298           send_nack_bitrate_(0),
    299           send_bandwidth_(0),
    300           receive_bandwidth_(0) {
    301       ssrcs_[0] = 0;  // default ssrc.
    302       memset(&send_codec, 0, sizeof(send_codec));
    303     }
    304     int capture_id_;
    305     int original_channel_id_;
    306     bool has_renderer_;
    307     bool render_started_;
    308     bool send;
    309     bool receive_;
    310     bool can_transmit_;
    311     std::map<int, int> ssrcs_;
    312     std::map<int, int> rtx_ssrcs_;
    313     int remote_rtx_ssrc_;
    314     int rtx_send_payload_type;
    315     std::string cname_;
    316     webrtc::ViERTCPMode rtcp_status_;
    317     webrtc::ViEKeyFrameRequestMethod key_frame_request_method_;
    318     bool tmmbr_;
    319     bool remb_contribute_;   // This channel contributes to the remb report.
    320     bool remb_bw_partition_; // This channel is allocated part of total bw.
    321     int rtp_offset_send_id_;
    322     int rtp_offset_receive_id_;
    323     int rtp_absolute_send_time_send_id_;
    324     int rtp_absolute_send_time_receive_id_;
    325     int sender_target_delay_;
    326     int receiver_target_delay_;
    327     bool transmission_smoothing_;
    328     bool nack_;
    329     bool hybrid_nack_fec_;
    330     std::vector<webrtc::VideoCodec> recv_codecs;
    331     std::set<unsigned int> ext_decoder_pl_types_;
    332     std::set<unsigned int> ext_encoder_pl_types_;
    333     webrtc::VideoCodec send_codec;
    334     unsigned int send_video_bitrate_;
    335     unsigned int send_fec_bitrate_;
    336     unsigned int send_nack_bitrate_;
    337     unsigned int send_bandwidth_;
    338     unsigned int receive_bandwidth_;
    339   };
    340   class Capturer : public webrtc::ViEExternalCapture {
    341    public:
    342     Capturer() : channel_id_(-1), denoising_(false),
    343                  last_capture_time_(0), incoming_frame_num_(0) { }
    344     int channel_id() const { return channel_id_; }
    345     void set_channel_id(int channel_id) { channel_id_ = channel_id; }
    346     bool denoising() const { return denoising_; }
    347     void set_denoising(bool denoising) { denoising_ = denoising; }
    348     int64 last_capture_time() const { return last_capture_time_; }
    349     int incoming_frame_num() const { return incoming_frame_num_; }
    350 
    351     // From ViEExternalCapture
    352     virtual int IncomingFrame(unsigned char* videoFrame,
    353                               unsigned int videoFrameLength,
    354                               unsigned short width,
    355                               unsigned short height,
    356                               webrtc::RawVideoType videoType,
    357                               unsigned long long captureTime) {
    358       return 0;
    359     }
    360     virtual int IncomingFrameI420(
    361         const webrtc::ViEVideoFrameI420& video_frame,
    362         unsigned long long captureTime) {
    363       last_capture_time_ = captureTime;
    364       ++incoming_frame_num_;
    365       return 0;
    366     }
    367 
    368    private:
    369     int channel_id_;
    370     bool denoising_;
    371     int64 last_capture_time_;
    372     int incoming_frame_num_;
    373   };
    374 
    375   FakeWebRtcVideoEngine(const cricket::VideoCodec* const* codecs,
    376                         int num_codecs)
    377       : inited_(false),
    378         last_channel_(kViEChannelIdBase - 1),
    379         fail_create_channel_(false),
    380         last_capturer_(kViECaptureIdBase - 1),
    381         fail_alloc_capturer_(false),
    382         codecs_(codecs),
    383         num_codecs_(num_codecs),
    384         num_set_send_codecs_(0) {
    385   }
    386 
    387   ~FakeWebRtcVideoEngine() {
    388     ASSERT(0 == channels_.size());
    389     ASSERT(0 == capturers_.size());
    390   }
    391   bool IsInited() const { return inited_; }
    392 
    393   int GetLastChannel() const { return last_channel_; }
    394   int GetChannelFromLocalSsrc(int local_ssrc) const {
    395     // ssrcs_[0] is the default local ssrc.
    396     for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
    397          iter != channels_.end(); ++iter) {
    398       if (local_ssrc == iter->second->ssrcs_[0]) {
    399         return iter->first;
    400       }
    401     }
    402     return -1;
    403   }
    404 
    405   int GetNumChannels() const { return static_cast<int>(channels_.size()); }
    406   bool IsChannel(int channel) const {
    407     return (channels_.find(channel) != channels_.end());
    408   }
    409   void set_fail_create_channel(bool fail_create_channel) {
    410     fail_create_channel_ = fail_create_channel;
    411   }
    412 
    413   int GetLastCapturer() const { return last_capturer_; }
    414   int GetNumCapturers() const { return static_cast<int>(capturers_.size()); }
    415   int GetIncomingFrameNum(int channel_id) const {
    416     for (std::map<int, Capturer*>::const_iterator iter = capturers_.begin();
    417          iter != capturers_.end(); ++iter) {
    418       Capturer* capturer = iter->second;
    419       if (capturer->channel_id() == channel_id) {
    420         return capturer->incoming_frame_num();
    421       }
    422     }
    423     return -1;
    424   }
    425   void set_fail_alloc_capturer(bool fail_alloc_capturer) {
    426     fail_alloc_capturer_ = fail_alloc_capturer;
    427   }
    428   int num_set_send_codecs() const { return num_set_send_codecs_; }
    429 
    430   int GetCaptureId(int channel) const {
    431     WEBRTC_ASSERT_CHANNEL(channel);
    432     return channels_.find(channel)->second->capture_id_;
    433   }
    434   int GetOriginalChannelId(int channel) const {
    435     WEBRTC_ASSERT_CHANNEL(channel);
    436     return channels_.find(channel)->second->original_channel_id_;
    437   }
    438   bool GetHasRenderer(int channel) const {
    439     WEBRTC_ASSERT_CHANNEL(channel);
    440     return channels_.find(channel)->second->has_renderer_;
    441   }
    442   bool GetRenderStarted(int channel) const {
    443     WEBRTC_ASSERT_CHANNEL(channel);
    444     return channels_.find(channel)->second->render_started_;
    445   }
    446   bool GetSend(int channel) const {
    447     WEBRTC_ASSERT_CHANNEL(channel);
    448     return channels_.find(channel)->second->send;
    449   }
    450   int GetCaptureChannelId(int capture_id) const {
    451     WEBRTC_ASSERT_CAPTURER(capture_id);
    452     return capturers_.find(capture_id)->second->channel_id();
    453   }
    454   bool GetCaptureDenoising(int capture_id) const {
    455     WEBRTC_ASSERT_CAPTURER(capture_id);
    456     return capturers_.find(capture_id)->second->denoising();
    457   }
    458   int64 GetCaptureLastTimestamp(int capture_id) const {
    459     WEBRTC_ASSERT_CAPTURER(capture_id);
    460     return capturers_.find(capture_id)->second->last_capture_time();
    461   }
    462   webrtc::ViERTCPMode GetRtcpStatus(int channel) const {
    463     WEBRTC_ASSERT_CHANNEL(channel);
    464     return channels_.find(channel)->second->rtcp_status_;
    465   }
    466   webrtc::ViEKeyFrameRequestMethod GetKeyFrameRequestMethod(int channel) const {
    467     WEBRTC_ASSERT_CHANNEL(channel);
    468     return channels_.find(channel)->second->key_frame_request_method_;
    469   }
    470   bool GetTmmbrStatus(int channel) const {
    471     WEBRTC_ASSERT_CHANNEL(channel);
    472     return channels_.find(channel)->second->tmmbr_;
    473   }
    474   bool GetRembStatusBwPartition(int channel) const {
    475     WEBRTC_ASSERT_CHANNEL(channel);
    476     return channels_.find(channel)->second->remb_bw_partition_;
    477   }
    478   bool GetRembStatusContribute(int channel) const {
    479     WEBRTC_ASSERT_CHANNEL(channel);
    480     return channels_.find(channel)->second->remb_contribute_;
    481   }
    482   int GetSendRtpTimestampOffsetExtensionId(int channel) {
    483     WEBRTC_ASSERT_CHANNEL(channel);
    484     return channels_.find(channel)->second->rtp_offset_send_id_;
    485   }
    486   int GetReceiveRtpTimestampOffsetExtensionId(int channel) {
    487     WEBRTC_ASSERT_CHANNEL(channel);
    488     return channels_.find(channel)->second->rtp_offset_receive_id_;
    489   }
    490   int GetSendAbsoluteSendTimeExtensionId(int channel) {
    491     WEBRTC_ASSERT_CHANNEL(channel);
    492     return channels_.find(channel)->second->rtp_absolute_send_time_send_id_;
    493   }
    494   int GetReceiveAbsoluteSendTimeExtensionId(int channel) {
    495     WEBRTC_ASSERT_CHANNEL(channel);
    496     return channels_.find(channel)->second->rtp_absolute_send_time_receive_id_;
    497   }
    498   bool GetTransmissionSmoothingStatus(int channel) {
    499     WEBRTC_ASSERT_CHANNEL(channel);
    500     return channels_.find(channel)->second->transmission_smoothing_;
    501   }
    502   int GetSenderTargetDelay(int channel) {
    503     WEBRTC_ASSERT_CHANNEL(channel);
    504     return channels_.find(channel)->second->sender_target_delay_;
    505   }
    506   int GetReceiverTargetDelay(int channel) {
    507     WEBRTC_ASSERT_CHANNEL(channel);
    508     return channels_.find(channel)->second->receiver_target_delay_;
    509   }
    510   bool GetNackStatus(int channel) const {
    511     WEBRTC_ASSERT_CHANNEL(channel);
    512     return channels_.find(channel)->second->nack_;
    513   }
    514   bool GetHybridNackFecStatus(int channel) const {
    515     WEBRTC_ASSERT_CHANNEL(channel);
    516     return channels_.find(channel)->second->hybrid_nack_fec_;
    517   }
    518   int GetNumSsrcs(int channel) const {
    519     WEBRTC_ASSERT_CHANNEL(channel);
    520     return static_cast<int>(
    521         channels_.find(channel)->second->ssrcs_.size());
    522   }
    523   int GetNumRtxSsrcs(int channel) const {
    524     WEBRTC_ASSERT_CHANNEL(channel);
    525     return static_cast<int>(
    526         channels_.find(channel)->second->rtx_ssrcs_.size());
    527   }
    528   bool GetIsTransmitting(int channel) const {
    529     WEBRTC_ASSERT_CHANNEL(channel);
    530     return channels_.find(channel)->second->can_transmit_;
    531   }
    532   int GetRtxSsrc(int channel, int simulcast_idx) const {
    533     WEBRTC_ASSERT_CHANNEL(channel);
    534     if (channels_.find(channel)->second->rtx_ssrcs_.find(simulcast_idx) ==
    535         channels_.find(channel)->second->rtx_ssrcs_.end()) {
    536       return -1;
    537     }
    538     return channels_.find(channel)->second->rtx_ssrcs_[simulcast_idx];
    539   }
    540   bool ReceiveCodecRegistered(int channel,
    541                               const webrtc::VideoCodec& codec) const {
    542     WEBRTC_ASSERT_CHANNEL(channel);
    543     const std::vector<webrtc::VideoCodec>& codecs =
    544       channels_.find(channel)->second->recv_codecs;
    545     return std::find(codecs.begin(), codecs.end(), codec) != codecs.end();
    546   };
    547   bool ExternalDecoderRegistered(int channel,
    548                                  unsigned int pl_type) const {
    549     WEBRTC_ASSERT_CHANNEL(channel);
    550     return channels_.find(channel)->second->
    551         ext_decoder_pl_types_.count(pl_type) != 0;
    552   };
    553   int GetNumExternalDecoderRegistered(int channel) const {
    554     WEBRTC_ASSERT_CHANNEL(channel);
    555     return static_cast<int>(
    556         channels_.find(channel)->second->ext_decoder_pl_types_.size());
    557   };
    558   bool ExternalEncoderRegistered(int channel,
    559                                  unsigned int pl_type) const {
    560     WEBRTC_ASSERT_CHANNEL(channel);
    561     return channels_.find(channel)->second->
    562         ext_encoder_pl_types_.count(pl_type) != 0;
    563   };
    564   int GetNumExternalEncoderRegistered(int channel) const {
    565     WEBRTC_ASSERT_CHANNEL(channel);
    566     return static_cast<int>(
    567         channels_.find(channel)->second->ext_encoder_pl_types_.size());
    568   };
    569   int GetTotalNumExternalEncoderRegistered() const {
    570     std::map<int, Channel*>::const_iterator it;
    571     int total_num_registered = 0;
    572     for (it = channels_.begin(); it != channels_.end(); ++it)
    573       total_num_registered +=
    574           static_cast<int>(it->second->ext_encoder_pl_types_.size());
    575     return total_num_registered;
    576   }
    577   void SetSendBitrates(int channel, unsigned int video_bitrate,
    578                        unsigned int fec_bitrate, unsigned int nack_bitrate) {
    579     WEBRTC_ASSERT_CHANNEL(channel);
    580     channels_[channel]->send_video_bitrate_ = video_bitrate;
    581     channels_[channel]->send_fec_bitrate_ = fec_bitrate;
    582     channels_[channel]->send_nack_bitrate_ = nack_bitrate;
    583   }
    584   void SetSendBandwidthEstimate(int channel, unsigned int send_bandwidth) {
    585     WEBRTC_ASSERT_CHANNEL(channel);
    586     channels_[channel]->send_bandwidth_ = send_bandwidth;
    587   }
    588   void SetReceiveBandwidthEstimate(int channel,
    589                                    unsigned int receive_bandwidth) {
    590     WEBRTC_ASSERT_CHANNEL(channel);
    591     channels_[channel]->receive_bandwidth_ = receive_bandwidth;
    592   };
    593   int GetRtxSendPayloadType(int channel) {
    594     WEBRTC_CHECK_CHANNEL(channel);
    595     return channels_[channel]->rtx_send_payload_type;
    596   }
    597   int GetRemoteRtxSsrc(int channel) {
    598     WEBRTC_CHECK_CHANNEL(channel);
    599     return channels_.find(channel)->second->remote_rtx_ssrc_;
    600   }
    601 
    602   WEBRTC_STUB(Release, ());
    603 
    604   // webrtc::ViEBase
    605   WEBRTC_FUNC(Init, ()) {
    606     inited_ = true;
    607     return 0;
    608   };
    609   WEBRTC_STUB(SetVoiceEngine, (webrtc::VoiceEngine*));
    610   WEBRTC_FUNC(CreateChannel, (int& channel)) {  // NOLINT
    611     if (fail_create_channel_) {
    612       return -1;
    613     }
    614     if (kViEChannelIdMax == last_channel_) {
    615       return -1;
    616     }
    617     Channel* ch = new Channel();
    618     channels_[++last_channel_] = ch;
    619     channel = last_channel_;
    620     return 0;
    621   };
    622   WEBRTC_FUNC(CreateChannel, (int& channel, int original_channel)) {
    623     WEBRTC_CHECK_CHANNEL(original_channel);
    624     if (CreateChannel(channel) != 0) {
    625       return -1;
    626     }
    627     channels_[channel]->original_channel_id_ = original_channel;
    628     return 0;
    629   }
    630   WEBRTC_FUNC(CreateReceiveChannel, (int& channel, int original_channel)) {
    631     return CreateChannel(channel, original_channel);
    632   }
    633   WEBRTC_FUNC(DeleteChannel, (const int channel)) {
    634     WEBRTC_CHECK_CHANNEL(channel);
    635     // Make sure we deregister all the decoders before deleting a channel.
    636     EXPECT_EQ(0, GetNumExternalDecoderRegistered(channel));
    637     delete channels_[channel];
    638     channels_.erase(channel);
    639     return 0;
    640   }
    641   WEBRTC_STUB(RegisterCpuOveruseObserver,
    642       (int channel, webrtc::CpuOveruseObserver* observer));
    643 #ifdef USE_WEBRTC_DEV_BRANCH
    644   WEBRTC_STUB(CpuOveruseMeasures, (int, int*, int*, int*, int*));
    645 #endif
    646   WEBRTC_STUB(ConnectAudioChannel, (const int, const int));
    647   WEBRTC_STUB(DisconnectAudioChannel, (const int));
    648   WEBRTC_FUNC(StartSend, (const int channel)) {
    649     WEBRTC_CHECK_CHANNEL(channel);
    650     channels_[channel]->send = true;
    651     return 0;
    652   }
    653   WEBRTC_FUNC(StopSend, (const int channel)) {
    654     WEBRTC_CHECK_CHANNEL(channel);
    655     channels_[channel]->send = false;
    656     return 0;
    657   }
    658   WEBRTC_FUNC(StartReceive, (const int channel)) {
    659     WEBRTC_CHECK_CHANNEL(channel);
    660     channels_[channel]->receive_ = true;
    661     return 0;
    662   }
    663   WEBRTC_FUNC(StopReceive, (const int channel)) {
    664     WEBRTC_CHECK_CHANNEL(channel);
    665     channels_[channel]->receive_ = false;
    666     return 0;
    667   }
    668   WEBRTC_STUB(GetVersion, (char version[1024]));
    669   WEBRTC_STUB(LastError, ());
    670 
    671   // webrtc::ViECodec
    672   WEBRTC_FUNC_CONST(NumberOfCodecs, ()) {
    673     return num_codecs_;
    674   };
    675   WEBRTC_FUNC_CONST(GetCodec, (const unsigned char list_number,
    676                                webrtc::VideoCodec& out_codec)) {
    677     if (list_number >= NumberOfCodecs()) {
    678       return -1;
    679     }
    680     memset(&out_codec, 0, sizeof(out_codec));
    681     const cricket::VideoCodec& c(*codecs_[list_number]);
    682     if ("I420" == c.name) {
    683       out_codec.codecType = webrtc::kVideoCodecI420;
    684     } else if ("VP8" == c.name) {
    685       out_codec.codecType = webrtc::kVideoCodecVP8;
    686     } else if ("red" == c.name) {
    687       out_codec.codecType = webrtc::kVideoCodecRED;
    688     } else if ("ulpfec" == c.name) {
    689       out_codec.codecType = webrtc::kVideoCodecULPFEC;
    690     } else {
    691       out_codec.codecType = webrtc::kVideoCodecUnknown;
    692     }
    693     talk_base::strcpyn(out_codec.plName, sizeof(out_codec.plName),
    694                        c.name.c_str());
    695     out_codec.plType = c.id;
    696     out_codec.width = c.width;
    697     out_codec.height = c.height;
    698     out_codec.startBitrate = kStartVideoBitrate;
    699     out_codec.maxBitrate = kMaxVideoBitrate;
    700     out_codec.minBitrate = kMinVideoBitrate;
    701     out_codec.maxFramerate = c.framerate;
    702     return 0;
    703   };
    704   WEBRTC_FUNC(SetSendCodec, (const int channel,
    705                              const webrtc::VideoCodec& codec)) {
    706     WEBRTC_CHECK_CHANNEL(channel);
    707     channels_[channel]->send_codec = codec;
    708     ++num_set_send_codecs_;
    709     return 0;
    710   };
    711   WEBRTC_FUNC_CONST(GetSendCodec, (const int channel,
    712                                    webrtc::VideoCodec& codec)) {  // NOLINT
    713     WEBRTC_CHECK_CHANNEL(channel);
    714     codec = channels_.find(channel)->second->send_codec;
    715     return 0;
    716   };
    717   WEBRTC_FUNC(SetReceiveCodec, (const int channel,
    718                                 const webrtc::VideoCodec& codec)) {  // NOLINT
    719     WEBRTC_CHECK_CHANNEL(channel);
    720     channels_[channel]->recv_codecs.push_back(codec);
    721     return 0;
    722   };
    723   WEBRTC_STUB_CONST(GetReceiveCodec, (const int, webrtc::VideoCodec&));
    724   WEBRTC_STUB_CONST(GetCodecConfigParameters, (const int,
    725       unsigned char*, unsigned char&));
    726   WEBRTC_STUB(SetImageScaleStatus, (const int, const bool));
    727   WEBRTC_STUB_CONST(GetSendCodecStastistics, (const int,
    728       unsigned int&, unsigned int&));
    729   WEBRTC_STUB_CONST(GetReceiveCodecStastistics, (const int,
    730       unsigned int&, unsigned int&));
    731   WEBRTC_STUB_CONST(GetReceiveSideDelay, (const int video_channel,
    732                                           int* delay_ms));
    733   WEBRTC_FUNC_CONST(GetCodecTargetBitrate, (const int channel,
    734       unsigned int* codec_target_bitrate)) {
    735     WEBRTC_CHECK_CHANNEL(channel);
    736 
    737     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
    738     if (it->second->send) {
    739       // Assume the encoder produces the expected rate.
    740       *codec_target_bitrate = it->second->send_video_bitrate_;
    741     } else {
    742       *codec_target_bitrate = 0;
    743     }
    744     return 0;
    745   }
    746   virtual unsigned int GetDiscardedPackets(const int channel) const {
    747     return 0;
    748   }
    749 
    750   WEBRTC_STUB(SetKeyFrameRequestCallbackStatus, (const int, const bool));
    751   WEBRTC_STUB(SetSignalKeyPacketLossStatus, (const int, const bool,
    752       const bool));
    753   WEBRTC_STUB(RegisterEncoderObserver, (const int,
    754       webrtc::ViEEncoderObserver&));
    755   WEBRTC_STUB(DeregisterEncoderObserver, (const int));
    756   WEBRTC_STUB(RegisterDecoderObserver, (const int,
    757       webrtc::ViEDecoderObserver&));
    758   WEBRTC_STUB(DeregisterDecoderObserver, (const int));
    759   WEBRTC_STUB(SendKeyFrame, (const int));
    760   WEBRTC_STUB(WaitForFirstKeyFrame, (const int, const bool));
    761   WEBRTC_STUB(StartDebugRecording, (int, const char*));
    762   WEBRTC_STUB(StopDebugRecording, (int));
    763   WEBRTC_VOID_STUB(SuspendBelowMinBitrate, (int));
    764 
    765   // webrtc::ViECapture
    766   WEBRTC_STUB(NumberOfCaptureDevices, ());
    767   WEBRTC_STUB(GetCaptureDevice, (unsigned int, char*,
    768       const unsigned int, char*, const unsigned int));
    769   WEBRTC_STUB(AllocateCaptureDevice, (const char*, const unsigned int, int&));
    770   WEBRTC_FUNC(AllocateExternalCaptureDevice,
    771               (int& capture_id, webrtc::ViEExternalCapture*& capture)) {
    772     if (fail_alloc_capturer_) {
    773       return -1;
    774     }
    775     if (kViECaptureIdMax == last_capturer_) {
    776       return -1;
    777     }
    778     Capturer* cap = new Capturer();
    779     capturers_[++last_capturer_] = cap;
    780     capture_id = last_capturer_;
    781     capture = cap;
    782     return 0;
    783   }
    784   WEBRTC_STUB(AllocateCaptureDevice, (webrtc::VideoCaptureModule&, int&));
    785   WEBRTC_FUNC(ReleaseCaptureDevice, (const int capture_id)) {
    786     WEBRTC_CHECK_CAPTURER(capture_id);
    787     delete capturers_[capture_id];
    788     capturers_.erase(capture_id);
    789     return 0;
    790   }
    791   WEBRTC_FUNC(ConnectCaptureDevice, (const int capture_id,
    792                                      const int channel)) {
    793     WEBRTC_CHECK_CHANNEL(channel);
    794     WEBRTC_CHECK_CAPTURER(capture_id);
    795     channels_[channel]->capture_id_ = capture_id;
    796     capturers_[capture_id]->set_channel_id(channel);
    797     return 0;
    798   }
    799   WEBRTC_FUNC(DisconnectCaptureDevice, (const int channel)) {
    800     WEBRTC_CHECK_CHANNEL(channel);
    801     int capture_id = channels_[channel]->capture_id_;
    802     WEBRTC_CHECK_CAPTURER(capture_id);
    803     channels_[channel]->capture_id_ = -1;
    804     capturers_[capture_id]->set_channel_id(-1);
    805     return 0;
    806   }
    807   WEBRTC_STUB(StartCapture, (const int, const webrtc::CaptureCapability&));
    808   WEBRTC_STUB(StopCapture, (const int));
    809   WEBRTC_STUB(SetRotateCapturedFrames, (const int,
    810       const webrtc::RotateCapturedFrame));
    811   WEBRTC_STUB(SetCaptureDelay, (const int, const unsigned int));
    812   WEBRTC_STUB(NumberOfCapabilities, (const char*, const unsigned int));
    813   WEBRTC_STUB(GetCaptureCapability, (const char*, const unsigned int,
    814       const unsigned int, webrtc::CaptureCapability&));
    815   WEBRTC_STUB(ShowCaptureSettingsDialogBox, (const char*, const unsigned int,
    816       const char*, void*, const unsigned int, const unsigned int));
    817   WEBRTC_STUB(GetOrientation, (const char*, webrtc::RotateCapturedFrame&));
    818   WEBRTC_STUB(EnableBrightnessAlarm, (const int, const bool));
    819   WEBRTC_STUB(RegisterObserver, (const int, webrtc::ViECaptureObserver&));
    820   WEBRTC_STUB(DeregisterObserver, (const int));
    821 
    822   // webrtc::ViENetwork
    823   WEBRTC_VOID_FUNC(SetNetworkTransmissionState, (const int channel,
    824                                                  const bool is_transmitting)) {
    825     WEBRTC_ASSERT_CHANNEL(channel);
    826     channels_[channel]->can_transmit_ = is_transmitting;
    827   }
    828   WEBRTC_STUB(RegisterSendTransport, (const int, webrtc::Transport&));
    829   WEBRTC_STUB(DeregisterSendTransport, (const int));
    830 #ifdef USE_WEBRTC_DEV_BRANCH
    831   WEBRTC_STUB(ReceivedRTPPacket, (const int, const void*, const int,
    832       const webrtc::PacketTime&));
    833 #else
    834   WEBRTC_STUB(ReceivedRTPPacket, (const int, const void*, const int));
    835 #endif
    836   WEBRTC_STUB(ReceivedRTCPPacket, (const int, const void*, const int));
    837   // Not using WEBRTC_STUB due to bool return value
    838   virtual bool IsIPv6Enabled(int channel) { return true; }
    839   WEBRTC_STUB(SetMTU, (int, unsigned int));
    840 
    841   // webrtc::ViERender
    842   WEBRTC_STUB(RegisterVideoRenderModule, (webrtc::VideoRender&));
    843   WEBRTC_STUB(DeRegisterVideoRenderModule, (webrtc::VideoRender&));
    844   WEBRTC_STUB(AddRenderer, (const int, void*, const unsigned int, const float,
    845       const float, const float, const float));
    846   WEBRTC_FUNC(RemoveRenderer, (const int render_id)) {
    847     if (IsCapturerId(render_id)) {
    848       WEBRTC_CHECK_CAPTURER(render_id);
    849       return 0;
    850     } else if (IsChannelId(render_id)) {
    851       WEBRTC_CHECK_CHANNEL(render_id);
    852       channels_[render_id]->has_renderer_ = false;
    853       return 0;
    854     }
    855     return -1;
    856   }
    857   WEBRTC_FUNC(StartRender, (const int render_id)) {
    858     if (IsCapturerId(render_id)) {
    859       WEBRTC_CHECK_CAPTURER(render_id);
    860       return 0;
    861     } else if (IsChannelId(render_id)) {
    862       WEBRTC_CHECK_CHANNEL(render_id);
    863       channels_[render_id]->render_started_ = true;
    864       return 0;
    865     }
    866     return -1;
    867   }
    868   WEBRTC_FUNC(StopRender, (const int render_id)) {
    869     if (IsCapturerId(render_id)) {
    870       WEBRTC_CHECK_CAPTURER(render_id);
    871       return 0;
    872     } else if (IsChannelId(render_id)) {
    873       WEBRTC_CHECK_CHANNEL(render_id);
    874       channels_[render_id]->render_started_ = false;
    875       return 0;
    876     }
    877     return -1;
    878   }
    879   WEBRTC_STUB(SetExpectedRenderDelay, (int render_id, int render_delay));
    880   WEBRTC_STUB(ConfigureRender, (int, const unsigned int, const float,
    881       const float, const float, const float));
    882   WEBRTC_STUB(MirrorRenderStream, (const int, const bool, const bool,
    883       const bool));
    884   WEBRTC_FUNC(AddRenderer, (const int render_id,
    885                             webrtc::RawVideoType video_type,
    886                             webrtc::ExternalRenderer* renderer)) {
    887     if (IsCapturerId(render_id)) {
    888       WEBRTC_CHECK_CAPTURER(render_id);
    889       return 0;
    890     } else if (IsChannelId(render_id)) {
    891       WEBRTC_CHECK_CHANNEL(render_id);
    892       channels_[render_id]->has_renderer_ = true;
    893       return 0;
    894     }
    895     return -1;
    896   }
    897 
    898   // webrtc::ViERTP_RTCP
    899   WEBRTC_FUNC(SetLocalSSRC, (const int channel,
    900                              const unsigned int ssrc,
    901                              const webrtc::StreamType usage,
    902                              const unsigned char idx)) {
    903     WEBRTC_CHECK_CHANNEL(channel);
    904     switch (usage) {
    905       case webrtc::kViEStreamTypeNormal:
    906         channels_[channel]->ssrcs_[idx] = ssrc;
    907         break;
    908       case webrtc::kViEStreamTypeRtx:
    909         channels_[channel]->rtx_ssrcs_[idx] = ssrc;
    910         break;
    911       default:
    912         return -1;
    913     }
    914     return 0;
    915   }
    916 
    917   WEBRTC_FUNC_CONST(SetRemoteSSRCType, (const int channel,
    918         const webrtc::StreamType usage, const unsigned int ssrc)) {
    919     WEBRTC_CHECK_CHANNEL(channel);
    920     if (usage == webrtc::kViEStreamTypeRtx) {
    921       channels_.find(channel)->second->remote_rtx_ssrc_ = ssrc;
    922       return 0;
    923     }
    924     return -1;
    925   }
    926 
    927   WEBRTC_FUNC_CONST(GetLocalSSRC, (const int channel,
    928                                    unsigned int& ssrc)) {
    929     // ssrcs_[0] is the default local ssrc.
    930     WEBRTC_CHECK_CHANNEL(channel);
    931     ssrc = channels_.find(channel)->second->ssrcs_[0];
    932     return 0;
    933   }
    934   WEBRTC_STUB_CONST(GetRemoteSSRC, (const int, unsigned int&));
    935   WEBRTC_STUB_CONST(GetRemoteCSRCs, (const int, unsigned int*));
    936 
    937   WEBRTC_FUNC(SetRtxSendPayloadType, (const int channel,
    938                                       const uint8 payload_type)) {
    939     WEBRTC_CHECK_CHANNEL(channel);
    940     channels_[channel]->rtx_send_payload_type = payload_type;
    941     return 0;
    942   }
    943   WEBRTC_STUB(SetRtxReceivePayloadType, (const int, const uint8));
    944 
    945   WEBRTC_STUB(SetStartSequenceNumber, (const int, unsigned short));
    946   WEBRTC_FUNC(SetRTCPStatus,
    947               (const int channel, const webrtc::ViERTCPMode mode)) {
    948     WEBRTC_CHECK_CHANNEL(channel);
    949     channels_[channel]->rtcp_status_ = mode;
    950     return 0;
    951   }
    952   WEBRTC_STUB_CONST(GetRTCPStatus, (const int, webrtc::ViERTCPMode&));
    953   WEBRTC_FUNC(SetRTCPCName, (const int channel,
    954                              const char rtcp_cname[KMaxRTCPCNameLength])) {
    955     WEBRTC_CHECK_CHANNEL(channel);
    956     channels_[channel]->cname_.assign(rtcp_cname);
    957     return 0;
    958   }
    959   WEBRTC_FUNC_CONST(GetRTCPCName, (const int channel,
    960                                    char rtcp_cname[KMaxRTCPCNameLength])) {
    961     WEBRTC_CHECK_CHANNEL(channel);
    962     talk_base::strcpyn(rtcp_cname, KMaxRTCPCNameLength,
    963                        channels_.find(channel)->second->cname_.c_str());
    964     return 0;
    965   }
    966   WEBRTC_STUB_CONST(GetRemoteRTCPCName, (const int, char*));
    967   WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (const int, const unsigned char,
    968       unsigned int, const char*, unsigned short));
    969   WEBRTC_FUNC(SetNACKStatus, (const int channel, const bool enable)) {
    970     WEBRTC_CHECK_CHANNEL(channel);
    971     channels_[channel]->nack_ = enable;
    972     channels_[channel]->hybrid_nack_fec_ = false;
    973     return 0;
    974   }
    975   WEBRTC_STUB(SetFECStatus, (const int, const bool, const unsigned char,
    976       const unsigned char));
    977   WEBRTC_FUNC(SetHybridNACKFECStatus, (const int channel, const bool enable,
    978       const unsigned char red_type, const unsigned char fec_type)) {
    979     WEBRTC_CHECK_CHANNEL(channel);
    980     if (red_type == fec_type ||
    981         red_type == channels_[channel]->send_codec.plType ||
    982         fec_type == channels_[channel]->send_codec.plType) {
    983       return -1;
    984     }
    985     channels_[channel]->nack_ = false;
    986     channels_[channel]->hybrid_nack_fec_ = enable;
    987     return 0;
    988   }
    989   WEBRTC_FUNC(SetKeyFrameRequestMethod,
    990               (const int channel,
    991                const webrtc::ViEKeyFrameRequestMethod method)) {
    992     WEBRTC_CHECK_CHANNEL(channel);
    993     channels_[channel]->key_frame_request_method_ = method;
    994     return 0;
    995   }
    996   WEBRTC_FUNC(SetSenderBufferingMode, (int channel, int target_delay)) {
    997     WEBRTC_CHECK_CHANNEL(channel);
    998     channels_[channel]->sender_target_delay_ = target_delay;
    999     return 0;
   1000   }
   1001   WEBRTC_FUNC(SetReceiverBufferingMode, (int channel, int target_delay)) {
   1002     WEBRTC_CHECK_CHANNEL(channel);
   1003     channels_[channel]->receiver_target_delay_ = target_delay;
   1004     return 0;
   1005   }
   1006   // |Send| and |receive| are stored locally in variables that more clearly
   1007   // explain what they mean.
   1008   WEBRTC_FUNC(SetRembStatus, (int channel, bool send, bool receive)) {
   1009     WEBRTC_CHECK_CHANNEL(channel);
   1010     channels_[channel]->remb_contribute_ = receive;
   1011     channels_[channel]->remb_bw_partition_ = send;
   1012     return 0;
   1013   }
   1014   WEBRTC_FUNC(SetTMMBRStatus, (const int channel, const bool enable)) {
   1015     WEBRTC_CHECK_CHANNEL(channel);
   1016     channels_[channel]->tmmbr_ = enable;
   1017     return 0;
   1018   }
   1019   WEBRTC_FUNC(SetSendTimestampOffsetStatus, (int channel, bool enable,
   1020       int id)) {
   1021     WEBRTC_CHECK_CHANNEL(channel);
   1022     channels_[channel]->rtp_offset_send_id_ = (enable) ? id : 0;
   1023     return 0;
   1024   }
   1025   WEBRTC_FUNC(SetReceiveTimestampOffsetStatus, (int channel, bool enable,
   1026       int id)) {
   1027     WEBRTC_CHECK_CHANNEL(channel);
   1028     channels_[channel]->rtp_offset_receive_id_ = (enable) ? id : 0;
   1029     return 0;
   1030   }
   1031   WEBRTC_FUNC(SetSendAbsoluteSendTimeStatus, (int channel, bool enable,
   1032       int id)) {
   1033     WEBRTC_CHECK_CHANNEL(channel);
   1034     channels_[channel]->rtp_absolute_send_time_send_id_ = (enable) ? id : 0;
   1035     return 0;
   1036   }
   1037   WEBRTC_FUNC(SetReceiveAbsoluteSendTimeStatus, (int channel, bool enable,
   1038       int id)) {
   1039     WEBRTC_CHECK_CHANNEL(channel);
   1040     channels_[channel]->rtp_absolute_send_time_receive_id_ = (enable) ? id : 0;
   1041     return 0;
   1042   }
   1043 #ifdef USE_WEBRTC_DEV_BRANCH
   1044   WEBRTC_STUB(SetRtcpXrRrtrStatus, (int, bool));
   1045 #endif
   1046   WEBRTC_FUNC(SetTransmissionSmoothingStatus, (int channel, bool enable)) {
   1047     WEBRTC_CHECK_CHANNEL(channel);
   1048     channels_[channel]->transmission_smoothing_ = enable;
   1049     return 0;
   1050   }
   1051   WEBRTC_STUB_CONST(GetReceivedRTCPStatistics, (const int, unsigned short&,
   1052       unsigned int&, unsigned int&, unsigned int&, int&));
   1053   WEBRTC_STUB_CONST(GetSentRTCPStatistics, (const int, unsigned short&,
   1054       unsigned int&, unsigned int&, unsigned int&, int&));
   1055   WEBRTC_STUB_CONST(GetRTPStatistics, (const int, unsigned int&, unsigned int&,
   1056       unsigned int&, unsigned int&));
   1057   WEBRTC_STUB_CONST(GetReceiveChannelRtcpStatistics, (const int,
   1058       webrtc::RtcpStatistics&, int&));
   1059   WEBRTC_STUB_CONST(GetSendChannelRtcpStatistics, (const int,
   1060       webrtc::RtcpStatistics&, int&));
   1061   WEBRTC_STUB_CONST(GetRtpStatistics, (const int, webrtc::StreamDataCounters&,
   1062       webrtc::StreamDataCounters&));
   1063   WEBRTC_FUNC_CONST(GetBandwidthUsage, (const int channel,
   1064       unsigned int& total_bitrate, unsigned int& video_bitrate,
   1065       unsigned int& fec_bitrate, unsigned int& nack_bitrate)) {
   1066     WEBRTC_CHECK_CHANNEL(channel);
   1067     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
   1068     if (it->second->send) {
   1069       video_bitrate = it->second->send_video_bitrate_;
   1070       fec_bitrate = it->second->send_fec_bitrate_;
   1071       nack_bitrate = it->second->send_nack_bitrate_;
   1072       total_bitrate = video_bitrate + fec_bitrate + nack_bitrate;
   1073     } else {
   1074       total_bitrate = 0;
   1075       video_bitrate = 0;
   1076       fec_bitrate = 0;
   1077       nack_bitrate = 0;
   1078     }
   1079     return 0;
   1080   }
   1081   WEBRTC_FUNC_CONST(GetEstimatedSendBandwidth, (const int channel,
   1082       unsigned int* send_bandwidth_estimate)) {
   1083     WEBRTC_CHECK_CHANNEL(channel);
   1084     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
   1085     // Assume the current video, fec and nack bitrate sums up to our estimate.
   1086     if (it->second->send) {
   1087       *send_bandwidth_estimate = it->second->send_bandwidth_;
   1088     } else {
   1089       *send_bandwidth_estimate = 0;
   1090     }
   1091     return 0;
   1092   }
   1093   WEBRTC_FUNC_CONST(GetEstimatedReceiveBandwidth, (const int channel,
   1094       unsigned int* receive_bandwidth_estimate)) {
   1095     WEBRTC_CHECK_CHANNEL(channel);
   1096     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
   1097     if (it->second->receive_) {
   1098     // For simplicity, assume all channels receive half of max send rate.
   1099       *receive_bandwidth_estimate = it->second->receive_bandwidth_;
   1100     } else {
   1101       *receive_bandwidth_estimate = 0;
   1102     }
   1103     return 0;
   1104   }
   1105   WEBRTC_STUB(RegisterSendChannelRtcpStatisticsCallback,
   1106                     (int, webrtc::RtcpStatisticsCallback*));
   1107   WEBRTC_STUB(DeregisterSendChannelRtcpStatisticsCallback,
   1108                     (int, webrtc::RtcpStatisticsCallback*));
   1109   WEBRTC_STUB(RegisterReceiveChannelRtcpStatisticsCallback,
   1110                     (int, webrtc::RtcpStatisticsCallback*));
   1111   WEBRTC_STUB(DeregisterReceiveChannelRtcpStatisticsCallback,
   1112                     (int, webrtc::RtcpStatisticsCallback*));
   1113   WEBRTC_STUB(RegisterSendChannelRtpStatisticsCallback,
   1114                     (int, webrtc::StreamDataCountersCallback*));
   1115   WEBRTC_STUB(DeregisterSendChannelRtpStatisticsCallback,
   1116                     (int, webrtc::StreamDataCountersCallback*));
   1117   WEBRTC_STUB(RegisterReceiveChannelRtpStatisticsCallback,
   1118                     (int, webrtc::StreamDataCountersCallback*));
   1119   WEBRTC_STUB(DeregisterReceiveChannelRtpStatisticsCallback,
   1120                     (int, webrtc::StreamDataCountersCallback*));
   1121   WEBRTC_STUB(RegisterSendBitrateObserver,
   1122                     (int, webrtc::BitrateStatisticsObserver*));
   1123   WEBRTC_STUB(DeregisterSendBitrateObserver,
   1124                     (int, webrtc::BitrateStatisticsObserver*));
   1125   WEBRTC_STUB(RegisterSendFrameCountObserver,
   1126                     (int, webrtc::FrameCountObserver*));
   1127   WEBRTC_STUB(DeregisterSendFrameCountObserver,
   1128                     (int, webrtc::FrameCountObserver*));
   1129 
   1130   WEBRTC_STUB(StartRTPDump, (const int, const char*, webrtc::RTPDirections));
   1131   WEBRTC_STUB(StopRTPDump, (const int, webrtc::RTPDirections));
   1132   WEBRTC_STUB(RegisterRTPObserver, (const int, webrtc::ViERTPObserver&));
   1133   WEBRTC_STUB(DeregisterRTPObserver, (const int));
   1134   WEBRTC_STUB(RegisterRTCPObserver, (const int, webrtc::ViERTCPObserver&));
   1135   WEBRTC_STUB(DeregisterRTCPObserver, (const int));
   1136 
   1137   // webrtc::ViEImageProcess
   1138   WEBRTC_STUB(RegisterCaptureEffectFilter, (const int,
   1139       webrtc::ViEEffectFilter&));
   1140   WEBRTC_STUB(DeregisterCaptureEffectFilter, (const int));
   1141   WEBRTC_STUB(RegisterSendEffectFilter, (const int,
   1142       webrtc::ViEEffectFilter&));
   1143   WEBRTC_STUB(DeregisterSendEffectFilter, (const int));
   1144   WEBRTC_STUB(RegisterRenderEffectFilter, (const int,
   1145       webrtc::ViEEffectFilter&));
   1146   WEBRTC_STUB(DeregisterRenderEffectFilter, (const int));
   1147   WEBRTC_STUB(EnableDeflickering, (const int, const bool));
   1148   WEBRTC_FUNC(EnableDenoising, (const int capture_id, const bool denoising)) {
   1149     WEBRTC_CHECK_CAPTURER(capture_id);
   1150     capturers_[capture_id]->set_denoising(denoising);
   1151     return 0;
   1152   }
   1153   WEBRTC_STUB(EnableColorEnhancement, (const int, const bool));
   1154   WEBRTC_VOID_STUB(RegisterPreEncodeCallback,
   1155                    (int, webrtc::I420FrameCallback*));
   1156   WEBRTC_VOID_STUB(DeRegisterPreEncodeCallback, (int));
   1157   WEBRTC_VOID_STUB(RegisterPreRenderCallback,
   1158                    (int, webrtc::I420FrameCallback*));
   1159   WEBRTC_VOID_STUB(DeRegisterPreRenderCallback, (int));
   1160   // webrtc::ViEExternalCodec
   1161   WEBRTC_FUNC(RegisterExternalSendCodec,
   1162       (const int channel, const unsigned char pl_type, webrtc::VideoEncoder*,
   1163           bool)) {
   1164     WEBRTC_CHECK_CHANNEL(channel);
   1165     channels_[channel]->ext_encoder_pl_types_.insert(pl_type);
   1166     return 0;
   1167   }
   1168   WEBRTC_FUNC(DeRegisterExternalSendCodec,
   1169       (const int channel, const unsigned char pl_type)) {
   1170     WEBRTC_CHECK_CHANNEL(channel);
   1171     channels_[channel]->ext_encoder_pl_types_.erase(pl_type);
   1172     return 0;
   1173   }
   1174   WEBRTC_FUNC(RegisterExternalReceiveCodec,
   1175       (const int channel, const unsigned int pl_type, webrtc::VideoDecoder*,
   1176        bool, int)) {
   1177     WEBRTC_CHECK_CHANNEL(channel);
   1178     channels_[channel]->ext_decoder_pl_types_.insert(pl_type);
   1179     return 0;
   1180   }
   1181   WEBRTC_FUNC(DeRegisterExternalReceiveCodec,
   1182       (const int channel, const unsigned char pl_type)) {
   1183     WEBRTC_CHECK_CHANNEL(channel);
   1184     channels_[channel]->ext_decoder_pl_types_.erase(pl_type);
   1185     return 0;
   1186   }
   1187 
   1188  private:
   1189   bool IsChannelId(int id) const {
   1190     return (id >= kViEChannelIdBase && id <= kViEChannelIdMax);
   1191   }
   1192   bool IsCapturerId(int id) const {
   1193     return (id >= kViECaptureIdBase && id <= kViECaptureIdMax);
   1194   }
   1195 
   1196   bool inited_;
   1197   int last_channel_;
   1198   std::map<int, Channel*> channels_;
   1199   bool fail_create_channel_;
   1200   int last_capturer_;
   1201   std::map<int, Capturer*> capturers_;
   1202   bool fail_alloc_capturer_;
   1203   const cricket::VideoCodec* const* codecs_;
   1204   int num_codecs_;
   1205   int num_set_send_codecs_;  // how many times we call SetSendCodec().
   1206 };
   1207 
   1208 }  // namespace cricket
   1209 
   1210 #endif  // TALK_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_
   1211