aw: Ensure fallback tick unsets |block_invalidates_|
[chromium-blink-merge.git] / content / renderer / media / media_stream_video_track.h
bloba99d1a4e3c300da3dda2ec96c5300608ae8d304e
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 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 SetMutedState(bool state) OVERRIDE;
54 virtual bool GetMutedState(void) const OVERRIDE;
56 virtual void Stop() OVERRIDE;
58 void OnReadyStateChanged(blink::WebMediaStreamSource::ReadyState state);
60 const blink::WebMediaConstraints& constraints() const {
61 return constraints_;
64 protected:
65 // Used to DCHECK that we are called on the correct thread.
66 base::ThreadChecker thread_checker_;
68 private:
69 // MediaStreamVideoSink is a friend to allow it to call AddSink() and
70 // RemoveSink().
71 friend class MediaStreamVideoSink;
72 FRIEND_TEST_ALL_PREFIXES(MediaStreamRemoteVideoSourceTest, StartTrack);
73 FRIEND_TEST_ALL_PREFIXES(MediaStreamRemoteVideoSourceTest, RemoteTrackStop);
74 FRIEND_TEST_ALL_PREFIXES(VideoDestinationHandlerTest, PutFrame);
76 // Add |sink| to receive state changes on the main render thread and video
77 // frames in the |callback| method on the IO-thread.
78 // |callback| will be reset on the render thread.
79 // These two methods are private such that no subclass can intercept and
80 // store the callback. This is important to ensure that we can release
81 // the callback on render thread without reference to it on the IO-thread.
82 void AddSink(MediaStreamVideoSink* sink,
83 const VideoCaptureDeliverFrameCB& callback);
84 void RemoveSink(MediaStreamVideoSink* sink);
86 std::vector<MediaStreamVideoSink*> sinks_;
88 // |FrameDeliverer| is an internal helper object used for delivering video
89 // frames on the IO-thread using callbacks to all registered tracks.
90 class FrameDeliverer;
91 scoped_refptr<FrameDeliverer> frame_deliverer_;
93 blink::WebMediaConstraints constraints_;
95 // Weak ref to the source this tracks is connected to. |source_| is owned
96 // by the blink::WebMediaStreamSource and is guaranteed to outlive the
97 // track.
98 MediaStreamVideoSource* source_;
100 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoTrack);
103 } // namespace content
105 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_