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/threading/thread_checker.h"
13 #include "content/common/content_export.h"
14 #include "content/public/renderer/media_stream_video_sink.h"
15 #include "content/renderer/media/media_stream_track.h"
16 #include "content/renderer/media/media_stream_video_source.h"
20 // MediaStreamVideoTrack is a video specific representation of a
21 // blink::WebMediaStreamTrack in content. It is owned by the blink object
22 // and can be retrieved from a blink object using
23 // WebMediaStreamTrack::extraData() or MediaStreamVideoTrack::GetVideoTrack.
24 class CONTENT_EXPORT MediaStreamVideoTrack
: public MediaStreamTrack
{
26 // Help method to create a blink::WebMediaStreamTrack and a
27 // MediaStreamVideoTrack instance. The MediaStreamVideoTrack object is owned
28 // by the blink object in its WebMediaStreamTrack::ExtraData member.
29 // |callback| is triggered if the track is added to the source
30 // successfully and will receive video frames that match |constraints|
31 // or if the source fail to provide video frames.
32 // If |enabled| is true, sinks added to the track will
33 // receive video frames when the source deliver frames to the track.
34 static blink::WebMediaStreamTrack
CreateVideoTrack(
35 MediaStreamVideoSource
* source
,
36 const blink::WebMediaConstraints
& constraints
,
37 const MediaStreamVideoSource::ConstraintsCallback
& callback
,
40 static MediaStreamVideoTrack
* GetVideoTrack(
41 const blink::WebMediaStreamTrack
& track
);
43 // Constructor for video tracks.
44 MediaStreamVideoTrack(
45 MediaStreamVideoSource
* source
,
46 const blink::WebMediaConstraints
& constraints
,
47 const MediaStreamVideoSource::ConstraintsCallback
& callback
,
49 virtual ~MediaStreamVideoTrack();
51 void SetEnabled(bool enabled
) override
;
55 void OnReadyStateChanged(blink::WebMediaStreamSource::ReadyState state
);
57 const blink::WebMediaConstraints
& constraints() const { return constraints_
; }
60 // MediaStreamVideoSink is a friend to allow it to call AddSink() and
62 friend class MediaStreamVideoSink
;
63 FRIEND_TEST_ALL_PREFIXES(MediaStreamRemoteVideoSourceTest
, StartTrack
);
64 FRIEND_TEST_ALL_PREFIXES(MediaStreamRemoteVideoSourceTest
, RemoteTrackStop
);
65 FRIEND_TEST_ALL_PREFIXES(PepperToVideoTrackAdapterTest
, PutFrame
);
67 // Add |sink| to receive state changes on the main render thread and video
68 // frames in the |callback| method on the IO-thread.
69 // |callback| will be reset on the render thread.
70 // These two methods are private such that no subclass can intercept and
71 // store the callback. This is important to ensure that we can release
72 // the callback on render thread without reference to it on the IO-thread.
73 void AddSink(MediaStreamVideoSink
* sink
,
74 const VideoCaptureDeliverFrameCB
& callback
);
75 void RemoveSink(MediaStreamVideoSink
* sink
);
77 std::vector
<MediaStreamVideoSink
*> sinks_
;
79 // |FrameDeliverer| is an internal helper object used for delivering video
80 // frames on the IO-thread using callbacks to all registered tracks.
82 const scoped_refptr
<FrameDeliverer
> frame_deliverer_
;
84 const blink::WebMediaConstraints constraints_
;
86 // Weak ref to the source this tracks is connected to. |source_| is owned
87 // by the blink::WebMediaStreamSource and is guaranteed to outlive the
89 MediaStreamVideoSource
* source_
;
91 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoTrack
);
94 } // namespace content
96 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_