| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 protected: | 151 protected: |
| 152 ~PeerConnection() override; | 152 ~PeerConnection() override; |
| 153 | 153 |
| 154 private: | 154 private: |
| 155 struct TrackInfo { | 155 struct TrackInfo { |
| 156 TrackInfo() : ssrc(0) {} | 156 TrackInfo() : ssrc(0) {} |
| 157 TrackInfo(const std::string& stream_label, | 157 TrackInfo(const std::string& stream_label, |
| 158 const std::string track_id, | 158 const std::string track_id, |
| 159 uint32_t ssrc) | 159 uint32_t ssrc) |
| 160 : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {} | 160 : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {} |
| 161 bool operator==(const TrackInfo& other) { |
| 162 return this->stream_label == other.stream_label && |
| 163 this->track_id == other.track_id && this->ssrc == other.ssrc; |
| 164 } |
| 161 std::string stream_label; | 165 std::string stream_label; |
| 162 std::string track_id; | 166 std::string track_id; |
| 163 uint32_t ssrc; | 167 uint32_t ssrc; |
| 164 }; | 168 }; |
| 165 typedef std::vector<TrackInfo> TrackInfos; | 169 typedef std::vector<TrackInfo> TrackInfos; |
| 166 | 170 |
| 167 struct RemotePeerInfo { | |
| 168 RemotePeerInfo() | |
| 169 : msid_supported(false), | |
| 170 default_audio_track_needed(false), | |
| 171 default_video_track_needed(false) {} | |
| 172 // True if it has been discovered that the remote peer support MSID. | |
| 173 bool msid_supported; | |
| 174 // The remote peer indicates in the session description that audio will be | |
| 175 // sent but no MSID is given. | |
| 176 bool default_audio_track_needed; | |
| 177 // The remote peer indicates in the session description that video will be | |
| 178 // sent but no MSID is given. | |
| 179 bool default_video_track_needed; | |
| 180 | |
| 181 bool IsDefaultMediaStreamNeeded() { | |
| 182 return !msid_supported && | |
| 183 (default_audio_track_needed || default_video_track_needed); | |
| 184 } | |
| 185 }; | |
| 186 | |
| 187 // Implements MessageHandler. | 171 // Implements MessageHandler. |
| 188 void OnMessage(rtc::Message* msg) override; | 172 void OnMessage(rtc::Message* msg) override; |
| 189 | 173 |
| 190 void CreateAudioReceiver(MediaStreamInterface* stream, | 174 void CreateAudioReceiver(MediaStreamInterface* stream, |
| 191 AudioTrackInterface* audio_track, | 175 AudioTrackInterface* audio_track, |
| 192 uint32_t ssrc); | 176 uint32_t ssrc); |
| 193 void CreateVideoReceiver(MediaStreamInterface* stream, | 177 void CreateVideoReceiver(MediaStreamInterface* stream, |
| 194 VideoTrackInterface* video_track, | 178 VideoTrackInterface* video_track, |
| 195 uint32_t ssrc); | 179 uint32_t ssrc); |
| 196 void DestroyAudioReceiver(MediaStreamInterface* stream, | 180 void DestroyAudioReceiver(MediaStreamInterface* stream, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // Returns a MediaSessionOptions struct with options decided by | 227 // Returns a MediaSessionOptions struct with options decided by |
| 244 // |constraints|, the local MediaStreams and DataChannels. | 228 // |constraints|, the local MediaStreams and DataChannels. |
| 245 virtual bool GetOptionsForAnswer( | 229 virtual bool GetOptionsForAnswer( |
| 246 const MediaConstraintsInterface* constraints, | 230 const MediaConstraintsInterface* constraints, |
| 247 cricket::MediaSessionOptions* session_options); | 231 cricket::MediaSessionOptions* session_options); |
| 248 | 232 |
| 249 // Remove all local and remote tracks of type |media_type|. | 233 // Remove all local and remote tracks of type |media_type|. |
| 250 // Called when a media type is rejected (m-line set to port 0). | 234 // Called when a media type is rejected (m-line set to port 0). |
| 251 void RemoveTracks(cricket::MediaType media_type); | 235 void RemoveTracks(cricket::MediaType media_type); |
| 252 | 236 |
| 253 // Makes sure a MediaStream Track is created for each StreamParam in | 237 // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|, |
| 254 // |streams|. |media_type| is the type of the |streams| and can be either | 238 // and existing MediaStreamTracks are removed if there is no corresponding |
| 255 // audio or video. | 239 // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack |
| 240 // is created if it doesn't exist; if false, it's removed if it exists. |
| 241 // |media_type| is the type of the |streams| and can be either audio or video. |
| 256 // If a new MediaStream is created it is added to |new_streams|. | 242 // If a new MediaStream is created it is added to |new_streams|. |
| 257 void UpdateRemoteStreamsList( | 243 void UpdateRemoteStreamsList( |
| 258 const std::vector<cricket::StreamParams>& streams, | 244 const std::vector<cricket::StreamParams>& streams, |
| 245 bool default_track_needed, |
| 259 cricket::MediaType media_type, | 246 cricket::MediaType media_type, |
| 260 StreamCollection* new_streams); | 247 StreamCollection* new_streams); |
| 261 | 248 |
| 262 // Triggered when a remote track has been seen for the first time in a remote | 249 // Triggered when a remote track has been seen for the first time in a remote |
| 263 // session description. It creates a remote MediaStreamTrackInterface | 250 // session description. It creates a remote MediaStreamTrackInterface |
| 264 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. | 251 // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. |
| 265 void OnRemoteTrackSeen(const std::string& stream_label, | 252 void OnRemoteTrackSeen(const std::string& stream_label, |
| 266 const std::string& track_id, | 253 const std::string& track_id, |
| 267 uint32_t ssrc, | 254 uint32_t ssrc, |
| 268 cricket::MediaType media_type); | 255 cricket::MediaType media_type); |
| 269 | 256 |
| 270 // Triggered when a remote track has been removed from a remote session | 257 // Triggered when a remote track has been removed from a remote session |
| 271 // description. It removes the remote track with id |track_id| from a remote | 258 // description. It removes the remote track with id |track_id| from a remote |
| 272 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. | 259 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. |
| 273 void OnRemoteTrackRemoved(const std::string& stream_label, | 260 void OnRemoteTrackRemoved(const std::string& stream_label, |
| 274 const std::string& track_id, | 261 const std::string& track_id, |
| 275 cricket::MediaType media_type); | 262 cricket::MediaType media_type); |
| 276 | 263 |
| 277 // Finds remote MediaStreams without any tracks and removes them from | 264 // Finds remote MediaStreams without any tracks and removes them from |
| 278 // |remote_streams_| and notifies the observer that the MediaStreams no longer | 265 // |remote_streams_| and notifies the observer that the MediaStreams no longer |
| 279 // exist. | 266 // exist. |
| 280 void UpdateEndedRemoteMediaStreams(); | 267 void UpdateEndedRemoteMediaStreams(); |
| 281 | 268 |
| 282 void MaybeCreateDefaultStream(); | |
| 283 | |
| 284 // Set the MediaStreamTrackInterface::TrackState to |kEnded| on all remote | 269 // Set the MediaStreamTrackInterface::TrackState to |kEnded| on all remote |
| 285 // tracks of type |media_type|. | 270 // tracks of type |media_type|. |
| 286 void EndRemoteTracks(cricket::MediaType media_type); | 271 void EndRemoteTracks(cricket::MediaType media_type); |
| 287 | 272 |
| 288 // Loops through the vector of |streams| and finds added and removed | 273 // Loops through the vector of |streams| and finds added and removed |
| 289 // StreamParams since last time this method was called. | 274 // StreamParams since last time this method was called. |
| 290 // For each new or removed StreamParam, OnLocalTrackSeen or | 275 // For each new or removed StreamParam, OnLocalTrackSeen or |
| 291 // OnLocalTrackRemoved is invoked. | 276 // OnLocalTrackRemoved is invoked. |
| 292 void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams, | 277 void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams, |
| 293 cricket::MediaType media_type); | 278 cricket::MediaType media_type); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 TrackInfos remote_audio_tracks_; | 369 TrackInfos remote_audio_tracks_; |
| 385 TrackInfos remote_video_tracks_; | 370 TrackInfos remote_video_tracks_; |
| 386 TrackInfos local_audio_tracks_; | 371 TrackInfos local_audio_tracks_; |
| 387 TrackInfos local_video_tracks_; | 372 TrackInfos local_video_tracks_; |
| 388 | 373 |
| 389 SctpSidAllocator sid_allocator_; | 374 SctpSidAllocator sid_allocator_; |
| 390 // label -> DataChannel | 375 // label -> DataChannel |
| 391 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_; | 376 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_; |
| 392 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_; | 377 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_; |
| 393 | 378 |
| 394 RemotePeerInfo remote_info_; | 379 bool remote_peer_supports_msid_ = false; |
| 395 rtc::scoped_ptr<RemoteMediaStreamFactory> remote_stream_factory_; | 380 rtc::scoped_ptr<RemoteMediaStreamFactory> remote_stream_factory_; |
| 396 | 381 |
| 397 std::vector<rtc::scoped_refptr<RtpSenderInterface>> senders_; | 382 std::vector<rtc::scoped_refptr<RtpSenderInterface>> senders_; |
| 398 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers_; | 383 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers_; |
| 399 | 384 |
| 400 // The session_ scoped_ptr is declared at the bottom of PeerConnection | 385 // The session_ scoped_ptr is declared at the bottom of PeerConnection |
| 401 // because its destruction fires signals (such as VoiceChannelDestroyed) | 386 // because its destruction fires signals (such as VoiceChannelDestroyed) |
| 402 // which will trigger some final actions in PeerConnection... | 387 // which will trigger some final actions in PeerConnection... |
| 403 rtc::scoped_ptr<WebRtcSession> session_; | 388 rtc::scoped_ptr<WebRtcSession> session_; |
| 404 // ... But stats_ depends on session_ so it should be destroyed even earlier. | 389 // ... But stats_ depends on session_ so it should be destroyed even earlier. |
| 405 rtc::scoped_ptr<StatsCollector> stats_; | 390 rtc::scoped_ptr<StatsCollector> stats_; |
| 406 }; | 391 }; |
| 407 | 392 |
| 408 } // namespace webrtc | 393 } // namespace webrtc |
| 409 | 394 |
| 410 #endif // TALK_APP_WEBRTC_PEERCONNECTION_H_ | 395 #endif // TALK_APP_WEBRTC_PEERCONNECTION_H_ |
| OLD | NEW |