Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(659)

Side by Side Diff: media/capture/video/mac/video_capture_device_mac.mm

Issue 1345993002: Change the functions in video_capture_device to pass around PowerLineFrequency enums instead of int… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed formatting issue pointed out of ajose Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "media/capture/video/mac/video_capture_device_mac.h" 5 #include "media/capture/video/mac/video_capture_device_mac.h"
6 6
7 #include <IOKit/IOCFPlugIn.h> 7 #include <IOKit/IOCFPlugIn.h>
8 #include <IOKit/usb/IOUSBLib.h> 8 #include <IOKit/usb/IOUSBLib.h>
9 #include <IOKit/usb/USBSpec.h> 9 #include <IOKit/usb/USBSpec.h>
10 10
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 DLOG(ERROR) << "IOCreatePlugInInterfaceForService"; 182 DLOG(ERROR) << "IOCreatePlugInInterfaceForService";
183 return false; 183 return false;
184 } 184 }
185 return true; 185 return true;
186 } 186 }
187 187
188 // Creates a control interface for |plugin_interface| and produces a command to 188 // Creates a control interface for |plugin_interface| and produces a command to
189 // set the appropriate Power Line frequency for flicker removal. 189 // set the appropriate Power Line frequency for flicker removal.
190 static void SetAntiFlickerInVideoControlInterface( 190 static void SetAntiFlickerInVideoControlInterface(
191 IOCFPlugInInterface** plugin_interface, 191 IOCFPlugInInterface** plugin_interface,
192 const int frequency) { 192 const PowerLineFrequency frequency) {
193 // Create, the control interface for the found plugin, and release 193 // Create, the control interface for the found plugin, and release
194 // the intermediate plugin. 194 // the intermediate plugin.
195 IOUSBInterfaceInterface** control_interface = NULL; 195 IOUSBInterfaceInterface** control_interface = NULL;
196 HRESULT res = 196 HRESULT res =
197 (*plugin_interface) 197 (*plugin_interface)
198 ->QueryInterface(plugin_interface, 198 ->QueryInterface(plugin_interface,
199 CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID), 199 CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID),
200 reinterpret_cast<LPVOID*>(&control_interface)); 200 reinterpret_cast<LPVOID*>(&control_interface));
201 if (!SUCCEEDED(res) || !control_interface) { 201 if (!SUCCEEDED(res) || !control_interface) {
202 DLOG(ERROR) << "Couldn’t create control interface"; 202 DLOG(ERROR) << "Couldn’t create control interface";
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 USBmakebmRequestType(kUSBOut, kUSBClass, kUSBInterface); 242 USBmakebmRequestType(kUSBOut, kUSBClass, kUSBInterface);
243 command.bRequest = kVcRequestCodeSetCur; 243 command.bRequest = kVcRequestCodeSetCur;
244 UInt8 interface_number; 244 UInt8 interface_number;
245 (*control_interface) 245 (*control_interface)
246 ->GetInterfaceNumber(control_interface, &interface_number); 246 ->GetInterfaceNumber(control_interface, &interface_number);
247 command.wIndex = (real_unit_id << 8) | interface_number; 247 command.wIndex = (real_unit_id << 8) | interface_number;
248 const int selector = kPuPowerLineFrequencyControl; 248 const int selector = kPuPowerLineFrequencyControl;
249 command.wValue = (selector << 8); 249 command.wValue = (selector << 8);
250 command.wLength = kPuPowerLineFrequencyControlCommandSize; 250 command.wLength = kPuPowerLineFrequencyControlCommandSize;
251 command.wLenDone = 0; 251 command.wLenDone = 0;
252 int power_line_flag_value = (frequency == 50) ? k50Hz : k60Hz; 252 int power_line_flag_value =
253 (frequency == PowerLineFrequency::FREQUENCY_50HZ) ? k50Hz : k60Hz;
253 command.pData = &power_line_flag_value; 254 command.pData = &power_line_flag_value;
254 255
255 IOReturn ret = 256 IOReturn ret =
256 (*control_interface)->ControlRequest(control_interface, 0, &command); 257 (*control_interface)->ControlRequest(control_interface, 0, &command);
257 DLOG_IF(ERROR, ret != kIOReturnSuccess) << "Anti-flicker control request" 258 DLOG_IF(ERROR, ret != kIOReturnSuccess) << "Anti-flicker control request"
258 << " failed (0x" << std::hex << ret 259 << " failed (0x" << std::hex << ret
259 << "), unit id: " << real_unit_id; 260 << "), unit id: " << real_unit_id;
260 DVLOG_IF(1, ret == kIOReturnSuccess) << "Anti-flicker set to " << frequency 261 DVLOG_IF(1, ret == kIOReturnSuccess) << "Anti-flicker set to "
261 << "Hz"; 262 << static_cast<int>(frequency) << "Hz";
262 263
263 (*control_interface)->USBInterfaceClose(control_interface); 264 (*control_interface)->USBInterfaceClose(control_interface);
264 } 265 }
265 266
266 // Sets the flicker removal in a USB webcam identified by |vendor_id| and 267 // Sets the flicker removal in a USB webcam identified by |vendor_id| and
267 // |product_id|, if available. The process includes first finding all USB 268 // |product_id|, if available. The process includes first finding all USB
268 // devices matching the specified |vendor_id| and |product_id|; for each 269 // devices matching the specified |vendor_id| and |product_id|; for each
269 // matching device, a device interface, and inside it a video control interface 270 // matching device, a device interface, and inside it a video control interface
270 // are created. The latter is used to a send a power frequency setting command. 271 // are created. The latter is used to a send a power frequency setting command.
271 static void SetAntiFlickerInUsbDevice(const int vendor_id, 272 static void SetAntiFlickerInUsbDevice(const int vendor_id,
272 const int product_id, 273 const int product_id,
273 const int frequency) { 274 const PowerLineFrequency frequency) {
274 if (frequency == 0) 275 if (frequency == PowerLineFrequency::FREQUENCY_DEFAULT)
275 return; 276 return;
276 DVLOG(1) << "Setting Power Line Frequency to " << frequency << " Hz, device " 277 DVLOG(1) << "Setting Power Line Frequency to " << static_cast<int>(frequency)
277 << std::hex << vendor_id << "-" << product_id; 278 << " Hz, device " << std::hex << vendor_id << "-" << product_id;
278 279
279 // Compose a search dictionary with vendor and product ID. 280 // Compose a search dictionary with vendor and product ID.
280 CFMutableDictionaryRef query_dictionary = 281 CFMutableDictionaryRef query_dictionary =
281 IOServiceMatching(kIOUSBDeviceClassName); 282 IOServiceMatching(kIOUSBDeviceClassName);
282 CFDictionarySetValue( 283 CFDictionarySetValue(
283 query_dictionary, CFSTR(kUSBVendorName), 284 query_dictionary, CFSTR(kUSBVendorName),
284 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vendor_id)); 285 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vendor_id));
285 CFDictionarySetValue( 286 CFDictionarySetValue(
286 query_dictionary, CFSTR(kUSBProductName), 287 query_dictionary, CFSTR(kUSBProductName),
287 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &product_id)); 288 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &product_id));
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() 561 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height()
561 width:capture_format_.frame_size.width() 562 width:capture_format_.frame_size.width()
562 frameRate:capture_format_.frame_rate]) { 563 frameRate:capture_format_.frame_rate]) {
563 ReceiveError("Could not configure capture device."); 564 ReceiveError("Could not configure capture device.");
564 return false; 565 return false;
565 } 566 }
566 return true; 567 return true;
567 } 568 }
568 569
569 } // namespace media 570 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698