bool MockConstraints::verifyConstraints(const WebMediaConstraints& constraints, WebString* failedConstraint)
{
    WebVector<WebMediaConstraint> mandatoryConstraints;
    constraints.getMandatoryConstraints(mandatoryConstraints);
    if (mandatoryConstraints.size()) {
        for (size_t i = 0; i < mandatoryConstraints.size(); ++i) {
            const WebMediaConstraint& curr = mandatoryConstraints[i];
            if (!isSupported(curr.m_name) || curr.m_value != "1") {
                if (failedConstraint)
                    *failedConstraint = curr.m_name;
                return false;
            }
        }
    }

    WebVector<WebMediaConstraint> optionalConstraints;
    constraints.getOptionalConstraints(optionalConstraints);
    if (optionalConstraints.size()) {
        for (size_t i = 0; i < optionalConstraints.size(); ++i) {
            const WebMediaConstraint& curr = optionalConstraints[i];
            if (!isValid(curr.m_name) || curr.m_value != "0") {
                if (failedConstraint)
                    *failedConstraint = curr.m_name;
                return false;
            }
        }
    }

    return true;
}
UserMediaRequest* UserMediaRequest::create(ExecutionContext* context, UserMediaController* controller, const Dictionary& options, PassOwnPtr<NavigatorUserMediaSuccessCallback> successCallback, PassOwnPtr<NavigatorUserMediaErrorCallback> errorCallback, ExceptionState& exceptionState)
{
    WebMediaConstraints audio = parseOptions(options, "audio", exceptionState);
    if (exceptionState.hadException())
        return nullptr;

    WebMediaConstraints video = parseOptions(options, "video", exceptionState);
    if (exceptionState.hadException())
        return nullptr;

    if (audio.isNull() && video.isNull()) {
        exceptionState.throwDOMException(SyntaxError, "At least one of audio and video must be requested");
        return nullptr;
    }

    return new UserMediaRequest(context, controller, audio, video, successCallback, errorCallback);
}
Esempio n. 3
0
UserMediaRequest* UserMediaRequest::create(ExecutionContext* context, UserMediaController* controller, const MediaStreamConstraints& options, NavigatorUserMediaSuccessCallback* successCallback, NavigatorUserMediaErrorCallback* errorCallback, MediaErrorState& errorState)
{
    WebMediaConstraints audio = parseOptions(context, options.audio(), errorState);
    if (errorState.hadException())
        return nullptr;

    WebMediaConstraints video = parseOptions(context, options.video(), errorState);
    if (errorState.hadException())
        return nullptr;

    if (audio.isNull() && video.isNull()) {
        errorState.throwDOMException(SyntaxError, "At least one of audio and video must be requested");
        return nullptr;
    }

    return new UserMediaRequest(context, controller, audio, video, successCallback, errorCallback);
}
static WebMediaConstraints createFromNamedConstraints(WebVector<WebMediaConstraint>& mandatory, const WebVector<WebMediaConstraint>& optional, MediaErrorState& errorState)
{
    WebMediaTrackConstraintSet basic;
    WebMediaTrackConstraintSet advanced;
    WebMediaConstraints constraints;
    if (RuntimeEnabledFeatures::mediaConstraintsEnabled()) {
        parseOldStyleNames(mandatory, basic, errorState);
        if (errorState.hadException())
            return constraints;
        // We ignore errors in optional constraints.
        MediaErrorState ignoredErrorState;
        parseOldStyleNames(optional, advanced, ignoredErrorState);
    }
    WebVector<WebMediaTrackConstraintSet> advancedVector(&advanced, 1);
    // Use the 4-argument initializer until Chrome has been converted.
    constraints.initialize(optional, mandatory, basic, advancedVector);
    return constraints;
}
WebMediaConstraints create(const MediaTrackConstraintSet& constraintsIn, MediaErrorState& errorState)
{
    WebMediaConstraints constraints;
    WebMediaTrackConstraintSet constraintBuffer;
    WebVector<WebMediaTrackConstraintSet> advancedBuffer;
    copyConstraints(constraintsIn, constraintBuffer);
    // TODO(hta): Add initialization of advanced constraints once present.
    // https://crbug.com/253412
    if (constraintsIn.hasOptional() || constraintsIn.hasMandatory()) {
        if (!constraintBuffer.isEmpty()) {
            errorState.throwTypeError("Malformed constraint: Cannot use both optional/mandatory and specific constraints.");
            return WebMediaConstraints();
        }
        WebVector<WebMediaConstraint> optional;
        WebVector<WebMediaConstraint> mandatory;
        if (!parse(constraintsIn, optional, mandatory)) {
            errorState.throwTypeError("Malformed constraints object.");
            return WebMediaConstraints();
        }
        return createFromNamedConstraints(mandatory, optional, errorState);
    }
    constraints.initialize(constraintBuffer, advancedBuffer);
    return constraints;
}
WebMediaConstraints create()
{
    WebMediaConstraints constraints;
    constraints.initialize();
    return constraints;
}