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