OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_MEDIA_STREAM_VIDEO_TRACK_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_ |
7 | 7 |
| 8 #include <vector> |
| 9 |
8 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
10 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
11 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
12 #include "content/public/renderer/media_stream_video_sink.h" | 14 #include "content/public/renderer/media_stream_video_sink.h" |
13 #include "content/renderer/media/media_stream_track.h" | 15 #include "content/renderer/media/media_stream_track.h" |
| 16 #include "content/renderer/media/media_stream_video_source.h" |
14 | 17 |
15 namespace webrtc { | 18 namespace webrtc { |
16 class VideoTrackInterface; | 19 class VideoTrackInterface; |
17 } | 20 } |
18 | 21 |
19 namespace content { | 22 namespace content { |
20 | 23 |
21 class MediaStreamDependencyFactory; | 24 class MediaStreamDependencyFactory; |
22 class WebRtcVideoSinkAdapter; | 25 class WebRtcVideoSinkAdapter; |
23 | 26 |
24 // MediaStreamVideoTrack is a video specific representation of a | 27 // MediaStreamVideoTrack is a video specific representation of a |
25 // blink::WebMediaStreamTrack in content. It is owned by the blink object | 28 // blink::WebMediaStreamTrack in content. It is owned by the blink object |
26 // and can be retrieved from a blink object using | 29 // and can be retrieved from a blink object using |
27 // WebMediaStreamTrack::extraData() | 30 // WebMediaStreamTrack::extraData() or MediaStreamVideoTrack::GetVideoTrack. |
28 class CONTENT_EXPORT MediaStreamVideoTrack : public MediaStreamTrack { | 31 class CONTENT_EXPORT MediaStreamVideoTrack : public MediaStreamTrack { |
29 public: | 32 public: |
| 33 // Help method to create a blink::WebMediaStreamTrack and a |
| 34 // MediaStreamVideoTrack instance. The MediaStreamVideoTrack object is owned |
| 35 // by the blink object in its WebMediaStreamTrack::ExtraData member. |
| 36 // |callback| is triggered if the track is added to the source |
| 37 // successfully and will receive video frames that match |constraints| |
| 38 // or if the source fail to provide video frames. |
| 39 // If |enabled| is true, sinks added to the track will |
| 40 // receive video frames when the source deliver frames to the track. |
| 41 static blink::WebMediaStreamTrack CreateVideoTrack( |
| 42 MediaStreamVideoSource* source, |
| 43 const blink::WebMediaConstraints& constraints, |
| 44 const MediaStreamVideoSource::ConstraintsCallback& callback, |
| 45 bool enabled, |
| 46 MediaStreamDependencyFactory* factory); |
| 47 |
| 48 static MediaStreamVideoTrack* GetVideoTrack( |
| 49 const blink::WebMediaStreamTrack& track); |
| 50 |
30 // Constructor for local video tracks. | 51 // Constructor for local video tracks. |
31 explicit MediaStreamVideoTrack(MediaStreamDependencyFactory* factory); | 52 MediaStreamVideoTrack( |
32 // Constructor for remote video tracks. | 53 MediaStreamVideoSource* source, |
33 explicit MediaStreamVideoTrack(webrtc::VideoTrackInterface* track); | 54 const blink::WebMediaConstraints& constraints, |
| 55 const MediaStreamVideoSource::ConstraintsCallback& callback, |
| 56 bool enabled, |
| 57 MediaStreamDependencyFactory* factory); |
34 virtual ~MediaStreamVideoTrack(); | 58 virtual ~MediaStreamVideoTrack(); |
35 void AddSink(MediaStreamVideoSink* sink); | 59 virtual void AddSink(MediaStreamVideoSink* sink); |
36 void RemoveSink(MediaStreamVideoSink* sink); | 60 virtual void RemoveSink(MediaStreamVideoSink* sink); |
37 | 61 |
| 62 // TODO(perkj): GetVideoAdapter is webrtc specific. Move GetVideoAdapter to |
| 63 // where the track is added to a RTCPeerConnection. crbug/323223. |
38 virtual webrtc::VideoTrackInterface* GetVideoAdapter() OVERRIDE; | 64 virtual webrtc::VideoTrackInterface* GetVideoAdapter() OVERRIDE; |
| 65 virtual void SetEnabled(bool enabled) OVERRIDE; |
| 66 |
| 67 void OnVideoFrame(const scoped_refptr<media::VideoFrame>& frame); |
| 68 void OnReadyStateChanged(blink::WebMediaStreamSource::ReadyState state); |
| 69 |
| 70 protected: |
| 71 // Used to DCHECK that we are called on the correct thread. |
| 72 base::ThreadChecker thread_checker_; |
39 | 73 |
40 private: | 74 private: |
41 // Used to DCHECK that we are called on the correct thread. | 75 bool enabled_; |
42 base::ThreadChecker thread_checker_; | 76 std::vector<MediaStreamVideoSink*> sinks_; |
43 ScopedVector<WebRtcVideoSinkAdapter> sinks_; | 77 |
| 78 // Weak ref to the source this tracks is connected to. |source_| is owned |
| 79 // by the blink::WebMediaStreamSource and is guaranteed to outlive the |
| 80 // track. |
| 81 MediaStreamVideoSource* source_; |
44 | 82 |
45 // Weak ref to a MediaStreamDependencyFactory, owned by the RenderThread. | 83 // Weak ref to a MediaStreamDependencyFactory, owned by the RenderThread. |
46 // It's valid for the lifetime of RenderThread. | 84 // It's valid for the lifetime of RenderThread. |
47 MediaStreamDependencyFactory* factory_; | 85 MediaStreamDependencyFactory* factory_; |
48 | 86 |
49 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoTrack); | 87 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoTrack); |
50 }; | 88 }; |
51 | 89 |
| 90 // WebRtcMediaStreamVideoTrack is a content representation of a video track. |
| 91 // received on a PeerConnection. |
| 92 // TODO(perkj): Replace WebRtcMediaStreamVideoTrack with a remote |
| 93 // MediaStreamVideoSource class so that all tracks are MediaStreamVideoTracks |
| 94 // and new tracks can be cloned from the original remote video track. |
| 95 // crbug/334243. |
| 96 class CONTENT_EXPORT WebRtcMediaStreamVideoTrack |
| 97 : public MediaStreamVideoTrack { |
| 98 public: |
| 99 explicit WebRtcMediaStreamVideoTrack(webrtc::VideoTrackInterface* track); |
| 100 virtual ~WebRtcMediaStreamVideoTrack(); |
| 101 virtual void AddSink(MediaStreamVideoSink* sink) OVERRIDE; |
| 102 virtual void RemoveSink(MediaStreamVideoSink* sink) OVERRIDE; |
| 103 |
| 104 private: |
| 105 ScopedVector<WebRtcVideoSinkAdapter> sinks_; |
| 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(WebRtcMediaStreamVideoTrack); |
| 108 }; |
| 109 |
52 } // namespace content | 110 } // namespace content |
53 | 111 |
54 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_ | 112 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_ |
OLD | NEW |