blob: 68570e51cfec210290591ff7af464d663bac9ca1 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mflodman@webrtc.orgc80d9d92012-02-06 10:11:25 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000011#include "webrtc/video_engine/vie_input_manager.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <assert.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000014
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000015#include "webrtc/common_types.h"
andrew@webrtc.org94caca72012-10-30 21:58:00 +000016#include "webrtc/modules/video_capture/include/video_capture_factory.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000017#include "webrtc/modules/video_coding/main/interface/video_coding.h"
18#include "webrtc/modules/video_coding/main/interface/video_coding_defines.h"
19#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000020#include "webrtc/system_wrappers/interface/logging.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000021#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000022#include "webrtc/video_engine/include/vie_errors.h"
23#include "webrtc/video_engine/vie_capturer.h"
24#include "webrtc/video_engine/vie_defines.h"
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000025
niklase@google.com470e71d2011-07-07 08:21:25 +000026namespace webrtc {
27
andresp@webrtc.org7707d062013-05-13 10:50:50 +000028ViEInputManager::ViEInputManager(const int engine_id, const Config& config)
29 : config_(config),
30 engine_id_(engine_id),
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +000031 map_cs_(CriticalSectionWrapper::CreateCriticalSection()),
pbos@webrtc.org927296f2013-03-08 13:12:29 +000032 device_info_cs_(CriticalSectionWrapper::CreateCriticalSection()),
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000033 vie_frame_provider_map_(),
34 capture_device_info_(NULL),
35 module_process_thread_(NULL) {
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000036 for (int idx = 0; idx < kViEMaxCaptureDevices; idx++) {
37 free_capture_device_id_[idx] = true;
38 }
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000039}
niklase@google.com470e71d2011-07-07 08:21:25 +000040
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000041ViEInputManager::~ViEInputManager() {
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +000042 for (FrameProviderMap::iterator it = vie_frame_provider_map_.begin();
43 it != vie_frame_provider_map_.end();
44 ++it) {
45 delete it->second;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000046 }
47
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +000048 delete capture_device_info_;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000049}
50void ViEInputManager::SetModuleProcessThread(
mflodman@webrtc.org8baed512012-06-21 12:11:50 +000051 ProcessThread* module_process_thread) {
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000052 assert(!module_process_thread_);
mflodman@webrtc.org8baed512012-06-21 12:11:50 +000053 module_process_thread_ = module_process_thread;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000054}
55
56int ViEInputManager::NumberOfCaptureDevices() {
pbos@webrtc.org927296f2013-03-08 13:12:29 +000057 CriticalSectionScoped cs(device_info_cs_.get());
58 if (capture_device_info_ == NULL)
59 capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
60 ViEModuleId(engine_id_));
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000061 assert(capture_device_info_);
62 return capture_device_info_->NumberOfDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +000063}
64
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000065int ViEInputManager::GetDeviceName(uint32_t device_number,
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000066 char* device_nameUTF8,
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000067 uint32_t device_name_length,
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000068 char* device_unique_idUTF8,
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000069 uint32_t device_unique_idUTF8Length) {
pbos@webrtc.org927296f2013-03-08 13:12:29 +000070 CriticalSectionScoped cs(device_info_cs_.get());
71 if (capture_device_info_ == NULL)
72 capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
73 ViEModuleId(engine_id_));
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000074 assert(capture_device_info_);
75 return capture_device_info_->GetDeviceName(device_number, device_nameUTF8,
76 device_name_length,
77 device_unique_idUTF8,
78 device_unique_idUTF8Length);
niklase@google.com470e71d2011-07-07 08:21:25 +000079}
80
niklase@google.com470e71d2011-07-07 08:21:25 +000081int ViEInputManager::NumberOfCaptureCapabilities(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000082 const char* device_unique_idUTF8) {
pbos@webrtc.org927296f2013-03-08 13:12:29 +000083 CriticalSectionScoped cs(device_info_cs_.get());
84 if (capture_device_info_ == NULL)
85 capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
86 ViEModuleId(engine_id_));
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000087 assert(capture_device_info_);
88 return capture_device_info_->NumberOfCapabilities(device_unique_idUTF8);
niklase@google.com470e71d2011-07-07 08:21:25 +000089}
90
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000091int ViEInputManager::GetCaptureCapability(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000092 const char* device_unique_idUTF8,
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000093 const uint32_t device_capability_number,
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000094 CaptureCapability& capability) {
pbos@webrtc.org927296f2013-03-08 13:12:29 +000095 CriticalSectionScoped cs(device_info_cs_.get());
96 if (capture_device_info_ == NULL)
97 capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
98 ViEModuleId(engine_id_));
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +000099 assert(capture_device_info_);
100 VideoCaptureCapability module_capability;
101 int result = capture_device_info_->GetCapability(device_unique_idUTF8,
102 device_capability_number,
103 module_capability);
104 if (result != 0)
niklase@google.com470e71d2011-07-07 08:21:25 +0000105 return result;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000106
107 // Copy from module type to public type.
108 capability.expectedCaptureDelay = module_capability.expectedCaptureDelay;
109 capability.height = module_capability.height;
110 capability.width = module_capability.width;
111 capability.interlaced = module_capability.interlaced;
112 capability.rawType = module_capability.rawType;
113 capability.codecType = module_capability.codecType;
114 capability.maxFPS = module_capability.maxFPS;
115 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116}
117
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000118int ViEInputManager::GetOrientation(const char* device_unique_idUTF8,
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000119 RotateCapturedFrame& orientation) {
pbos@webrtc.org927296f2013-03-08 13:12:29 +0000120 CriticalSectionScoped cs(device_info_cs_.get());
121 if (capture_device_info_ == NULL)
122 capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
123 ViEModuleId(engine_id_));
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000124 assert(capture_device_info_);
125 VideoCaptureRotation module_orientation;
126 int result = capture_device_info_->GetOrientation(device_unique_idUTF8,
127 module_orientation);
128 // Copy from module type to public type.
129 switch (module_orientation) {
130 case kCameraRotate0:
131 orientation = RotateCapturedFrame_0;
132 break;
133 case kCameraRotate90:
134 orientation = RotateCapturedFrame_90;
135 break;
136 case kCameraRotate180:
137 orientation = RotateCapturedFrame_180;
138 break;
139 case kCameraRotate270:
140 orientation = RotateCapturedFrame_270;
141 break;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000142 }
143 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000144}
145
niklase@google.com470e71d2011-07-07 08:21:25 +0000146int ViEInputManager::DisplayCaptureSettingsDialogBox(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000147 const char* device_unique_idUTF8,
148 const char* dialog_titleUTF8,
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000149 void* parent_window,
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000150 uint32_t positionX,
151 uint32_t positionY) {
pbos@webrtc.org927296f2013-03-08 13:12:29 +0000152 CriticalSectionScoped cs(device_info_cs_.get());
153 if (capture_device_info_ == NULL)
154 capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
155 ViEModuleId(engine_id_));
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000156 assert(capture_device_info_);
157 return capture_device_info_->DisplayCaptureSettingsDialogBox(
158 device_unique_idUTF8, dialog_titleUTF8, parent_window, positionX,
159 positionY);
niklase@google.com470e71d2011-07-07 08:21:25 +0000160}
161
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000162int ViEInputManager::CreateCaptureDevice(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000163 const char* device_unique_idUTF8,
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000164 const uint32_t device_unique_idUTF8Length,
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000165 int& capture_id) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000166 CriticalSectionScoped cs(map_cs_.get());
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000168 // Make sure the device is not already allocated.
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000169 for (FrameProviderMap::iterator it = vie_frame_provider_map_.begin();
170 it != vie_frame_provider_map_.end();
171 ++it) {
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000172 // Make sure this is a capture device.
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000173 if (it->first >= kViECaptureIdBase && it->first <= kViECaptureIdMax) {
174 ViECapturer* vie_capture = static_cast<ViECapturer*>(it->second);
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000175 assert(vie_capture);
176 // TODO(mflodman) Can we change input to avoid this cast?
177 const char* device_name =
178 reinterpret_cast<const char*>(vie_capture->CurrentDeviceName());
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000179 if (strncmp(device_name, device_unique_idUTF8,
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000180 strlen(device_name)) == 0) {
181 return kViECaptureDeviceAlreadyAllocated;
182 }
183 }
184 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000185
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000186 // Make sure the device name is valid.
187 bool found_device = false;
pbos@webrtc.org927296f2013-03-08 13:12:29 +0000188 CriticalSectionScoped cs_devinfo(device_info_cs_.get());
189 if (capture_device_info_ == NULL)
190 capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
191 ViEModuleId(engine_id_));
192 assert(capture_device_info_);
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000193 for (uint32_t device_index = 0;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000194 device_index < capture_device_info_->NumberOfDevices(); ++device_index) {
195 if (device_unique_idUTF8Length > kVideoCaptureUniqueNameLength) {
196 // User's string length is longer than the max.
197 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000198 }
199
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000200 char found_name[kVideoCaptureDeviceNameLength] = "";
201 char found_unique_name[kVideoCaptureUniqueNameLength] = "";
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000202 capture_device_info_->GetDeviceName(device_index, found_name,
203 kVideoCaptureDeviceNameLength,
204 found_unique_name,
205 kVideoCaptureUniqueNameLength);
206
207 // TODO(mflodman) Can we change input to avoid this cast?
208 const char* cast_id = reinterpret_cast<const char*>(device_unique_idUTF8);
209 if (strncmp(cast_id, reinterpret_cast<const char*>(found_unique_name),
210 strlen(cast_id)) == 0) {
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000211 found_device = true;
212 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000213 }
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000214 }
215 if (!found_device) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000216 LOG(LS_ERROR) << "Capture device not found: " << device_unique_idUTF8;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000217 return kViECaptureDeviceDoesNotExist;
218 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000219
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000220 int newcapture_id = 0;
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000221 if (!GetFreeCaptureId(&newcapture_id)) {
222 LOG(LS_ERROR) << "All capture devices already allocated.";
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000223 return kViECaptureDeviceMaxNoDevicesAllocated;
224 }
225 ViECapturer* vie_capture = ViECapturer::CreateViECapture(
andresp@webrtc.org7707d062013-05-13 10:50:50 +0000226 newcapture_id, engine_id_, config_, device_unique_idUTF8,
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000227 device_unique_idUTF8Length, *module_process_thread_);
228 if (!vie_capture) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000229 ReturnCaptureId(newcapture_id);
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000230 return kViECaptureDeviceUnknownError;
231 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000232
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000233 vie_frame_provider_map_[newcapture_id] = vie_capture;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000234 capture_id = newcapture_id;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000235 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000236}
237
mflodman@webrtc.org8baed512012-06-21 12:11:50 +0000238int ViEInputManager::CreateCaptureDevice(VideoCaptureModule* capture_module,
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000239 int& capture_id) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000240 CriticalSectionScoped cs(map_cs_.get());
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000241 int newcapture_id = 0;
mflodman@webrtc.org8baed512012-06-21 12:11:50 +0000242 if (!GetFreeCaptureId(&newcapture_id)) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000243 LOG(LS_ERROR) << "All capture devices already allocated.";
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000244 return kViECaptureDeviceMaxNoDevicesAllocated;
245 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000246
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000247 ViECapturer* vie_capture = ViECapturer::CreateViECapture(
andresp@webrtc.org7707d062013-05-13 10:50:50 +0000248 newcapture_id, engine_id_, config_,
249 capture_module, *module_process_thread_);
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000250 if (!vie_capture) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000251 ReturnCaptureId(newcapture_id);
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000252 return kViECaptureDeviceUnknownError;
253 }
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000254 vie_frame_provider_map_[newcapture_id] = vie_capture;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000255 capture_id = newcapture_id;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000256 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000257}
258
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000259int ViEInputManager::DestroyCaptureDevice(const int capture_id) {
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000260 ViECapturer* vie_capture = NULL;
261 {
262 // We need exclusive access to the object to delete it.
263 // Take this write lock first since the read lock is taken before map_cs_.
mflodman@webrtc.orgcee447a2012-06-28 07:29:46 +0000264 ViEManagerWriteScoped wl(this);
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000265 CriticalSectionScoped cs(map_cs_.get());
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000266
267 vie_capture = ViECapturePtr(capture_id);
268 if (!vie_capture) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000269 LOG(LS_ERROR) << "No such capture device id: " << capture_id;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000270 return -1;
271 }
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000272 uint32_t num_callbacks =
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000273 vie_capture->NumberOfRegisteredFrameCallbacks();
274 if (num_callbacks > 0) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000275 LOG(LS_WARNING) << num_callbacks << " still registered to capture id "
276 << capture_id << " when destroying capture device.";
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000277 }
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000278 vie_frame_provider_map_.erase(capture_id);
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000279 ReturnCaptureId(capture_id);
280 // Leave cs before deleting the capture object. This is because deleting the
281 // object might cause deletions of renderers so we prefer to not have a lock
282 // at that time.
283 }
284 delete vie_capture;
285 return 0;
286}
287
288int ViEInputManager::CreateExternalCaptureDevice(
289 ViEExternalCapture*& external_capture,
290 int& capture_id) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000291 CriticalSectionScoped cs(map_cs_.get());
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000292
293 int newcapture_id = 0;
mflodman@webrtc.org8baed512012-06-21 12:11:50 +0000294 if (GetFreeCaptureId(&newcapture_id) == false) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000295 LOG(LS_ERROR) << "All capture devices already allocated.";
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000296 return kViECaptureDeviceMaxNoDevicesAllocated;
297 }
298
299 ViECapturer* vie_capture = ViECapturer::CreateViECapture(
andresp@webrtc.org7707d062013-05-13 10:50:50 +0000300 newcapture_id, engine_id_, config_, NULL, 0, *module_process_thread_);
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000301 if (!vie_capture) {
302 ReturnCaptureId(newcapture_id);
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000303 return kViECaptureDeviceUnknownError;
304 }
305
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000306 vie_frame_provider_map_[newcapture_id] = vie_capture;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000307 capture_id = newcapture_id;
308 external_capture = vie_capture;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000309 return 0;
310}
311
mflodman@webrtc.org8baed512012-06-21 12:11:50 +0000312bool ViEInputManager::GetFreeCaptureId(int* freecapture_id) {
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000313 for (int id = 0; id < kViEMaxCaptureDevices; id++) {
314 if (free_capture_device_id_[id]) {
315 // We found a free capture device id.
316 free_capture_device_id_[id] = false;
mflodman@webrtc.org8baed512012-06-21 12:11:50 +0000317 *freecapture_id = id + kViECaptureIdBase;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000318 return true;
319 }
320 }
321 return false;
322}
niklase@google.com470e71d2011-07-07 08:21:25 +0000323
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000324void ViEInputManager::ReturnCaptureId(int capture_id) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000325 CriticalSectionScoped cs(map_cs_.get());
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000326 if (capture_id >= kViECaptureIdBase &&
327 capture_id < kViEMaxCaptureDevices + kViECaptureIdBase) {
328 free_capture_device_id_[capture_id - kViECaptureIdBase] = true;
329 }
330 return;
331}
niklase@google.com470e71d2011-07-07 08:21:25 +0000332
niklase@google.com470e71d2011-07-07 08:21:25 +0000333ViEFrameProviderBase* ViEInputManager::ViEFrameProvider(
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000334 const ViEFrameCallback* capture_observer) const {
335 assert(capture_observer);
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000336 CriticalSectionScoped cs(map_cs_.get());
niklase@google.com470e71d2011-07-07 08:21:25 +0000337
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000338 for (FrameProviderMap::const_iterator it = vie_frame_provider_map_.begin();
339 it != vie_frame_provider_map_.end();
340 ++it) {
341 if (it->second->IsFrameCallbackRegistered(capture_observer))
342 return it->second;
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000343 }
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000344
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000345 // No capture device set for this channel.
346 return NULL;
347}
348
349ViEFrameProviderBase* ViEInputManager::ViEFrameProvider(int provider_id) const {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000350 CriticalSectionScoped cs(map_cs_.get());
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000351
352 FrameProviderMap::const_iterator it =
353 vie_frame_provider_map_.find(provider_id);
354 if (it == vie_frame_provider_map_.end())
niklase@google.com470e71d2011-07-07 08:21:25 +0000355 return NULL;
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000356 return it->second;
niklase@google.com470e71d2011-07-07 08:21:25 +0000357}
358
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000359ViECapturer* ViEInputManager::ViECapturePtr(int capture_id) const {
360 if (!(capture_id >= kViECaptureIdBase &&
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000361 capture_id <= kViECaptureIdBase + kViEMaxCaptureDevices)) {
362 LOG(LS_ERROR) << "Capture device doesn't exist " << capture_id << ".";
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000363 return NULL;
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000364 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000365
pbos@webrtc.org4ca7d3f2013-08-12 19:51:57 +0000366 return static_cast<ViECapturer*>(ViEFrameProvider(capture_id));
niklase@google.com470e71d2011-07-07 08:21:25 +0000367}
368
niklase@google.com470e71d2011-07-07 08:21:25 +0000369ViEInputManagerScoped::ViEInputManagerScoped(
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000370 const ViEInputManager& vie_input_manager)
371 : ViEManagerScopedBase(vie_input_manager) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000372}
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000373
374ViECapturer* ViEInputManagerScoped::Capture(int capture_id) const {
375 return static_cast<const ViEInputManager*>(vie_manager_)->ViECapturePtr(
376 capture_id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000377}
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000378
niklase@google.com470e71d2011-07-07 08:21:25 +0000379ViEFrameProviderBase* ViEInputManagerScoped::FrameProvider(
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000380 const ViEFrameCallback* capture_observer) const {
381 return static_cast<const ViEInputManager*>(vie_manager_)->ViEFrameProvider(
382 capture_observer);
niklase@google.com470e71d2011-07-07 08:21:25 +0000383}
384
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000385ViEFrameProviderBase* ViEInputManagerScoped::FrameProvider(
386 int provider_id) const {
387 return static_cast<const ViEInputManager*>(vie_manager_)->ViEFrameProvider(
388 provider_id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000389}
390
mflodman@webrtc.orge8be22c2011-12-15 10:19:29 +0000391} // namespace webrtc