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 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 PacketBuffer::~PacketBuffer() { | 54 PacketBuffer::~PacketBuffer() { |
55 Clear(); | 55 Clear(); |
56 } | 56 } |
57 | 57 |
58 bool PacketBuffer::InsertPacket(VCMPacket* packet) { | 58 bool PacketBuffer::InsertPacket(VCMPacket* packet) { |
59 std::vector<std::unique_ptr<RtpFrameObject>> found_frames; | 59 std::vector<std::unique_ptr<RtpFrameObject>> found_frames; |
60 { | 60 { |
61 rtc::CritScope lock(&crit_); | 61 rtc::CritScope lock(&crit_); |
| 62 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 63 last_received_packet_ms_ = rtc::Optional<int64_t>(now_ms); |
| 64 if (packet->frameType == kVideoFrameKey) |
| 65 last_received_keyframe_packet_ms_ = rtc::Optional<int64_t>(now_ms); |
| 66 |
62 uint16_t seq_num = packet->seqNum; | 67 uint16_t seq_num = packet->seqNum; |
63 size_t index = seq_num % size_; | 68 size_t index = seq_num % size_; |
64 | 69 |
65 if (!first_packet_received_) { | 70 if (!first_packet_received_) { |
66 first_seq_num_ = seq_num; | 71 first_seq_num_ = seq_num; |
67 first_packet_received_ = true; | 72 first_packet_received_ = true; |
68 } else if (AheadOf(first_seq_num_, seq_num)) { | 73 } else if (AheadOf(first_seq_num_, seq_num)) { |
69 // If we have explicitly cleared past this packet then it's old, | 74 // If we have explicitly cleared past this packet then it's old, |
70 // don't insert it. | 75 // don't insert it. |
71 if (is_cleared_to_first_seq_num_) { | 76 if (is_cleared_to_first_seq_num_) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 void PacketBuffer::Clear() { | 141 void PacketBuffer::Clear() { |
137 rtc::CritScope lock(&crit_); | 142 rtc::CritScope lock(&crit_); |
138 for (size_t i = 0; i < size_; ++i) { | 143 for (size_t i = 0; i < size_; ++i) { |
139 delete[] data_buffer_[i].dataPtr; | 144 delete[] data_buffer_[i].dataPtr; |
140 data_buffer_[i].dataPtr = nullptr; | 145 data_buffer_[i].dataPtr = nullptr; |
141 sequence_buffer_[i].used = false; | 146 sequence_buffer_[i].used = false; |
142 } | 147 } |
143 | 148 |
144 first_packet_received_ = false; | 149 first_packet_received_ = false; |
145 is_cleared_to_first_seq_num_ = false; | 150 is_cleared_to_first_seq_num_ = false; |
| 151 last_received_packet_ms_ = rtc::Optional<int64_t>(); |
| 152 last_received_keyframe_packet_ms_ = rtc::Optional<int64_t>(); |
| 153 } |
| 154 |
| 155 rtc::Optional<int64_t> PacketBuffer::LastReceivedPacketMs() const { |
| 156 rtc::CritScope lock(&crit_); |
| 157 return last_received_packet_ms_; |
| 158 } |
| 159 |
| 160 rtc::Optional<int64_t> PacketBuffer::LastReceivedKeyframePacketMs() const { |
| 161 rtc::CritScope lock(&crit_); |
| 162 return last_received_keyframe_packet_ms_; |
146 } | 163 } |
147 | 164 |
148 bool PacketBuffer::ExpandBufferSize() { | 165 bool PacketBuffer::ExpandBufferSize() { |
149 if (size_ == max_size_) { | 166 if (size_ == max_size_) { |
150 LOG(LS_WARNING) << "PacketBuffer is already at max size (" << max_size_ | 167 LOG(LS_WARNING) << "PacketBuffer is already at max size (" << max_size_ |
151 << "), failed to increase size. Clearing PacketBuffer."; | 168 << "), failed to increase size. Clearing PacketBuffer."; |
152 Clear(); | 169 Clear(); |
153 return false; | 170 return false; |
154 } | 171 } |
155 | 172 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 int PacketBuffer::Release() const { | 329 int PacketBuffer::Release() const { |
313 int count = rtc::AtomicOps::Decrement(&ref_count_); | 330 int count = rtc::AtomicOps::Decrement(&ref_count_); |
314 if (!count) { | 331 if (!count) { |
315 delete this; | 332 delete this; |
316 } | 333 } |
317 return count; | 334 return count; |
318 } | 335 } |
319 | 336 |
320 } // namespace video_coding | 337 } // namespace video_coding |
321 } // namespace webrtc | 338 } // namespace webrtc |
OLD | NEW |