solenberg | 18f5427 | 2017-09-15 09:56:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 "test/call_test.h" |
| 12 | #include "test/gtest.h" |
| 13 | #include "test/rtcp_packet_parser.h" |
| 14 | |
| 15 | namespace webrtc { |
| 16 | namespace test { |
| 17 | namespace { |
| 18 | |
| 19 | class AudioSendTest : public SendTest { |
| 20 | public: |
| 21 | AudioSendTest() : SendTest(CallTest::kDefaultTimeoutMs) {} |
| 22 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 23 | size_t GetNumVideoStreams() const override { return 0; } |
| 24 | size_t GetNumAudioStreams() const override { return 1; } |
| 25 | size_t GetNumFlexfecStreams() const override { return 0; } |
solenberg | 18f5427 | 2017-09-15 09:56:08 -0700 | [diff] [blame] | 26 | }; |
| 27 | } // namespace |
| 28 | |
| 29 | using AudioSendStreamCallTest = CallTest; |
| 30 | |
| 31 | TEST_F(AudioSendStreamCallTest, SupportsCName) { |
| 32 | static std::string kCName = "PjqatC14dGfbVwGPUOA9IH7RlsFDbWl4AhXEiDsBizo="; |
| 33 | class CNameObserver : public AudioSendTest { |
| 34 | public: |
| 35 | CNameObserver() = default; |
| 36 | |
| 37 | private: |
| 38 | Action OnSendRtcp(const uint8_t* packet, size_t length) override { |
| 39 | RtcpPacketParser parser; |
| 40 | EXPECT_TRUE(parser.Parse(packet, length)); |
| 41 | if (parser.sdes()->num_packets() > 0) { |
| 42 | EXPECT_EQ(1u, parser.sdes()->chunks().size()); |
| 43 | EXPECT_EQ(kCName, parser.sdes()->chunks()[0].cname); |
| 44 | |
| 45 | observation_complete_.Set(); |
| 46 | } |
| 47 | |
| 48 | return SEND_PACKET; |
| 49 | } |
| 50 | |
| 51 | void ModifyAudioConfigs( |
| 52 | AudioSendStream::Config* send_config, |
| 53 | std::vector<AudioReceiveStream::Config>* receive_configs) override { |
| 54 | send_config->rtp.c_name = kCName; |
| 55 | } |
| 56 | |
| 57 | void PerformTest() override { |
| 58 | EXPECT_TRUE(Wait()) << "Timed out while waiting for RTCP with CNAME."; |
| 59 | } |
| 60 | } test; |
| 61 | |
| 62 | RunBaseTest(&test); |
| 63 | } |
| 64 | |
| 65 | TEST_F(AudioSendStreamCallTest, NoExtensionsByDefault) { |
| 66 | class NoExtensionsObserver : public AudioSendTest { |
| 67 | public: |
| 68 | NoExtensionsObserver() = default; |
| 69 | |
| 70 | private: |
| 71 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 72 | RTPHeader header; |
| 73 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
| 74 | |
| 75 | EXPECT_FALSE(header.extension.hasTransmissionTimeOffset); |
| 76 | EXPECT_FALSE(header.extension.hasAbsoluteSendTime); |
| 77 | EXPECT_FALSE(header.extension.hasTransportSequenceNumber); |
| 78 | EXPECT_FALSE(header.extension.hasAudioLevel); |
| 79 | EXPECT_FALSE(header.extension.hasVideoRotation); |
| 80 | EXPECT_FALSE(header.extension.hasVideoContentType); |
| 81 | observation_complete_.Set(); |
| 82 | |
| 83 | return SEND_PACKET; |
| 84 | } |
| 85 | |
| 86 | void ModifyAudioConfigs( |
| 87 | AudioSendStream::Config* send_config, |
| 88 | std::vector<AudioReceiveStream::Config>* receive_configs) override { |
| 89 | send_config->rtp.extensions.clear(); |
| 90 | } |
| 91 | |
| 92 | void PerformTest() override { |
| 93 | EXPECT_TRUE(Wait()) << "Timed out while waiting for a single RTP packet."; |
| 94 | } |
| 95 | } test; |
| 96 | |
| 97 | RunBaseTest(&test); |
| 98 | } |
| 99 | |
| 100 | TEST_F(AudioSendStreamCallTest, SupportsAudioLevel) { |
| 101 | class AudioLevelObserver : public AudioSendTest { |
| 102 | public: |
| 103 | AudioLevelObserver() : AudioSendTest() { |
| 104 | EXPECT_TRUE(parser_->RegisterRtpHeaderExtension( |
| 105 | kRtpExtensionAudioLevel, test::kAudioLevelExtensionId)); |
| 106 | } |
| 107 | |
| 108 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 109 | RTPHeader header; |
| 110 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
| 111 | |
| 112 | EXPECT_TRUE(header.extension.hasAudioLevel); |
| 113 | if (header.extension.audioLevel != 0) { |
| 114 | // Wait for at least one packet with a non-zero level. |
| 115 | observation_complete_.Set(); |
| 116 | } else { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 117 | RTC_LOG(LS_WARNING) << "Got a packet with zero audioLevel - waiting" |
| 118 | " for another packet..."; |
solenberg | 18f5427 | 2017-09-15 09:56:08 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | return SEND_PACKET; |
| 122 | } |
| 123 | |
| 124 | void ModifyAudioConfigs( |
| 125 | AudioSendStream::Config* send_config, |
| 126 | std::vector<AudioReceiveStream::Config>* receive_configs) override { |
| 127 | send_config->rtp.extensions.clear(); |
| 128 | send_config->rtp.extensions.push_back(RtpExtension( |
| 129 | RtpExtension::kAudioLevelUri, test::kAudioLevelExtensionId)); |
| 130 | } |
| 131 | |
| 132 | void PerformTest() override { |
| 133 | EXPECT_TRUE(Wait()) << "Timed out while waiting for single RTP packet."; |
| 134 | } |
| 135 | } test; |
| 136 | |
| 137 | RunBaseTest(&test); |
| 138 | } |
| 139 | |
| 140 | TEST_F(AudioSendStreamCallTest, SupportsTransportWideSequenceNumbers) { |
| 141 | static const uint8_t kExtensionId = test::kTransportSequenceNumberExtensionId; |
| 142 | class TransportWideSequenceNumberObserver : public AudioSendTest { |
| 143 | public: |
| 144 | TransportWideSequenceNumberObserver() : AudioSendTest() { |
| 145 | EXPECT_TRUE(parser_->RegisterRtpHeaderExtension( |
| 146 | kRtpExtensionTransportSequenceNumber, kExtensionId)); |
| 147 | } |
| 148 | |
| 149 | private: |
| 150 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 151 | RTPHeader header; |
| 152 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
| 153 | |
| 154 | EXPECT_TRUE(header.extension.hasTransportSequenceNumber); |
| 155 | EXPECT_FALSE(header.extension.hasTransmissionTimeOffset); |
| 156 | EXPECT_FALSE(header.extension.hasAbsoluteSendTime); |
| 157 | |
| 158 | observation_complete_.Set(); |
| 159 | |
| 160 | return SEND_PACKET; |
| 161 | } |
| 162 | |
| 163 | void ModifyAudioConfigs( |
| 164 | AudioSendStream::Config* send_config, |
| 165 | std::vector<AudioReceiveStream::Config>* receive_configs) override { |
| 166 | send_config->rtp.extensions.clear(); |
| 167 | send_config->rtp.extensions.push_back(RtpExtension( |
| 168 | RtpExtension::kTransportSequenceNumberUri, kExtensionId)); |
| 169 | } |
| 170 | |
| 171 | void PerformTest() override { |
| 172 | EXPECT_TRUE(Wait()) << "Timed out while waiting for a single RTP packet."; |
| 173 | } |
| 174 | } test; |
| 175 | |
| 176 | RunBaseTest(&test); |
| 177 | } |
| 178 | |
| 179 | TEST_F(AudioSendStreamCallTest, SendDtmf) { |
| 180 | static const uint8_t kDtmfPayloadType = 120; |
| 181 | static const int kDtmfPayloadFrequency = 8000; |
| 182 | static const int kDtmfEventFirst = 12; |
| 183 | static const int kDtmfEventLast = 31; |
| 184 | static const int kDtmfDuration = 50; |
| 185 | class DtmfObserver : public AudioSendTest { |
| 186 | public: |
| 187 | DtmfObserver() = default; |
| 188 | |
| 189 | private: |
| 190 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 191 | RTPHeader header; |
| 192 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
| 193 | |
| 194 | if (header.payloadType == kDtmfPayloadType) { |
| 195 | EXPECT_EQ(12u, header.headerLength); |
| 196 | EXPECT_EQ(16u, length); |
| 197 | const int event = packet[12]; |
| 198 | if (event != expected_dtmf_event_) { |
| 199 | ++expected_dtmf_event_; |
| 200 | EXPECT_EQ(event, expected_dtmf_event_); |
| 201 | if (expected_dtmf_event_ == kDtmfEventLast) { |
| 202 | observation_complete_.Set(); |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return SEND_PACKET; |
| 208 | } |
| 209 | |
| 210 | void OnAudioStreamsCreated( |
| 211 | AudioSendStream* send_stream, |
| 212 | const std::vector<AudioReceiveStream*>& receive_streams) override { |
| 213 | // Need to start stream here, else DTMF events are dropped. |
| 214 | send_stream->Start(); |
| 215 | for (int event = kDtmfEventFirst; event <= kDtmfEventLast; ++event) { |
| 216 | send_stream->SendTelephoneEvent(kDtmfPayloadType, kDtmfPayloadFrequency, |
| 217 | event, kDtmfDuration); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void PerformTest() override { |
| 222 | EXPECT_TRUE(Wait()) << "Timed out while waiting for DTMF stream."; |
| 223 | } |
| 224 | |
| 225 | int expected_dtmf_event_ = kDtmfEventFirst; |
| 226 | } test; |
| 227 | |
| 228 | RunBaseTest(&test); |
| 229 | } |
| 230 | |
| 231 | } // namespace test |
| 232 | } // namespace webrtc |