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

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

Issue 2322263002: Frame continuity is now tested as soon as a frame is inserted into the FrameBuffer. (Closed)
Patch Set: Avoid adding unnecessary backwards references for inter layer predicted frames. Created 4 years, 3 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_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 {
stefan-webrtc 2016/09/21 14:50:14 I think rhs is a better name than other as it make
philipel 2016/09/22 11:18:39 Done.
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 { return !(other < *this); }
stefan-webrtc 2016/09/21 14:50:14 Same here.
philipel 2016/09/22 11:18:38 Done.
85
86 uint16_t picture_id;
87 uint8_t spatial_layer;
80 }; 88 };
81 89
82 // Determines whether a frame is continuous. 90 struct FrameInfo {
83 bool IsContinuous(const FrameObject& frame) const 91 static constexpr size_t kMaxNumDependentFrames = 5;
92
93 // Which other frames that have unfulfilled dependencies on this frame.
94 FrameKey dependent_frames[kMaxNumDependentFrames];
stefan-webrtc 2016/09/21 14:50:14 Comment on if this array only contains direct depe
philipel 2016/09/22 11:18:38 Updated comment, I think 5 should be enough but I
95 size_t num_dependent_frames = 0;
96
97 // A frame is continiuous if have all its referenced/indirectly referenced
stefan-webrtc 2016/09/21 14:50:14 continuous if it has
philipel 2016/09/22 11:18:39 Done.
98 // frames.
99 //
100 // How many unfulfilled frames this frame have to become continuous.
stefan-webrtc 2016/09/21 14:50:14 s/have/need?
philipel 2016/09/22 11:18:38 this frame have until it becomes
101 size_t num_missing_continuous = 0;
stefan-webrtc 2016/09/21 14:50:14 num_missing_dependencies?
philipel 2016/09/22 11:18:39 Not really, this hold how many referenced frames w
102
103 // A frame is decodable if all its referenced frames have been decoded.
104 //
105 // How many unfulfilled frames this frame have to become decodable.
106 size_t num_missing_decodable = 0;
stefan-webrtc 2016/09/21 14:50:14 Not clear to me what the difference is between dec
philipel 2016/09/22 11:18:38 A frame is continuous if all frames this frame dep
107
108 // If this frame is continuous or not.
109 bool continuous = false;
stefan-webrtc 2016/09/21 14:50:14 Isn't this true whenever num_missing_continuous is
philipel 2016/09/22 11:18:39 No, since we create FrameInfos to hold backwards r
110
111 // The actual FrameObject.
112 std::unique_ptr<FrameObject> frame;
113 };
114
115 using FrameMap = std::map<FrameKey, FrameInfo>;
116
117 // Update all directly dependent and indirectly dependent frames and mark
118 // them as continuous if all their references has been fulfilled.
119 void PropagateContinuity(FrameMap::iterator start)
84 EXCLUSIVE_LOCKS_REQUIRED(crit_); 120 EXCLUSIVE_LOCKS_REQUIRED(crit_);
85 121
86 // Keep track of decoded frames. 122 // Mark the frame as decoded and updates all directly dependent frames.
stefan-webrtc 2016/09/21 14:50:14 "and update"
philipel 2016/09/22 11:18:38 Done.
87 std::set<FrameKey, FrameComp> decoded_frames_ GUARDED_BY(crit_); 123 void PropagateDecodability(const FrameInfo& info)
124 EXCLUSIVE_LOCKS_REQUIRED(crit_);
88 125
89 // The actual buffer that holds the FrameObjects. 126 // Advances |last_decoded_frame_it_| to |decoded| and remove old
stefan-webrtc 2016/09/21 14:50:14 "and removes"
philipel 2016/09/22 11:18:39 Done.
90 std::map<FrameKey, std::unique_ptr<FrameObject>, FrameComp> frames_ 127 // frame info.
stefan-webrtc 2016/09/21 14:50:14 FrameInfo
philipel 2016/09/22 11:18:38 Done.
91 GUARDED_BY(crit_); 128 void AdvanceLastDecodedFrame(FrameMap::iterator decoded)
129 EXCLUSIVE_LOCKS_REQUIRED(crit_);
130
131 // Update the corresponding FrameInfo of |frame| and all FrameInfos that
132 // |frame| references.
133 // Return false if |frame| will never be decodable, true otherwise.
134 bool UpdateFrameInfoWithIncomingFrame(const FrameObject& frame,
135 FrameMap::iterator info)
136 EXCLUSIVE_LOCKS_REQUIRED(crit_);
137
138 FrameMap frames_ GUARDED_BY(crit_);
92 139
93 rtc::CriticalSection crit_; 140 rtc::CriticalSection crit_;
94 Clock* const clock_; 141 Clock* const clock_;
95 rtc::Event frame_inserted_event_; 142 rtc::Event new_countinuous_frame_event_;
96 VCMJitterEstimator* const jitter_estimator_ GUARDED_BY(crit_); 143 VCMJitterEstimator* const jitter_estimator_ GUARDED_BY(crit_);
97 VCMTiming* const timing_ GUARDED_BY(crit_); 144 VCMTiming* const timing_ GUARDED_BY(crit_);
98 VCMInterFrameDelay inter_frame_delay_ GUARDED_BY(crit_); 145 VCMInterFrameDelay inter_frame_delay_ GUARDED_BY(crit_);
99 int newest_picture_id_ GUARDED_BY(crit_); 146 FrameMap::iterator last_decoded_frame_it_ GUARDED_BY(crit_);
stefan-webrtc 2016/09/21 14:50:14 Does this mean we're always keeping the last decod
philipel 2016/09/22 11:18:38 No, the actual FrameObject is passed to the decode
147 FrameMap::iterator last_continuous_frame_it_ GUARDED_BY(crit_);
148 int num_frames_history_ GUARDED_BY(crit_);
149 int num_frames_buffered_ GUARDED_BY(crit_);
100 bool stopped_ GUARDED_BY(crit_); 150 bool stopped_ GUARDED_BY(crit_);
101 VCMVideoProtection protection_mode_ GUARDED_BY(crit_); 151 VCMVideoProtection protection_mode_ GUARDED_BY(crit_);
102 152
103 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FrameBuffer); 153 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FrameBuffer);
104 }; 154 };
105 155
106 } // namespace video_coding 156 } // namespace video_coding
107 } // namespace webrtc 157 } // namespace webrtc
108 158
109 #endif // WEBRTC_MODULES_VIDEO_CODING_FRAME_BUFFER2_H_ 159 #endif // WEBRTC_MODULES_VIDEO_CODING_FRAME_BUFFER2_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/video_coding/frame_buffer2.cc » ('j') | webrtc/modules/video_coding/frame_buffer2.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698