| 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" |
| 11 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
| 12 #include "public/platform/WebCanvasCaptureHandler.h" | 12 #include "public/platform/WebCanvasCaptureHandler.h" |
| 13 #include "public/platform/WebMediaStream.h" | 13 #include "public/platform/WebMediaStream.h" |
| 14 #include "public/platform/WebMediaStreamTrack.h" | 14 #include "public/platform/WebMediaStreamTrack.h" |
| 15 #include "wtf/PtrUtil.h" |
| 16 #include <memory> |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 const double kDefaultFrameRate = 60.0; | 19 const double kDefaultFrameRate = 60.0; |
| 18 } // anonymous namespace | 20 } // anonymous namespace |
| 19 | 21 |
| 20 namespace blink { | 22 namespace blink { |
| 21 | 23 |
| 22 MediaStream* HTMLCanvasElementCapture::captureStream(HTMLCanvasElement& element,
ExceptionState& exceptionState) | 24 MediaStream* HTMLCanvasElementCapture::captureStream(HTMLCanvasElement& element,
ExceptionState& exceptionState) |
| 23 { | 25 { |
| 24 return HTMLCanvasElementCapture::captureStream(element, false, 0, exceptionS
tate); | 26 return HTMLCanvasElementCapture::captureStream(element, false, 0, exceptionS
tate); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 | 38 |
| 37 MediaStream* HTMLCanvasElementCapture::captureStream(HTMLCanvasElement& element,
bool givenFrameRate, double frameRate, ExceptionState& exceptionState) | 39 MediaStream* HTMLCanvasElementCapture::captureStream(HTMLCanvasElement& element,
bool givenFrameRate, double frameRate, ExceptionState& exceptionState) |
| 38 { | 40 { |
| 39 if (!element.originClean()) { | 41 if (!element.originClean()) { |
| 40 exceptionState.throwSecurityError("Canvas is not origin-clean."); | 42 exceptionState.throwSecurityError("Canvas is not origin-clean."); |
| 41 return nullptr; | 43 return nullptr; |
| 42 } | 44 } |
| 43 | 45 |
| 44 WebMediaStreamTrack track; | 46 WebMediaStreamTrack track; |
| 45 const WebSize size(element.width(), element.height()); | 47 const WebSize size(element.width(), element.height()); |
| 46 OwnPtr<WebCanvasCaptureHandler> handler; | 48 std::unique_ptr<WebCanvasCaptureHandler> handler; |
| 47 if (givenFrameRate) | 49 if (givenFrameRate) |
| 48 handler = adoptPtr(Platform::current()->createCanvasCaptureHandler(size,
frameRate, &track)); | 50 handler = wrapUnique(Platform::current()->createCanvasCaptureHandler(siz
e, frameRate, &track)); |
| 49 else | 51 else |
| 50 handler = adoptPtr(Platform::current()->createCanvasCaptureHandler(size,
kDefaultFrameRate, &track)); | 52 handler = wrapUnique(Platform::current()->createCanvasCaptureHandler(siz
e, kDefaultFrameRate, &track)); |
| 51 | 53 |
| 52 if (!handler) { | 54 if (!handler) { |
| 53 exceptionState.throwDOMException(NotSupportedError, "No CanvasCapture ha
ndler can be created."); | 55 exceptionState.throwDOMException(NotSupportedError, "No CanvasCapture ha
ndler can be created."); |
| 54 return nullptr; | 56 return nullptr; |
| 55 } | 57 } |
| 56 | 58 |
| 57 CanvasCaptureMediaStreamTrack* canvasTrack; | 59 CanvasCaptureMediaStreamTrack* canvasTrack; |
| 58 if (givenFrameRate) | 60 if (givenFrameRate) |
| 59 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler), frameRate); | 61 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler), frameRate); |
| 60 else | 62 else |
| 61 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler)); | 63 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler)); |
| 62 // We want to capture a frame in the beginning. | 64 // We want to capture a frame in the beginning. |
| 63 canvasTrack->requestFrame(); | 65 canvasTrack->requestFrame(); |
| 64 | 66 |
| 65 MediaStreamTrackVector tracks; | 67 MediaStreamTrackVector tracks; |
| 66 tracks.append(canvasTrack); | 68 tracks.append(canvasTrack); |
| 67 return MediaStream::create(element.getExecutionContext(), tracks); | 69 return MediaStream::create(element.getExecutionContext(), tracks); |
| 68 } | 70 } |
| 69 | 71 |
| 70 } // namespace blink | 72 } // namespace blink |
| OLD | NEW |