Fix thread safety in VcmCapturer.
Makes VcmCapturer::Stop() blocking so that no frames can be in delivery while the camera has stopped. BUG= R=mflodman@webrtc.org Review URL: https://codereview.webrtc.org/1411813004 . Cr-Commit-Position: refs/heads/master@{#10385}
This commit is contained in:
@ -58,19 +58,25 @@ VcmCapturer* VcmCapturer::Create(VideoCaptureInput* input,
|
|||||||
size_t width,
|
size_t width,
|
||||||
size_t height,
|
size_t height,
|
||||||
size_t target_fps) {
|
size_t target_fps) {
|
||||||
VcmCapturer* vcm__capturer = new VcmCapturer(input);
|
VcmCapturer* vcm_capturer = new VcmCapturer(input);
|
||||||
if (!vcm__capturer->Init(width, height, target_fps)) {
|
if (!vcm_capturer->Init(width, height, target_fps)) {
|
||||||
// TODO(pbos): Log a warning that this failed.
|
// TODO(pbos): Log a warning that this failed.
|
||||||
delete vcm__capturer;
|
delete vcm_capturer;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return vcm__capturer;
|
return vcm_capturer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void VcmCapturer::Start() { started_ = true; }
|
void VcmCapturer::Start() {
|
||||||
|
rtc::CritScope lock(&crit_);
|
||||||
|
started_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
void VcmCapturer::Stop() { started_ = false; }
|
void VcmCapturer::Stop() {
|
||||||
|
rtc::CritScope lock(&crit_);
|
||||||
|
started_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
void VcmCapturer::Destroy() {
|
void VcmCapturer::Destroy() {
|
||||||
if (vcm_ == NULL) {
|
if (vcm_ == NULL) {
|
||||||
@ -90,6 +96,7 @@ VcmCapturer::~VcmCapturer() { Destroy(); }
|
|||||||
|
|
||||||
void VcmCapturer::OnIncomingCapturedFrame(const int32_t id,
|
void VcmCapturer::OnIncomingCapturedFrame(const int32_t id,
|
||||||
const VideoFrame& frame) {
|
const VideoFrame& frame) {
|
||||||
|
rtc::CritScope lock(&crit_);
|
||||||
if (started_)
|
if (started_)
|
||||||
input_->IncomingCapturedFrame(frame);
|
input_->IncomingCapturedFrame(frame);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#ifndef WEBRTC_VIDEO_ENGINE_TEST_COMMON_VCM_CAPTURER_H_
|
#ifndef WEBRTC_VIDEO_ENGINE_TEST_COMMON_VCM_CAPTURER_H_
|
||||||
#define WEBRTC_VIDEO_ENGINE_TEST_COMMON_VCM_CAPTURER_H_
|
#define WEBRTC_VIDEO_ENGINE_TEST_COMMON_VCM_CAPTURER_H_
|
||||||
|
|
||||||
|
#include "webrtc/base/criticalsection.h"
|
||||||
#include "webrtc/common_types.h"
|
#include "webrtc/common_types.h"
|
||||||
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
|
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
|
||||||
#include "webrtc/modules/video_capture/include/video_capture.h"
|
#include "webrtc/modules/video_capture/include/video_capture.h"
|
||||||
@ -38,7 +39,8 @@ class VcmCapturer : public VideoCapturer, public VideoCaptureDataCallback {
|
|||||||
bool Init(size_t width, size_t height, size_t target_fps);
|
bool Init(size_t width, size_t height, size_t target_fps);
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
bool started_;
|
rtc::CriticalSection crit_;
|
||||||
|
bool started_ GUARDED_BY(crit_);
|
||||||
VideoCaptureModule* vcm_;
|
VideoCaptureModule* vcm_;
|
||||||
VideoCaptureCapability capability_;
|
VideoCaptureCapability capability_;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user