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 29 matching lines...) Expand all Loading... | |
40 return AheadOf(f2.first, f1.first); | 40 return AheadOf(f2.first, f1.first); |
41 } | 41 } |
42 | 42 |
43 FrameBuffer::FrameBuffer(Clock* clock, | 43 FrameBuffer::FrameBuffer(Clock* clock, |
44 VCMJitterEstimator* jitter_estimator, | 44 VCMJitterEstimator* jitter_estimator, |
45 const VCMTiming* timing) | 45 const VCMTiming* timing) |
46 : clock_(clock), | 46 : clock_(clock), |
47 frame_inserted_event_(false, false), | 47 frame_inserted_event_(false, false), |
48 jitter_estimator_(jitter_estimator), | 48 jitter_estimator_(jitter_estimator), |
49 timing_(timing), | 49 timing_(timing), |
50 newest_picture_id_(-1) {} | 50 newest_picture_id_(-1), |
51 stopped_(false) {} | |
51 | 52 |
52 std::unique_ptr<FrameObject> FrameBuffer::NextFrame(int64_t max_wait_time_ms) { | 53 std::unique_ptr<FrameObject> FrameBuffer::NextFrame(int64_t max_wait_time_ms) { |
53 int64_t latest_return_time = clock_->TimeInMilliseconds() + max_wait_time_ms; | 54 int64_t latest_return_time = clock_->TimeInMilliseconds() + max_wait_time_ms; |
54 while (true) { | 55 while (true) { |
56 crit_.Enter(); | |
pbos-webrtc
2016/06/29 15:51:26
Can you replace these explicit enters with rtc::Cr
philipel
2016/06/30 09:36:56
Sorry, scopes wont work throughout this functions,
pbos-webrtc
2016/06/30 09:44:07
What do you mean? Have one scoped between line 56
philipel
2016/06/30 11:37:35
The problem is the |next_frame| iterator which we
pbos-webrtc
2016/06/30 12:04:53
Can frames_' size be modified while the lock is dr
philipel
2016/06/30 12:20:04
You can't call frames_.size() while not holding th
| |
57 frame_inserted_event_.Reset(); | |
58 if (stopped_) { | |
59 crit_.Leave(); | |
60 return std::unique_ptr<FrameObject>(); | |
61 } | |
62 | |
55 int64_t now = clock_->TimeInMilliseconds(); | 63 int64_t now = clock_->TimeInMilliseconds(); |
56 int64_t wait_ms = max_wait_time_ms; | 64 int64_t wait_ms = max_wait_time_ms; |
57 | |
58 crit_.Enter(); | |
59 frame_inserted_event_.Reset(); | |
60 auto next_frame = frames_.end(); | 65 auto next_frame = frames_.end(); |
61 for (auto frame_it = frames_.begin(); frame_it != frames_.end(); | 66 for (auto frame_it = frames_.begin(); frame_it != frames_.end(); |
62 ++frame_it) { | 67 ++frame_it) { |
63 const FrameObject& frame = *frame_it->second; | 68 const FrameObject& frame = *frame_it->second; |
64 if (IsContinuous(frame)) { | 69 if (IsContinuous(frame)) { |
65 next_frame = frame_it; | 70 next_frame = frame_it; |
66 int64_t render_time = timing_->RenderTimeMs(frame.timestamp, now); | 71 int64_t render_time = timing_->RenderTimeMs(frame.timestamp, now); |
67 wait_ms = timing_->MaxWaitingTime(render_time, now); | 72 wait_ms = timing_->MaxWaitingTime(render_time, now); |
68 | 73 |
69 // This will cause the frame buffer to prefer high framerate rather | 74 // This will cause the frame buffer to prefer high framerate rather |
(...skipping 23 matching lines...) Expand all Loading... | |
93 crit_.Leave(); | 98 crit_.Leave(); |
94 return frame; | 99 return frame; |
95 } else { | 100 } else { |
96 crit_.Leave(); | 101 crit_.Leave(); |
97 return std::unique_ptr<FrameObject>(); | 102 return std::unique_ptr<FrameObject>(); |
98 } | 103 } |
99 } | 104 } |
100 } | 105 } |
101 } | 106 } |
102 | 107 |
108 void FrameBuffer::Start() { | |
109 rtc::CritScope lock(&crit_); | |
110 stopped_ = false; | |
111 } | |
112 | |
113 void FrameBuffer::Stop() { | |
114 rtc::CritScope lock(&crit_); | |
115 stopped_ = true; | |
116 frame_inserted_event_.Set(); | |
117 } | |
118 | |
103 void FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) { | 119 void FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) { |
104 rtc::CritScope lock(&crit_); | 120 rtc::CritScope lock(&crit_); |
105 if (newest_picture_id_ == -1) | 121 if (newest_picture_id_ == -1) |
106 newest_picture_id_ = frame->picture_id; | 122 newest_picture_id_ = frame->picture_id; |
107 | 123 |
108 if (AheadOf<uint16_t>(frame->picture_id, newest_picture_id_)) | 124 if (AheadOf<uint16_t>(frame->picture_id, newest_picture_id_)) |
109 newest_picture_id_ = frame->picture_id; | 125 newest_picture_id_ = frame->picture_id; |
110 | 126 |
111 // Remove frames as long as we have too many, |kMaxNumHistoryFrames|. | 127 // Remove frames as long as we have too many, |kMaxNumHistoryFrames|. |
112 while (decoded_frames_.size() > kMaxNumHistoryFrames) | 128 while (decoded_frames_.size() > kMaxNumHistoryFrames) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 FrameKey ref_key(frame.picture_id, frame.spatial_layer - 1); | 161 FrameKey ref_key(frame.picture_id, frame.spatial_layer - 1); |
146 if (decoded_frames_.find(ref_key) == decoded_frames_.end()) | 162 if (decoded_frames_.find(ref_key) == decoded_frames_.end()) |
147 return false; | 163 return false; |
148 } | 164 } |
149 | 165 |
150 return true; | 166 return true; |
151 } | 167 } |
152 | 168 |
153 } // namespace video_coding | 169 } // namespace video_coding |
154 } // namespace webrtc | 170 } // namespace webrtc |
OLD | NEW |