Fixing capture frame race in ViECapturer.

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4654 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mflodman@webrtc.org
2013-09-02 12:44:57 +00:00
parent 5aedb295d5
commit dfbf52baac
2 changed files with 13 additions and 7 deletions

View File

@@ -511,13 +511,7 @@ bool ViECapturer::ViECaptureThreadFunction(void* obj) {
bool ViECapturer::ViECaptureProcess() {
if (capture_event_.Wait(kThreadWaitTimeMs) == kEventSignaled) {
deliver_cs_->Enter();
if (!captured_frame_.IsZeroSize()) {
// New I420 frame.
capture_cs_->Enter();
deliver_frame_.SwapFrame(&captured_frame_);
captured_frame_.ResetSize();
capture_cs_->Leave();
if (MaybeSwapCapturedToDeliverFrame()) {
DeliverI420Frame(&deliver_frame_);
}
deliver_cs_->Leave();
@@ -652,4 +646,14 @@ void ViECapturer::OnNoPictureAlarm(const int32_t id,
observer_->NoPictureAlarm(id, vie_alarm);
}
bool ViECapturer::MaybeSwapCapturedToDeliverFrame() {
CriticalSectionScoped cs(capture_cs_.get());
if (captured_frame_.IsZeroSize())
return false;
deliver_frame_.SwapFrame(&captured_frame_);
captured_frame_.ResetSize();
return true;
}
} // namespace webrtc

View File

@@ -144,6 +144,8 @@ class ViECapturer
void DeliverCodedFrame(VideoFrame* video_frame);
private:
bool MaybeSwapCapturedToDeliverFrame();
// Never take capture_cs_ before deliver_cs_!
scoped_ptr<CriticalSectionWrapper> capture_cs_;
scoped_ptr<CriticalSectionWrapper> deliver_cs_;