Upstream version 5.34.104.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   bool GetReceive(int channel) const {
451     WEBRTC_ASSERT_CHANNEL(channel);
452     return channels_.find(channel)->second->receive_;
453   }
454   int GetCaptureChannelId(int capture_id) const {
455     WEBRTC_ASSERT_CAPTURER(capture_id);
456     return capturers_.find(capture_id)->second->channel_id();
457   }
458   bool GetCaptureDenoising(int capture_id) const {
459     WEBRTC_ASSERT_CAPTURER(capture_id);
460     return capturers_.find(capture_id)->second->denoising();
461   }
462   int64 GetCaptureLastTimestamp(int capture_id) const {
463     WEBRTC_ASSERT_CAPTURER(capture_id);
464     return capturers_.find(capture_id)->second->last_capture_time();
465   }
466   webrtc::ViERTCPMode GetRtcpStatus(int channel) const {
467     WEBRTC_ASSERT_CHANNEL(channel);
468     return channels_.find(channel)->second->rtcp_status_;
469   }
470   webrtc::ViEKeyFrameRequestMethod GetKeyFrameRequestMethod(int channel) const {
471     WEBRTC_ASSERT_CHANNEL(channel);
472     return channels_.find(channel)->second->key_frame_request_method_;
473   }
474   bool GetTmmbrStatus(int channel) const {
475     WEBRTC_ASSERT_CHANNEL(channel);
476     return channels_.find(channel)->second->tmmbr_;
477   }
478   bool GetRembStatusBwPartition(int channel) const {
479     WEBRTC_ASSERT_CHANNEL(channel);
480     return channels_.find(channel)->second->remb_bw_partition_;
481   }
482   bool GetRembStatusContribute(int channel) const {
483     WEBRTC_ASSERT_CHANNEL(channel);
484     return channels_.find(channel)->second->remb_contribute_;
485   }
486   int GetSendRtpTimestampOffsetExtensionId(int channel) {
487     WEBRTC_ASSERT_CHANNEL(channel);
488     return channels_.find(channel)->second->rtp_offset_send_id_;
489   }
490   int GetReceiveRtpTimestampOffsetExtensionId(int channel) {
491     WEBRTC_ASSERT_CHANNEL(channel);
492     return channels_.find(channel)->second->rtp_offset_receive_id_;
493   }
494   int GetSendAbsoluteSendTimeExtensionId(int channel) {
495     WEBRTC_ASSERT_CHANNEL(channel);
496     return channels_.find(channel)->second->rtp_absolute_send_time_send_id_;
497   }
498   int GetReceiveAbsoluteSendTimeExtensionId(int channel) {
499     WEBRTC_ASSERT_CHANNEL(channel);
500     return channels_.find(channel)->second->rtp_absolute_send_time_receive_id_;
501   }
502   bool GetTransmissionSmoothingStatus(int channel) {
503     WEBRTC_ASSERT_CHANNEL(channel);
504     return channels_.find(channel)->second->transmission_smoothing_;
505   }
506   int GetSenderTargetDelay(int channel) {
507     WEBRTC_ASSERT_CHANNEL(channel);
508     return channels_.find(channel)->second->sender_target_delay_;
509   }
510   int GetReceiverTargetDelay(int channel) {
511     WEBRTC_ASSERT_CHANNEL(channel);
512     return channels_.find(channel)->second->receiver_target_delay_;
513   }
514   bool GetNackStatus(int channel) const {
515     WEBRTC_ASSERT_CHANNEL(channel);
516     return channels_.find(channel)->second->nack_;
517   }
518   bool GetHybridNackFecStatus(int channel) const {
519     WEBRTC_ASSERT_CHANNEL(channel);
520     return channels_.find(channel)->second->hybrid_nack_fec_;
521   }
522   int GetNumSsrcs(int channel) const {
523     WEBRTC_ASSERT_CHANNEL(channel);
524     return static_cast<int>(
525         channels_.find(channel)->second->ssrcs_.size());
526   }
527   int GetNumRtxSsrcs(int channel) const {
528     WEBRTC_ASSERT_CHANNEL(channel);
529     return static_cast<int>(
530         channels_.find(channel)->second->rtx_ssrcs_.size());
531   }
532   bool GetIsTransmitting(int channel) const {
533     WEBRTC_ASSERT_CHANNEL(channel);
534     return channels_.find(channel)->second->can_transmit_;
535   }
536   int GetRtxSsrc(int channel, int simulcast_idx) const {
537     WEBRTC_ASSERT_CHANNEL(channel);
538     if (channels_.find(channel)->second->rtx_ssrcs_.find(simulcast_idx) ==
539         channels_.find(channel)->second->rtx_ssrcs_.end()) {
540       return -1;
541     }
542     return channels_.find(channel)->second->rtx_ssrcs_[simulcast_idx];
543   }
544   bool ReceiveCodecRegistered(int channel,
545                               const webrtc::VideoCodec& codec) const {
546     WEBRTC_ASSERT_CHANNEL(channel);
547     const std::vector<webrtc::VideoCodec>& codecs =
548       channels_.find(channel)->second->recv_codecs;
549     return std::find(codecs.begin(), codecs.end(), codec) != codecs.end();
550   };
551   bool ExternalDecoderRegistered(int channel,
552                                  unsigned int pl_type) const {
553     WEBRTC_ASSERT_CHANNEL(channel);
554     return channels_.find(channel)->second->
555         ext_decoder_pl_types_.count(pl_type) != 0;
556   };
557   int GetNumExternalDecoderRegistered(int channel) const {
558     WEBRTC_ASSERT_CHANNEL(channel);
559     return static_cast<int>(
560         channels_.find(channel)->second->ext_decoder_pl_types_.size());
561   };
562   bool ExternalEncoderRegistered(int channel,
563                                  unsigned int pl_type) const {
564     WEBRTC_ASSERT_CHANNEL(channel);
565     return channels_.find(channel)->second->
566         ext_encoder_pl_types_.count(pl_type) != 0;
567   };
568   int GetNumExternalEncoderRegistered(int channel) const {
569     WEBRTC_ASSERT_CHANNEL(channel);
570     return static_cast<int>(
571         channels_.find(channel)->second->ext_encoder_pl_types_.size());
572   };
573   int GetTotalNumExternalEncoderRegistered() const {
574     std::map<int, Channel*>::const_iterator it;
575     int total_num_registered = 0;
576     for (it = channels_.begin(); it != channels_.end(); ++it)
577       total_num_registered +=
578           static_cast<int>(it->second->ext_encoder_pl_types_.size());
579     return total_num_registered;
580   }
581   void SetSendBitrates(int channel, unsigned int video_bitrate,
582                        unsigned int fec_bitrate, unsigned int nack_bitrate) {
583     WEBRTC_ASSERT_CHANNEL(channel);
584     channels_[channel]->send_video_bitrate_ = video_bitrate;
585     channels_[channel]->send_fec_bitrate_ = fec_bitrate;
586     channels_[channel]->send_nack_bitrate_ = nack_bitrate;
587   }
588   void SetSendBandwidthEstimate(int channel, unsigned int send_bandwidth) {
589     WEBRTC_ASSERT_CHANNEL(channel);
590     channels_[channel]->send_bandwidth_ = send_bandwidth;
591   }
592   void SetReceiveBandwidthEstimate(int channel,
593                                    unsigned int receive_bandwidth) {
594     WEBRTC_ASSERT_CHANNEL(channel);
595     channels_[channel]->receive_bandwidth_ = receive_bandwidth;
596   };
597   int GetRtxSendPayloadType(int channel) {
598     WEBRTC_CHECK_CHANNEL(channel);
599     return channels_[channel]->rtx_send_payload_type;
600   }
601   int GetRemoteRtxSsrc(int channel) {
602     WEBRTC_CHECK_CHANNEL(channel);
603     return channels_.find(channel)->second->remote_rtx_ssrc_;
604   }
605
606   WEBRTC_STUB(Release, ());
607
608   // webrtc::ViEBase
609   WEBRTC_FUNC(Init, ()) {
610     inited_ = true;
611     return 0;
612   };
613   WEBRTC_STUB(SetVoiceEngine, (webrtc::VoiceEngine*));
614   WEBRTC_FUNC(CreateChannel, (int& channel)) {  // NOLINT
615     if (fail_create_channel_) {
616       return -1;
617     }
618     if (kViEChannelIdMax == last_channel_) {
619       return -1;
620     }
621     Channel* ch = new Channel();
622     channels_[++last_channel_] = ch;
623     channel = last_channel_;
624     return 0;
625   };
626   WEBRTC_FUNC(CreateChannel, (int& channel, int original_channel)) {
627     WEBRTC_CHECK_CHANNEL(original_channel);
628     if (CreateChannel(channel) != 0) {
629       return -1;
630     }
631     channels_[channel]->original_channel_id_ = original_channel;
632     return 0;
633   }
634   WEBRTC_FUNC(CreateReceiveChannel, (int& channel, int original_channel)) {
635     return CreateChannel(channel, original_channel);
636   }
637   WEBRTC_FUNC(DeleteChannel, (const int channel)) {
638     WEBRTC_CHECK_CHANNEL(channel);
639     // Make sure we deregister all the decoders before deleting a channel.
640     EXPECT_EQ(0, GetNumExternalDecoderRegistered(channel));
641     delete channels_[channel];
642     channels_.erase(channel);
643     return 0;
644   }
645   WEBRTC_STUB(RegisterCpuOveruseObserver,
646       (int channel, webrtc::CpuOveruseObserver* observer));
647   WEBRTC_STUB(CpuOveruseMeasures, (int, int*, int*, int*, int*));
648   WEBRTC_STUB(ConnectAudioChannel, (const int, const int));
649   WEBRTC_STUB(DisconnectAudioChannel, (const int));
650   WEBRTC_FUNC(StartSend, (const int channel)) {
651     WEBRTC_CHECK_CHANNEL(channel);
652     channels_[channel]->send = true;
653     return 0;
654   }
655   WEBRTC_FUNC(StopSend, (const int channel)) {
656     WEBRTC_CHECK_CHANNEL(channel);
657     channels_[channel]->send = false;
658     return 0;
659   }
660   WEBRTC_FUNC(StartReceive, (const int channel)) {
661     WEBRTC_CHECK_CHANNEL(channel);
662     channels_[channel]->receive_ = true;
663     return 0;
664   }
665   WEBRTC_FUNC(StopReceive, (const int channel)) {
666     WEBRTC_CHECK_CHANNEL(channel);
667     channels_[channel]->receive_ = false;
668     return 0;
669   }
670   WEBRTC_STUB(GetVersion, (char version[1024]));
671   WEBRTC_STUB(LastError, ());
672
673   // webrtc::ViECodec
674   WEBRTC_FUNC_CONST(NumberOfCodecs, ()) {
675     return num_codecs_;
676   };
677   WEBRTC_FUNC_CONST(GetCodec, (const unsigned char list_number,
678                                webrtc::VideoCodec& out_codec)) {
679     if (list_number >= NumberOfCodecs()) {
680       return -1;
681     }
682     memset(&out_codec, 0, sizeof(out_codec));
683     const cricket::VideoCodec& c(*codecs_[list_number]);
684     if ("I420" == c.name) {
685       out_codec.codecType = webrtc::kVideoCodecI420;
686     } else if ("VP8" == c.name) {
687       out_codec.codecType = webrtc::kVideoCodecVP8;
688     } else if ("red" == c.name) {
689       out_codec.codecType = webrtc::kVideoCodecRED;
690     } else if ("ulpfec" == c.name) {
691       out_codec.codecType = webrtc::kVideoCodecULPFEC;
692     } else {
693       out_codec.codecType = webrtc::kVideoCodecUnknown;
694     }
695     talk_base::strcpyn(out_codec.plName, sizeof(out_codec.plName),
696                        c.name.c_str());
697     out_codec.plType = c.id;
698     out_codec.width = c.width;
699     out_codec.height = c.height;
700     out_codec.startBitrate = kStartVideoBitrate;
701     out_codec.maxBitrate = kMaxVideoBitrate;
702     out_codec.minBitrate = kMinVideoBitrate;
703     out_codec.maxFramerate = c.framerate;
704     return 0;
705   };
706   WEBRTC_FUNC(SetSendCodec, (const int channel,
707                              const webrtc::VideoCodec& codec)) {
708     WEBRTC_CHECK_CHANNEL(channel);
709     channels_[channel]->send_codec = codec;
710     ++num_set_send_codecs_;
711     return 0;
712   };
713   WEBRTC_FUNC_CONST(GetSendCodec, (const int channel,
714                                    webrtc::VideoCodec& codec)) {  // NOLINT
715     WEBRTC_CHECK_CHANNEL(channel);
716     codec = channels_.find(channel)->second->send_codec;
717     return 0;
718   };
719   WEBRTC_FUNC(SetReceiveCodec, (const int channel,
720                                 const webrtc::VideoCodec& codec)) {  // NOLINT
721     WEBRTC_CHECK_CHANNEL(channel);
722     channels_[channel]->recv_codecs.push_back(codec);
723     return 0;
724   };
725   WEBRTC_STUB_CONST(GetReceiveCodec, (const int, webrtc::VideoCodec&));
726   WEBRTC_STUB_CONST(GetCodecConfigParameters, (const int,
727       unsigned char*, unsigned char&));
728   WEBRTC_STUB(SetImageScaleStatus, (const int, const bool));
729   WEBRTC_STUB_CONST(GetSendCodecStastistics, (const int,
730       unsigned int&, unsigned int&));
731   WEBRTC_STUB_CONST(GetReceiveCodecStastistics, (const int,
732       unsigned int&, unsigned int&));
733   WEBRTC_STUB_CONST(GetReceiveSideDelay, (const int video_channel,
734                                           int* delay_ms));
735   WEBRTC_FUNC_CONST(GetCodecTargetBitrate, (const int channel,
736       unsigned int* codec_target_bitrate)) {
737     WEBRTC_CHECK_CHANNEL(channel);
738
739     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
740     if (it->second->send) {
741       // Assume the encoder produces the expected rate.
742       *codec_target_bitrate = it->second->send_video_bitrate_;
743     } else {
744       *codec_target_bitrate = 0;
745     }
746     return 0;
747   }
748   virtual unsigned int GetDiscardedPackets(const int channel) const {
749     return 0;
750   }
751
752   WEBRTC_STUB(SetKeyFrameRequestCallbackStatus, (const int, const bool));
753   WEBRTC_STUB(SetSignalKeyPacketLossStatus, (const int, const bool,
754       const bool));
755   WEBRTC_STUB(RegisterEncoderObserver, (const int,
756       webrtc::ViEEncoderObserver&));
757   WEBRTC_STUB(DeregisterEncoderObserver, (const int));
758   WEBRTC_STUB(RegisterDecoderObserver, (const int,
759       webrtc::ViEDecoderObserver&));
760   WEBRTC_STUB(DeregisterDecoderObserver, (const int));
761   WEBRTC_STUB(SendKeyFrame, (const int));
762   WEBRTC_STUB(WaitForFirstKeyFrame, (const int, const bool));
763   WEBRTC_STUB(StartDebugRecording, (int, const char*));
764   WEBRTC_STUB(StopDebugRecording, (int));
765   WEBRTC_VOID_STUB(SuspendBelowMinBitrate, (int));
766
767   // webrtc::ViECapture
768   WEBRTC_STUB(NumberOfCaptureDevices, ());
769   WEBRTC_STUB(GetCaptureDevice, (unsigned int, char*,
770       const unsigned int, char*, const unsigned int));
771   WEBRTC_STUB(AllocateCaptureDevice, (const char*, const unsigned int, int&));
772   WEBRTC_FUNC(AllocateExternalCaptureDevice,
773               (int& capture_id, webrtc::ViEExternalCapture*& capture)) {
774     if (fail_alloc_capturer_) {
775       return -1;
776     }
777     if (kViECaptureIdMax == last_capturer_) {
778       return -1;
779     }
780     Capturer* cap = new Capturer();
781     capturers_[++last_capturer_] = cap;
782     capture_id = last_capturer_;
783     capture = cap;
784     return 0;
785   }
786   WEBRTC_STUB(AllocateCaptureDevice, (webrtc::VideoCaptureModule&, int&));
787   WEBRTC_FUNC(ReleaseCaptureDevice, (const int capture_id)) {
788     WEBRTC_CHECK_CAPTURER(capture_id);
789     delete capturers_[capture_id];
790     capturers_.erase(capture_id);
791     return 0;
792   }
793   WEBRTC_FUNC(ConnectCaptureDevice, (const int capture_id,
794                                      const int channel)) {
795     WEBRTC_CHECK_CHANNEL(channel);
796     WEBRTC_CHECK_CAPTURER(capture_id);
797     channels_[channel]->capture_id_ = capture_id;
798     capturers_[capture_id]->set_channel_id(channel);
799     return 0;
800   }
801   WEBRTC_FUNC(DisconnectCaptureDevice, (const int channel)) {
802     WEBRTC_CHECK_CHANNEL(channel);
803     int capture_id = channels_[channel]->capture_id_;
804     WEBRTC_CHECK_CAPTURER(capture_id);
805     channels_[channel]->capture_id_ = -1;
806     capturers_[capture_id]->set_channel_id(-1);
807     return 0;
808   }
809   WEBRTC_STUB(StartCapture, (const int, const webrtc::CaptureCapability&));
810   WEBRTC_STUB(StopCapture, (const int));
811   WEBRTC_STUB(SetRotateCapturedFrames, (const int,
812       const webrtc::RotateCapturedFrame));
813   WEBRTC_STUB(SetCaptureDelay, (const int, const unsigned int));
814   WEBRTC_STUB(NumberOfCapabilities, (const char*, const unsigned int));
815   WEBRTC_STUB(GetCaptureCapability, (const char*, const unsigned int,
816       const unsigned int, webrtc::CaptureCapability&));
817   WEBRTC_STUB(ShowCaptureSettingsDialogBox, (const char*, const unsigned int,
818       const char*, void*, const unsigned int, const unsigned int));
819   WEBRTC_STUB(GetOrientation, (const char*, webrtc::RotateCapturedFrame&));
820   WEBRTC_STUB(EnableBrightnessAlarm, (const int, const bool));
821   WEBRTC_STUB(RegisterObserver, (const int, webrtc::ViECaptureObserver&));
822   WEBRTC_STUB(DeregisterObserver, (const int));
823
824   // webrtc::ViENetwork
825   WEBRTC_VOID_FUNC(SetNetworkTransmissionState, (const int channel,
826                                                  const bool is_transmitting)) {
827     WEBRTC_ASSERT_CHANNEL(channel);
828     channels_[channel]->can_transmit_ = is_transmitting;
829   }
830   WEBRTC_STUB(RegisterSendTransport, (const int, webrtc::Transport&));
831   WEBRTC_STUB(DeregisterSendTransport, (const int));
832   WEBRTC_STUB(ReceivedRTPPacket, (const int, const void*, const int,
833       const webrtc::PacketTime&));
834   WEBRTC_STUB(ReceivedRTCPPacket, (const int, const void*, const int));
835   // Not using WEBRTC_STUB due to bool return value
836   virtual bool IsIPv6Enabled(int channel) { return true; }
837   WEBRTC_STUB(SetMTU, (int, unsigned int));
838
839   // webrtc::ViERender
840   WEBRTC_STUB(RegisterVideoRenderModule, (webrtc::VideoRender&));
841   WEBRTC_STUB(DeRegisterVideoRenderModule, (webrtc::VideoRender&));
842   WEBRTC_STUB(AddRenderer, (const int, void*, const unsigned int, const float,
843       const float, const float, const float));
844   WEBRTC_FUNC(RemoveRenderer, (const int render_id)) {
845     if (IsCapturerId(render_id)) {
846       WEBRTC_CHECK_CAPTURER(render_id);
847       return 0;
848     } else if (IsChannelId(render_id)) {
849       WEBRTC_CHECK_CHANNEL(render_id);
850       channels_[render_id]->has_renderer_ = false;
851       return 0;
852     }
853     return -1;
854   }
855   WEBRTC_FUNC(StartRender, (const int render_id)) {
856     if (IsCapturerId(render_id)) {
857       WEBRTC_CHECK_CAPTURER(render_id);
858       return 0;
859     } else if (IsChannelId(render_id)) {
860       WEBRTC_CHECK_CHANNEL(render_id);
861       channels_[render_id]->render_started_ = true;
862       return 0;
863     }
864     return -1;
865   }
866   WEBRTC_FUNC(StopRender, (const int render_id)) {
867     if (IsCapturerId(render_id)) {
868       WEBRTC_CHECK_CAPTURER(render_id);
869       return 0;
870     } else if (IsChannelId(render_id)) {
871       WEBRTC_CHECK_CHANNEL(render_id);
872       channels_[render_id]->render_started_ = false;
873       return 0;
874     }
875     return -1;
876   }
877   WEBRTC_STUB(SetExpectedRenderDelay, (int render_id, int render_delay));
878   WEBRTC_STUB(ConfigureRender, (int, const unsigned int, const float,
879       const float, const float, const float));
880   WEBRTC_STUB(MirrorRenderStream, (const int, const bool, const bool,
881       const bool));
882   WEBRTC_FUNC(AddRenderer, (const int render_id,
883                             webrtc::RawVideoType video_type,
884                             webrtc::ExternalRenderer* renderer)) {
885     if (IsCapturerId(render_id)) {
886       WEBRTC_CHECK_CAPTURER(render_id);
887       return 0;
888     } else if (IsChannelId(render_id)) {
889       WEBRTC_CHECK_CHANNEL(render_id);
890       channels_[render_id]->has_renderer_ = true;
891       return 0;
892     }
893     return -1;
894   }
895
896   // webrtc::ViERTP_RTCP
897   WEBRTC_FUNC(SetLocalSSRC, (const int channel,
898                              const unsigned int ssrc,
899                              const webrtc::StreamType usage,
900                              const unsigned char idx)) {
901     WEBRTC_CHECK_CHANNEL(channel);
902     switch (usage) {
903       case webrtc::kViEStreamTypeNormal:
904         channels_[channel]->ssrcs_[idx] = ssrc;
905         break;
906       case webrtc::kViEStreamTypeRtx:
907         channels_[channel]->rtx_ssrcs_[idx] = ssrc;
908         break;
909       default:
910         return -1;
911     }
912     return 0;
913   }
914
915   WEBRTC_FUNC_CONST(SetRemoteSSRCType, (const int channel,
916         const webrtc::StreamType usage, const unsigned int ssrc)) {
917     WEBRTC_CHECK_CHANNEL(channel);
918     if (usage == webrtc::kViEStreamTypeRtx) {
919       channels_.find(channel)->second->remote_rtx_ssrc_ = ssrc;
920       return 0;
921     }
922     return -1;
923   }
924
925   WEBRTC_FUNC_CONST(GetLocalSSRC, (const int channel,
926                                    unsigned int& ssrc)) {
927     // ssrcs_[0] is the default local ssrc.
928     WEBRTC_CHECK_CHANNEL(channel);
929     ssrc = channels_.find(channel)->second->ssrcs_[0];
930     return 0;
931   }
932   WEBRTC_STUB_CONST(GetRemoteSSRC, (const int, unsigned int&));
933   WEBRTC_STUB_CONST(GetRemoteCSRCs, (const int, unsigned int*));
934
935   WEBRTC_FUNC(SetRtxSendPayloadType, (const int channel,
936                                       const uint8 payload_type)) {
937     WEBRTC_CHECK_CHANNEL(channel);
938     channels_[channel]->rtx_send_payload_type = payload_type;
939     return 0;
940   }
941   WEBRTC_STUB(SetRtxReceivePayloadType, (const int, const uint8));
942
943   WEBRTC_STUB(SetStartSequenceNumber, (const int, unsigned short));
944   WEBRTC_FUNC(SetRTCPStatus,
945               (const int channel, const webrtc::ViERTCPMode mode)) {
946     WEBRTC_CHECK_CHANNEL(channel);
947     channels_[channel]->rtcp_status_ = mode;
948     return 0;
949   }
950   WEBRTC_STUB_CONST(GetRTCPStatus, (const int, webrtc::ViERTCPMode&));
951   WEBRTC_FUNC(SetRTCPCName, (const int channel,
952                              const char rtcp_cname[KMaxRTCPCNameLength])) {
953     WEBRTC_CHECK_CHANNEL(channel);
954     channels_[channel]->cname_.assign(rtcp_cname);
955     return 0;
956   }
957   WEBRTC_FUNC_CONST(GetRTCPCName, (const int channel,
958                                    char rtcp_cname[KMaxRTCPCNameLength])) {
959     WEBRTC_CHECK_CHANNEL(channel);
960     talk_base::strcpyn(rtcp_cname, KMaxRTCPCNameLength,
961                        channels_.find(channel)->second->cname_.c_str());
962     return 0;
963   }
964   WEBRTC_STUB_CONST(GetRemoteRTCPCName, (const int, char*));
965   WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (const int, const unsigned char,
966       unsigned int, const char*, unsigned short));
967   WEBRTC_FUNC(SetNACKStatus, (const int channel, const bool enable)) {
968     WEBRTC_CHECK_CHANNEL(channel);
969     channels_[channel]->nack_ = enable;
970     channels_[channel]->hybrid_nack_fec_ = false;
971     return 0;
972   }
973   WEBRTC_STUB(SetFECStatus, (const int, const bool, const unsigned char,
974       const unsigned char));
975   WEBRTC_FUNC(SetHybridNACKFECStatus, (const int channel, const bool enable,
976       const unsigned char red_type, const unsigned char fec_type)) {
977     WEBRTC_CHECK_CHANNEL(channel);
978     if (red_type == fec_type ||
979         red_type == channels_[channel]->send_codec.plType ||
980         fec_type == channels_[channel]->send_codec.plType) {
981       return -1;
982     }
983     channels_[channel]->nack_ = false;
984     channels_[channel]->hybrid_nack_fec_ = enable;
985     return 0;
986   }
987   WEBRTC_FUNC(SetKeyFrameRequestMethod,
988               (const int channel,
989                const webrtc::ViEKeyFrameRequestMethod method)) {
990     WEBRTC_CHECK_CHANNEL(channel);
991     channels_[channel]->key_frame_request_method_ = method;
992     return 0;
993   }
994   WEBRTC_FUNC(SetSenderBufferingMode, (int channel, int target_delay)) {
995     WEBRTC_CHECK_CHANNEL(channel);
996     channels_[channel]->sender_target_delay_ = target_delay;
997     return 0;
998   }
999   WEBRTC_FUNC(SetReceiverBufferingMode, (int channel, int target_delay)) {
1000     WEBRTC_CHECK_CHANNEL(channel);
1001     channels_[channel]->receiver_target_delay_ = target_delay;
1002     return 0;
1003   }
1004   // |Send| and |receive| are stored locally in variables that more clearly
1005   // explain what they mean.
1006   WEBRTC_FUNC(SetRembStatus, (int channel, bool send, bool receive)) {
1007     WEBRTC_CHECK_CHANNEL(channel);
1008     channels_[channel]->remb_contribute_ = receive;
1009     channels_[channel]->remb_bw_partition_ = send;
1010     return 0;
1011   }
1012   WEBRTC_FUNC(SetTMMBRStatus, (const int channel, const bool enable)) {
1013     WEBRTC_CHECK_CHANNEL(channel);
1014     channels_[channel]->tmmbr_ = enable;
1015     return 0;
1016   }
1017   WEBRTC_FUNC(SetSendTimestampOffsetStatus, (int channel, bool enable,
1018       int id)) {
1019     WEBRTC_CHECK_CHANNEL(channel);
1020     channels_[channel]->rtp_offset_send_id_ = (enable) ? id : 0;
1021     return 0;
1022   }
1023   WEBRTC_FUNC(SetReceiveTimestampOffsetStatus, (int channel, bool enable,
1024       int id)) {
1025     WEBRTC_CHECK_CHANNEL(channel);
1026     channels_[channel]->rtp_offset_receive_id_ = (enable) ? id : 0;
1027     return 0;
1028   }
1029   WEBRTC_FUNC(SetSendAbsoluteSendTimeStatus, (int channel, bool enable,
1030       int id)) {
1031     WEBRTC_CHECK_CHANNEL(channel);
1032     channels_[channel]->rtp_absolute_send_time_send_id_ = (enable) ? id : 0;
1033     return 0;
1034   }
1035   WEBRTC_FUNC(SetReceiveAbsoluteSendTimeStatus, (int channel, bool enable,
1036       int id)) {
1037     WEBRTC_CHECK_CHANNEL(channel);
1038     channels_[channel]->rtp_absolute_send_time_receive_id_ = (enable) ? id : 0;
1039     return 0;
1040   }
1041   WEBRTC_STUB(SetRtcpXrRrtrStatus, (int, bool));
1042   WEBRTC_FUNC(SetTransmissionSmoothingStatus, (int channel, bool enable)) {
1043     WEBRTC_CHECK_CHANNEL(channel);
1044     channels_[channel]->transmission_smoothing_ = enable;
1045     return 0;
1046   }
1047   WEBRTC_STUB_CONST(GetReceivedRTCPStatistics, (const int, unsigned short&,
1048       unsigned int&, unsigned int&, unsigned int&, int&));
1049   WEBRTC_STUB_CONST(GetSentRTCPStatistics, (const int, unsigned short&,
1050       unsigned int&, unsigned int&, unsigned int&, int&));
1051   WEBRTC_STUB_CONST(GetRTPStatistics, (const int, unsigned int&, unsigned int&,
1052       unsigned int&, unsigned int&));
1053   WEBRTC_STUB_CONST(GetReceiveChannelRtcpStatistics, (const int,
1054       webrtc::RtcpStatistics&, int&));
1055   WEBRTC_STUB_CONST(GetSendChannelRtcpStatistics, (const int,
1056       webrtc::RtcpStatistics&, int&));
1057   WEBRTC_STUB_CONST(GetRtpStatistics, (const int, webrtc::StreamDataCounters&,
1058       webrtc::StreamDataCounters&));
1059   WEBRTC_FUNC_CONST(GetBandwidthUsage, (const int channel,
1060       unsigned int& total_bitrate, unsigned int& video_bitrate,
1061       unsigned int& fec_bitrate, unsigned int& nack_bitrate)) {
1062     WEBRTC_CHECK_CHANNEL(channel);
1063     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
1064     if (it->second->send) {
1065       video_bitrate = it->second->send_video_bitrate_;
1066       fec_bitrate = it->second->send_fec_bitrate_;
1067       nack_bitrate = it->second->send_nack_bitrate_;
1068       total_bitrate = video_bitrate + fec_bitrate + nack_bitrate;
1069     } else {
1070       total_bitrate = 0;
1071       video_bitrate = 0;
1072       fec_bitrate = 0;
1073       nack_bitrate = 0;
1074     }
1075     return 0;
1076   }
1077   WEBRTC_FUNC_CONST(GetEstimatedSendBandwidth, (const int channel,
1078       unsigned int* send_bandwidth_estimate)) {
1079     WEBRTC_CHECK_CHANNEL(channel);
1080     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
1081     // Assume the current video, fec and nack bitrate sums up to our estimate.
1082     if (it->second->send) {
1083       *send_bandwidth_estimate = it->second->send_bandwidth_;
1084     } else {
1085       *send_bandwidth_estimate = 0;
1086     }
1087     return 0;
1088   }
1089   WEBRTC_FUNC_CONST(GetEstimatedReceiveBandwidth, (const int channel,
1090       unsigned int* receive_bandwidth_estimate)) {
1091     WEBRTC_CHECK_CHANNEL(channel);
1092     std::map<int, Channel*>::const_iterator it = channels_.find(channel);
1093     if (it->second->receive_) {
1094     // For simplicity, assume all channels receive half of max send rate.
1095       *receive_bandwidth_estimate = it->second->receive_bandwidth_;
1096     } else {
1097       *receive_bandwidth_estimate = 0;
1098     }
1099     return 0;
1100   }
1101   WEBRTC_STUB(RegisterSendChannelRtcpStatisticsCallback,
1102                     (int, webrtc::RtcpStatisticsCallback*));
1103   WEBRTC_STUB(DeregisterSendChannelRtcpStatisticsCallback,
1104                     (int, webrtc::RtcpStatisticsCallback*));
1105   WEBRTC_STUB(RegisterReceiveChannelRtcpStatisticsCallback,
1106                     (int, webrtc::RtcpStatisticsCallback*));
1107   WEBRTC_STUB(DeregisterReceiveChannelRtcpStatisticsCallback,
1108                     (int, webrtc::RtcpStatisticsCallback*));
1109   WEBRTC_STUB(RegisterSendChannelRtpStatisticsCallback,
1110                     (int, webrtc::StreamDataCountersCallback*));
1111   WEBRTC_STUB(DeregisterSendChannelRtpStatisticsCallback,
1112                     (int, webrtc::StreamDataCountersCallback*));
1113   WEBRTC_STUB(RegisterReceiveChannelRtpStatisticsCallback,
1114                     (int, webrtc::StreamDataCountersCallback*));
1115   WEBRTC_STUB(DeregisterReceiveChannelRtpStatisticsCallback,
1116                     (int, webrtc::StreamDataCountersCallback*));
1117   WEBRTC_STUB(RegisterSendBitrateObserver,
1118                     (int, webrtc::BitrateStatisticsObserver*));
1119   WEBRTC_STUB(DeregisterSendBitrateObserver,
1120                     (int, webrtc::BitrateStatisticsObserver*));
1121   WEBRTC_STUB(RegisterSendFrameCountObserver,
1122                     (int, webrtc::FrameCountObserver*));
1123   WEBRTC_STUB(DeregisterSendFrameCountObserver,
1124                     (int, webrtc::FrameCountObserver*));
1125
1126   WEBRTC_STUB(StartRTPDump, (const int, const char*, webrtc::RTPDirections));
1127   WEBRTC_STUB(StopRTPDump, (const int, webrtc::RTPDirections));
1128   WEBRTC_STUB(RegisterRTPObserver, (const int, webrtc::ViERTPObserver&));
1129   WEBRTC_STUB(DeregisterRTPObserver, (const int));
1130   WEBRTC_STUB(RegisterRTCPObserver, (const int, webrtc::ViERTCPObserver&));
1131   WEBRTC_STUB(DeregisterRTCPObserver, (const int));
1132
1133   // webrtc::ViEImageProcess
1134   WEBRTC_STUB(RegisterCaptureEffectFilter, (const int,
1135       webrtc::ViEEffectFilter&));
1136   WEBRTC_STUB(DeregisterCaptureEffectFilter, (const int));
1137   WEBRTC_STUB(RegisterSendEffectFilter, (const int,
1138       webrtc::ViEEffectFilter&));
1139   WEBRTC_STUB(DeregisterSendEffectFilter, (const int));
1140   WEBRTC_STUB(RegisterRenderEffectFilter, (const int,
1141       webrtc::ViEEffectFilter&));
1142   WEBRTC_STUB(DeregisterRenderEffectFilter, (const int));
1143   WEBRTC_STUB(EnableDeflickering, (const int, const bool));
1144   WEBRTC_FUNC(EnableDenoising, (const int capture_id, const bool denoising)) {
1145     WEBRTC_CHECK_CAPTURER(capture_id);
1146     capturers_[capture_id]->set_denoising(denoising);
1147     return 0;
1148   }
1149   WEBRTC_STUB(EnableColorEnhancement, (const int, const bool));
1150   WEBRTC_VOID_STUB(RegisterPreEncodeCallback,
1151                    (int, webrtc::I420FrameCallback*));
1152   WEBRTC_VOID_STUB(DeRegisterPreEncodeCallback, (int));
1153   WEBRTC_VOID_STUB(RegisterPreRenderCallback,
1154                    (int, webrtc::I420FrameCallback*));
1155   WEBRTC_VOID_STUB(DeRegisterPreRenderCallback, (int));
1156   // webrtc::ViEExternalCodec
1157   WEBRTC_FUNC(RegisterExternalSendCodec,
1158       (const int channel, const unsigned char pl_type, webrtc::VideoEncoder*,
1159           bool)) {
1160     WEBRTC_CHECK_CHANNEL(channel);
1161     channels_[channel]->ext_encoder_pl_types_.insert(pl_type);
1162     return 0;
1163   }
1164   WEBRTC_FUNC(DeRegisterExternalSendCodec,
1165       (const int channel, const unsigned char pl_type)) {
1166     WEBRTC_CHECK_CHANNEL(channel);
1167     channels_[channel]->ext_encoder_pl_types_.erase(pl_type);
1168     return 0;
1169   }
1170   WEBRTC_FUNC(RegisterExternalReceiveCodec,
1171       (const int channel, const unsigned int pl_type, webrtc::VideoDecoder*,
1172        bool, int)) {
1173     WEBRTC_CHECK_CHANNEL(channel);
1174     channels_[channel]->ext_decoder_pl_types_.insert(pl_type);
1175     return 0;
1176   }
1177   WEBRTC_FUNC(DeRegisterExternalReceiveCodec,
1178       (const int channel, const unsigned char pl_type)) {
1179     WEBRTC_CHECK_CHANNEL(channel);
1180     channels_[channel]->ext_decoder_pl_types_.erase(pl_type);
1181     return 0;
1182   }
1183
1184  private:
1185   bool IsChannelId(int id) const {
1186     return (id >= kViEChannelIdBase && id <= kViEChannelIdMax);
1187   }
1188   bool IsCapturerId(int id) const {
1189     return (id >= kViECaptureIdBase && id <= kViECaptureIdMax);
1190   }
1191
1192   bool inited_;
1193   int last_channel_;
1194   std::map<int, Channel*> channels_;
1195   bool fail_create_channel_;
1196   int last_capturer_;
1197   std::map<int, Capturer*> capturers_;
1198   bool fail_alloc_capturer_;
1199   const cricket::VideoCodec* const* codecs_;
1200   int num_codecs_;
1201   int num_set_send_codecs_;  // how many times we call SetSendCodec().
1202 };
1203
1204 }  // namespace cricket
1205
1206 #endif  // TALK_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_