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

Side by Side Diff: content/renderer/media/media_stream_video_capturer_source.cc

Issue 1729683002: Remove old-style constraints from Chrome internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Complete the interface change Created 4 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/media/media_stream_video_capturer_source.h" 5 #include "content/renderer/media/media_stream_video_capturer_source.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } else { 89 } else {
90 NOTREACHED(); 90 NOTREACHED();
91 } 91 }
92 92
93 // If the maximum frame resolution was provided in the constraints, use it if 93 // If the maximum frame resolution was provided in the constraints, use it if
94 // either: 1) none has been set yet; or 2) the maximum specificed is smaller 94 // either: 1) none has been set yet; or 2) the maximum specificed is smaller
95 // than the current setting. 95 // than the current setting.
96 int width = 0; 96 int width = 0;
97 int height = 0; 97 int height = 0;
98 gfx::Size desired_max_frame_size; 98 gfx::Size desired_max_frame_size;
99 if (GetConstraintValueAsInteger(constraints, 99 if (GetConstraintMaxAsInteger(
100 MediaStreamVideoSource::kMaxWidth, 100 constraints, &blink::WebMediaTrackConstraintSet::width, &width) &&
101 &width) && 101 GetConstraintMaxAsInteger(
102 GetConstraintValueAsInteger(constraints, 102 constraints, &blink::WebMediaTrackConstraintSet::height, &height) &&
103 MediaStreamVideoSource::kMaxHeight, 103 DimensionValueIsValid(width) && DimensionValueIsValid(height)) {
104 &height) &&
105 DimensionValueIsValid(width) &&
106 DimensionValueIsValid(height)) {
107 desired_max_frame_size.SetSize(width, height); 104 desired_max_frame_size.SetSize(width, height);
108 if (params->requested_format.frame_size.IsEmpty() || 105 if (params->requested_format.frame_size.IsEmpty() ||
109 desired_max_frame_size.width() < 106 desired_max_frame_size.width() <
110 params->requested_format.frame_size.width() || 107 params->requested_format.frame_size.width() ||
111 desired_max_frame_size.height() < 108 desired_max_frame_size.height() <
112 params->requested_format.frame_size.height()) { 109 params->requested_format.frame_size.height()) {
113 params->requested_format.frame_size = desired_max_frame_size; 110 params->requested_format.frame_size = desired_max_frame_size;
114 } 111 }
115 } 112 }
116 113
117 // Set the default frame resolution if none was provided. 114 // Set the default frame resolution if none was provided.
118 if (params->requested_format.frame_size.IsEmpty()) { 115 if (params->requested_format.frame_size.IsEmpty()) {
119 params->requested_format.frame_size.SetSize( 116 params->requested_format.frame_size.SetSize(
120 MediaStreamVideoSource::kDefaultWidth, 117 MediaStreamVideoSource::kDefaultWidth,
121 MediaStreamVideoSource::kDefaultHeight); 118 MediaStreamVideoSource::kDefaultHeight);
122 } 119 }
123 120
124 // If the maximum frame rate was provided, use it if either: 1) none has been 121 // If the maximum frame rate was provided, use it if either: 1) none has been
125 // set yet; or 2) the maximum specificed is smaller than the current setting. 122 // set yet; or 2) the maximum specificed is smaller than the current setting.
126 double frame_rate = 0.0; 123 double frame_rate = 0.0;
127 if (GetConstraintValueAsDouble(constraints, 124 if (GetConstraintMaxAsDouble(constraints,
128 MediaStreamVideoSource::kMaxFrameRate, 125 &blink::WebMediaTrackConstraintSet::frameRate,
129 &frame_rate) && 126 &frame_rate) &&
130 FrameRateValueIsValid(frame_rate)) { 127 FrameRateValueIsValid(frame_rate)) {
131 if (params->requested_format.frame_rate <= 0.0f || 128 if (params->requested_format.frame_rate <= 0.0f ||
132 frame_rate < params->requested_format.frame_rate) { 129 frame_rate < params->requested_format.frame_rate) {
133 params->requested_format.frame_rate = frame_rate; 130 params->requested_format.frame_rate = frame_rate;
134 } 131 }
135 } 132 }
136 133
137 // Set the default frame rate if none was provided. 134 // Set the default frame rate if none was provided.
138 if (params->requested_format.frame_rate <= 0.0f) { 135 if (params->requested_format.frame_rate <= 0.0f) {
139 params->requested_format.frame_rate = 136 params->requested_format.frame_rate =
140 MediaStreamVideoSource::kDefaultFrameRate; 137 MediaStreamVideoSource::kDefaultFrameRate;
141 } 138 }
142 139
143 // If the minimum frame resolution was provided, compare it to the maximum 140 // If the minimum frame resolution was provided, compare it to the maximum
144 // frame resolution to determine the intended resolution change policy. 141 // frame resolution to determine the intended resolution change policy.
145 if (!desired_max_frame_size.IsEmpty() && 142 if (!desired_max_frame_size.IsEmpty() &&
146 GetConstraintValueAsInteger(constraints, 143 GetConstraintMinAsInteger(
147 MediaStreamVideoSource::kMinWidth, 144 constraints, &blink::WebMediaTrackConstraintSet::width, &width) &&
148 &width) && 145 GetConstraintMinAsInteger(
149 GetConstraintValueAsInteger(constraints, 146 constraints, &blink::WebMediaTrackConstraintSet::height, &height) &&
150 MediaStreamVideoSource::kMinHeight,
151 &height) &&
152 width <= desired_max_frame_size.width() && 147 width <= desired_max_frame_size.width() &&
153 height <= desired_max_frame_size.height()) { 148 height <= desired_max_frame_size.height()) {
154 if (width == desired_max_frame_size.width() && 149 if (width == desired_max_frame_size.width() &&
155 height == desired_max_frame_size.height()) { 150 height == desired_max_frame_size.height()) {
156 // Constraints explicitly require a single frame resolution. 151 // Constraints explicitly require a single frame resolution.
157 params->resolution_change_policy = 152 params->resolution_change_policy =
158 media::RESOLUTION_POLICY_FIXED_RESOLUTION; 153 media::RESOLUTION_POLICY_FIXED_RESOLUTION;
159 } else if (DimensionValueIsValid(width) && 154 } else if (DimensionValueIsValid(width) &&
160 DimensionValueIsValid(height) && 155 DimensionValueIsValid(height) &&
161 AreNearlyEquivalentInAspectRatio(gfx::Size(width, height), 156 AreNearlyEquivalentInAspectRatio(gfx::Size(width, height),
(...skipping 17 matching lines...) Expand all
179 << params->resolution_change_policy; 174 << params->resolution_change_policy;
180 } 175 }
181 176
182 // Interprets the properties in |constraints| to override values in |params| and 177 // Interprets the properties in |constraints| to override values in |params| and
183 // determine the power line frequency. 178 // determine the power line frequency.
184 void SetPowerLineFrequencyParamFromConstraints( 179 void SetPowerLineFrequencyParamFromConstraints(
185 const blink::WebMediaConstraints& constraints, 180 const blink::WebMediaConstraints& constraints,
186 media::VideoCaptureParams* params) { 181 media::VideoCaptureParams* params) {
187 int freq; 182 int freq;
188 params->power_line_frequency = media::PowerLineFrequency::FREQUENCY_DEFAULT; 183 params->power_line_frequency = media::PowerLineFrequency::FREQUENCY_DEFAULT;
189 if (!GetOptionalConstraintValueAsInteger(constraints, kPowerLineFrequency, 184 if (!GetConstraintValueAsInteger(
190 &freq)) { 185 constraints,
186 &blink::WebMediaTrackConstraintSet::googPowerLineFrequency, &freq)) {
191 return; 187 return;
192 } 188 }
193 if (freq == static_cast<int>(media::PowerLineFrequency::FREQUENCY_50HZ)) 189 if (freq == static_cast<int>(media::PowerLineFrequency::FREQUENCY_50HZ))
194 params->power_line_frequency = media::PowerLineFrequency::FREQUENCY_50HZ; 190 params->power_line_frequency = media::PowerLineFrequency::FREQUENCY_50HZ;
195 else if (freq == static_cast<int>(media::PowerLineFrequency::FREQUENCY_60HZ)) 191 else if (freq == static_cast<int>(media::PowerLineFrequency::FREQUENCY_60HZ))
196 params->power_line_frequency = media::PowerLineFrequency::FREQUENCY_60HZ; 192 params->power_line_frequency = media::PowerLineFrequency::FREQUENCY_60HZ;
197 } 193 }
198 194
199 // LocalVideoCapturerSource is a delegate used by MediaStreamVideoCapturerSource 195 // LocalVideoCapturerSource is a delegate used by MediaStreamVideoCapturerSource
200 // for local video capture. It uses the Render singleton VideoCaptureImplManager 196 // for local video capture. It uses the Render singleton VideoCaptureImplManager
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 void MediaStreamVideoCapturerSource::OnStarted(bool result) { 436 void MediaStreamVideoCapturerSource::OnStarted(bool result) {
441 OnStartDone(result ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE); 437 OnStartDone(result ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE);
442 } 438 }
443 439
444 const char* 440 const char*
445 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { 441 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const {
446 return kPowerLineFrequency; 442 return kPowerLineFrequency;
447 } 443 }
448 444
449 } // namespace content 445 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698