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 #ifndef WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ |
12 #define WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ |
13 | 13 |
14 #include <array> | 14 #include <array> |
15 #include <utility> | |
mflodman
2016/05/06 13:09:44
Alphabetic order.
| |
15 #include <vector> | 16 #include <vector> |
16 #include <map> | 17 #include <map> |
17 #include <memory> | 18 #include <memory> |
18 #include <set> | 19 #include <set> |
19 #include <queue> | 20 #include <queue> |
20 | 21 |
21 #include "webrtc/base/criticalsection.h" | 22 #include "webrtc/base/criticalsection.h" |
22 #include "webrtc/base/scoped_ptr.h" | 23 #include "webrtc/base/scoped_ptr.h" |
23 #include "webrtc/base/thread_annotations.h" | 24 #include "webrtc/base/thread_annotations.h" |
25 #include "webrtc/modules/include/module_common_types.h" | |
24 #include "webrtc/modules/video_coding/packet.h" | 26 #include "webrtc/modules/video_coding/packet.h" |
25 #include "webrtc/modules/video_coding/sequence_number_util.h" | 27 #include "webrtc/modules/video_coding/sequence_number_util.h" |
26 | 28 |
27 namespace webrtc { | 29 namespace webrtc { |
28 namespace video_coding { | 30 namespace video_coding { |
29 | 31 |
30 class FrameObject; | 32 class FrameObject; |
31 class RtpFrameObject; | 33 class RtpFrameObject; |
32 | 34 |
33 class OnCompleteFrameCallback { | 35 class OnCompleteFrameCallback { |
34 public: | 36 public: |
35 virtual ~OnCompleteFrameCallback() {} | 37 virtual ~OnCompleteFrameCallback() {} |
36 virtual void OnCompleteFrame(std::unique_ptr<FrameObject> frame) = 0; | 38 virtual void OnCompleteFrame(std::unique_ptr<FrameObject> frame) = 0; |
37 }; | 39 }; |
38 | 40 |
39 class PacketBuffer { | 41 class PacketBuffer { |
40 public: | 42 public: |
41 // Both |start_buffer_size| and |max_buffer_size| must be a power of 2. | 43 // Both |start_buffer_size| and |max_buffer_size| must be a power of 2. |
42 PacketBuffer(size_t start_buffer_size, | 44 PacketBuffer(size_t start_buffer_size, |
43 size_t max_buffer_size, | 45 size_t max_buffer_size, |
44 OnCompleteFrameCallback* frame_callback); | 46 OnCompleteFrameCallback* frame_callback); |
45 | 47 |
46 bool InsertPacket(const VCMPacket& packet); | 48 bool InsertPacket(const VCMPacket& packet); |
47 void ClearTo(uint16_t seq_num); | 49 void ClearTo(uint16_t seq_num); |
48 void Flush(); | 50 void Flush(); |
49 | 51 |
50 private: | 52 private: |
51 static const uint16_t kPicIdLength = 1 << 7; | 53 static const uint16_t kPicIdLength = 1 << 7; |
52 static const uint8_t kMaxTemporalLayer = 5; | 54 static const uint8_t kMaxTemporalLayers = 5; |
53 static const int kMaxStashedFrames = 10; | 55 static const int kMaxStashedFrames = 10; |
54 static const int kMaxLayerInfo = 10; | 56 static const int kMaxLayerInfo = 10; |
55 static const int kMaxNotYetReceivedFrames = 20; | 57 static const int kMaxNotYetReceivedFrames = 20; |
58 static const int kMaxGofSaved = 15; | |
56 | 59 |
57 friend RtpFrameObject; | 60 friend RtpFrameObject; |
58 // Since we want the packet buffer to be as packet type agnostic | 61 // Since we want the packet buffer to be as packet type agnostic |
59 // as possible we extract only the information needed in order | 62 // as possible we extract only the information needed in order |
60 // to determine whether a sequence of packets is continuous or not. | 63 // to determine whether a sequence of packets is continuous or not. |
61 struct ContinuityInfo { | 64 struct ContinuityInfo { |
62 // The sequence number of the packet. | 65 // The sequence number of the packet. |
63 uint16_t seq_num = 0; | 66 uint16_t seq_num = 0; |
64 | 67 |
65 // If this is the first packet of the frame. | 68 // If this is the first packet of the frame. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 // Find references for Vp8 frames | 112 // Find references for Vp8 frames |
110 void ManageFrameVp8(std::unique_ptr<RtpFrameObject> frame) | 113 void ManageFrameVp8(std::unique_ptr<RtpFrameObject> frame) |
111 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 114 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
112 | 115 |
113 // Updates all necessary state used to determine frame references | 116 // Updates all necessary state used to determine frame references |
114 // for Vp8 and then calls the |frame_callback| callback with the | 117 // for Vp8 and then calls the |frame_callback| callback with the |
115 // completed frame. | 118 // completed frame. |
116 void CompletedFrameVp8(std::unique_ptr<RtpFrameObject> frame) | 119 void CompletedFrameVp8(std::unique_ptr<RtpFrameObject> frame) |
117 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 120 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
118 | 121 |
122 // Find references for Vp9 frames | |
123 void ManageFrameVp9(std::unique_ptr<RtpFrameObject> frame) | |
124 EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
125 | |
126 // Unwrap the picture id and the frame references and then call the | |
127 // |frame_callback| callback with the completed frame. | |
128 void CompletedFrameVp9(std::unique_ptr<RtpFrameObject> frame) | |
129 EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
130 | |
131 // Check if we are missing a frame necessary to determine the references | |
132 // for this frame. | |
133 bool MissingRequiredFrameVp9(uint16_t picture_id, const GofInfoVP9& gof) | |
134 EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
135 | |
136 // Updates which frames that have been received. If there is a gap, | |
137 // missing frames will be added to |missing_frames_for_layer_| or | |
138 // if this is an already missing frame then it will be removed. | |
139 void FrameReceivedVp9(uint16_t picture_id, const GofInfoVP9& gof) | |
140 EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
141 | |
142 // Check if there is a frame with the up-switch flag set in the interval | |
143 // (|pid_ref|, |picture_id|) with temporal layer smaller than |temporal_idx|. | |
144 bool UpSwitchInIntervalVp9(uint16_t picture_id, | |
145 uint8_t temporal_idx, | |
146 uint16_t pid_ref) EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
147 | |
119 // All picture ids are unwrapped to 16 bits. | 148 // All picture ids are unwrapped to 16 bits. |
120 uint16_t UnwrapPictureId(uint16_t picture_id) | 149 uint16_t UnwrapPictureId(uint16_t picture_id) |
121 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 150 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
122 | 151 |
123 rtc::CriticalSection crit_; | 152 rtc::CriticalSection crit_; |
124 | 153 |
125 // Buffer size_ and max_size_ must always be a power of two. | 154 // Buffer size_ and max_size_ must always be a power of two. |
126 size_t size_ GUARDED_BY(crit_); | 155 size_t size_ GUARDED_BY(crit_); |
127 const size_t max_size_; | 156 const size_t max_size_; |
128 | 157 |
(...skipping 25 matching lines...) Expand all Loading... | |
154 // Save the last picture id in order to detect when there is a gap in frames | 183 // Save the last picture id in order to detect when there is a gap in frames |
155 // that have not yet been fully received. | 184 // that have not yet been fully received. |
156 int last_picture_id_ GUARDED_BY(crit_); | 185 int last_picture_id_ GUARDED_BY(crit_); |
157 | 186 |
158 // The last unwrapped picture id. Used to unwrap the picture id from a length | 187 // The last unwrapped picture id. Used to unwrap the picture id from a length |
159 // of |kPicIdLength| to 16 bits. | 188 // of |kPicIdLength| to 16 bits. |
160 int last_unwrap_ GUARDED_BY(crit_); | 189 int last_unwrap_ GUARDED_BY(crit_); |
161 | 190 |
162 // Frames earlier than the last received frame that have not yet been | 191 // Frames earlier than the last received frame that have not yet been |
163 // fully received. | 192 // fully received. |
164 std::set<uint8_t, DescendingSeqNumComp<uint8_t, kPicIdLength>> | 193 std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>> |
165 not_yet_received_frames_ GUARDED_BY(crit_); | 194 not_yet_received_frames_ GUARDED_BY(crit_); |
166 | 195 |
167 // Frames that have been fully received but didn't have all the information | 196 // Frames that have been fully received but didn't have all the information |
168 // needed to determine their references. | 197 // needed to determine their references. |
169 std::queue<std::unique_ptr<RtpFrameObject>> stashed_frames_ GUARDED_BY(crit_); | 198 std::queue<std::unique_ptr<RtpFrameObject>> stashed_frames_ GUARDED_BY(crit_); |
170 | 199 |
171 // Holds the information about the last completed frame for a given temporal | 200 // Holds the information about the last completed frame for a given temporal |
172 // layer given a Tl0 picture index. | 201 // layer given a Tl0 picture index. |
173 std::map<uint8_t, | 202 std::map<uint8_t, |
174 std::array<int16_t, kMaxTemporalLayer>, | 203 std::array<int16_t, kMaxTemporalLayers>, |
175 DescendingSeqNumComp<uint8_t>> layer_info_ GUARDED_BY(crit_); | 204 DescendingSeqNumComp<uint8_t>> |
205 layer_info_ GUARDED_BY(crit_); | |
206 | |
207 // Where the current scalability structure is in the | |
208 // |scalability_structures_| array. | |
209 uint8_t current_ss_idx_; | |
210 | |
211 // Holds received scalability structures. | |
212 std::array<GofInfoVP9, kMaxGofSaved> scalability_structures_ | |
213 GUARDED_BY(crit_); | |
214 | |
215 // Holds the picture id and the Gof information for a given TL0 picture index. | |
216 std::map<uint8_t, | |
217 std::pair<uint16_t, GofInfoVP9*>, | |
218 DescendingSeqNumComp<uint8_t>> | |
219 gof_info_ GUARDED_BY(crit_); | |
220 | |
221 // Keep track of which picture id and which temporal layer that had the | |
222 // up switch flag set. | |
223 std::map<uint16_t, uint8_t> up_switch_ GUARDED_BY(crit_); | |
224 | |
225 // For every temporal layer, keep a set of which frames that are missing. | |
226 std::array<std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>>, | |
227 kMaxTemporalLayers> | |
228 missing_frames_for_layer_ GUARDED_BY(crit_); | |
176 }; | 229 }; |
177 | 230 |
178 } // namespace video_coding | 231 } // namespace video_coding |
179 } // namespace webrtc | 232 } // namespace webrtc |
180 | 233 |
181 #endif // WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ | 234 #endif // WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ |
OLD | NEW |