Adding "first packet received" notification to PeerConnectionObserver.

R=glaznev@webrtc.org, pthatcher@webrtc.org, tkchin@webrtc.org

Review URL: https://codereview.webrtc.org/1581693006 .

Cr-Commit-Position: refs/heads/master@{#11401}
This commit is contained in:
Taylor Brandstetter 2016-01-27 12:10:36 -08:00
parent 80f1db971d
commit 42265a8cc3
15 changed files with 79 additions and 0 deletions

View File

@ -374,6 +374,14 @@ class PCOJava : public PeerConnectionObserver {
CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
}
void OnFirstMediaPacketReceived() override {
ScopedLocalRefFrame local_ref_frame(jni());
jmethodID m = GetMethodID(jni(), *j_observer_class_,
"onFirstMediaPacketReceived", "()V");
jni()->CallVoidMethod(*j_observer_global_, m);
CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
}
void SetConstraints(ConstraintsWrapper* constraints) {
RTC_CHECK(!constraints_.get()) << "constraints already set!";
constraints_.reset(constraints);

View File

@ -86,6 +86,9 @@ public class PeerConnection {
/** Triggered when renegotiation is necessary. */
public void onRenegotiationNeeded();
/** Called when the first RTP packet is received. */
public void onFirstMediaPacketReceived();
}
/** Java version of PeerConnectionInterface.IceServer. */

View File

@ -289,6 +289,9 @@ public class PeerConnectionTest {
++expectedStatsCallbacks;
}
@Override
public synchronized void onFirstMediaPacketReceived() {}
public synchronized LinkedList<StatsReport[]> takeStatsReports() {
LinkedList<StatsReport[]> got = gotStatsReports;
gotStatsReports = new LinkedList<StatsReport[]>();

View File

@ -68,6 +68,9 @@ class RTCPeerConnectionObserver : public PeerConnectionObserver {
// New Ice candidate have been found.
void OnIceCandidate(const IceCandidateInterface* candidate) override;
// Called when the first RTP packet is received.
void OnFirstMediaPacketReceived() override;
private:
__weak RTCPeerConnection* _peerConnection;
};

View File

@ -105,4 +105,9 @@ void RTCPeerConnectionObserver::OnIceCandidate(
gotICECandidate:iceCandidate];
}
void RTCPeerConnectionObserver::OnFirstMediaPacketReceived() {
id<RTCPeerConnectionDelegate> delegate = _peerConnection.delegate;
[delegate peerConnectionOnFirstMediaPacketReceived:_peerConnection];
}
} // namespace webrtc

View File

@ -69,4 +69,8 @@
- (void)peerConnection:(RTCPeerConnection*)peerConnection
didOpenDataChannel:(RTCDataChannel*)dataChannel;
// Called when the first RTP packet is received.
- (void)peerConnectionOnFirstMediaPacketReceived:
(RTCPeerConnection *)peerConnection;
@end

View File

@ -233,6 +233,10 @@
@"Unexpected state");
}
- (void)peerConnectionOnFirstMediaPacketReceived:
(RTCPeerConnection*)peerConnection {
}
#pragma mark - RTCDataChannelDelegate
- (void)channelDidChangeState:(RTCDataChannel*)channel {

View File

@ -663,6 +663,8 @@ bool PeerConnection::Initialize(
this, &PeerConnection::OnDataChannelDestroyed);
session_->SignalDataChannelOpenMessage.connect(
this, &PeerConnection::OnDataChannelOpenMessage);
session_->SignalFirstMediaPacketReceived.connect(
this, &PeerConnection::OnFirstMediaPacketReceived);
return true;
}
@ -2029,6 +2031,11 @@ void PeerConnection::OnDataChannelOpenMessage(
DataChannelProxy::Create(signaling_thread(), channel));
}
void PeerConnection::OnFirstMediaPacketReceived() {
RTC_DCHECK(signaling_thread()->IsCurrent());
observer_->OnFirstMediaPacketReceived();
}
RtpSenderInterface* PeerConnection::FindSenderById(const std::string& id) {
auto it =
std::find_if(senders_.begin(), senders_.end(),

View File

@ -326,6 +326,7 @@ class PeerConnection : public PeerConnectionInterface,
// webrtc::DataChannel should be opened.
void OnDataChannelOpenMessage(const std::string& label,
const InternalDataChannelInit& config);
void OnFirstMediaPacketReceived();
RtpSenderInterface* FindSenderById(const std::string& id);

View File

@ -251,6 +251,7 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
signaling_message_receiver_->ReceiveIceMessage(
candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
}
void OnFirstMediaPacketReceived() override { received_media_packet_ = true; }
// MediaStreamInterface callback
void OnChanged() override {
@ -386,6 +387,8 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
return true;
}
bool received_media_packet() const { return received_media_packet_; }
void OnIceComplete() override { LOG(INFO) << id_ << "OnIceComplete"; }
void OnDataChannel(DataChannelInterface* data_channel) override {
@ -924,6 +927,10 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
rtc::scoped_refptr<DataChannelInterface> data_channel_;
rtc::scoped_ptr<MockDataChannelObserver> data_observer_;
// "true" if the PeerConnection indicated that a packet was received,
// through PeerConnectionObserverInterface.
bool received_media_packet_ = false;
};
class P2PTestConductor : public testing::Test {
@ -1104,6 +1111,10 @@ class P2PTestConductor : public testing::Test {
EXPECT_TRUE_WAIT(FramesNotPending(audio_frame_count, video_frame_count),
kMaxWaitForFramesMs);
if (audio_frame_count != -1 || video_frame_count != -1) {
EXPECT_TRUE(initiating_client_->received_media_packet());
EXPECT_TRUE(receiving_client_->received_media_packet());
}
}
void SetupAndVerifyDtlsCall() {

View File

@ -501,6 +501,9 @@ class PeerConnectionObserver {
// Called when the ICE connection receiving status changes.
virtual void OnIceConnectionReceivingChange(bool receiving) {}
// Called when the first RTP packet is received.
virtual void OnFirstMediaPacketReceived() {}
protected:
// Dtor protected as objects shouldn't be deleted via this interface.
~PeerConnectionObserver() {}

View File

@ -1844,6 +1844,8 @@ bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) {
voice_channel_->SignalDtlsSetupFailure.connect(
this, &WebRtcSession::OnDtlsSetupFailure);
voice_channel_->SignalFirstPacketReceived.connect(
this, &WebRtcSession::OnChannelFirstPacketReceived);
SignalVoiceChannelCreated();
voice_channel_->transport_channel()->SignalSentPacket.connect(
@ -1861,6 +1863,8 @@ bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) {
video_channel_->SignalDtlsSetupFailure.connect(
this, &WebRtcSession::OnDtlsSetupFailure);
video_channel_->SignalFirstPacketReceived.connect(
this, &WebRtcSession::OnChannelFirstPacketReceived);
SignalVideoChannelCreated();
video_channel_->transport_channel()->SignalSentPacket.connect(
@ -1895,6 +1899,14 @@ void WebRtcSession::OnDtlsSetupFailure(cricket::BaseChannel*, bool rtcp) {
rtcp ? kDtlsSetupFailureRtcp : kDtlsSetupFailureRtp);
}
void WebRtcSession::OnChannelFirstPacketReceived(cricket::BaseChannel*) {
ASSERT(signaling_thread()->IsCurrent());
if (!has_received_media_packet_) {
has_received_media_packet_ = true;
SignalFirstMediaPacketReceived();
}
}
void WebRtcSession::OnDataChannelMessageReceived(
cricket::DataChannel* channel,
const cricket::ReceiveDataParams& params,

View File

@ -309,6 +309,7 @@ class WebRtcSession : public AudioProviderInterface,
void OnCertificateReady(
const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
void OnDtlsSetupFailure(cricket::BaseChannel*, bool rtcp);
void OnChannelFirstPacketReceived(cricket::BaseChannel*);
// For unit test.
bool waiting_for_certificate_for_testing() const;
@ -335,6 +336,9 @@ class WebRtcSession : public AudioProviderInterface,
sigslot::signal2<const std::string&, const InternalDataChannelInit&>
SignalDataChannelOpenMessage;
// Called when the first RTP packet is received.
sigslot::signal0<> SignalFirstMediaPacketReceived;
private:
// Indicates the type of SessionDescription in a call to SetLocalDescription
// and SetRemoteDescription.
@ -518,6 +522,8 @@ class WebRtcSession : public AudioProviderInterface,
// Declares the RTCP mux policy for the WebRTCSession.
PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy_;
bool has_received_media_packet_ = false;
RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSession);
};
} // namespace webrtc

View File

@ -1000,6 +1000,10 @@ public class PeerConnectionClient {
// No need to do anything; AppRTC follows a pre-agreed-upon
// signaling/negotiation protocol.
}
@Override
public void onFirstMediaPacketReceived() {
}
}
// Implementation detail: handle offer creation/signaling and answer setting,

View File

@ -384,6 +384,11 @@ static NSInteger const kARDAppClientErrorInvalidRoom = -6;
didOpenDataChannel:(RTCDataChannel *)dataChannel {
}
- (void)peerConnectionOnFirstMediaPacketReceived:
(RTCPeerConnection *)peerConnection {
RTCLog(@"Received first media packet.");
}
#pragma mark - RTCStatsDelegate
- (void)peerConnection:(RTCPeerConnection *)peerConnection