2017-09-26 16:20:19 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef PC_PEERCONNECTIONWRAPPER_H_
|
|
|
|
|
#define PC_PEERCONNECTIONWRAPPER_H_
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
2017-10-30 09:57:42 -07:00
|
|
|
#include <vector>
|
2017-09-26 16:20:19 -07:00
|
|
|
|
|
|
|
|
#include "api/peerconnectioninterface.h"
|
|
|
|
|
#include "pc/test/mockpeerconnectionobservers.h"
|
2017-11-13 11:50:33 +01:00
|
|
|
#include "rtc_base/function_view.h"
|
2017-09-26 16:20:19 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// Class that wraps a PeerConnection so that it is easier to use in unit tests.
|
|
|
|
|
// Namely, gives a synchronous API for the event-callback-based API of
|
|
|
|
|
// PeerConnection and provides an observer object that stores information from
|
|
|
|
|
// PeerConnectionObserver callbacks.
|
|
|
|
|
//
|
|
|
|
|
// This is intended to be subclassed if additional information needs to be
|
|
|
|
|
// stored with the PeerConnection (e.g., fake PeerConnection parameters so that
|
|
|
|
|
// tests can be written against those interactions). The base
|
|
|
|
|
// PeerConnectionWrapper should only have helper methods that are broadly
|
|
|
|
|
// useful. More specific helper methods should be created in the test-specific
|
|
|
|
|
// subclass.
|
|
|
|
|
//
|
|
|
|
|
// The wrapper is intended to be constructed by specialized factory methods on
|
|
|
|
|
// a test fixture class then used as a local variable in each test case.
|
|
|
|
|
class PeerConnectionWrapper {
|
|
|
|
|
public:
|
|
|
|
|
// Constructs a PeerConnectionWrapper from the given PeerConnection.
|
|
|
|
|
// The given PeerConnectionFactory should be the factory that created the
|
|
|
|
|
// PeerConnection and the MockPeerConnectionObserver should be the observer
|
|
|
|
|
// that is watching the PeerConnection.
|
|
|
|
|
PeerConnectionWrapper(
|
|
|
|
|
rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory,
|
|
|
|
|
rtc::scoped_refptr<PeerConnectionInterface> pc,
|
|
|
|
|
std::unique_ptr<MockPeerConnectionObserver> observer);
|
|
|
|
|
virtual ~PeerConnectionWrapper();
|
|
|
|
|
|
|
|
|
|
PeerConnectionFactoryInterface* pc_factory();
|
|
|
|
|
PeerConnectionInterface* pc();
|
|
|
|
|
MockPeerConnectionObserver* observer();
|
|
|
|
|
|
|
|
|
|
// Calls the underlying PeerConnection's CreateOffer method and returns the
|
|
|
|
|
// resulting SessionDescription once it is available. If the method call
|
|
|
|
|
// failed, null is returned.
|
|
|
|
|
std::unique_ptr<SessionDescriptionInterface> CreateOffer(
|
2017-10-20 15:30:51 -07:00
|
|
|
const PeerConnectionInterface::RTCOfferAnswerOptions& options,
|
|
|
|
|
std::string* error_out = nullptr);
|
2017-09-26 16:20:19 -07:00
|
|
|
// Calls CreateOffer with default options.
|
|
|
|
|
std::unique_ptr<SessionDescriptionInterface> CreateOffer();
|
|
|
|
|
// Calls CreateOffer and sets a copy of the offer as the local description.
|
2017-10-20 15:30:51 -07:00
|
|
|
std::unique_ptr<SessionDescriptionInterface> CreateOfferAndSetAsLocal(
|
|
|
|
|
const PeerConnectionInterface::RTCOfferAnswerOptions& options);
|
|
|
|
|
// Calls CreateOfferAndSetAsLocal with default options.
|
2017-09-26 16:20:19 -07:00
|
|
|
std::unique_ptr<SessionDescriptionInterface> CreateOfferAndSetAsLocal();
|
|
|
|
|
|
|
|
|
|
// Calls the underlying PeerConnection's CreateAnswer method and returns the
|
|
|
|
|
// resulting SessionDescription once it is available. If the method call
|
|
|
|
|
// failed, null is returned.
|
|
|
|
|
std::unique_ptr<SessionDescriptionInterface> CreateAnswer(
|
2017-10-20 15:30:51 -07:00
|
|
|
const PeerConnectionInterface::RTCOfferAnswerOptions& options,
|
|
|
|
|
std::string* error_out = nullptr);
|
2017-09-26 16:20:19 -07:00
|
|
|
// Calls CreateAnswer with the default options.
|
|
|
|
|
std::unique_ptr<SessionDescriptionInterface> CreateAnswer();
|
|
|
|
|
// Calls CreateAnswer and sets a copy of the offer as the local description.
|
2017-10-20 15:30:51 -07:00
|
|
|
std::unique_ptr<SessionDescriptionInterface> CreateAnswerAndSetAsLocal(
|
|
|
|
|
const PeerConnectionInterface::RTCOfferAnswerOptions& options);
|
|
|
|
|
// Calls CreateAnswerAndSetAsLocal with default options.
|
2017-09-26 16:20:19 -07:00
|
|
|
std::unique_ptr<SessionDescriptionInterface> CreateAnswerAndSetAsLocal();
|
|
|
|
|
|
|
|
|
|
// Calls the underlying PeerConnection's SetLocalDescription method with the
|
|
|
|
|
// given session description and waits for the success/failure response.
|
|
|
|
|
// Returns true if the description was successfully set.
|
2017-10-20 15:30:51 -07:00
|
|
|
bool SetLocalDescription(std::unique_ptr<SessionDescriptionInterface> desc,
|
|
|
|
|
std::string* error_out = nullptr);
|
2017-09-26 16:20:19 -07:00
|
|
|
// Calls the underlying PeerConnection's SetRemoteDescription method with the
|
|
|
|
|
// given session description and waits for the success/failure response.
|
|
|
|
|
// Returns true if the description was successfully set.
|
2017-10-20 15:30:51 -07:00
|
|
|
bool SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc,
|
|
|
|
|
std::string* error_out = nullptr);
|
Reland "SetRemoteDescriptionObserverInterface added."
Description for changes from the original CL:
Calling legacy SRD, implemented using
SetRemoteDescriptionObserverAdapter wrapping the old observer, was
meant to have the exact same behavior as the legacy SRD implementation
which invokes the callbacks in a Post.
However, in the CL that landed and got reverted (PS1), the Adapter had
its own message handler, and callbacks would be invoked even if the PC
was destroyed.
In PS2 I've changed the Adapter to use the PeerConnection's message
handler. If the PC is destroyed, the callback will not be invoked.
This gives identical behavior to before this CL, and the legacy
behavior is covered by a new unittest.
I changed the adapter to be an implementation detail of
peerconnection.cc, therefor some stuff was moved, and the only tests
covering this is now in peerconnection_rtp_unittest.cc.
This is a reland of 6c7ec32bd63ab2b45d4d83ae1de817ee946b4d72
Original change's description:
> SetRemoteDescriptionObserverInterface added.
>
> The new observer replaced SetSessionDescriptionObserver for
> SetRemoteDescription. Unlike SetSessionDescriptionObserver,
> SetRemoteDescriptionObserverInterface is invoked synchronously so
> that the you can rely on the state of the PeerConnection to represent
> the result of the SetRemoteDescription call in the callback.
>
> The new observer succeeds or fails with an RTCError.
>
> This deprecates the need for PeerConnectionObserver::OnAdd/RemoveTrack
> and SetSessionDescriptionObserver, with the benefit that all media
> object changes can be processed in a single callback by the application
> in a synchronous callback. This will help Chromium keep objects in-sync
> across layers and threads in a non-racy and straight-forward way, see
> design doc (Proposal 2):
> https://docs.google.com/a/google.com/document/d/1-cDDC82mgU5zrHacfFz720p3xwRtuBkOPSRchh07Ho0/edit?usp=sharing
>
> An adapter for SetSessionDescriptionObserver is added to allow calling
> the old SetRemoteDescription signature and get the old behavior
> (OnSuccess/OnFailure callback in a Post) until third parties switch.
>
> Bug: webrtc:8473
> Change-Id: I3d4eb60da6dd34615f2c9f384aeaf4634e648c99
> Reviewed-on: https://webrtc-review.googlesource.com/17523
> Commit-Queue: Henrik Boström <hbos@webrtc.org>
> Reviewed-by: Peter Thatcher <pthatcher@webrtc.org>
> Reviewed-by: Guido Urdaneta <guidou@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#20841}
TBR=pthatcher@webrtc.org
Bug: webrtc:8473
Change-Id: If2b1a1929663b0e77fcc9c2ebeef043e6f73adf5
Reviewed-on: https://webrtc-review.googlesource.com/25640
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Guido Urdaneta <guidou@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20854}
2017-11-23 17:48:32 +01:00
|
|
|
bool SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc,
|
|
|
|
|
RTCError* error_out);
|
2017-10-20 15:30:51 -07:00
|
|
|
|
|
|
|
|
// Calls the underlying PeerConnection's AddTrack method with an audio media
|
|
|
|
|
// stream track not bound to any source.
|
|
|
|
|
rtc::scoped_refptr<RtpSenderInterface> AddAudioTrack(
|
|
|
|
|
const std::string& track_label,
|
|
|
|
|
std::vector<MediaStreamInterface*> streams = {});
|
|
|
|
|
|
|
|
|
|
// Calls the underlying PeerConnection's AddTrack method with a video media
|
|
|
|
|
// stream track fed by a fake video capturer.
|
|
|
|
|
rtc::scoped_refptr<RtpSenderInterface> AddVideoTrack(
|
|
|
|
|
const std::string& track_label,
|
|
|
|
|
std::vector<MediaStreamInterface*> streams = {});
|
|
|
|
|
|
|
|
|
|
// Returns the signaling state of the underlying PeerConnection.
|
|
|
|
|
PeerConnectionInterface::SignalingState signaling_state();
|
2017-09-26 16:20:19 -07:00
|
|
|
|
2017-10-13 11:13:35 -07:00
|
|
|
// Returns true if ICE has finished gathering candidates.
|
|
|
|
|
bool IsIceGatheringDone();
|
|
|
|
|
|
2017-10-23 09:39:20 -07:00
|
|
|
// Returns true if ICE has established a connection.
|
|
|
|
|
bool IsIceConnected();
|
|
|
|
|
|
|
|
|
|
// Calls GetStats() on the underlying PeerConnection and returns the resulting
|
|
|
|
|
// report. If GetStats() fails, this method returns null and fails the test.
|
|
|
|
|
rtc::scoped_refptr<const RTCStatsReport> GetStats();
|
|
|
|
|
|
2017-09-26 16:20:19 -07:00
|
|
|
private:
|
|
|
|
|
std::unique_ptr<SessionDescriptionInterface> CreateSdp(
|
2017-11-13 11:50:33 +01:00
|
|
|
rtc::FunctionView<void(CreateSessionDescriptionObserver*)> fn,
|
2017-10-20 15:30:51 -07:00
|
|
|
std::string* error_out);
|
2017-11-13 11:50:33 +01:00
|
|
|
bool SetSdp(rtc::FunctionView<void(SetSessionDescriptionObserver*)> fn,
|
2017-10-20 15:30:51 -07:00
|
|
|
std::string* error_out);
|
2017-09-26 16:20:19 -07:00
|
|
|
|
|
|
|
|
rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_;
|
2017-10-20 09:42:08 +00:00
|
|
|
std::unique_ptr<MockPeerConnectionObserver> observer_;
|
2017-10-20 15:30:51 -07:00
|
|
|
rtc::scoped_refptr<PeerConnectionInterface> pc_;
|
2017-09-26 16:20:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // PC_PEERCONNECTIONWRAPPER_H_
|