| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 // Allocates the requested bit rates from |bitrateOptions| into the respective | 46 // Allocates the requested bit rates from |bitrateOptions| into the respective |
| 47 // |{audio,video}BitsPerSecond| (where a value of zero indicates Platform to use | 47 // |{audio,video}BitsPerSecond| (where a value of zero indicates Platform to use |
| 48 // whatever it sees fit). If |options.bitsPerSecond()| is specified, it | 48 // whatever it sees fit). If |options.bitsPerSecond()| is specified, it |
| 49 // overrides any specific bitrate, and the UA is free to allocate as desired: | 49 // overrides any specific bitrate, and the UA is free to allocate as desired: |
| 50 // here a 90%/10% video/audio is used. In all cases where a value is explicited | 50 // here a 90%/10% video/audio is used. In all cases where a value is explicited |
| 51 // or calculated, values are clamped in sane ranges. | 51 // or calculated, values are clamped in sane ranges. |
| 52 // This method throws NotSupportedError. | 52 // This method throws NotSupportedError. |
| 53 void AllocateVideoAndAudioBitrates(ExceptionState& exceptionState, ExecutionCont
ext* context, const MediaRecorderOptions& options, MediaStream* stream, int* aud
ioBitsPerSecond, int* videoBitsPerSecond) | 53 void AllocateVideoAndAudioBitrates(ExceptionState& exceptionState, ExecutionCont
ext* context, const MediaRecorderOptions& options, MediaStream* stream, int* aud
ioBitsPerSecond, int* videoBitsPerSecond) |
| 54 { | 54 { |
| 55 const bool useVideo = !stream->getVideoTracks().isEmpty(); |
| 56 const bool useAudio = !stream->getAudioTracks().isEmpty(); |
| 57 |
| 55 // Clamp incoming values into a signed integer's range. | 58 // Clamp incoming values into a signed integer's range. |
| 56 // TODO(mcasas): This section would no be needed if the bit rates are signed
or double, see https://github.com/w3c/mediacapture-record/issues/48. | 59 // TODO(mcasas): This section would no be needed if the bit rates are signed
or double, see https://github.com/w3c/mediacapture-record/issues/48. |
| 57 const unsigned kMaxIntAsUnsigned = std::numeric_limits<int>::max(); | 60 const unsigned kMaxIntAsUnsigned = std::numeric_limits<int>::max(); |
| 58 | 61 |
| 59 ASSERT(options.bitsPerSecond() >= 0); | 62 int overallBps = 0; |
| 60 ASSERT(options.bitsPerSecond() < kMaxIntAsUnsigned); | 63 if (options.hasBitsPerSecond()) |
| 61 const int overallBps = std::min(options.bitsPerSecond(), kMaxIntAsUnsigned); | 64 overallBps = std::min(options.bitsPerSecond(), kMaxIntAsUnsigned); |
| 62 | 65 int videoBps = 0; |
| 63 // If options.hasBitsPerSecond() is not present, assert than the individual
|{video,audio}BitsPerSecond| are smaller than the maximum. | 66 if (options.hasVideoBitsPerSecond() && useVideo) |
| 64 ASSERT(!options.hasBitsPerSecond() || options.videoBitsPerSecond() < kMaxInt
AsUnsigned); | 67 videoBps = std::min(options.videoBitsPerSecond(), kMaxIntAsUnsigned); |
| 65 int videoBps = std::min(options.videoBitsPerSecond(), kMaxIntAsUnsigned); | 68 int audioBps = 0; |
| 66 | 69 if (options.hasAudioBitsPerSecond() && useAudio) |
| 67 ASSERT(!options.hasBitsPerSecond() || options.audioBitsPerSecond() < kMaxInt
AsUnsigned); | 70 audioBps = std::min(options.audioBitsPerSecond(), kMaxIntAsUnsigned); |
| 68 int audioBps = std::min(options.audioBitsPerSecond(), kMaxIntAsUnsigned); | |
| 69 | |
| 70 const bool useVideo = !stream->getVideoTracks().isEmpty(); | |
| 71 const bool useAudio = !stream->getAudioTracks().isEmpty(); | |
| 72 | 71 |
| 73 if (useAudio) { | 72 if (useAudio) { |
| 74 // |overallBps| overrides the specific audio and video bit rates. | 73 // |overallBps| overrides the specific audio and video bit rates. |
| 75 if (overallBps) { | 74 if (options.hasBitsPerSecond()) { |
| 76 if (useVideo) | 75 if (useVideo) |
| 77 audioBps = overallBps / 10; | 76 audioBps = overallBps / 10; |
| 78 else | 77 else |
| 79 audioBps = overallBps; | 78 audioBps = overallBps; |
| 80 } | 79 } |
| 81 // Limit audio bitrate values if set explicitly or calculated. | 80 // Limit audio bitrate values if set explicitly or calculated. |
| 82 if (audioBps) { | 81 if (options.hasAudioBitsPerSecond() || options.hasBitsPerSecond()) { |
| 83 if (audioBps > kLargestAutoAllocatedOpusBitRate) { | 82 if (audioBps > kLargestAutoAllocatedOpusBitRate) { |
| 84 context->addConsoleMessage(ConsoleMessage::create(JSMessageSourc
e, WarningMessageLevel, "Clamping calculated audio bitrate (" + String::number(a
udioBps) + "bps) to the maximum (" + String::number(kLargestAutoAllocatedOpusBit
Rate) + "bps)")); | 83 context->addConsoleMessage(ConsoleMessage::create(JSMessageSourc
e, WarningMessageLevel, "Clamping calculated audio bitrate (" + String::number(a
udioBps) + "bps) to the maximum (" + String::number(kLargestAutoAllocatedOpusBit
Rate) + "bps)")); |
| 85 audioBps = kLargestAutoAllocatedOpusBitRate; | 84 audioBps = kLargestAutoAllocatedOpusBitRate; |
| 86 } | 85 } |
| 87 | 86 |
| 88 if (audioBps < kSmallestPossibleOpusBitRate) { | 87 if (audioBps < kSmallestPossibleOpusBitRate) { |
| 89 context->addConsoleMessage(ConsoleMessage::create(JSMessageSourc
e, WarningMessageLevel, "Clamping calculated audio bitrate (" + String::number(a
udioBps) + "bps) to the minimum (" + String::number(kSmallestPossibleOpusBitRate
) + "bps)")); | 88 context->addConsoleMessage(ConsoleMessage::create(JSMessageSourc
e, WarningMessageLevel, "Clamping calculated audio bitrate (" + String::number(a
udioBps) + "bps) to the minimum (" + String::number(kSmallestPossibleOpusBitRate
) + "bps)")); |
| 90 audioBps = kSmallestPossibleOpusBitRate; | 89 audioBps = kSmallestPossibleOpusBitRate; |
| 91 } | 90 } |
| 91 } else { |
| 92 ASSERT(!audioBps); |
| 92 } | 93 } |
| 93 } else { | |
| 94 audioBps = 0; | |
| 95 } | 94 } |
| 95 |
| 96 if (useVideo) { | 96 if (useVideo) { |
| 97 // Allocate the remaining |overallBps|, if any, to video. | 97 // Allocate the remaining |overallBps|, if any, to video. |
| 98 if (overallBps) | 98 if (options.hasBitsPerSecond()) |
| 99 videoBps = overallBps - audioBps; | 99 videoBps = overallBps - audioBps; |
| 100 // Clamp the video bit rate if the user has set it explicitly or has use
d the overall bitrate. | 100 // Clamp the video bit rate. Avoid clamping if the user has not set it e
xplicitly. |
| 101 if ((options.videoBitsPerSecond() > 0 || overallBps > 0) && (videoBps <
kSmallestPossibleVpxBitRate)) { | 101 if (options.hasVideoBitsPerSecond() || options.hasBitsPerSecond()) { |
| 102 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, W
arningMessageLevel, "Clamping calculated video bitrate (" + String::number(video
Bps) + "bps) to the minimum (" + String::number(kSmallestPossibleVpxBitRate) + "
bps)")); | 102 if (videoBps < kSmallestPossibleVpxBitRate) { |
| 103 videoBps = kSmallestPossibleVpxBitRate; | 103 context->addConsoleMessage(ConsoleMessage::create(JSMessageSourc
e, WarningMessageLevel, "Clamping calculated video bitrate (" + String::number(v
ideoBps) + "bps) to the minimum (" + String::number(kSmallestPossibleVpxBitRate)
+ "bps)")); |
| 104 videoBps = kSmallestPossibleVpxBitRate; |
| 105 } |
| 106 } else { |
| 107 ASSERT(!videoBps); |
| 104 } | 108 } |
| 105 } else { | |
| 106 videoBps = 0; | |
| 107 } | 109 } |
| 108 | 110 |
| 109 *videoBitsPerSecond = videoBps; | 111 *videoBitsPerSecond = videoBps; |
| 110 *audioBitsPerSecond = audioBps; | 112 *audioBitsPerSecond = audioBps; |
| 111 return; | 113 return; |
| 112 } | 114 } |
| 113 | 115 |
| 114 } // namespace | 116 } // namespace |
| 115 | 117 |
| 116 MediaRecorder* MediaRecorder::create(ExecutionContext* context, MediaStream* str
eam, ExceptionState& exceptionState) | 118 MediaRecorder* MediaRecorder::create(ExecutionContext* context, MediaStream* str
eam, ExceptionState& exceptionState) |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 DEFINE_TRACE(MediaRecorder) | 351 DEFINE_TRACE(MediaRecorder) |
| 350 { | 352 { |
| 351 visitor->trace(m_stream); | 353 visitor->trace(m_stream); |
| 352 visitor->trace(m_dispatchScheduledEventRunner); | 354 visitor->trace(m_dispatchScheduledEventRunner); |
| 353 visitor->trace(m_scheduledEvents); | 355 visitor->trace(m_scheduledEvents); |
| 354 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi
sitor); | 356 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi
sitor); |
| 355 ActiveDOMObject::trace(visitor); | 357 ActiveDOMObject::trace(visitor); |
| 356 } | 358 } |
| 357 | 359 |
| 358 } // namespace blink | 360 } // namespace blink |
| OLD | NEW |