1/*
2 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <iostream>
12
13#include "webrtc/engine_configurations.h"
14#include "webrtc/test/testsupport/fileutils.h"
15#include "webrtc/video_engine/include/vie_rtp_rtcp.h"
16#include "webrtc/video_engine/test/auto_test/interface/vie_autotest.h"
17#include "webrtc/video_engine/test/auto_test/interface/vie_autotest_defines.h"
18#include "webrtc/video_engine/test/libvietest/include/tb_capture_device.h"
19#include "webrtc/video_engine/test/libvietest/include/tb_external_transport.h"
20#include "webrtc/video_engine/test/libvietest/include/tb_interfaces.h"
21#include "webrtc/video_engine/test/libvietest/include/tb_video_channel.h"
22
23class ViERtpObserver: public webrtc::ViERTPObserver
24{
25public:
26    ViERtpObserver()
27    {
28    }
29    virtual ~ViERtpObserver()
30    {
31    }
32
33    virtual void IncomingSSRCChanged(const int videoChannel,
34                                     const unsigned int SSRC)
35    {
36    }
37    virtual void IncomingCSRCChanged(const int videoChannel,
38                                     const unsigned int CSRC, const bool added)
39    {
40    }
41};
42
43class ViERtcpObserver: public webrtc::ViERTCPObserver
44{
45public:
46    int _channel;
47    unsigned char _subType;
48    unsigned int _name;
49    char* _data;
50    unsigned short _dataLength;
51
52    ViERtcpObserver() :
53        _channel(-1),
54        _subType(0),
55        _name(0),
56        _data(NULL),
57        _dataLength(0)
58    {
59    }
60    ~ViERtcpObserver()
61    {
62        if (_data)
63        {
64            delete[] _data;
65        }
66    }
67    virtual void OnApplicationDataReceived(
68        const int videoChannel, const unsigned char subType,
69        const unsigned int name, const char* data,
70        const unsigned short dataLengthInBytes)
71    {
72        _channel = videoChannel;
73        _subType = subType;
74        _name = name;
75        if (dataLengthInBytes > _dataLength)
76        {
77            delete[] _data;
78            _data = NULL;
79        }
80        if (_data == NULL)
81        {
82            _data = new char[dataLengthInBytes];
83        }
84        memcpy(_data, data, dataLengthInBytes);
85        _dataLength = dataLengthInBytes;
86    }
87};
88
89void ViEAutoTest::ViERtpRtcpStandardTest()
90{
91    // ***************************************************************
92    // Begin create/initialize WebRTC Video Engine for testing
93    // ***************************************************************
94
95    // Create VIE
96    TbInterfaces ViE("ViERtpRtcpStandardTest");
97    // Create a video channel
98    TbVideoChannel tbChannel(ViE, webrtc::kVideoCodecVP8);
99
100    // Create a capture device
101    TbCaptureDevice tbCapture(ViE);
102    tbCapture.ConnectTo(tbChannel.videoChannel);
103
104    ViETest::Log("\n");
105    TbExternalTransport myTransport(*(ViE.network), tbChannel.videoChannel,
106                                    NULL);
107
108    ViE.network->DeregisterSendTransport(tbChannel.videoChannel);
109    EXPECT_EQ(0, ViE.network->RegisterSendTransport(
110        tbChannel.videoChannel, myTransport));
111
112    // ***************************************************************
113    // Engine ready. Begin testing class
114    // ***************************************************************
115    unsigned short startSequenceNumber = 12345;
116    ViETest::Log("Set start sequence number: %u", startSequenceNumber);
117    EXPECT_EQ(0, ViE.rtp_rtcp->SetStartSequenceNumber(
118        tbChannel.videoChannel, startSequenceNumber));
119    const unsigned int kVideoSsrc = 123456;
120    // Set an SSRC to avoid issues with collisions.
121    EXPECT_EQ(0, ViE.rtp_rtcp->SetLocalSSRC(tbChannel.videoChannel, kVideoSsrc,
122                                            webrtc::kViEStreamTypeNormal, 0));
123
124    myTransport.EnableSequenceNumberCheck();
125
126    EXPECT_EQ(0, ViE.base->StartReceive(tbChannel.videoChannel));
127    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
128
129    AutoTestSleep(2000);
130
131    unsigned short receivedSequenceNumber =
132        myTransport.GetFirstSequenceNumber();
133    ViETest::Log("First received sequence number: %u\n",
134                 receivedSequenceNumber);
135    EXPECT_EQ(startSequenceNumber, receivedSequenceNumber);
136
137    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
138
139    //
140    // RTCP CName
141    //
142    ViETest::Log("Testing CName\n");
143    const char* sendCName = "ViEAutoTestCName\0";
144    EXPECT_EQ(0, ViE.rtp_rtcp->SetRTCPCName(tbChannel.videoChannel, sendCName));
145
146    char returnCName[webrtc::ViERTP_RTCP::KMaxRTCPCNameLength];
147    memset(returnCName, 0, webrtc::ViERTP_RTCP::KMaxRTCPCNameLength);
148    EXPECT_EQ(0, ViE.rtp_rtcp->GetRTCPCName(
149        tbChannel.videoChannel, returnCName));
150    EXPECT_STRCASEEQ(sendCName, returnCName);
151
152    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
153
154    AutoTestSleep(1000);
155
156    if (FLAGS_include_timing_dependent_tests) {
157      char remoteCName[webrtc::ViERTP_RTCP::KMaxRTCPCNameLength];
158      memset(remoteCName, 0, webrtc::ViERTP_RTCP::KMaxRTCPCNameLength);
159      EXPECT_EQ(0, ViE.rtp_rtcp->GetRemoteRTCPCName(
160          tbChannel.videoChannel, remoteCName));
161      EXPECT_STRCASEEQ(sendCName, remoteCName);
162    }
163
164
165    //
166    // Pacing
167    //
168    webrtc::RtcpStatistics received;
169    int recRttMs = 0;
170    unsigned int sentTotalBitrate = 0;
171    unsigned int sentVideoBitrate = 0;
172    unsigned int sentFecBitrate = 0;
173    unsigned int sentNackBitrate = 0;
174
175    ViETest::Log("Testing Pacing\n");
176    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
177    EXPECT_EQ(0, ViE.base->StopReceive(tbChannel.videoChannel));
178
179    myTransport.ClearStats();
180
181    EXPECT_EQ(0, ViE.rtp_rtcp->SetNACKStatus(tbChannel.videoChannel, true));
182    EXPECT_EQ(0, ViE.base->StartReceive(tbChannel.videoChannel));
183    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
184
185    NetworkParameters network;
186    network.packet_loss_rate = 0;
187    network.loss_model = kUniformLoss;
188    myTransport.SetNetworkParameters(network);
189
190    AutoTestSleep(kAutoTestSleepTimeMs);
191
192    EXPECT_EQ(0, ViE.rtp_rtcp->GetReceiveChannelRtcpStatistics(
193        tbChannel.videoChannel, received, recRttMs));
194    EXPECT_EQ(0, ViE.rtp_rtcp->GetBandwidthUsage(
195        tbChannel.videoChannel, sentTotalBitrate, sentVideoBitrate,
196        sentFecBitrate, sentNackBitrate));
197
198    int num_rtp_packets = 0;
199    int num_dropped_packets = 0;
200    int num_rtcp_packets = 0;
201    std::map<uint8_t, int> packet_counters;
202    myTransport.GetStats(num_rtp_packets, num_dropped_packets, num_rtcp_packets,
203                         &packet_counters);
204    EXPECT_GT(num_rtp_packets, 0);
205    EXPECT_EQ(num_dropped_packets, 0);
206    EXPECT_GT(num_rtcp_packets, 0);
207    EXPECT_GT(sentTotalBitrate, 0u);
208    EXPECT_EQ(sentNackBitrate, 0u);
209    EXPECT_EQ(received.cumulative_lost, 0u);
210
211    //
212    // RTX
213    //
214    ViETest::Log("Testing NACK over RTX\n");
215    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
216    EXPECT_EQ(0, ViE.base->StopReceive(tbChannel.videoChannel));
217
218    myTransport.ClearStats();
219
220    const uint8_t kRtxPayloadType = 96;
221    // Temporarily disable pacing.
222    EXPECT_EQ(0, ViE.rtp_rtcp->SetTransmissionSmoothingStatus(
223        tbChannel.videoChannel, false));
224    EXPECT_EQ(0, ViE.rtp_rtcp->SetNACKStatus(tbChannel.videoChannel, true));
225    EXPECT_EQ(0, ViE.rtp_rtcp->SetRtxSendPayloadType(tbChannel.videoChannel,
226                                                     kRtxPayloadType));
227    EXPECT_EQ(0, ViE.rtp_rtcp->SetRtxReceivePayloadType(tbChannel.videoChannel,
228                                                        kRtxPayloadType));
229    EXPECT_EQ(0, ViE.rtp_rtcp->SetLocalSSRC(tbChannel.videoChannel, 1234,
230                                            webrtc::kViEStreamTypeRtx, 0));
231    EXPECT_EQ(0, ViE.rtp_rtcp->SetRemoteSSRCType(tbChannel.videoChannel,
232                                                 webrtc::kViEStreamTypeRtx,
233                                                 1234));
234    EXPECT_EQ(0, ViE.rtp_rtcp->SetStartSequenceNumber(
235        tbChannel.videoChannel, startSequenceNumber));
236    EXPECT_EQ(0, ViE.base->StartReceive(tbChannel.videoChannel));
237    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
238
239    // Make sure the first key frame gets through.
240    AutoTestSleep(100);
241    const int kPacketLossRate = 20;
242    network.packet_loss_rate = kPacketLossRate;
243    network.loss_model = kUniformLoss;
244    myTransport.SetNetworkParameters(network);
245    AutoTestSleep(kAutoTestSleepTimeMs);
246
247    EXPECT_EQ(0, ViE.rtp_rtcp->GetReceiveChannelRtcpStatistics(
248        tbChannel.videoChannel, received, recRttMs));
249    EXPECT_EQ(0, ViE.rtp_rtcp->GetBandwidthUsage(
250        tbChannel.videoChannel, sentTotalBitrate, sentVideoBitrate,
251        sentFecBitrate, sentNackBitrate));
252
253    packet_counters.clear();
254    myTransport.GetStats(num_rtp_packets, num_dropped_packets, num_rtcp_packets,
255                         &packet_counters);
256    EXPECT_GT(num_rtp_packets, 0);
257    EXPECT_GT(num_dropped_packets, 0);
258    EXPECT_GT(num_rtcp_packets, 0);
259    EXPECT_GT(packet_counters[kRtxPayloadType], 0);
260
261    // Make sure we have lost packets and that they were retransmitted.
262    // TODO(holmer): Disabled due to being flaky. Could be a bug in our stats.
263    // EXPECT_GT(recCumulativeLost, 0u);
264    EXPECT_GT(sentTotalBitrate, 0u);
265    EXPECT_GT(sentNackBitrate, 0u);
266
267    //
268    //  Statistics
269    //
270    // Stop and restart to clear stats
271    ViETest::Log("Testing statistics\n");
272    EXPECT_EQ(0, ViE.rtp_rtcp->SetNACKStatus(tbChannel.videoChannel, false));
273    EXPECT_EQ(0, ViE.base->StopReceive(tbChannel.videoChannel));
274    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
275
276    myTransport.ClearStats();
277    network.packet_loss_rate = kPacketLossRate;
278    network.loss_model = kUniformLoss;
279    myTransport.SetNetworkParameters(network);
280
281    // Start send to verify sending stats
282
283    EXPECT_EQ(0, ViE.rtp_rtcp->SetStartSequenceNumber(
284        tbChannel.videoChannel, startSequenceNumber));
285    EXPECT_EQ(0, ViE.base->StartReceive(tbChannel.videoChannel));
286    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
287
288    webrtc::RtcpStatistics sent;
289    int sentRttMs = 0;
290
291    // Fraction lost is a transient value that can get reset after a new rtcp
292    // report block. Make regular polls to make sure it is propagated.
293    // TODO(sprang): Replace with callbacks, when those are fully implemented.
294    int time_to_sleep = kAutoTestSleepTimeMs;
295    bool got_send_channel_frac_lost = false;
296    bool got_receive_channel_frac_lost = false;
297    while (time_to_sleep > 0) {
298      AutoTestSleep(500);
299      time_to_sleep -= 500;
300      EXPECT_EQ(0,
301                ViE.rtp_rtcp->GetSendChannelRtcpStatistics(
302                    tbChannel.videoChannel, sent, sentRttMs));
303      got_send_channel_frac_lost |= sent.fraction_lost > 0;
304      EXPECT_EQ(0,
305                ViE.rtp_rtcp->GetReceiveChannelRtcpStatistics(
306                    tbChannel.videoChannel, received, recRttMs));
307      got_receive_channel_frac_lost |= received.fraction_lost > 0;
308    }
309    EXPECT_TRUE(got_send_channel_frac_lost);
310    EXPECT_TRUE(got_receive_channel_frac_lost);
311
312    EXPECT_EQ(0, ViE.rtp_rtcp->GetBandwidthUsage(
313        tbChannel.videoChannel, sentTotalBitrate, sentVideoBitrate,
314        sentFecBitrate, sentNackBitrate));
315
316    EXPECT_GT(sentTotalBitrate, 0u);
317    EXPECT_EQ(sentFecBitrate, 0u);
318    EXPECT_EQ(sentNackBitrate, 0u);
319
320    EXPECT_EQ(0, ViE.base->StopReceive(tbChannel.videoChannel));
321
322    AutoTestSleep(2000);
323
324    EXPECT_EQ(0, ViE.rtp_rtcp->GetSendChannelRtcpStatistics(
325        tbChannel.videoChannel, sent, sentRttMs));
326    EXPECT_GT(sent.cumulative_lost, 0u);
327    EXPECT_GT(sent.extended_max_sequence_number, startSequenceNumber);
328    EXPECT_GT(sent.jitter, 0u);
329    EXPECT_GT(sentRttMs, 0);
330
331    EXPECT_EQ(0, ViE.rtp_rtcp->GetReceiveChannelRtcpStatistics(
332        tbChannel.videoChannel, received, recRttMs));
333
334    EXPECT_GT(received.cumulative_lost, 0u);
335    EXPECT_GT(received.extended_max_sequence_number, startSequenceNumber);
336    EXPECT_GT(received.jitter, 0u);
337    EXPECT_GT(recRttMs, 0);
338
339    unsigned int estimated_bandwidth = 0;
340    EXPECT_EQ(0, ViE.rtp_rtcp->GetEstimatedSendBandwidth(
341        tbChannel.videoChannel,
342        &estimated_bandwidth));
343    EXPECT_GT(estimated_bandwidth, 0u);
344
345    if (FLAGS_include_timing_dependent_tests) {
346      EXPECT_EQ(0, ViE.rtp_rtcp->GetEstimatedReceiveBandwidth(
347          tbChannel.videoChannel,
348          &estimated_bandwidth));
349      EXPECT_GT(estimated_bandwidth, 0u);
350
351      int passive_channel = -1;
352      EXPECT_EQ(ViE.base->CreateReceiveChannel(passive_channel,
353                                               tbChannel.videoChannel), 0);
354      EXPECT_EQ(ViE.base->StartReceive(passive_channel), 0);
355      EXPECT_EQ(
356          ViE.rtp_rtcp->GetEstimatedReceiveBandwidth(passive_channel,
357                                                     &estimated_bandwidth),
358          0);
359      EXPECT_EQ(estimated_bandwidth, 0u);
360    }
361
362    // Check that rec stats extended max is greater than what we've sent.
363    EXPECT_GE(received.extended_max_sequence_number,
364              sent.extended_max_sequence_number);
365    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
366    EXPECT_EQ(0, ViE.base->StopReceive(tbChannel.videoChannel));
367
368    //
369    // Test bandwidth statistics with reserved bitrate
370    //
371
372    myTransport.ClearStats();
373    network.packet_loss_rate = 0;
374    network.loss_model = kUniformLoss;
375    myTransport.SetNetworkParameters(network);
376
377    ViE.rtp_rtcp->SetReservedTransmitBitrate(tbChannel.videoChannel, 2000000);
378
379    EXPECT_EQ(0, ViE.base->StartReceive(tbChannel.videoChannel));
380    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
381
382    AutoTestSleep(kAutoTestSleepTimeMs);
383
384    estimated_bandwidth = 0;
385    EXPECT_EQ(0, ViE.rtp_rtcp->GetEstimatedSendBandwidth(tbChannel.videoChannel,
386                                                         &estimated_bandwidth));
387    if (FLAGS_include_timing_dependent_tests) {
388      EXPECT_EQ(0u, estimated_bandwidth);
389    }
390
391    EXPECT_EQ(0, ViE.base->StopReceive(tbChannel.videoChannel));
392    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
393
394    //
395    // Test bandwidth statistics with NACK and FEC separately
396    //
397
398    myTransport.ClearStats();
399    network.packet_loss_rate = kPacketLossRate;
400    myTransport.SetNetworkParameters(network);
401
402    EXPECT_EQ(0, ViE.rtp_rtcp->SetFECStatus(
403        tbChannel.videoChannel, true, 96, 97));
404    EXPECT_EQ(0, ViE.base->StartReceive(tbChannel.videoChannel));
405    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
406
407    AutoTestSleep(kAutoTestSleepTimeMs);
408
409    EXPECT_EQ(0, ViE.rtp_rtcp->GetBandwidthUsage(
410        tbChannel.videoChannel, sentTotalBitrate, sentVideoBitrate,
411         sentFecBitrate, sentNackBitrate));
412
413    if (FLAGS_include_timing_dependent_tests) {
414      EXPECT_GT(sentTotalBitrate, 0u);
415      EXPECT_GT(sentFecBitrate, 0u);
416      EXPECT_EQ(sentNackBitrate, 0u);
417    }
418
419    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
420    EXPECT_EQ(0, ViE.rtp_rtcp->SetFECStatus(
421        tbChannel.videoChannel, false, 96, 97));
422    EXPECT_EQ(0, ViE.rtp_rtcp->SetNACKStatus(tbChannel.videoChannel, true));
423    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
424
425    AutoTestSleep(4 * kAutoTestSleepTimeMs);
426
427    EXPECT_EQ(0, ViE.rtp_rtcp->GetBandwidthUsage(
428        tbChannel.videoChannel, sentTotalBitrate, sentVideoBitrate,
429        sentFecBitrate, sentNackBitrate));
430
431    if (FLAGS_include_timing_dependent_tests) {
432      EXPECT_GT(sentTotalBitrate, 0u);
433      EXPECT_EQ(sentFecBitrate, 0u);
434
435      // TODO(holmer): Test disabled due to being too flaky on buildbots. Tests
436      // for new API provide partial coverage.
437      // EXPECT_GT(sentNackBitrate, 0u);
438    }
439
440    EXPECT_EQ(0, ViE.base->StopReceive(tbChannel.videoChannel));
441    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
442    EXPECT_EQ(0, ViE.rtp_rtcp->SetNACKStatus(tbChannel.videoChannel, false));
443
444
445    // Test to set SSRC
446    network.packet_loss_rate = 0;
447    myTransport.SetNetworkParameters(network);
448    myTransport.ClearStats();
449
450    unsigned int setSSRC = 0x01234567;
451    ViETest::Log("Set SSRC %u", setSSRC);
452    EXPECT_EQ(0, ViE.rtp_rtcp->SetLocalSSRC(tbChannel.videoChannel, setSSRC));
453    EXPECT_EQ(0, ViE.base->StartReceive(tbChannel.videoChannel));
454    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
455
456    myTransport.EnableSSRCCheck();
457
458    AutoTestSleep(2000);
459    unsigned int receivedSSRC = myTransport.ReceivedSSRC();
460    ViETest::Log("Received SSRC %u\n", receivedSSRC);
461
462    if (FLAGS_include_timing_dependent_tests) {
463      EXPECT_EQ(setSSRC, receivedSSRC);
464
465      unsigned int localSSRC = 0;
466      EXPECT_EQ(0, ViE.rtp_rtcp->GetLocalSSRC(
467          tbChannel.videoChannel, localSSRC));
468      EXPECT_EQ(setSSRC, localSSRC);
469
470      unsigned int remoteSSRC = 0;
471      EXPECT_EQ(0, ViE.rtp_rtcp->GetRemoteSSRC(
472          tbChannel.videoChannel, remoteSSRC));
473      EXPECT_EQ(setSSRC, remoteSSRC);
474    }
475
476    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
477
478    ViETest::Log("Testing RTP dump...\n");
479
480    std::string inDumpName =
481        ViETest::GetResultOutputPath() + "IncomingRTPDump.rtp";
482    std::string outDumpName =
483        ViETest::GetResultOutputPath() + "OutgoingRTPDump.rtp";
484    EXPECT_EQ(0, ViE.rtp_rtcp->StartRTPDump(
485        tbChannel.videoChannel, inDumpName.c_str(), webrtc::kRtpIncoming));
486    EXPECT_EQ(0, ViE.rtp_rtcp->StartRTPDump(
487        tbChannel.videoChannel, outDumpName.c_str(), webrtc::kRtpOutgoing));
488
489    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
490
491    AutoTestSleep(kAutoTestSleepTimeMs);
492
493    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
494
495    AutoTestSleep(1000);
496
497    EXPECT_EQ(0, ViE.rtp_rtcp->StopRTPDump(
498        tbChannel.videoChannel, webrtc::kRtpIncoming));
499    EXPECT_EQ(0, ViE.rtp_rtcp->StopRTPDump(
500        tbChannel.videoChannel, webrtc::kRtpOutgoing));
501
502    // Make sure data was actually saved to the file and we stored the same
503    // amount of data in both files
504    FILE* inDump = fopen(inDumpName.c_str(), "r");
505    fseek(inDump, 0L, SEEK_END);
506    long inEndPos = ftell(inDump);
507    fclose(inDump);
508    FILE* outDump = fopen(outDumpName.c_str(), "r");
509    fseek(outDump, 0L, SEEK_END);
510    // long outEndPos = ftell(outDump);
511    fclose(outDump);
512
513    EXPECT_GT(inEndPos, 0);
514
515    // TODO(phoglund): This is flaky for some reason. Are the sleeps too
516    // short above?
517    // EXPECT_LT(inEndPos, outEndPos + 100);
518
519    EXPECT_EQ(0, ViE.base->StopReceive(tbChannel.videoChannel));
520
521
522    ViETest::Log("Testing Network Down...\n");
523
524    EXPECT_EQ(0, ViE.rtp_rtcp->SetNACKStatus(tbChannel.videoChannel, true));
525    // Reenable pacing.
526    EXPECT_EQ(0, ViE.rtp_rtcp->SetTransmissionSmoothingStatus(
527        tbChannel.videoChannel, true));
528
529    webrtc::StreamDataCounters sent_before;
530    webrtc::StreamDataCounters received_before;
531    webrtc::StreamDataCounters sent_after;
532    webrtc::StreamDataCounters received_after;
533
534    EXPECT_EQ(0, ViE.rtp_rtcp->GetRtpStatistics(tbChannel.videoChannel,
535                                                sent_before,
536                                                received_before));
537    EXPECT_EQ(0, ViE.base->StartReceive(tbChannel.videoChannel));
538    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
539
540    // Real-time mode.
541    AutoTestSleep(kAutoTestSleepTimeMs);
542    EXPECT_EQ(0, ViE.rtp_rtcp->GetRtpStatistics(tbChannel.videoChannel,
543                                                sent_after, received_after));
544    if (FLAGS_include_timing_dependent_tests) {
545      EXPECT_GT(received_after.bytes, received_before.bytes);
546    }
547    // Simulate lost reception and verify that nothing is sent during that time.
548    ViE.network->SetNetworkTransmissionState(tbChannel.videoChannel, false);
549    // Allow the encoder to finish the current frame before we expect that no
550    // additional packets will be sent.
551    AutoTestSleep(kAutoTestSleepTimeMs);
552    received_before.bytes = received_after.bytes;
553    ViETest::Log("Network Down...\n");
554    AutoTestSleep(kAutoTestSleepTimeMs);
555    EXPECT_EQ(0, ViE.rtp_rtcp->GetRtpStatistics(tbChannel.videoChannel,
556                                                sent_before,
557                                                received_before));
558    if (FLAGS_include_timing_dependent_tests) {
559      EXPECT_EQ(received_before.bytes, received_after.bytes);
560    }
561
562    // Network reception back. Video should now be sent.
563    ViE.network->SetNetworkTransmissionState(tbChannel.videoChannel, true);
564    ViETest::Log("Network Up...\n");
565    AutoTestSleep(kAutoTestSleepTimeMs);
566    EXPECT_EQ(0, ViE.rtp_rtcp->GetRtpStatistics(tbChannel.videoChannel,
567                                                sent_before,
568                                                received_before));
569    if (FLAGS_include_timing_dependent_tests) {
570      EXPECT_GT(received_before.bytes, received_after.bytes);
571    }
572    received_after.bytes = received_before.bytes;
573    // Buffering mode.
574    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
575    EXPECT_EQ(0, ViE.base->StopReceive(tbChannel.videoChannel));
576    ViE.rtp_rtcp->SetSenderBufferingMode(tbChannel.videoChannel,
577                                         kAutoTestSleepTimeMs / 2);
578    // Add extra delay to the receiver to make sure it doesn't flush due to
579    // too old packets being received (as the down-time introduced is longer
580    // than what we buffer at the sender).
581    ViE.rtp_rtcp->SetReceiverBufferingMode(tbChannel.videoChannel,
582                                           3 * kAutoTestSleepTimeMs / 2);
583    EXPECT_EQ(0, ViE.base->StartReceive(tbChannel.videoChannel));
584    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
585    AutoTestSleep(kAutoTestSleepTimeMs);
586    // Simulate lost reception and verify that nothing is sent during that time.
587    ViETest::Log("Network Down...\n");
588    ViE.network->SetNetworkTransmissionState(tbChannel.videoChannel, false);
589    // Allow the encoder to finish the current frame before we expect that no
590    // additional packets will be sent.
591    AutoTestSleep(kAutoTestSleepTimeMs);
592    EXPECT_EQ(0, ViE.rtp_rtcp->GetRtpStatistics(tbChannel.videoChannel,
593                                                sent_before,
594                                                received_before));
595    if (FLAGS_include_timing_dependent_tests) {
596      EXPECT_GT(received_before.bytes, received_after.bytes);
597    }
598    received_after.bytes = received_before.bytes;
599    AutoTestSleep(kAutoTestSleepTimeMs);
600    EXPECT_EQ(0, ViE.rtp_rtcp->GetRtpStatistics(tbChannel.videoChannel,
601                                                sent_before,
602                                                received_before));
603    if (FLAGS_include_timing_dependent_tests) {
604      EXPECT_EQ(received_after.bytes, received_before.bytes);
605    }
606    // Network reception back. Video should now be sent.
607    ViETest::Log("Network Up...\n");
608    ViE.network->SetNetworkTransmissionState(tbChannel.videoChannel, true);
609    AutoTestSleep(kAutoTestSleepTimeMs);
610    EXPECT_EQ(0, ViE.rtp_rtcp->GetRtpStatistics(tbChannel.videoChannel,
611                                                sent_before,
612                                                received_before));
613    if (FLAGS_include_timing_dependent_tests) {
614      EXPECT_GT(received_before.bytes, received_after.bytes);
615    }
616    // TODO(holmer): Verify that the decoded framerate doesn't decrease on an
617    // outage when in buffering mode. This isn't currently possible because we
618    // don't have an API to get decoded framerate.
619
620    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
621    EXPECT_EQ(0, ViE.base->StopReceive(tbChannel.videoChannel));
622
623
624    // Deregister external transport
625    EXPECT_EQ(0, ViE.network->DeregisterSendTransport(tbChannel.videoChannel));
626
627
628    //***************************************************************
629    //  Testing finished. Tear down Video Engine
630    //***************************************************************
631}
632
633void ViEAutoTest::ViERtpRtcpExtendedTest()
634{
635    //***************************************************************
636    //  Begin create/initialize WebRTC Video Engine for testing
637    //***************************************************************
638    // Create VIE
639    TbInterfaces ViE("ViERtpRtcpExtendedTest");
640    // Create a video channel
641    TbVideoChannel tbChannel(ViE, webrtc::kVideoCodecVP8);
642    // Create a capture device
643    TbCaptureDevice tbCapture(ViE);
644    tbCapture.ConnectTo(tbChannel.videoChannel);
645
646    //tbChannel.StartReceive(rtpPort);
647    //tbChannel.StartSend(rtpPort);
648    TbExternalTransport myTransport(*(ViE.network), tbChannel.videoChannel,
649                                    NULL);
650
651    EXPECT_EQ(0, ViE.network->DeregisterSendTransport(tbChannel.videoChannel));
652    EXPECT_EQ(0, ViE.network->RegisterSendTransport(
653        tbChannel.videoChannel, myTransport));
654    EXPECT_EQ(0, ViE.base->StartReceive(tbChannel.videoChannel));
655    EXPECT_EQ(0, ViE.base->StartSend(tbChannel.videoChannel));
656
657    //***************************************************************
658    //  Engine ready. Begin testing class
659    //***************************************************************
660
661    //
662    // Application specific RTCP
663    //
664    //
665
666    ViERtcpObserver rtcpObserver;
667    EXPECT_EQ(0, ViE.rtp_rtcp->RegisterRTCPObserver(
668        tbChannel.videoChannel, rtcpObserver));
669
670    unsigned char subType = 3;
671    unsigned int name = static_cast<unsigned int> (0x41424344); // 'ABCD';
672    const char* data = "ViEAutoTest Data of length 32 -\0";
673    const unsigned short numBytes = 32;
674
675    EXPECT_EQ(0, ViE.rtp_rtcp->SendApplicationDefinedRTCPPacket(
676        tbChannel.videoChannel, subType, name, data, numBytes));
677
678    ViETest::Log("Sending RTCP application data...\n");
679    AutoTestSleep(kAutoTestSleepTimeMs);
680
681    EXPECT_EQ(subType, rtcpObserver._subType);
682    EXPECT_STRCASEEQ(data, rtcpObserver._data);
683    EXPECT_EQ(name, rtcpObserver._name);
684    EXPECT_EQ(numBytes, rtcpObserver._dataLength);
685
686    ViETest::Log("\t RTCP application data received\n");
687
688    //***************************************************************
689    //  Testing finished. Tear down Video Engine
690    //***************************************************************
691    EXPECT_EQ(0, ViE.base->StopReceive(tbChannel.videoChannel));
692    EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel));
693
694    EXPECT_EQ(0, ViE.network->DeregisterSendTransport(tbChannel.videoChannel));
695}
696
697void ViEAutoTest::ViERtpRtcpAPITest()
698{
699    //***************************************************************
700    //  Begin create/initialize WebRTC Video Engine for testing
701    //***************************************************************
702    // Create VIE
703    TbInterfaces ViE("ViERtpRtcpAPITest");
704
705    // Create a video channel
706    TbVideoChannel tbChannel(ViE, webrtc::kVideoCodecVP8);
707
708    // Create a capture device
709    TbCaptureDevice tbCapture(ViE);
710    tbCapture.ConnectTo(tbChannel.videoChannel);
711
712    //***************************************************************
713    //  Engine ready. Begin testing class
714    //***************************************************************
715
716    //
717    // Check different RTCP modes
718    //
719    webrtc::ViERTCPMode rtcpMode = webrtc::kRtcpNone;
720    EXPECT_EQ(0, ViE.rtp_rtcp->GetRTCPStatus(
721        tbChannel.videoChannel, rtcpMode));
722    EXPECT_EQ(webrtc::kRtcpCompound_RFC4585, rtcpMode);
723    EXPECT_EQ(0, ViE.rtp_rtcp->SetRTCPStatus(
724        tbChannel.videoChannel, webrtc::kRtcpCompound_RFC4585));
725    EXPECT_EQ(0, ViE.rtp_rtcp->GetRTCPStatus(
726        tbChannel.videoChannel, rtcpMode));
727    EXPECT_EQ(webrtc::kRtcpCompound_RFC4585, rtcpMode);
728    EXPECT_EQ(0, ViE.rtp_rtcp->SetRTCPStatus(
729        tbChannel.videoChannel, webrtc::kRtcpNonCompound_RFC5506));
730    EXPECT_EQ(0, ViE.rtp_rtcp->GetRTCPStatus(
731        tbChannel.videoChannel, rtcpMode));
732    EXPECT_EQ(webrtc::kRtcpNonCompound_RFC5506, rtcpMode);
733    EXPECT_EQ(0, ViE.rtp_rtcp->SetRTCPStatus(
734        tbChannel.videoChannel, webrtc::kRtcpNone));
735    EXPECT_EQ(0, ViE.rtp_rtcp->GetRTCPStatus(
736        tbChannel.videoChannel, rtcpMode));
737    EXPECT_EQ(webrtc::kRtcpNone, rtcpMode);
738    EXPECT_EQ(0, ViE.rtp_rtcp->SetRTCPStatus(
739        tbChannel.videoChannel, webrtc::kRtcpCompound_RFC4585));
740
741    //
742    // CName is testedn in SimpleTest
743    // Start sequence number is tested in SimplTEst
744    //
745    const char* testCName = "ViEAutotestCName";
746    EXPECT_EQ(0, ViE.rtp_rtcp->SetRTCPCName(
747        tbChannel.videoChannel, testCName));
748
749    char returnCName[256];
750    memset(returnCName, 0, 256);
751    EXPECT_EQ(0, ViE.rtp_rtcp->GetRTCPCName(
752        tbChannel.videoChannel, returnCName));
753    EXPECT_STRCASEEQ(testCName, returnCName);
754
755    //
756    // SSRC
757    //
758    EXPECT_EQ(0, ViE.rtp_rtcp->SetLocalSSRC(
759        tbChannel.videoChannel, 0x01234567));
760    EXPECT_EQ(0, ViE.rtp_rtcp->SetLocalSSRC(
761        tbChannel.videoChannel, 0x76543210));
762
763    unsigned int ssrc = 0;
764    EXPECT_EQ(0, ViE.rtp_rtcp->GetLocalSSRC(tbChannel.videoChannel, ssrc));
765    EXPECT_EQ(0, ViE.rtp_rtcp->SetStartSequenceNumber(
766        tbChannel.videoChannel, 1000));
767    tbChannel.StartSend();
768    EXPECT_NE(0, ViE.rtp_rtcp->SetStartSequenceNumber(
769        tbChannel.videoChannel, 12345));
770    tbChannel.StopSend();
771
772    //
773    // Start sequence number
774    //
775    EXPECT_EQ(0, ViE.rtp_rtcp->SetStartSequenceNumber(
776        tbChannel.videoChannel, 12345));
777    EXPECT_EQ(0, ViE.rtp_rtcp->SetStartSequenceNumber(
778        tbChannel.videoChannel, 1000));
779    tbChannel.StartSend();
780    EXPECT_NE(0, ViE.rtp_rtcp->SetStartSequenceNumber(
781        tbChannel.videoChannel, 12345));
782    tbChannel.StopSend();
783
784    //
785    // Application specific RTCP
786    //
787    {
788        unsigned char subType = 3;
789        unsigned int name = static_cast<unsigned int> (0x41424344); // 'ABCD';
790        const char* data = "ViEAutoTest Data of length 32 --";
791        const unsigned short numBytes = 32;
792
793        tbChannel.StartSend();
794        EXPECT_EQ(0, ViE.rtp_rtcp->SendApplicationDefinedRTCPPacket(
795            tbChannel.videoChannel, subType, name, data, numBytes));
796        EXPECT_NE(0, ViE.rtp_rtcp->SendApplicationDefinedRTCPPacket(
797            tbChannel.videoChannel, subType, name, NULL, numBytes)) <<
798                "Should fail on NULL input.";
799        EXPECT_NE(0, ViE.rtp_rtcp->SendApplicationDefinedRTCPPacket(
800            tbChannel.videoChannel, subType, name, data, numBytes - 1)) <<
801                "Should fail on incorrect length.";
802
803        EXPECT_EQ(0, ViE.rtp_rtcp->GetRTCPStatus(
804            tbChannel.videoChannel, rtcpMode));
805        EXPECT_EQ(0, ViE.rtp_rtcp->SendApplicationDefinedRTCPPacket(
806            tbChannel.videoChannel, subType, name, data, numBytes));
807        EXPECT_EQ(0, ViE.rtp_rtcp->SetRTCPStatus(
808            tbChannel.videoChannel, webrtc::kRtcpCompound_RFC4585));
809        tbChannel.StopSend();
810        EXPECT_NE(0, ViE.rtp_rtcp->SendApplicationDefinedRTCPPacket(
811            tbChannel.videoChannel, subType, name, data, numBytes));
812    }
813
814    //
815    // Statistics
816    //
817    // Tested in SimpleTest(), we'll get errors if we haven't received a RTCP
818    // packet.
819
820    //
821    // RTP Dump
822    //
823    {
824        std::string output_file = webrtc::test::OutputPath() +
825            "DumpFileName.rtp";
826        const char* dumpName = output_file.c_str();
827
828        EXPECT_EQ(0, ViE.rtp_rtcp->StartRTPDump(
829            tbChannel.videoChannel, dumpName, webrtc::kRtpIncoming));
830        EXPECT_EQ(0, ViE.rtp_rtcp->StopRTPDump(
831            tbChannel.videoChannel, webrtc::kRtpIncoming));
832        EXPECT_NE(0, ViE.rtp_rtcp->StopRTPDump(
833            tbChannel.videoChannel, webrtc::kRtpIncoming));
834        EXPECT_EQ(0, ViE.rtp_rtcp->StartRTPDump(
835            tbChannel.videoChannel, dumpName, webrtc::kRtpOutgoing));
836        EXPECT_EQ(0, ViE.rtp_rtcp->StopRTPDump(
837            tbChannel.videoChannel, webrtc::kRtpOutgoing));
838        EXPECT_NE(0, ViE.rtp_rtcp->StopRTPDump(
839            tbChannel.videoChannel, webrtc::kRtpOutgoing));
840        EXPECT_NE(0, ViE.rtp_rtcp->StartRTPDump(
841            tbChannel.videoChannel, dumpName, (webrtc::RTPDirections) 3));
842    }
843    //
844    // RTP/RTCP Observers
845    //
846    {
847        ViERtpObserver rtpObserver;
848        EXPECT_EQ(0, ViE.rtp_rtcp->RegisterRTPObserver(
849            tbChannel.videoChannel, rtpObserver));
850        EXPECT_NE(0, ViE.rtp_rtcp->RegisterRTPObserver(
851            tbChannel.videoChannel, rtpObserver));
852        EXPECT_EQ(0, ViE.rtp_rtcp->DeregisterRTPObserver(
853            tbChannel.videoChannel));
854        EXPECT_NE(0, ViE.rtp_rtcp->DeregisterRTPObserver(
855            tbChannel.videoChannel));
856
857        ViERtcpObserver rtcpObserver;
858        EXPECT_EQ(0, ViE.rtp_rtcp->RegisterRTCPObserver(
859            tbChannel.videoChannel, rtcpObserver));
860        EXPECT_NE(0, ViE.rtp_rtcp->RegisterRTCPObserver(
861            tbChannel.videoChannel, rtcpObserver));
862        EXPECT_EQ(0, ViE.rtp_rtcp->DeregisterRTCPObserver(
863            tbChannel.videoChannel));
864        EXPECT_NE(0, ViE.rtp_rtcp->DeregisterRTCPObserver(
865            tbChannel.videoChannel));
866    }
867    //
868    // PLI
869    //
870    {
871        EXPECT_EQ(0, ViE.rtp_rtcp->SetKeyFrameRequestMethod(
872            tbChannel.videoChannel, webrtc::kViEKeyFrameRequestPliRtcp));
873        EXPECT_EQ(0, ViE.rtp_rtcp->SetKeyFrameRequestMethod(
874            tbChannel.videoChannel, webrtc::kViEKeyFrameRequestPliRtcp));
875        EXPECT_EQ(0, ViE.rtp_rtcp->SetKeyFrameRequestMethod(
876            tbChannel.videoChannel, webrtc::kViEKeyFrameRequestNone));
877        EXPECT_EQ(0, ViE.rtp_rtcp->SetKeyFrameRequestMethod(
878            tbChannel.videoChannel, webrtc::kViEKeyFrameRequestNone));
879    }
880    //
881    // NACK
882    //
883    {
884      EXPECT_EQ(0, ViE.rtp_rtcp->SetNACKStatus(tbChannel.videoChannel, true));
885    }
886
887    // Timestamp offset extension.
888    // Valid range is 1 to 14 inclusive.
889    EXPECT_EQ(-1, ViE.rtp_rtcp->SetSendTimestampOffsetStatus(
890        tbChannel.videoChannel, true, 0));
891    EXPECT_EQ(-1, ViE.rtp_rtcp->SetSendTimestampOffsetStatus(
892        tbChannel.videoChannel, true, 15));
893    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendTimestampOffsetStatus(
894        tbChannel.videoChannel, true, 3));
895    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendTimestampOffsetStatus(
896        tbChannel.videoChannel, true, 3));
897    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendTimestampOffsetStatus(
898            tbChannel.videoChannel, false, 3));
899    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendTimestampOffsetStatus(
900        tbChannel.videoChannel, true, 3));
901    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendTimestampOffsetStatus(
902              tbChannel.videoChannel, false, 3));
903    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendTimestampOffsetStatus(
904            tbChannel.videoChannel, false, 3));
905
906    EXPECT_EQ(-1, ViE.rtp_rtcp->SetReceiveTimestampOffsetStatus(
907        tbChannel.videoChannel, true, 0));
908    EXPECT_EQ(-1, ViE.rtp_rtcp->SetReceiveTimestampOffsetStatus(
909        tbChannel.videoChannel, true, 15));
910    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveTimestampOffsetStatus(
911        tbChannel.videoChannel, true, 3));
912    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveTimestampOffsetStatus(
913        tbChannel.videoChannel, true, 3));
914    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveTimestampOffsetStatus(
915            tbChannel.videoChannel, false, 3));
916    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveTimestampOffsetStatus(
917        tbChannel.videoChannel, true, 3));
918    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveTimestampOffsetStatus(
919              tbChannel.videoChannel, false, 3));
920    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveTimestampOffsetStatus(
921            tbChannel.videoChannel, false, 3));
922
923    // Absolute send time extension.
924    // Valid range is 1 to 14 inclusive.
925    EXPECT_EQ(-1, ViE.rtp_rtcp->SetSendAbsoluteSendTimeStatus(
926        tbChannel.videoChannel, true, 0));
927    EXPECT_EQ(-1, ViE.rtp_rtcp->SetSendAbsoluteSendTimeStatus(
928        tbChannel.videoChannel, true, 15));
929    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendAbsoluteSendTimeStatus(
930        tbChannel.videoChannel, true, 3));
931    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendAbsoluteSendTimeStatus(
932        tbChannel.videoChannel, true, 3));
933    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendAbsoluteSendTimeStatus(
934        tbChannel.videoChannel, false, 3));
935    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendAbsoluteSendTimeStatus(
936        tbChannel.videoChannel, true, 3));
937    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendAbsoluteSendTimeStatus(
938        tbChannel.videoChannel, false, 3));
939    EXPECT_EQ(0, ViE.rtp_rtcp->SetSendAbsoluteSendTimeStatus(
940        tbChannel.videoChannel, false, 3));
941
942    EXPECT_EQ(-1, ViE.rtp_rtcp->SetReceiveAbsoluteSendTimeStatus(
943        tbChannel.videoChannel, true, 0));
944    EXPECT_EQ(-1, ViE.rtp_rtcp->SetReceiveAbsoluteSendTimeStatus(
945        tbChannel.videoChannel, true, 15));
946    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveAbsoluteSendTimeStatus(
947        tbChannel.videoChannel, true, 3));
948    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveAbsoluteSendTimeStatus(
949        tbChannel.videoChannel, true, 3));
950    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveAbsoluteSendTimeStatus(
951        tbChannel.videoChannel, false, 3));
952    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveAbsoluteSendTimeStatus(
953        tbChannel.videoChannel, true, 3));
954    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveAbsoluteSendTimeStatus(
955        tbChannel.videoChannel, false, 3));
956    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiveAbsoluteSendTimeStatus(
957        tbChannel.videoChannel, false, 3));
958
959    // Transmission smoothening.
960    const int invalid_channel_id = 17;
961    EXPECT_EQ(-1, ViE.rtp_rtcp->SetTransmissionSmoothingStatus(
962        invalid_channel_id, true));
963    EXPECT_EQ(0, ViE.rtp_rtcp->SetTransmissionSmoothingStatus(
964        tbChannel.videoChannel, true));
965    EXPECT_EQ(0, ViE.rtp_rtcp->SetTransmissionSmoothingStatus(
966        tbChannel.videoChannel, true));
967    EXPECT_EQ(0, ViE.rtp_rtcp->SetTransmissionSmoothingStatus(
968        tbChannel.videoChannel, false));
969    EXPECT_EQ(0, ViE.rtp_rtcp->SetTransmissionSmoothingStatus(
970        tbChannel.videoChannel, false));
971
972    // Buffering mode - sender side.
973    EXPECT_EQ(-1, ViE.rtp_rtcp->SetSenderBufferingMode(
974        invalid_channel_id, 0));
975    int invalid_delay = -1;
976    EXPECT_EQ(-1, ViE.rtp_rtcp->SetSenderBufferingMode(
977        tbChannel.videoChannel, invalid_delay));
978    invalid_delay = 15000;
979    EXPECT_EQ(-1, ViE.rtp_rtcp->SetSenderBufferingMode(
980        tbChannel.videoChannel, invalid_delay));
981    EXPECT_EQ(0, ViE.rtp_rtcp->SetSenderBufferingMode(
982        tbChannel.videoChannel, 5000));
983
984    // Buffering mode - receiver side.
985    // Run without VoE to verify it that does not crash, but return an error.
986    EXPECT_EQ(-1, ViE.rtp_rtcp->SetReceiverBufferingMode(
987        tbChannel.videoChannel, 0));
988    EXPECT_EQ(-1, ViE.rtp_rtcp->SetReceiverBufferingMode(
989        tbChannel.videoChannel, 2000));
990
991    // Set VoE (required to set up stream-sync).
992    webrtc::VoiceEngine* voice_engine = webrtc::VoiceEngine::Create();
993    EXPECT_TRUE(NULL != voice_engine);
994    webrtc::VoEBase* voe_base = webrtc::VoEBase::GetInterface(voice_engine);
995    EXPECT_TRUE(NULL != voe_base);
996    EXPECT_EQ(0, voe_base->Init());
997    int audio_channel = voe_base->CreateChannel();
998    EXPECT_NE(-1, audio_channel);
999    EXPECT_EQ(0, ViE.base->SetVoiceEngine(voice_engine));
1000    EXPECT_EQ(0, ViE.base->ConnectAudioChannel(tbChannel.videoChannel,
1001                                               audio_channel));
1002
1003    EXPECT_EQ(-1, ViE.rtp_rtcp->SetReceiverBufferingMode(
1004        invalid_channel_id, 0));
1005    EXPECT_EQ(-1, ViE.rtp_rtcp->SetReceiverBufferingMode(
1006        tbChannel.videoChannel, invalid_delay));
1007    invalid_delay = 15000;
1008    EXPECT_EQ(-1, ViE.rtp_rtcp->SetReceiverBufferingMode(
1009        tbChannel.videoChannel, invalid_delay));
1010    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiverBufferingMode(
1011        tbChannel.videoChannel, 5000));
1012
1013    // Real-time mode - sender side.
1014    EXPECT_EQ(0, ViE.rtp_rtcp->SetSenderBufferingMode(
1015        tbChannel.videoChannel, 0));
1016    // Real-time mode - receiver side.
1017    EXPECT_EQ(0, ViE.rtp_rtcp->SetReceiverBufferingMode(
1018        tbChannel.videoChannel, 0));
1019
1020    EXPECT_EQ(0, ViE.base->DisconnectAudioChannel(tbChannel.videoChannel));
1021    EXPECT_EQ(0, ViE.base->SetVoiceEngine(NULL));
1022    EXPECT_EQ(0, voe_base->DeleteChannel(audio_channel));
1023    voe_base->Release();
1024    EXPECT_TRUE(webrtc::VoiceEngine::Delete(voice_engine));
1025
1026    //***************************************************************
1027    //  Testing finished. Tear down Video Engine
1028    //***************************************************************
1029}
1030