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

Side by Side Diff: media/capture/content/capture_resolution_chooser.h

Issue 2143903003: [WIP] Move media/capture to device/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 #ifndef MEDIA_CAPTURE_CONTENT_CAPTURE_RESOLUTION_CHOOSER_H_
6 #define MEDIA_CAPTURE_CONTENT_CAPTURE_RESOLUTION_CHOOSER_H_
7
8 #include <vector>
9
10 #include "media/base/video_capture_types.h"
11 #include "media/capture/capture_export.h"
12 #include "ui/gfx/geometry/size.h"
13
14 namespace media {
15
16 // Encapsulates the logic that determines the capture frame resolution based on:
17 // 1. The configured maximum frame resolution and resolution change policy.
18 // 2. Changes to resolution of the source content.
19 // 3. Changes to the (externally-computed) target data volume, provided in
20 // terms of the number of pixels in the frame.
21 //
22 // CaptureResolutionChooser always computes capture sizes less than the maximum
23 // frame size, and adheres to the configured resolution change policy. Within
24 // those hard limits, the capture size is computed to be as close to the
25 // targeted frame area as possible.
26 //
27 // In variable-resolution use cases, the capture sizes are "snapped" to a small
28 // (i.e., usually less than a dozen) set of possibilities. This is to prevent
29 // the end-to-end system from having to deal with rapidly-changing video frame
30 // resolutions that results from providing a fine-grained range of values. The
31 // possibile snapped frame sizes are computed relative to the resolution of the
32 // source content: They are the same or smaller in size, and are of the same
33 // aspect ratio.
34 class CAPTURE_EXPORT CaptureResolutionChooser {
35 public:
36 // media::ResolutionChangePolicy determines whether the variable frame
37 // resolutions being computed must adhere to a fixed aspect ratio or not, or
38 // that there must only be a single fixed resolution.
39 CaptureResolutionChooser(const gfx::Size& max_frame_size,
40 ResolutionChangePolicy resolution_change_policy);
41 ~CaptureResolutionChooser();
42
43 // Returns the current capture frame resolution to use.
44 gfx::Size capture_size() const { return capture_size_; }
45
46 // Updates the capture size based on a change in the resolution of the source
47 // content.
48 void SetSourceSize(const gfx::Size& source_size);
49
50 // Updates the capture size to target the given frame area, in terms of
51 // gfx::Size::GetArea(). The initial target frame area is the maximum int
52 // (i.e., always target the source size).
53 void SetTargetFrameArea(int area);
54
55 // Search functions to, given a frame |area|, return the nearest snapped frame
56 // size, or N size steps up/down. Snapped frame sizes are based on the
57 // current source size.
58 gfx::Size FindNearestFrameSize(int area) const;
59 gfx::Size FindLargerFrameSize(int area, int num_steps_up) const;
60 gfx::Size FindSmallerFrameSize(int area, int num_steps_down) const;
61
62 private:
63 // Called after any update that requires |capture_size_| be re-computed.
64 void RecomputeCaptureSize();
65
66 // Recomputes the |snapped_sizes_| cache.
67 void UpdateSnappedFrameSizes(const gfx::Size& constrained_size);
68
69 // Hard constraints.
70 const gfx::Size max_frame_size_;
71 const gfx::Size min_frame_size_; // Computed from the ctor arguments.
72
73 // Specifies the set of heuristics to use.
74 const ResolutionChangePolicy resolution_change_policy_;
75
76 // |capture_size_| will be computed such that its area is as close to this
77 // value as possible.
78 int target_area_;
79
80 // The current computed capture frame resolution.
81 gfx::Size capture_size_;
82
83 // Cache of the set of possible values |capture_size_| can have, in order from
84 // smallest to largest. This is recomputed whenever UpdateSnappedFrameSizes()
85 // is called.
86 std::vector<gfx::Size> snapped_sizes_;
87 };
88
89 } // namespace media
90
91 #endif // MEDIA_CAPTURE_CONTENT_CAPTURE_RESOLUTION_CHOOSER_H_
OLDNEW
« no previous file with comments | « media/capture/content/animated_content_sampler_unittest.cc ('k') | media/capture/content/capture_resolution_chooser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698