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 #include "content/renderer/media/media_stream.h" 6 7 #include "base/logging.h" 8 #include "third_party/WebKit/public/platform/WebString.h" 9 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" 10 11 namespace content { 12 13 // static 14 MediaStream* MediaStream::GetMediaStream( 15 const blink::WebMediaStream& stream) { 16 return static_cast<MediaStream*>(stream.extraData()); 17 } 18 19 // static 20 webrtc::MediaStreamInterface* MediaStream::GetAdapter( 21 const blink::WebMediaStream& stream) { 22 MediaStream* native_stream = GetMediaStream(stream); 23 DCHECK(native_stream); 24 return native_stream->GetWebRtcAdapter(stream); 25 } 26 27 MediaStream::MediaStream(const blink::WebMediaStream& stream) 28 : is_local_(true), 29 webrtc_media_stream_(NULL) { 30 } 31 32 MediaStream::MediaStream(webrtc::MediaStreamInterface* webrtc_stream) 33 : is_local_(false), 34 webrtc_media_stream_(webrtc_stream) { 35 } 36 37 MediaStream::~MediaStream() { 38 DCHECK(observers_.empty()); 39 } 40 41 webrtc::MediaStreamInterface* MediaStream::GetWebRtcAdapter( 42 const blink::WebMediaStream& stream) { 43 DCHECK(webrtc_media_stream_.get()); 44 DCHECK(thread_checker_.CalledOnValidThread()); 45 return webrtc_media_stream_.get(); 46 } 47 48 void MediaStream::AddObserver(MediaStreamObserver* observer) { 49 DCHECK(thread_checker_.CalledOnValidThread()); 50 DCHECK(std::find(observers_.begin(), observers_.end(), observer) == 51 observers_.end()); 52 observers_.push_back(observer); 53 } 54 55 void MediaStream::RemoveObserver(MediaStreamObserver* observer) { 56 DCHECK(thread_checker_.CalledOnValidThread()); 57 std::vector<MediaStreamObserver*>::iterator it = 58 std::find(observers_.begin(), observers_.end(), observer); 59 DCHECK(it != observers_.end()); 60 observers_.erase(it); 61 } 62 63 bool MediaStream::AddTrack(const blink::WebMediaStreamTrack& track) { 64 DCHECK(thread_checker_.CalledOnValidThread()); 65 for (std::vector<MediaStreamObserver*>::iterator it = observers_.begin(); 66 it != observers_.end(); ++it) { 67 (*it)->TrackAdded(track); 68 } 69 return true; 70 } 71 72 bool MediaStream::RemoveTrack(const blink::WebMediaStreamTrack& track) { 73 DCHECK(thread_checker_.CalledOnValidThread()); 74 for (std::vector<MediaStreamObserver*>::iterator it = observers_.begin(); 75 it != observers_.end(); ++it) { 76 (*it)->TrackRemoved(track); 77 } 78 return true; 79 } 80 81 } // namespace content 82