1// Copyright 2014 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_WEBRTC_MEDIA_STREAM_REMOTE_VIDEO_SOURCE_H_
6#define CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_VIDEO_SOURCE_H_
7
8#include "base/threading/thread_checker.h"
9#include "content/common/content_export.h"
10#include "content/renderer/media/media_stream_video_source.h"
11#include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
12#include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
13
14namespace content {
15
16// MediaStreamRemoteVideoSource implements the MediaStreamVideoSource interface
17// for video tracks received on a PeerConnection. The purpose of the class is
18// to make sure there is no difference between a video track where the source is
19// a local source and a video track where the source is a remote video track.
20class CONTENT_EXPORT MediaStreamRemoteVideoSource
21     : public MediaStreamVideoSource,
22       NON_EXPORTED_BASE(public webrtc::ObserverInterface) {
23 public:
24  explicit MediaStreamRemoteVideoSource(
25      webrtc::VideoTrackInterface* remote_track);
26  virtual ~MediaStreamRemoteVideoSource();
27
28 protected:
29  // Implements MediaStreamVideoSource.
30  virtual void GetCurrentSupportedFormats(
31      int max_requested_width,
32      int max_requested_height,
33      double max_requested_frame_rate,
34      const VideoCaptureDeviceFormatsCB& callback) OVERRIDE;
35
36  virtual void StartSourceImpl(
37      const media::VideoCaptureFormat& format,
38      const VideoCaptureDeliverFrameCB& frame_callback) OVERRIDE;
39
40  virtual void StopSourceImpl() OVERRIDE;
41
42  // Used by tests to test that a frame can be received and that the
43  // MediaStreamRemoteVideoSource behaves as expected.
44  webrtc::VideoRendererInterface* RenderInterfaceForTest();
45
46 private:
47  // webrtc::ObserverInterface implementation.
48  virtual void OnChanged() OVERRIDE;
49
50  scoped_refptr<webrtc::VideoTrackInterface> remote_track_;
51  webrtc::MediaStreamTrackInterface::TrackState last_state_;
52
53  // Internal class used for receiving frames from the webrtc track on a
54  // libjingle thread and forward it to the IO-thread.
55  class RemoteVideoSourceDelegate;
56  scoped_refptr<RemoteVideoSourceDelegate> delegate_;
57
58  // Bound to the render thread.
59  base::ThreadChecker thread_checker_;
60
61  DISALLOW_COPY_AND_ASSIGN(MediaStreamRemoteVideoSource);
62};
63
64}  // namespace content
65
66#endif  // CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_VIDEO_SOURCE_H_
67