aboutsummaryrefslogtreecommitdiff
path: root/webrtc/voice_engine/test/auto_test/voe_cpu_test.cc
blob: 5666b3f8d180ffa1c14ed5e291ba18d4029af558 (plain)
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
/*
 *  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 "webrtc/voice_engine/test/auto_test/voe_cpu_test.h"

#include <stdio.h>
#include <string.h>
#include <time.h>
#if defined(_WIN32)
#include <conio.h>
#endif

#include "webrtc/base/scoped_ptr.h"
#include "webrtc/test/channel_transport/channel_transport.h"
#include "webrtc/voice_engine/test/auto_test/voe_test_defines.h"

using namespace webrtc;
using namespace test;

namespace voetest {

#define CHECK(expr)                                             \
    if (expr)                                                   \
    {                                                           \
        printf("Error at line: %i, %s \n", __LINE__, #expr);    \
        printf("Error code: %i \n", base->LastError());  \
        PAUSE												    \
        return -1;                                              \
    }

VoECpuTest::VoECpuTest(VoETestManager& mgr)
    : _mgr(mgr) {

}

int VoECpuTest::DoTest() {
  printf("------------------------------------------------\n");
  printf(" CPU Reference Test\n");
  printf("------------------------------------------------\n");

  VoEBase* base = _mgr.BasePtr();
  VoEFile* file = _mgr.FilePtr();
  VoECodec* codec = _mgr.CodecPtr();
  VoEAudioProcessing* apm = _mgr.APMPtr();
  VoENetwork* voe_network = _mgr.NetworkPtr();

  int channel(-1);
  CodecInst isac;

  isac.pltype = 104;
  strcpy(isac.plname, "ISAC");
  isac.pacsize = 960;
  isac.plfreq = 32000;
  isac.channels = 1;
  isac.rate = -1;

  CHECK(base->Init());
  channel = base->CreateChannel();

  rtc::scoped_ptr<VoiceChannelTransport> voice_socket_transport(
      new VoiceChannelTransport(voe_network, channel));

  CHECK(voice_socket_transport->SetSendDestination("127.0.0.1", 5566));
  CHECK(voice_socket_transport->SetLocalReceiver(5566));

  CHECK(codec->SetRecPayloadType(channel, isac));
  CHECK(codec->SetSendCodec(channel, isac));

  CHECK(base->StartReceive(channel));
  CHECK(base->StartPlayout(channel));
  CHECK(base->StartSend(channel));
  CHECK(file->StartPlayingFileAsMicrophone(channel, _mgr.AudioFilename(),
          true, true));

  CHECK(codec->SetVADStatus(channel, true));
  CHECK(apm->SetAgcStatus(true, kAgcAdaptiveAnalog));
  CHECK(apm->SetNsStatus(true, kNsModerateSuppression));
  CHECK(apm->SetEcStatus(true, kEcAec));

  TEST_LOG("\nMeasure CPU and memory while running a full-duplex"
    " iSAC-swb call.\n\n");

  PAUSE

  CHECK(base->StopSend(channel));
  CHECK(base->StopPlayout(channel));
  CHECK(base->StopReceive(channel));

  base->DeleteChannel(channel);
  CHECK(base->Terminate());
  return 0;
}

}  // namespace voetest