File: dual_stream_unittest.cc

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (542 lines) | stat: -rw-r--r-- 19,638 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
#include "webrtc/modules/audio_coding/main/test/PCMFile.h"
#include "webrtc/modules/audio_coding/main/test/utility.h"
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
#include "webrtc/typedefs.h"
#include "webrtc/test/testsupport/fileutils.h"
#include "webrtc/test/testsupport/gtest_disable.h"

namespace webrtc {

class DualStreamTest : public AudioPacketizationCallback,
                       public ::testing::Test {
 protected:
  DualStreamTest();
  ~DualStreamTest();

  void RunTest(int frame_size_primary_samples,
               int num_channels_primary,
               int sampling_rate,
               bool start_in_sync,
               int num_channels_input);

  void ApiTest();

  virtual int32_t SendData(
      FrameType frameType,
      uint8_t payload_type,
      uint32_t timestamp,
      const uint8_t* payload_data,
      size_t payload_size,
      const RTPFragmentationHeader* fragmentation) OVERRIDE;

  void Perform(bool start_in_sync, int num_channels_input);

  void InitializeSender(int frame_size_primary_samples,
                        int num_channels_primary, int sampling_rate);

  void PopulateCodecInstances(int frame_size_primary_ms,
                              int num_channels_primary, int sampling_rate);

  void Validate(bool start_in_sync, size_t tolerance);
  bool EqualTimestamp(int stream, int position);
  size_t EqualPayloadLength(int stream, int position);
  bool EqualPayloadData(int stream, int position);

  static const int kMaxNumStoredPayloads = 2;

  enum {
    kPrimary = 0,
    kSecondary,
    kMaxNumStreams
  };

  scoped_ptr<AudioCodingModule> acm_dual_stream_;
  scoped_ptr<AudioCodingModule> acm_ref_primary_;
  scoped_ptr<AudioCodingModule> acm_ref_secondary_;

  CodecInst primary_encoder_;
  CodecInst secondary_encoder_;

  CodecInst red_encoder_;

  int payload_ref_is_stored_[kMaxNumStreams][kMaxNumStoredPayloads];
  int payload_dual_is_stored_[kMaxNumStreams][kMaxNumStoredPayloads];

  uint32_t timestamp_ref_[kMaxNumStreams][kMaxNumStoredPayloads];
  uint32_t timestamp_dual_[kMaxNumStreams][kMaxNumStoredPayloads];

  size_t payload_len_ref_[kMaxNumStreams][kMaxNumStoredPayloads];
  size_t payload_len_dual_[kMaxNumStreams][kMaxNumStoredPayloads];

  uint8_t payload_data_ref_[kMaxNumStreams][MAX_PAYLOAD_SIZE_BYTE
      * kMaxNumStoredPayloads];
  uint8_t payload_data_dual_[kMaxNumStreams][MAX_PAYLOAD_SIZE_BYTE
      * kMaxNumStoredPayloads];
  int num_received_payloads_dual_[kMaxNumStreams];
  int num_received_payloads_ref_[kMaxNumStreams];

  int num_compared_payloads_[kMaxNumStreams];
  uint32_t last_timestamp_[kMaxNumStreams];
  bool received_payload_[kMaxNumStreams];
};

DualStreamTest::DualStreamTest()
    : acm_dual_stream_(AudioCodingModule::Create(0)),
      acm_ref_primary_(AudioCodingModule::Create(1)),
      acm_ref_secondary_(AudioCodingModule::Create(2)),
      payload_ref_is_stored_(),
      payload_dual_is_stored_(),
      timestamp_ref_(),
      num_received_payloads_dual_(),
      num_received_payloads_ref_(),
      num_compared_payloads_(),
      last_timestamp_(),
      received_payload_() {}

DualStreamTest::~DualStreamTest() {}

void DualStreamTest::PopulateCodecInstances(int frame_size_primary_ms,
                                            int num_channels_primary,
                                            int sampling_rate) {
  CodecInst my_codec;

  // Invalid values. To check later on if the codec are found in the database.
  primary_encoder_.pltype = -1;
  secondary_encoder_.pltype = -1;
  red_encoder_.pltype = -1;

  for (int n = 0; n < AudioCodingModule::NumberOfCodecs(); n++) {
    AudioCodingModule::Codec(n, &my_codec);
    if (strcmp(my_codec.plname, "ISAC") == 0
        && my_codec.plfreq == sampling_rate) {
      my_codec.rate = 32000;
      my_codec.pacsize = 30 * sampling_rate / 1000;
      memcpy(&secondary_encoder_, &my_codec, sizeof(my_codec));
    } else if (strcmp(my_codec.plname, "L16") == 0
        && my_codec.channels == num_channels_primary
        && my_codec.plfreq == sampling_rate) {
      my_codec.pacsize = frame_size_primary_ms * sampling_rate / 1000;
      memcpy(&primary_encoder_, &my_codec, sizeof(my_codec));
    } else if (strcmp(my_codec.plname, "red") == 0) {
      memcpy(&red_encoder_, &my_codec, sizeof(my_codec));
    }
  }

  ASSERT_GE(primary_encoder_.pltype, 0);
  ASSERT_GE(secondary_encoder_.pltype, 0);
  ASSERT_GE(red_encoder_.pltype, 0);
}

void DualStreamTest::InitializeSender(int frame_size_primary_samples,
                                      int num_channels_primary,
                                      int sampling_rate) {
  ASSERT_TRUE(acm_dual_stream_.get() != NULL);
  ASSERT_TRUE(acm_ref_primary_.get() != NULL);
  ASSERT_TRUE(acm_ref_secondary_.get() != NULL);

  ASSERT_EQ(0, acm_dual_stream_->InitializeSender());
  ASSERT_EQ(0, acm_ref_primary_->InitializeSender());
  ASSERT_EQ(0, acm_ref_secondary_->InitializeSender());

  PopulateCodecInstances(frame_size_primary_samples, num_channels_primary,
                         sampling_rate);

  ASSERT_EQ(0, acm_ref_primary_->RegisterSendCodec(primary_encoder_));
  ASSERT_EQ(0, acm_ref_secondary_->RegisterSendCodec(secondary_encoder_));
  ASSERT_EQ(0, acm_dual_stream_->RegisterSendCodec(primary_encoder_));
  ASSERT_EQ(0,
            acm_dual_stream_->RegisterSecondarySendCodec(secondary_encoder_));

  ASSERT_EQ(0, acm_ref_primary_->RegisterTransportCallback(this));
  ASSERT_EQ(0, acm_ref_secondary_->RegisterTransportCallback(this));
  ASSERT_EQ(0, acm_dual_stream_->RegisterTransportCallback(this));
}

void DualStreamTest::Perform(bool start_in_sync, int num_channels_input) {
  PCMFile pcm_file;
  std::string file_name = test::ResourcePath(
      (num_channels_input == 1) ?
          "audio_coding/testfile32kHz" : "audio_coding/teststereo32kHz",
      "pcm");
  pcm_file.Open(file_name, 32000, "rb");
  pcm_file.ReadStereo(num_channels_input == 2);
  AudioFrame audio_frame;

  size_t tolerance = 0;
  if (num_channels_input == 2 && primary_encoder_.channels == 2
      && secondary_encoder_.channels == 1) {
    tolerance = 12;
  }

  if (!start_in_sync) {
    pcm_file.Read10MsData(audio_frame);
    // Unregister secondary codec and feed only the primary
    acm_dual_stream_->UnregisterSecondarySendCodec();
    EXPECT_EQ(0, acm_dual_stream_->Add10MsData(audio_frame));
    EXPECT_EQ(0, acm_ref_primary_->Add10MsData(audio_frame));
    ASSERT_EQ(0,
              acm_dual_stream_->RegisterSecondarySendCodec(secondary_encoder_));
  }

  const int kNumFramesToProcess = 100;
  int frame_cntr = 0;
  while (!pcm_file.EndOfFile() && frame_cntr < kNumFramesToProcess) {
    pcm_file.Read10MsData(audio_frame);
    frame_cntr++;
    EXPECT_EQ(0, acm_dual_stream_->Add10MsData(audio_frame));
    EXPECT_EQ(0, acm_ref_primary_->Add10MsData(audio_frame));
    EXPECT_EQ(0, acm_ref_secondary_->Add10MsData(audio_frame));

    EXPECT_GE(acm_dual_stream_->Process(), 0);
    EXPECT_GE(acm_ref_primary_->Process(), 0);
    EXPECT_GE(acm_ref_secondary_->Process(), 0);

    if (start_in_sync || frame_cntr > 7) {
      // If we haven't started in sync the first few audio frames might
      // slightly differ due to the difference in the state of the resamplers
      // of dual-ACM and reference-ACM.
      Validate(start_in_sync, tolerance);
    } else {
      // SendData stores the payloads, if we are not comparing we have to free
      // the space by resetting these flags.
      memset(payload_ref_is_stored_, 0, sizeof(payload_ref_is_stored_));
      memset(payload_dual_is_stored_, 0, sizeof(payload_dual_is_stored_));
    }
  }
  pcm_file.Close();

  // Make sure that number of received payloads match. In case of secondary
  // encoder, the dual-stream might deliver one lesser payload. The reason is
  // that some secondary payloads are stored to be sent with a payload generated
  // later and the input file may end before the "next" payload .
  EXPECT_EQ(num_received_payloads_ref_[kPrimary],
            num_received_payloads_dual_[kPrimary]);
  EXPECT_TRUE(
      num_received_payloads_ref_[kSecondary]
          == num_received_payloads_dual_[kSecondary]
          || num_received_payloads_ref_[kSecondary]
              == (num_received_payloads_dual_[kSecondary] + 1));

  // Make sure all received payloads are compared.
  if (start_in_sync) {
    EXPECT_EQ(num_received_payloads_dual_[kPrimary],
              num_compared_payloads_[kPrimary]);
    EXPECT_EQ(num_received_payloads_dual_[kSecondary],
              num_compared_payloads_[kSecondary]);
  } else {
    // In asynchronous test we don't compare couple of first frames, so we
    // should account for them in our counting.
    EXPECT_GE(num_compared_payloads_[kPrimary],
              num_received_payloads_dual_[kPrimary] - 4);
    EXPECT_GE(num_compared_payloads_[kSecondary],
              num_received_payloads_dual_[kSecondary] - 4);
  }
}

bool DualStreamTest::EqualTimestamp(int stream_index, int position) {
  if (timestamp_dual_[stream_index][position]
      != timestamp_ref_[stream_index][position]) {
    return false;
  }
  return true;
}

size_t DualStreamTest::EqualPayloadLength(int stream_index, int position) {
  size_t dual = payload_len_dual_[stream_index][position];
  size_t ref = payload_len_ref_[stream_index][position];
  return (dual > ref) ? (dual - ref) : (ref - dual);
}

bool DualStreamTest::EqualPayloadData(int stream_index, int position) {
  assert(
      payload_len_dual_[stream_index][position]
          == payload_len_ref_[stream_index][position]);
  int offset = position * MAX_PAYLOAD_SIZE_BYTE;
  for (size_t n = 0; n < payload_len_dual_[stream_index][position]; n++) {
    if (payload_data_dual_[stream_index][offset + n]
        != payload_data_ref_[stream_index][offset + n]) {
      return false;
    }
  }
  return true;
}

void DualStreamTest::Validate(bool start_in_sync, size_t tolerance) {
  for (int stream_index = 0; stream_index < kMaxNumStreams; stream_index++) {
    size_t my_tolerance = stream_index == kPrimary ? 0 : tolerance;
    for (int position = 0; position < kMaxNumStoredPayloads; position++) {
      if (payload_ref_is_stored_[stream_index][position] == 1
          && payload_dual_is_stored_[stream_index][position] == 1) {
        // Check timestamps only if codecs started in sync or it is primary.
        if (start_in_sync || stream_index == 0)
          EXPECT_TRUE(EqualTimestamp(stream_index, position));
        EXPECT_LE(EqualPayloadLength(stream_index, position), my_tolerance);
        if (my_tolerance == 0)
          EXPECT_TRUE(EqualPayloadData(stream_index, position));
        num_compared_payloads_[stream_index]++;
        payload_ref_is_stored_[stream_index][position] = 0;
        payload_dual_is_stored_[stream_index][position] = 0;
      }
    }
  }
}

int32_t DualStreamTest::SendData(FrameType frameType, uint8_t payload_type,
                                 uint32_t timestamp,
                                 const uint8_t* payload_data,
                                 size_t payload_size,
                                 const RTPFragmentationHeader* fragmentation) {
  int position;
  int stream_index;

  if (payload_type == red_encoder_.pltype) {
    if (fragmentation == NULL) {
      assert(false);
      return -1;
    }
    // As the oldest payloads are in the higher indices of fragmentation,
    // to be able to check the increment of timestamps are correct we loop
    // backward.
    for (int n = fragmentation->fragmentationVectorSize - 1; n >= 0; --n) {
      if (fragmentation->fragmentationPlType[n] == primary_encoder_.pltype) {
        // Received primary payload from dual stream.
        stream_index = kPrimary;
      } else if (fragmentation->fragmentationPlType[n]
          == secondary_encoder_.pltype) {
        // Received secondary payload from dual stream.
        stream_index = kSecondary;
      } else {
        assert(false);
        return -1;
      }
      num_received_payloads_dual_[stream_index]++;
      if (payload_dual_is_stored_[stream_index][0] == 0) {
        position = 0;
      } else if (payload_dual_is_stored_[stream_index][1] == 0) {
        position = 1;
      } else {
        assert(false);
        return -1;
      }
      timestamp_dual_[stream_index][position] = timestamp
          - fragmentation->fragmentationTimeDiff[n];
      payload_len_dual_[stream_index][position] = fragmentation
          ->fragmentationLength[n];
      memcpy(
          &payload_data_dual_[stream_index][position * MAX_PAYLOAD_SIZE_BYTE],
          &payload_data[fragmentation->fragmentationOffset[n]],
          fragmentation->fragmentationLength[n]);
      payload_dual_is_stored_[stream_index][position] = 1;
      // Check if timestamps are incremented correctly.
      if (received_payload_[stream_index]) {
        int t = timestamp_dual_[stream_index][position]
            - last_timestamp_[stream_index];
        if ((stream_index == kPrimary) && (t != primary_encoder_.pacsize)) {
          assert(false);
          return -1;
        }
        if ((stream_index == kSecondary) && (t != secondary_encoder_.pacsize)) {
          assert(false);
          return -1;
        }
      } else {
        received_payload_[stream_index] = true;
      }
      last_timestamp_[stream_index] = timestamp_dual_[stream_index][position];
    }
  } else {
    if (fragmentation != NULL) {
      assert(false);
      return -1;
    }
    if (payload_type == primary_encoder_.pltype) {
      stream_index = kPrimary;
    } else if (payload_type == secondary_encoder_.pltype) {
      stream_index = kSecondary;
    } else {
      assert(false);
      return -1;
    }
    num_received_payloads_ref_[stream_index]++;
    if (payload_ref_is_stored_[stream_index][0] == 0) {
      position = 0;
    } else if (payload_ref_is_stored_[stream_index][1] == 0) {
      position = 1;
    } else {
      assert(false);
      return -1;
    }
    timestamp_ref_[stream_index][position] = timestamp;
    payload_len_ref_[stream_index][position] = payload_size;
    memcpy(&payload_data_ref_[stream_index][position * MAX_PAYLOAD_SIZE_BYTE],
           payload_data, payload_size);
    payload_ref_is_stored_[stream_index][position] = 1;
  }
  return 0;
}

// Mono input, mono primary WB 20 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncMonoInputMonoPrimaryWb20Ms)) {
  InitializeSender(20, 1, 16000);
  Perform(true, 1);
}

