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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 | 117 |
118 void FrameList::Reset(UnorderedFrameList* free_frames) { | 118 void FrameList::Reset(UnorderedFrameList* free_frames) { |
119 while (!empty()) { | 119 while (!empty()) { |
120 begin()->second->Reset(); | 120 begin()->second->Reset(); |
121 free_frames->push_back(begin()->second); | 121 free_frames->push_back(begin()->second); |
122 erase(begin()); | 122 erase(begin()); |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 bool Vp9SsMap::Insert(const VCMPacket& packet) { | 126 bool Vp9SsMap::Insert(const VCMPacket& packet) { |
127 if (!packet.codecSpecificHeader.codecHeader.VP9.ss_data_available) | 127 if (!packet.video_header.codecHeader.VP9.ss_data_available) |
128 return false; | 128 return false; |
129 | 129 |
130 ss_map_[packet.timestamp] = packet.codecSpecificHeader.codecHeader.VP9.gof; | 130 ss_map_[packet.timestamp] = packet.video_header.codecHeader.VP9.gof; |
131 return true; | 131 return true; |
132 } | 132 } |
133 | 133 |
134 void Vp9SsMap::Reset() { | 134 void Vp9SsMap::Reset() { |
135 ss_map_.clear(); | 135 ss_map_.clear(); |
136 } | 136 } |
137 | 137 |
138 bool Vp9SsMap::Find(uint32_t timestamp, SsMap::iterator* it_out) { | 138 bool Vp9SsMap::Find(uint32_t timestamp, SsMap::iterator* it_out) { |
139 bool found = false; | 139 bool found = false; |
140 for (SsMap::iterator it = ss_map_.begin(); it != ss_map_.end(); ++it) { | 140 for (SsMap::iterator it = ss_map_.begin(); it != ss_map_.end(); ++it) { |
(...skipping 27 matching lines...) Expand all Loading... | |
168 | 168 |
169 void Vp9SsMap::AdvanceFront(uint32_t timestamp) { | 169 void Vp9SsMap::AdvanceFront(uint32_t timestamp) { |
170 RTC_DCHECK(!ss_map_.empty()); | 170 RTC_DCHECK(!ss_map_.empty()); |
171 GofInfoVP9 gof = ss_map_.begin()->second; | 171 GofInfoVP9 gof = ss_map_.begin()->second; |
172 ss_map_.erase(ss_map_.begin()); | 172 ss_map_.erase(ss_map_.begin()); |
173 ss_map_[timestamp] = gof; | 173 ss_map_[timestamp] = gof; |
174 } | 174 } |
175 | 175 |
176 // TODO(asapersson): Update according to updates in RTP payload profile. | 176 // TODO(asapersson): Update according to updates in RTP payload profile. |
177 bool Vp9SsMap::UpdatePacket(VCMPacket* packet) { | 177 bool Vp9SsMap::UpdatePacket(VCMPacket* packet) { |
178 uint8_t gof_idx = packet->codecSpecificHeader.codecHeader.VP9.gof_idx; | 178 uint8_t gof_idx = packet->video_header.codecHeader.VP9.gof_idx; |
179 if (gof_idx == kNoGofIdx) | 179 if (gof_idx == kNoGofIdx) |
180 return false; // No update needed. | 180 return false; // No update needed. |
181 | 181 |
182 SsMap::iterator it; | 182 SsMap::iterator it; |
183 if (!Find(packet->timestamp, &it)) | 183 if (!Find(packet->timestamp, &it)) |
184 return false; // Corresponding SS not yet received. | 184 return false; // Corresponding SS not yet received. |
185 | 185 |
186 if (gof_idx >= it->second.num_frames_in_gof) | 186 if (gof_idx >= it->second.num_frames_in_gof) |
187 return false; // Assume corresponding SS not yet received. | 187 return false; // Assume corresponding SS not yet received. |
188 | 188 |
189 RTPVideoHeaderVP9* vp9 = &packet->codecSpecificHeader.codecHeader.VP9; | 189 RTPVideoHeaderVP9* vp9 = &packet->video_header.codecHeader.VP9; |
190 vp9->temporal_idx = it->second.temporal_idx[gof_idx]; | 190 vp9->temporal_idx = it->second.temporal_idx[gof_idx]; |
191 vp9->temporal_up_switch = it->second.temporal_up_switch[gof_idx]; | 191 vp9->temporal_up_switch = it->second.temporal_up_switch[gof_idx]; |
192 | 192 |
193 // TODO(asapersson): Set vp9.ref_picture_id[i] and add usage. | 193 // TODO(asapersson): Set vp9.ref_picture_id[i] and add usage. |
194 vp9->num_ref_pics = it->second.num_ref_pics[gof_idx]; | 194 vp9->num_ref_pics = it->second.num_ref_pics[gof_idx]; |
195 for (uint8_t i = 0; i < it->second.num_ref_pics[gof_idx]; ++i) { | 195 for (uint8_t i = 0; i < it->second.num_ref_pics[gof_idx]; ++i) { |
196 vp9->pid_diff[i] = it->second.pid_diff[gof_idx][i]; | 196 vp9->pid_diff[i] = it->second.pid_diff[gof_idx][i]; |
197 } | 197 } |
198 return true; | 198 return true; |
199 } | 199 } |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 } | 490 } |
491 } else if (incomplete_frames_.size() <= 1) { | 491 } else if (incomplete_frames_.size() <= 1) { |
492 // Frame not ready to be decoded. | 492 // Frame not ready to be decoded. |
493 return true; | 493 return true; |
494 } | 494 } |
495 return false; | 495 return false; |
496 } | 496 } |
497 | 497 |
498 // Returns immediately or a |max_wait_time_ms| ms event hang waiting for a | 498 // Returns immediately or a |max_wait_time_ms| ms event hang waiting for a |
499 // complete frame, |max_wait_time_ms| decided by caller. | 499 // complete frame, |max_wait_time_ms| decided by caller. |
500 bool VCMJitterBuffer::NextCompleteTimestamp(uint32_t max_wait_time_ms, | 500 VCMEncodedFrame* VCMJitterBuffer::NextCompleteFrame(uint32_t max_wait_time_ms) { |
501 uint32_t* timestamp) { | 501 VCMEncodedFrame* encoded_frame; |
stefan-webrtc
2016/06/06 14:08:16
Move this down to when it's actually used.
Irfan
2016/06/06 15:39:42
Done.
| |
502 crit_sect_->Enter(); | 502 crit_sect_->Enter(); |
stefan-webrtc
2016/06/06 14:08:16
Could you change this to a scoped crit?
Irfan
2016/06/06 15:39:42
This is actually released at line 515 while doing
stefan-webrtc
2016/06/06 20:02:25
You are right, my mistake.
| |
503 if (!running_) { | 503 if (!running_) { |
504 crit_sect_->Leave(); | 504 crit_sect_->Leave(); |
505 return false; | 505 return nullptr; |
506 } | 506 } |
507 CleanUpOldOrEmptyFrames(); | 507 CleanUpOldOrEmptyFrames(); |
508 | 508 |
509 if (decodable_frames_.empty() || | 509 if (decodable_frames_.empty() || |
510 decodable_frames_.Front()->GetState() != kStateComplete) { | 510 decodable_frames_.Front()->GetState() != kStateComplete) { |
511 const int64_t end_wait_time_ms = | 511 const int64_t end_wait_time_ms = |
512 clock_->TimeInMilliseconds() + max_wait_time_ms; | 512 clock_->TimeInMilliseconds() + max_wait_time_ms; |
513 int64_t wait_time_ms = max_wait_time_ms; | 513 int64_t wait_time_ms = max_wait_time_ms; |
514 while (wait_time_ms > 0) { | 514 while (wait_time_ms > 0) { |
515 crit_sect_->Leave(); | 515 crit_sect_->Leave(); |
516 const EventTypeWrapper ret = | 516 const EventTypeWrapper ret = |
517 frame_event_->Wait(static_cast<uint32_t>(wait_time_ms)); | 517 frame_event_->Wait(static_cast<uint32_t>(wait_time_ms)); |
518 crit_sect_->Enter(); | 518 crit_sect_->Enter(); |
519 if (ret == kEventSignaled) { | 519 if (ret == kEventSignaled) { |
520 // Are we shutting down the jitter buffer? | 520 // Are we shutting down the jitter buffer? |
521 if (!running_) { | 521 if (!running_) { |
522 crit_sect_->Leave(); | 522 crit_sect_->Leave(); |
523 return false; | 523 return nullptr; |
524 } | 524 } |
525 // Finding oldest frame ready for decoder. | 525 // Finding oldest frame ready for decoder. |
526 CleanUpOldOrEmptyFrames(); | 526 CleanUpOldOrEmptyFrames(); |
527 if (decodable_frames_.empty() || | 527 if (decodable_frames_.empty() || |
528 decodable_frames_.Front()->GetState() != kStateComplete) { | 528 decodable_frames_.Front()->GetState() != kStateComplete) { |
529 wait_time_ms = end_wait_time_ms - clock_->TimeInMilliseconds(); | 529 wait_time_ms = end_wait_time_ms - clock_->TimeInMilliseconds(); |
530 } else { | 530 } else { |
531 break; | 531 break; |
532 } | 532 } |
533 } else { | 533 } else { |
534 break; | 534 break; |
535 } | 535 } |
536 } | 536 } |
537 } | 537 } |
538 if (decodable_frames_.empty() || | 538 if (decodable_frames_.empty() || |
539 decodable_frames_.Front()->GetState() != kStateComplete) { | 539 decodable_frames_.Front()->GetState() != kStateComplete) { |
540 crit_sect_->Leave(); | 540 crit_sect_->Leave(); |
541 return false; | 541 return nullptr; |
542 } | 542 } |
543 *timestamp = decodable_frames_.Front()->TimeStamp(); | 543 encoded_frame = decodable_frames_.Front(); |
stefan-webrtc
2016/06/06 14:08:16
Actually, might as well just return this directly
Irfan
2016/06/06 15:39:42
Done.
| |
544 crit_sect_->Leave(); | 544 crit_sect_->Leave(); |
545 return true; | 545 return encoded_frame; |
546 } | 546 } |
547 | 547 |
548 bool VCMJitterBuffer::NextMaybeIncompleteTimestamp(uint32_t* timestamp) { | 548 bool VCMJitterBuffer::NextMaybeIncompleteTimestamp(uint32_t* timestamp) { |
549 CriticalSectionScoped cs(crit_sect_); | 549 CriticalSectionScoped cs(crit_sect_); |
550 if (!running_) { | 550 if (!running_) { |
551 return false; | 551 return false; |
552 } | 552 } |
553 if (decode_error_mode_ == kNoErrors) { | 553 if (decode_error_mode_ == kNoErrors) { |
554 // No point to continue, as we are not decoding with errors. | 554 // No point to continue, as we are not decoding with errors. |
555 return false; | 555 return false; |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1381 if (nack_module_) | 1381 if (nack_module_) |
1382 return nack_module_->TimeUntilNextProcess(); | 1382 return nack_module_->TimeUntilNextProcess(); |
1383 return std::numeric_limits<int64_t>::max(); | 1383 return std::numeric_limits<int64_t>::max(); |
1384 } | 1384 } |
1385 | 1385 |
1386 void VCMJitterBuffer::Process() { | 1386 void VCMJitterBuffer::Process() { |
1387 if (nack_module_) | 1387 if (nack_module_) |
1388 nack_module_->Process(); | 1388 nack_module_->Process(); |
1389 } | 1389 } |
1390 } // namespace webrtc | 1390 } // namespace webrtc |
OLD | NEW |