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