OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_VIDEO_SOURCE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 static bool IsConstraintSupported(const std::string& name); | 63 static bool IsConstraintSupported(const std::string& name); |
64 | 64 |
65 // Returns the MessageLoopProxy where video frames will be delivered on. | 65 // Returns the MessageLoopProxy where video frames will be delivered on. |
66 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() const; | 66 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() const; |
67 | 67 |
68 // Constraint keys used by a video source. | 68 // Constraint keys used by a video source. |
69 // Specified by draft-alvestrand-constraints-resolution-00b | 69 // Specified by draft-alvestrand-constraints-resolution-00b |
70 static const char kMinAspectRatio[]; // minAspectRatio | 70 static const char kMinAspectRatio[]; // minAspectRatio |
71 static const char kMaxAspectRatio[]; // maxAspectRatio | 71 static const char kMaxAspectRatio[]; // maxAspectRatio |
72 static const char kMaxWidth[]; // maxWidth | 72 static const char kMaxWidth[]; // maxWidth |
73 static const char kMinWidth[]; // minWidthOnCaptureFormats | 73 static const char kMinWidth[]; // minWidth |
74 static const char kMaxHeight[]; // maxHeight | 74 static const char kMaxHeight[]; // maxHeight |
75 static const char kMinHeight[]; // minHeight | 75 static const char kMinHeight[]; // minHeight |
76 static const char kMaxFrameRate[]; // maxFrameRate | 76 static const char kMaxFrameRate[]; // maxFrameRate |
77 static const char kMinFrameRate[]; // minFrameRate | 77 static const char kMinFrameRate[]; // minFrameRate |
78 | 78 |
79 enum { | 79 enum { |
80 // Default resolution. If no constraints are specified and the delegate | 80 // Default resolution. If no constraints are specified and the delegate |
81 // support it, this is the resolution that will be used. | 81 // support it, this is the resolution that will be used. |
82 kDefaultWidth = 640, | 82 kDefaultWidth = 640, |
83 kDefaultHeight = 480, | 83 kDefaultHeight = 480, |
(...skipping 16 matching lines...) Expand all Loading... |
100 // |max_requested_height| and |max_requested_width| is the max height and | 100 // |max_requested_height| and |max_requested_width| is the max height and |
101 // width set as a mandatory constraint if set when calling | 101 // width set as a mandatory constraint if set when calling |
102 // MediaStreamVideoSource::AddTrack. If max height and max width is not set | 102 // MediaStreamVideoSource::AddTrack. If max height and max width is not set |
103 // |max_requested_height| and |max_requested_width| are 0. | 103 // |max_requested_height| and |max_requested_width| are 0. |
104 virtual void GetCurrentSupportedFormats( | 104 virtual void GetCurrentSupportedFormats( |
105 int max_requested_width, | 105 int max_requested_width, |
106 int max_requested_height, | 106 int max_requested_height, |
107 double max_requested_frame_rate, | 107 double max_requested_frame_rate, |
108 const VideoCaptureDeviceFormatsCB& callback) = 0; | 108 const VideoCaptureDeviceFormatsCB& callback) = 0; |
109 | 109 |
110 // An implementation must start capture frames using the resolution in | 110 // An implementation must start capturing frames using the requested |
111 // |params|. When the source has started or the source failed to start | 111 // |format|. The fulfilled |constraints| are provided as additional context, |
112 // OnStartDone must be called. An implementation must call | 112 // and may be used to modify the behavior of the source. When the source has |
113 // |frame_callback| on the IO thread with the captured frames. | 113 // started or the source failed to start OnStartDone must be called. An |
| 114 // implementation must call |frame_callback| on the IO thread with the |
| 115 // captured frames. |
114 virtual void StartSourceImpl( | 116 virtual void StartSourceImpl( |
115 const media::VideoCaptureFormat& format, | 117 const media::VideoCaptureFormat& format, |
| 118 const blink::WebMediaConstraints& constraints, |
116 const VideoCaptureDeliverFrameCB& frame_callback) = 0; | 119 const VideoCaptureDeliverFrameCB& frame_callback) = 0; |
117 void OnStartDone(MediaStreamRequestResult result); | 120 void OnStartDone(MediaStreamRequestResult result); |
118 | 121 |
119 // An implementation must immediately stop capture video frames and must not | 122 // An implementation must immediately stop capture video frames and must not |
120 // call OnSupportedFormats after this method has been called. After this | 123 // call OnSupportedFormats after this method has been called. After this |
121 // method has been called, MediaStreamVideoSource may be deleted. | 124 // method has been called, MediaStreamVideoSource may be deleted. |
122 virtual void StopSourceImpl() = 0; | 125 virtual void StopSourceImpl() = 0; |
123 | 126 |
124 enum State { | 127 enum State { |
125 NEW, | 128 NEW, |
126 RETRIEVING_CAPABILITIES, | 129 RETRIEVING_CAPABILITIES, |
127 STARTING, | 130 STARTING, |
128 STARTED, | 131 STARTED, |
129 ENDED | 132 ENDED |
130 }; | 133 }; |
131 State state() const { return state_; } | 134 State state() const { return state_; } |
132 | 135 |
133 private: | 136 private: |
134 void OnSupportedFormats(const media::VideoCaptureFormats& formats); | 137 void OnSupportedFormats(const media::VideoCaptureFormats& formats); |
135 | 138 |
136 // Finds the first constraints in |requested_constraints_| that can be | 139 // Finds the first WebMediaConstraints in |requested_constraints_| that allows |
137 // fulfilled. |best_format| is set to the video resolution that can be | 140 // the use of one of the |formats|. |best_format| and |fulfilled_constraints| |
138 // fulfilled. | 141 // are set to the results of this search-and-match operation. Returns false |
| 142 // if no WebMediaConstraints allow the use any of the |formats|. |
139 bool FindBestFormatWithConstraints( | 143 bool FindBestFormatWithConstraints( |
140 const media::VideoCaptureFormats& formats, | 144 const media::VideoCaptureFormats& formats, |
141 media::VideoCaptureFormat* best_format); | 145 media::VideoCaptureFormat* best_format, |
| 146 blink::WebMediaConstraints* fulfilled_constraints); |
142 | 147 |
143 // Trigger all cached callbacks from AddTrack. AddTrack is successful | 148 // Trigger all cached callbacks from AddTrack. AddTrack is successful |
144 // if the capture delegate has started and the constraints provided in | 149 // if the capture delegate has started and the constraints provided in |
145 // AddTrack match the format that was used to start the device. | 150 // AddTrack match the format that was used to start the device. |
146 // Note that it must be ok to delete the MediaStreamVideoSource object | 151 // Note that it must be ok to delete the MediaStreamVideoSource object |
147 // in the context of the callback. If gUM fail, the implementation will | 152 // in the context of the callback. If gUM fail, the implementation will |
148 // simply drop the references to the blink source and track which will lead | 153 // simply drop the references to the blink source and track which will lead |
149 // to that this object is deleted. | 154 // to that this object is deleted. |
150 void FinalizeAddTrack(); | 155 void FinalizeAddTrack(); |
151 | 156 |
(...skipping 25 matching lines...) Expand all Loading... |
177 | 182 |
178 // NOTE: Weak pointers must be invalidated before all other member variables. | 183 // NOTE: Weak pointers must be invalidated before all other member variables. |
179 base::WeakPtrFactory<MediaStreamVideoSource> weak_factory_; | 184 base::WeakPtrFactory<MediaStreamVideoSource> weak_factory_; |
180 | 185 |
181 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoSource); | 186 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoSource); |
182 }; | 187 }; |
183 | 188 |
184 } // namespace content | 189 } // namespace content |
185 | 190 |
186 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_ | 191 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_ |
OLD | NEW |