Commit 9573aad7 authored by perkj@chromium.org's avatar perkj@chromium.org

Update the Chromium version of webrtc::VideoCaptureModule to be reference counted.

The reason is to be able to share ownership between PeerConnection and Chromium.

TEST=
BUG=
Review URL: http://codereview.chromium.org/7887002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102286 0039d316-1c4b-4281-b951-d872f2087c98
parent 4d6f01a9
......@@ -4,6 +4,7 @@
#include "content/renderer/media/video_capture_module_impl.h"
#include "base/atomicops.h"
#include "content/renderer/media/video_capture_impl_manager.h"
VideoCaptureModuleImpl::VideoCaptureModuleImpl(
......@@ -20,7 +21,8 @@ VideoCaptureModuleImpl::VideoCaptureModuleImpl(
frame_rate_(-1),
video_type_(webrtc::kVideoI420),
capture_engine_(NULL),
pending_start_(false) {
pending_start_(false),
ref_count_(0) {
DCHECK(vc_manager_);
Init();
}
......@@ -36,6 +38,21 @@ void VideoCaptureModuleImpl::Init() {
capture_engine_ = vc_manager_->AddDevice(session_id_, this);
}
int32_t VideoCaptureModuleImpl::AddRef() {
VLOG(1) << "VideoCaptureModuleImpl::AddRef()";
return base::subtle::Barrier_AtomicIncrement(&ref_count_, 1);
}
int32_t VideoCaptureModuleImpl::Release() {
VLOG(1) << "VideoCaptureModuleImpl::Release()";
int ret = base::subtle::Barrier_AtomicIncrement(&ref_count_, -1);
if (ret == 0) {
VLOG(1) << "Reference count is zero, hence this object is now deleted.";
delete this;
}
return ret;
}
WebRtc_Word32 VideoCaptureModuleImpl::StartCapture(
const webrtc::VideoCaptureCapability& capability) {
message_loop_proxy_->PostTask(
......
......@@ -22,7 +22,10 @@ class VideoCaptureModuleImpl
public:
VideoCaptureModuleImpl(const media::VideoCaptureSessionId id,
VideoCaptureImplManager* vc_manager);
virtual ~VideoCaptureModuleImpl();
// Implement reference counting. This make it possible to reference the
// object from both Chromium and WebRtc.
virtual int32_t AddRef() OVERRIDE;
virtual int32_t Release() OVERRIDE;
// Override webrtc::videocapturemodule::VideoCaptureImpl implementation.
virtual WebRtc_Word32 StartCapture(
......@@ -45,6 +48,7 @@ class VideoCaptureModuleImpl
const media::VideoCaptureParams& device_info);
private:
virtual ~VideoCaptureModuleImpl();
void Init();
void StartCaptureOnCaptureThread(
......@@ -76,6 +80,7 @@ class VideoCaptureModuleImpl
media::VideoCapture* capture_engine_;
bool pending_start_;
webrtc::VideoCaptureCapability pending_cap_;
int ref_count_;
DISALLOW_COPY_AND_ASSIGN(VideoCaptureModuleImpl);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment