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_
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"
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
{
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
,
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
,
50 virtual ~MediaStreamVideoTrack();
52 void SetEnabled(bool enabled
) override
;
56 void OnReadyStateChanged(blink::WebMediaStreamSource::ReadyState state
);
58 const blink::WebMediaConstraints
& constraints() const {
63 // MediaStreamVideoSink is a friend to allow it to call AddSink() and
65 friend class MediaStreamVideoSink
;
66 FRIEND_TEST_ALL_PREFIXES(MediaStreamRemoteVideoSourceTest
, StartTrack
);
67 FRIEND_TEST_ALL_PREFIXES(MediaStreamRemoteVideoSourceTest
, RemoteTrackStop
);
68 FRIEND_TEST_ALL_PREFIXES(VideoDestinationHandlerTest
, PutFrame
);
70 // Add |sink| to receive state changes on the main render thread and video
71 // frames in the |callback| method on the IO-thread.
72 // |callback| will be reset on the render thread.
73 // These two methods are private such that no subclass can intercept and
74 // store the callback. This is important to ensure that we can release
75 // the callback on render thread without reference to it on the IO-thread.
76 void AddSink(MediaStreamVideoSink
* sink
,
77 const VideoCaptureDeliverFrameCB
& callback
);
78 void RemoveSink(MediaStreamVideoSink
* sink
);
80 std::vector
<MediaStreamVideoSink
*> sinks_
;
82 // |FrameDeliverer| is an internal helper object used for delivering video
83 // frames on the IO-thread using callbacks to all registered tracks.
85 const scoped_refptr
<FrameDeliverer
> frame_deliverer_
;
87 const blink::WebMediaConstraints constraints_
;
89 // Weak ref to the source this tracks is connected to. |source_| is owned
90 // by the blink::WebMediaStreamSource and is guaranteed to outlive the
92 MediaStreamVideoSource
* source_
;
94 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoTrack
);
97 } // namespace content
99 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_