| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 "webrtc/modules/congestion_controller/delay_based_bwe_unittest_helper.h
" | 10 #include "webrtc/modules/congestion_controller/delay_based_bwe_unittest_helper.h
" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 bitrate_bps_(bitrate_bps), | 40 bitrate_bps_(bitrate_bps), |
| 41 next_rtp_time_(0), | 41 next_rtp_time_(0), |
| 42 sequence_number_(0) { | 42 sequence_number_(0) { |
| 43 RTC_CHECK_GT(fps_, 0); | 43 RTC_CHECK_GT(fps_, 0); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Generates a new frame for this stream. If called too soon after the | 46 // Generates a new frame for this stream. If called too soon after the |
| 47 // previous frame, no frame will be generated. The frame is split into | 47 // previous frame, no frame will be generated. The frame is split into |
| 48 // packets. | 48 // packets. |
| 49 int64_t RtpStream::GenerateFrame(int64_t time_now_us, | 49 int64_t RtpStream::GenerateFrame(int64_t time_now_us, |
| 50 std::vector<PacketInfo>* packets) { | 50 std::vector<PacketFeedback>* packets) { |
| 51 if (time_now_us < next_rtp_time_) { | 51 if (time_now_us < next_rtp_time_) { |
| 52 return next_rtp_time_; | 52 return next_rtp_time_; |
| 53 } | 53 } |
| 54 RTC_CHECK(packets != NULL); | 54 RTC_CHECK(packets != NULL); |
| 55 size_t bits_per_frame = (bitrate_bps_ + fps_ / 2) / fps_; | 55 size_t bits_per_frame = (bitrate_bps_ + fps_ / 2) / fps_; |
| 56 size_t n_packets = | 56 size_t n_packets = |
| 57 std::max<size_t>((bits_per_frame + 4 * kMtu) / (8 * kMtu), 1u); | 57 std::max<size_t>((bits_per_frame + 4 * kMtu) / (8 * kMtu), 1u); |
| 58 size_t payload_size = (bits_per_frame + 4 * n_packets) / (8 * n_packets); | 58 size_t payload_size = (bits_per_frame + 4 * n_packets) / (8 * n_packets); |
| 59 for (size_t i = 0; i < n_packets; ++i) { | 59 for (size_t i = 0; i < n_packets; ++i) { |
| 60 PacketInfo packet(-1, sequence_number_++); | 60 PacketFeedback packet(-1, sequence_number_++); |
| 61 packet.send_time_ms = (time_now_us + kSendSideOffsetUs) / 1000; | 61 packet.send_time_ms = (time_now_us + kSendSideOffsetUs) / 1000; |
| 62 packet.payload_size = payload_size; | 62 packet.payload_size = payload_size; |
| 63 packets->push_back(packet); | 63 packets->push_back(packet); |
| 64 } | 64 } |
| 65 next_rtp_time_ = time_now_us + (1000000 + fps_ / 2) / fps_; | 65 next_rtp_time_ = time_now_us + (1000000 + fps_ / 2) / fps_; |
| 66 return next_rtp_time_; | 66 return next_rtp_time_; |
| 67 } | 67 } |
| 68 | 68 |
| 69 // The send-side time when the next frame can be generated. | 69 // The send-side time when the next frame can be generated. |
| 70 int64_t RtpStream::next_rtp_time() const { | 70 int64_t RtpStream::next_rtp_time() const { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 total_bitrate_before; | 116 total_bitrate_before; |
| 117 stream->set_bitrate_bps(bitrate_after - total_bitrate_after); | 117 stream->set_bitrate_bps(bitrate_after - total_bitrate_after); |
| 118 total_bitrate_after += stream->bitrate_bps(); | 118 total_bitrate_after += stream->bitrate_bps(); |
| 119 } | 119 } |
| 120 ASSERT_EQ(bitrate_before, total_bitrate_before); | 120 ASSERT_EQ(bitrate_before, total_bitrate_before); |
| 121 EXPECT_EQ(total_bitrate_after, bitrate_bps); | 121 EXPECT_EQ(total_bitrate_after, bitrate_bps); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // TODO(holmer): Break out the channel simulation part from this class to make | 124 // TODO(holmer): Break out the channel simulation part from this class to make |
| 125 // it possible to simulate different types of channels. | 125 // it possible to simulate different types of channels. |
| 126 int64_t StreamGenerator::GenerateFrame(std::vector<PacketInfo>* packets, | 126 int64_t StreamGenerator::GenerateFrame(std::vector<PacketFeedback>* packets, |
| 127 int64_t time_now_us) { | 127 int64_t time_now_us) { |
| 128 RTC_CHECK(packets != NULL); | 128 RTC_CHECK(packets != NULL); |
| 129 RTC_CHECK(packets->empty()); | 129 RTC_CHECK(packets->empty()); |
| 130 RTC_CHECK_GT(capacity_, 0); | 130 RTC_CHECK_GT(capacity_, 0); |
| 131 auto it = | 131 auto it = |
| 132 std::min_element(streams_.begin(), streams_.end(), RtpStream::Compare); | 132 std::min_element(streams_.begin(), streams_.end(), RtpStream::Compare); |
| 133 (*it)->GenerateFrame(time_now_us, packets); | 133 (*it)->GenerateFrame(time_now_us, packets); |
| 134 int i = 0; | 134 int i = 0; |
| 135 for (PacketInfo& packet : *packets) { | 135 for (PacketFeedback& packet : *packets) { |
| 136 int capacity_bpus = capacity_ / 1000; | 136 int capacity_bpus = capacity_ / 1000; |
| 137 int64_t required_network_time_us = | 137 int64_t required_network_time_us = |
| 138 (8 * 1000 * packet.payload_size + capacity_bpus / 2) / capacity_bpus; | 138 (8 * 1000 * packet.payload_size + capacity_bpus / 2) / capacity_bpus; |
| 139 prev_arrival_time_us_ = | 139 prev_arrival_time_us_ = |
| 140 std::max(time_now_us + required_network_time_us, | 140 std::max(time_now_us + required_network_time_us, |
| 141 prev_arrival_time_us_ + required_network_time_us); | 141 prev_arrival_time_us_ + required_network_time_us); |
| 142 packet.arrival_time_ms = prev_arrival_time_us_ / 1000; | 142 packet.arrival_time_ms = prev_arrival_time_us_ / 1000; |
| 143 ++i; | 143 ++i; |
| 144 } | 144 } |
| 145 it = std::min_element(streams_.begin(), streams_.end(), RtpStream::Compare); | 145 it = std::min_element(streams_.begin(), streams_.end(), RtpStream::Compare); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 170 IncomingFeedback(arrival_time_ms, send_time_ms, sequence_number, payload_size, | 170 IncomingFeedback(arrival_time_ms, send_time_ms, sequence_number, payload_size, |
| 171 PacedPacketInfo()); | 171 PacedPacketInfo()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void DelayBasedBweTest::IncomingFeedback(int64_t arrival_time_ms, | 174 void DelayBasedBweTest::IncomingFeedback(int64_t arrival_time_ms, |
| 175 int64_t send_time_ms, | 175 int64_t send_time_ms, |
| 176 uint16_t sequence_number, | 176 uint16_t sequence_number, |
| 177 size_t payload_size, | 177 size_t payload_size, |
| 178 const PacedPacketInfo& pacing_info) { | 178 const PacedPacketInfo& pacing_info) { |
| 179 RTC_CHECK_GE(arrival_time_ms + arrival_time_offset_ms_, 0); | 179 RTC_CHECK_GE(arrival_time_ms + arrival_time_offset_ms_, 0); |
| 180 PacketInfo packet(arrival_time_ms + arrival_time_offset_ms_, send_time_ms, | 180 PacketFeedback packet(arrival_time_ms + arrival_time_offset_ms_, send_time_ms, |
| 181 sequence_number, payload_size, pacing_info); | 181 sequence_number, payload_size, pacing_info); |
| 182 std::vector<PacketInfo> packets; | 182 std::vector<PacketFeedback> packets; |
| 183 packets.push_back(packet); | 183 packets.push_back(packet); |
| 184 DelayBasedBwe::Result result = | 184 DelayBasedBwe::Result result = |
| 185 bitrate_estimator_->IncomingPacketFeedbackVector(packets); | 185 bitrate_estimator_->IncomingPacketFeedbackVector(packets); |
| 186 const uint32_t kDummySsrc = 0; | 186 const uint32_t kDummySsrc = 0; |
| 187 if (result.updated) { | 187 if (result.updated) { |
| 188 bitrate_observer_.OnReceiveBitrateChanged({kDummySsrc}, | 188 bitrate_observer_.OnReceiveBitrateChanged({kDummySsrc}, |
| 189 result.target_bitrate_bps); | 189 result.target_bitrate_bps); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 // Generates a frame of packets belonging to a stream at a given bitrate and | 193 // Generates a frame of packets belonging to a stream at a given bitrate and |
| 194 // with a given ssrc. The stream is pushed through a very simple simulated | 194 // with a given ssrc. The stream is pushed through a very simple simulated |
| 195 // network, and is then given to the receive-side bandwidth estimator. | 195 // network, and is then given to the receive-side bandwidth estimator. |
| 196 // Returns true if an over-use was seen, false otherwise. | 196 // Returns true if an over-use was seen, false otherwise. |
| 197 // The StreamGenerator::updated() should be used to check for any changes in | 197 // The StreamGenerator::updated() should be used to check for any changes in |
| 198 // target bitrate after the call to this function. | 198 // target bitrate after the call to this function. |
| 199 bool DelayBasedBweTest::GenerateAndProcessFrame(uint32_t ssrc, | 199 bool DelayBasedBweTest::GenerateAndProcessFrame(uint32_t ssrc, |
| 200 uint32_t bitrate_bps) { | 200 uint32_t bitrate_bps) { |
| 201 stream_generator_->SetBitrateBps(bitrate_bps); | 201 stream_generator_->SetBitrateBps(bitrate_bps); |
| 202 std::vector<PacketInfo> packets; | 202 std::vector<PacketFeedback> packets; |
| 203 int64_t next_time_us = | 203 int64_t next_time_us = |
| 204 stream_generator_->GenerateFrame(&packets, clock_.TimeInMicroseconds()); | 204 stream_generator_->GenerateFrame(&packets, clock_.TimeInMicroseconds()); |
| 205 if (packets.empty()) | 205 if (packets.empty()) |
| 206 return false; | 206 return false; |
| 207 | 207 |
| 208 bool overuse = false; | 208 bool overuse = false; |
| 209 bitrate_observer_.Reset(); | 209 bitrate_observer_.Reset(); |
| 210 clock_.AdvanceTimeMicroseconds(1000 * packets.back().arrival_time_ms - | 210 clock_.AdvanceTimeMicroseconds(1000 * packets.back().arrival_time_ms - |
| 211 clock_.TimeInMicroseconds()); | 211 clock_.TimeInMicroseconds()); |
| 212 for (auto& packet : packets) { | 212 for (auto& packet : packets) { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, | 496 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, |
| 497 sequence_number++, 1000); | 497 sequence_number++, 1000); |
| 498 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs); | 498 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs); |
| 499 send_time_ms += kFrameIntervalMs; | 499 send_time_ms += kFrameIntervalMs; |
| 500 } | 500 } |
| 501 uint32_t bitrate_after = 0; | 501 uint32_t bitrate_after = 0; |
| 502 bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_after); | 502 bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_after); |
| 503 EXPECT_LT(bitrate_after, bitrate_before); | 503 EXPECT_LT(bitrate_after, bitrate_before); |
| 504 } | 504 } |
| 505 } // namespace webrtc | 505 } // namespace webrtc |
| OLD | NEW |