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_WEBRTC_MEDIA_STREAM_ADAPTER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_ADAPTER_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_ADAPTER_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_ADAPTER_H_ |
7 | 7 |
8 #include <memory> | |
9 #include <vector> | |
10 | |
11 #include "base/macros.h" | 8 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_vector.h" |
13 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
14 #include "content/renderer/media/media_stream.h" | 12 #include "content/renderer/media/media_stream.h" |
15 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 13 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
16 #include "third_party/webrtc/api/mediastreaminterface.h" | 14 #include "third_party/webrtc/api/mediastreaminterface.h" |
17 | 15 |
18 namespace content { | 16 namespace content { |
19 | 17 |
20 class PeerConnectionDependencyFactory; | 18 class PeerConnectionDependencyFactory; |
21 class MediaStreamVideoWebRtcSink; | 19 class MediaStreamVideoWebRtcSink; |
22 class WebRtcAudioSink; | |
23 | 20 |
24 // WebRtcMediaStreamAdapter is an adapter between a blink::WebMediaStream | 21 // WebRtcMediaStreamAdapter is an adapter between a blink::WebMediaStream |
25 // object and a webrtc MediaStreams that is currently sent on a PeerConnection. | 22 // object and a webrtc MediaStreams that is currently sent on a PeerConnection. |
26 // The responsibility of the class is to create and own a representation of a | 23 // The responsibility of the class is to create and own a representation of a |
27 // webrtc MediaStream that can be added and removed from a RTCPeerConnection. | 24 // webrtc MediaStream that can be added and removed from a RTCPeerConnection. |
28 // An instance of WebRtcMediaStreamAdapter is created when a MediaStream is | 25 // An instance of WebRtcMediaStreamAdapter is created when a MediaStream is |
29 // added to an RTCPeerConnection object | 26 // added to an RTCPeerConnection object |
30 // Instances of this class is owned by the RTCPeerConnectionHandler object that | 27 // Instances of this class is owned by the RTCPeerConnectionHandler object that |
31 // created it. | 28 // created it. |
32 class CONTENT_EXPORT WebRtcMediaStreamAdapter | 29 class CONTENT_EXPORT WebRtcMediaStreamAdapter |
33 : NON_EXPORTED_BASE(public MediaStreamObserver) { | 30 : NON_EXPORTED_BASE(public MediaStreamObserver) { |
34 public: | 31 public: |
35 WebRtcMediaStreamAdapter(const blink::WebMediaStream& web_stream, | 32 WebRtcMediaStreamAdapter(const blink::WebMediaStream& web_stream, |
36 PeerConnectionDependencyFactory* factory); | 33 PeerConnectionDependencyFactory* factory); |
37 ~WebRtcMediaStreamAdapter() override; | 34 ~WebRtcMediaStreamAdapter() override; |
38 | 35 |
39 bool IsEqual(const blink::WebMediaStream& web_stream) const { | 36 bool IsEqual(const blink::WebMediaStream& web_stream) { |
40 return web_stream_.getExtraData() == web_stream.getExtraData(); | 37 return web_stream_.getExtraData() == web_stream.getExtraData(); |
41 } | 38 } |
42 | 39 |
43 webrtc::MediaStreamInterface* webrtc_media_stream() const { | 40 webrtc::MediaStreamInterface* webrtc_media_stream() { |
44 return webrtc_media_stream_.get(); | 41 return webrtc_media_stream_.get(); |
45 } | 42 } |
46 | 43 |
47 protected: | 44 protected: |
48 // MediaStreamObserver implementation. | 45 // MediaStreamObserver implementation. |
49 void TrackAdded(const blink::WebMediaStreamTrack& track) override; | 46 void TrackAdded(const blink::WebMediaStreamTrack& track) override; |
50 void TrackRemoved(const blink::WebMediaStreamTrack& track) override; | 47 void TrackRemoved(const blink::WebMediaStreamTrack& track) override; |
51 | 48 |
52 private: | 49 private: |
53 void AddAudioSinkToTrack(const blink::WebMediaStreamTrack& track); | 50 void CreateAudioTrack(const blink::WebMediaStreamTrack& track); |
54 void AddVideoSinkToTrack(const blink::WebMediaStreamTrack& track); | 51 void CreateVideoTrack(const blink::WebMediaStreamTrack& track); |
55 | 52 |
56 const blink::WebMediaStream web_stream_; | 53 const blink::WebMediaStream web_stream_; |
57 | 54 |
58 // Pointer to a PeerConnectionDependencyFactory, owned by the RenderThread. | 55 // Pointer to a PeerConnectionDependencyFactory, owned by the RenderThread. |
59 // It's valid for the lifetime of RenderThread. | 56 // It's valid for the lifetime of RenderThread. |
60 PeerConnectionDependencyFactory* const factory_; | 57 PeerConnectionDependencyFactory* const factory_; |
61 | 58 |
62 scoped_refptr<webrtc::MediaStreamInterface> webrtc_media_stream_; | 59 scoped_refptr<webrtc::MediaStreamInterface> webrtc_media_stream_; |
63 std::vector<std::unique_ptr<WebRtcAudioSink>> audio_sinks_; | 60 ScopedVector<MediaStreamVideoWebRtcSink> video_adapters_; |
64 std::vector<std::unique_ptr<MediaStreamVideoWebRtcSink>> video_sinks_; | |
65 | 61 |
66 DISALLOW_COPY_AND_ASSIGN (WebRtcMediaStreamAdapter); | 62 DISALLOW_COPY_AND_ASSIGN (WebRtcMediaStreamAdapter); |
67 }; | 63 }; |
68 | 64 |
69 } // namespace content | 65 } // namespace content |
70 | 66 |
71 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_ADAPTER_H_ | 67 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_ADAPTER_H_ |
OLD | NEW |