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 "config.h" | 5 #include "config.h" |
6 #include "modules/mediarecorder/MediaRecorder.h" | 6 #include "modules/mediarecorder/MediaRecorder.h" |
7 | 7 |
8 #include "bindings/core/v8/Dictionary.h" | |
8 #include "core/dom/DOMError.h" | 9 #include "core/dom/DOMError.h" |
9 #include "core/fileapi/Blob.h" | 10 #include "core/fileapi/Blob.h" |
10 #include "modules/EventModules.h" | 11 #include "modules/EventModules.h" |
11 #include "modules/EventTargetModules.h" | 12 #include "modules/EventTargetModules.h" |
12 #include "modules/mediarecorder/BlobEvent.h" | 13 #include "modules/mediarecorder/BlobEvent.h" |
13 #include "modules/mediarecorder/MediaRecorderErrorEvent.h" | 14 #include "modules/mediarecorder/MediaRecorderErrorEvent.h" |
14 #include "platform/NotImplemented.h" | 15 #include "platform/NotImplemented.h" |
15 #include "platform/blob/BlobData.h" | 16 #include "platform/blob/BlobData.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" |
(...skipping 14 matching lines...) Expand all Loading... | |
32 } | 33 } |
33 | 34 |
34 ASSERT_NOT_REACHED(); | 35 ASSERT_NOT_REACHED(); |
35 return String(); | 36 return String(); |
36 } | 37 } |
37 | 38 |
38 } // namespace | 39 } // namespace |
39 | 40 |
40 MediaRecorder* MediaRecorder::create(ExecutionContext* context, MediaStream* str eam, ExceptionState& exceptionState) | 41 MediaRecorder* MediaRecorder::create(ExecutionContext* context, MediaStream* str eam, ExceptionState& exceptionState) |
41 { | 42 { |
42 MediaRecorder* recorder = new MediaRecorder(context, stream, String(), excep tionState); | 43 MediaRecorder* recorder = new MediaRecorder(context, stream, MediaRecorderOp tions(), exceptionState); |
43 recorder->suspendIfNeeded(); | 44 recorder->suspendIfNeeded(); |
44 | 45 |
45 return recorder; | 46 return recorder; |
46 } | 47 } |
47 | 48 |
48 MediaRecorder* MediaRecorder::create(ExecutionContext* context, MediaStream* str eam, const String& mimeType, ExceptionState& exceptionState) | 49 MediaRecorder* MediaRecorder::create(ExecutionContext* context, MediaStream* str eam, const MediaRecorderOptions& options, ExceptionState& exceptionState) |
49 { | 50 { |
50 MediaRecorder* recorder = new MediaRecorder(context, stream, mimeType, excep tionState); | 51 MediaRecorder* recorder = new MediaRecorder(context, stream, options, except ionState); |
51 recorder->suspendIfNeeded(); | 52 recorder->suspendIfNeeded(); |
52 | 53 |
53 return recorder; | 54 return recorder; |
54 } | 55 } |
55 | 56 |
56 MediaRecorder::MediaRecorder(ExecutionContext* context, MediaStream* stream, con st String& mimeType, ExceptionState& exceptionState) | 57 MediaRecorder::MediaRecorder(ExecutionContext* context, MediaStream* stream, con st MediaRecorderOptions& options, ExceptionState& exceptionState) |
57 : ActiveDOMObject(context) | 58 : ActiveDOMObject(context) |
58 , m_stream(stream) | 59 , m_stream(stream) |
59 , m_mimeType(mimeType) | 60 , m_mimeType(options.mimeType()) |
60 , m_stopped(true) | 61 , m_stopped(true) |
61 , m_ignoreMutedMedia(true) | 62 , m_ignoreMutedMedia(true) |
62 , m_state(State::Inactive) | 63 , m_state(State::Inactive) |
63 , m_dispatchScheduledEventRunner(this, &MediaRecorder::dispatchScheduledEven t) | 64 , m_dispatchScheduledEventRunner(this, &MediaRecorder::dispatchScheduledEven t) |
64 { | 65 { |
65 ASSERT(m_stream->getTracks().size()); | 66 ASSERT(m_stream->getTracks().size()); |
66 | 67 |
67 m_recorderHandler = adoptPtr(Platform::current()->createMediaRecorderHandler ()); | 68 m_recorderHandler = adoptPtr(Platform::current()->createMediaRecorderHandler ()); |
68 ASSERT(m_recorderHandler); | 69 ASSERT(m_recorderHandler); |
69 | 70 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 145 |
145 void MediaRecorder::requestData(ExceptionState& exceptionState) | 146 void MediaRecorder::requestData(ExceptionState& exceptionState) |
146 { | 147 { |
147 if (m_state != State::Recording) { | 148 if (m_state != State::Recording) { |
148 exceptionState.throwDOMException(InvalidStateError, "The MediaRecorder's state is '" + stateToString(m_state) + "'."); | 149 exceptionState.throwDOMException(InvalidStateError, "The MediaRecorder's state is '" + stateToString(m_state) + "'."); |
149 return; | 150 return; |
150 } | 151 } |
151 writeData(nullptr /* data */, 0 /* length */, true /* lastInSlice */); | 152 writeData(nullptr /* data */, 0 /* length */, true /* lastInSlice */); |
152 } | 153 } |
153 | 154 |
154 String MediaRecorder::canRecordMimeType(const String& mimeType) | 155 bool MediaRecorder::isTypeSupported(const String& type) |
155 { | 156 { |
156 RawPtr<WebMediaRecorderHandler> handler = Platform::current()->createMediaRe corderHandler(); | 157 RawPtr<WebMediaRecorderHandler> handler = Platform::current()->createMediaRe corderHandler(); |
157 if (!handler) | 158 if (!handler) |
158 return emptyString(); | 159 return false; |
159 | 160 |
160 // MediaRecorder canRecordMimeType() MUST return 'probably' "if the UA is | 161 // If true is returned from this method, it only indicates that the |
161 // confident that mimeType represents a type that it can record" [1], but a | 162 // MediaRecorder implementation is capable of recording Blob objects for the |
162 // number of reasons could prevent the recording from happening as expected, | 163 // specified MIME type. Recording may still fail if sufficient resources are |
163 // so 'maybe' is a better option: "Implementors are encouraged to return | 164 // not available to support the concrete media encoding. |
164 // "maybe" unless the type can be confidently established as being supported | |
165 // or not.". Hence this method returns '' or 'maybe', never 'probably'. | |
166 // [1] http://w3c.github.io/mediacapture-record/MediaRecorder.html#methods | 165 // [1] http://w3c.github.io/mediacapture-record/MediaRecorder.html#methods |
Peter Beverloo
2015/12/10 20:28:53
nit: the [1] reference is gone
mcasas
2015/12/10 21:40:40
I was probably messing up with the github, I just
| |
167 return handler->canSupportMimeType(mimeType) ? "maybe" : emptyString(); | 166 return handler->canSupportMimeType(type); |
168 } | 167 } |
169 | 168 |
170 const AtomicString& MediaRecorder::interfaceName() const | 169 const AtomicString& MediaRecorder::interfaceName() const |
171 { | 170 { |
172 return EventTargetNames::MediaRecorder; | 171 return EventTargetNames::MediaRecorder; |
173 } | 172 } |
174 | 173 |
175 ExecutionContext* MediaRecorder::executionContext() const | 174 ExecutionContext* MediaRecorder::executionContext() const |
176 { | 175 { |
177 return ActiveDOMObject::executionContext(); | 176 return ActiveDOMObject::executionContext(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 | 280 |
282 DEFINE_TRACE(MediaRecorder) | 281 DEFINE_TRACE(MediaRecorder) |
283 { | 282 { |
284 visitor->trace(m_stream); | 283 visitor->trace(m_stream); |
285 visitor->trace(m_scheduledEvents); | 284 visitor->trace(m_scheduledEvents); |
286 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi sitor); | 285 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi sitor); |
287 ActiveDOMObject::trace(visitor); | 286 ActiveDOMObject::trace(visitor); |
288 } | 287 } |
289 | 288 |
290 } // namespace blink | 289 } // namespace blink |
OLD | NEW |