summaryrefslogtreecommitdiffstats
path: root/content/renderer/media/media_stream_video_source.h
diff options
context:
space:
mode:
authorperkj@chromium.org <perkj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-26 11:25:41 +0000
committerperkj@chromium.org <perkj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-26 11:25:41 +0000
commit2bb8e323c7d10ce6ff1b301f185f9dd57896f330 (patch)
tree9cf2015b0fd0bd015848810929a6998c7d7f86e0 /content/renderer/media/media_stream_video_source.h
parent11ff8c7bda21d8f35fd4fe5fd3e3151ded80ca85 (diff)
downloadchromium_src-2bb8e323c7d10ce6ff1b301f185f9dd57896f330.zip
chromium_src-2bb8e323c7d10ce6ff1b301f185f9dd57896f330.tar.gz
chromium_src-2bb8e323c7d10ce6ff1b301f185f9dd57896f330.tar.bz2
Implement MediaStreamVideoSource using video capturerers in Chrome.
This cl deprecates the use of the old RTCVideoCapturer that inherits cricket::VideoCapturer from libjingle and moves the constraints parsing of video resolution from libjingle to Chrome in MediaStreamVideoSource. Other, none standard, constraints such as CPU adaptation etc are still parsed in libjingle. Note that we still rely on the libjingle video track implementation to forward frames from the source to all its sinks. WebRtcVideoCapturerAdapter is added that implements cricket::VideoCapturer and this is currently used to forward video frames from MediaStreamVideoSource to the libjingle MediaStreamVideoTracks. Before this change a video frame was delivered to a PeerConnection via RtcVideoCaptureDelegate-> RtcVideoCapturer(cricket::VideoCapturer>->WebRtcVideoEngineChannel(in libjingle) After this change: VideoCaptureDelegate->MediaStreamVideoSource->WebRtcVideoCaptureAdapter(cricket::VideoCapturer)->WebRtcVideoEngineChannel(in libjingle) MediaStreamVideoSource is intended to be a generic source implementation that can be used for local video capture, remote video sources and Nacl. The reason to have constraints parsing in MediaStreamVideoSource is because we can then implement scaling/cropping etc for different tracks regardless of the source type. ie- it would be possible to crop video data from a remote video track if so is requested. Adding tbr jam for gypi changes. TBR=jam BUG=247937 Review URL: https://codereview.chromium.org/144083002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253401 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/media/media_stream_video_source.h')
-rw-r--r--content/renderer/media/media_stream_video_source.h141
1 files changed, 105 insertions, 36 deletions
diff --git a/content/renderer/media/media_stream_video_source.h b/content/renderer/media/media_stream_video_source.h
index 063bf0c..8e7d51a1 100644
--- a/content/renderer/media/media_stream_video_source.h
+++ b/content/renderer/media/media_stream_video_source.h
@@ -5,11 +5,14 @@
#ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_
#define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_
+#include <vector>
+
#include "base/compiler_specific.h"
-#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "content/renderer/media/media_stream_dependency_factory.h"
#include "content/renderer/media/media_stream_source.h"
+#include "media/base/video_frame.h"
+#include "media/video/capture/video_capture_types.h"
#include "third_party/WebKit/public/platform/WebMediaConstraints.h"
#include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
@@ -21,19 +24,29 @@ class VideoFrame;
namespace content {
class MediaStreamDependencyFactory;
+class WebRtcVideoCapturerAdapter;
// MediaStreamVideoSource is an interface used for sending video frames to a
// MediaStreamVideoTrack.
// http://dev.w3.org/2011/webrtc/editor/getusermedia.html
+// The purpose of this base class is to be able to implement different
+// MediaStreaVideoSources such as local video capture, video sources received
+// on a PeerConnection or a source created in NaCl.
// All methods calls will be done from the main render thread.
+//
+// When the first track is added to the source by calling AddTrack
+// the MediaStreamVideoSource implementation calls GetCurrentSupportedFormats.
+// the source implementation must call OnSupportedFormats.
+// MediaStreamVideoSource then match the constraints provided in AddTrack with
+// the formats and call StartSourceImpl. The source implementation must call
+// OnStartDone when the underlying source has been started or failed to
+// start.
class CONTENT_EXPORT MediaStreamVideoSource
: public MediaStreamSource,
- NON_EXPORTED_BASE(public webrtc::ObserverInterface),
NON_EXPORTED_BASE(public base::NonThreadSafe) {
public:
- explicit MediaStreamVideoSource(
- MediaStreamDependencyFactory* factory);
-
+ explicit MediaStreamVideoSource(MediaStreamDependencyFactory* factory);
+ virtual ~MediaStreamVideoSource();
// Puts |track| in the registered tracks list.
virtual void AddTrack(const blink::WebMediaStreamTrack& track,
@@ -43,24 +56,29 @@ class CONTENT_EXPORT MediaStreamVideoSource
// TODO(ronghuawu): Remove webrtc::VideoSourceInterface from the public
// interface of this class.
- webrtc::VideoSourceInterface* GetAdapter() {
- return adapter_;
- }
+ // This creates a VideoSourceInterface implementation if it does not already
+ // exist.
+ webrtc::VideoSourceInterface* GetAdapter();
+
+ // Constraint keys used by a video source.
+ // Specified by draft-alvestrand-constraints-resolution-00b
+ static const char kMinAspectRatio[]; // minAspectRatio
+ static const char kMaxAspectRatio[]; // maxAspectRatio
+ static const char kMaxWidth[]; // maxWidth
+ static const char kMinWidth[]; // minWidthOnCaptureFormats
+ static const char kMaxHeight[]; // maxHeight
+ static const char kMinHeight[]; // minHeight
+ static const char kMaxFrameRate[]; // maxFrameRate
+ static const char kMinFrameRate[]; // minFrameRate
+
+ // Default resolution. If no constraints are specified and the delegate
+ // support it, this is the resolution that will be used.
+ static const int kDefaultWidth;
+ static const int kDefaultHeight;
+ static const int kDefaultFrameRate;
protected:
- virtual void DoStopSource() OVERRIDE {}
-
- // Called when the first track is added to this source.
- // It currently creates a webrtc::VideoSourceInterface.
- // If a derived class overrides this method, it must call SetAdapter.
- virtual void InitAdapter(const blink::WebMediaConstraints& constraints);
-
- // Set the webrtc::VideoSourceInterface adapter used by this class.
- // It must be called by a derived class that overrides the InitAdapter method.
- void SetAdapter(webrtc::VideoSourceInterface* adapter) {
- DCHECK(!adapter_);
- adapter_ = adapter;
- }
+ virtual void DoStopSource() OVERRIDE;
MediaStreamDependencyFactory* factory() { return factory_; }
@@ -72,26 +90,77 @@ class CONTENT_EXPORT MediaStreamVideoSource
// planes and I420.
virtual void DeliverVideoFrame(const scoped_refptr<media::VideoFrame>& frame);
- // Implements webrtc::Observer.
- virtual void OnChanged() OVERRIDE;
-
- virtual ~MediaStreamVideoSource();
+ // An implementation must fetch the formats that can currently be used by
+ // the source and call OnSupportedFormats when done.
+ // |max_requested_height| and |max_requested_width| is the max height and
+ // width set as a mandatory constraint if set when calling
+ // MediaStreamVideoSource::AddTrack. If max height and max width is not set
+ // |max_requested_height| and |max_requested_width| are 0.
+ virtual void GetCurrentSupportedFormats(int max_requested_width,
+ int max_requested_height) = 0;
+ void OnSupportedFormats(const media::VideoCaptureFormats& formats);
+
+ // An implementation must starts capture frames using the resolution in
+ // |params|. When the source has started or the source failed to start
+ // OnStartDone must be called. An implementation must call
+ // DeliverVideoFrame with the captured frames.
+ virtual void StartSourceImpl(const media::VideoCaptureParams& params) = 0;
+ void OnStartDone(bool success);
+
+ // An implementation must immediately stop capture video frames and must not
+ // call OnSupportedFormats after this method has been called. After this
+ // method has been called, MediaStreamVideoSource may be deleted.
+ virtual void StopSourceImpl() = 0;
private:
- // Checks if the underlying source state has changed from an initializing
- // state to a final state and in that case trigger all callbacks in
- // |constraints_callbacks_|.
- void TriggerConstraintsCallbackOnStateChange();
+ // Creates a webrtc::VideoSourceInterface used by libjingle.
+ void InitAdapter();
+
+ // Finds the first constraints in |requested_constraints_| that can be
+ // fulfilled. |best_format| is set to the video resolution that can be
+ // fulfilled. |resulting_constraints| is set to the found constraints in
+ // |requested_constraints_|.
+ bool FindBestFormatWithConstraints(
+ const media::VideoCaptureFormats& formats,
+ media::VideoCaptureFormat* best_format,
+ blink::WebMediaConstraints* resulting_constraints);
+
+ // Trigger all cached callbacks from AddTrack. AddTrack is successful
+ // if the capture delegate has started and the constraints provided in
+ // AddTrack match the format that was used to start the device.
+ void FinalizeAddTrack();
+
+ enum State {
+ NEW,
+ RETRIEVING_CAPABILITIES,
+ STARTING,
+ STARTED,
+ ENDED
+ };
+ State state_;
+
+ media::VideoCaptureFormat current_format_;
+ blink::WebMediaConstraints current_constraints_;
+
+ struct RequestedConstraints {
+ RequestedConstraints(const blink::WebMediaStreamTrack& track,
+ const blink::WebMediaConstraints& constraints,
+ const ConstraintsCallback& callback);
+ ~RequestedConstraints();
+
+ blink::WebMediaStreamTrack track;
+ blink::WebMediaConstraints constraints;
+ ConstraintsCallback callback;
+ };
+ std::vector<RequestedConstraints> requested_constraints_;
- bool initializing_;
+ media::VideoCaptureFormats supported_formats_;
+
+ // TODO(perkj): The below classes use webrtc/libjingle types. The goal is to
+ // get rid of them as far as possible.
MediaStreamDependencyFactory* factory_;
scoped_refptr<webrtc::VideoSourceInterface> adapter_;
- int width_;
- int height_;
- base::TimeDelta first_frame_timestamp_;
-
- blink::WebMediaConstraints current_constraints_;
- std::vector<ConstraintsCallback> constraints_callbacks_;
+ WebRtcVideoCapturerAdapter* capture_adapter_;
DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoSource);
};