Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Side by Side Diff: content/renderer/media/peer_connection_handler_base.cc

Issue 9699069: Adding JSEP PeerConnection glue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Deleting two renamed files. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 native_stream->AddTrack(static_cast<webrtc::AudioTrackInterface*>(track));
tommi (sloooow) - chröme 2012/03/26 12:34:45 add a DCHECK() that the type is audio?
Henrik Grunell 2012/03/27 07:22:05 Sounds good. Done.
65 }
66 }
67
68 native_peer_connection_->AddStream(native_stream);
69 }
70
71 void PeerConnectionHandlerBase::RemoveStream(
72 const WebKit::WebMediaStreamDescriptor& stream) {
73 webrtc::MediaStreamInterface* native_stream =
74 native_peer_connection_->remote_streams()->find(
75 UTF16ToUTF8(stream.label()));
76 native_peer_connection_->RemoveStream(
77 static_cast<webrtc::LocalMediaStreamInterface*>(native_stream));
78 }
79
80 WebKit::WebMediaStreamDescriptor
81 PeerConnectionHandlerBase::CreateWebKitStreamDescriptor(
82 webrtc::MediaStreamInterface* stream) {
83 webrtc::AudioTracks* audio_tracks = stream->audio_tracks();
84 webrtc::VideoTracks* video_tracks = stream->video_tracks();
85 WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector(
86 audio_tracks->count() + video_tracks->count());
87
88 // Add audio tracks.
89 size_t i = 0;
90 for (; i < audio_tracks->count(); ++i) {
91 webrtc::AudioTrackInterface* audio_track = audio_tracks->at(i);
92 DCHECK(audio_track);
93 source_vector[i].initialize(
94 // TODO(grunell): Set id to something unique.
tommi (sloooow) - chröme 2012/03/26 12:34:45 hmm... 6 space indent?
Henrik Grunell 2012/03/27 07:22:05 Done.
95 UTF8ToUTF16(audio_track->label()),
96 WebKit::WebMediaStreamSource::TypeAudio,
97 UTF8ToUTF16(audio_track->label()));
98 }
99
100 // Add video tracks.
101 for (i = 0; i < video_tracks->count(); ++i) {
102 webrtc::VideoTrackInterface* video_track = video_tracks->at(i);
103 DCHECK(video_track);
104 source_vector[audio_tracks->count() + i].initialize(
105 // TODO(grunell): Set id to something unique.
106 UTF8ToUTF16(video_track->label()),
tommi (sloooow) - chröme 2012/03/26 12:34:45 fix indent
Henrik Grunell 2012/03/27 07:22:05 Done.
107 WebKit::WebMediaStreamSource::TypeVideo,
108 UTF8ToUTF16(video_track->label()));
109 }
110
111 WebKit::WebMediaStreamDescriptor descriptor;
112 descriptor.initialize(UTF8ToUTF16(stream->label()), source_vector);
113
114 return descriptor;
115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698