OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/video_capture_module_impl.h" | 5 #include "content/renderer/media/video_capture_module_impl.h" |
6 | 6 |
| 7 #include "base/atomicops.h" |
7 #include "content/renderer/media/video_capture_impl_manager.h" | 8 #include "content/renderer/media/video_capture_impl_manager.h" |
8 | 9 |
9 // static | 10 // static |
10 webrtc::VideoCaptureModule* webrtc::VideoCaptureModule::Create( | 11 webrtc::VideoCaptureModule* webrtc::VideoCaptureModule::Create( |
11 const WebRtc_Word32 id, const WebRtc_UWord8* device_unique_id_utf8) { | 12 const WebRtc_Word32 id, const WebRtc_UWord8* device_unique_id_utf8) { |
12 NOTREACHED(); | 13 NOTREACHED(); |
13 return NULL; | 14 return NULL; |
14 } | 15 } |
15 | 16 |
16 VideoCaptureModuleImpl::VideoCaptureModuleImpl( | 17 VideoCaptureModuleImpl::VideoCaptureModuleImpl( |
17 const media::VideoCaptureSessionId id, | 18 const media::VideoCaptureSessionId id, |
18 VideoCaptureImplManager* vc_manager) | 19 VideoCaptureImplManager* vc_manager) |
19 : webrtc::videocapturemodule::VideoCaptureImpl(id), | 20 : webrtc::videocapturemodule::VideoCaptureImpl(id), |
20 session_id_(id), | 21 session_id_(id), |
21 thread_("VideoCaptureModuleImpl"), | 22 thread_("VideoCaptureModuleImpl"), |
22 vc_manager_(vc_manager), | 23 vc_manager_(vc_manager), |
23 state_(media::VideoCapture::kStopped), | 24 state_(media::VideoCapture::kStopped), |
24 got_first_frame_(false), | 25 got_first_frame_(false), |
25 width_(-1), | 26 width_(-1), |
26 height_(-1), | 27 height_(-1), |
27 frame_rate_(-1), | 28 frame_rate_(-1), |
28 video_type_(webrtc::kVideoI420), | 29 video_type_(webrtc::kVideoI420), |
29 capture_engine_(NULL), | 30 capture_engine_(NULL), |
30 pending_start_(false) { | 31 pending_start_(false), |
| 32 ref_count_(0) { |
31 DCHECK(vc_manager_); | 33 DCHECK(vc_manager_); |
32 Init(); | 34 Init(); |
33 } | 35 } |
34 | 36 |
35 VideoCaptureModuleImpl::~VideoCaptureModuleImpl() { | 37 VideoCaptureModuleImpl::~VideoCaptureModuleImpl() { |
36 vc_manager_->RemoveDevice(session_id_, this); | 38 vc_manager_->RemoveDevice(session_id_, this); |
37 thread_.Stop(); | 39 thread_.Stop(); |
38 } | 40 } |
39 | 41 |
40 void VideoCaptureModuleImpl::Init() { | 42 void VideoCaptureModuleImpl::Init() { |
41 thread_.Start(); | 43 thread_.Start(); |
42 message_loop_proxy_ = thread_.message_loop_proxy(); | 44 message_loop_proxy_ = thread_.message_loop_proxy(); |
43 capture_engine_ = vc_manager_->AddDevice(session_id_, this); | 45 capture_engine_ = vc_manager_->AddDevice(session_id_, this); |
44 } | 46 } |
45 | 47 |
| 48 int32_t VideoCaptureModuleImpl::AddRef() { |
| 49 VLOG(1) << "VideoCaptureModuleImpl::AddRef()"; |
| 50 return base::subtle::Barrier_AtomicIncrement(&ref_count_, 1); |
| 51 } |
| 52 |
| 53 int32_t VideoCaptureModuleImpl::Release() { |
| 54 VLOG(1) << "VideoCaptureModuleImpl::Release()"; |
| 55 int ret = base::subtle::Barrier_AtomicIncrement(&ref_count_, -1); |
| 56 if (ret == 0) { |
| 57 VLOG(1) << "Reference count is zero, hence this object is now deleted."; |
| 58 delete this; |
| 59 } |
| 60 return ret; |
| 61 } |
| 62 |
46 WebRtc_Word32 VideoCaptureModuleImpl::StartCapture( | 63 WebRtc_Word32 VideoCaptureModuleImpl::StartCapture( |
47 const webrtc::VideoCaptureCapability& capability) { | 64 const webrtc::VideoCaptureCapability& capability) { |
48 message_loop_proxy_->PostTask( | 65 message_loop_proxy_->PostTask( |
49 FROM_HERE, | 66 FROM_HERE, |
50 NewRunnableMethod(this, | 67 NewRunnableMethod(this, |
51 &VideoCaptureModuleImpl::StartCaptureOnCaptureThread, | 68 &VideoCaptureModuleImpl::StartCaptureOnCaptureThread, |
52 capability)); | 69 capability)); |
53 return 0; | 70 return 0; |
54 } | 71 } |
55 | 72 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 225 |
209 IncomingFrame( | 226 IncomingFrame( |
210 static_cast<WebRtc_UWord8*>(buf->memory_pointer), | 227 static_cast<WebRtc_UWord8*>(buf->memory_pointer), |
211 static_cast<WebRtc_Word32>(buf->buffer_size), | 228 static_cast<WebRtc_Word32>(buf->buffer_size), |
212 frameInfo_, | 229 frameInfo_, |
213 static_cast<WebRtc_Word64>( | 230 static_cast<WebRtc_Word64>( |
214 (buf->timestamp - start_time_).InMicroseconds())); | 231 (buf->timestamp - start_time_).InMicroseconds())); |
215 | 232 |
216 capture->FeedBuffer(buf); | 233 capture->FeedBuffer(buf); |
217 } | 234 } |
OLD | NEW |