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_FRAME_BUFFER2_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_FRAME_BUFFER2_H_ |
12 #define WEBRTC_MODULES_VIDEO_CODING_FRAME_BUFFER2_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_FRAME_BUFFER2_H_ |
13 | 13 |
14 #include <array> | 14 #include <array> |
15 #include <map> | 15 #include <map> |
16 #include <memory> | 16 #include <memory> |
17 #include <set> | |
18 #include <utility> | 17 #include <utility> |
19 | 18 |
20 #include "webrtc/base/constructormagic.h" | 19 #include "webrtc/base/constructormagic.h" |
21 #include "webrtc/base/criticalsection.h" | 20 #include "webrtc/base/criticalsection.h" |
22 #include "webrtc/base/event.h" | 21 #include "webrtc/base/event.h" |
23 #include "webrtc/base/thread_annotations.h" | 22 #include "webrtc/base/thread_annotations.h" |
23 #include "webrtc/modules/video_coding/frame_object.h" | |
24 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 24 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
25 #include "webrtc/modules/video_coding/inter_frame_delay.h" | 25 #include "webrtc/modules/video_coding/inter_frame_delay.h" |
26 #include "webrtc/modules/video_coding/sequence_number_util.h" | |
26 | 27 |
27 namespace webrtc { | 28 namespace webrtc { |
28 | 29 |
29 class Clock; | 30 class Clock; |
30 class VCMJitterEstimator; | 31 class VCMJitterEstimator; |
31 class VCMTiming; | 32 class VCMTiming; |
32 | 33 |
33 namespace video_coding { | 34 namespace video_coding { |
34 | 35 |
35 class FrameObject; | |
36 | |
37 class FrameBuffer { | 36 class FrameBuffer { |
38 public: | 37 public: |
39 enum ReturnReason { kFrameFound, kTimeout, kStopped }; | 38 enum ReturnReason { kFrameFound, kTimeout, kStopped }; |
40 | 39 |
41 FrameBuffer(Clock* clock, | 40 FrameBuffer(Clock* clock, |
42 VCMJitterEstimator* jitter_estimator, | 41 VCMJitterEstimator* jitter_estimator, |
43 VCMTiming* timing); | 42 VCMTiming* timing); |
44 | 43 |
45 // Insert a frame into the frame buffer. | 44 // Insert a frame into the frame buffer. Returns the picture id |
46 void InsertFrame(std::unique_ptr<FrameObject> frame); | 45 // of the last continuous frame or -1 if there is no continuous frame. |
46 int InsertFrame(std::unique_ptr<FrameObject> frame); | |
47 | 47 |
48 // Get the next frame for decoding. Will return at latest after | 48 // Get the next frame for decoding. Will return at latest after |
49 // |max_wait_time_ms|. | 49 // |max_wait_time_ms|. |
50 // - If a frame is availiable within |max_wait_time_ms| it will return | 50 // - If a frame is available within |max_wait_time_ms| it will return |
51 // kFrameFound and set |frame_out| to the resulting frame. | 51 // kFrameFound and set |frame_out| to the resulting frame. |
52 // - If no frame is available after |max_wait_time_ms| it will return | 52 // - If no frame is available after |max_wait_time_ms| it will return |
53 // kTimeout. | 53 // kTimeout. |
54 // - If the FrameBuffer is stopped then it will return kStopped. | 54 // - If the FrameBuffer is stopped then it will return kStopped. |
55 ReturnReason NextFrame(int64_t max_wait_time_ms, | 55 ReturnReason NextFrame(int64_t max_wait_time_ms, |
56 std::unique_ptr<FrameObject>* frame_out); | 56 std::unique_ptr<FrameObject>* frame_out); |
57 | 57 |
58 // Tells the FrameBuffer which protection mode that is in use. Affects | 58 // Tells the FrameBuffer which protection mode that is in use. Affects |
59 // the frame timing. | 59 // the frame timing. |
60 // TODO(philipel): Remove this when new timing calculations has been | 60 // TODO(philipel): Remove this when new timing calculations has been |
61 // implemented. | 61 // implemented. |
62 void SetProtectionMode(VCMVideoProtection mode); | 62 void SetProtectionMode(VCMVideoProtection mode); |
63 | 63 |
64 // Start the frame buffer, has no effect if the frame buffer is started. | 64 // Start the frame buffer, has no effect if the frame buffer is started. |
65 // The frame buffer is started upon construction. | 65 // The frame buffer is started upon construction. |
66 void Start(); | 66 void Start(); |
67 | 67 |
68 // Stop the frame buffer, causing any sleeping thread in NextFrame to | 68 // Stop the frame buffer, causing any sleeping thread in NextFrame to |
69 // return immediately. | 69 // return immediately. |
70 void Stop(); | 70 void Stop(); |
71 | 71 |
72 private: | 72 private: |
73 // FrameKey is a pair of (picture id, spatial layer). | 73 struct FrameKey { |
74 using FrameKey = std::pair<uint16_t, uint8_t>; | 74 FrameKey() : picture_id(0), spatial_layer(0) {} |
75 FrameKey(uint16_t picture_id, uint8_t spatial_layer) | |
76 : picture_id(picture_id), spatial_layer(spatial_layer) {} | |
75 | 77 |
76 // Comparator used to sort frames, first on their picture id, and second | 78 bool operator<(const FrameKey& other) const { |
77 // on their spatial layer. | 79 if (picture_id == other.picture_id) |
78 struct FrameComp { | 80 return spatial_layer < other.spatial_layer; |
79 bool operator()(const FrameKey& f1, const FrameKey& f2) const; | 81 return AheadOf(other.picture_id, picture_id); |
82 } | |
83 | |
84 bool operator==(const FrameKey& other) const { | |
danilchap
2016/09/19 12:21:50
look like instead you want
bool operator<=(const F
philipel
2016/09/19 15:36:57
Done.
| |
85 return picture_id == other.picture_id && | |
86 spatial_layer == other.spatial_layer; | |
87 } | |
88 | |
89 uint16_t picture_id; | |
90 uint8_t spatial_layer; | |
80 }; | 91 }; |
81 | 92 |
82 // Determines whether a frame is continuous. | 93 struct FrameInfo { |
83 bool IsContinuous(const FrameObject& frame) const | 94 static constexpr size_t kMaxNumDependentFrames = 5; |
95 | |
96 // Which other frames that have unfulfilled dependencies on this frame. | |
97 FrameKey dependent_frames[kMaxNumDependentFrames]; | |
98 size_t num_dependent_frames = 0; | |
99 | |
100 // How many unfulfilled frames this frame have to become continuous. | |
danilchap
2016/09/19 12:21:51
may be add description what is continuous and what
philipel
2016/09/19 15:36:57
Added comments.
| |
101 size_t num_missing_continuous = 0; | |
102 | |
103 // How many unfulfilled frames this frame have to become decodable. | |
104 size_t num_missing_decodable = 0; | |
105 | |
106 // If this frame is continuous or not. | |
107 bool continuous = false; | |
108 | |
109 // The actual FrameObject. | |
110 std::unique_ptr<FrameObject> frame; | |
111 }; | |
112 | |
113 using FrameMap = std::map<FrameKey, FrameInfo>; | |
114 | |
115 // Update all directly dependent and indirectly dependent frames and mark | |
116 // them as continuous if all their references has been fulfilled. | |
117 void PropagateContinuity(const FrameMap::iterator& start) | |
danilchap
2016/09/19 12:21:50
probably better to treat iterator as pointer and p
philipel
2016/09/19 15:36:57
Done.
| |
84 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 118 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
85 | 119 |
86 // Keep track of decoded frames. | 120 // Mark the frame as decoded and updates all directly dependent frames. |
87 std::set<FrameKey, FrameComp> decoded_frames_ GUARDED_BY(crit_); | 121 void PropagateDecodability(const FrameInfo& info) |
122 EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
88 | 123 |
89 // The actual buffer that holds the FrameObjects. | 124 // Update the corresponding FrameInfo of |frame| and all FrameInfos that |
90 std::map<FrameKey, std::unique_ptr<FrameObject>, FrameComp> frames_ | 125 // |frame| references. |
91 GUARDED_BY(crit_); | 126 // Return frames_.end() if |frame| will never be decodable or |
127 // the iterator to the updated FrameInfo otherwise. | |
128 FrameMap::iterator UpdateFrameInfo(const FrameObject& frame) | |
danilchap
2016/09/19 12:21:50
this name doesn't describe neither how it will be
philipel
2016/09/19 15:36:57
UpdateFrameInfoWithIncomingFrame
| |
129 EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
130 | |
131 // Advances |last_decoded_frame_it_| to |decoded| and remove old | |
132 // frame info. | |
133 void AdvanceLastDecodedFrame(const FrameMap::iterator& decoded) | |
danilchap
2016/09/19 12:21:50
pass iterator by value
philipel
2016/09/19 15:36:57
Done.
| |
134 EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
135 | |
136 FrameMap frames_ GUARDED_BY(crit_); | |
92 | 137 |
93 rtc::CriticalSection crit_; | 138 rtc::CriticalSection crit_; |
94 Clock* const clock_; | 139 Clock* const clock_; |
95 rtc::Event frame_inserted_event_; | 140 rtc::Event new_countinuous_frame_event_; |
96 VCMJitterEstimator* const jitter_estimator_ GUARDED_BY(crit_); | 141 VCMJitterEstimator* const jitter_estimator_ GUARDED_BY(crit_); |
97 VCMTiming* const timing_ GUARDED_BY(crit_); | 142 VCMTiming* const timing_ GUARDED_BY(crit_); |
98 VCMInterFrameDelay inter_frame_delay_ GUARDED_BY(crit_); | 143 VCMInterFrameDelay inter_frame_delay_ GUARDED_BY(crit_); |
99 int newest_picture_id_ GUARDED_BY(crit_); | 144 FrameMap::iterator last_decoded_frame_it_ GUARDED_BY(crit_); |
145 FrameMap::iterator last_continuous_frame_it_ GUARDED_BY(crit_); | |
146 int num_frames_history_ GUARDED_BY(crit_); | |
147 int num_frames_buffered_ GUARDED_BY(crit_); | |
100 bool stopped_ GUARDED_BY(crit_); | 148 bool stopped_ GUARDED_BY(crit_); |
101 VCMVideoProtection protection_mode_ GUARDED_BY(crit_); | 149 VCMVideoProtection protection_mode_ GUARDED_BY(crit_); |
102 | 150 |
103 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FrameBuffer); | 151 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FrameBuffer); |
104 }; | 152 }; |
105 | 153 |
106 } // namespace video_coding | 154 } // namespace video_coding |
107 } // namespace webrtc | 155 } // namespace webrtc |
108 | 156 |
109 #endif // WEBRTC_MODULES_VIDEO_CODING_FRAME_BUFFER2_H_ | 157 #endif // WEBRTC_MODULES_VIDEO_CODING_FRAME_BUFFER2_H_ |
OLD | NEW |