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

Unified Diff: content/renderer/media/media_stream_video_source.cc

Issue 964293002: VideoCaptureImpl & relatives small cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/media_stream_video_source.cc
diff --git a/content/renderer/media/media_stream_video_source.cc b/content/renderer/media/media_stream_video_source.cc
index e23794511ee5e07236fce83c5fd6b24f3b1fda5a..bf16a72094862e09c611e347be0b7115c1652afe 100644
--- a/content/renderer/media/media_stream_video_source.cc
+++ b/content/renderer/media/media_stream_video_source.cc
@@ -209,11 +209,10 @@ void FilterFormatsByConstraint(
while (format_it != formats->end()) {
// Modify the format_it to fulfill the constraint if possible.
// Delete it otherwise.
- if (!UpdateFormatForConstraint(constraint, mandatory, &(*format_it))) {
+ if (!UpdateFormatForConstraint(constraint, mandatory, &(*format_it)))
format_it = formats->erase(format_it);
- } else {
+ else
++format_it;
- }
}
}
@@ -222,9 +221,8 @@ media::VideoCaptureFormats FilterFormats(
const blink::WebMediaConstraints& constraints,
const media::VideoCaptureFormats& supported_formats,
blink::WebString* unsatisfied_constraint) {
- if (constraints.isNull()) {
+ if (constraints.isNull())
return supported_formats;
- }
double max_aspect_ratio;
double min_aspect_ratio;
@@ -291,9 +289,8 @@ media::VideoCaptureFormats FilterFormats(
for (size_t i = 0; i < optional.size(); ++i) {
media::VideoCaptureFormats current_candidates = candidates;
FilterFormatsByConstraint(optional[i], false, &current_candidates);
- if (!current_candidates.empty()) {
+ if (!current_candidates.empty())
candidates = current_candidates;
- }
}
// We have done as good as we can to filter the supported resolutions.
@@ -303,17 +300,14 @@ media::VideoCaptureFormats FilterFormats(
const media::VideoCaptureFormat& GetBestFormatBasedOnArea(
const media::VideoCaptureFormats& formats,
int area) {
- media::VideoCaptureFormats::const_iterator it = formats.begin();
- media::VideoCaptureFormats::const_iterator best_it = formats.begin();
- int best_diff = std::numeric_limits<int>::max();
- for (; it != formats.end(); ++it) {
- int diff = abs(area - it->frame_size.width() * it->frame_size.height());
- if (diff < best_diff) {
- best_diff = diff;
- best_it = it;
- }
- }
- return *best_it;
+ return *std::min_element(
+ formats.begin(),
+ formats.end(),
+ [&](const media::VideoCaptureFormat& f1,
emircan 2015/03/02 19:29:07 Default lambda captures are not allowed in the sty
mcasas 2015/03/02 22:57:58 Done.
+ const media::VideoCaptureFormat& f2) {
+ return abs(area - f1.frame_size.GetArea()) <
+ abs(area - f2.frame_size.GetArea());
+ });
emircan 2015/03/02 19:29:07 Overall comparison complexity is O(N) for min_elem
mcasas 2015/03/02 22:57:58 Hmm you're right. I was too centered in making the
}
// Find the format that best matches the default video size.
@@ -348,8 +342,8 @@ MediaStreamVideoSource* MediaStreamVideoSource::GetVideoSource(
// static
bool MediaStreamVideoSource::IsConstraintSupported(const std::string& name) {
- for (size_t i = 0; i < arraysize(kSupportedConstraints); ++i) {
- if (kSupportedConstraints[i] == name)
+ for (const auto& constraint : kSupportedConstraints) {
+ if (constraint == name)
return true;
}
return false;
@@ -492,11 +486,9 @@ bool MediaStreamVideoSource::FindBestFormatWithConstraints(
media::VideoCaptureFormat* best_format) {
DCHECK(CalledOnValidThread());
// Find the first constraints that we can fulfill.
- for (std::vector<RequestedConstraints>::iterator request_it =
- requested_constraints_.begin();
- request_it != requested_constraints_.end(); ++request_it) {
+ for (const auto& request_it : requested_constraints_) {
const blink::WebMediaConstraints& requested_constraints =
- request_it->constraints;
+ request_it.constraints;
// If the source doesn't support capability enumeration it is still ok if
// no mandatory constraints have been specified. That just means that
@@ -548,15 +540,15 @@ void MediaStreamVideoSource::FinalizeAddTrack() {
std::vector<RequestedConstraints> callbacks;
callbacks.swap(requested_constraints_);
- for (std::vector<RequestedConstraints>::iterator it = callbacks.begin();
- it != callbacks.end(); ++it) {
+ for (const auto& it : callbacks) {
MediaStreamRequestResult result = MEDIA_DEVICE_OK;
blink::WebString unsatisfied_constraint;
- if (HasMandatoryConstraints(it->constraints) &&
- FilterFormats(it->constraints, formats,
- &unsatisfied_constraint).empty())
+ if (HasMandatoryConstraints(it.constraints) &&
+ FilterFormats(it.constraints, formats,
+ &unsatisfied_constraint).empty()) {
result = MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED;
+ }
if (state_ != STARTED && result == MEDIA_DEVICE_OK)
result = MEDIA_DEVICE_TRACK_START_FAILURE;
@@ -564,17 +556,17 @@ void MediaStreamVideoSource::FinalizeAddTrack() {
if (result == MEDIA_DEVICE_OK) {
int max_width;
int max_height;
- GetDesiredMaxWidthAndHeight(it->constraints, &max_width, &max_height);
+ GetDesiredMaxWidthAndHeight(it.constraints, &max_width, &max_height);
double max_aspect_ratio;
double min_aspect_ratio;
- GetDesiredMinAndMaxAspectRatio(it->constraints,
+ GetDesiredMinAndMaxAspectRatio(it.constraints,
&min_aspect_ratio,
&max_aspect_ratio);
double max_frame_rate = 0.0f;
- GetConstraintValueAsDouble(it->constraints,
+ GetConstraintValueAsDouble(it.constraints,
kMaxFrameRate, &max_frame_rate);
- track_adapter_->AddTrack(it->track, it->frame_callback,
+ track_adapter_->AddTrack(it.track, it.frame_callback,
max_width, max_height,
min_aspect_ratio, max_aspect_ratio,
max_frame_rate);
@@ -582,8 +574,8 @@ void MediaStreamVideoSource::FinalizeAddTrack() {
DVLOG(3) << "FinalizeAddTrack() result " << result;
- if (!it->callback.is_null()) {
- it->callback.Run(this, result, unsatisfied_constraint);
+ if (!it.callback.is_null()) {
+ it.callback.Run(this, result, unsatisfied_constraint);
}
}
}
@@ -594,10 +586,8 @@ void MediaStreamVideoSource::SetReadyState(
DCHECK(CalledOnValidThread());
if (!owner().isNull())
owner().setReadyState(state);
- for (std::vector<MediaStreamVideoTrack*>::iterator it = tracks_.begin();
- it != tracks_.end(); ++it) {
- (*it)->OnReadyStateChanged(state);
- }
+ for (const auto& it : tracks_)
+ it->OnReadyStateChanged(state);
}
void MediaStreamVideoSource::SetMutedState(bool muted_state) {
« no previous file with comments | « no previous file | content/renderer/media/video_capture_impl.cc » ('j') | content/renderer/media/video_capture_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698