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 |
62 uint16_t seq_num = packet->seqNum; | 63 uint16_t seq_num = packet->seqNum; |
63 size_t index = seq_num % size_; | 64 size_t index = seq_num % size_; |
64 | 65 |
65 if (!first_packet_received_) { | 66 if (!first_packet_received_) { |
66 first_seq_num_ = seq_num; | 67 first_seq_num_ = seq_num; |
67 first_packet_received_ = true; | 68 first_packet_received_ = true; |
68 } else if (AheadOf(first_seq_num_, seq_num)) { | 69 } else if (AheadOf(first_seq_num_, seq_num)) { |
69 // If we have explicitly cleared past this packet then it's old, | 70 // If we have explicitly cleared past this packet then it's old, |
70 // don't insert it. | 71 // don't insert it. |
71 if (is_cleared_to_first_seq_num_) { | 72 if (is_cleared_to_first_seq_num_) { |
(...skipping 28 matching lines...) Expand all Loading... |
100 | 101 |
101 sequence_buffer_[index].frame_begin = packet->is_first_packet_in_frame; | 102 sequence_buffer_[index].frame_begin = packet->is_first_packet_in_frame; |
102 sequence_buffer_[index].frame_end = packet->markerBit; | 103 sequence_buffer_[index].frame_end = packet->markerBit; |
103 sequence_buffer_[index].seq_num = packet->seqNum; | 104 sequence_buffer_[index].seq_num = packet->seqNum; |
104 sequence_buffer_[index].continuous = false; | 105 sequence_buffer_[index].continuous = false; |
105 sequence_buffer_[index].frame_created = false; | 106 sequence_buffer_[index].frame_created = false; |
106 sequence_buffer_[index].used = true; | 107 sequence_buffer_[index].used = true; |
107 data_buffer_[index] = *packet; | 108 data_buffer_[index] = *packet; |
108 packet->dataPtr = nullptr; | 109 packet->dataPtr = nullptr; |
109 | 110 |
| 111 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 112 last_received_packet_ms_ = rtc::Optional<int64_t>(now_ms); |
| 113 if (packet->frameType == kVideoFrameKey) |
| 114 last_received_keyframe_packet_ms_ = rtc::Optional<int64_t>(now_ms); |
| 115 |
110 found_frames = FindFrames(seq_num); | 116 found_frames = FindFrames(seq_num); |
111 } | 117 } |
112 | 118 |
113 for (std::unique_ptr<RtpFrameObject>& frame : found_frames) | 119 for (std::unique_ptr<RtpFrameObject>& frame : found_frames) |
114 received_frame_callback_->OnReceivedFrame(std::move(frame)); | 120 received_frame_callback_->OnReceivedFrame(std::move(frame)); |
115 | 121 |
116 return true; | 122 return true; |
117 } | 123 } |
118 | 124 |
119 void PacketBuffer::ClearTo(uint16_t seq_num) { | 125 void PacketBuffer::ClearTo(uint16_t seq_num) { |
(...skipping 16 matching lines...) Expand all Loading... |
136 void PacketBuffer::Clear() { | 142 void PacketBuffer::Clear() { |
137 rtc::CritScope lock(&crit_); | 143 rtc::CritScope lock(&crit_); |
138 for (size_t i = 0; i < size_; ++i) { | 144 for (size_t i = 0; i < size_; ++i) { |
139 delete[] data_buffer_[i].dataPtr; | 145 delete[] data_buffer_[i].dataPtr; |
140 data_buffer_[i].dataPtr = nullptr; | 146 data_buffer_[i].dataPtr = nullptr; |
141 sequence_buffer_[i].used = false; | 147 sequence_buffer_[i].used = false; |
142 } | 148 } |
143 | 149 |
144 first_packet_received_ = false; | 150 first_packet_received_ = false; |
145 is_cleared_to_first_seq_num_ = false; | 151 is_cleared_to_first_seq_num_ = false; |
| 152 last_received_packet_ms_ = rtc::Optional<int64_t>(); |
| 153 last_received_keyframe_packet_ms_ = rtc::Optional<int64_t>(); |
| 154 } |
| 155 |
| 156 rtc::Optional<int64_t> PacketBuffer::LastReceivedPacketMs() const { |
| 157 rtc::CritScope lock(&crit_); |
| 158 return last_received_packet_ms_; |
| 159 } |
| 160 |
| 161 rtc::Optional<int64_t> PacketBuffer::LastReceivedKeyframePacketMs() const { |
| 162 rtc::CritScope lock(&crit_); |
| 163 return last_received_keyframe_packet_ms_; |
146 } | 164 } |
147 | 165 |
148 bool PacketBuffer::ExpandBufferSize() { | 166 bool PacketBuffer::ExpandBufferSize() { |
149 if (size_ == max_size_) { | 167 if (size_ == max_size_) { |
150 LOG(LS_WARNING) << "PacketBuffer is already at max size (" << max_size_ | 168 LOG(LS_WARNING) << "PacketBuffer is already at max size (" << max_size_ |
151 << "), failed to increase size. Clearing PacketBuffer."; | 169 << "), failed to increase size. Clearing PacketBuffer."; |
152 Clear(); | 170 Clear(); |
153 return false; | 171 return false; |
154 } | 172 } |
155 | 173 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 int PacketBuffer::Release() const { | 326 int PacketBuffer::Release() const { |
309 int count = rtc::AtomicOps::Decrement(&ref_count_); | 327 int count = rtc::AtomicOps::Decrement(&ref_count_); |
310 if (!count) { | 328 if (!count) { |
311 delete this; | 329 delete this; |
312 } | 330 } |
313 return count; | 331 return count; |
314 } | 332 } |
315 | 333 |
316 } // namespace video_coding | 334 } // namespace video_coding |
317 } // namespace webrtc | 335 } // namespace webrtc |
OLD | NEW |