Hello,
I noticed interesting behavior on one computer. I thought it is by design But after looking at code I believe it is bug. Computer should be quite new and fast. Here the problem:
libjingle/trunk/webrtc/modules/video_capture/video_capture_impl.cc
int32_t VideoCaptureImpl::DeliverCapturedFrame(I420VideoFrame& captureFrame,
int64_t capture_time) {
UpdateFrameCount(); // frame count used for local frame rate callback.
const bool callOnCaptureDelayChanged = _setCaptureDelay != _captureDelay;
// Capture delay changed
if (_setCaptureDelay != _captureDelay) {
_setCaptureDelay = _captureDelay;
}
// Set the capture time
if (capture_time != 0) {
captureFrame.set_render_time_ms(capture_time - delta_ntp_internal_ms_);
} else {
captureFrame.set_render_time_ms(TickTime::MillisecondTimestamp());
}
if (captureFrame.render_time_ms() == last_capture_time_) {
// We don't allow the same capture time for two frames, drop this one.
return -1;
}
last_capture_time_ = captureFrame.render_time_ms();
if (_dataCallBack) {
if (callOnCaptureDelayChanged) {
_dataCallBack->OnCaptureDelayChanged(_id, _captureDelay);
}
_dataCallBack->OnIncomingCapturedFrame(_id, captureFrame);
}
return 0;
}
Generally speaking nothing is wrong with the code but this piece:
if (captureFrame.render_time_ms() == last_capture_time_) {
// We don't allow the same capture time for two frames, drop this one.
return -1;
}
that drops the frame get executed quite often on fast computers. Once I looked at stack I found that this method executed 2 times.
And second call happens quite soon, sometime less then 1 microsecond interval. That time both time stamps are the same due this code
last_capture_time_ = captureFrame.render_time_ms();
And on second execution somebody expected that this call
captureFrame.set_render_time_ms(TickTime::MillisecondTimestamp());
will get something different.
But WebRTC uses time stamp precision in milliseconds
(which is bad idea, for instance Media Foundation uses 100 nanosecond interval). And new timestamp still the same (again it could be different if timestamp was in microseconds).
So it cause to drop quite legal and useful frame.
It is very tricky problem and happens on computer which able to run that piece of code fast. I have only one such machine, and it drops frames quite intensively.
Actually it can make video quite shaky on fast computer (where you would expect better result)
Regards
Aleksey