MediaRecorder::MediaRecorder(ExecutionContext* context, MediaStream* stream, const MediaRecorderOptions& options, ExceptionState& exceptionState)
    : ActiveDOMObject(context)
    , m_stream(stream)
    , m_streamAmountOfTracks(stream->getTracks().size())
    , m_mimeType(options.mimeType())
    , m_stopped(true)
    , m_ignoreMutedMedia(true)
    , m_state(State::Inactive)
    , m_dispatchScheduledEventRunner(AsyncMethodRunner<MediaRecorder>::create(this, &MediaRecorder::dispatchScheduledEvent))
{
    ASSERT(m_stream->getTracks().size());

    m_recorderHandler = adoptPtr(Platform::current()->createMediaRecorderHandler());
    ASSERT(m_recorderHandler);

    // We deviate from the spec by not returning |UnsupportedOption|, see https://github.com/w3c/mediacapture-record/issues/18
    if (!m_recorderHandler) {
        exceptionState.throwDOMException(NotSupportedError, "No MediaRecorder handler can be created.");
        return;
    }
    ContentType contentType(m_mimeType);
    if (!m_recorderHandler->initialize(this, stream->descriptor(), contentType.type(), contentType.parameter("codecs"))) {
        exceptionState.throwDOMException(NotSupportedError, "Failed to initialize native MediaRecorder, the type provided " + m_mimeType + "is unsupported." );
        return;
    }
    m_stopped = false;
}
示例#2
0
MediaRecorder::MediaRecorder(ExecutionContext* context, MediaStream* stream, const MediaRecorderOptions& options, ExceptionState& exceptionState)
    : ActiveDOMObject(context)
    , m_stream(stream)
    , m_streamAmountOfTracks(stream->getTracks().size())
    , m_mimeType(options.mimeType())
    , m_stopped(true)
    , m_ignoreMutedMedia(true)
    , m_state(State::Inactive)
    , m_dispatchScheduledEventRunner(AsyncMethodRunner<MediaRecorder>::create(this, &MediaRecorder::dispatchScheduledEvent))
{
    ASSERT(m_stream->getTracks().size());

    m_recorderHandler = adoptPtr(Platform::current()->createMediaRecorderHandler());
    ASSERT(m_recorderHandler);

    if (!m_recorderHandler) {
        exceptionState.throwDOMException(NotSupportedError, "No MediaRecorder handler can be created.");
        return;
    }

    int32_t audioBitsPerSecond = 0;
    int32_t videoBitsPerSecond = 0;
    AllocateVideoAndAudioBitrates(exceptionState, context, options, stream, &audioBitsPerSecond, &videoBitsPerSecond);

    const ContentType contentType(m_mimeType);
    if (!m_recorderHandler->initialize(this, stream->descriptor(), contentType.type(), contentType.parameter("codecs"), audioBitsPerSecond, videoBitsPerSecond)) {
        exceptionState.throwDOMException(NotSupportedError, "Failed to initialize native MediaRecorder the type provided (" + m_mimeType + ") is not supported.");
        return;
    }
    m_stopped = false;
}