Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: webrtc/video/end_to_end_tests.cc

Issue 1633843003: Added validation between RTP and RTCP timestamps (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
12 #include <sstream> 13 #include <sstream>
13 #include <string> 14 #include <string>
14 15
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
18 #include "webrtc/base/event.h" 19 #include "webrtc/base/event.h"
19 #include "webrtc/base/scoped_ptr.h" 20 #include "webrtc/base/scoped_ptr.h"
20 #include "webrtc/call.h" 21 #include "webrtc/call.h"
21 #include "webrtc/call/transport_adapter.h" 22 #include "webrtc/call/transport_adapter.h"
(...skipping 2901 matching lines...) Expand 10 before | Expand all | Expand 10 after
2923 size_t ssrcs_to_observe_; 2924 size_t ssrcs_to_observe_;
2924 std::map<uint32_t, bool> observed_redundant_retransmission_; 2925 std::map<uint32_t, bool> observed_redundant_retransmission_;
2925 std::map<uint32_t, bool> registered_rtx_ssrc_; 2926 std::map<uint32_t, bool> registered_rtx_ssrc_;
2926 } test; 2927 } test;
2927 2928
2928 RunBaseTest(&test); 2929 RunBaseTest(&test);
2929 } 2930 }
2930 2931
2931 void EndToEndTest::TestRtpStatePreservation(bool use_rtx) { 2932 void EndToEndTest::TestRtpStatePreservation(bool use_rtx) {
2932 static const uint32_t kMaxSequenceNumberGap = 100; 2933 static const uint32_t kMaxSequenceNumberGap = 100;
2933 static const uint64_t kMaxTimestampGap = kDefaultTimeoutMs * 90; 2934 static const uint32_t kMaxTimestampGap = kDefaultTimeoutMs * 90;
2934 class RtpSequenceObserver : public test::RtpRtcpObserver { 2935 class RtpSequenceObserver : public test::RtpRtcpObserver {
2935 public: 2936 public:
2936 explicit RtpSequenceObserver(bool use_rtx) 2937 explicit RtpSequenceObserver(bool use_rtx)
2937 : test::RtpRtcpObserver(kDefaultTimeoutMs), 2938 : test::RtpRtcpObserver(kDefaultTimeoutMs),
2938 ssrcs_to_observe_(kNumSsrcs) { 2939 ssrcs_to_observe_(kNumSsrcs) {
2939 for (size_t i = 0; i < kNumSsrcs; ++i) { 2940 for (size_t i = 0; i < kNumSsrcs; ++i) {
2940 configured_ssrcs_[kVideoSendSsrcs[i]] = true; 2941 configured_ssrcs_[kVideoSendSsrcs[i]] = true;
2941 if (use_rtx) 2942 if (use_rtx)
2942 configured_ssrcs_[kSendRtxSsrcs[i]] = true; 2943 configured_ssrcs_[kSendRtxSsrcs[i]] = true;
2943 } 2944 }
2944 } 2945 }
2945 2946
2946 void ResetExpectedSsrcs(size_t num_expected_ssrcs) { 2947 void ResetExpectedSsrcs(size_t num_expected_ssrcs) {
2947 rtc::CritScope lock(&crit_); 2948 rtc::CritScope lock(&crit_);
2948 ssrc_observed_.clear(); 2949 ssrc_observed_rtp_.clear();
2950 ssrc_observed_rtcp_sr_.clear();
2949 ssrcs_to_observe_ = num_expected_ssrcs; 2951 ssrcs_to_observe_ = num_expected_ssrcs;
2950 } 2952 }
2951 2953
2952 private: 2954 private:
2955 void ValidateTimestampGap(uint32_t ssrc, uint32_t timestamp) {
pbos-webrtc 2016/01/28 10:25:06 Can you use TimeDiff or TimeIsBetween in webrtc/ba
danilchap 2016/01/28 10:44:09 Thanks, that makes test more clear what is checked
2956 auto find_timestamp = last_observed_timestamp_.find(ssrc);
2957 if (find_timestamp == last_observed_timestamp_.end()) {
2958 last_observed_timestamp_[ssrc] = timestamp;
2959 } else {
2960 // Use unsigned operation to automagicaly manage roll-over.
2961 uint32_t timestamp_gap = timestamp - find_timestamp->second;
2962 if (timestamp_gap >= 0x80000000) { // negative - negate.
2963 timestamp_gap = (0xffffffff - timestamp_gap) + 1;
2964 }
2965 // It is normal for the gap to be negative: RTCP with current time
2966 // can be sent just before RTP with capture time.
2967 EXPECT_LE(timestamp_gap, kMaxTimestampGap)
2968 << "Gap in timestamps ("
2969 << find_timestamp->second
2970 << " -> " << timestamp << ") too large for SSRC: " << ssrc << ".";
2971 find_timestamp->second = timestamp;
2972 }
2973 }
2974
2953 Action OnSendRtp(const uint8_t* packet, size_t length) override { 2975 Action OnSendRtp(const uint8_t* packet, size_t length) override {
2954 RTPHeader header; 2976 RTPHeader header;
2955 EXPECT_TRUE(parser_->Parse(packet, length, &header)); 2977 EXPECT_TRUE(parser_->Parse(packet, length, &header));
2956 const uint32_t ssrc = header.ssrc; 2978 const uint32_t ssrc = header.ssrc;
2957 const uint16_t sequence_number = header.sequenceNumber; 2979 const uint16_t sequence_number = header.sequenceNumber;
2958 const uint32_t timestamp = header.timestamp; 2980 const uint32_t timestamp = header.timestamp;
2959 const bool only_padding =
2960 header.headerLength + header.paddingLength == length;
2961 2981
2962 EXPECT_TRUE(configured_ssrcs_[ssrc]) 2982 EXPECT_TRUE(configured_ssrcs_[ssrc])
2963 << "Received SSRC that wasn't configured: " << ssrc; 2983 << "Received SSRC that wasn't configured: " << ssrc;
2964 2984
2965 std::map<uint32_t, uint16_t>::iterator it = 2985 std::map<uint32_t, uint16_t>::iterator it =
2966 last_observed_sequence_number_.find(header.ssrc); 2986 last_observed_sequence_number_.find(header.ssrc);
2967 if (it == last_observed_sequence_number_.end()) { 2987 if (it == last_observed_sequence_number_.end()) {
2968 last_observed_sequence_number_[ssrc] = sequence_number; 2988 last_observed_sequence_number_[ssrc] = sequence_number;
2969 last_observed_timestamp_[ssrc] = timestamp;
2970 } else { 2989 } else {
2971 // Verify sequence numbers are reasonably close. 2990 // Verify sequence numbers are reasonably close.
2972 uint32_t extended_sequence_number = sequence_number; 2991 uint32_t extended_sequence_number = sequence_number;
2973 // Check for roll-over. 2992 // Check for roll-over.
2974 if (sequence_number < last_observed_sequence_number_[ssrc]) 2993 if (sequence_number < last_observed_sequence_number_[ssrc])
2975 extended_sequence_number += 0xFFFFu + 1; 2994 extended_sequence_number += 0xFFFFu + 1;
2976 EXPECT_LE( 2995 EXPECT_LE(
2977 extended_sequence_number - last_observed_sequence_number_[ssrc], 2996 extended_sequence_number - last_observed_sequence_number_[ssrc],
2978 kMaxSequenceNumberGap) 2997 kMaxSequenceNumberGap)
2979 << "Gap in sequence numbers (" 2998 << "Gap in sequence numbers ("
2980 << last_observed_sequence_number_[ssrc] << " -> " << sequence_number 2999 << last_observed_sequence_number_[ssrc] << " -> " << sequence_number
2981 << ") too large for SSRC: " << ssrc << "."; 3000 << ") too large for SSRC: " << ssrc << ".";
2982 last_observed_sequence_number_[ssrc] = sequence_number; 3001 last_observed_sequence_number_[ssrc] = sequence_number;
3002 }
3003 ValidateTimestampGap(ssrc, timestamp);
2983 3004
2984 // TODO(pbos): Remove this check if we ever have monotonically 3005 rtc::CritScope lock(&crit_);
2985 // increasing timestamps. Right now padding packets add a delta which 3006 ssrc_observed_rtp_.insert(ssrc);
2986 // can cause reordering between padding packets and regular packets, 3007 if (ssrc_observed_rtcp_sr_.size() >= ssrcs_to_observe_ &&
2987 // hence we drop padding-only packets to not flake. 3008 ssrc_observed_rtp_.size() >= ssrcs_to_observe_) {
2988 if (only_padding) { 3009 observation_complete_.Set();
2989 // Verify that timestamps are reasonably close.
2990 uint64_t extended_timestamp = timestamp;
2991 // Check for roll-over.
2992 if (timestamp < last_observed_timestamp_[ssrc])
2993 extended_timestamp += static_cast<uint64_t>(0xFFFFFFFFu) + 1;
2994 EXPECT_LE(extended_timestamp - last_observed_timestamp_[ssrc],
2995 kMaxTimestampGap)
2996 << "Gap in timestamps (" << last_observed_timestamp_[ssrc]
2997 << " -> " << timestamp << ") too large for SSRC: " << ssrc << ".";
2998 }
2999 last_observed_timestamp_[ssrc] = timestamp;
3000 } 3010 }
3001 3011
3002 rtc::CritScope lock(&crit_); 3012 return SEND_PACKET;
3003 // Wait for media packets on all ssrcs. 3013 }
3004 if (!ssrc_observed_[ssrc] && !only_padding) { 3014 Action OnSendRtcp(const uint8_t* packet, size_t length) override {
3005 ssrc_observed_[ssrc] = true; 3015 test::RtcpPacketParser rtcp_parser;
3006 if (--ssrcs_to_observe_ == 0) 3016 rtcp_parser.Parse(packet, length);
3017 if (rtcp_parser.sender_report()->num_packets() > 0) {
3018 uint32_t ssrc = rtcp_parser.sender_report()->Ssrc();
3019 uint32_t rtcp_timestamp = rtcp_parser.sender_report()->RtpTimestamp();
3020 ValidateTimestampGap(ssrc, rtcp_timestamp);
3021
3022 rtc::CritScope lock(&crit_);
3023 ssrc_observed_rtcp_sr_.insert(ssrc);
3024 if (ssrc_observed_rtcp_sr_.size() >= ssrcs_to_observe_ &&
3025 ssrc_observed_rtp_.size() >= ssrcs_to_observe_) {
3007 observation_complete_.Set(); 3026 observation_complete_.Set();
3027 }
3008 } 3028 }
3009
3010 return SEND_PACKET; 3029 return SEND_PACKET;
3011 } 3030 }
3012 3031
3013 std::map<uint32_t, uint16_t> last_observed_sequence_number_; 3032 std::map<uint32_t, uint16_t> last_observed_sequence_number_;
3014 std::map<uint32_t, uint32_t> last_observed_timestamp_; 3033 std::map<uint32_t, uint32_t> last_observed_timestamp_;
3015 std::map<uint32_t, bool> configured_ssrcs_; 3034 std::map<uint32_t, bool> configured_ssrcs_;
3016 3035
3017 rtc::CriticalSection crit_; 3036 rtc::CriticalSection crit_;
3018 size_t ssrcs_to_observe_ GUARDED_BY(crit_); 3037 size_t ssrcs_to_observe_ GUARDED_BY(crit_);
3019 std::map<uint32_t, bool> ssrc_observed_ GUARDED_BY(crit_); 3038 std::set<uint32_t> ssrc_observed_rtp_ GUARDED_BY(crit_);
3039 std::set<uint32_t> ssrc_observed_rtcp_sr_ GUARDED_BY(crit_);
3020 } observer(use_rtx); 3040 } observer(use_rtx);
3021 3041
3022 CreateCalls(Call::Config(), Call::Config()); 3042 CreateCalls(Call::Config(), Call::Config());
3023 3043
3024 test::PacketTransport send_transport(sender_call_.get(), &observer, 3044 test::PacketTransport send_transport(sender_call_.get(), &observer,
3025 test::PacketTransport::kSender, 3045 test::PacketTransport::kSender,
3026 FakeNetworkPipe::Config()); 3046 FakeNetworkPipe::Config());
3027 test::PacketTransport receive_transport(nullptr, &observer, 3047 test::PacketTransport receive_transport(nullptr, &observer,
3028 test::PacketTransport::kReceiver, 3048 test::PacketTransport::kReceiver,
3029 FakeNetworkPipe::Config()); 3049 FakeNetworkPipe::Config());
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
3493 private: 3513 private:
3494 bool video_observed_; 3514 bool video_observed_;
3495 bool audio_observed_; 3515 bool audio_observed_;
3496 SequenceNumberUnwrapper unwrapper_; 3516 SequenceNumberUnwrapper unwrapper_;
3497 std::set<int64_t> received_packet_ids_; 3517 std::set<int64_t> received_packet_ids_;
3498 } test; 3518 } test;
3499 3519
3500 RunBaseTest(&test); 3520 RunBaseTest(&test);
3501 } 3521 }
3502 } // namespace webrtc 3522 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698