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/renderer/media/video_frame_provider.h"
14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
15 #include "ui/gfx/size.h"
18 class MessageLoopProxy
;
23 // RTCVideoRenderer is a VideoFrameProvider designed for rendering
24 // Video MediaStreamTracks,
25 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediastreamtrack
26 // RTCVideoRenderer implements VideoTrackSink in order to render
27 // video frames provided from a VideoTrack.
28 // RTCVideoRenderer register itself as a sink to the VideoTrack when the
29 // VideoFrameProvider is started and deregisters itself when it is stopped.
30 // TODO(wuchengli): Add unit test. See the link below for reference.
31 // http://src.chromium.org/viewvc/chrome/trunk/src/content/renderer/media/rtc_vi
32 // deo_decoder_unittest.cc?revision=180591&view=markup
33 class CONTENT_EXPORT RTCVideoRenderer
34 : NON_EXPORTED_BASE(public VideoFrameProvider
),
35 NON_EXPORTED_BASE(public MediaStreamVideoSink
) {
37 RTCVideoRenderer(const blink::WebMediaStreamTrack
& video_track
,
38 const base::Closure
& error_cb
,
39 const RepaintCB
& repaint_cb
);
41 // VideoFrameProvider implementation. Called on the main thread.
42 virtual void Start() OVERRIDE
;
43 virtual void Stop() OVERRIDE
;
44 virtual void Play() OVERRIDE
;
45 virtual void Pause() OVERRIDE
;
48 virtual ~RTCVideoRenderer();
57 void OnVideoFrame(const scoped_refptr
<media::VideoFrame
>& frame
,
58 const media::VideoCaptureFormat
& format
,
59 const base::TimeTicks
& estimated_capture_time
);
61 // VideoTrackSink implementation. Called on the main thread.
62 virtual void OnReadyStateChanged(
63 blink::WebMediaStreamSource::ReadyState state
) OVERRIDE
;
65 void RenderSignalingFrame();
67 base::Closure error_cb_
;
68 RepaintCB repaint_cb_
;
69 scoped_refptr
<base::MessageLoopProxy
> message_loop_proxy_
;
71 gfx::Size frame_size_
;
72 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_