Chromium Code Reviews| Index: content/renderer/media/gpu/rtc_video_encoder.cc |
| diff --git a/content/renderer/media/gpu/rtc_video_encoder.cc b/content/renderer/media/gpu/rtc_video_encoder.cc |
| index 4c42938e2a4bef07048703ba1fb759c6d4448135..80e6e8e2fa40f061b819a572cd69e7bb8cdd95f6 100644 |
| --- a/content/renderer/media/gpu/rtc_video_encoder.cc |
| +++ b/content/renderer/media/gpu/rtc_video_encoder.cc |
| @@ -234,6 +234,10 @@ class RTCVideoEncoder::Impl |
| // 15 bits running index of the VP8 frames. See VP8 RTP spec for details. |
| uint16_t picture_id_; |
| + // capture_time_ms_ field of the last returned webrtc::EncodedImage from |
|
mcasas
2017/02/16 19:10:15
nit : |capture_time_ms_|
emircan
2017/02/16 19:41:54
Done.
|
| + // BitstreamBufferReady(). |
| + int64_t last_capture_time_ms_; |
| + |
| // webrtc::VideoEncoder encode complete callback. |
| webrtc::EncodedImageCallback* encoded_image_callback_; |
| @@ -261,6 +265,7 @@ RTCVideoEncoder::Impl::Impl(media::GpuVideoAcceleratorFactories* gpu_factories, |
| input_next_frame_(NULL), |
| input_next_frame_keyframe_(false), |
| output_buffers_free_count_(0), |
| + last_capture_time_ms_(-1), |
| encoded_image_callback_(nullptr), |
| video_codec_type_(video_codec_type), |
| status_(WEBRTC_VIDEO_CODEC_UNINITIALIZED) { |
| @@ -469,21 +474,23 @@ void RTCVideoEncoder::Impl::BitstreamBufferReady(int32_t bitstream_buffer_id, |
| } |
| output_buffers_free_count_--; |
| - // Derive the capture time (in ms) and RTP timestamp (in 90KHz ticks). |
| - int64_t capture_time_us, capture_time_ms; |
| - uint32_t rtp_timestamp; |
| - |
| - if (!timestamp.is_zero()) { |
| - capture_time_us = timestamp.InMicroseconds();; |
| - capture_time_ms = timestamp.InMilliseconds(); |
| - } else { |
| - // Fallback to the current time if encoder does not provide timestamp. |
| - capture_time_us = rtc::TimeMicros(); |
| - capture_time_ms = capture_time_us / base::Time::kMicrosecondsPerMillisecond; |
| - } |
| - // RTP timestamp can wrap around. Get the lower 32 bits. |
| - rtp_timestamp = static_cast<uint32_t>( |
| - capture_time_us * 90 / base::Time::kMicrosecondsPerMillisecond); |
| + // Derive the capture time in ms from system clock. Make sure that it is |
| + // greater than the last. |
| + const int64_t capture_time_us = rtc::TimeMicros(); |
|
mcasas
2017/02/16 19:10:15
Could we do all these calcuations in ms and use
r
emircan
2017/02/16 19:41:54
It would lose the precision in |rtp_timestamp| cal
|
| + int64_t capture_time_ms = |
| + capture_time_us / base::Time::kMicrosecondsPerMillisecond; |
| + if (capture_time_ms <= last_capture_time_ms_) |
| + capture_time_ms = last_capture_time_ms_ + 1; |
|
mcasas
2017/02/16 19:10:15
Maybe
capture_time_ms = std::min(capture_time_m
emircan
2017/02/16 19:41:54
That wouldn't work. Suppose there is a rapid succe
|
| + last_capture_time_ms_ = capture_time_ms; |
| + |
| + // Fallback to the current time if encoder does not provide timestamp. |
| + const int64_t encoder_time_us = |
| + timestamp.is_zero() ? capture_time_us : timestamp.InMicroseconds(); |
| + |
| + // Derive the RTP timestamp (in 90KHz ticks). It can wrap around, get the |
| + // lower 32 bits. |
| + const uint32_t rtp_timestamp = static_cast<uint32_t>( |
| + encoder_time_us * 90 / base::Time::kMicrosecondsPerMillisecond); |
| webrtc::EncodedImage image( |
| reinterpret_cast<uint8_t*>(output_buffer->memory()), payload_size, |