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 22 matching lines...) Expand all Loading... | |
33 } | 33 } |
34 | 34 |
35 PacketBuffer::PacketBuffer(Clock* clock, | 35 PacketBuffer::PacketBuffer(Clock* clock, |
36 size_t start_buffer_size, | 36 size_t start_buffer_size, |
37 size_t max_buffer_size, | 37 size_t max_buffer_size, |
38 OnReceivedFrameCallback* received_frame_callback) | 38 OnReceivedFrameCallback* received_frame_callback) |
39 : clock_(clock), | 39 : clock_(clock), |
40 size_(start_buffer_size), | 40 size_(start_buffer_size), |
41 max_size_(max_buffer_size), | 41 max_size_(max_buffer_size), |
42 first_seq_num_(0), | 42 first_seq_num_(0), |
43 last_seq_num_(0), | |
44 first_packet_received_(false), | 43 first_packet_received_(false), |
45 is_cleared_to_first_seq_num_(false), | 44 is_cleared_to_first_seq_num_(false), |
46 data_buffer_(start_buffer_size), | 45 data_buffer_(start_buffer_size), |
47 sequence_buffer_(start_buffer_size), | 46 sequence_buffer_(start_buffer_size), |
48 received_frame_callback_(received_frame_callback) { | 47 received_frame_callback_(received_frame_callback) { |
49 RTC_DCHECK_LE(start_buffer_size, max_buffer_size); | 48 RTC_DCHECK_LE(start_buffer_size, max_buffer_size); |
50 // Buffer size must always be a power of 2. | 49 // Buffer size must always be a power of 2. |
51 RTC_DCHECK((start_buffer_size & (start_buffer_size - 1)) == 0); | 50 RTC_DCHECK((start_buffer_size & (start_buffer_size - 1)) == 0); |
52 RTC_DCHECK((max_buffer_size & (max_buffer_size - 1)) == 0); | 51 RTC_DCHECK((max_buffer_size & (max_buffer_size - 1)) == 0); |
53 } | 52 } |
54 | 53 |
55 PacketBuffer::~PacketBuffer() { | 54 PacketBuffer::~PacketBuffer() { |
56 Clear(); | 55 Clear(); |
57 } | 56 } |
58 | 57 |
59 bool PacketBuffer::InsertPacket(VCMPacket* packet) { | 58 bool PacketBuffer::InsertPacket(VCMPacket* packet) { |
60 std::vector<std::unique_ptr<RtpFrameObject>> found_frames; | 59 std::vector<std::unique_ptr<RtpFrameObject>> found_frames; |
61 { | 60 { |
62 rtc::CritScope lock(&crit_); | 61 rtc::CritScope lock(&crit_); |
63 uint16_t seq_num = packet->seqNum; | 62 uint16_t seq_num = packet->seqNum; |
64 size_t index = seq_num % size_; | 63 size_t index = seq_num % size_; |
65 | 64 |
66 if (!first_packet_received_) { | 65 if (!first_packet_received_) { |
67 first_seq_num_ = seq_num; | 66 first_seq_num_ = seq_num; |
68 last_seq_num_ = seq_num; | |
69 first_packet_received_ = true; | 67 first_packet_received_ = true; |
70 } else if (AheadOf(first_seq_num_, seq_num)) { | 68 } else if (AheadOf(first_seq_num_, seq_num)) { |
71 // If we have explicitly cleared past this packet then it's old, | 69 // If we have explicitly cleared past this packet then it's old, |
72 // don't insert it. | 70 // don't insert it. |
73 if (is_cleared_to_first_seq_num_) { | 71 if (is_cleared_to_first_seq_num_) { |
74 delete[] packet->dataPtr; | 72 delete[] packet->dataPtr; |
75 packet->dataPtr = nullptr; | 73 packet->dataPtr = nullptr; |
76 return false; | 74 return false; |
77 } | 75 } |
78 | 76 |
(...skipping 14 matching lines...) Expand all Loading... | |
93 index = seq_num % size_; | 91 index = seq_num % size_; |
94 | 92 |
95 // Packet buffer is still full. | 93 // Packet buffer is still full. |
96 if (sequence_buffer_[index].used) { | 94 if (sequence_buffer_[index].used) { |
97 delete[] packet->dataPtr; | 95 delete[] packet->dataPtr; |
98 packet->dataPtr = nullptr; | 96 packet->dataPtr = nullptr; |
99 return false; | 97 return false; |
100 } | 98 } |
101 } | 99 } |
102 | 100 |
103 if (AheadOf(seq_num, last_seq_num_)) | |
104 last_seq_num_ = seq_num; | |
105 | |
106 sequence_buffer_[index].frame_begin = packet->isFirstPacket; | 101 sequence_buffer_[index].frame_begin = packet->isFirstPacket; |
107 sequence_buffer_[index].frame_end = packet->markerBit; | 102 sequence_buffer_[index].frame_end = packet->markerBit; |
108 sequence_buffer_[index].seq_num = packet->seqNum; | 103 sequence_buffer_[index].seq_num = packet->seqNum; |
109 sequence_buffer_[index].continuous = false; | 104 sequence_buffer_[index].continuous = false; |
110 sequence_buffer_[index].frame_created = false; | 105 sequence_buffer_[index].frame_created = false; |
111 sequence_buffer_[index].used = true; | 106 sequence_buffer_[index].used = true; |
112 data_buffer_[index] = *packet; | 107 data_buffer_[index] = *packet; |
113 packet->dataPtr = nullptr; | 108 packet->dataPtr = nullptr; |
114 | 109 |
115 found_frames = FindFrames(seq_num); | 110 found_frames = FindFrames(seq_num); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 int prev_index = index > 0 ? index - 1 : size_ - 1; | 174 int prev_index = index > 0 ? index - 1 : size_ - 1; |
180 | 175 |
181 if (!sequence_buffer_[index].used) | 176 if (!sequence_buffer_[index].used) |
182 return false; | 177 return false; |
183 if (sequence_buffer_[index].frame_created) | 178 if (sequence_buffer_[index].frame_created) |
184 return false; | 179 return false; |
185 if (sequence_buffer_[index].frame_begin) | 180 if (sequence_buffer_[index].frame_begin) |
186 return true; | 181 return true; |
187 if (!sequence_buffer_[prev_index].used) | 182 if (!sequence_buffer_[prev_index].used) |
188 return false; | 183 return false; |
184 if (sequence_buffer_[prev_index].frame_created) | |
stefan-webrtc
2017/01/10 11:50:00
It's not clear to me why this is needed. Why can't
philipel
2017/01/10 12:03:36
This check covers this case:
p1:
seqnum 1
first
| |
185 return false; | |
189 if (sequence_buffer_[prev_index].seq_num != | 186 if (sequence_buffer_[prev_index].seq_num != |
190 sequence_buffer_[index].seq_num - 1) { | 187 sequence_buffer_[index].seq_num - 1) { |
191 return false; | 188 return false; |
192 } | 189 } |
193 if (sequence_buffer_[prev_index].continuous) | 190 if (sequence_buffer_[prev_index].continuous) |
194 return true; | 191 return true; |
195 | 192 |
196 return false; | 193 return false; |
197 } | 194 } |
198 | 195 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 int PacketBuffer::Release() const { | 290 int PacketBuffer::Release() const { |
294 int count = rtc::AtomicOps::Decrement(&ref_count_); | 291 int count = rtc::AtomicOps::Decrement(&ref_count_); |
295 if (!count) { | 292 if (!count) { |
296 delete this; | 293 delete this; |
297 } | 294 } |
298 return count; | 295 return count; |
299 } | 296 } |
300 | 297 |
301 } // namespace video_coding | 298 } // namespace video_coding |
302 } // namespace webrtc | 299 } // namespace webrtc |
OLD | NEW |