Chromium Code Reviews| 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 <map> | |
| 8 #include <memory> | 9 #include <memory> |
| 9 #include <vector> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 14 #include "content/renderer/media/media_stream.h" | 15 #include "content/renderer/media/media_stream.h" |
| 16 #include "content/renderer/media/webrtc/webrtc_media_stream_track_adapter_map.h" | |
| 15 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 17 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 16 #include "third_party/webrtc/api/mediastreaminterface.h" | 18 #include "third_party/webrtc/api/mediastreaminterface.h" |
| 17 | 19 |
| 18 namespace content { | 20 namespace content { |
| 19 | 21 |
| 20 class PeerConnectionDependencyFactory; | 22 class PeerConnectionDependencyFactory; |
| 21 class MediaStreamVideoWebRtcSink; | |
| 22 class WebRtcAudioSink; | |
| 23 | 23 |
| 24 // WebRtcMediaStreamAdapter is an adapter between a blink::WebMediaStream | 24 // WebRtcMediaStreamAdapter is an adapter between a blink::WebMediaStream |
| 25 // object and a webrtc MediaStreams that is currently sent on a PeerConnection. | 25 // 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 | 26 // 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. | 27 // webrtc MediaStream that can be added and removed from a RTCPeerConnection. |
| 28 // An instance of WebRtcMediaStreamAdapter is created when a MediaStream is | 28 // An instance of WebRtcMediaStreamAdapter is created when a MediaStream is |
| 29 // added to an RTCPeerConnection object | 29 // added to an RTCPeerConnection object |
| 30 // Instances of this class is owned by the RTCPeerConnectionHandler object that | 30 // Instances of this class is owned by the RTCPeerConnectionHandler object that |
| 31 // created it. | 31 // created it. |
| 32 class CONTENT_EXPORT WebRtcMediaStreamAdapter | 32 class CONTENT_EXPORT WebRtcMediaStreamAdapter |
| 33 : NON_EXPORTED_BASE(public MediaStreamObserver) { | 33 : NON_EXPORTED_BASE(public MediaStreamObserver) { |
| 34 public: | 34 public: |
| 35 WebRtcMediaStreamAdapter(const blink::WebMediaStream& web_stream, | 35 WebRtcMediaStreamAdapter( |
| 36 PeerConnectionDependencyFactory* factory); | 36 PeerConnectionDependencyFactory* factory, |
| 37 scoped_refptr<WebRtcMediaStreamTrackAdapterMap> track_adapter_map, | |
| 38 const blink::WebMediaStream& web_stream); | |
| 37 ~WebRtcMediaStreamAdapter() override; | 39 ~WebRtcMediaStreamAdapter() override; |
| 38 | 40 |
| 39 bool IsEqual(const blink::WebMediaStream& web_stream) const { | 41 bool IsEqual(const blink::WebMediaStream& web_stream) const { |
| 40 return web_stream_.GetExtraData() == web_stream.GetExtraData(); | 42 return web_stream_.GetExtraData() == web_stream.GetExtraData(); |
| 41 } | 43 } |
| 42 | 44 |
| 43 webrtc::MediaStreamInterface* webrtc_media_stream() const { | 45 webrtc::MediaStreamInterface* webrtc_media_stream() const { |
| 44 return webrtc_media_stream_.get(); | 46 return webrtc_media_stream_.get(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 const blink::WebMediaStream& web_stream() const { return web_stream_; } | 49 const blink::WebMediaStream& web_stream() const { return web_stream_; } |
| 48 | 50 |
| 49 protected: | 51 protected: |
| 50 // MediaStreamObserver implementation. | 52 // MediaStreamObserver implementation. Also used as a helper functions when |
| 51 void TrackAdded(const blink::WebMediaStreamTrack& track) override; | 53 // adding/removing all tracks in the constructor/destructor. |
| 52 void TrackRemoved(const blink::WebMediaStreamTrack& track) override; | 54 void TrackAdded(const blink::WebMediaStreamTrack& web_track) override; |
| 55 void TrackRemoved(const blink::WebMediaStreamTrack& web_track) override; | |
| 53 | 56 |
| 54 private: | 57 private: |
| 55 void AddAudioSinkToTrack(const blink::WebMediaStreamTrack& track); | |
| 56 void AddVideoSinkToTrack(const blink::WebMediaStreamTrack& track); | |
| 57 | |
| 58 const blink::WebMediaStream web_stream_; | |
| 59 | |
| 60 // Pointer to a PeerConnectionDependencyFactory, owned by the RenderThread. | 58 // Pointer to a PeerConnectionDependencyFactory, owned by the RenderThread. |
| 61 // It's valid for the lifetime of RenderThread. | 59 // It's valid for the lifetime of RenderThread. |
| 62 PeerConnectionDependencyFactory* const factory_; | 60 PeerConnectionDependencyFactory* const factory_; |
| 61 scoped_refptr<WebRtcMediaStreamTrackAdapterMap> track_adapter_map_; | |
|
Guido Urdaneta
2017/06/08 13:54:35
document this field
hbos_chromium
2017/06/08 14:34:43
Done.
| |
| 63 | 62 |
| 63 const blink::WebMediaStream web_stream_; | |
| 64 scoped_refptr<webrtc::MediaStreamInterface> webrtc_media_stream_; | 64 scoped_refptr<webrtc::MediaStreamInterface> webrtc_media_stream_; |
| 65 std::vector<std::unique_ptr<WebRtcAudioSink>> audio_sinks_; | 65 // Retaining |AdapterRef|s of adapters in use protects them from being |
| 66 std::vector<std::unique_ptr<MediaStreamVideoWebRtcSink>> video_sinks_; | 66 // disposed by the |track_adapter_map_|. |
| 67 std::map<std::string, | |
|
Guido Urdaneta
2017/06/08 13:54:35
document what this map is. In particular, document
hbos_chromium
2017/06/08 14:34:43
Done.
| |
| 68 std::unique_ptr<WebRtcMediaStreamTrackAdapterMap::AdapterRef>> | |
| 69 adapter_refs_; | |
| 67 | 70 |
| 68 DISALLOW_COPY_AND_ASSIGN (WebRtcMediaStreamAdapter); | 71 DISALLOW_COPY_AND_ASSIGN(WebRtcMediaStreamAdapter); |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 } // namespace content | 74 } // namespace content |
| 72 | 75 |
| 73 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_ADAPTER_H_ | 76 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_MEDIA_STREAM_ADAPTER_H_ |
| OLD | NEW |