Bug 1595479 - Add RtcpEventObserver to Conduits and Transceiver; r=ng

Differential Revision: https://phabricator.services.mozilla.com/D57860

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dan Minor 2019-12-20 20:54:35 +00:00
parent 0cd4afab2d
commit f50ddd24b2
8 changed files with 119 additions and 3 deletions

View File

@ -277,6 +277,34 @@ void WebrtcAudioConduit::OnRtpPacket(const webrtc::RTPHeader& aHeader,
mRtpSourceObserver.OnRtpPacket(aHeader, aTimestamp, aJitter);
}
void WebrtcAudioConduit::OnRtcpBye() {
RefPtr<WebrtcAudioConduit> self = this;
NS_DispatchToMainThread(media::NewRunnableFrom([self]() mutable {
MOZ_ASSERT(NS_IsMainThread());
if (self->mRtcpEventObserver) {
self->mRtcpEventObserver->OnRtcpBye();
}
return NS_OK;
}));
}
void WebrtcAudioConduit::OnRtcpTimeout() {
RefPtr<WebrtcAudioConduit> self = this;
NS_DispatchToMainThread(media::NewRunnableFrom([self]() mutable {
MOZ_ASSERT(NS_IsMainThread());
if (self->mRtcpEventObserver) {
self->mRtcpEventObserver->OnRtcpTimeout();
}
return NS_OK;
}));
}
void WebrtcAudioConduit::SetRtcpEventObserver(
mozilla::RtcpEventObserver* observer) {
MOZ_ASSERT(NS_IsMainThread());
mRtcpEventObserver = observer;
}
void WebrtcAudioConduit::GetRtpSources(
const int64_t aTimeNow, nsTArray<dom::RTCRtpSourceEntry>& outSources) {
MOZ_ASSERT(NS_IsMainThread());
@ -1080,6 +1108,7 @@ MediaConduitErrorCode WebrtcAudioConduit::CreateChannels() {
}
mRecvChannelProxy->SetRtpPacketObserver(this);
mRecvChannelProxy->SetRtcpEventObserver(this);
mRecvChannelProxy->RegisterTransport(this);
mSendChannelProxy = vei->GetChannelProxy(mSendChannel);

View File

@ -35,6 +35,7 @@ DOMHighResTimeStamp NTPtoDOMHighResTimeStamp(uint32_t ntpHigh, uint32_t ntpLow);
*/
class WebrtcAudioConduit : public AudioSessionConduit,
public webrtc::Transport,
public webrtc::RtcpEventObserver,
public webrtc::RtpPacketObserver {
public:
// VoiceEngine defined constant for Payload Name Size.
@ -246,6 +247,11 @@ class WebrtcAudioConduit : public AudioSessionConduit,
void OnRtpPacket(const webrtc::RTPHeader& aRtpHeader,
const int64_t aTimestamp, const uint32_t aJitter) override;
void OnRtcpBye() override;
void OnRtcpTimeout() override;
void SetRtcpEventObserver(mozilla::RtcpEventObserver* observer) override;
// test-only: inserts fake CSRCs and audio level data
void InsertAudioLevelForContributingSource(const uint32_t aCsrcSource,
const int64_t aTimestamp,
@ -362,6 +368,9 @@ class WebrtcAudioConduit : public AudioSessionConduit,
// Accessed only on mStsThread
Maybe<DOMHighResTimeStamp> mLastRtcpReceived;
// Accessed only on main thread.
mozilla::RtcpEventObserver* mRtcpEventObserver = nullptr;
};
} // namespace mozilla

View File

@ -12,6 +12,7 @@
#include "mozilla/RefCounted.h"
#include "mozilla/UniquePtr.h"
#include "RtpSourceObserver.h"
#include "RtcpEventObserver.h"
#include "CodecConfig.h"
#include "VideoTypes.h"
#include "MediaConduitErrors.h"
@ -254,6 +255,8 @@ class MediaSessionConduit {
virtual Maybe<RefPtr<VideoSessionConduit>> AsVideoSessionConduit() = 0;
virtual void SetRtcpEventObserver(RtcpEventObserver* observer) = 0;
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaSessionConduit)
};

View File

@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef RTCP_EVENT_OBSERVER_
#define RTCP_EVENT_OBSERVER_
namespace mozilla {
/**
* This provides an interface to allow for receiving notifications
* of rtcp bye packets and timeouts.
*/
class RtcpEventObserver {
public:
virtual void OnRtcpBye() = 0;
virtual void OnRtcpTimeout() = 0;
};
} // namespace mozilla
#endif

View File

