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

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

Issue 1639253007: Validates sending RTCP before RTP. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: fix lint error Created 4 years, 5 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 | « webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc ('k') | 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 <list> 11 #include <list>
12 #include <map> 12 #include <map>
13 #include <memory> 13 #include <memory>
14 #include <sstream> 14 #include <sstream>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 #include "webrtc/base/checks.h" 20 #include "webrtc/base/checks.h"
21 #include "webrtc/base/event.h" 21 #include "webrtc/base/event.h"
22 #include "webrtc/call.h" 22 #include "webrtc/call.h"
23 #include "webrtc/call/transport_adapter.h" 23 #include "webrtc/call/transport_adapter.h"
24 #include "webrtc/common_video/include/frame_callback.h" 24 #include "webrtc/common_video/include/frame_callback.h"
25 #include "webrtc/modules/include/module_common_types.h" 25 #include "webrtc/modules/include/module_common_types.h"
26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
27 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 27 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
28 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h"
28 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" 29 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
29 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 30 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
30 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" 31 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
31 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" 32 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
32 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" 33 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
33 #include "webrtc/modules/video_coding/include/video_coding_defines.h" 34 #include "webrtc/modules/video_coding/include/video_coding_defines.h"
34 #include "webrtc/system_wrappers/include/metrics.h" 35 #include "webrtc/system_wrappers/include/metrics.h"
35 #include "webrtc/system_wrappers/include/metrics_default.h" 36 #include "webrtc/system_wrappers/include/metrics_default.h"
36 #include "webrtc/system_wrappers/include/sleep.h" 37 #include "webrtc/system_wrappers/include/sleep.h"
37 #include "webrtc/test/call_test.h" 38 #include "webrtc/test/call_test.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 105 }
105 bool need_rtp_; 106 bool need_rtp_;
106 bool need_rtcp_; 107 bool need_rtcp_;
107 }; 108 };
108 109
109 void DecodesRetransmittedFrame(bool enable_rtx, bool enable_red); 110 void DecodesRetransmittedFrame(bool enable_rtx, bool enable_red);
110 void ReceivesPliAndRecovers(int rtp_history_ms); 111 void ReceivesPliAndRecovers(int rtp_history_ms);
111 void RespectsRtcpMode(RtcpMode rtcp_mode); 112 void RespectsRtcpMode(RtcpMode rtcp_mode);
112 void TestXrReceiverReferenceTimeReport(bool enable_rrtr); 113 void TestXrReceiverReferenceTimeReport(bool enable_rrtr);
113 void TestSendsSetSsrcs(size_t num_ssrcs, bool send_single_ssrc_first); 114 void TestSendsSetSsrcs(size_t num_ssrcs, bool send_single_ssrc_first);
114 void TestRtpStatePreservation(bool use_rtx); 115 void TestRtpStatePreservation(bool use_rtx, bool provoke_rtcpsr_before_rtp);
115 void VerifyHistogramStats(bool use_rtx, bool use_red, bool screenshare); 116 void VerifyHistogramStats(bool use_rtx, bool use_red, bool screenshare);
116 void VerifyNewVideoSendStreamsRespectNetworkState( 117 void VerifyNewVideoSendStreamsRespectNetworkState(
117 MediaType network_to_bring_down, 118 MediaType network_to_bring_down,
118 VideoEncoder* encoder, 119 VideoEncoder* encoder,
119 Transport* transport); 120 Transport* transport);
120 void VerifyNewVideoReceiveStreamsRespectNetworkState( 121 void VerifyNewVideoReceiveStreamsRespectNetworkState(
121 MediaType network_to_bring_down, 122 MediaType network_to_bring_down,
122 Transport* transport); 123 Transport* transport);
123 }; 124 };
124 125
(...skipping 2833 matching lines...) Expand 10 before | Expand all | Expand 10 after
2958 2959
2959 private: 2960 private:
2960 size_t ssrcs_to_observe_; 2961 size_t ssrcs_to_observe_;
2961 std::map<uint32_t, bool> observed_redundant_retransmission_; 2962 std::map<uint32_t, bool> observed_redundant_retransmission_;
2962 std::map<uint32_t, bool> registered_rtx_ssrc_; 2963 std::map<uint32_t, bool> registered_rtx_ssrc_;
2963 } test; 2964 } test;
2964 2965
2965 RunBaseTest(&test); 2966 RunBaseTest(&test);
2966 } 2967 }
2967 2968
2968 void EndToEndTest::TestRtpStatePreservation(bool use_rtx) { 2969 void EndToEndTest::TestRtpStatePreservation(bool use_rtx,
2970 bool provoke_rtcpsr_before_rtp) {
2969 class RtpSequenceObserver : public test::RtpRtcpObserver { 2971 class RtpSequenceObserver : public test::RtpRtcpObserver {
2970 public: 2972 public:
2971 explicit RtpSequenceObserver(bool use_rtx) 2973 explicit RtpSequenceObserver(bool use_rtx)
2972 : test::RtpRtcpObserver(kDefaultTimeoutMs), 2974 : test::RtpRtcpObserver(kDefaultTimeoutMs),
2973 ssrcs_to_observe_(kNumSsrcs) { 2975 ssrcs_to_observe_(kNumSsrcs) {
2974 for (size_t i = 0; i < kNumSsrcs; ++i) { 2976 for (size_t i = 0; i < kNumSsrcs; ++i) {
2975 configured_ssrcs_[kVideoSendSsrcs[i]] = true; 2977 configured_ssrcs_[kVideoSendSsrcs[i]] = true;
2976 if (use_rtx) 2978 if (use_rtx)
2977 configured_ssrcs_[kSendRtxSsrcs[i]] = true; 2979 configured_ssrcs_[kSendRtxSsrcs[i]] = true;
2978 } 2980 }
2979 } 2981 }
2980 2982
2981 void ResetExpectedSsrcs(size_t num_expected_ssrcs) { 2983 void ResetExpectedSsrcs(size_t num_expected_ssrcs) {
2982 rtc::CritScope lock(&crit_); 2984 rtc::CritScope lock(&crit_);
2983 ssrc_observed_.clear(); 2985 ssrc_observed_.clear();
2984 ssrcs_to_observe_ = num_expected_ssrcs; 2986 ssrcs_to_observe_ = num_expected_ssrcs;
2985 } 2987 }
2986 2988
2987 private: 2989 private:
2990 void ValidateTimestampGap(uint32_t ssrc,
2991 uint32_t timestamp,
2992 bool only_padding)
2993 EXCLUSIVE_LOCKS_REQUIRED(crit_) {
2994 static const int32_t kMaxTimestampGap = kDefaultTimeoutMs * 90;
2995 auto timestamp_it = last_observed_timestamp_.find(ssrc);
2996 if (timestamp_it == last_observed_timestamp_.end()) {
2997 EXPECT_FALSE(only_padding);
2998 last_observed_timestamp_[ssrc] = timestamp;
2999 } else {
3000 // Verify timestamps are reasonably close.
3001 uint32_t latest_observed = timestamp_it->second;
3002 // Wraparound handling is unnecessary here as long as an int variable
3003 // is used to store the result.
3004 int32_t timestamp_gap = timestamp - latest_observed;
3005 EXPECT_LE(std::abs(timestamp_gap), kMaxTimestampGap)
3006 << "Gap in timestamps (" << latest_observed << " -> " << timestamp
3007 << ") too large for SSRC: " << ssrc << ".";
3008 timestamp_it->second = timestamp;
3009 }
3010 }
3011
2988 Action OnSendRtp(const uint8_t* packet, size_t length) override { 3012 Action OnSendRtp(const uint8_t* packet, size_t length) override {
2989 RTPHeader header; 3013 RTPHeader header;
2990 EXPECT_TRUE(parser_->Parse(packet, length, &header)); 3014 EXPECT_TRUE(parser_->Parse(packet, length, &header));
2991 const uint32_t ssrc = header.ssrc; 3015 const uint32_t ssrc = header.ssrc;
2992 const int64_t sequence_number = 3016 const int64_t sequence_number =
2993 seq_numbers_unwrapper_.Unwrap(header.sequenceNumber); 3017 seq_numbers_unwrapper_.Unwrap(header.sequenceNumber);
2994 const uint32_t timestamp = header.timestamp; 3018 const uint32_t timestamp = header.timestamp;
2995 const bool only_padding = 3019 const bool only_padding =
2996 header.headerLength + header.paddingLength == length; 3020 header.headerLength + header.paddingLength == length;
2997 3021
(...skipping 16 matching lines...) Expand all
3014 int64_t sequence_number_gap = sequence_number - latest_observed; 3038 int64_t sequence_number_gap = sequence_number - latest_observed;
3015 EXPECT_LE(std::abs(sequence_number_gap), kMaxSequenceNumberGap) 3039 EXPECT_LE(std::abs(sequence_number_gap), kMaxSequenceNumberGap)
3016 << "Gap in sequence numbers (" << latest_observed << " -> " 3040 << "Gap in sequence numbers (" << latest_observed << " -> "
3017 << sequence_number << ") too large for SSRC: " << ssrc << "."; 3041 << sequence_number << ") too large for SSRC: " << ssrc << ".";
3018 seq_numbers->push_back(sequence_number); 3042 seq_numbers->push_back(sequence_number);
3019 if (seq_numbers->size() >= kMaxSequenceNumberGap) { 3043 if (seq_numbers->size() >= kMaxSequenceNumberGap) {
3020 seq_numbers->pop_front(); 3044 seq_numbers->pop_front();
3021 } 3045 }
3022 } 3046 }
3023 3047
3024 static const int32_t kMaxTimestampGap = kDefaultTimeoutMs * 90; 3048 rtc::CritScope lock(&crit_);
3025 auto timestamp_it = last_observed_timestamp_.find(ssrc); 3049 ValidateTimestampGap(ssrc, timestamp, only_padding);
3026 if (timestamp_it == last_observed_timestamp_.end()) {
3027 EXPECT_FALSE(only_padding);
3028 last_observed_timestamp_[ssrc] = timestamp;
3029 } else {
3030 // Verify timestamps are reasonably close.
3031 uint32_t latest_observed = timestamp_it->second;
3032 // Wraparound handling is unnecessary here as long as an int variable
3033 // is used to store the result.
3034 int32_t timestamp_gap = timestamp - latest_observed;
3035 EXPECT_LE(std::abs(timestamp_gap), kMaxTimestampGap)
3036 << "Gap in timestamps (" << latest_observed << " -> "
3037 << timestamp << ") too large for SSRC: " << ssrc << ".";
3038 timestamp_it->second = timestamp;
3039 }
3040 3050
3041 rtc::CritScope lock(&crit_);
3042 // Wait for media packets on all ssrcs. 3051 // Wait for media packets on all ssrcs.
3043 if (!ssrc_observed_[ssrc] && !only_padding) { 3052 if (!ssrc_observed_[ssrc] && !only_padding) {
3044 ssrc_observed_[ssrc] = true; 3053 ssrc_observed_[ssrc] = true;
3045 if (--ssrcs_to_observe_ == 0) 3054 if (--ssrcs_to_observe_ == 0)
3046 observation_complete_.Set(); 3055 observation_complete_.Set();
3047 } 3056 }
3048 3057
3049 return SEND_PACKET; 3058 return SEND_PACKET;
3050 } 3059 }
3051 3060
3061 Action OnSendRtcp(const uint8_t* packet, size_t length) override {
3062 test::RtcpPacketParser rtcp_parser;
3063 rtcp_parser.Parse(packet, length);
3064 if (rtcp_parser.sender_report()->num_packets() > 0) {
3065 uint32_t ssrc = rtcp_parser.sender_report()->Ssrc();
3066 uint32_t rtcp_timestamp = rtcp_parser.sender_report()->RtpTimestamp();
3067
3068 rtc::CritScope lock(&crit_);
3069 ValidateTimestampGap(ssrc, rtcp_timestamp, false);
3070 }
3071 return SEND_PACKET;
3072 }
3073
3052 SequenceNumberUnwrapper seq_numbers_unwrapper_; 3074 SequenceNumberUnwrapper seq_numbers_unwrapper_;
3053 std::map<uint32_t, std::list<int64_t>> last_observed_seq_numbers_; 3075 std::map<uint32_t, std::list<int64_t>> last_observed_seq_numbers_;
3054 std::map<uint32_t, uint32_t> last_observed_timestamp_; 3076 std::map<uint32_t, uint32_t> last_observed_timestamp_;
3055 std::map<uint32_t, bool> configured_ssrcs_; 3077 std::map<uint32_t, bool> configured_ssrcs_;
3056 3078
3057 rtc::CriticalSection crit_; 3079 rtc::CriticalSection crit_;
3058 size_t ssrcs_to_observe_ GUARDED_BY(crit_); 3080 size_t ssrcs_to_observe_ GUARDED_BY(crit_);
3059 std::map<uint32_t, bool> ssrc_observed_ GUARDED_BY(crit_); 3081 std::map<uint32_t, bool> ssrc_observed_ GUARDED_BY(crit_);
3060 } observer(use_rtx); 3082 } observer(use_rtx);
3061 3083
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3111 // Test stream resetting more than once to make sure that the state doesn't 3133 // Test stream resetting more than once to make sure that the state doesn't
3112 // get set once (this could be due to using std::map::insert for instance). 3134 // get set once (this could be due to using std::map::insert for instance).
3113 for (size_t i = 0; i < 3; ++i) { 3135 for (size_t i = 0; i < 3; ++i) {
3114 frame_generator_capturer_->Stop(); 3136 frame_generator_capturer_->Stop();
3115 sender_call_->DestroyVideoSendStream(video_send_stream_); 3137 sender_call_->DestroyVideoSendStream(video_send_stream_);
3116 3138
3117 // Re-create VideoSendStream with only one stream. 3139 // Re-create VideoSendStream with only one stream.
3118 video_send_stream_ = 3140 video_send_stream_ =
3119 sender_call_->CreateVideoSendStream(video_send_config_, one_stream); 3141 sender_call_->CreateVideoSendStream(video_send_config_, one_stream);
3120 video_send_stream_->Start(); 3142 video_send_stream_->Start();
3143 if (provoke_rtcpsr_before_rtp) {
3144 // Rapid Resync Request forces sending RTCP Sender Report back.
3145 // Using this request speeds up this test because then there is no need
3146 // to wait for a second for periodic Sender Report.
3147 rtcp::RapidResyncRequest force_send_sr_back_request;
3148 rtc::Buffer packet = force_send_sr_back_request.Build();
3149 static_cast<webrtc::test::DirectTransport&>(receive_transport)
3150 .SendRtcp(packet.data(), packet.size());
3151 }
3121 CreateFrameGeneratorCapturer(); 3152 CreateFrameGeneratorCapturer();
3122 frame_generator_capturer_->Start(); 3153 frame_generator_capturer_->Start();
3123 3154
3124 observer.ResetExpectedSsrcs(1); 3155 observer.ResetExpectedSsrcs(1);
3125 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for single RTP packet."; 3156 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for single RTP packet.";
3126 3157
3127 // Reconfigure back to use all streams. 3158 // Reconfigure back to use all streams.
3128 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_); 3159 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_);
3129 observer.ResetExpectedSsrcs(kNumSsrcs); 3160 observer.ResetExpectedSsrcs(kNumSsrcs);
3130 EXPECT_TRUE(observer.Wait()) 3161 EXPECT_TRUE(observer.Wait())
(...skipping 12 matching lines...) Expand all
3143 } 3174 }
3144 3175
3145 send_transport.StopSending(); 3176 send_transport.StopSending();
3146 receive_transport.StopSending(); 3177 receive_transport.StopSending();
3147 3178
3148 Stop(); 3179 Stop();
3149 DestroyStreams(); 3180 DestroyStreams();
3150 } 3181 }
3151 3182
3152 TEST_F(EndToEndTest, RestartingSendStreamPreservesRtpState) { 3183 TEST_F(EndToEndTest, RestartingSendStreamPreservesRtpState) {
3153 TestRtpStatePreservation(false); 3184 TestRtpStatePreservation(false, false);
3154 } 3185 }
3155 3186
3156 // This test is flaky. See: 3187 // These tests are flaky. See:
3157 // https://bugs.chromium.org/p/webrtc/issues/detail?id=4332 3188 // https://bugs.chromium.org/p/webrtc/issues/detail?id=4332
3158 TEST_F(EndToEndTest, DISABLED_RestartingSendStreamPreservesRtpStatesWithRtx) { 3189 TEST_F(EndToEndTest, DISABLED_RestartingSendStreamPreservesRtpStatesWithRtx) {
3159 TestRtpStatePreservation(true); 3190 TestRtpStatePreservation(true, false);
3191 }
3192
3193 TEST_F(EndToEndTest,
3194 DISABLED_RestartingSendStreamKeepsRtpAndRtcpTimestampsSynced) {
3195 TestRtpStatePreservation(true, true);
3160 } 3196 }
3161 3197
3162 TEST_F(EndToEndTest, RespectsNetworkState) { 3198 TEST_F(EndToEndTest, RespectsNetworkState) {
3163 // TODO(pbos): Remove accepted downtime packets etc. when signaling network 3199 // TODO(pbos): Remove accepted downtime packets etc. when signaling network
3164 // down blocks until no more packets will be sent. 3200 // down blocks until no more packets will be sent.
3165 3201
3166 // Pacer will send from its packet list and then send required padding before 3202 // Pacer will send from its packet list and then send required padding before
3167 // checking paused_ again. This should be enough for one round of pacing, 3203 // checking paused_ again. This should be enough for one round of pacing,
3168 // otherwise increase. 3204 // otherwise increase.
3169 static const int kNumAcceptedDowntimeRtp = 5; 3205 static const int kNumAcceptedDowntimeRtp = 5;
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
3608 private: 3644 private:
3609 bool video_observed_; 3645 bool video_observed_;
3610 bool audio_observed_; 3646 bool audio_observed_;
3611 SequenceNumberUnwrapper unwrapper_; 3647 SequenceNumberUnwrapper unwrapper_;
3612 std::set<int64_t> received_packet_ids_; 3648 std::set<int64_t> received_packet_ids_;
3613 } test; 3649 } test;
3614 3650
3615 RunBaseTest(&test); 3651 RunBaseTest(&test);
3616 } 3652 }
3617 } // namespace webrtc 3653 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698