Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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/peer_connection_handler_base.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "content/renderer/media/media_stream_dependency_factory.h" | |
| 10 #include "content/renderer/media/media_stream_impl.h" | |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amDescriptor.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h" | |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | |
| 14 | |
| 15 PeerConnectionHandlerBase::PeerConnectionHandlerBase( | |
| 16 MediaStreamImpl* msi, | |
| 17 MediaStreamDependencyFactory* dependency_factory) | |
| 18 : media_stream_impl_(msi), | |
| 19 dependency_factory_(dependency_factory), | |
| 20 message_loop_proxy_(base::MessageLoopProxy::current()) { | |
| 21 } | |
| 22 | |
| 23 PeerConnectionHandlerBase::~PeerConnectionHandlerBase() { | |
| 24 } | |
| 25 | |
| 26 bool PeerConnectionHandlerBase::HasStream(const std::string& stream_label) { | |
| 27 webrtc::MediaStreamInterface* stream = | |
| 28 native_peer_connection_->remote_streams()->find(stream_label); | |
| 29 return stream != NULL; | |
| 30 } | |
| 31 | |
| 32 void PeerConnectionHandlerBase::SetVideoRenderer( | |
| 33 const std::string& stream_label, | |
| 34 webrtc::VideoRendererWrapperInterface* renderer) { | |
| 35 webrtc::MediaStreamInterface* stream = | |
| 36 native_peer_connection_->remote_streams()->find(stream_label); | |
| 37 webrtc::VideoTracks* video_tracks = stream->video_tracks(); | |
| 38 // We assume there is only one enabled video track. | |
| 39 for (size_t i = 0; i < video_tracks->count(); ++i) { | |
| 40 webrtc::VideoTrackInterface* video_track = video_tracks->at(i); | |
| 41 if (video_track->enabled()) { | |
| 42 video_track->SetRenderer(renderer); | |
| 43 return; | |
| 44 } | |
| 45 } | |
| 46 DVLOG(1) << "No enabled video track."; | |
| 47 } | |
| 48 | |
| 49 void PeerConnectionHandlerBase::AddStream( | |
| 50 const WebKit::WebMediaStreamDescriptor& stream) { | |
| 51 talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> native_stream = | |
| 52 dependency_factory_->CreateLocalMediaStream(UTF16ToUTF8(stream.label())); | |
| 53 WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector; | |
| 54 stream.sources(source_vector); | |
| 55 | |
| 56 // Get and add all tracks. | |
| 57 for (size_t i = 0; i < source_vector.size(); ++i) { | |
| 58 webrtc::MediaStreamTrackInterface* track = media_stream_impl_ | |
| 59 ->GetLocalMediaStreamTrack(UTF16ToUTF8(source_vector[i].id())); | |
| 60 DCHECK(track); | |
| 61 if (source_vector[i].type() == WebKit::WebMediaStreamSource::TypeVideo) { | |
| 62 native_stream->AddTrack(static_cast<webrtc::VideoTrackInterface*>(track)); | |
| 63 } else { | |
| 64 DCHECK(source_vector[i].type() == | |
| 65 WebKit::WebMediaStreamSource::TypeAudio); | |
| 66 native_stream->AddTrack(static_cast<webrtc::AudioTrackInterface*>(track)); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 native_peer_connection_->AddStream(native_stream); | |
| 71 } | |
| 72 | |
| 73 void PeerConnectionHandlerBase::RemoveStream( | |
| 74 const WebKit::WebMediaStreamDescriptor& stream) { | |
| 75 talk_base::scoped_refptr<webrtc::StreamCollectionInterface> native_streams = | |
| 76 native_peer_connection_->local_streams(); | |
| 77 if (!native_streams) | |
|
perkj_chrome
2012/04/11 12:28:19
should be !native_streams.get()
tommi (sloooow) - chröme
2012/04/11 15:07:43
not for scoped_refptr. this is the preferred way.
| |
| 78 return; | |
| 79 // TODO(perkj): Change libJingle PeerConnection::RemoveStream API to take a | |
| 80 // label as input instead of stream and return bool. | |
| 81 webrtc::LocalMediaStreamInterface* native_stream = | |
| 82 static_cast<webrtc::LocalMediaStreamInterface*>(native_streams->find( | |
| 83 UTF16ToUTF8(stream.label()))); | |
| 84 DCHECK(native_stream); | |
| 85 native_peer_connection_->RemoveStream(native_stream); | |
| 86 } | |
| 87 | |
| 88 WebKit::WebMediaStreamDescriptor | |
| 89 PeerConnectionHandlerBase::CreateWebKitStreamDescriptor( | |
| 90 webrtc::MediaStreamInterface* stream) { | |
| 91 webrtc::AudioTracks* audio_tracks = stream->audio_tracks(); | |
| 92 webrtc::VideoTracks* video_tracks = stream->video_tracks(); | |
| 93 WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector( | |
| 94 audio_tracks->count() + video_tracks->count()); | |
| 95 | |
| 96 // Add audio tracks. | |
| 97 size_t i = 0; | |
| 98 for (; i < audio_tracks->count(); ++i) { | |
| 99 webrtc::AudioTrackInterface* audio_track = audio_tracks->at(i); | |
| 100 DCHECK(audio_track); | |
| 101 source_vector[i].initialize( | |
| 102 // TODO(grunell): Set id to something unique. | |
| 103 UTF8ToUTF16(audio_track->label()), | |
| 104 WebKit::WebMediaStreamSource::TypeAudio, | |
| 105 UTF8ToUTF16(audio_track->label())); | |
| 106 } | |
| 107 | |
| 108 // Add video tracks. | |
| 109 for (i = 0; i < video_tracks->count(); ++i) { | |
| 110 webrtc::VideoTrackInterface* video_track = video_tracks->at(i); | |
| 111 DCHECK(video_track); | |
| 112 source_vector[audio_tracks->count() + i].initialize( | |
| 113 // TODO(grunell): Set id to something unique. | |
| 114 UTF8ToUTF16(video_track->label()), | |
| 115 WebKit::WebMediaStreamSource::TypeVideo, | |
| 116 UTF8ToUTF16(video_track->label())); | |
| 117 } | |
| 118 | |
| 119 WebKit::WebMediaStreamDescriptor descriptor; | |
| 120 descriptor.initialize(UTF8ToUTF16(stream->label()), source_vector); | |
| 121 | |
| 122 return descriptor; | |
| 123 } | |
| OLD | NEW |