| 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 "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" | 
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" | 
| 10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" | 
| 11 #include "content/renderer/media/media_stream_source_extra_data.h" | 11 #include "content/renderer/media/media_stream_dependency_factory.h" | 
|  | 12 #include "content/renderer/media/media_stream_source.h" | 
| 12 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 13 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 
| 13 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 14 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 
| 14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 
| 15 | 16 | 
| 16 namespace media { | 17 namespace media { | 
| 17 class VideoFrame; | 18 class VideoFrame; | 
| 18 } | 19 } | 
| 19 | 20 | 
| 20 namespace content { | 21 namespace content { | 
| 21 | 22 | 
| 22 class MediaStreamDependencyFactory; | 23 class MediaStreamDependencyFactory; | 
| 23 | 24 | 
| 24 // MediaStreamVideoSource is an interface used for sending video frames to a | 25 // MediaStreamVideoSource is an interface used for sending video frames to a | 
| 25 // MediaStreamVideoTrack. | 26 // MediaStreamVideoTrack. | 
| 26 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html | 27 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html | 
| 27 // All methods calls will be done from the main render thread. | 28 // All methods calls will be done from the main render thread. | 
| 28 class CONTENT_EXPORT MediaStreamVideoSource | 29 class CONTENT_EXPORT MediaStreamVideoSource | 
| 29     : public MediaStreamSourceExtraData { | 30     : public MediaStreamSource, | 
|  | 31       NON_EXPORTED_BASE(public webrtc::ObserverInterface), | 
|  | 32       NON_EXPORTED_BASE(public base::NonThreadSafe) { | 
| 30  public: | 33  public: | 
| 31   explicit MediaStreamVideoSource( | 34   explicit MediaStreamVideoSource( | 
| 32       MediaStreamDependencyFactory* factory); | 35       MediaStreamDependencyFactory* factory); | 
| 33 | 36 | 
| 34   // Puts |track| in the registered tracks list. Will later | 37 | 
| 35   // deliver frames to it according to |constraints|. | 38   // Puts |track| in the registered tracks list. | 
| 36   virtual void AddTrack(const blink::WebMediaStreamTrack& track, | 39   virtual void AddTrack(const blink::WebMediaStreamTrack& track, | 
| 37                         const blink::WebMediaConstraints& constraints); | 40                         const blink::WebMediaConstraints& constraints, | 
| 38 | 41                         const ConstraintsCallback& callback) OVERRIDE; | 
| 39   // Removes |track| from the registered tracks list, i.e. will stop delivering | 42   virtual void RemoveTrack(const blink::WebMediaStreamTrack& track) OVERRIDE; | 
| 40   // frame to |track|. |  | 
| 41   virtual void RemoveTrack(const blink::WebMediaStreamTrack& track); |  | 
| 42 | 43 | 
| 43   // TODO(ronghuawu): Remove webrtc::VideoSourceInterface from the public | 44   // TODO(ronghuawu): Remove webrtc::VideoSourceInterface from the public | 
| 44   // interface of this class. | 45   // interface of this class. | 
| 45   webrtc::VideoSourceInterface* GetAdapter() { | 46   webrtc::VideoSourceInterface* GetAdapter() { | 
| 46     return adapter_; | 47     return adapter_; | 
| 47   } | 48   } | 
| 48 | 49 | 
| 49  protected: | 50  protected: | 
| 50   // Sets an external adapter. Must be called before Init, which creates a | 51   virtual void DoStopSource() OVERRIDE {} | 
| 51   // default adapter if the adapter is not set already. | 52 | 
|  | 53   // Called when the first track is added to this source. | 
|  | 54   // It currently creates a webrtc::VideoSourceInterface. | 
|  | 55   // If a derived class overrides this method, it must call SetAdapter. | 
|  | 56   virtual void InitAdapter(const blink::WebMediaConstraints& constraints); | 
|  | 57 | 
|  | 58   // Set the webrtc::VideoSourceInterface adapter used by this class. | 
|  | 59   // It must be called by a derived class that overrides the InitAdapter method. | 
| 52   void SetAdapter(webrtc::VideoSourceInterface* adapter) { | 60   void SetAdapter(webrtc::VideoSourceInterface* adapter) { | 
| 53     DCHECK(!adapter_); | 61     DCHECK(!adapter_); | 
| 54     adapter_ = adapter; | 62     adapter_ = adapter; | 
| 55   } | 63   } | 
| 56 | 64 | 
| 57   // Called by the derived class before any other methods except SetAdapter. | 65   MediaStreamDependencyFactory* factory() { return factory_; } | 
| 58   void Init(); |  | 
| 59 | 66 | 
| 60   // Sets ready state and notifies the ready state to all registered tracks. | 67   // Sets ready state and notifies the ready state to all registered tracks. | 
| 61   virtual void SetReadyState(blink::WebMediaStreamSource::ReadyState state); | 68   virtual void SetReadyState(blink::WebMediaStreamSource::ReadyState state); | 
| 62 | 69 | 
| 63   // Delivers |frame| to registered tracks according to their constraints. | 70   // Delivers |frame| to registered tracks according to their constraints. | 
| 64   // Note: current implementation assumes |frame| be contiguous layout of image | 71   // Note: current implementation assumes |frame| be contiguous layout of image | 
| 65   // planes and I420. | 72   // planes and I420. | 
| 66   virtual void DeliverVideoFrame(const scoped_refptr<media::VideoFrame>& frame); | 73   virtual void DeliverVideoFrame(const scoped_refptr<media::VideoFrame>& frame); | 
| 67 | 74 | 
|  | 75   // Implements webrtc::Observer. | 
|  | 76   virtual void OnChanged() OVERRIDE; | 
|  | 77 | 
| 68   virtual ~MediaStreamVideoSource(); | 78   virtual ~MediaStreamVideoSource(); | 
| 69 | 79 | 
| 70  private: | 80  private: | 
|  | 81   // Checks if the underlying source state has changed from an initializing | 
|  | 82   // state to a final state and in that case trigger all callbacks in | 
|  | 83   // |constraints_callbacks_|. | 
|  | 84   void TriggerConstraintsCallbackOnStateChange(); | 
|  | 85 | 
|  | 86   bool initializing_; | 
| 71   MediaStreamDependencyFactory* factory_; | 87   MediaStreamDependencyFactory* factory_; | 
| 72   scoped_refptr<webrtc::VideoSourceInterface> adapter_; | 88   scoped_refptr<webrtc::VideoSourceInterface> adapter_; | 
| 73   int width_; | 89   int width_; | 
| 74   int height_; | 90   int height_; | 
| 75   base::TimeDelta first_frame_timestamp_; | 91   base::TimeDelta first_frame_timestamp_; | 
|  | 92 | 
|  | 93   blink::WebMediaConstraints current_constraints_; | 
|  | 94   std::vector<ConstraintsCallback> constraints_callbacks_; | 
|  | 95 | 
|  | 96   DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoSource); | 
| 76 }; | 97 }; | 
| 77 | 98 | 
| 78 }  // namespace content | 99 }  // namespace content | 
| 79 | 100 | 
| 80 #endif  // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_ | 101 #endif  // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_ | 
| OLD | NEW | 
|---|