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

Side by Side Diff: content/browser/media/capture/capture_resolution_evaluator.cc

Issue 1135823004: Implement all resolution change policies for desktop and tab capture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resolution_change_policy_constraints_ITEM1_CR1
Patch Set: Addressed Dale's comments. Created 5 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/media/capture/capture_resolution_evaluator.h"
6
7 #include "media/base/limits.h"
8 #include "media/base/video_util.h"
9
10 namespace content {
11
12 namespace {
13
14 // Compute the minimum frame size from the given |max_frame_size| and
15 // |resolution_change_policy|.
16 gfx::Size ComputeMinimumCaptureSize(
17 const gfx::Size& max_frame_size,
18 media::ResolutionChangePolicy resolution_change_policy) {
19 switch (resolution_change_policy) {
20 case media::RESOLUTION_POLICY_FIXED_RESOLUTION:
21 return max_frame_size;
22 case media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO: {
23 // TODO(miu): This is a place-holder until "min constraints" are plumbed-
24 // in from the MediaStream framework. http://crbug.com/473336
25 const int kMinLines = 180;
26 if (max_frame_size.height() <= kMinLines)
27 return max_frame_size;
28 const gfx::Size result(
29 kMinLines * max_frame_size.width() / max_frame_size.height(),
30 kMinLines);
31 if (result.width() <= 0 || result.width() > media::limits::kMaxDimension)
32 return max_frame_size;
33 return result;
34 }
35 case media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT:
36 break;
Wez 2015/05/13 19:05:08 nit: Suggest returning Size(1,1) explicitly here,
miu 2015/05/14 01:21:32 Done.
37 case media::RESOLUTION_POLICY_LAST:
Wez 2015/05/13 19:05:08 Won't this raise compilation errors since you're h
miu 2015/05/14 01:21:32 This is the "meaningless" enum value that only exi
Wez 2015/05/15 00:55:42 Dang, hoisted by my own petard! I thought the IPC
38 NOTREACHED();
39 }
40 return gfx::Size(1, 1);
Wez 2015/05/13 19:05:08 nit: Can you get rid of this if you add a return t
miu 2015/05/14 01:21:32 MSVC++ compiler complains, unfortunately, even tho
Wez 2015/05/15 00:55:42 I thought that VS2010 and above got this right, pr
miu 2015/05/15 21:14:00 Nope. The compile of patch set 4 (where I tried i
41 }
42
43 // Returns |size|, unless it exceeds |max_size| or is under |min_size|. When
44 // the bounds are exceeded, a uniformly scaled |size| is returned that is within
Wez 2015/05/13 19:05:08 nit: Is "uniformly scaled" sufficiently well-under
miu 2015/05/14 01:21:32 Done. Clarified.
45 // the bounds.
46 gfx::Size ComputeBoundedCaptureSize(const gfx::Size& size,
47 const gfx::Size& min_size,
48 const gfx::Size& max_size) {
49 if (size.width() > max_size.width() || size.height() > max_size.height()) {
50 gfx::Size result = media::ScaleSizeToFitWithinTarget(size, max_size);
51 result.SetToMax(min_size);
52 return result;
53 } else if (size.width() < min_size.width() ||
54 size.height() < min_size.height()) {
55 gfx::Size result = media::ScaleSizeToEncompassTarget(size, min_size);
56 result.SetToMin(max_size);
57 return result;
58 } else {
59 return size;
60 }
61 }
62
63 } // nampspace
64
65 CaptureResolutionEvaluator::CaptureResolutionEvaluator(
66 const gfx::Size& max_frame_size,
67 media::ResolutionChangePolicy resolution_change_policy)
68 : max_frame_size_(max_frame_size),
69 min_frame_size_(ComputeMinimumCaptureSize(max_frame_size,
70 resolution_change_policy)),
71 resolution_change_policy_(resolution_change_policy),
72 ideal_capture_size_(max_frame_size) {
73 DCHECK_LT(0, max_frame_size_.width());
74 DCHECK_LT(0, max_frame_size_.height());
75 DCHECK_LE(min_frame_size_.width(), max_frame_size_.width());
76 DCHECK_LE(min_frame_size_.height(), max_frame_size_.height());
77
78 UpdateCaptureSize();
79 }
80
81 CaptureResolutionEvaluator::~CaptureResolutionEvaluator() {}
82
83 void CaptureResolutionEvaluator::UpdateForNewSourceSize(
84 const gfx::Size& source_size) {
85 if (source_size.IsEmpty())
86 return;
87
88 switch (resolution_change_policy_) {
89 case media::RESOLUTION_POLICY_FIXED_RESOLUTION:
90 // Source size changes do not affect the frame resolution. Frame
91 // resolution is always fixed to |max_frame_size_|.
92 break;
93
94 case media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO:
95 ideal_capture_size_ = ComputeBoundedCaptureSize(
96 media::PadToMatchAspectRatio(source_size, max_frame_size_),
97 min_frame_size_,
98 max_frame_size_);
99 UpdateCaptureSize();
100 break;
101
102 case media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT:
103 ideal_capture_size_ = ComputeBoundedCaptureSize(
104 source_size, min_frame_size_, max_frame_size_);
105 UpdateCaptureSize();
106 break;
107
108 case media::RESOLUTION_POLICY_LAST:
109 NOTREACHED();
110 }
111 }
112
113 void CaptureResolutionEvaluator::UpdateForNewCapabilityLimit(int num_pixels) {
Wez 2015/05/13 19:05:08 Is the rationale for including this in this CL rat
miu 2015/05/14 01:21:32 No. I decided to add it in as a skeleton method s
Wez 2015/05/15 00:55:42 OK; in that case I'd remove it and just add it in
miu 2015/05/15 21:14:00 Done.
114 NOTIMPLEMENTED();
115 }
116
117 void CaptureResolutionEvaluator::UpdateCaptureSize() {
118 // TODO(miu): An upcoming change will introduce the ability to find the best
119 // capture resolution, given the current capabilities of the system.
Wez 2015/05/13 19:05:08 Bug # for that change? :)
miu 2015/05/14 01:21:31 Done.
120 capture_size_ = ideal_capture_size_;
121 }
122
123 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698