@ -486,6 +486,7 @@ WebrtcVideoConduit::WebrtcVideoConduit(
mVideoStatsTimer(NS_NewTimer()) {
mCall->RegisterConduit(this);
mRecvStreamConfig.renderer = this;
mRecvStreamConfig.rtcp_event_observer = this;
}
WebrtcVideoConduit::~WebrtcVideoConduit() {
@ -1786,7 +1787,10 @@ void WebrtcVideoConduit::SelectSendResolution(unsigned short width,
// Limit resolution to max-fs
if (mCurSendCodecConfig->mEncodingConstraints.maxFs) {
// max-fs is in macroblocks, convert to pixels
max_fs = std::min(max_fs, static_cast<int>(mCurSendCodecConfig->mEncodingConstraints.maxFs * (16 * 16)));
max_fs = std::min(
max_fs,
static_cast<int>(mCurSendCodecConfig->mEncodingConstraints.maxFs *
(16 * 16)));
}
mVideoAdapter->OnResolutionFramerateRequest(
rtc::Optional<int>(), max_fs, std::numeric_limits<int>::max());
@ -1885,7 +1889,8 @@ MediaConduitErrorCode WebrtcVideoConduit::SendVideoFrame(
this, __FUNCTION__, mSendStreamConfig.rtp.ssrcs.front(),
mSendStreamConfig.rtp.ssrcs.front());
if (mUpdateResolution || frame.width() != mLastWidth || frame.height() != mLastHeight) {
if (mUpdateResolution || frame.width() != mLastWidth ||
frame.height() != mLastHeight) {
// See if we need to recalculate what we're sending.
CSFLogVerbose(LOGTAG, "%s: call SelectSendResolution with %ux%u",
__FUNCTION__, frame.width(), frame.height());
@ -2288,6 +2293,34 @@ uint64_t WebrtcVideoConduit::MozVideoLatencyAvg() {
return mVideoLatencyAvg / sRoundingPadding;
}
void WebrtcVideoConduit::OnRtcpBye() {
RefPtr<WebrtcVideoConduit> self = this;
NS_DispatchToMainThread(media::NewRunnableFrom([self]() mutable {
MOZ_ASSERT(NS_IsMainThread());
if (self->mRtcpEventObserver) {
self->mRtcpEventObserver->OnRtcpBye();
}
return NS_OK;
}));
}
void WebrtcVideoConduit::OnRtcpTimeout() {
RefPtr<WebrtcVideoConduit> self = this;
NS_DispatchToMainThread(media::NewRunnableFrom([self]() mutable {
MOZ_ASSERT(NS_IsMainThread());
if (self->mRtcpEventObserver) {
self->mRtcpEventObserver->OnRtcpTimeout();
}
return NS_OK;
}));
}
void WebrtcVideoConduit::SetRtcpEventObserver(
mozilla::RtcpEventObserver* observer) {
MOZ_ASSERT(NS_IsMainThread());
mRtcpEventObserver = observer;
}
uint64_t WebrtcVideoConduit::CodecPluginID() {
MOZ_ASSERT(NS_IsMainThread());

View File

@ -68,6 +68,7 @@ class WebrtcVideoDecoder : public VideoDecoder, public webrtc::VideoDecoder {};
*/
class WebrtcVideoConduit
: public VideoSessionConduit,
public webrtc::RtcpEventObserver,
public webrtc::Transport,
public webrtc::VideoEncoderFactory,
public rtc::VideoSinkInterface<webrtc::VideoFrame>,
@ -295,6 +296,12 @@ class WebrtcVideoConduit
mRecvStreamStats.RecordTelemetry();
}
void OnRtcpBye() override;
void OnRtcpTimeout() override;
void SetRtcpEventObserver(mozilla::RtcpEventObserver* observer) override;
private:
// Don't allow copying/assigning.
WebrtcVideoConduit(const WebrtcVideoConduit&) = delete;
@ -640,6 +647,9 @@ class WebrtcVideoConduit
// Accessed only on mStsThread
Maybe<DOMHighResTimeStamp> mLastRtcpReceived;
// Accessed only on main thread.
mozilla::RtcpEventObserver* mRtcpEventObserver = nullptr;
};
} // namespace mozilla

View File

@ -59,6 +59,8 @@ TransceiverImpl::TransceiverImpl(
mConduit->SetPCHandle(mPCHandle);
mConduit->SetRtcpEventObserver(this);
mTransmitPipeline =
new MediaPipelineTransmit(mPCHandle, mTransportHandler, mMainThread.get(),
mStsThread.get(), IsVideo(), mConduit);
@ -959,6 +961,7 @@ void TransceiverImpl::Stop() {
if (mConduit) {
mConduit->DeleteStreams();
mConduit->SetRtcpEventObserver(nullptr);
}
mConduit = nullptr;
}
@ -979,6 +982,10 @@ void TransceiverImpl::GetRtpSources(
audio_conduit->GetRtpSources(aTimeNow, outSources);
}
void TransceiverImpl::OnRtcpBye() { SetReceiveTrackMuted(true); }
void TransceiverImpl::OnRtcpTimeout() { SetReceiveTrackMuted(true); }
void TransceiverImpl::InsertAudioLevelForContributingSource(
const uint32_t aSource, const int64_t aTimestamp,
const uint32_t aRtpTimestamp, const bool aHasLevel, const uint8_t aLevel) {

View File

@ -12,6 +12,7 @@
#include "mozilla/dom/MediaStreamTrack.h"
#include "ErrorList.h"
#include "signaling/src/jsep/JsepTransceiver.h"
#include "signaling/src/media-conduit/RtcpEventObserver.h"
class nsIPrincipal;
@ -43,7 +44,7 @@ struct RTCRtpSourceEntry;
* Audio/VideoConduit for feeding RTP/RTCP into webrtc.org for decoding, and
* feeding audio/video frames into webrtc.org for encoding into RTP/RTCP.
*/
class TransceiverImpl : public nsISupports {
class TransceiverImpl : public nsISupports, public RtcpEventObserver {
public:
/**
* |aReceiveTrack| is always set; this holds even if the remote end has not
@ -119,6 +120,10 @@ class TransceiverImpl : public nsISupports {
void GetRtpSources(const int64_t aTimeNow,
nsTArray<dom::RTCRtpSourceEntry>& outSources) const;
void OnRtcpBye() override;
void OnRtcpTimeout() override;
// test-only: insert fake CSRCs and audio levels for testing
void InsertAudioLevelForContributingSource(const uint32_t aSource,
const int64_t aTimestamp,