Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/api/videocapturertracksource.h" | 11 #include "webrtc/api/videocapturertracksource.h" |
| 12 | 12 |
| 13 #include <cstdlib> | 13 #include <cstdlib> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "webrtc/api/mediaconstraintsinterface.h" | 17 #include "webrtc/api/mediaconstraintsinterface.h" |
| 18 #include "webrtc/base/arraysize.h" | 18 #include "webrtc/base/arraysize.h" |
| 19 #include "webrtc/base/checks.h" | |
| 19 | 20 |
| 20 using cricket::CaptureState; | 21 using cricket::CaptureState; |
| 21 using webrtc::MediaConstraintsInterface; | 22 using webrtc::MediaConstraintsInterface; |
| 22 using webrtc::MediaSourceInterface; | 23 using webrtc::MediaSourceInterface; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const double kRoundingTruncation = 0.0005; | 27 const double kRoundingTruncation = 0.0005; |
| 27 | 28 |
| 28 // Default resolution. If no constraint is specified, this is the resolution we | 29 // Default resolution. If no constraint is specified, this is the resolution we |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 43 MediaSourceInterface::SourceState GetReadyState(cricket::CaptureState state) { | 44 MediaSourceInterface::SourceState GetReadyState(cricket::CaptureState state) { |
| 44 switch (state) { | 45 switch (state) { |
| 45 case cricket::CS_STARTING: | 46 case cricket::CS_STARTING: |
| 46 return MediaSourceInterface::kInitializing; | 47 return MediaSourceInterface::kInitializing; |
| 47 case cricket::CS_RUNNING: | 48 case cricket::CS_RUNNING: |
| 48 return MediaSourceInterface::kLive; | 49 return MediaSourceInterface::kLive; |
| 49 case cricket::CS_FAILED: | 50 case cricket::CS_FAILED: |
| 50 case cricket::CS_STOPPED: | 51 case cricket::CS_STOPPED: |
| 51 return MediaSourceInterface::kEnded; | 52 return MediaSourceInterface::kEnded; |
| 52 default: | 53 default: |
| 53 ASSERT(false && "GetReadyState unknown state"); | 54 RTC_DCHECK(false && "GetReadyState unknown state"); |
|
kwiberg-webrtc
2017/01/12 02:10:41
RTC_NOTREACHED?
| |
| 54 } | 55 } |
| 55 return MediaSourceInterface::kEnded; | 56 return MediaSourceInterface::kEnded; |
| 56 } | 57 } |
| 57 | 58 |
| 58 void SetUpperLimit(int new_limit, int* original_limit) { | 59 void SetUpperLimit(int new_limit, int* original_limit) { |
| 59 if (*original_limit < 0 || new_limit < *original_limit) | 60 if (*original_limit < 0 || new_limit < *original_limit) |
| 60 *original_limit = new_limit; | 61 *original_limit = new_limit; |
| 61 } | 62 } |
| 62 | 63 |
| 63 // Updates |format_upper_limit| from |constraint|. | 64 // Updates |format_upper_limit| from |constraint|. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 94 } | 95 } |
| 95 | 96 |
| 96 // Returns true if |constraint| is fulfilled. |format_out| can differ from | 97 // Returns true if |constraint| is fulfilled. |format_out| can differ from |
| 97 // |format_in| if the format is changed by the constraint. Ie - the frame rate | 98 // |format_in| if the format is changed by the constraint. Ie - the frame rate |
| 98 // can be changed by setting maxFrameRate. | 99 // can be changed by setting maxFrameRate. |
| 99 bool NewFormatWithConstraints( | 100 bool NewFormatWithConstraints( |
| 100 const MediaConstraintsInterface::Constraint& constraint, | 101 const MediaConstraintsInterface::Constraint& constraint, |
| 101 const cricket::VideoFormat& format_in, | 102 const cricket::VideoFormat& format_in, |
| 102 bool mandatory, | 103 bool mandatory, |
| 103 cricket::VideoFormat* format_out) { | 104 cricket::VideoFormat* format_out) { |
| 104 ASSERT(format_out != NULL); | 105 RTC_DCHECK(format_out != NULL); |
| 105 *format_out = format_in; | 106 *format_out = format_in; |
| 106 | 107 |
| 107 if (constraint.key == MediaConstraintsInterface::kMinWidth) { | 108 if (constraint.key == MediaConstraintsInterface::kMinWidth) { |
| 108 int value = rtc::FromString<int>(constraint.value); | 109 int value = rtc::FromString<int>(constraint.value); |
| 109 return (value <= format_in.width); | 110 return (value <= format_in.width); |
| 110 } else if (constraint.key == MediaConstraintsInterface::kMaxWidth) { | 111 } else if (constraint.key == MediaConstraintsInterface::kMaxWidth) { |
| 111 int value = rtc::FromString<int>(constraint.value); | 112 int value = rtc::FromString<int>(constraint.value); |
| 112 return (value >= format_in.width); | 113 return (value >= format_in.width); |
| 113 } else if (constraint.key == MediaConstraintsInterface::kMinHeight) { | 114 } else if (constraint.key == MediaConstraintsInterface::kMinHeight) { |
| 114 int value = rtc::FromString<int>(constraint.value); | 115 int value = rtc::FromString<int>(constraint.value); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 return candidates; | 209 return candidates; |
| 209 } | 210 } |
| 210 | 211 |
| 211 // Find the format that best matches the default video size. | 212 // Find the format that best matches the default video size. |
| 212 // Constraints are optional and since the performance of a video call | 213 // Constraints are optional and since the performance of a video call |
| 213 // might be bad due to bitrate limitations, CPU, and camera performance, | 214 // might be bad due to bitrate limitations, CPU, and camera performance, |
| 214 // it is better to select a resolution that is as close as possible to our | 215 // it is better to select a resolution that is as close as possible to our |
| 215 // default and still meets the contraints. | 216 // default and still meets the contraints. |
| 216 const cricket::VideoFormat& GetBestCaptureFormat( | 217 const cricket::VideoFormat& GetBestCaptureFormat( |
| 217 const std::vector<cricket::VideoFormat>& formats) { | 218 const std::vector<cricket::VideoFormat>& formats) { |
| 218 ASSERT(formats.size() > 0); | 219 RTC_DCHECK(formats.size() > 0); |
| 219 | 220 |
| 220 int default_area = kDefaultFormat.width * kDefaultFormat.height; | 221 int default_area = kDefaultFormat.width * kDefaultFormat.height; |
| 221 | 222 |
| 222 std::vector<cricket::VideoFormat>::const_iterator it = formats.begin(); | 223 std::vector<cricket::VideoFormat>::const_iterator it = formats.begin(); |
| 223 std::vector<cricket::VideoFormat>::const_iterator best_it = formats.begin(); | 224 std::vector<cricket::VideoFormat>::const_iterator best_it = formats.begin(); |
| 224 int best_diff_area = std::abs(default_area - it->width * it->height); | 225 int best_diff_area = std::abs(default_area - it->width * it->height); |
| 225 int64_t best_diff_interval = kDefaultFormat.interval; | 226 int64_t best_diff_interval = kDefaultFormat.interval; |
| 226 for (; it != formats.end(); ++it) { | 227 for (; it != formats.end(); ++it) { |
| 227 int diff_area = std::abs(default_area - it->width * it->height); | 228 int diff_area = std::abs(default_area - it->width * it->height); |
| 228 int64_t diff_interval = std::abs(kDefaultFormat.interval - it->interval); | 229 int64_t diff_interval = std::abs(kDefaultFormat.interval - it->interval); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 capture_state)); | 388 capture_state)); |
| 388 return; | 389 return; |
| 389 } | 390 } |
| 390 | 391 |
| 391 if (capturer == video_capturer_.get()) { | 392 if (capturer == video_capturer_.get()) { |
| 392 SetState(GetReadyState(capture_state)); | 393 SetState(GetReadyState(capture_state)); |
| 393 } | 394 } |
| 394 } | 395 } |
| 395 | 396 |
| 396 } // namespace webrtc | 397 } // namespace webrtc |
| OLD | NEW |