| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2014 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 <memory> | |
| 12 | |
| 13 #include "modules/include/module_common_types.h" | |
| 14 #include "modules/rtp_rtcp/include/rtp_header_parser.h" | |
| 15 #include "system_wrappers/include/atomic32.h" | |
| 16 #include "system_wrappers/include/sleep.h" | |
| 17 #include "voice_engine/test/auto_test/fixtures/before_streaming_fixture.h" | |
| 18 | |
| 19 using ::testing::_; | |
| 20 using ::testing::AtLeast; | |
| 21 using ::testing::Eq; | |
| 22 using ::testing::Field; | |
| 23 | |
| 24 class ExtensionVerifyTransport : public webrtc::Transport { | |
| 25 public: | |
| 26 ExtensionVerifyTransport() | |
| 27 : parser_(webrtc::RtpHeaderParser::Create()), | |
| 28 received_packets_(0), | |
| 29 bad_packets_(0), | |
| 30 audio_level_id_(-1), | |
| 31 absolute_sender_time_id_(-1) {} | |
| 32 | |
| 33 bool SendRtp(const uint8_t* data, | |
| 34 size_t len, | |
| 35 const webrtc::PacketOptions& options) override { | |
| 36 webrtc::RTPHeader header; | |
| 37 if (parser_->Parse(reinterpret_cast<const uint8_t*>(data), len, &header)) { | |
| 38 bool ok = true; | |
| 39 if (audio_level_id_ >= 0 && | |
| 40 !header.extension.hasAudioLevel) { | |
| 41 ok = false; | |
| 42 } | |
| 43 if (absolute_sender_time_id_ >= 0 && | |
| 44 !header.extension.hasAbsoluteSendTime) { | |
| 45 ok = false; | |
| 46 } | |
| 47 if (!ok) { | |
| 48 // bad_packets_ count packets we expected to have an extension but | |
| 49 // didn't have one. | |
| 50 ++bad_packets_; | |
| 51 } | |
| 52 } | |
| 53 // received_packets_ count all packets we receive. | |
| 54 ++received_packets_; | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 bool SendRtcp(const uint8_t* data, size_t len) override { | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 void SetAudioLevelId(int id) { | |
| 63 audio_level_id_ = id; | |
| 64 parser_->RegisterRtpHeaderExtension(webrtc::kRtpExtensionAudioLevel, id); | |
| 65 } | |
| 66 | |
| 67 void SetAbsoluteSenderTimeId(int id) { | |
| 68 absolute_sender_time_id_ = id; | |
| 69 parser_->RegisterRtpHeaderExtension(webrtc::kRtpExtensionAbsoluteSendTime, | |
| 70 id); | |
| 71 } | |
| 72 | |
| 73 bool Wait() { | |
| 74 // Wait until we've received to specified number of packets. | |
| 75 while (received_packets_.Value() < kPacketsExpected) { | |
| 76 webrtc::SleepMs(kSleepIntervalMs); | |
| 77 } | |
| 78 // Check whether any were 'bad' (didn't contain an extension when they | |
| 79 // where supposed to). | |
| 80 return bad_packets_.Value() == 0; | |
| 81 } | |
| 82 | |
| 83 private: | |
| 84 enum { | |
| 85 kPacketsExpected = 10, | |
| 86 kSleepIntervalMs = 10 | |
| 87 }; | |
| 88 std::unique_ptr<webrtc::RtpHeaderParser> parser_; | |
| 89 webrtc::Atomic32 received_packets_; | |
| 90 webrtc::Atomic32 bad_packets_; | |
| 91 int audio_level_id_; | |
| 92 int absolute_sender_time_id_; | |
| 93 }; | |
| 94 | |
| 95 class SendRtpRtcpHeaderExtensionsTest : public BeforeStreamingFixture { | |
| 96 protected: | |
| 97 void SetUp() override { | |
| 98 EXPECT_EQ(0, voe_network_->DeRegisterExternalTransport(channel_)); | |
| 99 EXPECT_EQ(0, voe_network_->RegisterExternalTransport(channel_, | |
| 100 verifying_transport_)); | |
| 101 } | |
| 102 void TearDown() override { PausePlaying(); } | |
| 103 | |
| 104 ExtensionVerifyTransport verifying_transport_; | |
| 105 }; | |
| 106 | |
| 107 TEST_F(SendRtpRtcpHeaderExtensionsTest, SentPacketsIncludeNoAudioLevel) { | |
| 108 verifying_transport_.SetAudioLevelId(0); | |
| 109 ResumePlaying(); | |
| 110 EXPECT_FALSE(verifying_transport_.Wait()); | |
| 111 } | |
| 112 | |
| 113 TEST_F(SendRtpRtcpHeaderExtensionsTest, SentPacketsIncludeAudioLevel) { | |
| 114 EXPECT_EQ(0, voe_rtp_rtcp_->SetSendAudioLevelIndicationStatus(channel_, true, | |
| 115 9)); | |
| 116 verifying_transport_.SetAudioLevelId(9); | |
| 117 ResumePlaying(); | |
| 118 EXPECT_TRUE(verifying_transport_.Wait()); | |
| 119 } | |
| 120 | |
| OLD | NEW |