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

Unified Diff: content/renderer/media/media_stream_impl.cc

Issue 9699069: Adding JSEP PeerConnection glue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed missing export. Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/media_stream_impl.h ('k') | content/renderer/media/media_stream_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/media_stream_impl.cc
diff --git a/content/renderer/media/media_stream_impl.cc b/content/renderer/media/media_stream_impl.cc
index 072def1d4168a5adc22ca08e9f30a3bbd19ae213..49404339748fb18cfbc84c9533155c84a84b19af 100644
--- a/content/renderer/media/media_stream_impl.cc
+++ b/content/renderer/media/media_stream_impl.cc
@@ -14,6 +14,7 @@
#include "content/renderer/media/media_stream_dependency_factory.h"
#include "content/renderer/media/media_stream_dispatcher.h"
#include "content/renderer/media/peer_connection_handler.h"
+#include "content/renderer/media/peer_connection_handler_jsep.h"
#include "content/renderer/media/video_capture_impl_manager.h"
#include "content/renderer/media/video_capture_module_impl.h"
#include "content/renderer/media/webrtc_audio_device_impl.h"
@@ -81,15 +82,13 @@ MediaStreamImpl::MediaStreamImpl(
p2p_socket_dispatcher_(p2p_socket_dispatcher),
network_manager_(NULL),
vc_manager_(vc_manager),
- peer_connection_handler_(NULL),
- message_loop_proxy_(base::MessageLoopProxy::current()),
signaling_thread_(NULL),
worker_thread_(NULL),
chrome_worker_thread_("Chrome_libJingle_WorkerThread") {
}
MediaStreamImpl::~MediaStreamImpl() {
- DCHECK(!peer_connection_handler_);
+ DCHECK(peer_connection_handlers_.empty());
if (dependency_factory_.get())
dependency_factory_->ReleasePeerConnectionFactory();
if (network_manager_) {
@@ -112,30 +111,46 @@ MediaStreamImpl::~MediaStreamImpl() {
WebKit::WebPeerConnectionHandler* MediaStreamImpl::CreatePeerConnectionHandler(
WebKit::WebPeerConnectionHandlerClient* client) {
DCHECK(CalledOnValidThread());
- if (peer_connection_handler_) {
- DVLOG(1) << "A PeerConnection already exists";
+ if (!EnsurePeerConnectionFactory())
return NULL;
- }
+
+ PeerConnectionHandler* pc_handler = new PeerConnectionHandler(
+ client,
+ this,
+ dependency_factory_.get());
+ peer_connection_handlers_.push_back(pc_handler);
+
+ return pc_handler;
+}
+
+WebKit::WebPeerConnection00Handler*
+MediaStreamImpl::CreatePeerConnectionHandlerJsep(
+ WebKit::WebPeerConnection00HandlerClient* client) {
+ DCHECK(CalledOnValidThread());
if (!EnsurePeerConnectionFactory())
return NULL;
- peer_connection_handler_ = new PeerConnectionHandler(
+ PeerConnectionHandlerJsep* pc_handler = new PeerConnectionHandlerJsep(
client,
this,
dependency_factory_.get());
+ peer_connection_handlers_.push_back(pc_handler);
- return peer_connection_handler_;
+ return pc_handler;
}
-void MediaStreamImpl::ClosePeerConnection() {
+void MediaStreamImpl::ClosePeerConnection(
+ PeerConnectionHandlerBase* pc_handler) {
DCHECK(CalledOnValidThread());
- video_renderer_ = NULL;
- peer_connection_handler_ = NULL;
- // TODO(grunell): This is a temporary workaround for an error in native
- // PeerConnection where added live tracks are not seen on the remote side.
- MediaStreamTrackPtrMap::const_iterator it = local_tracks_.begin();
- for (; it != local_tracks_.end(); ++it)
- it->second->set_state(webrtc::MediaStreamTrackInterface::kEnded);
+ VideoRendererMap::iterator vr_it = video_renderers_.begin();
+ while (vr_it != video_renderers_.end()) {
+ if (vr_it->second.second == pc_handler) {
+ video_renderers_.erase(vr_it++);
+ } else {
+ ++vr_it;
+ }
+ }
+ peer_connection_handlers_.remove(pc_handler);
}
webrtc::MediaStreamTrackInterface* MediaStreamImpl::GetLocalMediaStreamTrack(
@@ -144,8 +159,8 @@ webrtc::MediaStreamTrackInterface* MediaStreamImpl::GetLocalMediaStreamTrack(
MediaStreamTrackPtrMap::iterator it = local_tracks_.find(label);
if (it == local_tracks_.end())
return NULL;
- MediaStreamTrackPtr stream = it->second;
- return stream.get();
+ MediaStreamTrackPtr track = it->second;
+ return track.get();
}
void MediaStreamImpl::requestUserMedia(
@@ -236,27 +251,34 @@ scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder(
capability);
} else {
// It's a remote stream.
- if (!video_renderer_.get())
- video_renderer_ = new talk_base::RefCountedObject<VideoRendererWrapper>();
- if (video_renderer_->renderer()) {
- // The renderer is used by PeerConnection, release it first.
- if (peer_connection_handler_) {
- peer_connection_handler_->SetVideoRenderer(
- UTF16ToUTF8(descriptor.label()),
- NULL);
+ std::string desc_label = UTF16ToUTF8(descriptor.label());
+ PeerConnectionHandlerBase* pc_handler = NULL;
+ std::list<PeerConnectionHandlerBase*>::iterator it;
+ for (it = peer_connection_handlers_.begin();
+ it != peer_connection_handlers_.end(); ++it) {
+ if ((*it)->HasStream(desc_label)) {
+ pc_handler = *it;
+ break;
}
- video_renderer_->SetVideoDecoder(NULL);
}
+ DCHECK(it != peer_connection_handlers_.end());
+ // TODO(grunell): We are not informed when a renderer should be deleted.
+ // When this has been fixed, ensure we delete it. For now, we hold on
+ // to all renderers until a PeerConnectionHandler is closed or we are
+ // deleted (then all renderers are deleted), so it sort of leaks.
+ // TODO(grunell): There is no support for multiple decoders per stream, this
+ // code will need to be updated when that is supported.
+ talk_base::scoped_refptr<VideoRendererWrapper> video_renderer =
+ new talk_base::RefCountedObject<VideoRendererWrapper>();
RTCVideoDecoder* rtc_video_decoder = new RTCVideoDecoder(
message_loop_factory->GetMessageLoop("RtcVideoDecoderThread"),
url.spec());
decoder = rtc_video_decoder;
- video_renderer_->SetVideoDecoder(rtc_video_decoder);
- if (peer_connection_handler_) {
- peer_connection_handler_->SetVideoRenderer(
- UTF16ToUTF8(descriptor.label()),
- video_renderer_);
- }
+ video_renderer->SetVideoDecoder(rtc_video_decoder);
+ pc_handler->SetVideoRenderer(desc_label, video_renderer);
+ video_renderers_.erase(desc_label); // Remove old renderer if exists.
+ video_renderers_.insert(
+ std::make_pair(desc_label, std::make_pair(video_renderer, pc_handler)));
}
return decoder;
}
« no previous file with comments | « content/renderer/media/media_stream_impl.h ('k') | content/renderer/media/media_stream_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698