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

Side by Side Diff: Source/modules/mediarecorder/MediaRecorder.cpp

Issue 1354863002: MediaRecorder: Adding BlobEvent and connecting it in MediaRecorderHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: BlobEvent in global-interface-listing-expected.txt, and rebase Created 5 years, 3 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 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 "core/dom/DOMError.h" 8 #include "core/dom/DOMError.h"
9 #include "core/fileapi/Blob.h" 9 #include "core/fileapi/Blob.h"
10 #include "modules/EventModules.h" 10 #include "modules/EventModules.h"
11 #include "modules/EventTargetModules.h" 11 #include "modules/EventTargetModules.h"
12 #include "modules/mediarecorder/BlobEvent.h"
12 #include "modules/mediarecorder/MediaRecorderErrorEvent.h" 13 #include "modules/mediarecorder/MediaRecorderErrorEvent.h"
13 #include "platform/NotImplemented.h" 14 #include "platform/NotImplemented.h"
14 #include "platform/blob/BlobData.h" 15 #include "platform/blob/BlobData.h"
15 #include "public/platform/Platform.h" 16 #include "public/platform/Platform.h"
16 #include "public/platform/WebMediaStream.h" 17 #include "public/platform/WebMediaStream.h"
17 18
18 namespace blink { 19 namespace blink {
19 20
20 namespace { 21 namespace {
21 22
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 m_recorderHandler->resume(); 146 m_recorderHandler->resume();
146 } 147 }
147 148
148 void MediaRecorder::requestData(ExceptionState& exceptionState) 149 void MediaRecorder::requestData(ExceptionState& exceptionState)
149 { 150 {
150 if (m_state != State::Recording) { 151 if (m_state != State::Recording) {
151 exceptionState.throwDOMException(InvalidStateError, "The MediaRecorder's state is '" + stateToString(m_state) + "'."); 152 exceptionState.throwDOMException(InvalidStateError, "The MediaRecorder's state is '" + stateToString(m_state) + "'.");
152 return; 153 return;
153 } 154 }
154 155
155 createBlobEvent(BlobData::create()); 156 createBlobEvent(nullptr);
156 } 157 }
157 158
158 String MediaRecorder::canRecordMimeType(const String& mimeType) 159 String MediaRecorder::canRecordMimeType(const String& mimeType)
159 { 160 {
160 RawPtr<WebMediaRecorderHandler> handler = Platform::current()->createMediaRe corderHandler(); 161 RawPtr<WebMediaRecorderHandler> handler = Platform::current()->createMediaRe corderHandler();
161 if (!handler) 162 if (!handler)
162 return emptyString(); 163 return emptyString();
163 164
164 // MediaRecorder canRecordMimeType() MUST return 'probably' "if the UA is 165 // MediaRecorder canRecordMimeType() MUST return 'probably' "if the UA is
165 // confident that mimeType represents a type that it can record" [1], but a 166 // confident that mimeType represents a type that it can record" [1], but a
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 206
206 void MediaRecorder::writeData(const char* data, size_t length, bool lastInSlice) 207 void MediaRecorder::writeData(const char* data, size_t length, bool lastInSlice)
207 { 208 {
208 if (!lastInSlice && m_stopped) { 209 if (!lastInSlice && m_stopped) {
209 m_stopped = false; 210 m_stopped = false;
210 scheduleDispatchEvent(Event::create(EventTypeNames::start)); 211 scheduleDispatchEvent(Event::create(EventTypeNames::start));
211 } 212 }
212 213
213 // TODO(mcasas): Act as |m_ignoredMutedMedia| instructs if |m_stream| track( s) is in muted() state. 214 // TODO(mcasas): Act as |m_ignoredMutedMedia| instructs if |m_stream| track( s) is in muted() state.
214 // TODO(mcasas): Use |lastInSlice| to indicate to JS that recording is done. 215 // TODO(mcasas): Use |lastInSlice| to indicate to JS that recording is done.
215
216 OwnPtr<BlobData> blobData = BlobData::create(); 216 OwnPtr<BlobData> blobData = BlobData::create();
217 blobData->appendBytes(data, length); 217 blobData->appendBytes(data, length);
218 createBlobEvent(blobData.release()); 218 createBlobEvent(Blob::create(BlobDataHandle::create(blobData.release(), leng th)));
219 } 219 }
220 220
221 void MediaRecorder::failOutOfMemory(const WebString& message) 221 void MediaRecorder::failOutOfMemory(const WebString& message)
222 { 222 {
223 scheduleDispatchEvent(MediaRecorderErrorEvent::create( 223 scheduleDispatchEvent(MediaRecorderErrorEvent::create(
224 EventTypeNames::error, false, false, "OutOfMemory", message)); 224 EventTypeNames::error, false, false, "OutOfMemory", message));
225 225
226 if (m_state == State::Recording) 226 if (m_state == State::Recording)
227 stopRecording(); 227 stopRecording();
228 } 228 }
229 229
230 void MediaRecorder::failIllegalStreamModification(const WebString& message) 230 void MediaRecorder::failIllegalStreamModification(const WebString& message)
231 { 231 {
232 scheduleDispatchEvent(MediaRecorderErrorEvent::create( 232 scheduleDispatchEvent(MediaRecorderErrorEvent::create(
233 EventTypeNames::error, false, false, "IllegalStreamModification", messag e)); 233 EventTypeNames::error, false, false, "IllegalStreamModification", messag e));
234 234
235 if (m_state == State::Recording) 235 if (m_state == State::Recording)
236 stopRecording(); 236 stopRecording();
237 } 237 }
238 238
239 void MediaRecorder::failOtherRecordingError(const WebString& message) 239 void MediaRecorder::failOtherRecordingError(const WebString& message)
240 { 240 {
241 scheduleDispatchEvent(MediaRecorderErrorEvent::create( 241 scheduleDispatchEvent(MediaRecorderErrorEvent::create(
242 EventTypeNames::error, false, false, "OtherRecordingError", message)); 242 EventTypeNames::error, false, false, "OtherRecordingError", message));
243 243
244 if (m_state == State::Recording) 244 if (m_state == State::Recording)
245 stopRecording(); 245 stopRecording();
246 } 246 }
247 247
248 void MediaRecorder::createBlobEvent(PassOwnPtr<BlobData> blobData) 248 void MediaRecorder::createBlobEvent(Blob* blob)
249 { 249 {
250 // TODO(mcasas): Launch a BlobEvent when that class is landed, but also see https://github.com/w3c/mediacapture-record/issues/17. 250 // TODO(mcasas): Consider launching an Event with a TypedArray inside, see h ttps://github.com/w3c/mediacapture-record/issues/17.
251 notImplemented(); 251 scheduleDispatchEvent(BlobEvent::create(EventTypeNames::dataavailable, blob) );
252 } 252 }
253 253
254 void MediaRecorder::stopRecording() 254 void MediaRecorder::stopRecording()
255 { 255 {
256 ASSERT(m_state != State::Inactive); 256 ASSERT(m_state != State::Inactive);
257 m_state = State::Inactive; 257 m_state = State::Inactive;
258 258
259 m_recorderHandler->stop(); 259 m_recorderHandler->stop();
260 260
261 createBlobEvent(BlobData::create()); 261 createBlobEvent(nullptr);
262 262
263 scheduleDispatchEvent(Event::create(EventTypeNames::stop)); 263 scheduleDispatchEvent(Event::create(EventTypeNames::stop));
264 } 264 }
265 265
266 void MediaRecorder::scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event> event) 266 void MediaRecorder::scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event> event)
267 { 267 {
268 m_scheduledEvents.append(event); 268 m_scheduledEvents.append(event);
269 269
270 m_dispatchScheduledEventRunner.runAsync(); 270 m_dispatchScheduledEventRunner.runAsync();
271 } 271 }
272 272
273 void MediaRecorder::dispatchScheduledEvent() 273 void MediaRecorder::dispatchScheduledEvent()
274 { 274 {
275 WillBeHeapVector<RefPtrWillBeMember<Event>> events; 275 WillBeHeapVector<RefPtrWillBeMember<Event>> events;
276 events.swap(m_scheduledEvents); 276 events.swap(m_scheduledEvents);
277 277
278 for (const auto& event : events) 278 for (const auto& event : events)
279 dispatchEvent(event); 279 dispatchEvent(event);
280 } 280 }
281 281
282 DEFINE_TRACE(MediaRecorder) 282 DEFINE_TRACE(MediaRecorder)
283 { 283 {
284 visitor->trace(m_stream); 284 visitor->trace(m_stream);
285 visitor->trace(m_scheduledEvents); 285 visitor->trace(m_scheduledEvents);
286 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi sitor); 286 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi sitor);
287 ActiveDOMObject::trace(visitor); 287 ActiveDOMObject::trace(visitor);
288 } 288 }
289 289
290 } // namespace blink 290 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/mediarecorder/MediaRecorder.h ('k') | Source/modules/mediarecorder/MediaRecorder.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698