blob: 440b6ca6580f6ba55d78d59841166b5013c6949d [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
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"
wu@webrtc.org9caf2762013-12-11 18:25:07 +000036#include "talk/base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#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
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044namespace cricket {
45
46#define WEBRTC_CHECK_CAPTURER(capturer) \
47 if (capturers_.find(capturer) == capturers_.end()) return -1;
48
49#define WEBRTC_ASSERT_CAPTURER(capturer) \
50 ASSERT(capturers_.find(capturer) != capturers_.end());
51
52static const int kMinVideoBitrate = 100;
53static const int kStartVideoBitrate = 300;
54static const int kMaxVideoBitrate = 1000;
55
56// WebRtc channel id and capture id share the same number space.
57// This is how AddRenderer(renderId, ...) is able to tell if it is adding a
58// renderer for a channel or it is adding a renderer for a capturer.
59static const int kViEChannelIdBase = 0;
60static const int kViEChannelIdMax = 1000;
61static const int kViECaptureIdBase = 10000; // Make sure there is a gap.
62static const int kViECaptureIdMax = 11000;
63
64// Fake class for mocking out webrtc::VideoDecoder
65class FakeWebRtcVideoDecoder : public webrtc::VideoDecoder {
66 public:
67 FakeWebRtcVideoDecoder()
68 : num_frames_received_(0) {
69 }
70
71 virtual int32 InitDecode(const webrtc::VideoCodec*, int32) {
72 return WEBRTC_VIDEO_CODEC_OK;
73 }
74
75 virtual int32 Decode(
76 const webrtc::EncodedImage&, bool, const webrtc::RTPFragmentationHeader*,
77 const webrtc::CodecSpecificInfo*, int64) {
78 num_frames_received_++;
79 return WEBRTC_VIDEO_CODEC_OK;
80 }
81
82 virtual int32 RegisterDecodeCompleteCallback(
83 webrtc::DecodedImageCallback*) {
84 return WEBRTC_VIDEO_CODEC_OK;
85 }
86
87 virtual int32 Release() {
88 return WEBRTC_VIDEO_CODEC_OK;
89 }
90
91 virtual int32 Reset() {
92 return WEBRTC_VIDEO_CODEC_OK;
93 }
94
95 int GetNumFramesReceived() const {
96 return num_frames_received_;
97 }
98
99 private:
100 int num_frames_received_;
101};
102
103// Fake class for mocking out WebRtcVideoDecoderFactory.
104class FakeWebRtcVideoDecoderFactory : public WebRtcVideoDecoderFactory {
105 public:
106 FakeWebRtcVideoDecoderFactory()
107 : num_created_decoders_(0) {
108 }
109
110 virtual webrtc::VideoDecoder* CreateVideoDecoder(
111 webrtc::VideoCodecType type) {
112 if (supported_codec_types_.count(type) == 0) {
113 return NULL;
114 }
115 FakeWebRtcVideoDecoder* decoder = new FakeWebRtcVideoDecoder();
116 decoders_.push_back(decoder);
117 num_created_decoders_++;
118 return decoder;
119 }
120
121 virtual void DestroyVideoDecoder(webrtc::VideoDecoder* decoder) {
122 decoders_.erase(
123 std::remove(decoders_.begin(), decoders_.end(), decoder),
124 decoders_.end());
125 delete decoder;
126 }
127
128 void AddSupportedVideoCodecType(webrtc::VideoCodecType type) {
129 supported_codec_types_.insert(type);
130 }
131
132 int GetNumCreatedDecoders() {
133 return num_created_decoders_;
134 }
135
136 const std::vector<FakeWebRtcVideoDecoder*>& decoders() {
137 return decoders_;
138 }
139
140 private:
141 std::set<webrtc::VideoCodecType> supported_codec_types_;
142 std::vector<FakeWebRtcVideoDecoder*> decoders_;
143 int num_created_decoders_;
144};
145
146// Fake class for mocking out webrtc::VideoEnoder
147class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder {
148 public:
149 FakeWebRtcVideoEncoder() {}
150
151 virtual int32 InitEncode(const webrtc::VideoCodec* codecSettings,
152 int32 numberOfCores,
153 uint32 maxPayloadSize) {
154 return WEBRTC_VIDEO_CODEC_OK;
155 }
156
157 virtual int32 Encode(
158 const webrtc::I420VideoFrame& inputImage,
159 const webrtc::CodecSpecificInfo* codecSpecificInfo,
160 const std::vector<webrtc::VideoFrameType>* frame_types) {
161 return WEBRTC_VIDEO_CODEC_OK;
162 }
163
164 virtual int32 RegisterEncodeCompleteCallback(
165 webrtc::EncodedImageCallback* callback) {
166 return WEBRTC_VIDEO_CODEC_OK;
167 }
168
169 virtual int32 Release() {
170 return WEBRTC_VIDEO_CODEC_OK;
171 }
172
173 virtual int32 SetChannelParameters(uint32 packetLoss,
174 int rtt) {
175 return WEBRTC_VIDEO_CODEC_OK;
176 }
177
178 virtual int32 SetRates(uint32 newBitRate,
179 uint32 frameRate) {
180 return WEBRTC_VIDEO_CODEC_OK;
181 }
182};
183
184// Fake class for mocking out WebRtcVideoEncoderFactory.
185class FakeWebRtcVideoEncoderFactory : public WebRtcVideoEncoderFactory {
186 public:
187 FakeWebRtcVideoEncoderFactory()
188 : num_created_encoders_(0) {
189 }
190
191 virtual webrtc::VideoEncoder* CreateVideoEncoder(
192 webrtc::VideoCodecType type) {
193 if (supported_codec_types_.count(type) == 0) {
194 return NULL;
195 }
196 FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder();
197 encoders_.push_back(encoder);
198 num_created_encoders_++;
199 return encoder;
200 }
201
202 virtual void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) {
203 encoders_.erase(
204 std::remove(encoders_.begin(), encoders_.end(), encoder),
205 encoders_.end());
206 delete encoder;
207 }
208
209 virtual void AddObserver(WebRtcVideoEncoderFactory::Observer* observer) {
210 bool inserted = observers_.insert(observer).second;
211 EXPECT_TRUE(inserted);
212 }
213
214 virtual void RemoveObserver(WebRtcVideoEncoderFactory::Observer* observer) {
215 size_t erased = observers_.erase(observer);
216 EXPECT_EQ(erased, 1UL);
217 }
218
219 virtual const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs()
220 const {
221 return codecs_;
222 }
223
224 void AddSupportedVideoCodecType(webrtc::VideoCodecType type,
225 const std::string& name) {
226 supported_codec_types_.insert(type);
227 codecs_.push_back(
228 WebRtcVideoEncoderFactory::VideoCodec(type, name, 1280, 720, 30));
229 }
230
231 void NotifyCodecsAvailable() {
232 std::set<WebRtcVideoEncoderFactory::Observer*>::iterator it;
233 for (it = observers_.begin(); it != observers_.end(); ++it)
234 (*it)->OnCodecsAvailable();
235 }
236
wu@webrtc.orgb884eb62014-04-10 16:59:16 +0000237 int GetNumCreatedEncoders() {
238 return num_created_encoders_;
239 }
240
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 const std::vector<FakeWebRtcVideoEncoder*>& encoders() {
242 return encoders_;
243 }
244
245 private:
246 std::set<webrtc::VideoCodecType> supported_codec_types_;
247 std::vector<WebRtcVideoEncoderFactory::VideoCodec> codecs_;
248 std::vector<FakeWebRtcVideoEncoder*> encoders_;
249 std::set<WebRtcVideoEncoderFactory::Observer*> observers_;
250 int num_created_encoders_;
251};
252
253class FakeWebRtcVideoEngine
254 : public webrtc::ViEBase,
255 public webrtc::ViECodec,
256 public webrtc::ViECapture,
257 public webrtc::ViENetwork,
258 public webrtc::ViERender,
259 public webrtc::ViERTP_RTCP,
260 public webrtc::ViEImageProcess,
261 public webrtc::ViEExternalCodec {
262 public:
263 struct Channel {
264 Channel()
265 : capture_id_(-1),
266 original_channel_id_(-1),
267 has_renderer_(false),
268 render_started_(false),
269 send(false),
270 receive_(false),
271 can_transmit_(true),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000272 remote_rtx_ssrc_(-1),
273 rtx_send_payload_type(-1),
buildbot@webrtc.orgdd4742a2014-05-07 14:50:35 +0000274 rtx_recv_payload_type(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 rtcp_status_(webrtc::kRtcpNone),
276 key_frame_request_method_(webrtc::kViEKeyFrameRequestNone),
277 tmmbr_(false),
278 remb_contribute_(false),
279 remb_bw_partition_(false),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000280 rtp_offset_send_id_(-1),
281 rtp_offset_receive_id_(-1),
282 rtp_absolute_send_time_send_id_(-1),
283 rtp_absolute_send_time_receive_id_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284 sender_target_delay_(0),
285 receiver_target_delay_(0),
286 transmission_smoothing_(false),
287 nack_(false),
buildbot@webrtc.org4b83a472014-06-05 21:11:28 +0000288 fec_(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 hybrid_nack_fec_(false),
290 send_video_bitrate_(0),
291 send_fec_bitrate_(0),
292 send_nack_bitrate_(0),
293 send_bandwidth_(0),
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000294 receive_bandwidth_(0),
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000295 reserved_transmit_bitrate_bps_(0),
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000296 suspend_below_min_bitrate_(false),
buildbot@webrtc.orgdd4742a2014-05-07 14:50:35 +0000297 overuse_observer_(NULL),
298 last_recvd_payload_type_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 ssrcs_[0] = 0; // default ssrc.
300 memset(&send_codec, 0, sizeof(send_codec));
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000301 memset(&overuse_options_, 0, sizeof(overuse_options_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 }
303 int capture_id_;
304 int original_channel_id_;
305 bool has_renderer_;
306 bool render_started_;
307 bool send;
308 bool receive_;
309 bool can_transmit_;
310 std::map<int, int> ssrcs_;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000311 std::map<int, int> rtx_ssrcs_;
312 int remote_rtx_ssrc_;
313 int rtx_send_payload_type;
buildbot@webrtc.orgdd4742a2014-05-07 14:50:35 +0000314 int rtx_recv_payload_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 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_;
buildbot@webrtc.org4b83a472014-06-05 21:11:28 +0000329 bool fec_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 bool hybrid_nack_fec_;
331 std::vector<webrtc::VideoCodec> recv_codecs;
332 std::set<unsigned int> ext_decoder_pl_types_;
333 std::set<unsigned int> ext_encoder_pl_types_;
334 webrtc::VideoCodec send_codec;
335 unsigned int send_video_bitrate_;
336 unsigned int send_fec_bitrate_;
337 unsigned int send_nack_bitrate_;
338 unsigned int send_bandwidth_;
339 unsigned int receive_bandwidth_;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000340 unsigned int reserved_transmit_bitrate_bps_;
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000341 bool suspend_below_min_bitrate_;
342 webrtc::CpuOveruseObserver* overuse_observer_;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000343 webrtc::CpuOveruseOptions overuse_options_;
buildbot@webrtc.orgdd4742a2014-05-07 14:50:35 +0000344 int last_recvd_payload_type_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 };
346 class Capturer : public webrtc::ViEExternalCapture {
347 public:
wu@webrtc.org24301a62013-12-13 19:17:43 +0000348 Capturer() : channel_id_(-1), denoising_(false),
349 last_capture_time_(0), incoming_frame_num_(0) { }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 int channel_id() const { return channel_id_; }
351 void set_channel_id(int channel_id) { channel_id_ = channel_id; }
352 bool denoising() const { return denoising_; }
353 void set_denoising(bool denoising) { denoising_ = denoising; }
wu@webrtc.org24301a62013-12-13 19:17:43 +0000354 int64 last_capture_time() const { return last_capture_time_; }
355 int incoming_frame_num() const { return incoming_frame_num_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356
357 // From ViEExternalCapture
358 virtual int IncomingFrame(unsigned char* videoFrame,
359 unsigned int videoFrameLength,
360 unsigned short width,
361 unsigned short height,
362 webrtc::RawVideoType videoType,
363 unsigned long long captureTime) {
364 return 0;
365 }
366 virtual int IncomingFrameI420(
367 const webrtc::ViEVideoFrameI420& video_frame,
368 unsigned long long captureTime) {
369 last_capture_time_ = captureTime;
wu@webrtc.org24301a62013-12-13 19:17:43 +0000370 ++incoming_frame_num_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 return 0;
372 }
373
374 private:
375 int channel_id_;
376 bool denoising_;
377 int64 last_capture_time_;
wu@webrtc.org24301a62013-12-13 19:17:43 +0000378 int incoming_frame_num_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 };
380
381 FakeWebRtcVideoEngine(const cricket::VideoCodec* const* codecs,
382 int num_codecs)
383 : inited_(false),
384 last_channel_(kViEChannelIdBase - 1),
385 fail_create_channel_(false),
386 last_capturer_(kViECaptureIdBase - 1),
387 fail_alloc_capturer_(false),
388 codecs_(codecs),
389 num_codecs_(num_codecs),
390 num_set_send_codecs_(0) {
391 }
392
393 ~FakeWebRtcVideoEngine() {
394 ASSERT(0 == channels_.size());
395 ASSERT(0 == capturers_.size());
396 }
397 bool IsInited() const { return inited_; }
398
399 int GetLastChannel() const { return last_channel_; }
400 int GetChannelFromLocalSsrc(int local_ssrc) const {
401 // ssrcs_[0] is the default local ssrc.
402 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
403 iter != channels_.end(); ++iter) {
404 if (local_ssrc == iter->second->ssrcs_[0]) {
405 return iter->first;
406 }
407 }
408 return -1;
409 }
410
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000411 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 bool IsChannel(int channel) const {
413 return (channels_.find(channel) != channels_.end());
414 }
415 void set_fail_create_channel(bool fail_create_channel) {
416 fail_create_channel_ = fail_create_channel;
417 }
418
419 int GetLastCapturer() const { return last_capturer_; }
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000420 int GetNumCapturers() const { return static_cast<int>(capturers_.size()); }
wu@webrtc.org24301a62013-12-13 19:17:43 +0000421 int GetIncomingFrameNum(int channel_id) const {
422 for (std::map<int, Capturer*>::const_iterator iter = capturers_.begin();
423 iter != capturers_.end(); ++iter) {
424 Capturer* capturer = iter->second;
425 if (capturer->channel_id() == channel_id) {
426 return capturer->incoming_frame_num();
427 }
428 }
429 return -1;
430 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 void set_fail_alloc_capturer(bool fail_alloc_capturer) {
432 fail_alloc_capturer_ = fail_alloc_capturer;
433 }
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000434 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435
436 int GetCaptureId(int channel) const {
437 WEBRTC_ASSERT_CHANNEL(channel);
438 return channels_.find(channel)->second->capture_id_;
439 }
440 int GetOriginalChannelId(int channel) const {
441 WEBRTC_ASSERT_CHANNEL(channel);
442 return channels_.find(channel)->second->original_channel_id_;
443 }
444 bool GetHasRenderer(int channel) const {
445 WEBRTC_ASSERT_CHANNEL(channel);
446 return channels_.find(channel)->second->has_renderer_;
447 }
448 bool GetRenderStarted(int channel) const {
449 WEBRTC_ASSERT_CHANNEL(channel);
450 return channels_.find(channel)->second->render_started_;
451 }
452 bool GetSend(int channel) const {
453 WEBRTC_ASSERT_CHANNEL(channel);
454 return channels_.find(channel)->second->send;
455 }
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000456 bool GetReceive(int channel) const {
457 WEBRTC_ASSERT_CHANNEL(channel);
458 return channels_.find(channel)->second->receive_;
459 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460 int GetCaptureChannelId(int capture_id) const {
461 WEBRTC_ASSERT_CAPTURER(capture_id);
462 return capturers_.find(capture_id)->second->channel_id();
463 }
464 bool GetCaptureDenoising(int capture_id) const {
465 WEBRTC_ASSERT_CAPTURER(capture_id);
466 return capturers_.find(capture_id)->second->denoising();
467 }
468 int64 GetCaptureLastTimestamp(int capture_id) const {
469 WEBRTC_ASSERT_CAPTURER(capture_id);
470 return capturers_.find(capture_id)->second->last_capture_time();
471 }
472 webrtc::ViERTCPMode GetRtcpStatus(int channel) const {
473 WEBRTC_ASSERT_CHANNEL(channel);
474 return channels_.find(channel)->second->rtcp_status_;
475 }
476 webrtc::ViEKeyFrameRequestMethod GetKeyFrameRequestMethod(int channel) const {
477 WEBRTC_ASSERT_CHANNEL(channel);
478 return channels_.find(channel)->second->key_frame_request_method_;
479 }
480 bool GetTmmbrStatus(int channel) const {
481 WEBRTC_ASSERT_CHANNEL(channel);
482 return channels_.find(channel)->second->tmmbr_;
483 }
484 bool GetRembStatusBwPartition(int channel) const {
485 WEBRTC_ASSERT_CHANNEL(channel);
486 return channels_.find(channel)->second->remb_bw_partition_;
487 }
488 bool GetRembStatusContribute(int channel) const {
489 WEBRTC_ASSERT_CHANNEL(channel);
490 return channels_.find(channel)->second->remb_contribute_;
491 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000492 int GetSendRtpExtensionId(int channel, const std::string& extension) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493 WEBRTC_ASSERT_CHANNEL(channel);
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000494 if (extension == kRtpTimestampOffsetHeaderExtension) {
495 return channels_.find(channel)->second->rtp_offset_send_id_;
496 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
497 return channels_.find(channel)->second->rtp_absolute_send_time_send_id_;
498 }
499 return -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000500 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000501 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 WEBRTC_ASSERT_CHANNEL(channel);
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000503 if (extension == kRtpTimestampOffsetHeaderExtension) {
504 return channels_.find(channel)->second->rtp_offset_receive_id_;
505 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
506 return
507 channels_.find(channel)->second->rtp_absolute_send_time_receive_id_;
508 }
509 return -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 }
511 bool GetTransmissionSmoothingStatus(int channel) {
512 WEBRTC_ASSERT_CHANNEL(channel);
513 return channels_.find(channel)->second->transmission_smoothing_;
514 }
515 int GetSenderTargetDelay(int channel) {
516 WEBRTC_ASSERT_CHANNEL(channel);
517 return channels_.find(channel)->second->sender_target_delay_;
518 }
519 int GetReceiverTargetDelay(int channel) {
520 WEBRTC_ASSERT_CHANNEL(channel);
521 return channels_.find(channel)->second->receiver_target_delay_;
522 }
buildbot@webrtc.org4b83a472014-06-05 21:11:28 +0000523 bool GetFecStatus(int channel) const {
524 WEBRTC_ASSERT_CHANNEL(channel);
525 return channels_.find(channel)->second->fec_;
526 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000527 bool GetNackStatus(int channel) const {
528 WEBRTC_ASSERT_CHANNEL(channel);
529 return channels_.find(channel)->second->nack_;
530 }
531 bool GetHybridNackFecStatus(int channel) const {
532 WEBRTC_ASSERT_CHANNEL(channel);
533 return channels_.find(channel)->second->hybrid_nack_fec_;
534 }
535 int GetNumSsrcs(int channel) const {
536 WEBRTC_ASSERT_CHANNEL(channel);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000537 return static_cast<int>(
538 channels_.find(channel)->second->ssrcs_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000540 int GetNumRtxSsrcs(int channel) const {
541 WEBRTC_ASSERT_CHANNEL(channel);
542 return static_cast<int>(
543 channels_.find(channel)->second->rtx_ssrcs_.size());
544 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545 bool GetIsTransmitting(int channel) const {
546 WEBRTC_ASSERT_CHANNEL(channel);
547 return channels_.find(channel)->second->can_transmit_;
548 }
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000549 webrtc::CpuOveruseObserver* GetCpuOveruseObserver(int channel) const {
550 WEBRTC_ASSERT_CHANNEL(channel);
551 return channels_.find(channel)->second->overuse_observer_;
552 }
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000553 webrtc::CpuOveruseOptions GetCpuOveruseOptions(int channel) const {
554 WEBRTC_ASSERT_CHANNEL(channel);
555 return channels_.find(channel)->second->overuse_options_;
556 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000557 int GetRtxSsrc(int channel, int simulcast_idx) const {
558 WEBRTC_ASSERT_CHANNEL(channel);
559 if (channels_.find(channel)->second->rtx_ssrcs_.find(simulcast_idx) ==
560 channels_.find(channel)->second->rtx_ssrcs_.end()) {
561 return -1;
562 }
563 return channels_.find(channel)->second->rtx_ssrcs_[simulcast_idx];
564 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 bool ReceiveCodecRegistered(int channel,
566 const webrtc::VideoCodec& codec) const {
567 WEBRTC_ASSERT_CHANNEL(channel);
buildbot@webrtc.orgdd4742a2014-05-07 14:50:35 +0000568 const std::vector<webrtc::VideoCodec>& codecs =
569 channels_.find(channel)->second->recv_codecs;
570 return std::find(codecs.begin(), codecs.end(), codec) != codecs.end();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 };
572 bool ExternalDecoderRegistered(int channel,
573 unsigned int pl_type) const {
574 WEBRTC_ASSERT_CHANNEL(channel);
575 return channels_.find(channel)->second->
576 ext_decoder_pl_types_.count(pl_type) != 0;
577 };
578 int GetNumExternalDecoderRegistered(int channel) const {
579 WEBRTC_ASSERT_CHANNEL(channel);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000580 return static_cast<int>(
581 channels_.find(channel)->second->ext_decoder_pl_types_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 };
583 bool ExternalEncoderRegistered(int channel,
584 unsigned int pl_type) const {
585 WEBRTC_ASSERT_CHANNEL(channel);
586 return channels_.find(channel)->second->
587 ext_encoder_pl_types_.count(pl_type) != 0;
588 };
589 int GetNumExternalEncoderRegistered(int channel) const {
590 WEBRTC_ASSERT_CHANNEL(channel);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000591 return static_cast<int>(
592 channels_.find(channel)->second->ext_encoder_pl_types_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 };
594 int GetTotalNumExternalEncoderRegistered() const {
595 std::map<int, Channel*>::const_iterator it;
596 int total_num_registered = 0;
597 for (it = channels_.begin(); it != channels_.end(); ++it)
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000598 total_num_registered +=
599 static_cast<int>(it->second->ext_encoder_pl_types_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600 return total_num_registered;
601 }
602 void SetSendBitrates(int channel, unsigned int video_bitrate,
603 unsigned int fec_bitrate, unsigned int nack_bitrate) {
604 WEBRTC_ASSERT_CHANNEL(channel);
605 channels_[channel]->send_video_bitrate_ = video_bitrate;
606 channels_[channel]->send_fec_bitrate_ = fec_bitrate;
607 channels_[channel]->send_nack_bitrate_ = nack_bitrate;
608 }
609 void SetSendBandwidthEstimate(int channel, unsigned int send_bandwidth) {
610 WEBRTC_ASSERT_CHANNEL(channel);
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +0000611 channels_[GetOriginalChannelId(channel)]->send_bandwidth_ = send_bandwidth;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 }
613 void SetReceiveBandwidthEstimate(int channel,
614 unsigned int receive_bandwidth) {
615 WEBRTC_ASSERT_CHANNEL(channel);
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +0000616 channels_[GetOriginalChannelId(channel)]->receive_bandwidth_ =
617 receive_bandwidth;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 };
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000619 int GetRtxSendPayloadType(int channel) {
620 WEBRTC_CHECK_CHANNEL(channel);
621 return channels_[channel]->rtx_send_payload_type;
622 }
buildbot@webrtc.orgdd4742a2014-05-07 14:50:35 +0000623 int GetRtxRecvPayloadType(int channel) {
624 WEBRTC_CHECK_CHANNEL(channel);
625 return channels_[channel]->rtx_recv_payload_type;
626 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000627 int GetRemoteRtxSsrc(int channel) {
628 WEBRTC_CHECK_CHANNEL(channel);
629 return channels_.find(channel)->second->remote_rtx_ssrc_;
630 }
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000631 bool GetSuspendBelowMinBitrateStatus(int channel) {
632 WEBRTC_ASSERT_CHANNEL(channel);
633 return channels_.find(channel)->second->suspend_below_min_bitrate_;
634 }
buildbot@webrtc.orgdd4742a2014-05-07 14:50:35 +0000635 int GetLastRecvdPayloadType(int channel) const {
636 WEBRTC_CHECK_CHANNEL(channel);
637 return channels_.find(channel)->second->last_recvd_payload_type_;
638 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000639 unsigned int GetReservedTransmitBitrate(int channel) {
640 WEBRTC_ASSERT_CHANNEL(channel);
641 return channels_.find(channel)->second->reserved_transmit_bitrate_bps_;
642 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643
644 WEBRTC_STUB(Release, ());
645
646 // webrtc::ViEBase
647 WEBRTC_FUNC(Init, ()) {
648 inited_ = true;
649 return 0;
650 };
651 WEBRTC_STUB(SetVoiceEngine, (webrtc::VoiceEngine*));
652 WEBRTC_FUNC(CreateChannel, (int& channel)) { // NOLINT
653 if (fail_create_channel_) {
654 return -1;
655 }
656 if (kViEChannelIdMax == last_channel_) {
657 return -1;
658 }
659 Channel* ch = new Channel();
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +0000660 ++last_channel_;
661 // The original channel of the first channel in a group refers to itself
662 // for code simplicity.
663 ch->original_channel_id_ = last_channel_;
664 channels_[last_channel_] = ch;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665 channel = last_channel_;
666 return 0;
667 };
668 WEBRTC_FUNC(CreateChannel, (int& channel, int original_channel)) {
669 WEBRTC_CHECK_CHANNEL(original_channel);
670 if (CreateChannel(channel) != 0) {
671 return -1;
672 }
673 channels_[channel]->original_channel_id_ = original_channel;
674 return 0;
675 }
676 WEBRTC_FUNC(CreateReceiveChannel, (int& channel, int original_channel)) {
677 return CreateChannel(channel, original_channel);
678 }
679 WEBRTC_FUNC(DeleteChannel, (const int channel)) {
680 WEBRTC_CHECK_CHANNEL(channel);
681 // Make sure we deregister all the decoders before deleting a channel.
682 EXPECT_EQ(0, GetNumExternalDecoderRegistered(channel));
683 delete channels_[channel];
684 channels_.erase(channel);
685 return 0;
686 }
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000687 WEBRTC_FUNC(RegisterCpuOveruseObserver,
688 (int channel, webrtc::CpuOveruseObserver* observer)) {
689 WEBRTC_CHECK_CHANNEL(channel);
690 channels_[channel]->overuse_observer_ = observer;
691 return 0;
692 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000693 WEBRTC_STUB(CpuOveruseMeasures, (int, int*, int*, int*, int*));
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000694 WEBRTC_FUNC(SetCpuOveruseOptions,
695 (int channel, const webrtc::CpuOveruseOptions& options)) {
696 WEBRTC_CHECK_CHANNEL(channel);
697 channels_[channel]->overuse_options_ = options;
698 return 0;
699 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 WEBRTC_STUB(ConnectAudioChannel, (const int, const int));
701 WEBRTC_STUB(DisconnectAudioChannel, (const int));
702 WEBRTC_FUNC(StartSend, (const int channel)) {
703 WEBRTC_CHECK_CHANNEL(channel);
704 channels_[channel]->send = true;
705 return 0;
706 }
707 WEBRTC_FUNC(StopSend, (const int channel)) {
708 WEBRTC_CHECK_CHANNEL(channel);
709 channels_[channel]->send = false;
710 return 0;
711 }
712 WEBRTC_FUNC(StartReceive, (const int channel)) {
713 WEBRTC_CHECK_CHANNEL(channel);
714 channels_[channel]->receive_ = true;
715 return 0;
716 }
717 WEBRTC_FUNC(StopReceive, (const int channel)) {
718 WEBRTC_CHECK_CHANNEL(channel);
719 channels_[channel]->receive_ = false;
720 return 0;
721 }
722 WEBRTC_STUB(GetVersion, (char version[1024]));
723 WEBRTC_STUB(LastError, ());
724
725 // webrtc::ViECodec
726 WEBRTC_FUNC_CONST(NumberOfCodecs, ()) {
727 return num_codecs_;
728 };
729 WEBRTC_FUNC_CONST(GetCodec, (const unsigned char list_number,
730 webrtc::VideoCodec& out_codec)) {
731 if (list_number >= NumberOfCodecs()) {
732 return -1;
733 }
734 memset(&out_codec, 0, sizeof(out_codec));
735 const cricket::VideoCodec& c(*codecs_[list_number]);
736 if ("I420" == c.name) {
737 out_codec.codecType = webrtc::kVideoCodecI420;
738 } else if ("VP8" == c.name) {
739 out_codec.codecType = webrtc::kVideoCodecVP8;
740 } else if ("red" == c.name) {
741 out_codec.codecType = webrtc::kVideoCodecRED;
742 } else if ("ulpfec" == c.name) {
743 out_codec.codecType = webrtc::kVideoCodecULPFEC;
744 } else {
745 out_codec.codecType = webrtc::kVideoCodecUnknown;
746 }
747 talk_base::strcpyn(out_codec.plName, sizeof(out_codec.plName),
748 c.name.c_str());
749 out_codec.plType = c.id;
750 out_codec.width = c.width;
751 out_codec.height = c.height;
752 out_codec.startBitrate = kStartVideoBitrate;
753 out_codec.maxBitrate = kMaxVideoBitrate;
754 out_codec.minBitrate = kMinVideoBitrate;
755 out_codec.maxFramerate = c.framerate;
756 return 0;
757 };
758 WEBRTC_FUNC(SetSendCodec, (const int channel,
759 const webrtc::VideoCodec& codec)) {
760 WEBRTC_CHECK_CHANNEL(channel);
761 channels_[channel]->send_codec = codec;
762 ++num_set_send_codecs_;
763 return 0;
764 };
765 WEBRTC_FUNC_CONST(GetSendCodec, (const int channel,
766 webrtc::VideoCodec& codec)) { // NOLINT
767 WEBRTC_CHECK_CHANNEL(channel);
768 codec = channels_.find(channel)->second->send_codec;
769 return 0;
770 };
771 WEBRTC_FUNC(SetReceiveCodec, (const int channel,
772 const webrtc::VideoCodec& codec)) { // NOLINT
773 WEBRTC_CHECK_CHANNEL(channel);
774 channels_[channel]->recv_codecs.push_back(codec);
775 return 0;
776 };
777 WEBRTC_STUB_CONST(GetReceiveCodec, (const int, webrtc::VideoCodec&));
778 WEBRTC_STUB_CONST(GetCodecConfigParameters, (const int,
779 unsigned char*, unsigned char&));
780 WEBRTC_STUB(SetImageScaleStatus, (const int, const bool));
781 WEBRTC_STUB_CONST(GetSendCodecStastistics, (const int,
782 unsigned int&, unsigned int&));
783 WEBRTC_STUB_CONST(GetReceiveCodecStastistics, (const int,
784 unsigned int&, unsigned int&));
785 WEBRTC_STUB_CONST(GetReceiveSideDelay, (const int video_channel,
786 int* delay_ms));
787 WEBRTC_FUNC_CONST(GetCodecTargetBitrate, (const int channel,
788 unsigned int* codec_target_bitrate)) {
789 WEBRTC_CHECK_CHANNEL(channel);
790
791 std::map<int, Channel*>::const_iterator it = channels_.find(channel);
792 if (it->second->send) {
793 // Assume the encoder produces the expected rate.
794 *codec_target_bitrate = it->second->send_video_bitrate_;
795 } else {
796 *codec_target_bitrate = 0;
797 }
798 return 0;
799 }
800 virtual unsigned int GetDiscardedPackets(const int channel) const {
801 return 0;
802 }
803
804 WEBRTC_STUB(SetKeyFrameRequestCallbackStatus, (const int, const bool));
805 WEBRTC_STUB(SetSignalKeyPacketLossStatus, (const int, const bool,
806 const bool));
807 WEBRTC_STUB(RegisterEncoderObserver, (const int,
808 webrtc::ViEEncoderObserver&));
809 WEBRTC_STUB(DeregisterEncoderObserver, (const int));
810 WEBRTC_STUB(RegisterDecoderObserver, (const int,
811 webrtc::ViEDecoderObserver&));
812 WEBRTC_STUB(DeregisterDecoderObserver, (const int));
813 WEBRTC_STUB(SendKeyFrame, (const int));
814 WEBRTC_STUB(WaitForFirstKeyFrame, (const int, const bool));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000815 WEBRTC_STUB(StartDebugRecording, (int, const char*));
816 WEBRTC_STUB(StopDebugRecording, (int));
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000817 WEBRTC_VOID_FUNC(SuspendBelowMinBitrate, (int channel)) {
818 WEBRTC_ASSERT_CHANNEL(channel);
819 channels_[channel]->suspend_below_min_bitrate_ = true;
820 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821
822 // webrtc::ViECapture
823 WEBRTC_STUB(NumberOfCaptureDevices, ());
824 WEBRTC_STUB(GetCaptureDevice, (unsigned int, char*,
825 const unsigned int, char*, const unsigned int));
826 WEBRTC_STUB(AllocateCaptureDevice, (const char*, const unsigned int, int&));
827 WEBRTC_FUNC(AllocateExternalCaptureDevice,
828 (int& capture_id, webrtc::ViEExternalCapture*& capture)) {
829 if (fail_alloc_capturer_) {
830 return -1;
831 }
832 if (kViECaptureIdMax == last_capturer_) {
833 return -1;
834 }
835 Capturer* cap = new Capturer();
836 capturers_[++last_capturer_] = cap;
837 capture_id = last_capturer_;
838 capture = cap;
839 return 0;
840 }
841 WEBRTC_STUB(AllocateCaptureDevice, (webrtc::VideoCaptureModule&, int&));
842 WEBRTC_FUNC(ReleaseCaptureDevice, (const int capture_id)) {
843 WEBRTC_CHECK_CAPTURER(capture_id);
844 delete capturers_[capture_id];
845 capturers_.erase(capture_id);
846 return 0;
847 }
848 WEBRTC_FUNC(ConnectCaptureDevice, (const int capture_id,
849 const int channel)) {
850 WEBRTC_CHECK_CHANNEL(channel);
851 WEBRTC_CHECK_CAPTURER(capture_id);
852 channels_[channel]->capture_id_ = capture_id;
853 capturers_[capture_id]->set_channel_id(channel);
854 return 0;
855 }
856 WEBRTC_FUNC(DisconnectCaptureDevice, (const int channel)) {
857 WEBRTC_CHECK_CHANNEL(channel);
858 int capture_id = channels_[channel]->capture_id_;
859 WEBRTC_CHECK_CAPTURER(capture_id);
860 channels_[channel]->capture_id_ = -1;
861 capturers_[capture_id]->set_channel_id(-1);
862 return 0;
863 }
864 WEBRTC_STUB(StartCapture, (const int, const webrtc::CaptureCapability&));
865 WEBRTC_STUB(StopCapture, (const int));
866 WEBRTC_STUB(SetRotateCapturedFrames, (const int,
867 const webrtc::RotateCapturedFrame));
868 WEBRTC_STUB(SetCaptureDelay, (const int, const unsigned int));
869 WEBRTC_STUB(NumberOfCapabilities, (const char*, const unsigned int));
870 WEBRTC_STUB(GetCaptureCapability, (const char*, const unsigned int,
871 const unsigned int, webrtc::CaptureCapability&));
872 WEBRTC_STUB(ShowCaptureSettingsDialogBox, (const char*, const unsigned int,
873 const char*, void*, const unsigned int, const unsigned int));
874 WEBRTC_STUB(GetOrientation, (const char*, webrtc::RotateCapturedFrame&));
875 WEBRTC_STUB(EnableBrightnessAlarm, (const int, const bool));
876 WEBRTC_STUB(RegisterObserver, (const int, webrtc::ViECaptureObserver&));
877 WEBRTC_STUB(DeregisterObserver, (const int));
878
879 // webrtc::ViENetwork
880 WEBRTC_VOID_FUNC(SetNetworkTransmissionState, (const int channel,
881 const bool is_transmitting)) {
882 WEBRTC_ASSERT_CHANNEL(channel);
883 channels_[channel]->can_transmit_ = is_transmitting;
884 }
885 WEBRTC_STUB(RegisterSendTransport, (const int, webrtc::Transport&));
886 WEBRTC_STUB(DeregisterSendTransport, (const int));
buildbot@webrtc.orgdd4742a2014-05-07 14:50:35 +0000887
888 WEBRTC_FUNC(ReceivedRTPPacket, (const int channel,
889 const void* packet,
890 const int length,
891 const webrtc::PacketTime& packet_time)) {
892 WEBRTC_ASSERT_CHANNEL(channel);
893 ASSERT(length > 1);
894 uint8_t payload_type = static_cast<const uint8_t*>(packet)[1] & 0x7F;
895 channels_[channel]->last_recvd_payload_type_ = payload_type;
896 return 0;
897 }
898
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 WEBRTC_STUB(ReceivedRTCPPacket, (const int, const void*, const int));
900 // Not using WEBRTC_STUB due to bool return value
901 virtual bool IsIPv6Enabled(int channel) { return true; }
902 WEBRTC_STUB(SetMTU, (int, unsigned int));
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000903 WEBRTC_STUB(ReceivedBWEPacket, (const int, int64_t, int,
904 const webrtc::RTPHeader&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905
906 // webrtc::ViERender
907 WEBRTC_STUB(RegisterVideoRenderModule, (webrtc::VideoRender&));
908 WEBRTC_STUB(DeRegisterVideoRenderModule, (webrtc::VideoRender&));
909 WEBRTC_STUB(AddRenderer, (const int, void*, const unsigned int, const float,
910 const float, const float, const float));
911 WEBRTC_FUNC(RemoveRenderer, (const int render_id)) {
912 if (IsCapturerId(render_id)) {
913 WEBRTC_CHECK_CAPTURER(render_id);
914 return 0;
915 } else if (IsChannelId(render_id)) {
916 WEBRTC_CHECK_CHANNEL(render_id);
917 channels_[render_id]->has_renderer_ = false;
918 return 0;
919 }
920 return -1;
921 }
922 WEBRTC_FUNC(StartRender, (const int render_id)) {
923 if (IsCapturerId(render_id)) {
924 WEBRTC_CHECK_CAPTURER(render_id);
925 return 0;
926 } else if (IsChannelId(render_id)) {
927 WEBRTC_CHECK_CHANNEL(render_id);
928 channels_[render_id]->render_started_ = true;
929 return 0;
930 }
931 return -1;
932 }
933 WEBRTC_FUNC(StopRender, (const int render_id)) {
934 if (IsCapturerId(render_id)) {
935 WEBRTC_CHECK_CAPTURER(render_id);
936 return 0;
937 } else if (IsChannelId(render_id)) {
938 WEBRTC_CHECK_CHANNEL(render_id);
939 channels_[render_id]->render_started_ = false;
940 return 0;
941 }
942 return -1;
943 }
944 WEBRTC_STUB(SetExpectedRenderDelay, (int render_id, int render_delay));
945 WEBRTC_STUB(ConfigureRender, (int, const unsigned int, const float,
946 const float, const float, const float));
947 WEBRTC_STUB(MirrorRenderStream, (const int, const bool, const bool,
948 const bool));
949 WEBRTC_FUNC(AddRenderer, (const int render_id,
950 webrtc::RawVideoType video_type,
951 webrtc::ExternalRenderer* renderer)) {
952 if (IsCapturerId(render_id)) {
953 WEBRTC_CHECK_CAPTURER(render_id);
954 return 0;
955 } else if (IsChannelId(render_id)) {
956 WEBRTC_CHECK_CHANNEL(render_id);
957 channels_[render_id]->has_renderer_ = true;
958 return 0;
959 }
960 return -1;
961 }
962
963 // webrtc::ViERTP_RTCP
964 WEBRTC_FUNC(SetLocalSSRC, (const int channel,
965 const unsigned int ssrc,
966 const webrtc::StreamType usage,
967 const unsigned char idx)) {
968 WEBRTC_CHECK_CHANNEL(channel);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000969 switch (usage) {
970 case webrtc::kViEStreamTypeNormal:
971 channels_[channel]->ssrcs_[idx] = ssrc;
972 break;
973 case webrtc::kViEStreamTypeRtx:
974 channels_[channel]->rtx_ssrcs_[idx] = ssrc;
975 break;
976 default:
977 return -1;
978 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 return 0;
980 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000981
982 WEBRTC_FUNC_CONST(SetRemoteSSRCType, (const int channel,
983 const webrtc::StreamType usage, const unsigned int ssrc)) {
984 WEBRTC_CHECK_CHANNEL(channel);
985 if (usage == webrtc::kViEStreamTypeRtx) {
986 channels_.find(channel)->second->remote_rtx_ssrc_ = ssrc;
987 return 0;
988 }
989 return -1;
990 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991
992 WEBRTC_FUNC_CONST(GetLocalSSRC, (const int channel,
993 unsigned int& ssrc)) {
994 // ssrcs_[0] is the default local ssrc.
995 WEBRTC_CHECK_CHANNEL(channel);
996 ssrc = channels_.find(channel)->second->ssrcs_[0];
997 return 0;
998 }
999 WEBRTC_STUB_CONST(GetRemoteSSRC, (const int, unsigned int&));
1000 WEBRTC_STUB_CONST(GetRemoteCSRCs, (const int, unsigned int*));
1001
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001002 WEBRTC_FUNC(SetRtxSendPayloadType, (const int channel,
1003 const uint8 payload_type)) {
1004 WEBRTC_CHECK_CHANNEL(channel);
1005 channels_[channel]->rtx_send_payload_type = payload_type;
1006 return 0;
1007 }
buildbot@webrtc.orgdd4742a2014-05-07 14:50:35 +00001008
1009 WEBRTC_FUNC(SetRtxReceivePayloadType, (const int channel,
1010 const uint8 payload_type)) {
1011 WEBRTC_CHECK_CHANNEL(channel);
1012 channels_[channel]->rtx_recv_payload_type = payload_type;
1013 return 0;
1014 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015
1016 WEBRTC_STUB(SetStartSequenceNumber, (const int, unsigned short));
1017 WEBRTC_FUNC(SetRTCPStatus,
1018 (const int channel, const webrtc::ViERTCPMode mode)) {
1019 WEBRTC_CHECK_CHANNEL(channel);
1020 channels_[channel]->rtcp_status_ = mode;
1021 return 0;
1022 }
1023 WEBRTC_STUB_CONST(GetRTCPStatus, (const int, webrtc::ViERTCPMode&));
1024 WEBRTC_FUNC(SetRTCPCName, (const int channel,
1025 const char rtcp_cname[KMaxRTCPCNameLength])) {
1026 WEBRTC_CHECK_CHANNEL(channel);
1027 channels_[channel]->cname_.assign(rtcp_cname);
1028 return 0;
1029 }
1030 WEBRTC_FUNC_CONST(GetRTCPCName, (const int channel,
1031 char rtcp_cname[KMaxRTCPCNameLength])) {
1032 WEBRTC_CHECK_CHANNEL(channel);
1033 talk_base::strcpyn(rtcp_cname, KMaxRTCPCNameLength,
1034 channels_.find(channel)->second->cname_.c_str());
1035 return 0;
1036 }
1037 WEBRTC_STUB_CONST(GetRemoteRTCPCName, (const int, char*));
1038 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (const int, const unsigned char,
1039 unsigned int, const char*, unsigned short));
1040 WEBRTC_FUNC(SetNACKStatus, (const int channel, const bool enable)) {
1041 WEBRTC_CHECK_CHANNEL(channel);
1042 channels_[channel]->nack_ = enable;
1043 channels_[channel]->hybrid_nack_fec_ = false;
1044 return 0;
1045 }
buildbot@webrtc.org4b83a472014-06-05 21:11:28 +00001046 WEBRTC_FUNC(SetFECStatus, (const int channel, const bool enable,
1047 const unsigned char red_type, const unsigned char fec_type)) {
1048 WEBRTC_CHECK_CHANNEL(channel);
1049 if (enable && (red_type == fec_type ||
1050 red_type == channels_[channel]->send_codec.plType ||
1051 fec_type == channels_[channel]->send_codec.plType)) {
1052 return -1;
1053 }
1054 channels_[channel]->fec_ = enable;
1055 channels_[channel]->nack_ = false;
1056 channels_[channel]->hybrid_nack_fec_ = false;
1057 return 0;
1058 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 WEBRTC_FUNC(SetHybridNACKFECStatus, (const int channel, const bool enable,
1060 const unsigned char red_type, const unsigned char fec_type)) {
1061 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org4b83a472014-06-05 21:11:28 +00001062 if (enable && (red_type == fec_type ||
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 red_type == channels_[channel]->send_codec.plType ||
buildbot@webrtc.org4b83a472014-06-05 21:11:28 +00001064 fec_type == channels_[channel]->send_codec.plType)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 return -1;
1066 }
buildbot@webrtc.org4b83a472014-06-05 21:11:28 +00001067 channels_[channel]->fec_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 channels_[channel]->nack_ = false;
1069 channels_[channel]->hybrid_nack_fec_ = enable;
1070 return 0;
1071 }
1072 WEBRTC_FUNC(SetKeyFrameRequestMethod,
1073 (const int channel,
1074 const webrtc::ViEKeyFrameRequestMethod method)) {
1075 WEBRTC_CHECK_CHANNEL(channel);
1076 channels_[channel]->key_frame_request_method_ = method;
1077 return 0;
1078 }
1079 WEBRTC_FUNC(SetSenderBufferingMode, (int channel, int target_delay)) {
1080 WEBRTC_CHECK_CHANNEL(channel);
1081 channels_[channel]->sender_target_delay_ = target_delay;
1082 return 0;
1083 }
1084 WEBRTC_FUNC(SetReceiverBufferingMode, (int channel, int target_delay)) {
1085 WEBRTC_CHECK_CHANNEL(channel);
1086 channels_[channel]->receiver_target_delay_ = target_delay;
1087 return 0;
1088 }
1089 // |Send| and |receive| are stored locally in variables that more clearly
1090 // explain what they mean.
1091 WEBRTC_FUNC(SetRembStatus, (int channel, bool send, bool receive)) {
1092 WEBRTC_CHECK_CHANNEL(channel);
1093 channels_[channel]->remb_contribute_ = receive;
1094 channels_[channel]->remb_bw_partition_ = send;
1095 return 0;
1096 }
1097 WEBRTC_FUNC(SetTMMBRStatus, (const int channel, const bool enable)) {
1098 WEBRTC_CHECK_CHANNEL(channel);
1099 channels_[channel]->tmmbr_ = enable;
1100 return 0;
1101 }
1102 WEBRTC_FUNC(SetSendTimestampOffsetStatus, (int channel, bool enable,
1103 int id)) {
1104 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001105 channels_[channel]->rtp_offset_send_id_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 return 0;
1107 }
1108 WEBRTC_FUNC(SetReceiveTimestampOffsetStatus, (int channel, bool enable,
1109 int id)) {
1110 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001111 channels_[channel]->rtp_offset_receive_id_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112 return 0;
1113 }
1114 WEBRTC_FUNC(SetSendAbsoluteSendTimeStatus, (int channel, bool enable,
1115 int id)) {
1116 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001117 channels_[channel]->rtp_absolute_send_time_send_id_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 return 0;
1119 }
1120 WEBRTC_FUNC(SetReceiveAbsoluteSendTimeStatus, (int channel, bool enable,
1121 int id)) {
1122 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001123 channels_[channel]->rtp_absolute_send_time_receive_id_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124 return 0;
1125 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001126 WEBRTC_STUB(SetRtcpXrRrtrStatus, (int, bool));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 WEBRTC_FUNC(SetTransmissionSmoothingStatus, (int channel, bool enable)) {
1128 WEBRTC_CHECK_CHANNEL(channel);
1129 channels_[channel]->transmission_smoothing_ = enable;
1130 return 0;
1131 }
buildbot@webrtc.org4b83a472014-06-05 21:11:28 +00001132 WEBRTC_FUNC(SetReservedTransmitBitrate, (int channel,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001133 unsigned int reserved_transmit_bitrate_bps)) {
1134 WEBRTC_CHECK_CHANNEL(channel);
1135 channels_[channel]->reserved_transmit_bitrate_bps_ =
1136 reserved_transmit_bitrate_bps;
1137 return 0;
1138 }
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001139 WEBRTC_STUB_CONST(GetRtcpPacketTypeCounters, (int,
1140 webrtc::RtcpPacketTypeCounter*, webrtc::RtcpPacketTypeCounter*));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141 WEBRTC_STUB_CONST(GetReceivedRTCPStatistics, (const int, unsigned short&,
1142 unsigned int&, unsigned int&, unsigned int&, int&));
1143 WEBRTC_STUB_CONST(GetSentRTCPStatistics, (const int, unsigned short&,
1144 unsigned int&, unsigned int&, unsigned int&, int&));
1145 WEBRTC_STUB_CONST(GetRTPStatistics, (const int, unsigned int&, unsigned int&,
1146 unsigned int&, unsigned int&));
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001147 WEBRTC_STUB_CONST(GetReceiveChannelRtcpStatistics, (const int,
1148 webrtc::RtcpStatistics&, int&));
1149 WEBRTC_STUB_CONST(GetSendChannelRtcpStatistics, (const int,
1150 webrtc::RtcpStatistics&, int&));
1151 WEBRTC_STUB_CONST(GetRtpStatistics, (const int, webrtc::StreamDataCounters&,
1152 webrtc::StreamDataCounters&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001153 WEBRTC_FUNC_CONST(GetBandwidthUsage, (const int channel,
1154 unsigned int& total_bitrate, unsigned int& video_bitrate,
1155 unsigned int& fec_bitrate, unsigned int& nack_bitrate)) {
1156 WEBRTC_CHECK_CHANNEL(channel);
1157 std::map<int, Channel*>::const_iterator it = channels_.find(channel);
1158 if (it->second->send) {
1159 video_bitrate = it->second->send_video_bitrate_;
1160 fec_bitrate = it->second->send_fec_bitrate_;
1161 nack_bitrate = it->second->send_nack_bitrate_;
1162 total_bitrate = video_bitrate + fec_bitrate + nack_bitrate;
1163 } else {
1164 total_bitrate = 0;
1165 video_bitrate = 0;
1166 fec_bitrate = 0;
1167 nack_bitrate = 0;
1168 }
1169 return 0;
1170 }
1171 WEBRTC_FUNC_CONST(GetEstimatedSendBandwidth, (const int channel,
1172 unsigned int* send_bandwidth_estimate)) {
1173 WEBRTC_CHECK_CHANNEL(channel);
1174 std::map<int, Channel*>::const_iterator it = channels_.find(channel);
1175 // Assume the current video, fec and nack bitrate sums up to our estimate.
1176 if (it->second->send) {
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001177 it = channels_.find(GetOriginalChannelId(channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001178 *send_bandwidth_estimate = it->second->send_bandwidth_;
1179 } else {
1180 *send_bandwidth_estimate = 0;
1181 }
1182 return 0;
1183 }
1184 WEBRTC_FUNC_CONST(GetEstimatedReceiveBandwidth, (const int channel,
1185 unsigned int* receive_bandwidth_estimate)) {
1186 WEBRTC_CHECK_CHANNEL(channel);
1187 std::map<int, Channel*>::const_iterator it = channels_.find(channel);
1188 if (it->second->receive_) {
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001189 it = channels_.find(GetOriginalChannelId(channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001190 *receive_bandwidth_estimate = it->second->receive_bandwidth_;
1191 } else {
1192 *receive_bandwidth_estimate = 0;
1193 }
1194 return 0;
1195 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001196 WEBRTC_STUB(RegisterSendChannelRtcpStatisticsCallback,
1197 (int, webrtc::RtcpStatisticsCallback*));
1198 WEBRTC_STUB(DeregisterSendChannelRtcpStatisticsCallback,
1199 (int, webrtc::RtcpStatisticsCallback*));
1200 WEBRTC_STUB(RegisterReceiveChannelRtcpStatisticsCallback,
1201 (int, webrtc::RtcpStatisticsCallback*));
1202 WEBRTC_STUB(DeregisterReceiveChannelRtcpStatisticsCallback,
1203 (int, webrtc::RtcpStatisticsCallback*));
1204 WEBRTC_STUB(RegisterSendChannelRtpStatisticsCallback,
1205 (int, webrtc::StreamDataCountersCallback*));
1206 WEBRTC_STUB(DeregisterSendChannelRtpStatisticsCallback,
1207 (int, webrtc::StreamDataCountersCallback*));
1208 WEBRTC_STUB(RegisterReceiveChannelRtpStatisticsCallback,
1209 (int, webrtc::StreamDataCountersCallback*));
1210 WEBRTC_STUB(DeregisterReceiveChannelRtpStatisticsCallback,
1211 (int, webrtc::StreamDataCountersCallback*));
1212 WEBRTC_STUB(RegisterSendBitrateObserver,
1213 (int, webrtc::BitrateStatisticsObserver*));
1214 WEBRTC_STUB(DeregisterSendBitrateObserver,
1215 (int, webrtc::BitrateStatisticsObserver*));
1216 WEBRTC_STUB(RegisterSendFrameCountObserver,
1217 (int, webrtc::FrameCountObserver*));
1218 WEBRTC_STUB(DeregisterSendFrameCountObserver,
1219 (int, webrtc::FrameCountObserver*));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220
1221 WEBRTC_STUB(StartRTPDump, (const int, const char*, webrtc::RTPDirections));
1222 WEBRTC_STUB(StopRTPDump, (const int, webrtc::RTPDirections));
1223 WEBRTC_STUB(RegisterRTPObserver, (const int, webrtc::ViERTPObserver&));
1224 WEBRTC_STUB(DeregisterRTPObserver, (const int));
1225 WEBRTC_STUB(RegisterRTCPObserver, (const int, webrtc::ViERTCPObserver&));
1226 WEBRTC_STUB(DeregisterRTCPObserver, (const int));
1227
1228 // webrtc::ViEImageProcess
1229 WEBRTC_STUB(RegisterCaptureEffectFilter, (const int,
1230 webrtc::ViEEffectFilter&));
1231 WEBRTC_STUB(DeregisterCaptureEffectFilter, (const int));
1232 WEBRTC_STUB(RegisterSendEffectFilter, (const int,
1233 webrtc::ViEEffectFilter&));
1234 WEBRTC_STUB(DeregisterSendEffectFilter, (const int));
1235 WEBRTC_STUB(RegisterRenderEffectFilter, (const int,
1236 webrtc::ViEEffectFilter&));
1237 WEBRTC_STUB(DeregisterRenderEffectFilter, (const int));
1238 WEBRTC_STUB(EnableDeflickering, (const int, const bool));
1239 WEBRTC_FUNC(EnableDenoising, (const int capture_id, const bool denoising)) {
1240 WEBRTC_CHECK_CAPTURER(capture_id);
1241 capturers_[capture_id]->set_denoising(denoising);
1242 return 0;
1243 }
1244 WEBRTC_STUB(EnableColorEnhancement, (const int, const bool));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001245 WEBRTC_VOID_STUB(RegisterPreEncodeCallback,
1246 (int, webrtc::I420FrameCallback*));
1247 WEBRTC_VOID_STUB(DeRegisterPreEncodeCallback, (int));
1248 WEBRTC_VOID_STUB(RegisterPreRenderCallback,
1249 (int, webrtc::I420FrameCallback*));
1250 WEBRTC_VOID_STUB(DeRegisterPreRenderCallback, (int));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 // webrtc::ViEExternalCodec
1252 WEBRTC_FUNC(RegisterExternalSendCodec,
1253 (const int channel, const unsigned char pl_type, webrtc::VideoEncoder*,
1254 bool)) {
1255 WEBRTC_CHECK_CHANNEL(channel);
1256 channels_[channel]->ext_encoder_pl_types_.insert(pl_type);
1257 return 0;
1258 }
1259 WEBRTC_FUNC(DeRegisterExternalSendCodec,
1260 (const int channel, const unsigned char pl_type)) {
1261 WEBRTC_CHECK_CHANNEL(channel);
1262 channels_[channel]->ext_encoder_pl_types_.erase(pl_type);
1263 return 0;
1264 }
1265 WEBRTC_FUNC(RegisterExternalReceiveCodec,
1266 (const int channel, const unsigned int pl_type, webrtc::VideoDecoder*,
1267 bool, int)) {
1268 WEBRTC_CHECK_CHANNEL(channel);
1269 channels_[channel]->ext_decoder_pl_types_.insert(pl_type);
1270 return 0;
1271 }
1272 WEBRTC_FUNC(DeRegisterExternalReceiveCodec,
1273 (const int channel, const unsigned char pl_type)) {
1274 WEBRTC_CHECK_CHANNEL(channel);
1275 channels_[channel]->ext_decoder_pl_types_.erase(pl_type);
1276 return 0;
1277 }
1278
1279 private:
1280 bool IsChannelId(int id) const {
1281 return (id >= kViEChannelIdBase && id <= kViEChannelIdMax);
1282 }
1283 bool IsCapturerId(int id) const {
1284 return (id >= kViECaptureIdBase && id <= kViECaptureIdMax);
1285 }
1286
1287 bool inited_;
1288 int last_channel_;
1289 std::map<int, Channel*> channels_;
1290 bool fail_create_channel_;
1291 int last_capturer_;
1292 std::map<int, Capturer*> capturers_;
1293 bool fail_alloc_capturer_;
1294 const cricket::VideoCodec* const* codecs_;
1295 int num_codecs_;
1296 int num_set_send_codecs_; // how many times we call SetSendCodec().
1297};
1298
1299} // namespace cricket
1300
1301#endif // TALK_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_