OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/renderer/media/peer_connection_handler_base.h" | 5 #include "content/renderer/media/peer_connection_handler_base.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stringprintf.h" | |
perkj_chrome
2012/05/13 13:39:18
Seems to be unused
perkj_chrome
2012/05/14 11:50:25
Done.
| |
8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
9 #include "content/renderer/media/media_stream_dependency_factory.h" | 10 #include "content/renderer/media/media_stream_dependency_factory.h" |
10 #include "content/renderer/media/media_stream_impl.h" | 11 #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 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/WebMediaStre amSource.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
14 | 15 |
16 static webrtc::LocalMediaStreamInterface* GetLocalNativeMediaStream( | |
17 const WebKit::WebMediaStreamDescriptor& stream) { | |
18 MediaStreamExtraData* extra_data = | |
19 static_cast<MediaStreamExtraData*>(stream.extraData()); | |
20 if (extra_data) | |
21 return extra_data->local_stream(); | |
22 return NULL; | |
23 } | |
24 | |
15 PeerConnectionHandlerBase::PeerConnectionHandlerBase( | 25 PeerConnectionHandlerBase::PeerConnectionHandlerBase( |
16 MediaStreamImpl* msi, | |
17 MediaStreamDependencyFactory* dependency_factory) | 26 MediaStreamDependencyFactory* dependency_factory) |
18 : media_stream_impl_(msi), | 27 : dependency_factory_(dependency_factory), |
19 dependency_factory_(dependency_factory), | |
20 message_loop_proxy_(base::MessageLoopProxy::current()) { | 28 message_loop_proxy_(base::MessageLoopProxy::current()) { |
29 DVLOG(1) << "PeerConnectionHandlerBase::PeerConnectionHandlerBase"; | |
21 } | 30 } |
22 | 31 |
23 PeerConnectionHandlerBase::~PeerConnectionHandlerBase() { | 32 PeerConnectionHandlerBase::~PeerConnectionHandlerBase() { |
24 } | 33 DVLOG(1) << "PeerConnectionHandlerBase::~PeerConnectionHandlerBase"; |
25 | |
26 webrtc::MediaStreamInterface* PeerConnectionHandlerBase::GetRemoteMediaStream( | |
27 const WebKit::WebMediaStreamDescriptor& stream) { | |
28 for (RemoteStreamMap::const_iterator it = remote_streams_.begin(); | |
29 it != remote_streams_.end(); ++it) { | |
30 if (it->second.label() == stream.label()) | |
31 return it->first; | |
32 } | |
33 return NULL; | |
34 } | |
35 | |
36 void PeerConnectionHandlerBase::SetRemoteVideoRenderer( | |
37 const std::string& source_id, | |
38 webrtc::VideoRendererWrapperInterface* renderer) { | |
39 webrtc::VideoTrackInterface* remote_track = FindRemoteVideoTrack(source_id); | |
40 if (remote_track) { | |
41 remote_track->SetRenderer(renderer); | |
42 // TODO(perkj): Remove video_renderers_ from this class when it's not longer | |
43 // needed. See http://code.google.com/p/webrtc/issues/detail?id=447 | |
44 video_renderers_.erase(source_id); // Remove old renderer if exists. | |
45 video_renderers_.insert(std::make_pair(source_id, renderer)); | |
46 } else { | |
47 NOTREACHED(); | |
48 } | |
49 } | 34 } |
50 | 35 |
51 void PeerConnectionHandlerBase::AddStream( | 36 void PeerConnectionHandlerBase::AddStream( |
52 const WebKit::WebMediaStreamDescriptor& stream) { | 37 const WebKit::WebMediaStreamDescriptor& stream) { |
53 webrtc::LocalMediaStreamInterface* native_stream = | 38 webrtc::LocalMediaStreamInterface* native_stream = |
54 media_stream_impl_->GetLocalMediaStream(stream); | 39 GetLocalNativeMediaStream(stream); |
55 if (native_stream) | 40 if (native_stream) |
56 native_peer_connection_->AddStream(native_stream); | 41 native_peer_connection_->AddStream(native_stream); |
57 DCHECK(native_stream); | 42 DCHECK(native_stream); |
58 } | 43 } |
59 | 44 |
60 void PeerConnectionHandlerBase::RemoveStream( | 45 void PeerConnectionHandlerBase::RemoveStream( |
61 const WebKit::WebMediaStreamDescriptor& stream) { | 46 const WebKit::WebMediaStreamDescriptor& stream) { |
62 webrtc::LocalMediaStreamInterface* native_stream = | 47 webrtc::LocalMediaStreamInterface* native_stream = |
63 media_stream_impl_->GetLocalMediaStream(stream); | 48 GetLocalNativeMediaStream(stream); |
64 if (native_stream) | 49 if (native_stream) |
65 native_peer_connection_->RemoveStream(native_stream); | 50 native_peer_connection_->RemoveStream(native_stream); |
66 DCHECK(native_stream); | 51 DCHECK(native_stream); |
67 } | 52 } |
68 | 53 |
69 WebKit::WebMediaStreamDescriptor | 54 WebKit::WebMediaStreamDescriptor |
70 PeerConnectionHandlerBase::CreateWebKitStreamDescriptor( | 55 PeerConnectionHandlerBase::CreateWebKitStreamDescriptor( |
71 webrtc::MediaStreamInterface* stream) { | 56 webrtc::MediaStreamInterface* stream) { |
72 webrtc::AudioTracks* audio_tracks = stream->audio_tracks(); | 57 webrtc::AudioTracks* audio_tracks = stream->audio_tracks(); |
73 webrtc::VideoTracks* video_tracks = stream->video_tracks(); | 58 webrtc::VideoTracks* video_tracks = stream->video_tracks(); |
74 WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector( | 59 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_source_vector( |
75 audio_tracks->count() + video_tracks->count()); | 60 audio_tracks->count()); |
61 WebKit::WebVector<WebKit::WebMediaStreamSource> video_source_vector( | |
62 video_tracks->count()); | |
76 | 63 |
77 // Add audio tracks. | 64 // Add audio tracks. |
78 size_t i = 0; | 65 size_t i = 0; |
79 for (; i < audio_tracks->count(); ++i) { | 66 for (; i < audio_tracks->count(); ++i) { |
80 webrtc::AudioTrackInterface* audio_track = audio_tracks->at(i); | 67 webrtc::AudioTrackInterface* audio_track = audio_tracks->at(i); |
81 DCHECK(audio_track); | 68 DCHECK(audio_track); |
82 source_vector[i].initialize( | 69 audio_source_vector[i].initialize( |
83 // TODO(grunell): Set id to something unique. | |
84 UTF8ToUTF16(audio_track->label()), | 70 UTF8ToUTF16(audio_track->label()), |
85 WebKit::WebMediaStreamSource::TypeAudio, | 71 WebKit::WebMediaStreamSource::TypeAudio, |
86 UTF8ToUTF16(audio_track->label())); | 72 UTF8ToUTF16(audio_track->label())); |
87 } | 73 } |
88 | 74 |
89 // Add video tracks. | 75 // Add video tracks. |
90 for (i = 0; i < video_tracks->count(); ++i) { | 76 for (i = 0; i < video_tracks->count(); ++i) { |
91 webrtc::VideoTrackInterface* video_track = video_tracks->at(i); | 77 webrtc::VideoTrackInterface* video_track = video_tracks->at(i); |
92 DCHECK(video_track); | 78 DCHECK(video_track); |
93 source_vector[audio_tracks->count() + i].initialize( | 79 video_source_vector[i].initialize( |
94 // TODO(grunell): Set id to something unique. | |
95 UTF8ToUTF16(video_track->label()), | 80 UTF8ToUTF16(video_track->label()), |
96 WebKit::WebMediaStreamSource::TypeVideo, | 81 WebKit::WebMediaStreamSource::TypeVideo, |
97 UTF8ToUTF16(video_track->label())); | 82 UTF8ToUTF16(video_track->label())); |
98 } | 83 } |
99 | |
100 WebKit::WebMediaStreamDescriptor descriptor; | 84 WebKit::WebMediaStreamDescriptor descriptor; |
101 descriptor.initialize(UTF8ToUTF16(stream->label()), source_vector); | 85 descriptor.initialize(UTF8ToUTF16(stream->label()), |
102 | 86 audio_source_vector, video_source_vector); |
87 descriptor.setExtraData(new MediaStreamExtraData(stream)); | |
103 return descriptor; | 88 return descriptor; |
104 } | 89 } |
105 | |
106 webrtc::VideoTrackInterface* PeerConnectionHandlerBase::FindRemoteVideoTrack( | |
107 const std::string& source_id) { | |
108 talk_base::scoped_refptr<webrtc::StreamCollectionInterface> streams = | |
109 native_peer_connection_->remote_streams(); | |
110 for (size_t i = 0; i < streams->count(); ++i) { | |
111 webrtc::VideoTracks* track_list =streams->at(i)->video_tracks(); | |
112 for (size_t j =0; j < track_list->count(); ++j) { | |
113 if (track_list->at(j)->label() == source_id) { | |
114 return track_list->at(j); | |
115 } | |
116 } | |
117 } | |
118 return NULL; | |
119 } | |
120 | |
121 | |
122 | |
OLD | NEW |