2017-06-12 01:16:46 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#ifndef MEDIA_ENGINE_WEBRTC_VIDEO_ENGINE_H_
|
|
|
|
|
#define MEDIA_ENGINE_WEBRTC_VIDEO_ENGINE_H_
|
2017-06-12 01:16:46 -07:00
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2018-06-15 15:58:38 +02:00
|
|
|
#include "absl/types/optional.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/call/transport.h"
|
2021-02-10 14:31:24 +01:00
|
|
|
#include "api/sequence_checker.h"
|
2022-06-16 21:27:45 +02:00
|
|
|
#include "api/task_queue/pending_task_safety_flag.h"
|
2020-09-22 11:36:35 +02:00
|
|
|
#include "api/transport/field_trial_based_config.h"
|
2018-11-08 10:02:56 -08:00
|
|
|
#include "api/video/video_bitrate_allocator_factory.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video/video_frame.h"
|
2018-05-11 11:15:30 +02:00
|
|
|
#include "api/video/video_sink_interface.h"
|
2018-05-21 14:09:31 +02:00
|
|
|
#include "api/video/video_source_interface.h"
|
|
|
|
|
#include "api/video_codecs/sdp_video_format.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "call/call.h"
|
|
|
|
|
#include "call/flexfec_receive_stream.h"
|
|
|
|
|
#include "call/video_receive_stream.h"
|
|
|
|
|
#include "call/video_send_stream.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "media/base/media_engine.h"
|
2019-03-18 10:59:40 +01:00
|
|
|
#include "media/engine/unhandled_packets_buffer.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/network_route.h"
|
2020-07-07 15:43:11 +02:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2022-08-16 10:23:47 +02:00
|
|
|
#include "rtc_base/system/no_unique_address.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/thread_annotations.h"
|
2017-06-12 01:16:46 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2017-09-14 10:24:54 +02:00
|
|
|
class VideoDecoderFactory;
|
|
|
|
|
class VideoEncoderFactory;
|
2017-06-12 01:16:46 -07:00
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
class WebRtcVideoChannel;
|
|
|
|
|
|
[Stats] Explicit RTP-RTX and RTP-FEC mappings. Unblocks simulcast stats.
--- Background ---
The webrtc::VideoSendStream::StreamStats are converted into
VideoSenderInfo objects which turn into "outbound-rtp" stats objects in
getStats() (or "ssrc" objects in legacy getStats()).
StreamStats are created for each type of substream: RTP media streams,
RTX streams and FlexFEC streams - each with individual packet counters.
The RTX stream is responsible for retransmissions of a referenced media
stream and the FlexFEC stream is responsible for FEC of a referenced
media stream. RTX/FEC streams do not show up as separate objects in
getStats(). Only the media streams become "outbound-rtp" objects, but
their packet and byte counters have to include the RTX and FEC counters.
--- Overview of this CL ---
This CL adds MergeInfoAboutOutboundRtpSubstreams(). It takes
StreamStats of all kinds as input, and outputs media-only StreamStats
- incorporating the RTX and FEC counters into the relevant media
StreamStats.
The merged StreamStats objects is a smaller set of objects than the
non-merged counterparts, but when aggregating all packet counters
together we end up with exact same packet and count as before.
Because WebRtcVideoSendStream::GetVideoSenderInfo() currently aggregates
the StreamStats into a single VideoSenderInfo (single "outbound-rtp"),
this CL should not have any observable side-effects. Prior to this CL:
aggregate StreamStats. After this CL: merge StreamStats and then
aggregate them.
However, when simulcast stats are implemented (WIP CL:
https://webrtc-review.googlesource.com/c/src/+/168120) each RTP media
stream should turn into an individual "outbound-rtp" object. We will
then no longer aggregate all StreamStats into a single "info". This CL
unblocks simulcast stats by providing StreamStats objects that could be
turned into individual VideoSenderInfos.
--- The Changes ---
1. Methods added to RtpConfig to be able to easily tell the relationship
between RTP, RTX and FEC ssrcs.
2. StreamStats gets a StreamType (kMedia, kRtx or kFlexfec) that
replaces the booleans (is_rtx, is_flexfec).
3. "referenced_media_ssrc" is added to StreamStats, making it possible
to tell which kRtx/kFlexFec stream stats need to be merged with which
kMedia StreamStats.
4. MergeInfoAboutOutboundRtpSubstreams() added and used.
Bug: webrtc:11439
Change-Id: Iaf9002041169a054ddfd32c7ea06bd1dc36c6bca
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170826
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30869}
2020-03-24 13:30:50 +01:00
|
|
|
// Public for testing.
|
|
|
|
|
// Inputs StreamStats for all types of substreams (kMedia, kRtx, kFlexfec) and
|
|
|
|
|
// merges any non-kMedia substream stats object into its referenced kMedia-type
|
|
|
|
|
// substream. The resulting substreams are all kMedia. This means, for example,
|
|
|
|
|
// that packet and byte counters of RTX and FlexFEC streams are accounted for in
|
|
|
|
|
// the relevant RTP media stream's stats. This makes the resulting StreamStats
|
|
|
|
|
// objects ready to be turned into "outbound-rtp" stats objects for GetStats()
|
|
|
|
|
// which does not create separate stream stats objects for complementary
|
|
|
|
|
// streams.
|
|
|
|
|
std::map<uint32_t, webrtc::VideoSendStream::StreamStats>
|
|
|
|
|
MergeInfoAboutOutboundRtpSubstreamsForTesting(
|
|
|
|
|
const std::map<uint32_t, webrtc::VideoSendStream::StreamStats>& substreams);
|
|
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
class UnsignalledSsrcHandler {
|
|
|
|
|
public:
|
|
|
|
|
enum Action {
|
|
|
|
|
kDropPacket,
|
|
|
|
|
kDeliverPacket,
|
|
|
|
|
};
|
|
|
|
|
virtual Action OnUnsignalledSsrc(WebRtcVideoChannel* channel,
|
|
|
|
|
uint32_t ssrc) = 0;
|
|
|
|
|
virtual ~UnsignalledSsrcHandler() = default;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO(pbos): Remove, use external handlers only.
|
|
|
|
|
class DefaultUnsignalledSsrcHandler : public UnsignalledSsrcHandler {
|
|
|
|
|
public:
|
|
|
|
|
DefaultUnsignalledSsrcHandler();
|
|
|
|
|
Action OnUnsignalledSsrc(WebRtcVideoChannel* channel, uint32_t ssrc) override;
|
|
|
|
|
|
|
|
|
|
rtc::VideoSinkInterface<webrtc::VideoFrame>* GetDefaultSink() const;
|
|
|
|
|
void SetDefaultSink(WebRtcVideoChannel* channel,
|
|
|
|
|
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
|
|
|
|
|
|
|
|
|
|
virtual ~DefaultUnsignalledSsrcHandler() = default;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
rtc::VideoSinkInterface<webrtc::VideoFrame>* default_sink_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// WebRtcVideoEngine is used for the new native WebRTC Video API (webrtc:1667).
|
2018-11-16 10:40:36 +01:00
|
|
|
class WebRtcVideoEngine : public VideoEngineInterface {
|
2017-06-12 01:16:46 -07:00
|
|
|
public:
|
2017-09-14 10:24:54 +02:00
|
|
|
// These video codec factories represents all video codecs, i.e. both software
|
|
|
|
|
// and external hardware codecs.
|
|
|
|
|
WebRtcVideoEngine(
|
|
|
|
|
std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory,
|
2020-09-22 11:36:35 +02:00
|
|
|
std::unique_ptr<webrtc::VideoDecoderFactory> video_decoder_factory,
|
2022-03-29 11:04:48 +02:00
|
|
|
const webrtc::FieldTrialsView& trials);
|
2017-09-14 10:24:54 +02:00
|
|
|
|
2018-11-16 10:40:36 +01:00
|
|
|
~WebRtcVideoEngine() override;
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2018-11-16 10:40:36 +01:00
|
|
|
VideoMediaChannel* CreateMediaChannel(
|
2018-10-15 10:20:24 -07:00
|
|
|
webrtc::Call* call,
|
|
|
|
|
const MediaConfig& config,
|
|
|
|
|
const VideoOptions& options,
|
2019-04-17 07:38:40 +02:00
|
|
|
const webrtc::CryptoOptions& crypto_options,
|
|
|
|
|
webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory)
|
|
|
|
|
override;
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2022-05-22 10:57:01 +00:00
|
|
|
std::vector<VideoCodec> send_codecs() const override {
|
|
|
|
|
return send_codecs(true);
|
|
|
|
|
}
|
|
|
|
|
std::vector<VideoCodec> recv_codecs() const override {
|
|
|
|
|
return recv_codecs(true);
|
|
|
|
|
}
|
|
|
|
|
std::vector<VideoCodec> send_codecs(bool include_rtx) const override;
|
|
|
|
|
std::vector<VideoCodec> recv_codecs(bool include_rtx) const override;
|
2020-03-16 13:40:51 +01:00
|
|
|
std::vector<webrtc::RtpHeaderExtensionCapability> GetRtpHeaderExtensions()
|
|
|
|
|
const override;
|
2017-06-12 01:16:46 -07:00
|
|
|
|
|
|
|
|
private:
|
2018-09-03 18:07:56 +02:00
|
|
|
const std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory_;
|
2017-10-31 11:24:54 +01:00
|
|
|
const std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory_;
|
2018-11-08 10:02:56 -08:00
|
|
|
const std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>
|
|
|
|
|
bitrate_allocator_factory_;
|
2022-03-29 11:04:48 +02:00
|
|
|
const webrtc::FieldTrialsView& trials_;
|
2017-06-12 01:16:46 -07:00
|
|
|
};
|
|
|
|
|
|
2019-07-03 11:53:48 +02:00
|
|
|
class WebRtcVideoChannel : public VideoMediaChannel,
|
|
|
|
|
public webrtc::Transport,
|
2019-09-16 14:53:40 +02:00
|
|
|
public webrtc::EncoderSwitchRequestCallback {
|
2017-06-12 01:16:46 -07:00
|
|
|
public:
|
2018-11-08 10:02:56 -08:00
|
|
|
WebRtcVideoChannel(
|
|
|
|
|
webrtc::Call* call,
|
|
|
|
|
const MediaConfig& config,
|
|
|
|
|
const VideoOptions& options,
|
|
|
|
|
const webrtc::CryptoOptions& crypto_options,
|
|
|
|
|
webrtc::VideoEncoderFactory* encoder_factory,
|
|
|
|
|
webrtc::VideoDecoderFactory* decoder_factory,
|
|
|
|
|
webrtc::VideoBitrateAllocatorFactory* bitrate_allocator_factory);
|
2017-06-12 01:16:46 -07:00
|
|
|
~WebRtcVideoChannel() override;
|
|
|
|
|
|
|
|
|
|
// VideoMediaChannel implementation
|
|
|
|
|
bool SetSendParameters(const VideoSendParameters& params) override;
|
|
|
|
|
bool SetRecvParameters(const VideoRecvParameters& params) override;
|
|
|
|
|
webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
|
2018-01-23 15:02:36 -08:00
|
|
|
webrtc::RTCError SetRtpSendParameters(
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
const webrtc::RtpParameters& parameters) override;
|
2017-06-12 01:16:46 -07:00
|
|
|
webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const override;
|
2019-12-04 09:31:36 -08:00
|
|
|
webrtc::RtpParameters GetDefaultRtpReceiveParameters() const override;
|
2017-06-12 01:16:46 -07:00
|
|
|
bool GetSendCodec(VideoCodec* send_codec) override;
|
|
|
|
|
bool SetSend(bool send) override;
|
|
|
|
|
bool SetVideoSend(
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
const VideoOptions* options,
|
|
|
|
|
rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override;
|
|
|
|
|
bool AddSendStream(const StreamParams& sp) override;
|
|
|
|
|
bool RemoveSendStream(uint32_t ssrc) override;
|
|
|
|
|
bool AddRecvStream(const StreamParams& sp) override;
|
|
|
|
|
bool AddRecvStream(const StreamParams& sp, bool default_stream);
|
|
|
|
|
bool RemoveRecvStream(uint32_t ssrc) override;
|
2019-09-20 11:05:30 -07:00
|
|
|
void ResetUnsignaledRecvStream() override;
|
2021-04-16 09:54:18 +02:00
|
|
|
void OnDemuxerCriteriaUpdatePending() override;
|
|
|
|
|
void OnDemuxerCriteriaUpdateComplete() override;
|
2017-06-12 01:16:46 -07:00
|
|
|
bool SetSink(uint32_t ssrc,
|
|
|
|
|
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
|
2019-12-04 09:31:36 -08:00
|
|
|
void SetDefaultSink(
|
|
|
|
|
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
|
2017-06-12 01:16:46 -07:00
|
|
|
void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override;
|
|
|
|
|
bool GetStats(VideoMediaInfo* info) override;
|
|
|
|
|
|
2019-03-12 11:10:27 -07:00
|
|
|
void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
|
2018-11-05 13:01:41 +01:00
|
|
|
int64_t packet_time_us) override;
|
2021-04-19 12:53:09 +02:00
|
|
|
void OnPacketSent(const rtc::SentPacket& sent_packet) override;
|
2017-06-12 01:16:46 -07:00
|
|
|
void OnReadyToSend(bool ready) override;
|
2022-01-03 14:59:12 +00:00
|
|
|
void OnNetworkRouteChanged(absl::string_view transport_name,
|
2017-06-12 01:16:46 -07:00
|
|
|
const rtc::NetworkRoute& network_route) override;
|
2020-06-16 16:39:13 +02:00
|
|
|
void SetInterface(NetworkInterface* iface) override;
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2018-10-17 17:27:25 -07:00
|
|
|
// E2E Encrypted Video Frame API
|
|
|
|
|
// Set a frame decryptor to a particular ssrc that will intercept all
|
|
|
|
|
// incoming video frames and attempt to decrypt them before forwarding the
|
|
|
|
|
// result.
|
|
|
|
|
void SetFrameDecryptor(uint32_t ssrc,
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameDecryptorInterface>
|
|
|
|
|
frame_decryptor) override;
|
|
|
|
|
// Set a frame encryptor to a particular ssrc that will intercept all
|
|
|
|
|
// outgoing video frames and attempt to encrypt them and forward the result
|
|
|
|
|
// to the packetizer.
|
|
|
|
|
void SetFrameEncryptor(uint32_t ssrc,
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameEncryptorInterface>
|
|
|
|
|
frame_encryptor) override;
|
|
|
|
|
|
2022-06-08 11:25:46 +02:00
|
|
|
// note: The encoder_selector object must remain valid for the lifetime of the
|
|
|
|
|
// MediaChannel, unless replaced.
|
|
|
|
|
void SetEncoderSelector(uint32_t ssrc,
|
|
|
|
|
webrtc::VideoEncoderFactory::EncoderSelectorInterface*
|
|
|
|
|
encoder_selector) override;
|
|
|
|
|
|
2019-10-25 12:23:02 +02:00
|
|
|
void SetVideoCodecSwitchingEnabled(bool enabled) override;
|
|
|
|
|
|
2019-02-27 15:32:48 +01:00
|
|
|
bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override;
|
|
|
|
|
|
|
|
|
|
absl::optional<int> GetBaseMinimumPlayoutDelayMs(
|
|
|
|
|
uint32_t ssrc) const override;
|
|
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
// Implemented for VideoMediaChannelTest.
|
2019-03-01 15:15:38 -08:00
|
|
|
bool sending() const {
|
|
|
|
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
|
|
|
|
return sending_;
|
|
|
|
|
}
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2018-06-15 15:58:38 +02:00
|
|
|
absl::optional<uint32_t> GetDefaultReceiveStreamSsrc();
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2019-03-01 15:15:38 -08:00
|
|
|
StreamParams unsignaled_stream_params() {
|
|
|
|
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
|
|
|
|
return unsignaled_stream_params_;
|
|
|
|
|
}
|
2018-04-03 11:16:33 -07:00
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
// AdaptReason is used for expressing why a WebRtcVideoSendStream request
|
|
|
|
|
// a lower input frame size than the currently configured camera input frame
|
|
|
|
|
// size. There can be more than one reason OR:ed together.
|
|
|
|
|
enum AdaptReason {
|
|
|
|
|
ADAPTREASON_NONE = 0,
|
|
|
|
|
ADAPTREASON_CPU = 1,
|
|
|
|
|
ADAPTREASON_BANDWIDTH = 2,
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-15 06:34:42 -07:00
|
|
|
static constexpr int kDefaultQpMax = 56;
|
|
|
|
|
|
2018-09-26 16:04:32 +02:00
|
|
|
std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override;
|
|
|
|
|
|
2021-07-26 13:24:57 +02:00
|
|
|
// Take the buffered packets for `ssrcs` and feed them into DeliverPacket.
|
2019-03-18 10:59:40 +01:00
|
|
|
// This method does nothing unless unknown_ssrc_packet_buffer_ is configured.
|
|
|
|
|
void BackfillBufferedPackets(rtc::ArrayView<const uint32_t> ssrcs);
|
|
|
|
|
|
2019-09-16 14:53:40 +02:00
|
|
|
// Implements webrtc::EncoderSwitchRequestCallback.
|
|
|
|
|
void RequestEncoderFallback() override;
|
2022-01-21 11:35:04 +01:00
|
|
|
void RequestEncoderSwitch(const webrtc::SdpVideoFormat& format,
|
|
|
|
|
bool allow_default_fallback) override;
|
2019-12-04 09:31:36 -08:00
|
|
|
|
2019-12-04 10:58:17 +01:00
|
|
|
void SetRecordableEncodedFrameCallback(
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
std::function<void(const webrtc::RecordableEncodedFrame&)> callback)
|
|
|
|
|
override;
|
|
|
|
|
void ClearRecordableEncodedFrameCallback(uint32_t ssrc) override;
|
|
|
|
|
void GenerateKeyFrame(uint32_t ssrc) override;
|
2019-07-03 11:53:48 +02:00
|
|
|
|
2020-02-27 16:16:55 +01:00
|
|
|
void SetEncoderToPacketizerFrameTransformer(
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
|
|
|
|
|
override;
|
2020-02-28 16:02:06 +01:00
|
|
|
void SetDepacketizerToDecoderFrameTransformer(
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
|
|
|
|
|
override;
|
2020-02-27 16:16:55 +01:00
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
private:
|
|
|
|
|
class WebRtcVideoReceiveStream;
|
2019-12-04 10:58:17 +01:00
|
|
|
|
2022-05-20 15:21:20 +02:00
|
|
|
// Finds VideoReceiveStreamInterface corresponding to ssrc. Aware of
|
|
|
|
|
// unsignalled ssrc handling.
|
2019-12-04 10:58:17 +01:00
|
|
|
WebRtcVideoReceiveStream* FindReceiveStream(uint32_t ssrc)
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
|
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
struct VideoCodecSettings {
|
|
|
|
|
VideoCodecSettings();
|
|
|
|
|
|
|
|
|
|
// Checks if all members of |*this| are equal to the corresponding members
|
2021-07-26 13:24:57 +02:00
|
|
|
// of `other`.
|
2017-06-12 01:16:46 -07:00
|
|
|
bool operator==(const VideoCodecSettings& other) const;
|
|
|
|
|
bool operator!=(const VideoCodecSettings& other) const;
|
|
|
|
|
|
2021-07-26 13:24:57 +02:00
|
|
|
// Checks if all members of `a`, except `flexfec_payload_type`, are equal
|
|
|
|
|
// to the corresponding members of `b`.
|
2017-06-12 01:16:46 -07:00
|
|
|
static bool EqualsDisregardingFlexfec(const VideoCodecSettings& a,
|
|
|
|
|
const VideoCodecSettings& b);
|
|
|
|
|
|
|
|
|
|
VideoCodec codec;
|
|
|
|
|
webrtc::UlpfecConfig ulpfec;
|
2019-08-07 09:57:59 -07:00
|
|
|
int flexfec_payload_type; // -1 if absent.
|
|
|
|
|
int rtx_payload_type; // -1 if absent.
|
2021-03-24 17:49:02 +01:00
|
|
|
int rtx_time; // -1 if absent.
|
2017-06-12 01:16:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ChangedSendParameters {
|
|
|
|
|
// These optionals are unset if not changed.
|
2019-07-03 11:53:48 +02:00
|
|
|
absl::optional<VideoCodecSettings> send_codec;
|
|
|
|
|
absl::optional<std::vector<VideoCodecSettings>> negotiated_codecs;
|
2018-06-15 15:58:38 +02:00
|
|
|
absl::optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions;
|
|
|
|
|
absl::optional<std::string> mid;
|
2018-10-29 11:22:05 +01:00
|
|
|
absl::optional<bool> extmap_allow_mixed;
|
2018-06-15 15:58:38 +02:00
|
|
|
absl::optional<int> max_bandwidth_bps;
|
|
|
|
|
absl::optional<bool> conference_mode;
|
|
|
|
|
absl::optional<webrtc::RtcpMode> rtcp_mode;
|
2017-06-12 01:16:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ChangedRecvParameters {
|
|
|
|
|
// These optionals are unset if not changed.
|
2018-06-15 15:58:38 +02:00
|
|
|
absl::optional<std::vector<VideoCodecSettings>> codec_settings;
|
|
|
|
|
absl::optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions;
|
2021-07-26 13:24:57 +02:00
|
|
|
// Keep track of the FlexFEC payload type separately from `codec_settings`.
|
2017-06-12 01:16:46 -07:00
|
|
|
// This allows us to recreate the FlexfecReceiveStream separately from the
|
2022-05-20 15:21:20 +02:00
|
|
|
// VideoReceiveStreamInterface when the FlexFEC payload type is changed.
|
2018-06-15 15:58:38 +02:00
|
|
|
absl::optional<int> flexfec_payload_type;
|
2017-06-12 01:16:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool GetChangedSendParameters(const VideoSendParameters& params,
|
2019-03-01 15:15:38 -08:00
|
|
|
ChangedSendParameters* changed_params) const
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
2019-07-03 11:53:48 +02:00
|
|
|
bool ApplyChangedParams(const ChangedSendParameters& changed_params);
|
2017-06-12 01:16:46 -07:00
|
|
|
bool GetChangedRecvParameters(const VideoRecvParameters& params,
|
2019-03-01 15:15:38 -08:00
|
|
|
ChangedRecvParameters* changed_params) const
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
|
|
|
|
|
void ConfigureReceiverRtp(
|
2022-05-20 15:21:20 +02:00
|
|
|
webrtc::VideoReceiveStreamInterface::Config* config,
|
2017-06-12 01:16:46 -07:00
|
|
|
webrtc::FlexfecReceiveStream::Config* flexfec_config,
|
2019-03-01 15:15:38 -08:00
|
|
|
const StreamParams& sp) const
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
bool ValidateSendSsrcAvailability(const StreamParams& sp) const
|
2019-03-01 15:15:38 -08:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
bool ValidateReceiveSsrcAvailability(const StreamParams& sp) const
|
2019-03-01 15:15:38 -08:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
void DeleteReceiveStream(WebRtcVideoReceiveStream* stream)
|
2019-03-01 15:15:38 -08:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
|
|
|
|
|
static std::string CodecSettingsVectorToString(
|
|
|
|
|
const std::vector<VideoCodecSettings>& codecs);
|
|
|
|
|
|
2022-08-03 14:03:55 +02:00
|
|
|
// Populates `rtx_associated_payload_types`, `raw_payload_types` and
|
|
|
|
|
// `decoders` based on codec settings provided by `recv_codecs`.
|
|
|
|
|
// `recv_codecs` must be non-empty and all other parameters must be empty.
|
|
|
|
|
static void ExtractCodecInformation(
|
|
|
|
|
rtc::ArrayView<const VideoCodecSettings> recv_codecs,
|
|
|
|
|
std::map<int, int>& rtx_associated_payload_types,
|
|
|
|
|
std::set<int>& raw_payload_types,
|
|
|
|
|
std::vector<webrtc::VideoReceiveStreamInterface::Decoder>& decoders);
|
|
|
|
|
|
2022-05-17 10:13:52 +02:00
|
|
|
// Called when the local ssrc changes. Sets `rtcp_receiver_report_ssrc_` and
|
|
|
|
|
// updates the receive streams.
|
|
|
|
|
void SetReceiverReportSsrc(uint32_t ssrc) RTC_RUN_ON(&thread_checker_);
|
|
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
// Wrapper for the sender part.
|
2020-09-22 09:21:34 +02:00
|
|
|
class WebRtcVideoSendStream {
|
2017-06-12 01:16:46 -07:00
|
|
|
public:
|
|
|
|
|
WebRtcVideoSendStream(
|
|
|
|
|
webrtc::Call* call,
|
|
|
|
|
const StreamParams& sp,
|
|
|
|
|
webrtc::VideoSendStream::Config config,
|
|
|
|
|
const VideoOptions& options,
|
|
|
|
|
bool enable_cpu_overuse_detection,
|
|
|
|
|
int max_bitrate_bps,
|
2018-06-15 15:58:38 +02:00
|
|
|
const absl::optional<VideoCodecSettings>& codec_settings,
|
|
|
|
|
const absl::optional<std::vector<webrtc::RtpExtension>>& rtp_extensions,
|
2017-06-12 01:16:46 -07:00
|
|
|
const VideoSendParameters& send_params);
|
2020-09-22 09:21:34 +02:00
|
|
|
~WebRtcVideoSendStream();
|
2017-06-12 01:16:46 -07:00
|
|
|
|
|
|
|
|
void SetSendParameters(const ChangedSendParameters& send_params);
|
2018-01-23 15:02:36 -08:00
|
|
|
webrtc::RTCError SetRtpParameters(const webrtc::RtpParameters& parameters);
|
2017-06-12 01:16:46 -07:00
|
|
|
webrtc::RtpParameters GetRtpParameters() const;
|
|
|
|
|
|
2018-10-17 17:27:25 -07:00
|
|
|
void SetFrameEncryptor(
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor);
|
|
|
|
|
|
2018-04-09 08:49:14 +02:00
|
|
|
bool SetVideoSend(const VideoOptions* options,
|
2017-06-12 01:16:46 -07:00
|
|
|
rtc::VideoSourceInterface<webrtc::VideoFrame>* source);
|
|
|
|
|
|
2022-06-08 11:25:46 +02:00
|
|
|
// note: The encoder_selector object must remain valid for the lifetime of
|
|
|
|
|
// the MediaChannel, unless replaced.
|
|
|
|
|
void SetEncoderSelector(
|
|
|
|
|
webrtc::VideoEncoderFactory::EncoderSelectorInterface*
|
|
|
|
|
encoder_selector);
|
|
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
void SetSend(bool send);
|
|
|
|
|
|
|
|
|
|
const std::vector<uint32_t>& GetSsrcs() const;
|
Reland "Improve outbound-rtp statistics for simulcast"
This reverts commit 9a925c9ce33a6ccdd11b545b11ba68e985c2a65d.
Reason for revert: The original CL is updated in PS #2 to
fix the googRtt issue which was that when the legacy sender
stats were put in "aggregated_senders" we forgot to update
rtt_ms the same way that we do it for "senders".
Original change's description:
> Revert "Improve outbound-rtp statistics for simulcast"
>
> This reverts commit da6cda839dac7d9d18eba8d365188fa94831e0b1.
>
> Reason for revert: Breaks googRtt in legacy getStats API
>
> Original change's description:
> > Improve outbound-rtp statistics for simulcast
> >
> > Bug: webrtc:9547
> > Change-Id: Iec4eb976aa11ee743805425bedb77dcea7c2c9be
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168120
> > Reviewed-by: Sebastian Jansson <srte@webrtc.org>
> > Reviewed-by: Erik Språng <sprang@webrtc.org>
> > Reviewed-by: Henrik Boström <hbos@webrtc.org>
> > Reviewed-by: Harald Alvestrand <hta@webrtc.org>
> > Commit-Queue: Eldar Rello <elrello@microsoft.com>
> > Cr-Commit-Position: refs/heads/master@{#31097}
>
> TBR=hbos@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,srte@webrtc.org,hta@webrtc.org,elrello@microsoft.com
>
> # Not skipping CQ checks because original CL landed > 1 day ago.
>
> Bug: webrtc:9547
> Change-Id: I06673328c2a5293a7eef03b3aaf2ded9d13df1b3
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174443
> Reviewed-by: Henrik Boström <hbos@webrtc.org>
> Commit-Queue: Henrik Boström <hbos@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#31165}
TBR=hbos@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,srte@webrtc.org,hta@webrtc.org,elrello@microsoft.com
# Not skipping CQ checks because this is a reland.
Bug: webrtc:9547
Change-Id: I723744c496c3c65f95ab6a8940862c8b9f544338
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174480
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31169}
2020-05-05 15:54:46 +02:00
|
|
|
// Returns per ssrc VideoSenderInfos. Useful for simulcast scenario.
|
|
|
|
|
std::vector<VideoSenderInfo> GetPerLayerVideoSenderInfos(bool log_stats);
|
|
|
|
|
// Aggregates per ssrc VideoSenderInfos to single VideoSenderInfo for
|
|
|
|
|
// legacy reasons. Used in old GetStats API and track stats.
|
|
|
|
|
VideoSenderInfo GetAggregatedVideoSenderInfo(
|
|
|
|
|
const std::vector<VideoSenderInfo>& infos) const;
|
2017-06-12 01:16:46 -07:00
|
|
|
void FillBitrateInfo(BandwidthEstimationInfo* bwe_info);
|
|
|
|
|
|
2020-02-27 16:16:55 +01:00
|
|
|
void SetEncoderToPacketizerFrameTransformer(
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameTransformerInterface>
|
|
|
|
|
frame_transformer);
|
|
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
private:
|
|
|
|
|
// Parameters needed to reconstruct the underlying stream.
|
|
|
|
|
// webrtc::VideoSendStream doesn't support setting a lot of options on the
|
|
|
|
|
// fly, so when those need to be changed we tear down and reconstruct with
|
|
|
|
|
// similar parameters depending on which options changed etc.
|
|
|
|
|
struct VideoSendStreamParameters {
|
|
|
|
|
VideoSendStreamParameters(
|
|
|
|
|
webrtc::VideoSendStream::Config config,
|
|
|
|
|
const VideoOptions& options,
|
|
|
|
|
int max_bitrate_bps,
|
2018-06-15 15:58:38 +02:00
|
|
|
const absl::optional<VideoCodecSettings>& codec_settings);
|
2017-06-12 01:16:46 -07:00
|
|
|
webrtc::VideoSendStream::Config config;
|
|
|
|
|
VideoOptions options;
|
|
|
|
|
int max_bitrate_bps;
|
|
|
|
|
bool conference_mode;
|
2018-06-15 15:58:38 +02:00
|
|
|
absl::optional<VideoCodecSettings> codec_settings;
|
2017-06-12 01:16:46 -07:00
|
|
|
// Sent resolutions + bitrates etc. by the underlying VideoSendStream,
|
|
|
|
|
// typically changes when setting a new resolution or reconfiguring
|
|
|
|
|
// bitrates.
|
|
|
|
|
webrtc::VideoEncoderConfig encoder_config;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings>
|
|
|
|
|
ConfigureVideoEncoderSettings(const VideoCodec& codec);
|
2018-03-15 14:16:11 +01:00
|
|
|
void SetCodec(const VideoCodecSettings& codec);
|
2017-06-12 01:16:46 -07:00
|
|
|
void RecreateWebRtcStream();
|
|
|
|
|
webrtc::VideoEncoderConfig CreateVideoEncoderConfig(
|
|
|
|
|
const VideoCodec& codec) const;
|
|
|
|
|
void ReconfigureEncoder();
|
|
|
|
|
|
2021-07-26 13:24:57 +02:00
|
|
|
// Calls Start or Stop according to whether or not `sending_` is true,
|
|
|
|
|
// and whether or not the encoding in `rtp_parameters_` is active.
|
2017-06-12 01:16:46 -07:00
|
|
|
void UpdateSendState();
|
|
|
|
|
|
2018-05-16 14:20:41 -07:00
|
|
|
webrtc::DegradationPreference GetDegradationPreference() const
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(&thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2022-08-16 10:23:47 +02:00
|
|
|
RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker thread_checker_;
|
2021-04-26 20:11:18 +02:00
|
|
|
webrtc::TaskQueueBase* const worker_thread_;
|
2018-02-07 10:18:32 +01:00
|
|
|
const std::vector<uint32_t> ssrcs_ RTC_GUARDED_BY(&thread_checker_);
|
|
|
|
|
const std::vector<SsrcGroup> ssrc_groups_ RTC_GUARDED_BY(&thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
webrtc::Call* const call_;
|
|
|
|
|
const bool enable_cpu_overuse_detection_;
|
|
|
|
|
rtc::VideoSourceInterface<webrtc::VideoFrame>* source_
|
2018-02-07 10:18:32 +01:00
|
|
|
RTC_GUARDED_BY(&thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2018-02-07 10:18:32 +01:00
|
|
|
webrtc::VideoSendStream* stream_ RTC_GUARDED_BY(&thread_checker_);
|
2020-09-22 09:21:34 +02:00
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
// Contains settings that are the same for all streams in the MediaChannel,
|
|
|
|
|
// such as codecs, header extensions, and the global bitrate limit for the
|
|
|
|
|
// entire channel.
|
2018-02-07 10:18:32 +01:00
|
|
|
VideoSendStreamParameters parameters_ RTC_GUARDED_BY(&thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
// Contains settings that are unique for each stream, such as max_bitrate.
|
|
|
|
|
// Does *not* contain codecs, however.
|
|
|
|
|
// TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_.
|
|
|
|
|
// TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only
|
|
|
|
|
// one stream per MediaChannel.
|
2018-02-07 10:18:32 +01:00
|
|
|
webrtc::RtpParameters rtp_parameters_ RTC_GUARDED_BY(&thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2018-02-07 10:18:32 +01:00
|
|
|
bool sending_ RTC_GUARDED_BY(&thread_checker_);
|
2019-06-14 11:28:51 +02:00
|
|
|
|
2020-08-07 00:08:17 -07:00
|
|
|
// TODO(asapersson): investigate why setting
|
|
|
|
|
// DegrationPreferences::MAINTAIN_RESOLUTION isn't sufficient to disable
|
|
|
|
|
// downscaling everywhere in the pipeline.
|
|
|
|
|
const bool disable_automatic_resize_;
|
2017-06-12 01:16:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Wrapper for the receiver part, contains configs etc. that are needed to
|
2022-05-20 15:21:20 +02:00
|
|
|
// reconstruct the underlying VideoReceiveStreamInterface.
|
2017-06-12 01:16:46 -07:00
|
|
|
class WebRtcVideoReceiveStream
|
|
|
|
|
: public rtc::VideoSinkInterface<webrtc::VideoFrame> {
|
|
|
|
|
public:
|
|
|
|
|
WebRtcVideoReceiveStream(
|
2019-03-18 10:59:40 +01:00
|
|
|
WebRtcVideoChannel* channel,
|
2017-06-12 01:16:46 -07:00
|
|
|
webrtc::Call* call,
|
|
|
|
|
const StreamParams& sp,
|
2022-05-20 15:21:20 +02:00
|
|
|
webrtc::VideoReceiveStreamInterface::Config config,
|
2017-06-12 01:16:46 -07:00
|
|
|
bool default_stream,
|
|
|
|
|
const std::vector<VideoCodecSettings>& recv_codecs,
|
|
|
|
|
const webrtc::FlexfecReceiveStream::Config& flexfec_config);
|
|
|
|
|
~WebRtcVideoReceiveStream();
|
|
|
|
|
|
2022-05-20 15:21:20 +02:00
|
|
|
webrtc::VideoReceiveStreamInterface& stream();
|
2022-05-17 10:13:52 +02:00
|
|
|
// Return value may be nullptr.
|
|
|
|
|
webrtc::FlexfecReceiveStream* flexfec_stream();
|
|
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
const std::vector<uint32_t>& GetSsrcs() const;
|
2018-06-12 18:33:49 +02:00
|
|
|
|
2018-09-26 16:04:32 +02:00
|
|
|
std::vector<webrtc::RtpSource> GetSources();
|
|
|
|
|
|
2018-06-12 18:33:49 +02:00
|
|
|
// Does not return codecs, they are filled by the owning WebRtcVideoChannel.
|
|
|
|
|
webrtc::RtpParameters GetRtpParameters() const;
|
2017-06-12 01:16:46 -07:00
|
|
|
|
|
|
|
|
// TODO(deadbeef): Move these feedback parameters into the recv parameters.
|
2019-05-24 13:40:02 +02:00
|
|
|
void SetFeedbackParameters(bool lntf_enabled,
|
|
|
|
|
bool nack_enabled,
|
2017-06-12 01:16:46 -07:00
|
|
|
bool transport_cc_enabled,
|
2021-03-24 17:49:02 +01:00
|
|
|
webrtc::RtcpMode rtcp_mode,
|
|
|
|
|
int rtx_time);
|
2017-06-12 01:16:46 -07:00
|
|
|
void SetRecvParameters(const ChangedRecvParameters& recv_params);
|
|
|
|
|
|
|
|
|
|
void OnFrame(const webrtc::VideoFrame& frame) override;
|
|
|
|
|
bool IsDefaultStream() const;
|
|
|
|
|
|
2018-10-17 17:27:25 -07:00
|
|
|
void SetFrameDecryptor(
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor);
|
|
|
|
|
|
2019-02-27 15:32:48 +01:00
|
|
|
bool SetBaseMinimumPlayoutDelayMs(int delay_ms);
|
|
|
|
|
|
|
|
|
|
int GetBaseMinimumPlayoutDelayMs() const;
|
|
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
void SetSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
|
|
|
|
|
|
|
|
|
|
VideoReceiverInfo GetVideoReceiverInfo(bool log_stats);
|
|
|
|
|
|
2019-12-04 10:58:17 +01:00
|
|
|
void SetRecordableEncodedFrameCallback(
|
|
|
|
|
std::function<void(const webrtc::RecordableEncodedFrame&)> callback);
|
|
|
|
|
void ClearRecordableEncodedFrameCallback();
|
|
|
|
|
void GenerateKeyFrame();
|
|
|
|
|
|
2020-02-28 16:02:06 +01:00
|
|
|
void SetDepacketizerToDecoderFrameTransformer(
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameTransformerInterface>
|
|
|
|
|
frame_transformer);
|
|
|
|
|
|
2022-05-17 10:13:52 +02:00
|
|
|
void SetLocalSsrc(uint32_t local_ssrc);
|
|
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
private:
|
2022-08-02 14:37:53 +02:00
|
|
|
// Attempts to reconfigure an already existing `flexfec_stream_`, create
|
|
|
|
|
// one if the configuration is now complete or remove a flexfec stream
|
|
|
|
|
// when disabled.
|
|
|
|
|
void SetFlexFecPayload(int payload_type);
|
2022-07-28 09:24:52 +02:00
|
|
|
|
2022-05-17 10:13:52 +02:00
|
|
|
void RecreateReceiveStream();
|
2022-08-03 14:03:55 +02:00
|
|
|
void CreateReceiveStream();
|
|
|
|
|
void StartReceiveStream();
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2021-07-01 12:21:21 +02:00
|
|
|
// Applies a new receive codecs configration to `config_`. Returns true
|
|
|
|
|
// if the internal stream needs to be reconstructed, or false if no changes
|
|
|
|
|
// were applied.
|
2022-08-03 14:03:55 +02:00
|
|
|
bool ReconfigureCodecs(const std::vector<VideoCodecSettings>& recv_codecs);
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2019-03-18 10:59:40 +01:00
|
|
|
WebRtcVideoChannel* const channel_;
|
2017-06-12 01:16:46 -07:00
|
|
|
webrtc::Call* const call_;
|
2018-09-28 09:07:24 +02:00
|
|
|
const StreamParams stream_params_;
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2021-07-26 13:24:57 +02:00
|
|
|
// Both `stream_` and `flexfec_stream_` are managed by `this`. They are
|
2017-06-12 01:16:46 -07:00
|
|
|
// destroyed by calling call_->DestroyVideoReceiveStream and
|
|
|
|
|
// call_->DestroyFlexfecReceiveStream, respectively.
|
2022-05-20 15:21:20 +02:00
|
|
|
webrtc::VideoReceiveStreamInterface* stream_;
|
2017-06-12 01:16:46 -07:00
|
|
|
const bool default_stream_;
|
2022-05-20 15:21:20 +02:00
|
|
|
webrtc::VideoReceiveStreamInterface::Config config_;
|
2017-06-12 01:16:46 -07:00
|
|
|
webrtc::FlexfecReceiveStream::Config flexfec_config_;
|
|
|
|
|
webrtc::FlexfecReceiveStream* flexfec_stream_;
|
|
|
|
|
|
2020-07-07 15:43:11 +02:00
|
|
|
webrtc::Mutex sink_lock_;
|
2017-09-09 04:17:22 -07:00
|
|
|
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink_
|
|
|
|
|
RTC_GUARDED_BY(sink_lock_);
|
2017-06-12 01:16:46 -07:00
|
|
|
// Expands remote RTP timestamps to int64_t to be able to estimate how long
|
|
|
|
|
// the stream has been running.
|
|
|
|
|
rtc::TimestampWrapAroundHandler timestamp_wraparound_handler_
|
2017-09-09 04:17:22 -07:00
|
|
|
RTC_GUARDED_BY(sink_lock_);
|
|
|
|
|
int64_t first_frame_timestamp_ RTC_GUARDED_BY(sink_lock_);
|
2017-06-12 01:16:46 -07:00
|
|
|
// Start NTP time is estimated as current remote NTP time (estimated from
|
|
|
|
|
// RTCP) minus the elapsed time, as soon as remote NTP time is available.
|
2017-09-09 04:17:22 -07:00
|
|
|
int64_t estimated_remote_start_ntp_time_ms_ RTC_GUARDED_BY(sink_lock_);
|
2017-06-12 01:16:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void Construct(webrtc::Call* call, WebRtcVideoEngine* engine);
|
|
|
|
|
|
|
|
|
|
bool SendRtp(const uint8_t* data,
|
|
|
|
|
size_t len,
|
|
|
|
|
const webrtc::PacketOptions& options) override;
|
|
|
|
|
bool SendRtcp(const uint8_t* data, size_t len) override;
|
|
|
|
|
|
2019-08-07 09:57:59 -07:00
|
|
|
// Generate the list of codec parameters to pass down based on the negotiated
|
|
|
|
|
// "codecs". Note that VideoCodecSettings correspond to concrete codecs like
|
|
|
|
|
// VP8, VP9, H264 while VideoCodecs correspond also to "virtual" codecs like
|
|
|
|
|
// RTX, ULPFEC, FLEXFEC.
|
2017-06-12 01:16:46 -07:00
|
|
|
static std::vector<VideoCodecSettings> MapCodecs(
|
|
|
|
|
const std::vector<VideoCodec>& codecs);
|
2019-07-03 11:53:48 +02:00
|
|
|
// Get all codecs that are compatible with the receiver.
|
|
|
|
|
std::vector<VideoCodecSettings> SelectSendVideoCodecs(
|
2019-03-01 15:15:38 -08:00
|
|
|
const std::vector<VideoCodecSettings>& remote_mapped_codecs) const
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
|
|
|
|
|
static bool NonFlexfecReceiveCodecsHaveChanged(
|
|
|
|
|
std::vector<VideoCodecSettings> before,
|
|
|
|
|
std::vector<VideoCodecSettings> after);
|
|
|
|
|
|
2019-03-01 15:15:38 -08:00
|
|
|
void FillSenderStats(VideoMediaInfo* info, bool log_stats)
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
|
|
|
|
void FillReceiverStats(VideoMediaInfo* info, bool log_stats)
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
void FillBandwidthEstimationStats(const webrtc::Call::Stats& stats,
|
2019-03-01 15:15:38 -08:00
|
|
|
VideoMediaInfo* info)
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
|
|
|
|
void FillSendAndReceiveCodecStats(VideoMediaInfo* video_media_info)
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2021-04-26 20:11:18 +02:00
|
|
|
webrtc::TaskQueueBase* const worker_thread_;
|
2021-01-18 10:49:05 +01:00
|
|
|
webrtc::ScopedTaskSafety task_safety_;
|
2022-08-16 10:23:47 +02:00
|
|
|
RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker network_thread_checker_;
|
|
|
|
|
RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker thread_checker_;
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2019-03-01 15:15:38 -08:00
|
|
|
uint32_t rtcp_receiver_report_ssrc_ RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
bool sending_ RTC_GUARDED_BY(thread_checker_);
|
2021-01-18 10:49:05 +01:00
|
|
|
webrtc::Call* const call_;
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2019-03-01 15:15:38 -08:00
|
|
|
DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_
|
|
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
UnsignalledSsrcHandler* const unsignalled_ssrc_handler_
|
|
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
|
2019-02-27 15:32:48 +01:00
|
|
|
// Delay for unsignaled streams, which may be set before the stream exists.
|
2019-03-01 15:15:38 -08:00
|
|
|
int default_recv_base_minimum_delay_ms_ RTC_GUARDED_BY(thread_checker_) = 0;
|
2019-02-27 15:32:48 +01:00
|
|
|
|
2019-03-01 15:15:38 -08:00
|
|
|
const MediaConfig::Video video_config_ RTC_GUARDED_BY(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
|
|
|
|
|
// Using primary-ssrc (first ssrc) as key.
|
|
|
|
|
std::map<uint32_t, WebRtcVideoSendStream*> send_streams_
|
2019-03-01 15:15:38 -08:00
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_
|
2019-03-01 15:15:38 -08:00
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
2021-04-16 09:54:18 +02:00
|
|
|
// When the channel and demuxer get reconfigured, there is a window of time
|
|
|
|
|
// where we have to be prepared for packets arriving based on the old demuxer
|
|
|
|
|
// criteria because the streams live on the worker thread and the demuxer
|
|
|
|
|
// lives on the network thread. Because packets are posted from the network
|
|
|
|
|
// thread to the worker thread, they can still be in-flight when streams are
|
2021-07-26 13:24:57 +02:00
|
|
|
// reconfgured. This can happen when `demuxer_criteria_id_` and
|
|
|
|
|
// `demuxer_criteria_completed_id_` don't match. During this time, we do not
|
2021-04-16 09:54:18 +02:00
|
|
|
// want to create unsignalled receive streams and should instead drop the
|
|
|
|
|
// packets. E.g:
|
|
|
|
|
// * If RemoveRecvStream(old_ssrc) was recently called, there may be packets
|
|
|
|
|
// in-flight for that ssrc. This happens when a receiver becomes inactive.
|
|
|
|
|
// * If we go from one to many m= sections, the demuxer may change from
|
|
|
|
|
// forwarding all packets to only forwarding the configured ssrcs, so there
|
|
|
|
|
// is a risk of receiving ssrcs for other, recently added m= sections.
|
|
|
|
|
uint32_t demuxer_criteria_id_ RTC_GUARDED_BY(thread_checker_) = 0;
|
|
|
|
|
uint32_t demuxer_criteria_completed_id_ RTC_GUARDED_BY(thread_checker_) = 0;
|
2021-06-09 11:10:15 +02:00
|
|
|
absl::optional<int64_t> last_unsignalled_ssrc_creation_time_ms_
|
|
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
2019-03-01 15:15:38 -08:00
|
|
|
std::set<uint32_t> send_ssrcs_ RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
std::set<uint32_t> receive_ssrcs_ RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
|
|
|
|
|
absl::optional<VideoCodecSettings> send_codec_
|
|
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
2019-07-03 11:53:48 +02:00
|
|
|
std::vector<VideoCodecSettings> negotiated_codecs_
|
|
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
|
2021-10-21 22:37:50 +00:00
|
|
|
std::vector<webrtc::RtpExtension> send_rtp_extensions_
|
2019-03-01 15:15:38 -08:00
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
|
|
|
|
|
webrtc::VideoEncoderFactory* const encoder_factory_
|
|
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
webrtc::VideoDecoderFactory* const decoder_factory_
|
|
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
webrtc::VideoBitrateAllocatorFactory* const bitrate_allocator_factory_
|
|
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
std::vector<VideoCodecSettings> recv_codecs_ RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
std::vector<webrtc::RtpExtension> recv_rtp_extensions_
|
|
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
// See reason for keeping track of the FlexFEC payload type separately in
|
|
|
|
|
// comment in WebRtcVideoChannel::ChangedRecvParameters.
|
2019-03-01 15:15:38 -08:00
|
|
|
int recv_flexfec_payload_type_ RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
webrtc::BitrateConstraints bitrate_config_ RTC_GUARDED_BY(thread_checker_);
|
2017-06-12 01:16:46 -07:00
|
|
|
// TODO(deadbeef): Don't duplicate information between
|
|
|
|
|
// send_params/recv_params, rtp_extensions, options, etc.
|
2019-03-01 15:15:38 -08:00
|
|
|
VideoSendParameters send_params_ RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
VideoOptions default_send_options_ RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
VideoRecvParameters recv_params_ RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
int64_t last_stats_log_ms_ RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
const bool discard_unknown_ssrc_packets_ RTC_GUARDED_BY(thread_checker_);
|
2018-04-03 11:16:33 -07:00
|
|
|
// This is a stream param that comes from the remote description, but wasn't
|
|
|
|
|
// signaled with any a=ssrc lines. It holds information that was signaled
|
|
|
|
|
// before the unsignaled receive stream is created when the first packet is
|
|
|
|
|
// received.
|
2019-03-01 15:15:38 -08:00
|
|
|
StreamParams unsignaled_stream_params_ RTC_GUARDED_BY(thread_checker_);
|
2018-10-17 17:27:25 -07:00
|
|
|
// Per peer connection crypto options that last for the lifetime of the peer
|
|
|
|
|
// connection.
|
2019-03-01 15:15:38 -08:00
|
|
|
const webrtc::CryptoOptions crypto_options_ RTC_GUARDED_BY(thread_checker_);
|
2019-03-18 10:59:40 +01:00
|
|
|
|
2020-04-11 12:42:49 +02:00
|
|
|
// Optional frame transformer set on unsignaled streams.
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameTransformerInterface>
|
|
|
|
|
unsignaled_frame_transformer_ RTC_GUARDED_BY(thread_checker_);
|
|
|
|
|
|
2019-03-18 10:59:40 +01:00
|
|
|
// Buffer for unhandled packets.
|
|
|
|
|
std::unique_ptr<UnhandledPacketsBuffer> unknown_ssrc_packet_buffer_
|
|
|
|
|
RTC_GUARDED_BY(thread_checker_);
|
2019-07-03 11:53:48 +02:00
|
|
|
|
2022-01-21 11:35:04 +01:00
|
|
|
// TODO(bugs.webrtc.org/11341): Remove this and relevant PC API. Presence
|
|
|
|
|
// of multiple negotiated codecs allows generic encoder fallback on failures.
|
|
|
|
|
// Presence of EncoderSelector allows switching to specific encoders.
|
2019-10-25 12:23:02 +02:00
|
|
|
bool allow_codec_switching_ = false;
|
2017-06-12 01:16:46 -07:00
|
|
|
};
|
|
|
|
|
|
2017-06-16 06:53:48 -07:00
|
|
|
class EncoderStreamFactory
|
|
|
|
|
: public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface {
|
|
|
|
|
public:
|
|
|
|
|
EncoderStreamFactory(std::string codec_name,
|
|
|
|
|
int max_qp,
|
2018-02-07 08:50:36 -08:00
|
|
|
bool is_screenshare,
|
2020-09-22 11:36:35 +02:00
|
|
|
bool conference_mode)
|
|
|
|
|
: EncoderStreamFactory(codec_name,
|
|
|
|
|
max_qp,
|
|
|
|
|
is_screenshare,
|
|
|
|
|
conference_mode,
|
|
|
|
|
nullptr) {}
|
|
|
|
|
|
|
|
|
|
EncoderStreamFactory(std::string codec_name,
|
|
|
|
|
int max_qp,
|
|
|
|
|
bool is_screenshare,
|
|
|
|
|
bool conference_mode,
|
2022-03-29 11:04:48 +02:00
|
|
|
const webrtc::FieldTrialsView* trials);
|
2017-06-16 06:53:48 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::vector<webrtc::VideoStream> CreateEncoderStreams(
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
const webrtc::VideoEncoderConfig& encoder_config) override;
|
|
|
|
|
|
2020-01-21 14:50:54 +01:00
|
|
|
std::vector<webrtc::VideoStream> CreateDefaultVideoStreams(
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
const webrtc::VideoEncoderConfig& encoder_config,
|
|
|
|
|
const absl::optional<webrtc::DataRate>& experimental_min_bitrate) const;
|
|
|
|
|
|
|
|
|
|
std::vector<webrtc::VideoStream>
|
2020-08-04 11:40:23 +02:00
|
|
|
CreateSimulcastOrConferenceModeScreenshareStreams(
|
2020-01-21 14:50:54 +01:00
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
const webrtc::VideoEncoderConfig& encoder_config,
|
|
|
|
|
const absl::optional<webrtc::DataRate>& experimental_min_bitrate) const;
|
|
|
|
|
|
2017-06-16 06:53:48 -07:00
|
|
|
const std::string codec_name_;
|
|
|
|
|
const int max_qp_;
|
2018-02-07 08:50:36 -08:00
|
|
|
const bool is_screenshare_;
|
|
|
|
|
// Allows a screenshare specific configuration, which enables temporal
|
2019-07-10 16:57:57 +02:00
|
|
|
// layering and various settings.
|
|
|
|
|
const bool conference_mode_;
|
2020-09-22 11:36:35 +02:00
|
|
|
const webrtc::FieldTrialBasedConfig fallback_trials_;
|
2022-03-29 11:04:48 +02:00
|
|
|
const webrtc::FieldTrialsView& trials_;
|
2017-06-16 06:53:48 -07:00
|
|
|
};
|
|
|
|
|
|
2017-06-12 01:16:46 -07:00
|
|
|
} // namespace cricket
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#endif // MEDIA_ENGINE_WEBRTC_VIDEO_ENGINE_H_
|