| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 : gof(gof), last_picture_id(last_picture_id) {} | 72 : gof(gof), last_picture_id(last_picture_id) {} |
| 73 GofInfoVP9* gof; | 73 GofInfoVP9* gof; |
| 74 uint16_t last_picture_id; | 74 uint16_t last_picture_id; |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 rtc::CriticalSection crit_; | 77 rtc::CriticalSection crit_; |
| 78 | 78 |
| 79 // Find the relevant group of pictures and update its "last-picture-id-with | 79 // Find the relevant group of pictures and update its "last-picture-id-with |
| 80 // padding" sequence number. | 80 // padding" sequence number. |
| 81 void UpdateLastPictureIdWithPadding(uint16_t seq_num) | 81 void UpdateLastPictureIdWithPadding(uint16_t seq_num) |
| 82 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 82 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 83 | 83 |
| 84 // Retry stashed frames until no more complete frames are found. | 84 // Retry stashed frames until no more complete frames are found. |
| 85 void RetryStashedFrames() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 85 void RetryStashedFrames() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 86 | 86 |
| 87 FrameDecision ManageFrameInternal(RtpFrameObject* frame) | 87 FrameDecision ManageFrameInternal(RtpFrameObject* frame) |
| 88 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 88 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 89 | 89 |
| 90 // Find references for generic frames. If |picture_id| is unspecified | 90 // Find references for generic frames. If |picture_id| is unspecified |
| 91 // then packet sequence numbers will be used to determine the references | 91 // then packet sequence numbers will be used to determine the references |
| 92 // of the frames. | 92 // of the frames. |
| 93 FrameDecision ManageFrameGeneric(RtpFrameObject* frame, int picture_id) | 93 FrameDecision ManageFrameGeneric(RtpFrameObject* frame, int picture_id) |
| 94 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 94 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 95 | 95 |
| 96 // Find references for Vp8 frames | 96 // Find references for Vp8 frames |
| 97 FrameDecision ManageFrameVp8(RtpFrameObject* frame) | 97 FrameDecision ManageFrameVp8(RtpFrameObject* frame) |
| 98 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 98 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 99 | 99 |
| 100 // Updates necessary layer info state used to determine frame references for | 100 // Updates necessary layer info state used to determine frame references for |
| 101 // Vp8. | 101 // Vp8. |
| 102 void UpdateLayerInfoVp8(RtpFrameObject* frame) | 102 void UpdateLayerInfoVp8(RtpFrameObject* frame) |
| 103 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 103 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 104 | 104 |
| 105 // Find references for Vp9 frames | 105 // Find references for Vp9 frames |
| 106 FrameDecision ManageFrameVp9(RtpFrameObject* frame) | 106 FrameDecision ManageFrameVp9(RtpFrameObject* frame) |
| 107 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 107 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 108 | 108 |
| 109 // Check if we are missing a frame necessary to determine the references | 109 // Check if we are missing a frame necessary to determine the references |
| 110 // for this frame. | 110 // for this frame. |
| 111 bool MissingRequiredFrameVp9(uint16_t picture_id, const GofInfo& info) | 111 bool MissingRequiredFrameVp9(uint16_t picture_id, const GofInfo& info) |
| 112 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 112 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 113 | 113 |
| 114 // Updates which frames that have been received. If there is a gap, | 114 // Updates which frames that have been received. If there is a gap, |
| 115 // missing frames will be added to |missing_frames_for_layer_| or | 115 // missing frames will be added to |missing_frames_for_layer_| or |
| 116 // if this is an already missing frame then it will be removed. | 116 // if this is an already missing frame then it will be removed. |
| 117 void FrameReceivedVp9(uint16_t picture_id, GofInfo* info) | 117 void FrameReceivedVp9(uint16_t picture_id, GofInfo* info) |
| 118 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 118 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 119 | 119 |
| 120 // Check if there is a frame with the up-switch flag set in the interval | 120 // Check if there is a frame with the up-switch flag set in the interval |
| 121 // (|pid_ref|, |picture_id|) with temporal layer smaller than |temporal_idx|. | 121 // (|pid_ref|, |picture_id|) with temporal layer smaller than |temporal_idx|. |
| 122 bool UpSwitchInIntervalVp9(uint16_t picture_id, | 122 bool UpSwitchInIntervalVp9(uint16_t picture_id, |
| 123 uint8_t temporal_idx, | 123 uint8_t temporal_idx, |
| 124 uint16_t pid_ref) EXCLUSIVE_LOCKS_REQUIRED(crit_); | 124 uint16_t pid_ref) |
| 125 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 125 | 126 |
| 126 // Unwrap |frame|s picture id and its references to 16 bits. | 127 // Unwrap |frame|s picture id and its references to 16 bits. |
| 127 void UnwrapPictureIds(RtpFrameObject* frame) EXCLUSIVE_LOCKS_REQUIRED(crit_); | 128 void UnwrapPictureIds(RtpFrameObject* frame) |
| 129 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 128 | 130 |
| 129 // Returns true if the frame is old and should be dropped. | 131 // Returns true if the frame is old and should be dropped. |
| 130 // TODO(philipel): Remove when VP9 PID/TL0 does not jump mid-stream (should be | 132 // TODO(philipel): Remove when VP9 PID/TL0 does not jump mid-stream (should be |
| 131 // around M59). | 133 // around M59). |
| 132 bool Vp9PidTl0Fix(const RtpFrameObject& frame, | 134 bool Vp9PidTl0Fix(const RtpFrameObject& frame, |
| 133 int16_t* picture_id, | 135 int16_t* picture_id, |
| 134 int16_t* tl0_pic_idx) EXCLUSIVE_LOCKS_REQUIRED(crit_); | 136 int16_t* tl0_pic_idx) RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 135 | 137 |
| 136 // TODO(philipel): Remove when VP9 PID/TL0 does not jump mid-stream (should be | 138 // TODO(philipel): Remove when VP9 PID/TL0 does not jump mid-stream (should be |
| 137 // around M59). | 139 // around M59). |
| 138 bool DetectVp9PicIdJump(int fixed_pid, | 140 bool DetectVp9PicIdJump(int fixed_pid, |
| 139 int fixed_tl0, | 141 int fixed_tl0, |
| 140 uint32_t timestamp) const | 142 uint32_t timestamp) const |
| 141 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 143 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 142 | 144 |
| 143 // TODO(philipel): Remove when VP9 PID/TL0 does not jump mid-stream (should be | 145 // TODO(philipel): Remove when VP9 PID/TL0 does not jump mid-stream (should be |
| 144 // around M59). | 146 // around M59). |
| 145 bool DetectVp9Tl0PicIdxJump(int fixed_tl0, uint32_t timestamp) const | 147 bool DetectVp9Tl0PicIdxJump(int fixed_tl0, uint32_t timestamp) const |
| 146 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 148 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 147 | 149 |
| 148 // For every group of pictures, hold two sequence numbers. The first being | 150 // For every group of pictures, hold two sequence numbers. The first being |
| 149 // the sequence number of the last packet of the last completed frame, and | 151 // the sequence number of the last packet of the last completed frame, and |
| 150 // the second being the sequence number of the last packet of the last | 152 // the second being the sequence number of the last packet of the last |
| 151 // completed frame advanced by any potential continuous packets of padding. | 153 // completed frame advanced by any potential continuous packets of padding. |
| 152 std::map<uint16_t, | 154 std::map<uint16_t, |
| 153 std::pair<uint16_t, uint16_t>, | 155 std::pair<uint16_t, uint16_t>, |
| 154 DescendingSeqNumComp<uint16_t>> | 156 DescendingSeqNumComp<uint16_t>> |
| 155 last_seq_num_gop_ GUARDED_BY(crit_); | 157 last_seq_num_gop_ RTC_GUARDED_BY(crit_); |
| 156 | 158 |
| 157 // Save the last picture id in order to detect when there is a gap in frames | 159 // Save the last picture id in order to detect when there is a gap in frames |
| 158 // that have not yet been fully received. | 160 // that have not yet been fully received. |
| 159 int last_picture_id_ GUARDED_BY(crit_); | 161 int last_picture_id_ RTC_GUARDED_BY(crit_); |
| 160 | 162 |
| 161 // Padding packets that have been received but that are not yet continuous | 163 // Padding packets that have been received but that are not yet continuous |
| 162 // with any group of pictures. | 164 // with any group of pictures. |
| 163 std::set<uint16_t, DescendingSeqNumComp<uint16_t>> stashed_padding_ | 165 std::set<uint16_t, DescendingSeqNumComp<uint16_t>> stashed_padding_ |
| 164 GUARDED_BY(crit_); | 166 RTC_GUARDED_BY(crit_); |
| 165 | 167 |
| 166 // The last unwrapped picture id. Used to unwrap the picture id from a length | 168 // The last unwrapped picture id. Used to unwrap the picture id from a length |
| 167 // of |kPicIdLength| to 16 bits. | 169 // of |kPicIdLength| to 16 bits. |
| 168 int last_unwrap_ GUARDED_BY(crit_); | 170 int last_unwrap_ RTC_GUARDED_BY(crit_); |
| 169 | 171 |
| 170 // Frames earlier than the last received frame that have not yet been | 172 // Frames earlier than the last received frame that have not yet been |
| 171 // fully received. | 173 // fully received. |
| 172 std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>> | 174 std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>> |
| 173 not_yet_received_frames_ GUARDED_BY(crit_); | 175 not_yet_received_frames_ RTC_GUARDED_BY(crit_); |
| 174 | 176 |
| 175 // Frames that have been fully received but didn't have all the information | 177 // Frames that have been fully received but didn't have all the information |
| 176 // needed to determine their references. | 178 // needed to determine their references. |
| 177 std::deque<std::unique_ptr<RtpFrameObject>> stashed_frames_ GUARDED_BY(crit_); | 179 std::deque<std::unique_ptr<RtpFrameObject>> stashed_frames_ |
| 180 RTC_GUARDED_BY(crit_); |
| 178 | 181 |
| 179 // Holds the information about the last completed frame for a given temporal | 182 // Holds the information about the last completed frame for a given temporal |
| 180 // layer given a Tl0 picture index. | 183 // layer given a Tl0 picture index. |
| 181 std::map<uint8_t, | 184 std::map<uint8_t, |
| 182 std::array<int16_t, kMaxTemporalLayers>, | 185 std::array<int16_t, kMaxTemporalLayers>, |
| 183 DescendingSeqNumComp<uint8_t>> | 186 DescendingSeqNumComp<uint8_t>> |
| 184 layer_info_ GUARDED_BY(crit_); | 187 layer_info_ RTC_GUARDED_BY(crit_); |
| 185 | 188 |
| 186 // Where the current scalability structure is in the | 189 // Where the current scalability structure is in the |
| 187 // |scalability_structures_| array. | 190 // |scalability_structures_| array. |
| 188 uint8_t current_ss_idx_; | 191 uint8_t current_ss_idx_; |
| 189 | 192 |
| 190 // Holds received scalability structures. | 193 // Holds received scalability structures. |
| 191 std::array<GofInfoVP9, kMaxGofSaved> scalability_structures_ | 194 std::array<GofInfoVP9, kMaxGofSaved> scalability_structures_ |
| 192 GUARDED_BY(crit_); | 195 RTC_GUARDED_BY(crit_); |
| 193 | 196 |
| 194 // Holds the the Gof information for a given TL0 picture index. | 197 // Holds the the Gof information for a given TL0 picture index. |
| 195 std::map<uint8_t, GofInfo, DescendingSeqNumComp<uint8_t>> gof_info_ | 198 std::map<uint8_t, GofInfo, DescendingSeqNumComp<uint8_t>> gof_info_ |
| 196 GUARDED_BY(crit_); | 199 RTC_GUARDED_BY(crit_); |
| 197 | 200 |
| 198 // Keep track of which picture id and which temporal layer that had the | 201 // Keep track of which picture id and which temporal layer that had the |
| 199 // up switch flag set. | 202 // up switch flag set. |
| 200 std::map<uint16_t, uint8_t, DescendingSeqNumComp<uint16_t, kPicIdLength>> | 203 std::map<uint16_t, uint8_t, DescendingSeqNumComp<uint16_t, kPicIdLength>> |
| 201 up_switch_ GUARDED_BY(crit_); | 204 up_switch_ RTC_GUARDED_BY(crit_); |
| 202 | 205 |
| 203 // For every temporal layer, keep a set of which frames that are missing. | 206 // For every temporal layer, keep a set of which frames that are missing. |
| 204 std::array<std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>>, | 207 std::array<std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>>, |
| 205 kMaxTemporalLayers> | 208 kMaxTemporalLayers> |
| 206 missing_frames_for_layer_ GUARDED_BY(crit_); | 209 missing_frames_for_layer_ RTC_GUARDED_BY(crit_); |
| 207 | 210 |
| 208 // How far frames have been cleared by sequence number. A frame will be | 211 // How far frames have been cleared by sequence number. A frame will be |
| 209 // cleared if it contains a packet with a sequence number older than | 212 // cleared if it contains a packet with a sequence number older than |
| 210 // |cleared_to_seq_num_|. | 213 // |cleared_to_seq_num_|. |
| 211 int cleared_to_seq_num_ GUARDED_BY(crit_); | 214 int cleared_to_seq_num_ RTC_GUARDED_BY(crit_); |
| 212 | 215 |
| 213 OnCompleteFrameCallback* frame_callback_; | 216 OnCompleteFrameCallback* frame_callback_; |
| 214 | 217 |
| 215 // Unwrapper used to unwrap generic RTP streams. In a generic stream we derive | 218 // Unwrapper used to unwrap generic RTP streams. In a generic stream we derive |
| 216 // a picture id from the packet sequence number. | 219 // a picture id from the packet sequence number. |
| 217 SeqNumUnwrapper<uint16_t> generic_unwrapper_ GUARDED_BY(crit_); | 220 SeqNumUnwrapper<uint16_t> generic_unwrapper_ RTC_GUARDED_BY(crit_); |
| 218 | 221 |
| 219 // Unwrapper used to unwrap VP8/VP9 streams which have their picture id | 222 // Unwrapper used to unwrap VP8/VP9 streams which have their picture id |
| 220 // specified. | 223 // specified. |
| 221 SeqNumUnwrapper<uint16_t, kPicIdLength> unwrapper_ GUARDED_BY(crit_); | 224 SeqNumUnwrapper<uint16_t, kPicIdLength> unwrapper_ RTC_GUARDED_BY(crit_); |
| 222 }; | 225 }; |
| 223 | 226 |
| 224 } // namespace video_coding | 227 } // namespace video_coding |
| 225 } // namespace webrtc | 228 } // namespace webrtc |
| 226 | 229 |
| 227 #endif // WEBRTC_MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_ | 230 #endif // WEBRTC_MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_ |
| OLD | NEW |