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/mediarecorder/MediaRecorder.h" | 5 #include "modules/mediarecorder/MediaRecorder.h" |
6 | 6 |
7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
8 #include "core/events/Event.h" | 8 #include "core/events/Event.h" |
9 #include "core/fileapi/Blob.h" | 9 #include "core/fileapi/Blob.h" |
10 #include "modules/EventTargetModules.h" | 10 #include "modules/EventTargetModules.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 case MediaRecorder::State::Paused: | 29 case MediaRecorder::State::Paused: |
30 return "paused"; | 30 return "paused"; |
31 } | 31 } |
32 | 32 |
33 ASSERT_NOT_REACHED(); | 33 ASSERT_NOT_REACHED(); |
34 return String(); | 34 return String(); |
35 } | 35 } |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
| 39 class MediaRecorder::TrackEventListener final : public EventListener { |
| 40 public: |
| 41 static PassRefPtrWillBeRawPtr<TrackEventListener> create(blink::WebMediaReco
rderHandlerClient* client) |
| 42 { |
| 43 return adoptRefWillBeNoop(new TrackEventListener(client)); |
| 44 } |
| 45 |
| 46 bool operator==(const EventListener& other) const override |
| 47 { |
| 48 return this == &other; |
| 49 } |
| 50 |
| 51 private: |
| 52 TrackEventListener(blink::WebMediaRecorderHandlerClient* client) |
| 53 : EventListener(JSEventListenerType) |
| 54 , m_client(client) |
| 55 { |
| 56 } |
| 57 |
| 58 void handleEvent(ExecutionContext* executionContext, Event*) override |
| 59 { |
| 60 m_client->onError("MediaStream got a Track added/removed"); |
| 61 } |
| 62 |
| 63 blink::WebMediaRecorderHandlerClient* const m_client; |
| 64 }; |
| 65 |
39 MediaRecorder* MediaRecorder::create(ExecutionContext* context, MediaStream* str
eam, ExceptionState& exceptionState) | 66 MediaRecorder* MediaRecorder::create(ExecutionContext* context, MediaStream* str
eam, ExceptionState& exceptionState) |
40 { | 67 { |
41 MediaRecorder* recorder = new MediaRecorder(context, stream, MediaRecorderOp
tions(), exceptionState); | 68 MediaRecorder* recorder = new MediaRecorder(context, stream, MediaRecorderOp
tions(), exceptionState); |
42 recorder->suspendIfNeeded(); | 69 recorder->suspendIfNeeded(); |
43 | 70 |
44 return recorder; | 71 return recorder; |
45 } | 72 } |
46 | 73 |
47 MediaRecorder* MediaRecorder::create(ExecutionContext* context, MediaStream* str
eam, const MediaRecorderOptions& options, ExceptionState& exceptionState) | 74 MediaRecorder* MediaRecorder::create(ExecutionContext* context, MediaStream* str
eam, const MediaRecorderOptions& options, ExceptionState& exceptionState) |
48 { | 75 { |
(...skipping 20 matching lines...) Expand all Loading... |
69 // We deviate from the spec by not returning |UnsupportedOption|, see https:
//github.com/w3c/mediacapture-record/issues/18 | 96 // We deviate from the spec by not returning |UnsupportedOption|, see https:
//github.com/w3c/mediacapture-record/issues/18 |
70 if (!m_recorderHandler) { | 97 if (!m_recorderHandler) { |
71 exceptionState.throwDOMException(NotSupportedError, "No MediaRecorder ha
ndler can be created."); | 98 exceptionState.throwDOMException(NotSupportedError, "No MediaRecorder ha
ndler can be created."); |
72 return; | 99 return; |
73 } | 100 } |
74 ContentType contentType(m_mimeType); | 101 ContentType contentType(m_mimeType); |
75 if (!m_recorderHandler->initialize(this, stream->descriptor(), contentType.t
ype(), contentType.parameter("codecs"))) { | 102 if (!m_recorderHandler->initialize(this, stream->descriptor(), contentType.t
ype(), contentType.parameter("codecs"))) { |
76 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ
e native MediaRecorder, the type provided " + m_mimeType + "is unsupported." ); | 103 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ
e native MediaRecorder, the type provided " + m_mimeType + "is unsupported." ); |
77 return; | 104 return; |
78 } | 105 } |
| 106 |
| 107 m_addOrRemoveTrackListener = TrackEventListener::create(this); |
| 108 stream->addEventListener(EventTypeNames::addtrack, m_addOrRemoveTrackListene
r, false); |
| 109 stream->addEventListener(EventTypeNames::removetrack, m_addOrRemoveTrackList
ener, false); |
| 110 |
79 m_stopped = false; | 111 m_stopped = false; |
80 } | 112 } |
81 | 113 |
82 String MediaRecorder::state() const | 114 String MediaRecorder::state() const |
83 { | 115 { |
84 return stateToString(m_state); | 116 return stateToString(m_state); |
85 } | 117 } |
86 | 118 |
87 void MediaRecorder::start(ExceptionState& exceptionState) | 119 void MediaRecorder::start(ExceptionState& exceptionState) |
88 { | 120 { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 297 |
266 DEFINE_TRACE(MediaRecorder) | 298 DEFINE_TRACE(MediaRecorder) |
267 { | 299 { |
268 visitor->trace(m_stream); | 300 visitor->trace(m_stream); |
269 visitor->trace(m_scheduledEvents); | 301 visitor->trace(m_scheduledEvents); |
270 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi
sitor); | 302 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi
sitor); |
271 ActiveDOMObject::trace(visitor); | 303 ActiveDOMObject::trace(visitor); |
272 } | 304 } |
273 | 305 |
274 } // namespace blink | 306 } // namespace blink |
OLD | NEW |