Chromium Code Reviews| 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/main/source/jitter_buffer.h" | 10 #include "webrtc/modules/video_coding/main/source/jitter_buffer.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 : clock_(clock), | 118 : clock_(clock), |
| 119 running_(false), | 119 running_(false), |
| 120 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), | 120 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
| 121 frame_event_(event.Pass()), | 121 frame_event_(event.Pass()), |
| 122 max_number_of_frames_(kStartNumberOfFrames), | 122 max_number_of_frames_(kStartNumberOfFrames), |
| 123 free_frames_(), | 123 free_frames_(), |
| 124 decodable_frames_(), | 124 decodable_frames_(), |
| 125 incomplete_frames_(), | 125 incomplete_frames_(), |
| 126 last_decoded_state_(), | 126 last_decoded_state_(), |
| 127 first_packet_since_reset_(true), | 127 first_packet_since_reset_(true), |
| 128 last_gof_timestamp_(0), | |
| 129 last_gof_valid_(false), | |
| 128 stats_callback_(NULL), | 130 stats_callback_(NULL), |
| 129 incoming_frame_rate_(0), | 131 incoming_frame_rate_(0), |
| 130 incoming_frame_count_(0), | 132 incoming_frame_count_(0), |
| 131 time_last_incoming_frame_count_(0), | 133 time_last_incoming_frame_count_(0), |
| 132 incoming_bit_count_(0), | 134 incoming_bit_count_(0), |
| 133 incoming_bit_rate_(0), | 135 incoming_bit_rate_(0), |
| 134 num_consecutive_old_packets_(0), | 136 num_consecutive_old_packets_(0), |
| 135 num_packets_(0), | 137 num_packets_(0), |
| 136 num_duplicated_packets_(0), | 138 num_duplicated_packets_(0), |
| 137 num_discarded_packets_(0), | 139 num_discarded_packets_(0), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 num_discarded_packets_ = 0; | 215 num_discarded_packets_ = 0; |
| 214 time_first_packet_ms_ = 0; | 216 time_first_packet_ms_ = 0; |
| 215 | 217 |
| 216 // Start in a non-signaled state. | 218 // Start in a non-signaled state. |
| 217 waiting_for_completion_.frame_size = 0; | 219 waiting_for_completion_.frame_size = 0; |
| 218 waiting_for_completion_.timestamp = 0; | 220 waiting_for_completion_.timestamp = 0; |
| 219 waiting_for_completion_.latest_packet_time = -1; | 221 waiting_for_completion_.latest_packet_time = -1; |
| 220 first_packet_since_reset_ = true; | 222 first_packet_since_reset_ = true; |
| 221 rtt_ms_ = kDefaultRtt; | 223 rtt_ms_ = kDefaultRtt; |
| 222 last_decoded_state_.Reset(); | 224 last_decoded_state_.Reset(); |
| 225 last_gof_valid_ = false; | |
| 223 } | 226 } |
| 224 | 227 |
| 225 void VCMJitterBuffer::Stop() { | 228 void VCMJitterBuffer::Stop() { |
| 226 crit_sect_->Enter(); | 229 crit_sect_->Enter(); |
| 227 UpdateHistograms(); | 230 UpdateHistograms(); |
| 228 running_ = false; | 231 running_ = false; |
| 229 last_decoded_state_.Reset(); | 232 last_decoded_state_.Reset(); |
| 233 last_gof_valid_ = false; | |
| 234 | |
| 230 // Make sure all frames are free and reset. | 235 // Make sure all frames are free and reset. |
| 231 for (FrameList::iterator it = decodable_frames_.begin(); | 236 for (FrameList::iterator it = decodable_frames_.begin(); |
| 232 it != decodable_frames_.end(); ++it) { | 237 it != decodable_frames_.end(); ++it) { |
| 233 free_frames_.push_back(it->second); | 238 free_frames_.push_back(it->second); |
| 234 } | 239 } |
| 235 for (FrameList::iterator it = incomplete_frames_.begin(); | 240 for (FrameList::iterator it = incomplete_frames_.begin(); |
| 236 it != incomplete_frames_.end(); ++it) { | 241 it != incomplete_frames_.end(); ++it) { |
| 237 free_frames_.push_back(it->second); | 242 free_frames_.push_back(it->second); |
| 238 } | 243 } |
| 239 for (UnorderedFrameList::iterator it = free_frames_.begin(); | 244 for (UnorderedFrameList::iterator it = free_frames_.begin(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 250 bool VCMJitterBuffer::Running() const { | 255 bool VCMJitterBuffer::Running() const { |
| 251 CriticalSectionScoped cs(crit_sect_); | 256 CriticalSectionScoped cs(crit_sect_); |
| 252 return running_; | 257 return running_; |
| 253 } | 258 } |
| 254 | 259 |
| 255 void VCMJitterBuffer::Flush() { | 260 void VCMJitterBuffer::Flush() { |
| 256 CriticalSectionScoped cs(crit_sect_); | 261 CriticalSectionScoped cs(crit_sect_); |
| 257 decodable_frames_.Reset(&free_frames_); | 262 decodable_frames_.Reset(&free_frames_); |
| 258 incomplete_frames_.Reset(&free_frames_); | 263 incomplete_frames_.Reset(&free_frames_); |
| 259 last_decoded_state_.Reset(); // TODO(mikhal): sync reset. | 264 last_decoded_state_.Reset(); // TODO(mikhal): sync reset. |
| 265 last_gof_valid_ = false; | |
| 260 num_consecutive_old_packets_ = 0; | 266 num_consecutive_old_packets_ = 0; |
| 261 // Also reset the jitter and delay estimates | 267 // Also reset the jitter and delay estimates |
| 262 jitter_estimate_.Reset(); | 268 jitter_estimate_.Reset(); |
| 263 inter_frame_delay_.Reset(clock_->TimeInMilliseconds()); | 269 inter_frame_delay_.Reset(clock_->TimeInMilliseconds()); |
| 264 waiting_for_completion_.frame_size = 0; | 270 waiting_for_completion_.frame_size = 0; |
| 265 waiting_for_completion_.timestamp = 0; | 271 waiting_for_completion_.timestamp = 0; |
| 266 waiting_for_completion_.latest_packet_time = -1; | 272 waiting_for_completion_.latest_packet_time = -1; |
| 267 first_packet_since_reset_ = true; | 273 first_packet_since_reset_ = true; |
| 268 missing_sequence_numbers_.clear(); | 274 missing_sequence_numbers_.clear(); |
| 269 } | 275 } |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 } else if (waiting_for_completion_.latest_packet_time >= 0 && | 620 } else if (waiting_for_completion_.latest_packet_time >= 0 && |
| 615 waiting_for_completion_.latest_packet_time + 2000 <= now_ms) { | 621 waiting_for_completion_.latest_packet_time + 2000 <= now_ms) { |
| 616 // A packet should never be more than two seconds late | 622 // A packet should never be more than two seconds late |
| 617 UpdateJitterEstimate(waiting_for_completion_, true); | 623 UpdateJitterEstimate(waiting_for_completion_, true); |
| 618 waiting_for_completion_.latest_packet_time = -1; | 624 waiting_for_completion_.latest_packet_time = -1; |
| 619 waiting_for_completion_.frame_size = 0; | 625 waiting_for_completion_.frame_size = 0; |
| 620 waiting_for_completion_.timestamp = 0; | 626 waiting_for_completion_.timestamp = 0; |
| 621 } | 627 } |
| 622 } | 628 } |
| 623 | 629 |
| 630 if (packet.codec == kVideoCodecVP9) { | |
| 631 // TODO(asapersson): Move this code? | |
| 632 if (packet.codecSpecificHeader.codecHeader.VP9.ssDataAvailable) { | |
| 633 if (first_packet_since_reset_ || | |
| 634 IsNewerTimestamp(packet.timestamp, last_gof_timestamp_)) { | |
| 635 last_gof_.CopyGofInfoVP9( | |
| 636 packet.codecSpecificHeader.codecHeader.VP9.gof); | |
|
stefan-webrtc
2015/07/09 14:49:00
This gof info is necessary to know if a frame is d
åsapersson
2015/07/29 12:10:13
Decoding state looks at frame's TL, etc. Shouldn't
| |
| 637 last_gof_timestamp_ = packet.timestamp; | |
| 638 last_gof_valid_ = true; | |
| 639 } | |
| 640 } | |
| 641 if (last_gof_valid_ && | |
| 642 !packet.codecSpecificHeader.codecHeader.VP9.flexibleMode) { | |
| 643 uint8_t gof_idx = packet.codecSpecificHeader.codecHeader.VP9.gofIdx; | |
| 644 if (gof_idx != kNoGofIdx) { | |
| 645 if (gof_idx >= last_gof_.numFramesInGof) { | |
| 646 return kGeneralError; | |
| 647 } | |
| 648 RTPVideoTypeHeader* hdr = const_cast<RTPVideoTypeHeader*>( | |
| 649 &packet.codecSpecificHeader.codecHeader); | |
| 650 hdr->VP9.temporalIdx = last_gof_.temporalIdx[gof_idx]; | |
| 651 hdr->VP9.temporalUpSwitch = last_gof_.temporalUpSwitch[gof_idx]; | |
| 652 } | |
| 653 } | |
| 654 // TODO(asapersson): Handle out of order GOF. | |
| 655 } | |
| 656 | |
| 624 VCMFrameBufferStateEnum previous_state = frame->GetState(); | 657 VCMFrameBufferStateEnum previous_state = frame->GetState(); |
| 625 // Insert packet. | 658 // Insert packet. |
| 626 FrameData frame_data; | 659 FrameData frame_data; |
| 627 frame_data.rtt_ms = rtt_ms_; | 660 frame_data.rtt_ms = rtt_ms_; |
| 628 frame_data.rolling_average_packets_per_frame = average_packets_per_frame_; | 661 frame_data.rolling_average_packets_per_frame = average_packets_per_frame_; |
| 629 VCMFrameBufferEnum buffer_state = | 662 VCMFrameBufferEnum buffer_state = |
| 630 frame->InsertPacket(packet, now_ms, decode_error_mode_, frame_data); | 663 frame->InsertPacket(packet, now_ms, decode_error_mode_, frame_data); |
| 631 | 664 |
| 632 if (previous_state != kStateComplete) { | 665 if (previous_state != kStateComplete) { |
| 633 TRACE_EVENT_ASYNC_BEGIN1("webrtc", "Video", frame->TimeStamp(), | 666 TRACE_EVENT_ASYNC_BEGIN1("webrtc", "Video", frame->TimeStamp(), |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1215 } | 1248 } |
| 1216 // Evaluate if the RTT is higher than |high_rtt_nack_threshold_ms_|, and in | 1249 // Evaluate if the RTT is higher than |high_rtt_nack_threshold_ms_|, and in |
| 1217 // that case we don't wait for retransmissions. | 1250 // that case we don't wait for retransmissions. |
| 1218 if (high_rtt_nack_threshold_ms_ >= 0 && | 1251 if (high_rtt_nack_threshold_ms_ >= 0 && |
| 1219 rtt_ms_ >= high_rtt_nack_threshold_ms_) { | 1252 rtt_ms_ >= high_rtt_nack_threshold_ms_) { |
| 1220 return false; | 1253 return false; |
| 1221 } | 1254 } |
| 1222 return true; | 1255 return true; |
| 1223 } | 1256 } |
| 1224 } // namespace webrtc | 1257 } // namespace webrtc |
| OLD | NEW |