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_RTP_FRAME_REFERENCE_FINDER_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_ |
12 #define WEBRTC_MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_ |
13 | 13 |
14 #include <array> | 14 #include <array> |
15 #include <map> | 15 #include <map> |
16 #include <memory> | 16 #include <memory> |
17 #include <queue> | 17 #include <deque> |
18 #include <set> | 18 #include <set> |
19 #include <utility> | 19 #include <utility> |
20 | 20 |
21 #include "webrtc/base/criticalsection.h" | 21 #include "webrtc/base/criticalsection.h" |
22 #include "webrtc/base/thread_annotations.h" | 22 #include "webrtc/base/thread_annotations.h" |
23 #include "webrtc/modules/include/module_common_types.h" | 23 #include "webrtc/modules/include/module_common_types.h" |
24 #include "webrtc/modules/video_coding/sequence_number_util.h" | 24 #include "webrtc/modules/video_coding/sequence_number_util.h" |
25 | 25 |
26 namespace webrtc { | 26 namespace webrtc { |
27 namespace video_coding { | 27 namespace video_coding { |
28 | 28 |
29 class FrameObject; | 29 class FrameObject; |
30 class RtpFrameObject; | 30 class RtpFrameObject; |
31 | 31 |
32 // A complete frame is a frame which has received all its packets and all its | 32 // A complete frame is a frame which has received all its packets and all its |
33 // references are known. | 33 // references are known. |
34 class OnCompleteFrameCallback { | 34 class OnCompleteFrameCallback { |
35 public: | 35 public: |
36 virtual ~OnCompleteFrameCallback() {} | 36 virtual ~OnCompleteFrameCallback() {} |
37 virtual void OnCompleteFrame(std::unique_ptr<FrameObject> frame) = 0; | 37 virtual void OnCompleteFrame(std::unique_ptr<FrameObject> frame) = 0; |
38 }; | 38 }; |
39 | 39 |
40 class RtpFrameReferenceFinder { | 40 class RtpFrameReferenceFinder { |
41 public: | 41 public: |
42 explicit RtpFrameReferenceFinder(OnCompleteFrameCallback* frame_callback); | 42 explicit RtpFrameReferenceFinder(OnCompleteFrameCallback* frame_callback); |
| 43 |
| 44 // Manage this frame until: |
| 45 // - We have all information needed to determine its references, after |
| 46 // which |frame_callback_| is called with the completed frame, or |
| 47 // - We have too many stashed frames (determined by |kMaxStashedFrames) |
| 48 // so we drop this frame, or |
| 49 // - It gets cleared by ClearTo, which also means we drop it. |
43 void ManageFrame(std::unique_ptr<RtpFrameObject> frame); | 50 void ManageFrame(std::unique_ptr<RtpFrameObject> frame); |
| 51 |
| 52 // Notifies that padding has been received, which the reference finder |
| 53 // might need to calculate the references of a frame. |
44 void PaddingReceived(uint16_t seq_num); | 54 void PaddingReceived(uint16_t seq_num); |
45 | 55 |
| 56 // Clear all stashed frames that include packets older than |seq_num|. |
| 57 void ClearTo(uint16_t seq_num); |
| 58 |
46 private: | 59 private: |
47 static const uint16_t kPicIdLength = 1 << 7; | 60 static const uint16_t kPicIdLength = 1 << 7; |
48 static const uint8_t kMaxTemporalLayers = 5; | 61 static const uint8_t kMaxTemporalLayers = 5; |
49 static const int kMaxLayerInfo = 10; | 62 static const int kMaxLayerInfo = 10; |
50 static const int kMaxStashedFrames = 10; | 63 static const int kMaxStashedFrames = 10; |
51 static const int kMaxNotYetReceivedFrames = 20; | 64 static const int kMaxNotYetReceivedFrames = 20; |
52 static const int kMaxGofSaved = 15; | 65 static const int kMaxGofSaved = 15; |
53 static const int kMaxPaddingAge = 100; | 66 static const int kMaxPaddingAge = 100; |
54 | 67 |
55 | 68 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // of |kPicIdLength| to 16 bits. | 152 // of |kPicIdLength| to 16 bits. |
140 int last_unwrap_ GUARDED_BY(crit_); | 153 int last_unwrap_ GUARDED_BY(crit_); |
141 | 154 |
142 // Frames earlier than the last received frame that have not yet been | 155 // Frames earlier than the last received frame that have not yet been |
143 // fully received. | 156 // fully received. |
144 std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>> | 157 std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>> |
145 not_yet_received_frames_ GUARDED_BY(crit_); | 158 not_yet_received_frames_ GUARDED_BY(crit_); |
146 | 159 |
147 // Frames that have been fully received but didn't have all the information | 160 // Frames that have been fully received but didn't have all the information |
148 // needed to determine their references. | 161 // needed to determine their references. |
149 std::queue<std::unique_ptr<RtpFrameObject>> stashed_frames_ GUARDED_BY(crit_); | 162 std::deque<std::unique_ptr<RtpFrameObject>> stashed_frames_ GUARDED_BY(crit_); |
150 | 163 |
151 // Holds the information about the last completed frame for a given temporal | 164 // Holds the information about the last completed frame for a given temporal |
152 // layer given a Tl0 picture index. | 165 // layer given a Tl0 picture index. |
153 std::map<uint8_t, | 166 std::map<uint8_t, |
154 std::array<int16_t, kMaxTemporalLayers>, | 167 std::array<int16_t, kMaxTemporalLayers>, |
155 DescendingSeqNumComp<uint8_t>> | 168 DescendingSeqNumComp<uint8_t>> |
156 layer_info_ GUARDED_BY(crit_); | 169 layer_info_ GUARDED_BY(crit_); |
157 | 170 |
158 // Where the current scalability structure is in the | 171 // Where the current scalability structure is in the |
159 // |scalability_structures_| array. | 172 // |scalability_structures_| array. |
(...skipping 10 matching lines...) Expand all Loading... |
170 // Keep track of which picture id and which temporal layer that had the | 183 // Keep track of which picture id and which temporal layer that had the |
171 // up switch flag set. | 184 // up switch flag set. |
172 std::map<uint16_t, uint8_t, DescendingSeqNumComp<uint16_t, kPicIdLength>> | 185 std::map<uint16_t, uint8_t, DescendingSeqNumComp<uint16_t, kPicIdLength>> |
173 up_switch_ GUARDED_BY(crit_); | 186 up_switch_ GUARDED_BY(crit_); |
174 | 187 |
175 // For every temporal layer, keep a set of which frames that are missing. | 188 // For every temporal layer, keep a set of which frames that are missing. |
176 std::array<std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>>, | 189 std::array<std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>>, |
177 kMaxTemporalLayers> | 190 kMaxTemporalLayers> |
178 missing_frames_for_layer_ GUARDED_BY(crit_); | 191 missing_frames_for_layer_ GUARDED_BY(crit_); |
179 | 192 |
| 193 // How far frames have been cleared by sequence number. A frame will be |
| 194 // cleared if it contains a packet with a sequence number older than |
| 195 // |cleared_to_seq_num_|. |
| 196 int cleared_to_seq_num_ GUARDED_BY(crit_); |
| 197 |
180 OnCompleteFrameCallback* frame_callback_; | 198 OnCompleteFrameCallback* frame_callback_; |
181 }; | 199 }; |
182 | 200 |
183 } // namespace video_coding | 201 } // namespace video_coding |
184 } // namespace webrtc | 202 } // namespace webrtc |
185 | 203 |
186 #endif // WEBRTC_MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_ | 204 #endif // WEBRTC_MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_ |
OLD | NEW |