~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/libjingle/talk/session/phone/fakewebrtcvideoengine.h

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_SESSION_PHONE_FAKEWEBRTCVIDEOENGINE_H_
 
29
#define TALK_SESSION_PHONE_FAKEWEBRTCVIDEOENGINE_H_
 
30
 
 
31
#include <list>
 
32
#include <map>
 
33
#include <vector>
 
34
 
 
35
#include "talk/base/basictypes.h"
 
36
#include "talk/base/stringutils.h"
 
37
#include "talk/session/phone/codec.h"
 
38
#include "talk/session/phone/fakewebrtccommon.h"
 
39
#include "talk/session/phone/webrtcvie.h"
 
40
 
 
41
namespace webrtc {
 
42
 
 
43
bool operator==(const webrtc::VideoCodec& c1, const webrtc::VideoCodec& c2) {
 
44
  return memcmp(&c1, &c2, sizeof(c1)) == 0;
 
45
}
 
46
 
 
47
}
 
48
 
 
49
namespace cricket {
 
50
 
 
51
#define WEBRTC_CHECK_CAPTURER(capturer) \
 
52
  if (capturers_.find(capturer) == capturers_.end()) return -1;
 
53
 
 
54
#define WEBRTC_ASSERT_CAPTURER(capturer) \
 
55
  ASSERT(capturers_.find(capturer) != capturers_.end());
 
56
 
 
57
static const int kMinVideoBitrate = 100;
 
58
static const int kStartVideoBitrate = 300;
 
59
static const int kMaxVideoBitrate = 1000;
 
60
 
 
61
// WebRtc channel id and capture id share the same number space.
 
62
// This is how AddRenderer(renderId, ...) is able to tell if it is adding a
 
63
// renderer for a channel or it is adding a renderer for a capturer.
 
64
static const int kViEChannelIdBase = 0;
 
65
static const int kViEChannelIdMax = 1000;
 
66
static const int kViECaptureIdBase = 10000;  // Make sure there is a gap.
 
67
static const int kViECaptureIdMax = 11000;
 
68
 
 
69
class FakeWebRtcVideoEngine
 
70
    : public webrtc::ViEBase,
 
71
      public webrtc::ViECodec,
 
72
      public webrtc::ViECapture,
 
73
      public webrtc::ViENetwork,
 
74
      public webrtc::ViERender,
 
75
      public webrtc::ViERTP_RTCP,
 
76
      public webrtc::ViEImageProcess {
 
77
 public:
 
78
  struct Channel {
 
79
    Channel()
 
80
        : capture_id_(-1),
 
81
          original_channel_id_(-1),
 
82
          has_renderer_(false),
 
83
          render_started_(false),
 
84
          send(false),
 
85
          rtcp_status_(webrtc::kRtcpNone),
 
86
          key_frame_request_method_(webrtc::kViEKeyFrameRequestNone),
 
87
          tmmbr_(false),
 
88
          remb_send_(false),
 
89
          remb_(false),
 
90
          nack_(false),
 
91
          hybrid_nack_fec_(false) {
 
92
      ssrcs_[0] = 0;  // default ssrc.
 
93
      memset(&send_codec, 0, sizeof(send_codec));
 
94
    }
 
95
    int capture_id_;
 
96
    int original_channel_id_;
 
97
    bool has_renderer_;
 
98
    bool render_started_;
 
99
    bool send;
 
100
    std::map<int, int> ssrcs_;
 
101
    std::string cname_;
 
102
    webrtc::ViERTCPMode rtcp_status_;
 
103
    webrtc::ViEKeyFrameRequestMethod key_frame_request_method_;
 
104
    bool tmmbr_;
 
105
    bool remb_send_;  // This channel send REMB packets.
 
106
    bool remb_;  // This channel report BWE using remb.
 
107
    bool nack_;
 
108
    bool hybrid_nack_fec_;
 
109
    std::vector<webrtc::VideoCodec> recv_codecs;
 
110
    webrtc::VideoCodec send_codec;
 
111
  };
 
112
  class Capturer : public webrtc::ViEExternalCapture {
 
113
   public:
 
114
    Capturer() : channel_id_(-1), denoising_(false) { }
 
115
    int channel_id() const { return channel_id_; }
 
116
    void set_channel_id(int channel_id) { channel_id_ = channel_id; }
 
117
    bool denoising() const { return denoising_; }
 
118
    void set_denoising(bool denoising) { denoising_ = denoising; }
 
119
 
 
120
    // From ViEExternalCapture
 
121
    virtual int IncomingFrame(unsigned char* videoFrame,
 
122
                              unsigned int videoFrameLength,
 
123
                              unsigned short width,
 
124
                              unsigned short height,
 
125
                              webrtc::RawVideoType videoType,
 
126
                              unsigned long long captureTime) {
 
127
      return 0;
 
128
    }
 
129
    virtual int IncomingFrameI420(
 
130
        const webrtc::ViEVideoFrameI420& video_frame,
 
131
        unsigned long long captureTime) {
 
132
      return 0;
 
133
    }
 
134
 
 
135
   private:
 
136
    int channel_id_;
 
137
    bool denoising_;
 
138
  };
 
139
 
 
140
  FakeWebRtcVideoEngine(const cricket::VideoCodec* const* codecs,
 
141
                        int num_codecs)
 
142
      : inited_(false),
 
143
        last_channel_(kViEChannelIdBase - 1),
 
144
        fail_create_channel_(false),
 
145
        last_capturer_(kViECaptureIdBase - 1),
 
146
        fail_alloc_capturer_(false),
 
147
        codecs_(codecs),
 
148
        num_codecs_(num_codecs) {
 
149
  }
 
150
 
 
151
  ~FakeWebRtcVideoEngine() {
 
152
    ASSERT(0 == channels_.size());
 
153
    ASSERT(0 == capturers_.size());
 
154
  }
 
155
  bool IsInited() const { return inited_; }
 
156
 
 
157
  int GetLastChannel() const { return last_channel_; }
 
158
  int GetNumChannels() const { return channels_.size(); }
 
159
  bool IsChannel(int channel) const {
 
160
    return (channels_.find(channel) != channels_.end());
 
161
  }
 
162
  void set_fail_create_channel(bool fail_create_channel) {
 
163
    fail_create_channel_ = fail_create_channel;
 
164
  }
 
165
 
 
166
  int GetLastCapturer() const { return last_capturer_; }
 
167
  int GetNumCapturers() const { return capturers_.size(); }
 
168
  void set_fail_alloc_capturer(bool fail_alloc_capturer) {
 
169
    fail_alloc_capturer_ = fail_alloc_capturer;
 
170
  }
 
171
 
 
172
  int GetCaptureId(int channel) const {
 
173
    WEBRTC_ASSERT_CHANNEL(channel);
 
174
    return channels_.find(channel)->second->capture_id_;
 
175
  }
 
176
  int GetOriginalChannelId(int channel) const {
 
177
    WEBRTC_ASSERT_CHANNEL(channel);
 
178
    return channels_.find(channel)->second->original_channel_id_;
 
179
  }
 
180
  bool GetHasRenderer(int channel) const {
 
181
    WEBRTC_ASSERT_CHANNEL(channel);
 
182
    return channels_.find(channel)->second->has_renderer_;
 
183
  }
 
184
  bool GetRenderStarted(int channel) const {
 
185
    WEBRTC_ASSERT_CHANNEL(channel);
 
186
    return channels_.find(channel)->second->render_started_;
 
187
  }
 
188
  bool GetSend(int channel) const {
 
189
    WEBRTC_ASSERT_CHANNEL(channel);
 
190
    return channels_.find(channel)->second->send;
 
191
  }
 
192
  int GetCaptureChannelId(int capture_id) const {
 
193
    WEBRTC_ASSERT_CAPTURER(capture_id);
 
194
    return capturers_.find(capture_id)->second->channel_id();
 
195
  }
 
196
  bool GetCaptureDenoising(int capture_id) const {
 
197
    WEBRTC_ASSERT_CAPTURER(capture_id);
 
198
    return capturers_.find(capture_id)->second->denoising();
 
199
  }
 
200
  webrtc::ViERTCPMode GetRtcpStatus(int channel) const {
 
201
    WEBRTC_ASSERT_CHANNEL(channel);
 
202
    return channels_.find(channel)->second->rtcp_status_;
 
203
  }
 
204
  webrtc::ViEKeyFrameRequestMethod GetKeyFrameRequestMethod(int channel) const {
 
205
    WEBRTC_ASSERT_CHANNEL(channel);
 
206
    return channels_.find(channel)->second->key_frame_request_method_;
 
207
  }
 
208
  bool GetTmmbrStatus(int channel) const {
 
209
    WEBRTC_ASSERT_CHANNEL(channel);
 
210
    return channels_.find(channel)->second->tmmbr_;
 
211
  }
 
212
  bool GetRembStatus(int channel) const {
 
213
    WEBRTC_ASSERT_CHANNEL(channel);
 
214
    return channels_.find(channel)->second->remb_;
 
215
  }
 
216
  bool GetRembStatusSend(int channel) const {
 
217
    WEBRTC_ASSERT_CHANNEL(channel);
 
218
    return channels_.find(channel)->second->remb_send_;
 
219
  }
 
220
  bool GetNackStatus(int channel) const {
 
221
    WEBRTC_ASSERT_CHANNEL(channel);
 
222
    return channels_.find(channel)->second->nack_;
 
223
  }
 
224
  bool GetHybridNackFecStatus(int channel) const {
 
225
    WEBRTC_ASSERT_CHANNEL(channel);
 
226
    return channels_.find(channel)->second->hybrid_nack_fec_;
 
227
  }
 
228
  int GetNumSsrcs(int channel) const {
 
229
    WEBRTC_ASSERT_CHANNEL(channel);
 
230
    return channels_.find(channel)->second->ssrcs_.size();
 
231
  }
 
232
  int GetSimulcastSsrc(int channel,
 
233
                       int simulcast_idx) const {
 
234
    WEBRTC_ASSERT_CHANNEL(channel);
 
235
    if (channels_.find(channel)->second->ssrcs_.find(simulcast_idx) ==
 
236
        channels_.find(channel)->second->ssrcs_.end()) {
 
237
      return -1;
 
238
    }
 
239
    return channels_.find(channel)->second->ssrcs_[simulcast_idx];
 
240
  }
 
241
  bool ReceiveCodecRegistered(int channel,
 
242
                              const webrtc::VideoCodec& codec) const {
 
243
    WEBRTC_ASSERT_CHANNEL(channel);
 
244
    const std::vector<webrtc::VideoCodec>& codecs =
 
245
      channels_.find(channel)->second->recv_codecs;
 
246
    return std::find(codecs.begin(), codecs.end(), codec) != codecs.end();
 
247
  };
 
248
 
 
249
  WEBRTC_STUB(Release, ());
 
250
 
 
251
  // webrtc::ViEBase
 
252
  WEBRTC_FUNC(Init, ()) {
 
253
    inited_ = true;
 
254
    return 0;
 
255
  };
 
256
  WEBRTC_STUB(SetVoiceEngine, (webrtc::VoiceEngine*));
 
257
  WEBRTC_FUNC(CreateChannel, (int& channel)) {  // NOLINT
 
258
    if (fail_create_channel_) {
 
259
      return -1;
 
260
    }
 
261
    if (kViEChannelIdMax == last_channel_) {
 
262
      return -1;
 
263
    }
 
264
    Channel* ch = new Channel();
 
265
    channels_[++last_channel_] = ch;
 
266
    channel = last_channel_;
 
267
    return 0;
 
268
  };
 
269
  WEBRTC_FUNC(CreateChannel, (int& channel, int original_channel)) {
 
270
    WEBRTC_CHECK_CHANNEL(original_channel);
 
271
    if (CreateChannel(channel) != 0) {
 
272
      return -1;
 
273
    }
 
274
    channels_[channel]->original_channel_id_ = original_channel;
 
275
    return 0;
 
276
  }
 
277
  WEBRTC_FUNC(CreateReceiveChannel, (int& channel, int original_channel)) {
 
278
    return CreateChannel(channel, original_channel);
 
279
  }
 
280
  WEBRTC_FUNC(DeleteChannel, (const int channel)) {
 
281
    WEBRTC_CHECK_CHANNEL(channel);
 
282
    delete channels_[channel];
 
283
    channels_.erase(channel);
 
284
    return 0;
 
285
  }
 
286
  WEBRTC_STUB(ConnectAudioChannel, (const int, const int));
 
287
  WEBRTC_STUB(DisconnectAudioChannel, (const int));
 
288
  WEBRTC_FUNC(StartSend, (const int channel)) {
 
289
    WEBRTC_CHECK_CHANNEL(channel);
 
290
    channels_[channel]->send = true;
 
291
    return 0;
 
292
  }
 
293
  WEBRTC_FUNC(StopSend, (const int channel)) {
 
294
    WEBRTC_CHECK_CHANNEL(channel);
 
295
    channels_[channel]->send = false;
 
296
    return 0;
 
297
  }
 
298
  WEBRTC_STUB(StartReceive, (const int));
 
299
  WEBRTC_STUB(StopReceive, (const int));
 
300
  WEBRTC_STUB(RegisterObserver, (webrtc::ViEBaseObserver&));
 
301
  WEBRTC_STUB(DeregisterObserver, ());
 
302
  WEBRTC_STUB(GetVersion, (char version[1024]));
 
303
  WEBRTC_STUB(LastError, ());
 
304
 
 
305
  // webrtc::ViECodec
 
306
  WEBRTC_FUNC(NumberOfCodecs, ()) const {
 
307
    return num_codecs_;
 
308
  };
 
309
  WEBRTC_FUNC(GetCodec, (const unsigned char list_number,
 
310
                         webrtc::VideoCodec& out_codec)) const {
 
311
    if (list_number >= NumberOfCodecs()) {
 
312
      return -1;
 
313
    }
 
314
    memset(&out_codec, 0, sizeof(out_codec));
 
315
    const cricket::VideoCodec& c(*codecs_[list_number]);
 
316
    if ("I420" == c.name) {
 
317
      out_codec.codecType = webrtc::kVideoCodecI420;
 
318
    } else if ("VP8" == c.name) {
 
319
      out_codec.codecType = webrtc::kVideoCodecVP8;
 
320
    } else if ("red" == c.name) {
 
321
      out_codec.codecType = webrtc::kVideoCodecRED;
 
322
    } else if ("ulpfec" == c.name) {
 
323
      out_codec.codecType = webrtc::kVideoCodecULPFEC;
 
324
    } else {
 
325
      out_codec.codecType = webrtc::kVideoCodecUnknown;
 
326
    }
 
327
    talk_base::strcpyn(out_codec.plName, sizeof(out_codec.plName),
 
328
                       c.name.c_str());
 
329
    out_codec.plType = c.id;
 
330
    out_codec.width = c.width;
 
331
    out_codec.height = c.height;
 
332
    out_codec.startBitrate = kStartVideoBitrate;
 
333
    out_codec.maxBitrate = kMaxVideoBitrate;
 
334
    out_codec.minBitrate = kMinVideoBitrate;
 
335
    out_codec.maxFramerate = c.framerate;
 
336
    return 0;
 
337
  };
 
338
  WEBRTC_FUNC(SetSendCodec, (const int channel,
 
339
                             const webrtc::VideoCodec& codec)) {
 
340
    WEBRTC_CHECK_CHANNEL(channel);
 
341
    channels_[channel]->send_codec = codec;
 
342
    return 0;
 
343
  };
 
344
  WEBRTC_FUNC(GetSendCodec, (const int channel,
 
345
                             webrtc::VideoCodec& codec)) const {  // NOLINT
 
346
    WEBRTC_CHECK_CHANNEL(channel);
 
347
    codec = channels_.find(channel)->second->send_codec;
 
348
    return 0;
 
349
  };
 
350
  WEBRTC_FUNC(SetReceiveCodec, (const int channel,
 
351
                                const webrtc::VideoCodec& codec)) {  // NOLINT
 
352
    WEBRTC_CHECK_CHANNEL(channel);
 
353
    channels_[channel]->recv_codecs.push_back(codec);
 
354
    return 0;
 
355
  };
 
356
  WEBRTC_STUB_CONST(GetReceiveCodec, (const int, webrtc::VideoCodec&));
 
357
  WEBRTC_STUB_CONST(GetCodecConfigParameters, (const int,
 
358
      unsigned char*, unsigned char&));
 
359
  WEBRTC_STUB(SetImageScaleStatus, (const int, const bool));
 
360
  WEBRTC_STUB_CONST(GetSendCodecStastistics, (const int,
 
361
      unsigned int&, unsigned int&));
 
362
  WEBRTC_STUB_CONST(GetReceiveCodecStastistics, (const int,
 
363
      unsigned int&, unsigned int&));
 
364
  WEBRTC_STUB_CONST(GetCodecTargetBitrate, (const int, unsigned int*));
 
365
  virtual unsigned int GetDiscardedPackets(const int channel) const {
 
366
    return 0;
 
367
  }
 
368
 
 
369
  WEBRTC_STUB(SetKeyFrameRequestCallbackStatus, (const int, const bool));
 
370
  WEBRTC_STUB(SetSignalKeyPacketLossStatus, (const int, const bool,
 
371
      const bool));
 
372
  WEBRTC_STUB(RegisterEncoderObserver, (const int,
 
373
      webrtc::ViEEncoderObserver&));
 
374
  WEBRTC_STUB(DeregisterEncoderObserver, (const int));
 
375
  WEBRTC_STUB(RegisterDecoderObserver, (const int,
 
376
      webrtc::ViEDecoderObserver&));
 
377
  WEBRTC_STUB(DeregisterDecoderObserver, (const int));
 
378
  WEBRTC_STUB(SendKeyFrame, (const int));
 
379
  WEBRTC_STUB(WaitForFirstKeyFrame, (const int, const bool));
 
380
  WEBRTC_STUB(SetInverseH263Logic, (int, bool));
 
381
 
 
382
  // webrtc::ViECapture
 
383
  WEBRTC_STUB(NumberOfCaptureDevices, ());
 
384
  WEBRTC_STUB(GetCaptureDevice, (unsigned int, char*,
 
385
      const unsigned int, char*, const unsigned int));
 
386
  WEBRTC_STUB(AllocateCaptureDevice, (const char*, const unsigned int, int&));
 
387
  WEBRTC_FUNC(AllocateExternalCaptureDevice,
 
388
              (int& capture_id, webrtc::ViEExternalCapture*& capture)) {
 
389
    if (fail_alloc_capturer_) {
 
390
      return -1;
 
391
    }
 
392
    if (kViECaptureIdMax == last_capturer_) {
 
393
      return -1;
 
394
    }
 
395
    Capturer* cap = new Capturer();
 
396
    capturers_[++last_capturer_] = cap;
 
397
    capture_id = last_capturer_;
 
398
    capture = cap;
 
399
    return 0;
 
400
  }
 
401
  WEBRTC_STUB(AllocateCaptureDevice, (webrtc::VideoCaptureModule&, int&));
 
402
  WEBRTC_FUNC(ReleaseCaptureDevice, (const int capture_id)) {
 
403
    WEBRTC_CHECK_CAPTURER(capture_id);
 
404
    delete capturers_[capture_id];
 
405
    capturers_.erase(capture_id);
 
406
    return 0;
 
407
  }
 
408
  WEBRTC_FUNC(ConnectCaptureDevice, (const int capture_id,
 
409
                                     const int channel)) {
 
410
    WEBRTC_CHECK_CHANNEL(channel);
 
411
    WEBRTC_CHECK_CAPTURER(capture_id);
 
412
    channels_[channel]->capture_id_ = capture_id;
 
413
    capturers_[capture_id]->set_channel_id(channel);
 
414
    return 0;
 
415
  }
 
416
  WEBRTC_FUNC(DisconnectCaptureDevice, (const int channel)) {
 
417
    WEBRTC_CHECK_CHANNEL(channel);
 
418
    int capture_id = channels_[channel]->capture_id_;
 
419
    WEBRTC_CHECK_CAPTURER(capture_id);
 
420
    channels_[channel]->capture_id_ = -1;
 
421
    capturers_[capture_id]->set_channel_id(-1);
 
422
    return 0;
 
423
  }
 
424
  WEBRTC_STUB(StartCapture, (const int, const webrtc::CaptureCapability&));
 
425
  WEBRTC_STUB(StopCapture, (const int));
 
426
  WEBRTC_STUB(SetRotateCapturedFrames, (const int,
 
427
      const webrtc::RotateCapturedFrame));
 
428
  WEBRTC_STUB(SetCaptureDelay, (const int, const unsigned int));
 
429
  WEBRTC_STUB(NumberOfCapabilities, (const char*, const unsigned int));
 
430
  WEBRTC_STUB(GetCaptureCapability, (const char*, const unsigned int,
 
431
      const unsigned int, webrtc::CaptureCapability&));
 
432
  WEBRTC_STUB(ShowCaptureSettingsDialogBox, (const char*, const unsigned int,
 
433
      const char*, void*, const unsigned int, const unsigned int));
 
434
  WEBRTC_STUB(GetOrientation, (const char*, webrtc::RotateCapturedFrame&));
 
435
  WEBRTC_STUB(EnableBrightnessAlarm, (const int, const bool));
 
436
  WEBRTC_STUB(RegisterObserver, (const int, webrtc::ViECaptureObserver&));
 
437
  WEBRTC_STUB(DeregisterObserver, (const int));
 
438
 
 
439
  // webrtc::ViENetwork
 
440
  WEBRTC_STUB(SetLocalReceiver, (const int, const unsigned short,
 
441
      const unsigned short, const char*));
 
442
  WEBRTC_STUB(GetLocalReceiver, (const int, unsigned short&,
 
443
      unsigned short&, char*));
 
444
  WEBRTC_STUB(SetSendDestination, (const int, const char*, const unsigned short,
 
445
      const unsigned short, const unsigned short, const unsigned short));
 
446
  WEBRTC_STUB(GetSendDestination, (const int, char*, unsigned short&,
 
447
      unsigned short&, unsigned short&, unsigned short&));
 
448
  WEBRTC_STUB(RegisterSendTransport, (const int, webrtc::Transport&));
 
449
  WEBRTC_STUB(DeregisterSendTransport, (const int));
 
450
  WEBRTC_STUB(ReceivedRTPPacket, (const int, const void*, const int));
 
451
  WEBRTC_STUB(ReceivedRTCPPacket, (const int, const void*, const int));
 
452
  WEBRTC_STUB(GetSourceInfo, (const int, unsigned short&, unsigned short&,
 
453
                              char*, unsigned int));
 
454
  WEBRTC_STUB(GetLocalIP, (char*, bool));
 
455
  WEBRTC_STUB(EnableIPv6, (int));
 
456
  // Not using WEBRTC_STUB due to bool return value
 
457
  virtual bool IsIPv6Enabled(int channel) { return true; }
 
458
  WEBRTC_STUB(SetSourceFilter, (const int, const unsigned short,
 
459
      const unsigned short, const char*));
 
460
  WEBRTC_STUB(GetSourceFilter, (const int, unsigned short&,
 
461
      unsigned short&, char*));
 
462
  WEBRTC_STUB(SetSendToS, (const int, const int, const bool));
 
463
  WEBRTC_STUB(GetSendToS, (const int, int&, bool&));
 
464
  WEBRTC_STUB(SetSendGQoS, (const int, const bool, const int, const int));
 
465
  WEBRTC_STUB(GetSendGQoS, (const int, bool&, int&, int&));
 
466
  WEBRTC_STUB(SetMTU, (int, unsigned int));
 
467
  WEBRTC_STUB(SetPacketTimeoutNotification, (const int, bool, int));
 
468
  WEBRTC_STUB(RegisterObserver, (const int, webrtc::ViENetworkObserver&));
 
469
  WEBRTC_STUB(SetPeriodicDeadOrAliveStatus, (const int, const bool,
 
470
    const unsigned int));
 
471
  WEBRTC_STUB(SendUDPPacket, (const int, const void*, const unsigned int,
 
472
      int&, bool));
 
473
 
 
474
  // webrtc::ViERender
 
475
  WEBRTC_STUB(RegisterVideoRenderModule, (webrtc::VideoRender&));
 
476
  WEBRTC_STUB(DeRegisterVideoRenderModule, (webrtc::VideoRender&));
 
477
  WEBRTC_STUB(AddRenderer, (const int, void*, const unsigned int, const float,
 
478
      const float, const float, const float));
 
479
  WEBRTC_FUNC(RemoveRenderer, (const int render_id)) {
 
480
    if (IsCapturerId(render_id)) {
 
481
      WEBRTC_CHECK_CAPTURER(render_id);
 
482
      return 0;
 
483
    } else if (IsChannelId(render_id)) {
 
484
      WEBRTC_CHECK_CHANNEL(render_id);
 
485
      channels_[render_id]->has_renderer_ = false;
 
486
      return 0;
 
487
    }
 
488
    return -1;
 
489
  }
 
490
  WEBRTC_FUNC(StartRender, (const int render_id)) {
 
491
    if (IsCapturerId(render_id)) {
 
492
      WEBRTC_CHECK_CAPTURER(render_id);
 
493
      return 0;
 
494
    } else if (IsChannelId(render_id)) {
 
495
      WEBRTC_CHECK_CHANNEL(render_id);
 
496
      channels_[render_id]->render_started_ = true;
 
497
      return 0;
 
498
    }
 
499
    return -1;
 
500
  }
 
501
  WEBRTC_FUNC(StopRender, (const int render_id)) {
 
502
    if (IsCapturerId(render_id)) {
 
503
      WEBRTC_CHECK_CAPTURER(render_id);
 
504
      return 0;
 
505
    } else if (IsChannelId(render_id)) {
 
506
      WEBRTC_CHECK_CHANNEL(render_id);
 
507
      channels_[render_id]->render_started_ = false;
 
508
      return 0;
 
509
    }
 
510
    return -1;
 
511
  }
 
512
  WEBRTC_STUB(ConfigureRender, (int, const unsigned int, const float,
 
513
      const float, const float, const float));
 
514
  WEBRTC_STUB(MirrorRenderStream, (const int, const bool, const bool,
 
515
      const bool));
 
516
  WEBRTC_FUNC(AddRenderer, (const int render_id,
 
517
                            webrtc::RawVideoType video_type,
 
518
                            webrtc::ExternalRenderer* renderer)) {
 
519
    if (IsCapturerId(render_id)) {
 
520
      WEBRTC_CHECK_CAPTURER(render_id);
 
521
      return 0;
 
522
    } else if (IsChannelId(render_id)) {
 
523
      WEBRTC_CHECK_CHANNEL(render_id);
 
524
      channels_[render_id]->has_renderer_ = true;
 
525
      return 0;
 
526
    }
 
527
    return -1;
 
528
  }
 
529
 
 
530
  // webrtc::ViERTP_RTCP
 
531
  WEBRTC_FUNC(SetLocalSSRC, (const int channel,
 
532
                             const unsigned int ssrc,
 
533
                             const webrtc::StreamType usage,
 
534
                             const unsigned char simulcast_idx)) {
 
535
    // default simulcast_idx is 0.
 
536
    WEBRTC_CHECK_CHANNEL(channel);
 
537
    channels_[channel]->ssrcs_[simulcast_idx] = ssrc;
 
538
    return 0;
 
539
  }
 
540
  WEBRTC_STUB_CONST(SetRemoteSSRCType, (const int,
 
541
        const webrtc::StreamType, const unsigned int));
 
542
 
 
543
  WEBRTC_FUNC_CONST(GetLocalSSRC, (const int channel,
 
544
                                   unsigned int& ssrc)) {
 
545
    // ssrcs_[0] is the default local ssrc.
 
546
    WEBRTC_CHECK_CHANNEL(channel);
 
547
    ssrc = channels_.find(channel)->second->ssrcs_[0];
 
548
    return 0;
 
549
  }
 
550
  WEBRTC_STUB_CONST(GetRemoteSSRC, (const int, unsigned int&));
 
551
      WEBRTC_STUB_CONST(GetRemoteCSRCs, (const int, unsigned int*));
 
552
  WEBRTC_STUB(SetStartSequenceNumber, (const int, unsigned short));
 
553
  WEBRTC_FUNC(SetRTCPStatus,
 
554
              (const int channel, const webrtc::ViERTCPMode mode)) {
 
555
    WEBRTC_CHECK_CHANNEL(channel);
 
556
    channels_[channel]->rtcp_status_ = mode;
 
557
    return 0;
 
558
  }
 
559
  WEBRTC_STUB_CONST(GetRTCPStatus, (const int, webrtc::ViERTCPMode&));
 
560
  WEBRTC_FUNC(SetRTCPCName, (const int channel,
 
561
                             const char rtcp_cname[KMaxRTCPCNameLength])) {
 
562
    WEBRTC_CHECK_CHANNEL(channel);
 
563
    channels_[channel]->cname_.assign(rtcp_cname);
 
564
    return 0;
 
565
  }
 
566
  WEBRTC_FUNC_CONST(GetRTCPCName, (const int channel,
 
567
                                   char rtcp_cname[KMaxRTCPCNameLength])) {
 
568
    WEBRTC_CHECK_CHANNEL(channel);
 
569
    talk_base::strcpyn(rtcp_cname, KMaxRTCPCNameLength,
 
570
                       channels_.find(channel)->second->cname_.c_str());
 
571
    return 0;
 
572
  }
 
573
  WEBRTC_STUB_CONST(GetRemoteRTCPCName, (const int, char*));
 
574
  WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (const int, const unsigned char,
 
575
      unsigned int, const char*, unsigned short));
 
576
  WEBRTC_FUNC(SetNACKStatus, (const int channel, const bool enable)) {
 
577
    WEBRTC_CHECK_CHANNEL(channel);
 
578
    channels_[channel]->nack_ = enable;
 
579
    channels_[channel]->hybrid_nack_fec_ = false;
 
580
    return 0;
 
581
  }
 
582
  WEBRTC_STUB(SetFECStatus, (const int, const bool, const unsigned char,
 
583
      const unsigned char));
 
584
  WEBRTC_FUNC(SetHybridNACKFECStatus, (const int channel, const bool enable,
 
585
      const unsigned char red_type, const unsigned char fec_type)) {
 
586
    WEBRTC_CHECK_CHANNEL(channel);
 
587
    if (red_type == fec_type ||
 
588
        red_type == channels_[channel]->send_codec.plType ||
 
589
        fec_type == channels_[channel]->send_codec.plType) {
 
590
      return -1;
 
591
    }
 
592
    channels_[channel]->nack_ = false;
 
593
    channels_[channel]->hybrid_nack_fec_ = true;
 
594
    return 0;
 
595
  }
 
596
  WEBRTC_FUNC(SetKeyFrameRequestMethod,
 
597
              (const int channel,
 
598
               const webrtc::ViEKeyFrameRequestMethod method)) {
 
599
    WEBRTC_CHECK_CHANNEL(channel);
 
600
    channels_[channel]->key_frame_request_method_ = method;
 
601
    return 0;
 
602
  }
 
603
  WEBRTC_FUNC(SetRembStatus, (int channel, bool send, bool receive)) {
 
604
    WEBRTC_CHECK_CHANNEL(channel);
 
605
    channels_[channel]->remb_send_ = send;
 
606
    channels_[channel]->remb_ = receive;
 
607
    return 0;
 
608
  }
 
609
  WEBRTC_FUNC(SetTMMBRStatus, (const int channel, const bool enable)) {
 
610
    WEBRTC_CHECK_CHANNEL(channel);
 
611
    channels_[channel]->tmmbr_ = enable;
 
612
    return 0;
 
613
  }
 
614
  WEBRTC_STUB_CONST(GetReceivedRTCPStatistics, (const int, unsigned short&,
 
615
      unsigned int&, unsigned int&, unsigned int&, int&));
 
616
  WEBRTC_STUB_CONST(GetSentRTCPStatistics, (const int, unsigned short&,
 
617
      unsigned int&, unsigned int&, unsigned int&, int&));
 
618
  WEBRTC_STUB_CONST(GetRTPStatistics, (const int, unsigned int&, unsigned int&,
 
619
      unsigned int&, unsigned int&));
 
620
  WEBRTC_STUB_CONST(GetBandwidthUsage, (const int, unsigned int&,
 
621
      unsigned int&, unsigned int&, unsigned int&));
 
622
  WEBRTC_STUB_CONST(GetEstimatedSendBandwidth, (const int, unsigned int*));
 
623
  WEBRTC_STUB_CONST(GetEstimatedReceiveBandwidth, (const int, unsigned int*));
 
624
 
 
625
  WEBRTC_STUB(SetRTPKeepAliveStatus, (const int, bool, const int,
 
626
      const unsigned int));
 
627
  WEBRTC_STUB_CONST(GetRTPKeepAliveStatus,
 
628
                    (const int, bool&, int&, unsigned int&));
 
629
  WEBRTC_STUB(StartRTPDump, (const int, const char*, webrtc::RTPDirections));
 
630
  WEBRTC_STUB(StopRTPDump, (const int, webrtc::RTPDirections));
 
631
  WEBRTC_STUB(RegisterRTPObserver, (const int, webrtc::ViERTPObserver&));
 
632
  WEBRTC_STUB(DeregisterRTPObserver, (const int));
 
633
  WEBRTC_STUB(RegisterRTCPObserver, (const int, webrtc::ViERTCPObserver&));
 
634
  WEBRTC_STUB(DeregisterRTCPObserver, (const int));
 
635
 
 
636
  // webrtc::ViEImageProcess
 
637
  WEBRTC_STUB(RegisterCaptureEffectFilter, (const int,
 
638
      webrtc::ViEEffectFilter&));
 
639
  WEBRTC_STUB(DeregisterCaptureEffectFilter, (const int));
 
640
  WEBRTC_STUB(RegisterSendEffectFilter, (const int,
 
641
      webrtc::ViEEffectFilter&));
 
642
  WEBRTC_STUB(DeregisterSendEffectFilter, (const int));
 
643
  WEBRTC_STUB(RegisterRenderEffectFilter, (const int,
 
644
      webrtc::ViEEffectFilter&));
 
645
  WEBRTC_STUB(DeregisterRenderEffectFilter, (const int));
 
646
  WEBRTC_STUB(EnableDeflickering, (const int, const bool));
 
647
  WEBRTC_FUNC(EnableDenoising, (const int capture_id, const bool denoising)) {
 
648
    WEBRTC_CHECK_CAPTURER(capture_id);
 
649
    capturers_[capture_id]->set_denoising(denoising);
 
650
    return 0;
 
651
  }
 
652
  WEBRTC_STUB(EnableColorEnhancement, (const int, const bool));
 
653
 
 
654
 private:
 
655
  bool IsChannelId(int id) const {
 
656
    return (id >= kViEChannelIdBase && id <= kViEChannelIdMax);
 
657
  }
 
658
  bool IsCapturerId(int id) const {
 
659
    return (id >= kViECaptureIdBase && id <= kViECaptureIdMax);
 
660
  }
 
661
 
 
662
  bool inited_;
 
663
  int last_channel_;
 
664
  std::map<int, Channel*> channels_;
 
665
  bool fail_create_channel_;
 
666
  int last_capturer_;
 
667
  std::map<int, Capturer*> capturers_;
 
668
  bool fail_alloc_capturer_;
 
669
  const cricket::VideoCodec* const* codecs_;
 
670
  int num_codecs_;
 
671
};
 
672
 
 
673
}  // namespace cricket
 
674
 
 
675
#endif  // TALK_SESSION_PHONE_FAKEWEBRTCVIDEOENGINE_H_