summaryrefslogtreecommitdiffstats
path: root/content/renderer/media
diff options
context:
space:
mode:
authoreugenis@google.com <eugenis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-12 10:07:53 +0000
committereugenis@google.com <eugenis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-12 10:07:53 +0000
commit19746afb63d62e6355cc4b6312b809350794cf46 (patch)
tree3444efd445301ba910df434d4efdc5edff3adcce /content/renderer/media
parent49ae3e55200b24617f7ae12752eaed1514fdaeb8 (diff)
downloadchromium_src-19746afb63d62e6355cc4b6312b809350794cf46.zip
chromium_src-19746afb63d62e6355cc4b6312b809350794cf46.tar.gz
chromium_src-19746afb63d62e6355cc4b6312b809350794cf46.tar.bz2
Revert 131949 (multiple memory leaks) - Adding JSEP PeerConnection glue.
This adds glue for JSEP PeerConnection. PeerConnectionHandler is split in two classes and a base class. The class name is kept for the old ROAP PeerConnection to be aligned with WebKit naming. ROAP is planned to be removed pretty soon, then the classes can be refactored. See also main WebKit bug https://bugs.webkit.org/show_bug.cgi?id=80589 (In particular https://bugs.webkit.org/show_bug.cgi?id=82450) TEST=content_unittests and manual webrtc test. Review URL: http://codereview.chromium.org/9699069 TBR=grunell@chromium.org Review URL: https://chromiumcodereview.appspot.com/10038009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131961 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/media')
-rw-r--r--content/renderer/media/media_stream_center.cc39
-rw-r--r--content/renderer/media/media_stream_center.h6
-rw-r--r--content/renderer/media/media_stream_dependency_factory.cc11
-rw-r--r--content/renderer/media/media_stream_dependency_factory.h6
-rw-r--r--content/renderer/media/media_stream_impl.cc88
-rw-r--r--content/renderer/media/media_stream_impl.h28
-rw-r--r--content/renderer/media/media_stream_impl_unittest.cc68
-rw-r--r--content/renderer/media/mock_media_stream_dependency_factory.cc76
-rw-r--r--content/renderer/media/mock_media_stream_dependency_factory.h5
-rw-r--r--content/renderer/media/mock_media_stream_impl.cc3
-rw-r--r--content/renderer/media/mock_media_stream_impl.h3
-rw-r--r--content/renderer/media/mock_peer_connection_impl.cc52
-rw-r--r--content/renderer/media/mock_peer_connection_impl.h25
-rw-r--r--content/renderer/media/mock_web_peer_connection_00_handler_client.cc56
-rw-r--r--content/renderer/media/mock_web_peer_connection_00_handler_client.h51
-rw-r--r--content/renderer/media/peer_connection_handler.cc120
-rw-r--r--content/renderer/media/peer_connection_handler.h49
-rw-r--r--content/renderer/media/peer_connection_handler_base.cc123
-rw-r--r--content/renderer/media/peer_connection_handler_base.h71
-rw-r--r--content/renderer/media/peer_connection_handler_jsep.cc368
-rw-r--r--content/renderer/media/peer_connection_handler_jsep.h85
-rw-r--r--content/renderer/media/peer_connection_handler_jsep_unittest.cc231
22 files changed, 220 insertions, 1344 deletions
diff --git a/content/renderer/media/media_stream_center.cc b/content/renderer/media/media_stream_center.cc
index 2e5a43b..172a151 100644
--- a/content/renderer/media/media_stream_center.cc
+++ b/content/renderer/media/media_stream_center.cc
@@ -4,17 +4,10 @@
#include "content/renderer/media/media_stream_center.h"
-#include <string>
-
-#include "base/logging.h"
-#include "base/utf_string_conversions.h"
-#include "third_party/libjingle/source/talk/app/webrtc/jsep.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebICECandidateDescriptor.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamCenterClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamDescriptor.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamSource.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamSourcesRequest.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSessionDescriptionDescriptor.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
namespace content {
@@ -48,36 +41,4 @@ void MediaStreamCenter::didConstructMediaStream(
const WebKit::WebMediaStreamDescriptor& stream) {
}
-WebKit::WebString MediaStreamCenter::constructSDP(
- const WebKit::WebICECandidateDescriptor& candidate) {
- webrtc::IceCandidateInterface* native_candidate =
- webrtc::CreateIceCandidate(UTF16ToUTF8(candidate.label()),
- UTF16ToUTF8(candidate.candidateLine()));
- std::string sdp;
- if (!native_candidate->ToString(&sdp))
- LOG(ERROR) << "Could not create SDP string";
- return UTF8ToUTF16(sdp);
-}
-
-WebKit::WebString MediaStreamCenter::constructSDP(
- const WebKit::WebSessionDescriptionDescriptor& description) {
- webrtc::SessionDescriptionInterface* native_desc =
- webrtc::CreateSessionDescription(UTF16ToUTF8(description.initialSDP()));
- if (!native_desc)
- return WebKit::WebString();
-
- for (size_t i = 0; i < description.numberOfAddedCandidates(); ++i) {
- WebKit::WebICECandidateDescriptor candidate = description.candidate(i);
- webrtc::IceCandidateInterface* native_candidate =
- webrtc::CreateIceCandidate(UTF16ToUTF8(candidate.label()),
- UTF16ToUTF8(candidate.candidateLine()));
- native_desc->AddCandidate(native_candidate);
- }
-
- std::string sdp;
- if (!native_desc->ToString(&sdp))
- LOG(ERROR) << "Could not create SDP string";
- return UTF8ToUTF16(sdp);
-}
-
} // namespace content
diff --git a/content/renderer/media/media_stream_center.h b/content/renderer/media/media_stream_center.h
index d7020fd..11c1fc4 100644
--- a/content/renderer/media/media_stream_center.h
+++ b/content/renderer/media/media_stream_center.h
@@ -38,12 +38,6 @@ class CONTENT_EXPORT MediaStreamCenter
virtual void didConstructMediaStream(
const WebKit::WebMediaStreamDescriptor& stream) OVERRIDE;
- virtual WebKit::WebString constructSDP(
- const WebKit::WebICECandidateDescriptor& candidate) OVERRIDE;
-
- virtual WebKit::WebString constructSDP(
- const WebKit::WebSessionDescriptionDescriptor& description) OVERRIDE;
-
private:
// Weak pointer, owned by WebKit.
WebKit::WebMediaStreamCenterClient* client_;
diff --git a/content/renderer/media/media_stream_dependency_factory.cc b/content/renderer/media/media_stream_dependency_factory.cc
index 2c8d997..f245485 100644
--- a/content/renderer/media/media_stream_dependency_factory.cc
+++ b/content/renderer/media/media_stream_dependency_factory.cc
@@ -137,14 +137,3 @@ MediaStreamDependencyFactory::CreateLocalAudioTrack(
webrtc::AudioDeviceModule* audio_device) {
return pc_factory_->CreateLocalAudioTrack(label, audio_device);
}
-
-webrtc::SessionDescriptionInterface*
-MediaStreamDependencyFactory::CreateSessionDescription(const std::string& sdp) {
- return webrtc::CreateSessionDescription(sdp);
-}
-
-webrtc::IceCandidateInterface* MediaStreamDependencyFactory::CreateIceCandidate(
- const std::string& label,
- const std::string& sdp) {
- return webrtc::CreateIceCandidate(label, sdp);
-}
diff --git a/content/renderer/media/media_stream_dependency_factory.h b/content/renderer/media/media_stream_dependency_factory.h
index 559b8d9..9bf0e80 100644
--- a/content/renderer/media/media_stream_dependency_factory.h
+++ b/content/renderer/media/media_stream_dependency_factory.h
@@ -74,12 +74,6 @@ class CONTENT_EXPORT MediaStreamDependencyFactory {
CreateLocalAudioTrack(const std::string& label,
webrtc::AudioDeviceModule* audio_device);
- virtual webrtc::SessionDescriptionInterface* CreateSessionDescription(
- const std::string& sdp);
- virtual webrtc::IceCandidateInterface* CreateIceCandidate(
- const std::string& label,
- const std::string& sdp);
-
private:
talk_base::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
diff --git a/content/renderer/media/media_stream_impl.cc b/content/renderer/media/media_stream_impl.cc
index 4940433..072def1 100644
--- a/content/renderer/media/media_stream_impl.cc
+++ b/content/renderer/media/media_stream_impl.cc
@@ -14,7 +14,6 @@
#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"
@@ -82,13 +81,15 @@ 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_handlers_.empty());
+ DCHECK(!peer_connection_handler_);
if (dependency_factory_.get())
dependency_factory_->ReleasePeerConnectionFactory();
if (network_manager_) {
@@ -111,46 +112,30 @@ MediaStreamImpl::~MediaStreamImpl() {
WebKit::WebPeerConnectionHandler* MediaStreamImpl::CreatePeerConnectionHandler(
WebKit::WebPeerConnectionHandlerClient* client) {
DCHECK(CalledOnValidThread());
- if (!EnsurePeerConnectionFactory())
+ if (peer_connection_handler_) {
+ DVLOG(1) << "A PeerConnection already exists";
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;
- PeerConnectionHandlerJsep* pc_handler = new PeerConnectionHandlerJsep(
+ peer_connection_handler_ = new PeerConnectionHandler(
client,
this,
dependency_factory_.get());
- peer_connection_handlers_.push_back(pc_handler);
- return pc_handler;
+ return peer_connection_handler_;
}
-void MediaStreamImpl::ClosePeerConnection(
- PeerConnectionHandlerBase* pc_handler) {
+void MediaStreamImpl::ClosePeerConnection() {
DCHECK(CalledOnValidThread());
- 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);
+ 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);
}
webrtc::MediaStreamTrackInterface* MediaStreamImpl::GetLocalMediaStreamTrack(
@@ -159,8 +144,8 @@ webrtc::MediaStreamTrackInterface* MediaStreamImpl::GetLocalMediaStreamTrack(
MediaStreamTrackPtrMap::iterator it = local_tracks_.find(label);
if (it == local_tracks_.end())
return NULL;
- MediaStreamTrackPtr track = it->second;
- return track.get();
+ MediaStreamTrackPtr stream = it->second;
+ return stream.get();
}
void MediaStreamImpl::requestUserMedia(
@@ -251,34 +236,27 @@ scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder(
capability);
} else {
// It's a remote stream.
- 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;
+ 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);
}
+ 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);
- 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)));
+ video_renderer_->SetVideoDecoder(rtc_video_decoder);
+ if (peer_connection_handler_) {
+ peer_connection_handler_->SetVideoRenderer(
+ UTF16ToUTF8(descriptor.label()),
+ video_renderer_);
+ }
}
return decoder;
}
diff --git a/content/renderer/media/media_stream_impl.h b/content/renderer/media/media_stream_impl.h
index a9c2db7..7a59582 100644
--- a/content/renderer/media/media_stream_impl.h
+++ b/content/renderer/media/media_stream_impl.h
@@ -8,7 +8,6 @@
#include <list>
#include <map>
#include <string>
-#include <utility>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
@@ -43,15 +42,13 @@ class Thread;
}
namespace WebKit {
-class WebPeerConnection00Handler;
-class WebPeerConnection00HandlerClient;
class WebPeerConnectionHandler;
class WebPeerConnectionHandlerClient;
}
class MediaStreamDispatcher;
class MediaStreamDependencyFactory;
-class PeerConnectionHandlerBase;
+class PeerConnectionHandler;
class VideoCaptureImplManager;
class RTCVideoDecoder;
@@ -77,9 +74,7 @@ class CONTENT_EXPORT MediaStreamImpl
virtual WebKit::WebPeerConnectionHandler* CreatePeerConnectionHandler(
WebKit::WebPeerConnectionHandlerClient* client);
- virtual WebKit::WebPeerConnection00Handler* CreatePeerConnectionHandlerJsep(
- WebKit::WebPeerConnection00HandlerClient* client);
- virtual void ClosePeerConnection(PeerConnectionHandlerBase* pc_handler);
+ virtual void ClosePeerConnection();
virtual webrtc::MediaStreamTrackInterface* GetLocalMediaStreamTrack(
const std::string& label);
@@ -122,7 +117,6 @@ class CONTENT_EXPORT MediaStreamImpl
private:
FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, Basic);
- FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, MultiplePeerConnections);
class VideoRendererWrapper : public webrtc::VideoRendererWrapperInterface {
public:
@@ -165,10 +159,10 @@ class CONTENT_EXPORT MediaStreamImpl
scoped_refptr<VideoCaptureImplManager> vc_manager_;
- // peer_connection_handlers_ contains raw references, owned by WebKit. A
- // pointer is valid until stop is called on the object (which will call
- // ClosePeerConnection on us and we remove the pointer).
- std::list<PeerConnectionHandlerBase*> peer_connection_handlers_;
+ // peer_connection_handler_ is a weak reference, owned by WebKit. It's valid
+ // until stop is called on it (which will call ClosePeerConnection on us).
+ // TODO(grunell): Support several PeerConnectionsHandlers.
+ PeerConnectionHandler* peer_connection_handler_;
// We keep a list of the generated local tracks, so that we can add capture
// devices when generated and also use them for recording.
@@ -177,14 +171,8 @@ class CONTENT_EXPORT MediaStreamImpl
typedef std::map<std::string, MediaStreamTrackPtr> MediaStreamTrackPtrMap;
MediaStreamTrackPtrMap local_tracks_;
- // Native PeerConnection only supports 1:1 mapping between MediaStream and
- // video tag/renderer, so we restrict to this too. The key in
- // VideoRendererMap is the stream label.
- typedef talk_base::scoped_refptr<VideoRendererWrapper> VideoRendererPtr;
- typedef std::pair<VideoRendererPtr, PeerConnectionHandlerBase*>
- VideoRendererPair;
- typedef std::map<std::string, VideoRendererPair> VideoRendererMap;
- VideoRendererMap video_renderers_;
+ talk_base::scoped_refptr<VideoRendererWrapper> video_renderer_;
+ scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
// PeerConnection threads. signaling_thread_ is created from the
// "current" chrome thread.
diff --git a/content/renderer/media/media_stream_impl_unittest.cc b/content/renderer/media/media_stream_impl_unittest.cc
index f00aa04..110c69d 100644
--- a/content/renderer/media/media_stream_impl_unittest.cc
+++ b/content/renderer/media/media_stream_impl_unittest.cc
@@ -7,14 +7,10 @@
#include "content/renderer/media/media_stream_impl.h"
#include "content/renderer/media/mock_media_stream_dependency_factory.h"
#include "content/renderer/media/mock_media_stream_dispatcher.h"
-#include "content/renderer/media/mock_web_peer_connection_00_handler_client.h"
#include "content/renderer/media/mock_web_peer_connection_handler_client.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/p2p/socket_dispatcher.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
// Disabled due to http://crbug.com/112408 .
@@ -42,67 +38,9 @@ TEST(MediaStreamImplTest, DISABLED_Basic) {
WebKit::MockWebPeerConnectionHandlerClient client;
WebKit::WebPeerConnectionHandler* pc_handler =
ms_impl->CreatePeerConnectionHandler(&client);
- EXPECT_EQ(1u, ms_impl->peer_connection_handlers_.size());
+ EXPECT_TRUE(ms_impl->peer_connection_handler_);
- // Delete PC handler explicitly after closing to mimic WebKit behavior.
- ms_impl->ClosePeerConnection(
- static_cast<PeerConnectionHandler*>(pc_handler));
- EXPECT_TRUE(ms_impl->peer_connection_handlers_.empty());
+ ms_impl->ClosePeerConnection();
+ EXPECT_FALSE(ms_impl->peer_connection_handler_);
delete pc_handler;
-
- WebKit::MockWebPeerConnection00HandlerClient client_jsep;
- WebKit::WebPeerConnection00Handler* pc_handler_jsep =
- ms_impl->CreatePeerConnectionHandlerJsep(&client_jsep);
- EXPECT_EQ(1u, ms_impl->peer_connection_handlers_.size());
-
- // Delete PC handler explicitly after closing to mimic WebKit behavior.
- ms_impl->ClosePeerConnection(
- static_cast<PeerConnectionHandlerJsep*>(pc_handler_jsep));
- EXPECT_TRUE(ms_impl->peer_connection_handlers_.empty());
- delete pc_handler_jsep;
-}
-
-// Disabled due to http://crbug.com/112408 .
-TEST(MediaStreamImplTest, DISABLED_MultiplePeerConnections) {
- MessageLoop loop;
-
- // Create our test object.
- scoped_ptr<MockMediaStreamDispatcher> ms_dispatcher(
- new MockMediaStreamDispatcher());
- scoped_ptr<content::P2PSocketDispatcher> p2p_socket_dispatcher(
- new content::P2PSocketDispatcher(NULL));
- scoped_refptr<VideoCaptureImplManager> vc_manager(
- new VideoCaptureImplManager());
- MockMediaStreamDependencyFactory* dependency_factory =
- new MockMediaStreamDependencyFactory();
- scoped_refptr<MediaStreamImpl> ms_impl(new MediaStreamImpl(
- ms_dispatcher.get(),
- p2p_socket_dispatcher.get(),
- vc_manager.get(),
- dependency_factory));
-
- // TODO(grunell): Add tests for WebKit::WebUserMediaClient and
- // MediaStreamDispatcherEventHandler implementations.
-
- WebKit::MockWebPeerConnectionHandlerClient client;
- WebKit::WebPeerConnectionHandler* pc_handler =
- ms_impl->CreatePeerConnectionHandler(&client);
- EXPECT_EQ(1u, ms_impl->peer_connection_handlers_.size());
-
- WebKit::MockWebPeerConnection00HandlerClient client_jsep;
- WebKit::WebPeerConnection00Handler* pc_handler_jsep =
- ms_impl->CreatePeerConnectionHandlerJsep(&client_jsep);
- EXPECT_EQ(2u, ms_impl->peer_connection_handlers_.size());
-
- // Delete PC handler explicitly after closing to mimic WebKit behavior.
- ms_impl->ClosePeerConnection(
- static_cast<PeerConnectionHandler*>(pc_handler));
- EXPECT_EQ(1u, ms_impl->peer_connection_handlers_.size());
- delete pc_handler;
-
- // Delete PC handler explicitly after closing to mimic WebKit behavior.
- ms_impl->ClosePeerConnection(
- static_cast<PeerConnectionHandlerJsep*>(pc_handler_jsep));
- EXPECT_TRUE(ms_impl->peer_connection_handlers_.empty());
- delete pc_handler_jsep;
}
diff --git a/content/renderer/media/mock_media_stream_dependency_factory.cc b/content/renderer/media/mock_media_stream_dependency_factory.cc
index 7d54d11..2d76882 100644
--- a/content/renderer/media/mock_media_stream_dependency_factory.cc
+++ b/content/renderer/media/mock_media_stream_dependency_factory.cc
@@ -123,65 +123,6 @@ void MockLocalVideoTrack::UnregisterObserver(ObserverInterface* observer) {
NOTIMPLEMENTED();
}
-class MockSessionDescription : public SessionDescriptionInterface {
- public:
- MockSessionDescription(const std::string& sdp)
- : sdp_(sdp) {
- }
- virtual ~MockSessionDescription() {}
- virtual const cricket::SessionDescription* description() const OVERRIDE {
- NOTIMPLEMENTED();
- return NULL;
- }
- virtual bool AddCandidate(const IceCandidateInterface* candidate) OVERRIDE {
- NOTIMPLEMENTED();
- return false;
- }
- virtual size_t number_of_mediasections() const OVERRIDE {
- NOTIMPLEMENTED();
- return 0;
- }
- virtual const IceCandidateColletion* candidates(
- size_t mediasection_index) const OVERRIDE {
- NOTIMPLEMENTED();
- return NULL;
- }
- virtual bool ToString(std::string* out) const OVERRIDE {
- *out = sdp_;
- return true;
- }
-
- private:
- std::string sdp_;
-};
-
-class MockIceCandidate : public IceCandidateInterface {
- public:
- MockIceCandidate(const std::string& label, const std::string& sdp)
- : label_(label),
- sdp_(sdp) {
- }
- virtual ~MockIceCandidate() {}
- virtual std::string label() const OVERRIDE {
- return label_;
- }
- virtual const cricket::Candidate& candidate() const OVERRIDE {
- // This function should never be called. It will intentionally crash. The
- // base class forces us to return a reference.
- NOTREACHED();
- cricket::Candidate* candidate = NULL;
- return *candidate;
- }
- virtual bool ToString(std::string* out) const OVERRIDE {
- *out = sdp_;
- return true;
- }
-
- private:
- std::string label_;
- std::string sdp_;
-};
-
} // namespace webrtc
MockMediaStreamDependencyFactory::MockMediaStreamDependencyFactory()
@@ -213,7 +154,7 @@ MockMediaStreamDependencyFactory::CreatePeerConnection(
const std::string& config,
webrtc::PeerConnectionObserver* observer) {
DCHECK(mock_pc_factory_created_);
- return new talk_base::RefCountedObject<webrtc::MockPeerConnectionImpl>(this);
+ return new talk_base::RefCountedObject<webrtc::MockPeerConnectionImpl>();
}
talk_base::scoped_refptr<webrtc::PeerConnectionInterface>
@@ -221,7 +162,7 @@ MockMediaStreamDependencyFactory::CreateRoapPeerConnection(
const std::string& config,
webrtc::PeerConnectionObserver* observer) {
DCHECK(mock_pc_factory_created_);
- return new talk_base::RefCountedObject<webrtc::MockPeerConnectionImpl>(this);
+ return new talk_base::RefCountedObject<webrtc::MockPeerConnectionImpl>();
}
talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface>
@@ -248,16 +189,3 @@ MockMediaStreamDependencyFactory::CreateLocalAudioTrack(
NOTIMPLEMENTED();
return NULL;
}
-
-webrtc::SessionDescriptionInterface*
-MockMediaStreamDependencyFactory::CreateSessionDescription(
- const std::string& sdp) {
- return new webrtc::MockSessionDescription(sdp);
-}
-
-webrtc::IceCandidateInterface*
-MockMediaStreamDependencyFactory::CreateIceCandidate(
- const std::string& label,
- const std::string& sdp) {
- return new webrtc::MockIceCandidate(label, sdp);
-}
diff --git a/content/renderer/media/mock_media_stream_dependency_factory.h b/content/renderer/media/mock_media_stream_dependency_factory.h
index 2a8737a..f482ce5 100644
--- a/content/renderer/media/mock_media_stream_dependency_factory.h
+++ b/content/renderer/media/mock_media_stream_dependency_factory.h
@@ -77,11 +77,6 @@ class MockMediaStreamDependencyFactory : public MediaStreamDependencyFactory {
CreateLocalAudioTrack(
const std::string& label,
webrtc::AudioDeviceModule* audio_device) OVERRIDE;
- virtual webrtc::SessionDescriptionInterface* CreateSessionDescription(
- const std::string& sdp) OVERRIDE;
- virtual webrtc::IceCandidateInterface* CreateIceCandidate(
- const std::string& label,
- const std::string& sdp) OVERRIDE;
private:
bool mock_pc_factory_created_;
diff --git a/content/renderer/media/mock_media_stream_impl.cc b/content/renderer/media/mock_media_stream_impl.cc
index 8ce04de..4996e95 100644
--- a/content/renderer/media/mock_media_stream_impl.cc
+++ b/content/renderer/media/mock_media_stream_impl.cc
@@ -21,8 +21,7 @@ MockMediaStreamImpl::CreatePeerConnectionHandler(
return NULL;
}
-void MockMediaStreamImpl::ClosePeerConnection(
- PeerConnectionHandlerBase* pc_handler) {
+void MockMediaStreamImpl::ClosePeerConnection() {
}
webrtc::MediaStreamTrackInterface*
diff --git a/content/renderer/media/mock_media_stream_impl.h b/content/renderer/media/mock_media_stream_impl.h
index f751ed7..8340b9e 100644
--- a/content/renderer/media/mock_media_stream_impl.h
+++ b/content/renderer/media/mock_media_stream_impl.h
@@ -17,8 +17,7 @@ class MockMediaStreamImpl : public MediaStreamImpl {
virtual WebKit::WebPeerConnectionHandler* CreatePeerConnectionHandler(
WebKit::WebPeerConnectionHandlerClient* client) OVERRIDE;
- virtual void ClosePeerConnection(
- PeerConnectionHandlerBase* pc_handler) OVERRIDE;
+ virtual void ClosePeerConnection() OVERRIDE;
virtual webrtc::MediaStreamTrackInterface* GetLocalMediaStreamTrack(
const std::string& label) OVERRIDE;
diff --git a/content/renderer/media/mock_peer_connection_impl.cc b/content/renderer/media/mock_peer_connection_impl.cc
index 7f68eae..ccfae44 100644
--- a/content/renderer/media/mock_peer_connection_impl.cc
+++ b/content/renderer/media/mock_peer_connection_impl.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/renderer/media/mock_media_stream_dependency_factory.h"
#include "content/renderer/media/mock_peer_connection_impl.h"
#include <vector>
@@ -37,19 +36,10 @@ class MockStreamCollection : public StreamCollectionInterface {
std::vector<talk_base::scoped_refptr<MediaStreamInterface> > streams_;
};
-const char MockPeerConnectionImpl::kDummyOffer[] = "dummy offer";
-
-MockPeerConnectionImpl::MockPeerConnectionImpl(
- MockMediaStreamDependencyFactory* factory)
- : dependency_factory_(factory),
- stream_changes_committed_(false),
+MockPeerConnectionImpl::MockPeerConnectionImpl()
+ : stream_changes_committed_(false),
local_streams_(new talk_base::RefCountedObject<MockStreamCollection>),
- remote_streams_(new talk_base::RefCountedObject<MockStreamCollection>),
- hint_audio_(false),
- hint_video_(false),
- action_(kAnswer),
- ice_options_(kOnlyRelay),
- ready_state_(kNew) {
+ remote_streams_(new talk_base::RefCountedObject<MockStreamCollection>) {
}
MockPeerConnectionImpl::~MockPeerConnectionImpl() {}
@@ -95,7 +85,8 @@ void MockPeerConnectionImpl::Close() {
}
MockPeerConnectionImpl::ReadyState MockPeerConnectionImpl::ready_state() {
- return ready_state_;
+ NOTIMPLEMENTED();
+ return kNew;
}
MockPeerConnectionImpl::SdpState MockPeerConnectionImpl::sdp_state() {
@@ -104,54 +95,53 @@ MockPeerConnectionImpl::SdpState MockPeerConnectionImpl::sdp_state() {
}
bool MockPeerConnectionImpl::StartIce(IceOptions options) {
- ice_options_ = options;
- return true;
+ NOTIMPLEMENTED();
+ return false;
}
webrtc::SessionDescriptionInterface* MockPeerConnectionImpl::CreateOffer(
const webrtc::MediaHints& hints) {
- hint_audio_ = hints.has_audio();
- hint_video_ = hints.has_video();
- return dependency_factory_->CreateSessionDescription(kDummyOffer);
+ NOTIMPLEMENTED();
+ return NULL;
}
webrtc::SessionDescriptionInterface* MockPeerConnectionImpl::CreateAnswer(
const webrtc::MediaHints& hints,
const webrtc::SessionDescriptionInterface* offer) {
- hint_audio_ = hints.has_audio();
- hint_video_ = hints.has_video();
- offer->ToString(&description_sdp_);
- return dependency_factory_->CreateSessionDescription(description_sdp_);
+ NOTIMPLEMENTED();
+ return NULL;
}
bool MockPeerConnectionImpl::SetLocalDescription(
Action action,
webrtc::SessionDescriptionInterface* desc) {
- action_ = action;
- return desc->ToString(&description_sdp_);
+ NOTIMPLEMENTED();
+ return false;
}
bool MockPeerConnectionImpl::SetRemoteDescription(
Action action,
webrtc::SessionDescriptionInterface* desc) {
- action_ = action;
- return desc->ToString(&description_sdp_);
+ NOTIMPLEMENTED();
+ return false;
}
bool MockPeerConnectionImpl::ProcessIceMessage(
const webrtc::IceCandidateInterface* ice_candidate) {
- ice_label_ = ice_candidate->label();
- return ice_candidate->ToString(&ice_sdp_);
+ NOTIMPLEMENTED();
+ return false;
}
const webrtc::SessionDescriptionInterface*
MockPeerConnectionImpl::local_description() const {
- return dependency_factory_->CreateSessionDescription(description_sdp_);
+ NOTIMPLEMENTED();
+ return NULL;
}
const webrtc::SessionDescriptionInterface*
MockPeerConnectionImpl::remote_description() const {
- return dependency_factory_->CreateSessionDescription(description_sdp_);
+ NOTIMPLEMENTED();
+ return NULL;
}
void MockPeerConnectionImpl::AddRemoteStream(MediaStreamInterface* stream) {
diff --git a/content/renderer/media/mock_peer_connection_impl.h b/content/renderer/media/mock_peer_connection_impl.h
index 60afd6c..2993ce4 100644
--- a/content/renderer/media/mock_peer_connection_impl.h
+++ b/content/renderer/media/mock_peer_connection_impl.h
@@ -11,15 +11,13 @@
#include "base/compiler_specific.h"
#include "third_party/libjingle/source/talk/app/webrtc/peerconnection.h"
-class MockMediaStreamDependencyFactory;
-
namespace webrtc {
class MockStreamCollection;
class MockPeerConnectionImpl : public PeerConnectionInterface {
public:
- MockPeerConnectionImpl(MockMediaStreamDependencyFactory* factory);
+ MockPeerConnectionImpl();
// PeerConnectionInterface implementation.
virtual void ProcessSignalingMessage(const std::string& msg) OVERRIDE;
@@ -56,41 +54,20 @@ class MockPeerConnectionImpl : public PeerConnectionInterface {
void AddRemoteStream(MediaStreamInterface* stream);
void ClearStreamChangesCommitted() { stream_changes_committed_ = false; }
- void SetReadyState(ReadyState state) { ready_state_ = state; }
const std::string& signaling_message() const { return signaling_message_; }
const std::string& stream_label() const { return stream_label_; }
bool stream_changes_committed() const { return stream_changes_committed_; }
- bool hint_audio() const { return hint_audio_; }
- bool hint_video() const { return hint_video_; }
- Action action() const { return action_; }
- const std::string& description_sdp() const { return description_sdp_; }
- IceOptions ice_options() const { return ice_options_; }
- const std::string& ice_label() const { return ice_label_; }
- const std::string& ice_sdp() const { return ice_sdp_; }
-
- static const char kDummyOffer[];
protected:
virtual ~MockPeerConnectionImpl();
private:
- // Used for creating MockSessionDescription.
- MockMediaStreamDependencyFactory* dependency_factory_;
-
std::string signaling_message_;
std::string stream_label_;
bool stream_changes_committed_;
talk_base::scoped_refptr<MockStreamCollection> local_streams_;
talk_base::scoped_refptr<MockStreamCollection> remote_streams_;
- bool hint_audio_;
- bool hint_video_;
- Action action_;
- std::string description_sdp_;
- IceOptions ice_options_;
- std::string ice_label_;
- std::string ice_sdp_;
- ReadyState ready_state_;
DISALLOW_COPY_AND_ASSIGN(MockPeerConnectionImpl);
};
diff --git a/content/renderer/media/mock_web_peer_connection_00_handler_client.cc b/content/renderer/media/mock_web_peer_connection_00_handler_client.cc
deleted file mode 100644
index 770e3fb7..0000000
--- a/content/renderer/media/mock_web_peer_connection_00_handler_client.cc
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/logging.h"
-#include "base/utf_string_conversions.h"
-#include "content/renderer/media/mock_web_peer_connection_00_handler_client.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebICECandidateDescriptor.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamDescriptor.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
-
-namespace WebKit {
-
-MockWebPeerConnection00HandlerClient::
-MockWebPeerConnection00HandlerClient()
- : ready_state_(ReadyStateNew),
- more_to_follow_(false) {
-}
-
-MockWebPeerConnection00HandlerClient::
-~MockWebPeerConnection00HandlerClient() {}
-
-void MockWebPeerConnection00HandlerClient::didGenerateICECandidate(
- const WebICECandidateDescriptor& candidate,
- bool more_to_follow) {
- if (candidate.isNull()) {
- candidate_label_.clear();
- candidate_sdp_.clear();
- } else {
- candidate_label_ = UTF16ToUTF8(candidate.label());
- candidate_sdp_ = UTF16ToUTF8(candidate.candidateLine());
- }
- more_to_follow_ = more_to_follow;
-}
-
-void MockWebPeerConnection00HandlerClient::didChangeReadyState(
- ReadyState state) {
- ready_state_ = state;
-}
-
-void MockWebPeerConnection00HandlerClient::didChangeICEState(ICEState state) {
- NOTIMPLEMENTED();
-}
-
-void MockWebPeerConnection00HandlerClient::didAddRemoteStream(
- const WebMediaStreamDescriptor& stream_descriptor) {
- stream_label_ = UTF16ToUTF8(stream_descriptor.label());
-}
-
-void MockWebPeerConnection00HandlerClient::didRemoveRemoteStream(
- const WebMediaStreamDescriptor& stream_descriptor) {
- DCHECK(stream_label_ == UTF16ToUTF8(stream_descriptor.label()));
- stream_label_.clear();
-}
-
-} // namespace WebKit
diff --git a/content/renderer/media/mock_web_peer_connection_00_handler_client.h b/content/renderer/media/mock_web_peer_connection_00_handler_client.h
deleted file mode 100644
index 7f3de5c..0000000
--- a/content/renderer/media/mock_web_peer_connection_00_handler_client.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_RENDERER_MEDIA_MOCK_WEB_JSEP_PEER_CONNECTION_HANDLER_CLIENT_H_
-#define CONTENT_RENDERER_MEDIA_MOCK_WEB_JSEP_PEER_CONNECTION_HANDLER_CLIENT_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00HandlerClient.h"
-
-namespace WebKit {
-
-class MockWebPeerConnection00HandlerClient
- : public WebPeerConnection00HandlerClient {
- public:
- MockWebPeerConnection00HandlerClient();
- virtual ~MockWebPeerConnection00HandlerClient();
-
- // WebPeerConnection00HandlerClient implementation.
- virtual void didGenerateICECandidate(
- const WebICECandidateDescriptor& candidate,
- bool more_to_follow) OVERRIDE;
- virtual void didChangeReadyState(ReadyState state) OVERRIDE;
- virtual void didChangeICEState(ICEState state) OVERRIDE;
- virtual void didAddRemoteStream(
- const WebMediaStreamDescriptor& stream_descriptor) OVERRIDE;
- virtual void didRemoveRemoteStream(
- const WebMediaStreamDescriptor& stream_descriptor) OVERRIDE;
-
- const std::string& stream_label() const { return stream_label_; }
- ReadyState ready_state() const { return ready_state_; }
- const std::string& candidate_label() const { return candidate_label_; }
- const std::string& candidate_sdp() const { return candidate_sdp_; }
- bool more_to_follow() const { return more_to_follow_; }
-
- private:
- std::string stream_label_;
- ReadyState ready_state_;
- std::string candidate_label_;
- std::string candidate_sdp_;
- bool more_to_follow_;
-
- DISALLOW_COPY_AND_ASSIGN(MockWebPeerConnection00HandlerClient);
-};
-
-} // namespace WebKit
-
-#endif // CONTENT_RENDERER_MEDIA_MOCK_WEB_JSEP_PEER_CONNECTION_HANDLER_CLIENT_H_
diff --git a/content/renderer/media/peer_connection_handler.cc b/content/renderer/media/peer_connection_handler.cc
index 747e95f..74acf2e 100644
--- a/content/renderer/media/peer_connection_handler.cc
+++ b/content/renderer/media/peer_connection_handler.cc
@@ -22,13 +22,32 @@ PeerConnectionHandler::PeerConnectionHandler(
WebKit::WebPeerConnectionHandlerClient* client,
MediaStreamImpl* msi,
MediaStreamDependencyFactory* dependency_factory)
- : PeerConnectionHandlerBase(msi, dependency_factory),
- client_(client) {
+ : client_(client),
+ media_stream_impl_(msi),
+ dependency_factory_(dependency_factory),
+ message_loop_proxy_(base::MessageLoopProxy::current()) {
}
PeerConnectionHandler::~PeerConnectionHandler() {
}
+void PeerConnectionHandler::SetVideoRenderer(
+ const std::string& stream_label,
+ webrtc::VideoRendererWrapperInterface* renderer) {
+ webrtc::MediaStreamInterface* stream =
+ native_peer_connection_->remote_streams()->find(stream_label);
+ webrtc::VideoTracks* video_tracks = stream->video_tracks();
+ // We assume there is only one enabled video track.
+ for (size_t i = 0; i < video_tracks->count(); ++i) {
+ webrtc::VideoTrackInterface* video_track = video_tracks->at(i);
+ if (video_track->enabled()) {
+ video_track->SetRenderer(renderer);
+ return;
+ }
+ }
+ DVLOG(1) << "No enabled video track.";
+}
+
void PeerConnectionHandler::initialize(
const WebKit::WebString& server_configuration,
const WebKit::WebString& username) {
@@ -41,8 +60,7 @@ void PeerConnectionHandler::initialize(
void PeerConnectionHandler::produceInitialOffer(
const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>&
pending_add_streams) {
- for (size_t i = 0; i < pending_add_streams.size(); ++i)
- AddStream(pending_add_streams[i]);
+ AddStreams(pending_add_streams);
native_peer_connection_->CommitStreamChanges();
}
@@ -59,10 +77,8 @@ void PeerConnectionHandler::processPendingStreams(
pending_add_streams,
const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>&
pending_remove_streams) {
- for (size_t i = 0; i < pending_add_streams.size(); ++i)
- AddStream(pending_add_streams[i]);
- for (size_t i = 0; i < pending_remove_streams.size(); ++i)
- RemoveStream(pending_remove_streams[i]);
+ AddStreams(pending_add_streams);
+ RemoveStreams(pending_remove_streams);
native_peer_connection_->CommitStreamChanges();
}
@@ -78,7 +94,7 @@ void PeerConnectionHandler::stop() {
// close. We need to investigate further. Not calling Close() on native
// PeerConnection is OK for now.
native_peer_connection_ = NULL;
- media_stream_impl_->ClosePeerConnection(this);
+ media_stream_impl_->ClosePeerConnection();
}
void PeerConnectionHandler::OnError() {
@@ -138,13 +154,54 @@ void PeerConnectionHandler::OnRemoveStream(
void PeerConnectionHandler::OnIceCandidate(
const webrtc::IceCandidateInterface* candidate) {
- // Not used by ROAP PeerConnection.
- NOTREACHED();
+ // TODO(grunell): Implement.
+ NOTIMPLEMENTED();
}
void PeerConnectionHandler::OnIceComplete() {
- // Not used by ROAP PeerConnection.
- NOTREACHED();
+ // TODO(grunell): Implement.
+ NOTIMPLEMENTED();
+}
+
+void PeerConnectionHandler::AddStreams(
+ const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& streams) {
+ for (size_t i = 0; i < streams.size(); ++i) {
+ talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> stream =
+ dependency_factory_->CreateLocalMediaStream(
+ UTF16ToUTF8(streams[i].label()));
+ WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector;
+ streams[i].sources(source_vector);
+
+ // Get and add all tracks.
+ for (size_t j = 0; j < source_vector.size(); ++j) {
+ webrtc::MediaStreamTrackInterface* track =
+ media_stream_impl_->GetLocalMediaStreamTrack(
+ UTF16ToUTF8(source_vector[j].id()));
+ DCHECK(track);
+ if (source_vector[j].type() == WebKit::WebMediaStreamSource::TypeVideo) {
+ stream->AddTrack(static_cast<webrtc::VideoTrackInterface*>(track));
+ } else {
+ stream->AddTrack(static_cast<webrtc::AudioTrackInterface*>(track));
+ }
+ }
+
+ native_peer_connection_->AddStream(stream);
+ }
+}
+
+void PeerConnectionHandler::RemoveStreams(
+ const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& streams) {
+ talk_base::scoped_refptr<webrtc::StreamCollectionInterface> native_streams =
+ native_peer_connection_->local_streams();
+ // TODO(perkj): Change libJingle PeerConnection::RemoveStream API to take a
+ // label as input instead of stream and return bool.
+ for (size_t i = 0; i < streams.size() && native_streams != NULL; ++i) {
+ webrtc::LocalMediaStreamInterface* stream =
+ static_cast<webrtc::LocalMediaStreamInterface*>(native_streams->find(
+ UTF16ToUTF8(streams[i].label())));
+ DCHECK(stream);
+ native_peer_connection_->RemoveStream(stream);
+ }
}
void PeerConnectionHandler::OnAddStreamCallback(
@@ -170,3 +227,40 @@ void PeerConnectionHandler::OnRemoveStreamCallback(
remote_streams_.erase(it);
client_->didRemoveRemoteStream(descriptor);
}
+
+WebKit::WebMediaStreamDescriptor
+PeerConnectionHandler::CreateWebKitStreamDescriptor(
+ webrtc::MediaStreamInterface* stream) {
+ webrtc::AudioTracks* audio_tracks = stream->audio_tracks();
+ webrtc::VideoTracks* video_tracks = stream->video_tracks();
+ WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector(
+ audio_tracks->count() + video_tracks->count());
+
+ // Add audio tracks.
+ size_t i = 0;
+ for (; i < audio_tracks->count(); ++i) {
+ webrtc::AudioTrackInterface* audio_track = audio_tracks->at(i);
+ DCHECK(audio_track);
+ source_vector[i].initialize(
+ // TODO(grunell): Set id to something unique.
+ UTF8ToUTF16(audio_track->label()),
+ WebKit::WebMediaStreamSource::TypeAudio,
+ UTF8ToUTF16(audio_track->label()));
+ }
+
+ // Add video tracks.
+ for (i = 0; i < video_tracks->count(); ++i) {
+ webrtc::VideoTrackInterface* video_track = video_tracks->at(i);
+ DCHECK(video_track);
+ source_vector[audio_tracks->count() + i].initialize(
+ // TODO(grunell): Set id to something unique.
+ UTF8ToUTF16(video_track->label()),
+ WebKit::WebMediaStreamSource::TypeVideo,
+ UTF8ToUTF16(video_track->label()));
+ }
+
+ WebKit::WebMediaStreamDescriptor descriptor;
+ descriptor.initialize(UTF8ToUTF16(stream->label()), source_vector);
+
+ return descriptor;
+}
diff --git a/content/renderer/media/peer_connection_handler.h b/content/renderer/media/peer_connection_handler.h
index e9a50e8..aa969a1 100644
--- a/content/renderer/media/peer_connection_handler.h
+++ b/content/renderer/media/peer_connection_handler.h
@@ -5,21 +5,28 @@
#ifndef CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_H_
#define CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_H_
+#include <map>
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop_proxy.h"
#include "content/common/content_export.h"
-#include "content/renderer/media/peer_connection_handler_base.h"
+#include "third_party/libjingle/source/talk/app/webrtc/mediastream.h"
+#include "third_party/libjingle/source/talk/app/webrtc/peerconnection.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
-// PeerConnectionHandler is a delegate for the ROAP PeerConnection API messages
-// going between WebKit and native PeerConnection in libjingle. It's owned by
-// WebKit. ROAP PeerConnection will be removed soon.
+class MediaStreamDependencyFactory;
+class MediaStreamImpl;
+
+// PeerConnectionHandler is a delegate for the PeerConnection API messages going
+// between WebKit and native PeerConnection in libjingle. It's owned by
+// WebKit.
class CONTENT_EXPORT PeerConnectionHandler
- : public PeerConnectionHandlerBase,
- NON_EXPORTED_BASE(public WebKit::WebPeerConnectionHandler) {
+ : NON_EXPORTED_BASE(public WebKit::WebPeerConnectionHandler),
+ NON_EXPORTED_BASE(public webrtc::PeerConnectionObserver) {
public:
PeerConnectionHandler(
WebKit::WebPeerConnectionHandlerClient* client,
@@ -27,6 +34,11 @@ class CONTENT_EXPORT PeerConnectionHandler
MediaStreamDependencyFactory* dependency_factory);
virtual ~PeerConnectionHandler();
+ // Set the video renderer for the specified stream.
+ virtual void SetVideoRenderer(
+ const std::string& stream_label,
+ webrtc::VideoRendererWrapperInterface* renderer);
+
// WebKit::WebPeerConnectionHandler implementation
virtual void initialize(
const WebKit::WebString& server_configuration,
@@ -59,12 +71,37 @@ class CONTENT_EXPORT PeerConnectionHandler
private:
FRIEND_TEST_ALL_PREFIXES(PeerConnectionHandlerTest, Basic);
+ void AddStreams(
+ const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& streams);
+ void RemoveStreams(
+ const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& streams);
void OnAddStreamCallback(webrtc::MediaStreamInterface* stream);
void OnRemoveStreamCallback(webrtc::MediaStreamInterface* stream);
+ WebKit::WebMediaStreamDescriptor CreateWebKitStreamDescriptor(
+ webrtc::MediaStreamInterface* stream);
// client_ is a weak pointer, and is valid until stop() has returned.
WebKit::WebPeerConnectionHandlerClient* client_;
+ // media_stream_impl_ is a weak pointer, and is valid for the lifetime of this
+ // class. Calls to it must be done on the render thread.
+ MediaStreamImpl* media_stream_impl_;
+
+ // dependency_factory_ is a weak pointer, and is valid for the lifetime of
+ // MediaStreamImpl.
+ MediaStreamDependencyFactory* dependency_factory_;
+
+ // native_peer_connection_ is the native PeerConnection object,
+ // it handles the ICE processing and media engine.
+ talk_base::scoped_refptr<webrtc::PeerConnectionInterface>
+ native_peer_connection_;
+
+ typedef std::map<webrtc::MediaStreamInterface*,
+ WebKit::WebMediaStreamDescriptor> RemoteStreamMap;
+ RemoteStreamMap remote_streams_;
+
+ scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
+
DISALLOW_COPY_AND_ASSIGN(PeerConnectionHandler);
};
diff --git a/content/renderer/media/peer_connection_handler_base.cc b/content/renderer/media/peer_connection_handler_base.cc
deleted file mode 100644
index cf82ffe..0000000
--- a/content/renderer/media/peer_connection_handler_base.cc
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/renderer/media/peer_connection_handler_base.h"
-
-#include "base/logging.h"
-#include "base/utf_string_conversions.h"
-#include "content/renderer/media/media_stream_dependency_factory.h"
-#include "content/renderer/media/media_stream_impl.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamDescriptor.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamSource.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
-
-PeerConnectionHandlerBase::PeerConnectionHandlerBase(
- MediaStreamImpl* msi,
- MediaStreamDependencyFactory* dependency_factory)
- : media_stream_impl_(msi),
- dependency_factory_(dependency_factory),
- message_loop_proxy_(base::MessageLoopProxy::current()) {
-}
-
-PeerConnectionHandlerBase::~PeerConnectionHandlerBase() {
-}
-
-bool PeerConnectionHandlerBase::HasStream(const std::string& stream_label) {
- webrtc::MediaStreamInterface* stream =
- native_peer_connection_->remote_streams()->find(stream_label);
- return stream != NULL;
-}
-
-void PeerConnectionHandlerBase::SetVideoRenderer(
- const std::string& stream_label,
- webrtc::VideoRendererWrapperInterface* renderer) {
- webrtc::MediaStreamInterface* stream =
- native_peer_connection_->remote_streams()->find(stream_label);
- webrtc::VideoTracks* video_tracks = stream->video_tracks();
- // We assume there is only one enabled video track.
- for (size_t i = 0; i < video_tracks->count(); ++i) {
- webrtc::VideoTrackInterface* video_track = video_tracks->at(i);
- if (video_track->enabled()) {
- video_track->SetRenderer(renderer);
- return;
- }
- }
- DVLOG(1) << "No enabled video track.";
-}
-
-void PeerConnectionHandlerBase::AddStream(
- const WebKit::WebMediaStreamDescriptor& stream) {
- talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> native_stream =
- dependency_factory_->CreateLocalMediaStream(UTF16ToUTF8(stream.label()));
- WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector;
- stream.sources(source_vector);
-
- // Get and add all tracks.
- for (size_t i = 0; i < source_vector.size(); ++i) {
- webrtc::MediaStreamTrackInterface* track = media_stream_impl_
- ->GetLocalMediaStreamTrack(UTF16ToUTF8(source_vector[i].id()));
- DCHECK(track);
- if (source_vector[i].type() == WebKit::WebMediaStreamSource::TypeVideo) {
- native_stream->AddTrack(static_cast<webrtc::VideoTrackInterface*>(track));
- } else {
- DCHECK(source_vector[i].type() ==
- WebKit::WebMediaStreamSource::TypeAudio);
- native_stream->AddTrack(static_cast<webrtc::AudioTrackInterface*>(track));
- }
- }
-
- native_peer_connection_->AddStream(native_stream);
-}
-
-void PeerConnectionHandlerBase::RemoveStream(
- const WebKit::WebMediaStreamDescriptor& stream) {
- talk_base::scoped_refptr<webrtc::StreamCollectionInterface> native_streams =
- native_peer_connection_->local_streams();
- if (!native_streams)
- return;
- // TODO(perkj): Change libJingle PeerConnection::RemoveStream API to take a
- // label as input instead of stream and return bool.
- webrtc::LocalMediaStreamInterface* native_stream =
- static_cast<webrtc::LocalMediaStreamInterface*>(native_streams->find(
- UTF16ToUTF8(stream.label())));
- DCHECK(native_stream);
- native_peer_connection_->RemoveStream(native_stream);
-}
-
-WebKit::WebMediaStreamDescriptor
-PeerConnectionHandlerBase::CreateWebKitStreamDescriptor(
- webrtc::MediaStreamInterface* stream) {
- webrtc::AudioTracks* audio_tracks = stream->audio_tracks();
- webrtc::VideoTracks* video_tracks = stream->video_tracks();
- WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector(
- audio_tracks->count() + video_tracks->count());
-
- // Add audio tracks.
- size_t i = 0;
- for (; i < audio_tracks->count(); ++i) {
- webrtc::AudioTrackInterface* audio_track = audio_tracks->at(i);
- DCHECK(audio_track);
- source_vector[i].initialize(
- // TODO(grunell): Set id to something unique.
- UTF8ToUTF16(audio_track->label()),
- WebKit::WebMediaStreamSource::TypeAudio,
- UTF8ToUTF16(audio_track->label()));
- }
-
- // Add video tracks.
- for (i = 0; i < video_tracks->count(); ++i) {
- webrtc::VideoTrackInterface* video_track = video_tracks->at(i);
- DCHECK(video_track);
- source_vector[audio_tracks->count() + i].initialize(
- // TODO(grunell): Set id to something unique.
- UTF8ToUTF16(video_track->label()),
- WebKit::WebMediaStreamSource::TypeVideo,
- UTF8ToUTF16(video_track->label()));
- }
-
- WebKit::WebMediaStreamDescriptor descriptor;
- descriptor.initialize(UTF8ToUTF16(stream->label()), source_vector);
-
- return descriptor;
-}
diff --git a/content/renderer/media/peer_connection_handler_base.h b/content/renderer/media/peer_connection_handler_base.h
deleted file mode 100644
index 4ae027f..0000000
--- a/content/renderer/media/peer_connection_handler_base.h
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_BASE_H_
-#define CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_BASE_H_
-
-#include <map>
-#include <string>
-
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop_proxy.h"
-#include "content/common/content_export.h"
-#include "third_party/libjingle/source/talk/app/webrtc/mediastream.h"
-#include "third_party/libjingle/source/talk/app/webrtc/peerconnection.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamDescriptor.h"
-
-class MediaStreamDependencyFactory;
-class MediaStreamImpl;
-
-// PeerConnectionHandlerBase is the base class of a delegate for the
-// PeerConnection (JSEP or ROAP) API messages going between WebKit and native
-// PeerConnection in libjingle. ROAP PeerConnection will be removed soon.
-class CONTENT_EXPORT PeerConnectionHandlerBase
- : NON_EXPORTED_BASE(public webrtc::PeerConnectionObserver) {
- public:
- PeerConnectionHandlerBase(
- MediaStreamImpl* msi,
- MediaStreamDependencyFactory* dependency_factory);
-
- // Checks if a remote stream belongs to this PeerConnection.
- virtual bool HasStream(const std::string& stream_label);
-
- // Set the video renderer for the specified stream.
- virtual void SetVideoRenderer(
- const std::string& stream_label,
- webrtc::VideoRendererWrapperInterface* renderer);
-
- protected:
- virtual ~PeerConnectionHandlerBase();
-
- void AddStream(const WebKit::WebMediaStreamDescriptor& stream);
- void RemoveStream(const WebKit::WebMediaStreamDescriptor& stream);
- WebKit::WebMediaStreamDescriptor CreateWebKitStreamDescriptor(
- webrtc::MediaStreamInterface* stream);
-
- // media_stream_impl_ is a raw pointer, and is valid for the lifetime of this
- // class. Calls to it must be done on the render thread.
- MediaStreamImpl* media_stream_impl_;
-
- // dependency_factory_ is a raw pointer, and is valid for the lifetime of
- // MediaStreamImpl.
- MediaStreamDependencyFactory* dependency_factory_;
-
- // native_peer_connection_ is the native PeerConnection object,
- // it handles the ICE processing and media engine.
- talk_base::scoped_refptr<webrtc::PeerConnectionInterface>
- native_peer_connection_;
-
- typedef std::map<webrtc::MediaStreamInterface*,
- WebKit::WebMediaStreamDescriptor> RemoteStreamMap;
- RemoteStreamMap remote_streams_;
-
- // The message loop we are created on and on which to make calls to WebKit.
- // This should be the render thread message loop.
- scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
-
- DISALLOW_COPY_AND_ASSIGN(PeerConnectionHandlerBase);
-};
-
-#endif // CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_BASE_H_
diff --git a/content/renderer/media/peer_connection_handler_jsep.cc b/content/renderer/media/peer_connection_handler_jsep.cc
deleted file mode 100644
index b524abe..0000000
--- a/content/renderer/media/peer_connection_handler_jsep.cc
+++ /dev/null
@@ -1,368 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/renderer/media/peer_connection_handler_jsep.h"
-
-#include <utility>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/string_number_conversions.h"
-#include "base/utf_string_conversions.h"
-#include "content/renderer/media/media_stream_dependency_factory.h"
-#include "content/renderer/media/media_stream_impl.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebICECandidateDescriptor.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebICEOptions.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00HandlerClient.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaHints.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamDescriptor.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamSource.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSessionDescriptionDescriptor.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
-
-PeerConnectionHandlerJsep::PeerConnectionHandlerJsep(
- WebKit::WebPeerConnection00HandlerClient* client,
- MediaStreamImpl* msi,
- MediaStreamDependencyFactory* dependency_factory)
- : PeerConnectionHandlerBase(msi, dependency_factory),
- client_(client) {
-}
-
-PeerConnectionHandlerJsep::~PeerConnectionHandlerJsep() {
-}
-
-void PeerConnectionHandlerJsep::initialize(
- const WebKit::WebString& server_configuration,
- const WebKit::WebString& username) {
- native_peer_connection_ = dependency_factory_->CreatePeerConnection(
- UTF16ToUTF8(server_configuration),
- this);
- CHECK(native_peer_connection_);
-}
-
-WebKit::WebSessionDescriptionDescriptor PeerConnectionHandlerJsep::createOffer(
- const WebKit::WebMediaHints& hints) {
- WebKit::WebSessionDescriptionDescriptor offer;
-
- webrtc::MediaHints native_hints(hints.audio(), hints.video());
- scoped_ptr<webrtc::SessionDescriptionInterface> native_offer(
- native_peer_connection_->CreateOffer(native_hints));
- if (!native_offer.get()) {
- LOG(ERROR) << "Failed to create native offer";
- return offer;
- }
-
- offer = CreateWebKitSessionDescription(native_offer.get());
- return offer;
-}
-
-WebKit::WebSessionDescriptionDescriptor PeerConnectionHandlerJsep::createAnswer(
- const WebKit::WebString& offer,
- const WebKit::WebMediaHints& hints) {
- WebKit::WebSessionDescriptionDescriptor answer;
-
- webrtc::MediaHints native_hints(hints.audio(), hints.video());
- scoped_ptr<webrtc::SessionDescriptionInterface> native_offer(
- dependency_factory_->CreateSessionDescription(UTF16ToUTF8(offer)));
- if (!native_offer.get()) {
- LOG(ERROR) << "Failed to create native offer";
- return answer;
- }
-
- scoped_ptr<webrtc::SessionDescriptionInterface> native_answer(
- native_peer_connection_->CreateAnswer(native_hints, native_offer.get()));
- if (!native_answer.get()) {
- LOG(ERROR) << "Failed to create native answer";
- return answer;
- }
-
- answer = CreateWebKitSessionDescription(native_answer.get());
- return answer;
-}
-
-bool PeerConnectionHandlerJsep::setLocalDescription(
- Action action,
- const WebKit::WebSessionDescriptionDescriptor& description) {
- webrtc::PeerConnectionInterface::Action native_action;
- if (!GetNativeAction(action, &native_action))
- return false;
-
- webrtc::SessionDescriptionInterface* native_desc =
- CreateNativeSessionDescription(description);
- if (!native_desc)
- return false;
-
- return native_peer_connection_->SetLocalDescription(native_action,
- native_desc);
-}
-
-bool PeerConnectionHandlerJsep::setRemoteDescription(
- Action action,
- const WebKit::WebSessionDescriptionDescriptor& description) {
- webrtc::PeerConnectionInterface::Action native_action;
- if (!GetNativeAction(action, &native_action))
- return false;
-
- webrtc::SessionDescriptionInterface* native_desc =
- CreateNativeSessionDescription(description);
- if (!native_desc)
- return false;
-
- return native_peer_connection_->SetRemoteDescription(native_action,
- native_desc);
-}
-
-WebKit::WebSessionDescriptionDescriptor
-PeerConnectionHandlerJsep::localDescription() {
- const webrtc::SessionDescriptionInterface* native_desc =
- native_peer_connection_->local_description();
- WebKit::WebSessionDescriptionDescriptor description =
- CreateWebKitSessionDescription(native_desc);
- return description;
-}
-
-WebKit::WebSessionDescriptionDescriptor
-PeerConnectionHandlerJsep::remoteDescription() {
- const webrtc::SessionDescriptionInterface* native_desc =
- native_peer_connection_->remote_description();
- WebKit::WebSessionDescriptionDescriptor description =
- CreateWebKitSessionDescription(native_desc);
- return description;
-}
-
-bool PeerConnectionHandlerJsep::startIce(const WebKit::WebICEOptions& options) {
- webrtc::PeerConnectionInterface::IceOptions native_options;
- switch (options.candidateTypeToUse()) {
- case WebKit::WebICEOptions::CandidateTypeAll:
- native_options = webrtc::PeerConnectionInterface::kUseAll;
- break;
- case WebKit::WebICEOptions::CandidateTypeNoRelay:
- native_options = webrtc::PeerConnectionInterface::kNoRelay;
- break;
- case WebKit::WebICEOptions::CandidateTypeOnlyRelay:
- native_options = webrtc::PeerConnectionInterface::kOnlyRelay;
- break;
- default:
- NOTREACHED();
- return false;
- }
- native_peer_connection_->StartIce(native_options);
- return true;
-}
-
-bool PeerConnectionHandlerJsep::processIceMessage(
- const WebKit::WebICECandidateDescriptor& candidate) {
- scoped_ptr<webrtc::IceCandidateInterface> native_candidate(
- dependency_factory_->CreateIceCandidate(
- UTF16ToUTF8(candidate.label()),
- UTF16ToUTF8(candidate.candidateLine())));
- if (!native_candidate.get()) {
- LOG(ERROR) << "Could not create native ICE candidate";
- return false;
- }
-
- bool return_value =
- native_peer_connection_->ProcessIceMessage(native_candidate.get());
- if (!return_value)
- LOG(ERROR) << "Error processing ICE message";
- return return_value;
-}
-
-void PeerConnectionHandlerJsep::addStream(
- const WebKit::WebMediaStreamDescriptor& stream) {
- AddStream(stream);
- native_peer_connection_->CommitStreamChanges();
-}
-
-void PeerConnectionHandlerJsep::removeStream(
- const WebKit::WebMediaStreamDescriptor& stream) {
- RemoveStream(stream);
- native_peer_connection_->CommitStreamChanges();
-}
-
-void PeerConnectionHandlerJsep::stop() {
- // TODO(ronghuawu): There's an issue with signaling messages being sent during
- // close. We need to investigate further. Not calling Close() on native
- // PeerConnection is OK for now.
- native_peer_connection_ = NULL;
- media_stream_impl_->ClosePeerConnection(this);
-}
-
-void PeerConnectionHandlerJsep::OnError() {
- // TODO(grunell): Implement.
- NOTIMPLEMENTED();
-}
-
-void PeerConnectionHandlerJsep::OnMessage(const std::string& msg) {
- // TODO(grunell): Implement.
- NOTIMPLEMENTED();
-}
-
-void PeerConnectionHandlerJsep::OnSignalingMessage(const std::string& msg) {
- // Not used by JSEP PeerConnection.
- NOTREACHED();
-}
-
-void PeerConnectionHandlerJsep::OnStateChange(StateType state_changed) {
- switch (state_changed) {
- case kReadyState:
- WebKit::WebPeerConnection00HandlerClient::ReadyState ready_state;
- switch (native_peer_connection_->ready_state()) {
- case webrtc::PeerConnectionInterface::kNew:
- ready_state = WebKit::WebPeerConnection00HandlerClient::ReadyStateNew;
- break;
- case webrtc::PeerConnectionInterface::kNegotiating:
- ready_state =
- WebKit::WebPeerConnection00HandlerClient::ReadyStateNegotiating;
- break;
- case webrtc::PeerConnectionInterface::kActive:
- ready_state =
- WebKit::WebPeerConnection00HandlerClient::ReadyStateActive;
- break;
- case webrtc::PeerConnectionInterface::kClosing:
- // Not used by JSEP.
- NOTREACHED();
- return;
- case webrtc::PeerConnectionInterface::kClosed:
- ready_state =
- WebKit::WebPeerConnection00HandlerClient::ReadyStateClosed;
- break;
- default:
- NOTREACHED();
- return;
- }
- client_->didChangeReadyState(ready_state);
- break;
- case kIceState:
- // TODO(grunell): Implement when available in native PeerConnection.
- NOTIMPLEMENTED();
- break;
- case kSdpState:
- // Not used by JSEP.
- NOTREACHED();
- break;
- default:
- NOTREACHED();
- break;
- }
-}
-
-void PeerConnectionHandlerJsep::OnAddStream(
- webrtc::MediaStreamInterface* stream) {
- if (!stream)
- return;
-
- DCHECK(remote_streams_.find(stream) == remote_streams_.end());
- WebKit::WebMediaStreamDescriptor descriptor =
- CreateWebKitStreamDescriptor(stream);
- remote_streams_.insert(
- std::pair<webrtc::MediaStreamInterface*,
- WebKit::WebMediaStreamDescriptor>(stream, descriptor));
- client_->didAddRemoteStream(descriptor);
-}
-
-void PeerConnectionHandlerJsep::OnRemoveStream(
- webrtc::MediaStreamInterface* stream) {
- if (!stream)
- return;
-
- RemoteStreamMap::iterator it = remote_streams_.find(stream);
- if (it == remote_streams_.end()) {
- NOTREACHED() << "Stream not found";
- return;
- }
- WebKit::WebMediaStreamDescriptor descriptor = it->second;
- DCHECK(!descriptor.isNull());
- remote_streams_.erase(it);
- client_->didRemoveRemoteStream(descriptor);
-}
-
-void PeerConnectionHandlerJsep::OnIceCandidate(
- const webrtc::IceCandidateInterface* candidate) {
- WebKit::WebICECandidateDescriptor web_candidate;
-
- std::string label = candidate->label();
- std::string sdp;
- if (!candidate->ToString(&sdp)) {
- LOG(ERROR) << "Could not get SDP string";
- return;
- }
-
- web_candidate.initialize(UTF8ToUTF16(label), UTF8ToUTF16(sdp));
-
- // moreToFollow parameter isn't supported in native PeerConnection, so we
- // always use true here, and then false in OnIceComplete().
- client_->didGenerateICECandidate(web_candidate, true);
-}
-
-void PeerConnectionHandlerJsep::OnIceComplete() {
- // moreToFollow parameter isn't supported in native PeerConnection, so we
- // send an empty WebIseCandidate with moreToFollow=false.
- WebKit::WebICECandidateDescriptor web_candidate;
- client_->didGenerateICECandidate(web_candidate, false);
-}
-
-webrtc::SessionDescriptionInterface*
-PeerConnectionHandlerJsep::CreateNativeSessionDescription(
- const WebKit::WebSessionDescriptionDescriptor& description) {
- std::string initial_sdp = UTF16ToUTF8(description.initialSDP());
- webrtc::SessionDescriptionInterface* native_desc =
- dependency_factory_->CreateSessionDescription(initial_sdp);
- if (!native_desc) {
- LOG(ERROR) << "Failed to create native session description";
- return NULL;
- }
-
- for (size_t i = 0; i < description.numberOfAddedCandidates(); ++i) {
- WebKit::WebICECandidateDescriptor candidate = description.candidate(i);
- scoped_ptr<webrtc::IceCandidateInterface> native_candidate(
- dependency_factory_->CreateIceCandidate(
- UTF16ToUTF8(candidate.label()),
- UTF16ToUTF8(candidate.candidateLine())));
- if (!native_desc->AddCandidate(native_candidate.get()))
- LOG(ERROR) << "Failed to add candidate to native session description";
- }
-
- return native_desc;
-}
-
-WebKit::WebSessionDescriptionDescriptor
-PeerConnectionHandlerJsep::CreateWebKitSessionDescription(
- const webrtc::SessionDescriptionInterface* native_desc) {
- WebKit::WebSessionDescriptionDescriptor description;
- if (!native_desc) {
- VLOG(1) << "Native session description is null";
- return description;
- }
-
- std::string sdp;
- if (!native_desc->ToString(&sdp)) {
- LOG(ERROR) << "Failed to get SDP string of native session description";
- return description;
- }
-
- description.initialize(UTF8ToUTF16(sdp));
- return description;
-}
-
-bool PeerConnectionHandlerJsep::GetNativeAction(
- const Action action,
- webrtc::PeerConnectionInterface::Action* native_action) {
- switch (action) {
- case ActionSDPOffer:
- *native_action = webrtc::PeerConnectionInterface::kOffer;
- break;
- case ActionSDPPRanswer:
- VLOG(1) << "Action PRANSWER not supported yet";
- return false;
- case ActionSDPAnswer:
- *native_action = webrtc::PeerConnectionInterface::kAnswer;
- break;
- default:
- NOTREACHED();
- return false;
- }
- return true;
-}
diff --git a/content/renderer/media/peer_connection_handler_jsep.h b/content/renderer/media/peer_connection_handler_jsep.h
deleted file mode 100644
index 463b05e..0000000
--- a/content/renderer/media/peer_connection_handler_jsep.h
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_JSEP_H_
-#define CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_JSEP_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/gtest_prod_util.h"
-#include "content/common/content_export.h"
-#include "content/renderer/media/peer_connection_handler_base.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
-
-// PeerConnectionHandlerJsep is a delegate for the JSEP PeerConnection API
-// messages going between WebKit and native PeerConnection in libjingle. It's
-// owned by WebKit.
-class CONTENT_EXPORT PeerConnectionHandlerJsep
- : public PeerConnectionHandlerBase,
- NON_EXPORTED_BASE(public WebKit::WebPeerConnection00Handler) {
- public:
- PeerConnectionHandlerJsep(
- WebKit::WebPeerConnection00HandlerClient* client,
- MediaStreamImpl* msi,
- MediaStreamDependencyFactory* dependency_factory);
- virtual ~PeerConnectionHandlerJsep();
-
- // WebKit::WebPeerConnection00Handler implementation
- virtual void initialize(
- const WebKit::WebString& server_configuration,
- const WebKit::WebString& username) OVERRIDE;
- virtual WebKit::WebSessionDescriptionDescriptor createOffer(
- const WebKit::WebMediaHints& hints) OVERRIDE;
- virtual WebKit::WebSessionDescriptionDescriptor createAnswer(
- const WebKit::WebString& offer,
- const WebKit::WebMediaHints& hints) OVERRIDE;
- virtual bool setLocalDescription(
- Action action,
- const WebKit::WebSessionDescriptionDescriptor& description) OVERRIDE;
- virtual bool setRemoteDescription(
- Action action,
- const WebKit::WebSessionDescriptionDescriptor& description) OVERRIDE;
- virtual WebKit::WebSessionDescriptionDescriptor localDescription() OVERRIDE;
- virtual WebKit::WebSessionDescriptionDescriptor remoteDescription() OVERRIDE;
- virtual bool startIce(const WebKit::WebICEOptions& options) OVERRIDE;
- virtual bool processIceMessage(
- const WebKit::WebICECandidateDescriptor& candidate) OVERRIDE;
- virtual void addStream(
- const WebKit::WebMediaStreamDescriptor& stream) OVERRIDE;
- virtual void removeStream(
- const WebKit::WebMediaStreamDescriptor& stream) OVERRIDE;
- // We will be deleted by WebKit after stop has been returned.
- virtual void stop() OVERRIDE;
-
- // webrtc::PeerConnectionObserver implementation
- virtual void OnError() OVERRIDE;
- virtual void OnMessage(const std::string& msg) OVERRIDE;
- virtual void OnSignalingMessage(const std::string& msg) OVERRIDE;
- virtual void OnStateChange(StateType state_changed) OVERRIDE;
- virtual void OnAddStream(webrtc::MediaStreamInterface* stream) OVERRIDE;
- virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream) OVERRIDE;
- virtual void OnIceCandidate(
- const webrtc::IceCandidateInterface* candidate) OVERRIDE;
- virtual void OnIceComplete() OVERRIDE;
-
- private:
- FRIEND_TEST_ALL_PREFIXES(PeerConnectionHandlerJsepTest, Basic);
-
- webrtc::SessionDescriptionInterface* CreateNativeSessionDescription(
- const WebKit::WebSessionDescriptionDescriptor& description);
- WebKit::WebSessionDescriptionDescriptor CreateWebKitSessionDescription(
- const webrtc::SessionDescriptionInterface* native_desc);
- bool GetNativeAction(
- const Action action,
- webrtc::PeerConnectionInterface::Action* native_action);
-
- // client_ is a weak pointer, and is valid until stop() has returned.
- WebKit::WebPeerConnection00HandlerClient* client_;
-
- DISALLOW_COPY_AND_ASSIGN(PeerConnectionHandlerJsep);
-};
-
-#endif // CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_JSEP_H_
diff --git a/content/renderer/media/peer_connection_handler_jsep_unittest.cc b/content/renderer/media/peer_connection_handler_jsep_unittest.cc
deleted file mode 100644
index 03f3eb6..0000000
--- a/content/renderer/media/peer_connection_handler_jsep_unittest.cc
+++ /dev/null
@@ -1,231 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <string>
-
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop.h"
-#include "base/utf_string_conversions.h"
-#include "content/renderer/media/mock_media_stream_dependency_factory.h"
-#include "content/renderer/media/mock_media_stream_impl.h"
-#include "content/renderer/media/mock_web_peer_connection_00_handler_client.h"
-#include "content/renderer/media/mock_peer_connection_impl.h"
-#include "content/renderer/media/peer_connection_handler_jsep.h"
-#include "content/renderer/media/rtc_video_decoder.h"
-#include "jingle/glue/thread_wrapper.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/libjingle/source/talk/app/webrtc/peerconnection.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebICECandidateDescriptor.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebICEOptions.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaHints.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamDescriptor.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStreamSource.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSessionDescriptionDescriptor.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
-
-namespace webrtc {
-
-class MockVideoRendererWrapper : public VideoRendererWrapperInterface {
- public:
- virtual cricket::VideoRenderer* renderer() OVERRIDE { return NULL; }
-
- protected:
- virtual ~MockVideoRendererWrapper() {}
-};
-
-} // namespace webrtc
-
-TEST(PeerConnectionHandlerJsepTest, Basic) {
- MessageLoop loop;
-
- scoped_ptr<WebKit::MockWebPeerConnection00HandlerClient> mock_client(
- new WebKit::MockWebPeerConnection00HandlerClient());
- scoped_refptr<MockMediaStreamImpl> mock_ms_impl(new MockMediaStreamImpl());
- scoped_ptr<MockMediaStreamDependencyFactory> mock_dependency_factory(
- new MockMediaStreamDependencyFactory());
- mock_dependency_factory->CreatePeerConnectionFactory(NULL,
- NULL,
- NULL,
- NULL,
- NULL);
- scoped_ptr<PeerConnectionHandlerJsep> pc_handler(
- new PeerConnectionHandlerJsep(mock_client.get(),
- mock_ms_impl.get(),
- mock_dependency_factory.get()));
-
- WebKit::WebString server_config(
- WebKit::WebString::fromUTF8("STUN stun.l.google.com:19302"));
- WebKit::WebString username;
- pc_handler->initialize(server_config, username);
- EXPECT_TRUE(pc_handler->native_peer_connection_.get());
- webrtc::MockPeerConnectionImpl* mock_peer_connection =
- static_cast<webrtc::MockPeerConnectionImpl*>(
- pc_handler->native_peer_connection_.get());
-
- // Create offer.
- WebKit::WebMediaHints hints;
- hints.initialize(true, true);
- WebKit::WebSessionDescriptionDescriptor offer =
- pc_handler->createOffer(hints);
- EXPECT_FALSE(offer.isNull());
- EXPECT_EQ(std::string(mock_peer_connection->kDummyOffer),
- UTF16ToUTF8(offer.initialSDP()));
- EXPECT_EQ(hints.audio(), mock_peer_connection->hint_audio());
- EXPECT_EQ(hints.video(), mock_peer_connection->hint_video());
-
- // Create answer.
- WebKit::WebString offer_string = "offer";
- hints.reset();
- hints.initialize(false, false);
- WebKit::WebSessionDescriptionDescriptor answer =
- pc_handler->createAnswer(offer_string, hints);
- EXPECT_FALSE(answer.isNull());
- EXPECT_EQ(UTF16ToUTF8(offer_string), UTF16ToUTF8(answer.initialSDP()));
- EXPECT_EQ(UTF16ToUTF8(offer_string), mock_peer_connection->description_sdp());
- EXPECT_EQ(hints.audio(), mock_peer_connection->hint_audio());
- EXPECT_EQ(hints.video(), mock_peer_connection->hint_video());
-
- // Set local description.
- PeerConnectionHandlerJsep::Action action =
- PeerConnectionHandlerJsep::ActionSDPOffer;
- WebKit::WebSessionDescriptionDescriptor description;
- WebKit::WebString sdp = "test sdp";
- description.initialize(sdp);
- EXPECT_TRUE(pc_handler->setLocalDescription(action, description));
- EXPECT_EQ(webrtc::PeerConnectionInterface::kOffer,
- mock_peer_connection->action());
- EXPECT_EQ(UTF16ToUTF8(sdp), mock_peer_connection->description_sdp());
-
- // Get local description.
- description.reset();
- description = pc_handler->localDescription();
- EXPECT_FALSE(description.isNull());
- EXPECT_EQ(UTF16ToUTF8(sdp), UTF16ToUTF8(description.initialSDP()));
-
- // Set remote description.
- action = PeerConnectionHandlerJsep::ActionSDPAnswer;
- sdp = "test sdp 2";
- description.reset();
- description.initialize(sdp);
- EXPECT_TRUE(pc_handler->setRemoteDescription(action, description));
- EXPECT_EQ(webrtc::PeerConnectionInterface::kAnswer,
- mock_peer_connection->action());
- EXPECT_EQ(UTF16ToUTF8(sdp), mock_peer_connection->description_sdp());
-
- // Get remote description.
- description.reset();
- description = pc_handler->remoteDescription();
- EXPECT_FALSE(description.isNull());
- EXPECT_EQ(UTF16ToUTF8(sdp), UTF16ToUTF8(description.initialSDP()));
-
- // Start ICE.
- WebKit::WebICEOptions options;
- options.initialize(WebKit::WebICEOptions::CandidateTypeAll);
- EXPECT_TRUE(pc_handler->startIce(options));
- EXPECT_EQ(webrtc::PeerConnectionInterface::kUseAll,
- mock_peer_connection->ice_options());
-
- // Process ICE message.
- WebKit::WebICECandidateDescriptor candidate;
- WebKit::WebString label = "test label";
- sdp = "test sdp";
- candidate.initialize(label, sdp);
- EXPECT_TRUE(pc_handler->processIceMessage(candidate));
- EXPECT_EQ(UTF16ToUTF8(label), mock_peer_connection->ice_label());
- EXPECT_EQ(UTF16ToUTF8(sdp), mock_peer_connection->ice_sdp());
-
- // Add stream.
- // TODO(grunell): Add an audio track as well.
- std::string stream_label("stream-label");
- std::string video_track_label("video-label");
- talk_base::scoped_refptr<webrtc::LocalVideoTrackInterface> local_video_track(
- mock_dependency_factory->CreateLocalVideoTrack(video_track_label, NULL));
- mock_ms_impl->AddTrack(video_track_label, local_video_track);
- WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector(
- static_cast<size_t>(1));
- source_vector[0].initialize(WebKit::WebString::fromUTF8(video_track_label),
- WebKit::WebMediaStreamSource::TypeVideo,
- WebKit::WebString::fromUTF8("RemoteVideo"));
- WebKit::WebMediaStreamDescriptor local_stream;
- local_stream.initialize(UTF8ToUTF16(stream_label), source_vector);
- pc_handler->addStream(local_stream);
- EXPECT_EQ(stream_label, mock_peer_connection->stream_label());
- EXPECT_TRUE(mock_peer_connection->stream_changes_committed());
-
- // On add stream.
- std::string remote_stream_label(stream_label);
- remote_stream_label += "-remote";
- std::string remote_video_track_label(video_track_label);
- remote_video_track_label += "-remote";
- // We use a local stream as a remote since for testing purposes we really
- // only need the MediaStreamInterface.
- talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> remote_stream(
- mock_dependency_factory->CreateLocalMediaStream(remote_stream_label));
- talk_base::scoped_refptr<webrtc::LocalVideoTrackInterface> remote_video_track(
- mock_dependency_factory->CreateLocalVideoTrack(remote_video_track_label,
- NULL));
- remote_video_track->set_enabled(true);
- remote_stream->AddTrack(remote_video_track);
- mock_peer_connection->AddRemoteStream(remote_stream);
- pc_handler->OnAddStream(remote_stream);
- EXPECT_EQ(remote_stream_label, mock_client->stream_label());
-
- // Set renderer.
- talk_base::scoped_refptr<webrtc::MockVideoRendererWrapper> renderer(
- new talk_base::RefCountedObject<webrtc::MockVideoRendererWrapper>());
- pc_handler->SetVideoRenderer(remote_stream_label, renderer);
- EXPECT_EQ(renderer, static_cast<webrtc::MockLocalVideoTrack*>(
- remote_video_track.get())->renderer());
-
- // Remove stream.
- WebKit::WebVector<WebKit::WebMediaStreamDescriptor> empty_streams(
- static_cast<size_t>(0));
- pc_handler->removeStream(local_stream);
- EXPECT_EQ("", mock_peer_connection->stream_label());
- mock_peer_connection->ClearStreamChangesCommitted();
- EXPECT_TRUE(!mock_peer_connection->stream_changes_committed());
-
- // On remove stream.
- pc_handler->OnRemoveStream(remote_stream);
- EXPECT_TRUE(mock_client->stream_label().empty());
-
- // Add stream again.
- pc_handler->addStream(local_stream);
- EXPECT_EQ(stream_label, mock_peer_connection->stream_label());
- EXPECT_TRUE(mock_peer_connection->stream_changes_committed());
-
- // On state change.
- mock_peer_connection->SetReadyState(webrtc::PeerConnectionInterface::kActive);
- webrtc::PeerConnectionObserver::StateType state =
- webrtc::PeerConnectionObserver::kReadyState;
- pc_handler->OnStateChange(state);
- EXPECT_EQ(WebKit::WebPeerConnection00HandlerClient::ReadyStateActive,
- mock_client->ready_state());
-
- // On ICE candidate.
- std::string candidate_label = "test label";
- std::string candidate_sdp = "test sdp";
- webrtc::IceCandidateInterface* native_candidate =
- mock_dependency_factory->CreateIceCandidate(candidate_label,
- candidate_sdp);
- pc_handler->OnIceCandidate(native_candidate);
- EXPECT_EQ(candidate_label, mock_client->candidate_label());
- EXPECT_EQ(candidate_sdp, mock_client->candidate_sdp());
- EXPECT_TRUE(mock_client->more_to_follow());
-
- // On ICE complete.
- pc_handler->OnIceComplete();
- EXPECT_TRUE(mock_client->candidate_label().empty());
- EXPECT_TRUE(mock_client->candidate_sdp().empty());
- EXPECT_FALSE(mock_client->more_to_follow());
-
- // Stop.
- pc_handler->stop();
- EXPECT_FALSE(pc_handler->native_peer_connection_.get());
-
- // PC handler is expected to be deleted when stop calls
- // MediaStreamImpl::ClosePeerConnection. We own and delete it here instead of
- // in the mock.
- pc_handler.reset();
-}