示例#1
0
void UserMediaRequest::allow(const String& audioDeviceUID, const String& videoDeviceUID)
{
    m_allowedAudioDeviceUID = audioDeviceUID;
    m_allowedVideoDeviceUID = videoDeviceUID;

    RefPtr<UserMediaRequest> protectedThis = this;
    RealtimeMediaSourceCenter::NewMediaStreamHandler callback = [this, protectedThis = WTFMove(protectedThis)](RefPtr<MediaStreamPrivate>&& privateStream) mutable {
        if (!m_scriptExecutionContext)
            return;

        if (!privateStream) {
            deny(MediaAccessDenialReason::HardwareError, emptyString());
            return;
        }

        auto stream = MediaStream::create(*m_scriptExecutionContext, WTFMove(privateStream));
        if (stream->getTracks().isEmpty()) {
            deny(MediaAccessDenialReason::HardwareError, emptyString());
            return;
        }

        for (auto& track : stream->getAudioTracks())
            track->source().startProducingData();

        for (auto& track : stream->getVideoTracks())
            track->source().startProducingData();

        m_promise.resolve(stream);
    };

    RealtimeMediaSourceCenter::singleton().createMediaStream(WTFMove(callback), m_allowedAudioDeviceUID, m_allowedVideoDeviceUID, &m_audioConstraints.get(), &m_videoConstraints.get());
}
示例#2
0
PassRefPtr<MediaStream> MediaStream::clone()
{
    Vector<RefPtr<MediaStreamTrack>> trackSet;

    cloneMediaStreamTrackVector(trackSet, getAudioTracks());
    cloneMediaStreamTrackVector(trackSet, getVideoTracks());
    return MediaStream::create(*scriptExecutionContext(), trackSet);
}