1 // Copyright (c) 2012 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_RTC_VIDEO_RENDERER_H_
6 #define CONTENT_RENDERER_MEDIA_RTC_VIDEO_RENDERER_H_
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/common/content_export.h"
11 #include "content/common/media/video_capture.h"
12 #include "content/public/renderer/media_stream_video_sink.h"
13 #include "content/public/renderer/video_frame_provider.h"
14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
15 #include "ui/gfx/geometry/size.h"
18 class SingleThreadTaskRunner
;
23 // RTCVideoRenderer is a VideoFrameProvider designed for rendering Video
24 // MediaStreamTracks [1], RTCVideoRenderer implements MediaStreamVideoSink in
25 // order to render video frames provided from a MediaStreamVideoTrack, to which
26 // it AddToVideoTrack()s itself when the VideoFrameProvider is Start()ed
27 // and RemoveFromVideoTrack()s itself when the latter is Stop()ed.
29 // [1] http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediastreamtrack
31 // TODO(wuchengli): Add unit test. See the link below for reference.
32 // http://src.chromium.org/viewvc/chrome/trunk/src/content/renderer/media/rtc_vi
33 // deo_decoder_unittest.cc?revision=180591&view=markup
34 class CONTENT_EXPORT RTCVideoRenderer
35 : NON_EXPORTED_BASE(public VideoFrameProvider
),
36 NON_EXPORTED_BASE(public MediaStreamVideoSink
) {
38 RTCVideoRenderer(const blink::WebMediaStreamTrack
& video_track
,
39 const base::Closure
& error_cb
,
40 const RepaintCB
& repaint_cb
);
42 // VideoFrameProvider implementation. Called on the main thread.
43 void Start() override
;
46 void Pause() override
;
49 ~RTCVideoRenderer() override
;
58 void OnVideoFrame(const scoped_refptr
<media::VideoFrame
>& frame
,
59 const base::TimeTicks
& estimated_capture_time
);
61 // MediaStreamVideoSink implementation. Called on the main thread.
62 void OnReadyStateChanged(
63 blink::WebMediaStreamSource::ReadyState state
) override
;
65 void RenderSignalingFrame();
67 const base::Closure error_cb_
;
68 const RepaintCB repaint_cb_
;
69 const scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
71 gfx::Size frame_size_
;
72 const blink::WebMediaStreamTrack video_track_
;
73 base::WeakPtrFactory
<RTCVideoRenderer
> weak_factory_
;
75 DISALLOW_COPY_AND_ASSIGN(RTCVideoRenderer
);
78 } // namespace content
80 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_RENDERER_H_