|
Lines 33-39
a/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp_sec1
|
| 33 |
#if ENABLE(MEDIA_STREAM) |
33 |
#if ENABLE(MEDIA_STREAM) |
| 34 |
#include "RealtimeMediaSourceCenterMac.h" |
34 |
#include "RealtimeMediaSourceCenterMac.h" |
| 35 |
|
35 |
|
|
|
36 |
#include "AVAudioCaptureSource.h" |
| 36 |
#include "AVCaptureDeviceManager.h" |
37 |
#include "AVCaptureDeviceManager.h" |
|
|
38 |
#include "AVVideoCaptureSource.h" |
| 37 |
#include "Logging.h" |
39 |
#include "Logging.h" |
| 38 |
#include "MediaStreamPrivate.h" |
40 |
#include "MediaStreamPrivate.h" |
| 39 |
#include <wtf/MainThread.h> |
41 |
#include <wtf/MainThread.h> |
|
Lines 60-65
RealtimeMediaSourceCenterMac::RealtimeMediaSourceCenterMac()
a/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp_sec2
|
| 60 |
m_supportedConstraints.setSupportsEchoCancellation(false); |
62 |
m_supportedConstraints.setSupportsEchoCancellation(false); |
| 61 |
m_supportedConstraints.setSupportsDeviceId(true); |
63 |
m_supportedConstraints.setSupportsDeviceId(true); |
| 62 |
m_supportedConstraints.setSupportsGroupId(true); |
64 |
m_supportedConstraints.setSupportsGroupId(true); |
|
|
65 |
|
| 66 |
m_audioFactory = &AVAudioCaptureSource::factory(); |
| 67 |
m_videoFactory = &AVVideoCaptureSource::factory(); |
| 63 |
} |
68 |
} |
| 64 |
|
69 |
|
| 65 |
RealtimeMediaSourceCenterMac::~RealtimeMediaSourceCenterMac() |
70 |
RealtimeMediaSourceCenterMac::~RealtimeMediaSourceCenterMac() |
|
Lines 73-79
void RealtimeMediaSourceCenterMac::validateRequestConstraints(ValidConstraintsHa
a/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp_sec3
|
| 73 |
String invalidConstraint; |
78 |
String invalidConstraint; |
| 74 |
|
79 |
|
| 75 |
if (audioConstraints.isValid()) { |
80 |
if (audioConstraints.isValid()) { |
| 76 |
audioSourceUIDs = AVCaptureDeviceManager::singleton().bestSourcesForTypeAndConstraints(RealtimeMediaSource::Type::Audio, audioConstraints, invalidConstraint); |
81 |
audioSourceUIDs = bestSourcesForTypeAndConstraints(RealtimeMediaSource::Type::Audio, audioConstraints, invalidConstraint); |
| 77 |
if (!invalidConstraint.isEmpty()) { |
82 |
if (!invalidConstraint.isEmpty()) { |
| 78 |
invalidHandler(invalidConstraint); |
83 |
invalidHandler(invalidConstraint); |
| 79 |
return; |
84 |
return; |
|
Lines 81-87
void RealtimeMediaSourceCenterMac::validateRequestConstraints(ValidConstraintsHa
a/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp_sec4
|
| 81 |
} |
86 |
} |
| 82 |
|
87 |
|
| 83 |
if (videoConstraints.isValid()) { |
88 |
if (videoConstraints.isValid()) { |
| 84 |
videoSourceUIDs = AVCaptureDeviceManager::singleton().bestSourcesForTypeAndConstraints(RealtimeMediaSource::Type::Video, videoConstraints, invalidConstraint); |
89 |
videoSourceUIDs = bestSourcesForTypeAndConstraints(RealtimeMediaSource::Type::Video, videoConstraints, invalidConstraint); |
| 85 |
if (!invalidConstraint.isEmpty()) { |
90 |
if (!invalidConstraint.isEmpty()) { |
| 86 |
invalidHandler(invalidConstraint); |
91 |
invalidHandler(invalidConstraint); |
| 87 |
return; |
92 |
return; |
|
Lines 98-120
void RealtimeMediaSourceCenterMac::createMediaStream(NewMediaStreamHandler compl
a/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp_sec5
|
| 98 |
String invalidConstraint; |
103 |
String invalidConstraint; |
| 99 |
|
104 |
|
| 100 |
if (!audioDeviceID.isEmpty()) { |
105 |
if (!audioDeviceID.isEmpty()) { |
| 101 |
auto audioSource = AVCaptureDeviceManager::singleton().sourceWithUID(audioDeviceID, RealtimeMediaSource::Type::Audio, audioConstraints, invalidConstraint); |
106 |
auto audioDevice = AVCaptureDeviceManager::singleton().deviceWithUID(audioDeviceID, RealtimeMediaSource::Audio); |
|
|
107 |
if (audioDevice && m_audioFactory) { |
| 108 |
if (auto audioSource = m_audioFactory->createMediaSourceForCaptureDeviceWithConstraints(audioDevice.value(), audioConstraints, invalidConstraint)) |
| 109 |
audioSources.append(audioSource.releaseNonNull()); |
| 102 |
#if !LOG_DISABLED |
110 |
#if !LOG_DISABLED |
| 103 |
if (!invalidConstraint.isEmpty()) |
111 |
if (!invalidConstraint.isEmpty()) |
| 104 |
LOG(Media, "RealtimeMediaSourceCenterMac::createMediaStream(%p), audio constraints failed to apply: %s", this, invalidConstraint.utf8().data()); |
112 |
LOG(Media, "RealtimeMediaSourceCenterMac::createMediaStream(%p), audio constraints failed to apply: %s", this, invalidConstraint.utf8().data()); |
| 105 |
#endif |
113 |
#endif |
| 106 |
|
114 |
} |
| 107 |
if (audioSource) |
|
|
| 108 |
audioSources.append(audioSource.releaseNonNull()); |
| 109 |
} |
115 |
} |
| 110 |
if (!videoDeviceID.isEmpty()) { |
116 |
if (!videoDeviceID.isEmpty()) { |
| 111 |
auto videoSource = AVCaptureDeviceManager::singleton().sourceWithUID(videoDeviceID, RealtimeMediaSource::Type::Video, videoConstraints, invalidConstraint); |
117 |
auto videoDevice = AVCaptureDeviceManager::singleton().deviceWithUID(videoDeviceID, RealtimeMediaSource::Video); |
|
|
118 |
if (videoDevice && m_videoFactory) { |
| 119 |
if (auto videoSource = m_videoFactory->createMediaSourceForCaptureDeviceWithConstraints(videoDevice.value(), videoConstraints, invalidConstraint)) |
| 120 |
videoSources.append(videoSource.releaseNonNull()); |
| 112 |
#if !LOG_DISABLED |
121 |
#if !LOG_DISABLED |
| 113 |
if (!invalidConstraint.isEmpty()) |
122 |
if (!invalidConstraint.isEmpty()) |
| 114 |
LOG(Media, "RealtimeMediaSourceCenterMac::createMediaStream(%p), video constraints failed to apply: %s", this, invalidConstraint.utf8().data()); |
123 |
LOG(Media, "RealtimeMediaSourceCenterMac::createMediaStream(%p), video constraints failed to apply: %s", this, invalidConstraint.utf8().data()); |
| 115 |
#endif |
124 |
#endif |
| 116 |
if (videoSource) |
125 |
} |
| 117 |
videoSources.append(videoSource.releaseNonNull()); |
|
|
| 118 |
} |
126 |
} |
| 119 |
|
127 |
|
| 120 |
if (videoSources.isEmpty() && audioSources.isEmpty()) |
128 |
if (videoSources.isEmpty() && audioSources.isEmpty()) |
|
Lines 128-133
Vector<CaptureDevice> RealtimeMediaSourceCenterMac::getMediaStreamDevices()
a/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp_sec6
|
| 128 |
return AVCaptureDeviceManager::singleton().getSourcesInfo(); |
136 |
return AVCaptureDeviceManager::singleton().getSourcesInfo(); |
| 129 |
} |
137 |
} |
| 130 |
|
138 |
|
|
|
139 |
Vector<String> RealtimeMediaSourceCenterMac::bestSourcesForTypeAndConstraints(RealtimeMediaSource::Type type, const MediaConstraints& constraints, String& invalidConstraint) |
| 140 |
{ |
| 141 |
Vector<RefPtr<RealtimeMediaSource>> bestSources; |
| 142 |
|
| 143 |
struct { |
| 144 |
bool operator()(RefPtr<RealtimeMediaSource> a, RefPtr<RealtimeMediaSource> b) |
| 145 |
{ |
| 146 |
return a->fitnessScore() < b->fitnessScore(); |
| 147 |
} |
| 148 |
} sortBasedOnFitnessScore; |
| 149 |
|
| 150 |
CaptureDevice::DeviceType deviceType = type == RealtimeMediaSource::Video ? CaptureDevice::DeviceType::Video : CaptureDevice::DeviceType::Audio; |
| 151 |
for (auto& captureDevice : getMediaStreamDevices()) { |
| 152 |
if (!captureDevice.enabled() || captureDevice.type() != deviceType) |
| 153 |
continue; |
| 154 |
|
| 155 |
RealtimeMediaSource::CaptureFactory* factory = type == RealtimeMediaSource::Video ? m_videoFactory : m_audioFactory; |
| 156 |
if (!factory) |
| 157 |
continue; |
| 158 |
|
| 159 |
if (auto captureSource = factory->createMediaSourceForCaptureDeviceWithConstraints(captureDevice, &constraints, invalidConstraint)) |
| 160 |
bestSources.append(captureSource.leakRef()); |
| 161 |
} |
| 162 |
|
| 163 |
Vector<String> sourceUIDs; |
| 164 |
if (bestSources.isEmpty()) |
| 165 |
return sourceUIDs; |
| 166 |
|
| 167 |
sourceUIDs.reserveInitialCapacity(bestSources.size()); |
| 168 |
std::sort(bestSources.begin(), bestSources.end(), sortBasedOnFitnessScore); |
| 169 |
for (auto& device : bestSources) |
| 170 |
sourceUIDs.uncheckedAppend(device->persistentID()); |
| 171 |
|
| 172 |
return sourceUIDs; |
| 173 |
} |
| 174 |
|
| 175 |
RealtimeMediaSource::CaptureFactory* RealtimeMediaSourceCenterMac::defaultAudioFactory() |
| 176 |
{ |
| 177 |
return &AVAudioCaptureSource::factory(); |
| 178 |
} |
| 179 |
|
| 180 |
RealtimeMediaSource::CaptureFactory* RealtimeMediaSourceCenterMac::defaultVideoFactory() |
| 181 |
{ |
| 182 |
return &AVVideoCaptureSource::factory(); |
| 183 |
} |
| 184 |
|
| 131 |
} // namespace WebCore |
185 |
} // namespace WebCore |
| 132 |
|
186 |
|
| 133 |
#endif // ENABLE(MEDIA_STREAM) |
187 |
#endif // ENABLE(MEDIA_STREAM) |