1/*
2 *  Copyright (c) 2011 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 "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
12#include "webrtc/voice_engine/voice_engine_defines.h"
13
14class DtmfTest : public AfterStreamingFixture {
15 protected:
16  void RunSixteenDtmfEvents(bool out_of_band) {
17    TEST_LOG("Sending telephone events:\n");
18    EXPECT_EQ(0, voe_dtmf_->SetDtmfFeedbackStatus(false));
19
20    for (int i = 0; i < 16; i++) {
21      TEST_LOG("%d ", i);
22      TEST_LOG_FLUSH;
23      EXPECT_EQ(0, voe_dtmf_->SendTelephoneEvent(
24          channel_, i, out_of_band, 160, 10));
25      Sleep(500);
26    }
27    TEST_LOG("\n");
28  }
29};
30
31TEST_F(DtmfTest, DtmfFeedbackIsEnabledByDefaultButNotDirectFeedback) {
32  bool dtmf_feedback = false;
33  bool dtmf_direct_feedback = false;
34
35  EXPECT_EQ(0, voe_dtmf_->GetDtmfFeedbackStatus(dtmf_feedback,
36                                                dtmf_direct_feedback));
37
38  EXPECT_TRUE(dtmf_feedback);
39  EXPECT_FALSE(dtmf_direct_feedback);
40}
41
42TEST_F(DtmfTest, ManualSuccessfullySendsInBandTelephoneEvents) {
43  RunSixteenDtmfEvents(false);
44}
45
46TEST_F(DtmfTest, ManualSuccessfullySendsOutOfBandTelephoneEvents) {
47  RunSixteenDtmfEvents(true);
48}
49
50TEST_F(DtmfTest, TestTwoNonDtmfEvents) {
51  EXPECT_EQ(0, voe_dtmf_->SendTelephoneEvent(channel_, 32, true));
52  EXPECT_EQ(0, voe_dtmf_->SendTelephoneEvent(channel_, 110, true));
53}
54
55// This test modifies the DTMF payload type from the default 106 to 88
56// and then runs through 16 DTMF out.of-band events.
57TEST_F(DtmfTest, ManualCanChangeDtmfPayloadType) {
58  webrtc::CodecInst codec_instance = webrtc::CodecInst();
59
60  TEST_LOG("Changing DTMF payload type.\n");
61
62  // Start by modifying the receiving side.
63  for (int i = 0; i < voe_codec_->NumOfCodecs(); i++) {
64    EXPECT_EQ(0, voe_codec_->GetCodec(i, codec_instance));
65    if (!_stricmp("telephone-event", codec_instance.plname)) {
66      codec_instance.pltype = 88;  // Use 88 instead of default 106.
67      EXPECT_EQ(0, voe_base_->StopSend(channel_));
68      EXPECT_EQ(0, voe_base_->StopPlayout(channel_));
69      EXPECT_EQ(0, voe_base_->StopReceive(channel_));
70      EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance));
71      EXPECT_EQ(0, voe_base_->StartReceive(channel_));
72      EXPECT_EQ(0, voe_base_->StartPlayout(channel_));
73      EXPECT_EQ(0, voe_base_->StartSend(channel_));
74      break;
75    }
76  }
77
78  Sleep(500);
79
80  // Next, we must modify the sending side as well.
81  EXPECT_EQ(0, voe_dtmf_->SetSendTelephoneEventPayloadType(
82      channel_, codec_instance.pltype));
83
84  RunSixteenDtmfEvents(true);
85
86  EXPECT_EQ(0, voe_dtmf_->SetDtmfFeedbackStatus(true, false));
87}
88