1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/media/video_capture_impl_manager.h"
8 #include "base/stl_util.h"
9 #include "content/renderer/media/video_capture_impl.h"
10 #include "content/renderer/media/video_capture_message_filter.h"
14 VideoCaptureImplManager::VideoCaptureImplManager()
15 : thread_("VC manager") {
17 message_loop_proxy_
= thread_
.message_loop_proxy();
18 filter_
= new VideoCaptureMessageFilter();
21 media::VideoCapture
* VideoCaptureImplManager::AddDevice(
22 media::VideoCaptureSessionId id
,
23 media::VideoCapture::EventHandler
* handler
) {
26 base::AutoLock
auto_lock(lock_
);
27 Devices::iterator it
= devices_
.find(id
);
28 if (it
== devices_
.end()) {
29 VideoCaptureImpl
* vc
=
30 new VideoCaptureImpl(id
, message_loop_proxy_
, filter_
);
31 devices_
[id
] = new Device(vc
, handler
);
36 devices_
[id
]->clients
.push_front(handler
);
37 return it
->second
->vc
;
40 void VideoCaptureImplManager::SuspendDevices(bool suspend
) {
41 base::AutoLock
auto_lock(lock_
);
42 for (Devices::iterator it
= devices_
.begin(); it
!= devices_
.end(); ++it
)
43 it
->second
->vc
->SuspendCapture(suspend
);
46 void VideoCaptureImplManager::RemoveDevice(
47 media::VideoCaptureSessionId id
,
48 media::VideoCapture::EventHandler
* handler
) {
51 base::AutoLock
auto_lock(lock_
);
52 Devices::iterator it
= devices_
.find(id
);
53 if (it
== devices_
.end())
56 size_t size
= it
->second
->clients
.size();
57 it
->second
->clients
.remove(handler
);
59 if (size
== it
->second
->clients
.size() || size
> 1)
62 devices_
[id
]->vc
->DeInit(base::Bind(&VideoCaptureImplManager::FreeDevice
,
63 this, devices_
[id
]->vc
));
68 void VideoCaptureImplManager::FreeDevice(VideoCaptureImpl
* vc
) {
72 VideoCaptureImplManager::~VideoCaptureImplManager() {
74 // TODO(wjia): uncomment the line below after collecting enough info for
76 // STLDeleteContainerPairSecondPointers(devices_.begin(), devices_.end());
79 VideoCaptureImplManager::Device::Device(
80 VideoCaptureImpl
* device
,
81 media::VideoCapture::EventHandler
* handler
)
83 clients
.push_front(handler
);
86 VideoCaptureImplManager::Device::~Device() {}
88 } // namespace content