OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <map> | 11 #include <map> |
12 #include <set> | |
13 #include <sstream> | 12 #include <sstream> |
14 #include <string> | 13 #include <string> |
15 | 14 |
16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
17 | 16 |
18 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/event.h" | 18 #include "webrtc/base/event.h" |
20 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
21 #include "webrtc/base/timeutils.h" | |
22 #include "webrtc/call.h" | 20 #include "webrtc/call.h" |
23 #include "webrtc/call/transport_adapter.h" | 21 #include "webrtc/call/transport_adapter.h" |
24 #include "webrtc/frame_callback.h" | 22 #include "webrtc/frame_callback.h" |
25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 23 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
26 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 24 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
27 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 25 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
28 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" | 26 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
29 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 27 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
30 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" | 28 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" |
31 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 29 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
(...skipping 2899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2931 size_t ssrcs_to_observe_; | 2929 size_t ssrcs_to_observe_; |
2932 std::map<uint32_t, bool> observed_redundant_retransmission_; | 2930 std::map<uint32_t, bool> observed_redundant_retransmission_; |
2933 std::map<uint32_t, bool> registered_rtx_ssrc_; | 2931 std::map<uint32_t, bool> registered_rtx_ssrc_; |
2934 } test; | 2932 } test; |
2935 | 2933 |
2936 RunBaseTest(&test); | 2934 RunBaseTest(&test); |
2937 } | 2935 } |
2938 | 2936 |
2939 void EndToEndTest::TestRtpStatePreservation(bool use_rtx) { | 2937 void EndToEndTest::TestRtpStatePreservation(bool use_rtx) { |
2940 static const uint32_t kMaxSequenceNumberGap = 100; | 2938 static const uint32_t kMaxSequenceNumberGap = 100; |
| 2939 static const uint64_t kMaxTimestampGap = kDefaultTimeoutMs * 90; |
2941 class RtpSequenceObserver : public test::RtpRtcpObserver { | 2940 class RtpSequenceObserver : public test::RtpRtcpObserver { |
2942 public: | 2941 public: |
2943 explicit RtpSequenceObserver(bool use_rtx) | 2942 explicit RtpSequenceObserver(bool use_rtx) |
2944 : test::RtpRtcpObserver(kDefaultTimeoutMs), | 2943 : test::RtpRtcpObserver(kDefaultTimeoutMs), |
2945 ssrcs_to_observe_(kNumSsrcs) { | 2944 ssrcs_to_observe_(kNumSsrcs) { |
2946 for (size_t i = 0; i < kNumSsrcs; ++i) { | 2945 for (size_t i = 0; i < kNumSsrcs; ++i) { |
2947 configured_ssrcs_[kVideoSendSsrcs[i]] = true; | 2946 configured_ssrcs_[kVideoSendSsrcs[i]] = true; |
2948 if (use_rtx) | 2947 if (use_rtx) |
2949 configured_ssrcs_[kSendRtxSsrcs[i]] = true; | 2948 configured_ssrcs_[kSendRtxSsrcs[i]] = true; |
2950 } | 2949 } |
2951 thread_checker_.DetachFromThread(); | |
2952 } | 2950 } |
2953 | 2951 |
2954 void ResetExpectedSsrcs(size_t num_expected_ssrcs) { | 2952 void ResetExpectedSsrcs(size_t num_expected_ssrcs) { |
2955 rtc::CritScope lock(&crit_); | 2953 rtc::CritScope lock(&crit_); |
2956 ssrc_observed_rtp_.clear(); | 2954 ssrc_observed_.clear(); |
2957 ssrc_observed_rtcp_sr_.clear(); | |
2958 ssrcs_to_observe_ = num_expected_ssrcs; | 2955 ssrcs_to_observe_ = num_expected_ssrcs; |
2959 } | 2956 } |
2960 | 2957 |
2961 private: | 2958 private: |
2962 void ValidateTimestampGap(uint32_t ssrc, uint32_t timestamp) | |
2963 EXCLUSIVE_LOCKS_REQUIRED(crit_) { | |
2964 auto timestamp_it = last_observed_timestamp_.find(ssrc); | |
2965 if (timestamp_it == last_observed_timestamp_.end()) { | |
2966 last_observed_timestamp_[ssrc] = timestamp; | |
2967 } else { | |
2968 static const int32_t kMaxTimestampGap = kDefaultTimeoutMs * 90; | |
2969 // It is normal for the gap to be negative: RTCP with current time | |
2970 // can be sent just before RTP with capture time. | |
2971 int32_t gap = rtc::TimeDiff(timestamp, timestamp_it->second); | |
2972 EXPECT_LE(std::abs(gap), kMaxTimestampGap) | |
2973 << "Gap in timestamps (" << timestamp_it->second << " -> " | |
2974 << timestamp << ") too large for SSRC: " << ssrc << "."; | |
2975 timestamp_it->second = timestamp; | |
2976 } | |
2977 } | |
2978 | |
2979 Action OnSendRtp(const uint8_t* packet, size_t length) override { | 2959 Action OnSendRtp(const uint8_t* packet, size_t length) override { |
2980 RTPHeader header; | 2960 RTPHeader header; |
2981 EXPECT_TRUE(parser_->Parse(packet, length, &header)); | 2961 EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
2982 const uint32_t ssrc = header.ssrc; | 2962 const uint32_t ssrc = header.ssrc; |
2983 const uint16_t sequence_number = header.sequenceNumber; | 2963 const uint16_t sequence_number = header.sequenceNumber; |
2984 const uint32_t timestamp = header.timestamp; | 2964 const uint32_t timestamp = header.timestamp; |
| 2965 const bool only_padding = |
| 2966 header.headerLength + header.paddingLength == length; |
2985 | 2967 |
2986 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
2987 EXPECT_TRUE(configured_ssrcs_[ssrc]) | 2968 EXPECT_TRUE(configured_ssrcs_[ssrc]) |
2988 << "Received SSRC that wasn't configured: " << ssrc; | 2969 << "Received SSRC that wasn't configured: " << ssrc; |
2989 | 2970 |
2990 std::map<uint32_t, uint16_t>::iterator it = | 2971 std::map<uint32_t, uint16_t>::iterator it = |
2991 last_observed_sequence_number_.find(header.ssrc); | 2972 last_observed_sequence_number_.find(header.ssrc); |
2992 if (it == last_observed_sequence_number_.end()) { | 2973 if (it == last_observed_sequence_number_.end()) { |
2993 last_observed_sequence_number_[ssrc] = sequence_number; | 2974 last_observed_sequence_number_[ssrc] = sequence_number; |
| 2975 last_observed_timestamp_[ssrc] = timestamp; |
2994 } else { | 2976 } else { |
2995 // Verify sequence numbers are reasonably close. | 2977 // Verify sequence numbers are reasonably close. |
2996 uint32_t extended_sequence_number = sequence_number; | 2978 uint32_t extended_sequence_number = sequence_number; |
2997 // Check for roll-over. | 2979 // Check for roll-over. |
2998 if (sequence_number < last_observed_sequence_number_[ssrc]) | 2980 if (sequence_number < last_observed_sequence_number_[ssrc]) |
2999 extended_sequence_number += 0xFFFFu + 1; | 2981 extended_sequence_number += 0xFFFFu + 1; |
3000 EXPECT_LE( | 2982 EXPECT_LE( |
3001 extended_sequence_number - last_observed_sequence_number_[ssrc], | 2983 extended_sequence_number - last_observed_sequence_number_[ssrc], |
3002 kMaxSequenceNumberGap) | 2984 kMaxSequenceNumberGap) |
3003 << "Gap in sequence numbers (" | 2985 << "Gap in sequence numbers (" |
3004 << last_observed_sequence_number_[ssrc] << " -> " << sequence_number | 2986 << last_observed_sequence_number_[ssrc] << " -> " << sequence_number |
3005 << ") too large for SSRC: " << ssrc << "."; | 2987 << ") too large for SSRC: " << ssrc << "."; |
3006 last_observed_sequence_number_[ssrc] = sequence_number; | 2988 last_observed_sequence_number_[ssrc] = sequence_number; |
| 2989 |
| 2990 // TODO(pbos): Remove this check if we ever have monotonically |
| 2991 // increasing timestamps. Right now padding packets add a delta which |
| 2992 // can cause reordering between padding packets and regular packets, |
| 2993 // hence we drop padding-only packets to not flake. |
| 2994 if (only_padding) { |
| 2995 // Verify that timestamps are reasonably close. |
| 2996 uint64_t extended_timestamp = timestamp; |
| 2997 // Check for roll-over. |
| 2998 if (timestamp < last_observed_timestamp_[ssrc]) |
| 2999 extended_timestamp += static_cast<uint64_t>(0xFFFFFFFFu) + 1; |
| 3000 EXPECT_LE(extended_timestamp - last_observed_timestamp_[ssrc], |
| 3001 kMaxTimestampGap) |
| 3002 << "Gap in timestamps (" << last_observed_timestamp_[ssrc] |
| 3003 << " -> " << timestamp << ") too large for SSRC: " << ssrc << "."; |
| 3004 } |
| 3005 last_observed_timestamp_[ssrc] = timestamp; |
3007 } | 3006 } |
| 3007 |
3008 rtc::CritScope lock(&crit_); | 3008 rtc::CritScope lock(&crit_); |
3009 ValidateTimestampGap(ssrc, timestamp); | 3009 // Wait for media packets on all ssrcs. |
3010 | 3010 if (!ssrc_observed_[ssrc] && !only_padding) { |
3011 ssrc_observed_rtp_.insert(ssrc); | 3011 ssrc_observed_[ssrc] = true; |
3012 if (ssrc_observed_rtcp_sr_.size() >= ssrcs_to_observe_ && | 3012 if (--ssrcs_to_observe_ == 0) |
3013 ssrc_observed_rtp_.size() >= ssrcs_to_observe_) { | 3013 observation_complete_.Set(); |
3014 observation_complete_.Set(); | |
3015 } | 3014 } |
3016 | 3015 |
3017 return SEND_PACKET; | 3016 return SEND_PACKET; |
3018 } | 3017 } |
3019 Action OnSendRtcp(const uint8_t* packet, size_t length) override { | |
3020 test::RtcpPacketParser rtcp_parser; | |
3021 rtcp_parser.Parse(packet, length); | |
3022 if (rtcp_parser.sender_report()->num_packets() > 0) { | |
3023 uint32_t ssrc = rtcp_parser.sender_report()->Ssrc(); | |
3024 uint32_t rtcp_timestamp = rtcp_parser.sender_report()->RtpTimestamp(); | |
3025 | 3018 |
3026 rtc::CritScope lock(&crit_); | |
3027 ValidateTimestampGap(ssrc, rtcp_timestamp); | |
3028 | |
3029 ssrc_observed_rtcp_sr_.insert(ssrc); | |
3030 if (ssrc_observed_rtcp_sr_.size() >= ssrcs_to_observe_ && | |
3031 ssrc_observed_rtp_.size() >= ssrcs_to_observe_) { | |
3032 observation_complete_.Set(); | |
3033 } | |
3034 } | |
3035 return SEND_PACKET; | |
3036 } | |
3037 | |
3038 rtc::ThreadChecker thread_checker_; | |
3039 std::map<uint32_t, uint16_t> last_observed_sequence_number_; | 3019 std::map<uint32_t, uint16_t> last_observed_sequence_number_; |
| 3020 std::map<uint32_t, uint32_t> last_observed_timestamp_; |
3040 std::map<uint32_t, bool> configured_ssrcs_; | 3021 std::map<uint32_t, bool> configured_ssrcs_; |
3041 | 3022 |
3042 rtc::CriticalSection crit_; | 3023 rtc::CriticalSection crit_; |
3043 size_t ssrcs_to_observe_ GUARDED_BY(crit_); | 3024 size_t ssrcs_to_observe_ GUARDED_BY(crit_); |
3044 std::map<uint32_t, uint32_t> last_observed_timestamp_ GUARDED_BY(crit_); | 3025 std::map<uint32_t, bool> ssrc_observed_ GUARDED_BY(crit_); |
3045 std::set<uint32_t> ssrc_observed_rtp_ GUARDED_BY(crit_); | |
3046 std::set<uint32_t> ssrc_observed_rtcp_sr_ GUARDED_BY(crit_); | |
3047 } observer(use_rtx); | 3026 } observer(use_rtx); |
3048 | 3027 |
3049 CreateCalls(Call::Config(), Call::Config()); | 3028 CreateCalls(Call::Config(), Call::Config()); |
3050 | 3029 |
3051 test::PacketTransport send_transport(sender_call_.get(), &observer, | 3030 test::PacketTransport send_transport(sender_call_.get(), &observer, |
3052 test::PacketTransport::kSender, | 3031 test::PacketTransport::kSender, |
3053 FakeNetworkPipe::Config()); | 3032 FakeNetworkPipe::Config()); |
3054 test::PacketTransport receive_transport(nullptr, &observer, | 3033 test::PacketTransport receive_transport(nullptr, &observer, |
3055 test::PacketTransport::kReceiver, | 3034 test::PacketTransport::kReceiver, |
3056 FakeNetworkPipe::Config()); | 3035 FakeNetworkPipe::Config()); |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3520 private: | 3499 private: |
3521 bool video_observed_; | 3500 bool video_observed_; |
3522 bool audio_observed_; | 3501 bool audio_observed_; |
3523 SequenceNumberUnwrapper unwrapper_; | 3502 SequenceNumberUnwrapper unwrapper_; |
3524 std::set<int64_t> received_packet_ids_; | 3503 std::set<int64_t> received_packet_ids_; |
3525 } test; | 3504 } test; |
3526 | 3505 |
3527 RunBaseTest(&test); | 3506 RunBaseTest(&test); |
3528 } | 3507 } |
3529 } // namespace webrtc | 3508 } // namespace webrtc |
OLD | NEW |