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 |
11 #include "webrtc/modules/video_coding/packet_buffer.h" | 11 #include "webrtc/modules/video_coding/packet_buffer.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <limits> | 14 #include <limits> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/modules/video_coding/frame_object.h" | 18 #include "webrtc/modules/video_coding/frame_object.h" |
19 #include "webrtc/system_wrappers/include/clock.h" | 19 #include "webrtc/system_wrappers/include/clock.h" |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 namespace video_coding { | 22 namespace video_coding { |
23 | 23 |
24 rtc::scoped_refptr<PacketBuffer> PacketBuffer::Create( | |
25 Clock* clock, | |
26 size_t start_buffer_size, | |
27 size_t max_buffer_size, | |
28 OnCompleteFrameCallback* frame_callback) { | |
29 return rtc::scoped_refptr<PacketBuffer>(new PacketBuffer(clock, | |
30 start_buffer_size, max_buffer_size, frame_callback)); | |
31 } | |
32 | |
24 PacketBuffer::PacketBuffer(Clock* clock, | 33 PacketBuffer::PacketBuffer(Clock* clock, |
25 size_t start_buffer_size, | 34 size_t start_buffer_size, |
26 size_t max_buffer_size, | 35 size_t max_buffer_size, |
27 OnCompleteFrameCallback* frame_callback) | 36 OnCompleteFrameCallback* frame_callback) |
28 : clock_(clock), | 37 : clock_(clock), |
29 size_(start_buffer_size), | 38 size_(start_buffer_size), |
30 max_size_(max_buffer_size), | 39 max_size_(max_buffer_size), |
31 first_seq_num_(0), | 40 first_seq_num_(0), |
32 last_seq_num_(0), | 41 last_seq_num_(0), |
33 first_packet_received_(false), | 42 first_packet_received_(false), |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 if (sequence_buffer_[start_index].frame_begin) | 171 if (sequence_buffer_[start_index].frame_begin) |
163 break; | 172 break; |
164 | 173 |
165 start_index = start_index > 0 ? start_index - 1 : size_ - 1; | 174 start_index = start_index > 0 ? start_index - 1 : size_ - 1; |
166 start_seq_num--; | 175 start_seq_num--; |
167 } | 176 } |
168 | 177 |
169 std::unique_ptr<RtpFrameObject> frame( | 178 std::unique_ptr<RtpFrameObject> frame( |
170 new RtpFrameObject(this, start_seq_num, seq_num, frame_size, | 179 new RtpFrameObject(this, start_seq_num, seq_num, frame_size, |
171 max_nack_count, clock_->TimeInMilliseconds())); | 180 max_nack_count, clock_->TimeInMilliseconds())); |
172 reference_finder_.ManageFrame(std::move(frame)); | 181 reference_finder_.ManageFrame(std::move(frame)); |
danilchap
2016/08/02 14:04:45
this look like a circular dependency:
{
auto buf
philipel
2016/08/02 14:39:59
You are right, the risk of having a stashed frame
| |
173 } | 182 } |
174 | 183 |
175 index = (index + 1) % size_; | 184 index = (index + 1) % size_; |
176 ++seq_num; | 185 ++seq_num; |
177 } | 186 } |
178 } | 187 } |
179 | 188 |
180 void PacketBuffer::ReturnFrame(RtpFrameObject* frame) { | 189 void PacketBuffer::ReturnFrame(RtpFrameObject* frame) { |
181 rtc::CritScope lock(&crit_); | 190 rtc::CritScope lock(&crit_); |
182 size_t index = frame->first_seq_num() % size_; | 191 size_t index = frame->first_seq_num() % size_; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 } | 241 } |
233 | 242 |
234 void PacketBuffer::Clear() { | 243 void PacketBuffer::Clear() { |
235 rtc::CritScope lock(&crit_); | 244 rtc::CritScope lock(&crit_); |
236 for (size_t i = 0; i < size_; ++i) | 245 for (size_t i = 0; i < size_; ++i) |
237 sequence_buffer_[i].used = false; | 246 sequence_buffer_[i].used = false; |
238 | 247 |
239 first_packet_received_ = false; | 248 first_packet_received_ = false; |
240 } | 249 } |
241 | 250 |
251 int PacketBuffer::AddRef() const { | |
252 return rtc::AtomicOps::Increment(&ref_count_); | |
253 } | |
254 | |
255 int PacketBuffer::Release() const { | |
256 int count = rtc::AtomicOps::Decrement(&ref_count_); | |
257 if (!count) { | |
258 delete this; | |
259 } | |
260 return count; | |
261 } | |
262 | |
242 } // namespace video_coding | 263 } // namespace video_coding |
243 } // namespace webrtc | 264 } // namespace webrtc |
OLD | NEW |