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

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

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

Powered by Google App Engine
This is Rietveld 408576698