OLD | NEW |
---|---|
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/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
15 #include "content/child/child_process.h" | 15 #include "content/child/child_process.h" |
16 #include "content/renderer/media/media_stream_video_track.h" | 16 #include "content/renderer/media/media_stream_video_track.h" |
17 #include "content/renderer/media/video_track_adapter.h" | 17 #include "content/renderer/media/video_track_adapter.h" |
18 #include "third_party/WebKit/public/platform/WebString.h" | |
19 | |
20 using blink::WebString; | |
18 | 21 |
19 namespace content { | 22 namespace content { |
20 | 23 |
21 namespace { | 24 namespace { |
22 | 25 |
23 const char* const kLegalVideoConstraints[] = {"width", | 26 const char* const kLegalVideoConstraints[] = {"width", |
24 "height", | 27 "height", |
25 "aspectRatio", | 28 "aspectRatio", |
26 "frameRate", | 29 "frameRate", |
27 "facingMode", | 30 "facingMode", |
28 "deviceId", | 31 "deviceId", |
29 "groupId", | 32 "groupId", |
30 "mediaStreamSource", | 33 "mediaStreamSource", |
31 "googNoiseReduction"}; | 34 "googNoiseReduction", |
35 "videoKind"}; | |
36 | |
37 const char kVideoKindDepth[] = "depth"; | |
Guido Urdaneta
2017/02/07 10:26:04
This constant is also defined elsewhere and litera
aleksandar.stojiljkovic
2017/02/07 11:33:49
Done - media_stream_options.h
aleksandar.stojiljkovic
2017/02/09 21:39:25
Moved to media_stream_video_track.h as it is used
| |
38 const char kVideoKindColor[] = "color"; | |
39 // Returns videoKind value for |format|. | |
40 WebString getVideoKindForFormat(const media::VideoCaptureFormat& format) { | |
41 return (format.pixel_format == media::PIXEL_FORMAT_Y16) | |
42 ? WebString::fromUTF8(kVideoKindDepth) | |
43 : WebString::fromUTF8(kVideoKindColor); | |
kinuko
2017/02/07 04:55:49
nit: fromASCII() would be enough as they're both a
aleksandar.stojiljkovic
2017/02/07 11:33:49
Done.
| |
44 } | |
32 | 45 |
33 // Returns true if |constraint| has mandatory constraints. | 46 // Returns true if |constraint| has mandatory constraints. |
34 bool HasMandatoryConstraints(const blink::WebMediaConstraints& constraints) { | 47 bool HasMandatoryConstraints(const blink::WebMediaConstraints& constraints) { |
35 return constraints.basic().hasMandatory(); | 48 return constraints.basic().hasMandatory(); |
36 } | 49 } |
37 | 50 |
38 // Retrieve the desired max width and height from |constraints|. If not set, | 51 // Retrieve the desired max width and height from |constraints|. If not set, |
39 // the |desired_width| and |desired_height| are set to | 52 // the |desired_width| and |desired_height| are set to |
40 // std::numeric_limits<int>::max(); | 53 // std::numeric_limits<int>::max(); |
41 // If either max or exact width or height is set as a mandatory constraint, | 54 // If either max or exact width or height is set as a mandatory constraint, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 (constraints.width.hasMax() && constraints.width.max() <= 0) || | 148 (constraints.width.hasMax() && constraints.width.max() <= 0) || |
136 (constraints.width.hasExact() && | 149 (constraints.width.hasExact() && |
137 constraints.width.exact() > format->frame_size.width())) { | 150 constraints.width.exact() > format->frame_size.width())) { |
138 *failing_constraint_name = constraints.width.name(); | 151 *failing_constraint_name = constraints.width.name(); |
139 } else if ((constraints.height.hasMin() && | 152 } else if ((constraints.height.hasMin() && |
140 constraints.height.min() > format->frame_size.height()) || | 153 constraints.height.min() > format->frame_size.height()) || |
141 (constraints.height.hasMax() && constraints.height.max() <= 0) || | 154 (constraints.height.hasMax() && constraints.height.max() <= 0) || |
142 (constraints.height.hasExact() && | 155 (constraints.height.hasExact() && |
143 constraints.height.exact() > format->frame_size.height())) { | 156 constraints.height.exact() > format->frame_size.height())) { |
144 *failing_constraint_name = constraints.height.name(); | 157 *failing_constraint_name = constraints.height.name(); |
158 } else if (constraints.videoKind.hasExact() && | |
159 !constraints.videoKind.matches(getVideoKindForFormat(*format))) { | |
160 *failing_constraint_name = constraints.videoKind.name(); | |
145 } else if (!constraints.frameRate.matches(format->frame_rate)) { | 161 } else if (!constraints.frameRate.matches(format->frame_rate)) { |
146 if (constraints.frameRate.hasMax()) { | 162 if (constraints.frameRate.hasMax()) { |
147 const double value = constraints.frameRate.max(); | 163 const double value = constraints.frameRate.max(); |
148 // TODO(hta): Check if handling of max = 0.0 is relevant. | 164 // TODO(hta): Check if handling of max = 0.0 is relevant. |
149 // (old handling was to set rate to 1.0 if 0.0 was specified) | 165 // (old handling was to set rate to 1.0 if 0.0 was specified) |
150 if (constraints.frameRate.matches(value)) { | 166 if (constraints.frameRate.matches(value)) { |
151 format->frame_rate = | 167 format->frame_rate = |
152 (format->frame_rate > value) ? value : format->frame_rate; | 168 (format->frame_rate > value) ? value : format->frame_rate; |
153 return true; | 169 return true; |
154 } | 170 } |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 callback(callback) { | 634 callback(callback) { |
619 } | 635 } |
620 | 636 |
621 MediaStreamVideoSource::TrackDescriptor::TrackDescriptor( | 637 MediaStreamVideoSource::TrackDescriptor::TrackDescriptor( |
622 const TrackDescriptor& other) = default; | 638 const TrackDescriptor& other) = default; |
623 | 639 |
624 MediaStreamVideoSource::TrackDescriptor::~TrackDescriptor() { | 640 MediaStreamVideoSource::TrackDescriptor::~TrackDescriptor() { |
625 } | 641 } |
626 | 642 |
627 } // namespace content | 643 } // namespace content |
OLD | NEW |