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

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

Issue 1682483002: MediaRecorder: remove ASSERTS in bitrate clamping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Clamp incoming values into a signed integer's range. 55 // 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. 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.
57 const unsigned kMaxIntAsUnsigned = std::numeric_limits<int>::max(); 57 const unsigned kMaxIntAsUnsigned = std::numeric_limits<int>::max();
58 58
59 ASSERT(options.bitsPerSecond() >= 0);
60 ASSERT(options.bitsPerSecond() < kMaxIntAsUnsigned);
61 const int overallBps = std::min(options.bitsPerSecond(), kMaxIntAsUnsigned); 59 const int overallBps = std::min(options.bitsPerSecond(), kMaxIntAsUnsigned);
philipj_slow 2016/02/09 06:31:22 Can you write test cases that exercise this clampi
mcasas 2016/02/12 02:11:38 Done, added a few more LayoutTests.
62
63 // If options.hasBitsPerSecond() is not present, assert than the individual |{video,audio}BitsPerSecond| are smaller than the maximum.
64 ASSERT(!options.hasBitsPerSecond() || options.videoBitsPerSecond() < kMaxInt AsUnsigned);
65 int videoBps = std::min(options.videoBitsPerSecond(), kMaxIntAsUnsigned); 60 int videoBps = std::min(options.videoBitsPerSecond(), kMaxIntAsUnsigned);
66
67 ASSERT(!options.hasBitsPerSecond() || options.audioBitsPerSecond() < kMaxInt AsUnsigned);
68 int audioBps = std::min(options.audioBitsPerSecond(), kMaxIntAsUnsigned); 61 int audioBps = std::min(options.audioBitsPerSecond(), kMaxIntAsUnsigned);
69 62
70 const bool useVideo = !stream->getVideoTracks().isEmpty(); 63 const bool useVideo = !stream->getVideoTracks().isEmpty();
71 const bool useAudio = !stream->getAudioTracks().isEmpty(); 64 const bool useAudio = !stream->getAudioTracks().isEmpty();
72 65
73 if (useAudio) { 66 if (useAudio) {
74 // |overallBps| overrides the specific audio and video bit rates. 67 // |overallBps| overrides the specific audio and video bit rates.
75 if (overallBps) { 68 if (overallBps) {
76 if (useVideo) 69 if (useVideo)
77 audioBps = overallBps / 10; 70 audioBps = overallBps / 10;
(...skipping 12 matching lines...) Expand all
90 audioBps = kSmallestPossibleOpusBitRate; 83 audioBps = kSmallestPossibleOpusBitRate;
91 } 84 }
92 } 85 }
93 } else { 86 } else {
94 audioBps = 0; 87 audioBps = 0;
95 } 88 }
96 if (useVideo) { 89 if (useVideo) {
97 // Allocate the remaining |overallBps|, if any, to video. 90 // Allocate the remaining |overallBps|, if any, to video.
98 if (overallBps) 91 if (overallBps)
99 videoBps = overallBps - audioBps; 92 videoBps = overallBps - audioBps;
100 // Clamp the video bit rate if the user has set it explicitly or has use d the overall bitrate. 93 // 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)) { 94 if ((options.videoBitsPerSecond() > 0 || overallBps > 0) && (videoBps < kSmallestPossibleVpxBitRate)) {
mcasas 2016/02/08 21:55:56 From https://codereview.chromium.org/1652373004/:
philipj_slow 2016/02/09 06:31:22 The trouble is that because MediaRecorderOptions.i
mcasas 2016/02/12 02:11:38 I see. I removed the by-default =0 in MediaRecorde
102 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, W arningMessageLevel, "Clamping calculated video bitrate (" + String::number(video Bps) + "bps) to the minimum (" + String::number(kSmallestPossibleVpxBitRate) + " bps)")); 95 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, W arningMessageLevel, "Clamping calculated video bitrate (" + String::number(video Bps) + "bps) to the minimum (" + String::number(kSmallestPossibleVpxBitRate) + " bps)"));
103 videoBps = kSmallestPossibleVpxBitRate; 96 videoBps = kSmallestPossibleVpxBitRate;
104 } 97 }
105 } else { 98 } else {
106 videoBps = 0; 99 videoBps = 0;
107 } 100 }
108 101
109 *videoBitsPerSecond = videoBps; 102 *videoBitsPerSecond = videoBps;
110 *audioBitsPerSecond = audioBps; 103 *audioBitsPerSecond = audioBps;
111 return; 104 return;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 DEFINE_TRACE(MediaRecorder) 342 DEFINE_TRACE(MediaRecorder)
350 { 343 {
351 visitor->trace(m_stream); 344 visitor->trace(m_stream);
352 visitor->trace(m_dispatchScheduledEventRunner); 345 visitor->trace(m_dispatchScheduledEventRunner);
353 visitor->trace(m_scheduledEvents); 346 visitor->trace(m_scheduledEvents);
354 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi sitor); 347 RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder>::trace(vi sitor);
355 ActiveDOMObject::trace(visitor); 348 ActiveDOMObject::trace(visitor);
356 } 349 }
357 350
358 } // namespace blink 351 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698