| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_VIDEO_SOURCE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_VIDEO_SOURCE_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_VIDEO_SOURCE_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_VIDEO_SOURCE_H_ |
| 7 | 7 |
| 8 #include "base/threading/thread_checker.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/single_thread_task_runner.h" |
| 9 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
| 10 #include "content/renderer/media/media_stream_video_source.h" | 11 #include "content/renderer/media/media_stream_video_source.h" |
| 11 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 12 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 12 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 13 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 // MediaStreamRemoteVideoSource implements the MediaStreamVideoSource interface | 17 // MediaStreamRemoteVideoSource implements the MediaStreamVideoSource interface |
| 17 // for video tracks received on a PeerConnection. The purpose of the class is | 18 // 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 // 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. | 20 // a local source and a video track where the source is a remote video track. |
| 20 class CONTENT_EXPORT MediaStreamRemoteVideoSource | 21 class CONTENT_EXPORT MediaStreamRemoteVideoSource |
| 21 : public MediaStreamVideoSource, | 22 : public MediaStreamVideoSource { |
| 22 NON_EXPORTED_BASE(public webrtc::ObserverInterface) { | |
| 23 public: | 23 public: |
| 24 explicit MediaStreamRemoteVideoSource( | 24 class CONTENT_EXPORT Observer |
| 25 webrtc::VideoTrackInterface* remote_track); | 25 : public base::RefCountedThreadSafe<Observer>, |
| 26 NON_EXPORTED_BASE(public webrtc::ObserverInterface) { |
| 27 public: |
| 28 Observer(const scoped_refptr<base::SingleThreadTaskRunner>& main_thread, |
| 29 webrtc::VideoTrackInterface* track); |
| 30 |
| 31 const scoped_refptr<webrtc::VideoTrackInterface>& track(); |
| 32 webrtc::MediaStreamTrackInterface::TrackState state() const; |
| 33 |
| 34 private: |
| 35 friend class base::RefCountedThreadSafe<Observer>; |
| 36 ~Observer() override; |
| 37 |
| 38 friend class MediaStreamRemoteVideoSource; |
| 39 void SetSource(const base::WeakPtr<MediaStreamRemoteVideoSource>& source); |
| 40 |
| 41 // webrtc::ObserverInterface implementation. |
| 42 void OnChanged() override; |
| 43 |
| 44 void OnChangedImpl(webrtc::MediaStreamTrackInterface::TrackState state); |
| 45 |
| 46 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
| 47 base::WeakPtr<MediaStreamRemoteVideoSource> source_; |
| 48 const scoped_refptr<webrtc::VideoTrackInterface> track_; |
| 49 webrtc::MediaStreamTrackInterface::TrackState state_; |
| 50 }; |
| 51 |
| 52 MediaStreamRemoteVideoSource(const scoped_refptr<Observer>& observer); |
| 26 virtual ~MediaStreamRemoteVideoSource(); | 53 virtual ~MediaStreamRemoteVideoSource(); |
| 27 | 54 |
| 28 protected: | 55 protected: |
| 29 // Implements MediaStreamVideoSource. | 56 // Implements MediaStreamVideoSource. |
| 30 void GetCurrentSupportedFormats( | 57 void GetCurrentSupportedFormats( |
| 31 int max_requested_width, | 58 int max_requested_width, |
| 32 int max_requested_height, | 59 int max_requested_height, |
| 33 double max_requested_frame_rate, | 60 double max_requested_frame_rate, |
| 34 const VideoCaptureDeviceFormatsCB& callback) override; | 61 const VideoCaptureDeviceFormatsCB& callback) override; |
| 35 | 62 |
| 36 void StartSourceImpl( | 63 void StartSourceImpl( |
| 37 const media::VideoCaptureFormat& format, | 64 const media::VideoCaptureFormat& format, |
| 38 const VideoCaptureDeliverFrameCB& frame_callback) override; | 65 const VideoCaptureDeliverFrameCB& frame_callback) override; |
| 39 | 66 |
| 40 void StopSourceImpl() override; | 67 void StopSourceImpl() override; |
| 41 | 68 |
| 42 // Used by tests to test that a frame can be received and that the | 69 // Used by tests to test that a frame can be received and that the |
| 43 // MediaStreamRemoteVideoSource behaves as expected. | 70 // MediaStreamRemoteVideoSource behaves as expected. |
| 44 webrtc::VideoRendererInterface* RenderInterfaceForTest(); | 71 webrtc::VideoRendererInterface* RenderInterfaceForTest(); |
| 45 | 72 |
| 46 private: | 73 private: |
| 47 // webrtc::ObserverInterface implementation. | 74 friend class Observer; |
| 48 void OnChanged() override; | 75 void OnChanged(webrtc::MediaStreamTrackInterface::TrackState state); |
| 49 | 76 |
| 50 scoped_refptr<webrtc::VideoTrackInterface> remote_track_; | 77 scoped_refptr<Observer> observer_; |
| 51 webrtc::MediaStreamTrackInterface::TrackState last_state_; | |
| 52 | 78 |
| 53 // Internal class used for receiving frames from the webrtc track on a | 79 // Internal class used for receiving frames from the webrtc track on a |
| 54 // libjingle thread and forward it to the IO-thread. | 80 // libjingle thread and forward it to the IO-thread. |
| 55 class RemoteVideoSourceDelegate; | 81 class RemoteVideoSourceDelegate; |
| 56 scoped_refptr<RemoteVideoSourceDelegate> delegate_; | 82 scoped_refptr<RemoteVideoSourceDelegate> delegate_; |
| 57 | 83 base::WeakPtrFactory<MediaStreamRemoteVideoSource> weak_factory_; |
| 58 // Bound to the render thread. | |
| 59 base::ThreadChecker thread_checker_; | |
| 60 | 84 |
| 61 DISALLOW_COPY_AND_ASSIGN(MediaStreamRemoteVideoSource); | 85 DISALLOW_COPY_AND_ASSIGN(MediaStreamRemoteVideoSource); |
| 62 }; | 86 }; |
| 63 | 87 |
| 64 } // namespace content | 88 } // namespace content |
| 65 | 89 |
| 66 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_VIDEO_SOURCE_H_ | 90 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_REMOTE_VIDEO_SOURCE_H_ |
| OLD | NEW |