OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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/video_coding/jitter_buffer.h" | 10 #include "webrtc/modules/video_coding/jitter_buffer.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "webrtc/modules/video_coding/include/video_coding.h" | 21 #include "webrtc/modules/video_coding/include/video_coding.h" |
22 #include "webrtc/modules/video_coding/frame_buffer.h" | 22 #include "webrtc/modules/video_coding/frame_buffer.h" |
23 #include "webrtc/modules/video_coding/inter_frame_delay.h" | 23 #include "webrtc/modules/video_coding/inter_frame_delay.h" |
24 #include "webrtc/modules/video_coding/internal_defines.h" | 24 #include "webrtc/modules/video_coding/internal_defines.h" |
25 #include "webrtc/modules/video_coding/jitter_buffer_common.h" | 25 #include "webrtc/modules/video_coding/jitter_buffer_common.h" |
26 #include "webrtc/modules/video_coding/jitter_estimator.h" | 26 #include "webrtc/modules/video_coding/jitter_estimator.h" |
27 #include "webrtc/modules/video_coding/packet.h" | 27 #include "webrtc/modules/video_coding/packet.h" |
28 #include "webrtc/system_wrappers/include/clock.h" | 28 #include "webrtc/system_wrappers/include/clock.h" |
29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
30 #include "webrtc/system_wrappers/include/event_wrapper.h" | 30 #include "webrtc/system_wrappers/include/event_wrapper.h" |
31 #include "webrtc/system_wrappers/include/field_trial.h" | |
31 #include "webrtc/system_wrappers/include/metrics.h" | 32 #include "webrtc/system_wrappers/include/metrics.h" |
32 | 33 |
33 namespace webrtc { | 34 namespace webrtc { |
34 | |
35 // Interval for updating SS data. | 35 // Interval for updating SS data. |
36 static const uint32_t kSsCleanupIntervalSec = 60; | 36 static const uint32_t kSsCleanupIntervalSec = 60; |
37 | 37 |
38 // Use this rtt if no value has been reported. | 38 // Use this rtt if no value has been reported. |
39 static const int64_t kDefaultRtt = 200; | 39 static const int64_t kDefaultRtt = 200; |
40 | 40 |
41 // Request a keyframe if no continuous frame has been received for this | 41 // Request a keyframe if no continuous frame has been received for this |
42 // number of milliseconds and NACKs are disabled. | 42 // number of milliseconds and NACKs are disabled. |
43 static const int64_t kMaxDiscontinuousFramesTime = 1000; | 43 static const int64_t kMaxDiscontinuousFramesTime = 1000; |
44 | 44 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 if (Find(frame_it.second->TimeStamp(), &ss_it)) { | 208 if (Find(frame_it.second->TimeStamp(), &ss_it)) { |
209 if (gof_idx >= ss_it->second.num_frames_in_gof) { | 209 if (gof_idx >= ss_it->second.num_frames_in_gof) { |
210 continue; // Assume corresponding SS not yet received. | 210 continue; // Assume corresponding SS not yet received. |
211 } | 211 } |
212 frame_it.second->SetGofInfo(ss_it->second, gof_idx); | 212 frame_it.second->SetGofInfo(ss_it->second, gof_idx); |
213 } | 213 } |
214 } | 214 } |
215 } | 215 } |
216 | 216 |
217 VCMJitterBuffer::VCMJitterBuffer(Clock* clock, | 217 VCMJitterBuffer::VCMJitterBuffer(Clock* clock, |
218 std::unique_ptr<EventWrapper> event) | 218 std::unique_ptr<EventWrapper> event, |
219 NackSender* nack_sender, | |
220 KeyFrameRequestSender* keyframe_request_sender) | |
219 : clock_(clock), | 221 : clock_(clock), |
220 running_(false), | 222 running_(false), |
221 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), | 223 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
222 frame_event_(std::move(event)), | 224 frame_event_(std::move(event)), |
223 max_number_of_frames_(kStartNumberOfFrames), | 225 max_number_of_frames_(kStartNumberOfFrames), |
224 free_frames_(), | 226 free_frames_(), |
225 decodable_frames_(), | 227 decodable_frames_(), |
226 incomplete_frames_(), | 228 incomplete_frames_(), |
227 last_decoded_state_(), | 229 last_decoded_state_(), |
228 first_packet_since_reset_(true), | 230 first_packet_since_reset_(true), |
(...skipping 14 matching lines...) Expand all Loading... | |
243 nack_mode_(kNoNack), | 245 nack_mode_(kNoNack), |
244 low_rtt_nack_threshold_ms_(-1), | 246 low_rtt_nack_threshold_ms_(-1), |
245 high_rtt_nack_threshold_ms_(-1), | 247 high_rtt_nack_threshold_ms_(-1), |
246 missing_sequence_numbers_(SequenceNumberLessThan()), | 248 missing_sequence_numbers_(SequenceNumberLessThan()), |
247 max_nack_list_size_(0), | 249 max_nack_list_size_(0), |
248 max_packet_age_to_nack_(0), | 250 max_packet_age_to_nack_(0), |
249 max_incomplete_time_ms_(0), | 251 max_incomplete_time_ms_(0), |
250 decode_error_mode_(kNoErrors), | 252 decode_error_mode_(kNoErrors), |
251 average_packets_per_frame_(0.0f), | 253 average_packets_per_frame_(0.0f), |
252 frame_counter_(0) { | 254 frame_counter_(0) { |
255 if (field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") == "Enabled") { | |
256 // Still need to check if the nack module should be created since | |
257 // a jitter buffer is created for the video send stream as well. | |
stefan-webrtc
2016/03/10 17:06:29
Change this comment, since when the refactoring is
philipel
2016/03/11 09:24:14
Done.
| |
258 if (nack_sender) { | |
259 RTC_DCHECK(nack_sender); | |
stefan-webrtc
2016/03/10 17:06:30
Indentation
philipel
2016/03/11 09:24:14
Done.
| |
260 RTC_DCHECK(keyframe_request_sender); | |
261 | |
262 nack_module_.reset( | |
263 new NackModule(clock, nack_sender, keyframe_request_sender)); | |
264 } | |
265 } | |
253 for (int i = 0; i < kStartNumberOfFrames; i++) | 266 for (int i = 0; i < kStartNumberOfFrames; i++) |
254 free_frames_.push_back(new VCMFrameBuffer()); | 267 free_frames_.push_back(new VCMFrameBuffer()); |
255 } | 268 } |
256 | 269 |
257 VCMJitterBuffer::~VCMJitterBuffer() { | 270 VCMJitterBuffer::~VCMJitterBuffer() { |
258 Stop(); | 271 Stop(); |
259 for (UnorderedFrameList::iterator it = free_frames_.begin(); | 272 for (UnorderedFrameList::iterator it = free_frames_.begin(); |
260 it != free_frames_.end(); ++it) { | 273 it != free_frames_.end(); ++it) { |
261 delete *it; | 274 delete *it; |
262 } | 275 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 first_packet_since_reset_ = true; | 335 first_packet_since_reset_ = true; |
323 rtt_ms_ = kDefaultRtt; | 336 rtt_ms_ = kDefaultRtt; |
324 last_decoded_state_.Reset(); | 337 last_decoded_state_.Reset(); |
325 } | 338 } |
326 | 339 |
327 void VCMJitterBuffer::Stop() { | 340 void VCMJitterBuffer::Stop() { |
328 crit_sect_->Enter(); | 341 crit_sect_->Enter(); |
329 UpdateHistograms(); | 342 UpdateHistograms(); |
330 running_ = false; | 343 running_ = false; |
331 last_decoded_state_.Reset(); | 344 last_decoded_state_.Reset(); |
345 if (nack_module_) | |
346 nack_module_->Stop(); | |
332 | 347 |
333 // Make sure all frames are free and reset. | 348 // Make sure all frames are free and reset. |
334 for (FrameList::iterator it = decodable_frames_.begin(); | 349 for (FrameList::iterator it = decodable_frames_.begin(); |
335 it != decodable_frames_.end(); ++it) { | 350 it != decodable_frames_.end(); ++it) { |
336 free_frames_.push_back(it->second); | 351 free_frames_.push_back(it->second); |
337 } | 352 } |
338 for (FrameList::iterator it = incomplete_frames_.begin(); | 353 for (FrameList::iterator it = incomplete_frames_.begin(); |
339 it != incomplete_frames_.end(); ++it) { | 354 it != incomplete_frames_.end(); ++it) { |
340 free_frames_.push_back(it->second); | 355 free_frames_.push_back(it->second); |
341 } | 356 } |
(...skipping 20 matching lines...) Expand all Loading... | |
362 last_decoded_state_.Reset(); // TODO(mikhal): sync reset. | 377 last_decoded_state_.Reset(); // TODO(mikhal): sync reset. |
363 num_consecutive_old_packets_ = 0; | 378 num_consecutive_old_packets_ = 0; |
364 // Also reset the jitter and delay estimates | 379 // Also reset the jitter and delay estimates |
365 jitter_estimate_.Reset(); | 380 jitter_estimate_.Reset(); |
366 inter_frame_delay_.Reset(clock_->TimeInMilliseconds()); | 381 inter_frame_delay_.Reset(clock_->TimeInMilliseconds()); |
367 waiting_for_completion_.frame_size = 0; | 382 waiting_for_completion_.frame_size = 0; |
368 waiting_for_completion_.timestamp = 0; | 383 waiting_for_completion_.timestamp = 0; |
369 waiting_for_completion_.latest_packet_time = -1; | 384 waiting_for_completion_.latest_packet_time = -1; |
370 first_packet_since_reset_ = true; | 385 first_packet_since_reset_ = true; |
371 missing_sequence_numbers_.clear(); | 386 missing_sequence_numbers_.clear(); |
387 if (nack_module_) | |
388 nack_module_->Flush(); | |
372 } | 389 } |
373 | 390 |
374 // Get received key and delta frames | 391 // Get received key and delta frames |
375 FrameCounts VCMJitterBuffer::FrameStatistics() const { | 392 FrameCounts VCMJitterBuffer::FrameStatistics() const { |
376 CriticalSectionScoped cs(crit_sect_); | 393 CriticalSectionScoped cs(crit_sect_); |
377 return receive_statistics_; | 394 return receive_statistics_; |
378 } | 395 } |
379 | 396 |
380 int VCMJitterBuffer::num_packets() const { | 397 int VCMJitterBuffer::num_packets() const { |
381 CriticalSectionScoped cs(crit_sect_); | 398 CriticalSectionScoped cs(crit_sect_); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 // decoder. Propagates the missing_frame bit. | 615 // decoder. Propagates the missing_frame bit. |
599 frame->PrepareForDecode(continuous); | 616 frame->PrepareForDecode(continuous); |
600 | 617 |
601 // We have a frame - update the last decoded state and nack list. | 618 // We have a frame - update the last decoded state and nack list. |
602 last_decoded_state_.SetState(frame); | 619 last_decoded_state_.SetState(frame); |
603 DropPacketsFromNackList(last_decoded_state_.sequence_num()); | 620 DropPacketsFromNackList(last_decoded_state_.sequence_num()); |
604 | 621 |
605 if ((*frame).IsSessionComplete()) | 622 if ((*frame).IsSessionComplete()) |
606 UpdateAveragePacketsPerFrame(frame->NumPackets()); | 623 UpdateAveragePacketsPerFrame(frame->NumPackets()); |
607 | 624 |
625 if (nack_module_) | |
626 nack_module_->ClearUpTo(frame->GetHighSeqNum()); | |
608 return frame; | 627 return frame; |
609 } | 628 } |
610 | 629 |
611 // Release frame when done with decoding. Should never be used to release | 630 // Release frame when done with decoding. Should never be used to release |
612 // frames from within the jitter buffer. | 631 // frames from within the jitter buffer. |
613 void VCMJitterBuffer::ReleaseFrame(VCMEncodedFrame* frame) { | 632 void VCMJitterBuffer::ReleaseFrame(VCMEncodedFrame* frame) { |
614 CriticalSectionScoped cs(crit_sect_); | 633 CriticalSectionScoped cs(crit_sect_); |
615 VCMFrameBuffer* frame_buffer = static_cast<VCMFrameBuffer*>(frame); | 634 VCMFrameBuffer* frame_buffer = static_cast<VCMFrameBuffer*>(frame); |
616 if (frame_buffer) { | 635 if (frame_buffer) { |
617 free_frames_.push_back(frame_buffer); | 636 free_frames_.push_back(frame_buffer); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 const VCMFrameBuffer* frame_buffer = | 677 const VCMFrameBuffer* frame_buffer = |
659 static_cast<const VCMFrameBuffer*>(frame); | 678 static_cast<const VCMFrameBuffer*>(frame); |
660 *retransmitted = (frame_buffer->GetNackCount() > 0); | 679 *retransmitted = (frame_buffer->GetNackCount() > 0); |
661 return frame_buffer->LatestPacketTimeMs(); | 680 return frame_buffer->LatestPacketTimeMs(); |
662 } | 681 } |
663 | 682 |
664 VCMFrameBufferEnum VCMJitterBuffer::InsertPacket(const VCMPacket& packet, | 683 VCMFrameBufferEnum VCMJitterBuffer::InsertPacket(const VCMPacket& packet, |
665 bool* retransmitted) { | 684 bool* retransmitted) { |
666 CriticalSectionScoped cs(crit_sect_); | 685 CriticalSectionScoped cs(crit_sect_); |
667 | 686 |
687 if (nack_module_) | |
688 nack_module_->OnReceivedPacket(packet); | |
689 | |
668 ++num_packets_; | 690 ++num_packets_; |
669 if (num_packets_ == 1) { | 691 if (num_packets_ == 1) { |
670 time_first_packet_ms_ = clock_->TimeInMilliseconds(); | 692 time_first_packet_ms_ = clock_->TimeInMilliseconds(); |
671 } | 693 } |
672 // Does this packet belong to an old frame? | 694 // Does this packet belong to an old frame? |
673 if (last_decoded_state_.IsOldPacket(&packet)) { | 695 if (last_decoded_state_.IsOldPacket(&packet)) { |
674 // Account only for media packets. | 696 // Account only for media packets. |
675 if (packet.sizeBytes > 0) { | 697 if (packet.sizeBytes > 0) { |
676 num_discarded_packets_++; | 698 num_discarded_packets_++; |
677 num_consecutive_old_packets_++; | 699 num_consecutive_old_packets_++; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
920 // when waiting for retransmissions. | 942 // when waiting for retransmissions. |
921 rtt_mult = 0.0f; | 943 rtt_mult = 0.0f; |
922 } | 944 } |
923 return jitter_estimate_.GetJitterEstimate(rtt_mult); | 945 return jitter_estimate_.GetJitterEstimate(rtt_mult); |
924 } | 946 } |
925 | 947 |
926 void VCMJitterBuffer::UpdateRtt(int64_t rtt_ms) { | 948 void VCMJitterBuffer::UpdateRtt(int64_t rtt_ms) { |
927 CriticalSectionScoped cs(crit_sect_); | 949 CriticalSectionScoped cs(crit_sect_); |
928 rtt_ms_ = rtt_ms; | 950 rtt_ms_ = rtt_ms; |
929 jitter_estimate_.UpdateRtt(rtt_ms); | 951 jitter_estimate_.UpdateRtt(rtt_ms); |
952 if (nack_module_) | |
953 nack_module_->UpdateRtt(rtt_ms); | |
930 } | 954 } |
931 | 955 |
932 void VCMJitterBuffer::SetNackMode(VCMNackMode mode, | 956 void VCMJitterBuffer::SetNackMode(VCMNackMode mode, |
933 int64_t low_rtt_nack_threshold_ms, | 957 int64_t low_rtt_nack_threshold_ms, |
934 int64_t high_rtt_nack_threshold_ms) { | 958 int64_t high_rtt_nack_threshold_ms) { |
935 CriticalSectionScoped cs(crit_sect_); | 959 CriticalSectionScoped cs(crit_sect_); |
936 nack_mode_ = mode; | 960 nack_mode_ = mode; |
937 if (mode == kNoNack) { | 961 if (mode == kNoNack) { |
938 missing_sequence_numbers_.clear(); | 962 missing_sequence_numbers_.clear(); |
939 } | 963 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1039 } else { | 1063 } else { |
1040 // Skip to the last key frame. If it's incomplete we will start | 1064 // Skip to the last key frame. If it's incomplete we will start |
1041 // NACKing it. | 1065 // NACKing it. |
1042 // Note that the estimated low sequence number is correct for VP8 | 1066 // Note that the estimated low sequence number is correct for VP8 |
1043 // streams because only the first packet of a key frame is marked. | 1067 // streams because only the first packet of a key frame is marked. |
1044 last_decoded_state_.Reset(); | 1068 last_decoded_state_.Reset(); |
1045 DropPacketsFromNackList(EstimatedLowSequenceNumber(*rit->second)); | 1069 DropPacketsFromNackList(EstimatedLowSequenceNumber(*rit->second)); |
1046 } | 1070 } |
1047 } | 1071 } |
1048 } | 1072 } |
1073 // The experiment is running, the nack module will send Nacks. | |
1074 if (nack_module_) | |
1075 return std::vector<uint16_t>(); | |
1076 | |
1049 std::vector<uint16_t> nack_list(missing_sequence_numbers_.begin(), | 1077 std::vector<uint16_t> nack_list(missing_sequence_numbers_.begin(), |
1050 missing_sequence_numbers_.end()); | 1078 missing_sequence_numbers_.end()); |
1051 return nack_list; | 1079 return nack_list; |
1052 } | 1080 } |
1053 | 1081 |
1054 void VCMJitterBuffer::SetDecodeErrorMode(VCMDecodeErrorMode error_mode) { | 1082 void VCMJitterBuffer::SetDecodeErrorMode(VCMDecodeErrorMode error_mode) { |
1055 CriticalSectionScoped cs(crit_sect_); | 1083 CriticalSectionScoped cs(crit_sect_); |
1056 decode_error_mode_ = error_mode; | 1084 decode_error_mode_ = error_mode; |
1057 } | 1085 } |
1058 | 1086 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1336 return false; | 1364 return false; |
1337 } | 1365 } |
1338 // Evaluate if the RTT is higher than |high_rtt_nack_threshold_ms_|, and in | 1366 // Evaluate if the RTT is higher than |high_rtt_nack_threshold_ms_|, and in |
1339 // that case we don't wait for retransmissions. | 1367 // that case we don't wait for retransmissions. |
1340 if (high_rtt_nack_threshold_ms_ >= 0 && | 1368 if (high_rtt_nack_threshold_ms_ >= 0 && |
1341 rtt_ms_ >= high_rtt_nack_threshold_ms_) { | 1369 rtt_ms_ >= high_rtt_nack_threshold_ms_) { |
1342 return false; | 1370 return false; |
1343 } | 1371 } |
1344 return true; | 1372 return true; |
1345 } | 1373 } |
1374 | |
1375 int64_t VCMJitterBuffer::TimeUntilNextProcess() { | |
1376 if (nack_module_) | |
1377 return nack_module_->TimeUntilNextProcess(); | |
1378 return 100000; | |
stefan-webrtc
2016/03/10 17:06:29
This is a bit ugly, but it might be necessary. Is
philipel
2016/03/11 09:24:14
Changed to int64_t max. Just testing using video_l
| |
1379 } | |
1380 | |
1381 void VCMJitterBuffer::Process() { | |
1382 if (nack_module_) | |
1383 nack_module_->Process(); | |
1384 } | |
1346 } // namespace webrtc | 1385 } // namespace webrtc |
OLD | NEW |