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

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: Refactoring of VideoCaptureDeviceFactory interface Created 4 years, 5 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.friendly_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::Create(
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, VideoCaptureApiType::API_TYPE_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 == VideoCaptureApiType::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) {
85 int transport_type = [[capture_devices valueForKey:key] transportType]; 86 int transport_type = [[capture_devices valueForKey:key] transportType];
86 // Transport types are defined for Audio devices and reused for video. 87 // Transport types are defined for Audio devices and reused for video.
87 VideoCaptureDevice::Name::TransportType device_transport_type = 88 VideoCaptureTransportType device_transport_type =
88 (transport_type == kIOAudioDeviceTransportTypeBuiltIn || 89 (transport_type == kIOAudioDeviceTransportTypeBuiltIn ||
89 transport_type == kIOAudioDeviceTransportTypeUSB) 90 transport_type == kIOAudioDeviceTransportTypeUSB)
90 ? VideoCaptureDevice::Name::USB_OR_BUILT_IN 91 ? VideoCaptureTransportType::MACOSX_USB_OR_BUILT_IN
91 : VideoCaptureDevice::Name::OTHER_TRANSPORT; 92 : VideoCaptureTransportType::OTHER_TRANSPORT;
92 VideoCaptureDevice::Name name( 93 VideoCaptureDeviceDescriptor descriptor;
93 [[[capture_devices valueForKey:key] deviceName] UTF8String], 94 descriptor.friendly_name =
94 [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION, 95 [[[capture_devices valueForKey:key] deviceName] UTF8String];
95 device_transport_type); 96 descriptor.device_id = [key UTF8String];
96 if (IsDeviceBlacklisted(name)) 97 descriptor.capture_api = VideoCaptureApiType::MACOSX_AVFOUNDATION;
98 descriptor.transport_type = device_transport_type;
99 if (IsDeviceBlacklisted(descriptor))
97 continue; 100 continue;
98 device_names->push_back(name); 101 device_descriptors->push_back(descriptor);
99 } 102 }
100 // Also retrieve Blackmagic devices, if present, via DeckLink SDK API. 103 // Also retrieve Blackmagic devices, if present, via DeckLink SDK API.
101 VideoCaptureDeviceDeckLinkMac::EnumerateDevices(device_names); 104 VideoCaptureDeviceDeckLinkMac::EnumerateDevices(device_descriptors);
102 } 105 }
103 106
104 void VideoCaptureDeviceFactoryMac::EnumerateDeviceNames( 107 void VideoCaptureDeviceFactoryMac::GetDeviceInfo(
105 const base::Callback< 108 const VideoCaptureDeviceDescriptor& device_descriptor,
106 void(std::unique_ptr<media::VideoCaptureDevice::Names>)>& callback) { 109 VideoCaptureDeviceInfo* device_info) {
107 DCHECK(thread_checker_.CalledOnValidThread()); 110 DCHECK(device_info);
108 std::unique_ptr<VideoCaptureDevice::Names> device_names( 111 device_info->descriptor = device_descriptor;
109 new VideoCaptureDevice::Names()); 112 GetDeviceSupportedFormats(device_descriptor,
110 GetDeviceNames(device_names.get()); 113 &(device_info->supported_formats));
111 callback.Run(std::move(device_names)); 114 device_info->model_id =
115 VideoCaptureDeviceMac::GetDeviceModelId(device_descriptor);
112 } 116 }
113 117
114 void VideoCaptureDeviceFactoryMac::GetDeviceSupportedFormats( 118 void VideoCaptureDeviceFactoryMac::GetDeviceSupportedFormats(
115 const VideoCaptureDevice::Name& device, 119 const VideoCaptureDeviceDescriptor& device,
116 VideoCaptureFormats* supported_formats) { 120 VideoCaptureFormats* supported_formats) {
117 DCHECK(thread_checker_.CalledOnValidThread()); 121 DCHECK(thread_checker_.CalledOnValidThread());
118 switch (device.capture_api_type()) { 122 switch (device.capture_api) {
119 case VideoCaptureDevice::Name::AVFOUNDATION: 123 case VideoCaptureApiType::MACOSX_AVFOUNDATION:
120 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; 124 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation";
121 [VideoCaptureDeviceAVFoundation getDevice:device 125 [VideoCaptureDeviceAVFoundation getDevice:device
122 supportedFormats:supported_formats]; 126 supportedFormats:supported_formats];
123 break; 127 break;
124 case VideoCaptureDevice::Name::DECKLINK: 128 case VideoCaptureApiType::MACOSX_DECKLINK:
125 DVLOG(1) << "Enumerating video capture capabilities " << device.name(); 129 DVLOG(1) << "Enumerating video capture capabilities "
126 VideoCaptureDeviceDeckLinkMac::EnumerateDeviceCapabilities( 130 << device.friendly_name;
127 device, supported_formats); 131 VideoCaptureDeviceDeckLinkMac::EnumerateDeviceCapabilities(
128 break; 132 device, supported_formats);
129 default: 133 break;
130 NOTREACHED(); 134 default:
135 NOTREACHED();
131 } 136 }
132 } 137 }
133 138
134 // static 139 // static
135 VideoCaptureDeviceFactory* 140 VideoCaptureDeviceFactory*
136 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( 141 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory(
137 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { 142 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
138 return new VideoCaptureDeviceFactoryMac(); 143 return new VideoCaptureDeviceFactoryMac();
139 } 144 }
140 145
141 } // namespace media 146 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698