2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* 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.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// This file contains mock implementations of observers used in PeerConnection.
|
2017-09-26 16:20:19 -07:00
|
|
|
// TODO(steveanton): These aren't really mocks and should be renamed.
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#ifndef PC_TEST_MOCK_PEER_CONNECTION_OBSERVERS_H_
|
|
|
|
|
#define PC_TEST_MOCK_PEER_CONNECTION_OBSERVERS_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2018-01-10 17:15:20 -08:00
|
|
|
#include <map>
|
2016-04-27 06:47:29 -07:00
|
|
|
#include <memory>
|
2013-07-10 00:45:36 +00:00
|
|
|
#include <string>
|
2017-10-30 09:57:42 -07:00
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "api/data_channel_interface.h"
|
|
|
|
|
#include "api/jsep_ice_candidate.h"
|
|
|
|
|
#include "pc/stream_collection.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2017-09-26 16:20:19 -07:00
|
|
|
class MockPeerConnectionObserver : public PeerConnectionObserver {
|
|
|
|
|
public:
|
Reland "Added PeerConnectionObserver::OnRemoveTrack."
This reverts commit 6c0c55c31817ecfa32409424495eb68b31828c40.
Reason for revert:
Fixed the flake.
Original change's description:
> Revert "Added PeerConnectionObserver::OnRemoveTrack."
>
> This reverts commit ba97ba7af917d4152f5f3363aba1c1561c6673dc.
>
> Reason for revert: The new tests have caused several test failures on the test bots; the method FakeAudioMediaStreamTrack:GetSignalLevel, which is not supposed to be called is sometimes called anyway.
>
> Original change's description:
> > Added PeerConnectionObserver::OnRemoveTrack.
> >
> > This corresponds to processing the removal of a remote track step of
> > the spec, with processing the addition of a remote track already
> > covered by OnAddTrack.
> > https://w3c.github.io/webrtc-pc/#processing-remote-mediastreamtracks
> >
> > Bug: webrtc:8260, webrtc:8315
> > Change-Id: Ica8be92369733eb3cf1397fb60385d45a9b58700
> > Reviewed-on: https://webrtc-review.googlesource.com/4722
> > Commit-Queue: Henrik Boström <hbos@webrtc.org>
> > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> > Reviewed-by: Steve Anton <steveanton@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#20214}
>
> TBR=steveanton@webrtc.org,deadbeef@webrtc.org,hbos@webrtc.org
>
> Change-Id: Id2d9533e27227254769b4280a8ff10a47313e714
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:8260, webrtc:8315
> Reviewed-on: https://webrtc-review.googlesource.com/7940
> Reviewed-by: Alex Loiko <aleloi@webrtc.org>
> Commit-Queue: Alex Loiko <aleloi@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#20218}
TBR=steveanton@webrtc.org,deadbeef@webrtc.org,aleloi@webrtc.org,hbos@webrtc.org
Change-Id: Iab7500bebf98535754b102874259de43831fff6b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8260, webrtc:8315
Reviewed-on: https://webrtc-review.googlesource.com/8180
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20227}
2017-10-10 10:05:16 -07:00
|
|
|
struct AddTrackEvent {
|
|
|
|
|
explicit AddTrackEvent(
|
2018-01-10 17:15:20 -08:00
|
|
|
rtc::scoped_refptr<RtpReceiverInterface> event_receiver,
|
|
|
|
|
std::vector<rtc::scoped_refptr<MediaStreamInterface>> event_streams)
|
|
|
|
|
: receiver(std::move(event_receiver)),
|
|
|
|
|
streams(std::move(event_streams)) {
|
|
|
|
|
for (auto stream : streams) {
|
|
|
|
|
std::vector<rtc::scoped_refptr<MediaStreamTrackInterface>> tracks;
|
|
|
|
|
for (auto audio_track : stream->GetAudioTracks()) {
|
|
|
|
|
tracks.push_back(audio_track);
|
|
|
|
|
}
|
|
|
|
|
for (auto video_track : stream->GetVideoTracks()) {
|
|
|
|
|
tracks.push_back(video_track);
|
|
|
|
|
}
|
|
|
|
|
snapshotted_stream_tracks[stream] = tracks;
|
|
|
|
|
}
|
|
|
|
|
}
|
Reland "Added PeerConnectionObserver::OnRemoveTrack."
This reverts commit 6c0c55c31817ecfa32409424495eb68b31828c40.
Reason for revert:
Fixed the flake.
Original change's description:
> Revert "Added PeerConnectionObserver::OnRemoveTrack."
>
> This reverts commit ba97ba7af917d4152f5f3363aba1c1561c6673dc.
>
> Reason for revert: The new tests have caused several test failures on the test bots; the method FakeAudioMediaStreamTrack:GetSignalLevel, which is not supposed to be called is sometimes called anyway.
>
> Original change's description:
> > Added PeerConnectionObserver::OnRemoveTrack.
> >
> > This corresponds to processing the removal of a remote track step of
> > the spec, with processing the addition of a remote track already
> > covered by OnAddTrack.
> > https://w3c.github.io/webrtc-pc/#processing-remote-mediastreamtracks
> >
> > Bug: webrtc:8260, webrtc:8315
> > Change-Id: Ica8be92369733eb3cf1397fb60385d45a9b58700
> > Reviewed-on: https://webrtc-review.googlesource.com/4722
> > Commit-Queue: Henrik Boström <hbos@webrtc.org>
> > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> > Reviewed-by: Steve Anton <steveanton@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#20214}
>
> TBR=steveanton@webrtc.org,deadbeef@webrtc.org,hbos@webrtc.org
>
> Change-Id: Id2d9533e27227254769b4280a8ff10a47313e714
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:8260, webrtc:8315
> Reviewed-on: https://webrtc-review.googlesource.com/7940
> Reviewed-by: Alex Loiko <aleloi@webrtc.org>
> Commit-Queue: Alex Loiko <aleloi@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#20218}
TBR=steveanton@webrtc.org,deadbeef@webrtc.org,aleloi@webrtc.org,hbos@webrtc.org
Change-Id: Iab7500bebf98535754b102874259de43831fff6b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8260, webrtc:8315
Reviewed-on: https://webrtc-review.googlesource.com/8180
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20227}
2017-10-10 10:05:16 -07:00
|
|
|
|
|
|
|
|
rtc::scoped_refptr<RtpReceiverInterface> receiver;
|
|
|
|
|
std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams;
|
2018-01-10 17:15:20 -08:00
|
|
|
// This map records the tracks present in each stream at the time the
|
|
|
|
|
// OnAddTrack callback was issued.
|
|
|
|
|
std::map<rtc::scoped_refptr<MediaStreamInterface>,
|
|
|
|
|
std::vector<rtc::scoped_refptr<MediaStreamTrackInterface>>>
|
|
|
|
|
snapshotted_stream_tracks;
|
Reland "Added PeerConnectionObserver::OnRemoveTrack."
This reverts commit 6c0c55c31817ecfa32409424495eb68b31828c40.
Reason for revert:
Fixed the flake.
Original change's description:
> Revert "Added PeerConnectionObserver::OnRemoveTrack."
>
> This reverts commit ba97ba7af917d4152f5f3363aba1c1561c6673dc.
>
> Reason for revert: The new tests have caused several test failures on the test bots; the method FakeAudioMediaStreamTrack:GetSignalLevel, which is not supposed to be called is sometimes called anyway.
>
> Original change's description:
> > Added PeerConnectionObserver::OnRemoveTrack.
> >
> > This corresponds to processing the removal of a remote track step of
> > the spec, with processing the addition of a remote track already
> > covered by OnAddTrack.
> > https://w3c.github.io/webrtc-pc/#processing-remote-mediastreamtracks
> >
> > Bug: webrtc:8260, webrtc:8315
> > Change-Id: Ica8be92369733eb3cf1397fb60385d45a9b58700
> > Reviewed-on: https://webrtc-review.googlesource.com/4722
> > Commit-Queue: Henrik Boström <hbos@webrtc.org>
> > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> > Reviewed-by: Steve Anton <steveanton@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#20214}
>
> TBR=steveanton@webrtc.org,deadbeef@webrtc.org,hbos@webrtc.org
>
> Change-Id: Id2d9533e27227254769b4280a8ff10a47313e714
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:8260, webrtc:8315
> Reviewed-on: https://webrtc-review.googlesource.com/7940
> Reviewed-by: Alex Loiko <aleloi@webrtc.org>
> Commit-Queue: Alex Loiko <aleloi@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#20218}
TBR=steveanton@webrtc.org,deadbeef@webrtc.org,aleloi@webrtc.org,hbos@webrtc.org
Change-Id: Iab7500bebf98535754b102874259de43831fff6b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8260, webrtc:8315
Reviewed-on: https://webrtc-review.googlesource.com/8180
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20227}
2017-10-10 10:05:16 -07:00
|
|
|
};
|
|
|
|
|
|
2017-09-26 16:20:19 -07:00
|
|
|
MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {}
|
|
|
|
|
virtual ~MockPeerConnectionObserver() {}
|
|
|
|
|
void SetPeerConnectionInterface(PeerConnectionInterface* pc) {
|
|
|
|
|
pc_ = pc;
|
|
|
|
|
if (pc) {
|
|
|
|
|
state_ = pc_->signaling_state();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void OnSignalingChange(
|
|
|
|
|
PeerConnectionInterface::SignalingState new_state) override {
|
2018-10-25 10:28:12 +02:00
|
|
|
RTC_DCHECK(pc_);
|
2017-09-26 16:20:19 -07:00
|
|
|
RTC_DCHECK(pc_->signaling_state() == new_state);
|
|
|
|
|
state_ = new_state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MediaStreamInterface* RemoteStream(const std::string& label) {
|
|
|
|
|
return remote_streams_->find(label);
|
|
|
|
|
}
|
|
|
|
|
StreamCollectionInterface* remote_streams() const { return remote_streams_; }
|
|
|
|
|
void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override {
|
|
|
|
|
last_added_stream_ = stream;
|
|
|
|
|
remote_streams_->AddStream(stream);
|
|
|
|
|
}
|
|
|
|
|
void OnRemoveStream(
|
|
|
|
|
rtc::scoped_refptr<MediaStreamInterface> stream) override {
|
|
|
|
|
last_removed_stream_ = stream;
|
|
|
|
|
remote_streams_->RemoveStream(stream);
|
|
|
|
|
}
|
|
|
|
|
void OnRenegotiationNeeded() override { renegotiation_needed_ = true; }
|
2020-08-25 10:20:11 +02:00
|
|
|
void OnNegotiationNeededEvent(uint32_t event_id) override {
|
|
|
|
|
latest_negotiation_needed_event_ = event_id;
|
|
|
|
|
}
|
2017-09-26 16:20:19 -07:00
|
|
|
void OnDataChannel(
|
|
|
|
|
rtc::scoped_refptr<DataChannelInterface> data_channel) override {
|
|
|
|
|
last_datachannel_ = data_channel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnIceConnectionChange(
|
|
|
|
|
PeerConnectionInterface::IceConnectionState new_state) override {
|
2018-10-25 10:28:12 +02:00
|
|
|
RTC_DCHECK(pc_);
|
2017-09-26 16:20:19 -07:00
|
|
|
RTC_DCHECK(pc_->ice_connection_state() == new_state);
|
2018-06-22 15:40:16 -07:00
|
|
|
// When ICE is finished, the caller will get to a kIceConnectionCompleted
|
|
|
|
|
// state, because it has the ICE controlling role, while the callee
|
|
|
|
|
// will get to a kIceConnectionConnected state. This means that both ICE
|
|
|
|
|
// and DTLS are connected.
|
2017-10-23 09:39:20 -07:00
|
|
|
ice_connected_ =
|
2018-06-22 15:40:16 -07:00
|
|
|
(new_state == PeerConnectionInterface::kIceConnectionConnected) ||
|
|
|
|
|
(new_state == PeerConnectionInterface::kIceConnectionCompleted);
|
2017-09-26 16:20:19 -07:00
|
|
|
callback_triggered_ = true;
|
|
|
|
|
}
|
|
|
|
|
void OnIceGatheringChange(
|
|
|
|
|
PeerConnectionInterface::IceGatheringState new_state) override {
|
2018-10-25 10:28:12 +02:00
|
|
|
RTC_DCHECK(pc_);
|
2017-09-26 16:20:19 -07:00
|
|
|
RTC_DCHECK(pc_->ice_gathering_state() == new_state);
|
2017-10-23 09:39:20 -07:00
|
|
|
ice_gathering_complete_ =
|
|
|
|
|
new_state == PeerConnectionInterface::kIceGatheringComplete;
|
2017-09-26 16:20:19 -07:00
|
|
|
callback_triggered_ = true;
|
|
|
|
|
}
|
2017-10-13 11:13:35 -07:00
|
|
|
void OnIceCandidate(const IceCandidateInterface* candidate) override {
|
2018-10-25 10:28:12 +02:00
|
|
|
RTC_DCHECK(pc_);
|
2019-09-17 17:06:18 +02:00
|
|
|
candidates_.push_back(std::make_unique<JsepIceCandidate>(
|
2017-10-13 11:13:35 -07:00
|
|
|
candidate->sdp_mid(), candidate->sdp_mline_index(),
|
|
|
|
|
candidate->candidate()));
|
2017-09-26 16:20:19 -07:00
|
|
|
callback_triggered_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnIceCandidatesRemoved(
|
|
|
|
|
const std::vector<cricket::Candidate>& candidates) override {
|
2017-10-13 11:13:35 -07:00
|
|
|
num_candidates_removed_++;
|
2017-09-26 16:20:19 -07:00
|
|
|
callback_triggered_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnIceConnectionReceivingChange(bool receiving) override {
|
|
|
|
|
callback_triggered_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
Reland "Added PeerConnectionObserver::OnRemoveTrack."
This reverts commit 6c0c55c31817ecfa32409424495eb68b31828c40.
Reason for revert:
Fixed the flake.
Original change's description:
> Revert "Added PeerConnectionObserver::OnRemoveTrack."
>
> This reverts commit ba97ba7af917d4152f5f3363aba1c1561c6673dc.
>
> Reason for revert: The new tests have caused several test failures on the test bots; the method FakeAudioMediaStreamTrack:GetSignalLevel, which is not supposed to be called is sometimes called anyway.
>
> Original change's description:
> > Added PeerConnectionObserver::OnRemoveTrack.
> >
> > This corresponds to processing the removal of a remote track step of
> > the spec, with processing the addition of a remote track already
> > covered by OnAddTrack.
> > https://w3c.github.io/webrtc-pc/#processing-remote-mediastreamtracks
> >
> > Bug: webrtc:8260, webrtc:8315
> > Change-Id: Ica8be92369733eb3cf1397fb60385d45a9b58700
> > Reviewed-on: https://webrtc-review.googlesource.com/4722
> > Commit-Queue: Henrik Boström <hbos@webrtc.org>
> > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> > Reviewed-by: Steve Anton <steveanton@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#20214}
>
> TBR=steveanton@webrtc.org,deadbeef@webrtc.org,hbos@webrtc.org
>
> Change-Id: Id2d9533e27227254769b4280a8ff10a47313e714
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:8260, webrtc:8315
> Reviewed-on: https://webrtc-review.googlesource.com/7940
> Reviewed-by: Alex Loiko <aleloi@webrtc.org>
> Commit-Queue: Alex Loiko <aleloi@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#20218}
TBR=steveanton@webrtc.org,deadbeef@webrtc.org,aleloi@webrtc.org,hbos@webrtc.org
Change-Id: Iab7500bebf98535754b102874259de43831fff6b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8260, webrtc:8315
Reviewed-on: https://webrtc-review.googlesource.com/8180
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20227}
2017-10-10 10:05:16 -07:00
|
|
|
void OnAddTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver,
|
|
|
|
|
const std::vector<rtc::scoped_refptr<MediaStreamInterface>>&
|
|
|
|
|
streams) override {
|
2017-09-26 16:20:19 -07:00
|
|
|
RTC_DCHECK(receiver);
|
|
|
|
|
num_added_tracks_++;
|
|
|
|
|
last_added_track_label_ = receiver->id();
|
Reland "Added PeerConnectionObserver::OnRemoveTrack."
This reverts commit 6c0c55c31817ecfa32409424495eb68b31828c40.
Reason for revert:
Fixed the flake.
Original change's description:
> Revert "Added PeerConnectionObserver::OnRemoveTrack."
>
> This reverts commit ba97ba7af917d4152f5f3363aba1c1561c6673dc.
>
> Reason for revert: The new tests have caused several test failures on the test bots; the method FakeAudioMediaStreamTrack:GetSignalLevel, which is not supposed to be called is sometimes called anyway.
>
> Original change's description:
> > Added PeerConnectionObserver::OnRemoveTrack.
> >
> > This corresponds to processing the removal of a remote track step of
> > the spec, with processing the addition of a remote track already
> > covered by OnAddTrack.
> > https://w3c.github.io/webrtc-pc/#processing-remote-mediastreamtracks
> >
> > Bug: webrtc:8260, webrtc:8315
> > Change-Id: Ica8be92369733eb3cf1397fb60385d45a9b58700
> > Reviewed-on: https://webrtc-review.googlesource.com/4722
> > Commit-Queue: Henrik Boström <hbos@webrtc.org>
> > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> > Reviewed-by: Steve Anton <steveanton@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#20214}
>
> TBR=steveanton@webrtc.org,deadbeef@webrtc.org,hbos@webrtc.org
>
> Change-Id: Id2d9533e27227254769b4280a8ff10a47313e714
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:8260, webrtc:8315
> Reviewed-on: https://webrtc-review.googlesource.com/7940
> Reviewed-by: Alex Loiko <aleloi@webrtc.org>
> Commit-Queue: Alex Loiko <aleloi@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#20218}
TBR=steveanton@webrtc.org,deadbeef@webrtc.org,aleloi@webrtc.org,hbos@webrtc.org
Change-Id: Iab7500bebf98535754b102874259de43831fff6b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8260, webrtc:8315
Reviewed-on: https://webrtc-review.googlesource.com/8180
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20227}
2017-10-10 10:05:16 -07:00
|
|
|
add_track_events_.push_back(AddTrackEvent(receiver, streams));
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-16 16:14:42 -08:00
|
|
|
void OnTrack(
|
|
|
|
|
rtc::scoped_refptr<RtpTransceiverInterface> transceiver) override {
|
|
|
|
|
on_track_transceivers_.push_back(transceiver);
|
|
|
|
|
}
|
|
|
|
|
|
Reland "Added PeerConnectionObserver::OnRemoveTrack."
This reverts commit 6c0c55c31817ecfa32409424495eb68b31828c40.
Reason for revert:
Fixed the flake.
Original change's description:
> Revert "Added PeerConnectionObserver::OnRemoveTrack."
>
> This reverts commit ba97ba7af917d4152f5f3363aba1c1561c6673dc.
>
> Reason for revert: The new tests have caused several test failures on the test bots; the method FakeAudioMediaStreamTrack:GetSignalLevel, which is not supposed to be called is sometimes called anyway.
>
> Original change's description:
> > Added PeerConnectionObserver::OnRemoveTrack.
> >
> > This corresponds to processing the removal of a remote track step of
> > the spec, with processing the addition of a remote track already
> > covered by OnAddTrack.
> > https://w3c.github.io/webrtc-pc/#processing-remote-mediastreamtracks
> >
> > Bug: webrtc:8260, webrtc:8315
> > Change-Id: Ica8be92369733eb3cf1397fb60385d45a9b58700
> > Reviewed-on: https://webrtc-review.googlesource.com/4722
> > Commit-Queue: Henrik Boström <hbos@webrtc.org>
> > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> > Reviewed-by: Steve Anton <steveanton@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#20214}
>
> TBR=steveanton@webrtc.org,deadbeef@webrtc.org,hbos@webrtc.org
>
> Change-Id: Id2d9533e27227254769b4280a8ff10a47313e714
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:8260, webrtc:8315
> Reviewed-on: https://webrtc-review.googlesource.com/7940
> Reviewed-by: Alex Loiko <aleloi@webrtc.org>
> Commit-Queue: Alex Loiko <aleloi@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#20218}
TBR=steveanton@webrtc.org,deadbeef@webrtc.org,aleloi@webrtc.org,hbos@webrtc.org
Change-Id: Iab7500bebf98535754b102874259de43831fff6b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8260, webrtc:8315
Reviewed-on: https://webrtc-review.googlesource.com/8180
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20227}
2017-10-10 10:05:16 -07:00
|
|
|
void OnRemoveTrack(
|
|
|
|
|
rtc::scoped_refptr<RtpReceiverInterface> receiver) override {
|
|
|
|
|
remove_track_events_.push_back(receiver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetAddTrackReceivers() {
|
|
|
|
|
std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers;
|
|
|
|
|
for (const AddTrackEvent& event : add_track_events_) {
|
|
|
|
|
receivers.push_back(event.receiver);
|
|
|
|
|
}
|
|
|
|
|
return receivers;
|
2017-09-26 16:20:19 -07:00
|
|
|
}
|
|
|
|
|
|
2018-03-02 11:34:10 -08:00
|
|
|
int CountAddTrackEventsForStream(const std::string& stream_id) {
|
2018-02-16 16:04:20 -08:00
|
|
|
int found_tracks = 0;
|
|
|
|
|
for (const AddTrackEvent& event : add_track_events_) {
|
2018-03-02 11:34:10 -08:00
|
|
|
bool has_stream_id = false;
|
2018-02-16 16:04:20 -08:00
|
|
|
for (auto stream : event.streams) {
|
2018-03-02 11:34:10 -08:00
|
|
|
if (stream->id() == stream_id) {
|
|
|
|
|
has_stream_id = true;
|
2018-02-16 16:04:20 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-02 11:34:10 -08:00
|
|
|
if (has_stream_id) {
|
2018-02-16 16:04:20 -08:00
|
|
|
++found_tracks;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return found_tracks;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-02 11:34:10 -08:00
|
|
|
// Returns the id of the last added stream.
|
2017-09-26 16:20:19 -07:00
|
|
|
// Empty string if no stream have been added.
|
2018-03-02 11:34:10 -08:00
|
|
|
std::string GetLastAddedStreamId() {
|
2017-09-26 16:20:19 -07:00
|
|
|
if (last_added_stream_.get())
|
2018-03-02 11:34:10 -08:00
|
|
|
return last_added_stream_->id();
|
2017-09-26 16:20:19 -07:00
|
|
|
return "";
|
|
|
|
|
}
|
2018-03-02 11:34:10 -08:00
|
|
|
std::string GetLastRemovedStreamId() {
|
2017-09-26 16:20:19 -07:00
|
|
|
if (last_removed_stream_.get())
|
2018-03-02 11:34:10 -08:00
|
|
|
return last_removed_stream_->id();
|
2017-09-26 16:20:19 -07:00
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-13 11:13:35 -07:00
|
|
|
IceCandidateInterface* last_candidate() {
|
|
|
|
|
if (candidates_.empty()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
} else {
|
|
|
|
|
return candidates_.back().get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 15:40:16 -07:00
|
|
|
std::vector<const IceCandidateInterface*> GetAllCandidates() {
|
|
|
|
|
std::vector<const IceCandidateInterface*> candidates;
|
|
|
|
|
for (const auto& candidate : candidates_) {
|
|
|
|
|
candidates.push_back(candidate.get());
|
|
|
|
|
}
|
|
|
|
|
return candidates;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-13 11:13:35 -07:00
|
|
|
std::vector<IceCandidateInterface*> GetCandidatesByMline(int mline_index) {
|
|
|
|
|
std::vector<IceCandidateInterface*> candidates;
|
|
|
|
|
for (const auto& candidate : candidates_) {
|
|
|
|
|
if (candidate->sdp_mline_index() == mline_index) {
|
|
|
|
|
candidates.push_back(candidate.get());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return candidates;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-25 10:20:11 +02:00
|
|
|
bool legacy_renegotiation_needed() const { return renegotiation_needed_; }
|
|
|
|
|
void clear_legacy_renegotiation_needed() { renegotiation_needed_ = false; }
|
|
|
|
|
|
|
|
|
|
bool has_negotiation_needed_event() {
|
|
|
|
|
return latest_negotiation_needed_event_.has_value();
|
|
|
|
|
}
|
|
|
|
|
uint32_t latest_negotiation_needed_event() {
|
|
|
|
|
return latest_negotiation_needed_event_.value_or(0u);
|
|
|
|
|
}
|
|
|
|
|
void clear_latest_negotiation_needed_event() {
|
|
|
|
|
latest_negotiation_needed_event_ = absl::nullopt;
|
|
|
|
|
}
|
2017-12-14 10:23:57 -08:00
|
|
|
|
2017-09-26 16:20:19 -07:00
|
|
|
rtc::scoped_refptr<PeerConnectionInterface> pc_;
|
|
|
|
|
PeerConnectionInterface::SignalingState state_;
|
2017-10-13 11:13:35 -07:00
|
|
|
std::vector<std::unique_ptr<IceCandidateInterface>> candidates_;
|
2017-09-26 16:20:19 -07:00
|
|
|
rtc::scoped_refptr<DataChannelInterface> last_datachannel_;
|
|
|
|
|
rtc::scoped_refptr<StreamCollection> remote_streams_;
|
|
|
|
|
bool renegotiation_needed_ = false;
|
2020-08-25 10:20:11 +02:00
|
|
|
absl::optional<uint32_t> latest_negotiation_needed_event_;
|
2017-10-23 09:39:20 -07:00
|
|
|
bool ice_gathering_complete_ = false;
|
|
|
|
|
bool ice_connected_ = false;
|
2017-09-26 16:20:19 -07:00
|
|
|
bool callback_triggered_ = false;
|
|
|
|
|
int num_added_tracks_ = 0;
|
|
|
|
|
std::string last_added_track_label_;
|
Reland "Added PeerConnectionObserver::OnRemoveTrack."
This reverts commit 6c0c55c31817ecfa32409424495eb68b31828c40.
Reason for revert:
Fixed the flake.
Original change's description:
> Revert "Added PeerConnectionObserver::OnRemoveTrack."
>
> This reverts commit ba97ba7af917d4152f5f3363aba1c1561c6673dc.
>
> Reason for revert: The new tests have caused several test failures on the test bots; the method FakeAudioMediaStreamTrack:GetSignalLevel, which is not supposed to be called is sometimes called anyway.
>
> Original change's description:
> > Added PeerConnectionObserver::OnRemoveTrack.
> >
> > This corresponds to processing the removal of a remote track step of
> > the spec, with processing the addition of a remote track already
> > covered by OnAddTrack.
> > https://w3c.github.io/webrtc-pc/#processing-remote-mediastreamtracks
> >
> > Bug: webrtc:8260, webrtc:8315
> > Change-Id: Ica8be92369733eb3cf1397fb60385d45a9b58700
> > Reviewed-on: https://webrtc-review.googlesource.com/4722
> > Commit-Queue: Henrik Boström <hbos@webrtc.org>
> > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> > Reviewed-by: Steve Anton <steveanton@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#20214}
>
> TBR=steveanton@webrtc.org,deadbeef@webrtc.org,hbos@webrtc.org
>
> Change-Id: Id2d9533e27227254769b4280a8ff10a47313e714
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:8260, webrtc:8315
> Reviewed-on: https://webrtc-review.googlesource.com/7940
> Reviewed-by: Alex Loiko <aleloi@webrtc.org>
> Commit-Queue: Alex Loiko <aleloi@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#20218}
TBR=steveanton@webrtc.org,deadbeef@webrtc.org,aleloi@webrtc.org,hbos@webrtc.org
Change-Id: Iab7500bebf98535754b102874259de43831fff6b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8260, webrtc:8315
Reviewed-on: https://webrtc-review.googlesource.com/8180
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20227}
2017-10-10 10:05:16 -07:00
|
|
|
std::vector<AddTrackEvent> add_track_events_;
|
|
|
|
|
std::vector<rtc::scoped_refptr<RtpReceiverInterface>> remove_track_events_;
|
2018-02-16 16:14:42 -08:00
|
|
|
std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>
|
|
|
|
|
on_track_transceivers_;
|
2017-10-13 11:13:35 -07:00
|
|
|
int num_candidates_removed_ = 0;
|
2017-09-26 16:20:19 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
rtc::scoped_refptr<MediaStreamInterface> last_added_stream_;
|
|
|
|
|
rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_;
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
class MockCreateSessionDescriptionObserver
|
|
|
|
|
: public webrtc::CreateSessionDescriptionObserver {
|
|
|
|
|
public:
|
|
|
|
|
MockCreateSessionDescriptionObserver()
|
|
|
|
|
: called_(false),
|
2017-10-20 15:30:51 -07:00
|
|
|
error_("MockCreateSessionDescriptionObserver not called") {}
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual ~MockCreateSessionDescriptionObserver() {}
|
2018-03-09 15:18:03 +01:00
|
|
|
void OnSuccess(SessionDescriptionInterface* desc) override {
|
2021-09-16 08:59:11 +00:00
|
|
|
MutexLock lock(&mutex_);
|
2013-07-10 00:45:36 +00:00
|
|
|
called_ = true;
|
2017-10-20 15:30:51 -07:00
|
|
|
error_ = "";
|
2013-07-10 00:45:36 +00:00
|
|
|
desc_.reset(desc);
|
|
|
|
|
}
|
2018-03-09 15:18:03 +01:00
|
|
|
void OnFailure(webrtc::RTCError error) override {
|
2021-09-16 08:59:11 +00:00
|
|
|
MutexLock lock(&mutex_);
|
2013-07-10 00:45:36 +00:00
|
|
|
called_ = true;
|
2018-03-09 15:18:03 +01:00
|
|
|
error_ = error.message();
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2021-09-16 08:59:11 +00:00
|
|
|
bool called() const {
|
|
|
|
|
MutexLock lock(&mutex_);
|
|
|
|
|
return called_;
|
|
|
|
|
}
|
|
|
|
|
bool result() const {
|
|
|
|
|
MutexLock lock(&mutex_);
|
|
|
|
|
return error_.empty();
|
|
|
|
|
}
|
|
|
|
|
const std::string& error() const {
|
|
|
|
|
MutexLock lock(&mutex_);
|
|
|
|
|
return error_;
|
|
|
|
|
}
|
2017-03-29 21:08:16 -07:00
|
|
|
std::unique_ptr<SessionDescriptionInterface> MoveDescription() {
|
2021-09-16 08:59:11 +00:00
|
|
|
MutexLock lock(&mutex_);
|
2017-03-29 21:08:16 -07:00
|
|
|
return std::move(desc_);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2021-09-16 08:59:11 +00:00
|
|
|
mutable Mutex mutex_;
|
|
|
|
|
bool called_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
std::string error_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
std::unique_ptr<SessionDescriptionInterface> desc_ RTC_GUARDED_BY(mutex_);
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MockSetSessionDescriptionObserver
|
|
|
|
|
: public webrtc::SetSessionDescriptionObserver {
|
|
|
|
|
public:
|
2019-10-30 10:35:50 +01:00
|
|
|
static rtc::scoped_refptr<MockSetSessionDescriptionObserver> Create() {
|
2021-04-27 14:43:08 +02:00
|
|
|
return rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
|
2019-10-30 10:35:50 +01:00
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
MockSetSessionDescriptionObserver()
|
|
|
|
|
: called_(false),
|
2017-10-20 15:30:51 -07:00
|
|
|
error_("MockSetSessionDescriptionObserver not called") {}
|
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
|
|
|
~MockSetSessionDescriptionObserver() override {}
|
|
|
|
|
void OnSuccess() override {
|
2021-09-16 08:59:11 +00:00
|
|
|
MutexLock lock(&mutex_);
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
called_ = true;
|
2017-10-20 15:30:51 -07:00
|
|
|
error_ = "";
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2018-03-09 15:18:03 +01:00
|
|
|
void OnFailure(webrtc::RTCError error) override {
|
2021-09-16 08:59:11 +00:00
|
|
|
MutexLock lock(&mutex_);
|
2013-07-10 00:45:36 +00:00
|
|
|
called_ = true;
|
2018-03-09 15:18:03 +01:00
|
|
|
error_ = error.message();
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2018-03-09 15:18:03 +01:00
|
|
|
|
2021-09-16 08:59:11 +00:00
|
|
|
bool called() const {
|
|
|
|
|
MutexLock lock(&mutex_);
|
|
|
|
|
return called_;
|
|
|
|
|
}
|
|
|
|
|
bool result() const {
|
|
|
|
|
MutexLock lock(&mutex_);
|
|
|
|
|
return error_.empty();
|
|
|
|
|
}
|
|
|
|
|
const std::string& error() const {
|
|
|
|
|
MutexLock lock(&mutex_);
|
|
|
|
|
return error_;
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
private:
|
2021-09-16 08:59:11 +00:00
|
|
|
mutable Mutex mutex_;
|
2013-07-10 00:45:36 +00:00
|
|
|
bool called_;
|
2017-10-20 15:30:51 -07:00
|
|
|
std::string error_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
2020-07-29 12:04:00 +02:00
|
|
|
class FakeSetLocalDescriptionObserver
|
2022-03-21 10:36:32 +01:00
|
|
|
: public SetLocalDescriptionObserverInterface {
|
2020-07-29 12:04:00 +02:00
|
|
|
public:
|
|
|
|
|
bool called() const { return error_.has_value(); }
|
|
|
|
|
RTCError& error() {
|
|
|
|
|
RTC_DCHECK(error_.has_value());
|
|
|
|
|
return *error_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetLocalDescriptionObserverInterface implementation.
|
|
|
|
|
void OnSetLocalDescriptionComplete(RTCError error) override {
|
|
|
|
|
error_ = std::move(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Set on complete, on success this is set to an RTCError::OK() error.
|
|
|
|
|
absl::optional<RTCError> error_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FakeSetRemoteDescriptionObserver
|
2022-03-21 10:36:32 +01:00
|
|
|
: public SetRemoteDescriptionObserverInterface {
|
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
|
|
|
public:
|
|
|
|
|
bool called() const { return error_.has_value(); }
|
|
|
|
|
RTCError& error() {
|
|
|
|
|
RTC_DCHECK(error_.has_value());
|
|
|
|
|
return *error_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetRemoteDescriptionObserverInterface implementation.
|
|
|
|
|
void OnSetRemoteDescriptionComplete(RTCError error) override {
|
|
|
|
|
error_ = std::move(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Set on complete, on success this is set to an RTCError::OK() error.
|
2018-06-19 16:47:43 +02:00
|
|
|
absl::optional<RTCError> error_;
|
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
|
|
|
};
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
class MockDataChannelObserver : public webrtc::DataChannelObserver {
|
|
|
|
|
public:
|
2021-04-22 13:32:39 +02:00
|
|
|
struct Message {
|
|
|
|
|
std::string data;
|
|
|
|
|
bool binary;
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
explicit MockDataChannelObserver(webrtc::DataChannelInterface* channel)
|
2016-08-18 11:40:37 -07:00
|
|
|
: channel_(channel) {
|
2013-07-10 00:45:36 +00:00
|
|
|
channel_->RegisterObserver(this);
|
2021-04-29 12:49:25 +02:00
|
|
|
states_.push_back(channel_->state());
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
virtual ~MockDataChannelObserver() { channel_->UnregisterObserver(); }
|
|
|
|
|
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
void OnBufferedAmountChange(uint64_t previous_amount) override {}
|
2015-07-01 13:34:33 -07:00
|
|
|
|
2021-04-29 12:49:25 +02:00
|
|
|
void OnStateChange() override { states_.push_back(channel_->state()); }
|
2015-07-01 13:34:33 -07:00
|
|
|
void OnMessage(const DataBuffer& buffer) override {
|
2016-08-18 11:40:37 -07:00
|
|
|
messages_.push_back(
|
2021-04-22 13:32:39 +02:00
|
|
|
{std::string(buffer.data.data<char>(), buffer.data.size()),
|
|
|
|
|
buffer.binary});
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-29 12:49:25 +02:00
|
|
|
bool IsOpen() const { return state() == DataChannelInterface::kOpen; }
|
2021-04-22 13:32:39 +02:00
|
|
|
std::vector<Message> messages() const { return messages_; }
|
2016-08-18 11:40:37 -07:00
|
|
|
std::string last_message() const {
|
2021-04-22 13:32:39 +02:00
|
|
|
if (messages_.empty())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
return messages_.back().data;
|
|
|
|
|
}
|
|
|
|
|
bool last_message_is_binary() const {
|
|
|
|
|
if (messages_.empty())
|
|
|
|
|
return false;
|
|
|
|
|
return messages_.back().binary;
|
2016-08-18 11:40:37 -07:00
|
|
|
}
|
|
|
|
|
size_t received_message_count() const { return messages_.size(); }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2021-04-29 12:49:25 +02:00
|
|
|
DataChannelInterface::DataState state() const { return states_.back(); }
|
|
|
|
|
const std::vector<DataChannelInterface::DataState>& states() const {
|
|
|
|
|
return states_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
private:
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<webrtc::DataChannelInterface> channel_;
|
2021-04-29 12:49:25 +02:00
|
|
|
std::vector<DataChannelInterface::DataState> states_;
|
2021-04-22 13:32:39 +02:00
|
|
|
std::vector<Message> messages_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MockStatsObserver : public webrtc::StatsObserver {
|
|
|
|
|
public:
|
2014-12-17 14:09:05 +00:00
|
|
|
MockStatsObserver() : called_(false), stats_() {}
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual ~MockStatsObserver() {}
|
2014-12-17 14:09:05 +00:00
|
|
|
|
Revert of New method StatsObserver::OnCompleteReports, passing ownership. (patchset #2 id:20001 of https://codereview.webrtc.org/2584553002/ )
Reason for revert:
The new method doesn't work as intended.
It can't pass ownership, because the StatsReports is a vector of raw pointers to StatReport objects owned by the StatsCollector.
Original issue's description:
> New method StatsObserver::OnCompleteReports, passing ownership.
>
> The new name, OnCompleteReports rather than OnComplete, is needed
> because in C++ method lookup, overriding a method hides all otherwise
> inherited methods with the same name, even if they have a different
> signature. And here, the intention is that each subclass should
> override one or the other of the two methods, and inherit the method it
> doesn't override.
>
> This cl is a prerequisite for
> https://codereview.webrtc.org/2567143003/, because the Chrome glue
> code needs to retain the stats report after the OnComplete method has
> returned.
>
> Currently, Chrome makes a copy of the stats mapping (which breaks when
> changing ValuePtr from an rtc::linked_ptr to an std::unique_ptr). After
> this cl, Chrome can be fixed to take ownership and no longer needs to
> copy anything, unblocking cl 2567143003.
>
> BUG=webrtc:6424
>
> Review-Url: https://codereview.webrtc.org/2584553002
> Cr-Commit-Position: refs/heads/master@{#15708}
> Committed: https://chromium.googlesource.com/external/webrtc/+/b36ee8d498be2fa58fde3f3f3d69a74e4d3b817d
TBR=solenberg@webrtc.org,magjed@webrtc.org,tkchin@webrtc.org,hbos@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:6424
Review-Url: https://codereview.webrtc.org/2641783002
Cr-Commit-Position: refs/heads/master@{#16144}
2017-01-18 05:00:34 -08:00
|
|
|
virtual void OnComplete(const StatsReports& reports) {
|
2017-01-18 07:20:55 -08:00
|
|
|
RTC_CHECK(!called_);
|
2013-07-10 00:45:36 +00:00
|
|
|
called_ = true;
|
2015-03-04 01:38:30 +00:00
|
|
|
stats_.Clear();
|
Revert of New method StatsObserver::OnCompleteReports, passing ownership. (patchset #2 id:20001 of https://codereview.webrtc.org/2584553002/ )
Reason for revert:
The new method doesn't work as intended.
It can't pass ownership, because the StatsReports is a vector of raw pointers to StatReport objects owned by the StatsCollector.
Original issue's description:
> New method StatsObserver::OnCompleteReports, passing ownership.
>
> The new name, OnCompleteReports rather than OnComplete, is needed
> because in C++ method lookup, overriding a method hides all otherwise
> inherited methods with the same name, even if they have a different
> signature. And here, the intention is that each subclass should
> override one or the other of the two methods, and inherit the method it
> doesn't override.
>
> This cl is a prerequisite for
> https://codereview.webrtc.org/2567143003/, because the Chrome glue
> code needs to retain the stats report after the OnComplete method has
> returned.
>
> Currently, Chrome makes a copy of the stats mapping (which breaks when
> changing ValuePtr from an rtc::linked_ptr to an std::unique_ptr). After
> this cl, Chrome can be fixed to take ownership and no longer needs to
> copy anything, unblocking cl 2567143003.
>
> BUG=webrtc:6424
>
> Review-Url: https://codereview.webrtc.org/2584553002
> Cr-Commit-Position: refs/heads/master@{#15708}
> Committed: https://chromium.googlesource.com/external/webrtc/+/b36ee8d498be2fa58fde3f3f3d69a74e4d3b817d
TBR=solenberg@webrtc.org,magjed@webrtc.org,tkchin@webrtc.org,hbos@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:6424
Review-Url: https://codereview.webrtc.org/2641783002
Cr-Commit-Position: refs/heads/master@{#16144}
2017-01-18 05:00:34 -08:00
|
|
|
stats_.number_of_reports = reports.size();
|
|
|
|
|
for (const auto* r : reports) {
|
2015-01-21 11:36:18 +00:00
|
|
|
if (r->type() == StatsReport::kStatsReportTypeSsrc) {
|
2015-06-22 15:06:43 -07:00
|
|
|
stats_.timestamp = r->timestamp();
|
2014-12-17 14:09:05 +00:00
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameAudioOutputLevel,
|
|
|
|
|
&stats_.audio_output_level);
|
|
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameAudioInputLevel,
|
|
|
|
|
&stats_.audio_input_level);
|
|
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameBytesReceived,
|
|
|
|
|
&stats_.bytes_received);
|
|
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameBytesSent,
|
|
|
|
|
&stats_.bytes_sent);
|
2017-09-14 14:46:47 +02:00
|
|
|
GetInt64Value(r, StatsReport::kStatsValueNameCaptureStartNtpTimeMs,
|
|
|
|
|
&stats_.capture_start_ntp_time);
|
2018-11-28 11:15:33 -08:00
|
|
|
stats_.track_ids.emplace_back();
|
|
|
|
|
GetStringValue(r, StatsReport::kStatsValueNameTrackId,
|
|
|
|
|
&stats_.track_ids.back());
|
2015-01-21 11:36:18 +00:00
|
|
|
} else if (r->type() == StatsReport::kStatsReportTypeBwe) {
|
2015-06-22 15:06:43 -07:00
|
|
|
stats_.timestamp = r->timestamp();
|
2014-12-17 14:09:05 +00:00
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameAvailableReceiveBandwidth,
|
|
|
|
|
&stats_.available_receive_bandwidth);
|
2015-03-04 01:38:30 +00:00
|
|
|
} else if (r->type() == StatsReport::kStatsReportTypeComponent) {
|
2015-06-22 15:06:43 -07:00
|
|
|
stats_.timestamp = r->timestamp();
|
2015-03-04 01:38:30 +00:00
|
|
|
GetStringValue(r, StatsReport::kStatsValueNameDtlsCipher,
|
|
|
|
|
&stats_.dtls_cipher);
|
|
|
|
|
GetStringValue(r, StatsReport::kStatsValueNameSrtpCipher,
|
|
|
|
|
&stats_.srtp_cipher);
|
2014-12-17 14:09:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool called() const { return called_; }
|
2014-12-17 14:09:05 +00:00
|
|
|
size_t number_of_reports() const { return stats_.number_of_reports; }
|
2015-06-22 15:06:43 -07:00
|
|
|
double timestamp() const { return stats_.timestamp; }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int AudioOutputLevel() const {
|
2017-01-18 07:20:55 -08:00
|
|
|
RTC_CHECK(called_);
|
2014-12-17 14:09:05 +00:00
|
|
|
return stats_.audio_output_level;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int AudioInputLevel() const {
|
2017-01-18 07:20:55 -08:00
|
|
|
RTC_CHECK(called_);
|
2014-12-17 14:09:05 +00:00
|
|
|
return stats_.audio_input_level;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int BytesReceived() const {
|
2017-01-18 07:20:55 -08:00
|
|
|
RTC_CHECK(called_);
|
2014-12-17 14:09:05 +00:00
|
|
|
return stats_.bytes_received;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int BytesSent() const {
|
2017-01-18 07:20:55 -08:00
|
|
|
RTC_CHECK(called_);
|
2014-12-17 14:09:05 +00:00
|
|
|
return stats_.bytes_sent;
|
2014-08-25 12:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
2017-09-14 14:46:47 +02:00
|
|
|
int64_t CaptureStartNtpTime() const {
|
|
|
|
|
RTC_CHECK(called_);
|
|
|
|
|
return stats_.capture_start_ntp_time;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int AvailableReceiveBandwidth() const {
|
2017-01-18 07:20:55 -08:00
|
|
|
RTC_CHECK(called_);
|
2014-12-17 14:09:05 +00:00
|
|
|
return stats_.available_receive_bandwidth;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-04 01:38:30 +00:00
|
|
|
std::string DtlsCipher() const {
|
2017-01-18 07:20:55 -08:00
|
|
|
RTC_CHECK(called_);
|
2015-03-04 01:38:30 +00:00
|
|
|
return stats_.dtls_cipher;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string SrtpCipher() const {
|
2017-01-18 07:20:55 -08:00
|
|
|
RTC_CHECK(called_);
|
2015-03-04 01:38:30 +00:00
|
|
|
return stats_.srtp_cipher;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-28 11:15:33 -08:00
|
|
|
std::vector<std::string> TrackIds() const {
|
|
|
|
|
RTC_CHECK(called_);
|
|
|
|
|
return stats_.track_ids;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
private:
|
2014-12-17 14:09:05 +00:00
|
|
|
bool GetIntValue(const StatsReport* report,
|
|
|
|
|
StatsReport::StatsValueName name,
|
|
|
|
|
int* value) {
|
2015-03-04 15:25:19 +00:00
|
|
|
const StatsReport::Value* v = report->FindValue(name);
|
|
|
|
|
if (v) {
|
|
|
|
|
// TODO(tommi): We should really just be using an int here :-/
|
|
|
|
|
*value = rtc::FromString<int>(v->ToString());
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2015-03-04 15:25:19 +00:00
|
|
|
return v != nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2015-03-04 15:25:19 +00:00
|
|
|
|
2017-09-14 14:46:47 +02:00
|
|
|
bool GetInt64Value(const StatsReport* report,
|
|
|
|
|
StatsReport::StatsValueName name,
|
|
|
|
|
int64_t* value) {
|
|
|
|
|
const StatsReport::Value* v = report->FindValue(name);
|
|
|
|
|
if (v) {
|
|
|
|
|
// TODO(tommi): We should really just be using an int here :-/
|
|
|
|
|
*value = rtc::FromString<int64_t>(v->ToString());
|
|
|
|
|
}
|
|
|
|
|
return v != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 01:38:30 +00:00
|
|
|
bool GetStringValue(const StatsReport* report,
|
|
|
|
|
StatsReport::StatsValueName name,
|
|
|
|
|
std::string* value) {
|
2015-03-04 15:25:19 +00:00
|
|
|
const StatsReport::Value* v = report->FindValue(name);
|
|
|
|
|
if (v)
|
|
|
|
|
*value = v->ToString();
|
|
|
|
|
return v != nullptr;
|
2015-03-04 01:38:30 +00:00
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
bool called_;
|
2014-12-17 14:09:05 +00:00
|
|
|
struct {
|
2015-03-04 01:38:30 +00:00
|
|
|
void Clear() {
|
|
|
|
|
number_of_reports = 0;
|
2015-06-22 15:06:43 -07:00
|
|
|
timestamp = 0;
|
2015-03-04 01:38:30 +00:00
|
|
|
audio_output_level = 0;
|
|
|
|
|
audio_input_level = 0;
|
|
|
|
|
bytes_received = 0;
|
|
|
|
|
bytes_sent = 0;
|
2017-09-14 14:46:47 +02:00
|
|
|
capture_start_ntp_time = 0;
|
2015-03-04 01:38:30 +00:00
|
|
|
available_receive_bandwidth = 0;
|
|
|
|
|
dtls_cipher.clear();
|
|
|
|
|
srtp_cipher.clear();
|
2018-11-28 11:15:33 -08:00
|
|
|
track_ids.clear();
|
2015-03-04 01:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
size_t number_of_reports;
|
2015-06-22 15:06:43 -07:00
|
|
|
double timestamp;
|
2014-12-17 14:09:05 +00:00
|
|
|
int audio_output_level;
|
|
|
|
|
int audio_input_level;
|
|
|
|
|
int bytes_received;
|
|
|
|
|
int bytes_sent;
|
2017-09-14 14:46:47 +02:00
|
|
|
int64_t capture_start_ntp_time;
|
2014-12-17 14:09:05 +00:00
|
|
|
int available_receive_bandwidth;
|
2015-03-04 01:38:30 +00:00
|
|
|
std::string dtls_cipher;
|
|
|
|
|
std::string srtp_cipher;
|
2018-11-28 11:15:33 -08:00
|
|
|
std::vector<std::string> track_ids;
|
2014-12-17 14:09:05 +00:00
|
|
|
} stats_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
2017-04-18 16:01:17 -07:00
|
|
|
// Helper class that just stores the report from the callback.
|
|
|
|
|
class MockRTCStatsCollectorCallback : public webrtc::RTCStatsCollectorCallback {
|
|
|
|
|
public:
|
|
|
|
|
rtc::scoped_refptr<const RTCStatsReport> report() { return report_; }
|
|
|
|
|
|
|
|
|
|
bool called() const { return called_; }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void OnStatsDelivered(
|
|
|
|
|
const rtc::scoped_refptr<const RTCStatsReport>& report) override {
|
|
|
|
|
report_ = report;
|
|
|
|
|
called_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool called_ = false;
|
|
|
|
|
rtc::scoped_refptr<const RTCStatsReport> report_;
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#endif // PC_TEST_MOCK_PEER_CONNECTION_OBSERVERS_H_
|