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

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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 tracks_.push_back(track); 399 tracks_.push_back(track);
411 400
412 requested_constraints_.push_back( 401 requested_constraints_.push_back(
413 RequestedConstraints(track, frame_callback, constraints, callback)); 402 RequestedConstraints(track, frame_callback, constraints, callback));
414 403
415 switch (state_) { 404 switch (state_) {
416 case NEW: { 405 case NEW: {
417 // Tab capture and Screen capture needs the maximum requested height 406 // Tab capture and Screen capture needs the maximum requested height
418 // and width to decide on the resolution. 407 // and width to decide on the resolution.
419 int max_requested_width = 0; 408 int max_requested_width = 0;
420 GetConstraintValue(constraints, true, kMaxWidth, &max_requested_width); 409 GetMandatoryConstraintValueAsInteger(constraints, kMaxWidth,
410 &max_requested_width);
421 411
422 int max_requested_height = 0; 412 int max_requested_height = 0;
423 GetConstraintValue(constraints, true, kMaxHeight, &max_requested_height); 413 GetMandatoryConstraintValueAsInteger(constraints, kMaxHeight,
414 &max_requested_height);
424 415
425 state_ = RETRIEVING_CAPABILITIES; 416 state_ = RETRIEVING_CAPABILITIES;
426 GetCurrentSupportedFormats( 417 GetCurrentSupportedFormats(
427 max_requested_width, 418 max_requested_width,
428 max_requested_height, 419 max_requested_height,
429 base::Bind(&MediaStreamVideoSource::OnSupportedFormats, 420 base::Bind(&MediaStreamVideoSource::OnSupportedFormats,
430 weak_factory_.GetWeakPtr())); 421 weak_factory_.GetWeakPtr()));
431 422
432 break; 423 break;
433 } 424 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 : track(track), 597 : track(track),
607 frame_callback(frame_callback), 598 frame_callback(frame_callback),
608 constraints(constraints), 599 constraints(constraints),
609 callback(callback) { 600 callback(callback) {
610 } 601 }
611 602
612 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { 603 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() {
613 } 604 }
614 605
615 } // namespace content 606 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_source.cc ('k') | content/renderer/media/mock_media_constraint_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698