| 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 <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 23 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 24 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 24 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 25 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 25 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 class MediaStreamVideoTrack; | 29 class MediaStreamVideoTrack; |
| 30 class VideoTrackAdapter; | 30 class VideoTrackAdapter; |
| 31 struct VideoTrackAdapterSettings; | 31 struct VideoTrackAdapterSettings; |
| 32 | 32 |
| 33 CONTENT_EXPORT bool IsOldVideoConstraints(); | |
| 34 | |
| 35 // MediaStreamVideoSource is an interface used for sending video frames to a | 33 // MediaStreamVideoSource is an interface used for sending video frames to a |
| 36 // MediaStreamVideoTrack. | 34 // MediaStreamVideoTrack. |
| 37 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html | 35 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html |
| 38 // The purpose of this base class is to be able to implement different | 36 // The purpose of this base class is to be able to implement different |
| 39 // MediaStreaVideoSources such as local video capture, video sources received | 37 // MediaStreaVideoSources such as local video capture, video sources received |
| 40 // on a PeerConnection or a source created in NaCl. | 38 // on a PeerConnection or a source created in NaCl. |
| 41 // All methods calls will be done from the main render thread. | 39 // All methods calls will be done from the main render thread. |
| 42 // | 40 // |
| 43 // When the first track is added to the source by calling AddTrack, the | 41 // When the first track is added to the source by calling AddTrack, the |
| 44 // MediaStreamVideoSource implementation calls GetCurrentSupportedFormats. | 42 // MediaStreamVideoSource implementation calls GetCurrentSupportedFormats. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 66 | 64 |
| 67 // Returns the MediaStreamVideoSource object owned by |source|. | 65 // Returns the MediaStreamVideoSource object owned by |source|. |
| 68 static MediaStreamVideoSource* GetVideoSource( | 66 static MediaStreamVideoSource* GetVideoSource( |
| 69 const blink::WebMediaStreamSource& source); | 67 const blink::WebMediaStreamSource& source); |
| 70 | 68 |
| 71 // Puts |track| in the registered tracks list. | 69 // Puts |track| in the registered tracks list. |
| 72 void AddTrack(MediaStreamVideoTrack* track, | 70 void AddTrack(MediaStreamVideoTrack* track, |
| 73 const VideoTrackAdapterSettings& track_adapter_settings, | 71 const VideoTrackAdapterSettings& track_adapter_settings, |
| 74 const VideoCaptureDeliverFrameCB& frame_callback, | 72 const VideoCaptureDeliverFrameCB& frame_callback, |
| 75 const ConstraintsCallback& callback); | 73 const ConstraintsCallback& callback); |
| 76 // TODO(guidou): Remove this method. http://crbug.com/706408 | |
| 77 void AddTrackLegacy(MediaStreamVideoTrack* track, | |
| 78 const VideoCaptureDeliverFrameCB& frame_callback, | |
| 79 const blink::WebMediaConstraints& constraints, | |
| 80 const ConstraintsCallback& callback); | |
| 81 void RemoveTrack(MediaStreamVideoTrack* track); | 74 void RemoveTrack(MediaStreamVideoTrack* track); |
| 82 | 75 |
| 83 // Called by |track| to notify the source whether it has any paths to a | 76 // Called by |track| to notify the source whether it has any paths to a |
| 84 // consuming endpoint. | 77 // consuming endpoint. |
| 85 void UpdateHasConsumers(MediaStreamVideoTrack* track, bool has_consumers); | 78 void UpdateHasConsumers(MediaStreamVideoTrack* track, bool has_consumers); |
| 86 | 79 |
| 87 void UpdateCapturingLinkSecure(MediaStreamVideoTrack* track, bool is_secure); | 80 void UpdateCapturingLinkSecure(MediaStreamVideoTrack* track, bool is_secure); |
| 88 | 81 |
| 89 // Request underlying source to capture a new frame. | 82 // Request underlying source to capture a new frame. |
| 90 virtual void RequestRefreshFrame() {} | 83 virtual void RequestRefreshFrame() {} |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // frames, giving it the option of running in an "idle" state to minimize | 142 // frames, giving it the option of running in an "idle" state to minimize |
| 150 // resource usage. | 143 // resource usage. |
| 151 virtual void OnHasConsumers(bool has_consumers) {} | 144 virtual void OnHasConsumers(bool has_consumers) {} |
| 152 | 145 |
| 153 // Optionally overridden by subclasses to act on whether the capturing link | 146 // Optionally overridden by subclasses to act on whether the capturing link |
| 154 // has become secure or insecure. | 147 // has become secure or insecure. |
| 155 virtual void OnCapturingLinkSecured(bool is_secure) {} | 148 virtual void OnCapturingLinkSecured(bool is_secure) {} |
| 156 | 149 |
| 157 enum State { | 150 enum State { |
| 158 NEW, | 151 NEW, |
| 159 // TODO(guidou): Remove this state. http://crbug.com/706408 | |
| 160 RETRIEVING_CAPABILITIES, | |
| 161 STARTING, | 152 STARTING, |
| 162 STARTED, | 153 STARTED, |
| 163 ENDED | 154 ENDED |
| 164 }; | 155 }; |
| 165 State state() const { return state_; } | 156 State state() const { return state_; } |
| 166 | 157 |
| 167 SEQUENCE_CHECKER(sequence_checker_); | 158 SEQUENCE_CHECKER(sequence_checker_); |
| 168 | 159 |
| 169 private: | 160 private: |
| 170 void OnSupportedFormats(const media::VideoCaptureFormats& formats); | |
| 171 | |
| 172 // Finds the first WebMediaConstraints in |track_descriptors_| that allows | |
| 173 // the use of one of the |formats|. |best_format| and |fulfilled_constraints| | |
| 174 // are set to the results of this search-and-match operation. Returns false | |
| 175 // if no WebMediaConstraints allow the use any of the |formats|. | |
| 176 bool FindBestFormatWithConstraints( | |
| 177 const media::VideoCaptureFormats& formats, | |
| 178 media::VideoCaptureFormat* best_format, | |
| 179 blink::WebMediaConstraints* fulfilled_constraints); | |
| 180 | |
| 181 // Trigger all cached callbacks from AddTrack. AddTrack is successful | 161 // Trigger all cached callbacks from AddTrack. AddTrack is successful |
| 182 // if the capture delegate has started and the constraints provided in | 162 // if the capture delegate has started and the constraints provided in |
| 183 // AddTrack match the format that was used to start the device. | 163 // AddTrack match the format that was used to start the device. |
| 184 // Note that it must be ok to delete the MediaStreamVideoSource object | 164 // Note that it must be ok to delete the MediaStreamVideoSource object |
| 185 // in the context of the callback. If gUM fails, the implementation will | 165 // in the context of the callback. If gUM fails, the implementation will |
| 186 // simply drop the references to the blink source and track which will lead | 166 // simply drop the references to the blink source and track which will lead |
| 187 // to this object being deleted. | 167 // to this object being deleted. |
| 188 void FinalizeAddTrack(); | 168 void FinalizeAddTrack(); |
| 189 // TODO(guidou): Remove this method. http://crbug.com/706408 | |
| 190 void FinalizeAddTrackLegacy(); | |
| 191 | 169 |
| 192 State state_; | 170 State state_; |
| 193 | 171 |
| 194 // TODO(guidou): Remove this field. http://crbug.com/706408 | |
| 195 media::VideoCaptureFormat current_format_; | |
| 196 | |
| 197 struct TrackDescriptor { | 172 struct TrackDescriptor { |
| 198 TrackDescriptor(MediaStreamVideoTrack* track, | 173 TrackDescriptor(MediaStreamVideoTrack* track, |
| 199 const VideoCaptureDeliverFrameCB& frame_callback, | 174 const VideoCaptureDeliverFrameCB& frame_callback, |
| 200 const blink::WebMediaConstraints& constraints, | |
| 201 const ConstraintsCallback& callback); | |
| 202 TrackDescriptor(MediaStreamVideoTrack* track, | |
| 203 const VideoCaptureDeliverFrameCB& frame_callback, | |
| 204 std::unique_ptr<VideoTrackAdapterSettings> adapter_settings, | 175 std::unique_ptr<VideoTrackAdapterSettings> adapter_settings, |
| 205 const ConstraintsCallback& callback); | 176 const ConstraintsCallback& callback); |
| 206 TrackDescriptor(TrackDescriptor&& other); | 177 TrackDescriptor(TrackDescriptor&& other); |
| 207 TrackDescriptor& operator=(TrackDescriptor&& other); | 178 TrackDescriptor& operator=(TrackDescriptor&& other); |
| 208 ~TrackDescriptor(); | 179 ~TrackDescriptor(); |
| 209 | 180 |
| 210 MediaStreamVideoTrack* track; | 181 MediaStreamVideoTrack* track; |
| 211 VideoCaptureDeliverFrameCB frame_callback; | 182 VideoCaptureDeliverFrameCB frame_callback; |
| 212 // TODO(guidou): remove this field. http://crbug.com/706408 | |
| 213 blink::WebMediaConstraints constraints; | |
| 214 // TODO(guidou): Make |adapter_settings| a regular field instead of a | 183 // TODO(guidou): Make |adapter_settings| a regular field instead of a |
| 215 // unique_ptr. | 184 // unique_ptr. |
| 216 std::unique_ptr<VideoTrackAdapterSettings> adapter_settings; | 185 std::unique_ptr<VideoTrackAdapterSettings> adapter_settings; |
| 217 ConstraintsCallback callback; | 186 ConstraintsCallback callback; |
| 218 }; | 187 }; |
| 219 std::vector<TrackDescriptor> track_descriptors_; | 188 std::vector<TrackDescriptor> track_descriptors_; |
| 220 | 189 |
| 221 media::VideoCaptureFormats supported_formats_; | |
| 222 | |
| 223 // |track_adapter_| delivers video frames to the tracks on the IO-thread. | 190 // |track_adapter_| delivers video frames to the tracks on the IO-thread. |
| 224 const scoped_refptr<VideoTrackAdapter> track_adapter_; | 191 const scoped_refptr<VideoTrackAdapter> track_adapter_; |
| 225 | 192 |
| 226 // Tracks that currently are connected to this source. | 193 // Tracks that currently are connected to this source. |
| 227 std::vector<MediaStreamVideoTrack*> tracks_; | 194 std::vector<MediaStreamVideoTrack*> tracks_; |
| 228 | 195 |
| 229 // Tracks that have no paths to a consuming endpoint, and so do not need | 196 // Tracks that have no paths to a consuming endpoint, and so do not need |
| 230 // frames delivered from the source. This is a subset of |tracks_|. | 197 // frames delivered from the source. This is a subset of |tracks_|. |
| 231 std::vector<MediaStreamVideoTrack*> suspended_tracks_; | 198 std::vector<MediaStreamVideoTrack*> suspended_tracks_; |
| 232 | 199 |
| 233 // This is used for tracking if all connected video sinks are secure. | 200 // This is used for tracking if all connected video sinks are secure. |
| 234 SecureDisplayLinkTracker<MediaStreamVideoTrack> secure_tracker_; | 201 SecureDisplayLinkTracker<MediaStreamVideoTrack> secure_tracker_; |
| 235 | 202 |
| 236 // NOTE: Weak pointers must be invalidated before all other member variables. | 203 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 237 base::WeakPtrFactory<MediaStreamVideoSource> weak_factory_; | 204 base::WeakPtrFactory<MediaStreamVideoSource> weak_factory_; |
| 238 | 205 |
| 239 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoSource); | 206 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoSource); |
| 240 }; | 207 }; |
| 241 | 208 |
| 242 } // namespace content | 209 } // namespace content |
| 243 | 210 |
| 244 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_ | 211 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_ |
| OLD | NEW |