Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(703)

Side by Side Diff: third_party/WebKit/Source/modules/imagecapture/ImageCapture.cpp

Issue 1899403002: MediaStream Image Capture (2): Platform::ImageCaptureFrameGrabber and grabFrame() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. LayoutTests: Replace assert_array_equals with an for-each: assert_aprox_equals Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
12 #include "public/platform/Platform.h" 14 #include "public/platform/Platform.h"
15 #include "public/platform/WebImageCaptureFrameGrabber.h"
16 #include "public/platform/WebMediaStreamTrack.h"
13 17
14 namespace blink { 18 namespace blink {
15 19
16 ImageCapture* ImageCapture::create(ExecutionContext* context, MediaStreamTrack* track, ExceptionState& exceptionState) 20 ImageCapture* ImageCapture::create(ExecutionContext* context, MediaStreamTrack* track, ExceptionState& exceptionState)
17 { 21 {
18 if (track->kind() != "video") { 22 if (track->kind() != "video") {
19 exceptionState.throwDOMException(NotSupportedError, "Cannot create an Im ageCapturer from a non-video Track."); 23 exceptionState.throwDOMException(NotSupportedError, "Cannot create an Im ageCapturer from a non-video Track.");
20 return nullptr; 24 return nullptr;
21 } 25 }
22 26
(...skipping 30 matching lines...) Expand all
53 { 57 {
54 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
55 ScriptPromise promise = resolver->promise(); 59 ScriptPromise promise = resolver->promise();
56 60
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. 61 // 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()) { 62 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.")); 63 resolver->reject(DOMException::create(InvalidStateError, "The associated Track is in an invalid state."));
60 return promise; 64 return promise;
61 } 65 }
62 66
63 resolver->reject(DOMException::create(NotSupportedError, "Not implemented ye t")); 67 // Create |m_frameGrabber| the first time.
68 if (!m_frameGrabber) {
69 m_frameGrabber = adoptPtr(Platform::current()->createImageCaptureFrameGr abber());
70
71 }
72
73 if (!m_frameGrabber) {
74 resolver->reject(DOMException::create(UnknownError, "Couldn't create pla tform resources"));
75 return promise;
76 }
77
78 // The platform does not know about MediaStreamTrack, so we wrap it up.
79 WebMediaStreamTrack track(m_streamTrack->component());
80 m_frameGrabber->grabFrame(&track, new CallbackPromiseAdapter<ImageBitmap, vo id>(resolver));
81
64 return promise; 82 return promise;
65 } 83 }
66 84
67 ImageCapture::ImageCapture(ExecutionContext* context, MediaStreamTrack* track) 85 ImageCapture::ImageCapture(ExecutionContext* context, MediaStreamTrack* track)
68 : ActiveScriptWrappable(this) 86 : ActiveScriptWrappable(this)
69 , ContextLifecycleObserver(context) 87 , ContextLifecycleObserver(context)
70 , m_streamTrack(track) 88 , m_streamTrack(track)
71 { 89 {
72 DCHECK(m_streamTrack); 90 DCHECK(m_streamTrack);
73 } 91 }
74 92
75 bool ImageCapture::addEventListenerInternal(const AtomicString& eventType, Event Listener* listener, const EventListenerOptions& options) 93 bool ImageCapture::addEventListenerInternal(const AtomicString& eventType, Event Listener* listener, const EventListenerOptions& options)
76 { 94 {
77 return EventTarget::addEventListenerInternal(eventType, listener, options); 95 return EventTarget::addEventListenerInternal(eventType, listener, options);
78 } 96 }
79 97
80 DEFINE_TRACE(ImageCapture) 98 DEFINE_TRACE(ImageCapture)
81 { 99 {
82 visitor->trace(m_streamTrack); 100 visitor->trace(m_streamTrack);
83 EventTargetWithInlineData::trace(visitor); 101 EventTargetWithInlineData::trace(visitor);
84 ContextLifecycleObserver::trace(visitor); 102 ContextLifecycleObserver::trace(visitor);
85 } 103 }
86 104
87 } // namespace blink 105 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698