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 "core/inspector/ConsoleMessage.h" | 10 #include "core/inspector/ConsoleMessage.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 | 156 |
| 157 return recorder; | 157 return recorder; |
| 158 } | 158 } |
| 159 | 159 |
| 160 MediaRecorder::MediaRecorder(ExecutionContext* context, | 160 MediaRecorder::MediaRecorder(ExecutionContext* context, |
| 161 MediaStream* stream, | 161 MediaStream* stream, |
| 162 const MediaRecorderOptions& options, | 162 const MediaRecorderOptions& options, |
| 163 ExceptionState& exceptionState) | 163 ExceptionState& exceptionState) |
| 164 : SuspendableObject(context), | 164 : SuspendableObject(context), |
| 165 m_stream(stream), | 165 m_stream(stream), |
| 166 m_streamAmountOfTracks(stream->getTracks().size()), | |
| 167 m_mimeType(options.hasMimeType() ? options.mimeType() : kDefaultMimeType), | 166 m_mimeType(options.hasMimeType() ? options.mimeType() : kDefaultMimeType), |
| 168 m_stopped(true), | 167 m_stopped(true), |
| 169 m_audioBitsPerSecond(0), | 168 m_audioBitsPerSecond(0), |
| 170 m_videoBitsPerSecond(0), | 169 m_videoBitsPerSecond(0), |
| 171 m_state(State::Inactive), | 170 m_state(State::Inactive), |
| 172 m_dispatchScheduledEventRunner(AsyncMethodRunner<MediaRecorder>::create( | 171 m_dispatchScheduledEventRunner(AsyncMethodRunner<MediaRecorder>::create( |
| 173 this, | 172 this, |
| 174 &MediaRecorder::dispatchScheduledEvent)) { | 173 &MediaRecorder::dispatchScheduledEvent)) { |
| 175 DCHECK(m_stream->getTracks().size()); | 174 DCHECK(m_stream->getTracks().size()); |
| 176 | 175 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 } | 324 } |
| 326 | 325 |
| 327 void MediaRecorder::writeData(const char* data, | 326 void MediaRecorder::writeData(const char* data, |
| 328 size_t length, | 327 size_t length, |
| 329 bool lastInSlice, | 328 bool lastInSlice, |
| 330 double timecode) { | 329 double timecode) { |
| 331 if (m_stopped && !lastInSlice) { | 330 if (m_stopped && !lastInSlice) { |
| 332 m_stopped = false; | 331 m_stopped = false; |
| 333 scheduleDispatchEvent(Event::create(EventTypeNames::start)); | 332 scheduleDispatchEvent(Event::create(EventTypeNames::start)); |
| 334 } | 333 } |
| 335 if (m_stream && m_streamAmountOfTracks != m_stream->getTracks().size()) { | |
| 336 m_streamAmountOfTracks = m_stream->getTracks().size(); | |
| 337 onError("Amount of tracks in MediaStream has changed."); | |
| 338 } | |
| 339 | |
| 340 // TODO(mcasas): Act as |m_ignoredMutedMedia| instructs if |m_stream| track(s) | |
| 341 // is in muted() state. | |
|
emircan
2017/02/17 18:59:25
Is this TODO still relevant or...
mcasas
2017/02/17 20:40:29
No, it was removed from the Spec in
https://githu
| |
| 342 | 334 |
| 343 if (!m_blobData) { | 335 if (!m_blobData) { |
| 344 m_blobData = BlobData::create(); | 336 m_blobData = BlobData::create(); |
| 345 m_blobData->setContentType(m_mimeType); | 337 m_blobData->setContentType(m_mimeType); |
| 346 } | 338 } |
| 347 if (data) | 339 if (data) |
| 348 m_blobData->appendBytes(data, length); | 340 m_blobData->appendBytes(data, length); |
| 349 | 341 |
| 350 if (!lastInSlice) | 342 if (!lastInSlice) |
| 351 return; | 343 return; |
| 352 | 344 |
| 353 // Cache |m_blobData->length()| before release()ng it. | 345 // Cache |m_blobData->length()| before release()ng it. |
| 354 const long long blobDataLength = m_blobData->length(); | 346 const long long blobDataLength = m_blobData->length(); |
| 355 createBlobEvent(Blob::create(BlobDataHandle::create(std::move(m_blobData), | 347 createBlobEvent(Blob::create(BlobDataHandle::create(std::move(m_blobData), |
| 356 blobDataLength)), | 348 blobDataLength)), |
| 357 timecode); | 349 timecode); |
| 358 } | 350 } |
| 359 | 351 |
| 360 void MediaRecorder::onError(const WebString& message) { | 352 void MediaRecorder::onError(const WebString& message) { |
| 361 // TODO(mcasas): Beef up the Error Event and add the |message|, see | 353 DLOG(ERROR) << message.ascii(); |
| 362 // https://github.com/w3c/mediacapture-record/issues/31 | 354 stopRecording(); |
| 363 scheduleDispatchEvent(Event::create(EventTypeNames::error)); | 355 scheduleDispatchEvent(Event::create(EventTypeNames::error)); |
| 364 } | 356 } |
| 365 | 357 |
| 366 void MediaRecorder::createBlobEvent(Blob* blob, double timecode) { | 358 void MediaRecorder::createBlobEvent(Blob* blob, double timecode) { |
| 367 scheduleDispatchEvent( | 359 scheduleDispatchEvent( |
| 368 BlobEvent::create(EventTypeNames::dataavailable, blob, timecode)); | 360 BlobEvent::create(EventTypeNames::dataavailable, blob, timecode)); |
| 369 } | 361 } |
| 370 | 362 |
| 371 void MediaRecorder::stopRecording() { | 363 void MediaRecorder::stopRecording() { |
| 372 DCHECK(m_state != State::Inactive); | 364 DCHECK(m_state != State::Inactive); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 395 | 387 |
| 396 DEFINE_TRACE(MediaRecorder) { | 388 DEFINE_TRACE(MediaRecorder) { |
| 397 visitor->trace(m_stream); | 389 visitor->trace(m_stream); |
| 398 visitor->trace(m_dispatchScheduledEventRunner); | 390 visitor->trace(m_dispatchScheduledEventRunner); |
| 399 visitor->trace(m_scheduledEvents); | 391 visitor->trace(m_scheduledEvents); |
| 400 EventTargetWithInlineData::trace(visitor); | 392 EventTargetWithInlineData::trace(visitor); |
| 401 SuspendableObject::trace(visitor); | 393 SuspendableObject::trace(visitor); |
| 402 } | 394 } |
| 403 | 395 |
| 404 } // namespace blink | 396 } // namespace blink |
| OLD | NEW |