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 213 matching lines...) Loading... |
224 } else if (codec_specific->codecType == kVideoCodecVP8) { | 224 } else if (codec_specific->codecType == kVideoCodecVP8) { |
225 simulcast_svc_idx = codec_specific->codecSpecific.VP8.simulcastIdx; | 225 simulcast_svc_idx = codec_specific->codecSpecific.VP8.simulcastIdx; |
226 } else if (codec_specific->codecType == kVideoCodecGeneric) { | 226 } else if (codec_specific->codecType == kVideoCodecGeneric) { |
227 simulcast_svc_idx = codec_specific->codecSpecific.generic.simulcast_idx; | 227 simulcast_svc_idx = codec_specific->codecSpecific.generic.simulcast_idx; |
228 } else if (codec_specific->codecType == kVideoCodecH264) { | 228 } else if (codec_specific->codecType == kVideoCodecH264) { |
229 // TODO(ilnik): When h264 simulcast is landed, extract simulcast idx here. | 229 // TODO(ilnik): When h264 simulcast is landed, extract simulcast idx here. |
230 } | 230 } |
231 | 231 |
232 rtc::Optional<size_t> outlier_frame_size; | 232 rtc::Optional<size_t> outlier_frame_size; |
233 rtc::Optional<int64_t> encode_start_ms; | 233 rtc::Optional<int64_t> encode_start_ms; |
234 bool is_timing_frame = false; | 234 uint8_t timing_flags = TimingFrameFlags::kInvalid; |
235 { | 235 { |
236 rtc::CritScope crit(&timing_params_lock_); | 236 rtc::CritScope crit(&timing_params_lock_); |
237 | 237 |
238 // Encoders with internal sources do not call OnEncodeStarted and | 238 // Encoders with internal sources do not call OnEncodeStarted and |
239 // OnFrameRateChanged. |timing_frames_info_| may be not filled here. | 239 // OnFrameRateChanged. |timing_frames_info_| may be not filled here. |
240 if (simulcast_svc_idx < timing_frames_info_.size()) { | 240 if (simulcast_svc_idx < timing_frames_info_.size()) { |
241 auto encode_start_map = | 241 auto encode_start_map = |
242 &timing_frames_info_[simulcast_svc_idx].encode_start_time_ms; | 242 &timing_frames_info_[simulcast_svc_idx].encode_start_time_ms; |
243 auto it = encode_start_map->find(encoded_image.capture_time_ms_); | 243 auto it = encode_start_map->find(encoded_image.capture_time_ms_); |
244 if (it != encode_start_map->end()) { | 244 if (it != encode_start_map->end()) { |
(...skipping 22 matching lines...) Loading... |
267 | 267 |
268 // Check if it's time to send a timing frame. | 268 // Check if it's time to send a timing frame. |
269 int64_t timing_frame_delay_ms = | 269 int64_t timing_frame_delay_ms = |
270 encoded_image.capture_time_ms_ - last_timing_frame_time_ms_; | 270 encoded_image.capture_time_ms_ - last_timing_frame_time_ms_; |
271 // Trigger threshold if it's a first frame, too long passed since the last | 271 // Trigger threshold if it's a first frame, too long passed since the last |
272 // timing frame, or we already sent timing frame on a different simulcast | 272 // timing frame, or we already sent timing frame on a different simulcast |
273 // stream with the same capture time. | 273 // stream with the same capture time. |
274 if (last_timing_frame_time_ms_ == -1 || | 274 if (last_timing_frame_time_ms_ == -1 || |
275 timing_frame_delay_ms >= timing_frames_thresholds_.delay_ms || | 275 timing_frame_delay_ms >= timing_frames_thresholds_.delay_ms || |
276 timing_frame_delay_ms == 0) { | 276 timing_frame_delay_ms == 0) { |
277 is_timing_frame = true; | 277 timing_flags = TimingFrameFlags::kTriggeredByTimer; |
278 last_timing_frame_time_ms_ = encoded_image.capture_time_ms_; | 278 last_timing_frame_time_ms_ = encoded_image.capture_time_ms_; |
279 } | 279 } |
280 | 280 |
281 // Outliers trigger timing frames, but do not affect scheduled timing | 281 // Outliers trigger timing frames, but do not affect scheduled timing |
282 // frames. | 282 // frames. |
283 if (outlier_frame_size && encoded_image._length >= *outlier_frame_size) { | 283 if (outlier_frame_size && encoded_image._length >= *outlier_frame_size) { |
284 is_timing_frame = true; | 284 if (timing_flags == TimingFrameFlags::kInvalid) |
| 285 timing_flags = 0; |
| 286 timing_flags |= TimingFrameFlags::kTriggeredBySize; |
285 } | 287 } |
286 } | 288 } |
287 | 289 |
288 // If encode start is not available that means that encoder uses internal | 290 // If encode start is not available that means that encoder uses internal |
289 // source. In that case capture timestamp may be from a different clock with a | 291 // source. In that case capture timestamp may be from a different clock with a |
290 // drift relative to rtc::TimeMillis(). We can't use it for Timing frames, | 292 // drift relative to rtc::TimeMillis(). We can't use it for Timing frames, |
291 // because to being sent in the network capture time required to be less than | 293 // because to being sent in the network capture time required to be less than |
292 // all the other timestamps. | 294 // all the other timestamps. |
293 if (is_timing_frame && encode_start_ms) { | 295 if (timing_flags != TimingFrameFlags::kInvalid && encode_start_ms) { |
294 encoded_image.SetEncodeTime(*encode_start_ms, rtc::TimeMillis()); | 296 encoded_image.SetEncodeTime(*encode_start_ms, rtc::TimeMillis()); |
295 } | 297 } |
| 298 encoded_image.timing_.flags = timing_flags; |
296 | 299 |
297 Result result = post_encode_callback_->OnEncodedImage( | 300 Result result = post_encode_callback_->OnEncodedImage( |
298 encoded_image, codec_specific, fragmentation_header); | 301 encoded_image, codec_specific, fragmentation_header); |
299 if (result.error != Result::OK) | 302 if (result.error != Result::OK) |
300 return result; | 303 return result; |
301 | 304 |
302 if (media_opt_) { | 305 if (media_opt_) { |
303 media_opt_->UpdateWithEncodedData(encoded_image); | 306 media_opt_->UpdateWithEncodedData(encoded_image); |
304 if (internal_source_) { | 307 if (internal_source_) { |
305 // Signal to encoder to drop next frame. | 308 // Signal to encoder to drop next frame. |
306 result.drop_next_frame = media_opt_->DropFrame(); | 309 result.drop_next_frame = media_opt_->DropFrame(); |
307 } | 310 } |
308 } | 311 } |
309 return result; | 312 return result; |
310 } | 313 } |
311 | 314 |
312 } // namespace webrtc | 315 } // namespace webrtc |
OLD | NEW |