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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 RTC_DCHECK_LE(start_buffer_size, max_buffer_size); | 49 RTC_DCHECK_LE(start_buffer_size, max_buffer_size); |
50 // Buffer size must always be a power of 2. | 50 // Buffer size must always be a power of 2. |
51 RTC_DCHECK((start_buffer_size & (start_buffer_size - 1)) == 0); | 51 RTC_DCHECK((start_buffer_size & (start_buffer_size - 1)) == 0); |
52 RTC_DCHECK((max_buffer_size & (max_buffer_size - 1)) == 0); | 52 RTC_DCHECK((max_buffer_size & (max_buffer_size - 1)) == 0); |
53 } | 53 } |
54 | 54 |
55 PacketBuffer::~PacketBuffer() { | 55 PacketBuffer::~PacketBuffer() { |
56 Clear(); | 56 Clear(); |
57 } | 57 } |
58 | 58 |
59 bool PacketBuffer::InsertPacket(const VCMPacket& packet) { | 59 bool PacketBuffer::InsertPacket(VCMPacket* packet) { |
60 std::vector<std::unique_ptr<RtpFrameObject>> found_frames; | 60 std::vector<std::unique_ptr<RtpFrameObject>> found_frames; |
61 { | 61 { |
62 rtc::CritScope lock(&crit_); | 62 rtc::CritScope lock(&crit_); |
63 uint16_t seq_num = packet.seqNum; | 63 uint16_t seq_num = packet->seqNum; |
64 size_t index = seq_num % size_; | 64 size_t index = seq_num % size_; |
65 | 65 |
66 if (!first_packet_received_) { | 66 if (!first_packet_received_) { |
67 first_seq_num_ = seq_num; | 67 first_seq_num_ = seq_num; |
68 last_seq_num_ = seq_num; | 68 last_seq_num_ = seq_num; |
69 first_packet_received_ = true; | 69 first_packet_received_ = true; |
70 } else if (AheadOf(first_seq_num_, seq_num)) { | 70 } else if (AheadOf(first_seq_num_, seq_num)) { |
71 // If we have explicitly cleared past this packet then it's old, | 71 // If we have explicitly cleared past this packet then it's old, |
72 // don't insert it. | 72 // don't insert it. |
73 if (is_cleared_to_first_seq_num_) | 73 if (is_cleared_to_first_seq_num_) { |
| 74 delete[] packet->dataPtr; |
| 75 packet->dataPtr = nullptr; |
74 return false; | 76 return false; |
| 77 } |
75 | 78 |
76 first_seq_num_ = seq_num; | 79 first_seq_num_ = seq_num; |
77 } | 80 } |
78 | 81 |
79 if (sequence_buffer_[index].used) { | 82 if (sequence_buffer_[index].used) { |
80 // Duplicate packet, do nothing. | 83 // Duplicate packet, just delete the payload. |
81 if (data_buffer_[index].seqNum == packet.seqNum) | 84 if (data_buffer_[index].seqNum == packet->seqNum) { |
| 85 delete[] packet->dataPtr; |
| 86 packet->dataPtr = nullptr; |
82 return true; | 87 return true; |
| 88 } |
83 | 89 |
84 // The packet buffer is full, try to expand the buffer. | 90 // The packet buffer is full, try to expand the buffer. |
85 while (ExpandBufferSize() && sequence_buffer_[seq_num % size_].used) { | 91 while (ExpandBufferSize() && sequence_buffer_[seq_num % size_].used) { |
86 } | 92 } |
87 index = seq_num % size_; | 93 index = seq_num % size_; |
88 | 94 |
89 // Packet buffer is still full. | 95 // Packet buffer is still full. |
90 if (sequence_buffer_[index].used) | 96 if (sequence_buffer_[index].used) { |
| 97 delete[] packet->dataPtr; |
| 98 packet->dataPtr = nullptr; |
91 return false; | 99 return false; |
| 100 } |
92 } | 101 } |
93 | 102 |
94 if (AheadOf(seq_num, last_seq_num_)) | 103 if (AheadOf(seq_num, last_seq_num_)) |
95 last_seq_num_ = seq_num; | 104 last_seq_num_ = seq_num; |
96 | 105 |
97 sequence_buffer_[index].frame_begin = packet.isFirstPacket; | 106 sequence_buffer_[index].frame_begin = packet->isFirstPacket; |
98 sequence_buffer_[index].frame_end = packet.markerBit; | 107 sequence_buffer_[index].frame_end = packet->markerBit; |
99 sequence_buffer_[index].seq_num = packet.seqNum; | 108 sequence_buffer_[index].seq_num = packet->seqNum; |
100 sequence_buffer_[index].continuous = false; | 109 sequence_buffer_[index].continuous = false; |
101 sequence_buffer_[index].frame_created = false; | 110 sequence_buffer_[index].frame_created = false; |
102 sequence_buffer_[index].used = true; | 111 sequence_buffer_[index].used = true; |
103 data_buffer_[index] = packet; | 112 data_buffer_[index] = *packet; |
| 113 packet->dataPtr = nullptr; |
104 | 114 |
105 found_frames = FindFrames(seq_num); | 115 found_frames = FindFrames(seq_num); |
106 } | 116 } |
107 | 117 |
108 for (std::unique_ptr<RtpFrameObject>& frame : found_frames) | 118 for (std::unique_ptr<RtpFrameObject>& frame : found_frames) |
109 received_frame_callback_->OnReceivedFrame(std::move(frame)); | 119 received_frame_callback_->OnReceivedFrame(std::move(frame)); |
110 | 120 |
111 return true; | 121 return true; |
112 } | 122 } |
113 | 123 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 int PacketBuffer::Release() const { | 293 int PacketBuffer::Release() const { |
284 int count = rtc::AtomicOps::Decrement(&ref_count_); | 294 int count = rtc::AtomicOps::Decrement(&ref_count_); |
285 if (!count) { | 295 if (!count) { |
286 delete this; | 296 delete this; |
287 } | 297 } |
288 return count; | 298 return count; |
289 } | 299 } |
290 | 300 |
291 } // namespace video_coding | 301 } // namespace video_coding |
292 } // namespace webrtc | 302 } // namespace webrtc |
OLD | NEW |