// Mono input, stereo primary WB 20 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncMonoInput_StereoPrimaryWb20Ms)) {
  InitializeSender(20, 2, 16000);
  Perform(true, 1);
}

// Mono input, mono primary SWB 20 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncMonoInputMonoPrimarySwb20Ms)) {
  InitializeSender(20, 1, 32000);
  Perform(true, 1);
}

// Mono input, stereo primary SWB 20 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncMonoInputStereoPrimarySwb20Ms)) {
  InitializeSender(20, 2, 32000);
  Perform(true, 1);
}

// Mono input, mono primary WB 40 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncMonoInputMonoPrimaryWb40Ms)) {
  InitializeSender(40, 1, 16000);
  Perform(true, 1);
}

// Mono input, stereo primary WB 40 ms frame
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncMonoInputStereoPrimaryWb40Ms)) {
  InitializeSender(40, 2, 16000);
  Perform(true, 1);
}

// Stereo input, mono primary WB 20 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncStereoInputMonoPrimaryWb20Ms)) {
  InitializeSender(20, 1, 16000);
  Perform(true, 2);
}

// Stereo input, stereo primary WB 20 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncStereoInputStereoPrimaryWb20Ms)) {
  InitializeSender(20, 2, 16000);
  Perform(true, 2);
}

