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. 4 5 #ifndef CONTENT_RENDERER_MEDIA_RTC_VIDEO_RENDERER_H_ 6 #define CONTENT_RENDERER_MEDIA_RTC_VIDEO_RENDERER_H_ 7 8 #include "base/callback.h" 9 #include "content/common/content_export.h" 10 #include "content/public/renderer/media_stream_video_sink.h" 11 #include "content/renderer/media/video_frame_provider.h" 12 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 13 #include "ui/gfx/size.h" 14 15 namespace base { 16 class MessageLoopProxy; 17 } 18 19 namespace content { 20 21 // RTCVideoRenderer is a VideoFrameProvider designed for rendering 22 // Video MediaStreamTracks, 23 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediastreamtrack 24 // RTCVideoRenderer implements VideoTrackSink in order to render 25 // video frames provided from a VideoTrack. 26 // RTCVideoRenderer register itself as a sink to the VideoTrack when the 27 // VideoFrameProvider is started and deregisters itself when it is stopped. 28 // TODO(wuchengli): Add unit test. See the link below for reference. 29 // http://src.chromium.org/viewvc/chrome/trunk/src/content/renderer/media/rtc_vi 30 // deo_decoder_unittest.cc?revision=180591&view=markup 31 class CONTENT_EXPORT RTCVideoRenderer 32 : NON_EXPORTED_BASE(public VideoFrameProvider), 33 NON_EXPORTED_BASE(public MediaStreamVideoSink) { 34 public: 35 RTCVideoRenderer(const blink::WebMediaStreamTrack& video_track, 36 const base::Closure& error_cb, 37 const RepaintCB& repaint_cb); 38 39 // VideoFrameProvider implementation. Called on the main thread. 40 virtual void Start() OVERRIDE; 41 virtual void Stop() OVERRIDE; 42 virtual void Play() OVERRIDE; 43 virtual void Pause() OVERRIDE; 44 45 protected: 46 virtual ~RTCVideoRenderer(); 47 48 private: 49 enum State { 50 STARTED, 51 PAUSED, 52 STOPPED, 53 }; 54 55 // VideoTrackSink implementation. Called on the main thread. 56 virtual void OnVideoFrame( 57 const scoped_refptr<media::VideoFrame>& frame) OVERRIDE; 58 virtual void OnReadyStateChanged( 59 blink::WebMediaStreamSource::ReadyState state) OVERRIDE; 60 virtual void OnEnabledChanged(bool enabled) OVERRIDE; 61 62 void MaybeRenderSignalingFrame(); 63 64 base::Closure error_cb_; 65 RepaintCB repaint_cb_; 66 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 67 State state_; 68 bool first_frame_rendered_; 69 blink::WebMediaStreamTrack video_track_; 70 71 DISALLOW_COPY_AND_ASSIGN(RTCVideoRenderer); 72 }; 73 74 } // namespace content 75 76 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_RENDERER_H_ 77