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

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

Issue 2214533002: move //media/capture to //device/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
(Empty)
1 // Copyright 2014 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.
4
5 #include "media/capture/video/mac/video_capture_device_factory_mac.h"
6
7 #import <IOKit/audio/IOAudioTypes.h>
8 #include <stddef.h>
9
10 #include <utility>
11
12 #include "base/bind.h"
13 #include "base/location.h"
14 #include "base/macros.h"
15 #include "base/profiler/scoped_tracker.h"
16 #include "base/strings/string_util.h"
17 #include "base/task_runner_util.h"
18 #import "media/base/mac/avfoundation_glue.h"
19 #import "media/capture/video/mac/video_capture_device_avfoundation_mac.h"
20 #import "media/capture/video/mac/video_capture_device_decklink_mac.h"
21 #include "media/capture/video/mac/video_capture_device_mac.h"
22
23 namespace media {
24
25 // Blacklisted devices are identified by a characteristic trailing substring of
26 // uniqueId. At the moment these are just Blackmagic devices.
27 const char* kBlacklistedCamerasIdSignature[] = {"-01FDA82C8A9C"};
28
29 static bool IsDeviceBlacklisted(
30 const VideoCaptureDeviceDescriptor& descriptor) {
31 bool is_device_blacklisted = false;
32 for (size_t i = 0;
33 !is_device_blacklisted && i < arraysize(kBlacklistedCamerasIdSignature);
34 ++i) {
35 is_device_blacklisted =
36 base::EndsWith(descriptor.device_id, kBlacklistedCamerasIdSignature[i],
37 base::CompareCase::INSENSITIVE_ASCII);
38 }
39 DVLOG_IF(2, is_device_blacklisted)
40 << "Blacklisted camera: " << descriptor.display_name
41 << ", id: " << descriptor.device_id;
42 return is_device_blacklisted;
43 }
44
45 VideoCaptureDeviceFactoryMac::VideoCaptureDeviceFactoryMac() {
46 thread_checker_.DetachFromThread();
47 }
48
49 VideoCaptureDeviceFactoryMac::~VideoCaptureDeviceFactoryMac() {
50 }
51
52 std::unique_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::CreateDevice(
53 const VideoCaptureDeviceDescriptor& descriptor) {
54 DCHECK(thread_checker_.CalledOnValidThread());
55 DCHECK_NE(descriptor.capture_api, VideoCaptureApi::UNKNOWN);
56
57 std::unique_ptr<VideoCaptureDevice> capture_device;
58 if (descriptor.capture_api == VideoCaptureApi::MACOSX_DECKLINK) {
59 capture_device.reset(new VideoCaptureDeviceDeckLinkMac(descriptor));
60 } else {
61 VideoCaptureDeviceMac* device = new VideoCaptureDeviceMac(descriptor);
62 capture_device.reset(device);
63 if (!device->Init(descriptor.capture_api)) {
64 LOG(ERROR) << "Could not initialize VideoCaptureDevice.";
65 capture_device.reset();
66 }
67 }
68 return std::unique_ptr<VideoCaptureDevice>(std::move(capture_device));
69 }
70
71 void VideoCaptureDeviceFactoryMac::GetDeviceDescriptors(
72 VideoCaptureDeviceDescriptors* device_descriptors) {
73 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/458397 is
74 // fixed.
75 tracked_objects::ScopedTracker tracking_profile(
76 FROM_HERE_WITH_EXPLICIT_FUNCTION(
77 "458397 VideoCaptureDeviceFactoryMac::GetDeviceDescriptors"));
78 DCHECK(thread_checker_.CalledOnValidThread());
79 // Loop through all available devices and add to |device_descriptors|.
80 NSDictionary* capture_devices;
81 DVLOG(1) << "Enumerating video capture devices using AVFoundation";
82 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames];
83 // Enumerate all devices found by AVFoundation, translate the info for each
84 // to class Name and add it to |device_names|.
85 for (NSString* key in capture_devices) {
86 const std::string device_id = [key UTF8String];
87 const VideoCaptureApi capture_api = VideoCaptureApi::MACOSX_AVFOUNDATION;
88 int transport_type = [[capture_devices valueForKey:key] transportType];
89 // Transport types are defined for Audio devices and reused for video.
90 VideoCaptureTransportType device_transport_type =
91 (transport_type == kIOAudioDeviceTransportTypeBuiltIn ||
92 transport_type == kIOAudioDeviceTransportTypeUSB)
93 ? VideoCaptureTransportType::MACOSX_USB_OR_BUILT_IN
94 : VideoCaptureTransportType::OTHER_TRANSPORT;
95 const std::string model_id = VideoCaptureDeviceMac::GetDeviceModelId(
96 device_id, capture_api, device_transport_type);
97 VideoCaptureDeviceDescriptor descriptor(
98 [[[capture_devices valueForKey:key] deviceName] UTF8String], device_id,
99 model_id, capture_api, device_transport_type);
100 if (IsDeviceBlacklisted(descriptor))
101 continue;
102 device_descriptors->push_back(descriptor);
103 }
104 // Also retrieve Blackmagic devices, if present, via DeckLink SDK API.
105 VideoCaptureDeviceDeckLinkMac::EnumerateDevices(device_descriptors);
106 }
107
108 void VideoCaptureDeviceFactoryMac::GetSupportedFormats(
109 const VideoCaptureDeviceDescriptor& device,
110 VideoCaptureFormats* supported_formats) {
111 DCHECK(thread_checker_.CalledOnValidThread());
112 switch (device.capture_api) {
113 case VideoCaptureApi::MACOSX_AVFOUNDATION:
114 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation";
115 [VideoCaptureDeviceAVFoundation getDevice:device
116 supportedFormats:supported_formats];
117 break;
118 case VideoCaptureApi::MACOSX_DECKLINK:
119 DVLOG(1) << "Enumerating video capture capabilities "
120 << device.display_name;
121 VideoCaptureDeviceDeckLinkMac::EnumerateDeviceCapabilities(
122 device, supported_formats);
123 break;
124 default:
125 NOTREACHED();
126 }
127 }
128
129 // static
130 VideoCaptureDeviceFactory*
131 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory(
132 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
133 return new VideoCaptureDeviceFactoryMac();
134 }
135
136 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698