Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / media / media_stream_video_renderer_sink.h
blobed30c2ac7c3fc7450ed37f7eb3fc77a47b20746e
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"
17 namespace base {
18 class SingleThreadTaskRunner;
21 namespace content {
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) {
38 public:
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;
45 void Stop() override;
46 void Play() override;
47 void Pause() override;
49 protected:
50 ~MediaStreamVideoRendererSink() override;
52 private:
53 friend class MediaStreamVideoRendererSinkTest;
54 enum State {
55 STARTED,
56 PAUSED,
57 STOPPED,
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_;
72 State state_;
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_