OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/imagecapture/ImageCapture.h" | 5 #include "modules/imagecapture/ImageCapture.h" |
6 | 6 |
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
9 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
11 #include "core/frame/ImageBitmap.h" | |
10 #include "modules/EventTargetModules.h" | 12 #include "modules/EventTargetModules.h" |
11 #include "modules/mediastream/MediaStreamTrack.h" | 13 #include "modules/mediastream/MediaStreamTrack.h" |
14 #include "platform/graphics/StaticBitmapImage.h" | |
emircan
2016/04/26 19:19:31
Extra?
mcasas
2016/04/27 00:51:29
Done.
| |
12 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
16 #include "public/platform/WebImageCaptureFrameGrabber.h" | |
17 #include "public/platform/WebMediaStreamTrack.h" | |
13 | 18 |
14 namespace blink { | 19 namespace blink { |
15 | 20 |
16 ImageCapture* ImageCapture::create(ExecutionContext* context, MediaStreamTrack* track, ExceptionState& exceptionState) | 21 ImageCapture* ImageCapture::create(ExecutionContext* context, MediaStreamTrack* track, ExceptionState& exceptionState) |
17 { | 22 { |
18 if (track->kind() != "video") { | 23 if (track->kind() != "video") { |
19 exceptionState.throwDOMException(NotSupportedError, "Cannot create an Im ageCapturer from a non-video Track."); | 24 exceptionState.throwDOMException(NotSupportedError, "Cannot create an Im ageCapturer from a non-video Track."); |
20 return nullptr; | 25 return nullptr; |
21 } | 26 } |
22 | 27 |
(...skipping 30 matching lines...) Expand all Loading... | |
53 { | 58 { |
54 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 59 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
55 ScriptPromise promise = resolver->promise(); | 60 ScriptPromise promise = resolver->promise(); |
56 | 61 |
57 // Spec instructs to return an exception if the track's ready state is not " live". Also reject if the track is disabled or muted. | 62 // Spec instructs to return an exception if the track's ready state is not " live". Also reject if the track is disabled or muted. |
58 if (m_streamTrack->readyState() != "live" || !m_streamTrack->enabled() || m_ streamTrack->muted()) { | 63 if (m_streamTrack->readyState() != "live" || !m_streamTrack->enabled() || m_ streamTrack->muted()) { |
59 resolver->reject(DOMException::create(InvalidStateError, "The associated Track is in an invalid state.")); | 64 resolver->reject(DOMException::create(InvalidStateError, "The associated Track is in an invalid state.")); |
60 return promise; | 65 return promise; |
61 } | 66 } |
62 | 67 |
63 resolver->reject(DOMException::create(NotSupportedError, "Not implemented ye t")); | 68 // Create |m_frameGrabber| the first time. |
69 if (!m_frameGrabber) | |
70 m_frameGrabber = adoptPtr(Platform::current()->createImageCaptureFrameGr abber()); | |
71 | |
72 if (!m_frameGrabber) { | |
emircan
2016/04/26 19:19:31
Can you move this inside the if on l.69? I dont th
mcasas
2016/04/27 00:51:29
This a get-or-create snippet, right? The first
ti
| |
73 resolver->reject(DOMException::create(UnknownError, "Couldn't create pla tform resources")); | |
74 return promise; | |
75 } | |
76 | |
77 // The platform does not know about MediaStreamTrack, so we wrap it up. | |
78 WebMediaStreamTrack track(m_streamTrack->component()); | |
79 m_frameGrabber->grabFrame(&track, new CallbackPromiseAdapter<ImageBitmap, vo id>(resolver)); | |
80 | |
64 return promise; | 81 return promise; |
65 } | 82 } |
66 | 83 |
67 ImageCapture::ImageCapture(ExecutionContext* context, MediaStreamTrack* track) | 84 ImageCapture::ImageCapture(ExecutionContext* context, MediaStreamTrack* track) |
68 : ActiveScriptWrappable(this) | 85 : ActiveScriptWrappable(this) |
69 , ContextLifecycleObserver(context) | 86 , ContextLifecycleObserver(context) |
70 , m_streamTrack(track) | 87 , m_streamTrack(track) |
71 { | 88 { |
72 DCHECK(m_streamTrack); | 89 DCHECK(m_streamTrack); |
73 } | 90 } |
74 | 91 |
75 bool ImageCapture::addEventListenerInternal(const AtomicString& eventType, Event Listener* listener, const EventListenerOptions& options) | 92 bool ImageCapture::addEventListenerInternal(const AtomicString& eventType, Event Listener* listener, const EventListenerOptions& options) |
76 { | 93 { |
77 return EventTarget::addEventListenerInternal(eventType, listener, options); | 94 return EventTarget::addEventListenerInternal(eventType, listener, options); |
78 } | 95 } |
79 | 96 |
80 DEFINE_TRACE(ImageCapture) | 97 DEFINE_TRACE(ImageCapture) |
81 { | 98 { |
82 visitor->trace(m_streamTrack); | 99 visitor->trace(m_streamTrack); |
83 EventTargetWithInlineData::trace(visitor); | 100 EventTargetWithInlineData::trace(visitor); |
84 ContextLifecycleObserver::trace(visitor); | 101 ContextLifecycleObserver::trace(visitor); |
85 } | 102 } |
86 | 103 |
87 } // namespace blink | 104 } // namespace blink |
OLD | NEW |