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/base/timeutils.h" | 22 #include "webrtc/base/timeutils.h" |
23 #include "webrtc/call.h" | 23 #include "webrtc/call.h" |
24 #include "webrtc/call/transport_adapter.h" | 24 #include "webrtc/call/transport_adapter.h" |
25 #include "webrtc/common_video/include/frame_callback.h" | 25 #include "webrtc/common_video/include/frame_callback.h" |
26 #include "webrtc/modules/include/module_common_types.h" | 26 #include "webrtc/modules/include/module_common_types.h" |
27 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 27 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
28 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 28 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
29 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h" | |
29 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 30 #include "webrtc/modules/rtp_rtcp/source/rtcp_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/sleep.h" | 36 #include "webrtc/system_wrappers/include/sleep.h" |
36 #include "webrtc/test/call_test.h" | 37 #include "webrtc/test/call_test.h" |
37 #include "webrtc/test/direct_transport.h" | 38 #include "webrtc/test/direct_transport.h" |
38 #include "webrtc/test/encoder_settings.h" | 39 #include "webrtc/test/encoder_settings.h" |
(...skipping 65 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 2739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2864 | 2865 |
2865 private: | 2866 private: |
2866 size_t ssrcs_to_observe_; | 2867 size_t ssrcs_to_observe_; |
2867 std::map<uint32_t, bool> observed_redundant_retransmission_; | 2868 std::map<uint32_t, bool> observed_redundant_retransmission_; |
2868 std::map<uint32_t, bool> registered_rtx_ssrc_; | 2869 std::map<uint32_t, bool> registered_rtx_ssrc_; |
2869 } test; | 2870 } test; |
2870 | 2871 |
2871 RunBaseTest(&test); | 2872 RunBaseTest(&test); |
2872 } | 2873 } |
2873 | 2874 |
2874 void EndToEndTest::TestRtpStatePreservation(bool use_rtx) { | 2875 void EndToEndTest::TestRtpStatePreservation(bool use_rtx, bool wait_rtcp) { |
2875 class RtpSequenceObserver : public test::RtpRtcpObserver { | 2876 class RtpSequenceObserver : public test::RtpRtcpObserver { |
2876 public: | 2877 public: |
2877 explicit RtpSequenceObserver(bool use_rtx) | 2878 explicit RtpSequenceObserver(bool use_rtx) |
2878 : test::RtpRtcpObserver(kDefaultTimeoutMs), | 2879 : test::RtpRtcpObserver(kDefaultTimeoutMs), |
2879 ssrcs_to_observe_(kNumSsrcs) { | 2880 ssrcs_to_observe_(kNumSsrcs) { |
2880 for (size_t i = 0; i < kNumSsrcs; ++i) { | 2881 for (size_t i = 0; i < kNumSsrcs; ++i) { |
2881 configured_ssrcs_[kVideoSendSsrcs[i]] = true; | 2882 configured_ssrcs_[kVideoSendSsrcs[i]] = true; |
2882 if (use_rtx) | 2883 if (use_rtx) |
2883 configured_ssrcs_[kSendRtxSsrcs[i]] = true; | 2884 configured_ssrcs_[kSendRtxSsrcs[i]] = true; |
2884 } | 2885 } |
2885 } | 2886 } |
2886 | 2887 |
2887 void ResetExpectedSsrcs(size_t num_expected_ssrcs) { | 2888 void ResetExpectedSsrcs(size_t num_expected_ssrcs) { |
2888 rtc::CritScope lock(&crit_); | 2889 rtc::CritScope lock(&crit_); |
2889 ssrc_observed_.clear(); | 2890 ssrc_observed_.clear(); |
2890 ssrcs_to_observe_ = num_expected_ssrcs; | 2891 ssrcs_to_observe_ = num_expected_ssrcs; |
2891 } | 2892 } |
2892 | 2893 |
2893 private: | 2894 private: |
2895 void ValidateTimestampGap(uint32_t ssrc, uint32_t timestamp) | |
2896 EXCLUSIVE_LOCKS_REQUIRED(crit_) { | |
2897 static const int32_t kMaxTimestampGap = kDefaultTimeoutMs * 90; | |
2898 auto timestamp_it = last_observed_timestamp_.find(ssrc); | |
2899 if (timestamp_it == last_observed_timestamp_.end()) { | |
2900 last_observed_timestamp_[ssrc] = timestamp; | |
2901 } else { | |
2902 // Verify timestamps are reasonably close. | |
2903 uint32_t latest_observed = timestamp_it->second; | |
2904 int32_t timestamp_gap = rtc::TimeDiff(timestamp, latest_observed); | |
2905 EXPECT_LE(std::abs(timestamp_gap), kMaxTimestampGap) | |
2906 << "Gap in timestamps (" << latest_observed << " -> " << timestamp | |
2907 << ") too large for SSRC: " << ssrc << "."; | |
2908 timestamp_it->second = timestamp; | |
2909 } | |
2910 } | |
2911 | |
2894 Action OnSendRtp(const uint8_t* packet, size_t length) override { | 2912 Action OnSendRtp(const uint8_t* packet, size_t length) override { |
2895 RTPHeader header; | 2913 RTPHeader header; |
2896 EXPECT_TRUE(parser_->Parse(packet, length, &header)); | 2914 EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
2897 const uint32_t ssrc = header.ssrc; | 2915 const uint32_t ssrc = header.ssrc; |
2898 const int64_t sequence_number = | 2916 const int64_t sequence_number = |
2899 seq_numbers_unwrapper_.Unwrap(header.sequenceNumber); | 2917 seq_numbers_unwrapper_.Unwrap(header.sequenceNumber); |
2900 const uint32_t timestamp = header.timestamp; | 2918 const uint32_t timestamp = header.timestamp; |
2901 const bool only_padding = | 2919 const bool only_padding = |
2902 header.headerLength + header.paddingLength == length; | 2920 header.headerLength + header.paddingLength == length; |
2903 | 2921 |
(...skipping 16 matching lines...) Expand all Loading... | |
2920 int64_t sequence_number_gap = sequence_number - latest_observed; | 2938 int64_t sequence_number_gap = sequence_number - latest_observed; |
2921 EXPECT_LE(std::abs(sequence_number_gap), kMaxSequenceNumberGap) | 2939 EXPECT_LE(std::abs(sequence_number_gap), kMaxSequenceNumberGap) |
2922 << "Gap in sequence numbers (" << latest_observed << " -> " | 2940 << "Gap in sequence numbers (" << latest_observed << " -> " |
2923 << sequence_number << ") too large for SSRC: " << ssrc << "."; | 2941 << sequence_number << ") too large for SSRC: " << ssrc << "."; |
2924 seq_numbers->push_back(sequence_number); | 2942 seq_numbers->push_back(sequence_number); |
2925 if (seq_numbers->size() >= kMaxSequenceNumberGap) { | 2943 if (seq_numbers->size() >= kMaxSequenceNumberGap) { |
2926 seq_numbers->pop_front(); | 2944 seq_numbers->pop_front(); |
2927 } | 2945 } |
2928 } | 2946 } |
2929 | 2947 |
2930 static const int32_t kMaxTimestampGap = kDefaultTimeoutMs * 90; | 2948 rtc::CritScope lock(&crit_); |
2931 auto timestamp_it = last_observed_timestamp_.find(ssrc); | 2949 ValidateTimestampGap(ssrc, timestamp); |
2932 if (timestamp_it == last_observed_timestamp_.end()) { | |
2933 last_observed_timestamp_[ssrc] = timestamp; | |
2934 } else { | |
2935 // Verify timestamps are reasonably close. | |
2936 uint32_t latest_observed = timestamp_it->second; | |
2937 int32_t timestamp_gap = rtc::TimeDiff(timestamp, latest_observed); | |
2938 EXPECT_LE(std::abs(timestamp_gap), kMaxTimestampGap) | |
2939 << "Gap in timestamps (" << latest_observed << " -> " | |
2940 << timestamp << ") too large for SSRC: " << ssrc << "."; | |
2941 timestamp_it->second = timestamp; | |
2942 } | |
2943 | 2950 |
2944 rtc::CritScope lock(&crit_); | |
2945 // Wait for media packets on all ssrcs. | 2951 // Wait for media packets on all ssrcs. |
2946 if (!ssrc_observed_[ssrc] && !only_padding) { | 2952 if (!ssrc_observed_[ssrc] && !only_padding) { |
2947 ssrc_observed_[ssrc] = true; | 2953 ssrc_observed_[ssrc] = true; |
2948 if (--ssrcs_to_observe_ == 0) | 2954 if (--ssrcs_to_observe_ == 0) |
2949 observation_complete_.Set(); | 2955 observation_complete_.Set(); |
2950 } | 2956 } |
2951 | 2957 |
2952 return SEND_PACKET; | 2958 return SEND_PACKET; |
2953 } | 2959 } |
2954 | 2960 |
2961 Action OnSendRtcp(const uint8_t* packet, size_t length) override { | |
2962 test::RtcpPacketParser rtcp_parser; | |
2963 rtcp_parser.Parse(packet, length); | |
2964 if (rtcp_parser.sender_report()->num_packets() > 0) { | |
2965 uint32_t ssrc = rtcp_parser.sender_report()->Ssrc(); | |
2966 uint32_t rtcp_timestamp = rtcp_parser.sender_report()->RtpTimestamp(); | |
2967 | |
2968 rtc::CritScope lock(&crit_); | |
2969 ValidateTimestampGap(ssrc, rtcp_timestamp); | |
2970 } | |
2971 return SEND_PACKET; | |
2972 } | |
2973 | |
2955 SequenceNumberUnwrapper seq_numbers_unwrapper_; | 2974 SequenceNumberUnwrapper seq_numbers_unwrapper_; |
2956 std::map<uint32_t, std::list<int64_t>> last_observed_seq_numbers_; | 2975 std::map<uint32_t, std::list<int64_t>> last_observed_seq_numbers_; |
2957 std::map<uint32_t, uint32_t> last_observed_timestamp_; | 2976 std::map<uint32_t, uint32_t> last_observed_timestamp_; |
2958 std::map<uint32_t, bool> configured_ssrcs_; | 2977 std::map<uint32_t, bool> configured_ssrcs_; |
2959 | 2978 |
2960 rtc::CriticalSection crit_; | 2979 rtc::CriticalSection crit_; |
2961 size_t ssrcs_to_observe_ GUARDED_BY(crit_); | 2980 size_t ssrcs_to_observe_ GUARDED_BY(crit_); |
2962 std::map<uint32_t, bool> ssrc_observed_ GUARDED_BY(crit_); | 2981 std::map<uint32_t, bool> ssrc_observed_ GUARDED_BY(crit_); |
2963 } observer(use_rtx); | 2982 } observer(use_rtx); |
2964 | 2983 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3014 // Test stream resetting more than once to make sure that the state doesn't | 3033 // Test stream resetting more than once to make sure that the state doesn't |
3015 // get set once (this could be due to using std::map::insert for instance). | 3034 // get set once (this could be due to using std::map::insert for instance). |
3016 for (size_t i = 0; i < 3; ++i) { | 3035 for (size_t i = 0; i < 3; ++i) { |
3017 frame_generator_capturer_->Stop(); | 3036 frame_generator_capturer_->Stop(); |
3018 sender_call_->DestroyVideoSendStream(video_send_stream_); | 3037 sender_call_->DestroyVideoSendStream(video_send_stream_); |
3019 | 3038 |
3020 // Re-create VideoSendStream with only one stream. | 3039 // Re-create VideoSendStream with only one stream. |
3021 video_send_stream_ = | 3040 video_send_stream_ = |
3022 sender_call_->CreateVideoSendStream(video_send_config_, one_stream); | 3041 sender_call_->CreateVideoSendStream(video_send_config_, one_stream); |
3023 video_send_stream_->Start(); | 3042 video_send_stream_->Start(); |
3043 if (wait_rtcp) { | |
3044 // Wait for SR rtcp packet before generating rtp packets. | |
3045 // There should be no rtcp packet. | |
3046 | |
3047 // Rapid Resync Request forces sending RTCP Sender Report back. | |
3048 // Alternative approach is to wait several seconds for SR to be generated. | |
3049 rtcp::RapidResyncRequest rrr; | |
pbos-webrtc
2016/06/16 11:39:43
call rrr something understandable
danilchap
2016/06/16 12:05:02
Done.
| |
3050 rtc::Buffer packet = rrr.Build(); | |
3051 static_cast<webrtc::test::DirectTransport&>(receive_transport) | |
3052 .SendRtcp(packet.data(), packet.size()); | |
3053 } | |
3024 CreateFrameGeneratorCapturer(); | 3054 CreateFrameGeneratorCapturer(); |
3025 frame_generator_capturer_->Start(); | 3055 frame_generator_capturer_->Start(); |
3026 | 3056 |
3027 observer.ResetExpectedSsrcs(1); | 3057 observer.ResetExpectedSsrcs(1); |
3028 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for single RTP packet."; | 3058 EXPECT_TRUE(observer.Wait()) << "Timed out waiting for single RTP packet."; |
3029 | 3059 |
3030 // Reconfigure back to use all streams. | 3060 // Reconfigure back to use all streams. |
3031 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_); | 3061 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_); |
3032 observer.ResetExpectedSsrcs(kNumSsrcs); | 3062 observer.ResetExpectedSsrcs(kNumSsrcs); |
3033 EXPECT_TRUE(observer.Wait()) | 3063 EXPECT_TRUE(observer.Wait()) |
(...skipping 12 matching lines...) Expand all Loading... | |
3046 } | 3076 } |
3047 | 3077 |
3048 send_transport.StopSending(); | 3078 send_transport.StopSending(); |
3049 receive_transport.StopSending(); | 3079 receive_transport.StopSending(); |
3050 | 3080 |
3051 Stop(); | 3081 Stop(); |
3052 DestroyStreams(); | 3082 DestroyStreams(); |
3053 } | 3083 } |
3054 | 3084 |
3055 TEST_F(EndToEndTest, RestartingSendStreamPreservesRtpState) { | 3085 TEST_F(EndToEndTest, RestartingSendStreamPreservesRtpState) { |
3056 TestRtpStatePreservation(false); | 3086 TestRtpStatePreservation(false, false); |
3057 } | 3087 } |
3058 | 3088 |
3059 TEST_F(EndToEndTest, RestartingSendStreamPreservesRtpStatesWithRtx) { | 3089 TEST_F(EndToEndTest, RestartingSendStreamPreservesRtpStatesWithRtx) { |
3060 TestRtpStatePreservation(true); | 3090 TestRtpStatePreservation(true, false); |
3091 } | |
3092 | |
3093 TEST_F(EndToEndTest, RestartingSendStreamKeepsRtpAndRtcpTimestampsSynced) { | |
3094 TestRtpStatePreservation(true, true); | |
3061 } | 3095 } |
3062 | 3096 |
3063 TEST_F(EndToEndTest, RespectsNetworkState) { | 3097 TEST_F(EndToEndTest, RespectsNetworkState) { |
3064 // TODO(pbos): Remove accepted downtime packets etc. when signaling network | 3098 // TODO(pbos): Remove accepted downtime packets etc. when signaling network |
3065 // down blocks until no more packets will be sent. | 3099 // down blocks until no more packets will be sent. |
3066 | 3100 |
3067 // Pacer will send from its packet list and then send required padding before | 3101 // Pacer will send from its packet list and then send required padding before |
3068 // checking paused_ again. This should be enough for one round of pacing, | 3102 // checking paused_ again. This should be enough for one round of pacing, |
3069 // otherwise increase. | 3103 // otherwise increase. |
3070 static const int kNumAcceptedDowntimeRtp = 5; | 3104 static const int kNumAcceptedDowntimeRtp = 5; |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3502 private: | 3536 private: |
3503 bool video_observed_; | 3537 bool video_observed_; |
3504 bool audio_observed_; | 3538 bool audio_observed_; |
3505 SequenceNumberUnwrapper unwrapper_; | 3539 SequenceNumberUnwrapper unwrapper_; |
3506 std::set<int64_t> received_packet_ids_; | 3540 std::set<int64_t> received_packet_ids_; |
3507 } test; | 3541 } test; |
3508 | 3542 |
3509 RunBaseTest(&test); | 3543 RunBaseTest(&test); |
3510 } | 3544 } |
3511 } // namespace webrtc | 3545 } // namespace webrtc |
OLD | NEW |