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

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

Issue 227743004: Added a kEchoCancellation constraint to turn off the audio processing. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 7 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_source.h" 5 #include "content/renderer/media/media_stream_video_source.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "content/child/child_process.h" 14 #include "content/child/child_process.h"
15 #include "content/renderer/media/media_stream_constraints_util.h"
15 #include "content/renderer/media/media_stream_dependency_factory.h" 16 #include "content/renderer/media/media_stream_dependency_factory.h"
16 #include "content/renderer/media/media_stream_video_track.h" 17 #include "content/renderer/media/media_stream_video_track.h"
17 #include "content/renderer/media/video_frame_deliverer.h" 18 #include "content/renderer/media/video_frame_deliverer.h"
18 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" 19 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h"
19 20
20 namespace content { 21 namespace content {
21 22
22 // Constraint keys. Specified by draft-alvestrand-constraints-resolution-00b 23 // Constraint keys. Specified by draft-alvestrand-constraints-resolution-00b
23 const char MediaStreamVideoSource::kMinAspectRatio[] = "minAspectRatio"; 24 const char MediaStreamVideoSource::kMinAspectRatio[] = "minAspectRatio";
24 const char MediaStreamVideoSource::kMaxAspectRatio[] = "maxAspectRatio"; 25 const char MediaStreamVideoSource::kMaxAspectRatio[] = "maxAspectRatio";
(...skipping 13 matching lines...) Expand all
38 MediaStreamVideoSource::kMinHeight, 39 MediaStreamVideoSource::kMinHeight,
39 MediaStreamVideoSource::kMaxFrameRate, 40 MediaStreamVideoSource::kMaxFrameRate,
40 MediaStreamVideoSource::kMinFrameRate, 41 MediaStreamVideoSource::kMinFrameRate,
41 }; 42 };
42 43
43 const int MediaStreamVideoSource::kDefaultWidth = 640; 44 const int MediaStreamVideoSource::kDefaultWidth = 640;
44 const int MediaStreamVideoSource::kDefaultHeight = 480; 45 const int MediaStreamVideoSource::kDefaultHeight = 480;
45 const int MediaStreamVideoSource::kDefaultFrameRate = 30; 46 const int MediaStreamVideoSource::kDefaultFrameRate = 30;
46 47
47 namespace { 48 namespace {
48 // Constraints keys for http://dev.w3.org/2011/webrtc/editor/getusermedia.html
49 const char kSourceId[] = "sourceId";
50 49
51 // Google-specific key prefix. Constraints with this prefix are ignored if they 50 // Google-specific key prefix. Constraints with this prefix are ignored if they
52 // are unknown. 51 // are unknown.
53 const char kGooglePrefix[] = "goog"; 52 const char kGooglePrefix[] = "goog";
54 53
55 // MediaStreamVideoSource supports cropping of video frames but only up to 54 // MediaStreamVideoSource supports cropping of video frames but only up to
56 // kMaxCropFactor. Ie - if a constraint is set to maxHeight 360, an original 55 // kMaxCropFactor. Ie - if a constraint is set to maxHeight 360, an original
57 // input frame height of max 360 * kMaxCropFactor pixels is accepted. 56 // input frame height of max 360 * kMaxCropFactor pixels is accepted.
58 const int kMaxCropFactor = 2; 57 const int kMaxCropFactor = 2;
59 58
(...skipping 11 matching lines...) Expand all
71 70
72 std::string constraint_name = constraint.m_name.utf8(); 71 std::string constraint_name = constraint.m_name.utf8();
73 std::string constraint_value = constraint.m_value.utf8(); 72 std::string constraint_value = constraint.m_value.utf8();
74 73
75 if (constraint_name.find(kGooglePrefix) == 0) { 74 if (constraint_name.find(kGooglePrefix) == 0) {
76 // These are actually options, not constraints, so they can be satisfied 75 // These are actually options, not constraints, so they can be satisfied
77 // regardless of the format. 76 // regardless of the format.
78 return true; 77 return true;
79 } 78 }
80 79
81 if (constraint_name == kSourceId) { 80 if (constraint_name == MediaStreamSource::kSourceId) {
82 // This is a constraint that doesn't affect the format. 81 // This is a constraint that doesn't affect the format.
83 return true; 82 return true;
84 } 83 }
85 84
86 // Ignore Chrome specific Tab capture constraints. 85 // Ignore Chrome specific Tab capture constraints.
87 if (constraint_name == kMediaStreamSource || 86 if (constraint_name == kMediaStreamSource ||
88 constraint_name == kMediaStreamSourceId) 87 constraint_name == kMediaStreamSourceId)
89 return true; 88 return true;
90 89
91 if (constraint_name == MediaStreamVideoSource::kMinAspectRatio || 90 if (constraint_name == MediaStreamVideoSource::kMinAspectRatio ||
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 FilterFormatsByConstraint(optional[i], false, &current_candidates); 198 FilterFormatsByConstraint(optional[i], false, &current_candidates);
200 if (!current_candidates.empty()) { 199 if (!current_candidates.empty()) {
201 candidates = current_candidates; 200 candidates = current_candidates;
202 } 201 }
203 } 202 }
204 203
205 // We have done as good as we can to filter the supported resolutions. 204 // We have done as good as we can to filter the supported resolutions.
206 return candidates; 205 return candidates;
207 } 206 }
208 207
209 bool GetConstraintValue(const blink::WebMediaConstraints& constraints,
210 bool mandatory, const blink::WebString& name,
211 int* value) {
212 blink::WebString value_str;
213 bool ret = mandatory ?
214 constraints.getMandatoryConstraintValue(name, value_str) :
215 constraints.getOptionalConstraintValue(name, value_str);
216 if (ret)
217 base::StringToInt(value_str.utf8(), value);
218 return ret;
219 }
220
221 // Returns true if |constraint| has mandatory constraints. 208 // Returns true if |constraint| has mandatory constraints.
222 bool HasMandatoryConstraints(const blink::WebMediaConstraints& constraints) { 209 bool HasMandatoryConstraints(const blink::WebMediaConstraints& constraints) {
223 blink::WebVector<blink::WebMediaConstraint> mandatory_constraints; 210 blink::WebVector<blink::WebMediaConstraint> mandatory_constraints;
224 constraints.getMandatoryConstraints(mandatory_constraints); 211 constraints.getMandatoryConstraints(mandatory_constraints);
225 return !mandatory_constraints.isEmpty(); 212 return !mandatory_constraints.isEmpty();
226 } 213 }
227 214
228 // Retrieve the desired max width and height from |constraints|. 215 // Retrieve the desired max width and height from |constraints|.
229 void GetDesiredMaxWidthAndHeight(const blink::WebMediaConstraints& constraints, 216 void GetDesiredMaxWidthAndHeight(const blink::WebMediaConstraints& constraints,
230 int* desired_width, int* desired_height) { 217 int* desired_width, int* desired_height) {
231 bool mandatory = GetConstraintValue(constraints, true, 218 bool mandatory = GetMandatoryConstraintValueAsInteger(
232 MediaStreamVideoSource::kMaxWidth, 219 constraints, MediaStreamVideoSource::kMaxWidth, desired_width);
233 desired_width); 220 mandatory |= GetMandatoryConstraintValueAsInteger(
234 mandatory |= GetConstraintValue(constraints, true, 221 constraints, MediaStreamVideoSource::kMaxHeight, desired_height);
235 MediaStreamVideoSource::kMaxHeight, 222 // Skip the optional constraints if any of the mandatory constraint is
236 desired_height); 223 // specified.
237 if (mandatory) 224 if (mandatory)
238 return; 225 return;
239 226
240 GetConstraintValue(constraints, false, MediaStreamVideoSource::kMaxWidth, 227 GetOptionalConstraintValueAsInteger(constraints,
241 desired_width); 228 MediaStreamVideoSource::kMaxWidth,
242 GetConstraintValue(constraints, false, MediaStreamVideoSource::kMaxHeight, 229 desired_width);
243 desired_height); 230 GetOptionalConstraintValueAsInteger(constraints,
231 MediaStreamVideoSource::kMaxHeight,
232 desired_height);
244 } 233 }
245 234
246 const media::VideoCaptureFormat& GetBestFormatBasedOnArea( 235 const media::VideoCaptureFormat& GetBestFormatBasedOnArea(
247 const media::VideoCaptureFormats& formats, 236 const media::VideoCaptureFormats& formats,
248 int area) { 237 int area) {
249 media::VideoCaptureFormats::const_iterator it = formats.begin(); 238 media::VideoCaptureFormats::const_iterator it = formats.begin();
250 media::VideoCaptureFormats::const_iterator best_it = formats.begin(); 239 media::VideoCaptureFormats::const_iterator best_it = formats.begin();
251 int best_diff = std::numeric_limits<int>::max(); 240 int best_diff = std::numeric_limits<int>::max();
252 for (; it != formats.end(); ++it) { 241 for (; it != formats.end(); ++it) {
253 int diff = abs(area - it->frame_size.width() * it->frame_size.height()); 242 int diff = abs(area - it->frame_size.width() * it->frame_size.height());
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 tracks_.push_back(track); 398 tracks_.push_back(track);
410 399
411 requested_constraints_.push_back( 400 requested_constraints_.push_back(
412 RequestedConstraints(track, frame_callback, constraints, callback)); 401 RequestedConstraints(track, frame_callback, constraints, callback));
413 402
414 switch (state_) { 403 switch (state_) {
415 case NEW: { 404 case NEW: {
416 // Tab capture and Screen capture needs the maximum requested height 405 // Tab capture and Screen capture needs the maximum requested height
417 // and width to decide on the resolution. 406 // and width to decide on the resolution.
418 int max_requested_width = 0; 407 int max_requested_width = 0;
419 GetConstraintValue(constraints, true, kMaxWidth, &max_requested_width); 408 GetMandatoryConstraintValueAsInteger(constraints, kMaxWidth,
409 &max_requested_width);
420 410
421 int max_requested_height = 0; 411 int max_requested_height = 0;
422 GetConstraintValue(constraints, true, kMaxHeight, &max_requested_height); 412 GetMandatoryConstraintValueAsInteger(constraints, kMaxHeight,
413 &max_requested_height);
423 414
424 state_ = RETRIEVING_CAPABILITIES; 415 state_ = RETRIEVING_CAPABILITIES;
425 GetCurrentSupportedFormats( 416 GetCurrentSupportedFormats(
426 max_requested_width, 417 max_requested_width,
427 max_requested_height, 418 max_requested_height,
428 base::Bind(&MediaStreamVideoSource::OnSupportedFormats, 419 base::Bind(&MediaStreamVideoSource::OnSupportedFormats,
429 weak_factory_.GetWeakPtr())); 420 weak_factory_.GetWeakPtr()));
430 421
431 break; 422 break;
432 } 423 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 : track(track), 596 : track(track),
606 frame_callback(frame_callback), 597 frame_callback(frame_callback),
607 constraints(constraints), 598 constraints(constraints),
608 callback(callback) { 599 callback(callback) {
609 } 600 }
610 601
611 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { 602 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() {
612 } 603 }
613 604
614 } // namespace content 605 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698