// Stereo input, mono primary SWB 20 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncStereoInputMonoPrimarySwb20Ms)) {
  InitializeSender(20, 1, 32000);
  Perform(true, 2);
}

// Stereo input, stereo primary SWB 20 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncStereoInputStereoPrimarySwb20Ms)) {
  InitializeSender(20, 2, 32000);
  Perform(true, 2);
}

// Stereo input, mono primary WB 40 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncStereoInputMonoPrimaryWb40Ms)) {
  InitializeSender(40, 1, 16000);
  Perform(true, 2);
}

// Stereo input, stereo primary WB 40 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactSyncStereoInputStereoPrimaryWb40Ms)) {
  InitializeSender(40, 2, 16000);
  Perform(true, 2);
}

// Asynchronous test, ACM is fed with data then secondary coder is registered.
// Mono input, mono primary WB 20 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactAsyncMonoInputMonoPrimaryWb20Ms)) {
  InitializeSender(20, 1, 16000);
  Perform(false, 1);
}

// Mono input, mono primary WB 20 ms frame.
TEST_F(DualStreamTest,
       DISABLED_ON_ANDROID(BitExactAsyncMonoInputMonoPrimaryWb40Ms)) {
  InitializeSender(40, 1, 16000);
  Perform(false, 1);
}

