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

Side by Side Diff: content/renderer/media/media_stream_constraints_util_video_device.h

Issue 2751643003: Minor refactoring of SelectSettings results for consistency. (Closed)
Patch Set: Created 3 years, 9 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_VIDEO_DEVICE_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_VIDEO_DEVICE_H_
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_VIDEO_DEVICE_H_ 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_VIDEO_DEVICE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h"
11 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
12 #include "content/common/media/media_devices.mojom.h" 13 #include "content/common/media/media_devices.mojom.h"
13 #include "media/capture/video_capture_types.h" 14 #include "media/capture/video_capture_types.h"
14 #include "third_party/webrtc/base/optional.h" 15 #include "third_party/webrtc/base/optional.h"
15 16
16 namespace blink { 17 namespace blink {
17 class WebString; 18 class WebString;
18 class WebMediaConstraints; 19 class WebMediaConstraints;
19 } 20 }
20 21
(...skipping 10 matching lines...) Expand all
31 ~VideoDeviceCaptureCapabilities(); 32 ~VideoDeviceCaptureCapabilities();
32 VideoDeviceCaptureCapabilities& operator=( 33 VideoDeviceCaptureCapabilities& operator=(
33 VideoDeviceCaptureCapabilities&& other); 34 VideoDeviceCaptureCapabilities&& other);
34 35
35 // Each field is independent of each other. 36 // Each field is independent of each other.
36 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> device_capabilities; 37 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> device_capabilities;
37 std::vector<media::PowerLineFrequency> power_line_capabilities; 38 std::vector<media::PowerLineFrequency> power_line_capabilities;
38 std::vector<rtc::Optional<bool>> noise_reduction_capabilities; 39 std::vector<rtc::Optional<bool>> noise_reduction_capabilities;
39 }; 40 };
40 41
41 struct CONTENT_EXPORT VideoDeviceCaptureSourceSelectionResult { 42 class CONTENT_EXPORT VideoDeviceCaptureSourceSelectionResult {
43 public:
44 // Creates a result without value and with an empty failed constraint name.
42 VideoDeviceCaptureSourceSelectionResult(); 45 VideoDeviceCaptureSourceSelectionResult();
hta - Chromium 2017/03/15 11:55:08 Can we remove this constructor, since it creates a
Guido Urdaneta 2017/03/15 19:16:47 My original intention was to remove it, but we nee
46
47 // Creates a result without value and with the given |failed_constraint_name|.
48 // Does not take ownership of |failed_constraint_name|, so it must be null or
49 // point to a string that remains accessible.
50 explicit VideoDeviceCaptureSourceSelectionResult(
51 const char* failed_constraint_name);
52
53 // Creates a result with the given values. |device_id| is moved to an internal
54 // field.
43 VideoDeviceCaptureSourceSelectionResult( 55 VideoDeviceCaptureSourceSelectionResult(
56 const std::string& device_id,
57 ::mojom::FacingMode facing_mode_,
58 media::VideoCaptureParams capture_params_,
59 rtc::Optional<bool> noise_reduction_);
60
61 VideoDeviceCaptureSourceSelectionResult(
62 const VideoDeviceCaptureSourceSelectionResult& other);
63 VideoDeviceCaptureSourceSelectionResult& operator=(
44 const VideoDeviceCaptureSourceSelectionResult& other); 64 const VideoDeviceCaptureSourceSelectionResult& other);
45 VideoDeviceCaptureSourceSelectionResult( 65 VideoDeviceCaptureSourceSelectionResult(
46 VideoDeviceCaptureSourceSelectionResult&& other); 66 VideoDeviceCaptureSourceSelectionResult&& other);
47 ~VideoDeviceCaptureSourceSelectionResult();
48 VideoDeviceCaptureSourceSelectionResult& operator=(
49 const VideoDeviceCaptureSourceSelectionResult& other);
50 VideoDeviceCaptureSourceSelectionResult& operator=( 67 VideoDeviceCaptureSourceSelectionResult& operator=(
51 VideoDeviceCaptureSourceSelectionResult&& other); 68 VideoDeviceCaptureSourceSelectionResult&& other);
69 ~VideoDeviceCaptureSourceSelectionResult();
52 70
53 bool HasValue() const { return failed_constraint_name == nullptr; } 71 bool HasValue() const { return failed_constraint_name_ == nullptr; }
54 72
55 // Convenience accessors for fields embedded in |capture_params|. 73 // Convenience accessors for fields embedded in |capture_params|.
56 const media::VideoCaptureFormat& Format() const { 74 const media::VideoCaptureFormat& Format() const {
57 return capture_params.requested_format; 75 return capture_params_.requested_format;
58 } 76 }
59 int Width() const { 77 int Width() const {
60 return capture_params.requested_format.frame_size.width(); 78 DCHECK(HasValue());
79 return capture_params_.requested_format.frame_size.width();
61 } 80 }
62 int Height() const { 81 int Height() const {
63 return capture_params.requested_format.frame_size.height(); 82 DCHECK(HasValue());
83 return capture_params_.requested_format.frame_size.height();
64 } 84 }
65 float FrameRate() const { return capture_params.requested_format.frame_rate; } 85 float FrameRate() const {
86 DCHECK(HasValue());
87 return capture_params_.requested_format.frame_rate;
88 }
66 media::PowerLineFrequency PowerLineFrequency() const { 89 media::PowerLineFrequency PowerLineFrequency() const {
67 return capture_params.power_line_frequency; 90 DCHECK(HasValue());
91 return capture_params_.power_line_frequency;
68 } 92 }
69 93
70 const char* failed_constraint_name; 94 // Other accessors.
71 std::string device_id; 95 const char* failed_constraint_name() const { return failed_constraint_name_; }
72 ::mojom::FacingMode facing_mode; 96
73 media::VideoCaptureParams capture_params; 97 const std::string& device_id() const {
74 rtc::Optional<bool> noise_reduction; 98 DCHECK(HasValue());
99 return device_id_;
100 }
101
102 ::mojom::FacingMode facing_mode() const {
103 DCHECK(HasValue());
104 return facing_mode_;
105 }
106
107 const media::VideoCaptureParams& capture_params() const {
108 DCHECK(HasValue());
109 return capture_params_;
110 }
111
112 const rtc::Optional<bool>& noise_reduction() const {
113 DCHECK(HasValue());
114 return noise_reduction_;
115 }
116
117 private:
118 const char* failed_constraint_name_;
119 std::string device_id_;
120 ::mojom::FacingMode facing_mode_;
121 media::VideoCaptureParams capture_params_;
122 rtc::Optional<bool> noise_reduction_;
75 }; 123 };
76 124
77 // This function performs source and source-settings selection based on 125 // This function performs source and source-settings selection based on
78 // the given |capabilities| and |constraints|. 126 // the given |capabilities| and |constraints|.
79 // Chromium performs constraint resolution in two steps. First, a source and its 127 // Chromium performs constraint resolution in two steps. First, a source and its
80 // settings are selected; then a track is created, connected to the source, and 128 // settings are selected; then a track is created, connected to the source, and
81 // finally the track settings are selected. This function implements an 129 // finally the track settings are selected. This function implements an
82 // algorithm for the first step. Sources are not a user-visible concept, so the 130 // algorithm for the first step. Sources are not a user-visible concept, so the
83 // spec only specifies an algorithm for track settings. 131 // spec only specifies an algorithm for track settings.
84 // This algorithm for sources is compatible with the spec algorithm for tracks, 132 // This algorithm for sources is compatible with the spec algorithm for tracks,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // reduction, resolution, and frame rate, in that order. Note that there is 185 // reduction, resolution, and frame rate, in that order. Note that there is
138 // no default facing mode or aspect ratio. 186 // no default facing mode or aspect ratio.
139 VideoDeviceCaptureSourceSelectionResult CONTENT_EXPORT 187 VideoDeviceCaptureSourceSelectionResult CONTENT_EXPORT
140 SelectVideoDeviceCaptureSourceSettings( 188 SelectVideoDeviceCaptureSourceSettings(
141 const VideoDeviceCaptureCapabilities& capabilities, 189 const VideoDeviceCaptureCapabilities& capabilities,
142 const blink::WebMediaConstraints& constraints); 190 const blink::WebMediaConstraints& constraints);
143 191
144 } // namespace content 192 } // namespace content
145 193
146 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_VIDEO_DEVICE_H_ 194 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_CONSTRAINTS_UTIL_VIDEO_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698