OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 131 } |
132 return VCM_OK; | 132 return VCM_OK; |
133 } | 133 } |
134 | 134 |
135 void VCMReceiver::TriggerDecoderShutdown() { | 135 void VCMReceiver::TriggerDecoderShutdown() { |
136 jitter_buffer_.Stop(); | 136 jitter_buffer_.Stop(); |
137 render_wait_event_->Set(); | 137 render_wait_event_->Set(); |
138 } | 138 } |
139 | 139 |
140 VCMEncodedFrame* VCMReceiver::FrameForDecoding(uint16_t max_wait_time_ms, | 140 VCMEncodedFrame* VCMReceiver::FrameForDecoding(uint16_t max_wait_time_ms, |
141 int64_t* next_render_time_ms, | |
142 bool prefer_late_decoding) { | 141 bool prefer_late_decoding) { |
143 const int64_t start_time_ms = clock_->TimeInMilliseconds(); | 142 const int64_t start_time_ms = clock_->TimeInMilliseconds(); |
144 uint32_t frame_timestamp = 0; | 143 uint32_t frame_timestamp = 0; |
145 int min_playout_delay_ms = -1; | 144 int min_playout_delay_ms = -1; |
146 int max_playout_delay_ms = -1; | 145 int max_playout_delay_ms = -1; |
| 146 int64_t render_time_ms = 0; |
147 // Exhaust wait time to get a complete frame for decoding. | 147 // Exhaust wait time to get a complete frame for decoding. |
148 VCMEncodedFrame* found_frame = | 148 VCMEncodedFrame* found_frame = |
149 jitter_buffer_.NextCompleteFrame(max_wait_time_ms); | 149 jitter_buffer_.NextCompleteFrame(max_wait_time_ms); |
150 | 150 |
151 if (found_frame) { | 151 if (found_frame) { |
152 frame_timestamp = found_frame->TimeStamp(); | 152 frame_timestamp = found_frame->TimeStamp(); |
153 min_playout_delay_ms = found_frame->EncodedImage().playout_delay_.min_ms; | 153 min_playout_delay_ms = found_frame->EncodedImage().playout_delay_.min_ms; |
154 max_playout_delay_ms = found_frame->EncodedImage().playout_delay_.max_ms; | 154 max_playout_delay_ms = found_frame->EncodedImage().playout_delay_.max_ms; |
155 } else { | 155 } else { |
156 if (!jitter_buffer_.NextMaybeIncompleteTimestamp(&frame_timestamp)) | 156 if (!jitter_buffer_.NextMaybeIncompleteTimestamp(&frame_timestamp)) |
157 return nullptr; | 157 return nullptr; |
158 } | 158 } |
159 | 159 |
160 if (min_playout_delay_ms >= 0) | 160 if (min_playout_delay_ms >= 0) |
161 timing_->set_min_playout_delay(min_playout_delay_ms); | 161 timing_->set_min_playout_delay(min_playout_delay_ms); |
162 | 162 |
163 if (max_playout_delay_ms >= 0) | 163 if (max_playout_delay_ms >= 0) |
164 timing_->set_max_playout_delay(max_playout_delay_ms); | 164 timing_->set_max_playout_delay(max_playout_delay_ms); |
165 | 165 |
166 // We have a frame - Set timing and render timestamp. | 166 // We have a frame - Set timing and render timestamp. |
167 timing_->SetJitterDelay(jitter_buffer_.EstimatedJitterMs()); | 167 timing_->SetJitterDelay(jitter_buffer_.EstimatedJitterMs()); |
168 const int64_t now_ms = clock_->TimeInMilliseconds(); | 168 const int64_t now_ms = clock_->TimeInMilliseconds(); |
169 timing_->UpdateCurrentDelay(frame_timestamp); | 169 timing_->UpdateCurrentDelay(frame_timestamp); |
170 *next_render_time_ms = timing_->RenderTimeMs(frame_timestamp, now_ms); | 170 render_time_ms = timing_->RenderTimeMs(frame_timestamp, now_ms); |
171 // Check render timing. | 171 // Check render timing. |
172 bool timing_error = false; | 172 bool timing_error = false; |
173 // Assume that render timing errors are due to changes in the video stream. | 173 // Assume that render timing errors are due to changes in the video stream. |
174 if (*next_render_time_ms < 0) { | 174 if (render_time_ms < 0) { |
175 timing_error = true; | 175 timing_error = true; |
176 } else if (std::abs(*next_render_time_ms - now_ms) > max_video_delay_ms_) { | 176 } else if (std::abs(render_time_ms - now_ms) > max_video_delay_ms_) { |
177 int frame_delay = static_cast<int>(std::abs(*next_render_time_ms - now_ms)); | 177 int frame_delay = static_cast<int>(std::abs(render_time_ms - now_ms)); |
178 LOG(LS_WARNING) << "A frame about to be decoded is out of the configured " | 178 LOG(LS_WARNING) << "A frame about to be decoded is out of the configured " |
179 << "delay bounds (" << frame_delay << " > " | 179 << "delay bounds (" << frame_delay << " > " |
180 << max_video_delay_ms_ | 180 << max_video_delay_ms_ |
181 << "). Resetting the video jitter buffer."; | 181 << "). Resetting the video jitter buffer."; |
182 timing_error = true; | 182 timing_error = true; |
183 } else if (static_cast<int>(timing_->TargetVideoDelay()) > | 183 } else if (static_cast<int>(timing_->TargetVideoDelay()) > |
184 max_video_delay_ms_) { | 184 max_video_delay_ms_) { |
185 LOG(LS_WARNING) << "The video target delay has grown larger than " | 185 LOG(LS_WARNING) << "The video target delay has grown larger than " |
186 << max_video_delay_ms_ << " ms. Resetting jitter buffer."; | 186 << max_video_delay_ms_ << " ms. Resetting jitter buffer."; |
187 timing_error = true; | 187 timing_error = true; |
188 } | 188 } |
189 | 189 |
190 if (timing_error) { | 190 if (timing_error) { |
191 // Timing error => reset timing and flush the jitter buffer. | 191 // Timing error => reset timing and flush the jitter buffer. |
192 jitter_buffer_.Flush(); | 192 jitter_buffer_.Flush(); |
193 timing_->Reset(); | 193 timing_->Reset(); |
194 return NULL; | 194 return NULL; |
195 } | 195 } |
196 | 196 |
197 if (prefer_late_decoding) { | 197 if (prefer_late_decoding) { |
198 // Decode frame as close as possible to the render timestamp. | 198 // Decode frame as close as possible to the render timestamp. |
199 const int32_t available_wait_time = | 199 const int32_t available_wait_time = |
200 max_wait_time_ms - | 200 max_wait_time_ms - |
201 static_cast<int32_t>(clock_->TimeInMilliseconds() - start_time_ms); | 201 static_cast<int32_t>(clock_->TimeInMilliseconds() - start_time_ms); |
202 uint16_t new_max_wait_time = | 202 uint16_t new_max_wait_time = |
203 static_cast<uint16_t>(VCM_MAX(available_wait_time, 0)); | 203 static_cast<uint16_t>(VCM_MAX(available_wait_time, 0)); |
204 uint32_t wait_time_ms = timing_->MaxWaitingTime( | 204 uint32_t wait_time_ms = |
205 *next_render_time_ms, clock_->TimeInMilliseconds()); | 205 timing_->MaxWaitingTime(render_time_ms, clock_->TimeInMilliseconds()); |
206 if (new_max_wait_time < wait_time_ms) { | 206 if (new_max_wait_time < wait_time_ms) { |
207 // We're not allowed to wait until the frame is supposed to be rendered, | 207 // We're not allowed to wait until the frame is supposed to be rendered, |
208 // waiting as long as we're allowed to avoid busy looping, and then return | 208 // waiting as long as we're allowed to avoid busy looping, and then return |
209 // NULL. Next call to this function might return the frame. | 209 // NULL. Next call to this function might return the frame. |
210 render_wait_event_->Wait(new_max_wait_time); | 210 render_wait_event_->Wait(new_max_wait_time); |
211 return NULL; | 211 return NULL; |
212 } | 212 } |
213 // Wait until it's time to render. | 213 // Wait until it's time to render. |
214 render_wait_event_->Wait(wait_time_ms); | 214 render_wait_event_->Wait(wait_time_ms); |
215 } | 215 } |
216 | 216 |
217 // Extract the frame from the jitter buffer and set the render time. | 217 // Extract the frame from the jitter buffer and set the render time. |
218 VCMEncodedFrame* frame = jitter_buffer_.ExtractAndSetDecode(frame_timestamp); | 218 VCMEncodedFrame* frame = jitter_buffer_.ExtractAndSetDecode(frame_timestamp); |
219 if (frame == NULL) { | 219 if (frame == NULL) { |
220 return NULL; | 220 return NULL; |
221 } | 221 } |
222 frame->SetRenderTime(*next_render_time_ms); | 222 frame->SetRenderTime(render_time_ms); |
223 TRACE_EVENT_ASYNC_STEP1("webrtc", "Video", frame->TimeStamp(), "SetRenderTS", | 223 TRACE_EVENT_ASYNC_STEP1("webrtc", "Video", frame->TimeStamp(), "SetRenderTS", |
224 "render_time", *next_render_time_ms); | 224 "render_time", frame->RenderTimeMs()); |
225 if (!frame->Complete()) { | 225 if (!frame->Complete()) { |
226 // Update stats for incomplete frames. | 226 // Update stats for incomplete frames. |
227 bool retransmitted = false; | 227 bool retransmitted = false; |
228 const int64_t last_packet_time_ms = | 228 const int64_t last_packet_time_ms = |
229 jitter_buffer_.LastPacketTime(frame, &retransmitted); | 229 jitter_buffer_.LastPacketTime(frame, &retransmitted); |
230 if (last_packet_time_ms >= 0 && !retransmitted) { | 230 if (last_packet_time_ms >= 0 && !retransmitted) { |
231 // We don't want to include timestamps which have suffered from | 231 // We don't want to include timestamps which have suffered from |
232 // retransmission here, since we compensate with extra retransmission | 232 // retransmission here, since we compensate with extra retransmission |
233 // delay within the jitter estimate. | 233 // delay within the jitter estimate. |
234 timing_->IncomingTimestamp(frame_timestamp, last_packet_time_ms); | 234 timing_->IncomingTimestamp(frame_timestamp, last_packet_time_ms); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 timing_->set_min_playout_delay(desired_delay_ms); | 294 timing_->set_min_playout_delay(desired_delay_ms); |
295 return 0; | 295 return 0; |
296 } | 296 } |
297 | 297 |
298 void VCMReceiver::RegisterStatsCallback( | 298 void VCMReceiver::RegisterStatsCallback( |
299 VCMReceiveStatisticsCallback* callback) { | 299 VCMReceiveStatisticsCallback* callback) { |
300 jitter_buffer_.RegisterStatsCallback(callback); | 300 jitter_buffer_.RegisterStatsCallback(callback); |
301 } | 301 } |
302 | 302 |
303 } // namespace webrtc | 303 } // namespace webrtc |
OLD | NEW |