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/HTMLMediaElementCapture.h" | 5 #include "modules/mediacapturefromelement/HTMLMediaElementCapture.h" |
6 | 6 |
7 #include "core/dom/ExceptionCode.h" | 7 #include "core/dom/ExceptionCode.h" |
8 #include "core/events/EventListener.h" | |
8 #include "core/html/HTMLMediaElement.h" | 9 #include "core/html/HTMLMediaElement.h" |
9 #include "core/html/track/AudioTrackList.h" | 10 #include "core/html/track/AudioTrackList.h" |
10 #include "core/html/track/VideoTrackList.h" | 11 #include "core/html/track/VideoTrackList.h" |
11 #include "modules/encryptedmedia/HTMLMediaElementEncryptedMedia.h" | 12 #include "modules/encryptedmedia/HTMLMediaElementEncryptedMedia.h" |
12 #include "modules/encryptedmedia/MediaKeys.h" | 13 #include "modules/encryptedmedia/MediaKeys.h" |
13 #include "modules/mediastream/MediaStream.h" | 14 #include "modules/mediastream/MediaStream.h" |
14 #include "modules/mediastream/MediaStreamRegistry.h" | 15 #include "modules/mediastream/MediaStreamRegistry.h" |
15 #include "platform/mediastream/MediaStreamCenter.h" | 16 #include "platform/mediastream/MediaStreamCenter.h" |
16 #include "public/platform/Platform.h" | 17 #include "public/platform/Platform.h" |
17 #include "public/platform/WebMediaStream.h" | 18 #include "public/platform/WebMediaStream.h" |
18 #include "public/platform/WebMediaStreamTrack.h" | 19 #include "public/platform/WebMediaStreamTrack.h" |
19 | 20 |
20 namespace blink { | 21 namespace blink { |
21 | 22 |
23 namespace { | |
24 | |
25 // EventListener class to catch the HTMLMediaElement onEnded event and terminate | |
26 // the MediaStream passed on construction. | |
27 class HTMLMediaElementOnEndedEventListener : public EventListener { | |
haraken
2016/06/29 00:46:59
It looks strange that you have to subclass the Eve
foolip
2016/06/29 10:31:04
If this is all that this API does, do we really ne
| |
28 public: | |
29 static HTMLMediaElementOnEndedEventListener* create(MediaStream* stream) | |
30 { | |
31 return new HTMLMediaElementOnEndedEventListener(stream); | |
32 } | |
33 | |
34 bool operator==(const EventListener& other) const override | |
35 { | |
36 return this == &other; | |
37 } | |
38 | |
39 void handleEvent(ExecutionContext*, Event* event) override | |
40 { | |
41 DCHECK_EQ(EventTypeNames::ended, event->type()); | |
42 if (m_stream) | |
43 m_stream->streamEnded(); | |
foolip
2016/06/29 10:31:04
I think that creating an ended event with scripts
| |
44 } | |
45 | |
46 DEFINE_INLINE_TRACE() | |
47 { | |
48 visitor->trace(m_stream); | |
49 EventListener::trace(visitor); | |
50 } | |
51 | |
52 private: | |
53 explicit HTMLMediaElementOnEndedEventListener(MediaStream* stream) | |
54 : EventListener(CPPEventListenerType) | |
55 , m_stream(stream) | |
56 { | |
57 } | |
58 | |
59 WeakMember<MediaStream> m_stream; | |
60 }; | |
61 | |
62 } // anonymous namespace | |
63 | |
22 // static | 64 // static |
23 MediaStream* HTMLMediaElementCapture::captureStream(HTMLMediaElement& element, E xceptionState& exceptionState) | 65 MediaStream* HTMLMediaElementCapture::captureStream(HTMLMediaElement& element, E xceptionState& exceptionState) |
24 { | 66 { |
25 if (element.currentSrc().isNull()) { | 67 if (element.currentSrc().isNull()) { |
26 exceptionState.throwDOMException(NotSupportedError, "The media element m ust have a source."); | 68 exceptionState.throwDOMException(NotSupportedError, "The media element m ust have a source."); |
27 return nullptr; | 69 return nullptr; |
28 } | 70 } |
29 | 71 |
30 // Avoid capturing from EME-protected Media Elements. | 72 // Avoid capturing from EME-protected Media Elements. |
31 if (HTMLMediaElementEncryptedMedia::mediaKeys(element)) { | 73 if (HTMLMediaElementEncryptedMedia::mediaKeys(element)) { |
(...skipping 11 matching lines...) Expand all Loading... | |
43 webStream.initialize(WebVector<WebMediaStreamTrack>(), WebVector<WebMediaStr eamTrack>()); | 85 webStream.initialize(WebVector<WebMediaStreamTrack>(), WebVector<WebMediaStr eamTrack>()); |
44 MediaStreamCenter::instance().didCreateMediaStream(webStream); | 86 MediaStreamCenter::instance().didCreateMediaStream(webStream); |
45 | 87 |
46 if (element.hasVideo()) | 88 if (element.hasVideo()) |
47 Platform::current()->createHTMLVideoElementCapturer(&webStream, element. webMediaPlayer()); | 89 Platform::current()->createHTMLVideoElementCapturer(&webStream, element. webMediaPlayer()); |
48 if (element.hasAudio()) | 90 if (element.hasAudio()) |
49 Platform::current()->createHTMLAudioElementCapturer(&webStream, element. webMediaPlayer()); | 91 Platform::current()->createHTMLAudioElementCapturer(&webStream, element. webMediaPlayer()); |
50 return MediaStream::create(element.getExecutionContext(), webStream); | 92 return MediaStream::create(element.getExecutionContext(), webStream); |
51 } | 93 } |
52 | 94 |
95 // static | |
96 MediaStream* HTMLMediaElementCapture::captureStreamUntilEnded(HTMLMediaElement& element, ExceptionState& exceptionState) | |
97 { | |
98 MediaStream* stream = captureStream(element, exceptionState); | |
99 | |
100 element.addEventListener(EventTypeNames::ended, HTMLMediaElementOnEndedEvent Listener::create(stream), false); | |
101 | |
102 return stream; | |
103 } | |
104 | |
105 | |
53 } // namespace blink | 106 } // namespace blink |
OLD | NEW |