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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "content/common/content_export.h"
11 #include "content/renderer/media/media_stream_source_extra_data.h"
12 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
13 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
22 class MediaStreamDependencyFactory;
24 // MediaStreamVideoSource is an interface used for sending video frames to a
25 // MediaStreamVideoTrack.
26 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html
27 // All methods calls will be done from the main render thread.
28 class CONTENT_EXPORT MediaStreamVideoSource
29 : public MediaStreamSourceExtraData {
31 explicit MediaStreamVideoSource(
32 MediaStreamDependencyFactory* factory);
34 // Puts |track| in the registered tracks list. Will later
35 // deliver frames to it according to |constraints|.
36 virtual void AddTrack(const blink::WebMediaStreamTrack& track,
37 const blink::WebMediaConstraints& constraints);
39 // Removes |track| from the registered tracks list, i.e. will stop delivering
41 virtual void RemoveTrack(const blink::WebMediaStreamTrack& track);
43 // TODO(ronghuawu): Remove webrtc::VideoSourceInterface from the public
44 // interface of this class.
45 webrtc::VideoSourceInterface* GetAdapter() {
50 // Sets an external adapter. Must be called before Init, which creates a
51 // default adapter if the adapter is not set already.
52 void SetAdapter(webrtc::VideoSourceInterface* adapter) {
57 // Called by the derived class before any other methods except SetAdapter.
60 // Sets ready state and notifies the ready state to all registered tracks.
61 virtual void SetReadyState(blink::WebMediaStreamSource::ReadyState state);
63 // Delivers |frame| to registered tracks according to their constraints.
64 // Note: current implementation assumes |frame| be contiguous layout of image
66 virtual void DeliverVideoFrame(const scoped_refptr<media::VideoFrame>& frame);
68 virtual ~MediaStreamVideoSource();
71 MediaStreamDependencyFactory* factory_;
72 scoped_refptr<webrtc::VideoSourceInterface> adapter_;
75 base::TimeDelta first_frame_timestamp_;
78 } // namespace content
80 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_SOURCE_H_