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

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