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 // MediaStreamVideoRendererSink is a VideoFrameProvider designed for rendering
24 // Video MediaStreamTracks [1], MediaStreamVideoRendererSink implements
25 // MediaStreamVideoSink in order to render video frames provided from a
26 // MediaStreamVideoTrack, to which it AddToVideoTrack()s itself when the
27 // VideoFrameProvider is Start()ed and RemoveFromVideoTrack()s itself when the
28 // latter is Stop()ed.
30 // [1] http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediastreamtrack
32 // TODO(wuchengli): Add unit test. See the link below for reference.
33 // http://src.chromium.org/viewvc/chrome/trunk/src/content/renderer/media/rtc_vi
34 // deo_decoder_unittest.cc?revision=180591&view=markup
35 class CONTENT_EXPORT MediaStreamVideoRendererSink
36 : NON_EXPORTED_BASE(public VideoFrameProvider
),
37 NON_EXPORTED_BASE(public MediaStreamVideoSink
) {
39 MediaStreamVideoRendererSink(const blink::WebMediaStreamTrack
& video_track
,
40 const base::Closure
& error_cb
,
41 const RepaintCB
& repaint_cb
);
43 // VideoFrameProvider implementation. Called on the main thread.
44 void Start() override
;
47 void Pause() override
;
50 ~MediaStreamVideoRendererSink() override
;
53 friend class MediaStreamVideoRendererSinkTest
;
60 void OnVideoFrame(const scoped_refptr
<media::VideoFrame
>& frame
,
61 base::TimeTicks estimated_capture_time
);
63 // MediaStreamVideoSink implementation. Called on the main thread.
64 void OnReadyStateChanged(
65 blink::WebMediaStreamSource::ReadyState state
) override
;
67 void RenderSignalingFrame();
69 const base::Closure error_cb_
;
70 const RepaintCB repaint_cb_
;
71 const scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
73 gfx::Size frame_size_
;
74 const blink::WebMediaStreamTrack video_track_
;
75 base::WeakPtrFactory
<MediaStreamVideoRendererSink
> weak_factory_
;
77 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoRendererSink
);
80 } // namespace content
82 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_RENDERER_H_