Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: webrtc/modules/video_coding/rtp_frame_reference_finder.h

Issue 1961053002: Logic for finding frame references moved from PacketBuffer to new class (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Includes in order. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_RTP_FRAME_REFERENCE_FINDER_H_
12 #define WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_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>
17 #include <queue> 16 #include <queue>
18 #include <set> 17 #include <set>
19 #include <utility> 18 #include <utility>
20 #include <vector>
21 19
22 #include "webrtc/base/criticalsection.h" 20 #include "webrtc/base/criticalsection.h"
23 #include "webrtc/base/scoped_ptr.h" 21 #include "webrtc/base/scoped_ptr.h"
24 #include "webrtc/base/thread_annotations.h" 22 #include "webrtc/base/thread_annotations.h"
25 #include "webrtc/modules/include/module_common_types.h" 23 #include "webrtc/modules/include/module_common_types.h"
26 #include "webrtc/modules/video_coding/packet.h"
27 #include "webrtc/modules/video_coding/sequence_number_util.h" 24 #include "webrtc/modules/video_coding/sequence_number_util.h"
28 25
29 namespace webrtc { 26 namespace webrtc {
30 namespace video_coding { 27 namespace video_coding {
31 28
32 class FrameObject;
33 class RtpFrameObject; 29 class RtpFrameObject;
30 class OnCompleteFrameCallback;
34 31
35 class OnCompleteFrameCallback { 32 class RtpFrameReferenceFinder {
36 public: 33 public:
37 virtual ~OnCompleteFrameCallback() {} 34 explicit RtpFrameReferenceFinder(OnCompleteFrameCallback* frame_callback);
38 virtual void OnCompleteFrame(std::unique_ptr<FrameObject> frame) = 0; 35 void ManageFrame(std::unique_ptr<RtpFrameObject> frame);
39 };
40
41 class PacketBuffer {
42 public:
43 // Both |start_buffer_size| and |max_buffer_size| must be a power of 2.
44 PacketBuffer(size_t start_buffer_size,
45 size_t max_buffer_size,
46 OnCompleteFrameCallback* frame_callback);
47
48 bool InsertPacket(const VCMPacket& packet);
49 void ClearTo(uint16_t seq_num);
50 void Flush();
51 36
52 private: 37 private:
53 static const uint16_t kPicIdLength = 1 << 7; 38 static const uint16_t kPicIdLength = 1 << 7;
54 static const uint8_t kMaxTemporalLayers = 5; 39 static const uint8_t kMaxTemporalLayers = 5;
40 static const int kMaxLayerInfo = 10;
55 static const int kMaxStashedFrames = 10; 41 static const int kMaxStashedFrames = 10;
56 static const int kMaxLayerInfo = 10;
57 static const int kMaxNotYetReceivedFrames = 20; 42 static const int kMaxNotYetReceivedFrames = 20;
58 static const int kMaxGofSaved = 15; 43 static const int kMaxGofSaved = 15;
59 44
60 friend RtpFrameObject; 45 rtc::CriticalSection crit_;
61 // Since we want the packet buffer to be as packet type agnostic
62 // as possible we extract only the information needed in order
63 // to determine whether a sequence of packets is continuous or not.
64 struct ContinuityInfo {
65 // The sequence number of the packet.
66 uint16_t seq_num = 0;
67
68 // If this is the first packet of the frame.
69 bool frame_begin = false;
70
71 // If this is the last packet of the frame.
72 bool frame_end = false;
73
74 // If this slot is currently used.
75 bool used = false;
76
77 // If all its previous packets have been inserted into the packet buffer.
78 bool continuous = false;
79
80 // If this packet has been used to create a frame already.
81 bool frame_created = false;
82 };
83
84 // Expand the buffer.
85 bool ExpandBufferSize() EXCLUSIVE_LOCKS_REQUIRED(crit_);
86
87 // Test if all previous packets has arrived for the given sequence number.
88 bool IsContinuous(uint16_t seq_num) const EXCLUSIVE_LOCKS_REQUIRED(crit_);
89
90 // Test if all packets of a frame has arrived, and if so, creates a frame.
91 // May create multiple frames per invocation.
92 void FindFrames(uint16_t seq_num) EXCLUSIVE_LOCKS_REQUIRED(crit_);
93
94 // Copy the bitstream for |frame| to |destination|.
95 bool GetBitstream(const RtpFrameObject& frame, uint8_t* destination);
96
97 // Mark all slots used by |frame| as not used.
98 void ReturnFrame(RtpFrameObject* frame);
99
100 // Find the references for this frame.
101 void ManageFrame(std::unique_ptr<RtpFrameObject> frame)
102 EXCLUSIVE_LOCKS_REQUIRED(crit_);
103 46
104 // Retry finding references for all frames that previously didn't have 47 // Retry finding references for all frames that previously didn't have
105 // all information needed. 48 // all information needed.
106 void RetryStashedFrames() EXCLUSIVE_LOCKS_REQUIRED(crit_); 49 void RetryStashedFrames() EXCLUSIVE_LOCKS_REQUIRED(crit_);
107 50
108 // Find references for generic frames. 51 // Find references for generic frames.
109 void ManageFrameGeneric(std::unique_ptr<RtpFrameObject> frame) 52 void ManageFrameGeneric(std::unique_ptr<RtpFrameObject> frame)
110 EXCLUSIVE_LOCKS_REQUIRED(crit_); 53 EXCLUSIVE_LOCKS_REQUIRED(crit_);
111 54
112 // Find references for Vp8 frames 55 // Find references for Vp8 frames
(...skipping 26 matching lines...) Expand all
139 void FrameReceivedVp9(uint16_t picture_id, const GofInfoVP9& gof) 82 void FrameReceivedVp9(uint16_t picture_id, const GofInfoVP9& gof)
140 EXCLUSIVE_LOCKS_REQUIRED(crit_); 83 EXCLUSIVE_LOCKS_REQUIRED(crit_);
141 84
142 // Check if there is a frame with the up-switch flag set in the interval 85 // 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|. 86 // (|pid_ref|, |picture_id|) with temporal layer smaller than |temporal_idx|.
144 bool UpSwitchInIntervalVp9(uint16_t picture_id, 87 bool UpSwitchInIntervalVp9(uint16_t picture_id,
145 uint8_t temporal_idx, 88 uint8_t temporal_idx,
146 uint16_t pid_ref) EXCLUSIVE_LOCKS_REQUIRED(crit_); 89 uint16_t pid_ref) EXCLUSIVE_LOCKS_REQUIRED(crit_);
147 90
148 // All picture ids are unwrapped to 16 bits. 91 // All picture ids are unwrapped to 16 bits.
149 uint16_t UnwrapPictureId(uint16_t picture_id) 92 uint16_t UnwrapPictureId(uint16_t picture_id) EXCLUSIVE_LOCKS_REQUIRED(crit_);
150 EXCLUSIVE_LOCKS_REQUIRED(crit_);
151
152 rtc::CriticalSection crit_;
153
154 // Buffer size_ and max_size_ must always be a power of two.
155 size_t size_ GUARDED_BY(crit_);
156 const size_t max_size_;
157
158 // The fist sequence number currently in the buffer.
159 uint16_t first_seq_num_ GUARDED_BY(crit_);
160
161 // The last sequence number currently in the buffer.
162 uint16_t last_seq_num_ GUARDED_BY(crit_);
163
164 // If the packet buffer has received its first packet.
165 bool first_packet_received_ GUARDED_BY(crit_);
166
167 // Buffer that holds the inserted packets.
168 std::vector<VCMPacket> data_buffer_ GUARDED_BY(crit_);
169
170 // Buffer that holds the information about which slot that is currently in use
171 // and information needed to determine the continuity between packets.
172 std::vector<ContinuityInfo> sequence_buffer_ GUARDED_BY(crit_);
173
174 // The callback that is called when a frame has been created and all its
175 // references has been found.
176 OnCompleteFrameCallback* const frame_callback_;
177 93
178 // Holds the last sequence number of the last frame that has been created 94 // Holds the last sequence number of the last frame that has been created
179 // given the last sequence number of a given keyframe. 95 // given the last sequence number of a given keyframe.
180 std::map<uint16_t, uint16_t, DescendingSeqNumComp<uint16_t>> 96 std::map<uint16_t, uint16_t, DescendingSeqNumComp<uint16_t>> last_seq_num_gop_
181 last_seq_num_gop_ GUARDED_BY(crit_); 97 GUARDED_BY(crit_);
182 98
183 // Save the last picture id in order to detect when there is a gap in frames 99 // Save the last picture id in order to detect when there is a gap in frames
184 // that have not yet been fully received. 100 // that have not yet been fully received.
185 int last_picture_id_ GUARDED_BY(crit_); 101 int last_picture_id_ GUARDED_BY(crit_);
186 102
187 // The last unwrapped picture id. Used to unwrap the picture id from a length 103 // The last unwrapped picture id. Used to unwrap the picture id from a length
188 // of |kPicIdLength| to 16 bits. 104 // of |kPicIdLength| to 16 bits.
189 int last_unwrap_ GUARDED_BY(crit_); 105 int last_unwrap_ GUARDED_BY(crit_);
190 106
191 // Frames earlier than the last received frame that have not yet been 107 // Frames earlier than the last received frame that have not yet been
(...skipping 27 matching lines...) Expand all
219 gof_info_ GUARDED_BY(crit_); 135 gof_info_ GUARDED_BY(crit_);
220 136
221 // Keep track of which picture id and which temporal layer that had the 137 // Keep track of which picture id and which temporal layer that had the
222 // up switch flag set. 138 // up switch flag set.
223 std::map<uint16_t, uint8_t> up_switch_ GUARDED_BY(crit_); 139 std::map<uint16_t, uint8_t> up_switch_ GUARDED_BY(crit_);
224 140
225 // For every temporal layer, keep a set of which frames that are missing. 141 // For every temporal layer, keep a set of which frames that are missing.
226 std::array<std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>>, 142 std::array<std::set<uint16_t, DescendingSeqNumComp<uint16_t, kPicIdLength>>,
227 kMaxTemporalLayers> 143 kMaxTemporalLayers>
228 missing_frames_for_layer_ GUARDED_BY(crit_); 144 missing_frames_for_layer_ GUARDED_BY(crit_);
145
146 OnCompleteFrameCallback* frame_callback_;
229 }; 147 };
230 148
231 } // namespace video_coding 149 } // namespace video_coding
232 } // namespace webrtc 150 } // namespace webrtc
233 151
234 #endif // WEBRTC_MODULES_VIDEO_CODING_PACKET_BUFFER_H_ 152 #endif // WEBRTC_MODULES_VIDEO_CODING_RTP_FRAME_REFERENCE_FINDER_H_
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/packet_buffer_unittest.cc ('k') | webrtc/modules/video_coding/rtp_frame_reference_finder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698