Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / media / webrtc / fakewebrtcvideoengine.h
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   WEBRTC_STUB(CpuOveruseMeasures, (int, int*, int*, int*, int*));
644   WEBRTC_STUB(ConnectAudioChannel, (const int, const int));
645   WEBRTC_STUB(DisconnectAudioChannel, (const int));
646   WEBRTC_FUNC(StartSend, (const int channel)) {
647     WEBRTC_CHECK_CHANNEL(channel);
648     channels_[channel]->send = true;
649     return 0;
650   }
651   WEBRTC_FUNC(StopSend, (const int channel)) {
652     WEBRTC_CHECK_CHANNEL(channel);
653     channels_[channel]->send = false;
654     return 0;
655   }
656   WEBRTC_FUNC(StartReceive, (const int channel)) {
657     WEBRTC_CHECK_CHANNEL(channel);
658     channels_[channel]->receive_ = true;
659     return 0;
660   }
661   WEBRTC_FUNC(StopReceive, (const int channel)) {
662     WEBRTC_CHECK_CHANNEL(channel);
663     channels_[channel]->receive_ = false;
664     return 0;
665   }
666   WEBRTC_STUB(GetVersion, (char version[1024]));
667   WEBRTC_STUB(LastError, ());
668
669   // webrtc::ViECodec
670   WEBRTC_FUNC_CONST(NumberOfCodecs, ()) {
671     return num_codecs_;
672   };
673   WEBRTC_FUNC_CONST(GetCodec, (const unsigned char list_number,
674                                webrtc::VideoCodec& out_codec)) {
675     if (list_number >= NumberOfCodecs()) {
676       return -1;
677     }
678     memset(&out_codec, 0, sizeof(out_codec));
679     const cricket::VideoCodec& c(*codecs_[list_number]);
680     if ("I420" == c.name) {
681       out_codec.codecType = webrtc::kVideoCodecI420;
682     } else if ("VP8" == c.name) {
683       out_codec.codecType = webrtc::kVideoCodecVP8;
684     } else if ("red" == c.name) {
685       out_codec.codecType = webrtc::kVideoCodecRED;
686     } else if ("ulpfec" == c.name) {
687       out_codec.codecType = webrtc::kVideoCodecULPFEC;
688     } else {
689       out_codec.codecType = webrtc::kVideoCodecUnknown;
690     }
691     talk_base::strcpyn(out_codec.plName, sizeof(out_codec.plName),
692                        c.name.c_str());
693     out_codec.plType = c.id;
694     out_codec.width = c.width;
695     out_codec.height = c.height;
696     out_codec.startBitrate = kStartVideoBitrate;
697     out_codec.maxBitrate = kMaxVideoBitrate;
698     out_codec.minBitrate = kMinVideoBitrate;
699     out_codec.maxFramerate = c.framerate;
700     return 0;
701   };
702   WEBRTC_FUNC(SetSendCodec, (const int channel,
703                              const webrtc::VideoCodec& codec)) {
704     WEBRTC_CHECK_CHANNEL(channel);
705     channels_[channel]->send_codec = codec;
706     ++num_set_send_codecs_;
707     return 0;
708   };
709   WEBRTC_FUNC_CONST(GetSendCodec, (const int channel,
710                                    webrtc::VideoCodec& codec)) {  // NOLINT
711     WEBRTC_CHECK_CHANNEL(channel);
712     codec = channels_.find(channel)->second->send_codec;
713     return 0;
714   };
715   WEBRTC_FUNC(SetReceiveCodec, (const int channel,
716                                 const webrtc::VideoCodec& codec)) {  // NOLINT
717     WEBRTC_CHECK_CHANNEL(channel);
718     channels_[channel]->recv_codecs.push_back(codec);
719     return 0;
720   };
721   WEBRTC_STUB_CONST(GetReceiveCodec, (const int, webrtc::VideoCodec&));
722   WEBRTC_STUB_CONST(GetCodecConfigParameters, (const int,
723       unsigned char*, unsigned char&));
724   WEBRTC_STUB(SetImageScaleStatus, (const int, const bool));
725   WEBRTC_STUB_CONST(GetSendCodecStastistics, (const int,
726       unsigned int&, unsigned int&));
727   WEBRTC_STUB_CONST(GetReceiveCodecStastistics, (const int,
728       unsigned int&, unsigned int&));
729   WEBRTC_STUB_CONST(GetReceiveSideDelay, (const int video_channel,
730                                           int* delay_ms));
731   WEBRTC_FUNC_CONST(GetCodecTargetBitrate, (const int channel,
732       unsigned int* codec_target_bitrate)) {
733     WEBRTC_CHECK_CHANNEL(channel);
734
735     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
736     if (it->second->send) {
737       // Assume the encoder produces the expected rate.
738       *codec_target_bitrate = it->second->send_video_bitrate_;
739     } else {
740       *codec_target_bitrate = 0;
741     }
742     return 0;
743   }
744   virtual unsigned int GetDiscardedPackets(const int channel) const {
745     return 0;
746   }
747
748   WEBRTC_STUB(SetKeyFrameRequestCallbackStatus, (const int, const bool));
749   WEBRTC_STUB(SetSignalKeyPacketLossStatus, (const int, const bool,
750       const bool));
751   WEBRTC_STUB(RegisterEncoderObserver, (const int,
752       webrtc::ViEEncoderObserver&));
753   WEBRTC_STUB(DeregisterEncoderObserver, (const int));
754   WEBRTC_STUB(RegisterDecoderObserver, (const int,
755       webrtc::ViEDecoderObserver&));
756   WEBRTC_STUB(DeregisterDecoderObserver, (const int));
757   WEBRTC_STUB(SendKeyFrame, (const int));
758   WEBRTC_STUB(WaitForFirstKeyFrame, (const int, const bool));
759   WEBRTC_STUB(StartDebugRecording, (int, const char*));
760   WEBRTC_STUB(StopDebugRecording, (int));
761   WEBRTC_VOID_STUB(SuspendBelowMinBitrate, (int));
762
763   // webrtc::ViECapture
764   WEBRTC_STUB(NumberOfCaptureDevices, ());
765   WEBRTC_STUB(GetCaptureDevice, (unsigned int, char*,
766       const unsigned int, char*, const unsigned int));
767   WEBRTC_STUB(AllocateCaptureDevice, (const char*, const unsigned int, int&));
768   WEBRTC_FUNC(AllocateExternalCaptureDevice,
769               (int& capture_id, webrtc::ViEExternalCapture*& capture)) {
770     if (fail_alloc_capturer_) {
771       return -1;
772     }
773     if (kViECaptureIdMax == last_capturer_) {
774       return -1;
775     }
776     Capturer* cap = new Capturer();
777     capturers_[++last_capturer_] = cap;
778     capture_id = last_capturer_;
779     capture = cap;
780     return 0;
781   }
782   WEBRTC_STUB(AllocateCaptureDevice, (webrtc::VideoCaptureModule&, int&));
783   WEBRTC_FUNC(ReleaseCaptureDevice, (const int capture_id)) {
784     WEBRTC_CHECK_CAPTURER(capture_id);
785     delete capturers_[capture_id];
786     capturers_.erase(capture_id);
787     return 0;
788   }
789   WEBRTC_FUNC(ConnectCaptureDevice, (const int capture_id,
790                                      const int channel)) {
791     WEBRTC_CHECK_CHANNEL(channel);
792     WEBRTC_CHECK_CAPTURER(capture_id);
793     channels_[channel]->capture_id_ = capture_id;
794     capturers_[capture_id]->set_channel_id(channel);
795     return 0;
796   }
797   WEBRTC_FUNC(DisconnectCaptureDevice, (const int channel)) {
798     WEBRTC_CHECK_CHANNEL(channel);
799     int capture_id = channels_[channel]->capture_id_;
800     WEBRTC_CHECK_CAPTURER(capture_id);
801     channels_[channel]->capture_id_ = -1;
802     capturers_[capture_id]->set_channel_id(-1);
803     return 0;
804   }
805   WEBRTC_STUB(StartCapture, (const int, const webrtc::CaptureCapability&));
806   WEBRTC_STUB(StopCapture, (const int));
807   WEBRTC_STUB(SetRotateCapturedFrames, (const int,
808       const webrtc::RotateCapturedFrame));
809   WEBRTC_STUB(SetCaptureDelay, (const int, const unsigned int));
810   WEBRTC_STUB(NumberOfCapabilities, (const char*, const unsigned int));
811   WEBRTC_STUB(GetCaptureCapability, (const char*, const unsigned int,
812       const unsigned int, webrtc::CaptureCapability&));
813   WEBRTC_STUB(ShowCaptureSettingsDialogBox, (const char*, const unsigned int,
814       const char*, void*, const unsigned int, const unsigned int));
815   WEBRTC_STUB(GetOrientation, (const char*, webrtc::RotateCapturedFrame&));
816   WEBRTC_STUB(EnableBrightnessAlarm, (const int, const bool));
817   WEBRTC_STUB(RegisterObserver, (const int, webrtc::ViECaptureObserver&));
818   WEBRTC_STUB(DeregisterObserver, (const int));
819
820   // webrtc::ViENetwork
821   WEBRTC_VOID_FUNC(SetNetworkTransmissionState, (const int channel,
822                                                  const bool is_transmitting)) {
823     WEBRTC_ASSERT_CHANNEL(channel);
824     channels_[channel]->can_transmit_ = is_transmitting;
825   }
826   WEBRTC_STUB(RegisterSendTransport, (const int, webrtc::Transport&));
827   WEBRTC_STUB(DeregisterSendTransport, (const int));
828   WEBRTC_STUB(ReceivedRTPPacket, (const int, const void*, const int,
829       const webrtc::PacketTime&));
830   WEBRTC_STUB(ReceivedRTCPPacket, (const int, const void*, const int));
831   // Not using WEBRTC_STUB due to bool return value
832   virtual bool IsIPv6Enabled(int channel) { return true; }
833   WEBRTC_STUB(SetMTU, (int, unsigned int));
834
835   // webrtc::ViERender
836   WEBRTC_STUB(RegisterVideoRenderModule, (webrtc::VideoRender&));
837   WEBRTC_STUB(DeRegisterVideoRenderModule, (webrtc::VideoRender&));
838   WEBRTC_STUB(AddRenderer, (const int, void*, const unsigned int, const float,
839       const float, const float, const float));
840   WEBRTC_FUNC(RemoveRenderer, (const int render_id)) {
841     if (IsCapturerId(render_id)) {
842       WEBRTC_CHECK_CAPTURER(render_id);
843       return 0;
844     } else if (IsChannelId(render_id)) {
845       WEBRTC_CHECK_CHANNEL(render_id);
846       channels_[render_id]->has_renderer_ = false;
847       return 0;
848     }
849     return -1;
850   }
851   WEBRTC_FUNC(StartRender, (const int render_id)) {
852     if (IsCapturerId(render_id)) {
853       WEBRTC_CHECK_CAPTURER(render_id);
854       return 0;
855     } else if (IsChannelId(render_id)) {
856       WEBRTC_CHECK_CHANNEL(render_id);
857       channels_[render_id]->render_started_ = true;
858       return 0;
859     }
860     return -1;
861   }
862   WEBRTC_FUNC(StopRender, (const int render_id)) {
863     if (IsCapturerId(render_id)) {
864       WEBRTC_CHECK_CAPTURER(render_id);
865       return 0;
866     } else if (IsChannelId(render_id)) {
867       WEBRTC_CHECK_CHANNEL(render_id);
868       channels_[render_id]->render_started_ = false;
869       return 0;
870     }
871     return -1;
872   }
873   WEBRTC_STUB(SetExpectedRenderDelay, (int render_id, int render_delay));
874   WEBRTC_STUB(ConfigureRender, (int, const unsigned int, const float,
875       const float, const float, const float));
876   WEBRTC_STUB(MirrorRenderStream, (const int, const bool, const bool,
877       const bool));
878   WEBRTC_FUNC(AddRenderer, (const int render_id,
879                             webrtc::RawVideoType video_type,
880                             webrtc::ExternalRenderer* renderer)) {
881     if (IsCapturerId(render_id)) {
882       WEBRTC_CHECK_CAPTURER(render_id);
883       return 0;
884     } else if (IsChannelId(render_id)) {
885       WEBRTC_CHECK_CHANNEL(render_id);
886       channels_[render_id]->has_renderer_ = true;
887       return 0;
888     }
889     return -1;
890   }
891
892   // webrtc::ViERTP_RTCP
893   WEBRTC_FUNC(SetLocalSSRC, (const int channel,
894                              const unsigned int ssrc,
895                              const webrtc::StreamType usage,
896                              const unsigned char idx)) {
897     WEBRTC_CHECK_CHANNEL(channel);
898     switch (usage) {
899       case webrtc::kViEStreamTypeNormal:
900         channels_[channel]->ssrcs_[idx] = ssrc;
901         break;
902       case webrtc::kViEStreamTypeRtx:
903         channels_[channel]->rtx_ssrcs_[idx] = ssrc;
904         break;
905       default:
906         return -1;
907     }
908     return 0;
909   }
910
911   WEBRTC_FUNC_CONST(SetRemoteSSRCType, (const int channel,
912         const webrtc::StreamType usage, const unsigned int ssrc)) {
913     WEBRTC_CHECK_CHANNEL(channel);
914     if (usage == webrtc::kViEStreamTypeRtx) {
915       channels_.find(channel)->second->remote_rtx_ssrc_ = ssrc;
916       return 0;
917     }
918     return -1;
919   }
920
921   WEBRTC_FUNC_CONST(GetLocalSSRC, (const int channel,
922                                    unsigned int& ssrc)) {
923     // ssrcs_[0] is the default local ssrc.
924     WEBRTC_CHECK_CHANNEL(channel);
925     ssrc = channels_.find(channel)->second->ssrcs_[0];
926     return 0;
927   }
928   WEBRTC_STUB_CONST(GetRemoteSSRC, (const int, unsigned int&));
929   WEBRTC_STUB_CONST(GetRemoteCSRCs, (const int, unsigned int*));
930
931   WEBRTC_FUNC(SetRtxSendPayloadType, (const int channel,
932                                       const uint8 payload_type)) {
933     WEBRTC_CHECK_CHANNEL(channel);
934     channels_[channel]->rtx_send_payload_type = payload_type;
935     return 0;
936   }
937   WEBRTC_STUB(SetRtxReceivePayloadType, (const int, const uint8));
938
939   WEBRTC_STUB(SetStartSequenceNumber, (const int, unsigned short));
940   WEBRTC_FUNC(SetRTCPStatus,
941               (const int channel, const webrtc::ViERTCPMode mode)) {
942     WEBRTC_CHECK_CHANNEL(channel);
943     channels_[channel]->rtcp_status_ = mode;
944     return 0;
945   }
946   WEBRTC_STUB_CONST(GetRTCPStatus, (const int, webrtc::ViERTCPMode&));
947   WEBRTC_FUNC(SetRTCPCName, (const int channel,
948                              const char rtcp_cname[KMaxRTCPCNameLength])) {
949     WEBRTC_CHECK_CHANNEL(channel);
950     channels_[channel]->cname_.assign(rtcp_cname);
951     return 0;
952   }
953   WEBRTC_FUNC_CONST(GetRTCPCName, (const int channel,
954                                    char rtcp_cname[KMaxRTCPCNameLength])) {
955     WEBRTC_CHECK_CHANNEL(channel);
956     talk_base::strcpyn(rtcp_cname, KMaxRTCPCNameLength,
957                        channels_.find(channel)->second->cname_.c_str());
958     return 0;
959   }
960   WEBRTC_STUB_CONST(GetRemoteRTCPCName, (const int, char*));
961   WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (const int, const unsigned char,
962       unsigned int, const char*, unsigned short));
963   WEBRTC_FUNC(SetNACKStatus, (const int channel, const bool enable)) {
964     WEBRTC_CHECK_CHANNEL(channel);
965     channels_[channel]->nack_ = enable;
966     channels_[channel]->hybrid_nack_fec_ = false;
967     return 0;
968   }
969   WEBRTC_STUB(SetFECStatus, (const int, const bool, const unsigned char,
970       const unsigned char));
971   WEBRTC_FUNC(SetHybridNACKFECStatus, (const int channel, const bool enable,
972       const unsigned char red_type, const unsigned char fec_type)) {
973     WEBRTC_CHECK_CHANNEL(channel);
974     if (red_type == fec_type ||
975         red_type == channels_[channel]->send_codec.plType ||
976         fec_type == channels_[channel]->send_codec.plType) {
977       return -1;
978     }
979     channels_[channel]->nack_ = false;
980     channels_[channel]->hybrid_nack_fec_ = enable;
981     return 0;
982   }
983   WEBRTC_FUNC(SetKeyFrameRequestMethod,
984               (const int channel,
985                const webrtc::ViEKeyFrameRequestMethod method)) {
986     WEBRTC_CHECK_CHANNEL(channel);
987     channels_[channel]->key_frame_request_method_ = method;
988     return 0;
989   }
990   WEBRTC_FUNC(SetSenderBufferingMode, (int channel, int target_delay)) {
991     WEBRTC_CHECK_CHANNEL(channel);
992     channels_[channel]->sender_target_delay_ = target_delay;
993     return 0;
994   }
995   WEBRTC_FUNC(SetReceiverBufferingMode, (int channel, int target_delay)) {
996     WEBRTC_CHECK_CHANNEL(channel);
997     channels_[channel]->receiver_target_delay_ = target_delay;
998     return 0;
999   }
1000   // |Send| and |receive| are stored locally in variables that more clearly
1001   // explain what they mean.
1002   WEBRTC_FUNC(SetRembStatus, (int channel, bool send, bool receive)) {
1003     WEBRTC_CHECK_CHANNEL(channel);
1004     channels_[channel]->remb_contribute_ = receive;
1005     channels_[channel]->remb_bw_partition_ = send;
1006     return 0;
1007   }
1008   WEBRTC_FUNC(SetTMMBRStatus, (const int channel, const bool enable)) {
1009     WEBRTC_CHECK_CHANNEL(channel);
1010     channels_[channel]->tmmbr_ = enable;
1011     return 0;
1012   }
1013   WEBRTC_FUNC(SetSendTimestampOffsetStatus, (int channel, bool enable,
1014       int id)) {
1015     WEBRTC_CHECK_CHANNEL(channel);
1016     channels_[channel]->rtp_offset_send_id_ = (enable) ? id : 0;
1017     return 0;
1018   }
1019   WEBRTC_FUNC(SetReceiveTimestampOffsetStatus, (int channel, bool enable,
1020       int id)) {
1021     WEBRTC_CHECK_CHANNEL(channel);
1022     channels_[channel]->rtp_offset_receive_id_ = (enable) ? id : 0;
1023     return 0;
1024   }
1025   WEBRTC_FUNC(SetSendAbsoluteSendTimeStatus, (int channel, bool enable,
1026       int id)) {
1027     WEBRTC_CHECK_CHANNEL(channel);
1028     channels_[channel]->rtp_absolute_send_time_send_id_ = (enable) ? id : 0;
1029     return 0;
1030   }
1031   WEBRTC_FUNC(SetReceiveAbsoluteSendTimeStatus, (int channel, bool enable,
1032       int id)) {
1033     WEBRTC_CHECK_CHANNEL(channel);
1034     channels_[channel]->rtp_absolute_send_time_receive_id_ = (enable) ? id : 0;
1035     return 0;
1036   }
1037   WEBRTC_STUB(SetRtcpXrRrtrStatus, (int, bool));
1038   WEBRTC_FUNC(SetTransmissionSmoothingStatus, (int channel, bool enable)) {
1039     WEBRTC_CHECK_CHANNEL(channel);
1040     channels_[channel]->transmission_smoothing_ = enable;
1041     return 0;
1042   }
1043   WEBRTC_STUB_CONST(GetReceivedRTCPStatistics, (const int, unsigned short&,
1044       unsigned int&, unsigned int&, unsigned int&, int&));
1045   WEBRTC_STUB_CONST(GetSentRTCPStatistics, (const int, unsigned short&,
1046       unsigned int&, unsigned int&, unsigned int&, int&));
1047   WEBRTC_STUB_CONST(GetRTPStatistics, (const int, unsigned int&, unsigned int&,
1048       unsigned int&, unsigned int&));
1049   WEBRTC_STUB_CONST(GetReceiveChannelRtcpStatistics, (const int,
1050       webrtc::RtcpStatistics&, int&));
1051   WEBRTC_STUB_CONST(GetSendChannelRtcpStatistics, (const int,
1052       webrtc::RtcpStatistics&, int&));
1053   WEBRTC_STUB_CONST(GetRtpStatistics, (const int, webrtc::StreamDataCounters&,
1054       webrtc::StreamDataCounters&));
1055   WEBRTC_FUNC_CONST(GetBandwidthUsage, (const int channel,
1056       unsigned int& total_bitrate, unsigned int& video_bitrate,
1057       unsigned int& fec_bitrate, unsigned int& nack_bitrate)) {
1058     WEBRTC_CHECK_CHANNEL(channel);
1059     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
1060     if (it->second->send) {
1061       video_bitrate = it->second->send_video_bitrate_;
1062       fec_bitrate = it->second->send_fec_bitrate_;
1063       nack_bitrate = it->second->send_nack_bitrate_;
1064       total_bitrate = video_bitrate + fec_bitrate + nack_bitrate;
1065     } else {
1066       total_bitrate = 0;
1067       video_bitrate = 0;
1068       fec_bitrate = 0;
1069       nack_bitrate = 0;
1070     }
1071     return 0;
1072   }
1073   WEBRTC_FUNC_CONST(GetEstimatedSendBandwidth, (const int channel,
1074       unsigned int* send_bandwidth_estimate)) {
1075     WEBRTC_CHECK_CHANNEL(channel);
1076     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
1077     // Assume the current video, fec and nack bitrate sums up to our estimate.
1078     if (it->second->send) {
1079       *send_bandwidth_estimate = it->second->send_bandwidth_;
1080     } else {
1081       *send_bandwidth_estimate = 0;
1082     }
1083     return 0;
1084   }
1085   WEBRTC_FUNC_CONST(GetEstimatedReceiveBandwidth, (const int channel,
1086       unsigned int* receive_bandwidth_estimate)) {
1087     WEBRTC_CHECK_CHANNEL(channel);
1088     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
1089     if (it->second->receive_) {
1090     // For simplicity, assume all channels receive half of max send rate.
1091       *receive_bandwidth_estimate = it->second->receive_bandwidth_;
1092     } else {
1093       *receive_bandwidth_estimate = 0;
1094     }
1095     return 0;
1096   }
1097   WEBRTC_STUB(RegisterSendChannelRtcpStatisticsCallback,
1098                     (int, webrtc::RtcpStatisticsCallback*));
1099   WEBRTC_STUB(DeregisterSendChannelRtcpStatisticsCallback,
1100                     (int, webrtc::RtcpStatisticsCallback*));
1101   WEBRTC_STUB(RegisterReceiveChannelRtcpStatisticsCallback,
1102                     (int, webrtc::RtcpStatisticsCallback*));
1103   WEBRTC_STUB(DeregisterReceiveChannelRtcpStatisticsCallback,
1104                     (int, webrtc::RtcpStatisticsCallback*));
1105   WEBRTC_STUB(RegisterSendChannelRtpStatisticsCallback,
1106                     (int, webrtc::StreamDataCountersCallback*));
1107   WEBRTC_STUB(DeregisterSendChannelRtpStatisticsCallback,
1108                     (int, webrtc::StreamDataCountersCallback*));
1109   WEBRTC_STUB(RegisterReceiveChannelRtpStatisticsCallback,
1110                     (int, webrtc::StreamDataCountersCallback*));
1111   WEBRTC_STUB(DeregisterReceiveChannelRtpStatisticsCallback,
1112                     (int, webrtc::StreamDataCountersCallback*));
1113   WEBRTC_STUB(RegisterSendBitrateObserver,
1114                     (int, webrtc::BitrateStatisticsObserver*));
1115   WEBRTC_STUB(DeregisterSendBitrateObserver,
1116                     (int, webrtc::BitrateStatisticsObserver*));
1117   WEBRTC_STUB(RegisterSendFrameCountObserver,
1118                     (int, webrtc::FrameCountObserver*));
1119   WEBRTC_STUB(DeregisterSendFrameCountObserver,
1120                     (int, webrtc::FrameCountObserver*));
1121
1122   WEBRTC_STUB(StartRTPDump, (const int, const char*, webrtc::RTPDirections));
1123   WEBRTC_STUB(StopRTPDump, (const int, webrtc::RTPDirections));
1124   WEBRTC_STUB(RegisterRTPObserver, (const int, webrtc::ViERTPObserver&));
1125   WEBRTC_STUB(DeregisterRTPObserver, (const int));
1126   WEBRTC_STUB(RegisterRTCPObserver, (const int, webrtc::ViERTCPObserver&));
1127   WEBRTC_STUB(DeregisterRTCPObserver, (const int));
1128
1129   // webrtc::ViEImageProcess
1130   WEBRTC_STUB(RegisterCaptureEffectFilter, (const int,
1131       webrtc::ViEEffectFilter&));
1132   WEBRTC_STUB(DeregisterCaptureEffectFilter, (const int));
1133   WEBRTC_STUB(RegisterSendEffectFilter, (const int,
1134       webrtc::ViEEffectFilter&));
1135   WEBRTC_STUB(DeregisterSendEffectFilter, (const int));
1136   WEBRTC_STUB(RegisterRenderEffectFilter, (const int,
1137       webrtc::ViEEffectFilter&));
1138   WEBRTC_STUB(DeregisterRenderEffectFilter, (const int));
1139   WEBRTC_STUB(EnableDeflickering, (const int, const bool));
1140   WEBRTC_FUNC(EnableDenoising, (const int capture_id, const bool denoising)) {
1141     WEBRTC_CHECK_CAPTURER(capture_id);
1142     capturers_[capture_id]->set_denoising(denoising);
1143     return 0;
1144   }
1145   WEBRTC_STUB(EnableColorEnhancement, (const int, const bool));
1146   WEBRTC_VOID_STUB(RegisterPreEncodeCallback,
1147                    (int, webrtc::I420FrameCallback*));
1148   WEBRTC_VOID_STUB(DeRegisterPreEncodeCallback, (int));
1149   WEBRTC_VOID_STUB(RegisterPreRenderCallback,
1150                    (int, webrtc::I420FrameCallback*));
1151   WEBRTC_VOID_STUB(DeRegisterPreRenderCallback, (int));
1152   // webrtc::ViEExternalCodec
1153   WEBRTC_FUNC(RegisterExternalSendCodec,
1154       (const int channel, const unsigned char pl_type, webrtc::VideoEncoder*,
1155           bool)) {
1156     WEBRTC_CHECK_CHANNEL(channel);
1157     channels_[channel]->ext_encoder_pl_types_.insert(pl_type);
1158     return 0;
1159   }
1160   WEBRTC_FUNC(DeRegisterExternalSendCodec,
1161       (const int channel, const unsigned char pl_type)) {
1162     WEBRTC_CHECK_CHANNEL(channel);
1163     channels_[channel]->ext_encoder_pl_types_.erase(pl_type);
1164     return 0;
1165   }
1166   WEBRTC_FUNC(RegisterExternalReceiveCodec,
1167       (const int channel, const unsigned int pl_type, webrtc::VideoDecoder*,
1168        bool, int)) {
1169     WEBRTC_CHECK_CHANNEL(channel);
1170     channels_[channel]->ext_decoder_pl_types_.insert(pl_type);
1171     return 0;
1172   }
1173   WEBRTC_FUNC(DeRegisterExternalReceiveCodec,
1174       (const int channel, const unsigned char pl_type)) {
1175     WEBRTC_CHECK_CHANNEL(channel);
1176     channels_[channel]->ext_decoder_pl_types_.erase(pl_type);
1177     return 0;
1178   }
1179
1180  private:
1181   bool IsChannelId(int id) const {
1182     return (id >= kViEChannelIdBase && id <= kViEChannelIdMax);
1183   }
1184   bool IsCapturerId(int id) const {
1185     return (id >= kViECaptureIdBase && id <= kViECaptureIdMax);
1186   }
1187
1188   bool inited_;
1189   int last_channel_;
1190   std::map<int, Channel*> channels_;
1191   bool fail_create_channel_;
1192   int last_capturer_;
1193   std::map<int, Capturer*> capturers_;
1194   bool fail_alloc_capturer_;
1195   const cricket::VideoCodec* const* codecs_;
1196   int num_codecs_;
1197   int num_set_send_codecs_;  // how many times we call SetSendCodec().
1198 };
1199
1200 }  // namespace cricket
1201
1202 #endif  // TALK_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_