webrtc_m130/call/rtp_video_sender.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

217 lines
8.5 KiB
C
Raw Normal View History

/*
* Copyright (c) 2015 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.
*/
#ifndef CALL_RTP_VIDEO_SENDER_H_
#define CALL_RTP_VIDEO_SENDER_H_
#include <map>
#include <memory>
#include <unordered_set>
#include <vector>
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/call/transport.h"
#include "api/fec_controller.h"
#include "api/fec_controller_override.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "api/sequence_checker.h"
#include "api/transport/field_trial_based_config.h"
#include "api/video_codecs/video_encoder.h"
#include "call/rtp_config.h"
Reland "Move allocation and rtp conversion logic out of payload router." This reverts commit c2406e4eaf7703c6c64d21318186adda791e09fd. Reason for revert: Reland by removing the conflict with the broken CL. Original change's description: > Revert "Move allocation and rtp conversion logic out of payload router." > > This reverts commit 1da4d79ba3275b3fa48cad3b2c0949e0d3b7afe7. > > Reason for revert: Need to revert https://webrtc-review.googlesource.com/c/src/+/88220 > > This causes a merge conflict. So need to revert this first. > > Original change's description: > > Move allocation and rtp conversion logic out of payload router. > > > > Makes it easier to write tests, and allows for moving rtp module > > ownership into the payload router in the future. > > > > The RtpPayloadParams class is split into declaration and definition and > > moved into separate files. > > > > Bug: webrtc:9517 > > Change-Id: I8700628edff19abcacfe8d3a20e4ba7476f712ad > > Reviewed-on: https://webrtc-review.googlesource.com/88564 > > Commit-Queue: Stefan Holmer <stefan@webrtc.org> > > Reviewed-by: Sebastian Jansson <srte@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#23983} > > TBR=sprang@webrtc.org,stefan@webrtc.org,srte@webrtc.org > > Change-Id: I342c4bf483d975c87c706fe7f76f44e2dc60fe4c > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:9517 > Reviewed-on: https://webrtc-review.googlesource.com/88821 > Reviewed-by: JT Teh <jtteh@webrtc.org> > Commit-Queue: JT Teh <jtteh@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#23991} TBR=sprang@webrtc.org,stefan@webrtc.org,srte@webrtc.org,lliuu@webrtc.org,jtteh@webrtc.org,tkchin@webrtc.org Change-Id: I154145cdbc668feee86dbe78860147a6954fee6c No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:9517 Reviewed-on: https://webrtc-review.googlesource.com/89020 Commit-Queue: Stefan Holmer <stefan@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23996}
2018-07-17 10:16:41 +02:00
#include "call/rtp_payload_params.h"
#include "call/rtp_transport_controller_send_interface.h"
#include "call/rtp_video_sender_interface.h"
#include "modules/rtp_rtcp/include/flexfec_sender.h"
#include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
#include "modules/rtp_rtcp/source/rtp_sender.h"
#include "modules/rtp_rtcp/source/rtp_sender_video.h"
#include "modules/rtp_rtcp/source/rtp_sequence_number_map.h"
#include "modules/rtp_rtcp/source/rtp_video_header.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/rate_limiter.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
namespace webrtc {
class FrameEncryptorInterface;
class RtpTransportControllerSendInterface;
namespace webrtc_internal_rtp_video_sender {
// RTP state for a single simulcast stream. Internal to the implementation of
// RtpVideoSender.
struct RtpStreamSender {
RtpStreamSender(std::unique_ptr<ModuleRtpRtcpImpl2> rtp_rtcp,
Reland "Reland "Refactors UlpFec and FlexFec to use a common interface."" This is a reland of 49734dc0faa69616a58a1a95c7fc61a4610793cf Patchset 2 contains a fix for the fuzzer set up. Since we now parse an RtpPacket out of the fuzzer data, the header needs to be correct, otherwise we fail before even reaching the FEC code that we actually want to test. Bug: webrtc:11340, chromium:1052323, chromium:1055974 TBR=stefan@webrtc.org Original change's description: > Reland "Refactors UlpFec and FlexFec to use a common interface." > > This is a reland of 11af1d7444fd7438766b7bc52cbd64752d72e32e > > Original change's description: > > Refactors UlpFec and FlexFec to use a common interface. > > > > The new VideoFecGenerator is now injected into RtpSenderVideo, > > and generalizes the usage. > > This also prepares for being able to genera FEC in the RTP egress > > module. > > > > Bug: webrtc:11340 > > Change-Id: I8aa873129b2fb4131eb3399ee88f6ea2747155a3 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168347 > > Reviewed-by: Stefan Holmer <stefan@webrtc.org> > > Reviewed-by: Sebastian Jansson <srte@webrtc.org> > > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> > > Commit-Queue: Erik Språng <sprang@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#30515} > > Bug: webrtc:11340, chromium:1052323 > Change-Id: Id646047365f1c46cca9e6f3e8eefa5151207b4a0 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168608 > Commit-Queue: Erik Språng <sprang@webrtc.org> > Reviewed-by: Stefan Holmer <stefan@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#30593} Bug: webrtc:11340, chromium:1052323 Change-Id: Ib8925f44e2edfcfeadc95c845c3bfc23822604ed Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169222 Commit-Queue: Erik Språng <sprang@webrtc.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30724}
2020-03-05 10:14:04 +01:00
std::unique_ptr<RTPSenderVideo> sender_video,
std::unique_ptr<VideoFecGenerator> fec_generator);
~RtpStreamSender();
RtpStreamSender(RtpStreamSender&&) = default;
RtpStreamSender& operator=(RtpStreamSender&&) = default;
// Note: Needs pointer stability.
std::unique_ptr<ModuleRtpRtcpImpl2> rtp_rtcp;
std::unique_ptr<RTPSenderVideo> sender_video;
Reland "Reland "Refactors UlpFec and FlexFec to use a common interface."" This is a reland of 49734dc0faa69616a58a1a95c7fc61a4610793cf Patchset 2 contains a fix for the fuzzer set up. Since we now parse an RtpPacket out of the fuzzer data, the header needs to be correct, otherwise we fail before even reaching the FEC code that we actually want to test. Bug: webrtc:11340, chromium:1052323, chromium:1055974 TBR=stefan@webrtc.org Original change's description: > Reland "Refactors UlpFec and FlexFec to use a common interface." > > This is a reland of 11af1d7444fd7438766b7bc52cbd64752d72e32e > > Original change's description: > > Refactors UlpFec and FlexFec to use a common interface. > > > > The new VideoFecGenerator is now injected into RtpSenderVideo, > > and generalizes the usage. > > This also prepares for being able to genera FEC in the RTP egress > > module. > > > > Bug: webrtc:11340 > > Change-Id: I8aa873129b2fb4131eb3399ee88f6ea2747155a3 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168347 > > Reviewed-by: Stefan Holmer <stefan@webrtc.org> > > Reviewed-by: Sebastian Jansson <srte@webrtc.org> > > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> > > Commit-Queue: Erik Språng <sprang@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#30515} > > Bug: webrtc:11340, chromium:1052323 > Change-Id: Id646047365f1c46cca9e6f3e8eefa5151207b4a0 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168608 > Commit-Queue: Erik Språng <sprang@webrtc.org> > Reviewed-by: Stefan Holmer <stefan@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#30593} Bug: webrtc:11340, chromium:1052323 Change-Id: Ib8925f44e2edfcfeadc95c845c3bfc23822604ed Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169222 Commit-Queue: Erik Språng <sprang@webrtc.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30724}
2020-03-05 10:14:04 +01:00
std::unique_ptr<VideoFecGenerator> fec_generator;
};
} // namespace webrtc_internal_rtp_video_sender
// RtpVideoSender routes outgoing data to the correct sending RTP module, based
// on the simulcast layer in RTPVideoHeader.
class RtpVideoSender : public RtpVideoSenderInterface,
public VCMProtectionCallback,
public StreamFeedbackObserver {
public:
// Rtp modules are assumed to be sorted in simulcast index order.
RtpVideoSender(
Clock* clock,
std::map<uint32_t, RtpState> suspended_ssrcs,
const std::map<uint32_t, RtpPayloadState>& states,
const RtpConfig& rtp_config,
int rtcp_report_interval_ms,
Transport* send_transport,
const RtpSenderObservers& observers,
RtpTransportControllerSendInterface* transport,
RtcEventLog* event_log,
RateLimiter* retransmission_limiter, // move inside RtpTransport
std::unique_ptr<FecController> fec_controller,
FrameEncryptorInterface* frame_encryptor,
const CryptoOptions& crypto_options, // move inside RtpTransport
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer);
~RtpVideoSender() override;
// RtpVideoSender will only route packets if being active, all packets will be
// dropped otherwise.
void SetActive(bool active) RTC_LOCKS_EXCLUDED(mutex_) override;
// Sets the sending status of the rtp modules and appropriately sets the
// payload router to active if any rtp modules are active.
void SetActiveModules(const std::vector<bool> active_modules)
RTC_LOCKS_EXCLUDED(mutex_) override;
bool IsActive() RTC_LOCKS_EXCLUDED(mutex_) override;
void OnNetworkAvailability(bool network_available)
RTC_LOCKS_EXCLUDED(mutex_) override;
std::map<uint32_t, RtpState> GetRtpStates() const
RTC_LOCKS_EXCLUDED(mutex_) override;
std::map<uint32_t, RtpPayloadState> GetRtpPayloadStates() const
RTC_LOCKS_EXCLUDED(mutex_) override;
void DeliverRtcp(const uint8_t* packet, size_t length)
RTC_LOCKS_EXCLUDED(mutex_) override;
// Implements webrtc::VCMProtectionCallback.
int ProtectionRequest(const FecProtectionParams* delta_params,
const FecProtectionParams* key_params,
uint32_t* sent_video_rate_bps,
uint32_t* sent_nack_rate_bps,
uint32_t* sent_fec_rate_bps)
RTC_LOCKS_EXCLUDED(mutex_) override;
// Implements FecControllerOverride.
void SetFecAllowed(bool fec_allowed) RTC_LOCKS_EXCLUDED(mutex_) override;
Reland of Deprecate VCMPacketizationCallback::SendData and use EncodedImageCallback instead. (patchset #1 id:1 of https://codereview.webrtc.org/1903193002/ ) Reason for revert: A fix is being prepared downstream so this can now go in. Original issue's description: > Revert of Deprecate VCMPacketizationCallback::SendData and use EncodedImageCallback instead. (patchset #5 id:80001 of https://codereview.webrtc.org/1897233002/ ) > > Reason for revert: > API changes broke downstream. > > Original issue's description: > > Deprecate VCMPacketizationCallback::SendData and use EncodedImageCallback instead. > > EncodedImageCallback is used by all encoder implementations and seems to be what we should try to use in the transport. > > EncodedImageCallback can of course be cleaned up in the future. > > > > This moves creation of RTPVideoHeader from the GenericEncoder to the PayLoadRouter. > > > > BUG=webrtc::5687 > > > > Committed: https://crrev.com/f5d55aaecdc39e9cc66eb6e87614f04afe28f6eb > > Cr-Commit-Position: refs/heads/master@{#12436} > > TBR=stefan@webrtc.org,pbos@webrtc.org,perkj@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:5687 > > Committed: https://crrev.com/a261e6136655af33f283eda8e60a6dd93dd746a4 > Cr-Commit-Position: refs/heads/master@{#12441} TBR=stefan@webrtc.org,pbos@webrtc.org,perkj@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:5687 Review URL: https://codereview.webrtc.org/1905583002 Cr-Commit-Position: refs/heads/master@{#12442}
2016-04-20 05:05:54 -07:00
// Implements EncodedImageCallback.
// Returns 0 if the packet was routed / sent, -1 otherwise.
EncodedImageCallback::Result OnEncodedImage(
const EncodedImage& encoded_image,
const CodecSpecificInfo* codec_specific_info)
RTC_LOCKS_EXCLUDED(mutex_) override;
void OnBitrateAllocationUpdated(const VideoBitrateAllocation& bitrate)
RTC_LOCKS_EXCLUDED(mutex_) override;
void OnVideoLayersAllocationUpdated(
const VideoLayersAllocation& layers) override;
void OnTransportOverheadChanged(size_t transport_overhead_bytes_per_packet)
RTC_LOCKS_EXCLUDED(mutex_) override;
void OnBitrateUpdated(BitrateAllocationUpdate update, int framerate)
RTC_LOCKS_EXCLUDED(mutex_) override;
uint32_t GetPayloadBitrateBps() const RTC_LOCKS_EXCLUDED(mutex_) override;
uint32_t GetProtectionBitrateBps() const RTC_LOCKS_EXCLUDED(mutex_) override;
void SetEncodingData(size_t width, size_t height, size_t num_temporal_layers)
RTC_LOCKS_EXCLUDED(mutex_) override;
std::vector<RtpSequenceNumberMap::Info> GetSentRtpPacketInfos(
uint32_t ssrc,
rtc::ArrayView<const uint16_t> sequence_numbers) const
RTC_LOCKS_EXCLUDED(mutex_) override;
// From StreamFeedbackObserver.
void OnPacketFeedbackVector(
std::vector<StreamPacketInfo> packet_feedback_vector)
RTC_LOCKS_EXCLUDED(mutex_) override;
private:
bool IsActiveLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void SetActiveModulesLocked(const std::vector<bool> active_modules)
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void UpdateModuleSendingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void ConfigureProtection();
void ConfigureSsrcs();
void ConfigureRids();
bool NackEnabled() const;
uint32_t GetPacketizationOverheadRate() const;
DataRate CalculateOverheadRate(DataRate data_rate,
DataSize packet_size,
DataSize overhead_per_packet,
Frequency framerate) const;
const FieldTrialBasedConfig field_trials_;
const bool send_side_bwe_with_overhead_;
const bool use_frame_rate_for_overhead_;
Reland "Reland "Only include overhead if using send side bandwidth estimation."" This is a reland of 086055d0fd9b9b9efe8bcf85884324a019e9bd33 ANA was accitendly disabled even when transport sequence numbers were negotiated due to a bug in how the audio send stream is configured. To solve this we simply continue to always allow enabling ANA and leave it up to the application to ensure that it's not used together with receive side estimation. Original change's description: > Reland "Only include overhead if using send side bandwidth estimation." > > This is a reland of 8c79c6e1af354c526497082c79ccbe12af03a33e > > Original change's description: > > Only include overhead if using send side bandwidth estimation. > > > > Bug: webrtc:11298 > > Change-Id: Ia2daf690461b55d394c1b964d6a7977a98be8be2 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166820 > > Reviewed-by: Oskar Sundbom <ossu@webrtc.org> > > Reviewed-by: Sam Zackrisson <saza@webrtc.org> > > Reviewed-by: Ali Tofigh <alito@webrtc.org> > > Reviewed-by: Erik Språng <sprang@webrtc.org> > > Commit-Queue: Sebastian Jansson <srte@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#30382} > > Bug: webrtc:11298 > Change-Id: I33205e869a8ae27c15ffe991f6d985973ed6d15a > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167524 > Reviewed-by: Ali Tofigh <alito@webrtc.org> > Reviewed-by: Sam Zackrisson <saza@webrtc.org> > Reviewed-by: Erik Språng <sprang@webrtc.org> > Reviewed-by: Oskar Sundbom <ossu@webrtc.org> > Commit-Queue: Sebastian Jansson <srte@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#30390} Bug: webrtc:11298 Change-Id: If2ad91e17ebfc85dc51edcd9607996e18c5d1f13 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167883 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30413}
2020-01-29 17:42:52 +01:00
const bool has_packet_feedback_;
const bool simulate_vp9_structure_;
// TODO(holmer): Remove mutex_ once RtpVideoSender runs on the
// transport task queue.
mutable Mutex mutex_;
bool active_ RTC_GUARDED_BY(mutex_);
std::map<uint32_t, RtpState> suspended_ssrcs_;
const std::unique_ptr<FecController> fec_controller_;
bool fec_allowed_ RTC_GUARDED_BY(mutex_);
// Rtp modules are assumed to be sorted in simulcast index order.
const std::vector<webrtc_internal_rtp_video_sender::RtpStreamSender>
rtp_streams_;
const RtpConfig rtp_config_;
const absl::optional<VideoCodecType> codec_type_;
RtpTransportControllerSendInterface* const transport_;
// When using the generic descriptor we want all simulcast streams to share
// one frame id space (so that the SFU can switch stream without having to
// rewrite the frame id), therefore `shared_frame_id` has to live in a place
// where we are aware of all the different streams.
int64_t shared_frame_id_ = 0;
std::vector<RtpPayloadParams> params_ RTC_GUARDED_BY(mutex_);
size_t transport_overhead_bytes_per_packet_ RTC_GUARDED_BY(mutex_);
uint32_t protection_bitrate_bps_;
uint32_t encoder_target_rate_bps_;
std::vector<bool> loss_mask_vector_ RTC_GUARDED_BY(mutex_);
std::vector<FrameCounts> frame_counts_ RTC_GUARDED_BY(mutex_);
FrameCountObserver* const frame_count_observer_;
// Effectively const map from SSRC to RtpRtcp, for all media SSRCs.
// This map is set at construction time and never changed, but it's
// non-trivial to make it properly const.
std::map<uint32_t, RtpRtcpInterface*> ssrc_to_rtp_module_;
RTC_DISALLOW_COPY_AND_ASSIGN(RtpVideoSender);
};
} // namespace webrtc
#endif // CALL_RTP_VIDEO_SENDER_H_