MediaStream* HTMLCanvasElementCapture::captureStream(HTMLCanvasElement& element, bool givenFrameRate, double frameRate, ExceptionState& exceptionState)
{
    if (!element.originClean()) {
        exceptionState.throwSecurityError("Canvas is not origin-clean.");
        return nullptr;
    }

    WebMediaStreamTrack track;
    WebSize size(element.width(), element.height());
    OwnPtr<WebCanvasCaptureHandler> handler;
    if (givenFrameRate)
        handler = adoptPtr(Platform::current()->createCanvasCaptureHandler(size, frameRate, &track));
    else
        handler = adoptPtr(Platform::current()->createCanvasCaptureHandler(size, kDefaultFrameRate, &track));
    ASSERT(handler);
    if (!handler) {
        exceptionState.throwDOMException(NotSupportedError, "No CanvasCapture handler can be created.");
        return nullptr;
    }

    MediaStreamTrackVector tracks;
    if (givenFrameRate)
        tracks.append(CanvasCaptureMediaStreamTrack::create(track, &element, handler.release(), frameRate));
    else
        tracks.append(CanvasCaptureMediaStreamTrack::create(track, &element, handler.release()));
    // We want to capture one frame in the beginning.
    element.notifyListenersCanvasChanged();
    return MediaStream::create(element.executionContext(), tracks);
}
MediaStream* MediaStream::clone(ExecutionContext* context)
{
    MediaStreamTrackVector tracks;
    for (MediaStreamTrackVector::iterator iter = m_audioTracks.begin(); iter != m_audioTracks.end(); ++iter)
        tracks.append((*iter)->clone(context));
    for (MediaStreamTrackVector::iterator iter = m_videoTracks.begin(); iter != m_videoTracks.end(); ++iter)
        tracks.append((*iter)->clone(context));
    return MediaStream::create(context, tracks);
}
MediaStreamTrackVector MediaStream::getTracks()
{
    MediaStreamTrackVector tracks;
    for (MediaStreamTrackVector::iterator iter = m_audioTracks.begin(); iter != m_audioTracks.end(); ++iter)
        tracks.append(iter->get());
    for (MediaStreamTrackVector::iterator iter = m_videoTracks.begin(); iter != m_videoTracks.end(); ++iter)
        tracks.append(iter->get());
    return tracks;
}
Beispiel #4
0
static void processTrack(MediaStreamTrack* track,
                         MediaStreamTrackVector& trackVector) {
  if (track->ended())
    return;

  MediaStreamSource* source = track->component()->source();
  if (!containsSource(trackVector, source))
    trackVector.append(track);
}
MediaStreamTrackVector MediaStream::trackVectorForType(RealtimeMediaSource::Type filterType) const
{
    MediaStreamTrackVector tracks;
    for (auto& track : m_trackSet.values()) {
        if (track->source().type() == filterType)
            tracks.append(track);
    }

    return tracks;
}
RefPtr<MediaStream> MediaStream::clone()
{
    MediaStreamTrackVector clonedTracks;
    clonedTracks.reserveCapacity(m_trackSet.size());

    for (auto& track : m_trackSet.values())
        clonedTracks.append(track->clone());

    return MediaStream::create(*scriptExecutionContext(), clonedTracks);
}
MediaStream* HTMLCanvasElementCapture::captureStream(
    HTMLCanvasElement& element,
    bool givenFrameRate,
    double frameRate,
    ExceptionState& exceptionState) {
    if (!element.originClean()) {
        exceptionState.throwSecurityError("Canvas is not origin-clean.");
        return nullptr;
    }

    WebMediaStreamTrack track;
    const WebSize size(element.width(), element.height());
    std::unique_ptr<WebCanvasCaptureHandler> handler;
    if (givenFrameRate)
        handler = wrapUnique(Platform::current()->createCanvasCaptureHandler(
                                 size, frameRate, &track));
    else
        handler = wrapUnique(Platform::current()->createCanvasCaptureHandler(
                                 size, kDefaultFrameRate, &track));

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

    CanvasCaptureMediaStreamTrack* canvasTrack;
    if (givenFrameRate)
        canvasTrack = CanvasCaptureMediaStreamTrack::create(
                          track, &element, std::move(handler), frameRate);
    else
        canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element,
                      std::move(handler));
    // We want to capture a frame in the beginning.
    canvasTrack->requestFrame();

    MediaStreamTrackVector tracks;
    tracks.append(canvasTrack);
    return MediaStream::create(element.getExecutionContext(), tracks);
}