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.
5 #include "content/renderer/media/media_stream.h"
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"
14 MediaStream
* MediaStream::GetMediaStream(
15 const blink::WebMediaStream
& stream
) {
16 return static_cast<MediaStream
*>(stream
.extraData());
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
);
27 MediaStream::MediaStream(const blink::WebMediaStream
& stream
)
29 webrtc_media_stream_(NULL
) {
32 MediaStream::MediaStream(webrtc::MediaStreamInterface
* webrtc_stream
)
34 webrtc_media_stream_(webrtc_stream
) {
37 MediaStream::~MediaStream() {
38 DCHECK(observers_
.empty());
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();
48 void MediaStream::AddObserver(MediaStreamObserver
* observer
) {
49 DCHECK(thread_checker_
.CalledOnValidThread());
50 DCHECK(std::find(observers_
.begin(), observers_
.end(), observer
) ==
52 observers_
.push_back(observer
);
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());
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
);
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
);
81 } // namespace content