Skip to content

Commit

Permalink
Remove 'secondary sink' concept from webrtc::VideoReceiveStream.
Browse files Browse the repository at this point in the history
In practice, support for multiple sinks is not needed and supporting
the API that allows for dynamically adding/removing sinks at runtime,
adds to the complexity of the implementation.

This CL removes that Add/Remove methods for secondary sinks as well
as vectors of callback pointers (which were either of size 0 or 1).
Instead, an optional callback pointer is added to the config struct
for VideoReceiveStream, that an implementation can consider to be
const and there's not a need to do thread synchronization for that
pointer for every network packet.

As part of webrtc:11993, this simplifies the work towards keeping
the processing of network packets on the network thread. The secondary
sinks, currently operate on the worker thread.

Bug: webrtc:11993
Change-Id: I10c473e57d3809527a1b689f4352e903a4c78168
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/207421
Commit-Queue: Tommi <[email protected]>
Reviewed-by: Rasmus Brandt <[email protected]>
Cr-Commit-Position: refs/heads/master@{#33272}
  • Loading branch information
Tomas Gunnarsson authored and Commit Bot committed Feb 15, 2021
1 parent a33f41b commit 8408c99
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 272 deletions.
21 changes: 14 additions & 7 deletions call/video_receive_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ class VideoReceiveStream {
// Set if the stream is protected using FlexFEC.
bool protected_by_flexfec = false;

// Optional callback sink to support additional packet handlsers such as
// FlexFec.
RtpPacketSinkInterface* packet_sink_ = nullptr;

// Map from rtx payload type -> media payload type.
// For RTX to be enabled, both an SSRC and this mapping are needed.
std::map<int, int> rtx_associated_payload_types;
Expand Down Expand Up @@ -277,13 +281,6 @@ class VideoReceiveStream {
// TODO(pbos): Add info on currently-received codec to Stats.
virtual Stats GetStats() const = 0;

// RtpDemuxer only forwards a given RTP packet to one sink. However, some
// sinks, such as FlexFEC, might wish to be informed of all of the packets
// a given sink receives (or any set of sinks). They may do so by registering
// themselves as secondary sinks.
virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;

virtual std::vector<RtpSource> GetSources() const = 0;

// Sets a base minimum for the playout delay. Base minimum delay sets lower
Expand Down Expand Up @@ -324,6 +321,16 @@ class VideoReceiveStream {
virtual ~VideoReceiveStream() {}
};

class DEPRECATED_VideoReceiveStream : public VideoReceiveStream {
public:
// RtpDemuxer only forwards a given RTP packet to one sink. However, some
// sinks, such as FlexFEC, might wish to be informed of all of the packets
// a given sink receives (or any set of sinks). They may do so by registering
// themselves as secondary sinks.
virtual void AddSecondarySink(RtpPacketSinkInterface* sink) = 0;
virtual void RemoveSecondarySink(const RtpPacketSinkInterface* sink) = 0;
};

} // namespace webrtc

#endif // CALL_VIDEO_RECEIVE_STREAM_H_
23 changes: 1 addition & 22 deletions media/engine/fake_webrtc_call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,7 @@ void FakeVideoSendStream::InjectVideoSinkWants(

FakeVideoReceiveStream::FakeVideoReceiveStream(
webrtc::VideoReceiveStream::Config config)
: config_(std::move(config)),
receiving_(false),
num_added_secondary_sinks_(0),
num_removed_secondary_sinks_(0) {}
: config_(std::move(config)), receiving_(false) {}

const webrtc::VideoReceiveStream::Config& FakeVideoReceiveStream::GetConfig()
const {
Expand Down Expand Up @@ -361,24 +358,6 @@ void FakeVideoReceiveStream::SetStats(
stats_ = stats;
}

void FakeVideoReceiveStream::AddSecondarySink(
webrtc::RtpPacketSinkInterface* sink) {
++num_added_secondary_sinks_;
}

void FakeVideoReceiveStream::RemoveSecondarySink(
const webrtc::RtpPacketSinkInterface* sink) {
++num_removed_secondary_sinks_;
}

int FakeVideoReceiveStream::GetNumAddedSecondarySinks() const {
return num_added_secondary_sinks_;
}

int FakeVideoReceiveStream::GetNumRemovedSecondarySinks() const {
return num_removed_secondary_sinks_;
}

FakeFlexfecReceiveStream::FakeFlexfecReceiveStream(
const webrtc::FlexfecReceiveStream::Config& config)
: config_(config) {}
Expand Down
9 changes: 0 additions & 9 deletions media/engine/fake_webrtc_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,6 @@ class FakeVideoReceiveStream final : public webrtc::VideoReceiveStream {

void SetStats(const webrtc::VideoReceiveStream::Stats& stats);

void AddSecondarySink(webrtc::RtpPacketSinkInterface* sink) override;
void RemoveSecondarySink(const webrtc::RtpPacketSinkInterface* sink) override;

int GetNumAddedSecondarySinks() const;
int GetNumRemovedSecondarySinks() const;

std::vector<webrtc::RtpSource> GetSources() const override {
return std::vector<webrtc::RtpSource>();
}
Expand Down Expand Up @@ -267,9 +261,6 @@ class FakeVideoReceiveStream final : public webrtc::VideoReceiveStream {
webrtc::VideoReceiveStream::Stats stats_;

int base_mininum_playout_delay_ms_ = 0;

int num_added_secondary_sinks_;
int num_removed_secondary_sinks_;
};

class FakeFlexfecReceiveStream final : public webrtc::FlexfecReceiveStream {
Expand Down
94 changes: 31 additions & 63 deletions media/engine/webrtc_video_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,11 @@ WebRtcVideoEngine::WebRtcVideoEngine(
: decoder_factory_(std::move(video_decoder_factory)),
encoder_factory_(std::move(video_encoder_factory)),
trials_(trials) {
RTC_LOG(LS_INFO) << "WebRtcVideoEngine::WebRtcVideoEngine()";
RTC_DLOG(LS_INFO) << "WebRtcVideoEngine::WebRtcVideoEngine()";
}

WebRtcVideoEngine::~WebRtcVideoEngine() {
RTC_LOG(LS_INFO) << "WebRtcVideoEngine::~WebRtcVideoEngine";
RTC_DLOG(LS_INFO) << "WebRtcVideoEngine::~WebRtcVideoEngine";
}

VideoMediaChannel* WebRtcVideoEngine::CreateMediaChannel(
Expand Down Expand Up @@ -1214,25 +1214,25 @@ bool WebRtcVideoChannel::GetChangedRecvParameters(
bool WebRtcVideoChannel::SetRecvParameters(const VideoRecvParameters& params) {
RTC_DCHECK_RUN_ON(&thread_checker_);
TRACE_EVENT0("webrtc", "WebRtcVideoChannel::SetRecvParameters");
RTC_LOG(LS_INFO) << "SetRecvParameters: " << params.ToString();
RTC_DLOG(LS_INFO) << "SetRecvParameters: " << params.ToString();
ChangedRecvParameters changed_params;
if (!GetChangedRecvParameters(params, &changed_params)) {
return false;
}
if (changed_params.flexfec_payload_type) {
RTC_LOG(LS_INFO) << "Changing FlexFEC payload type (recv) from "
<< recv_flexfec_payload_type_ << " to "
<< *changed_params.flexfec_payload_type;
RTC_DLOG(LS_INFO) << "Changing FlexFEC payload type (recv) from "
<< recv_flexfec_payload_type_ << " to "
<< *changed_params.flexfec_payload_type;
recv_flexfec_payload_type_ = *changed_params.flexfec_payload_type;
}
if (changed_params.rtp_header_extensions) {
recv_rtp_extensions_ = *changed_params.rtp_header_extensions;
}
if (changed_params.codec_settings) {
RTC_LOG(LS_INFO) << "Changing recv codecs from "
<< CodecSettingsVectorToString(recv_codecs_) << " to "
<< CodecSettingsVectorToString(
*changed_params.codec_settings);
RTC_DLOG(LS_INFO) << "Changing recv codecs from "
<< CodecSettingsVectorToString(recv_codecs_) << " to "
<< CodecSettingsVectorToString(
*changed_params.codec_settings);
recv_codecs_ = *changed_params.codec_settings;
}

Expand Down Expand Up @@ -2782,17 +2782,14 @@ WebRtcVideoChannel::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream(
estimated_remote_start_ntp_time_ms_(0) {
config_.renderer = this;
ConfigureCodecs(recv_codecs);
ConfigureFlexfecCodec(flexfec_config.payload_type);
MaybeRecreateWebRtcFlexfecStream();
flexfec_config_.payload_type = flexfec_config.payload_type;
RecreateWebRtcVideoStream();
}

WebRtcVideoChannel::WebRtcVideoReceiveStream::~WebRtcVideoReceiveStream() {
if (flexfec_stream_) {
MaybeDissociateFlexfecFromVideo();
call_->DestroyFlexfecReceiveStream(flexfec_stream_);
}
call_->DestroyVideoReceiveStream(stream_);
if (flexfec_stream_)
call_->DestroyFlexfecReceiveStream(flexfec_stream_);
}

const std::vector<uint32_t>&
Expand Down Expand Up @@ -2862,11 +2859,6 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream::ConfigureCodecs(
}
}

void WebRtcVideoChannel::WebRtcVideoReceiveStream::ConfigureFlexfecCodec(
int flexfec_payload_type) {
flexfec_config_.payload_type = flexfec_payload_type;
}

void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetLocalSsrc(
uint32_t local_ssrc) {
// TODO(pbos): Consider turning this sanity check into a RTC_DCHECK. You
Expand All @@ -2885,7 +2877,6 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetLocalSsrc(
RTC_LOG(LS_INFO)
<< "RecreateWebRtcVideoStream (recv) because of SetLocalSsrc; local_ssrc="
<< local_ssrc;
MaybeRecreateWebRtcFlexfecStream();
RecreateWebRtcVideoStream();
}

Expand Down Expand Up @@ -2917,14 +2908,12 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetFeedbackParameters(
RTC_LOG(LS_INFO) << "RecreateWebRtcVideoStream (recv) because of "
"SetFeedbackParameters; nack="
<< nack_enabled << ", transport_cc=" << transport_cc_enabled;
MaybeRecreateWebRtcFlexfecStream();
RecreateWebRtcVideoStream();
}

void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetRecvParameters(
const ChangedRecvParameters& params) {
bool video_needs_recreation = false;
bool flexfec_needs_recreation = false;
if (params.codec_settings) {
ConfigureCodecs(*params.codec_settings);
video_needs_recreation = true;
Expand All @@ -2933,20 +2922,16 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetRecvParameters(
config_.rtp.extensions = *params.rtp_header_extensions;
flexfec_config_.rtp_header_extensions = *params.rtp_header_extensions;
video_needs_recreation = true;
flexfec_needs_recreation = true;
}
if (params.flexfec_payload_type) {
ConfigureFlexfecCodec(*params.flexfec_payload_type);
flexfec_needs_recreation = true;
}
if (flexfec_needs_recreation) {
RTC_LOG(LS_INFO) << "MaybeRecreateWebRtcFlexfecStream (recv) because of "
"SetRecvParameters";
MaybeRecreateWebRtcFlexfecStream();
flexfec_config_.payload_type = *params.flexfec_payload_type;
// TODO(tommi): See if it is better to always have a flexfec stream object
// configured and instead of recreating the video stream, reconfigure the
// flexfec object from within the rtp callback (soon to be on the network
// thread).
video_needs_recreation = true;
}
if (video_needs_recreation) {
RTC_LOG(LS_INFO)
<< "RecreateWebRtcVideoStream (recv) because of SetRecvParameters";
RecreateWebRtcVideoStream();
}
}
Expand All @@ -2959,12 +2944,22 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream::RecreateWebRtcVideoStream() {
recording_state = stream_->SetAndGetRecordingState(
webrtc::VideoReceiveStream::RecordingState(),
/*generate_key_frame=*/false);
MaybeDissociateFlexfecFromVideo();
call_->DestroyVideoReceiveStream(stream_);
stream_ = nullptr;
}

if (flexfec_stream_) {
call_->DestroyFlexfecReceiveStream(flexfec_stream_);
flexfec_stream_ = nullptr;
}

if (flexfec_config_.IsCompleteAndEnabled()) {
flexfec_stream_ = call_->CreateFlexfecReceiveStream(flexfec_config_);
}

webrtc::VideoReceiveStream::Config config = config_.Copy();
config.rtp.protected_by_flexfec = (flexfec_stream_ != nullptr);
config.rtp.packet_sink_ = flexfec_stream_;
config.stream_id = stream_params_.id;
stream_ = call_->CreateVideoReceiveStream(std::move(config));
if (base_minimum_playout_delay_ms) {
Expand All @@ -2975,41 +2970,14 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream::RecreateWebRtcVideoStream() {
stream_->SetAndGetRecordingState(std::move(*recording_state),
/*generate_key_frame=*/false);
}
MaybeAssociateFlexfecWithVideo();

stream_->Start();

if (IsEnabled(call_->trials(), "WebRTC-Video-BufferPacketsWithUnknownSsrc")) {
channel_->BackfillBufferedPackets(stream_params_.ssrcs);
}
}

void WebRtcVideoChannel::WebRtcVideoReceiveStream::
MaybeRecreateWebRtcFlexfecStream() {
if (flexfec_stream_) {
MaybeDissociateFlexfecFromVideo();
call_->DestroyFlexfecReceiveStream(flexfec_stream_);
flexfec_stream_ = nullptr;
}
if (flexfec_config_.IsCompleteAndEnabled()) {
flexfec_stream_ = call_->CreateFlexfecReceiveStream(flexfec_config_);
MaybeAssociateFlexfecWithVideo();
}
}

void WebRtcVideoChannel::WebRtcVideoReceiveStream::
MaybeAssociateFlexfecWithVideo() {
if (stream_ && flexfec_stream_) {
stream_->AddSecondarySink(flexfec_stream_);
}
}

void WebRtcVideoChannel::WebRtcVideoReceiveStream::
MaybeDissociateFlexfecFromVideo() {
if (stream_ && flexfec_stream_) {
stream_->RemoveSecondarySink(flexfec_stream_);
}
}

void WebRtcVideoChannel::WebRtcVideoReceiveStream::OnFrame(
const webrtc::VideoFrame& frame) {
webrtc::MutexLock lock(&sink_lock_);
Expand Down
5 changes: 0 additions & 5 deletions media/engine/webrtc_video_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,8 @@ class WebRtcVideoChannel : public VideoMediaChannel,

private:
void RecreateWebRtcVideoStream();
void MaybeRecreateWebRtcFlexfecStream();

void MaybeAssociateFlexfecWithVideo();
void MaybeDissociateFlexfecFromVideo();

void ConfigureCodecs(const std::vector<VideoCodecSettings>& recv_codecs);
void ConfigureFlexfecCodec(int flexfec_payload_type);

std::string GetCodecNameFromPayloadType(int payload_type);

Expand Down
Loading

0 comments on commit 8408c99

Please sign in to comment.