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

Unified Diff: talk/app/webrtc/peerconnection.h

Issue 1393563002: Moving MediaStreamSignaling logic into PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing copyright header Created 5 years, 2 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 | « talk/app/webrtc/mediastreamsignaling_unittest.cc ('k') | talk/app/webrtc/peerconnection.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: talk/app/webrtc/peerconnection.h
diff --git a/talk/app/webrtc/peerconnection.h b/talk/app/webrtc/peerconnection.h
index 3d6ce1ba6d94911c5ba95be793d25a39561150fc..0c048988e13d5de30feb4dcaf593d9386f1937e7 100644
--- a/talk/app/webrtc/peerconnection.h
+++ b/talk/app/webrtc/peerconnection.h
@@ -31,7 +31,6 @@
#include <string>
#include "talk/app/webrtc/dtlsidentitystore.h"
-#include "talk/app/webrtc/mediastreamsignaling.h"
#include "talk/app/webrtc/peerconnectionfactory.h"
#include "talk/app/webrtc/peerconnectioninterface.h"
#include "talk/app/webrtc/rtpreceiverinterface.h"
@@ -43,11 +42,26 @@
namespace webrtc {
+class RemoteMediaStreamFactory;
+
typedef std::vector<PortAllocatorFactoryInterface::StunConfiguration>
StunConfigurations;
typedef std::vector<PortAllocatorFactoryInterface::TurnConfiguration>
TurnConfigurations;
+// Populates |session_options| from |rtc_options|, and returns true if options
+// are valid.
+// Send streams should already be added to |session_options| before this method
+// is called, as this affects the values of recv_audio and recv_video.
+bool ConvertRtcOptionsForOffer(
+ const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
+ cricket::MediaSessionOptions* session_options);
+
+// Populates |session_options| from |constraints|, and returns true if all
+// mandatory constraints are satisfied.
+bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints,
+ cricket::MediaSessionOptions* session_options);
+
// Parses the URLs for each server in |servers| to build |stun_config| and
// |turn_config|.
bool ParseIceServers(const PeerConnectionInterface::IceServers& servers,
@@ -55,10 +69,8 @@ bool ParseIceServers(const PeerConnectionInterface::IceServers& servers,
TurnConfigurations* turn_config);
// PeerConnection implements the PeerConnectionInterface interface.
-// It uses MediaStreamSignaling and WebRtcSession to implement
-// the PeerConnection functionality.
+// It uses WebRtcSession to implement the PeerConnection functionality.
class PeerConnection : public PeerConnectionInterface,
- public MediaStreamSignalingObserver,
public IceObserver,
public rtc::MessageHandler,
public sigslot::has_slots<> {
@@ -76,6 +88,8 @@ class PeerConnection : public PeerConnectionInterface,
bool AddStream(MediaStreamInterface* local_stream) override;
void RemoveStream(MediaStreamInterface* local_stream) override;
+ virtual WebRtcSession* session() { return session_.get(); }
+
rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
AudioTrackInterface* track) override;
@@ -120,39 +134,72 @@ class PeerConnection : public PeerConnectionInterface,
void Close() override;
+ // Virtual for unit tests.
+ virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
+ sctp_data_channels() const {
+ return sctp_data_channels_;
+ };
+
protected:
~PeerConnection() override;
private:
+ struct TrackInfo {
+ TrackInfo() : ssrc(0) {}
+ TrackInfo(const std::string& stream_label,
+ const std::string track_id,
+ uint32_t ssrc)
+ : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {}
+ std::string stream_label;
+ std::string track_id;
+ uint32_t ssrc;
+ };
+ typedef std::vector<TrackInfo> TrackInfos;
+
+ struct RemotePeerInfo {
+ RemotePeerInfo()
+ : msid_supported(false),
+ default_audio_track_needed(false),
+ default_video_track_needed(false) {}
+ // True if it has been discovered that the remote peer support MSID.
+ bool msid_supported;
+ // The remote peer indicates in the session description that audio will be
+ // sent but no MSID is given.
+ bool default_audio_track_needed;
+ // The remote peer indicates in the session description that video will be
+ // sent but no MSID is given.
+ bool default_video_track_needed;
+
+ bool IsDefaultMediaStreamNeeded() {
+ return !msid_supported &&
+ (default_audio_track_needed || default_video_track_needed);
+ }
+ };
+
// Implements MessageHandler.
void OnMessage(rtc::Message* msg) override;
- // Implements MediaStreamSignalingObserver.
- void OnAddRemoteStream(MediaStreamInterface* stream) override;
- void OnRemoveRemoteStream(MediaStreamInterface* stream) override;
- void OnAddDataChannel(DataChannelInterface* data_channel) override;
- void OnAddRemoteAudioTrack(MediaStreamInterface* stream,
- AudioTrackInterface* audio_track,
- uint32_t ssrc) override;
- void OnAddRemoteVideoTrack(MediaStreamInterface* stream,
- VideoTrackInterface* video_track,
- uint32_t ssrc) override;
- void OnRemoveRemoteAudioTrack(MediaStreamInterface* stream,
- AudioTrackInterface* audio_track) override;
- void OnRemoveRemoteVideoTrack(MediaStreamInterface* stream,
- VideoTrackInterface* video_track) override;
- void OnAddLocalAudioTrack(MediaStreamInterface* stream,
- AudioTrackInterface* audio_track,
- uint32_t ssrc) override;
- void OnAddLocalVideoTrack(MediaStreamInterface* stream,
- VideoTrackInterface* video_track,
- uint32_t ssrc) override;
- void OnRemoveLocalAudioTrack(MediaStreamInterface* stream,
- AudioTrackInterface* audio_track,
- uint32_t ssrc) override;
- void OnRemoveLocalVideoTrack(MediaStreamInterface* stream,
- VideoTrackInterface* video_track) override;
- void OnRemoveLocalStream(MediaStreamInterface* stream) override;
+ void CreateAudioReceiver(MediaStreamInterface* stream,
+ AudioTrackInterface* audio_track,
+ uint32_t ssrc);
+ void CreateVideoReceiver(MediaStreamInterface* stream,
+ VideoTrackInterface* video_track,
+ uint32_t ssrc);
+ void DestroyAudioReceiver(MediaStreamInterface* stream,
+ AudioTrackInterface* audio_track);
+ void DestroyVideoReceiver(MediaStreamInterface* stream,
+ VideoTrackInterface* video_track);
+ void CreateAudioSender(MediaStreamInterface* stream,
+ AudioTrackInterface* audio_track,
+ uint32_t ssrc);
+ void CreateVideoSender(MediaStreamInterface* stream,
+ VideoTrackInterface* video_track,
+ uint32_t ssrc);
+ void DestroyAudioSender(MediaStreamInterface* stream,
+ AudioTrackInterface* audio_track,
+ uint32_t ssrc);
+ void DestroyVideoSender(MediaStreamInterface* stream,
+ VideoTrackInterface* video_track);
// Implements IceObserver
void OnIceConnectionChange(IceConnectionState new_state) override;
@@ -172,21 +219,138 @@ class PeerConnection : public PeerConnectionInterface,
void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer,
const std::string& error);
+ void PostCreateSessionDescriptionFailure(
+ CreateSessionDescriptionObserver* observer,
+ const std::string& error);
bool IsClosed() const {
return signaling_state_ == PeerConnectionInterface::kClosed;
}
+ // Returns a MediaSessionOptions struct with options decided by |options|,
+ // the local MediaStreams and DataChannels.
+ virtual bool GetOptionsForOffer(
+ const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
+ cricket::MediaSessionOptions* session_options);
+
+ // Returns a MediaSessionOptions struct with options decided by
+ // |constraints|, the local MediaStreams and DataChannels.
+ virtual bool GetOptionsForAnswer(
+ const MediaConstraintsInterface* constraints,
+ cricket::MediaSessionOptions* session_options);
+
+ // Makes sure a MediaStream Track is created for each StreamParam in
+ // |streams|. |media_type| is the type of the |streams| and can be either
+ // audio or video.
+ // If a new MediaStream is created it is added to |new_streams|.
+ void UpdateRemoteStreamsList(
+ const std::vector<cricket::StreamParams>& streams,
+ cricket::MediaType media_type,
+ StreamCollection* new_streams);
+
+ // Triggered when a remote track has been seen for the first time in a remote
+ // session description. It creates a remote MediaStreamTrackInterface
+ // implementation and triggers CreateAudioReceiver or CreateVideoReceiver.
+ void OnRemoteTrackSeen(const std::string& stream_label,
+ const std::string& track_id,
+ uint32_t ssrc,
+ cricket::MediaType media_type);
+
+ // Triggered when a remote track has been removed from a remote session
+ // description. It removes the remote track with id |track_id| from a remote
+ // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver.
+ void OnRemoteTrackRemoved(const std::string& stream_label,
+ const std::string& track_id,
+ cricket::MediaType media_type);
+
+ // Finds remote MediaStreams without any tracks and removes them from
+ // |remote_streams_| and notifies the observer that the MediaStreams no longer
+ // exist.
+ void UpdateEndedRemoteMediaStreams();
+
+ void MaybeCreateDefaultStream();
+
+ // Set the MediaStreamTrackInterface::TrackState to |kEnded| on all remote
+ // tracks of type |media_type|.
+ void EndRemoteTracks(cricket::MediaType media_type);
+
+ // Loops through the vector of |streams| and finds added and removed
+ // StreamParams since last time this method was called.
+ // For each new or removed StreamParam, OnLocalTrackSeen or
+ // OnLocalTrackRemoved is invoked.
+ void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams,
+ cricket::MediaType media_type);
+
+ // Triggered when a local track has been seen for the first time in a local
+ // session description.
+ // This method triggers CreateAudioSender or CreateVideoSender if the rtp
+ // streams in the local SessionDescription can be mapped to a MediaStreamTrack
+ // in a MediaStream in |local_streams_|
+ void OnLocalTrackSeen(const std::string& stream_label,
+ const std::string& track_id,
+ uint32_t ssrc,
+ cricket::MediaType media_type);
+
+ // Triggered when a local track has been removed from a local session
+ // description.
+ // This method triggers DestroyAudioSender or DestroyVideoSender if a stream
+ // has been removed from the local SessionDescription and the stream can be
+ // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|.
+ void OnLocalTrackRemoved(const std::string& stream_label,
+ const std::string& track_id,
+ uint32_t ssrc,
+ cricket::MediaType media_type);
+
+ void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams);
+ void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams);
+ void UpdateClosingRtpDataChannels(
+ const std::vector<std::string>& active_channels,
+ bool is_local_update);
+ void CreateRemoteRtpDataChannel(const std::string& label,
+ uint32_t remote_ssrc);
+
+ // Creates channel and adds it to the collection of DataChannels that will
+ // be offered in a SessionDescription.
+ rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
+ const std::string& label,
+ const InternalDataChannelInit* config);
+
+ // Checks if any data channel has been added.
+ bool HasDataChannels() const;
+
+ void AllocateSctpSids(rtc::SSLRole role);
+ void OnSctpDataChannelClosed(DataChannel* channel);
+
+ // Notifications from WebRtcSession relating to BaseChannels.
+ void OnVoiceChannelDestroyed();
+ void OnVideoChannelDestroyed();
+ void OnDataChannelCreated();
+ void OnDataChannelDestroyed();
+ // Called when the cricket::DataChannel receives a message indicating that a
+ // webrtc::DataChannel should be opened.
+ void OnDataChannelOpenMessage(const std::string& label,
+ const InternalDataChannelInit& config);
+
std::vector<rtc::scoped_refptr<RtpSenderInterface>>::iterator
FindSenderForTrack(MediaStreamTrackInterface* track);
std::vector<rtc::scoped_refptr<RtpReceiverInterface>>::iterator
FindReceiverForTrack(MediaStreamTrackInterface* track);
+ TrackInfos* GetRemoteTracks(cricket::MediaType media_type);
+ TrackInfos* GetLocalTracks(cricket::MediaType media_type);
+ const TrackInfo* FindTrackInfo(const TrackInfos& infos,
+ const std::string& stream_label,
+ const std::string track_id) const;
+
+ // Returns the specified SCTP DataChannel in sctp_data_channels_,
+ // or nullptr if not found.
+ DataChannel* FindDataChannelBySid(int sid) const;
+
// Storing the factory as a scoped reference pointer ensures that the memory
// in the PeerConnectionFactoryImpl remains available as long as the
// PeerConnection is running. It is passed to PeerConnection as a raw pointer.
// However, since the reference counting is done in the
- // PeerConnectionFactoryInteface all instances created using the raw pointer
+ // PeerConnectionFactoryInterface all instances created using the raw pointer
// will refer to the same reference count.
rtc::scoped_refptr<PeerConnectionFactory> factory_;
PeerConnectionObserver* observer_;
@@ -198,12 +362,35 @@ class PeerConnection : public PeerConnectionInterface,
IceGatheringState ice_gathering_state_;
rtc::scoped_ptr<cricket::PortAllocator> port_allocator_;
- rtc::scoped_ptr<WebRtcSession> session_;
- rtc::scoped_ptr<MediaStreamSignaling> mediastream_signaling_;
- rtc::scoped_ptr<StatsCollector> stats_;
+
+ // Streams added via AddStream.
+ rtc::scoped_refptr<StreamCollection> local_streams_;
+ // Streams created as a result of SetRemoteDescription.
+ rtc::scoped_refptr<StreamCollection> remote_streams_;
+
+ // These lists store track info seen in local/remote descriptions.
+ TrackInfos remote_audio_tracks_;
+ TrackInfos remote_video_tracks_;
+ TrackInfos local_audio_tracks_;
+ TrackInfos local_video_tracks_;
+
+ SctpSidAllocator sid_allocator_;
+ // label -> DataChannel
+ std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;
+ std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
+
+ RemotePeerInfo remote_info_;
+ rtc::scoped_ptr<RemoteMediaStreamFactory> remote_stream_factory_;
std::vector<rtc::scoped_refptr<RtpSenderInterface>> senders_;
std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers_;
+
+ // The session_ scoped_ptr is declared at the bottom of PeerConnection
+ // because its destruction fires signals (such as VoiceChannelDestroyed)
+ // which will trigger some final actions in PeerConnection...
+ rtc::scoped_ptr<WebRtcSession> session_;
+ // ... But stats_ depends on session_ so it should be destroyed even earlier.
+ rtc::scoped_ptr<StatsCollector> stats_;
};
} // namespace webrtc
« no previous file with comments | « talk/app/webrtc/mediastreamsignaling_unittest.cc ('k') | talk/app/webrtc/peerconnection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698