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 { | |
stefan-webrtc
2017/05/17 06:32:11
I think it would be good to add thread checks to e
philipel
2017/05/18 09:23:40
I'm not sure I understand why we should do that. W
holmer
2017/05/18 09:25:52
The main reason would be to ensure we get calls fr
| |
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 int PacketBuffer::Release() const { | 330 int PacketBuffer::Release() const { |
313 int count = rtc::AtomicOps::Decrement(&ref_count_); | 331 int count = rtc::AtomicOps::Decrement(&ref_count_); |
314 if (!count) { | 332 if (!count) { |
315 delete this; | 333 delete this; |
316 } | 334 } |
317 return count; | 335 return count; |
318 } | 336 } |
319 | 337 |
320 } // namespace video_coding | 338 } // namespace video_coding |
321 } // namespace webrtc | 339 } // namespace webrtc |
OLD | NEW |