Implement getMediaDevices.
[chromium-blink-merge.git] / content / renderer / media / media_stream_video_track.h
blob040686c582891d7ab598e04cca10205284773778
1 // Copyright 2013 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_TRACK_H_
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_
8 #include <vector>
10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/threading/thread_checker.h"
14 #include "content/common/content_export.h"
15 #include "content/public/renderer/media_stream_video_sink.h"
16 #include "content/renderer/media/media_stream_track.h"
17 #include "content/renderer/media/media_stream_video_source.h"
19 namespace content {
21 // MediaStreamVideoTrack is a video specific representation of a
22 // blink::WebMediaStreamTrack in content. It is owned by the blink object
23 // and can be retrieved from a blink object using
24 // WebMediaStreamTrack::extraData() or MediaStreamVideoTrack::GetVideoTrack.
25 class CONTENT_EXPORT MediaStreamVideoTrack : public MediaStreamTrack {
26 public:
27 // Help method to create a blink::WebMediaStreamTrack and a
28 // MediaStreamVideoTrack instance. The MediaStreamVideoTrack object is owned
29 // by the blink object in its WebMediaStreamTrack::ExtraData member.
30 // |callback| is triggered if the track is added to the source
31 // successfully and will receive video frames that match |constraints|
32 // or if the source fail to provide video frames.
33 // If |enabled| is true, sinks added to the track will
34 // receive video frames when the source deliver frames to the track.
35 static blink::WebMediaStreamTrack CreateVideoTrack(
36 MediaStreamVideoSource* source,
37 const blink::WebMediaConstraints& constraints,
38 const MediaStreamVideoSource::ConstraintsCallback& callback,
39 bool enabled);
41 static MediaStreamVideoTrack* GetVideoTrack(
42 const blink::WebMediaStreamTrack& track);
44 // Constructor for local video tracks.
45 MediaStreamVideoTrack(
46 MediaStreamVideoSource* source,
47 const blink::WebMediaConstraints& constraints,
48 const MediaStreamVideoSource::ConstraintsCallback& callback,
49 bool enabled);
50 virtual ~MediaStreamVideoTrack();
52 virtual void SetEnabled(bool enabled) OVERRIDE;
53 virtual void Stop() OVERRIDE;
55 void OnReadyStateChanged(blink::WebMediaStreamSource::ReadyState state);
57 const blink::WebMediaConstraints& constraints() const {
58 return constraints_;
61 protected:
62 // Used to DCHECK that we are called on the correct thread.
63 base::ThreadChecker thread_checker_;
65 private:
66 // MediaStreamVideoSink is a friend to allow it to call AddSink() and
67 // RemoveSink().
68 friend class MediaStreamVideoSink;
69 FRIEND_TEST_ALL_PREFIXES(MediaStreamRemoteVideoSourceTest, StartTrack);
70 FRIEND_TEST_ALL_PREFIXES(MediaStreamRemoteVideoSourceTest, RemoteTrackStop);
71 FRIEND_TEST_ALL_PREFIXES(VideoDestinationHandlerTest, PutFrame);
73 // Add |sink| to receive state changes on the main render thread and video
74 // frames in the |callback| method on the IO-thread.
75 // |callback| will be reset on the render thread.
76 // These two methods are private such that no subclass can intercept and
77 // store the callback. This is important to ensure that we can release
78 // the callback on render thread without reference to it on the IO-thread.
79 void AddSink(MediaStreamVideoSink* sink,
80 const VideoCaptureDeliverFrameCB& callback);
81 void RemoveSink(MediaStreamVideoSink* sink);
83 // |FrameDeliverer| is an internal helper object used for delivering video
84 // frames on the IO-thread using callbacks to all registered tracks.
85 class FrameDeliverer;
86 scoped_refptr<FrameDeliverer> frame_deliverer_;
88 blink::WebMediaConstraints constraints_;
90 // Weak ref to the source this tracks is connected to. |source_| is owned
91 // by the blink::WebMediaStreamSource and is guaranteed to outlive the
92 // track.
93 MediaStreamVideoSource* source_;
95 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoTrack);
98 } // namespace content
100 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_