| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/mediacapturefromelement/HTMLCanvasElementCapture.h" | 5 #include "modules/mediacapturefromelement/HTMLCanvasElementCapture.h" |
| 6 | 6 |
| 7 #include "core/dom/ExceptionCode.h" | 7 #include "core/dom/ExceptionCode.h" |
| 8 #include "core/html/HTMLCanvasElement.h" | 8 #include "core/html/HTMLCanvasElement.h" |
| 9 #include "modules/mediacapturefromelement/CanvasCaptureMediaStreamTrack.h" | 9 #include "modules/mediacapturefromelement/CanvasCaptureMediaStreamTrack.h" |
| 10 #include "modules/mediastream/MediaStream.h" | 10 #include "modules/mediastream/MediaStream.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 return HTMLCanvasElementCapture::captureStream(element, true, frameRate, exc
eptionState); | 36 return HTMLCanvasElementCapture::captureStream(element, true, frameRate, exc
eptionState); |
| 37 } | 37 } |
| 38 | 38 |
| 39 MediaStream* HTMLCanvasElementCapture::captureStream(HTMLCanvasElement& element,
bool givenFrameRate, double frameRate, ExceptionState& exceptionState) | 39 MediaStream* HTMLCanvasElementCapture::captureStream(HTMLCanvasElement& element,
bool givenFrameRate, double frameRate, ExceptionState& exceptionState) |
| 40 { | 40 { |
| 41 if (!element.originClean()) { | 41 if (!element.originClean()) { |
| 42 exceptionState.throwSecurityError("Canvas is not origin-clean."); | 42 exceptionState.throwSecurityError("Canvas is not origin-clean."); |
| 43 return nullptr; | 43 return nullptr; |
| 44 } | 44 } |
| 45 | 45 |
| 46 WebMediaStreamTrack track; | 46 |
| 47 const WebSize size(element.width(), element.height()); | 47 const WebSize size(element.width(), element.height()); |
| 48 std::unique_ptr<WebCanvasCaptureHandler> handler; | 48 std::unique_ptr<WebCanvasCaptureHandler> handler; |
| 49 if (givenFrameRate) | |
| 50 handler = wrapUnique(Platform::current()->createCanvasCaptureHandler(siz
e, frameRate, &track)); | |
| 51 else | |
| 52 handler = wrapUnique(Platform::current()->createCanvasCaptureHandler(siz
e, kDefaultFrameRate, &track)); | |
| 53 | 49 |
| 50 handler = wrapUnique(Platform::current()->createCanvasCaptureHandler()); |
| 54 if (!handler) { | 51 if (!handler) { |
| 55 exceptionState.throwDOMException(NotSupportedError, "No CanvasCapture ha
ndler can be created."); | 52 exceptionState.throwDOMException(NotSupportedError, "No CanvasCapture ha
ndler can be created."); |
| 56 return nullptr; | 53 return nullptr; |
| 57 } | 54 } |
| 58 | 55 |
| 56 WebMediaStreamTrack track = handler->createTrack(size, givenFrameRate ? fram
eRate : kDefaultFrameRate); |
| 57 |
| 59 CanvasCaptureMediaStreamTrack* canvasTrack; | 58 CanvasCaptureMediaStreamTrack* canvasTrack; |
| 60 if (givenFrameRate) | 59 if (givenFrameRate) |
| 61 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler), frameRate); | 60 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler), frameRate); |
| 62 else | 61 else |
| 63 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler)); | 62 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler)); |
| 64 // We want to capture a frame in the beginning. | 63 // We want to capture a frame in the beginning. |
| 65 canvasTrack->requestFrame(); | 64 canvasTrack->requestFrame(); |
| 66 | 65 |
| 67 MediaStreamTrackVector tracks; | 66 MediaStreamTrackVector tracks; |
| 68 tracks.append(canvasTrack); | 67 tracks.append(canvasTrack); |
| 69 return MediaStream::create(element.getExecutionContext(), tracks); | 68 return MediaStream::create(element.getExecutionContext(), tracks); |
| 70 } | 69 } |
| 71 | 70 |
| 72 } // namespace blink | 71 } // namespace blink |
| OLD | NEW |