TEST_F(DualStreamTest, DISABLED_ON_ANDROID(Api)) {
  PopulateCodecInstances(20, 1, 16000);
  CodecInst my_codec;
  ASSERT_EQ(0, acm_dual_stream_->InitializeSender());
  ASSERT_EQ(-1, acm_dual_stream_->SecondarySendCodec(&my_codec));

  // Not allowed to register secondary codec if primary is not registered yet.
  ASSERT_EQ(-1,
      acm_dual_stream_->RegisterSecondarySendCodec(secondary_encoder_));
  ASSERT_EQ(-1, acm_dual_stream_->SecondarySendCodec(&my_codec));

  ASSERT_EQ(0, acm_dual_stream_->RegisterSendCodec(primary_encoder_));

  ASSERT_EQ(0, acm_dual_stream_->SetVAD(true, true, VADNormal));

  // Make sure vad is activated.
  bool vad_status;
  bool dtx_status;
  ACMVADMode vad_mode;
  EXPECT_EQ(0, acm_dual_stream_->VAD(&vad_status, &dtx_status, &vad_mode));
  EXPECT_TRUE(vad_status);
  EXPECT_TRUE(dtx_status);
  EXPECT_EQ(VADNormal, vad_mode);

  ASSERT_EQ(0,
      acm_dual_stream_->RegisterSecondarySendCodec(secondary_encoder_));

  ASSERT_EQ(0, acm_dual_stream_->SecondarySendCodec(&my_codec));
  ASSERT_EQ(0, memcmp(&my_codec, &secondary_encoder_, sizeof(my_codec)));

  // Test if VAD get disabled after registering secondary codec.
  EXPECT_EQ(0, acm_dual_stream_->VAD(&vad_status, &dtx_status, &vad_mode));
  EXPECT_FALSE(vad_status);
  EXPECT_FALSE(dtx_status);

  // Activating VAD should fail.
  ASSERT_EQ(-1, acm_dual_stream_->SetVAD(true, true, VADNormal));

  // Unregister secondary encoder and it should be possible to activate VAD.
  acm_dual_stream_->UnregisterSecondarySendCodec();
  // Should fail.
  ASSERT_EQ(-1, acm_dual_stream_->SecondarySendCodec(&my_codec));

  ASSERT_EQ(0, acm_dual_stream_->SetVAD(true, true, VADVeryAggr));
  // Make sure VAD is activated.
  EXPECT_EQ(0, acm_dual_stream_->VAD(&vad_status, &dtx_status, &vad_mode));
  EXPECT_TRUE(vad_status);
  EXPECT_TRUE(dtx_status);
  EXPECT_EQ(VADVeryAggr, vad_mode);
}

}  // namespace webrtc