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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 void AllocateVideoAndAudioBitrates(ExceptionState& exceptionState, | 54 void AllocateVideoAndAudioBitrates(ExceptionState& exceptionState, |
55 ExecutionContext* context, | 55 ExecutionContext* context, |
56 const MediaRecorderOptions& options, | 56 const MediaRecorderOptions& options, |
57 MediaStream* stream, | 57 MediaStream* stream, |
58 int* audioBitsPerSecond, | 58 int* audioBitsPerSecond, |
59 int* videoBitsPerSecond) { | 59 int* videoBitsPerSecond) { |
60 const bool useVideo = !stream->getVideoTracks().isEmpty(); | 60 const bool useVideo = !stream->getVideoTracks().isEmpty(); |
61 const bool useAudio = !stream->getAudioTracks().isEmpty(); | 61 const bool useAudio = !stream->getAudioTracks().isEmpty(); |
62 | 62 |
63 // Clamp incoming values into a signed integer's range. | 63 // Clamp incoming values into a signed integer's range. |
64 // TODO(mcasas): This section would no be needed if the bit rates are signed o
r double, see https://github.com/w3c/mediacapture-record/issues/48. | 64 // TODO(mcasas): This section would no be needed if the bit rates are signed |
| 65 // or double, see https://github.com/w3c/mediacapture-record/issues/48. |
65 const unsigned kMaxIntAsUnsigned = std::numeric_limits<int>::max(); | 66 const unsigned kMaxIntAsUnsigned = std::numeric_limits<int>::max(); |
66 | 67 |
67 int overallBps = 0; | 68 int overallBps = 0; |
68 if (options.hasBitsPerSecond()) | 69 if (options.hasBitsPerSecond()) |
69 overallBps = std::min(options.bitsPerSecond(), kMaxIntAsUnsigned); | 70 overallBps = std::min(options.bitsPerSecond(), kMaxIntAsUnsigned); |
70 int videoBps = 0; | 71 int videoBps = 0; |
71 if (options.hasVideoBitsPerSecond() && useVideo) | 72 if (options.hasVideoBitsPerSecond() && useVideo) |
72 videoBps = std::min(options.videoBitsPerSecond(), kMaxIntAsUnsigned); | 73 videoBps = std::min(options.videoBitsPerSecond(), kMaxIntAsUnsigned); |
73 int audioBps = 0; | 74 int audioBps = 0; |
74 if (options.hasAudioBitsPerSecond() && useAudio) | 75 if (options.hasAudioBitsPerSecond() && useAudio) |
(...skipping 28 matching lines...) Expand all Loading... |
103 } | 104 } |
104 } else { | 105 } else { |
105 DCHECK(!audioBps); | 106 DCHECK(!audioBps); |
106 } | 107 } |
107 } | 108 } |
108 | 109 |
109 if (useVideo) { | 110 if (useVideo) { |
110 // Allocate the remaining |overallBps|, if any, to video. | 111 // Allocate the remaining |overallBps|, if any, to video. |
111 if (options.hasBitsPerSecond()) | 112 if (options.hasBitsPerSecond()) |
112 videoBps = overallBps - audioBps; | 113 videoBps = overallBps - audioBps; |
113 // Clamp the video bit rate. Avoid clamping if the user has not set it expli
citly. | 114 // Clamp the video bit rate. Avoid clamping if the user has not set it |
| 115 // explicitly. |
114 if (options.hasVideoBitsPerSecond() || options.hasBitsPerSecond()) { | 116 if (options.hasVideoBitsPerSecond() || options.hasBitsPerSecond()) { |
115 if (videoBps < kSmallestPossibleVpxBitRate) { | 117 if (videoBps < kSmallestPossibleVpxBitRate) { |
116 context->addConsoleMessage(ConsoleMessage::create( | 118 context->addConsoleMessage(ConsoleMessage::create( |
117 JSMessageSource, WarningMessageLevel, | 119 JSMessageSource, WarningMessageLevel, |
118 "Clamping calculated video bitrate (" + String::number(videoBps) + | 120 "Clamping calculated video bitrate (" + String::number(videoBps) + |
119 "bps) to the minimum (" + | 121 "bps) to the minimum (" + |
120 String::number(kSmallestPossibleVpxBitRate) + "bps)")); | 122 String::number(kSmallestPossibleVpxBitRate) + "bps)")); |
121 videoBps = kSmallestPossibleVpxBitRate; | 123 videoBps = kSmallestPossibleVpxBitRate; |
122 } | 124 } |
123 } else { | 125 } else { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 bool lastInSlice) { | 328 bool lastInSlice) { |
327 if (m_stopped && !lastInSlice) { | 329 if (m_stopped && !lastInSlice) { |
328 m_stopped = false; | 330 m_stopped = false; |
329 scheduleDispatchEvent(Event::create(EventTypeNames::start)); | 331 scheduleDispatchEvent(Event::create(EventTypeNames::start)); |
330 } | 332 } |
331 if (m_stream && m_streamAmountOfTracks != m_stream->getTracks().size()) { | 333 if (m_stream && m_streamAmountOfTracks != m_stream->getTracks().size()) { |
332 m_streamAmountOfTracks = m_stream->getTracks().size(); | 334 m_streamAmountOfTracks = m_stream->getTracks().size(); |
333 onError("Amount of tracks in MediaStream has changed."); | 335 onError("Amount of tracks in MediaStream has changed."); |
334 } | 336 } |
335 | 337 |
336 // TODO(mcasas): Act as |m_ignoredMutedMedia| instructs if |m_stream| track(s)
is in muted() state. | 338 // TODO(mcasas): Act as |m_ignoredMutedMedia| instructs if |m_stream| track(s) |
| 339 // is in muted() state. |
337 | 340 |
338 if (!m_blobData) { | 341 if (!m_blobData) { |
339 m_blobData = BlobData::create(); | 342 m_blobData = BlobData::create(); |
340 m_blobData->setContentType(m_mimeType); | 343 m_blobData->setContentType(m_mimeType); |
341 } | 344 } |
342 if (data) | 345 if (data) |
343 m_blobData->appendBytes(data, length); | 346 m_blobData->appendBytes(data, length); |
344 | 347 |
345 if (!lastInSlice) | 348 if (!lastInSlice) |
346 return; | 349 return; |
347 | 350 |
348 // Cache |m_blobData->length()| before release()ng it. | 351 // Cache |m_blobData->length()| before release()ng it. |
349 const long long blobDataLength = m_blobData->length(); | 352 const long long blobDataLength = m_blobData->length(); |
350 createBlobEvent(Blob::create( | 353 createBlobEvent(Blob::create( |
351 BlobDataHandle::create(std::move(m_blobData), blobDataLength))); | 354 BlobDataHandle::create(std::move(m_blobData), blobDataLength))); |
352 } | 355 } |
353 | 356 |
354 void MediaRecorder::onError(const WebString& message) { | 357 void MediaRecorder::onError(const WebString& message) { |
355 // TODO(mcasas): Beef up the Error Event and add the |message|, see https://gi
thub.com/w3c/mediacapture-record/issues/31 | 358 // TODO(mcasas): Beef up the Error Event and add the |message|, see |
| 359 // https://github.com/w3c/mediacapture-record/issues/31 |
356 scheduleDispatchEvent(Event::create(EventTypeNames::error)); | 360 scheduleDispatchEvent(Event::create(EventTypeNames::error)); |
357 } | 361 } |
358 | 362 |
359 void MediaRecorder::createBlobEvent(Blob* blob) { | 363 void MediaRecorder::createBlobEvent(Blob* blob) { |
360 // TODO(mcasas): Consider launching an Event with a TypedArray inside, see htt
ps://github.com/w3c/mediacapture-record/issues/17. | 364 // TODO(mcasas): Consider launching an Event with a TypedArray inside, see |
| 365 // https://github.com/w3c/mediacapture-record/issues/17. |
361 scheduleDispatchEvent(BlobEvent::create(EventTypeNames::dataavailable, blob)); | 366 scheduleDispatchEvent(BlobEvent::create(EventTypeNames::dataavailable, blob)); |
362 } | 367 } |
363 | 368 |
364 void MediaRecorder::stopRecording() { | 369 void MediaRecorder::stopRecording() { |
365 DCHECK(m_state != State::Inactive); | 370 DCHECK(m_state != State::Inactive); |
366 m_state = State::Inactive; | 371 m_state = State::Inactive; |
367 | 372 |
368 m_recorderHandler->stop(); | 373 m_recorderHandler->stop(); |
369 | 374 |
370 writeData(nullptr /* data */, 0 /* length */, true /* lastInSlice */); | 375 writeData(nullptr /* data */, 0 /* length */, true /* lastInSlice */); |
(...skipping 16 matching lines...) Expand all Loading... |
387 | 392 |
388 DEFINE_TRACE(MediaRecorder) { | 393 DEFINE_TRACE(MediaRecorder) { |
389 visitor->trace(m_stream); | 394 visitor->trace(m_stream); |
390 visitor->trace(m_dispatchScheduledEventRunner); | 395 visitor->trace(m_dispatchScheduledEventRunner); |
391 visitor->trace(m_scheduledEvents); | 396 visitor->trace(m_scheduledEvents); |
392 EventTargetWithInlineData::trace(visitor); | 397 EventTargetWithInlineData::trace(visitor); |
393 ActiveDOMObject::trace(visitor); | 398 ActiveDOMObject::trace(visitor); |
394 } | 399 } |
395 | 400 |
396 } // namespace blink | 401 } // namespace blink |
OLD | NEW |