Chromium Code Reviews| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 { | 48 { |
| 49 MediaRecorder* recorder = new MediaRecorder(context, stream, options, except ionState); | 49 MediaRecorder* recorder = new MediaRecorder(context, stream, options, except ionState); |
| 50 recorder->suspendIfNeeded(); | 50 recorder->suspendIfNeeded(); |
| 51 | 51 |
| 52 return recorder; | 52 return recorder; |
| 53 } | 53 } |
| 54 | 54 |
| 55 MediaRecorder::MediaRecorder(ExecutionContext* context, MediaStream* stream, con st MediaRecorderOptions& options, ExceptionState& exceptionState) | 55 MediaRecorder::MediaRecorder(ExecutionContext* context, MediaStream* stream, con st MediaRecorderOptions& options, ExceptionState& exceptionState) |
| 56 : ActiveDOMObject(context) | 56 : ActiveDOMObject(context) |
| 57 , m_stream(stream) | 57 , m_stream(stream) |
| 58 , m_streamAmountOfTracks(stream->getTracks().size()) | |
| 58 , m_mimeType(options.mimeType()) | 59 , m_mimeType(options.mimeType()) |
| 59 , m_stopped(true) | 60 , m_stopped(true) |
| 60 , m_ignoreMutedMedia(true) | 61 , m_ignoreMutedMedia(true) |
| 61 , m_state(State::Inactive) | 62 , m_state(State::Inactive) |
| 62 , m_dispatchScheduledEventRunner(this, &MediaRecorder::dispatchScheduledEven t) | 63 , m_dispatchScheduledEventRunner(this, &MediaRecorder::dispatchScheduledEven t) |
| 63 { | 64 { |
| 64 ASSERT(m_stream->getTracks().size()); | 65 ASSERT(m_stream->getTracks().size()); |
| 65 | 66 |
| 66 m_recorderHandler = adoptPtr(Platform::current()->createMediaRecorderHandler ()); | 67 m_recorderHandler = adoptPtr(Platform::current()->createMediaRecorderHandler ()); |
| 67 ASSERT(m_recorderHandler); | 68 ASSERT(m_recorderHandler); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 m_stream.clear(); | 199 m_stream.clear(); |
| 199 m_recorderHandler.clear(); | 200 m_recorderHandler.clear(); |
| 200 } | 201 } |
| 201 | 202 |
| 202 void MediaRecorder::writeData(const char* data, size_t length, bool lastInSlice) | 203 void MediaRecorder::writeData(const char* data, size_t length, bool lastInSlice) |
| 203 { | 204 { |
| 204 if (m_stopped && !lastInSlice) { | 205 if (m_stopped && !lastInSlice) { |
| 205 m_stopped = false; | 206 m_stopped = false; |
| 206 scheduleDispatchEvent(Event::create(EventTypeNames::start)); | 207 scheduleDispatchEvent(Event::create(EventTypeNames::start)); |
| 207 } | 208 } |
| 209 if (m_stream && m_streamAmountOfTracks != m_stream->getTracks().size()) | |
| 210 onError("Amount of tracks in MediaStream has changed."); | |
|
Peter Beverloo
2016/01/13 18:38:01
This fires an `onerror` event each time writeData(
Peter Beverloo
2016/01/13 18:38:01
Will you address the specification bug?
mcasas
2016/01/13 21:50:41
Acknowledged.
mcasas
2016/01/13 21:50:41
Yes, I should update m_streamAmountOfTracks after
| |
| 208 | 211 |
| 209 // TODO(mcasas): Act as |m_ignoredMutedMedia| instructs if |m_stream| track( s) is in muted() state. | 212 // TODO(mcasas): Act as |m_ignoredMutedMedia| instructs if |m_stream| track( s) is in muted() state. |
| 210 | 213 |
| 211 if (!m_blobData) | 214 if (!m_blobData) |
| 212 m_blobData = BlobData::create(); | 215 m_blobData = BlobData::create(); |
| 213 if (data) | 216 if (data) |
| 214 m_blobData->appendBytes(data, length); | 217 m_blobData->appendBytes(data, length); |
| 215 | 218 |
| 216 if (!lastInSlice) | 219 if (!lastInSlice) |
| 217 return; | 220 return; |
| 218 | 221 |
| 219 // Cache |m_blobData->length()| before release()ng it. | 222 // Cache |m_blobData->length()| before release()ng it. |
| 220 const long long blobDataLength = m_blobData->length(); | 223 const long long blobDataLength = m_blobData->length(); |
| 221 createBlobEvent(Blob::create(BlobDataHandle::create(m_blobData.release(), bl obDataLength))); | 224 createBlobEvent(Blob::create(BlobDataHandle::create(m_blobData.release(), bl obDataLength))); |
| 222 } | 225 } |
| 223 | 226 |
| 224 void MediaRecorder::onError(const WebString& message) | 227 void MediaRecorder::onError(const WebString& message) |
| 225 { | 228 { |
| 226 // TODO(mcasas): Beef up the Error Event and add the |message|, see https:// github.com/w3c/mediacapture-record/issues/31 | 229 // TODO(mcasas): Beef up the Error Event and add the |message|, see https:// github.com/w3c/mediacapture-record/issues/31 |
| 227 scheduleDispatchEvent(Event::create(EventTypeNames::error)); | 230 scheduleDispatchEvent(Event::create(EventTypeNames::error)); |
| 228 | |
| 229 if (m_state == State::Recording) | |
| 230 stopRecording(); | |
| 231 } | 231 } |
| 232 | 232 |
| 233 void MediaRecorder::createBlobEvent(Blob* blob) | 233 void MediaRecorder::createBlobEvent(Blob* blob) |
| 234 { | 234 { |
| 235 // TODO(mcasas): Consider launching an Event with a TypedArray inside, see h ttps://github.com/w3c/mediacapture-record/issues/17. | 235 // TODO(mcasas): Consider launching an Event with a TypedArray inside, see h ttps://github.com/w3c/mediacapture-record/issues/17. |
| 236 scheduleDispatchEvent(BlobEvent::create(EventTypeNames::dataavailable, blob) ); | 236 scheduleDispatchEvent(BlobEvent::create(EventTypeNames::dataavailable, blob) ); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void MediaRecorder::stopRecording() | 239 void MediaRecorder::stopRecording() |
| 240 { | 240 { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 265 | 265 |
| 266 DEFINE_TRACE(MediaRecorder) | 266 DEFINE_TRACE(MediaRecorder) |
| 267 { | 267 { |
| 268 visitor->trace(m_stream); | 268 visitor->trace(m_stream); |
| 269 visitor->trace(m_scheduledEvents); | 269 visitor->trace(m_scheduledEvents); |
| 270 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi sitor); | 270 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi sitor); |
| 271 ActiveDOMObject::trace(visitor); | 271 ActiveDOMObject::trace(visitor); |
| 272 } | 272 } |
| 273 | 273 |
| 274 } // namespace blink | 274 } // namespace blink |
| OLD | NEW |