| 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 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/common/media/video_capture.h" | 15 #include "content/common/media/video_capture.h" |
| 16 #include "content/renderer/media/media_stream_source.h" | 16 #include "content/renderer/media/media_stream_source.h" |
| 17 #include "content/renderer/media/video_frame_deliverer.h" | |
| 18 #include "media/base/video_frame.h" | 17 #include "media/base/video_frame.h" |
| 19 #include "media/video/capture/video_capture_types.h" | 18 #include "media/video/capture/video_capture_types.h" |
| 20 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 21 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 22 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 21 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 23 | 22 |
| 24 namespace content { | 23 namespace content { |
| 25 | 24 |
| 26 class MediaStreamVideoTrack; | 25 class MediaStreamVideoTrack; |
| 26 class VideoTrackAdapter; |
| 27 | 27 |
| 28 // MediaStreamVideoSource is an interface used for sending video frames to a | 28 // MediaStreamVideoSource is an interface used for sending video frames to a |
| 29 // MediaStreamVideoTrack. | 29 // MediaStreamVideoTrack. |
| 30 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html | 30 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html |
| 31 // The purpose of this base class is to be able to implement different | 31 // The purpose of this base class is to be able to implement different |
| 32 // MediaStreaVideoSources such as local video capture, video sources received | 32 // MediaStreaVideoSources such as local video capture, video sources received |
| 33 // on a PeerConnection or a source created in NaCl. | 33 // on a PeerConnection or a source created in NaCl. |
| 34 // All methods calls will be done from the main render thread. | 34 // All methods calls will be done from the main render thread. |
| 35 // | 35 // |
| 36 // When the first track is added to the source by calling AddTrack | 36 // When the first track is added to the source by calling AddTrack |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 STARTED, | 122 STARTED, |
| 123 ENDED | 123 ENDED |
| 124 }; | 124 }; |
| 125 State state() const { return state_; } | 125 State state() const { return state_; } |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 void OnSupportedFormats(const media::VideoCaptureFormats& formats); | 128 void OnSupportedFormats(const media::VideoCaptureFormats& formats); |
| 129 | 129 |
| 130 // Finds the first constraints in |requested_constraints_| that can be | 130 // Finds the first constraints in |requested_constraints_| that can be |
| 131 // fulfilled. |best_format| is set to the video resolution that can be | 131 // fulfilled. |best_format| is set to the video resolution that can be |
| 132 // fulfilled. |frame_output_size| is the requested frame size after cropping. | 132 // fulfilled. |
| 133 // |resulting_constraints| is set to the found constraints in | |
| 134 // |requested_constraints_|. | |
| 135 bool FindBestFormatWithConstraints( | 133 bool FindBestFormatWithConstraints( |
| 136 const media::VideoCaptureFormats& formats, | 134 const media::VideoCaptureFormats& formats, |
| 137 media::VideoCaptureFormat* best_format, | 135 media::VideoCaptureFormat* best_format); |
| 138 gfx::Size* frame_output_size, | |
| 139 blink::WebMediaConstraints* resulting_constraints); | |
| 140 | 136 |
| 141 // Trigger all cached callbacks from AddTrack. AddTrack is successful | 137 // Trigger all cached callbacks from AddTrack. AddTrack is successful |
| 142 // if the capture delegate has started and the constraints provided in | 138 // if the capture delegate has started and the constraints provided in |
| 143 // AddTrack match the format that was used to start the device. | 139 // AddTrack match the format that was used to start the device. |
| 144 // Note that it must be ok to delete the MediaStreamVideoSource object | 140 // Note that it must be ok to delete the MediaStreamVideoSource object |
| 145 // in the context of the callback. If gUM fail, the implementation will | 141 // in the context of the callback. If gUM fail, the implementation will |
| 146 // simply drop the references to the blink source and track which will lead | 142 // simply drop the references to the blink source and track which will lead |
| 147 // to that this object is deleted. | 143 // to that this object is deleted. |
| 148 void FinalizeAddTrack(); | 144 void FinalizeAddTrack(); |
| 149 | 145 |
| 150 State state_; | 146 State state_; |
| 151 | 147 |
| 152 media::VideoCaptureFormat current_format_; | 148 media::VideoCaptureFormat current_format_; |
| 153 blink::WebMediaConstraints current_constraints_; | |
| 154 // |max_frame_output_size_| is the maximum frame size allowed by | |
| 155 // |current_constraints_|. | |
| 156 gfx::Size max_frame_output_size_; | |
| 157 | 149 |
| 158 struct RequestedConstraints { | 150 struct RequestedConstraints { |
| 159 RequestedConstraints(MediaStreamVideoTrack* track, | 151 RequestedConstraints(MediaStreamVideoTrack* track, |
| 160 const VideoCaptureDeliverFrameCB& frame_callback, | 152 const VideoCaptureDeliverFrameCB& frame_callback, |
| 161 const blink::WebMediaConstraints& constraints, | 153 const blink::WebMediaConstraints& constraints, |
| 162 const ConstraintsCallback& callback); | 154 const ConstraintsCallback& callback); |
| 163 ~RequestedConstraints(); | 155 ~RequestedConstraints(); |
| 164 | 156 |
| 165 MediaStreamVideoTrack* track; | 157 MediaStreamVideoTrack* track; |
| 166 VideoCaptureDeliverFrameCB frame_callback; | 158 VideoCaptureDeliverFrameCB frame_callback; |
| 167 blink::WebMediaConstraints constraints; | 159 blink::WebMediaConstraints constraints; |
| 168 ConstraintsCallback callback; | 160 ConstraintsCallback callback; |
| 169 }; | 161 }; |
| 170 std::vector<RequestedConstraints> requested_constraints_; | 162 std::vector<RequestedConstraints> requested_constraints_; |
| 171 | 163 |
| 172 media::VideoCaptureFormats supported_formats_; | 164 media::VideoCaptureFormats supported_formats_; |
| 173 | 165 |
| 174 // |FrameDeliverer| is an internal helper object used for delivering video | 166 // |track_adapter_| delivers video frames to the tracks on the IO-thread. |
| 175 // frames using callbacks to all registered tracks on the IO thread. | 167 scoped_refptr<VideoTrackAdapter> track_adapter_; |
| 176 class FrameDeliverer; | |
| 177 scoped_refptr<FrameDeliverer> frame_deliverer_; | |
| 178 | 168 |
| 179 // Tracks that currently are receiving video frames. | 169 // Tracks that currently are connected to this source. |
| 180 std::vector<MediaStreamVideoTrack*> tracks_; | 170 std::vector<MediaStreamVideoTrack*> tracks_; |
| 181 | 171 |
| 182 // NOTE: Weak pointers must be invalidated before all other member variables. | 172 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 183 base::WeakPtrFactory<MediaStreamVideoSource> weak_factory_; | 173 base::WeakPtrFactory<MediaStreamVideoSource> weak_factory_; |
| 184 | 174 |
| 185 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoSource); | 175 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoSource); |
| 186 }; | 176 }; |
| 187 | 177 |
| 188 } // namespace content | 178 } // namespace content |
| 189 | 179 |
| 190 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_ | 180 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_ |
| OLD | NEW |