Chromium Code Reviews| 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 <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 Loading... | |
| 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 wait_rtcp); |
| 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 Loading... | |
| 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, bool wait_rtcp) { |
| 2969 class RtpSequenceObserver : public test::RtpRtcpObserver { | 2970 class RtpSequenceObserver : public test::RtpRtcpObserver { |
| 2970 public: | 2971 public: |
| 2971 explicit RtpSequenceObserver(bool use_rtx) | 2972 explicit RtpSequenceObserver(bool use_rtx) |
| 2972 : test::RtpRtcpObserver(kDefaultTimeoutMs), | 2973 : test::RtpRtcpObserver(kDefaultTimeoutMs), |
| 2973 ssrcs_to_observe_(kNumSsrcs) { | 2974 ssrcs_to_observe_(kNumSsrcs) { |
| 2974 for (size_t i = 0; i < kNumSsrcs; ++i) { | 2975 for (size_t i = 0; i < kNumSsrcs; ++i) { |
| 2975 configured_ssrcs_[kVideoSendSsrcs[i]] = true; | 2976 configured_ssrcs_[kVideoSendSsrcs[i]] = true; |
| 2976 if (use_rtx) | 2977 if (use_rtx) |
| 2977 configured_ssrcs_[kSendRtxSsrcs[i]] = true; | 2978 configured_ssrcs_[kSendRtxSsrcs[i]] = true; |
| 2978 } | 2979 } |
| 2979 } | 2980 } |
| 2980 | 2981 |
| 2981 void ResetExpectedSsrcs(size_t num_expected_ssrcs) { | 2982 void ResetExpectedSsrcs(size_t num_expected_ssrcs) { |
| 2982 rtc::CritScope lock(&crit_); | 2983 rtc::CritScope lock(&crit_); |
| 2983 ssrc_observed_.clear(); | 2984 ssrc_observed_.clear(); |
| 2984 ssrcs_to_observe_ = num_expected_ssrcs; | 2985 ssrcs_to_observe_ = num_expected_ssrcs; |
| 2985 } | 2986 } |
| 2986 | 2987 |
| 2987 private: | 2988 private: |
| 2989 void ValidateTimestampGap(uint32_t ssrc, | |
| 2990 uint32_t timestamp, | |
| 2991 bool only_padding) | |
| 2992 EXCLUSIVE_LOCKS_REQUIRED(crit_) { | |
| 2993 static const int32_t kMaxTimestampGap = kDefaultTimeoutMs * 90; | |
| 2994 auto timestamp_it = last_observed_timestamp_.find(ssrc); | |
| 2995 if (timestamp_it == last_observed_timestamp_.end()) { | |
| 2996 EXPECT_FALSE(only_padding); | |
| 2997 last_observed_timestamp_[ssrc] = timestamp; | |
| 2998 } else { | |
| 2999 // Verify timestamps are reasonably close. | |
| 3000 uint32_t latest_observed = timestamp_it->second; | |
| 3001 // Wraparound handling is unnecessary here as long as an int variable | |
| 3002 // is used to store the result. | |
| 3003 int32_t timestamp_gap = timestamp - latest_observed; | |
| 3004 EXPECT_LE(std::abs(timestamp_gap), kMaxTimestampGap) | |
| 3005 << "Gap in timestamps (" << latest_observed << " -> " << timestamp | |
| 3006 << ") too large for SSRC: " << ssrc << "."; | |
| 3007 timestamp_it->second = timestamp; | |
| 3008 } | |
| 3009 } | |
| 3010 | |
| 2988 Action OnSendRtp(const uint8_t* packet, size_t length) override { | 3011 Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 2989 RTPHeader header; | 3012 RTPHeader header; |
| 2990 EXPECT_TRUE(parser_->Parse(packet, length, &header)); | 3013 EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
| 2991 const uint32_t ssrc = header.ssrc; | 3014 const uint32_t ssrc = header.ssrc; |
| 2992 const int64_t sequence_number = | 3015 const int64_t sequence_number = |
| 2993 seq_numbers_unwrapper_.Unwrap(header.sequenceNumber); | 3016 seq_numbers_unwrapper_.Unwrap(header.sequenceNumber); |
| 2994 const uint32_t timestamp = header.timestamp; | 3017 const uint32_t timestamp = header.timestamp; |
| 2995 const bool only_padding = | 3018 const bool only_padding = |
| 2996 header.headerLength + header.paddingLength == length; | 3019 header.headerLength + header.paddingLength == length; |
| 2997 | 3020 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 3014 int64_t sequence_number_gap = sequence_number - latest_observed; | 3037 int64_t sequence_number_gap = sequence_number - latest_observed; |
| 3015 EXPECT_LE(std::abs(sequence_number_gap), kMaxSequenceNumberGap) | 3038 EXPECT_LE(std::abs(sequence_number_gap), kMaxSequenceNumberGap) |
| 3016 << "Gap in sequence numbers (" << latest_observed << " -> " | 3039 << "Gap in sequence numbers (" << latest_observed << " -> " |
| 3017 << sequence_number << ") too large for SSRC: " << ssrc << "."; | 3040 << sequence_number << ") too large for SSRC: " << ssrc << "."; |
| 3018 seq_numbers->push_back(sequence_number); | 3041 seq_numbers->push_back(sequence_number); |
| 3019 if (seq_numbers->size() >= kMaxSequenceNumberGap) { | 3042 if (seq_numbers->size() >= kMaxSequenceNumberGap) { |
| 3020 seq_numbers->pop_front(); | 3043 seq_numbers->pop_front(); |
| 3021 } | 3044 } |
| 3022 } | 3045 } |
| 3023 | 3046 |
| 3024 static const int32_t kMaxTimestampGap = kDefaultTimeoutMs * 90; | 3047 rtc::CritScope lock(&crit_); |
| 3025 auto timestamp_it = last_observed_timestamp_.find(ssrc); | 3048 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 | 3049 |
| 3041 rtc::CritScope lock(&crit_); | |
| 3042 // Wait for media packets on all ssrcs. | 3050 // Wait for media packets on all ssrcs. |
| 3043 if (!ssrc_observed_[ssrc] && !only_padding) { | 3051 if (!ssrc_observed_[ssrc] && !only_padding) { |
| 3044 ssrc_observed_[ssrc] = true; | 3052 ssrc_observed_[ssrc] = true; |
| 3045 if (--ssrcs_to_observe_ == 0) | 3053 if (--ssrcs_to_observe_ == 0) |
| 3046 observation_complete_.Set(); | 3054 observation_complete_.Set(); |
| 3047 } | 3055 } |
| 3048 | 3056 |
| 3049 return SEND_PACKET; | 3057 return SEND_PACKET; |
| 3050 } | 3058 } |
| 3051 | 3059 |
| 3060 Action OnSendRtcp(const uint8_t* packet, size_t length) override { | |
| 3061 test::RtcpPacketParser rtcp_parser; | |
| 3062 rtcp_parser.Parse(packet, length); | |
| 3063 if (rtcp_parser.sender_report()->num_packets() > 0) { | |
| 3064 uint32_t ssrc = rtcp_parser.sender_report()->Ssrc(); | |
| 3065 uint32_t rtcp_timestamp = rtcp_parser.sender_report()->RtpTimestamp(); | |
| 3066 | |
| 3067 rtc::CritScope lock(&crit_); | |
| 3068 ValidateTimestampGap(ssrc, rtcp_timestamp, false); | |
| 3069 } | |
| 3070 return SEND_PACKET; | |
| 3071 } | |
| 3072 | |
| 3052 SequenceNumberUnwrapper seq_numbers_unwrapper_; | 3073 SequenceNumberUnwrapper seq_numbers_unwrapper_; |
| 3053 std::map<uint32_t, std::list<int64_t>> last_observed_seq_numbers_; | 3074 std::map<uint32_t, std::list<int64_t>> last_observed_seq_numbers_; |
| 3054 std::map<uint32_t, uint32_t> last_observed_timestamp_; | 3075 std::map<uint32_t, uint32_t> last_observed_timestamp_; |
| 3055 std::map<uint32_t, bool> configured_ssrcs_; | 3076 std::map<uint32_t, bool> configured_ssrcs_; |
| 3056 | 3077 |
| 3057 rtc::CriticalSection crit_; | 3078 rtc::CriticalSection crit_; |
| 3058 size_t ssrcs_to_observe_ GUARDED_BY(crit_); | 3079 size_t ssrcs_to_observe_ GUARDED_BY(crit_); |
| 3059 std::map<uint32_t, bool> ssrc_observed_ GUARDED_BY(crit_); | 3080 std::map<uint32_t, bool> ssrc_observed_ GUARDED_BY(crit_); |
| 3060 } observer(use_rtx); | 3081 } observer(use_rtx); |
| 3061 | 3082 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3111 // Test stream resetting more than once to make sure that the state doesn't | 3132 // 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). | 3133 // get set once (this could be due to using std::map::insert for instance). |
| 3113 for (size_t i = 0; i < 3; ++i) { | 3134 for (size_t i = 0; i < 3; ++i) { |
| 3114 frame_generator_capturer_->Stop(); | 3135 frame_generator_capturer_->Stop(); |
| 3115 sender_call_->DestroyVideoSendStream(video_send_stream_); | 3136 sender_call_->DestroyVideoSendStream(video_send_stream_); |
| 3116 | 3137 |
| 3117 // Re-create VideoSendStream with only one stream. | 3138 // Re-create VideoSendStream with only one stream. |
| 3118 video_send_stream_ = | 3139 video_send_stream_ = |
| 3119 sender_call_->CreateVideoSendStream(video_send_config_, one_stream); | 3140 sender_call_->CreateVideoSendStream(video_send_config_, one_stream); |
| 3120 video_send_stream_->Start(); | 3141 video_send_stream_->Start(); |
| 3142 if (wait_rtcp) { | |
| 3143 // Wait for SR rtcp packet before generating rtp packets. | |
| 3144 // There should be no rtcp packet. | |
|
stefan-webrtc
2016/07/20 09:13:31
How can we wait for an rtcp before we send rtp if
danilchap
2016/07/20 10:09:49
Variable name adjusted (since no-wait approach is
| |
| 3145 | |
| 3146 // Rapid Resync Request forces sending RTCP Sender Report back. | |
| 3147 // Alternative approach is to wait several seconds for SR to be generated. | |
|
stefan-webrtc
2016/07/20 09:13:31
Can you clarify in the comment if this is part of
danilchap
2016/07/20 10:09:49
Done.
| |
| 3148 rtcp::RapidResyncRequest force_send_sr_back_request; | |
| 3149 rtc::Buffer packet = force_send_sr_back_request.Build(); | |
| 3150 static_cast<webrtc::test::DirectTransport&>(receive_transport) | |
| 3151 .SendRtcp(packet.data(), packet.size()); | |
| 3152 } | |
| 3121 CreateFrameGeneratorCapturer(); | 3153 CreateFrameGeneratorCapturer(); |
| 3122 frame_generator_capturer_->Start(); | 3154 frame_generator_capturer_->Start(); |
| 3123 | 3155 |
| 3124 observer.ResetExpectedSsrcs(1); | 3156 observer.ResetExpectedSsrcs(1); |
| 3125 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for single RTP packet."; | 3157 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for single RTP packet."; |
| 3126 | 3158 |
| 3127 // Reconfigure back to use all streams. | 3159 // Reconfigure back to use all streams. |
| 3128 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_); | 3160 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_); |
| 3129 observer.ResetExpectedSsrcs(kNumSsrcs); | 3161 observer.ResetExpectedSsrcs(kNumSsrcs); |
| 3130 EXPECT_TRUE(observer.Wait()) | 3162 EXPECT_TRUE(observer.Wait()) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 3143 } | 3175 } |
| 3144 | 3176 |
| 3145 send_transport.StopSending(); | 3177 send_transport.StopSending(); |
| 3146 receive_transport.StopSending(); | 3178 receive_transport.StopSending(); |
| 3147 | 3179 |
| 3148 Stop(); | 3180 Stop(); |
| 3149 DestroyStreams(); | 3181 DestroyStreams(); |
| 3150 } | 3182 } |
| 3151 | 3183 |
| 3152 TEST_F(EndToEndTest, RestartingSendStreamPreservesRtpState) { | 3184 TEST_F(EndToEndTest, RestartingSendStreamPreservesRtpState) { |
| 3153 TestRtpStatePreservation(false); | 3185 TestRtpStatePreservation(false, false); |
| 3154 } | 3186 } |
| 3155 | 3187 |
| 3156 // This test is flaky. See: | 3188 // This tests are flaky. See: |
|
stefan-webrtc
2016/07/20 09:13:31
These tests
danilchap
2016/07/20 10:09:49
Done.
| |
| 3157 // https://bugs.chromium.org/p/webrtc/issues/detail?id=4332 | 3189 // https://bugs.chromium.org/p/webrtc/issues/detail?id=4332 |
| 3158 TEST_F(EndToEndTest, DISABLED_RestartingSendStreamPreservesRtpStatesWithRtx) { | 3190 TEST_F(EndToEndTest, DISABLED_RestartingSendStreamPreservesRtpStatesWithRtx) { |
| 3159 TestRtpStatePreservation(true); | 3191 TestRtpStatePreservation(true, false); |
| 3192 } | |
| 3193 | |
| 3194 TEST_F(EndToEndTest, | |
| 3195 DISABLED_RestartingSendStreamKeepsRtpAndRtcpTimestampsSynced) { | |
| 3196 TestRtpStatePreservation(true, true); | |
| 3160 } | 3197 } |
| 3161 | 3198 |
| 3162 TEST_F(EndToEndTest, RespectsNetworkState) { | 3199 TEST_F(EndToEndTest, RespectsNetworkState) { |
| 3163 // TODO(pbos): Remove accepted downtime packets etc. when signaling network | 3200 // TODO(pbos): Remove accepted downtime packets etc. when signaling network |
| 3164 // down blocks until no more packets will be sent. | 3201 // down blocks until no more packets will be sent. |
| 3165 | 3202 |
| 3166 // Pacer will send from its packet list and then send required padding before | 3203 // 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, | 3204 // checking paused_ again. This should be enough for one round of pacing, |
| 3168 // otherwise increase. | 3205 // otherwise increase. |
| 3169 static const int kNumAcceptedDowntimeRtp = 5; | 3206 static const int kNumAcceptedDowntimeRtp = 5; |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3608 private: | 3645 private: |
| 3609 bool video_observed_; | 3646 bool video_observed_; |
| 3610 bool audio_observed_; | 3647 bool audio_observed_; |
| 3611 SequenceNumberUnwrapper unwrapper_; | 3648 SequenceNumberUnwrapper unwrapper_; |
| 3612 std::set<int64_t> received_packet_ids_; | 3649 std::set<int64_t> received_packet_ids_; |
| 3613 } test; | 3650 } test; |
| 3614 | 3651 |
| 3615 RunBaseTest(&test); | 3652 RunBaseTest(&test); |
| 3616 } | 3653 } |
| 3617 } // namespace webrtc | 3654 } // namespace webrtc |
| OLD | NEW |