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